<div dir="ltr"><div class="gmail_extra">Looks like this change breaks debug info under certain conditions. Here's a reproducer (sorry, but I wasn't able to quickly generate one without gtest):</div><div class="gmail_extra">
<br></div><div class="gmail_extra"><div class="gmail_extra">$ cat tmp/dbginfo/inl.cc</div><div class="gmail_extra">#include "gtest/gtest.h"</div><div class="gmail_extra">#include <stdio.h></div><div class="gmail_extra">
<br></div><div class="gmail_extra">void test(char x) {</div><div class="gmail_extra">  if (x)</div><div class="gmail_extra">    printf("good\n");</div><div class="gmail_extra">}</div><div class="gmail_extra"><br>
</div><div class="gmail_extra">TEST(Foo, foo) {</div><div class="gmail_extra">  char *x = new char[8];</div><div class="gmail_extra">  fprintf(stderr, "x: %p\n", x);</div><div class="gmail_extra">  test(x[1]);</div>
<div class="gmail_extra">}</div><div class="gmail_extra"><br></div><div class="gmail_extra">$ ./bin/clang++ -std=c++11 -O2 -gline-tables-only -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -I /llvm_build/include -I /llvm/utils/unittest/googletest/include -I /llvm/include /llvm_build/lib/libgtest_main.a llvm_build/lib/libgtest.a /llvm_build/lib/libLLVMSupport.a -lcurses -lpthread -ldl tmp/dbginfo/inl.cc<br>
</div><div class="gmail_extra"><br></div><div class="gmail_extra">invocation of test() gets inlined in Foo_foo_Test::TestBody(). However, there is no sign of DW_TAG_inlined_subroutine in the debug info:</div><div class="gmail_extra">
<br></div><div class="gmail_extra">$ readelf -wi a.out<br></div><div class="gmail_extra"><...></div><div class="gmail_extra"> <1><46>: Abbrev Number: 3 (DW_TAG_subprogram)<br></div><div class="gmail_extra">
<div class="gmail_extra">    <47>   DW_AT_name        : (indirect string, offset: 0x83): TestBody        </div><div class="gmail_extra">    <4b>   DW_AT_decl_file   : 2        </div><div class="gmail_extra">    <4c>   DW_AT_decl_line   : 9        </div>
<div class="gmail_extra">    <4d>   DW_AT_external    : 1        </div><div class="gmail_extra">    <4d>   DW_AT_accessibility: 1       (public)</div><div class="gmail_extra">    <4e>   DW_AT_low_pc      : 0x457b50 </div>
<div class="gmail_extra">    <56>   DW_AT_high_pc     : 0x37     </div><div class="gmail_extra">    <5a>   DW_AT_frame_base  : 1 byte block: 57         (DW_OP_reg7 (rsp))</div><div class="gmail_extra">    <5c>   Unknown AT value: 3fe7: 1  </div>
<div class="gmail_extra"><div class="gmail_extra"> <1><5c>: Abbrev Number: 4 (DW_TAG_subprogram)</div><div class="gmail_extra">    <5d>   DW_AT_name        : (indirect string, offset: 0x8c): Setup   </div>
<div><...></div></div></div></div><div class="gmail_extra"><br></div><div class="gmail_extra">This happens both for "-g" and for "-gline-tables-only". Any idea why this might happen?</div><div class="gmail_extra">
<br><div class="gmail_quote">On Sun, May 11, 2014 at 11:12 AM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Author: dblaikie<br>
Date: Sun May 11 13:12:17 2014<br>
New Revision: 208506<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=208506&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=208506&view=rev</a><br>
Log:<br>
DebugInfo: Include lexical scopes in inlined subroutines.<br>
<br>
Added:<br>
    llvm/trunk/test/DebugInfo/inline-scopes.ll<br>
