Marco Elver 75432ce3c9
[LowerAllowCheck] Add llvm.allow.sanitize.* intrinsics (#172029)
Add new intrinsics:
  - llvm.allow.sanitize.address
  - llvm.allow.sanitize.thread
  - llvm.allow.sanitize.memory
  - llvm.allow.sanitize.hwaddress

These intrinsics return true if the corresponding sanitizer is enabled
for the function, and false otherwise. They are lowered by
LowerAllowCheckPass to constant booleans based on the corresponding
sanitize_* function attributes. LowerAllowCheckPass is now "required" to
run on functions with optnone to ensure correct lowering at O0.

The LowerAllowCheckPass already performs similar duties for
@llvm.allow.runtime.check and @llvm.allow.ubsan.check, although with
subtly different semantics (based on profiles and/or sampling). In this
case, we want to make the true/false decision based on if any one of
address/memory/thread sanitization is enabled.
2026-01-03 16:20:43 +01:00

71 lines
1.8 KiB
LLVM

; RUN: opt < %s -passes=lower-allow-check -S | FileCheck %s
; RUN: opt < %s -passes=lower-allow-check -lower-allow-check-random-rate=0 -S | FileCheck %s
declare i1 @llvm.allow.sanitize.address()
declare i1 @llvm.allow.sanitize.thread()
declare i1 @llvm.allow.sanitize.memory()
declare i1 @llvm.allow.sanitize.hwaddress()
define i1 @test_address() sanitize_address {
; CHECK-LABEL: @test_address(
; CHECK-NEXT: ret i1 true
%1 = call i1 @llvm.allow.sanitize.address()
ret i1 %1
}
define i1 @test_no_sanitize_address() {
; CHECK-LABEL: @test_no_sanitize_address(
; CHECK-NEXT: ret i1 false
%1 = call i1 @llvm.allow.sanitize.address()
ret i1 %1
}
define i1 @test_address_but_no_thread() sanitize_address {
; CHECK-LABEL: @test_address_but_no_thread(
; CHECK-NEXT: ret i1 false
%1 = call i1 @llvm.allow.sanitize.thread()
ret i1 %1
}
define i1 @test_thread() sanitize_thread {
; CHECK-LABEL: @test_thread(
; CHECK-NEXT: ret i1 true
%1 = call i1 @llvm.allow.sanitize.thread()
ret i1 %1
}
define i1 @test_no_sanitize_thread() {
; CHECK-LABEL: @test_no_sanitize_thread(
; CHECK-NEXT: ret i1 false
%1 = call i1 @llvm.allow.sanitize.thread()
ret i1 %1
}
define i1 @test_memory() sanitize_memory {
; CHECK-LABEL: @test_memory(
; CHECK-NEXT: ret i1 true
%1 = call i1 @llvm.allow.sanitize.memory()
ret i1 %1
}
define i1 @test_no_sanitize_memory() {
; CHECK-LABEL: @test_no_sanitize_memory(
; CHECK-NEXT: ret i1 false
%1 = call i1 @llvm.allow.sanitize.memory()
ret i1 %1
}
define i1 @test_hwaddress() sanitize_hwaddress {
; CHECK-LABEL: @test_hwaddress(
; CHECK-NEXT: ret i1 true
%1 = call i1 @llvm.allow.sanitize.hwaddress()
ret i1 %1
}
define i1 @test_no_sanitize_hwaddress() {
; CHECK-LABEL: @test_no_sanitize_hwaddress(
; CHECK-NEXT: ret i1 false
%1 = call i1 @llvm.allow.sanitize.hwaddress()
ret i1 %1
}