[PATCH] D108337: StackLifetime: Remove asserts for multiple lifetime intrinsics.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 18 15:14:55 PDT 2021


pcc created this revision.
pcc added reviewers: eugenis, fmayer, vitalybuka.
Herald added a subscriber: hiraditya.
pcc requested review of this revision.
Herald added a project: LLVM.

According to the langref, it is valid to have multiple consecutive
lifetime start or end intrinsics on the same object.

For llvm.lifetime.start:
"If ptr [...] is a stack object that is already alive, it simply
fills all bytes of the object with poison."

For llvm.lifetime.end:
"Calling llvm.lifetime.end on an already dead alloca is no-op."

However, we currently fail an assertion in such cases. I've observed
the assertion failure when the loop vectorization pass duplicates
the intrinsic.

We can conservatively handle these intrinsics by ignoring all but
the first one, which can be implemented by removing the assertions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108337

Files:
  llvm/lib/Analysis/StackLifetime.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
@@ -179,6 +179,20 @@
   ret i32 0
 }
 
+define dso_local i32 @multiple_start_end() local_unnamed_addr sanitize_hwaddress {
+; SCOPE-LABEL: @multiple_start_end(
+; SCOPE: call void @__hwasan_tag_memory
+; SCOPE: call void @use
+; SCOPE: call void @__hwasan_tag_memory
+  %1 = alloca i8, align 1
+  call void @llvm.lifetime.start.p0i8(i64 1, i8* nonnull %1)
+  call void @llvm.lifetime.start.p0i8(i64 1, i8* nonnull %1)
+  call void @use(i8* nonnull %1)
+  call void @llvm.lifetime.end.p0i8(i64 1, i8* nonnull %1)
+  call void @llvm.lifetime.end.p0i8(i64 1, i8* nonnull %1)
+  ret i32 0
+}
+
 declare dso_local i1 @cond(...) local_unnamed_addr
 
 declare dso_local void @use(i8*) local_unnamed_addr
Index: llvm/lib/Analysis/StackLifetime.cpp
===================================================================
--- llvm/lib/Analysis/StackLifetime.cpp
+++ llvm/lib/Analysis/StackLifetime.cpp
@@ -257,14 +257,12 @@
       unsigned AllocaNo = It.second.AllocaNo;
 
       if (IsStart) {
-        assert(!Started.test(AllocaNo) || Start[AllocaNo] == BBStart);
         if (!Started.test(AllocaNo)) {
           Started.set(AllocaNo);
           Ended.reset(AllocaNo);
           Start[AllocaNo] = InstNo;
         }
       } else {
-        assert(!Ended.test(AllocaNo));
         if (Started.test(AllocaNo)) {
           LiveRanges[AllocaNo].addRange(Start[AllocaNo], InstNo);
           Started.reset(AllocaNo);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108337.367339.patch
Type: text/x-patch
Size: 1682 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210818/a851baae/attachment.bin>


More information about the llvm-commits mailing list