Skip to content

Commit ae3a494

Browse files
committed
Don't override statement location for for initializer
1 parent f87d5c8 commit ae3a494

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/frontc/cabs2cil.ml

+20-16
Original file line numberDiff line numberDiff line change
@@ -5966,17 +5966,18 @@ and doAliasFun vtype (thisname:string) (othername:string)
59665966
in
59675967
let body = { A.blabels = []; A.battrs = []; A.bstmts = [stmt] } in
59685968
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 *)
59705970
(* get the new function *)
59715971
let v,_ = try lookupGlobalVar thisname
59725972
with Not_found -> E.s (bug "error in doDecl") in
59735973
v.vattr <- dropAttribute "alias" v.vattr
59745974

59755975

59765976
(* Do one declaration *)
5977-
and doDecl (isglobal: bool) : A.definition -> chunk = function
5977+
and doDecl (isglobal: bool) (isstmt: bool) : A.definition -> chunk = function
59785978
| A.DECDEF ((s, nl), loc) ->
5979-
currentLoc := convLoc loc;
5979+
if isglobal || isstmt then
5980+
currentLoc := convLoc loc;
59805981
currentExpLoc := convLoc loc; (* eloc for local initializer assignment instruction *)
59815982
(* Do the specifiers exactly once *)
59825983
let sugg =
@@ -6033,20 +6034,22 @@ and doDecl (isglobal: bool) : A.definition -> chunk = function
60336034

60346035

60356036
| 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
60386040

60396041
| A.ONLYTYPEDEF (s, loc) ->
6040-
currentLoc := convLoc(loc);
6042+
if isglobal || isstmt then
6043+
currentLoc := convLoc(loc);
60416044
doOnlyTypedef s; empty
60426045

60436046
| A.GLOBASM (s,loc) when isglobal ->
6044-
currentLoc := convLoc(loc);
6047+
currentLoc := convLoc(loc); (* isglobal by guard *)
60456048
cabsPushGlobal (GAsm (s, !currentLoc));
60466049
empty
60476050

60486051
| A.PRAGMA (a, loc) when isglobal -> begin
6049-
currentLoc := convLoc(loc);
6052+
currentLoc := convLoc(loc); (* isglobal by guard *)
60506053
match doAttr ("dummy", [a]) with
60516054
[Attr("dummy", [a'])] ->
60526055
let a'' =
@@ -6069,7 +6072,7 @@ and doDecl (isglobal: bool) : A.definition -> chunk = function
60696072
(body : A.block), loc, _)
60706073
when isglobal && isExtern specs && isInline specs
60716074
&& (H.mem genv (n ^ "__extinline")) ->
6072-
currentLoc := convLoc(loc);
6075+
currentLoc := convLoc(loc); (* isglobal by guard *)
60736076
let othervi, _ = lookupVar (n ^ "__extinline") in
60746077
if othervi.vname = n then
60756078
(* The previous entry in the env is also an extern inline version
@@ -6084,15 +6087,15 @@ and doDecl (isglobal: bool) : A.definition -> chunk = function
60846087
^^ " reserved for CIL.\n") n n n)
60856088
end;
60866089
(* 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))
60886091

60896092
| A.FUNDEF (((specs,(n,dt,a, _)) : A.single_name),
60906093
(body : A.block), loc1, loc2) when isglobal ->
60916094
begin
60926095
let funloc = convLoc (joinLoc loc1 loc2) in (* TODO: do in parser and include RBRACE end *)
60936096
let endloc = convLoc (joinLoc loc2 loc2) in (* TODO: what to do about range of inserted Return? *)
60946097
(* ignore (E.log "Definition of %s at %a\n" n d_loc funloc); *)
6095-
currentLoc := funloc;
6098+
currentLoc := funloc; (* isglobal by guard *)
60966099
currentExpLoc := funloc; (* TODO: location just for declaration *)
60976100
E.withContext
60986101
(fun _ -> dprintf "2cil: %s" n)
@@ -6531,15 +6534,16 @@ and doDecl (isglobal: bool) : A.definition -> chunk = function
65316534
end (* FUNDEF *)
65326535

65336536
| LINKAGE (n, loc, dl) ->
6534-
currentLoc := convLoc loc;
6537+
if isglobal || isstmt then
6538+
currentLoc := convLoc loc;
65356539
if n <> "C" then
65366540
ignore (warn "Encountered linkage specification \"%s\"" n);
65376541
if not isglobal then
65386542
E.s (error "Encountered linkage specification in local scope");
65396543
(* For now drop the linkage on the floor !!! *)
65406544
List.iter
65416545
(fun d ->
6542-
let s = doDecl isglobal d in
6546+
let s = doDecl isglobal isstmt d in
65436547
if isNotEmpty s then
65446548
E.s (bug "doDecl returns non-empty statement for global"))
65456549
dl;
@@ -6777,7 +6781,7 @@ and doStatement (s : A.statement) : chunk =
67776781
let (se1, _, _) =
67786782
match fc1 with
67796783
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)
67816785
in
67826786
(* First instruction (assignment) in for loop initializer has non-synthetic statement location before for loop.
67836787
Its expression location inside for loop parentheses is synthetic.
@@ -6949,7 +6953,7 @@ and doStatement (s : A.statement) : chunk =
69496953
end
69506954

69516955
| A.DEFINITION d ->
6952-
let s = doDecl false d in
6956+
let s = doDecl false true d in
69536957
(*
69546958
ignore (E.log "Def at %a: %a\n" d_loc !currentLoc d_chunk s);
69556959
*)
@@ -7060,7 +7064,7 @@ let convFile (f : A.file) : Cil.file =
70607064

70617065
let globalidx = ref 0 in
70627066
let doOneGlobal (d: A.definition) =
7063-
let s = doDecl true d in
7067+
let s = doDecl true false d in
70647068
if isNotEmpty s then
70657069
E.s (bug "doDecl returns non-empty statement for global");
70667070
(* See if this is one of the globals which we can leave alone. Increment

0 commit comments

Comments
 (0)