Skip to content

[LifetimeSafety] False positive for pointers declared in a loop #169548

@usx95

Description

@usx95
bool cond();

void foo() {
    for (; cond();) {
        int obj;
        int* view;
        if (cond()) {
            view = &obj;
        }
        (void)*view; // error: use-after-scope.
    }
}

https://godbolt.org/z/MvrdMaKK4

My idea to fix this is to issue a Kill/Reset when process the DeclStmt. The problem currently is that decl int* view; does not kill the original value from the last iteration.

We can choose to have this warning as this is otherwise a use-of-uninitialised value

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:temporal-safetyIssue/FR relating to the lifetime analysis in Clang (-Wdangling, -Wreturn-local-addr)

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions