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(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(Ty)) { unsigned NumElements = STy->getNumElements(); 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