Skip to content

Commit 62c2909

Browse files
committed
Be precise as to whether __float128 is a keyword or a typedef
Add a new parser configuration setting to correctly configure the scanner.
1 parent 615af61 commit 62c2909

18 files changed

+63
-17
lines changed

src/ansi-c/ansi_c_internal_additions.cpp

-12
Original file line numberDiff line numberDiff line change
@@ -268,18 +268,6 @@ void ansi_c_internal_additions(std::string &code, bool support_float16_type)
268268
code+="typedef long double __float128;\n";
269269
}
270270
}
271-
else if(
272-
config.ansi_c.arch == "arm64" &&
273-
config.ansi_c.os == configt::ansi_ct::ost::OS_MACOS &&
274-
config.ansi_c.mode != configt::ansi_ct::flavourt::CLANG &&
275-
config.ansi_c.gcc__float128_type)
276-
{
277-
// https://gcc.gnu.org/onlinedocs/gcc/Floating-Types.html doesn't say so,
278-
// but GCC on macOS supports __float128 also for Apple Silicon. It really
279-
// appears to be a keyword, but we don't handle GCC version+platform
280-
// specifics in the scanner.
281-
code += "typedef " CPROVER_PREFIX "Float128 __float128;\n";
282-
}
283271

284272
if(
285273
config.ansi_c.arch == "i386" || config.ansi_c.arch == "x86_64" ||

src/ansi-c/ansi_c_language.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ bool ansi_c_languaget::parse(
7676
ansi_c_parser.in=&codestr;
7777
ansi_c_parser.for_has_scope=config.ansi_c.for_has_scope;
7878
ansi_c_parser.ts_18661_3_Floatn_types=config.ansi_c.ts_18661_3_Floatn_types;
79+
ansi_c_parser.__float128_is_keyword = config.ansi_c.__float128_is_keyword;
7980
ansi_c_parser.float16_type = config.ansi_c.float16_type;
8081
ansi_c_parser.bf16_type = config.ansi_c.bf16_type;
8182
ansi_c_parser.fp16_type = config.ansi_c.fp16_type;
@@ -201,6 +202,7 @@ bool ansi_c_languaget::to_expr(
201202
ansi_c_parser.in=&i_preprocessed;
202203
ansi_c_parser.for_has_scope = config.ansi_c.for_has_scope;
203204
ansi_c_parser.ts_18661_3_Floatn_types=config.ansi_c.ts_18661_3_Floatn_types;
205+
ansi_c_parser.__float128_is_keyword = config.ansi_c.__float128_is_keyword;
204206
ansi_c_parser.float16_type = config.ansi_c.float16_type;
205207
ansi_c_parser.bf16_type = config.ansi_c.bf16_type;
206208
ansi_c_parser.fp16_type = config.ansi_c.fp16_type;

src/ansi-c/ansi_c_parser.h

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class ansi_c_parsert:public parsert
3636
cpp11(false),
3737
for_has_scope(false),
3838
ts_18661_3_Floatn_types(false),
39+
__float128_is_keyword(false),
3940
float16_type(false),
4041
bf16_type(false),
4142
fp16_type(false)
@@ -68,6 +69,7 @@ class ansi_c_parsert:public parsert
6869

6970
// ISO/IEC TS 18661-3:2015
7071
bool ts_18661_3_Floatn_types;
72+
bool __float128_is_keyword;
7173
bool float16_type;
7274
bool bf16_type;
7375
bool fp16_type;

src/ansi-c/builtin_factory.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ static bool convert(
5252
ansi_c_parser.in=∈
5353
ansi_c_parser.for_has_scope=config.ansi_c.for_has_scope;
5454
ansi_c_parser.ts_18661_3_Floatn_types = config.ansi_c.ts_18661_3_Floatn_types;
55+
ansi_c_parser.__float128_is_keyword = config.ansi_c.__float128_is_keyword;
5556
ansi_c_parser.float16_type = config.ansi_c.float16_type;
5657
ansi_c_parser.bf16_type = config.ansi_c.bf16_type;
5758
ansi_c_parser.fp16_type = config.ansi_c.fp16_type;

src/ansi-c/gcc_version.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ void configure_gcc(const gcc_versiont &gcc_version)
162162
config.ansi_c.gcc__float128_type =
163163
gcc_version.flavor == gcc_versiont::flavort::GCC &&
164164
gcc_version.is_at_least(4u, gcc_float128_minor_version);
165+
config.ansi_c.__float128_is_keyword =
166+
gcc_version.flavor == gcc_versiont::flavort::CLANG ||
167+
(gcc_version.flavor == gcc_versiont::flavort::GCC &&
168+
config.ansi_c.arch == "arm64" &&
169+
config.ansi_c.os == configt::ansi_ct::ost::OS_MACOS &&
170+
config.ansi_c.gcc__float128_type);
165171

166172
config.ansi_c.float16_type =
167173
(gcc_version.flavor == gcc_versiont::flavort::GCC &&

src/ansi-c/scanner.l

+1-3
Original file line numberDiff line numberDiff line change
@@ -584,9 +584,7 @@ enable_or_disable ("enable"|"disable")
584584
loc(); return TOK_GCC_FLOAT80;
585585
}
586586

587-
"__float128" { // This is a keyword for CLANG,
588-
// but a typedef for GCC
589-
if(PARSER.mode==configt::ansi_ct::flavourt::CLANG)
587+
"__float128" { if(PARSER.__float128_is_keyword)
590588
{ loc(); return TOK_GCC_FLOAT128; }
591589
else
592590
return make_identifier();

src/cbmc/cbmc_parse_options.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,12 @@ int cbmc_parse_optionst::doit()
548548
gcc_version.get("gcc");
549549
configure_gcc(gcc_version);
550550
}
551+
else if(config.ansi_c.preprocessor == configt::ansi_ct::preprocessort::CLANG)
552+
{
553+
gcc_versiont gcc_version;
554+
gcc_version.get("clang");
555+
configure_gcc(gcc_version);
556+
}
551557

552558
if(cmdline.isset("test-preprocessor"))
553559
return test_c_preprocessor(ui_message_handler)

src/cpp/cpp_parser.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ bool cpp_parsert::parse()
4040
config.cpp.cpp_standard == configt::cppt::cpp_standardt::CPP17;
4141
token_buffer.ansi_c_parser.ts_18661_3_Floatn_types =
4242
false; // these are still typedefs
43+
token_buffer.ansi_c_parser.__float128_is_keyword = false;
4344
token_buffer.ansi_c_parser.float16_type = *support_float16;
4445
token_buffer.ansi_c_parser.bf16_type = *support_float16;
4546
token_buffer.ansi_c_parser.fp16_type = *support_float16;

src/cprover/cprover_parse_options.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ int cprover_parse_optionst::main()
131131
gcc_version.get("gcc");
132132
configure_gcc(gcc_version);
133133
}
134+
else if(
135+
config.ansi_c.preprocessor == configt::ansi_ct::preprocessort::CLANG)
136+
{
137+
gcc_versiont gcc_version;
138+
gcc_version.get("clang");
139+
configure_gcc(gcc_version);
140+
}
134141

135142
console_message_handlert message_handler;
136143
null_message_handlert null_message_handler;

src/goto-analyzer/goto_analyzer_parse_options.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,12 @@ int goto_analyzer_parse_optionst::doit()
421421
gcc_version.get("gcc");
422422
configure_gcc(gcc_version);
423423
}
424+
else if(config.ansi_c.preprocessor == configt::ansi_ct::preprocessort::CLANG)
425+
{
426+
gcc_versiont gcc_version;
427+
gcc_version.get("clang");
428+
configure_gcc(gcc_version);
429+
}
424430

425431
goto_model = initialize_goto_model(cmdline.args, ui_message_handler, options);
426432

src/goto-diff/goto_diff_parse_options.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ int goto_diff_parse_optionst::doit()
107107
gcc_version.get("gcc");
108108
configure_gcc(gcc_version);
109109
}
110+
else if(config.ansi_c.preprocessor == configt::ansi_ct::preprocessort::CLANG)
111+
{
112+
gcc_versiont gcc_version;
113+
gcc_version.get("clang");
114+
configure_gcc(gcc_version);
115+
}
110116

111117
if(process_goto_program(options, goto_model1))
112118
return CPROVER_EXIT_INTERNAL_ERROR;

src/goto-instrument/contracts/contracts_wrangler.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ void contracts_wranglert::mangle(
145145
ansi_c_parser.in = &is;
146146
ansi_c_parser.for_has_scope = config.ansi_c.for_has_scope;
147147
ansi_c_parser.ts_18661_3_Floatn_types = config.ansi_c.ts_18661_3_Floatn_types;
148+
ansi_c_parser.__float128_is_keyword = config.ansi_c.__float128_is_keyword;
148149
ansi_c_parser.float16_type = config.ansi_c.float16_type;
149150
ansi_c_parser.bf16_type = config.ansi_c.bf16_type;
150151
ansi_c_parser.fp16_type = config.ansi_c.fp16_type;

src/goto-instrument/goto_instrument_parse_options.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@ int goto_instrument_parse_optionst::doit()
139139
gcc_version.get("gcc");
140140
configure_gcc(gcc_version);
141141
}
142+
else if(
143+
config.ansi_c.preprocessor == configt::ansi_ct::preprocessort::CLANG)
144+
{
145+
gcc_versiont gcc_version;
146+
gcc_version.get("clang");
147+
configure_gcc(gcc_version);
148+
}
142149

143150
{
144151
const bool validate_only = cmdline.isset("validate-goto-binary");

src/goto-synthesizer/goto_synthesizer_parse_options.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ int goto_synthesizer_parse_optionst::doit()
7373
gcc_version.get("gcc");
7474
configure_gcc(gcc_version);
7575
}
76+
else if(config.ansi_c.preprocessor == configt::ansi_ct::preprocessort::CLANG)
77+
{
78+
gcc_versiont gcc_version;
79+
gcc_version.get("clang");
80+
configure_gcc(gcc_version);
81+
}
7682

7783
update_max_malloc_size(goto_model, ui_message_handler);
7884

src/libcprover-cpp/api.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ api_sessiont::api_sessiont(const api_optionst &options)
6969
gcc_version.get("gcc");
7070
configure_gcc(gcc_version);
7171
}
72+
else if(config.ansi_c.preprocessor == configt::ansi_ct::preprocessort::CLANG)
73+
{
74+
gcc_versiont gcc_version;
75+
gcc_version.get("clang");
76+
configure_gcc(gcc_version);
77+
}
7278
}
7379

