diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -1594,4 +1594,6 @@ def note_max_tokens_total_override : Note<"total token limit set here">; +def err_hlsl_pointers_unsupported : Error<"%select{pointers|references}0 are unsupported in HLSL">; + } // end of Parser diagnostics diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -5852,6 +5852,12 @@ return; } + if (getLangOpts().HLSL) { + Diag(Tok, diag::err_hlsl_pointers_unsupported) << 0; + D.SetIdentifier(0, Tok.getLocation()); + D.setInvalidType(); + } + if (SS.isValid()) { checkCompoundToken(SS.getEndLoc(), tok::coloncolon, CompoundToken::MemberPtr); @@ -5894,6 +5900,11 @@ return; } + if (getLangOpts().HLSL) { + unsigned PtrOrRef = (Kind == tok::amp || Kind == tok::ampamp) ? 1 : 0; + Diag(Tok, diag::err_hlsl_pointers_unsupported) << PtrOrRef; + } + // Otherwise, '*' -> pointer, '^' -> block, '&' -> lvalue reference, // '&&' -> rvalue reference SourceLocation Loc = ConsumeToken(); // Eat the *, ^, & or &&. diff --git a/clang/test/ParserHLSL/lit.local.cfg b/clang/test/ParserHLSL/lit.local.cfg new file mode 100644 --- /dev/null +++ b/clang/test/ParserHLSL/lit.local.cfg @@ -0,0 +1 @@ +config.suffixes = ['.hlsl'] diff --git a/clang/test/ParserHLSL/parse_pointer.hlsl b/clang/test/ParserHLSL/parse_pointer.hlsl new file mode 100644 --- /dev/null +++ b/clang/test/ParserHLSL/parse_pointer.hlsl @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -triple dxil-pc-shadermodel4.0-compute -x hlsl -o - -fsyntax-only %s -verify + +typedef int (*fn_int)(int); // expected-error {{pointers are unsupported in HLSL}} +void* bark(int); // expected-error {{pointers are unsupported in HLSL}} +void meow(int*); // expected-error {{pointers are unsupported in HLSL}} + +struct Foo { + int X; + int Y; +}; + +void woof(int Foo::*Member); // expected-error {{pointers are unsupported in HLSL}} + +int entry() { + int X; + Foo F; + int Foo::*Member = &F.X; // expected-error {{pointers are unsupported in HLSL}} + int *Y = &X; // expected-error {{pointers are unsupported in HLSL}} +} + +int roar(Foo *F) { // expected-error {{pointers are unsupported in HLSL}} + return F->X; +} diff --git a/clang/test/ParserHLSL/parse_reference.hlsl b/clang/test/ParserHLSL/parse_reference.hlsl new file mode 100644 --- /dev/null +++ b/clang/test/ParserHLSL/parse_reference.hlsl @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -triple dxil-pc-shadermodel4.0-compute -x hlsl -o - -fsyntax-only %s -verify + +int& bark(int); // expected-error {{references are unsupported in HLSL}} +void meow(int&); // expected-error {{references are unsupported in HLSL}} + +struct Foo { + int X; + int Y; +}; + +int entry() { + int X; + int &Y = X; // expected-error {{references are unsupported in HLSL}} +} + +int roar(Foo &F) { // expected-error {{references are unsupported in HLSL}} + return F.X; +}