Skip to content

Different attribute positions for 'noderef' has surprising behaviors #116242

Open
@AaronBallman

Description

@AaronBallman

While working on an unrelated crash, I noticed that the noderef attribute is highly sensitive to syntactic position as a GNU-style attribute, and the behavior seems inconsistent.

// When written before the declaration, it works.
__attribute__((noderef)) int * a;
int w = *a;

// When written in this location on the type, it works.
int __attribute__((noderef)) * b;
int x = *b;

// But when written in this location on the type, it gets loudly ignored.
int * __attribute__((noderef)) c;
int y = *c;

// And when written on the declarator, it gets quietly ignored, but only
// sort of (note the AST dump).
int * d __attribute__((noderef));
int z = *d;

https://godbolt.org/z/hesz5M4K8

I'm mostly surprised by the behavior of c and d. I would expect c to work because the attribute is written on a pointer type and I would sort of expect d to ignore the attribute loudly because it's a type attribute written on a declarator (I could also see "sliding" the attribute to the type because this is a GNU-style spelling).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviorclang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions