Skip to content

Commit 788c541

Browse files
committed
[ser] Diagnose implied 'reordercoherent' in type attributes
1 parent 33512df commit 788c541

5 files changed

Lines changed: 69 additions & 12 deletions

File tree

tools/clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7769,6 +7769,8 @@ def warn_hlsl_impcast_rdc_mismatch : Warning<
77697769
def warn_hlsl_impcast_rdc_glc_mismatch : Warning<
77707770
"implicit conversion from %0 to %1 %select{demotes globallycoherent to reordercoherent|promotes reordercoherent to globallycoherent}2 annotation">,
77717771
InGroup<Conversion>, DefaultWarn;
7772+
def warn_hlsl_glc_implies_rdc : Warning<
7773+
"attribute 'globallycoherent' implies 'reordercoherent'">, InGroup<IgnoredAttributes>;
77727774
def warn_hlsl_narrowing : Warning<
77737775
"conversion from larger type %0 to smaller type %1, possible loss of data">,
77747776
InGroup<Conversion>, DefaultWarn;

tools/clang/include/clang/Sema/SemaHLSL.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ void Indent(unsigned int Indentation, llvm::raw_ostream &Out);
203203
void GetHLSLAttributedTypes(clang::Sema *self, clang::QualType type,
204204
const clang::AttributedType **ppMatrixOrientation,
205205
const clang::AttributedType **ppNorm,
206-
const clang::AttributedType **ppGLC);
206+
const clang::AttributedType **ppGLC,
207+
const clang::AttributedType **ppRDC);
207208

208209
bool IsMatrixType(clang::Sema *self, clang::QualType type);
209210
bool IsVectorType(clang::Sema *self, clang::QualType type);

