Skip to content

Commit 30781b0

Browse files
authored
Merge pull request #171 from goblint/attr-assign
Add assignment and floating-point constant attributes
2 parents 8116086 + ac3a40a commit 30781b0

8 files changed

Lines changed: 41 additions & 3 deletions

File tree

src/cil.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ and attrparam =
344344
| AAddrOf of attrparam (** & a **)
345345
| AIndex of attrparam * attrparam (** a1[a2] *)
346346
| AQuestion of attrparam * attrparam * attrparam (** a1 ? a2 : a3 **)
347+
| AAssign of attrparam * attrparam (** a1 = a2 *)
347348

348349

349350
(** Information about a composite type (a struct or a union). Use
@@ -1874,6 +1875,7 @@ let additiveLevel = 60
18741875
let comparativeLevel = 70
18751876
let bitwiseLevel = 75
18761877
let questionLevel = 100
1878+
let assignLevel = 110
18771879
let getParenthLevel (e: exp) =
18781880
match e with
18791881
| Question _ -> questionLevel
@@ -1924,6 +1926,7 @@ let getParenthLevelAttrParam (a: attrparam) =
19241926
| AAddrOf _ -> 30
19251927
| ADot _ | AIndex _ | AStar _ -> 20
19261928
| AQuestion _ -> questionLevel
1929+
| AAssign _ -> assignLevel
19271930

19281931

19291932
let isIntegralType t =
@@ -4423,6 +4426,9 @@ class defaultCilPrinterClass : cilPrinter = object (self)
44234426
self#pAttrParam () a1 ++ text " ? " ++
44244427
self#pAttrParam () a2 ++ text " : " ++
44254428
self#pAttrParam () a3
4429+
| AAssign (a1, a2) ->
4430+
self#pAttrParam () a1 ++ text "=" ++
4431+
self#pAttrParam () a2
44264432

44274433

44284434
(* A general way of printing lists of attributes *)
@@ -5561,6 +5567,10 @@ and childrenAttrparam (vis: cilVisitor) (aa: attrparam) : attrparam =
55615567
let e3' = fAttrP e3 in
55625568
if e1' != e1 || e2' != e2 || e3' != e3
55635569
then AQuestion (e1', e2', e3') else aa
5570+
| AAssign (e1, e2) ->
5571+
let e1' = fAttrP e1 in
5572+
let e2' = fAttrP e2 in
5573+
if e1' != e1 || e2' != e2 then AAssign (e1', e2') else aa
55645574

55655575

55665576
let rec visitCilFunction (vis : cilVisitor) (f : fundec) : fundec =

src/cil.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ and attrparam =
338338
| AAddrOf of attrparam (** & a **)
339339
| AIndex of attrparam * attrparam (** a1[a2] *)
340340
| AQuestion of attrparam * attrparam * attrparam (** a1 ? a2 : a3 **)
341+
| AAssign of attrparam * attrparam (** a1 = a2 *)
341342

342343
(** {b Structures.} The {!compinfo} describes the definition of a
343344
structure or union type. Each such {!compinfo} must be defined at the

src/frontc/cabs2cil.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2927,6 +2927,7 @@ and doAttr (a: A.attribute) : attribute list =
29272927
| _ ->
29282928
E.s (error "Invalid attribute constant: %s")
29292929
end
2930+
| A.CONSTANT (A.CONST_FLOAT str) -> ACons (str, [])
29302931
| A.CALL(A.VARIABLE n, args) -> begin
29312932
let n' = if strip then stripUnderscore n else n in
29322933
let ae' = Util.list_map ae args in
@@ -2940,6 +2941,8 @@ and doAttr (a: A.attribute) : attribute list =
29402941
ABinOp(LAnd, ae aa1, ae aa2)
29412942
| A.BINARY(A.OR, aa1, aa2) ->
29422943
ABinOp(LOr, ae aa1, ae aa2)
2944+
| A.BINARY(A.ASSIGN, aa1, aa2) ->
2945+
AAssign(ae aa1, ae aa2)
29432946
| A.BINARY(abop, aa1, aa2) ->
29442947
ABinOp (convBinOp abop, ae aa1, ae aa2)
29452948
| A.UNARY(A.PLUS, aa) -> ae aa

src/frontc/cparser.mly

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1494,6 +1494,8 @@ primary_attr:
14941494
| LPAREN attr RPAREN { $2 }
14951495
| IDENT IDENT { CALL(VARIABLE (fst $1), [VARIABLE (fst $2)]) }
14961496
| CST_INT { CONSTANT(CONST_INT (fst $1)) }
1497+
| CST_FLOAT { CONSTANT(CONST_FLOAT (fst $1)) }
1498+
| CST_FLOAT CST_FLOAT { CONSTANT(CONST_FLOAT (fst $1 ^ fst $2)) } /* Clang-like hack to parse version numbers like "10.13.4" (https://github.com/goblint/cil/pull/171#issuecomment-2250670652). We lex them as "10.13" and ".4". */
14971499
| const_string_or_wstring { CONSTANT(fst $1) }
14981500
/*(* Const when it appears in
14991501
attribute lists, is translated
@@ -1619,8 +1621,12 @@ conditional_attr:
16191621
| logical_or_attr QUEST conditional_attr COLON conditional_attr
16201622
{ QUESTION($1, $3, $5) }
16211623

1624+
assignment_attr:
1625+
conditional_attr { $1 }
1626+
| unary_attr EQ assignment_attr { BINARY(ASSIGN, $1, $3) }
16221627

1623-
attr: conditional_attr { $1 }
1628+
1629+
attr: assignment_attr { $1 }
16241630
;
16251631

16261632
attr_list_ne:

test/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ ifdef SEPARATE
127127
CILLY+= --nomerge
128128
endif
129129

130+
# Disable GCC 14 new warnings as errors because some tests contain them
131+
CFLAGS += -Wno-error=implicit-int -Wno-error=implicit-function-declaration -Wno-error=int-conversion -Wno-error=incompatible-pointer-types
132+
130133
# sm: this will make gcc warnings into errors; it's almost never
131134
# what we want, but for a particular testcase (combine_copyptrs)
132135
# I need it to show the difference between something which works

test/small1/attr-assign.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// From some new MacOS headers: https://github.com/goblint/cil/issues/168
2+
3+
void foo(void) __attribute__((availability(macos,introduced=10.15)));
4+
5+
void foo(void) {
6+
return;
7+
}
8+
9+
// Version numbers may have multiple dots: https://github.com/goblint/cil/pull/171#issuecomment-2250670652
10+
void bar(void) __attribute__((availability(macos,introduced=10.13.4)));
11+
12+
void bar(void) {
13+
return;
14+
}

test/small2/kernel1.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
// This test is nonsense: DECLARE_WAIT_QUEUE_HEAD is a macro in Linux kernel
22
DECLARE_WAIT_QUEUE_HEAD(log_wait);
33

44

test/testcil.pl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ sub addToGroup {
222222
addTest("test/attr11 _GNUCC=1");
223223
addTest("test/attr12 _GNUCC=1");
224224
addTest("test/attr13 _GNUCC=1");
225+
# addTest("test/attr-assign"); # TODO: only on OSX, Linux GCC errors on introduced
225226
addTest("testrun/packed _GNUCC=1 WARNINGS_ARE_ERRORS=1");
226227
addTest("test/packed2 _GNUCC=1");
227228
addTest("test/bitfield");
@@ -657,7 +658,7 @@ sub addToGroup {
657658
addBadComment("scott/globalprob", "Notbug. Not a bug if fails on a non-Linux machine ;-)");
658659
addTest("scott/bisonerror $gcc");
659660
addTest("scott/cmpzero");
660-
addTest("scott/kernel1 $gcc");
661+
# addTest("scott/kernel1 $gcc");
661662
addTest("scott/kernel2 $gcc");
662663
addTest("scott/xcheckers $gcc");
663664
addTest("scott/memberofptr $gcc");

0 commit comments

Comments
 (0)