Skip to content

Commit 689c552

Browse files
authored
Merge pull request #8169 from tautschnig/bugfixes/float-extensions
C/C++ front-end: accept all floating-point extensions that GCC and Clang support
2 parents dbffea6 + bf1159f commit 689c552

21 files changed

+165
-70
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ src/ansi-c/compiler_headers/gcc_builtin_headers_omp.inc
5252
src/ansi-c/compiler_headers/gcc_builtin_headers_power.inc
5353
src/ansi-c/compiler_headers/gcc_builtin_headers_tm.inc
5454
src/ansi-c/compiler_headers/gcc_builtin_headers_types.inc
55-
src/ansi-c/compiler_headers/gcc_builtin_headers_types_gcc7plus.inc
5655
src/ansi-c/compiler_headers/gcc_builtin_headers_ubsan.inc
5756
src/ansi-c/compiler_headers/windows_builtin_headers.inc
5857
src/cpp/cprover_library.inc

regression/ansi-c/float_constant1/main.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,21 @@ STATIC_ASSERT(__builtin_types_compatible_p(_Float64, __typeof(1.0f64)));
2121
STATIC_ASSERT(__builtin_types_compatible_p(_Float128, __typeof(1.0f128)));
2222
STATIC_ASSERT(__builtin_types_compatible_p(_Float32x, __typeof(1.0f32x)));
2323
STATIC_ASSERT(__builtin_types_compatible_p(_Float64x, __typeof(1.0f64x)));
24+
// f128x should be supported by GCC >= 7 (and for C++ in GCC >=13), but there
25+
// are no current GCC target architectures that actually support such types
2426
STATIC_ASSERT(__builtin_types_compatible_p(_Float128x, __typeof(1.0f128x)));
2527
#endif
2628

29+
#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 13
30+
STATIC_ASSERT(__builtin_types_compatible_p(_Float16, __typeof(1.0f16)));
31+
STATIC_ASSERT(__builtin_types_compatible_p(__bf16, __typeof(1.0bf16)));
32+
STATIC_ASSERT(__builtin_types_compatible_p(__bf16, __typeof(1.BF16)));
33+
#endif
34+
35+
#if defined(__clang__) && __clang_major__ >= 15
36+
STATIC_ASSERT(__builtin_types_compatible_p(_Float16, __typeof(1.0f16)));
37+
#endif
38+
2739
#ifdef __GNUC__
2840
_Complex c;
2941
#endif

src/ansi-c/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ make_inc(compiler_headers/gcc_builtin_headers_omp)
7979
make_inc(compiler_headers/gcc_builtin_headers_power)
8080
make_inc(compiler_headers/gcc_builtin_headers_tm)
8181
make_inc(compiler_headers/gcc_builtin_headers_types)
82-
make_inc(compiler_headers/gcc_builtin_headers_types_gcc7plus)
8382
make_inc(compiler_headers/gcc_builtin_headers_ubsan)
8483
make_inc(compiler_headers/windows_builtin_headers)
8584
make_inc(cprover_builtin_headers)
@@ -104,7 +103,6 @@ set(extra_dependencies
104103
${CMAKE_CURRENT_BINARY_DIR}/compiler_headers/gcc_builtin_headers_power.inc
105104
${CMAKE_CURRENT_BINARY_DIR}/compiler_headers/gcc_builtin_headers_tm.inc
106105
${CMAKE_CURRENT_BINARY_DIR}/compiler_headers/gcc_builtin_headers_types.inc
107-
${CMAKE_CURRENT_BINARY_DIR}/compiler_headers/gcc_builtin_headers_types_gcc7plus.inc
108106
${CMAKE_CURRENT_BINARY_DIR}/compiler_headers/gcc_builtin_headers_ubsan.inc
109107
${CMAKE_CURRENT_BINARY_DIR}/compiler_headers/windows_builtin_headers.inc
110108
${CMAKE_CURRENT_BINARY_DIR}/cprover_library.inc

src/ansi-c/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ BUILTIN_FILES = \
7070
compiler_headers/gcc_builtin_headers_power.inc \
7171
compiler_headers/gcc_builtin_headers_tm.inc \
7272
compiler_headers/gcc_builtin_headers_types.inc \
73-
compiler_headers/gcc_builtin_headers_types_gcc7plus.inc \
7473
compiler_headers/gcc_builtin_headers_ubsan.inc \
7574
compiler_headers/windows_builtin_headers.inc
7675

src/ansi-c/ansi_c_internal_additions.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ const char gcc_builtin_headers_types[] =
2222
#include "compiler_headers/gcc_builtin_headers_types.inc" // IWYU pragma: keep
2323
; // NOLINT(whitespace/semicolon)
2424

25-
const char gcc_builtin_headers_types_gcc7plus[] =
26-
"#line 1 \"gcc_builtin_headers_types_gcc7plus.h\"\n"
27-
// NOLINTNEXTLINE(whitespace/line_length)
28-
#include "compiler_headers/gcc_builtin_headers_types_gcc7plus.inc" // IWYU pragma: keep
29-
; // NOLINT(whitespace/semicolon)
30-
3125
const char gcc_builtin_headers_generic[] =
3226
"#line 1 \"gcc_builtin_headers_generic.h\"\n"
3327
#include "compiler_headers/gcc_builtin_headers_generic.inc" // IWYU pragma: keep
@@ -158,9 +152,7 @@ max_malloc_size(std::size_t pointer_width, std::size_t object_bits)
158152
return ((mp_integer)1) << (mp_integer)bits_for_positive_offset;
159153
}
160154

