From f4a702c079674120bbc95c3474602334274c6046 Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Mon, 9 Jun 2014 21:53:47 +0000 Subject: Generate better location ranges for some register-described variables. Don't terminate location ranges for register-described variables at the end of machine basic block if this register is never modified in the function body, except for the prologue and epilogue. Prologue location is guessed by FrameSetup flags on MachineInstructions, while epilogue location is deduced from debug locations of instructions in the basic blocks ending with return instructions. This patch is mostly targeted to fix non-trivial debug locations for variables addressed via stack and frame pointers. It is not really a generic fix. We can still produce poor debug info for register-described variables if this register *is* modified somewhere in the function, but in unrelated places. This might be the case for the debug info in optimized binaries (e.g. for local variables in inlined functions). LiveDebugVariables pass in CodeGen attempts to fix this problem by adjusting DBG_VALUE instructions, but this pass is tied to greedy register allocator, which is used in optimized builds only. Proper fix would likely involve generalizing LiveDebugVariables to all register allocators. See more discussion in http://reviews.llvm.org/D3933 review thread. I'm proceeding with this patch to fix immediate severe problems and important cases, e.g. fix completely broken debug info with AddressSanitizer and fix PR19307 (missing debug info for by-value std::string arguments). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210492 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/DebugInfo/X86/debug-loc-asan.ll | 186 +++++++++++++++++++++++++++++++++ test/DebugInfo/X86/debug-loc-offset.ll | 132 ++++++++++++++--------- test/DebugInfo/X86/pr19307.ll | 147 ++++++++++++++++++++++++++ 3 files changed, 417 insertions(+), 48 deletions(-) create mode 100644 test/DebugInfo/X86/debug-loc-asan.ll create mode 100644 test/DebugInfo/X86/pr19307.ll (limited to 'test/DebugInfo/X86') diff --git a/test/DebugInfo/X86/debug-loc-asan.ll b/test/DebugInfo/X86/debug-loc-asan.ll new file mode 100644 index 0000000000..5f201ad163 --- /dev/null +++ b/test/DebugInfo/X86/debug-loc-asan.ll @@ -0,0 +1,186 @@ +; RUN: llc -O0 -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s + +; Verify that we have correct debug info for local variables in code +; instrumented with AddressSanitizer. + +; Generated from the source file test.cc: +; int bar(int y) { +; return y + 2; +; } +; with "clang++ -S -emit-llvm -fsanitize=address -O0 -g test.cc" + +; First, argument variable "y" resides in %rdi: +; CHECK: DEBUG_VALUE: bar:y <- RDI + +; Then its address is stored in a location on a stack: +; CHECK: movq %rdi, [[OFFSET:[0-9]+]](%rsp) +; CHECK-NEXT: [[START_LABEL:.Ltmp[0-9]+]] +; CHECK-NEXT: DEBUG_VALUE: bar:y <- [RSP+[[OFFSET]]] +; This location should be valid until the end of the function. + +; CHECK: .Ldebug_loc{{[0-9]+}}: +; We expect two location ranges for the variable. + +; First, it is stored in %rdi: +; CHECK: .Lset{{[0-9]+}} = .Lfunc_begin0-.Lfunc_begin0 +; CHECK-NEXT: .quad .Lset{{[0-9]+}} +; CHECK-NEXT: .Lset{{[0-9]+}} = [[START_LABEL]]-.Lfunc_begin0 +; CHECK-NEXT: .quad .Lset{{[0-9]+}} +; CHECK: DW_OP_reg5 + +; Then it's addressed via %rsp: +; CHECK: .Lset{{[0-9]+}} = [[START_LABEL]]-.Lfunc_begin0 +; CHECK-NEXT: .quad .Lset{{[0-9]+}} +; CHECK-NEXT: .Lset{{[0-9]+}} = .Lfunc_end0-.Lfunc_begin0 +; CHECK-NEXT: .quad .Lset{{[0-9]+}} +; CHECK: DW_OP_breg7 +; CHECK-NEXT: [[OFFSET]] +; CHECK: DW_OP_deref + +; ModuleID = 'test.cc' +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 1, void ()* @asan.module_ctor }] +@__asan_option_detect_stack_use_after_return = external global i32 +@__asan_gen_ = private unnamed_addr constant [16 x i8] c"1 32 4 6 y.addr\00", align 1 + +; Function Attrs: nounwind sanitize_address uwtable +define i32 @_Z3bari(i32 %y) #0 { +entry: + %MyAlloca = alloca [64 x i8], align 32 + %0 = ptrtoint [64 x i8]* %MyAlloca to i64 + %1 = load i32* @__asan_option_detect_stack_use_after_return + %2 = icmp ne i32 %1, 0 + br i1 %2, label %3, label %5 + +;