Skip to content

core.StackAddressEscape checker produce invalid detection #165762

@earnol

Description

@earnol

The core.StackAddressEscape produce invalid disgnostics (false positive) in the following case:

#include <stdint.h>

class LocalClass;
class VEI {
public:
  VEI():pLocal(nullptr) {}  
  LocalClass *pLocal;
};

class LocalClass {
public:
    LocalClass(VEI *v):p(v) {}
    VEI *p;
    ~LocalClass() { p->pLocal = nullptr; }
    void updateVei() {
        if(p->pLocal != this) {
          p->pLocal = this;
        }
    }
};

intptr_t funct(VEI *vei) {
  LocalClass ohRly(vei);
  ohRly.updateVei();
  return (intptr_t)vei;
}

int main(void) {
    VEI vei;
    intptr_t res = funct(&vei);
    return res > 0x7FFF;
}

The problem is the program context is analyzed at the time of return (line 32) but actual removal of local variable reference happens in the destructor and then context is actually destroyed.
The godbolt reference demonstrating the same is available though this link.

Observed behavior:
The error 32:3: warning: Address of stack memory associated with local variable 'ohRly' returned to caller [core.StackAddressEscape] is reported.

Expected behavior:
No diagnostics reported as no actual stack escape happens here as vei.pLocal is actually equals to nullptr in line 38 if the provided example.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions