Skip to content

Commit 26101e8

Browse files
authored
[flang][cuda] Avoid crash by exiting the check if assignment is not usable (#89149)
In the presence of other semantic error, `GetAssignment` would return a nullptr and therefore would make the rest of the check crash when trying to collect symbols. Exiting early when we have a nullptr so the compiler doesn't crash and user can get the meaningful semantic error.
1 parent 678f19f commit 26101e8

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

flang/lib/Semantics/check-cuda.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,10 @@ void CUDAChecker::Enter(const parser::AssignmentStmt &x) {
488488
}
489489

490490
const evaluate::Assignment *assign{semantics::GetAssignment(x)};
491+
if (!assign) {
492+
return;
493+
}
494+
491495
int nbLhs{evaluate::GetNbOfCUDASymbols(assign->lhs)};
492496
int nbRhs{evaluate::GetNbOfCUDASymbols(assign->rhs)};
493497

flang/test/Semantics/cuf11.cuf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,11 @@ subroutine sub1()
2222
ahost = adev + adev
2323

2424
end subroutine
25+
26+
logical function compare_h(a,b)
27+
!ERROR: Derived type 'h' not found
28+
type(h) :: a, b
29+
!ERROR: 'a' is not an object of derived type; it is implicitly typed
30+
!ERROR: 'b' is not an object of derived type; it is implicitly typed
31+
compare_h = (a%h .eq. b%h)
32+
end

0 commit comments

Comments
 (0)