Skip to content
Merged
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: 21 additions & 1 deletion flang/lib/Lower/ConvertConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,34 @@ class DenseGlobalBuilder {
fir::FirOpBuilder &builder,
const Fortran::evaluate::Constant<Fortran::evaluate::Type<TC, KIND>>
&constant) {
using Element =
Fortran::evaluate::Scalar<Fortran::evaluate::Type<TC, KIND>>;

static_assert(TC != Fortran::common::TypeCategory::Character,
"must be numerical or logical");
auto attrTc = TC == Fortran::common::TypeCategory::Logical
? Fortran::common::TypeCategory::Integer
: TC;
attributeElementType =
Fortran::lower::getFIRType(builder.getContext(), attrTc, KIND, {});
for (auto element : constant.values())

const std::vector<Element> &values = constant.values();
auto sameElements = [&]() -> bool {
if (values.empty())
return false;

return std::all_of(values.begin(), values.end(),
[&](const auto &v) { return v == values.front(); });
};

if (sameElements()) {
auto attr = convertToAttribute<TC, KIND>(builder, values.front(),
attributeElementType);
attributes.assign(values.size(), attr);
return;
}

for (auto element : values)
attributes.push_back(
convertToAttribute<TC, KIND>(builder, element, attributeElementType));
}
Expand Down
Loading