Skip to content

Commit 6674fd1

Browse files
committed
Add separate pconst attribute for tracking whether to print const
Normal const attribute will be preseved (not stripped from locals), such that type compatibility (e.g. for generic) is still correct. Must print some consts because otherwise the whole testing framework fails since it assumes CIL will keep some consts for GCC.
1 parent 3dfa002 commit 6674fd1

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

src/check.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ let typeSigIgnoreConst (t : typ) : typsig =
208208
let attrFilter (attr : attribute) : bool =
209209
match attr with
210210
| Attr ("const", []) -> false
211+
| Attr ("pconst", []) -> false
211212
| _ -> true
212213
in
213214
typeSigWithAttrs (List.filter attrFilter) t

src/cil.ml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,7 @@ let charType = TInt(IChar, [])
12751275
let boolType = TInt(IBool, [])
12761276

12771277
let charPtrType = TPtr(charType,[])
1278-
let charConstPtrType = TPtr(TInt(IChar, [Attr("const", [])]),[])
1278+
let charConstPtrType = TPtr(TInt(IChar, [Attr("const", []); Attr("pconst", [])]),[])
12791279
let stringLiteralType = charPtrType
12801280

12811281
let voidPtrType = TPtr(voidType, [])
@@ -2989,7 +2989,7 @@ let initGccBuiltins () : unit =
29892989
let ulongLongType = TInt(IULongLong, []) in
29902990
let floatType = TFloat(FFloat, []) in
29912991
let longDoubleType = TFloat (FLongDouble, []) in
2992-
let voidConstPtrType = TPtr(TVoid [Attr ("const", [])], []) in
2992+
let voidConstPtrType = TPtr(TVoid [Attr ("const", []); Attr ("pconst", [])], []) in
29932993
let sizeType = !typeOfSizeOf in
29942994
let v4sfType = TFloat (FFloat,[Attr("__vector_size__", [AInt 16])]) in
29952995

@@ -4428,7 +4428,7 @@ class defaultCilPrinterClass : cilPrinter = object (self)
44284428

44294429
| TArray (elemt, lo, a) ->
44304430
(* ignore the const attribute for arrays *)
4431-
let a' = dropAttributes [ "const" ] a in
4431+
let a' = dropAttributes [ "pconst" ] a in
44324432
let name' =
44334433
if a' == [] then name else
44344434
if nameOpt == None then printAttributes a' else
@@ -4496,7 +4496,8 @@ class defaultCilPrinterClass : cilPrinter = object (self)
44964496
method pAttr (Attr(an, args): attribute) : doc * bool =
44974497
(* Recognize and take care of some known cases *)
44984498
match an, args with
4499-
"const", [] -> text "const", false
4499+
"const", [] -> nil, false (* don't print const directly, because of split local declarations *)
4500+
| "pconst", [] -> text "const", false (* pconst means print const *)
45004501
(* Put the aconst inside the attribute list *)
45014502
| "complex", [] when !c99Mode -> text "_Complex", false
45024503
| "complex", [] when not !msvcMode -> text "__complex__", false
@@ -5068,7 +5069,7 @@ let makeVarinfo global name ?init typ =
50685069
{ vname = name;
50695070
vid = newVID ();
50705071
vglob = global;
5071-
vtype = if global then typ else typeRemoveAttributes ["const"] typ;
5072+
vtype = if global then typ else typeRemoveAttributes ["pconst"] typ;
50725073
vdecl = lu;
50735074
vinit = {init=init};
50745075
vinline = false;

src/frontc/cabs2cil.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,8 @@ let alphaConvertVarAndAddToEnv (addtoenv: bool) (vi: varinfo) : varinfo =
616616
* elements. *)
617617
let rec stripConstLocalType (t: typ) : typ =
618618
let dc a =
619-
if hasAttribute "const" a then
620-
dropAttribute "const" a
619+
if hasAttribute "pconst" a then
620+
dropAttribute "pconst" a
621621
else a
622622
in
623623
match t with
@@ -2670,7 +2670,7 @@ let rec doSpecList (suggestedAnonName: string) (* This string will be part of
26702670
and convertCVtoAttr (src: A.cvspec list) : A.attribute list =
26712671
match src with
26722672
| [] -> []
2673-
| CV_CONST :: tl -> ("const",[]) :: (convertCVtoAttr tl)
2673+
| CV_CONST :: tl -> ("const",[]) :: ("pconst",[]) :: (convertCVtoAttr tl)
26742674
| CV_VOLATILE :: tl -> ("volatile",[]) :: (convertCVtoAttr tl)
26752675
| CV_RESTRICT :: tl -> ("restrict",[]) :: (convertCVtoAttr tl)
26762676
| CV_COMPLEX :: tl -> ("complex",[]) :: (convertCVtoAttr tl)

src/mergecil.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,8 +820,10 @@ let oneFilePass1 (f:file) : unit =
820820
* can happen if one file declares the variable a non-const while
821821
* others declare it as "const". *)
822822
if hasAttribute "const" (typeAttrs vi.vtype) !=
823-
hasAttribute "const" (typeAttrs oldvi.vtype) then begin
824-
newrep.ndata.vtype <- typeRemoveAttributes ["const"] newtype;
823+
hasAttribute "const" (typeAttrs oldvi.vtype) ||
824+
hasAttribute "pconst" (typeAttrs vi.vtype) !=
825+
hasAttribute "pconst" (typeAttrs oldvi.vtype) then begin
826+
newrep.ndata.vtype <- typeRemoveAttributes ["const"; "pconst"] newtype;
825827
end else begin
826828
newrep.ndata.vtype <- newtype;
827829
end;

0 commit comments

Comments
 (0)