[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:10:59 PDT 2024


https://github.com/clementval updated https://github.com/llvm/llvm-project/pull/89149

>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 1/2] [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

>From 37b9a39070f0509ad1270a11377613203eadf9c1 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Wed, 17 Apr 2024 15:10:48 -0700
Subject: [PATCH 2/2] Add brace around if body

---
 flang/lib/Semantics/check-cuda.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/flang/lib/Semantics/check-cuda.cpp b/flang/lib/Semantics/check-cuda.cpp
index 45bf0699cbf6ad..fb1ebadd378586 100644
--- a/flang/lib/Semantics/check-cuda.cpp
+++ b/flang/lib/Semantics/check-cuda.cpp
@@ -488,8 +488,9 @@ void CUDAChecker::Enter(const parser::AssignmentStmt &x) {
   }
 
   const evaluate::Assignment *assign{semantics::GetAssignment(x)};
-  if (!assign)
+  if (!assign) {
     return;
+  }
 
   int nbLhs{evaluate::GetNbOfCUDASymbols(assign->lhs)};
   int nbRhs{evaluate::GetNbOfCUDASymbols(assign->rhs)};



More information about the flang-commits mailing list