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.
50 lines
789 B
C++
50 lines
789 B
C++
// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
|
|
struct A {
|
|
void f();
|
|
|
|
int a;
|
|
};
|
|
|
|
struct B : A {
|
|
double b;
|
|
};
|
|
|
|
void f() {
|
|
B b;
|
|
|
|
b.f();
|
|
}
|
|
|
|
// CHECK: define{{.*}} %struct.B* @_Z1fP1A(%struct.A* %a) [[NUW:#[0-9]+]]
|
|
B *f(A *a) {
|
|
// CHECK-NOT: br label
|
|
// CHECK: ret %struct.B*
|
|
return static_cast<B*>(a);
|
|
}
|
|
|
|
// PR5965
|
|
namespace PR5965 {
|
|
|
|
// CHECK: define{{.*}} %struct.A* @_ZN6PR59651fEP1B(%struct.B* %b) [[NUW]]
|
|
A *f(B* b) {
|
|
// CHECK-NOT: br label
|
|
// CHECK: ret %struct.A*
|
|
return b;
|
|
}
|
|
|
|
}
|
|
|
|
// Don't crash on a derived-to-base conversion of an r-value
|
|
// aggregate.
|
|
namespace test3 {
|
|
struct A {};
|
|
struct B : A {};
|
|
|
|
void foo(A a);
|
|
void test() {
|
|
foo(B());
|
|
}
|
|
}
|
|
|
|
// CHECK: attributes [[NUW]] = { noinline nounwind{{.*}} }
|