llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Soham Karandikar (skadewdl3) <details> <summary>Changes</summary> Fixes #<!-- -->230923. Taking a look at the segfault in a debugger and playing around with the reproducer, the error happened only when: - There's a non-empty statement before the nested for-loop - There's an interchange directive present The segfault was happening in `JumpScopeChecker::BuildScopeInformation` when processing the statement as an `OMPExecutableDirective`. In case of an interchange directive being present, `getStructuredBlock` returned `nullptr` causing `getBeginLoc` to segfault. This PR adds a fallback so if the transformed statement returned by `getStructuredBlock()` isn't available, the raw AST statement is used instead. Assisted-by: GPT Sol 6.1 I used Sol to decide upon where the fix should be placed. --- Full diff: https://github.com/llvm/llvm-project/pull/234881.diff 2 Files Affected: - (modified) clang/lib/Sema/JumpDiagnostics.cpp (+11-5) - (modified) clang/test/OpenMP/interchange_messages.cpp (+13) ``````````diff diff --git a/clang/lib/Sema/JumpDiagnostics.cpp b/clang/lib/Sema/JumpDiagnostics.cpp index bbe6f644609bf..96e65b4ca766c 100644 --- a/clang/lib/Sema/JumpDiagnostics.cpp +++ b/clang/lib/Sema/JumpDiagnostics.cpp @@ -655,12 +655,18 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S, default: if (auto *ED = dyn_cast<OMPExecutableDirective>(S)) { if (!ED->isStandaloneDirective()) { + // Sometimes, the transformed structured block may not be available + // when transformation is deferred (e.g., when using `omp interchange`). + // In such cases, use the existing source statement + Stmt *Block = ED->getStructuredBlock(); + if (!Block) + Block = ED->getRawStmt(); + unsigned NewParentScope = Scopes.size(); - Scopes.emplace_back(ParentScope, - diag::note_omp_protected_structured_block, - diag::note_omp_exits_structured_block, - ED->getStructuredBlock()->getBeginLoc()); - BuildScopeInformation(ED->getStructuredBlock(), NewParentScope); + Scopes.emplace_back( + ParentScope, diag::note_omp_protected_structured_block, + diag::note_omp_exits_structured_block, Block->getBeginLoc()); + BuildScopeInformation(Block, NewParentScope); return; } } diff --git a/clang/test/OpenMP/interchange_messages.cpp b/clang/test/OpenMP/interchange_messages.cpp index 7b9a4963445e4..d714267722a9b 100644 --- a/clang/test/OpenMP/interchange_messages.cpp +++ b/clang/test/OpenMP/interchange_messages.cpp @@ -220,6 +220,19 @@ static void templated_func_type_dependent() { } +// Deferred interchange must not crash jump-scope checking +template <typename T> +static void interchange_in_switch() { + switch (T(0)) { + int a = 10; +#pragma omp for collapse(2) +#pragma omp interchange + for (int j = 0; j < 2; j++) + for (int k = 0; k < 2; k++) + ; + } +} + void template_inst() { // expected-note@+1 {{in instantiation of function template specialization 'templated_func<int>' requested here}} templated_func<int>(); `````````` </details> https://github.com/llvm/llvm-project/pull/234881 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
