@@ -19,6 +19,8 @@ Author: Daniel Kroening, kroening@kroening.com
1919#include < util/std_types.h>
2020#include < util/symbol_table_base.h>
2121
22+ #include < goto-programs/name_mangler.h>
23+
2224#include " ansi_c_declaration.h"
2325#include " c_storage_spec.h"
2426#include " expr2c.h"
@@ -760,7 +762,6 @@ void c_typecheck_baset::typecheck_declaration(
760762 declaration.set_is_register (full_spec.is_register );
761763 declaration.set_is_typedef (full_spec.is_typedef );
762764 declaration.set_is_weak (full_spec.is_weak );
763- declaration.set_is_used (full_spec.is_used );
764765
765766 symbolt symbol;
766767 declaration.to_symbol (declarator, symbol);
@@ -790,6 +791,20 @@ void c_typecheck_baset::typecheck_declaration(
790791 symbol.is_macro =true ;
791792 }
792793
794+ if (full_spec.is_used && symbol.is_file_local )
795+ {
796+ // GCC __attribute__((__used__)) - do not treat those as file-local, but
797+ // make sure the name is unique
798+ symbol.is_file_local = false ;
799+
800+ symbolt symbol_for_renaming = symbol;
801+ if (!full_spec.asm_label .empty ())
802+ symbol_for_renaming.name = full_spec.asm_label ;
803+ full_spec.asm_label = djb_manglert{}(
804+ symbol_for_renaming,
805+ id2string (symbol_for_renaming.location .get_file ()));
806+ }
807+
793808 if (full_spec.section .empty ())
794809 apply_asm_label (full_spec.asm_label , symbol);
795810 else
0 commit comments