forked from OSchip/llvm-project
[flang] Address comment: make error a warning instead and ignore RESULT
Instead of emitting an error when RESULT has the same name as the function, emit a warning and ignore RESULT in the rest of the compilation. Original-commit: flang-compiler/f18@8ce3862d39 Reviewed-on: https://github.com/flang-compiler/f18/pull/743
This commit is contained in:
parent
ca86308453
commit
ba89315523
|
@ -2492,6 +2492,7 @@ void SubprogramVisitor::Post(const parser::FunctionStmt &stmt) {
|
|||
}
|
||||
const parser::Name *funcResultName;
|
||||
if (funcInfo_.resultName && funcInfo_.resultName->source != name.source) {
|
||||
// Note that RESULT is ignored if it has the same name as the function.
|
||||
funcResultName = funcInfo_.resultName;
|
||||
} else {
|
||||
EraseSymbol(name); // was added by PushSubprogramScope
|
||||
|
@ -2502,14 +2503,21 @@ void SubprogramVisitor::Post(const parser::FunctionStmt &stmt) {
|
|||
funcResultDetails.set_funcResult(true);
|
||||
funcInfo_.resultSymbol =
|
||||
&MakeSymbol(*funcResultName, std::move(funcResultDetails));
|
||||
if (funcInfo_.resultName && funcInfo_.resultName->source == name.source) {
|
||||
// C1560. TODO also enforce on entry names when entry implemented
|
||||
Say(funcInfo_.resultName->source,
|
||||
"'%s' is already the function name and cannot appear in RESULT"_err_en_US,
|
||||
name.source);
|
||||
context().SetError(*funcInfo_.resultSymbol);
|
||||
}
|
||||
details.set_result(*funcInfo_.resultSymbol);
|
||||
|
||||
// C1560. TODO also enforce on entry names when entry implemented
|
||||
if (funcInfo_.resultName && funcInfo_.resultName->source == name.source) {
|
||||
Say(funcInfo_.resultName->source,
|
||||
"The function name should not appear in RESULT, references to '%s' "
|
||||
"inside"
|
||||
" the function will be considered as references to the result only"_en_US,
|
||||
name.source);
|
||||
// RESULT name was ignored above, the only side effect from doing so will be
|
||||
// the inability to make recursive calls. The related parser::Name is still
|
||||
// resolved to the created function result symbol because every parser::Name
|
||||
// should be resolved to avoid internal errors.
|
||||
Resolve(*funcInfo_.resultName, funcInfo_.resultSymbol);
|
||||
}
|
||||
name.symbol = currScope().symbol(); // must not be function result symbol
|
||||
}
|
||||
|
||||
|
|
|
@ -71,21 +71,21 @@ contains
|
|||
!ERROR: Typeless item not allowed for 'x=' argument
|
||||
x = acos(f5)
|
||||
end function
|
||||
! Sanity test: f18 handles C1560 violation by ignoring RESULT
|
||||
function f6() result(f6) !OKI (warning)
|
||||
end function
|
||||
function f7() result(f7) !OKI (warning)
|
||||
real :: x, f7
|
||||
!ERROR: Reference to array 'f7' with empty subscript list
|
||||
x = acos(f7())
|
||||
f7 = x
|
||||
x = acos(f7) !OK
|
||||
end function
|
||||
end module
|
||||
|
||||
module m_with_result
|
||||
! With RESULT, it refers to the function (recursive calls possible)
|
||||
contains
|
||||
! Sanity test C1560
|
||||
!ERROR: 'f00' is already the function name and cannot appear in RESULT
|
||||
function f00() result(f00)
|
||||
end function
|
||||
!ERROR: 'f0' is already the function name and cannot appear in RESULT
|
||||
function f0(i) result(f0)
|
||||
integer :: i
|
||||
complex(4) :: f0
|
||||
f0 = f0(i+1)*2.
|
||||
end function
|
||||
|
||||
! testing with data object results
|
||||
function f1() result(r)
|
||||
|
|
Loading…
Reference in New Issue