[llvm] fb0c50b - [MoveAutoInit] Gracefully handle auto-init annotation on unexpected instr (PR64661)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 15 07:22:10 PDT 2023
Author: Nikita Popov
Date: 2023-08-15T16:21:25+02:00
New Revision: fb0c50be5b66ca689d78ad281cb07bf46d435756
URL: https://github.com/llvm/llvm-project/commit/fb0c50be5b66ca689d78ad281cb07bf46d435756
DIFF: https://github.com/llvm/llvm-project/commit/fb0c50be5b66ca689d78ad281cb07bf46d435756.diff
LOG: [MoveAutoInit] Gracefully handle auto-init annotation on unexpected instr (PR64661)
Abort the transform instead of asserting.
Fixes https://github.com/llvm/llvm-project/issues/64661.
Added:
llvm/test/Transforms/MoveAutoInit/invalid-annotation.ll
Modified:
llvm/lib/Transforms/Utils/MoveAutoInit.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/MoveAutoInit.cpp b/llvm/lib/Transforms/Utils/MoveAutoInit.cpp
index b0ca0b15c08e06..7c6b583dd88f38 100644
--- a/llvm/lib/Transforms/Utils/MoveAutoInit.cpp
+++ b/llvm/lib/Transforms/Utils/MoveAutoInit.cpp
@@ -50,7 +50,7 @@ static std::optional<MemoryLocation> writeToAlloca(const Instruction &I) {
else if (auto *SI = dyn_cast<StoreInst>(&I))
ML = MemoryLocation::get(SI);
else
- assert(false && "memory location set");
+ return std::nullopt;
if (isa<AllocaInst>(getUnderlyingObject(ML.Ptr)))
return ML;
diff --git a/llvm/test/Transforms/MoveAutoInit/invalid-annotation.ll b/llvm/test/Transforms/MoveAutoInit/invalid-annotation.ll
new file mode 100644
index 00000000000000..e87397377cdcca
--- /dev/null
+++ b/llvm/test/Transforms/MoveAutoInit/invalid-annotation.ll
@@ -0,0 +1,14 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
+; RUN: opt -S -passes=move-auto-init < %s | FileCheck %s
+
+define i1 @test(ptr %a, ptr %b) {
+; CHECK-LABEL: define i1 @test
+; CHECK-SAME: (ptr [[A:%.*]], ptr [[B:%.*]]) {
+; CHECK-NEXT: [[C:%.*]] = icmp uge ptr [[A]], [[B]], !annotation !0
+; CHECK-NEXT: ret i1 [[C]]
+;
+ %c = icmp uge ptr %a, %b, !annotation !0
+ ret i1 %c
+}
+
+!0 = !{ !"auto-init" }
More information about the llvm-commits
mailing list