Issue 233392
Summary [clang][OpenMP] Code completion inside an OpenMP var-list clause never terminates (spins in Parser::ParseOpenMPVarList)
Labels clang
Assignees
Reporter BayKeremm
    ### Summary

With `-fopenmp`, requesting code completion anywhere inside the variable list of an OpenMP clause such as `reduction(...)`, `private(...)` or `shared(...)` makes the parser loop forever. It uses 100% of one core, memory stays flat, and it produces no output. In clangd, this means every completion or signature-help request typed inside such a clause leaves a worker thread spinning permanently. Cancelling the request doesn't stop it, and clangd ignores SIGTERM while the thread runs, so it has to be SIGKILLed.

### Reproducer

`repro.cpp`:

```cpp
void f() {
  int s = 0;
#pragma omp parallel for reduction(+ : s)
  for (int i = 0; i < 10; ++i) s += i;
}
```

```sh
clang++ -fsyntax-only -fopenmp -Xclang -code-completion-at=repro.cpp:3:40 repro.cpp
```

Line 3, column 40 is the `s` inside `reduction(+ : s)`.

**Expected:** completion results are printed and clang exits.
**Actual:** clang never exits. Nothing is printed to stdout or stderr, CPU usage is 100% and RSS is constant (about 69 MB).

The same hang happens through clangd:

```sh
echo -fopenmp > compile_flags.txt
clangd --check=repro.cpp --check-completion --check-lines=3-3
```

### What triggers it

Each case below is a code-completion request with a 5-second timeout:

| Case | Result |
|---|---|
| `reduction(+ : s)`, cursor before or after `s` | hangs |
| `reduction(&& : x)`, `reduction(&& : )` (empty list) | hangs |
| `private()`, `shared(x)` | hangs |
| same file as C (`clang -x c`) | hangs |
| `-fopenmp-simd` instead of `-fopenmp` | hangs |
| `if()`, `num_threads()`, `schedule()` | completes |
| cursor in the loop body instead of the clause | completes |
| no `-fopenmp` | completes |

So it looks specific to clauses parsed through `ParseOpenMPVarList`; _expression_ clauses are fine.

### Backtrace

I sampled it twice, at 3 s and at 7 s. Both samples show the same frames with a stable depth, so it's a loop rather than recursion:

```
#1 clang::DiagnosticIDs::shouldSuppressAsSystemWarning(...)
#2 clang::DiagnosticIDs::getDiagnosticSeverity(...)
#3 clang::DiagnosticIDs::getDiagnosticLevel(...)
#4 clang::DiagnosticsEngine::ProcessDiag(...)
#5  ??
#6 clang::Parser::ParseAssignmentExpression(clang::TypoCorrectionTypeBehavior)
#7 clang::Parser::ParseOpenMPVarList(llvm::omp::Directive, llvm::omp::Clause, ...)
#8  clang::Parser::ParseOpenMPVarListClause(llvm::omp::Directive, llvm::omp::Clause, bool)
#9 clang::Parser::ParseOpenMPClause(llvm::omp::Directive, llvm::omp::Clause, bool)
#10 clang::Parser::ParseOpenMPExecutableDirective(...)
#11 clang::Parser::ParseOpenMPDeclarativeOrExecutableDirective(...)
...
#23 clang::ParseAST(...)
```

This build has no debug info. The pattern suggests that `ParseOpenMPVarList` keeps calling `ParseAssignmentExpression` without consuming the code-completion token, so its loop condition (not at `)` or end of pragma) never becomes false.

### Environment

- clang/clangd 23.1.3 (Arch Linux package `clang 23.1.3-3`), x86_64-pc-linux-gnu
- Linux 7.2.8
- I haven't tested other versions.

### Workaround

Hide `-fopenmp` from clangd in `~/.config/clangd/config.yaml`:

```yaml
CompileFlags:
  Remove: [-fopenmp*]
  Add: [-D_OPENMP=202111]
```

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to