[clang] [llvm] [mlir] [openmp] [Clang][OpenMP] Canonicalize Intra-tiles in Loop Tiling (PR #191114)
Michael Kruse via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 6 06:45:45 PDT 2026
https://github.com/Meinersbur commented:
I get a crash with this code:
```
$ cat tile2d.c
void f(int n) {
#pragma omp tile sizes(3,5)
#pragma omp tile sizes(2)
for (int i = 0; i < n; ++i)
body(i);
}
$ bin/clang -fopenmp tile2d.c
clang-24: /home/meinersbur/src/llvm/work/_src/clang/lib/Sema/SemaOpenMP.cpp:14766: clang::SemaOpenMP::checkTransformableLoopNest(clang::OpenMPDirectiveKind, clang::Stmt*, int, llvm::SmallVectorImpl<clang::OMPLoopBasedDirective::HelperExprs>&, clang::Stmt*&, llvm::SmallVectorImpl<llvm::SmallVector<clang::Stmt*> >&)::<lambda(unsigned int, clang::Stmt*)>: Assertion `isa<CXXForRangeStmt>(CurStmt) && "Expected canonical for or range-based for loops."' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files.
Stack dump:
0. Program arguments: /home/meinersbur/src/llvm/work/release/bin/clang-24 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name tile2d.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/home/meinersbur/src/llvm/work/release -fcoverage-compilation-dir=/home/meinersbur/src/llvm/work/release -resource-dir /home/meinersbur/src/llvm/work/release/lib/clang/24 -internal-isystem /home/meinersbur/src/llvm/work/release/lib/clang/24/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -ferror-limit 19 -fmessage-length=250 -fopenmp -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -faddrsig -fdwarf2-cfi-asm -o /tmp/meinersbur/tile2d-f57fad.o -x c tile2d.c
1. tile2d.c:8:1: current parser token '}'
2. tile2d.c:3:15: parsing function body 'f'
3. tile2d.c:3:15: in compound statement ('{}')
#0 0x00007f01c7fa9051 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/meinersbur/src/llvm/work/release/bin/../lib/libLLVMSupport.so.24.0git+0x2ec051)
#1 0x00007f01c7fa595c llvm::sys::RunSignalHandlers() (/home/meinersbur/src/llvm/work/release/bin/../lib/libLLVMSupport.so.24.0git+0x2e895c)
#2 0x00007f01c7fa5abe SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x00007f01c7fa5b7c SignalHandlerTerminate(int, siginfo_t*, void*) Signals.cpp:0:0
#4 0x00007f01c7855330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x00007f01c78aec0c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#6 0x00007f01c78aec0c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#7 0x00007f01c78aec0c pthread_kill ./nptl/pthread_kill.c:89:10
#8 0x00007f01c785527e raise ./signal/../sysdeps/posix/raise.c:27:6
#9 0x00007f01c78388ff abort ./stdlib/abort.c:81:7
#10 0x00007f01c783881b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#11 0x00007f01c784b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#12 0x00007f01c41af307 bool llvm::function_ref<bool (unsigned int, clang::Stmt*)>::callback_fn<clang::SemaOpenMP::checkTransformableLoopNest(llvm::omp::Directive, clang::Stmt*, int, llvm::SmallVectorImpl<clang::OMPLoopBasedDirective::HelperExprs>&, clang::Stmt*&, llvm::SmallVectorImpl<llvm::SmallVector<clang::Stmt*, 6u>>&)::'lambda'(unsigned int, clang::Stmt*)>(long, unsigned int, clang::Stmt*) SemaOpenMP.cpp:0:0
#13 0x00007f01c67490f1 clang::OMPLoopBasedDirective::doForAllLoops(clang::Stmt*, bool, unsigned int, llvm::function_ref<bool (unsigned int, clang::Stmt*)>, llvm::function_ref<void (clang::OMPLoopTransformationDirective*)>) (/home/meinersbur/src/llvm/work/release/bin/../lib/../lib/libclangAST.so.24.0git+0xfe50f1)
#14 0x00007f01c4138499 clang::SemaOpenMP::checkTransformableLoopNest(llvm::omp::Directive, clang::Stmt*, int, llvm::SmallVectorImpl<clang::OMPLoopBasedDirective::HelperExprs>&, clang::Stmt*&, llvm::SmallVectorImpl<llvm::SmallVector<clang::Stmt*, 6u>>&) (/home/meinersbur/src/llvm/work/release/bin/../lib/../lib/libclangSema.so.24.0git+0xc6e499)
#15 0x00007f01c421f5ef clang::SemaOpenMP::ActOnOpenMPTileDirective(llvm::ArrayRef<clang::OMPClause*>, clang::Stmt*, clang::SourceLocation, clang::SourceLocation) (/home/meinersbur/src/llvm/work/release/bin/../lib/../lib/libclangSema.so.24.0git+0xd555ef)
....
```
> One case remains unsupported: collapsing through stacked #pragma omp tile directives, where the inner tile's floor is body-derived from the outer reinterpreted tile. Since the fix for this may span in the shared collapse working, I've kept it out of this PR and marked it XFAIL ([openmp/runtime/test/transform/tile/parallel-wsloop-collapse-stacked-tile-deep.cpp](https://github.com/llvm/llvm-project/pull/url)) with a note in the central comments. Happy to follow up in a separate changeālmk if you prefer it here.
I'd implement this by sinking the Predicate of OMPInvariantPredicateBoundAttr further: If checkOpenMPIterationSpace encounters an OMPInvariantPredicateBoundAttr. then remember the body it to emit into its own OMPInvariantPredicateBoundAttr.
https://github.com/llvm/llvm-project/pull/191114
More information about the cfe-commits
mailing list