@@ -5966,17 +5966,18 @@ and doAliasFun vtype (thisname:string) (othername:string)
5966
5966
in
5967
5967
let body = { A. blabels = [] ; A. battrs = [] ; A. bstmts = [stmt] } in
5968
5968
let fdef = A. FUNDEF (sname, body, loc, loc) in
5969
- ignore (doDecl true fdef);
5969
+ ignore (doDecl true false fdef); (* doAliasFun only called for isglobal by guard *)
5970
5970
(* get the new function *)
5971
5971
let v,_ = try lookupGlobalVar thisname
5972
5972
with Not_found -> E. s (bug " error in doDecl" ) in
5973
5973
v.vattr < - dropAttribute " alias" v.vattr
5974
5974
5975
5975
5976
5976
(* Do one declaration *)
5977
- and doDecl (isglobal : bool ) : A.definition -> chunk = function
5977
+ and doDecl (isglobal : bool ) ( isstmt : bool ) : A.definition -> chunk = function
5978
5978
| A. DECDEF ((s , nl ), loc ) ->
5979
- currentLoc := convLoc loc;
5979
+ if isglobal || isstmt then
5980
+ currentLoc := convLoc loc;
5980
5981
currentExpLoc := convLoc loc; (* eloc for local initializer assignment instruction *)
5981
5982
(* Do the specifiers exactly once *)
5982
5983
let sugg =
@@ -6033,20 +6034,22 @@ and doDecl (isglobal: bool) : A.definition -> chunk = function
6033
6034
6034
6035
6035
6036
| A. TYPEDEF (ng , loc ) ->
6036
- currentLoc := convLoc(loc);
6037
- doTypedef ng; empty
6037
+ if isglobal || isstmt then
6038
+ currentLoc := convLoc(loc);
6039
+ doTypedef ng; empty
6038
6040
6039
6041
| A. ONLYTYPEDEF (s , loc ) ->
6040
- currentLoc := convLoc(loc);
6042
+ if isglobal || isstmt then
6043
+ currentLoc := convLoc(loc);
6041
6044
doOnlyTypedef s; empty
6042
6045
6043
6046
| A. GLOBASM (s ,loc ) when isglobal ->
6044
- currentLoc := convLoc(loc);
6047
+ currentLoc := convLoc(loc); (* isglobal by guard *)
6045
6048
cabsPushGlobal (GAsm (s, ! currentLoc));
6046
6049
empty
6047
6050
6048
6051
| A. PRAGMA (a , loc ) when isglobal -> begin
6049
- currentLoc := convLoc(loc);
6052
+ currentLoc := convLoc(loc); (* isglobal by guard *)
6050
6053
match doAttr (" dummy" , [a]) with
6051
6054
[Attr (" dummy" , [a'])] ->
6052
6055
let a'' =
@@ -6069,7 +6072,7 @@ and doDecl (isglobal: bool) : A.definition -> chunk = function
6069
6072
(body : A.block ), loc, _)
6070
6073
when isglobal && isExtern specs && isInline specs
6071
6074
&& (H. mem genv (n ^ " __extinline" )) ->
6072
- currentLoc := convLoc(loc);
6075
+ currentLoc := convLoc(loc); (* isglobal by guard *)
6073
6076
let othervi, _ = lookupVar (n ^ " __extinline" ) in
6074
6077
if othervi.vname = n then
6075
6078
(* The previous entry in the env is also an extern inline version
@@ -6084,15 +6087,15 @@ and doDecl (isglobal: bool) : A.definition -> chunk = function
6084
6087
^^ " reserved for CIL.\n " ) n n n)
6085
6088
end ;
6086
6089
(* Treat it as a prototype *)
6087
- doDecl isglobal (A. DECDEF ((specs, [((n,dt,a,loc'), A. NO_INIT )]), loc))
6090
+ doDecl isglobal isstmt (A. DECDEF ((specs, [((n,dt,a,loc'), A. NO_INIT )]), loc))
6088
6091
6089
6092
| A. FUNDEF (((specs,(n,dt,a, _)) : A. single_name),
6090
6093
(body : A.block ), loc1, loc2) when isglobal ->
6091
6094
begin
6092
6095
let funloc = convLoc (joinLoc loc1 loc2) in (* TODO: do in parser and include RBRACE end *)
6093
6096
let endloc = convLoc (joinLoc loc2 loc2) in (* TODO: what to do about range of inserted Return? *)
6094
6097
(* ignore (E.log "Definition of %s at %a\n" n d_loc funloc); *)
6095
- currentLoc := funloc;
6098
+ currentLoc := funloc; (* isglobal by guard *)
6096
6099
currentExpLoc := funloc; (* TODO: location just for declaration *)
6097
6100
E. withContext
6098
6101
(fun _ -> dprintf " 2cil: %s" n)
@@ -6531,15 +6534,16 @@ and doDecl (isglobal: bool) : A.definition -> chunk = function
6531
6534
end (* FUNDEF *)
6532
6535
6533
6536
| LINKAGE (n , loc , dl ) ->
6534
- currentLoc := convLoc loc;
6537
+ if isglobal || isstmt then
6538
+ currentLoc := convLoc loc;
6535
6539
if n <> " C" then
6536
6540
ignore (warn " Encountered linkage specification \" %s\" " n);
6537
6541
if not isglobal then
6538
6542
E. s (error " Encountered linkage specification in local scope" );
6539
6543
(* For now drop the linkage on the floor !!! *)
6540
6544
List. iter
6541
6545
(fun d ->
6542
- let s = doDecl isglobal d in
6546
+ let s = doDecl isglobal isstmt d in
6543
6547
if isNotEmpty s then
6544
6548
E. s (bug " doDecl returns non-empty statement for global" ))
6545
6549
dl;
@@ -6777,7 +6781,7 @@ and doStatement (s : A.statement) : chunk =
6777
6781
let (se1, _, _) =
6778
6782
match fc1 with
6779
6783
FC_EXP e1 -> doExp false e1 ADrop
6780
- | FC_DECL d1 -> (doDecl false d1, zero, voidType)
6784
+ | FC_DECL d1 -> (doDecl false false d1, zero, voidType)
6781
6785
in
6782
6786
(* First instruction (assignment) in for loop initializer has non-synthetic statement location before for loop.
6783
6787
Its expression location inside for loop parentheses is synthetic.
@@ -6949,7 +6953,7 @@ and doStatement (s : A.statement) : chunk =
6949
6953
end
6950
6954
6951
6955
| A. DEFINITION d ->
6952
- let s = doDecl false d in
6956
+ let s = doDecl false true d in
6953
6957
(*
6954
6958
ignore (E.log "Def at %a: %a\n" d_loc !currentLoc d_chunk s);
6955
6959
*)
@@ -7060,7 +7064,7 @@ let convFile (f : A.file) : Cil.file =
7060
7064
7061
7065
let globalidx = ref 0 in
7062
7066
let doOneGlobal (d : A.definition ) =
7063
- let s = doDecl true d in
7067
+ let s = doDecl true false d in
7064
7068
if isNotEmpty s then
7065
7069
E. s (bug " doDecl returns non-empty statement for global" );
7066
7070
(* See if this is one of the globals which we can leave alone. Increment
0 commit comments