llvm-project/llvm/test/Instrumentation/AddressSanitizer
Johannes Altmanninger 09667bc192 [asan] Remove debug locations from alloca prologue instrumentation
Summary:
This fixes https://llvm.org/PR26673
"Wrong debugging information with -fsanitize=address"
where asan instrumentation causes the prologue end to be computed
incorrectly: findPrologueEndLoc, looks for the first instruction
with a debug location to determine the prologue end.  Since the asan
instrumentation instructions had debug locations, that prologue end was
at some instruction, where the stack frame is still being set up.

There seems to be no good reason for extra debug locations for the
asan instrumentations that set up the frame; they don't have a natural
source location.  In the debugger they are simply located at the start
of the function.

For certain other instrumentations like -fsanitize-coverage=trace-pc-guard
the same problem persists - that might be more work to fix, since it
looks like they rely on locations of the tracee functions.

This partly reverts aaf4bb2394
"[asan] Set debug location in ASan function prologue"
whose motivation was to give debug location info to the coverage callback.
Its test only ensures that the call to @__sanitizer_cov_trace_pc_guard is
given the correct source location; as the debug location is still set in
ModuleSanitizerCoverage::InjectCoverageAtBlock, the test does not break.
So -fsanitize-coverage is hopefully unaffected - I don't think it should
rely on the debug locations of asan-generated allocas.

Related revision: 3c6c14d14b
"ASAN: Provide reliable debug info for local variables at -O0."

Below is how the X86 assembly version of the added test case changes.
We get rid of some .loc lines and put prologue_end where the user code starts.

```diff
--- 2.master.s	2019-12-02 12:32:38.982959053 +0100
+++ 2.patch.s	2019-12-02 12:32:41.106246674 +0100
@@ -45,8 +45,6 @@
 	.cfi_offset %rbx, -24
 	xorl	%eax, %eax
 	movl	%eax, %ecx
- .Ltmp2:
- 	.loc	1 3 0 prologue_end      # 2.c:3:0
 	cmpl	$0, __asan_option_detect_stack_use_after_return
 	movl	%edi, 92(%rbx)          # 4-byte Spill
 	movq	%rsi, 80(%rbx)          # 8-byte Spill
@@ -57,9 +55,7 @@
 	callq	__asan_stack_malloc_0
 	movq	%rax, 72(%rbx)          # 8-byte Spill
 .LBB1_2:
- 	.loc	1 0 0 is_stmt 0         # 2.c:0:0
 	movq	72(%rbx), %rax          # 8-byte Reload
- 	.loc	1 3 0                   # 2.c:3:0
 	cmpq	$0, %rax
 	movq	%rax, %rcx
 	movq	%rax, 64(%rbx)          # 8-byte Spill
@@ -72,9 +68,7 @@
 	movq	%rax, %rsp
 	movq	%rax, 56(%rbx)          # 8-byte Spill
 .LBB1_4:
- 	.loc	1 0 0                   # 2.c:0:0
 	movq	56(%rbx), %rax          # 8-byte Reload
- 	.loc	1 3 0                   # 2.c:3:0
 	movq	%rax, 120(%rbx)
 	movq	%rax, %rcx
 	addq	$32, %rcx
@@ -99,7 +93,6 @@
 	movb	%r8b, 31(%rbx)          # 1-byte Spill
 	je	.LBB1_7
 # %bb.5:
- 	.loc	1 0 0                   # 2.c:0:0
 	movq	40(%rbx), %rax          # 8-byte Reload
 	andq	$7, %rax
 	addq	$3, %rax
@@ -118,7 +111,8 @@
 	movl	%ecx, (%rax)
 	movq	80(%rbx), %rdx          # 8-byte Reload
 	movq	%rdx, 128(%rbx)
-	.loc	1 4 3 is_stmt 1         # 2.c:4:3
+.Ltmp2:
+	.loc	1 4 3 prologue_end      # 2.c:4:3
 	movq	%rax, %rdi
 	callq	f
 	movq	48(%rbx), %rax          # 8-byte Reload
```

Reviewers: eugenis, aprantl

Reviewed By: eugenis

