2014-06-09 21:53:47 +00:00
; 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"
2014-06-17 23:22:41 +00:00
; First, argument variable "y" resides in %rdi:
; CHECK: DEBUG_VALUE: bar:y <- RDI
2014-06-09 21:53:47 +00:00
; Then its address is stored in a location on a stack:
2014-06-17 23:22:41 +00:00
; CHECK: movq %rdi, [[OFFSET:[0-9]+]](%rsp)
2014-06-09 21:53:47 +00:00
; 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.
Debug Info: Move the complex expression handling (=the remainder) of
emitDebugLocValue() into DwarfExpression.
Ought to be NFC, but it actually uncovered a bug in the debug-loc-asan.ll
testcase. The testcase checks that the address of variable "y" is stored
at [RSP+16], which also lines up with the comment.
It also check(ed) that the *value* of "y" is stored in RDI before that,
but that is actually incorrect, since RDI is the very value that is
stored in [RSP+16]. Here's the assembler output:
movb 2147450880(%rcx), %r8b
#DEBUG_VALUE: bar:y <- RDI
cmpb $0, %r8b
movq %rax, 32(%rsp) # 8-byte Spill
movq %rsi, 24(%rsp) # 8-byte Spill
movq %rdi, 16(%rsp) # 8-byte Spill
.Ltmp3:
#DEBUG_VALUE: bar:y <- [RSP+16]
Fixed the comment to spell out the correct register and the check to
expect an address rather than a value.
Note that the range that is emitted for the RDI location was and is still
wrong, it claims to begin at the function prologue, but really it should
start where RDI is first assigned.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225851 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-13 23:39:11 +00:00
; First, its address is stored in %rdi:
2014-10-21 01:17:30 +00:00
; CHECK: .quad .Lfunc_begin0-.Lfunc_begin0
; CHECK-NEXT: .quad [[START_LABEL]]-.Lfunc_begin0
Debug Info: Move the complex expression handling (=the remainder) of
emitDebugLocValue() into DwarfExpression.
Ought to be NFC, but it actually uncovered a bug in the debug-loc-asan.ll
testcase. The testcase checks that the address of variable "y" is stored
at [RSP+16], which also lines up with the comment.
It also check(ed) that the *value* of "y" is stored in RDI before that,
but that is actually incorrect, since RDI is the very value that is
stored in [RSP+16]. Here's the assembler output:
movb 2147450880(%rcx), %r8b
#DEBUG_VALUE: bar:y <- RDI
cmpb $0, %r8b
movq %rax, 32(%rsp) # 8-byte Spill
movq %rsi, 24(%rsp) # 8-byte Spill
movq %rdi, 16(%rsp) # 8-byte Spill
.Ltmp3:
#DEBUG_VALUE: bar:y <- [RSP+16]
Fixed the comment to spell out the correct register and the check to
expect an address rather than a value.
Note that the range that is emitted for the RDI location was and is still
wrong, it claims to begin at the function prologue, but really it should
start where RDI is first assigned.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225851 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-13 23:39:11 +00:00
; CHECK: DW_OP_breg5
2014-06-09 21:53:47 +00:00
; Then it's addressed via %rsp:
2014-10-21 01:17:30 +00:00
; CHECK: .quad [[START_LABEL]]-.Lfunc_begin0
2015-03-05 02:05:42 +00:00
; CHECK-NEXT: .Lfunc_end0-.Lfunc_begin0
2014-06-09 21:53:47 +00:00
; 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
2015-02-27 21:17:42 +00:00
%1 = load i32 , i32 * @__asan_option_detect_stack_use_after_return
2014-06-09 21:53:47 +00:00
%2 = icmp ne i32 %1 , 0
br i1 %2 , label %3 , label %5
; <label>:3 ; preds = %entry
%4 = call i64 @__asan_stack_malloc_0 ( i64 64 , i64 %0 )
br label %5
; <label>:5 ; preds = %entry, %3
%6 = phi i64 [ %0 , %entry ] , [ %4 , %3 ]
%7 = add i64 %6 , 32
%8 = inttoptr i64 %7 to i32 *
%9 = inttoptr i64 %6 to i64 *
store i64 1102416563 , i64 * %9
%10 = add i64 %6 , 8
%11 = inttoptr i64 %10 to i64 *
store i64 ptrtoint ( [ 16 x i8 ] * @__asan_gen_ to i64 ) , i64 * %11
%12 = add i64 %6 , 16
%13 = inttoptr i64 %12 to i64 *
store i64 ptrtoint ( i32 ( i32 ) * @_Z3bari to i64 ) , i64 * %13
%14 = lshr i64 %6 , 3
%15 = add i64 %14 , 2147450880
%16 = add i64 %15 , 0
%17 = inttoptr i64 %16 to i64 *
store i64 -868083100587789839 , i64 * %17
%18 = ptrtoint i32 * %8 to i64
%19 = lshr i64 %18 , 3
%20 = add i64 %19 , 2147450880
%21 = inttoptr i64 %20 to i8 *
2015-02-27 21:17:42 +00:00
%22 = load i8 , i8 * %21
2014-06-09 21:53:47 +00:00
%23 = icmp ne i8 %22 , 0
2015-04-15 21:04:10 +00:00
call void @llvm.dbg.declare ( metadata i32 * %8 , metadata !12 , metadata !14 ) , !dbg !MDLocation ( scope: !4 )
2014-06-09 21:53:47 +00:00
br i1 %23 , label %24 , label %30
; <label>:24 ; preds = %5
%25 = and i64 %18 , 7
%26 = add i64 %25 , 3
%27 = trunc i64 %26 to i8
%28 = icmp sge i8 %27 , %22
br i1 %28 , label %29 , label %30
; <label>:29 ; preds = %24
call void @__asan_report_store4 ( i64 %18 )
call void asm sideeffect "" , "" ( )
unreachable
; <label>:30 ; preds = %24, %5
store i32 %y , i32 * %8 , align 4
%31 = ptrtoint i32 * %8 to i64 , !dbg !13
%32 = lshr i64 %31 , 3 , !dbg !13
%33 = add i64 %32 , 2147450880 , !dbg !13
%34 = inttoptr i64 %33 to i8 * , !dbg !13
2015-02-27 21:17:42 +00:00
%35 = load i8 , i8 * %34 , !dbg !13
2014-06-09 21:53:47 +00:00
%36 = icmp ne i8 %35 , 0 , !dbg !13
br i1 %36 , label %37 , label %43 , !dbg !13
; <label>:37 ; preds = %30
%38 = and i64 %31 , 7 , !dbg !13
%39 = add i64 %38 , 3 , !dbg !13
%40 = trunc i64 %39 to i8 , !dbg !13
%41 = icmp sge i8 %40 , %35 , !dbg !13
br i1 %41 , label %42 , label %43
; <label>:42 ; preds = %37
call void @__asan_report_load4 ( i64 %31 ) , !dbg !13
call void asm sideeffect "" , "" ( )
unreachable
; <label>:43 ; preds = %37, %30
2015-02-27 21:17:42 +00:00
%44 = load i32 , i32 * %8 , align 4 , !dbg !13
2014-06-09 21:53:47 +00:00
%add = add nsw i32 %44 , 2 , !dbg !13
store i64 1172321806 , i64 * %9 , !dbg !13
%45 = icmp ne i64 %6 , %0 , !dbg !13
br i1 %45 , label %46 , label %53 , !dbg !13
; <label>:46 ; preds = %43
%47 = add i64 %15 , 0 , !dbg !13
%48 = inttoptr i64 %47 to i64 * , !dbg !13
store i64 -723401728380766731 , i64 * %48 , !dbg !13
%49 = add i64 %6 , 56 , !dbg !13
%50 = inttoptr i64 %49 to i64 * , !dbg !13
2015-02-27 21:17:42 +00:00
%51 = load i64 , i64 * %50 , !dbg !13
2014-06-09 21:53:47 +00:00
%52 = inttoptr i64 %51 to i8 * , !dbg !13
store i8 0 , i8 * %52 , !dbg !13
br label %56 , !dbg !13
; <label>:53 ; preds = %43
%54 = add i64 %15 , 0 , !dbg !13
%55 = inttoptr i64 %54 to i64 * , !dbg !13
store i64 0 , i64 * %55 , !dbg !13
br label %56 , !dbg !13
; <label>:56 ; preds = %53, %46
ret i32 %add , !dbg !13
}
; Function Attrs: nounwind readnone
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218787 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-01 18:55:02 +00:00
declare void @llvm.dbg.declare ( metadata , metadata , metadata ) #1
2014-06-09 21:53:47 +00:00
define internal void @asan.module_ctor ( ) {
call void @__asan_init_v3 ( )
ret void
}
declare void @__asan_init_v3 ( )
declare void @__asan_report_load4 ( i64 )
declare void @__asan_report_store4 ( i64 )
declare i64 @__asan_stack_malloc_0 ( i64 , i64 )
attributes #0 = { nounwind sanitize_address 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" }
attributes #1 = { nounwind readnone }
!llvm.dbg.cu = ! { !0 }
!llvm.module.flags = ! { !9 , !10 }
!llvm.ident = ! { !11 }
2015-03-03 17:24:31 +00:00
!0 = !MDCompileUnit ( language: D W _ L A N G _ C _ p l u s _ p l u s , producer: "clang version 3.5.0 (209308)" , isOptimized: false , emissionKind: 1 , file: !1 , enums: !2 , retainedTypes: !2 , subprograms: !3 , globals: !2 , imports: !2 )
!1 = !MDFile ( filename: "test.cc" , directory: "/llvm_cmake_gcc" )
IR: Make metadata typeless in assembly
Now that `Metadata` is typeless, reflect that in the assembly. These
are the matching assembly changes for the metadata/value split in
r223802.
- Only use the `metadata` type when referencing metadata from a call
intrinsic -- i.e., only when it's used as a `Value`.
- Stop pretending that `ValueAsMetadata` is wrapped in an `MDNode`
when referencing it from call intrinsics.
So, assembly like this:
define @foo(i32 %v) {
call void @llvm.foo(metadata !{i32 %v}, metadata !0)
call void @llvm.foo(metadata !{i32 7}, metadata !0)
call void @llvm.foo(metadata !1, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{metadata !3}, metadata !0)
ret void, !bar !2
}
!0 = metadata !{metadata !2}
!1 = metadata !{i32* @global}
!2 = metadata !{metadata !3}
!3 = metadata !{}
turns into this:
define @foo(i32 %v) {
call void @llvm.foo(metadata i32 %v, metadata !0)
call void @llvm.foo(metadata i32 7, metadata !0)
call void @llvm.foo(metadata i32* @global, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{!3}, metadata !0)
ret void, !bar !2
}
!0 = !{!2}
!1 = !{i32* @global}
!2 = !{!3}
!3 = !{}
I wrote an upgrade script that handled almost all of the tests in llvm
and many of the tests in cfe (even handling many `CHECK` lines). I've
attached it (or will attach it in a moment if you're speedy) to PR21532
to help everyone update their out-of-tree testcases.
This is part of PR21532.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224257 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-15 19:07:53 +00:00
!2 = ! { }
!3 = ! { !4 }
2015-03-03 17:24:31 +00:00
!4 = !MDSubprogram ( name: "bar" , linkageName: "_Z3bari" , line: 1 , isLocal: false , isDefinition: true , virtualIndex: 6 , flags: D I F l a g P r o t o t y p e d , isOptimized: false , scopeLine: 1 , file: !1 , scope: !5 , type: !6 , function: i32 ( i32 ) * @_Z3bari , variables: !2 )
!5 = !MDFile ( filename: "test.cc" , directory: "/llvm_cmake_gcc" )
!6 = !MDSubroutineType ( types: !7 )
IR: Make metadata typeless in assembly
Now that `Metadata` is typeless, reflect that in the assembly. These
are the matching assembly changes for the metadata/value split in
r223802.
- Only use the `metadata` type when referencing metadata from a call
intrinsic -- i.e., only when it's used as a `Value`.
- Stop pretending that `ValueAsMetadata` is wrapped in an `MDNode`
when referencing it from call intrinsics.
So, assembly like this:
define @foo(i32 %v) {
call void @llvm.foo(metadata !{i32 %v}, metadata !0)
call void @llvm.foo(metadata !{i32 7}, metadata !0)
call void @llvm.foo(metadata !1, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{metadata !3}, metadata !0)
ret void, !bar !2
}
!0 = metadata !{metadata !2}
!1 = metadata !{i32* @global}
!2 = metadata !{metadata !3}
!3 = metadata !{}
turns into this:
define @foo(i32 %v) {
call void @llvm.foo(metadata i32 %v, metadata !0)
call void @llvm.foo(metadata i32 7, metadata !0)
call void @llvm.foo(metadata i32* @global, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{!3}, metadata !0)
ret void, !bar !2
}
!0 = !{!2}
!1 = !{i32* @global}
!2 = !{!3}
!3 = !{}
I wrote an upgrade script that handled almost all of the tests in llvm
and many of the tests in cfe (even handling many `CHECK` lines). I've
attached it (or will attach it in a moment if you're speedy) to PR21532
to help everyone update their out-of-tree testcases.
This is part of PR21532.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224257 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-15 19:07:53 +00:00
!7 = ! { !8 , !8 }
2015-03-03 17:24:31 +00:00
!8 = !MDBasicType ( tag: D W _ T A G _ b a s e _ type , name: "int" , size: 32 , align: 32 , encoding: D W _ A T E _ s i g n e d )
IR: Make metadata typeless in assembly
Now that `Metadata` is typeless, reflect that in the assembly. These
are the matching assembly changes for the metadata/value split in
r223802.
- Only use the `metadata` type when referencing metadata from a call
intrinsic -- i.e., only when it's used as a `Value`.
- Stop pretending that `ValueAsMetadata` is wrapped in an `MDNode`
when referencing it from call intrinsics.
So, assembly like this:
define @foo(i32 %v) {
call void @llvm.foo(metadata !{i32 %v}, metadata !0)
call void @llvm.foo(metadata !{i32 7}, metadata !0)
call void @llvm.foo(metadata !1, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{metadata !3}, metadata !0)
ret void, !bar !2
}
!0 = metadata !{metadata !2}
!1 = metadata !{i32* @global}
!2 = metadata !{metadata !3}
!3 = metadata !{}
turns into this:
define @foo(i32 %v) {
call void @llvm.foo(metadata i32 %v, metadata !0)
call void @llvm.foo(metadata i32 7, metadata !0)
call void @llvm.foo(metadata i32* @global, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{!3}, metadata !0)
ret void, !bar !2
}
!0 = !{!2}
!1 = !{i32* @global}
!2 = !{!3}
!3 = !{}
I wrote an upgrade script that handled almost all of the tests in llvm
and many of the tests in cfe (even handling many `CHECK` lines). I've
attached it (or will attach it in a moment if you're speedy) to PR21532
to help everyone update their out-of-tree testcases.
This is part of PR21532.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224257 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-15 19:07:53 +00:00
!9 = ! { i32 2 , !"Dwarf Version" , i32 4 }
2015-03-03 17:24:31 +00:00
!10 = ! { i32 2 , !"Debug Info Version" , i32 3 }
IR: Make metadata typeless in assembly
Now that `Metadata` is typeless, reflect that in the assembly. These
are the matching assembly changes for the metadata/value split in
r223802.
- Only use the `metadata` type when referencing metadata from a call
intrinsic -- i.e., only when it's used as a `Value`.
- Stop pretending that `ValueAsMetadata` is wrapped in an `MDNode`
when referencing it from call intrinsics.
So, assembly like this:
define @foo(i32 %v) {
call void @llvm.foo(metadata !{i32 %v}, metadata !0)
call void @llvm.foo(metadata !{i32 7}, metadata !0)
call void @llvm.foo(metadata !1, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{metadata !3}, metadata !0)
ret void, !bar !2
}
!0 = metadata !{metadata !2}
!1 = metadata !{i32* @global}
!2 = metadata !{metadata !3}
!3 = metadata !{}
turns into this:
define @foo(i32 %v) {
call void @llvm.foo(metadata i32 %v, metadata !0)
call void @llvm.foo(metadata i32 7, metadata !0)
call void @llvm.foo(metadata i32* @global, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{!3}, metadata !0)
ret void, !bar !2
}
!0 = !{!2}
!1 = !{i32* @global}
!2 = !{!3}
!3 = !{}
I wrote an upgrade script that handled almost all of the tests in llvm
and many of the tests in cfe (even handling many `CHECK` lines). I've
attached it (or will attach it in a moment if you're speedy) to PR21532
to help everyone update their out-of-tree testcases.
This is part of PR21532.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224257 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-15 19:07:53 +00:00
!11 = ! { !"clang version 3.5.0 (209308)" }
2015-03-03 17:24:31 +00:00
!12 = !MDLocalVariable ( tag: D W _ T A G _ a r g _ v a r i a b l e , name: "y" , line: 1 , arg: 1 , scope: !4 , file: !5 , type: !8 )
2015-01-14 22:27:36 +00:00
!13 = !MDLocation ( line: 2 , scope: !4 )
2015-03-03 17:24:31 +00:00
!14 = !MDExpression ( D W _ O P _ d e r e f )