Currently, anonymous types are merged into the same redecl chain even if they
are structurally inequivalent. This results that global objects are not
imported, if there are at least two global objects with different anonymous
types. This patch provides a fix.
Details
Diff Detail
- Repository
- rC Clang
Event Timeline
Hello Gabor,
The change looks reasonable to me. But could you please check if we can have some code unification with structural matching?
lib/AST/ASTImporter.cpp | ||
---|---|---|
2075 | Is it possible to use the added code for the entire condition if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)), replacing its body? Our structural matching already knows how to handle unnamed structures, and the upper code partially duplicates IsStructurallyEquivalent(StructuralEquivalenceContext &Context,RecordDecl *D1, RecordDecl *D2). Can we change structural matching to handle this stuff instead of doing it in ASTNodeImporter? |
lib/AST/ASTImporter.cpp | ||
---|---|---|
2075 | Yes, this is a good point, updated the patch accordingly. |
lib/AST/ASTImporter.cpp | ||
---|---|---|
2075 | My idea was to remove this whole if (!SearchName) branch, but some restructuring of the next conditions may be needed. Setting of PrevDecl in the if branch does not look correct (if !SearchName is false it is never set, unlike in the old code). |
lib/AST/ASTImporter.cpp | ||
---|---|---|
2075 | I tried what you mentioned Balazs. // Matches struct Unnamed { union { struct { int i; } S; struct { float i; } R; } U; } x14; The failing lit test and it's output: /home/egbomrt/WORK/llvm3/git/llvm/tools/clang/test/ASTMerge/struct/Inputs/struct1.c:84:5: warning: type 'struct Unnamed::(anonymous at /home/egbomrt/WORK/llvm3/git/llvm/tools/clang/test/ASTMerge/struct/Inputs/struct1.c:84:5)' has incompatible definitions in different translation units struct { ^ /home/egbomrt/WORK/llvm3/git/llvm/tools/clang/test/ASTMerge/struct/Inputs/struct1.c:85:11: note: field 'i' has type 'int' here int i; ^ /home/egbomrt/WORK/llvm3/git/llvm/tools/clang/test/ASTMerge/struct/Inputs/struct1.c:88:13: note: field 'i' has type 'float' here float i; ^ |
PrevDecl is set after the !SearchName branch, as it had been done before.
This way original behaviour is kept as much as possible.
Is it possible to use the added code for the entire condition if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)), replacing its body? Our structural matching already knows how to handle unnamed structures, and the upper code partially duplicates IsStructurallyEquivalent(StructuralEquivalenceContext &Context,RecordDecl *D1, RecordDecl *D2). Can we change structural matching to handle this stuff instead of doing it in ASTNodeImporter?