Under NPM, the asan-globals-md analysis is required but cannot be run
within the asan function pass due to module analyses not being able to
run from a function pass. So this pins all tests using "-asan" to the
legacy PM and adds a corresponding RUN line with
-passes='require<asan-globals-md>,function(asan)'.
Now all tests in Instrumentation/AddressSanitizer pass when
-enable-new-pm is by default on.
Tests were automatically converted using the following python script and
failures were manually fixed up.
import sys
for i in sys.argv:
with open(i, 'r') as f:
s = f.read()
with open(i, 'w') as f:
for l in s.splitlines():
if "RUN:" in l and ' -asan -asan-module ' in l and '\\' not in l:
f.write(l.replace(' -asan -asan-module ', ' -asan -asan-module -enable-new-pm=0 '))
f.write('\n')
f.write(l.replace(' -asan -asan-module ', " -passes='require<asan-globals-md>,function(asan),module(asan-module)' "))
f.write('\n')
elif "RUN:" in l and ' -asan ' in l and '\\' not in l:
f.write(l.replace(' -asan ', ' -asan -enable-new-pm=0 '))
f.write('\n')
f.write(l.replace(' -asan ', " -passes='require<asan-globals-md>,function(asan)' "))
f.write('\n')
else:
f.write(l)
f.write('\n')
See https://bugs.llvm.org/show_bug.cgi?id=46611.
Reviewed By: vitalybuka
Differential Revision: https://reviews.llvm.org/D83921
37 lines
1.1 KiB
LLVM
37 lines
1.1 KiB
LLVM
; Test basic address sanitizer instrumentation.
|
|
;
|
|
; RUN: opt -asan -asan-module -enable-new-pm=0 -S < %s | FileCheck %s
|
|
; RUN: opt -passes='asan-pipeline' -S < %s | FileCheck %s
|
|
|
|
target triple = "x86_64-pc-windows-msvc"
|
|
; CHECK: @llvm.global_ctors = {{.*}}@asan.module_ctor
|
|
|
|
define i32 @test_load(i32* %a) sanitize_address {
|
|
; First instrumentation in the function must be to load the dynamic shadow
|
|
; address into a local variable.
|
|
; CHECK-LABEL: @test_load
|
|
; CHECK: entry:
|
|
; CHECK-NEXT: %[[SHADOW:[^ ]*]] = load i64, i64* @__asan_shadow_memory_dynamic_address
|
|
|
|
; Shadow address is loaded and added into the whole offset computation.
|
|
; CHECK: add i64 %{{.*}}, %[[SHADOW]]
|
|
|
|
entry:
|
|
%tmp1 = load i32, i32* %a, align 4
|
|
ret i32 %tmp1
|
|
}
|
|
|
|
define i32 @__asan_options(i32* %a) sanitize_address {
|
|
; Asan functions are not instrumented. Asan function may be called by
|
|
; __asan_init before the shadow initialisation, which may lead to incorrect
|
|
; behavior of the instrumented code.
|
|
; CHECK-LABEL: @__asan_options
|
|
; CHECK: entry:
|
|
; CHECK-NEXT: %tmp1 = load i32, i32* %a, align 4
|
|
; CHECK-NEXT: ret i32 %tmp1
|
|
|
|
entry:
|
|
%tmp1 = load i32, i32* %a, align 4
|
|
ret i32 %tmp1
|
|
}
|