[flang-commits] [flang] [flang][FIR][Mem2Reg] Do not emit potentially wrong debug info (PR #194837)
via flang-commits
flang-commits at lists.llvm.org
Wed Apr 29 04:27:22 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-fir-hlfir
Author: Ivan R. Ivanov (ivanradanov)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/194837.diff
1 Files Affected:
- (modified) flang/lib/Optimizer/Dialect/FIROps.cpp (+6-1)
``````````diff
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());
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/194837
More information about the flang-commits
mailing list