[PATCH] D123167: [HLSL] Pointers are unsupported in HLSL

Chris Bieneman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 5 17:28:26 PDT 2022


beanz created this revision.
beanz added reviewers: aaron.ballman, MaskRay, kuhar, rnk, rsmith.
Herald added a subscriber: StephenFan.
Herald added a project: All.
beanz requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

HLSL does not support pointers or references. This change makes parsing
pointer or reference types into an error under HLSL.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123167

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParseDecl.cpp
  clang/test/ParserHLSL/lit.local.cfg
  clang/test/ParserHLSL/parse_pointer.hlsl
  clang/test/ParserHLSL/parse_reference.hlsl


Index: clang/test/ParserHLSL/parse_reference.hlsl
===================================================================
--- /dev/null
+++ 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;
+}
Index: clang/test/ParserHLSL/parse_pointer.hlsl
===================================================================
--- /dev/null
+++ 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;
+}
Index: clang/test/ParserHLSL/lit.local.cfg
===================================================================
--- /dev/null
+++ clang/test/ParserHLSL/lit.local.cfg
@@ -0,0 +1 @@
+config.suffixes = ['.hlsl']
Index: clang/lib/Parse/ParseDecl.cpp
===================================================================
--- clang/lib/Parse/ParseDecl.cpp
+++ 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 &&.
Index: clang/include/clang/Basic/DiagnosticParseKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticParseKinds.td
+++ 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123167.420670.patch
Type: text/x-patch
Size: 3237 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220406/2b618f8b/attachment-0001.bin>


More information about the cfe-commits mailing list