llvm / llvm/llvm-project

[bug] [clang-repl] `IncrementalParser::CleanUpPTU` deletes valid `Decl`s when it is not supposed to

Open
#201,844 0 comments 0 reactions 0 assignees View on GitHub
clang-repl
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Reproducer:
```c++
clang-repl> extern "C" int printf(const char*, ...);
clang-repl> namespace f { void foo() { printf("foo\n"); } }
clang-repl> f::foo();
foo
clang-repl> namespace f { void bar() { printf("bar\n" } }
In file included from <<< inputs >>>:1:
input_line_4:1:43: error: expected ')'
1 | namespace f { void bar() { printf("bar\n" } }
| ^
input_line_4:1:34: note: to match this '('
1 | namespace f { void bar() { printf("bar\n" } }
| ^
error: Parsing failed.
clang-repl> f::foo();
input_line_5:1:1: error: use of undeclared identifier 'f'
1 | f::foo();
| ^
input_line_5:1:1: error: use of undeclared identifier 'f'
error: Parsing failed.
```
The second call to `f::foo` should not fail. It fails because `IncrementalParser::CleanUpPTU` ends up deleting the entire `namespace f`, instead of the most recent redeclaration.

cc: @vgvassilev @SahilPatidar

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.