diff options
-rw-r--r-- | lib/Transforms/NaCl/FlattenGlobals.cpp | 6 | ||||
-rw-r--r-- | test/Transforms/NaCl/flatten-globals.ll | 20 |
2 files changed, 24 insertions, 2 deletions
diff --git a/lib/Transforms/NaCl/FlattenGlobals.cpp b/lib/Transforms/NaCl/FlattenGlobals.cpp index 86a46b5d30..77ce2b36b4 100644 --- a/lib/Transforms/NaCl/FlattenGlobals.cpp +++ b/lib/Transforms/NaCl/FlattenGlobals.cpp @@ -255,8 +255,8 @@ bool FlattenGlobals::runOnModule(Module &M) { continue; Modified = true; - uint64_t Size = DL.getTypeAllocSize( - Global->getType()->getPointerElementType()); + Type *GlobalType = Global->getType()->getPointerElementType(); + uint64_t Size = DL.getTypeAllocSize(GlobalType); Constant *NewInit; Type *NewType; if (Global->hasInitializer()) { @@ -281,6 +281,8 @@ bool FlattenGlobals::runOnModule(Module &M) { NewInit, "", Global, Global->getThreadLocalMode()); NewGlobal->copyAttributesFrom(Global); + if (NewGlobal->getAlignment() == 0) + NewGlobal->setAlignment(DL.getPrefTypeAlignment(GlobalType)); NewGlobal->setExternallyInitialized(Global->isExternallyInitialized()); NewGlobal->takeName(Global); Global->replaceAllUsesWith( diff --git a/test/Transforms/NaCl/flatten-globals.ll b/test/Transforms/NaCl/flatten-globals.ll index 4ac96d6a7c..938f11fec7 100644 --- a/test/Transforms/NaCl/flatten-globals.ll +++ b/test/Transforms/NaCl/flatten-globals.ll @@ -91,6 +91,26 @@ target datalayout = "p:32:32:32" ; CHECK: @aligned_var = global [4 x i8] c"\04\01\00\00", align 8 +; Check alignment handling + +@implicit_alignment_i32 = global i32 zeroinitializer +; CHECK: @implicit_alignment_i32 = global [4 x i8] zeroinitializer, align 4 + +@implicit_alignment_double = global double zeroinitializer +; CHECK: @implicit_alignment_double = global [8 x i8] zeroinitializer, align 8 + +; FlattenGlobals is not allowed to increase the alignment of the +; variable when an explicit section is specified (although PNaCl does +; not support this attribute). +@lower_alignment_section = global i32 0, section "mysection", align 1 +; CHECK: @lower_alignment_section = global [4 x i8] zeroinitializer, section "mysection", align 1 + +; FlattenGlobals could increase the alignment when no section is +; specified, but it does not. +@lower_alignment = global i32 0, align 1 +; CHECK: @lower_alignment = global [4 x i8] zeroinitializer, align 1 + + ; Check handling of global references @var1 = external global i32 |