Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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 <
"Syntax indicated an hlsl attribute (: packoffset() or : register()), but unexpected attribute '%0' was used instead.">;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def err_hlsl_expected_hlsl_attribute : Error <
"Syntax indicated an hlsl attribute (: packoffset() or : register()), but unexpected attribute '%0' was used instead.">;
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
11 changes: 11 additions & 0 deletions tools/clang/lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,17 @@ 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)
<< semanticName;
ConsumeParen();
SkipUntil(tok::r_paren, StopAtSemi); // skip through )
return true;
}

target.push_back(pUA);
}
else {
Expand Down
35 changes: 35 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,35 @@
// RUN: %dxc -T lib_6_3 -verify %s

// expected-error@+1 {{Syntax indicated an hlsl attribute (: packoffset() or : register()), but unexpected attribute 'registers' was used instead.}}
RWStructuredBuffer<float4> uav1 : registers(u3);

// expected-error@+1 {{Syntax indicated an hlsl attribute (: packoffset() or : register()), but unexpected attribute 'registers' was used instead.}}
RWStructuredBuffer<float4> uav2 : registers(outer_space);

// expected-error@+1 {{Syntax indicated an hlsl attribute (: packoffset() or : register()), but unexpected attribute 'UNDEFINED_MACRO1' was used instead.}}
RWStructuredBuffer<float4> uav3 : UNDEFINED_MACRO1(u3);

// expected-error@+1 {{Syntax indicated an hlsl attribute (: packoffset() or : register()), but unexpected attribute 'UNDEFINED_MACRO' was used instead.}}
RWStructuredBuffer<float4> uav4 : UNDEFINED_MACRO(something, more, complex);

cbuffer buf {

// expected-error@+1 {{Syntax indicated an hlsl attribute (: packoffset() or : register()), but unexpected attribute 'packofset' was used instead.}}
float4 v0 : packofset(c0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be able to add packoffsets so that it is tested the same way like registers?
I.E., a correct spelling with extra garbage at the end of the token.
This is effectively duplicating testing UNDEFINED_MACRO as is.


// expected-error@+1 {{Syntax indicated an hlsl attribute (: packoffset() or : register()), but unexpected attribute 'UNDEFINED_MACRO2' was used instead.}}
float v1 : UNDEFINED_MACRO2(c0.w);

// expected-error@+1 {{Syntax indicated an hlsl attribute (: packoffset() or : register()), but unexpected attribute 'UNDEFINED_MACRO' was used instead.}}
float v2 : UNDEFINED_MACRO(something, more, complex);
};

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