Skip to content

Commit 47b605f

Browse files
committed
Do not mark arbitrary constants as macros
1 parent 7d8d387 commit 47b605f

5 files changed

+40
-11
lines changed

src/cpp/cpp_declarator_converter.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,6 @@ symbolt &cpp_declarator_convertert::convert_new_symbol(
462462
symbol.is_macro=is_typedef && !is_template_parameter;
463463
symbol.pretty_name=pretty_name;
464464

465-
// Constant? These are propagated.
466-
if(symbol.type.get_bool(ID_C_constant) &&
467-
symbol.value.is_not_nil())
468-
symbol.is_macro=true;
469465

470466
if(is_code && !symbol.is_type)
471467
{

src/cpp/cpp_instantiate_template.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ std::string cpp_typecheckt::template_suffix(
5454
else // expression
5555
{
5656
exprt e=expr;
57+
58+
if(e.id() == ID_symbol)
59+
{
60+
const symbol_exprt &s = to_symbol_expr(e);
61+
const symbolt &symbol = lookup(s.get_identifier());
62+
63+
if(cpp_is_pod(symbol.type) && symbol.type.get_bool(ID_C_constant))
64+
e = symbol.value;
65+
}
66+
5767
make_constant(e);
5868

5969
// this must be a constant, which includes true/false

src/cpp/cpp_typecheck_compound_type.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -734,13 +734,6 @@ void cpp_typecheckt::typecheck_compound_declarator(
734734
{
735735
new_symbol->value.swap(value);
736736
c_typecheck_baset::do_initializer(*new_symbol);
737-
738-
// these are macros if they are PODs and come with a (constant) value
739-
if(new_symbol->type.get_bool(ID_C_constant))
740-
{
741-
simplify(new_symbol->value, *this);
742-
new_symbol->is_macro=true;
743-
}
744737
}
745738
else
746739
{
@@ -772,7 +765,18 @@ void cpp_typecheckt::check_fixed_size_array(typet &type)
772765
array_typet &array_type=to_array_type(type);
773766

774767
if(array_type.size().is_not_nil())
768+
{
769+
if(array_type.size().id() == ID_symbol)
770+
{
771+
const symbol_exprt &s = to_symbol_expr(array_type.size());
772+
const symbolt &symbol = lookup(s.get_identifier());
773+
774+
if(cpp_is_pod(symbol.type) && symbol.type.get_bool(ID_C_constant))
775+
array_type.size() = symbol.value;
776+
}
777+
775778
make_constant_index(array_type.size());
779+
}
776780

777781
// recursive call for multi-dimensional arrays
778782
check_fixed_size_array(array_type.subtype());

src/cpp/cpp_typecheck_enum_type.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ void cpp_typecheckt::typecheck_enum_body(symbolt &enum_symbol)
6363
symbol.type=enum_tag_type;
6464
symbol.is_type=false;
6565
symbol.is_macro=true;
66+
symbol.is_file_local = true;
67+
symbol.is_thread_local = true;
6668

6769
symbolt *new_symbol;
6870
if(symbol_table.move(symbol, new_symbol))

src/cpp/cpp_typecheck_resolve.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,23 @@ struct_tag_typet cpp_typecheck_resolvet::disambiguate_template_classes(
10461046
source_location,
10471047
primary_template_symbol,
10481048
full_template_args);
1049+
1050+
for(auto &arg : full_template_args_tc.arguments())
1051+
{
1052+
if(arg.id() == ID_symbol)
1053+
{
1054+
const symbol_exprt &s = to_symbol_expr(arg);
1055+
const symbolt &symbol = cpp_typecheck.lookup(s.get_identifier());
1056+
1057+
if(
1058+
cpp_typecheck.cpp_is_pod(symbol.type) &&
1059+
symbol.type.get_bool(ID_C_constant))
1060+
{
1061+
arg = symbol.value;
1062+
}
1063+
}
1064+
}
1065+
10491066
// go back to where we used to be
10501067
}
10511068

0 commit comments

Comments
 (0)