Skip to content

Commit

Permalink
Support __alignof__ as unary operator
Browse files Browse the repository at this point in the history
  • Loading branch information
dspinellis committed Jul 20, 2024
1 parent 1ca2097 commit 8107768
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ unary_expression:
{ $$ = basic(b_int); }
| SIZEOF '(' type_name ')'
{ $$ = basic(b_int); }
| ALIGNOF '(' unary_expression ')'
| ALIGNOF unary_expression
{ $$ = basic(b_int); }
| ALIGNOF '(' type_name ')'
{ $$ = basic(b_int); }
Expand Down
15 changes: 15 additions & 0 deletions src/test/c/c49-sizeof.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
void
f(void)
{
int a;
int b;

b = sizeof a;
b = __alignof__ a;

b = sizeof(a);
b = __alignof__(a);

b = sizeof(int);
b = __alignof__(int);
}
178 changes: 178 additions & 0 deletions src/test/out/c49-sizeof.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
Table: Ids
EID NAME READONLY UNDEFMACRO MACRO MACROARG ORDINARY SUETAG SUMEMBER LABEL TYPEDEF ENUM YACC FUN CSCOPE LSCOPE UNUSED
59 f 0 0 0 0 1 0 0 0 0 0 0 1 0 1 1
91 MAXDIGIT 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1
209 a 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
289 b 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
331 x 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1
441 main 1 0 0 0 1 0 0 0 0 0 0 1 0 1 0
571 qqq 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1
891 foo 0 0 0 0 1 0 0 0 0 0 0 1 0 1 1
2975 __DATE__ 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1
3295 __TIME__ 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1
3575 __FILE__ 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1
3865 __LINE__ 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1
4055 __STDC__ 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1
5355 _cscout_dummy1 1 0 0 0 1 0 0 0 0 0 0 1 1 0 0
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 5 59
4 20 209
4 28 289
4 33 289
4 44 209
4 48 289
4 64 209
4 69 289
4 80 209
4 85 289
4 101 209
4 107 289
4 125 289
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 0 void\u0000a
4 6 (void)\u0000a{\u0000a int
4 21 ;\u0000a int
4 29 ;\u0000a\u0000a
4 34 = sizeof
4 45 ;\u0000a
4 49 = __alignof__
4 65 ;\u0000a\u0000a
4 70 = sizeof(
4 81 );\u0000a
4 86 = __alignof__(
4 102 );\u0000a\u0000a
4 108 = sizeof(int);\u0000a
4 126 = __alignof__(int);\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
59 17
209 17
289 17
441 17
2975 17
3295 17
3575 17
3865 17
4055 17
5355 17
59 18
91 18
209 18
289 18
331 18
441 18
571 18
891 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 1 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 1 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 c49-sizeof.c 0 149 0 39 0 0 15 22 0 0 0 0 0 0 51 52 1 6 1 0 0 0 0 0 0 0 0
5 prj2.c 0 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
59 f 0 1 1 0 4 5 0
891 foo 0 1 1 0 5 88 0
4715 main 0 0 1 0 2 471 0
5355 _cscout_dummy1 0 1 1 1 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
59 135 0 37 0 0 13 22 0 0 0 0 0 0 45 45 8 6 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12 0 0 0 2 11 0 0 0 0 0 1 1 1 0.0 28.5293 0.0 4 14 4 148
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.0 0.0 0.0 5 95 5 117
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.0 0.0 1.0 2 557 2 577
Table: FunctionId
FUNCTIONID ORDINAL EID
59 0 59
891 0 891
4715 0 441
5355 0 5355
Table: Fcalls
SOURCEID DESTID
5355 5355
Done

0 comments on commit 8107768

Please sign in to comment.