[flang-commits] [PATCH] D119847: [flang] Handle CALL C_F_POINTER(without SHAPE=)
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Tue Feb 15 08:22:48 PST 2022
klausler created this revision.
klausler added a reviewer: vdonaldson.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
klausler requested review of this revision.
Calls to C_F_POINTER() without the optional SHAPE= third argument
were failing to be recognized as proper calls to the intrinsic,
but the failure was not generating any error message. This led to
a crash in lowering, which rightfully expects a typed expression
to be associated with the call.
So (1) catch silent failures to convert CALL statements as internal
errors, as is done for expressions and assignment statements; and
(2) clean up C_F_POINTER intrinsic handling to cope with only two
arguments and to emit an error for a FPTR= argument with no type.
https://reviews.llvm.org/D119847
Files:
flang/lib/Evaluate/intrinsics.cpp
flang/lib/Semantics/expression.cpp
flang/test/Semantics/c_f_pointer.f90
Index: flang/test/Semantics/c_f_pointer.f90
===================================================================
--- flang/test/Semantics/c_f_pointer.f90
+++ flang/test/Semantics/c_f_pointer.f90
@@ -29,4 +29,6 @@
call c_f_pointer(scalarC, charDeferredF)
!ERROR: FPTR= argument to C_F_POINTER() may not be a coindexed object
call c_f_pointer(scalarC, coindexed[0]%p)
+ !ERROR: FPTR= argument to C_F_POINTER() must have a type
+ call c_f_pointer(scalarC, null())
end program
Index: flang/lib/Semantics/expression.cpp
===================================================================
--- flang/lib/Semantics/expression.cpp
+++ flang/lib/Semantics/expression.cpp
@@ -2387,13 +2387,20 @@
ProcedureDesignator *proc{std::get_if<ProcedureDesignator>(&callee->u)};
CHECK(proc);
if (CheckCall(call.source, *proc, callee->arguments)) {
- bool hasAlternateReturns{HasAlternateReturns(callee->arguments)};
callStmt.typedCall.Reset(
new ProcedureRef{std::move(*proc), std::move(callee->arguments),
- hasAlternateReturns},
+ HasAlternateReturns(callee->arguments)},
ProcedureRef::Deleter);
+ return;
}
}
+ if (!context_.AnyFatalError()) {
+ std::string buf;
+ llvm::raw_string_ostream dump{buf};
+ parser::DumpTree(dump, callStmt);
+ Say("Internal error: Expression analysis failed on CALL statement: %s"_err_en_US,
+ dump.str());
+ }
}
}
Index: flang/lib/Evaluate/intrinsics.cpp
===================================================================
--- flang/lib/Evaluate/intrinsics.cpp
+++ flang/lib/Evaluate/intrinsics.cpp
@@ -2154,6 +2154,9 @@
fptr.intent = common::Intent::Out;
fptr.attrs.set(characteristics::DummyDataObject::Attr::Pointer);
dummies.emplace_back("fptr"s, std::move(fptr));
+ } else {
+ context.messages().Say(
+ "FPTR= argument to C_F_POINTER() must have a type"_err_en_US);
}
if (arguments[2] && fptrRank == 0) {
context.messages().Say(
@@ -2162,23 +2165,22 @@
context.messages().Say(
"SHAPE= argument to C_F_POINTER() must appear when FPTR= is an array"_err_en_US);
}
- if (arguments[2]) {
- DynamicType shapeType{
- TypeCategory::Integer, defaults_.sizeIntegerKind()};
- if (auto type{arguments[2]->GetType()}) {
- if (type->category() == TypeCategory::Integer) {
- shapeType = *type;
- }
+ }
+ }
+ if (dummies.size() == 2) {
+ DynamicType shapeType{TypeCategory::Integer, defaults_.sizeIntegerKind()};
+ if (arguments[2]) {
+ if (auto type{arguments[2]->GetType()}) {
+ if (type->category() == TypeCategory::Integer) {
+ shapeType = *type;
}
- characteristics::DummyDataObject shape{
- characteristics::TypeAndShape{shapeType, 1}};
- shape.intent = common::Intent::In;
- shape.attrs.set(characteristics::DummyDataObject::Attr::Optional);
- dummies.emplace_back("shape"s, std::move(shape));
}
}
- }
- if (dummies.size() == 3) {
+ characteristics::DummyDataObject shape{
+ characteristics::TypeAndShape{shapeType, 1}};
+ shape.intent = common::Intent::In;
+ shape.attrs.set(characteristics::DummyDataObject::Attr::Optional);
+ dummies.emplace_back("shape"s, std::move(shape));
return SpecificCall{
SpecificIntrinsic{"__builtin_c_f_pointer"s,
characteristics::Procedure{std::move(dummies), attrs}},
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119847.408880.patch
Type: text/x-patch
Size: 3573 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220215/a670dc93/attachment.bin>
More information about the flang-commits
mailing list