Skip to content

Commit 63f0ef8

Browse files
committed
Do not mark arbitrary constants as macros
1 parent 7aaaa82 commit 63f0ef8

5 files changed

+40
-11
lines changed

src/cpp/cpp_declarator_converter.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,6 @@ symbolt &cpp_declarator_convertert::convert_new_symbol(
444444
symbol.is_macro=is_typedef && !is_template_parameter;
445445
symbol.pretty_name=pretty_name;
446446

447-
// Constant? These are propagated.
448-
if(symbol.type.get_bool(ID_C_constant) &&
449-
symbol.value.is_not_nil())
450-
symbol.is_macro=true;
451447

452448
if(member_spec.is_inline())
453449
symbol.type.set(ID_C_inlined, true);

src/cpp/cpp_instantiate_template.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ std::string cpp_typecheckt::template_suffix(
5858
else // expression
5959
{
6060
exprt e=expr;
61+
62+
if(e.id() == ID_symbol)
63+
{
64+
const symbol_exprt &s = to_symbol_expr(e);
65+
const symbolt &symbol = lookup(s.get_identifier());
66+
67+
if(cpp_is_pod(symbol.type) && symbol.type.get_bool(ID_C_constant))
68+
e = symbol.value;
69+
}
70+
6171
make_constant(e);
6272

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

src/cpp/cpp_typecheck_compound_type.cpp

+11-7
Original file line numberDiff line numberDiff line change
@@ -713,13 +713,6 @@ void cpp_typecheckt::typecheck_compound_declarator(
713713
{
714714
new_symbol->value.swap(value);
715715
c_typecheck_baset::do_initializer(*new_symbol);
716-
717-
// these are macros if they are PODs and come with a (constant) value
718-
if(new_symbol->type.get_bool(ID_C_constant))
719-
{
720-
simplify(new_symbol->value, *this);
721-
new_symbol->is_macro=true;
722-
}
723716
}
724717
else
725718
{
@@ -752,7 +745,18 @@ void cpp_typecheckt::check_fixed_size_array(typet &type)
752745
array_typet &array_type=to_array_type(type);
753746

754747
if(array_type.size().is_not_nil())
748+
{
749+
if(array_type.size().id() == ID_symbol)
750+
{
751+
const symbol_exprt &s = to_symbol_expr(array_type.size());
752+
const symbolt &symbol = lookup(s.get_identifier());
753+
754+
if(cpp_is_pod(symbol.type) && symbol.type.get_bool(ID_C_constant))
755+
array_type.size() = symbol.value;
756+
}
757+
755758
make_constant_index(array_type.size());
759+
}
756760

757761
// recursive call for multi-dimensional arrays
758762
check_fixed_size_array(array_type.subtype());

src/cpp/cpp_typecheck_enum_type.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ void cpp_typecheckt::typecheck_enum_body(symbolt &enum_symbol)
6262
symbol.type=enum_tag_type;
6363
symbol.is_type=false;
6464
symbol.is_macro=true;
65+
symbol.is_file_local = true;
66+
symbol.is_thread_local = true;
6567

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

src/cpp/cpp_typecheck_resolve.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,23 @@ symbol_typet cpp_typecheck_resolvet::disambiguate_template_classes(
10941094
source_location,
10951095
primary_template_symbol,
10961096
full_template_args);
1097+
1098+
for(auto &arg : full_template_args_tc.arguments())
1099+
{
1100+
if(arg.id() == ID_symbol)
1101+
{
1102+
const symbol_exprt &s = to_symbol_expr(arg);
1103+
const symbolt &symbol = cpp_typecheck.lookup(s.get_identifier());
1104+
1105+
if(
1106+
cpp_typecheck.cpp_is_pod(symbol.type) &&
1107+
symbol.type.get_bool(ID_C_constant))
1108+
{
1109+
arg = symbol.value;
1110+
}
1111+
}
1112+
}
1113+
10971114
// go back to where we used to be
10981115
}
10991116

0 commit comments

Comments
 (0)