Skip to content

Commit 6cc9244

Browse files
committed
Enable hwasan-use-after-scope by default
This has been in use for a long time without any issues. Reviewed By: vitalybuka Differential Revision: https://reviews.llvm.org/D156267
1 parent 5555b9f commit 6cc9244

18 files changed

+25
-22
lines changed

compiler-rt/test/hwasan/TestCases/stack-uas.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
// Tests use-after-scope detection and reporting.
2-
// RUN: %clang_hwasan -mllvm -hwasan-use-after-scope -g %s -o %t && not %run %t 2>&1 | FileCheck %s
3-
// RUN: %clang_hwasan -mllvm -hwasan-use-after-scope -g %s -o %t && not %env_hwasan_opts=symbolize=0 %run %t 2>&1 | FileCheck %s --check-prefix=NOSYM
2+
// RUN: %clang_hwasan -g %s -o %t && not %run %t 2>&1 | FileCheck %s
3+
// RUN: %clang_hwasan -g %s -o %t && not %env_hwasan_opts=symbolize=0 %run %t 2>&1 | FileCheck %s --check-prefix=NOSYM
44

55
// RUN: %clang_hwasan -mllvm -hwasan-use-after-scope=false -g %s -o %t && %run %t 2>&1
6-
// Use after scope is turned off by default.
7-
// RUN: %clang_hwasan -g %s -o %t && %run %t 2>&1
86

9-
// RUN: %clang_hwasan -mllvm -hwasan-use-after-scope -g %s -o %t && not %run %t 2>&1 | FileCheck %s
7+
// RUN: %clang_hwasan -g %s -o %t && not %run %t 2>&1 | FileCheck %s
108

119
// Run the same test as above, but using the __hwasan_add_frame_record libcall.
1210
// The output should be the exact same.
13-
// RUN: %clang_hwasan -mllvm -hwasan-use-after-scope -mllvm -hwasan-record-stack-history=libcall -g %s -o %t && not %env_hwasan_opts=symbolize=0 %run %t 2>&1 | FileCheck %s --check-prefix=NOSYM
11+
// RUN: %clang_hwasan -mllvm -hwasan-record-stack-history=libcall -g %s -o %t && not %env_hwasan_opts=symbolize=0 %run %t 2>&1 | FileCheck %s --check-prefix=NOSYM
1412

1513
// Stack histories currently are not recorded on x86.
1614
// XFAIL: target=x86_64{{.*}}

compiler-rt/test/hwasan/TestCases/use-after-scope-capture.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This is the ASAN test of the same name ported to HWAsan.
22

3-
// RUN: %clangxx_hwasan -mllvm -hwasan-use-after-scope --std=c++11 -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
3+
// RUN: %clangxx_hwasan --std=c++11 -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
44

55
// REQUIRES: aarch64-target-arch || riscv64-target-arch
66

compiler-rt/test/hwasan/TestCases/use-after-scope-dtor-order.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This is the ASAN test of the same name ported to HWAsan.
22

3-
// RUN: %clangxx_hwasan -mllvm -hwasan-use-after-scope -O1 %s -o %t && \
3+
// RUN: %clangxx_hwasan -O1 %s -o %t && \
44
// RUN: not %run %t 2>&1 | FileCheck %s
55

66
// REQUIRES: aarch64-target-arch || riscv64-target-arch

compiler-rt/test/hwasan/TestCases/use-after-scope-goto.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This is the ASAN test of the same name ported to HWAsan.
22

3-
// RUN: %clangxx_hwasan -mllvm -hwasan-use-after-scope -O0 %s -o %t && %run %t
3+
// RUN: %clangxx_hwasan -O0 %s -o %t && %run %t
44

55
// Function jumps over variable initialization making lifetime analysis
66
// ambiguous. Asan should ignore such variable and program must not fail.

compiler-rt/test/hwasan/TestCases/use-after-scope-if.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This is the ASAN test of the same name ported to HWAsan.
22

3-
// RUN: %clangxx_hwasan -mllvm -hwasan-use-after-scope -O1 %s -o %t && \
3+
// RUN: %clangxx_hwasan -O1 %s -o %t && \
44
// RUN: not %run %t 2>&1 | FileCheck %s
55

66
// REQUIRES: aarch64-target-arch || riscv64-target-arch

compiler-rt/test/hwasan/TestCases/use-after-scope-inlined.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// happens. "always_inline" is not enough, as Clang doesn't emit
55
// llvm.lifetime intrinsics at -O0.
66
//
7-
// RUN: %clangxx_hwasan -mllvm -hwasan-use-after-scope -O2 %s -o %t && \
7+
// RUN: %clangxx_hwasan -O2 %s -o %t && \
88
// RUN: not %run %t 2>&1 | FileCheck %s
99

