Skip to content

Support -target in goto-cc GCC/Clang mode #6908

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions regression/ansi-c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
add_test_pl_tests(
"$<TARGET_FILE:goto-cc>" -X gcc-only
"$<TARGET_FILE:goto-cc>" -X gcc-only -X clang-x86-only
)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
add_test_pl_tests(
Expand All @@ -22,18 +22,28 @@ else()
find_program(CLANG_EXISTS "clang")
find_program(GCC_EXISTS "gcc")
if(CLANG_EXISTS)
add_test_pl_profile(
"ansi-c-clang"
"$<TARGET_FILE:goto-cc> --native-compiler clang"
"-C;-s;ansi-c-clang"
"CORE"
)
if("${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "x86_64" OR
"${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "i386")
add_test_pl_profile(
"ansi-c-clang"
"$<TARGET_FILE:goto-cc> --native-compiler clang"
"-C;-s;ansi-c-clang"
"CORE"
)
else()
add_test_pl_profile(
"ansi-c-clang"
"$<TARGET_FILE:goto-cc> --native-compiler clang"
"-C;-X;clang-x86-only;-s;ansi-c-clang"
"CORE"
)
endif()
endif()
if(GCC_EXISTS)
add_test_pl_profile(
"ansi-c-gcc"
"$<TARGET_FILE:goto-cc> --native-compiler gcc"
"-C;-X;fake-gcc-version;-s;ansi-c-gcc"
"-C;-X;fake-gcc-version;-X;clang-x86-only;-s;ansi-c-gcc"
"CORE"
)
add_test_pl_profile(
Expand All @@ -44,7 +54,7 @@ else()
)
elseif(NOT CLANG_EXISTS)
add_test_pl_tests(
"$<TARGET_FILE:goto-cc>"
"$<TARGET_FILE:goto-cc>" -X clang-x86-only
)
endif()

Expand Down
15 changes: 10 additions & 5 deletions regression/ansi-c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ else
endif

ifeq ($(BUILD_ENV_),MSVC)
excluded_tests = -X gcc-only
excluded_tests = -X gcc-only -X clang-x86-only
else
ifeq ($(BUILD_ENV_),OSX)
# In MacOS, a change in the assert.h header file
Expand All @@ -20,17 +20,21 @@ ifeq ($(BUILD_ENV_),OSX)
# <assert.h> or <cassert> headers.
excluded_tests = -X macos-assert-broken
endif
ifeq ($(filter x86_64 i386,$(shell uname -m)),)
excluded_tests += -X clang-x86-only
endif
endif

test:
if which clang ; then \
../test.pl -e -p -c "$(exe) --native-compiler clang" $(excluded_tests) ; \
fi
if which gcc ; then \
../test.pl -e -p -c "$(exe) --native-compiler gcc" $(excluded_tests) -X fake-gcc-version && \
../test.pl -e -p -c "$(exe) --native-compiler gcc" $(excluded_tests) \
-X fake-gcc-version -X clang-x86-only && \
../test.pl -e -p -c $(exe) $(excluded_tests) -I fake-gcc-version ; \
elif ! which clang ; then \
../test.pl -e -p -c $(exe) $(excluded_tests) ; \
../test.pl -e -p -c $(exe) $(excluded_tests) -X clang-x86-only ; \
fi
ifneq ($(BUILD_ENV_),MSVC)
@../test.pl -e -p -c "$(exe) -xc++ -D_Bool=bool" -I test-c++-front-end -s c++-front-end $(excluded_tests)
Expand All @@ -41,10 +45,11 @@ tests.log: ../test.pl
../test.pl -e -p -c "$(exe) --native-compiler clang" $(excluded_tests) ; \
fi
if which gcc ; then \
../test.pl -e -p -c "$(exe) --native-compiler gcc" $(excluded_tests) -X fake-gcc-version && \
../test.pl -e -p -c "$(exe) --native-compiler gcc" $(excluded_tests) \
-X fake-gcc-version -X clang-x86-only && \
../test.pl -e -p -c $(exe) $(excluded_tests) -I fake-gcc-version ; \
elif ! which clang ; then \
../test.pl -e -p -c $(exe) $(excluded_tests) ; \
../test.pl -e -p -c $(exe) $(excluded_tests) -X clang-x86-only ; \
fi
ifneq ($(BUILD_ENV_),MSVC)
@../test.pl -e -p -c "$(exe) -xc++ -D_Bool=bool" -I test-c++-front-end -s c++-front-end $(excluded_tests)
Expand Down
4 changes: 4 additions & 0 deletions regression/ansi-c/clang_target/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
int main()
{
int A[sizeof(void *) == 4 ? 1 : -1];
}
8 changes: 8 additions & 0 deletions regression/ansi-c/clang_target/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE clang-x86-only
main.c
-target i386-unknown-linux-gnu
^EXIT=0$
^SIGNAL=0$
--
^warning: ignoring
^CONVERSION ERROR$
2 changes: 2 additions & 0 deletions src/goto-cc/gcc_cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ const char *gcc_options_with_separated_argument[]=
"--include", // undocumented
"-current_version", // on the Mac
"-compatibility_version", // on the Mac
"-target",
"--target",
"-z",
nullptr
};
Expand Down
7 changes: 7 additions & 0 deletions src/goto-cc/gcc_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,13 @@ int gcc_modet::doit()
}
}

// clang supports -target <arch-quadruple> and --target=<arch-quadruple>
if(cmdline.isset("target"))
{
std::string arch_quadruple = cmdline.get_value("target");
config.set_arch(arch_quadruple.substr(0, arch_quadruple.find('-')));
}

// -fshort-wchar makes wchar_t "short unsigned int"
if(cmdline.isset("fshort-wchar"))
{
Expand Down