Skip to content

Commit

Permalink
Fix bug in double homogenization of split eclasses
Browse files Browse the repository at this point in the history
While at it change the parameter of Eclass::split() to
follow the end-exclusive convention.
  • Loading branch information
dspinellis committed Jul 9, 2024
1 parent 06e0b07 commit a295ffd
Show file tree
Hide file tree
Showing 4 changed files with 350 additions and 29 deletions.
10 changes: 5 additions & 5 deletions src/eclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ merge(Eclass *a, Eclass *b)
return (large);
}

// Split an equivalence class after the (0-based) character position
// pos returning the new EC receiving the split Tokids
// Split an equivalence class starting at the (0-based) character position
// pos returning the new EC receiving the Tokids split off at the end.
Eclass *
Eclass::split(int pos)
{
int oldchars = pos + 1; // Characters to retain in the old EC
int oldchars = pos; // Characters to retain in the old EC
if (DP())
cout << "Split " << this << " pos=" << pos << *this;
csassert(oldchars < len);
Expand Down Expand Up @@ -204,9 +204,9 @@ main()
Eclass *enew = merge(e1, e2);
cout << "merged:\n" << *enew;

Eclass *es = enew->split(2);
Eclass *es = enew->split(3);
cout << "split 0:\n" << *enew << "\n";
cout << "split 2:\n" << *es << "\n";
cout << "split 3:\n" << *es << "\n";

return (0);
}
Expand Down
17 changes: 17 additions & 0 deletions src/test/c/c46-double-split.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Test homogenization when a token part split
* during homogenization has its equivalence class
* reused later on.
*/

#define unsplit(x, a, b) x ## a ## x ## b

#define split(x, y, a, b) x ## y ## a ## x ## y ## b

