[llvm] r231121 - Fix PR22762. When emitting a DWARF expression check whether this is the

Adrian Prantl aprantl at apple.com
Tue Mar 3 12:12:53 PST 2015


Author: adrian
Date: Tue Mar  3 14:12:52 2015
New Revision: 231121

URL: http://llvm.org/viewvc/llvm-project?rev=231121&view=rev
Log:
Fix PR22762. When emitting a DWARF expression check whether this is the
frame register before checking if there is a DWARF register number for it.

Thanks to H.J. Lu for diagnosing this and providing the testcase!

Added:
    llvm/trunk/test/DebugInfo/X86/frame-register.ll
Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp?rev=231121&r1=231120&r2=231121&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp Tue Mar  3 14:12:52 2015
@@ -66,17 +66,18 @@ void DwarfExpression::AddShr(unsigned Sh
 }
 
 bool DwarfExpression::AddMachineRegIndirect(unsigned MachineReg, int Offset) {
-  int DwarfReg = TRI.getDwarfRegNum(MachineReg, false);
-  if (DwarfReg < 0)
-    return false;
-
   if (isFrameRegister(MachineReg)) {
     // If variable offset is based in frame register then use fbreg.
     EmitOp(dwarf::DW_OP_fbreg);
     EmitSigned(Offset);
-  } else {
-    AddRegIndirect(DwarfReg, Offset);
+    return true;
   }
+
+  int DwarfReg = TRI.getDwarfRegNum(MachineReg, false);
+  if (DwarfReg < 0)
+    return false;
+
+  AddRegIndirect(DwarfReg, Offset);
   return true;
 }
 

Added: llvm/trunk/test/DebugInfo/X86/frame-register.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/frame-register.ll?rev=231121&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/frame-register.ll (added)
+++ llvm/trunk/test/DebugInfo/X86/frame-register.ll Tue Mar  3 14:12:52 2015
@@ -0,0 +1,60 @@
+; RUN: llc %s -filetype=obj -o - | llvm-dwarfdump --debug-dump=info - | FileCheck %s
+; CHECK: DW_TAG_variable
+;                                                      DW_OP_fbreg
+; CHECK-NEXT: DW_AT_location [DW_FORM_exprloc]      (<0x2> 91 00 )
+; CHECK-NEXT: DW_AT_name {{.*}}"i"
+
+target datalayout = "e-m:e-p:32:32-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-darwin"
+
+; Function Attrs: nounwind uwtable
+declare i32 @foo(i32 %i) #0
+
+; Function Attrs: nounwind readnone
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
+
+; Function Attrs: nounwind uwtable
+define i32 @main() #0 {
+entry:
+  %retval = alloca i32, align 4
+  %i = alloca i32, align 4
+  store i32 0, i32* %retval
+  call void @llvm.dbg.declare(metadata i32* %i, metadata !20, metadata !16), !dbg !21
+  store i32 20, i32* %i, align 4, !dbg !21
+  %0 = load i32, i32* %i, align 4, !dbg !22
+  %call = call i32 @foo(i32 %0), !dbg !23
+  ret i32 %call, !dbg !24
+}
+
+attributes #0 = { nounwind uwtable  }
+attributes #1 = { nounwind readnone }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!12, !13}
+!llvm.ident = !{!14}
+
+!0 = !MDCompileUnit(language: DW_LANG_C99, producer: "clang version 3.7.0", isOptimized: false, emissionKind: 1, file: !1, enums: !2, retainedTypes: !2, subprograms: !3, globals: !2, imports: !2)
+!1 = !MDFile(filename: "x.c", directory: "")
+!2 = !{}
+!3 = !{!4, !9}
+!4 = !MDSubprogram(name: "foo", line: 2, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: false, scopeLine: 3, file: !1, scope: !5, type: !6, function: i32 (i32)* @foo, variables: !2)
+!5 = !MDFile(filename: "x.c", directory: "")
+!6 = !MDSubroutineType(types: !7)
+!7 = !{!8, !8}
+!8 = !MDBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+!9 = !MDSubprogram(name: "main", line: 8, isLocal: false, isDefinition: true, isOptimized: false, scopeLine: 9, file: !1, scope: !5, type: !10, function: i32 ()* @main, variables: !2)
+!10 = !MDSubroutineType(types: !11)
+!11 = !{!8}
+!12 = !{i32 2, !"Dwarf Version", i32 4}
+!13 = !{i32 2, !"Debug Info Version", i32 3}
+!14 = !{!"clang version 3.7.0"}
+!15 = !MDLocalVariable(tag: DW_TAG_arg_variable, name: "i", line: 2, arg: 1, scope: !4, file: !5, type: !8)
+!16 = !MDExpression()
+!17 = !MDLocation(line: 2, column: 10, scope: !4)
+!18 = !MDLocation(line: 4, column: 10, scope: !4)
+!19 = !MDLocation(line: 4, column: 3, scope: !4)
+!20 = !MDLocalVariable(tag: DW_TAG_auto_variable, name: "i", line: 10, scope: !9, file: !5, type: !8)
+!21 = !MDLocation(line: 10, column: 7, scope: !9)
+!22 = !MDLocation(line: 11, column: 15, scope: !9)
+!23 = !MDLocation(line: 11, column: 10, scope: !9)
+!24 = !MDLocation(line: 11, column: 3, scope: !9)





More information about the llvm-commits mailing list