Skip to content

[flang][cuda] Avoid crash by exiting the check if assignment is not usable #89149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 17, 2024

Conversation

clementval
Copy link
Contributor

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.

@clementval clementval requested a review from klausler April 17, 2024 22:03
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Apr 17, 2024
@llvmbot
Copy link
Member

llvmbot commented Apr 17, 2024

@llvm/pr-subscribers-flang-semantics

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

Changes

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

@clementval clementval merged commit 26101e8 into llvm:main Apr 17, 2024
@clementval clementval deleted the cuda_avoid_segfault branch April 17, 2024 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants