Skip to content

Commit 3e42e60

Browse files
committed
Don't emit diagnostics if MSStructAttr is implicit
1 parent 65a0abb commit 3e42e60

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6179,17 +6179,26 @@ static void handleMSStructAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
61796179
S.Diag(First->getLocation(), diag::note_conflicting_attribute);
61806180
return;
61816181
}
6182+
if (const auto *Preexisting = D->getAttr<MSStructAttr>()) {
6183+
if (Preexisting->isImplicit())
6184+
D->dropAttr<MSStructAttr>();
6185+
}
61826186

61836187
D->addAttr(::new (S.Context) MSStructAttr(S.Context, AL));
61846188
}
61856189

61866190
static void handleGCCStructAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
61876191
if (const auto *First = D->getAttr<MSStructAttr>()) {
6188-
S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible)
6189-
<< AL << First << 0;
6190-
S.Diag(First->getLocation(), diag::note_conflicting_attribute);
6191-
return;
6192+
if (First->isImplicit()) {
6193+
D->dropAttr<MSStructAttr>();
6194+
} else {
6195+
S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible)
6196+
<< AL << First << 0;
6197+
S.Diag(First->getLocation(), diag::note_conflicting_attribute);
6198+
return;
6199+
}
61926200
}
6201+
61936202
D->addAttr(::new (S.Context) GCCStructAttr(S.Context, AL));
61946203
}
61956204

clang/test/Sema/gcc_ms_struct.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,30 @@ __attribute__((gcc_struct))
88
// expected-error@+1 {{'ms_struct' and 'gcc_struct' attributes are not compatible}}
99
__attribute__((ms_struct))
1010
t1;
11+
12+
struct {
13+
int a;
14+
}
15+
// expected-note@+1 {{conflicting attribute is here}}
16+
__attribute__((ms_struct))
17+
// expected-error@+1 {{'gcc_struct' and 'ms_struct' attributes are not compatible}}
18+
__attribute__((gcc_struct))
19+
t2;
20+
21+
#pragma ms_struct on
22+
struct {
23+
int a;
24+
}
25+
// No diagnostic for an attribute, unambiguously overriding the pragma.
26+
__attribute__((gcc_struct))
27+
t3;
28+
29+
struct {
30+
int a;
31+
}
32+
// expected-note@+1 {{conflicting attribute is here}}
33+
__attribute__((ms_struct))
34+
// expected-error@+1 {{'gcc_struct' and 'ms_struct' attributes are not compatible}}
35+
__attribute__((gcc_struct))
36+
t4;
37+
#pragma ms_struct off

0 commit comments

Comments
 (0)