Subscribers: ormris, aprantl, hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D70894
2019-12-03 11:24:17 +01:00
..
X86 [lit] Delete empty lines at the end of lit.local.cfg NFC 2019-06-17 09:51:07 +00:00
adaptive_global_redzones.ll
asan-detect-invalid-pointer-pair.ll [asan] Add options -asan-detect-invalid-pointer-cmp and -asan-detect-invalid-pointer-sub options. 2019-03-28 10:51:24 +00:00
asan-masked-load-store.ll IR: Support parsing numeric block ids, and emit them in textual output. 2019-03-22 18:27:13 +00:00
asan-vs-gvn.ll
asan_address_space_attr.ll
basic-msvc64.ll
basic-myriad.ll
basic.ll [NewPM] Second attempt at porting ASan 2019-02-13 22:22:48 +00:00
debug-info-alloca.ll [asan] Remove debug locations from alloca prologue instrumentation 2019-12-03 11:24:17 +01:00
debug-info-global-var.ll
debug_info.ll
debug_info_noninstrumented_alloca.ll
debug_info_noninstrumented_alloca2.ll
do-not-instrument-globals-darwin.ll
do-not-instrument-globals-linux.ll
do-not-instrument-internal-globals.ll
do-not-instrument-profiling-globals.ll Rename __asan_gen_* symbols to ___asan_gen_*. 2018-07-18 22:23:14 +00:00
do-not-instrument-promotable-allocas.ll
do-not-instrument-sanitizers.ll
do-not-touch-comdat-global.ll
do-not-touch-odr-global.ll [asan] Don't check ODR violations for particular types of globals 2018-12-13 09:47:39 +00:00
do-not-touch-threadlocal.ll
dynamic-shadow-darwin.ll [ASan] Use dynamic shadow on 32-bit iOS and simulators 2019-06-21 21:01:39 +00:00
experiment-call.ll
experiment.ll
force-dynamic-shadow.ll
freebsd.ll [ASAN] Use the correct shadow offset for ASAN on FreeBSD/mips64. 2018-08-01 22:51:13 +00:00
global_addrspace.ll [AddressSanitizer] Only instrument globals of default address space 2019-10-30 09:32:19 +01:00
global_cstring_darwin.ll [asan] Prevent folding of globals with redzones 2018-12-20 00:30:18 +00:00
global_lto_merge.ll
global_metadata.ll [asan] Prevent folding of globals with redzones 2018-12-20 00:30:18 +00:00
global_metadata_array.ll [asan] Prevent folding of globals with redzones 2018-12-20 00:30:18 +00:00
global_metadata_bitcasts.ll [asan] In llvm.asan.globals, allow entries to be non-GlobalVariable and skip over them 2018-12-18 21:20:17 +00:00
global_metadata_darwin.ll
global_metadata_external_comdat.ll Fix global_metadata_external_comdat.ll test 2018-08-21 00:03:21 +00:00
global_metadata_windows.ll [asan] Prevent folding of globals with redzones 2018-12-20 00:30:18 +00:00
instrument-dynamic-allocas.ll
instrument-no-return.ll [Sanitizers] UBSan unreachable incompatible with Kernel ASan 2019-02-04 23:37:50 +00:00
instrument-stack.ll
instrument_global.ll Rename __asan_gen_* symbols to ___asan_gen_*. 2018-07-18 22:23:14 +00:00
instrument_initializer_metadata.ll [IR] Disallow llvm.global_ctors and llvm.global_dtors of the 2-field form in textual format 2019-05-15 02:35:32 +00:00
instrument_load_then_store.ll
instrumentation-with-call-threshold.ll
keep_going.ll
lifetime-throw.ll
lifetime-uar-uas.ll
lifetime.ll
local_alias.ll [asan] Don't check ODR violations for particular types of globals 2018-12-13 09:47:39 +00:00
local_stack_base.ll [asan] Remove debug locations from alloca prologue instrumentation 2019-12-03 11:24:17 +01:00
localescape.ll [EH] Rename llvm.x86.seh.recoverfp intrinsic to llvm.eh.recoverfp 2019-01-16 00:37:13 +00:00
no-globals.ll
odr-check-ignore.ll [asan] Restore ODR-violation detection on vtables 2018-12-18 22:23:30 +00:00
ps4.ll
scale-offset.ll
stack-poisoning-and-lifetime-be.ll IR: Support parsing numeric block ids, and emit them in textual output. 2019-03-22 18:27:13 +00:00
stack-poisoning-and-lifetime.ll Asan use-after-scope: don't poison allocas if there were untraced lifetime intrinsics in the function (PR41481) 2019-04-16 07:54:20 +00:00
stack-poisoning-byval-args.ll
stack-poisoning.ll
stack_dynamic_alloca.ll IR: Support parsing numeric block ids, and emit them in textual output. 2019-03-22 18:27:13 +00:00
stack_layout.ll
str-nobuiltin.ll
test64.ll
twice.ll
ubsan.ll
version-mismatch-check.ll [ASan] Version mismatch check follow-up 2019-08-29 20:20:05 +00:00
win-sorted-sections.ll
win-string-literal.ll [asan] Undo special treatment of linkonce_odr and weak_odr 2018-12-20 00:30:27 +00:00
with-ifunc.ll