[clang] 1d730d8 - [HWASAN] erase lifetime intrinsics if tag is outside.
Florian Mayer via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 1 14:47:43 PST 2022
Author: Florian Mayer
Date: 2022-03-01T14:47:33-08:00
New Revision: 1d730d80ce592fde66b1ba6153f08f72778f94ce
URL: https://github.com/llvm/llvm-project/commit/1d730d80ce592fde66b1ba6153f08f72778f94ce
DIFF: https://github.com/llvm/llvm-project/commit/1d730d80ce592fde66b1ba6153f08f72778f94ce.diff
LOG: [HWASAN] erase lifetime intrinsics if tag is outside.
Reviewed By: eugenis
Differential Revision: https://reviews.llvm.org/D120437
Added:
Modified:
clang/test/CodeGen/lifetime-sanitizer.c
clang/test/CodeGenCXX/lifetime-sanitizer.cpp
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
llvm/test/Instrumentation/HWAddressSanitizer/use-after-scope.ll
Removed:
################################################################################
diff --git a/clang/test/CodeGen/lifetime-sanitizer.c b/clang/test/CodeGen/lifetime-sanitizer.c
index 95fa970c72bc8..32adc36f01455 100644
--- a/clang/test/CodeGen/lifetime-sanitizer.c
+++ b/clang/test/CodeGen/lifetime-sanitizer.c
@@ -1,12 +1,13 @@
-// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -O0 %s | FileCheck %s -check-prefix=CHECK-O0
// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -O0 \
-// RUN: -fsanitize=address -fsanitize-address-use-after-scope %s | \
-// RUN: FileCheck %s -check-prefix=LIFETIME
+// RUN: -Xclang -disable-llvm-passes %s | FileCheck %s -check-prefix=CHECK-O0
+// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -O0 \
+// RUN: -fsanitize=address -fsanitize-address-use-after-scope \
+// RUN: -Xclang -disable-llvm-passes %s | FileCheck %s -check-prefix=LIFETIME
// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -O0 \
-// RUN: -fsanitize=memory %s | \
+// RUN: -fsanitize=memory -Xclang -disable-llvm-passes %s | \
// RUN: FileCheck %s -check-prefix=LIFETIME
// RUN: %clang -target aarch64-linux-gnu -S -emit-llvm -o - -O0 \
-// RUN: -fsanitize=hwaddress %s | \
+// RUN: -fsanitize=hwaddress -Xclang -disable-llvm-passes %s | \
// RUN: FileCheck %s -check-prefix=LIFETIME
extern int bar(char *A, int n);
diff --git a/clang/test/CodeGenCXX/lifetime-sanitizer.cpp b/clang/test/CodeGenCXX/lifetime-sanitizer.cpp
index 3cce664689598..8c7900294ef40 100644
--- a/clang/test/CodeGenCXX/lifetime-sanitizer.cpp
+++ b/clang/test/CodeGenCXX/lifetime-sanitizer.cpp
@@ -1,13 +1,14 @@
-// RUN: %clang -w -target x86_64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 %s | \
-// RUN: FileCheck %s -check-prefixes=CHECK --implicit-check-not=llvm.lifetime
// RUN: %clang -w -target x86_64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 \
-// RUN: -fsanitize=address -fsanitize-address-use-after-scope %s | \
-// RUN: FileCheck %s -check-prefixes=CHECK,LIFETIME
+// RUN: -Xclang -disable-llvm-passes %s | FileCheck %s -check-prefixes=CHECK \
+// RUN: --implicit-check-not=llvm.lifetime
+// RUN: %clang -w -target x86_64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 \
+// RUN: -fsanitize=address -fsanitize-address-use-after-scope \
+// RUN: -Xclang -disable-llvm-passes %s | FileCheck %s -check-prefixes=CHECK,LIFETIME
// RUN: %clang -w -target x86_64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 \
-// RUN: -fsanitize=memory %s | \
+// RUN: -fsanitize=memory -Xclang -disable-llvm-passes %s | \
// RUN: FileCheck %s -check-prefixes=CHECK,LIFETIME
// RUN: %clang -w -target aarch64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 \
-// RUN: -fsanitize=hwaddress %s | \
+// RUN: -fsanitize=hwaddress -Xclang -disable-llvm-passes %s | \
// RUN: FileCheck %s -check-prefixes=CHECK,LIFETIME
extern int bar(char *A, int n);
diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
index 350f9701d48d4..2b9e8655e4c93 100644
--- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
@@ -1371,12 +1371,12 @@ bool HWAddressSanitizer::instrumentStack(
tagAlloca(IRB, AI, Tag, Size);
for (auto *RI : SInfo.RetVec)
TagEnd(RI);
- if (!StandardLifetime) {
- for (auto &II : Info.LifetimeStart)
- II->eraseFromParent();
- for (auto &II : Info.LifetimeEnd)
- II->eraseFromParent();
- }
+ // We inserted tagging outside of the lifetimes, so we have to remove
+ // them.
+ for (auto &II : Info.LifetimeStart)
+ II->eraseFromParent();
+ for (auto &II : Info.LifetimeEnd)
+ II->eraseFromParent();
}
memtag::alignAndPadAlloca(Info, Align(Mapping.getObjectAlignment()));
}
diff --git a/llvm/test/Instrumentation/HWAddressSanitizer/use-after-scope.ll b/llvm/test/Instrumentation/HWAddressSanitizer/use-after-scope.ll
index 907fe026682c2..85309819a2eb9 100644
--- a/llvm/test/Instrumentation/HWAddressSanitizer/use-after-scope.ll
+++ b/llvm/test/Instrumentation/HWAddressSanitizer/use-after-scope.ll
@@ -45,9 +45,7 @@ define dso_local i32 @standard_lifetime() local_unnamed_addr sanitize_hwaddress
; NOSCOPE-NEXT: call void @__hwasan_tag_memory(i8* [[TMP2]], i8 [[TMP8]], i64 16)
; NOSCOPE-NEXT: br label [[TMP9:%.*]]
; NOSCOPE: 9:
-; NOSCOPE-NEXT: call void @llvm.lifetime.start.p0i8(i64 1, i8* nonnull [[ALLOCA_0_HWASAN]])
; NOSCOPE-NEXT: [[TMP10:%.*]] = tail call i1 (...) @cond()
-; NOSCOPE-NEXT: call void @llvm.lifetime.end.p0i8(i64 1, i8* nonnull [[ALLOCA_0_HWASAN]])
; NOSCOPE-NEXT: br i1 [[TMP10]], label [[TMP11:%.*]], label [[TMP9]]
; NOSCOPE: 11:
; NOSCOPE-NEXT: call void @use(i8* nonnull [[ALLOCA_0_HWASAN]])
@@ -153,12 +151,10 @@ define dso_local i32 @unreachable_exit() local_unnamed_addr sanitize_hwaddress {
; NOSCOPE-NEXT: [[ALLOCA_0_HWASAN:%.*]] = inttoptr i64 [[TMP7]] to i8*
; NOSCOPE-NEXT: [[TMP8:%.*]] = trunc i64 [[TMP4]] to i8
; NOSCOPE-NEXT: call void @__hwasan_tag_memory(i8* [[TMP2]], i8 [[TMP8]], i64 16)
-; NOSCOPE-NEXT: call void @llvm.lifetime.start.p0i8(i64 1, i8* nonnull [[ALLOCA_0_HWASAN]])
; NOSCOPE-NEXT: [[TMP9:%.*]] = tail call i1 (...) @cond()
; NOSCOPE-NEXT: br i1 [[TMP9]], label [[TMP10:%.*]], label [[TMP11:%.*]]
; NOSCOPE: 10:
; NOSCOPE-NEXT: call void @use(i8* nonnull [[ALLOCA_0_HWASAN]])
-; NOSCOPE-NEXT: call void @llvm.lifetime.end.p0i8(i64 1, i8* nonnull [[ALLOCA_0_HWASAN]])
; NOSCOPE-NEXT: call void @__hwasan_tag_memory(i8* [[TMP2]], i8 0, i64 16)
; NOSCOPE-NEXT: ret i32 0
; NOSCOPE: 11:
More information about the cfe-commits
mailing list