1010
// REQUIRES: aarch64-target-arch || riscv64-target-arch

compiler-rt/test/hwasan/TestCases/use-after-scope-loop-bug.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This is the ASAN test of the same name ported to HWAsan.
22

3-
// RUN: %clangxx_hwasan -mllvm -hwasan-use-after-scope -O1 %s -o %t && \
3+
// RUN: %clangxx_hwasan -O1 %s -o %t && \
44
// RUN: not %run %t 2>&1 | FileCheck %s
55

66
// REQUIRES: aarch64-target-arch || riscv64-target-arch

compiler-rt/test/hwasan/TestCases/use-after-scope-loop-removed.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This is the ASAN test of the same name ported to HWAsan.
22

3-
// RUN: %clangxx_hwasan -mllvm -hwasan-use-after-scope -O1 %s -o %t && \
3+
// RUN: %clangxx_hwasan -O1 %s -o %t && \
44
// RUN: not %run %t 2>&1 | FileCheck %s
55

66
// REQUIRES: aarch64-target-arch || riscv64-target-arch

compiler-rt/test/hwasan/TestCases/use-after-scope-loop.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This is the ASAN test of the same name ported to HWAsan.
22

3-
// RUN: %clangxx_hwasan -mllvm -hwasan-use-after-scope -O1 %s -o %t && \
3+
// RUN: %clangxx_hwasan -O1 %s -o %t && \
44
// RUN: not %run %t 2>&1 | FileCheck %s
55

66
// REQUIRES: aarch64-target-arch || riscv64-target-arch

compiler-rt/test/hwasan/TestCases/use-after-scope-nobug.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This is the ASAN test of the same name ported to HWAsan.
22

3-
// RUN: %clangxx_hwasan -mllvm -hwasan-use-after-scope -O1 %s -o %t && %run %t
3+
// RUN: %clangxx_hwasan -O1 %s -o %t && %run %t
44

55
// REQUIRES: aarch64-target-arch || riscv64-target-arch
66

compiler-rt/test/hwasan/TestCases/use-after-scope-setjmp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clangxx_hwasan -mllvm -hwasan-use-stack-safety=0 -mllvm -hwasan-use-after-scope -O2 %s -o %t && \
1+
// RUN: %clangxx_hwasan -mllvm -hwasan-use-stack-safety=0 -O2 %s -o %t && \
22
// RUN: %run %t 2>&1
33

44
// REQUIRES: aarch64-target-arch || riscv64-target-arch

compiler-rt/test/hwasan/TestCases/use-after-scope-temp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This is the ASAN test of the same name ported to HWAsan.
22

3-
// RUN: %clangxx_hwasan -mllvm -hwasan-use-after-scope -std=c++11 -O1 %s -o %t && \
3+
// RUN: %clangxx_hwasan -std=c++11 -O1 %s -o %t && \
44
// RUN: not %run %t 2>&1 | FileCheck %s
55

66
// REQUIRES: aarch64-target-arch || riscv64-target-arch

compiler-rt/test/hwasan/TestCases/use-after-scope-temp2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This is the ASAN test of the same name ported to HWAsan.
22

3-
// RUN: %clangxx_hwasan -mllvm -hwasan-use-after-scope -std=c++11 -O1 %s -o %t && \
3+
// RUN: %clangxx_hwasan -std=c++11 -O1 %s -o %t && \
44
// RUN: not %run %t 2>&1 | FileCheck %s
55

66
// REQUIRES: aarch64-target-arch || riscv64-target-arch

compiler-rt/test/hwasan/TestCases/use-after-scope-types.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This is the ASAN test of the same name ported to HWAsan.
22

3-
// RUN: %clangxx_hwasan -mllvm -hwasan-use-after-scope -std=c++11 -O0 %s -o %t
4-
// RUN: %clangxx_hwasan -fno-exceptions -mllvm -hwasan-use-after-scope -std=c++11 -O0 %s -o %t-noexcept
3+
// RUN: %clangxx_hwasan -std=c++11 -O0 %s -o %t
4+
// RUN: %clangxx_hwasan -fno-exceptions -std=c++11 -O0 %s -o %t-noexcept
55

66
// RUN: not %run %t 0 2>&1 | FileCheck %s
77
// RUN: not %run %t 1 2>&1 | FileCheck %s

compiler-rt/test/hwasan/TestCases/use-after-scope.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This is the ASAN test of the same name ported to HWAsan.
22

