[flang-commits] [flang] [flang][cuda] Avoid crash by exiting the check if assignment is not usable (PR #89149)

Valentin Clement バレンタイン クレメン via flang-commits flang-commits at lists.llvm.org
Wed Apr 17 15:03:44 PDT 2024


https://github.com/clementval created https://github.com/llvm/llvm-project/pull/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. 

>From b8452560e49feea1850a728529d97f09e6a1d61e Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Wed, 17 Apr 2024 15:00:31 -0700
Subject: [PATCH] [flang][cuda] Avoid crash by bailing out of check if
 assignment is not usable

---
 flang/lib/Semantics/check-cuda.cpp | 3 +++
 flang/test/Semantics/cuf11.cuf     | 8 ++++++++
 2 files changed, 11 insertions(+)

diff --git a/flang/lib/Semantics/check-cuda.cpp b/flang/lib/Semantics/check-cuda.cpp
index 2cb15437a235ae..45bf0699cbf6ad 100644
--- a/flang/lib/Semantics/check-cuda.cpp
+++ b/flang/lib/Semantics/check-cuda.cpp
@@ -488,6 +488,9 @@ 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