Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tools/clang/include/clang/Basic/DiagnosticParseKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,8 @@ def warn_hlsl_effect_technique : Warning <
def warn_hlsl_semantic_identifier_collision : Warning <
"'%0' interpreted as semantic; previous definition(s) ignored">,
InGroup< HLSLSemanticIdentifierCollision >;
def err_hlsl_expected_hlsl_attribute : Error <
"Unexpected '(' in semantic annotation. Did you mean 'packoffset()' or 'register()'?">;
def err_hlsl_enum : Error<
"enum is unsupported in HLSL before 2017">;
def warn_hlsl_new_feature : Warning <
Expand Down
10 changes: 10 additions & 0 deletions tools/clang/lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,16 @@ bool Parser::MaybeParseHLSLAttributes(std::vector<hlsl::UnusualAnnotation *> &ta
Actions.DiagnoseSemanticDecl(pUA);
ConsumeToken(); // consume semantic

// Likely a misspell of register(), packoffset() or a mismatching macro:
// both registr() and packofset() would cause a crash without this fix.

if (Tok.is(tok::l_paren)) {
Diag(Tok.getLocation(), diag::err_hlsl_expected_hlsl_attribute);
ConsumeParen();
SkipUntil(tok::r_paren, StopAtSemi); // skip through )
return true;
}

target.push_back(pUA);
}
else {
Expand Down
38 changes: 38 additions & 0 deletions tools/clang/test/SemaHLSL/hlsl-attribute-mistype-errors.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// RUN: %dxc -T lib_6_3 -verify %s

// expected-error@+1 {{Unexpected '(' in semantic annotation. Did you mean 'packoffset()' or 'register()'?}}
RWStructuredBuffer<float4> uav1 : registers(u3);

// expected-error@+1 {{Unexpected '(' in semantic annotation. Did you mean 'packoffset()' or 'register()'?}}
RWStructuredBuffer<float4> uav2 : registers(outer_space);

// expected-error@+1 {{Unexpected '(' in semantic annotation. Did you mean 'packoffset()' or 'register()'?}}
RWStructuredBuffer<float4> uav3 : UNDEFINED_MACRO1(u3);

// expected-error@+1 {{Unexpected '(' in semantic annotation. Did you mean 'packoffset()' or 'register()'?}}
RWStructuredBuffer<float4> uav4 : UNDEFINED_MACRO(something, more, complex);

cbuffer buf {

// expected-error@+1 {{Unexpected '(' in semantic annotation. Did you mean 'packoffset()' or 'register()'?}}
float4 v0 : packoffsets(c0);

// expected-error@+1 {{Unexpected '(' in semantic annotation. Did you mean 'packoffset()' or 'register()'?}}
float4 v1 : packoffsets(invalid_syntax);

// expected-error@+1 {{Unexpected '(' in semantic annotation. Did you mean 'packoffset()' or 'register()'?}}
float v2 : UNDEFINED_MACRO2(c0.w);

// expected-error@+1 {{Unexpected '(' in semantic annotation. Did you mean 'packoffset()' or 'register()'?}}
float v3 : UNDEFINED_MACRO(something, more, complex);
};

[shader("pixel")]
float4 main(): SV_Target
{
uav1[0] = v0;
uav2[0] = v1;
uav3[0] = v2;
uav4[0] = v3;
return 0.xxxx;
}