Skip to content

Commit a7d5b3f

Browse files
authored
[HLSL] Disallow virtual inheritance and functions (#127346)
This PR disallows virtual inheritance and virtual functions in HLSL.
1 parent b6bb9dc commit a7d5b3f

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,5 +1817,9 @@ def ext_hlsl_access_specifiers : ExtWarn<
18171817
InGroup<HLSLExtension>;
18181818
def err_hlsl_unsupported_component : Error<"invalid component '%0' used; expected 'x', 'y', 'z', or 'w'">;
18191819
def err_hlsl_packoffset_invalid_reg : Error<"invalid resource class specifier '%0' for packoffset, expected 'c'">;
1820+
def err_hlsl_virtual_function
1821+
: Error<"virtual functions are unsupported in HLSL">;
1822+
def err_hlsl_virtual_inheritance
1823+
: Error<"virtual inheritance is unsupported in HLSL">;
18201824

18211825
} // end of Parser diagnostics

clang/lib/Parse/ParseDecl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4411,6 +4411,10 @@ void Parser::ParseDeclarationSpecifiers(
44114411
DiagID = diag::err_openclcxx_virtual_function;
44124412
PrevSpec = Tok.getIdentifierInfo()->getNameStart();
44134413
isInvalid = true;
4414+
} else if (getLangOpts().HLSL) {
4415+
DiagID = diag::err_hlsl_virtual_function;
4416+
PrevSpec = Tok.getIdentifierInfo()->getNameStart();
4417+
isInvalid = true;
44144418
} else {
44154419
isInvalid = DS.setFunctionSpecVirtual(Loc, PrevSpec, DiagID);
44164420
}

clang/lib/Parse/ParseDeclCXX.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2492,6 +2492,9 @@ BaseResult Parser::ParseBaseSpecifier(Decl *ClassDecl) {
24922492
IsVirtual = true;
24932493
}
24942494

2495+
if (getLangOpts().HLSL && IsVirtual)
2496+
Diag(Tok.getLocation(), diag::err_hlsl_virtual_inheritance);
2497+
24952498
CheckMisplacedCXX11Attribute(Attributes, StartLoc);
24962499

24972500
// Parse the class-name.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -verify %s
2+
3+
struct Base {
4+
int X;
5+
void MemberFunction(); // valid
6+
virtual void MemberFunction2(); // expected-error{{virtual functions are unsupported in HLSL}}
7+
};
8+
9+
struct Derived : virtual Base { // expected-error{{virtual inheritance is unsupported in HLSL}}
10+
int Y;
11+
12+
void MemberFunction2() override; // expected-error{{only virtual member functions can be marked 'override'}}
13+
};
14+

0 commit comments

Comments
 (0)