diff options
author | Reid Kleckner <reid@kleckner.net> | 2014-07-22 00:53:05 +0000 |
---|---|---|
committer | Reid Kleckner <reid@kleckner.net> | 2014-07-22 00:53:05 +0000 |
commit | e6de71dffb8ce404e22505f0e80015137437fde9 (patch) | |
tree | dca670a4c974afefaebbf2eb76e9f77e312ebbbd /test/CodeGenCXX/pragma-init_seg.cpp | |
parent | 8a16cb111295cbb321a40788d8ea83e9c240d803 (diff) |
-fms-extensions: Implement half of #pragma init_seg
Summary:
This pragma is very rare. We could *hypothetically* lower some uses of
it down to @llvm.global_ctors, but given that GlobalOpt isn't able to
optimize prioritized global ctors today, there's really no point.
If we wanted to do this in the future, I would check if the section used
in the pragma started with ".CRT$XC" and had up to two characters after
it. Those two characters could form the 16-bit initialization priority
that we support in @llvm.global_ctors. We would have to teach LLVM to
lower prioritized global ctors on COFF as well.
This should let us compile some silly uses of this pragma in WebKit /
Blink.
Reviewers: rsmith, majnemer
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D4549
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@213593 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CodeGenCXX/pragma-init_seg.cpp')
-rw-r--r-- | test/CodeGenCXX/pragma-init_seg.cpp | 88 |
1 files changed, 72 insertions, 16 deletions
diff --git a/test/CodeGenCXX/pragma-init_seg.cpp b/test/CodeGenCXX/pragma-init_seg.cpp index 7356c52aa3..3f9ff217e6 100644 --- a/test/CodeGenCXX/pragma-init_seg.cpp +++ b/test/CodeGenCXX/pragma-init_seg.cpp @@ -1,16 +1,72 @@ -// RUN: not %clang_cc1 %s -triple=i686-pc-win32 -fms-extensions -emit-llvm-only 2>&1 | FileCheck %s - -// Reduced from WebKit. - -// FIXME: Implement this pragma and test the codegen. We probably want to -// completely skip @llvm.global_ctors and just create global function pointers -// to the initializer with the right section. - -// CHECK: '#pragma init_seg' not implemented -#pragma init_seg(".unwantedstaticinits") -struct A { - A(); - ~A(); - int a; -}; -A a; +// RUN: %clang_cc1 %s -triple=i686-pc-win32 -fms-extensions -emit-llvm -o - | FileCheck %s + +int f(); + +// CHECK: $"\01?x@selectany_init@@3HA" = comdat any +// CHECK: $"\01?x@?$A@H@explicit_template_instantiation@@2HB" = comdat any +// CHECK: $"\01?x@?$A@H@implicit_template_instantiation@@2HB" = comdat any + +namespace simple_init { +#pragma init_seg(compiler) +int x = f(); +// CHECK: @"\01?x@simple_init@@3HA" = global i32 0, align 4 +// CHECK: @__cxx_init_fn_ptr = private constant void ()* @"\01??__Ex@simple_init@@YAXXZ", section ".CRT$XCC" + +#pragma init_seg(lib) +int y = f(); +// CHECK: @"\01?y@simple_init@@3HA" = global i32 0, align 4 +// CHECK: @__cxx_init_fn_ptr1 = private constant void ()* @"\01??__Ey@simple_init@@YAXXZ", section ".CRT$XCL" + +#pragma init_seg(user) +int z = f(); +// CHECK: @"\01?z@simple_init@@3HA" = global i32 0, align 4 +// No function pointer! This one goes on @llvm.global_ctors. +} + +#pragma init_seg(".asdf") + +namespace internal_init { +namespace { +int x = f(); +// CHECK: @"\01?x@?A@internal_init@@3HA" = internal global i32 0, align 4 +// CHECK: @__cxx_init_fn_ptr2 = private constant void ()* @"\01??__Ex@?A@internal_init@@YAXXZ", section ".asdf" +} +} + +namespace selectany_init { +int __declspec(selectany) x = f(); +// CHECK: @"\01?x@selectany_init@@3HA" = weak_odr global i32 0, comdat $"\01?x@selectany_init@@3HA", align 4 +// CHECK: @__cxx_init_fn_ptr3 = private constant void ()* @"\01??__Ex@selectany_init@@YAXXZ", section ".asdf", comdat $"\01?x@selectany_init@@3HA" +} + +namespace explicit_template_instantiation { +template <typename T> struct A { static const int x; }; +template <typename T> const int A<T>::x = f(); +template struct A<int>; +// CHECK: @"\01?x@?$A@H@explicit_template_instantiation@@2HB" = weak_odr global i32 0, comdat $"\01?x@?$A@H@explicit_template_instantiation@@2HB", align 4 +// CHECK: @__cxx_init_fn_ptr4 = private constant void ()* @"\01??__Ex@?$A@H@explicit_template_instantiation@@2HB@YAXXZ", section ".asdf", comdat $"\01?x@?$A@H@explicit_template_instantiation@@2HB" +} + +namespace implicit_template_instantiation { +template <typename T> struct A { static const int x; }; +template <typename T> const int A<T>::x = f(); +int g() { return A<int>::x; } +// CHECK: @"\01?x@?$A@H@implicit_template_instantiation@@2HB" = linkonce_odr global i32 0, comdat $"\01?x@?$A@H@implicit_template_instantiation@@2HB", align 4 +// CHECK: @__cxx_init_fn_ptr5 = private constant void ()* @"\01??__Ex@?$A@H@implicit_template_instantiation@@2HB@YAXXZ", section ".asdf", comdat $"\01?x@?$A@H@implicit_template_instantiation@@2HB" +} + +// ... and here's where we emitted user level ctors. +// CHECK: @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] +// CHECK: [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__sub_I_pragma_init_seg.cpp, i8* null }] + +// We have to mark everything used so we can survive globalopt, even through +// LTO. There's no way LLVM could really understand if data in the .asdf +// section is really used or dead. +// +// CHECK: @llvm.used = appending global [6 x i8*] +// CHECK: [i8* bitcast (void ()** @__cxx_init_fn_ptr to i8*), +// CHECK: i8* bitcast (void ()** @__cxx_init_fn_ptr1 to i8*), +// CHECK: i8* bitcast (void ()** @__cxx_init_fn_ptr2 to i8*), +// CHECK: i8* bitcast (void ()** @__cxx_init_fn_ptr3 to i8*), +// CHECK: i8* bitcast (void ()** @__cxx_init_fn_ptr4 to i8*), +// CHECK: i8* bitcast (void ()** @__cxx_init_fn_ptr5 to i8*)], section "llvm.metadata" |