diff --git a/lib/AST/ASTImporter.cpp b/lib/AST/ASTImporter.cpp index 74449a965f900e4be99888e4ec5e4fbcae90f4ff..95492825eb9d7b5f726d2d71710db0c33ee8a332 100644 --- a/lib/AST/ASTImporter.cpp +++ b/lib/AST/ASTImporter.cpp @@ -1221,10 +1221,6 @@ static Optional<unsigned> findUntaggedStructOrUnionIndex(RecordDecl *Anon) { // If the field looks like this: // struct { ... } A; QualType FieldType = F->getType(); - // In case of nested structs. - while (const auto *ElabType = dyn_cast<ElaboratedType>(FieldType)) { - FieldType = ElabType->getNamedType(); - } if (const auto *RecType = dyn_cast<RecordType>(FieldType)) { const RecordDecl *RecDecl = RecType->getDecl(); if (RecDecl->getDeclContext() == Owner && @@ -3024,8 +3020,9 @@ Decl *ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { } if (RecordDecl *FoundRecord = dyn_cast<RecordDecl>(Found)) { - if (!SearchName) { - // If both unnamed structs/unions are in a record context, make sure + if (D->isAnonymousStructOrUnion() && + FoundRecord->isAnonymousStructOrUnion()) { + // If both anonymous structs/unions are in a record context, make sure // they occur in the same location in the context records. if (Optional<unsigned> Index1 = findUntaggedStructOrUnionIndex(D)) { diff --git a/test/ASTMerge/struct/Inputs/struct1.c b/test/ASTMerge/struct/Inputs/struct1.c index a85aec70a84ce718e487424cc0b4156266c34565..0f3e8b9bc3ebfd3252143a09c8474ed569dcf2a2 100644 --- a/test/ASTMerge/struct/Inputs/struct1.c +++ b/test/ASTMerge/struct/Inputs/struct1.c @@ -77,65 +77,3 @@ typedef struct { } S13; S13 x13; - -// Matches -struct Unnamed { - union { - struct { - int i; - } S; - struct { - float i; - } R; - } U; -} x14; - -// Matches -struct DeepUnnamed { - union { - union { - struct { - long i; - } S; - struct { - int i; - } R; - } U1; - union { - struct { - long i; - } S; - struct { - float i; - } T; - } U2; - } U; - struct { - long i; - } V; -} x15; - -// Mismatch due to unnamed struct used internally -struct DeepUnnamedError { - union { - union { - struct { - long i; - } S; - struct { - int i; - } R; - } U1; - union { - struct { - long i; // Mismatch here. - } S; - struct { - float i; - } T; - } U2; - } U; - struct { - long i; - } V; -} x16; diff --git a/test/ASTMerge/struct/Inputs/struct2.c b/test/ASTMerge/struct/Inputs/struct2.c index 49fe36d823d0c332401d9d106eef135d668a4cff..7fe17a576b23ac9b55c3b10d1660400e91e01ba3 100644 --- a/test/ASTMerge/struct/Inputs/struct2.c +++ b/test/ASTMerge/struct/Inputs/struct2.c @@ -74,65 +74,3 @@ typedef struct { } S13; S13 x13; - -// Matches -struct Unnamed { - union { - struct { - int i; - } S; - struct { - float i; - } R; - } U; -} x14; - -// Matches -struct DeepUnnamed { - union { - union { - struct { - long i; - } S; - struct { - int i; - } R; - } U1; - union { - struct { - long i; - } S; - struct { - float i; - } T; - } U2; - } U; - struct { - long i; - } V; -} x15; - -// Mismatch due to unnamed struct used internally -struct DeepUnnamedError { - union { - union { - struct { - long i; - } S; - struct { - int i; - } R; - } U1; - union { - struct { - float i; // Mismatch here. - } S; - struct { - float i; - } T; - } U2; - } U; - struct { - long i; - } V; -} x16; diff --git a/test/ASTMerge/struct/test.c b/test/ASTMerge/struct/test.c index b7e24416d2509d4f289bca739547bbd03325df9c..ed7750f6beccadc70a47376106cc3840cc823a39 100644 --- a/test/ASTMerge/struct/test.c +++ b/test/ASTMerge/struct/test.c @@ -44,12 +44,4 @@ // CHECK: struct2.c:72:7: note: field 'i' has type 'int' here // CHECK: struct2.c:76:5: error: external variable 'x13' declared with incompatible types in different translation units ('S13' vs. 'S13') // CHECK: struct1.c:79:5: note: declared here with type 'S13' -// CHECK: struct1.c:130:7: warning: type 'struct DeepUnnamedError::(anonymous at [[PATH_TO_INPUTS:.+]]/struct1.c:130:7)' has incompatible definitions in different translation units -// CHECK: struct1.c:131:14: note: field 'i' has type 'long' here -// CHECK: struct2.c:128:15: note: field 'i' has type 'float' here -// CHECK: struct1.c:129:5: warning: type 'union DeepUnnamedError::(anonymous at [[PATH_TO_INPUTS]]/struct1.c:129:5)' has incompatible definitions in different translation units -// CHECK: struct1.c:132:9: note: field 'S' has type 'struct (anonymous struct at [[PATH_TO_INPUTS]]/struct1.c:130:7)' here -// CHECK: struct2.c:129:9: note: field 'S' has type 'struct (anonymous struct at [[PATH_TO_INPUTS]]/struct2.c:127:7)' here -// CHECK: struct2.c:138:3: error: external variable 'x16' declared with incompatible types in different translation units ('struct DeepUnnamedError' vs. 'struct DeepUnnamedError') -// CHECK: struct1.c:141:3: note: declared here with type 'struct DeepUnnamedError' -// CHECK: 11 warnings and 9 errors generated +// CHECK: 9 warnings and 8 errors generated