Modified:<br>
    llvm/trunk/include/llvm/ADT/STLExtras.h<br>
    llvm/trunk/include/llvm/CodeGen/LexicalScopes.h<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp<br>
    llvm/trunk/lib/CodeGen/LexicalScopes.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/ADT/STLExtras.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/STLExtras.h?rev=208506&r1=208505&r2=208506&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/STLExtras.h?rev=208506&r1=208505&r2=208506&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/include/llvm/ADT/STLExtras.h (original)<br>
+++ llvm/trunk/include/llvm/ADT/STLExtras.h Sun May 11 13:12:17 2014<br>
@@ -530,6 +530,13 @@ make_unique(size_t n) {<br>
<br>
 #endif<br>
<br>
+template<typename First, typename Second><br>
+struct pair_hash {<br>
+  size_t operator()(const std::pair<First, Second> &P) const {<br>
+    return std::hash<First>()(P.first) * 31 + std::hash<Second>()(P.second);<br>
+  }<br>
+};<br>
+<br>
 } // End llvm namespace<br>
<br>
 #endif<br>
<br>
Modified: llvm/trunk/include/llvm/CodeGen/LexicalScopes.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/LexicalScopes.h?rev=208506&r1=208505&r2=208506&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/LexicalScopes.h?rev=208506&r1=208505&r2=208506&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/include/llvm/CodeGen/LexicalScopes.h (original)<br>
+++ llvm/trunk/include/llvm/CodeGen/LexicalScopes.h Sun May 11 13:12:17 2014<br>
@@ -21,6 +21,7 @@<br>
 #include "llvm/ADT/DenseMap.h"<br>
 #include "llvm/ADT/SmallPtrSet.h"<br>
 #include "llvm/ADT/SmallVector.h"<br>
+#include "llvm/ADT/STLExtras.h"<br>
 #include "llvm/IR/DebugLoc.h"<br>
 #include "llvm/IR/Metadata.h"<br>
 #include "llvm/IR/ValueHandle.h"<br>
@@ -185,9 +186,7 @@ public:<br>
<br>
   /// findInlinedScope - Find an inlined scope for the given DebugLoc or return<br>
   /// NULL.<br>
