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

via flang-commits flang-commits at lists.llvm.org
Wed Apr 17 15:04:19 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: Valentin Clement (バレンタイン クレメン) (clementval)

<details>
<summary>Changes</summary>

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. 

---
Full diff: https://github.com/llvm/llvm-project/pull/89149.diff


2 Files Affected:

- (modified) flang/lib/Semantics/check-cuda.cpp (+3) 
- (modified) flang/test/Semantics/cuf11.cuf (+8) 


``````````diff
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

``````````

</details>


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


More information about the flang-commits mailing list