@@ -32,6 +32,11 @@ type inline_status =
3232 | Noinline (* The atom is declared with the noinline attribute *)
3333 | Inline (* The atom is declared inline *)
3434
35+ type literal_status =
36+ | No_literal
37+ | String_literal
38+ | Wide_string_literal
39+
3540type atom_info =
3641 { a_storage : C .storage ; (* storage class *)
3742 a_defined : bool ; (* defined in the current comp. unit? *)
@@ -41,6 +46,7 @@ type atom_info =
4146 (* 1 section for data, 3 sections (code/lit/jumptbl) for functions *)
4247 a_access : Sections .access_mode ; (* access mode, e.g. small data area *)
4348 a_inline : inline_status ; (* function declared inline? *)
49+ a_literal : literal_status ; (* is this a string literal? *)
4450 a_loc : location (* source location *)
4551}
4652
@@ -138,6 +144,12 @@ let atom_location a =
138144 with Not_found ->
139145 Cutil. no_loc
140146
147+ let atom_literal a =
148+ try
149+ (Hashtbl. find decl_atom a).a_literal
150+ with Not_found ->
151+ No_literal
152+
141153(* * The current environment of composite definitions *)
142154
143155let comp_env : composite_env ref = ref Maps.PTree. empty
@@ -594,6 +606,14 @@ let is_int64 env ty =
594606(* * String literals *)
595607
596608let stringNum = ref 0 (* number of next global for string literals *)
609+
610+ let rec gensym_string_literal () =
611+ incr stringNum;
612+ let name = Printf. sprintf " __stringlit_%d" ! stringNum in
613+ if Hashtbl. mem atom_of_string name
614+ then gensym_string_literal ()
615+ else name
616+
597617let stringTable : (string, AST.ident) Hashtbl.t = Hashtbl. create 47
598618let wstringTable : (int64 list * ikind, AST.ident) Hashtbl.t = Hashtbl. create 47
599619
@@ -603,8 +623,7 @@ let name_for_string_literal s =
603623 try
604624 Hashtbl. find stringTable s
605625 with Not_found ->
606- incr stringNum;
607- let name = Printf. sprintf " __stringlit_%d" ! stringNum in
626+ let name = gensym_string_literal () in
608627 let id = intern_string name in
609628 let mergeable = if is_C_string s then 1 else 0 in
610629 Hashtbl. add decl_atom id
@@ -615,6 +634,7 @@ let name_for_string_literal s =
615634 a_sections = [Sections. for_stringlit mergeable];
616635 a_access = Sections. Access_default ;
617636 a_inline = No_specifier ;
637+ a_literal = String_literal ;
618638 a_loc = Cutil. no_loc };
619639 Hashtbl. add stringTable s id;
620640 id
@@ -638,8 +658,7 @@ let name_for_wide_string_literal s ik =
638658 try
639659 Hashtbl. find wstringTable (s, ik)
640660 with Not_found ->
641- incr stringNum;
642- let name = Printf. sprintf " __stringlit_%d" ! stringNum in
661+ let name = gensym_string_literal () in
643662 let id = intern_string name in
644663 let wchar_size = Cutil. sizeof_ikind ik in
645664 let mergeable = if is_C_wide_string s then wchar_size else 0 in
@@ -652,6 +671,7 @@ let name_for_wide_string_literal s ik =
652671 a_sections = [Sections. for_stringlit mergeable];
653672 a_access = Sections. Access_default ;
654673 a_inline = No_specifier ;
674+ a_literal = Wide_string_literal ;
655675 a_loc = Cutil. no_loc };
656676 Hashtbl. add wstringTable (s, ik) id;
657677 id
@@ -1185,6 +1205,7 @@ let convertFundef loc env fd =
11851205 a_sections = Sections. for_function env loc id' fd.fd_attrib;
11861206 a_access = Sections. Access_default ;
11871207 a_inline = inline;
1208+ a_literal = No_literal ;
11881209 a_loc = loc };
11891210 (id', AST. Gfun (Ctypes. Internal
11901211 {fn_return = ret;
@@ -1276,6 +1297,7 @@ let convertGlobvar loc env (sto, id, ty, optinit) =
12761297 a_sections = [section];
12771298 a_access = access;
12781299 a_inline = No_specifier ;
1300+ a_literal = No_literal ;
12791301 a_loc = loc };
12801302 let volatile = List. mem C. AVolatile attr in
12811303 let readonly = List. mem C. AConst attr && not volatile in
0 commit comments