int
fun(void)
{
int unsplit(kaboom, 1, 2);

split(ka, boom, 1, 2) = 0;
}
267 changes: 267 additions & 0 deletions src/test/out/c46-double-split.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
Table: Ids
EID NAME READONLY UNDEFMACRO MACRO MACROARG ORDINARY SUETAG SUMEMBER LABEL TYPEDEF ENUM YACC FUN CSCOPE LSCOPE UNUSED
---- -------------- -------- ---------- ----- -------- -------- ------ -------- ----- ------- ----- ----- ----- ------ ------ ------
91 MAXDIGIT FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE
331 x FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE
441 main TRUE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE TRUE FALSE
571 qqq FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE
891 foo FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE TRUE TRUE
1349 unsplit FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
1429 x FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
1459 a FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
1489 b FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
1779 split FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
1839 x FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
1869 y FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
1899 a FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
1929 b FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
2279 fun FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE TRUE TRUE
2529 ka FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
2549 boom FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
2609 1 FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
2639 2 FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
2975 __DATE__ TRUE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE
3295 __TIME__ TRUE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE
3575 __FILE__ TRUE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE
3865 __LINE__ TRUE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE
4055 __STDC__ TRUE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE
5355 _cscout_dummy1 TRUE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE FALSE FALSE
Table: Tokens
FID FOFFSET EID
--- ------- ----
2 297 2975
2 329 3295
2 357 3575
2 386 3865
2 405 4055
2 471 441
2 535 5355
2 558 5355
4 134 1349
4 142 1429
4 145 1459
4 148 1489
4 151 1429
4 156 1459
4 161 1429
4 166 1489
4 177 1779
4 183 1839
4 186 1869
4 189 1899
4 192 1929
4 195 1839
4 200 1869
4 205 1899
4 210 1839
4 215 1869
4 220 1929
4 227 2279
4 244 1349
4 252 2529
4 254 2549
4 260 2609
4 263 2639
4 269 1779
4 275 2529
4 279 2549
4 285 2609
4 288 2639
5 8 91
5 32 331
5 43 441
5 56 571
5 88 891
Table: Rest
FID FOFFSET CODE
--- ------- --------------------------------------------------------------------
2 287 \u0000a\u0000a#define
2 305
2 320 \u0000a#define
2 337
2 348 \u0000a#define
2 365
2 377 \u0000a#define
2 394 1\u0000a#define
2 413 1\u0000a\u0000a
2 466 \u0000aint
2 475 ();\u0000a
2 522 \u0000astatic void
2 549 (void) {
2 572 (); }\u0000a
3 152 \u0000a\u0000a\u0000a#pragma includepath
3 195 \u0000a
3 239 \u0000astatic void _cscout_dummy2(void) { _cscout_dummy2(); }\u0000a
4 124 \u0000a\u0000a#define
4 141 (
4 143 ,
4 146 ,
4 149 )
4 152 ##
4 157 ##
4 162 ##
4 167 \u0000a\u0000a#define
4 182 (
4 184 ,
4 187 ,
4 190 ,
4 193 )
4 196 ##
4 201 ##
4 206 ##
4 211 ##
4 216 ##
4 221 \u0000a\u0000aint\u0000a
4 230 (void)\u0000a{\u0000a int
4 251 (
4 258 ,
4 261 ,
4 264 );\u0000a\u0000a
4 274 (
4 277 ,
4 283 ,
4 286 ,
4 289 ) = 0;\u0000a}\u0000a
5 0 #define
5 16 11\u0000d\u0000aextern int
5 33 ;\u0000d\u0000aextern
5 47 ();\u0000d\u0000aint
5 59 ;\u0000d\u0000a\u0000d\u0000a
5 86 \u0000d\u0000a
5 91 () {\u0000d\u0000a
5 116 }\u0000d\u0000a\u0000d\u0000a
Table: Projects
PID NAME
--- -----------
16 unspecified
17 Prj1
18 Prj2
Table: IdProj
EID PID
---- ---
441 17
1349 17
1429 17
1459 17
1489 17
1779 17
1839 17
1869 17
1899 17
1929 17
2279 17
2529 17
2549 17
2609 17
2639 17
2975 17
3295 17
3575 17
3865 17
4055 17
5355 17
91 18
331 18
441 18
571 18
891 18
1349 18
1429 18
1459 18
1489 18
1779 18
1839 18
1869 18
1899 18
1929 18
2279 18
2529 18
2549 18
2609 18
2639 18
2975 18
3295 18
3575 18
3865 18
4055 18
5355 18
Table: Files
FID NAME RO NCHAR NCCOMMENT NSPACE NLCOMMENT NBCOMMENT NLINE MAXLINELEN NSTRING NULINE NPPDIRECTIVE NPPCOND NPPFMACRO NPPOMACRO NPPTOKEN NCTOKEN NCOPIES NSTATEMENT NPFUNCTION NFFUNCTION NPVAR NFVAR NAGGREGATE NAMEMBER NENUM NEMEMBER NINCFILE
--- ------------------ ----- ----- --------- ------ --------- --------- ----- ---------- ------- ------ ------------ ------- --------- --------- -------- ------- ------- ---------- ---------- ---------- ----- ----- ---------- -------- ----- -------- --------
2 host-defs.h TRUE 578 367 29 0 3 22 61 3 0 5 0 0 5 37 18 1 1 0 1 0 0 0 0 0 0 0
3 host-incs.h TRUE 295 187 13 0 2 13 54 1 0 1 0 0 0 16 0 1 0 0 0 0 0 0 0 0 0 0
4 c46-double-split.c FALSE 298 120 48 0 1 17 52 0 0 2 0 2 0 86 15 1 1 1 0 0 0 0 0 0 0 0
5 prj2.c FALSE 121 34 26 2 0 11 21 0 0 1 0 0 1 21 18 1 0 1 0 2 0 0 0 0 0 0
Table: FileProj
FID PID
--- ---
2 17
3 17
4 17
1 18
2 18
3 18
4 18
5 18
Table: Definers
PID CUID BASEFILEID DEFINERID
--- ---- ---------- ---------
18 5 5 2
Table: Includers
PID CUID BASEFILEID INCLUDERID
--- ---- ---------- ----------
17 2 2 1
17 4 3 1
17 4 4 1
18 2 2 1
18 2 2 1
18 4 3 1
18 4 4 1
18 5 3 1
18 5 5 1
Table: Providers
PID CUID PROVIDERID
--- ---- ----------
17 2 2
17 4 4
18 2 2
18 2 2
18 4 4
18 5 5
Table: IncTriggers
PID CUID BASEFILEID DEFINERID FOFFSET LEN
--- ---- ---------- --------- ------- ---
18 5 5 2 471 4
Table: Functions
ID NAME ISMACRO DEFINED DECLARED FILESCOPED FID FOFFSET FANIN
---- -------------- ------- ------- -------- ---------- --- ------- -----
891 foo FALSE TRUE TRUE FALSE 5 88 0
1349 unsplit TRUE TRUE FALSE TRUE 4 134 1
1779 split TRUE TRUE FALSE TRUE 4 177 1
2279 fun FALSE TRUE TRUE FALSE 4 227 0
4715 main FALSE FALSE TRUE FALSE 2 471 0
5355 _cscout_dummy1 FALSE TRUE TRUE TRUE 2 535 1
Table: FunctionMetrics
FUNCTIONID NCHAR NCCOMMENT NSPACE NLCOMMENT NBCOMMENT NLINE MAXLINELEN NSTRING NULINE NPPDIRECTIVE NPPCOND NPPFMACRO NPPOMACRO NPPTOKEN NCTOKEN NSTMT NOP NUOP NNCONST NCLIT NIF NELSE NSWITCH NCASE NDEFAULT NBREAK NFOR NWHILE NDO NCONTINUE NGOTO NRETURN NPID NFID NMID NID NUPID NUFID NUMID NUID NGNSOC NPARAM MAXNEST NLABEL FANIN FANOUT CCYCL1 CCYCL2 CCYCL3 CSTRUC CHAL IFLOW FIDBEGIN FOFFSETBEGIN FIDEND FOFFSETEND
---------- ----- --------- ------ --------- --------- ----- ---------- ------- ------ ------------ ------- --------- --------- -------- ------- ----- --- ---- ------- ----- --- ----- ------- ----- -------- ------ ---- ------ --- --------- ----- ------- ---- ---- ---- --- ----- ----- ----- ---- ------ ------ ------- ------ ----- ------ ------ ------ ------ ------ --------- ----- -------- ------------ ------ ----------
891 23 15 4 1 0 2 18 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 17 0 0 0 0 0 1 1 1 0.0E0 0.0E0 0.0E0 5 95 5 117
1349 19 0 9 0 0 2 17 0 0 0 0 0 0 7 0 0 3 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 1 0 1 1 1 0.0E0 0.0E0 0.0E0 4 150 4 168
1779 29 0 13 0 0 2 27 0 0 0 0 0 0 11 0 0 5 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 0 0 1 0 1 1 1 0.0E0 0.0E0 0.0E0 4 194 4 222
2279 60 0 15 0 0 5 27 0 0 0 0 0 0 40 8 2 1 1 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 10 0 0 2 6 13 0 0 0 0 2 1 1 1 0.0E0 57.3594E0 0.0E0 4 238 4 297
5355 21 0 3 0 0 1 20 0 0 0 0 0 0 5 5 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 9 0 0 0 1 1 1 1 1 1.0E0 0.0E0 1.0E0 2 557 2 577
Table: FunctionId
FUNCTIONID ORDINAL EID
---------- ------- ----
891 0 891
1349 0 1349
1779 0 1779
2279 0 2279
4715 0 441
5355 0 5355
Table: Fcalls
SOURCEID DESTID
-------- ------
2279 1349
2279 1779
5355 5355
Done
Loading

0 comments on commit a295ffd

Please sign in to comment.