3-
// RUN: %clangxx_hwasan -mllvm -hwasan-use-after-scope -O1 %s -o %t && \
3+
// RUN: %clangxx_hwasan -O1 %s -o %t \
44
// RUN: not %run %t 2>&1 | FileCheck %s
55

66
// REQUIRES: aarch64-target-arch || riscv64-target-arch

llvm/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ Changes to LLDB
133133

134134
Changes to Sanitizers
135135
---------------------
136+
* HWASan now defaults to detecting use-after-scope bugs.
136137

137138
Other Changes
138139
-------------

llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static cl::opt<size_t> ClMaxLifetimes(
134134
static cl::opt<bool>
135135
ClUseAfterScope("hwasan-use-after-scope",
136136
cl::desc("detect use after scope within function"),
137-
cl::Hidden, cl::init(false));
137+
cl::Hidden, cl::init(true));
138138

139139
static cl::opt<bool> ClGenerateTagsWithCalls(
140140
"hwasan-generate-tags-with-calls",

llvm/test/Instrumentation/HWAddressSanitizer/X86/alloca.ll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,15 @@ define i32 @test_simple(ptr %a) sanitize_hwaddress {
109109
; CHECK-NEXT: [[TMP8:%.*]] = shl i64 [[TMP5]], 57
110110
; CHECK-NEXT: [[TMP9:%.*]] = or i64 [[TMP7]], [[TMP8]]
111111
; CHECK-NEXT: [[BUF_SROA_0_HWASAN:%.*]] = inttoptr i64 [[TMP9]] to ptr
112+
; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 16, ptr nonnull [[BUF_SROA_0]])
112113
; CHECK-NEXT: [[TMP10:%.*]] = trunc i64 [[TMP5]] to i8
113114
; CHECK-NEXT: call void @__hwasan_tag_memory(ptr [[BUF_SROA_0]], i8 [[TMP10]], i64 16)
114115
; CHECK-NEXT: [[TMP11:%.*]] = ptrtoint ptr [[BUF_SROA_0_HWASAN]] to i64
115116
; CHECK-NEXT: call void @__hwasan_store1(i64 [[TMP11]])
116117
; CHECK-NEXT: store volatile i8 0, ptr [[BUF_SROA_0_HWASAN]], align 4
117118
; CHECK-NEXT: [[TMP12:%.*]] = trunc i64 [[HWASAN_UAR_TAG]] to i8
118119
; CHECK-NEXT: call void @__hwasan_tag_memory(ptr [[BUF_SROA_0]], i8 [[TMP12]], i64 16)
120+
; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 16, ptr nonnull [[BUF_SROA_0]])
119121
; CHECK-NEXT: ret i32 0
120122
;
121123
; INLINE-LABEL: define i32 @test_simple
@@ -148,6 +150,7 @@ define i32 @test_simple(ptr %a) sanitize_hwaddress {
148150
; INLINE-NEXT: [[TMP19:%.*]] = shl i64 [[TMP16]], 57
149151
; INLINE-NEXT: [[TMP20:%.*]] = or i64 [[TMP18]], [[TMP19]]
150152
; INLINE-NEXT: [[BUF_SROA_0_HWASAN:%.*]] = inttoptr i64 [[TMP20]] to ptr
153+
; INLINE-NEXT: call void @llvm.lifetime.start.p0(i64 16, ptr nonnull [[BUF_SROA_0]])
151154
; INLINE-NEXT: [[TMP21:%.*]] = trunc i64 [[TMP16]] to i8
152155
; INLINE-NEXT: [[TMP22:%.*]] = ptrtoint ptr [[BUF_SROA_0]] to i64
153156
; INLINE-NEXT: [[TMP23:%.*]] = and i64 [[TMP22]], -9079256848778919937
@@ -194,6 +197,7 @@ define i32 @test_simple(ptr %a) sanitize_hwaddress {
194197
; INLINE-NEXT: [[TMP54:%.*]] = lshr i64 [[TMP53]], 4
195198
; INLINE-NEXT: [[TMP55:%.*]] = getelementptr i8, ptr [[TMP14]], i64 [[TMP54]]
196199
; INLINE-NEXT: call void @llvm.memset.p0.i64(ptr align 1 [[TMP55]], i8 [[TMP51]], i64 1, i1 false)
200+
; INLINE-NEXT: call void @llvm.lifetime.end.p0(i64 16, ptr nonnull [[BUF_SROA_0]])
197201
; INLINE-NEXT: ret i32 0
198202
;
199203
entry:

0 commit comments

Comments
 (0)