File tree 2 files changed +24
-2
lines changed 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -255,8 +255,8 @@ bool FlattenGlobals::runOnModule(Module &M) {
255
255
continue ;
256
256
Modified = true ;
257
257
258
- uint64_t Size = DL. getTypeAllocSize (
259
- Global-> getType ()-> getPointerElementType () );
258
+ Type *GlobalType = Global-> getType ()-> getPointerElementType ();
259
+ uint64_t Size = DL. getTypeAllocSize (GlobalType );
260
260
Constant *NewInit;
261
261
Type *NewType;
262
262
if (Global->hasInitializer ()) {
@@ -281,6 +281,8 @@ bool FlattenGlobals::runOnModule(Module &M) {
281
281
NewInit, " " , Global,
282
282
Global->getThreadLocalMode ());
283
283
NewGlobal->copyAttributesFrom (Global);
284
+ if (NewGlobal->getAlignment () == 0 )
285
+ NewGlobal->setAlignment (DL.getPrefTypeAlignment (GlobalType));
284
286
NewGlobal->setExternallyInitialized (Global->isExternallyInitialized ());
285
287
NewGlobal->takeName (Global);
286
288
Global->replaceAllUsesWith (
Original file line number Diff line number Diff line change @@ -91,6 +91,26 @@ target datalayout = "p:32:32:32"
91
91
; CHECK: @aligned_var = global [4 x i8] c"\04\01\00\00", align 8
92
92
93
93
94
+ ; Check alignment handling
95
+
96
+ @implicit_alignment_i32 = global i32 zeroinitializer
97
+ ; CHECK: @implicit_alignment_i32 = global [4 x i8] zeroinitializer, align 4
98
+
99
+ @implicit_alignment_double = global double zeroinitializer
100
+ ; CHECK: @implicit_alignment_double = global [8 x i8] zeroinitializer, align 8
101
+
102
+ ; FlattenGlobals is not allowed to increase the alignment of the
103
+ ; variable when an explicit section is specified (although PNaCl does
104
+ ; not support this attribute).
105
+ @lower_alignment_section = global i32 0 , section "mysection" , align 1
106
+ ; CHECK: @lower_alignment_section = global [4 x i8] zeroinitializer, section "mysection", align 1
107
+
108
+ ; FlattenGlobals could increase the alignment when no section is
109
+ ; specified, but it does not.
110
+ @lower_alignment = global i32 0 , align 1
111
+ ; CHECK: @lower_alignment = global [4 x i8] zeroinitializer, align 1
112
+
113
+
94
114
; Check handling of global references
95
115
96
116
@var1 = external global i32
You can’t perform that action at this time.
0 commit comments