<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Thu, Aug 3, 2017 at 6:20 PM Adrian Prantl via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: adrian<br>
Date: Thu Aug  3 18:19:54 2017<br>
New Revision: 310014<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=310014&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=310014&view=rev</a><br>
Log:<br>
Teach GlobalSRA to update the debug info for split-up globals.<br>
<br>
This is similar to what we are doing in "regular" SROA and creates<br>
DW_OP_LLVM_fragment operations to describe the resulting variables.<br>
<br>
rdar://problem/33654891<br>
<br>
Added:<br>
    llvm/trunk/test/DebugInfo/Generic/global-sra-array.ll<br>
    llvm/trunk/test/DebugInfo/Generic/global-sra-struct.ll<br>
Modified:<br>
    llvm/trunk/include/llvm/IR/DIBuilder.h<br>
    llvm/trunk/lib/IR/DIBuilder.cpp<br>
    llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/IR/DIBuilder.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DIBuilder.h?rev=310014&r1=310013&r2=310014&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DIBuilder.h?rev=310014&r1=310013&r2=310014&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/IR/DIBuilder.h (original)<br>
+++ llvm/trunk/include/llvm/IR/DIBuilder.h Thu Aug  3 18:19:54 2017<br>
@@ -551,13 +551,17 @@ namespace llvm {<br>
     DIExpression *createExpression(ArrayRef<uint64_t> Addr = None);<br>
     DIExpression *createExpression(ArrayRef<int64_t> Addr);<br>
<br>
-    /// Create a descriptor to describe one part<br>
-    /// of aggregate variable that is fragmented across multiple Values.<br>
+    /// Create a descriptor to describe one part of an aggregate variable that<br>
+    /// is fragmented across multiple Values. The DW_OP_LLVM_fragment operation<br>
+    /// will be appended to the elements of \c Expr. If \c Expr already contains<br>
+    /// a \c DW_OP_LLVM_fragment \c OffsetInBits is interpreted as an offset<br>
+    /// into the existing fragment.<br>
     ///<br>
     /// \param OffsetInBits Offset of the piece in bits.<br>
     /// \param SizeInBits   Size of the piece in bits.<br>
     DIExpression *createFragmentExpression(unsigned OffsetInBits,<br>
-                                           unsigned SizeInBits);<br>
+                                           unsigned SizeInBits,<br>
+                                           const DIExpression *Expr = nullptr);<br>
<br>
     /// Create an expression for a variable that does not have an address, but<br>
     /// does have a constant value.<br>
<br>
Modified: llvm/trunk/lib/IR/DIBuilder.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DIBuilder.cpp?rev=310014&r1=310013&r2=310014&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DIBuilder.cpp?rev=310014&r1=310013&r2=310014&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/IR/DIBuilder.cpp (original)<br>
+++ llvm/trunk/lib/IR/DIBuilder.cpp Thu Aug  3 18:19:54 2017<br>
@@ -668,10 +668,31 @@ DIExpression *DIBuilder::createExpressio<br>
   return createExpression(Addr);<br>
 }<br>
