beanz updated this revision to Diff 425678.
beanz added a comment.
Herald added a project: clang-tools-extra.

Updates based on PR feedback.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124487/new/

https://reviews.llvm.org/D124487

Files:
  clang-tools-extra/test/clang-apply-replacements/Inputs/crlf/crlf.cpp
  clang-tools-extra/test/clang-apply-replacements/Inputs/crlf/crlf.cpp.expected
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/ParserHLSL/access_specifiers.hlsl

Index: clang/test/ParserHLSL/access_specifiers.hlsl
===================================================================
--- /dev/null
+++ clang/test/ParserHLSL/access_specifiers.hlsl
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -ast-dump -o - %s -verify
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -ast-dump -DSTRUCT -o - %s -verify
+
+#ifdef STRUCT
+#define KEYWORD struct
+#else
+#define KEYWORD class
+#endif
+
+KEYWORD Doggo {
+  int legs;    // expected-note {{member is declared here}} expected-note {{member is declared here}}
+protected:     // expected-warning {{access specifiers are a clang HLSL extension}}
+  int ears[2]; // expected-note {{declared protected here}}
+private:       // expected-warning {{access specifiers are a clang HLSL extension}}
+  int tail;    // expected-note {{declared private here}} expected-note {{declared private here}}
+};
+
+KEYWORD Shiba : public Doggo { // expected-warning {{access specifiers are a clang HLSL extension}}
+  int undercoat;
+};
+
+KEYWORD Akita : Doggo {
+  int floof;
+};
+
+KEYWORD Chow : private Doggo {  // expected-warning {{access specifiers are a clang HLSL extension}} expected-note {{constrained by private inheritance here}}
+  int megafloof;
+};
+
+KEYWORD Dachshund : protected Doggo {  // expected-warning {{access specifiers are a clang HLSL extension}} expected-note {{constrained by protected inheritance here}}
+  int wiry;
+};
+
+void Puppers() {
+  Shiba Shibe;
+  Shibe.undercoat = 0xFFFF;
+  Shibe.legs = 4;
+
+  Shibe.tail = 1;    // expected-error {{'tail' is a private member of 'Doggo'}}
+  Shibe.ears[0] = 1; // expected-error {{'ears' is a protected member of 'Doggo'}}
+
+  Akita Aki;
+  Aki.floof = 0xFFFF;
+  Aki.legs = 4;
+
+  Aki.tail = 1; // expected-error {{'tail' is a private member of 'Doggo'}}
+
+  Chow Ch;
+  Ch.megafloof = 0xFFFF;
+
+  Ch.legs = 4; // expected-error {{'legs' is a private member of 'Doggo'}}
+
+  Dachshund DH;
+  DH.legs = 4; // expected-error {{'legs' is a protected member of 'Doggo'}}
+}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===================================================================
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -2501,6 +2501,11 @@
                          bool Virtual, AccessSpecifier Access,
                          TypeSourceInfo *TInfo,
                          SourceLocation EllipsisLoc) {
+  // In HLSL, unspecified class access is public rather than private.
+  if (getLangOpts().HLSL && Class->getTagKind() == TTK_Class &&
+      Access == AS_none)
+    Access = AS_public;
+
   QualType BaseType = TInfo->getType();
   if (BaseType->containsErrors()) {
     // Already emitted a diagnostic when parsing the error type.
Index: clang/lib/Parse/ParseDeclCXX.cpp
===================================================================
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -2170,8 +2170,11 @@
 
   // Parse an (optional) access specifier.
   AccessSpecifier Access = getAccessSpecifierIfPresent();
-  if (Access != AS_none)
+  if (Access != AS_none) {
     ConsumeToken();
+    if (getLangOpts().HLSL)
+      Diag(Tok.getLocation(), diag::ext_hlsl_access_specifiers);
+  }
 
   CheckMisplacedCXX11Attribute(Attributes, StartLoc);
 
@@ -3270,6 +3273,8 @@
     LLVM_FALLTHROUGH;
   case tok::kw_public:
   case tok::kw_protected: {
+    if (getLangOpts().HLSL)
+      Diag(Tok.getLocation(), diag::ext_hlsl_access_specifiers);
     AccessSpecifier NewAS = getAccessSpecifierIfPresent();
     assert(NewAS != AS_none);
     // Current token is a C++ access specifier.
@@ -3509,8 +3514,9 @@
   // C++ 11p3: Members of a class defined with the keyword class are private
   // by default. Members of a class defined with the keywords struct or union
   // are public by default.
+  // HLSL: In HLSL members of a class are public by default.
   AccessSpecifier CurAS;
-  if (TagType == DeclSpec::TST_class)
+  if (TagType == DeclSpec::TST_class && !getLangOpts().HLSL)
     CurAS = AS_private;
   else
     CurAS = AS_public;
Index: clang/include/clang/Basic/DiagnosticParseKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticParseKinds.td
+++ clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1599,5 +1599,8 @@
 def err_expected_semantic_identifier : Error<
   "expected HLSL Semantic identifier">;
 def err_unknown_hlsl_semantic : Error<"unknown HLSL semantic %0">;
+def ext_hlsl_access_specifiers : ExtWarn<
+  "access specifiers are a clang HLSL extension">,
+  InGroup<HLSLExtension>;
 
 } // end of Parser diagnostics
Index: clang/include/clang/Basic/DiagnosticGroups.td
===================================================================
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -1362,3 +1362,6 @@
 
 def BranchProtection : DiagGroup<"branch-protection">;
 
+// HLSL diagnostic groups
+// Warnings for HLSL Clang extensions
+def HLSLExtension : DiagGroup<"hlsl-extensions">;
Index: clang-tools-extra/test/clang-apply-replacements/Inputs/crlf/crlf.cpp.expected
===================================================================
--- clang-tools-extra/test/clang-apply-replacements/Inputs/crlf/crlf.cpp.expected
+++ clang-tools-extra/test/clang-apply-replacements/Inputs/crlf/crlf.cpp.expected
@@ -1,6 +1,6 @@
-
-// This file intentionally uses a CRLF newlines!
-
-void foo() {
-  int *x = nullptr;
-}
+
+// This file intentionally uses a CRLF newlines!
+
+void foo() {
+  int *x = nullptr;
+}
Index: clang-tools-extra/test/clang-apply-replacements/Inputs/crlf/crlf.cpp
===================================================================
--- clang-tools-extra/test/clang-apply-replacements/Inputs/crlf/crlf.cpp
+++ clang-tools-extra/test/clang-apply-replacements/Inputs/crlf/crlf.cpp
@@ -1,6 +1,6 @@
-
-// This file intentionally uses a CRLF newlines!
-
-void foo() {
-  int *x = 0;
-}
+
+// This file intentionally uses a CRLF newlines!
+
+void foo() {
+  int *x = 0;
+}
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to