[PATCH] D42489: [GlobalOpt] Emit fragments using field offsets from struct layout
David Stenberg via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 24 08:46:02 PST 2018
dstenb created this revision.
dstenb added a reviewer: aprantl.
Herald added a subscriber: llvm-commits.
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.
Repository:
rL LLVM
https://reviews.llvm.org/D42489
Files:
lib/Transforms/IPO/GlobalOpt.cpp
test/DebugInfo/Generic/global-sra-struct.ll
Index: test/DebugInfo/Generic/global-sra-struct.ll
===================================================================
--- test/DebugInfo/Generic/global-sra-struct.ll
+++ test/DebugInfo/Generic/global-sra-struct.ll
@@ -24,7 +24,7 @@
; 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
Index: lib/Transforms/IPO/GlobalOpt.cpp
===================================================================
--- lib/Transforms/IPO/GlobalOpt.cpp
+++ lib/Transforms/IPO/GlobalOpt.cpp
@@ -483,7 +483,6 @@
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 @@
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();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42489.131277.patch
Type: text/x-patch
Size: 1860 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180124/023cbf76/attachment.bin>
More information about the llvm-commits
mailing list