Skip to content

[flang][OpenMP]Replace assert with if-condition #139559

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 1 commit into from
May 13, 2025

Conversation

Leporacanthicus
Copy link
Contributor

If a symbol is not declared, check-omp-structure hits an assert. It should be safe to treat undeclared symbols as "not from a block", as they would have to be declared to be in a block...

Adding simple test to confirm it gives error messages, not crashing.

This should fix issue #131655 (there is already a check for symbol being not null in the code identified in the ticket).

If a symbol is not declared, check-omp-structure hits an assert. It should
be safe to treat undeclared symbols as "not from a block", as they would
have to be declared to be in a block...

Adding simple test to confirm it gives error messages, not crashing.

This should fix issue llvm#131655 (there is already a check for symbol being
not null in the code identified in the ticket).
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:openmp flang:semantics labels May 12, 2025
@Leporacanthicus Leporacanthicus requested review from tblah and kparzysz May 12, 2025 15:24
@llvmbot
Copy link
Member

llvmbot commented May 12, 2025

@llvm/pr-subscribers-flang-semantics

@llvm/pr-subscribers-flang-openmp

Author: Mats Petersson (Leporacanthicus)

Changes

If a symbol is not declared, check-omp-structure hits an assert. It should be safe to treat undeclared symbols as "not from a block", as they would have to be declared to be in a block...

Adding simple test to confirm it gives error messages, not crashing.

This should fix issue #131655 (there is already a check for symbol being not null in the code identified in the ticket).


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

2 Files Affected:

  • (modified) flang/lib/Semantics/check-omp-structure.cpp (+1-2)
  • (added) flang/test/Semantics/OpenMP/reduction-undefined.f90 (+18)
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 8f6a623508aa7..78736ee1929d1 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -3545,8 +3545,7 @@ void OmpStructureChecker::CheckReductionObjects(
   // names into the lists of their members.
   for (const parser::OmpObject &object : objects.v) {
     auto *symbol{GetObjectSymbol(object)};
-    assert(symbol && "Expecting a symbol for object");
-    if (IsCommonBlock(*symbol)) {
+    if (symbol && IsCommonBlock(*symbol)) {
       auto source{GetObjectSource(object)};
       context_.Say(source ? *source : GetContext().clauseSource,
           "Common block names are not allowed in %s clause"_err_en_US,
diff --git a/flang/test/Semantics/OpenMP/reduction-undefined.f90 b/flang/test/Semantics/OpenMP/reduction-undefined.f90
new file mode 100644
index 0000000000000..bf1f03a878630
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/reduction-undefined.f90
@@ -0,0 +1,18 @@
+! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp
+
+subroutine dont_crash(values)
+  implicit none
+  integer, parameter :: n = 100
+  real :: values(n)
+  integer :: i
+  !ERROR: No explicit type declared for 'sum'
+  sum = 0
+  !ERROR: No explicit type declared for 'sum'
+  !$omp parallel do reduction(+:sum)
+  do i = 1, n
+  !ERROR: No explicit type declared for 'sum'
+  !ERROR: No explicit type declared for 'sum'
+     sum = sum + values(i)
+  end do
+end subroutine dont_crash
+

Copy link
Contributor

@tblah tblah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@Leporacanthicus Leporacanthicus merged commit 764e0cc into llvm:main May 13, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:openmp 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