forked from OSchip/llvm-project
[flang] Fix bad dereference of NULLIFY pointer object
When we have a subprogram that has been determined to contain errors, we do not perform name resolution on its execution part. In this case, if the subprogram contains a NULLIFY statement, the parser::Name of a pointer object in a NULLIFY statement will not have had name resolution performed on it. Thus, its symbol will not have been set. Later, however, we do semantic checking on the NULLIFY statement. The code that did this assumed that the parser::Name of the pointer object was non-null. I fixed this by just removing the null pointer check for the "symbol" member of the "parser::Name" of the pointer object when doing semantic checking for NULLIFY statements. I also added a test that will make the compiler crash without this change. Differential Revision: https://reviews.llvm.org/D98184
This commit is contained in:
parent
535a4192a9
commit
cfd7d8123a
|
@ -26,17 +26,17 @@ void NullifyChecker::Leave(const parser::NullifyStmt &nullifyStmt) {
|
|||
std::visit(
|
||||
common::visitors{
|
||||
[&](const parser::Name &name) {
|
||||
const Symbol &symbol{DEREF(name.symbol)};
|
||||
if (context_.HasError(&symbol)) {
|
||||
const Symbol *symbol{name.symbol};
|
||||
if (context_.HasError(symbol)) {
|
||||
// already reported an error
|
||||
} else if (!IsVariableName(symbol) && !IsProcName(symbol)) {
|
||||
} else if (!IsVariableName(*symbol) && !IsProcName(*symbol)) {
|
||||
messages.Say(name.source,
|
||||
"name in NULLIFY statement must be a variable or procedure pointer name"_err_en_US);
|
||||
} else if (!IsPointer(symbol)) { // C951
|
||||
} else if (!IsPointer(*symbol)) { // C951
|
||||
messages.Say(name.source,
|
||||
"name in NULLIFY statement must have the POINTER attribute"_err_en_US);
|
||||
} else if (pure) {
|
||||
CheckDefinabilityInPureScope(messages, symbol, scope, *pure);
|
||||
CheckDefinabilityInPureScope(messages, *symbol, scope, *pure);
|
||||
}
|
||||
},
|
||||
[&](const parser::StructureComponent &structureComponent) {
|
||||
|
|
|
@ -29,3 +29,21 @@ Nullify(prp)
|
|||
Nullify(maxvalue)
|
||||
|
||||
End Program
|
||||
|
||||
! Make sure that the compiler doesn't crash when NULLIFY is used in a context
|
||||
! that has reported errors
|
||||
module badNullify
|
||||
interface
|
||||
module function ptrFun()
|
||||
integer, pointer :: ptrFun
|
||||
end function
|
||||
end interface
|
||||
contains
|
||||
!ERROR: 'ptrfun' was not declared a separate module procedure
|
||||
module function ptrFun()
|
||||
integer, pointer :: ptrFun
|
||||
real :: realVar
|
||||
nullify(ptrFun)
|
||||
nullify(realVar)
|
||||
end function
|
||||
end module
|
||||
|
|
Loading…
Reference in New Issue