D48773 simplified ASTImporter nicely, but it introduced a new error: Unnamed
structs are not imported correctly, if they appear in a recursive context.
This patch provides a fix for structural equivalency.
Details
Diff Detail
- Repository
- rC Clang
- Build Status
Buildable 20396 Build 20396: arc lint + arc unit
Event Timeline
Hi Gabor,
The change is OK but I have some questions regarding tests.
| unittests/AST/ASTImporterTest.cpp | ||
|---|---|---|
| 2495 | There is already a similar lambda definitions for getRecordDecl() in ObjectsWithUnnamedStructType test. Can we make it a function, like it is done for StructuralEquivalenceContext? | |
| unittests/AST/StructuralEquivalenceTest.cpp | ||
| 582 | Do we really want to test the equivalence of decl to itself, not to its imported version? | |
| lib/AST/ASTStructuralEquivalence.cpp | ||
|---|---|---|
| 913 | The problem was that value of isAnonymousStructOrUnion is not (or not yet) set correctly during the import? But getDeclName is always correct (if it is a false the record is anonymous struct)? | |
| unittests/AST/StructuralEquivalenceTest.cpp | ||
| 486 | RecordDecl * | |
| 579 | Is it possible at all that getRecordDecl returns nullptr? It uses cast (nor cast_or_null and not dyn_cast). | |
| 582 | I think this is correct: R0 should be equivalent with itself but not with R1. | |
| lib/AST/ASTStructuralEquivalence.cpp | ||
|---|---|---|
| 913 | There is a strange thing here: A struct without a name is not necessarily an anonymous struct! /// Whether this is an anonymous struct or union. To be an anonymous
/// struct or union, it must have been declared without a name and
/// there must be no objects of this type declared, e.g.,
/// @code
/// union { int i; float f; };
/// @endcode
/// is an anonymous union but neither of the following are:
/// @code
/// union X { int i; float f; };
/// union { int i; float f; } obj;
/// @endcode
bool isAnonymousStructOrUnion() const { return AnonymousStructOrUnion; }This might seem very perplexed, but this is aligned with the C++17 Standard: 12.3.1 Anonymous unions para 3. A union for which objects, pointers, or references are declared is not an anonymous union. Consequently, we should check whether the Decl has a name, isAnonymousStructOrUnion is misleading here. | |
| unittests/AST/ASTImporterTest.cpp | ||
| 2495 | OK, I added a new function template to handle both cases. | |
| unittests/AST/StructuralEquivalenceTest.cpp | ||
| 579 | Yes, good catch, changed it. | |
| 582 | I think it makes sense, because from the StructuralEquivalence's viewpoint there is no imported version, just two Decls/Types which may or may not have the same ASTContext. | |
| unittests/AST/StructuralEquivalenceTest.cpp | ||
|---|---|---|
| 615 | These asserts can be removed too. | |
The problem was that value of isAnonymousStructOrUnion is not (or not yet) set correctly during the import? But getDeclName is always correct (if it is a false the record is anonymous struct)?