Skip to content

Commit 7f21a96

Browse files
committed
Add test coverage
1 parent 0817b92 commit 7f21a96

File tree

4 files changed

+55
-8
lines changed

4 files changed

+55
-8
lines changed

clang/lib/AST/ASTStructuralEquivalence.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,13 +2103,16 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
21032103
diag::err_odr_tag_type_inconsistent))
21042104
<< Context.ToCtx.getTypeDeclType(D2)
21052105
<< (&Context.FromCtx != &Context.ToCtx);
2106-
EnumDecl *Has = D1->isFixed() ? D1 : D2;
2107-
EnumDecl *Missing = D1->isFixed() ? D1 : D2;
2108-
Context.Diag1(Has->getLocation(), diag::note_odr_fixed_underlying_type)
2109-
<< Has;
2110-
Context.Diag2(Missing->getLocation(),
2111-
diag::note_odr_missing_fixed_underlying_type)
2112-
<< Missing;
2106+
Context.Diag1(D1->getLocation(),
2107+
D1->isFixed()
2108+
? diag::note_odr_fixed_underlying_type
2109+
: diag::note_odr_missing_fixed_underlying_type)
2110+
<< D1;
2111+
Context.Diag2(D2->getLocation(),
2112+
D2->isFixed()
2113+
? diag::note_odr_fixed_underlying_type
2114+
: diag::note_odr_missing_fixed_underlying_type)
2115+
<< D2;
21132116
}
21142117
return false;
21152118
}
@@ -2123,7 +2126,7 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
21232126
diag::err_odr_tag_type_inconsistent))
21242127
<< Context.ToCtx.getTypeDeclType(D2)
21252128
<< (&Context.FromCtx != &Context.ToCtx);
2126-
Context.Diag1(D2->getLocation(), diag::note_odr_enumerator)
2129+
Context.Diag2(D2->getLocation(), diag::note_odr_enumerator)
21272130
<< D2 << D2->getIntegerType() << D1->getIntegerType();
21282131
}
21292132
return false;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// [C23] missing underlying types
2+
enum E1 : int {
3+
E1Enumerator1
4+
};
5+
6+
enum E2 {
7+
E2Enumerator1
8+
};
9+
10+
// [C23] Incompatible underlying types
11+
enum E3 : long {
12+
E3Enumerator1
13+
};
14+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// [C23] missing underlying types
2+
enum E1 {
3+
E1Enumerator1
4+
};
5+
6+
enum E2 : int {
7+
E2Enumerator1
8+
};
9+
10+
// [C23] Incompatible underlying types
11+
enum E3 : short {
12+
E3Enumerator1
13+
};
14+

clang/test/ASTMerge/enum/test2.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -std=c23 -emit-pch -o %t.1.ast %S/Inputs/enum3.c
2+
// RUN: %clang_cc1 -std=c23 -emit-pch -o %t.2.ast %S/Inputs/enum4.c
3+
// RUN: not %clang_cc1 -std=c23 -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 | FileCheck %s
4+
5+
// FIXME: this error should not happen!
6+
// CHECK: error: type 'struct __NSConstantString_tag' has an attribute which currently causes the types to be treated as though they are incompatible
7+
// CHECK: enum3.c:2:6: warning: type 'enum E1' has incompatible definitions in different translation units
8+
// CHECK: enum4.c:2:6: note: enumeration 'E1' missing fixed underlying type here
9+
// CHECK: enum3.c:2:6: note: enumeration 'E1' has fixed underlying type here
10+
// CHECK: enum3.c:6:6: warning: type 'enum E2' has incompatible definitions in different translation units
11+
// CHECK: enum4.c:6:6: note: enumeration 'E2' has fixed underlying type here
12+
// CHECK: enum3.c:6:6: note: enumeration 'E2' missing fixed underlying type here
13+
// CHECK: enum3.c:11:6: warning: type 'enum E3' has incompatible definitions in different translation units
14+
// CHECK: enum3.c:11:6: note: enumerator 'E3' with value 'long' here
15+
// CHECK: 3 warnings and 1 error generated
16+

0 commit comments

Comments
 (0)