Skip to content

Commit b5d4c96

Browse files
committed
fix more comments
1 parent 0a6d767 commit b5d4c96

File tree

3 files changed

+19
-49
lines changed

3 files changed

+19
-49
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13070,13 +13070,11 @@ def warn_cuda_maxclusterrank_sm_90 : Warning<
1307013070
"maxclusterrank requires sm_90 or higher, CUDA arch provided: %0, ignoring "
1307113071
"%1 attribute">, InGroup<IgnoredAttributes>;
1307213072

13073-
def err_cuda_cluster_attr_not_supported : Error<
13074-
"%0 is not supported for this GPU architecture"
13075-
>;
13073+
def err_cluster_attr_not_supported : Error<
13074+
"%0 is not supported for this GPU architecture">;
1307613075

13077-
def err_cuda_cluster_dims_too_large : Error<
13078-
"cluster does not support more than %0 thread blocks; %1 provided"
13079-
>;
13076+
def err_cluster_dims_too_large : Error<
13077+
"cluster does not support more than %0 thread blocks; %1 provided">;
1308013078

1308113079
// VTable pointer authentication errors
1308213080
def err_non_polymorphic_vtable_pointer_auth : Error<

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5679,7 +5679,7 @@ static void handleLaunchBoundsAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
56795679
static std::pair<Expr *, int>
56805680
makeClusterDimsArgExpr(Sema &S, Expr *E, const CUDAClusterDimsAttr &AL,
56815681
const unsigned Idx) {
5682-
if (S.DiagnoseUnexpandedParameterPack(E))
5682+
if (!E || S.DiagnoseUnexpandedParameterPack(E))
56835683
return {};
56845684

56855685
// Accept template arguments for now as they depend on something else.
@@ -5712,26 +5712,13 @@ CUDAClusterDimsAttr *Sema::createClusterDimsAttr(const AttributeCommonInfo &CI,
57125712
Expr *X, Expr *Y, Expr *Z) {
57135713
CUDAClusterDimsAttr TmpAttr(Context, CI, X, Y, Z);
57145714

5715-
int ValX = 1;
5716-
int ValY = 1;
5717-
int ValZ = 1;
5715+
auto [NewX, ValX] = makeClusterDimsArgExpr(*this, X, TmpAttr, /*Idx=*/0);
5716+
auto [NewY, ValY] = makeClusterDimsArgExpr(*this, Y, TmpAttr, /*Idx=*/1);
5717+
auto [NewZ, ValZ] = makeClusterDimsArgExpr(*this, Z, TmpAttr, /*Idx=*/2);
57185718

5719-
std::tie(X, ValX) = makeClusterDimsArgExpr(*this, X, TmpAttr, /*Idx=*/0);
5720-
if (!X)
5719+
if (!NewX || (Y && !NewY) || (Z && !NewZ))
57215720
return nullptr;
57225721

5723-
if (Y) {
5724-
std::tie(Y, ValY) = makeClusterDimsArgExpr(*this, Y, TmpAttr, /*Idx=*/1);
5725-
if (!Y)
5726-
return nullptr;
5727-
}
5728-
5729-
if (Z) {
5730-
std::tie(Z, ValZ) = makeClusterDimsArgExpr(*this, Z, TmpAttr, /*Idx=*/2);
5731-
if (!Z)
5732-
return nullptr;
5733-
}
5734-
57355722
int FlatDim = ValX * ValY * ValZ;
57365723
const llvm::Triple TT =
57375724
(!Context.getLangOpts().CUDAIsDevice && Context.getAuxTargetInfo())
@@ -5748,12 +5735,11 @@ CUDAClusterDimsAttr *Sema::createClusterDimsAttr(const AttributeCommonInfo &CI,
57485735
// A maximum of 8 thread blocks in a cluster is supported as a portable
57495736
// cluster size in CUDA. The number is 16 for AMDGPU.
57505737
if (FlatDim > MaxDim) {
5751-
Diag(CI.getLoc(), diag::err_cuda_cluster_dims_too_large)
5752-
<< MaxDim << FlatDim;
5738+
Diag(CI.getLoc(), diag::err_cluster_dims_too_large) << MaxDim << FlatDim;
57535739
return nullptr;
57545740
}
57555741

5756-
return CUDAClusterDimsAttr::Create(Context, X, Y, Z, CI);
5742+
return CUDAClusterDimsAttr::Create(Context, NewX, NewY, NewZ, CI);
57575743
}
57585744

57595745
void Sema::addClusterDimsAttr(Decl *D, const AttributeCommonInfo &CI, Expr *X,
@@ -5772,7 +5758,7 @@ static void handleClusterDimsAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
57725758
if ((TTI.getTriple().isNVPTX() && Arch < clang::OffloadArch::SM_90) ||
57735759
(TTI.getTriple().isAMDGPU() &&
57745760
!TTI.hasFeatureEnabled(TTI.getTargetOpts().FeatureMap, "clusters"))) {
5775-
S.Diag(AL.getLoc(), diag::err_cuda_cluster_attr_not_supported)
5761+
S.Diag(AL.getLoc(), diag::err_cluster_attr_not_supported)
57765762
<< "__cluster_dims__";
57775763
return;
57785764
}
@@ -5792,7 +5778,7 @@ static void handleNoClusterAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
57925778
if ((TTI.getTriple().isNVPTX() && Arch < clang::OffloadArch::SM_90) ||
57935779
(TTI.getTriple().isAMDGPU() &&
57945780
!TTI.hasFeatureEnabled(TTI.getTargetOpts().FeatureMap, "clusters"))) {
5795-
S.Diag(AL.getLoc(), diag::err_cuda_cluster_attr_not_supported)
5781+
S.Diag(AL.getLoc(), diag::err_cluster_attr_not_supported)
57965782
<< "__no_cluster__";
57975783
return;
57985784
}

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -713,27 +713,13 @@ static void instantiateDependentCUDAClusterDimsAttr(
713713
EnterExpressionEvaluationContext Unevaluated(
714714
S, Sema::ExpressionEvaluationContext::ConstantEvaluated);
715715

716-
Expr *XExpr = nullptr;
717-
Expr *YExpr = nullptr;
718-
Expr *ZExpr = nullptr;
719-
720-
if (Attr.getX()) {
721-
ExprResult ResultX = S.SubstExpr(Attr.getX(), TemplateArgs);
722-
if (ResultX.isUsable())
723-
XExpr = ResultX.get();
724-
}
725-
726-
if (Attr.getY()) {
727-
ExprResult ResultY = S.SubstExpr(Attr.getY(), TemplateArgs);
728-
if (ResultY.isUsable())
729-
YExpr = ResultY.get();
730-
}
716+
auto SubstElt = [&S, &TemplateArgs](Expr *E) {
717+
return E ? S.SubstExpr(E, TemplateArgs).get() : nullptr;
718+
};
731719

732-
if (Attr.getZ()) {
733-
ExprResult ResultZ = S.SubstExpr(Attr.getZ(), TemplateArgs);
734-
if (ResultZ.isUsable())
735-
ZExpr = ResultZ.get();
736-
}
720+
Expr *XExpr = SubstElt(Attr.getX());
721+
Expr *YExpr = SubstElt(Attr.getY());
722+
Expr *ZExpr = SubstElt(Attr.getZ());
737723

738724
S.addClusterDimsAttr(New, Attr, XExpr, YExpr, ZExpr);
739725
}

0 commit comments

Comments
 (0)