Skip to content

-Wreturn-stack-address should handle clang::musttail calls #56676

@efriedma-quic

Description

@efriedma-quic

As noted at #56435 (comment) and #56435 (comment), there's a potential trap with musttail calls: all local variables are freed by the call. So if you pass a pointer to a local variable, and try to use it, it's a use-after-free. We should warn if someone writes something like the following:

int bar(int* x);
int foo(int*) {
    int local = 11;
    [[clang::musttail]] return bar(&local);
}

This is very similar to the existing -Wreturn-stack-address, so it probably makes sense to put it into the existing warning group.

(While we're looking at this, it might also be nice to update the documentation for clang::musttail)

CC @foonathan @haberman

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions