llvm / llvm/llvm-project

in `clang-analyzer`, `StackAddressEscape` has problems with user-declared destructors

Open
#165,900 3 comments 0 reactions 0 assignees View on GitHub
clang:static analyzer
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

The following code:

```c++
struct A {
int& x;
};

struct B {
A a;
~B() {}
B(A a) : a{a} {}
};

static B getA() {
int x;
return B{A{.x = x}};
}
```

incorrectly passes clang tidy with `--checks=clang-analyzer-core.StackAddressEscape`.

However, this very similar code correctly triggers the warning.

```c++
struct A {
int& x;
};

struct B {
A a;
B(A a) : a{a} {}
};

static B getA() {
int x;
return B{A{.x = x}};
}
```

Contributor guide

Open the contributing guide

Research direction

Start by running the two C++ reproductions with clang-tidy using clang-analyzer-core.StackAddressEscape, then compare the warning paths for the versions with and without the user-declared destructor. Trace the StackAddressEscape checker entry point and its existing tests; done means the destructor case reports the escaping stack address without regressing the existing case.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.