diff options
author | Adrian Prantl <aprantl@apple.com> | 2017-08-31 00:06:18 +0000 |
---|---|---|
committer | Adrian Prantl <aprantl@apple.com> | 2017-08-31 00:06:18 +0000 |
commit | 504b82d44b0e03ed6e56c16685ed5732cb16ecca (patch) | |
tree | 930c4f43a5184d9c73d76964b36102a4daca482e /llvm/lib/Transforms | |
parent | 53bb83d2506e21dd987f16daa1947adb7a4c2b6e (diff) | |
download | bcm5719-llvm-504b82d44b0e03ed6e56c16685ed5732cb16ecca.tar.gz bcm5719-llvm-504b82d44b0e03ed6e56c16685ed5732cb16ecca.zip |
Don't add a fragment expression when GlobalSRA splits up a single-member struct
Fixes PR34390.
https://bugs.llvm.org/show_bug.cgi?id=34390
llvm-svn: 312196
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/IPO/GlobalOpt.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp index 68d745f7ed3..ee8fdaebbda 100644 --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp @@ -420,15 +420,17 @@ static bool GlobalUsersSafeToSRA(GlobalValue *GV) { /// Copy over the debug info for a variable to its SRA replacements. static void transferSRADebugInfo(GlobalVariable *GV, GlobalVariable *NGV, uint64_t FragmentOffsetInBits, - uint64_t FragmentSizeInBits) { + uint64_t FragmentSizeInBits, + unsigned NumElements) { SmallVector<DIGlobalVariableExpression *, 1> GVs; GV->getDebugInfo(GVs); for (auto *GVE : GVs) { DIVariable *Var = GVE->getVariable(); DIExpression *Expr = GVE->getExpression(); - auto *NExpr = DIExpression::createFragmentExpression( - Expr, FragmentOffsetInBits, FragmentSizeInBits); - auto *NGVE = DIGlobalVariableExpression::get(GVE->getContext(), Var, NExpr); + if (NumElements > 1) + Expr = DIExpression::createFragmentExpression(Expr, FragmentOffsetInBits, + FragmentSizeInBits); + auto *NGVE = DIGlobalVariableExpression::get(GVE->getContext(), Var, Expr); NGV->addDebugInfo(NGVE); } } @@ -458,9 +460,10 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const DataLayout &DL) { if (StructType *STy = dyn_cast<StructType>(Ty)) { uint64_t FragmentOffset = 0; - NewGlobals.reserve(STy->getNumElements()); + unsigned NumElements = STy->getNumElements(); + NewGlobals.reserve(NumElements); const StructLayout &Layout = *DL.getStructLayout(STy); - for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) { + for (unsigned i = 0, e = NumElements; i != e; ++i) { Constant *In = Init->getAggregateElement(i); assert(In && "Couldn't get element of initializer?"); GlobalVariable *NGV = new GlobalVariable(STy->getElementType(i), false, @@ -484,7 +487,7 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const DataLayout &DL) { // Copy over the debug info for the variable. FragmentOffset = alignTo(FragmentOffset, NewAlign); uint64_t Size = DL.getTypeSizeInBits(NGV->getValueType()); - transferSRADebugInfo(GV, NGV, FragmentOffset, Size); + transferSRADebugInfo(GV, NGV, FragmentOffset, Size, NumElements); FragmentOffset += Size; } } else if (SequentialType *STy = dyn_cast<SequentialType>(Ty)) { @@ -516,8 +519,8 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const DataLayout &DL) { unsigned NewAlign = (unsigned)MinAlign(StartAlignment, EltSize*i); if (NewAlign > EltAlign) NGV->setAlignment(NewAlign); - - transferSRADebugInfo(GV, NGV, FragmentSizeInBits * i, FragmentSizeInBits); + transferSRADebugInfo(GV, NGV, FragmentSizeInBits * i, FragmentSizeInBits, + NumElements); } } |