Skip to content

Commit 764e0cc

Browse files
[flang][OpenMP]Replace assert with if-condition (#139559)
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).
1 parent 75d36dc commit 764e0cc

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

flang/lib/Semantics/check-omp-structure.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3545,8 +3545,7 @@ void OmpStructureChecker::CheckReductionObjects(
35453545
// names into the lists of their members.
35463546
for (const parser::OmpObject &object : objects.v) {
35473547
auto *symbol{GetObjectSymbol(object)};
3548-
assert(symbol && "Expecting a symbol for object");
3549-
if (IsCommonBlock(*symbol)) {
3548+
if (symbol && IsCommonBlock(*symbol)) {
35503549
auto source{GetObjectSource(object)};
35513550
context_.Say(source ? *source : GetContext().clauseSource,
35523551
"Common block names are not allowed in %s clause"_err_en_US,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp
2+
3+
subroutine dont_crash(values)
4+
implicit none
5+
integer, parameter :: n = 100
6+
real :: values(n)
7+
integer :: i
8+
!ERROR: No explicit type declared for 'sum'
9+
sum = 0
10+
!ERROR: No explicit type declared for 'sum'
11+
!$omp parallel do reduction(+:sum)
12+
do i = 1, n
13+
!ERROR: No explicit type declared for 'sum'
14+
!ERROR: No explicit type declared for 'sum'
15+
sum = sum + values(i)
16+
end do
17+
end subroutine dont_crash
18+

0 commit comments

Comments
 (0)