llvm.org GIT mirror llvm / d7a1a7b
[IR] Disallow llvm.global_ctors and llvm.global_dtors of the 2-field form in textual format The 3-field form was introduced by D3499 in 2014 and the legacy 2-field form was planned to be removed in LLVM 4.0 For the textual format, this patch migrates the existing 2-field form to use the 3-field form and deletes the compatibility code. test/Verifier/global-ctors-2.ll checks we have a friendly error message. For bitcode, lib/IR/AutoUpgrade UpgradeGlobalVariables will upgrade the 2-field form (add i8* null as the third field). Reviewed By: rnk, dexonsmith Differential Revision: https://reviews.llvm.org/D61547 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360742 91177308-0d34-0410-b5e6-96231b3b80d8 Fangrui Song 4 months ago
60 changed file(s) with 148 addition(s) and 179 deletion(s). Raw diff Collapse all Expand all
64816481 @llvm.global_ctors = appending global [1 x %0] [%0 { i32 65535, void ()* @ctor, i8* @data }]
64826482
64836483 The ``@llvm.global_ctors`` array contains a list of constructor
6484 functions, priorities, and an optional associated global or function.
6484 functions, priorities, and an associated global or function.
64856485 The functions referenced by this array will be called in ascending order
64866486 of priority (i.e. lowest first) when the module is loaded. The order of
64876487 functions with the same priority is not defined.
64886488
6489 If the third field is present, non-null, and points to a global variable
6489 If the third field is non-null, and points to a global variable
64906490 or function, the initializer function will only run if the associated
64916491 data from the current module is not discarded.
64926492
65016501 @llvm.global_dtors = appending global [1 x %0] [%0 { i32 65535, void ()* @dtor, i8* @data }]
65026502
65036503 The ``@llvm.global_dtors`` array contains a list of destructor
6504 functions, priorities, and an optional associated global or function.
6504 functions, priorities, and an associated global or function.
65056505 The functions referenced by this array will be called in descending
65066506 order of priority (i.e. highest first) when the module is unloaded. The
65076507 order of functions with the same priority is not defined.
65086508
6509 If the third field is present, non-null, and points to a global variable
6509 If the third field is non-null, and points to a global variable
65106510 or function, the destructor function will only run if the associated
65116511 data from the current module is not discarded.
65126512
6161 parameter is required to be a simple constant. This annotation must
6262 be accurate to avoid possible miscompiles.
6363
64 * The 2-field form of global variables ``@llvm.global_ctors`` and
65 ``@llvm.global_dtors`` has been deleted. The third field of their element
66 type is now mandatory. Specify `i8* null` to migrate from the obsoleted
67 2-field form.
6468
6569 Changes to the ARM Backend
6670 --------------------------
4545 /// so that it can update all calls to the old function.
4646 void UpgradeCallsToIntrinsic(Function* F);
4747
48 /// This checks for global variables which should be upgraded. It returns true
49 /// if it requires upgrading.
50 bool UpgradeGlobalVariable(GlobalVariable *GV);
48 /// This checks for global variables which should be upgraded. It it requires
49 /// upgrading, returns a pointer to the upgraded variable.
50 GlobalVariable *UpgradeGlobalVariable(GlobalVariable *GV);
5151
5252 /// This checks for module flags which should be upgraded. It returns true if
5353 /// module is modified.
27932793 }
27942794
27952795 // Look for global variables which need to be renamed.
2796 std::vector> UpgradedVariables;
27962797 for (GlobalVariable &GV : TheModule->globals())
2797 UpgradeGlobalVariable(&GV);
2798 if (GlobalVariable *Upgraded = UpgradeGlobalVariable(&GV))
2799 UpgradedVariables.emplace_back(&GV, Upgraded);
2800 for (auto &Pair : UpgradedVariables) {
2801 Pair.first->eraseFromParent();
2802 TheModule->getGlobalList().push_back(Pair.second);
2803 }
27982804
27992805 // Force deallocation of memory for these vectors to favor the client that
28002806 // want lazy deserialization.
19651965 /// priority.
19661966 void AsmPrinter::EmitXXStructorList(const DataLayout &DL, const Constant *List,
19671967 bool isCtor) {
1968 // Should be an array of '{ int, void ()* }' structs. The first value is the
1968 // Should be an array of '{ i32, void ()*, i8* }' structs. The first value is the
19691969 // init priority.
19701970 if (!isa(List)) return;
19711971
19731973 const ConstantArray *InitList = dyn_cast(List);
19741974 if (!InitList) return; // Not an array!
19751975 StructType *ETy = dyn_cast(InitList->getType()->getElementType());
1976 // FIXME: Only allow the 3-field form in LLVM 4.0.
1977 if (!ETy || ETy->getNumElements() < 2 || ETy->getNumElements() > 3)
1978 return; // Not an array of two or three elements!
1979 if (!isa(ETy->getTypeAtIndex(0U)) ||
1980 !isa(ETy->getTypeAtIndex(1U))) return; // Not (int, ptr).
1981 if (ETy->getNumElements() == 3 && !isa(ETy->getTypeAtIndex(2U)))
1976 if (!ETy || ETy->getNumElements() != 3 ||
1977 !isa(ETy->getTypeAtIndex(0U)) ||
1978 !isa(ETy->getTypeAtIndex(1U)) ||
1979 !isa(ETy->getTypeAtIndex(2U)))
19821980 return; // Not (int, ptr, ptr).
19831981
19841982 // Gather the structors in a form that's convenient for sorting by priority.
19941992 Structor &S = Structors.back();
19951993 S.Priority = Priority->getLimitedValue(65535);
19961994 S.Func = CS->getOperand(1);
1997 if (ETy->getNumElements() == 3 && !CS->getOperand(2)->isNullValue())
1995 if (!CS->getOperand(2)->isNullValue())
19981996 S.ComdatKey =
19991997 dyn_cast(CS->getOperand(2)->stripPointerCasts());
20001998 }
804804 return Upgraded;
805805 }
806806
807 bool llvm::UpgradeGlobalVariable(GlobalVariable *GV) {
808 // Nothing to do yet.
809 return false;
807 GlobalVariable *llvm::UpgradeGlobalVariable(GlobalVariable *GV) {
808 if (!(GV->hasName() && (GV->getName() == "llvm.global_ctors" ||
809 GV->getName() == "llvm.global_dtors")) ||
810 !GV->hasInitializer())
811 return nullptr;
812 ArrayType *ATy = dyn_cast(GV->getValueType());
813 if (!ATy)
814 return nullptr;
815 StructType *STy = dyn_cast(ATy->getElementType());
816 if (!STy || STy->getNumElements() != 2)
817 return nullptr;
818
819 LLVMContext &C = GV->getContext();
820 IRBuilder<> IRB(C);
821 auto EltTy = StructType::get(STy->getElementType(0), STy->getElementType(1),
822 IRB.getInt8PtrTy());
823 Constant *Init = GV->getInitializer();
824 unsigned N = Init->getNumOperands();
825 std::vector NewCtors(N);
826 for (unsigned i = 0; i != N; ++i) {
827 auto Ctor = cast(Init->getOperand(i));
828 NewCtors[i] = ConstantStruct::get(
829 EltTy, Ctor->getAggregateElement(0u), Ctor->getAggregateElement(1),
830 Constant::getNullValue(IRB.getInt8PtrTy()));
831 }
832 Constant *NewInit = ConstantArray::get(ArrayType::get(EltTy, N), NewCtors);
833
834 return new GlobalVariable(NewInit->getType(), false, GV->getLinkage(),
835 NewInit, GV->getName());
810836 }
811837
812838 // Handles upgrading SSE2/AVX2/AVX512BW PSLLDQ intrinsics by converting them
640640 PointerType *FuncPtrTy =
641641 FunctionType::get(Type::getVoidTy(Context), false)->
642642 getPointerTo(DL.getProgramAddressSpace());
643 // FIXME: Reject the 2-field form in LLVM 4.0.
644643 Assert(STy &&
645644 (STy->getNumElements() == 2 || STy->getNumElements() == 3) &&
646645 STy->getTypeAtIndex(0u)->isIntegerTy(32) &&
647646 STy->getTypeAtIndex(1) == FuncPtrTy,
648647 "wrong type for intrinsic global variable", &GV);
649 if (STy->getNumElements() == 3) {
650 Type *ETy = STy->getTypeAtIndex(2);
651 Assert(ETy->isPointerTy() &&
652 cast(ETy)->getElementType()->isIntegerTy(8),
653 "wrong type for intrinsic global variable", &GV);
654 }
648 Assert(STy->getNumElements() == 3,
649 "the third field of the element type is mandatory, "
650 "specify i8* null to migrate from the obsoleted 2-field form");
651 Type *ETy = STy->getTypeAtIndex(2);
652 Assert(ETy->isPointerTy() &&
653 cast(ETy)->getElementType()->isIntegerTy(8),
654 "wrong type for intrinsic global variable", &GV);
655655 }
656656 }
657657
2626 // Get the current set of static global constructors and add the new ctor
2727 // to the list.
2828 SmallVector CurrentCtors;
29 StructType *EltTy;
29 StructType *EltTy = StructType::get(
30 IRB.getInt32Ty(), PointerType::getUnqual(FnTy), IRB.getInt8PtrTy());
3031 if (GlobalVariable *GVCtor = M.getNamedGlobal(Array)) {
31 ArrayType *ATy = cast(GVCtor->getValueType());
32 StructType *OldEltTy = cast(ATy->getElementType());
33 // Upgrade a 2-field global array type to the new 3-field format if needed.
34 if (Data && OldEltTy->getNumElements() < 3)
35 EltTy = StructType::get(IRB.getInt32Ty(), PointerType::getUnqual(FnTy),
36 IRB.getInt8PtrTy());
37 else
38 EltTy = OldEltTy;
3932 if (Constant *Init = GVCtor->getInitializer()) {
4033 unsigned n = Init->getNumOperands();
4134 CurrentCtors.reserve(n + 1);
42 for (unsigned i = 0; i != n; ++i) {
43 auto Ctor = cast(Init->getOperand(i));
44 if (EltTy != OldEltTy)
45 Ctor =
46 ConstantStruct::get(EltTy, Ctor->getAggregateElement((unsigned)0),
47 Ctor->getAggregateElement(1),
48 Constant::getNullValue(IRB.getInt8PtrTy()));
49 CurrentCtors.push_back(Ctor);
50 }
35 for (unsigned i = 0; i != n; ++i)
36 CurrentCtors.push_back(cast(Init->getOperand(i)));
5137 }
5238 GVCtor->eraseFromParent();
53 } else {
54 // Use the new three-field struct if there isn't one already.
55 EltTy = StructType::get(IRB.getInt32Ty(), PointerType::getUnqual(FnTy),
56 IRB.getInt8PtrTy());
57 }
58
59 // Build a 2 or 3 field global_ctor entry. We don't take a comdat key.
39 }
40
41 // Build a 3 field global_ctor entry. We don't take a comdat key.
6042 Constant *CSVals[3];
6143 CSVals[0] = IRB.getInt32(Priority);
6244 CSVals[1] = F;
63 // FIXME: Drop support for the two element form in LLVM 4.0.
64 if (EltTy->getNumElements() >= 3)
65 CSVals[2] = Data ? ConstantExpr::getPointerCast(Data, IRB.getInt8PtrTy())
66 : Constant::getNullValue(IRB.getInt8PtrTy());
45 CSVals[2] = Data ? ConstantExpr::getPointerCast(Data, IRB.getInt8PtrTy())
46 : Constant::getNullValue(IRB.getInt8PtrTy());
6747 Constant *RuntimeCtorInit =
6848 ConstantStruct::get(EltTy, makeArrayRef(CSVals, EltTy->getNumElements()));
6949
11 ; RUN: verify-uselistorder < %s
22 %0 = type { %object.ModuleInfo.__vtbl*, i8*, %"byte[]", %1, %"ClassInfo[]", i32, void ()*, void ()*, void ()*, i8*, void ()* } ; type %0
33 %1 = type { i64, %object.ModuleInfo* } ; type %1
4 %2 = type { i32, void ()* } ; type %2
4 %2 = type { i32, void ()*, i8* } ; type %2
55 %"ClassInfo[]" = type { i64, %object.ClassInfo** }
66 %"Interface[]" = type { i64, %object.Interface* }
77 %"ModuleInfo[]" = type { i64, %object.ModuleInfo** }
2323 @_D5tango4core8BitManip8__ModuleZ = global %0 { %object.ModuleInfo.__vtbl* @_D10ModuleInfo6__vtblZ, i8* null, %"byte[]" { i64 19, i8* getelementptr ([20 x i8], [20 x i8]* @.str, i32 0, i32 0) }, %1 zeroinitializer, %"ClassInfo[]" zeroinitializer, i32 4, void ()* null, void ()* null, void ()* null, i8* null, void ()* null } ; <%0*> [#uses=1]
2424 @_D5tango4core8BitManip11__moduleRefZ = internal global %ModuleReference { %ModuleReference* null, %object.ModuleInfo* bitcast (%0* @_D5tango4core8BitManip8__ModuleZ to %object.ModuleInfo*) } ; <%ModuleReference*> [#uses=2]
2525 @_Dmodule_ref = external global %ModuleReference* ; <%ModuleReference**> [#uses=2]
26 @llvm.global_ctors = appending constant [1 x %2] [%2 { i32 65535, void ()* @_D5tango4core8BitManip16__moduleinfoCtorZ }] ; <[1 x %2]*> [#uses=0]
26 @llvm.global_ctors = appending constant [1 x %2] [%2 { i32 65535, void ()* @_D5tango4core8BitManip16__moduleinfoCtorZ, i8* null }] ; <[1 x %2]*> [#uses=0]
2727
2828 define fastcc i32 @_D5tango4core8BitManip6popcntFkZi(i32 %x_arg) nounwind readnone {
2929 entry:
0 ; RUN: llvm-dis < %s.bc| FileCheck %s
11 ; RUN: verify-uselistorder < %s.bc
22
3 ; Global constructors should no longer be upgraded when reading bitcode.
4 ; CHECK: @llvm.global_ctors = appending global [0 x { i32, void ()* }] zeroinitializer
3 ; The 2-field form @llvm.global_ctors will be upgraded when reading bitcode.
4 ; CHECK: @llvm.global_ctors = appending global [0 x { i32, void ()*, i8* }] zeroinitializer
0 ; RUN: llvm-dis < %s.bc | FileCheck %s
1 ; RUN: verify-uselistorder < %s.bc
2
3 ; The 2-field form @llvm.global_dtors will be upgraded when reading bitcode.
4 ; CHECK: @llvm.global_dtors = appending global [2 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* null, i8* null }, { i32, void ()*, i8* } { i32 65534, void ()* null, i8* null }]
44 ret void
55 }
66
7 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_a }]
7 @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I_a, i8* null }]
88
99 ; CHECK: .section .init_array
2020 ; GNUEABI: .long f152
2121
2222
23 @llvm.global_ctors = appending global [2 x { i32, void ()* }] [ { i32, void ()* } { i32 151, void ()* @f151 }, { i32, void ()* } { i32 152, void ()* @f152 } ]
23 @llvm.global_ctors = appending global [2 x { i32, void ()*, i8* }] [ { i32, void ()*, i8* } { i32 151, void ()* @f151, i8* null }, { i32, void ()*, i8* } { i32 152, void ()* @f152, i8* null } ]
2424
2525 define void @f151() {
2626 entry:
1010 ; GNUEABI: .section .init_array,"aw",%init_array
1111 ; GNUEABI: .section .fini_array,"aw",%fini_array
1212
13 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [ { i32, void ()* } { i32 65535, void ()* @__mf_init } ] ; <[1 x { i32, void ()* }]*> [#uses=0]
14 @llvm.global_dtors = appending global [1 x { i32, void ()* }] [ { i32, void ()* } { i32 65535, void ()* @__mf_fini } ] ; <[1 x { i32, void ()* }]*> [#uses=0]
13 @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [ { i32, void ()*, i8* } { i32 65535, void ()* @__mf_init, i8* null } ] ; <[1 x { i32, void ()*, i8* }]*> [#uses=0]
14 @llvm.global_dtors = appending global [1 x { i32, void ()*, i8* }] [ { i32, void ()*, i8* } { i32 65535, void ()* @__mf_fini, i8* null } ] ; <[1 x { i32, void ()*, i8* }]*> [#uses=0]
1515
1616 define void @__mf_init() {
1717 entry:
11
22 target triple = "mipsel-unknown-linux"
33
4 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @test }]
4 @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @test, i8* null }]
55 ; CHECK: .section
66 ; CHECK: .init_array
77 ; CHECK-NOT: .ctors
99 %struct.CS = type { i32 }
1010
1111 @_ZL3glb = internal global [1 x %struct.CS] zeroinitializer, align 4
12 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_a }]
12 @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I_a, i8* null }]
1313
1414 define internal void @__cxx_global_var_init() section ".text.startup" {
1515 entry:
1919 ret void
2020 }
2121
22 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_a }]
22 @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I_a, i8* null }]
2323
2424 ;INITARRAY: section .init_array
2525 ;INITARRAY-NOT: .section .ctors
11 ; PR 1557
22
33 target datalayout = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-f128:128:128"
4 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [ { i32, void ()* } { i32 65535, void ()* @set_fast_math } ] ; <[1 x { i32, void ()* }]*> [#uses=0]
4 @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [ { i32, void ()*, i8* } { i32 65535, void ()* @set_fast_math, i8* null } ] ; <[1 x { i32, void ()*, i8* }]*> [#uses=0]
55
66 define internal void @set_fast_math() nounwind {
77 entry:
22
33 %struct.A = type { [1024 x i8] }
44 @_ZN1A1aE = global %struct.A zeroinitializer, align 32 ; <%struct.A*> [#uses=1]
5 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [ { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZN1A1aE } ] ; <[1 x { i32, void ()* }]*> [#uses=0]
5 @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [ { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I__ZN1A1aE, i8* null } ] ; <[1 x { i32, void ()*, i8* null }]*> [#uses=0]
66
77 define internal void @_GLOBAL__I__ZN1A1aE() section "__TEXT,__StaticInit,regular,pure_instructions" {
88 entry:
11 ; RUN: llc < %s -mtriple=i386-apple-darwin | FileCheck %s --check-prefix=CHECK-DARWIN
22 ; PR5329
33
4 @llvm.global_ctors = appending global [3 x { i32, void ()* }] [{ i32, void ()* } { i32 2000, void ()* @construct_2 }, { i32, void ()* } { i32 3000, void ()* @construct_3 }, { i32, void ()* } { i32 1000, void ()* @construct_1 }]
4 @llvm.global_ctors = appending global [3 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 2000, void ()* @construct_2, i8* null }, { i32, void ()*, i8* } { i32 3000, void ()* @construct_3, i8* null }, { i32, void ()*, i8* } { i32 1000, void ()* @construct_1, i8* null }]
55 ; CHECK-DEFAULT: .section .ctors.64535,"aw",@progbits
66 ; CHECK-DEFAULT: .long construct_1
77 ; CHECK-DEFAULT: .section .ctors.63535,"aw",@progbits
1313 ; CHECK-DARWIN-NEXT: .long _construct_2
1414 ; CHECK-DARWIN-NEXT: .long _construct_3
1515
16 @llvm.global_dtors = appending global [3 x { i32, void ()* }] [{ i32, void ()* } { i32 2000, void ()* @destruct_2 }, { i32, void ()* } { i32 1000, void ()* @destruct_1 }, { i32, void ()* } { i32 3000, void ()* @destruct_3 }]
16 @llvm.global_dtors = appending global [3 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 2000, void ()* @destruct_2, i8* null }, { i32, void ()*, i8* } { i32 1000, void ()* @destruct_1, i8* null }, { i32, void ()*, i8* } { i32 3000, void ()* @destruct_3, i8* null }]
1717 ; CHECK-DEFAULT: .section .dtors.64535,"aw",@progbits
1818 ; CHECK-DEFAULT: .long destruct_1
1919 ; CHECK-DEFAULT: .section .dtors.63535,"aw",@progbits
1515
1616 @c1 = global %class.C zeroinitializer, align 1
1717 @d1 = global %class.D zeroinitializer, align 1
18 @llvm.global_ctors = appending global [2 x { i32, void ()* }] [{ i32, void ()* } { i32 101, void ()* @_GLOBAL__I_000101 }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_a }]
18 @llvm.global_ctors = appending global [2 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 101, void ()* @_GLOBAL__I_000101, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I_a, i8* null }]
1919
2020 define linkonce_odr void @_ZN1CC1Ev(%class.C* nocapture %this) {
2121 entry:
187187 @"\01LC28" = external constant [15 x i8] ; <[15 x i8]*> [#uses=0]
188188 @"\01LC29" = external constant [20 x i8] ; <[20 x i8]*> [#uses=0]
189189 @"\01LC30" = external constant [41 x i8] ; <[41 x i8]*> [#uses=0]
190 @llvm.global_ctors = external global [1 x { i32, void ()* }] ; <[1 x { i32, void ()* }]*> [#uses=0]
191190
192191 declare void @_GLOBAL__I__ZN9HingeNode7DEG2RADE() section "__TEXT,__StaticInit,regular,pure_instructions"
193192
2020 target datalayout = "e-m:w-p:32:32-i64:64-f80:32-n8:16:32-S32"
2121 target triple = "i686-pc-win32"
2222
23 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 1, void ()* @asan.module_ctor }]
23 @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 1, void ()* @asan.module_ctor, i8* null }]
2424
2525 ; Function Attrs: nounwind sanitize_address
2626 define i32 @foo() #0 !dbg !4 {
1313 target triple = "i686-pc-win32"
1414
1515 @c = global { i8, [63 x i8] } { i8 42, [63 x i8] zeroinitializer }, align 32
16 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 1, void ()* @asan.module_ctor }]
16 @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 1, void ()* @asan.module_ctor, i8* null }]
1717 @___asan_gen_ = private constant [7 x i8] c"asan.c\00", align 1
1818 @___asan_gen_1 = private unnamed_addr constant [2 x i8] c"c\00", align 1
1919 @0 = internal global [1 x { i32, i32, i32, i32, i32, i32 }] [{ i32, i32, i32, i32, i32, i32 } { i32 ptrtoint ({ i8, [63 x i8] }* @c to i32), i32 1, i32 64, i32 ptrtoint ([2 x i8]* @___asan_gen_1 to i32), i32 ptrtoint ([7 x i8]* @___asan_gen_ to i32), i32 0 }]
20 @llvm.global_dtors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 1, void ()* @asan.module_dtor }]
20 @llvm.global_dtors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 1, void ()* @asan.module_dtor, i8* null }]
2121
2222 define internal void @asan.module_ctor() {
2323 call void @__asan_init_v3()
5151 %struct.B = type { i32 }
5252 %struct.A = type { i8 }
5353
54 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 1, void ()* @asan.module_ctor }]
54 @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 1, void ()* @asan.module_ctor, i8* null }]
5555 @__asan_option_detect_stack_use_after_return = external global i32
5656 @___asan_gen_ = private unnamed_addr constant [11 x i8] c"1 32 8 1 A\00", align 1
5757 @___asan_gen_1 = private unnamed_addr constant [13 x i8] c"1 32 1 3 tmp\00", align 1
2222 %class.A = type { i32 }
2323
2424 @a = global %class.A zeroinitializer, align 4, !dbg !0
25 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_a }]
25 @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I_a, i8* null }]
2626
2727 define internal void @__cxx_global_var_init() section ".text.startup" !dbg !18 {
2828 entry:
1818
1919 @__asan_mapping_offset = linkonce_odr constant i64 2147450880
2020 @__asan_mapping_scale = linkonce_odr constant i64 3
21 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 1, void ()* @asan.module_ctor }]
21 @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 1, void ()* @asan.module_ctor, i8* null }]
2222 @___asan_gen_ = private unnamed_addr constant [16 x i8] c"1 32 4 5 .addr \00", align 1
2323
2424 ; Function Attrs: sanitize_address uwtable
55 ; low_pc for the compile unit.
66 ; CHECK-NOT: .rela.debug_ranges
77
8 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 0, void ()* @__msan_init }]
8 @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 0, void ()* @__msan_init, i8* null }]
99 @str = private unnamed_addr constant [4 x i8] c"zzz\00"
1010 @__msan_retval_tls = external thread_local(initialexec) global [8 x i64]
1111 @__msan_retval_origin_tls = external thread_local(initialexec) global i32
180180 @_ZN7echidna8capybara8mongoose6animalE = global %"class.echidna::capybara::mongoose::fluffy" zeroinitializer, align 4, !dbg !6
181181 @w = internal global %"struct.::walrus" zeroinitializer, align 1, !dbg !16
182182 @wom = global %struct.wombat zeroinitializer, align 4, !dbg !25
183 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_a }]
183 @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I_a, i8* null }]
184184
185185 ; Function Attrs: nounwind uwtable
186186 define void @_Z3foov() #0 !dbg !40 {
22 @G1 = global i32 zeroinitializer
33 @G2 = global i32 zeroinitializer
44 @g = global <2 x i32*> zeroinitializer
5 %0 = type { i32, void ()* }
6 @llvm.global_ctors = appending global [1 x %0] [%0 { i32 65535, void ()* @test }]
5 %0 = type { i32, void ()*, i8* }
6 @llvm.global_ctors = appending global [1 x %0] [%0 { i32 65535, void ()* @test, i8* null }]
77 define internal void @test() {
88 %A = insertelement <2 x i32*> undef, i32* @G1, i32 0
99 %B = insertelement <2 x i32*> %A, i32* @G2, i32 1
2525 ret void
2626 }
2727
28 @llvm.global_ctors = appending global [2 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @__late_ctor }, { i32, void ()* } { i32 0, void ()* @__early_ctor }]
28 @llvm.global_ctors = appending global [2 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @__late_ctor, i8* null }, { i32, void ()*, i8* } { i32 0, void ()* @__early_ctor, i8* null }]
2929
3030 define internal void @__late_ctor() sanitize_address section ".text.startup" {
3131 entry:
+0
-18
test/Instrumentation/MemorySanitizer/global_ctors_2to3.ll less more
None ; MSan converts 2-element global_ctors to 3-element when adding the new entry.
1 ; RUN: opt < %s -msan-with-comdat -S -passes=msan 2>&1 | FileCheck %s
2 ; RUN: opt < %s -msan -msan-with-comdat -S | FileCheck %s
3
4 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5 target triple = "x86_64-unknown-linux-gnu"
6
7 ; CHECK: $msan.module_ctor = comdat any
8 ; CHECK: @llvm.global_ctors = appending global [2 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @f, i8* null }, { i32, void ()*, i8* } { i32 0, void ()* @msan.module_ctor, i8* bitcast (void ()* @msan.module_ctor to i8*) }]
9
10 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @f }]
11
12 define internal void @f() {
13 entry:
14 ret void
15 }
16
17 ; CHECK: define internal void @msan.module_ctor() comdat {
+0
-8
test/Linker/ctors5.ll less more
None ; RUN: llvm-link -S %s | FileCheck %s
1
2 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @f }]
3 ; CHECK: @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @f, i8* null }]
4
5 define void @f() {
6 ret void
7 }
+0
-29
test/Linker/global_ctors.ll less more
None ; RUN: llvm-link -S %s %S/Inputs/old_global_ctors.3.4.bc | FileCheck %s
1 ; RUN: llvm-link -S %S/Inputs/old_global_ctors.3.4.bc %s | FileCheck %s
2
3 ; old_global_ctors.3.4.bc contains the following LLVM IL, assembled into
4 ; bitcode by llvm-as from 3.4. It uses a two element @llvm.global_ctors array.
5 ; ---
6 ; declare void @a_global_ctor()
7 ; declare void @b_global_ctor()
8 ;
9 ; @llvm.global_ctors = appending global [2 x { i32, void ()* } ] [
10 ; { i32, void ()* } { i32 65535, void ()* @a_global_ctor },
11 ; { i32, void ()* } { i32 65535, void ()* @b_global_ctor }
12 ; ]
13 ; ---
14
15 declare void @c_global_ctor()
16 declare void @d_global_ctor()
17
18 @llvm.global_ctors = appending global [2 x { i32, void ()*, i8* } ] [
19 { i32, void ()*, i8* } { i32 65535, void ()* @c_global_ctor, i8* null },
20 { i32, void ()*, i8* } { i32 65535, void ()* @d_global_ctor, i8* null }
21 ]
22
23 ; CHECK: @llvm.global_ctors = appending global [4 x { i32, void ()*, i8* }] [
24 ; CHECK-DAG: { i32, void ()*, i8* } { i32 65535, void ()* @a_global_ctor, i8* null }
25 ; CHECK-DAG: { i32, void ()*, i8* } { i32 65535, void ()* @b_global_ctor, i8* null }
26 ; CHECK-DAG: { i32, void ()*, i8* } { i32 65535, void ()* @c_global_ctor, i8* null }
27 ; CHECK-DAG: { i32, void ()*, i8* } { i32 65535, void ()* @d_global_ctor, i8* null }
28 ; CHECK: ]
11 ; RUN: -filetype=obj -o - | llvm-readobj -r | FileCheck %s
22
33
4 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @f }]
4 @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @f, i8* null }]
55
66 define void @f() {
77 ret void
0 ; RUN: opt -S -globaldce < %s | FileCheck %s
11
22 ; Test that the presence of debug intrinsics isn't affecting GlobalDCE.
3 ; CHECK: @llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @_notremovable }]
3 ; CHECK: @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_notremovable, i8* null }]
44 ; CHECK-NOT: @_GLOBAL__I_a
55
66 declare void @_notremovable()
77
8 @llvm.global_ctors = appending global [3 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_a }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_b }, { i32, void ()* } { i32 65535, void ()* @_notremovable }]
8 @llvm.global_ctors = appending global [3 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I_a, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I_b, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_notremovable, i8* null }]
99
1010 @x = internal unnamed_addr constant i8 undef, align 1
1111
88
99 @foo = global %class.Foo zeroinitializer, align 4
1010 @_ZN3Bar18LINKER_INITIALIZEDE = external constant i32
11 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_a }]
11 @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I_a, i8* null }]
1212
1313 define internal void @__cxx_global_var_init() section "__TEXT,__StaticInit,regular,pure_instructions" {
1414 %1 = load i32, i32* @_ZN3Bar18LINKER_INITIALIZEDE, align 4
1515 %"struct.std::vector >" = type { %"struct.std::_Vector_base >" }
1616 @registry_lock = external global %struct..0FileDescriptor ; <%struct..0FileDescriptor*> [#uses=0]
1717 @_ZN61FLAG__foo_int32_44FLAGS_E = external global %"struct.FlagRegisterer" ; <%"struct.FlagRegisterer"*> [#uses=0]
18 @llvm.global_ctors = appending global [20 x { i32, void ()* }] [ { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZN62FLAG__foo_string_10FLAGS_E }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZN60FLAG__foo_bool_19FLAGS_E }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZNK5Bzh4Enum13is_contiguousEv }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZN62FLAG__foo_string_17FLAGS_E }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZN61FLAG__foo_int32_21FLAGS_E }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZN7ScannerC2Ev }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__Z11StripStringPSsPKcc }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZNK9__gnu_cxx4hashI11StringPieceEclERKS1_ }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZN8Hasher325ResetEj }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__Z25ACLRv }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZN61FLAG__foo_int64_25FLAGS_E }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZN61FLAG__foo_int32_7FLAGS_E }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZN62FLAG__foo_string_18FLAGS_E }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZN62FLAG__foo_string_17FLAGS_E }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZN61FLAG__foo_int32_25FLAGS_E }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_eventbuf }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZN61FLAG__foo_int32_26FLAGS_E }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZN62FLAG__foo_string_16FLAGS_E }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZN17InitializerC2EPKcS1_PFvvE }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__checker_bcad_variable } ] ; <[20 x { i32, void ()* }]*> [#uses=0]
18 @llvm.global_ctors = appending global [20 x { i32, void ()*, i8* }] [ { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I__ZN62FLAG__foo_string_10FLAGS_E, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I__ZN60FLAG__foo_bool_19FLAGS_E, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I__ZNK5Bzh4Enum13is_contiguousEv, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I__ZN62FLAG__foo_string_17FLAGS_E, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I__ZN61FLAG__foo_int32_21FLAGS_E, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I__ZN7ScannerC2Ev, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I__Z11StripStringPSsPKcc, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I__ZNK9__gnu_cxx4hashI11StringPieceEclERKS1_, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I__ZN8Hasher325ResetEj, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I__Z25ACLRv, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I__ZN61FLAG__foo_int64_25FLAGS_E, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I__ZN61FLAG__foo_int32_7FLAGS_E, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I__ZN62FLAG__foo_string_18FLAGS_E, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I__ZN62FLAG__foo_string_17FLAGS_E, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I__ZN61FLAG__foo_int32_25FLAGS_E, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I_eventbuf, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I__ZN61FLAG__foo_int32_26FLAGS_E, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I__ZN62FLAG__foo_string_16FLAGS_E, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I__ZN17InitializerC2EPKcS1_PFvvE, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I__checker_bcad_variable, i8* null } ] ; <[20 x { i32, void ()*, i8* }]*> [#uses=0]
1919
2020 declare void @_GLOBAL__I__ZN62FLAG__foo_string_10FLAGS_E()
2121
88 %"struct.std::_Rb_tree_node_base" = type { i32, %"struct.std::_Rb_tree_node_base"*, %"struct.std::_Rb_tree_node_base"*, %"struct.std::_Rb_tree_node_base"* }
99 %"struct.std::map,std::allocator > >" = type { %"struct.std::_Rb_tree,std::_Select1st >,std::less,std::allocator > >" }
1010 @someMap = global %"struct.std::map,std::allocator > >" zeroinitializer ; <%"struct.std::map,std::allocator > >"*> [#uses=1]
11 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [ { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_someMap } ] ; <[1 x { i32, void ()* }]*> [#uses=0]
12 @llvm.global_dtors = appending global [1 x { i32, void ()* }] [ { i32, void ()* } { i32 65535, void ()* @_GLOBAL__D_someMap } ] ; <[1 x { i32, void ()* }]*> [#uses=0]
11 @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [ { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I_someMap, i8* null } ] ; <[1 x { i32, void ()*, i8* }]*> [#uses=0]
12 @llvm.global_dtors = appending global [1 x { i32, void ()*, i8* }] [ { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__D_someMap, i8* null } ] ; <[1 x { i32, void ()*, i8* }]*> [#uses=0]
1313
1414 define void @_GLOBAL__I_someMap() {
1515 entry:
55
66 @SomeVar = weak_odr global i32 0
77
8 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [ { i32, void ()* } { i32 65535, void ()* @CTOR } ]
8 @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [ { i32, void ()*, i8* } { i32 65535, void ()* @CTOR, i8* null } ]
99
1010 define internal void @CTOR() {
1111 store i32 23, i32* @SomeVar
0 ; RUN: opt < %s -globalopt -disable-output
11
2 %0 = type { i32, void ()* }
2 %0 = type { i32, void ()*, i8* }
33 @llvm.global_ctors = appending global [0 x %0] zeroinitializer
44
11
22 ; CHECK: @tmp = local_unnamed_addr global i32 42
33
4 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_a }]
4 @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I_a, i8* null }]
55 @tmp = global i32 0
66
77 define i32 @TheAnswerToLifeTheUniverseAndEverything() {
9393 }
9494
9595 @llvm.global_ctors = appending constant
96 [6 x { i32, void ()* }]
97 [{ i32, void ()* } { i32 65535, void ()* @test1 },
98 { i32, void ()* } { i32 65535, void ()* @test2 },
99 { i32, void ()* } { i32 65535, void ()* @test3 },
100 { i32, void ()* } { i32 65535, void ()* @test4 },
101 { i32, void ()* } { i32 65535, void ()* @test5 },
102 { i32, void ()* } { i32 65535, void ()* @test6 }]
96 [6 x { i32, void ()*, i8* }]
97 [{ i32, void ()*, i8* } { i32 65535, void ()* @test1, i8* null },
98 { i32, void ()*, i8* } { i32 65535, void ()* @test2, i8* null },
99 { i32, void ()*, i8* } { i32 65535, void ()* @test3, i8* null },
100 { i32, void ()*, i8* } { i32 65535, void ()* @test4, i8* null },
101 { i32, void ()*, i8* } { i32 65535, void ()* @test5, i8* null },
102 { i32, void ()*, i8* } { i32 65535, void ()* @test6, i8* null }]
11 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32"
22 target triple = "i386-apple-darwin9.8"
33
4 %0 = type { i32, void ()* }
4 %0 = type { i32, void ()*, i8* }
55 %struct.btSimdScalar = type { %"union.btSimdScalar::$_14" }
66 %"union.btSimdScalar::$_14" = type { <4 x float> }
77
88 @_ZL6vTwist = global %struct.btSimdScalar zeroinitializer ; <%struct.btSimdScalar*> [#uses=1]
9 @llvm.global_ctors = appending global [1 x %0] [%0 { i32 65535, void ()* @_GLOBAL__I__ZN21btConeTwistConstraintC2Ev }] ; <[12 x %0]*> [#uses=0]
9 @llvm.global_ctors = appending global [1 x %0] [%0 { i32 65535, void ()* @_GLOBAL__I__ZN21btConeTwistConstraintC2Ev, i8* null }] ; <[12 x %0]*> [#uses=0]
1010
1111 define internal void @_GLOBAL__I__ZN21btConeTwistConstraintC2Ev() nounwind section "__TEXT,__StaticInit,regular,pure_instructions" {
1212 entry:
11 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
22 target triple = "x86_64-apple-darwin10.0.0"
33
4 %0 = type { i32, void ()* }
4 %0 = type { i32, void ()*, i8* }
55 %struct.foo = type { i32* }
66 %struct.bar = type { i128 }
77
99 @H = global i32 0, align 4
1010 @X = global %struct.foo zeroinitializer, align 8
1111 @X2 = global %struct.bar zeroinitializer, align 8
12 @llvm.global_ctors = appending global [2 x %0] [%0 { i32 65535, void ()* @init1 }, %0 { i32 65535, void ()* @init2 }]
12 @llvm.global_ctors = appending global [2 x %0] [%0 { i32 65535, void ()* @init1, i8* null }, %0 { i32 65535, void ()* @init2, i8* null }]
1313
1414 ; PR8710 - GlobalOpt shouldn't change the global's initializer to have this
1515 ; arbitrary constant expression, the code generator can't handle it.
55 ; CHECK: @H = local_unnamed_addr global i32 2
66 ; CHECK: @I = local_unnamed_addr global i32 2
77
8 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [ { i32, void ()* } { i32 65535, void ()* @CTOR } ]
8 @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [ { i32, void ()*, i8* } { i32 65535, void ()* @CTOR, i8* null } ]
99 @addr = external global i32
1010 @G = internal global [6 x [5 x i32]] zeroinitializer
1111 @H = global i32 80
0 ; RUN: opt < %s -S -passes='cgscc(inline),function(early-cse),globalopt' | FileCheck %s
11
2 %0 = type { i32, void ()* }
2 %0 = type { i32, void ()*, i8* }
33 %struct.A = type { i8 }
44 %struct.B = type { }
55
66 @a = global %struct.A zeroinitializer, align 1
77 @__dso_handle = external global i8*
8 @llvm.global_ctors = appending global [1 x %0] [%0 { i32 65535, void ()* @_GLOBAL__I_a }]
8 @llvm.global_ctors = appending global [1 x %0] [%0 { i32 65535, void ()* @_GLOBAL__I_a, i8* null }]
99
1010 ; CHECK-NOT: call i32 @__cxa_atexit
1111
88 @"\01L_OBJC_METH_VAR_NAME_40" = internal global [7 x i8] c"print:\00", section "__TEXT,__objc_methname,cstring_literals", align 1
99 @"\01L_OBJC_SELECTOR_REFERENCES_41" = internal externally_initialized global i8* getelementptr inbounds ([7 x i8], [7 x i8]* @"\01L_OBJC_METH_VAR_NAME_40", i32 0, i32 0), section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
1010
11 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_a }]
11 @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I_a, i8* null }]
1212 @llvm.used = appending global [2 x i8*] [i8* getelementptr inbounds ([7 x i8], [7 x i8]* @"\01L_OBJC_METH_VAR_NAME_40", i32 0, i32 0), i8* bitcast (i8** @"\01L_OBJC_SELECTOR_REFERENCES_41" to i8*)]
1313
1414 define internal void @__cxx_global_var_init() section "__TEXT,__StaticInit,regular,pure_instructions" {
55
66 declare void @llvm.sideeffect()
77
8 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [ { i32, void ()* } { i32 65535, void ()* @ctor } ]
8 @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [ { i32, void ()*, i8* } { i32 65535, void ()* @ctor, i8* null } ]
99 @G = global i32 0
1010
1111 define internal void @ctor() {
1212 }
1313
1414 @llvm.global_ctors = appending constant
15 [1 x { i32, void ()* }]
16 [ { i32, void ()* } { i32 65535, void ()* @ctor1 } ]
15 [1 x { i32, void ()*, i8* }]
16 [ { i32, void ()*, i8* } { i32 65535, void ()* @ctor1, i8* null } ]
1010 @tmp3 = global i32 0
1111 @ptrToTmp3 = global i32* null
1212
13 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_a }]
13 @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I_a, i8* null }]
1414
1515 define i32 @TheAnswerToLifeTheUniverseAndEverything() {
1616 ret i32 42
5151
5252
5353 @llvm.global_ctors = appending constant
54 [4 x { i32, void ()* }]
55 [ { i32, void ()* } { i32 65535, void ()* @ctor1 },
56 { i32, void ()* } { i32 65535, void ()* @ctor2 },
57 { i32, void ()* } { i32 65535, void ()* @ctor3 },
58 { i32, void ()* } { i32 65535, void ()* @ctor4 } ]
54 [4 x { i32, void ()*, i8* }]
55 [ { i32, void ()*, i8* } { i32 65535, void ()* @ctor1, i8* null },
56 { i32, void ()*, i8* } { i32 65535, void ()* @ctor2, i8* null },
57 { i32, void ()*, i8* } { i32 65535, void ()* @ctor3, i8* null },
58 { i32, void ()*, i8* } { i32 65535, void ()* @ctor4, i8* null } ]
33 ; Globalopt should be able to evaluate an invoke.
44 ; CHECK: @tmp = local_unnamed_addr global i32 1
55
6 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_a }]
6 @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I_a, i8* null }]
77 @tmp = global i32 0
88
99 define i32 @one() {
0 ; RUN: opt -globalopt -S < %s | FileCheck %s
11 ; PR10047
22
3 %0 = type { i32, void ()* }
3 %0 = type { i32, void ()*, i8* }
44 %struct.A = type { [100 x i32] }
55
66 ; CHECK: @a
77 @a = global %struct.A zeroinitializer, align 4
8 @llvm.global_ctors = appending global [2 x %0] [%0 { i32 65535, void ()* @_GLOBAL__I_a }, %0 { i32 65535, void ()* @_GLOBAL__I_b }]
8 @llvm.global_ctors = appending global [2 x %0] [%0 { i32 65535, void ()* @_GLOBAL__I_a, i8* null }, %0 { i32 65535, void ()* @_GLOBAL__I_b, i8* null }]
99
1010 declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i1) nounwind
1111
0 ; RUN: opt < %s -globalopt -S | FileCheck %s
11 ; CHECK-NOT: store
22
3 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [ { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__Z3foov } ] ; <[1 x { i32, void ()* }]*> [#uses=0]
3 @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [ { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I__Z3foov, i8* null } ] ; <[1 x { i32, void ()*, i8* }]*> [#uses=0]
44 @X.0 = internal global i32 undef ; [#uses=2]
55
66 define i32 @_Z3foov() {
0 ; RUN: opt -S -objc-arc-apelim < %s | FileCheck %s
11 ; rdar://10227311
22
3 @llvm.global_ctors = appending global [2 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_x }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_y }]
3 @llvm.global_ctors = appending global [2 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I_x, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I_y, i8* null }]
44
55 @x = global i32 0
66
11
22 ; See PR26774
33
4 @llvm.global_ctors = appending global [2 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_x }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_y }]
4 @llvm.global_ctors = appending global [2 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I_x, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I_y, i8* null }]
55
66 @x = global i32 0
77
88 ; BCA-NOT:
99
1010 ; CHECK: @llvm.global_ctors = appending global
11 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @f }]
11 @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @f, i8* null }]
1212
1313 ; CHECK: @g = internal global i8 42, !type !0
1414 @g = internal global i8 42, !type !0
0 ; RUN: not llvm-as %s -o /dev/null 2>&1 | FileCheck %s
1
2 @llvm.global_ctors = appending global [1 x { i32, void()* } ] [
3 { i32, void()* } { i32 65535, void ()* null }
4 ]
5 ; CHECK: the third field of the element type is mandatory, specify i8* null to migrate from the obsoleted 2-field form