Skip to content

Commit ca69c68

Browse files
committed
Split into a MS and Itanium attribute
1 parent ec0efa9 commit ca69c68

File tree

6 files changed

+45
-16
lines changed

6 files changed

+45
-16
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,11 +1799,22 @@ def ArmMveStrictPolymorphism : TypeAttr, TargetSpecificAttr<TargetARM> {
17991799
}
18001800

18011801
def NoUniqueAddress : InheritableAttr {
1802-
let Spellings = [CXX11<"", "no_unique_address", 201803>,
1803-
CXX11<"msvc", "no_unique_address", 201803>];
1804-
let Accessors = [Accessor<"isStandard", [CXX11<"", "no_unique_address", 201803>]>,
1805-
Accessor<"isMSVC", [CXX11<"msvc", "no_unique_address", 201803>]>];
18061802
let Subjects = SubjectList<[NonBitField], ErrorDiag>;
1803+
// No spellings because instances of this attribute are created by
1804+
// MSNoUniqueAddress and ItaniumNoUniqueAddress
1805+
let Spellings = [];
1806+
let Documentation = [NoUniqueAddressDocs];
1807+
}
1808+
1809+
def MSNoUniqueAddress : InheritableAttr, TargetSpecificAttr<TargetMicrosoftCXXABI> {
1810+
let Subjects = SubjectList<[NonBitField], ErrorDiag>;
1811+
let Spellings = [CXX11<"msvc", "no_unique_address", 201803>];
1812+
let Documentation = [NoUniqueAddressDocs];
1813+
}
1814+
1815+
def ItaniumNoUniqueAddress : InheritableAttr, TargetSpecificAttr<TargetItaniumCXXABI> {
1816+
let Subjects = SubjectList<[NonBitField], ErrorDiag>;
1817+
let Spellings = [CXX11<"", "no_unique_address", 201803>];
18071818
let Documentation = [NoUniqueAddressDocs];
18081819
}
18091820

clang/lib/Parse/ParseDeclCXX.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4364,7 +4364,8 @@ static bool IsBuiltInOrStandardCXX11Attribute(IdentifierInfo *AttrName,
43644364
case ParsedAttr::AT_Deprecated:
43654365
case ParsedAttr::AT_FallThrough:
43664366
case ParsedAttr::AT_CXX11NoReturn:
4367-
case ParsedAttr::AT_NoUniqueAddress:
4367+
case ParsedAttr::AT_MSNoUniqueAddress:
4368+
case ParsedAttr::AT_ItaniumNoUniqueAddress:
43684369
case ParsedAttr::AT_Likely:
43694370
case ParsedAttr::AT_Unlikely:
43704371
return true;

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8372,14 +8372,6 @@ static void handleNoMergeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
83728372
}
83738373

83748374
static void handleNoUniqueAddressAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
8375-
NoUniqueAddressAttr TmpAttr(S.Context, AL);
8376-
if (S.getLangOpts().MSVCCompat && TmpAttr.isStandard()) {
8377-
S.Diag(AL.getLoc(), diag::warn_attribute_ignored) << AL;
8378-
return;
8379-
} else if (TmpAttr.isMSVC()) {
8380-
S.Diag(AL.getLoc(), diag::warn_attribute_ignored) << AL;
8381-
return;
8382-
}
83838375
D->addAttr(NoUniqueAddressAttr::Create(S.Context, AL));
83848376
}
83858377

@@ -9288,7 +9280,10 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL,
92889280
case ParsedAttr::AT_NoMerge:
92899281
handleNoMergeAttr(S, D, AL);
92909282
break;
9291-
case ParsedAttr::AT_NoUniqueAddress:
9283+
case ParsedAttr::AT_MSNoUniqueAddress:
9284+
handleNoUniqueAddressAttr(S, D, AL);
9285+
break;
9286+
case ParsedAttr::AT_ItaniumNoUniqueAddress:
92929287
handleNoUniqueAddressAttr(S, D, AL);
92939288
break;
92949289

clang/test/Preprocessor/has_attribute.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ CXX11(fallthrough)
4343
CXX11(likely)
4444
CXX11(maybe_unused)
4545
CXX11(no_unique_address)
46+
CXX11(msvc::no_unique_address)
4647
CXX11(nodiscard)
4748
CXX11(noreturn)
4849
CXX11(unlikely)
@@ -55,7 +56,9 @@ CXX11(unlikely)
5556
// CHECK: likely: 201803L
5657
// CHECK: maybe_unused: 201603L
5758
// ITANIUM: no_unique_address: 201803L
58-
// WINDOWS: no_unique_address: 201803L
59+
// WINDOWS: no_unique_address: 0
60+
// ITANIUM: msvc::no_unique_address: 0
61+
// WINDOWS: msvc::no_unique_address: 201803L
5962
// CHECK: nodiscard: 201907L
6063
// CHECK: noreturn: 200809L
6164
// CHECK: unlikely: 201803L
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %clang_cc1 -std=c++2a %s -verify=unsupported -triple x86_64-linux-gnu
2+
// RUN: %clang_cc1 -std=c++2a %s -verify -triple x86_64-windows -fms-compatibility
3+
4+
[[msvc::no_unique_address]] int a; // expected-error {{only applies to non-bit-field non-static data members}} unsupported-warning {{unknown}}
5+
[[msvc::no_unique_address]] void f(); // expected-error {{only applies to non-bit-field non-static data members}} unsupported-warning {{unknown}}
6+
struct [[msvc::no_unique_address]] S { // expected-error {{only applies to non-bit-field non-static data members}} unsupported-warning {{unknown}}
7+
[[msvc::no_unique_address]] int a; // unsupported-warning {{unknown}}
8+
[[msvc::no_unique_address]] void f(); // expected-error {{only applies to non-bit-field non-static data members}} unsupported-warning {{unknown}}
9+
[[msvc::no_unique_address]] static int sa;// expected-error {{only applies to non-bit-field non-static data members}} unsupported-warning {{unknown}}
10+
[[msvc::no_unique_address]] static void sf(); // expected-error {{only applies to non-bit-field non-static data members}} unsupported-warning {{unknown}}
11+
[[msvc::no_unique_address]] int b : 3; // expected-error {{only applies to non-bit-field non-static data members}} unsupported-warning {{unknown}}
12+
13+
[[msvc::no_unique_address, msvc::no_unique_address]] int duplicated; // ok
14+
// unsupported-warning@-1 2{{unknown}}
15+
[[msvc::no_unique_address]] [[msvc::no_unique_address]] int duplicated2; // unsupported-warning 2{{unknown}}
16+
[[msvc::no_unique_address()]] int arglist; // expected-error {{cannot have an argument list}} unsupported-warning {{unknown}}
17+
18+
int [[msvc::no_unique_address]] c; // expected-error {{cannot be applied to types}} unsupported-error {{cannot be applied to types}}
19+
};

clang/test/SemaCXX/cxx2a-no-unique-address.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %clang_cc1 -std=c++2a %s -verify -triple x86_64-linux-gnu
2-
// RUN: %clang_cc1 -std=c++2a %s -verify -triple x86_64-windows
2+
// RUN: %clang_cc1 -std=c++2a %s -verify=unsupported -triple x86_64-windows
33

44
[[no_unique_address]] int a; // expected-error {{only applies to non-bit-field non-static data members}} unsupported-warning {{unknown}}
55
[[no_unique_address]] void f(); // expected-error {{only applies to non-bit-field non-static data members}} unsupported-warning {{unknown}}

0 commit comments

Comments
 (0)