<br>
-DIExpression *DIBuilder::createFragmentExpression(unsigned OffsetInBytes,<br>
-                                                  unsigned SizeInBytes) {<br>
-  uint64_t Addr[] = {dwarf::DW_OP_LLVM_fragment, OffsetInBytes, SizeInBytes};<br>
-  return DIExpression::get(VMContext, Addr);<br>
+DIExpression *DIBuilder::createFragmentExpression(unsigned OffsetInBits,<br>
+                                                  unsigned SizeInBits,<br>
+                                                  const DIExpression *Expr) {<br>
+  SmallVector<uint64_t, 8> Ops;<br>
+  // Copy over the expression, but leave off any trailing DW_OP_LLVM_fragment.<br>
+  if (Expr) {<br>
+    for (auto Op : Expr->expr_ops()) {<br>
+      if (Op.getOp() == dwarf::DW_OP_LLVM_fragment) {<br>
+        // Make the new offset point into the existing fragment.<br>
+        uint64_t FragmentOffsetInBits = Op.getArg(0);<br>
+        uint64_t FragmentSizeInBits = Op.getArg(1);<br>
+        assert((OffsetInBits + SizeInBits <= FragmentSizeInBits) &&<br>
+               "new fragment outside of original fragment");<br>
+        OffsetInBits += FragmentOffsetInBits;<br>
+        break;<br>
+      }<br>
+      Ops.push_back(Op.getOp());<br>
+      for (unsigned I = 0; I < Op.getNumArgs(); ++I)<br>
+        Ops.push_back(Op.getArg(I));<br>
+    }<br>
+  }<br>
+  Ops.push_back(dwarf::DW_OP_LLVM_fragment);<br>
+  Ops.push_back(OffsetInBits);<br>
+  Ops.push_back(SizeInBits);<br>
+  return DIExpression::get(VMContext, Ops);<br>
 }<br>
<br>
 template <class... Ts><br>
<br>
Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=310014&r1=310013&r2=310014&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=310014&r1=310013&r2=310014&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Thu Aug  3 18:19:54 2017<br>
@@ -27,7 +27,9 @@<br>
 #include "llvm/IR/CallingConv.h"<br>
 #include "llvm/IR/Constants.h"<br>
 #include "llvm/IR/DataLayout.h"<br>
+#include "llvm/IR/DebugInfoMetadata.h"<br>
 #include "llvm/IR/DerivedTypes.h"<br>
+#include "llvm/IR/DIBuilder.h"<br>
 #include "llvm/IR/Dominators.h"<br>
 #include "llvm/IR/GetElementPtrTypeIterator.h"<br>
 #include "llvm/IR/Instructions.h"<br>
@@ -419,6 +421,23 @@ static bool GlobalUsersSafeToSRA(GlobalV<br>
   return true;<br>
 }<br>
<br>
+/// Copy over the debug info for a variable to its SRA replacements.<br>
+static void transferSRADebugInfo(GlobalVariable *GV, GlobalVariable *NGV,<br>
+                                 uint64_t FragmentOffsetInBits,<br>
+                                 uint64_t FragmentSizeInBits) {<br>
+  DIBuilder DIB(*GV->getParent(), /*AllowUnresolved*/ false);<br>
+  SmallVector<DIGlobalVariableExpression *, 1> GVs;<br>
+  GV->getDebugInfo(GVs);<br>
+  for (auto *GVE : GVs) {<br>
+    DIVariable *Var = GVE->getVariable();<br>
+    DIExpression *Expr = GVE->getExpression();<br>
+    DIExpression *NExpr = DIB.createFragmentExpression(<br>
+        FragmentOffsetInBits, FragmentSizeInBits, Expr);<br>
+    auto *NGVE = DIGlobalVariableExpression::get(GVE->getContext(), Var, NExpr);<br>
+    NGV->addDebugInfo(NGVE);<br>
+  }<br>
+}<br>
+<br>
<br>
 /// Perform scalar replacement of aggregates on the specified global variable.<br>
 /// This opens the door for other optimizations by exposing the behavior of the<br>
@@ -443,6 +462,7 @@ static GlobalVariable *SRAGlobal(GlobalV<br>
     StartAlignment = DL.getABITypeAlignment(GV->getType());<br>
<br>
   if (StructType *STy = dyn_cast<StructType>(Ty)) {<br>
+    uint64_t FragmentOffset = 0;<br>
     NewGlobals.reserve(STy->getNumElements());<br>
     const StructLayout &Layout = *DL.getStructLayout(STy);<br>
     for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {<br>
@@ -465,15 +485,22 @@ static GlobalVariable *SRAGlobal(GlobalV<br>
       unsigned NewAlign = (unsigned)MinAlign(StartAlignment, FieldOffset);<br>
       if (NewAlign > DL.getABITypeAlignment(STy->getElementType(i)))<br>
         NGV->setAlignment(NewAlign);<br>
+<br>
+      // Copy over the debug info for the variable.<br>
+      FragmentOffset = alignTo(FragmentOffset, NewAlign);<br>
+      uint64_t Size = DL.getTypeSizeInBits(NGV->getValueType());<br>
+      transferSRADebugInfo(GV, NGV, FragmentOffset, Size);<br>
+      FragmentOffset += Size;<br>
     }<br>
   } else if (SequentialType *STy = dyn_cast<SequentialType>(Ty)) {<br>
     unsigned NumElements = STy->getNumElements();<br>
     if (NumElements > 16 && GV->hasNUsesOrMore(16))<br>
       return nullptr; // It's not worth it.<br>
     NewGlobals.reserve(NumElements);<br>
-<br>
-    uint64_t EltSize = DL.getTypeAllocSize(STy->getElementType());<br>
-    unsigned EltAlign = DL.getABITypeAlignment(STy->getElementType());<br>
+    auto ElTy = STy->getElementType();<br>
+    uint64_t EltSize = DL.getTypeAllocSize(ElTy);<br>
+    unsigned EltAlign = DL.getABITypeAlignment(ElTy);<br>
+    uint64_t FragmentSizeInBits = DL.getTypeSizeInBits(ElTy);<br>
     for (unsigned i = 0, e = NumElements; i != e; ++i) {<br>
       Constant *In = Init->getAggregateElement(i);<br>
       assert(In && "Couldn't get element of initializer?");<br>
@@ -494,6 +521,8 @@ static GlobalVariable *SRAGlobal(GlobalV<br>
       unsigned NewAlign = (unsigned)MinAlign(StartAlignment, EltSize*i);<br>
       if (NewAlign > EltAlign)<br>
         NGV->setAlignment(NewAlign);<br>
+<br>
+      transferSRADebugInfo(GV, NGV, FragmentSizeInBits * i, FragmentSizeInBits);<br>
     }<br>
   }<br>
<br>
<br>
Added: llvm/trunk/test/DebugInfo/Generic/global-sra-array.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Generic/global-sra-array.ll?rev=310014&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Generic/global-sra-array.ll?rev=310014&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/DebugInfo/Generic/global-sra-array.ll (added)<br>
+++ llvm/trunk/test/DebugInfo/Generic/global-sra-array.ll Thu Aug  3 18:19:54 2017<br>
@@ -0,0 +1,129 @@<br>
+; RUN: opt -S -globalopt < %s | FileCheck %s<br>
+source_filename = "test.c"<br>
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"<br>
+target triple = "x86_64-apple-macosx10.12.0"<br>
+<br>
+%struct.mystruct = type { i32, i64 }<br>
+; Generated at -Os from:<br>
+;<br>
+; static struct { int a; char b; } array[2];<br>
+; void __attribute__((nodebug)) foo(int in) { array[0].a = in; }<br>
+; void __attribute__((nodebug)) bar(int in) { array[1].a = in; }<br>
+; int main(int argc, char **argv)<br>
+; {<br>
+;   foo(argv[0][1]);<br>
+;   bar(argv[0][1]);<br>
+;   return array[0].a + array[1].a;<br>
+; }<br></blockquote><div><br></div><div>Just some ideas, maybe for future reference/out of curiosity in terms of how to make test cases most legible:<br><br>Might be easier if this wasn't 'main', but an arbitrary function with an integer parameter & return? (so there's no argv/argc)<br><br>Do foo and bar need to be called to make this work? Why? Presumably foo and bar could be called from other translation units and have the same affect?<br><br>Does the struct need to be a struct? I guess it probably does because this is SRA? (do the members need to be of different types (int/char)? why?)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+%struct.anon = type { i32, i8 }<br>
+<br>
+; This array is first split into two struct, which are then split into their<br>
+; elements, of which only .a survives.<br>
+@array = internal global [2 x %struct.anon] zeroinitializer, align 16, !dbg !0<br>
+; CHECK: @array.0.0 = internal unnamed_addr global i32 0, align 16, !dbg ![[EL0:.*]]<br>
+; CHECK: @array.1.0 = internal unnamed_addr global i32 0, align 8, !dbg ![[EL1:.*]]<br>
+;<br>
+; CHECK: ![[EL0]] = !DIGlobalVariableExpression(var: ![[VAR:.*]], expr: ![[EX1:.*]])<br>
+; CHECK: ![[VAR]] = distinct !DIGlobalVariable(name: "array"<br>
+; CHECK: ![[EX1]] = !DIExpression(DW_OP_LLVM_fragment, 0, 32)<br>
+; CHECK: ![[EL1]] = !DIGlobalVariableExpression(var: ![[VAR]], expr: ![[EX2:.*]])<br>
+; CHECK: ![[EX2]] = !DIExpression(DW_OP_LLVM_fragment, 64, 32)<br>
+<br>
+<br>
+; Function Attrs: nounwind optsize ssp uwtable<br>
+define void @foo(i32 %in) #0 {<br>
+entry:<br>
+  store i32 %in, i32* getelementptr inbounds ([2 x %struct.anon], [2 x %struct.anon]* @array, i64 0, i64 0, i32 0), align 16, !tbaa !20<br>
+  ret void<br>
+}<br>
+<br>
+; Function Attrs: nounwind optsize ssp uwtable<br>
+define void @bar(i32 %in) #0 {<br>
+entry:<br>
+  store i32 %in, i32* getelementptr inbounds ([2 x %struct.anon], [2 x %struct.anon]* @array, i64 0, i64 1, i32 0), align 8, !tbaa !20<br>
+  ret void<br>
+}<br>
+<br>
+; Function Attrs: nounwind optsize ssp uwtable<br>
+define i32 @main(i32 %argc, i8** %argv) #0 !dbg !25 {<br>
+entry:<br>
+  call void @llvm.dbg.value(metadata i32 %argc, metadata !31, metadata !33), !dbg !34<br>
+  call void @llvm.dbg.value(metadata i8** %argv, metadata !32, metadata !33), !dbg !35<br>
+  %0 = load i8*, i8** %argv, align 8, !dbg !36, !tbaa !37<br>
+  %arrayidx1 = getelementptr inbounds i8, i8* %0, i64 1, !dbg !36<br>
+  %1 = load i8, i8* %arrayidx1, align 1, !dbg !36, !tbaa !39<br>
+  %conv = sext i8 %1 to i32, !dbg !36<br>
+  call void @foo(i32 %conv) #2, !dbg !40<br>
+  %2 = load i8*, i8** %argv, align 8, !dbg !41, !tbaa !37<br>
+  %arrayidx3 = getelementptr inbounds i8, i8* %2, i64 1, !dbg !41<br>
+  %3 = load i8, i8* %arrayidx3, align 1, !dbg !41, !tbaa !39<br>
+  %conv4 = sext i8 %3 to i32, !dbg !41<br>
+  call void @bar(i32 %conv4) #2, !dbg !42<br>
+  %4 = load i32, i32* getelementptr inbounds ([2 x %struct.anon], [2 x %struct.anon]* @array, i64 0, i64 0, i32 0), align 16, !dbg !43, !tbaa !20<br>
+  %5 = load i32, i32* getelementptr inbounds ([2 x %struct.anon], [2 x %struct.anon]* @array, i64 0, i64 1, i32 0), align 8, !dbg !44, !tbaa !20<br>
+  %add = add nsw i32 %4, %5, !dbg !45<br>
+  ret i32 %add, !dbg !46<br>
+}<br>
+<br>
+; Function Attrs: nounwind readnone speculatable<br>
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1<br>
+<br>
+; Function Attrs: nounwind readnone speculatable<br>
+declare void @llvm.dbg.value(metadata, metadata, metadata) #1<br>
+<br>
+attributes #0 = { nounwind optsize ssp uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+fxsr,+mmx,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }<br>
+attributes #1 = { nounwind readnone speculatable }<br>
+attributes #2 = { optsize }<br>
+<br>
+!<a href="http://llvm.dbg.cu" rel="noreferrer" target="_blank">llvm.dbg.cu</a> = !{!2}<br>
+!llvm.module.flags = !{!15, !16, !17, !18}<br>
+!llvm.ident = !{!19}<br>
+<br>
+!0 = !DIGlobalVariableExpression(var: !1)<br>
+!1 = distinct !DIGlobalVariable(name: "array", scope: !2, file: !3, line: 1, type: !6, isLocal: true, isDefinition: true)<br>
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 6.0.0 (trunk 309960) (llvm/trunk 309961)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)<br>
+!3 = !DIFile(filename: "test.c", directory: "/")<br>
+!4 = !{}<br>
+!5 = !{!0}<br>
+!6 = !DICompositeType(tag: DW_TAG_array_type, baseType: !7, size: 128, elements: !13)<br>
+!7 = distinct !DICompositeType(tag: DW_TAG_structure_type, file: !3, line: 1, size: 64, elements: !8)<br>
+!8 = !{!9, !11}<br>
+!9 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !7, file: !3, line: 1, baseType: !10, size: 32)<br>
+!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)<br>
+!11 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !7, file: !3, line: 1, baseType: !12, size: 8, offset: 32)<br>
+!12 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)<br>
+!13 = !{!14}<br>
+!14 = !DISubrange(count: 2)<br>
+!15 = !{i32 2, !"Dwarf Version", i32 4}<br>
+!16 = !{i32 2, !"Debug Info Version", i32 3}<br>
+!17 = !{i32 1, !"wchar_size", i32 4}<br>
+!18 = !{i32 7, !"PIC Level", i32 2}<br>
+!19 = !{!"clang version 6.0.0 (trunk 309960) (llvm/trunk 309961)"}<br>
+!20 = !{!21, !22, i64 0}<br>
+!21 = !{!"", !22, i64 0, !23, i64 4}<br>
+!22 = !{!"int", !23, i64 0}<br>
+!23 = !{!"omnipotent char", !24, i64 0}<br>
+!24 = !{!"Simple C/C++ TBAA"}<br>
+!25 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 4, type: !26, isLocal: false, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: true, unit: !2, variables: !30)<br>
+!26 = !DISubroutineType(types: !27)<br>
+!27 = !{!10, !10, !28}<br>
+!28 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !29, size: 64)<br>
+!29 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)<br>
+!30 = !{!31, !32}<br>
+!31 = !DILocalVariable(name: "argc", arg: 1, scope: !25, file: !3, line: 4, type: !10)<br>
+!32 = !DILocalVariable(name: "argv", arg: 2, scope: !25, file: !3, line: 4, type: !28)<br>
+!33 = !DIExpression()<br>
+!34 = !DILocation(line: 4, column: 14, scope: !25)<br>
+!35 = !DILocation(line: 4, column: 27, scope: !25)<br>
+!36 = !DILocation(line: 6, column: 7, scope: !25)<br>
+!37 = !{!38, !38, i64 0}<br>
+!38 = !{!"any pointer", !23, i64 0}<br>
+!39 = !{!23, !23, i64 0}<br>
+!40 = !DILocation(line: 6, column: 3, scope: !25)<br>
+!41 = !DILocation(line: 7, column: 7, scope: !25)<br>
+!42 = !DILocation(line: 7, column: 3, scope: !25)<br>
+!43 = !DILocation(line: 8, column: 19, scope: !25)<br>
+!44 = !DILocation(line: 8, column: 32, scope: !25)<br>
+!45 = !DILocation(line: 8, column: 21, scope: !25)<br>
+!46 = !DILocation(line: 8, column: 3, scope: !25)<br>
<br>
Added: llvm/trunk/test/DebugInfo/Generic/global-sra-struct.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Generic/global-sra-struct.ll?rev=310014&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Generic/global-sra-struct.ll?rev=310014&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/DebugInfo/Generic/global-sra-struct.ll (added)<br>
+++ llvm/trunk/test/DebugInfo/Generic/global-sra-struct.ll Thu Aug  3 18:19:54 2017<br>
@@ -0,0 +1,132 @@<br>
+; RUN: opt -S -globalopt < %s | FileCheck %s<br>
+source_filename = "test.c"<br>
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"<br>
+target triple = "x86_64-apple-macosx10.12.0"<br>
+<br>
+%struct.mystruct = type { i32, i64 }<br>
+; Generated at -Os from:<br>
+;<br>
+; static struct mystruct {<br>
+;     int a;<br>
+;     long long int b;<br>
+; } static_struct;<br>
+; void __attribute__((nodebug)) foo(int in) { static_struct.a = in; }<br>
+; void __attribute__((nodebug)) bar(int in) { static_struct.b = in; }<br>
+; int main(int argc, char **argv)<br>
+; {<br>
+;     foo(argv[0][1]);<br>
+;     bar(argv[0][1]);<br>
+;     return static_struct.a + static_struct.b;<br>
+; }<br>
+<br>
+; CHECK: @static_struct.0 = internal unnamed_addr global i32 0, align 8, !dbg ![[EL0:.*]]<br>
+; CHECK: @static_struct.1 = internal unnamed_addr global i64 0, align 8, !dbg ![[EL1:.*]]<br>
+<br>
+; CHECK: ![[EL0]] = !DIGlobalVariableExpression(var: ![[VAR:.*]], expr: ![[EX1:.*]])<br>
+; CHECK: ![[VAR]] = distinct !DIGlobalVariable(name: "static_struct"<br>
+; CHECK: ![[EX1]] = !DIExpression(DW_OP_LLVM_fragment, 0, 32)<br>
+; CHECK: ![[EL1]] = !DIGlobalVariableExpression(var: ![[VAR]], expr: ![[EX2:.*]])<br>
+; CHECK: ![[EX2]] = !DIExpression(DW_OP_LLVM_fragment, 32, 64)<br>
+<br>
+@static_struct = internal global %struct.mystruct zeroinitializer, align 8, !dbg !0<br>
+<br>
+; Function Attrs: nounwind optsize ssp uwtable<br>
+define void @foo(i32 %in) #0 {<br>
+entry:<br>
+  store i32 %in, i32* getelementptr inbounds (%struct.mystruct, %struct.mystruct* @static_struct, i32 0, i32 0), align 8, !tbaa !17<br>
+  ret void<br>
+}<br>
+<br>
+; Function Attrs: nounwind optsize ssp uwtable<br>
+define void @bar(i32 %in) #0 {<br>
+entry:<br>
+  %conv = sext i32 %in to i64<br>
+  store i64 %conv, i64* getelementptr inbounds (%struct.mystruct, %struct.mystruct* @static_struct, i32 0, i32 1), align 8, !tbaa !23<br>
+  ret void<br>
+}<br>
+<br>
+; Function Attrs: nounwind optsize ssp uwtable<br>
+define i32 @main(i32 %argc, i8** %argv) #0 !dbg !24 {<br>
+entry:<br>
+  call void @llvm.dbg.value(metadata i32 %argc, metadata !31, metadata !33), !dbg !34<br>
+  call void @llvm.dbg.value(metadata i8** %argv, metadata !32, metadata !33), !dbg !35<br>
+  %0 = load i8*, i8** %argv, align 8, !dbg !36, !tbaa !37<br>
+  %arrayidx1 = getelementptr inbounds i8, i8* %0, i64 1, !dbg !36<br>
+  %1 = load i8, i8* %arrayidx1, align 1, !dbg !36, !tbaa !39<br>
+  %conv = sext i8 %1 to i32, !dbg !36<br>
+  call void @foo(i32 %conv) #2, !dbg !40<br>
+  %2 = load i8*, i8** %argv, align 8, !dbg !41, !tbaa !37<br>
+  %arrayidx3 = getelementptr inbounds i8, i8* %2, i64 1, !dbg !41<br>
+  %3 = load i8, i8* %arrayidx3, align 1, !dbg !41, !tbaa !39<br>
+  %conv4 = sext i8 %3 to i32, !dbg !41<br>
+  call void @bar(i32 %conv4) #2, !dbg !42<br>
+  %4 = load i32, i32* getelementptr inbounds (%struct.mystruct, %struct.mystruct* @static_struct, i32 0, i32 0), align 8, !dbg !43, !tbaa !17<br>
+  %conv5 = sext i32 %4 to i64, !dbg !44<br>
+  %5 = load i64, i64* getelementptr inbounds (%struct.mystruct, %struct.mystruct* @static_struct, i32 0, i32 1), align 8, !dbg !45, !tbaa !23<br>
+  %add = add nsw i64 %conv5, %5, !dbg !46<br>
+  %conv6 = trunc i64 %add to i32, !dbg !44<br>
+  ret i32 %conv6, !dbg !47<br>
+}<br>
+<br>
+; Function Attrs: nounwind readnone speculatable<br>
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1<br>
+<br>
+; Function Attrs: nounwind readnone speculatable<br>
+declare void @llvm.dbg.value(metadata, metadata, metadata) #1<br>
+<br>
+attributes #0 = { nounwind optsize ssp uwtable }<br>
+attributes #1 = { nounwind readnone speculatable }<br>
+attributes #2 = { optsize }<br>
+<br>
+!<a href="http://llvm.dbg.cu" rel="noreferrer" target="_blank">llvm.dbg.cu</a> = !{!2}<br>
+!llvm.module.flags = !{!12, !13, !14, !15}<br>
+!llvm.ident = !{!16}<br>
+<br>
+!0 = !DIGlobalVariableExpression(var: !1)<br>
+!1 = distinct !DIGlobalVariable(name: "static_struct", scope: !2, file: !3, line: 4, type: !6, isLocal: true, isDefinition: true)<br>
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 6.0.0 (trunk 309852) (llvm/trunk 309850)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)<br>
+!3 = !DIFile(filename: "test.c", directory: "/")<br>
+!4 = !{}<br>
+!5 = !{!0}<br>
+!6 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "mystruct", file: !3, line: 1, size: 128, elements: !7)<br>
+!7 = !{!8, !10}<br>
+!8 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !6, file: !3, line: 2, baseType: !9, size: 32)<br>
+!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)<br>
+!10 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !6, file: !3, line: 3, baseType: !11, size: 64, offset: 64)<br>
+!11 = !DIBasicType(name: "long long int", size: 64, encoding: DW_ATE_signed)<br>
+!12 = !{i32 2, !"Dwarf Version", i32 4}<br>
+!13 = !{i32 2, !"Debug Info Version", i32 3}<br>
+!14 = !{i32 1, !"wchar_size", i32 4}<br>
+!15 = !{i32 7, !"PIC Level", i32 2}<br>
+!16 = !{!"clang version 6.0.0 (trunk 309852) (llvm/trunk 309850)"}<br>
+!17 = !{!18, !19, i64 0}<br>
+!18 = !{!"mystruct", !19, i64 0, !22, i64 8}<br>
+!19 = !{!"int", !20, i64 0}<br>
+!20 = !{!"omnipotent char", !21, i64 0}<br>
+!21 = !{!"Simple C/C++ TBAA"}<br>
+!22 = !{!"long long", !20, i64 0}<br>
+!23 = !{!18, !22, i64 8}<br>
+!24 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 7, type: !25, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: true, unit: !2, variables: !30)<br>
+!25 = !DISubroutineType(types: !26)<br>
+!26 = !{!9, !9, !27}<br>
+!27 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !28, size: 64)<br>
+!28 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !29, size: 64)<br>
+!29 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)<br>
+!30 = !{!31, !32}<br>
+!31 = !DILocalVariable(name: "argc", arg: 1, scope: !24, file: !3, line: 7, type: !9)<br>
+!32 = !DILocalVariable(name: "argv", arg: 2, scope: !24, file: !3, line: 7, type: !27)<br>
+!33 = !DIExpression()<br>
+!34 = !DILocation(line: 7, column: 14, scope: !24)<br>
+!35 = !DILocation(line: 7, column: 27, scope: !24)<br>
+!36 = !DILocation(line: 9, column: 9, scope: !24)<br>
+!37 = !{!38, !38, i64 0}<br>
+!38 = !{!"any pointer", !20, i64 0}<br>
+!39 = !{!20, !20, i64 0}<br>
+!40 = !DILocation(line: 9, column: 5, scope: !24)<br>
+!41 = !DILocation(line: 10, column: 9, scope: !24)<br>
+!42 = !DILocation(line: 10, column: 5, scope: !24)<br>
+!43 = !DILocation(line: 11, column: 26, scope: !24)<br>
+!44 = !DILocation(line: 11, column: 12, scope: !24)<br>
+!45 = !DILocation(line: 11, column: 44, scope: !24)<br>
+!46 = !DILocation(line: 11, column: 28, scope: !24)<br>
+!47 = !DILocation(line: 11, column: 5, scope: !24)<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div>