[PATCH] D120437: [HWASAN] erase lifetime intrinsics if tag is outside.

Florian Mayer via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 25 10:10:45 PST 2022


fmayer updated this revision to Diff 411448.
fmayer added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

fix tests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120437/new/

https://reviews.llvm.org/D120437

Files:
  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


Index: llvm/test/Instrumentation/HWAddressSanitizer/use-after-scope.ll
===================================================================
--- llvm/test/Instrumentation/HWAddressSanitizer/use-after-scope.ll
+++ llvm/test/Instrumentation/HWAddressSanitizer/use-after-scope.ll
@@ -45,9 +45,7 @@
 ; 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 @@
 ; 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:
Index: llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
@@ -1371,12 +1371,12 @@
       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()));
   }
Index: clang/test/CodeGenCXX/lifetime-sanitizer.cpp
===================================================================
--- clang/test/CodeGenCXX/lifetime-sanitizer.cpp
+++ clang/test/CodeGenCXX/lifetime-sanitizer.cpp
@@ -6,8 +6,8 @@
 // RUN: %clang -w -target x86_64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 \
 // RUN:     -fsanitize=memory %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: %clang -w -target aarch64-linux-gnu -S -emit-llvm -o /dev/null -fno-exceptions -O0 \
+// RUN:     -fsanitize=hwaddress -mllvm -print-before=hwasan %s 2>&1 | \
 // RUN:     FileCheck %s -check-prefixes=CHECK,LIFETIME
 
 extern int bar(char *A, int n);
Index: clang/test/CodeGen/lifetime-sanitizer.c
===================================================================
--- clang/test/CodeGen/lifetime-sanitizer.c
+++ clang/test/CodeGen/lifetime-sanitizer.c
@@ -5,8 +5,8 @@
 // RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -O0 \
 // RUN:     -fsanitize=memory %s | \
 // RUN:     FileCheck %s -check-prefix=LIFETIME
-// RUN: %clang -target aarch64-linux-gnu -S -emit-llvm -o - -O0 \
-// RUN:     -fsanitize=hwaddress %s | \
+// RUN: %clang -target aarch64-linux-gnu -S -emit-llvm -o /dev/null -O0 \
+// RUN:     -fsanitize=hwaddress -mllvm -print-before=hwasan %s 2>&1 | \
 // RUN:     FileCheck %s -check-prefix=LIFETIME
 
 extern int bar(char *A, int n);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120437.411448.patch
Type: text/x-patch
Size: 4070 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220225/139e9705/attachment.bin>


More information about the cfe-commits mailing list