Skip to content

Commit e62dc4b

Browse files
committed
[HLSL] Disallow virtual inheritance and functions
This PR disallows virtual inheritance and virtual functions in HLSL.
1 parent 50581ef commit e62dc4b

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,5 +1817,7 @@ 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 : Error<"virtual functions are unsupported in HLSL">;
1821+
def err_hlsl_virtual_inheritance : Error<"virtual inheritance is unsupported in HLSL">;
18201822

18211823
} // end of Parser diagnostics

clang/lib/Parse/ParseDecl.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4411,7 +4411,12 @@ void Parser::ParseDeclarationSpecifiers(
44114411
DiagID = diag::err_openclcxx_virtual_function;
44124412
PrevSpec = Tok.getIdentifierInfo()->getNameStart();
44134413
isInvalid = true;
4414-
} else {
4414+
} else if (getLangOpts().HLSL) {
4415+
DiagID = diag::err_hlsl_virtual_function;
4416+
PrevSpec = Tok.getIdentifierInfo()->getNameStart();
4417+
isInvalid = true;
4418+
}
4419+
else {
44154420
isInvalid = DS.setFunctionSpecVirtual(Loc, PrevSpec, DiagID);
44164421
}
44174422
break;

clang/lib/Parse/ParseDeclCXX.cpp

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

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

24962499
// 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)