[flang-commits] [flang] [flang][OpenMP]Replace assert with if-condition (PR #139559)
via flang-commits
flang-commits at lists.llvm.org
Mon May 12 08:24:32 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
@llvm/pr-subscribers-flang-openmp
Author: Mats Petersson (Leporacanthicus)
<details>
<summary>Changes</summary>
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
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
+
``````````
</details>
https://github.com/llvm/llvm-project/pull/139559
More information about the flang-commits
mailing list