Skip to content

Diagnose misuse of the cleanup attribute #79443

@AaronBallman

Description

@AaronBallman

The cleanup attribute is written on a variable declaration, and the address of the declared variable is passed to the specified function in the attribute. This has some subtle issues we should diagnose on. Consider:

__attribute__((cleanup(free))) void *p = malloc(10);

This will pass &p to free, which is going to do the wrong thing. GCC diagnoses this kind of misuse (warning: 'free' called on unallocated object 'p' [-Wfree-nonheap-object]) and it would be good if we did the same: https://godbolt.org/z/nhqh9EazM

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerenhancementImproving things as opposed to bug fixing, e.g. new or missing featurequality-of-implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions