llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.96k stars 11.94k forks source link

extend `-Wnonnull` diagnostics for `returns_nonnull` function attribute #108174

Open firewave opened 1 month ago

firewave commented 1 month ago
static char* cb()
{
    return nullptr;
}

[[gnu::returns_nonnull]] static char* f()
{
    return cb();
}

int main()
{
    f();
}

https://godbolt.org/z/d9dz8dxE9

firewave commented 1 month ago

Not sure if this would still be in the scope of the diagnostics:

char* cb();

[[gnu::returns_nonnull]] static char* f()
{
    return cb();
}

int main()
{
    f();
}

I think it should at least try to leverage the lack of function attributes.