https://github.com/Kristianerik updated https://github.com/llvm/llvm-project/pull/208826
>From e35009d0fa95e12c81b045e42480c19142838f7f Mon Sep 17 00:00:00 2001 From: Kristianerik <[email protected]> Date: Fri, 10 Jul 2026 12:53:11 -0700 Subject: [PATCH] [SROA] Fix assertion failure when promoting self-referential load/store --- clang/test/Parser/cxx-missing-semi-crash.cpp | 2 +- llvm/lib/Transforms/Utils/SSAUpdater.cpp | 3 +++ .../SROA/sroa-self-referential-load.ll | 20 +++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 llvm/test/Transforms/SROA/sroa-self-referential-load.ll diff --git a/clang/test/Parser/cxx-missing-semi-crash.cpp b/clang/test/Parser/cxx-missing-semi-crash.cpp index bed8a2633a618..a41eda6fc5419 100644 --- a/clang/test/Parser/cxx-missing-semi-crash.cpp +++ b/clang/test/Parser/cxx-missing-semi-crash.cpp @@ -10,5 +10,5 @@ void bar() { } ::foo<int>; // expected-error {{no template named 'foo' in the global namespace; did you mean simply 'foo'?}} \ // expected-error {{template specialization requires 'template<>'}} } -} // namespace N +} // namespace GH207992 // expected-error@* {{templates can only be declared in namespace or class scope}} diff --git a/llvm/lib/Transforms/Utils/SSAUpdater.cpp b/llvm/lib/Transforms/Utils/SSAUpdater.cpp index b6c5c28161fd8..44afd43ec3896 100644 --- a/llvm/lib/Transforms/Utils/SSAUpdater.cpp +++ b/llvm/lib/Transforms/Utils/SSAUpdater.cpp @@ -447,6 +447,9 @@ void LoadAndStorePromoter::run(const SmallVectorImpl<Instruction *> &Insts) { // use the stored value. if (StoredValue) { replaceLoadWithValue(L, StoredValue); + // Avoid assertions in unreachable code. + if (StoredValue == L) + StoredValue = PoisonValue::get(L->getType()); L->replaceAllUsesWith(StoredValue); ReplacedLoads[L] = StoredValue; } else { diff --git a/llvm/test/Transforms/SROA/sroa-self-referential-load.ll b/llvm/test/Transforms/SROA/sroa-self-referential-load.ll new file mode 100644 index 0000000000000..2d489208e3a1b --- /dev/null +++ b/llvm/test/Transforms/SROA/sroa-self-referential-load.ll @@ -0,0 +1,20 @@ +; RUN: opt --passes=sroa %s -S -o - 2>&1 | FileCheck %s + +; Ensure no crash when a store's value operand is the load being promoted, +; creating a self-referential cycle in unreachable code." + +define i32 @func() { +entry: + %a = alloca [2 x i32], align 4 + br label %loop + +loop: + br label %loop + +exit: + store i32 %0, ptr %a, align 4 + %0 = load i32, ptr %a, align 4 + br label %exit +} + +; CHECK-LABEL: @func _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
