Skip to content

[flang] Emit warning when Hollerith actual passed to CLASS(*) #84084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2024
Merged
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
3 changes: 3 additions & 0 deletions flang/include/flang/Evaluate/constant.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ class Constant<Type<TypeCategory::Character, KIND>> : public ConstantBounds {

const Scalar<Result> &values() const { return values_; }
ConstantSubscript LEN() const { return length_; }
bool wasHollerith() const { return wasHollerith_; }
void set_wasHollerith(bool yes = true) { wasHollerith_ = yes; }

std::optional<Scalar<Result>> GetScalarValue() const {
if (Rank() == 0) {
Expand All @@ -210,6 +212,7 @@ class Constant<Type<TypeCategory::Character, KIND>> : public ConstantBounds {
private:
Scalar<Result> values_; // one contiguous string
ConstantSubscript length_;
bool wasHollerith_{false};
};

class StructureConstructor;
Expand Down
10 changes: 9 additions & 1 deletion flang/lib/Semantics/check-call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,15 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
bool typesCompatible{typesCompatibleWithIgnoreTKR ||
dummy.type.type().IsTkCompatibleWith(actualType.type())};
int dummyRank{dummy.type.Rank()};
if (!typesCompatible && dummyRank == 0 && allowActualArgumentConversions) {
if (typesCompatible) {
if (const auto *constantChar{
evaluate::UnwrapConstantValue<evaluate::Ascii>(actual)};
constantChar && constantChar->wasHollerith() &&
dummy.type.type().IsUnlimitedPolymorphic()) {
messages.Say(
"passing Hollerith to unlimited polymorphic as if it were CHARACTER"_port_en_US);
}
} else if (dummyRank == 0 && allowActualArgumentConversions) {
// Extension: pass Hollerith literal to scalar as if it had been BOZ
if (auto converted{evaluate::HollerithToBOZ(
foldingContext, actual, dummy.type.type())}) {
Expand Down
7 changes: 5 additions & 2 deletions flang/lib/Semantics/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -875,8 +875,11 @@ MaybeExpr ExpressionAnalyzer::Analyze(const parser::CharLiteralConstant &x) {
MaybeExpr ExpressionAnalyzer::Analyze(
const parser::HollerithLiteralConstant &x) {
int kind{GetDefaultKind(TypeCategory::Character)};
auto value{x.v};
return AnalyzeString(std::move(value), kind);
auto result{AnalyzeString(std::string{x.v}, kind)};
if (auto *constant{UnwrapConstantValue<Ascii>(result)}) {
constant->set_wasHollerith(true);
}
return result;
}

// .TRUE. and .FALSE. of various kinds
Expand Down
12 changes: 12 additions & 0 deletions flang/test/Semantics/call41.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
! RUN: %python %S/test_errors.py %s %flang_fc1 -Werror
module m
contains
subroutine unlimited(x)
class(*), intent(in) :: x
end
subroutine test
!PORTABILITY: passing Hollerith to unlimited polymorphic as if it were CHARACTER
call unlimited(6HHERMAN)
call unlimited('abc') ! ok
end
end