tools/clang/lib/Sema/SemaHLSL.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15343,15 +15343,17 @@ static QualType getUnderlyingType(QualType Type) {
1534315343
void hlsl::GetHLSLAttributedTypes(
1534415344
clang::Sema *self, clang::QualType type,
1534515345
const clang::AttributedType **ppMatrixOrientation,
15346-
const clang::AttributedType **ppNorm, const clang::AttributedType **ppGLC) {
15346+
const clang::AttributedType **ppNorm, const clang::AttributedType **ppGLC,
15347+
const clang::AttributedType **ppRDC) {
1534715348
AssignOpt<const clang::AttributedType *>(nullptr, ppMatrixOrientation);
1534815349
AssignOpt<const clang::AttributedType *>(nullptr, ppNorm);
1534915350
AssignOpt<const clang::AttributedType *>(nullptr, ppGLC);
15351+
AssignOpt<const clang::AttributedType *>(nullptr, ppRDC);
1535015352

1535115353
// Note: we clear output pointers once set so we can stop searching
1535215354
QualType Desugared = getUnderlyingType(type);
1535315355
const AttributedType *AT = dyn_cast<AttributedType>(Desugared);
15354-
while (AT && (ppMatrixOrientation || ppNorm || ppGLC)) {
15356+
while (AT && (ppMatrixOrientation || ppNorm || ppGLC || ppRDC)) {
1535515357
AttributedType::Kind Kind = AT->getAttrKind();
1535615358

1535715359
if (Kind == AttributedType::attr_hlsl_row_major ||
@@ -15371,6 +15373,11 @@ void hlsl::GetHLSLAttributedTypes(
1537115373
*ppGLC = AT;
1537215374
ppGLC = nullptr;
1537315375
}
15376+
} else if (Kind == AttributedType::attr_hlsl_reordercoherent) {
15377+
if (ppRDC) {
15378+
*ppRDC = AT;
15379+
ppRDC = nullptr;
15380+
}
1537415381
}
1537515382

1537615383
Desugared = getUnderlyingType(AT->getEquivalentType());

tools/clang/lib/Sema/SemaType.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5805,7 +5805,9 @@ static bool handleHLSLTypeAttr(TypeProcessingState &State,
58055805
const AttributedType *pMatrixOrientation = nullptr;
58065806
const AttributedType *pNorm = nullptr;
58075807
const AttributedType *pGLC = nullptr;
5808-
hlsl::GetHLSLAttributedTypes(&S, Type, &pMatrixOrientation, &pNorm, &pGLC);
5808+
const AttributedType *pRDC = nullptr;
5809+
hlsl::GetHLSLAttributedTypes(&S, Type, &pMatrixOrientation, &pNorm, &pGLC,
5810+
&pRDC);
58095811

58105812
if (pMatrixOrientation &&
58115813
(Kind == AttributeList::AT_HLSLColumnMajor ||
@@ -5839,14 +5841,18 @@ static bool handleHLSLTypeAttr(TypeProcessingState &State,
58395841
return true;
58405842
}
58415843

5842-
if (pGLC && (Kind == AttributeList::AT_HLSLGloballyCoherent ||
5843-
Kind == AttributeList::AT_HLSLReorderCoherent)) {
5844-
AttributedType::Kind CurAttrKind = pGLC->getAttrKind();
5845-
if (Kind == getAttrListKind(CurAttrKind)) {
5846-
S.Diag(Attr.getLoc(), diag::warn_duplicate_attribute_exact)
5847-
<< Attr.getName() << Attr.getRange();
5848-
}
5849-
}
5844+
const bool hasGLC = pGLC;
5845+
const bool addsGLC = Kind == AttributeList::AT_HLSLGloballyCoherent;
5846+
const bool hasRDC = pRDC;
5847+
const bool addsRDC = Kind == AttributeList::AT_HLSLReorderCoherent;
5848+
5849+
const bool hasMismatchingAttrs = hasGLC && hasRDC;
5850+
const bool addsMismatchingAttr = (hasGLC && addsRDC) || (hasRDC && addsGLC);
5851+
if ((hasGLC && addsGLC) || (hasRDC && addsRDC))
5852+
S.Diag(Attr.getLoc(), diag::warn_duplicate_attribute_exact)
5853+
<< Attr.getName() << Attr.getRange();
5854+
else if (!hasMismatchingAttrs && addsMismatchingAttr)
5855+
S.Diag(Attr.getLoc(), diag::warn_hlsl_glc_implies_rdc) << Attr.getRange();
58505856

58515857
AttributedType::Kind TAK;
58525858
switch (Kind) {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// RUN: %dxc -E main -T lib_6_9 -verify %s
2+
// REQUIRES: dxil-1-9
3+
4+
using Ty = RWTexture1D<float4>;
5+
6+
using GTy = globallycoherent Ty;
7+
using RTy = reordercoherent Ty;
8+
9+
// expected-warning@+1{{attribute 'globallycoherent' is already applied}}
10+
using GGTy = globallycoherent GTy;
11+
// expected-warning@+1{{attribute 'reordercoherent' is already applied}}
12+
using RRTy = reordercoherent RTy;
13+
14+
// expected-warning@+1{{attribute 'globallycoherent' implies 'reordercoherent'}}
15+
using GRTy = globallycoherent RTy;
16+
// expected-warning@+1{{attribute 'globallycoherent' implies 'reordercoherent'}}
17+
using RGTy = reordercoherent GTy;
18+
19+
// expected-warning@+1{{attribute 'globallycoherent' is already applied}}
20+
using GGRTy = globallycoherent GRTy;
21+
// expected-warning@+1{{attribute 'reordercoherent' is already applied}}
22+
using RRGTy = reordercoherent RGTy;
23+
24+
// expected-warning@+1{{attribute 'globallycoherent' implies 'reordercoherent'}}
25+
using GRTy2 = globallycoherent reordercoherent Ty;
26+
// expected-warning@+1{{attribute 'globallycoherent' implies 'reordercoherent'}}
27+
using RGTy2 = reordercoherent globallycoherent Ty;
28+
29+
// expected-warning@+2{{attribute 'globallycoherent' implies 'reordercoherent'}}
30+
// expected-warning@+1{{attribute 'globallycoherent' is already applied}}
31+
using GGRTy2 = globallycoherent globallycoherent reordercoherent Ty;
32+
// expected-warning@+2{{attribute 'globallycoherent' implies 'reordercoherent'}}
33+
// expected-warning@+1{{attribute 'globallycoherent' is already applied}}
34+
using GRGTy2 = globallycoherent reordercoherent globallycoherent Ty;
35+
36+
// expected-warning@+2{{attribute 'globallycoherent' implies 'reordercoherent'}}
37+
// expected-warning@+1{{attribute 'reordercoherent' is already applied}}
38+
using RGRTy2 = reordercoherent globallycoherent reordercoherent Ty;
39+
// expected-warning@+2{{attribute 'globallycoherent' implies 'reordercoherent'}}
40+
// expected-warning@+1{{attribute 'reordercoherent' is already applied}}
41+
using RRGTy2 = reordercoherent reordercoherent globallycoherent Ty;

0 commit comments

Comments
 (0)