161-
void ansi_c_internal_additions(
162-
std::string &code,
163-
bool support_ts_18661_3_Floatn_types)
155+
void ansi_c_internal_additions(std::string &code, bool support_float16_type)
164156
{
165157
// clang-format off
166158
// do the built-in types and variables
@@ -249,8 +241,15 @@ void ansi_c_internal_additions(
249241
config.ansi_c.mode == configt::ansi_ct::flavourt::ARM)
250242
{
251243
code+=gcc_builtin_headers_types;
252-
if(support_ts_18661_3_Floatn_types)
253-
code += gcc_builtin_headers_types_gcc7plus;
244+
if(support_float16_type)
245+
{
246+
code +=
247+
"typedef _Float16 __gcc_v8hf __attribute__((__vector_size__(16)));\n";
248+
code +=
249+
"typedef _Float16 __gcc_v16hf __attribute__((__vector_size__(32)));\n";
250+
code +=
251+
"typedef _Float16 __gcc_v32hf __attribute__((__vector_size__(64)));\n";
252+
}
254253

255254
// there are many more, e.g., look at
256255
// https://developer.apple.com/library/mac/#documentation/developertools/gcc-4.0.1/gcc/Target-Builtins.html

src/ansi-c/ansi_c_internal_additions.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@ Author: Daniel Kroening, [email protected]
1212

1313
#include <string>
1414

15-
void ansi_c_internal_additions(
16-
std::string &code,
17-
bool support_ts_18661_3_Floatn_types);
15+
void ansi_c_internal_additions(std::string &code, bool support_float16_type);
1816
void ansi_c_architecture_strings(std::string &code);
1917

2018
extern const char clang_builtin_headers[];
2119
extern const char cprover_builtin_headers[];
2220
extern const char gcc_builtin_headers_types[];
23-
extern const char gcc_builtin_headers_types_gcc7plus[];
2421
extern const char gcc_builtin_headers_generic[];
2522
extern const char gcc_builtin_headers_math[];
2623
extern const char gcc_builtin_headers_mem_string[];

src/ansi-c/ansi_c_language.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ bool ansi_c_languaget::parse(
6868
// parsing
6969

7070
std::string code;
71-
ansi_c_internal_additions(code, config.ansi_c.ts_18661_3_Floatn_types);
71+
ansi_c_internal_additions(code, config.ansi_c.float16_type);
7272
std::istringstream codestr(code);
7373

7474
ansi_c_parser.clear();
@@ -77,6 +77,8 @@ bool ansi_c_languaget::parse(
7777
ansi_c_parser.log.set_message_handler(message_handler);
7878
ansi_c_parser.for_has_scope=config.ansi_c.for_has_scope;
7979
ansi_c_parser.ts_18661_3_Floatn_types=config.ansi_c.ts_18661_3_Floatn_types;
80+
ansi_c_parser.float16_type = config.ansi_c.float16_type;
81+
ansi_c_parser.bf16_type = config.ansi_c.bf16_type;
8082
ansi_c_parser.cpp98=false; // it's not C++
8183
ansi_c_parser.cpp11=false; // it's not C++
8284
ansi_c_parser.mode=config.ansi_c.mode;
@@ -203,6 +205,8 @@ bool ansi_c_languaget::to_expr(
203205
ansi_c_parser.log.set_message_handler(message_handler);
204206
ansi_c_parser.mode=config.ansi_c.mode;
205207
ansi_c_parser.ts_18661_3_Floatn_types=config.ansi_c.ts_18661_3_Floatn_types;
208+
ansi_c_parser.float16_type = config.ansi_c.float16_type;
209+
ansi_c_parser.bf16_type = config.ansi_c.bf16_type;
206210
ansi_c_scanner_init();
207211

208212
bool result=ansi_c_parser.parse();

src/ansi-c/ansi_c_parser.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ class ansi_c_parsert:public parsert
3333
cpp98(false),
3434
cpp11(false),
3535
for_has_scope(false),
36-
ts_18661_3_Floatn_types(false)
36+
ts_18661_3_Floatn_types(false),
37+
float16_type(false),
38+
bf16_type(false)
3739
{
3840
}
3941

@@ -78,6 +80,8 @@ class ansi_c_parsert:public parsert
7880

7981
// ISO/IEC TS 18661-3:2015
8082
bool ts_18661_3_Floatn_types;
83+
bool float16_type;
84+
bool bf16_type;
8185

8286
typedef ansi_c_identifiert identifiert;
8387
typedef ansi_c_scopet scopet;

src/ansi-c/builtin_factory.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static bool convert(
9797
//! \return 'true' on error
9898
bool builtin_factory(
9999
const irep_idt &identifier,
100-
bool support_ts_18661_3_Floatn_types,
100+
bool support_float16_type,
101101
symbol_table_baset &symbol_table,
102102
message_handlert &mh)
103103
{
@@ -107,7 +107,7 @@ bool builtin_factory(
107107
std::ostringstream s;
108108

109109
std::string code;
110-
ansi_c_internal_additions(code, support_ts_18661_3_Floatn_types);
110+
ansi_c_internal_additions(code, support_float16_type);
111111
s << code;
112112

113113
// our own extensions

src/ansi-c/builtin_factory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class symbol_table_baset;
1717
//! \return 'true' in case of error
1818
bool builtin_factory(
1919
const irep_idt &identifier,
20-
bool support_ts_18661_3_Floatn_types,
20+
bool support_float16_type,
2121
symbol_table_baset &,
2222
message_handlert &);
2323

0 commit comments

Comments
 (0)