Skip to content

Commit 13d0c18

Browse files
committed
Support -target in goto-cc GCC/Clang mode
Accept and parse Clang's -target <arch-quadruple> (and --target=-<arch quadruple>) command-line option. Fixes: #6906
1 parent 16240af commit 13d0c18

File tree

6 files changed

+50
-14
lines changed

6 files changed

+50
-14
lines changed

regression/ansi-c/CMakeLists.txt

Lines changed: 19 additions & 9 deletions
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
3+
"$<TARGET_FILE:goto-cc>" -X gcc-only -X clang-x86-only
44
)
55
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
66
add_test_pl_tests(
@@ -22,18 +22,28 @@ else()
2222
find_program(CLANG_EXISTS "clang")
2323
find_program(GCC_EXISTS "gcc")
2424
if(CLANG_EXISTS)
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-
)
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()
3141
endif()
3242
if(GCC_EXISTS)
3343
add_test_pl_profile(
3444
"ansi-c-gcc"
3545
"$<TARGET_FILE:goto-cc> --native-compiler gcc"
36-
"-C;-X;fake-gcc-version;-s;ansi-c-gcc"
46+
"-C;-X;fake-gcc-version;-X;clang-x86-only;-s;ansi-c-gcc"
3747
"CORE"
3848
)
3949
add_test_pl_profile(
@@ -44,7 +54,7 @@ else()
4454
)
4555
elseif(NOT CLANG_EXISTS)
4656
add_test_pl_tests(
47-
"$<TARGET_FILE:goto-cc>"
57+
"$<TARGET_FILE:goto-cc>" -X clang-x86-only
4858
)
4959
endif()
5060

regression/ansi-c/Makefile

Lines changed: 10 additions & 5 deletions
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
13+
excluded_tests = -X gcc-only -X clang-x86-only
1414
else
1515
ifeq ($(BUILD_ENV_),OSX)
1616
# In MacOS, a change in the assert.h header file
@@ -20,17 +20,21 @@ 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
2326
endif
2427

2528
test:
2629
if which clang ; then \
2730
../test.pl -e -p -c "$(exe) --native-compiler clang" $(excluded_tests) ; \
2831
fi
2932
if which gcc ; then \
30-
../test.pl -e -p -c "$(exe) --native-compiler gcc" $(excluded_tests) -X fake-gcc-version && \
33+
../test.pl -e -p -c "$(exe) --native-compiler gcc" $(excluded_tests) \
34+
-X fake-gcc-version -X clang-x86-only && \
3135
../test.pl -e -p -c $(exe) $(excluded_tests) -I fake-gcc-version ; \
3236
elif ! which clang ; then \
33-
../test.pl -e -p -c $(exe) $(excluded_tests) ; \
37+
../test.pl -e -p -c $(exe) $(excluded_tests) -X clang-x86-only ; \
3438
fi
3539
ifneq ($(BUILD_ENV_),MSVC)
3640
@../test.pl -e -p -c "$(exe) -xc++ -D_Bool=bool" -I test-c++-front-end -s c++-front-end $(excluded_tests)
@@ -41,10 +45,11 @@ tests.log: ../test.pl
4145
../test.pl -e -p -c "$(exe) --native-compiler clang" $(excluded_tests) ; \
4246
fi
4347
if which gcc ; then \
44-
../test.pl -e -p -c "$(exe) --native-compiler gcc" $(excluded_tests) -X fake-gcc-version && \
48+
../test.pl -e -p -c "$(exe) --native-compiler gcc" $(excluded_tests) \
49+
-X fake-gcc-version -X clang-x86-only && \
4550
../test.pl -e -p -c $(exe) $(excluded_tests) -I fake-gcc-version ; \
4651
elif ! which clang ; then \
47-
../test.pl -e -p -c $(exe) $(excluded_tests) ; \
52+
../test.pl -e -p -c $(exe) $(excluded_tests) -X clang-x86-only ; \
4853
fi
4954
ifneq ($(BUILD_ENV_),MSVC)
5055
@../test.pl -e -p -c "$(exe) -xc++ -D_Bool=bool" -I test-c++-front-end -s c++-front-end $(excluded_tests)

regression/ansi-c/clang_target/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
int main()
2+
{
3+
int A[sizeof(void *) == 4 ? 1 : -1];
4+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE clang-x86-only
2+
main.c
3+
-target i386-unknown-linux-gnu
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
^CONVERSION ERROR$

src/goto-cc/gcc_cmdline.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ const char *gcc_options_with_separated_argument[]=
111111
"--include", // undocumented
112112
"-current_version", // on the Mac
113113
"-compatibility_version", // on the Mac
114+
"-target",
115+
"--target",
114116
"-z",
115117
nullptr
116118
};

src/goto-cc/gcc_mode.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,13 @@ int gcc_modet::doit()
509509
}
510510
}
511511

512+
// clang support -target <arch-quadruple> and --target=<arch-quadruple>
513+
if(cmdline.isset("target"))
514+
{
515+
std::string arch_quadruple = cmdline.get_value("target");
516+
config.set_arch(arch_quadruple.substr(0, arch_quadruple.find('-')));
517+
}
518+
512519
// -fshort-wchar makes wchar_t "short unsigned int"
513520
if(cmdline.isset("fshort-wchar"))
514521
{

0 commit comments

Comments
 (0)