[flang-commits] [flang] [flang][FIR][Mem2Reg] Do not emit potentially wrong debug info (PR #194837)
Ivan R. Ivanov via flang-commits
flang-commits at lists.llvm.org
Wed Apr 29 04:26:38 PDT 2026
https://github.com/ivanradanov created https://github.com/llvm/llvm-project/pull/194837
When mem2reg replaces values, it can potentially replace a value that is stored before a fir.declare comes in scope, when the fir.declare was inlined from another routine. When we emit a declare_value op for such a variable, it can potentially break dominance with regards to the fir.dummy_scope op.
Do not emit fir.declare_value op in such cases to prevent compiler crashes.
>From 7da9efcd849a2e885103e8f0f26bb855bc0d2b4e Mon Sep 17 00:00:00 2001
From: Ivan Radanov Ivanov <iivanov at nvidia.com>
Date: Wed, 29 Apr 2026 04:12:20 -0700
Subject: [PATCH] [flang][FIR][Mem2Reg] Do not emit potentially wrong debug
info
When mem2reg replaces values, it can potentially replace a value that is
stored before a fir.declare comes in scope, when the fir.declare was
inlined from another routine. When we emit a declare_value op for such a
variable, it can potentially break dominance with regards to the
fir.dummy_scope op.
Do not emit fir.declare_value op in such cases to prevent compiler
crashes.
---
flang/lib/Optimizer/Dialect/FIROps.cpp | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp
index b412bc66718ac..8b730aba92d2b 100644
--- a/flang/lib/Optimizer/Dialect/FIROps.cpp
+++ b/flang/lib/Optimizer/Dialect/FIROps.cpp
@@ -5646,8 +5646,13 @@ void fir::DeclareOp::visitReplacedValues(
llvm::ArrayRef<std::pair<mlir::Operation *, mlir::Value>> definitions,
mlir::OpBuilder &builder) {
for (auto [op, value] : definitions) {
+ // Do not emit DeclareValue when we have a dummy scope as this can
+ // potentially result in us generating it where the DummyScope does not
+ // dominate it. This can happen after inlining.
+ if (getDummyScope())
+ continue;
builder.setInsertionPointAfter(op);
- fir::DeclareValueOp::create(builder, getLoc(), value, getDummyScope(),
+ fir::DeclareValueOp::create(builder, getLoc(), value, nullptr,
getUniqNameAttr(), getFortranAttrsAttr(),
getDataAttrAttr(), getDummyArgNoAttr());
}
More information about the flang-commits
mailing list