Skip to content

[flang][openmp]Incorrect order in openmp line causes assert #131659

Closed
@Leporacanthicus

Description

@Leporacanthicus

The following code is "wrong", but I happened to be confused and surely it should lead to an error or correct code, not an assert in the middle of lowering... Gfortran gives an error message when compiling the same code.

program omp_examples
  implicit none
  integer, parameter :: n = 100
  real :: values(n)
  integer :: i
  real :: sum
  
  call random_number(values)

  sum = 0
  !$omp do parallel reduction(+:sum)
  do i = 1, n
     sum = sum + values(i)
  end do

  
  print *, values
  print *, "sum=", sum
end program omp_examples

To reproduce: flang -fc1 -femit-obj -fopenmp sample.f90

(Change the !$omp do parallel into !$omp parallel do to be correct).

The assert that fails is the !decompose.output.empty() in this section of flang/lib/Lower/OpenMP/Decomposer.cpp:

ConstructQueue buildConstructQueue(
    mlir::ModuleOp modOp, Fortran::semantics::SemanticsContext &semaCtx,
    Fortran::lower::pft::Evaluation &eval, const parser::CharBlock &source,
    llvm::omp::Directive compound, const List<Clause> &clauses) {

  ConstructDecomposition decompose(modOp, semaCtx, eval, compound, clauses);
  assert(!decompose.output.empty() && "Construct decomposition failed");

  for (UnitConstruct &uc : decompose.output) {
    assert(getLeafConstructs(uc.id).empty() && "unexpected compound directive");
    //  If some clauses are left without source information, use the directive's
    //  source.
    for (auto &clause : uc.clauses)
      if (clause.source.empty())
        clause.source = source;
  }

  return decompose.output;
}

Again, raising bug just in case I get sidetracked and don't fix this in the next couple of days... The fix is probably not really in this section, and may be a bit more complicated to fix.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions