[llvm] r323411 - [GlobalOpt] Emit fragments using field offsets from struct layout

Mikael Holmen via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 25 02:09:27 PST 2018


Author: uabelho
Date: Thu Jan 25 02:09:26 2018
New Revision: 323411

URL: http://llvm.org/viewvc/llvm-project?rev=323411&view=rev
Log:
[GlobalOpt] Emit fragments using field offsets from struct layout

Summary:
When creating the debug fragments for a SRA'd struct, use the fields'
offsets, taken from the struct layout, as the offsets for the resulting
fragments. This fixes an issue where GlobalOpt would emit fragments with
incorrect offsets for padded fields.

This should solve PR36016.

Patch by David Stenberg.

Reviewers: aprantl

Reviewed By: aprantl

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D42489

Modified:
    llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
    llvm/trunk/test/DebugInfo/Generic/global-sra-struct.ll

Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=323411&r1=323410&r2=323411&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Thu Jan 25 02:09:26 2018
@@ -483,7 +483,6 @@ static GlobalVariable *SRAGlobal(GlobalV
     StartAlignment = DL.getABITypeAlignment(GV->getType());
 
   if (StructType *STy = dyn_cast<StructType>(Ty)) {
-    uint64_t FragmentOffset = 0;
     unsigned NumElements = STy->getNumElements();
     NewGlobals.reserve(NumElements);
     const StructLayout &Layout = *DL.getStructLayout(STy);
@@ -509,10 +508,9 @@ static GlobalVariable *SRAGlobal(GlobalV
         NGV->setAlignment(NewAlign);
 
       // Copy over the debug info for the variable.
-      FragmentOffset = alignTo(FragmentOffset, NewAlign);
       uint64_t Size = DL.getTypeSizeInBits(NGV->getValueType());
-      transferSRADebugInfo(GV, NGV, FragmentOffset, Size, NumElements);
-      FragmentOffset += Size;
+      uint64_t FragmentOffsetInBits = Layout.getElementOffsetInBits(i);
+      transferSRADebugInfo(GV, NGV, FragmentOffsetInBits, Size, NumElements);
     }
   } else if (SequentialType *STy = dyn_cast<SequentialType>(Ty)) {
     unsigned NumElements = STy->getNumElements();

Modified: llvm/trunk/test/DebugInfo/Generic/global-sra-struct.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Generic/global-sra-struct.ll?rev=323411&r1=323410&r2=323411&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/Generic/global-sra-struct.ll (original)
+++ llvm/trunk/test/DebugInfo/Generic/global-sra-struct.ll Thu Jan 25 02:09:26 2018
@@ -24,7 +24,7 @@ target triple = "x86_64-apple-macosx10.1
 
 ; CHECK: ![[EL0]] = !DIGlobalVariableExpression(var: ![[VAR:.*]], expr: !DIExpression(DW_OP_LLVM_fragment, 0, 32))
 ; CHECK: ![[VAR]] = distinct !DIGlobalVariable(name: "static_struct"
-; CHECK: ![[EL1]] = !DIGlobalVariableExpression(var: ![[VAR]], expr: !DIExpression(DW_OP_LLVM_fragment, 32, 64))
+; CHECK: ![[EL1]] = !DIGlobalVariableExpression(var: ![[VAR]], expr: !DIExpression(DW_OP_LLVM_fragment, 64, 64))
 
 @static_struct = internal global %struct.mystruct zeroinitializer, align 8, !dbg !0
 




More information about the llvm-commits mailing list