[flang-commits] [flang] 2c27d5b - [flang] Fix internal error with DATA-statement style initializers
Daniil Dudkin via flang-commits
flang-commits at lists.llvm.org
Fri May 6 08:22:25 PDT 2022
Author: Daniil Dudkin
Date: 2022-05-06T18:21:34+03:00
New Revision: 2c27d5b36a55c75a33a2a97198d0f0cd1d3d42bf
URL: https://github.com/llvm/llvm-project/commit/2c27d5b36a55c75a33a2a97198d0f0cd1d3d42bf
DIFF: https://github.com/llvm/llvm-project/commit/2c27d5b36a55c75a33a2a97198d0f0cd1d3d42bf.diff
LOG: [flang] Fix internal error with DATA-statement style initializers
The code below causes flang to crash with an exception.
After fixing the crash flang with an internal error "no symbol found for 'bar'"
This change fixes all the issues.
program name
implicit none
integer, parameter :: bar = 1
integer foo(bar) /bar*2/
end program name
Reviewed By: kiranchandramohan, klausler
Differential Revision: https://reviews.llvm.org/D124914
Added:
flang/test/Semantics/resolve111.f90
Modified:
flang/lib/Semantics/data-to-inits.cpp
flang/lib/Semantics/resolve-names.cpp
Removed:
################################################################################
diff --git a/flang/lib/Semantics/data-to-inits.cpp b/flang/lib/Semantics/data-to-inits.cpp
index 86d45e27a58b6..97b8f7f1094f6 100644
--- a/flang/lib/Semantics/data-to-inits.cpp
+++ b/flang/lib/Semantics/data-to-inits.cpp
@@ -43,7 +43,12 @@ template <typename DSV = parser::DataStmtValue> class ValueListIterator {
bool hasFatalError() const { return hasFatalError_; }
bool IsAtEnd() const { return at_ == end_; }
const SomeExpr *operator*() const { return GetExpr(context_, GetConstant()); }
- parser::CharBlock LocateSource() const { return GetConstant().source; }
+ std::optional<parser::CharBlock> LocateSource() const {
+ if (!hasFatalError_) {
+ return GetConstant().source;
+ }
+ return {};
+ }
ValueListIterator &operator++() {
if (repetitionsRemaining_ > 0) {
--repetitionsRemaining_;
@@ -312,7 +317,9 @@ bool DataInitializationCompiler<DSV>::InitElement(
bool isPointer{lastSymbol && IsPointer(*lastSymbol)};
bool isProcPointer{lastSymbol && IsProcedurePointer(*lastSymbol)};
evaluate::FoldingContext &context{exprAnalyzer_.GetFoldingContext()};
- auto restorer{context.messages().SetLocation(values_.LocateSource())};
+ auto &messages{context.messages()};
+ auto restorer{
+ messages.SetLocation(values_.LocateSource().value_or(messages.at()))};
const auto DescribeElement{[&]() {
if (auto badDesignator{
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index cc02cccdfb1ad..fd1b0a05c65cc 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -6562,9 +6562,10 @@ void DeclarationVisitor::Initialization(const parser::Name &name,
// work better.
ultimate.set(Symbol::Flag::InDataStmt);
},
- [&](const std::list<Indirection<parser::DataStmtValue>> &) {
+ [&](const std::list<Indirection<parser::DataStmtValue>> &values) {
// Handled later in data-to-inits conversion
ultimate.set(Symbol::Flag::InDataStmt);
+ Walk(values);
},
},
init.u);
diff --git a/flang/test/Semantics/resolve111.f90 b/flang/test/Semantics/resolve111.f90
new file mode 100644
index 0000000000000..700c8b3a18df2
--- /dev/null
+++ b/flang/test/Semantics/resolve111.f90
@@ -0,0 +1,7 @@
+!RUN: %flang_fc1 -fdebug-dump-symbols %s | FileCheck %s
+!Resolve names in legacy data initializers
+program name
+ implicit none
+ integer, parameter :: bar = 1
+ integer foo(bar) /bar*2/ !CHECK: foo (InDataStmt) size=4 offset=4: ObjectEntity type: INTEGER(4) shape: 1_8:1_8 init:[INTEGER(4)::2_4]
+end program name
More information about the flang-commits
mailing list