Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions flang/include/flang/Semantics/symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -874,10 +874,24 @@ class Symbol {
Scope *scope() { return scope_; }
const Scope *scope() const { return scope_; }
void set_scope(Scope *scope) { scope_ = scope; }
std::size_t size() const { return size_; }
std::optional<std::size_t> sizeOpt() const { return size_; }
std::size_t size() const {
// NOTE: I tried to insert the following check, but there are places where
// we are relying on the fact that the size is 0 if it is not set.
// CHECK(size_.has_value());
return size_.value_or(0);
}
void set_size(std::size_t size) { size_ = size; }
std::size_t offset() const { return offset_; }
void set_size(std::optional<std::size_t> size) { size_ = size; }
std::optional<std::size_t> offsetOpt() const { return offset_; }
std::size_t offset() const {
// NOTE: I tried to insert the following check, but there are places where
// we are relying on the fact that the offset is 0 if it is not set.
// CHECK(offset_.has_value());
return offset_.value_or(0);
}
void set_offset(std::size_t offset) { offset_ = offset; }
void set_offset(std::optional<std::size_t> offset) { offset_ = offset; }
// Give the symbol a name with a different source location but same chars.
void ReplaceName(const SourceName &);
static std::string OmpFlagToClauseName(Flag ompFlag);
Expand Down Expand Up @@ -986,8 +1000,8 @@ class Symbol {
Attrs implicitAttrs_; // subset of attrs_ that were not explicit
Flags flags_;
Scope *scope_{nullptr};
std::size_t size_{0}; // size in bytes
std::size_t offset_{0}; // byte offset in scope or common block
std::optional<std::size_t> size_; // size in bytes
std::optional<std::size_t> offset_; // byte offset in scope or common block
Details details_;

Symbol() {} // only created in class Symbols
Expand Down
5 changes: 5 additions & 0 deletions flang/lib/Semantics/compute-offsets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ void ComputeOffsetsHelper::Compute(Scope &scope) {
}
}
for (auto &[symbol, dep] : dependents_) {
// We are occassionally relying offset here to return zero when
// it has not been set yet.
symbol->set_offset(dep.symbol->offset() + dep.offset);
if (const auto *block{FindCommonBlockContaining(*dep.symbol)}) {
symbol->get<ObjectEntityDetails>().set_commonBlock(*block);
Expand Down Expand Up @@ -393,11 +395,14 @@ std::size_t ComputeOffsetsHelper::ComputeOffset(

std::size_t ComputeOffsetsHelper::DoSymbol(
Symbol &symbol, std::optional<const size_t> newAlign) {
// Symbols such as the main program and modules.
if (!symbol.has<ObjectEntityDetails>() && !symbol.has<ProcEntityDetails>()) {
return 0;
}
SizeAndAlignment s{GetSizeAndAlignment(symbol, true)};
if (s.size == 0) {
// FIXME: Errors that prevent us from computing the symbols size or
// variables that really require no storage should be set here.
return 0;
}
std::size_t previousOffset{offset_};
Expand Down
2 changes: 1 addition & 1 deletion flang/lib/Semantics/data-to-inits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ static bool CombineEquivalencedInitialization(
combinedSymbol.set(Symbol::Flag::CompilerCreated);
inits.emplace(&combinedSymbol, std::move(combined));
auto &details{combinedSymbol.get<ObjectEntityDetails>()};
combinedSymbol.set_offset(first.offset());
combinedSymbol.set_offset(first.offsetOpt());
combinedSymbol.set_size(bytes);
std::size_t minElementBytes{
ComputeMinElementBytes(associated, foldingContext)};
Expand Down
4 changes: 2 additions & 2 deletions flang/lib/Semantics/symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,8 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const Symbol &symbol) {
if (!symbol.flags().empty()) {
os << " (" << symbol.flags() << ')';
}
if (symbol.size_) {
os << " size=" << symbol.size_ << " offset=" << symbol.offset_;
if (symbol.size_ && *symbol.size_) {
os << " size=" << symbol.size_ << " offset=" << symbol.offset();
}
os << ": " << symbol.details_;
return os;
Expand Down