-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[HLSL] Disallow virtual inheritance and functions #127346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This PR disallows virtual inheritance and virtual functions in HLSL.
@llvm/pr-subscribers-clang @llvm/pr-subscribers-hlsl Author: Chris B (llvm-beanz) ChangesThis PR disallows virtual inheritance and virtual functions in HLSL. Full diff: https://github.com/llvm/llvm-project/pull/127346.diff 4 Files Affected:
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f..bec3b5d48fd51 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1817,5 +1817,7 @@ def ext_hlsl_access_specifiers : ExtWarn<
InGroup<HLSLExtension>;
def err_hlsl_unsupported_component : Error<"invalid component '%0' used; expected 'x', 'y', 'z', or 'w'">;
def err_hlsl_packoffset_invalid_reg : Error<"invalid resource class specifier '%0' for packoffset, expected 'c'">;
+def err_hlsl_virtual_function : Error<"virtual functions are unsupported in HLSL">;
+def err_hlsl_virtual_inheritance : Error<"virtual inheritance is unsupported in HLSL">;
} // end of Parser diagnostics
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 7ae136af47391..dfa2dbf5ab61f 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -4411,7 +4411,12 @@ void Parser::ParseDeclarationSpecifiers(
DiagID = diag::err_openclcxx_virtual_function;
PrevSpec = Tok.getIdentifierInfo()->getNameStart();
isInvalid = true;
- } else {
+ } else if (getLangOpts().HLSL) {
+ DiagID = diag::err_hlsl_virtual_function;
+ PrevSpec = Tok.getIdentifierInfo()->getNameStart();
+ isInvalid = true;
+ }
+ else {
isInvalid = DS.setFunctionSpecVirtual(Loc, PrevSpec, DiagID);
}
break;
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 43db715ac6d70..dbc6d5f7c43a3 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -2491,6 +2491,9 @@ BaseResult Parser::ParseBaseSpecifier(Decl *ClassDecl) {
IsVirtual = true;
}
+ if (getLangOpts().HLSL && IsVirtual)
+ Diag(Tok.getLocation(), diag::err_hlsl_virtual_inheritance);
+
CheckMisplacedCXX11Attribute(Attributes, StartLoc);
// Parse the class-name.
diff --git a/clang/test/SemaHLSL/Language/NoVirtual.hlsl b/clang/test/SemaHLSL/Language/NoVirtual.hlsl
new file mode 100644
index 0000000000000..8d61bde7d836e
--- /dev/null
+++ b/clang/test/SemaHLSL/Language/NoVirtual.hlsl
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -verify %s
+
+struct Base {
+ int X;
+ void MemberFunction(); // valid
+ virtual void MemberFunction2(); // expected-error{{virtual functions are unsupported in HLSL}}
+};
+
+struct Derived : virtual Base { // expected-error{{virtual inheritance is unsupported in HLSL}}
+ int Y;
+
+ void MemberFunction2() override; // expected-error{{only virtual member functions can be marked 'override'}}
+};
+
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
@@ -1817,5 +1817,9 @@ def ext_hlsl_access_specifiers : ExtWarn< | |||
InGroup<HLSLExtension>; | |||
def err_hlsl_unsupported_component : Error<"invalid component '%0' used; expected 'x', 'y', 'z', or 'w'">; | |||
def err_hlsl_packoffset_invalid_reg : Error<"invalid resource class specifier '%0' for packoffset, expected 'c'">; | |||
def err_hlsl_virtual_function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you make this 1 diagnostic with a selector?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately sharing the diagnostic would require a significant reworking of ParseDecl. The diagnostic for virtual functions is not emitted directly at the place where we encounter the keyword, instead we set the decl to invalid and provide the diagnostic ID. There isn't a way currently to also provide diagnostic arguments.
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/65/builds/13464 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/136/builds/3085 Here is the relevant piece of the build log for the reference
|
This PR disallows virtual inheritance and virtual functions in HLSL.