-  LexicalScope *findInlinedScope(DebugLoc DL) {<br>
-    return InlinedLexicalScopeMap.lookup(DL);<br>
-  }<br>
+  LexicalScope *findInlinedScope(DebugLoc DL);<br>
<br>
   /// findLexicalScope - Find regular lexical scope or return null.<br>
   LexicalScope *findLexicalScope(const MDNode *N) {<br>
@@ -230,7 +229,9 @@ private:<br>
<br>
   /// InlinedLexicalScopeMap - Tracks inlined function scopes in current<br>
   /// function.<br>
-  DenseMap<DebugLoc, LexicalScope *> InlinedLexicalScopeMap;<br>
+  std::unordered_map<std::pair<const MDNode *, const MDNode *>, LexicalScope,<br>
+                     pair_hash<const MDNode *, const MDNode *>><br>
+  InlinedLexicalScopeMap;<br>
<br>
   /// AbstractScopeMap - These scopes are  not included LexicalScopeMap.<br>
   // Use an unordered_map to ensure value pointer validity over insertion.<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=208506&r1=208505&r2=208506&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=208506&r1=208505&r2=208506&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Sun May 11 13:12:17 2014<br>
@@ -621,7 +621,7 @@ std::unique_ptr<DIE> DwarfDebug::constru<br>
   // avoid creating un-used children then removing them later when we find out<br>
   // the scope DIE is null.<br>
   std::unique_ptr<DIE> ScopeDIE;<br>
-  if (Scope->getInlinedAt()) {<br>
+  if (DS.getContext() && DS.isSubprogram()) {<br>
     ScopeDIE = constructInlinedScopeDIE(TheCU, Scope);<br>
     if (!ScopeDIE)<br>
       return nullptr;<br>
@@ -1212,10 +1212,12 @@ DwarfDebug::collectVariableInfo(SmallPtr<br>
     if (DV.getTag() == dwarf::DW_TAG_arg_variable &&<br>
         DISubprogram(DV.getContext()).describes(CurFn->getFunction()))<br>
       Scope = LScopes.getCurrentFunctionScope();<br>
-    else if (MDNode *IA = DV.getInlinedAt())<br>
-      Scope = LScopes.findInlinedScope(DebugLoc::getFromDILocation(IA));<br>
-    else<br>
-      Scope = LScopes.findLexicalScope(cast<MDNode>(DV->getOperand(1)));<br>
+    else if (MDNode *IA = DV.getInlinedAt()) {<br>
+      DebugLoc DL = DebugLoc::getFromDILocation(IA);<br>
+      Scope = LScopes.findInlinedScope(DebugLoc::get(<br>
+          DL.getLine(), DL.getCol(), DV.getContext(), IA));<br>
+    } else<br>
+      Scope = LScopes.findLexicalScope(DV.getContext());<br>
     // If variable scope is not found then skip this variable.<br>
     if (!Scope)<br>
       continue;<br>
<br>
Modified: llvm/trunk/lib/CodeGen/LexicalScopes.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LexicalScopes.cpp?rev=208506&r1=208505&r2=208506&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LexicalScopes.cpp?rev=208506&r1=208505&r2=208506&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/lib/CodeGen/LexicalScopes.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/LexicalScopes.cpp Sun May 11 13:12:17 2014<br>
@@ -104,6 +104,14 @@ void LexicalScopes::extractLexicalScopes<br>
   }<br>
 }<br>
<br>
+LexicalScope *LexicalScopes::findInlinedScope(DebugLoc DL) {<br>
+  MDNode *Scope = nullptr;<br>
+  MDNode *IA = nullptr;<br>
+  DL.getScopeAndInlinedAt(Scope, IA, MF->getFunction()->getContext());<br>
+  auto I = InlinedLexicalScopeMap.find(std::make_pair(Scope, IA));<br>
+  return I != InlinedLexicalScopeMap.end() ? &I->second : nullptr;<br>
+}<br>
+<br>
 /// findLexicalScope - Find lexical scope, either regular or inlined, for the<br>
 /// given DebugLoc. Return NULL if not found.<br>
 LexicalScope *LexicalScopes::findLexicalScope(DebugLoc DL) {<br>
@@ -119,8 +127,10 @@ LexicalScope *LexicalScopes::findLexical<br>
   if (D.isLexicalBlockFile())<br>
     Scope = DILexicalBlockFile(Scope).getScope();<br>
<br>
-  if (IA)<br>
-    return InlinedLexicalScopeMap.lookup(DebugLoc::getFromDILocation(IA));<br>
+  if (IA) {<br>
+    auto I = InlinedLexicalScopeMap.find(std::make_pair(Scope, IA));<br>
+    return I != InlinedLexicalScopeMap.end() ? &I->second : nullptr;<br>
+  }<br>
   return findLexicalScope(Scope);<br>
 }<br>
<br>
@@ -170,21 +180,27 @@ LexicalScope *LexicalScopes::getOrCreate<br>
 }<br>
<br>
 /// getOrCreateInlinedScope - Find or create an inlined lexical scope.<br>
-LexicalScope *LexicalScopes::getOrCreateInlinedScope(MDNode *Scope,<br>
+LexicalScope *LexicalScopes::getOrCreateInlinedScope(MDNode *ScopeNode,<br>
                                                      MDNode *InlinedAt) {<br>
-  auto I = LexicalScopeMap.find(InlinedAt);<br>
-  if (I != LexicalScopeMap.end())<br>
+  std::pair<const MDNode*, const MDNode*> P(ScopeNode, InlinedAt);<br>
+  auto I = InlinedLexicalScopeMap.find(P);<br>
+  if (I != InlinedLexicalScopeMap.end())<br>
     return &I->second;<br>
<br>
-  DebugLoc InlinedLoc = DebugLoc::getFromDILocation(InlinedAt);<br>
+  LexicalScope *Parent;<br>
+  DILexicalBlock Scope(ScopeNode);<br>
+  if (Scope.isLexicalBlock()) {<br>
+    DILexicalBlock PB(Scope.getContext());<br>
+    Parent = getOrCreateInlinedScope(PB, InlinedAt);<br>
+  } else<br>
+    Parent = getOrCreateLexicalScope(DebugLoc::getFromDILocation(InlinedAt));<br>
+<br>
   // FIXME: Use forward_as_tuple instead of make_tuple, once MSVC2012<br>
   // compatibility is no longer required.<br>
-  I = LexicalScopeMap.emplace(<br>
-                          std::piecewise_construct, std::make_tuple(InlinedAt),<br>
-                          std::make_tuple(getOrCreateLexicalScope(InlinedLoc),<br>
-                                          DIDescriptor(Scope), InlinedAt,<br>
-                                          false)).first;<br>
-  InlinedLexicalScopeMap[InlinedLoc] = &I->second;<br>
+  I = InlinedLexicalScopeMap.emplace(std::piecewise_construct,<br>
+                                     std::make_tuple(P),<br>
+                                     std::make_tuple(Parent, Scope, InlinedAt,<br>
+                                                     false)).first;<br>
   return &I->second;<br>
 }<br>
<br>
<br>
Added: llvm/trunk/test/DebugInfo/inline-scopes.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/inline-scopes.ll?rev=208506&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/inline-scopes.ll?rev=208506&view=auto</a><br>

==============================================================================<br>
--- llvm/trunk/test/DebugInfo/inline-scopes.ll (added)<br>
+++ llvm/trunk/test/DebugInfo/inline-scopes.ll Sun May 11 13:12:17 2014<br>
@@ -0,0 +1,83 @@<br>
+; REQUIRES: object-emission<br>
+<br>
+; RUN: %llc_dwarf -O0 -filetype=obj < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s<br>
+<br>
+; bool f1();<br>
+; inline __attribute__((always_inline))<br>
+; int f() {<br>
+;   if (bool b = f1())<br>
+;     return 1;<br>
+;   return 2;<br>
+; }<br>
+;<br>
+; int main() {<br>
+;   f();<br>
+; }<br>
+<br>
+; Ensure that lexical_blocks within inlined_subroutines are preserved/emitted.<br>
+; CHECK: DW_TAG_inlined_subroutine<br>
+; CHECK-NOT: DW_TAG<br>
+; CHECK: DW_TAG_lexical_block<br>
+; CHECK: DW_TAG_variable<br>
+<br>
+; Function Attrs: uwtable<br>
+define i32 @main() #0 {<br>
+entry:<br>
+  %retval.i = alloca i32, align 4<br>
+  %b.i = alloca i8, align 1<br>
+  call void @llvm.dbg.declare(metadata !{i8* %b.i}, metadata !13), !dbg !16<br>
+  %call.i = call zeroext i1 @_Z2f1v(), !dbg !16<br>
+  %frombool.i = zext i1 %call.i to i8, !dbg !16<br>
+  store i8 %frombool.i, i8* %b.i, align 1, !dbg !16<br>
+  %0 = load i8* %b.i, align 1, !dbg !16<br>
+  %tobool.i = trunc i8 %0 to i1, !dbg !16<br>
+  br i1 %tobool.i, label %if.then.i, label %if.end.i, !dbg !16<br>
+<br>
+if.then.i:                                        ; preds = %entry<br>
+  store i32 1, i32* %retval.i, !dbg !18<br>
+  br label %_Z1fv.exit, !dbg !18<br>
+<br>
+if.end.i:                                         ; preds = %entry<br>
+  store i32 2, i32* %retval.i, !dbg !19<br>
+  br label %_Z1fv.exit, !dbg !19<br>
+<br>
+_Z1fv.exit:                                       ; preds = %if.then.i, %if.end.i<br>
+  %1 = load i32* %retval.i, !dbg !20<br>
+  ret i32 0, !dbg !21<br>
+}<br>
+<br>
+; Function Attrs: nounwind readnone<br>
+declare void @llvm.dbg.declare(metadata, metadata) #1<br>
+<br>
+declare zeroext i1 @_Z2f1v() #2<br>
+<br>
+attributes #0 = { uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }<br>

+attributes #1 = { nounwind readnone }<br>
+attributes #2 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }<br>

+<br>
+!<a href="http://llvm.dbg.cu" target="_blank">llvm.dbg.cu</a> = !{!0}<br>
+!llvm.module.flags = !{!10, !11}<br>
+!llvm.ident = !{!12}<br>
+<br>
+!0 = metadata !{i32 786449, metadata !1, i32 4, metadata !"clang version 3.5.0 ", i1 false, metadata !"", i32 0, metadata !2, metadata !2, metadata !3, metadata !2, metadata !2, metadata !"", i32 1} ; [ DW_TAG_compile_unit ] [/tmp/dbginfo/inline-scopes.cpp] [DW_LANG_C_plus_plus]<br>

+!1 = metadata !{metadata !"inline-scopes.cpp", metadata !"/tmp/dbginfo"}<br>
+!2 = metadata !{}<br>
+!3 = metadata !{metadata !4, metadata !9}<br>
+!4 = metadata !{i32 786478, metadata !1, metadata !5, metadata !"main", metadata !"main", metadata !"", i32 9, metadata !6, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, i32 ()* @main, null, null, metadata !2, i32 9} ; [ DW_TAG_subprogram ] [line 9] [def] [main]<br>

+!5 = metadata !{i32 786473, metadata !1}          ; [ DW_TAG_file_type ] [/tmp/dbginfo/inline-scopes.cpp]<br>
+!6 = metadata !{i32 786453, i32 0, null, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !7, i32 0, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]<br>

+!7 = metadata !{metadata !8}<br>
+!8 = metadata !{i32 786468, null, null, metadata !"int", i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ] [int] [line 0, size 32, align 32, offset 0, enc DW_ATE_signed]<br>
+!9 = metadata !{i32 786478, metadata !1, metadata !5, metadata !"f", metadata !"f", metadata !"_Z1fv", i32 3, metadata !6, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, null, null, null, metadata !2, i32 3} ; [ DW_TAG_subprogram ] [line 3] [def] [f]<br>

+!10 = metadata !{i32 2, metadata !"Dwarf Version", i32 4}<br>
+!11 = metadata !{i32 1, metadata !"Debug Info Version", i32 1}<br>
+!12 = metadata !{metadata !"clang version 3.5.0 "}<br>
+!13 = metadata !{i32 786688, metadata !14, metadata !"b", metadata !5, i32 4, metadata !15, i32 0, i32 0} ; [ DW_TAG_auto_variable ] [b] [line 4]<br>
+!14 = metadata !{i32 786443, metadata !1, metadata !9, i32 4, i32 0, i32 0, i32 0} ; [ DW_TAG_lexical_block ] [/tmp/dbginfo/inline-scopes.cpp]<br>
+!15 = metadata !{i32 786468, null, null, metadata !"bool", i32 0, i64 8, i64 8, i64 0, i32 0, i32 2} ; [ DW_TAG_base_type ] [bool] [line 0, size 8, align 8, offset 0, enc DW_ATE_boolean]<br>
+!16 = metadata !{i32 4, i32 0, metadata !14, metadata !17}<br>
+!17 = metadata !{i32 10, i32 0, metadata !4, null}<br>
+!18 = metadata !{i32 5, i32 0, metadata !14, metadata !17}<br>
+!19 = metadata !{i32 6, i32 0, metadata !9, metadata !17}<br>
+!20 = metadata !{i32 7, i32 0, metadata !9, metadata !17}<br>
+!21 = metadata !{i32 11, i32 0, metadata !4, null}<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr"><div>Alexey Samsonov, Mountain View, CA</div></div>
</div></div>