Skip to content

Commit a54545b

Browse files
committed
[CMake] Fix __builtin_thread_pointer check with LTO
With LTO, gcc's IPA passes might drop the foo() function and then the test will pass even on platforms where __builtin_thread_pointer is unavailable. On PPC64, we get this as a result: ``` llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp:361:61: error: ‘__builtin_thread_pointer’ is not supported on this targ ``` Just mark the function in the CMake configure test with the 'used' attribute to avoid it being optimised out. The test then behaves correctly with -flto. Tested with e.g. 'powerpc64le-linux-gnu-gcc -O2 -flto a.c'. Reported-by: matoro Reviewed-by: maskray Closes: #70968 Signed-off-by: Sam James <[email protected]>
1 parent 8a7846f commit a54545b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

llvm/cmake/config-ix.cmake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ check_include_file(fenv.h HAVE_FENV_H)
6565
check_symbol_exists(FE_ALL_EXCEPT "fenv.h" HAVE_DECL_FE_ALL_EXCEPT)
6666
check_symbol_exists(FE_INEXACT "fenv.h" HAVE_DECL_FE_INEXACT)
6767
check_c_source_compiles("
68-
void *foo() {
68+
#if __has_attribute(used)
69+
#define LLVM_ATTRIBUTE_USED __attribute__((__used__))
70+
#else
71+
#define LLVM_ATTRIBUTE_USED
72+
#endif
73+
LLVM_ATTRIBUTE_USED void *foo() {
6974
return __builtin_thread_pointer();
7075
}
7176
int main(void) { return 0; }"

0 commit comments

Comments
 (0)