llvm-project
2bf008c3 - [clang][OpenMP] Fix crashes on target regions inside namespace-scope lambdas and blocks (#226691)

Commit
21 days ago
[clang][OpenMP] Fix crashes on target regions inside namespace-scope lambdas and blocks (#226691) Fixes #223397 A `target` region inside a lambda or block at namespace scope crashed clang in two places. In Sema, `isOpenMPCapturedDecl` decides whether a global must be captured by walking the function scope stack down to the innermost OpenMP captured region, stopping at an ordinary function scope. The capture initializers of a directive's outermost region are built after all of its regions have been popped. Inside a function that walk ends at the function's scope, but a namespace-scope lambda or block has nothing underneath it, so the walk ran off the stack and asserted. This happens for any global reference, such as `int &r = x; auto l = [] { #pragma omp target r = 1; };`. The self-referential declaration in the report is incidental. Once past Sema, CodeGen asserted too: it names the outlined kernel after the region's parent function, and such a region has none, even without a reference. In Sema, running out of scopes now means the same as reaching a function scope, so the variable is not captured from the current scope. That is what the same lambda already gets inside a function. In CodeGen, a region with no parent function is named after the function being emitted.
Parents
Loading