Skip to content

Commit 257edf0

Browse files
Merge from 'sycl' to 'sycl-web' (3 commits)
CONFLICT (content): Merge conflict in clang/include/clang/Basic/DiagnosticSemaKinds.td
2 parents 1aa5640 + 77dd693 commit 257edf0

25 files changed

+319
-340
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,6 +1288,23 @@ def SYCLSpecialClass: InheritableAttr {
12881288
let Documentation = [SYCLSpecialClassDocs];
12891289
}
12901290

1291+
def SYCLType: InheritableAttr {
1292+
let Spellings = [CXX11<"__sycl_detail__", "sycl_type">];
1293+
let Subjects = SubjectList<[CXXRecord, Enum], ErrorDiag>;
1294+
let LangOpts = [SYCLIsDevice, SYCLIsHost];
1295+
let Args = [EnumArgument<"Type", "SYCLType",
1296+
["accessor", "local_accessor", "spec_constant",
1297+
"specialization_id", "kernel_handler", "buffer_location",
1298+
"no_alias", "accessor_property_list", "group",
1299+
"private_memory", "aspect"],
1300+
["accessor", "local_accessor", "spec_constant",
1301+
"specialization_id", "kernel_handler", "buffer_location",
1302+
"no_alias", "accessor_property_list", "group",
1303+
"private_memory", "aspect"]>];
1304+
// Only used internally by SYCL implementation
1305+
let Documentation = [InternalOnly];
1306+
}
1307+
12911308
def SYCLDeviceHas : InheritableAttr {
12921309
let Spellings = [CXX11<"sycl", "device_has">];
12931310
let Subjects = SubjectList<[Function], ErrorDiag>;

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4106,6 +4106,8 @@ def warn_attribute_type_not_supported : Warning<
41064106
def warn_attribute_type_not_supported_global : Warning<
41074107
"%0 attribute argument '%1' not supported on a global variable">,
41084108
InGroup<IgnoredAttributes>;
4109+
def err_attribute_argument_not_supported : Error<
4110+
"%0 attribute argument %1 is not supported">;
41094111
def warn_attribute_unknown_visibility : Warning<"unknown visibility %0">,
41104112
InGroup<IgnoredAttributes>;
41114113
def warn_attribute_protected_visibility :

clang/include/clang/Sema/Sema.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10891,6 +10891,9 @@ class Sema final {
1089110891
ReqdWorkGroupSizeAttr *
1089210892
MergeReqdWorkGroupSizeAttr(Decl *D, const ReqdWorkGroupSizeAttr &A);
1089310893

10894+
SYCLTypeAttr *MergeSYCLTypeAttr(Decl *D, const AttributeCommonInfo &CI,
10895+
SYCLTypeAttr::SYCLType TypeName);
10896+
1089410897
/// Only called on function definitions; if there is a MSVC #pragma optimize
1089510898
/// in scope, consider changing the function's attributes based on the
1089610899
/// optimization list passed to the pragma.
@@ -13576,12 +13579,16 @@ class Sema final {
1357613579
const CXXRecordDecl *RecTy = Ty->getAsCXXRecordDecl();
1357713580
if (!RecTy)
1357813581
return false;
13582+
13583+
if (RecTy->hasAttr<AttrTy>())
13584+
return true;
13585+
1357913586
if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RecTy)) {
1358013587
ClassTemplateDecl *Template = CTSD->getSpecializedTemplate();
1358113588
if (CXXRecordDecl *RD = Template->getTemplatedDecl())
1358213589
return RD->hasAttr<AttrTy>();
1358313590
}
13584-
return RecTy->hasAttr<AttrTy>();
13591+
return false;
1358513592
}
1358613593

1358713594
private:

clang/lib/Sema/SemaDecl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2919,6 +2919,8 @@ static bool mergeDeclAttribute(Sema &S, NamedDecl *D,
29192919
NewAttr = S.MergeSYCLDeviceHasAttr(D, *A);
29202920
else if (const auto *A = dyn_cast<SYCLUsesAspectsAttr>(Attr))
29212921
NewAttr = S.MergeSYCLUsesAspectsAttr(D, *A);
2922+
else if (const auto *A = dyn_cast<SYCLTypeAttr>(Attr))
2923+
NewAttr = S.MergeSYCLTypeAttr(D, *A, A->getType());
29222924
else if (const auto *A = dyn_cast<SYCLIntelPipeIOAttr>(Attr))
29232925
NewAttr = S.MergeSYCLIntelPipeIOAttr(D, *A);
29242926
else if (const auto *A = dyn_cast<SYCLIntelMaxWorkGroupSizeAttr>(Attr))

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10430,46 +10430,15 @@ static void handleFunctionReturnThunksAttr(Sema &S, Decl *D,
1043010430
D->addAttr(FunctionReturnThunksAttr::Create(S.Context, Kind, AL));
1043110431
}
1043210432

10433-
static constexpr std::pair<Decl::Kind, StringRef>
10434-
MakeDeclContextDesc(Decl::Kind K, StringRef SR) {
10435-
return std::pair<Decl::Kind, StringRef>{K, SR};
10436-
}
10437-
10438-
// FIXME: Refactor Util class in SemaSYCL.cpp to avoid following
10439-
// code duplication.
1044010433
bool isDeviceAspectType(const QualType Ty) {
1044110434
const EnumType *ET = Ty->getAs<EnumType>();
1044210435
if (!ET)
1044310436
return false;
1044410437

10445-
std::array<std::pair<Decl::Kind, StringRef>, 3> Scopes = {
10446-
MakeDeclContextDesc(Decl::Kind::Namespace, "sycl"),
10447-
MakeDeclContextDesc(Decl::Kind::Namespace, "_V1"),
10448-
MakeDeclContextDesc(Decl::Kind::Enum, "aspect")};
10449-
10450-
const auto *Ctx = cast<DeclContext>(ET->getDecl());
10451-
StringRef Name = "";
10452-
10453-
for (const auto &Scope : llvm::reverse(Scopes)) {
10454-
Decl::Kind DK = Ctx->getDeclKind();
10455-
if (DK != Scope.first)
10456-
return false;
10438+
if (const auto *Attr = ET->getDecl()->getAttr<SYCLTypeAttr>())
10439+
return Attr->getType() == SYCLTypeAttr::aspect;
1045710440

10458-
switch (DK) {
10459-
case Decl::Kind::Enum:
10460-
Name = cast<EnumDecl>(Ctx)->getName();
10461-
break;
10462-
case Decl::Kind::Namespace:
10463-
Name = cast<NamespaceDecl>(Ctx)->getName();
10464-
break;
10465-
default:
10466-
llvm_unreachable("isDeviceAspectType: decl kind not supported");
10467-
}
10468-
if (Name != Scope.second)
10469-
return false;
10470-
Ctx = Ctx->getParent();
10471-
}
10472-
return Ctx->isTranslationUnit();
10441+
return false;
1047310442
}
1047410443

1047510444
SYCLDeviceHasAttr *Sema::MergeSYCLDeviceHasAttr(Decl *D,
@@ -10594,6 +10563,39 @@ static void handleSYCLKernelAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1059410563
handleSimpleAttribute<SYCLKernelAttr>(S, D, AL);
1059510564
}
1059610565

10566+
SYCLTypeAttr *Sema::MergeSYCLTypeAttr(Decl *D, const AttributeCommonInfo &CI,
10567+
SYCLTypeAttr::SYCLType TypeName) {
10568+
if (const auto *ExistingAttr = D->getAttr<SYCLTypeAttr>()) {
10569+
if (ExistingAttr->getType() != TypeName) {
10570+
Diag(ExistingAttr->getLoc(), diag::err_duplicate_attribute)
10571+
<< ExistingAttr;
10572+
Diag(CI.getLoc(), diag::note_previous_attribute);
10573+
}
10574+
// Do not add duplicate attribute
10575+
return nullptr;
10576+
}
10577+
return ::new (Context) SYCLTypeAttr(Context, CI, TypeName);
10578+
}
10579+
10580+
static void handleSYCLTypeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
10581+
if (!AL.isArgIdent(0)) {
10582+
S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
10583+
<< AL << AANT_ArgumentIdentifier;
10584+
return;
10585+
}
10586+
10587+
IdentifierInfo *II = AL.getArgAsIdent(0)->Ident;
10588+
SYCLTypeAttr::SYCLType Type;
10589+
10590+
if (!SYCLTypeAttr::ConvertStrToSYCLType(II->getName(), Type)) {
10591+
S.Diag(AL.getLoc(), diag::err_attribute_argument_not_supported) << AL << II;
10592+
return;
10593+
}
10594+
10595+
if (SYCLTypeAttr *NewAttr = S.MergeSYCLTypeAttr(D, AL, Type))
10596+
D->addAttr(NewAttr);
10597+
}
10598+
1059710599
static void handleDestroyAttr(Sema &S, Decl *D, const ParsedAttr &A) {
1059810600
if (!cast<VarDecl>(D)->hasGlobalStorage()) {
1059910601
S.Diag(D->getLocation(), diag::err_destroy_attr_on_non_static_var)
@@ -11146,6 +11148,9 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL,
1114611148
case ParsedAttr::AT_SYCLSpecialClass:
1114711149
handleSimpleAttribute<SYCLSpecialClassAttr>(S, D, AL);
1114811150
break;
11151+
case ParsedAttr::AT_SYCLType:
11152+
handleSYCLTypeAttr(S, D, AL);
11153+
break;
1114911154
case ParsedAttr::AT_SYCLDevice:
1115011155
handleSYCLDeviceAttr(S, D, AL);
1115111156
break;

0 commit comments

Comments
 (0)