mirror of
https://github.com/llvm/llvm-project.git
synced 2025-05-10 14:36:07 +00:00

For a definition (of most linkage types), dso_local is set for ELF -fno-pic/-fpie and COFF, but not for Mach-O. This nuance causes unneeded binary format differences. This patch replaces (function) `define ` with `define{{.*}} `, (variable/constant/alias) `= ` with `={{.*}} `, or inserts appropriate `{{.*}} ` if there is an explicit linkage. * Clang will set dso_local for Mach-O, which is currently implied by TargetMachine.cpp. This will make COFF/Mach-O and executable ELF similar. * Eventually I hope we can make dso_local the textual LLVM IR default (write explicit "dso_preemptable" when applicable) and -fpic ELF will be similar to everything else. This patch helps move toward that goal.
84 lines
2.3 KiB
C++
84 lines
2.3 KiB
C++
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s -fsanitize=unreachable | FileCheck %s
|
|
|
|
void abort() __attribute__((noreturn));
|
|
|
|
// CHECK-LABEL: define{{.*}} void @_Z14calls_noreturnv()
|
|
void calls_noreturn() {
|
|
// Check absence ([^#]*) of call site attributes (including noreturn)
|
|
// CHECK: call void @_Z5abortv(){{[^#]*}}
|
|
abort();
|
|
|
|
// CHECK: __ubsan_handle_builtin_unreachable
|
|
// CHECK: unreachable
|
|
}
|
|
|
|
struct A {
|
|
// CHECK: declare void @_Z5abortv() [[EXTERN_FN_ATTR:#[0-9]+]]
|
|
|
|
// CHECK-LABEL: define linkonce_odr void @_ZN1A5call1Ev
|
|
void call1() {
|
|
// CHECK: call void @_ZN1A16does_not_return2Ev({{.*}}){{[^#]*}}
|
|
does_not_return2();
|
|
|
|
// CHECK: __ubsan_handle_builtin_unreachable
|
|
// CHECK: unreachable
|
|
}
|
|
|
|
// Test static members. Checks are below after `struct A` scope ends.
|
|
static void does_not_return1() __attribute__((noreturn)) {
|
|
abort();
|
|
}
|
|
|
|
// CHECK-LABEL: define linkonce_odr void @_ZN1A5call2Ev
|
|
void call2() {
|
|
// CHECK: call void @_ZN1A16does_not_return1Ev(){{[^#]*}}
|
|
does_not_return1();
|
|
|
|
// CHECK: __ubsan_handle_builtin_unreachable
|
|
// CHECK: unreachable
|
|
}
|
|
|
|
// Test calls through pointers to non-static member functions.
|
|
typedef void (A::*MemFn)() __attribute__((noreturn));
|
|
|
|
// CHECK-LABEL: define linkonce_odr void @_ZN1A5call3Ev
|
|
void call3() {
|
|
MemFn MF = &A::does_not_return2;
|
|
// CHECK: call void %{{[0-9]+\(.*}}){{[^#]*}}
|
|
(this->*MF)();
|
|
|
|
// CHECK: __ubsan_handle_builtin_unreachable
|
|
// CHECK: unreachable
|
|
}
|
|
|
|
// Test regular members.
|
|
// CHECK-LABEL: define linkonce_odr void @_ZN1A16does_not_return2Ev({{.*}})
|
|
// CHECK-SAME: [[USER_FN_ATTR:#[0-9]+]]
|
|
void does_not_return2() __attribute__((noreturn)) {
|
|
// CHECK: call void @_Z5abortv(){{[^#]*}}
|
|
abort();
|
|
|
|
// CHECK: call void @__ubsan_handle_builtin_unreachable
|
|
// CHECK: unreachable
|
|
|
|
// CHECK: call void @__ubsan_handle_builtin_unreachable
|
|
// CHECK: unreachable
|
|
}
|
|
};
|
|
|
|
// CHECK-LABEL: define linkonce_odr void @_ZN1A16does_not_return1Ev()
|
|
// CHECK-SAME: [[USER_FN_ATTR]]
|
|
// CHECK: call void @_Z5abortv(){{[^#]*}}
|
|
|
|
void force_irgen() {
|
|
A a;
|
|
a.call1();
|
|
a.call2();
|
|
a.call3();
|
|
}
|
|
|
|
// `noreturn` should be removed from functions and call sites
|
|
// CHECK-LABEL: attributes
|
|
// CHECK-NOT: [[USER_FN_ATTR]] = { {{.*noreturn.*}} }
|
|
// CHECK-NOT: [[EXTERN_FN_ATTR]] = { {{.*noreturn.*}} }
|