Skip to content

Commit 4ac617f

Browse files
committed
[flang] Handle DATA initialization of EQUIVALENCE'd objects
Objects that are storage associated by EQUIVALENCE and initialized with DATA are initialized by creating a compiler temporary data object in the same scope, assigning it an offset, type, and size that covers the transitive closure of the associated initialized original symbols, and combining their initializers into one common initializer for the temporary. Some problems with offset assignment of EQUIVALENCE'd objects in COMMON were exposed and corrected, and some more error cases are checked. Remove obsolete function. Small bugfix (nested implied dos). Add a test. Fix struct/class warning. Differential Revision: https://reviews.llvm.org/D85560
1 parent 3c0597a commit 4ac617f

File tree

16 files changed

+743
-480
lines changed

16 files changed

+743
-480
lines changed

flang/include/flang/Evaluate/initial-image.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ class InitialImage {
8787

8888
void AddPointer(ConstantSubscript, const Expr<SomeType> &);
8989

90+
void Incorporate(ConstantSubscript, const InitialImage &);
91+
9092
// Conversions to constant initializers
9193
std::optional<Expr<SomeType>> AsConstant(FoldingContext &,
9294
const DynamicType &, const ConstantSubscripts &,

flang/include/flang/Parser/parsing.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ class Parsing {
6262
o, cooked_.GetProvenanceRange(CharBlock(at)), message, echoSourceLine);
6363
}
6464

65-
bool ForTesting(std::string path, llvm::raw_ostream &);
66-
6765
private:
6866
Options options_;
6967
CookedSource cooked_;

flang/include/flang/Semantics/semantics.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ class SemanticsContext {
170170
void ActivateIndexVar(const parser::Name &, IndexVarKind);
171171
void DeactivateIndexVar(const parser::Name &);
172172
SymbolVector GetIndexVars(IndexVarKind);
173+
SourceName GetTempName(const Scope &);
173174

174175
private:
175176
void CheckIndexVarRedefine(
@@ -196,6 +197,7 @@ class SemanticsContext {
196197
IndexVarKind kind;
197198
};
198199
std::map<SymbolRef, const IndexVarInfo> activeIndexVars_;
200+
std::vector<std::string> tempNames_;
199201
};
200202

201203
class Semantics {

flang/include/flang/Semantics/type.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Bound {
5353
static Bound Assumed() { return Bound(Category::Assumed); }
5454
static Bound Deferred() { return Bound(Category::Deferred); }
5555
explicit Bound(MaybeSubscriptIntExpr &&expr) : expr_{std::move(expr)} {}
56-
explicit Bound(int bound);
56+
explicit Bound(common::ConstantSubscript bound);
5757
Bound(const Bound &) = default;
5858
Bound(Bound &&) = default;
5959
Bound &operator=(const Bound &) = default;

flang/lib/Evaluate/initial-image.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "flang/Evaluate/initial-image.h"
1010
#include "flang/Semantics/scope.h"
1111
#include "flang/Semantics/tools.h"
12+
#include <cstring>
1213

1314
namespace Fortran::evaluate {
1415

@@ -53,6 +54,13 @@ void InitialImage::AddPointer(
5354
pointers_.emplace(offset, pointer);
5455
}
5556

57+
void InitialImage::Incorporate(
58+
ConstantSubscript offset, const InitialImage &that) {
59+
CHECK(that.pointers_.empty()); // pointers are not allowed in EQUIVALENCE
60+
CHECK(offset + that.size() <= size());
61+
std::memcpy(&data_[offset], &that.data_[0], that.size());
62+
}
63+
5664
// Classes used with common::SearchTypes() to (re)construct Constant<> values
5765
// of the right type to initialize each symbol from the values that have
5866
// been placed into its initialization image by DATA statements.

flang/lib/Parser/parsing.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -123,24 +123,4 @@ void Parsing::Parse(llvm::raw_ostream &out) {
123123

124124
void Parsing::ClearLog() { log_.clear(); }
125125

126-
bool Parsing::ForTesting(std::string path, llvm::raw_ostream &err) {
127-
llvm::raw_null_ostream NullStream;
128-
Prescan(path, Options{});
129-
if (messages_.AnyFatalError()) {
130-
messages_.Emit(err, cooked_);
131-
err << "could not scan " << path << '\n';
132-
return false;
133-
}
134-
Parse(NullStream);
135-
messages_.Emit(err, cooked_);
136-
if (!consumedWholeFile_) {
137-
EmitMessage(err, finalRestingPlace_, "parser FAIL; final position");
138-
return false;
139-
}
140-
if (messages_.AnyFatalError() || !parseTree_.has_value()) {
141-
err << "could not parse " << path << '\n';
142-
return false;
143-
}
144-
return true;
145-
}
146126
} // namespace Fortran::parser

flang/lib/Semantics/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ add_flang_library(FortranSemantics
2626
check-select-type.cpp
2727
check-stop.cpp
2828
compute-offsets.cpp
29+
data-to-inits.cpp
2930
expression.cpp
3031
mod-file.cpp
3132
pointer-assignment.cpp

0 commit comments

Comments
 (0)