Skip to content

Commit 6ec39f1

Browse files
authored
Merge pull request #6913 from tautschnig/bugfixes/6912-clang-target-map
Goto-cc: Map target names with clang's -target
2 parents 37bbd11 + 62bf79f commit 6ec39f1

File tree

6 files changed

+76
-29
lines changed

6 files changed

+76
-29
lines changed

regression/ansi-c/CMakeLists.txt

+9-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
22
add_test_pl_tests(
3-
"$<TARGET_FILE:goto-cc>" -X gcc-only -X clang-x86-only
3+
"$<TARGET_FILE:goto-cc>" -X gcc-only -X clang-only
44
)
55
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
66
add_test_pl_tests(
@@ -22,28 +22,18 @@ else()
2222
find_program(CLANG_EXISTS "clang")
2323
find_program(GCC_EXISTS "gcc")
2424
if(CLANG_EXISTS)
25-
if("${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "x86_64" OR
26-
"${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "i386")
27-
add_test_pl_profile(
28-
"ansi-c-clang"
29-
"$<TARGET_FILE:goto-cc> --native-compiler clang"
30-
"-C;-s;ansi-c-clang"
31-
"CORE"
32-
)
33-
else()
34-
add_test_pl_profile(
35-
"ansi-c-clang"
36-
"$<TARGET_FILE:goto-cc> --native-compiler clang"
37-
"-C;-X;clang-x86-only;-s;ansi-c-clang"
38-
"CORE"
39-
)
40-
endif()
25+
add_test_pl_profile(
26+
"ansi-c-clang"
27+
"$<TARGET_FILE:goto-cc> --native-compiler clang"
28+
"-C;-s;ansi-c-clang"
29+
"CORE"
30+
)
4131
endif()
4232
if(GCC_EXISTS)
4333
add_test_pl_profile(
4434
"ansi-c-gcc"
4535
"$<TARGET_FILE:goto-cc> --native-compiler gcc"
46-
"-C;-X;fake-gcc-version;-X;clang-x86-only;-s;ansi-c-gcc"
36+
"-C;-X;fake-gcc-version;-X;clang-only;-s;ansi-c-gcc"
4737
"CORE"
4838
)
4939
add_test_pl_profile(
@@ -54,7 +44,7 @@ else()
5444
)
5545
elseif(NOT CLANG_EXISTS)
5646
add_test_pl_tests(
57-
"$<TARGET_FILE:goto-cc>" -X clang-x86-only
47+
"$<TARGET_FILE:goto-cc>" -X clang-only
5848
)
5949
endif()
6050

regression/ansi-c/Makefile

+5-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ else
1010
endif
1111

1212
ifeq ($(BUILD_ENV_),MSVC)
13-
excluded_tests = -X gcc-only -X clang-x86-only
13+
excluded_tests = -X gcc-only -X clang-only
1414
else
1515
ifeq ($(BUILD_ENV_),OSX)
1616
# In MacOS, a change in the assert.h header file
@@ -20,9 +20,6 @@ ifeq ($(BUILD_ENV_),OSX)
2020
# <assert.h> or <cassert> headers.
2121
excluded_tests = -X macos-assert-broken
2222
endif
23-
ifeq ($(filter x86_64 i386,$(shell uname -m)),)
24-
excluded_tests += -X clang-x86-only
25-
endif
2623
endif
2724

2825
test:
@@ -31,10 +28,10 @@ test:
3128
fi
3229
if which gcc ; then \
3330
../test.pl -e -p -c "$(exe) --native-compiler gcc" $(excluded_tests) \
34-
-X fake-gcc-version -X clang-x86-only && \
31+
-X fake-gcc-version -X clang-only && \
3532
../test.pl -e -p -c $(exe) $(excluded_tests) -I fake-gcc-version ; \
3633
elif ! which clang ; then \
37-
../test.pl -e -p -c $(exe) $(excluded_tests) -X clang-x86-only ; \
34+
../test.pl -e -p -c $(exe) $(excluded_tests) -X clang-only ; \
3835
fi
3936
ifneq ($(BUILD_ENV_),MSVC)
4037
@../test.pl -e -p -c "$(exe) -xc++ -D_Bool=bool" -I test-c++-front-end -s c++-front-end $(excluded_tests)
@@ -46,10 +43,10 @@ tests.log: ../test.pl
4643
fi
4744
if which gcc ; then \
4845
../test.pl -e -p -c "$(exe) --native-compiler gcc" $(excluded_tests) \
49-
-X fake-gcc-version -X clang-x86-only && \
46+
-X fake-gcc-version -X clang-only && \
5047
../test.pl -e -p -c $(exe) $(excluded_tests) -I fake-gcc-version ; \
5148
elif ! which clang ; then \
52-
../test.pl -e -p -c $(exe) $(excluded_tests) -X clang-x86-only ; \
49+
../test.pl -e -p -c $(exe) $(excluded_tests) -X clang-only ; \
5350
fi
5451
ifneq ($(BUILD_ENV_),MSVC)
5552
@../test.pl -e -p -c "$(exe) -xc++ -D_Bool=bool" -I test-c++-front-end -s c++-front-end $(excluded_tests)
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
_Static_assert(sizeof(void *) == 8, "error");
2+
3+
int main()
4+
{
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE clang-only
2+
aarch64.c
3+
-target aarch64-linux-gnu
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
^CONVERSION ERROR$

regression/ansi-c/clang_target/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE clang-x86-only
1+
CORE clang-only
22
main.c
33
-target i386-unknown-linux-gnu
44
^EXIT=0$

src/goto-cc/gcc_mode.cpp

+48-1
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,55 @@ int gcc_modet::doit()
512512
// clang supports -target <arch-quadruple> and --target=<arch-quadruple>
513513
if(cmdline.isset("target"))
514514
{
515+
// list of targets supported by LLVM 10.0, found using llc --version
516+
static const std::map<std::string, std::string> target_map = {
517+
{"aarch64", "arm64" /* AArch64 (little endian) */},
518+
{"aarch64_32", "arm" /* AArch64 (little endian ILP32) */},
519+
{"aarch64_be", "none" /* AArch64 (big endian) */},
520+
{"amdgcn", "none" /* AMD GCN GPUs */},
521+
{"arm", "arm" /* ARM */},
522+
{"arm64", "arm64" /* ARM64 (little endian) */},
523+
{"arm64_32", "arm" /* ARM64 (little endian ILP32) */},
524+
{"armeb", "none" /* ARM (big endian) */},
525+
{"avr", "none" /* Atmel AVR Microcontroller */},
526+
{"bpf", "none" /* BPF (host endian) */},
527+
{"bpfeb", "none" /* BPF (big endian) */},
528+
{"bpfel", "none" /* BPF (little endian) */},
529+
{"hexagon", "none" /* Hexagon */},
530+
{"i386", "i386" /* (not in llc's list: 32-bit x86) */},
531+
{"lanai", "none" /* Lanai */},
532+
{"mips", "mips" /* MIPS (32-bit big endian) */},
533+
{"mips64", "mips64" /* MIPS (64-bit big endian) */},
534+
{"mips64el", "mips64el" /* MIPS (64-bit little endian) */},
535+
{"mipsel", "mipsel" /* MIPS (32-bit little endian) */},
536+
{"msp430", "none" /* MSP430 [experimental] */},
537+
{"nvptx", "none" /* NVIDIA PTX 32-bit */},
538+
{"nvptx64", "none" /* NVIDIA PTX 64-bit */},
539+
{"ppc32", "powerpc" /* PowerPC 32 */},
540+
{"ppc64", "ppc64" /* PowerPC 64 */},
541+
{"ppc64le", "ppc64le" /* PowerPC 64 LE */},
542+
{"r600", "none" /* AMD GPUs HD2XXX-HD6XXX */},
543+
{"riscv32", "none" /* 32-bit RISC-V */},
544+
{"riscv64", "riscv64" /* 64-bit RISC-V */},
545+
{"sparc", "sparc" /* Sparc */},
546+
{"sparcel", "none" /* Sparc LE */},
547+
{"sparcv9", "sparc64" /* Sparc V9 */},
548+
{"systemz", "none" /* SystemZ */},
549+
{"thumb", "armhf" /* Thumb */},
550+
{"thumbeb", "none" /* Thumb (big endian) */},
551+
{"wasm32", "none" /* WebAssembly 32-bit */},
552+
{"wasm64", "none" /* WebAssembly 64-bit */},
553+
{"x86", "i386" /* 32-bit X86: Pentium-Pro and above */},
554+
{"x86_64", "x86_64" /* 64-bit X86: EM64T and AMD64 */},
555+
{"xcore", "none" /* XCore */},
556+
};
515557
std::string arch_quadruple = cmdline.get_value("target");
516-
config.set_arch(arch_quadruple.substr(0, arch_quadruple.find('-')));
558+
auto it =
559+
target_map.find(arch_quadruple.substr(0, arch_quadruple.find('-')));
560+
if(it == target_map.end())
561+
config.set_arch("none");
562+
else
563+
config.set_arch(it->second);
517564
}
518565

519566
// -fshort-wchar makes wchar_t "short unsigned int"

0 commit comments

Comments
 (0)