Skip to content

Commit 1e50c4c

Browse files
committed
C front-end: declare further GCC built-ins
These cover the set of functions reported as undefined while trying to compile aws-c-common.
1 parent 216e96c commit 1e50c4c

9 files changed

+322
-1
lines changed

src/ansi-c/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ make_inc(compiler_headers/gcc_builtin_headers_omp)
7272
make_inc(compiler_headers/gcc_builtin_headers_power)
7373
make_inc(compiler_headers/gcc_builtin_headers_tm)
7474
make_inc(compiler_headers/gcc_builtin_headers_types)
75+
make_inc(compiler_headers/gcc_builtin_headers_types_gcc7plus)
7576
make_inc(compiler_headers/gcc_builtin_headers_ubsan)
7677
make_inc(compiler_headers/windows_builtin_headers)
7778
make_inc(cprover_builtin_headers)
@@ -95,6 +96,7 @@ set(extra_dependencies
9596
${CMAKE_CURRENT_BINARY_DIR}/compiler_headers/gcc_builtin_headers_power.inc
9697
${CMAKE_CURRENT_BINARY_DIR}/compiler_headers/gcc_builtin_headers_tm.inc
9798
${CMAKE_CURRENT_BINARY_DIR}/compiler_headers/gcc_builtin_headers_types.inc
99+
${CMAKE_CURRENT_BINARY_DIR}/compiler_headers/gcc_builtin_headers_types_gcc7plus.inc
98100
${CMAKE_CURRENT_BINARY_DIR}/compiler_headers/gcc_builtin_headers_ubsan.inc
99101
${CMAKE_CURRENT_BINARY_DIR}/compiler_headers/windows_builtin_headers.inc
100102
${CMAKE_CURRENT_BINARY_DIR}/cprover_library.inc

src/ansi-c/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ BUILTIN_FILES = \
6868
compiler_headers/gcc_builtin_headers_power.inc \
6969
compiler_headers/gcc_builtin_headers_tm.inc \
7070
compiler_headers/gcc_builtin_headers_types.inc \
71+
compiler_headers/gcc_builtin_headers_types_gcc7plus.inc \
7172
compiler_headers/gcc_builtin_headers_ubsan.inc \
7273
compiler_headers/windows_builtin_headers.inc
7374

src/ansi-c/ansi_c_internal_additions.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,23 @@ Author: Daniel Kroening, [email protected]
1111
#include <util/c_types.h>
1212
#include <util/config.h>
1313

14+
#include <goto-programs/adjust_float_expressions.h>
15+
1416
#include <linking/static_lifetime_init.h>
1517

16-
#include <goto-programs/adjust_float_expressions.h>
18+
#include "ansi_c_parser.h"
1719

1820
const char gcc_builtin_headers_types[] =
1921
"#line 1 \"gcc_builtin_headers_types.h\"\n"
2022
#include "compiler_headers/gcc_builtin_headers_types.inc" // IWYU pragma: keep
2123
; // NOLINT(whitespace/semicolon)
2224

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+
2331
const char gcc_builtin_headers_generic[] =
2432
"#line 1 \"gcc_builtin_headers_generic.h\"\n"
2533
#include "compiler_headers/gcc_builtin_headers_generic.inc" // IWYU pragma: keep
@@ -229,6 +237,10 @@ void ansi_c_internal_additions(std::string &code)
229237
config.ansi_c.mode == configt::ansi_ct::flavourt::ARM)
230238
{
231239
code+=gcc_builtin_headers_types;
240+
// check the parser and not config.ansi_c.ts_18661_3_Floatn_types to adjust
241+
// behaviour depending on C or C++ context
242+
if(ansi_c_parser.ts_18661_3_Floatn_types)
243+
code += gcc_builtin_headers_types_gcc7plus;
232244

233245
// there are many more, e.g., look at
234246
// 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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ void ansi_c_architecture_strings(std::string &code);
1818
extern const char clang_builtin_headers[];
1919
extern const char cprover_builtin_headers[];
2020
extern const char gcc_builtin_headers_types[];
21+
extern const char gcc_builtin_headers_types_gcc7plus[];
2122
extern const char gcc_builtin_headers_generic[];
2223
extern const char gcc_builtin_headers_math[];
2324
extern const char gcc_builtin_headers_mem_string[];

src/ansi-c/compiler_headers/clang_builtin_headers.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,8 @@ unsigned int __builtin_rotateright32(unsigned int, unsigned int);
9393
unsigned long long __builtin_rotateright64(unsigned long long, unsigned long long);
9494

9595
void __builtin_assume(__CPROVER_bool);
96+
97+
void __builtin_cpu_init(void);
98+
_Bool __builtin_cpu_is(const char *);
99+
_Bool __builtin_cpu_supports(const char *);
96100
// clang-format on

src/ansi-c/compiler_headers/gcc_builtin_headers_ia32-5.h

Lines changed: 286 additions & 0 deletions
Large diffs are not rendered by default.

src/ansi-c/compiler_headers/gcc_builtin_headers_ia32.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@ __gcc_v2df __builtin_ia32_cvtsi642sd(__gcc_v2df, long long);
309309
__gcc_v4sf __builtin_ia32_cvtsd2ss(__gcc_v4sf, __gcc_v2df);
310310
__gcc_v2df __builtin_ia32_cvtss2sd(__gcc_v2df, __gcc_v4sf);
311311
void __builtin_ia32_clflush(const void*);
312+
void __builtin_ia32_cldemote(const void*);
313+
void __builtin_ia32_clflushopt(const void*);
314+
void __builtin_ia32_clwb(const void*);
315+
void __builtin_ia32_clzero(void*);
312316
void __builtin_ia32_lfence(void);
313317
void __builtin_ia32_mfence(void);
314318
__gcc_v16qi __builtin_ia32_loaddqu(const char*);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
typedef _Float16 __gcc_v8hf __attribute__((__vector_size__(16)));
2+
typedef _Float16 __gcc_v16hf __attribute__((__vector_size__(32)));
3+
typedef _Float16 __gcc_v32hf __attribute__((__vector_size__(64)));

src/libcprover-cpp/api.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <ansi-c/ansi_c_language.h>
2121
#include <ansi-c/cprover_library.h>
22+
#include <ansi-c/gcc_version.h>
2223
#include <assembler/remove_asm.h>
2324
#include <goto-checker/all_properties_verifier_with_trace_storage.h>
2425
#include <goto-checker/multi_path_symex_checker.h>
@@ -59,6 +60,13 @@ api_sessiont::api_sessiont(const api_optionst &options)
5960
config.set(cmdline);
6061
// Initialise C language mode
6162
register_language(new_ansi_c_language);
63+
// configure gcc, if required -- get_goto_program will have set the config
64+
if(config.ansi_c.preprocessor == configt::ansi_ct::preprocessort::GCC)
65+
{
66+
gcc_versiont gcc_version;
67+
gcc_version.get("gcc");
68+
configure_gcc(gcc_version);
69+
}
6270
}
6371

6472
api_sessiont::~api_sessiont() = default;

0 commit comments

Comments
 (0)