[flang-commits] [flang] 26101e8 - [flang][cuda] Avoid crash by exiting the check if assignment is not usable (#89149)
via flang-commits
flang-commits at lists.llvm.org
Wed Apr 17 15:42:13 PDT 2024
Author: Valentin Clement (バレンタイン クレメン)
Date: 2024-04-17T15:42:09-07:00
New Revision: 26101e8c50e07ea53869b0c7f343d76bfed61b02
URL: https://github.com/llvm/llvm-project/commit/26101e8c50e07ea53869b0c7f343d76bfed61b02
DIFF: https://github.com/llvm/llvm-project/commit/26101e8c50e07ea53869b0c7f343d76bfed61b02.diff
LOG: [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.
Added:
Modified:
flang/lib/Semantics/check-cuda.cpp
flang/test/Semantics/cuf11.cuf
Removed:
################################################################################
diff --git a/flang/lib/Semantics/check-cuda.cpp b/flang/lib/Semantics/check-cuda.cpp
index 2cb15437a235ae..fb1ebadd378586 100644
--- a/flang/lib/Semantics/check-cuda.cpp
+++ b/flang/lib/Semantics/check-cuda.cpp
@@ -488,6 +488,10 @@ void CUDAChecker::Enter(const parser::AssignmentStmt &x) {
}
const evaluate::Assignment *assign{semantics::GetAssignment(x)};
+ if (!assign) {
+ return;
+ }
+
int nbLhs{evaluate::GetNbOfCUDASymbols(assign->lhs)};
int nbRhs{evaluate::GetNbOfCUDASymbols(assign->rhs)};
diff --git a/flang/test/Semantics/cuf11.cuf b/flang/test/Semantics/cuf11.cuf
index b915c7246ed947..de7ff29743242b 100644
--- a/flang/test/Semantics/cuf11.cuf
+++ b/flang/test/Semantics/cuf11.cuf
@@ -22,3 +22,11 @@ subroutine sub1()
ahost = adev + adev
end subroutine
+
+logical function compare_h(a,b)
+!ERROR: Derived type 'h' not found
+ type(h) :: a, b
+!ERROR: 'a' is not an object of derived type; it is implicitly typed
+!ERROR: 'b' is not an object of derived type; it is implicitly typed
+ compare_h = (a%h .eq. b%h)
+end
More information about the flang-commits
mailing list