2014-06-13 19:53:44 +02:00
; RUN: opt < %s -asan -asan-module -asan-use-after-return=0 -S | FileCheck %s
2012-12-12 15:31:53 +01:00
; Checks that llvm.dbg.declare instructions are updated
; accordingly as we merge allocas.
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
2015-11-05 23:03:56 +01:00
define i32 @_Z3zzzi ( i32 %p ) nounwind uwtable sanitize_address !dbg !5 {
2012-12-12 15:31:53 +01:00
entry:
%p.addr = alloca i32 , align 4
%r = alloca i32 , align 4
2015-02-27 04:12:36 +01:00
store volatile i32 %p , i32 * %p.addr , align 4
2015-04-29 18:38:44 +02:00
call void @llvm.dbg.declare ( metadata i32 * %p.addr , metadata !10 , metadata !DIExpression ( ) ) , !dbg !11
call void @llvm.dbg.declare ( metadata i32 * %r , metadata !12 , metadata !DIExpression ( ) ) , !dbg !14
2015-02-27 22:17:42 +01:00
%0 = load i32 , i32 * %p.addr , align 4 , !dbg !14
2012-12-12 15:31:53 +01:00
%add = add nsw i32 %0 , 1 , !dbg !14
2015-02-27 04:12:36 +01:00
store volatile i32 %add , i32 * %r , align 4 , !dbg !14
2015-02-27 22:17:42 +01:00
%1 = load i32 , i32 * %r , align 4 , !dbg !15
2012-12-12 15:31:53 +01:00
ret i32 %1 , !dbg !15
}
; CHECK: define i32 @_Z3zzzi
2020-02-11 00:37:56 +01:00
; CHECK: [[MyAlloca:%.*]] = alloca i8, i64 64
[AddressSanitizer] Ensure only AllocaInst is passed to dbg.declare
Various parts of the LLVM code generator assume that the address
argument of a dbg.declare is not a `ptrtoint`-of-alloca. ASan breaks
this assumption, and this results in local variables sometimes being
unavailable at -O0.
GlobalISel, SelectionDAG, and FastISel all do not appear to expect
dbg.declares to have a `ptrtoint` as an operand. This means that they do
not place entry block allocas in the usual side table reserved for local
variables available in the whole function scope. This isn't always a
problem, as LLVM can try to lower the dbg.declare to a DBG_VALUE, but
those DBG_VALUEs can get dropped for all the usual reasons DBG_VALUEs
get dropped. In the ObjC test case I'm looking at, the cause happens to
be that `replaceDbgDeclare` has hoisted dbg.declares into the entry
block, causing LiveDebugValues to "kill" the DBG_VALUEs because the
lexical dominance check fails.
To address this, I propose:
1) Have ASan (always) pass an alloca to dbg.declares (this patch). This
is a narrow bugfix for -O0 debugging.
2) Make replaceDbgDeclare not move dbg.declares around. This should be a
generic improvement for optimized debug info, as it would prevent the
lexical dominance check in LiveDebugValues from killing as many
variables.
This means reverting llvm/r227544, which fixed an assertion failure
(llvm.org/PR22386) but no longer seems to be necessary. I was able to
complete a stage2 build with the revert in place.
rdar://54688991
Differential Revision: https://reviews.llvm.org/D74369
2020-02-11 01:22:27 +01:00
; Note: these dbg.declares used to contain `ptrtoint` operands. The instruction
; selector would then decline to put the variable in the MachineFunction side
; table. Check that the dbg.declares have `alloca` operands.
; CHECK: call void @llvm.dbg.declare(metadata i8* [[MyAlloca]], metadata ![[ARG_ID:[0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 32))
; CHECK: call void @llvm.dbg.declare(metadata i8* [[MyAlloca]], metadata ![[VAR_ID:[0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 48))
2012-12-12 15:31:53 +01:00
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.
llvm-svn: 218787
2014-10-01 20:55:02 +02:00
declare void @llvm.dbg.declare ( metadata , metadata , metadata ) nounwind readnone
2012-12-12 15:31:53 +01:00
!llvm.dbg.cu = ! { !0 }
2013-11-22 22:49:45 +01:00
!llvm.module.flags = ! { !17 }
2012-12-12 15:31:53 +01:00
2016-04-15 17:57:41 +02:00
!0 = distinct !DICompileUnit ( language: D W _ L A N G _ C _ p l u s _ p l u s , producer: "clang version 3.3 (trunk 169314)" , isOptimized: true , emissionKind: F u l l D e b u g , file: !16 , enums: !1 , retainedTypes: !1 , globals: !1 )
2015-03-27 21:46:33 +01:00
!1 = ! { }
[DebugInfo] Add DILabel metadata and intrinsic llvm.dbg.label.
In order to set breakpoints on labels and list source code around
labels, we need collect debug information for labels, i.e., label
name, the function label belong, line number in the file, and the
address label located. In order to keep these information in LLVM
IR and to allow backend to generate debug information correctly.
We create a new kind of metadata for labels, DILabel. The format
of DILabel is
!DILabel(scope: !1, name: "foo", file: !2, line: 3)
We hope to keep debug information as much as possible even the
code is optimized. So, we create a new kind of intrinsic for label
metadata to avoid the metadata is eliminated with basic block.
The intrinsic will keep existing if we keep it from optimized out.
The format of the intrinsic is
llvm.dbg.label(metadata !1)
It has only one argument, that is the DILabel metadata. The
intrinsic will follow the label immediately. Backend could get the
label metadata through the intrinsic's parameter.
We also create DIBuilder API for labels to be used by Frontend.
Frontend could use createLabel() to allocate DILabel objects, and use
insertLabel() to insert llvm.dbg.label intrinsic in LLVM IR.
Differential Revision: https://reviews.llvm.org/D45024
Patch by Hsiangkai Wang.
llvm-svn: 331841
2018-05-09 04:40:45 +02:00
!5 = distinct !DISubprogram ( name: "zzz" , linkageName: "_Z3zzzi" , 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 , unit: !0 , scopeLine: 1 , file: !16 , scope: !6 , type: !7 , retainedNodes: !1 )
2015-04-29 18:38:44 +02:00
!6 = !DIFile ( filename: "a.cc" , directory: "/usr/local/google/llvm_cmake_clang/tmp/debuginfo" )
!7 = !DISubroutineType ( types: !8 )
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.
llvm-svn: 224257
2014-12-15 20:07:53 +01:00
!8 = ! { !9 , !9 }
2015-04-29 18:38:44 +02:00
!9 = !DIBasicType ( 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 )
2015-07-31 20:58:39 +02:00
!10 = !DILocalVariable ( name: "p" , line: 1 , arg: 1 , scope: !5 , file: !6 , type: !9 )
2015-04-29 18:38:44 +02:00
!11 = !DILocation ( line: 1 , scope: !5 )
2015-07-31 20:58:39 +02:00
!12 = !DILocalVariable ( name: "r" , line: 2 , scope: !13 , file: !6 , type: !9 )
2012-12-12 15:31:53 +01:00
; Verify that debug descriptors for argument and local variable will be replaced
; with descriptors that end with OpDeref (encoded as 2).
2015-07-31 20:58:39 +02:00
; CHECK: ![[ARG_ID]] = !DILocalVariable(name: "p", arg: 1,{{.*}} line: 1
; CHECK: ![[VAR_ID]] = !DILocalVariable(name: "r",{{.*}} line: 2
2012-12-12 15:31:53 +01:00
; Verify that there are no more variable descriptors.
2015-04-29 18:38:44 +02:00
; CHECK-NOT: !DILocalVariable(tag: DW_TAG_arg_variable
; CHECK-NOT: !DILocalVariable(tag: DW_TAG_auto_variable
2012-12-12 15:31:53 +01:00
2015-04-29 18:38:44 +02:00
!13 = distinct !DILexicalBlock ( line: 1 , column: 0 , file: !16 , scope: !5 )
!14 = !DILocation ( line: 2 , scope: !13 )
!15 = !DILocation ( line: 3 , scope: !13 )
!16 = !DIFile ( filename: "a.cc" , directory: "/usr/local/google/llvm_cmake_clang/tmp/debuginfo" )
2015-03-03 18:24:31 +01:00
!17 = ! { i32 1 , !"Debug Info Version" , i32 3 }