7480
api_sessiont::~api_sessiont() = default;

src/util/config.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,7 @@ bool configt::set(const cmdlinet &cmdline)
835835
ansi_c.single_precision_constant=false;
836836
ansi_c.for_has_scope=true; // C99 or later
837837
ansi_c.ts_18661_3_Floatn_types=false;
838+
ansi_c.__float128_is_keyword = false;
838839
ansi_c.float16_type = false;
839840
ansi_c.bf16_type = false;
840841
ansi_c.fp16_type = false;
@@ -1329,8 +1330,8 @@ void configt::set_from_symbol_table(const symbol_table_baset &symbol_table)
13291330
ansi_c.char_is_unsigned=unsigned_from_ns(ns, "char_is_unsigned")!=0;
13301331
ansi_c.wchar_t_is_unsigned=unsigned_from_ns(ns, "wchar_t_is_unsigned")!=0;
13311332
// for_has_scope, single_precision_constant, rounding_mode,
1332-
// ts_18661_3_Floatn_types, float16_type, bf16_type, fp16_type are not
1333-
// architectural features, and thus not stored in namespace
1333+
// ts_18661_3_Floatn_types, __float128_is_keyword, float16_type, bf16_type,
1334+
// fp16_type are not architectural features, and thus not stored in namespace
13341335

13351336
ansi_c.alignment=unsigned_from_ns(ns, "alignment");
13361337

src/util/config.h

+1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ class configt
151151
bool for_has_scope;
152152
bool ts_18661_3_Floatn_types; // ISO/IEC TS 18661-3:2015
153153
bool gcc__float128_type; // __float128, a gcc extension since 4.3/4.5
154+
bool __float128_is_keyword; // __float128 as a keyword (and not typedef)
154155
bool float16_type; // _Float16 (Clang >= 15, GCC >= 12)
155156
bool bf16_type; // __bf16 (Clang >= 15, GCC >= 13)
156157
bool fp16_type; // __fp16 (GCC >= 4.5 on ARM, Clang >= 6)

unit/cpp_scanner.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ int main(int argc, const char *argv[])
4141
ansi_c_parser.cpp98=true;
4242
ansi_c_parser.cpp11=false;
4343
ansi_c_parser.ts_18661_3_Floatn_types = false;
44+
ansi_c_parser.__float128_is_keyword = false;
4445
ansi_c_parser.float16_type = false;
4546
ansi_c_parser.bf16_type = false;
4647
ansi_c_parser.fp16_type = false;

0 commit comments

Comments
 (0)