llvm / llvm-project

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

[clang] `generateUSRForDecl` does not work for anonymous structs #94433

Open jirislaby opened 1 month ago

jirislaby commented 1 month ago

For simple structures like this:

struct A {
        struct {
                int a;
        };
        struct {
                int b;
        };
};

generateUSRForDecl at: https://github.com/llvm/llvm-project/blob/6009708b4367171ccdbf4b5905cb6a803753fe18/clang/lib/Index/USRGeneration.cpp#L1141 returns false for the two struct A's fields, i.e. the anonymous structures. And their USR is indeed duplicate c:@S@A@FI@.

BTW USR of those ints a and b is indeed valid and correct. c:@S@A@Sa@FI@a and c:@S@A@Sa@FI@b , respectively.

Why not simply add a field index after their @FI@?

jirislaby commented 1 month ago

6f536f2 seems to work, but I am not sure it's optimal.