Skip to content

Commit ffc174c

Browse files
Tim Corringhamdanbrown-amd
Tim Corringham
authored andcommitted
Allow const vars in attribute parameters
HLSL does not allow const vars to be evaluated in integer constant expressions - this change relaxes this restriction in the case of attribute integer parameter values. Specifically, a const var with integer constant expression initializer is accepted, and the value of the initializer is used as the value of the attribute parameter. This (expermental) behavior may be useful in cases where Vulkan specialization constants are used as an attribute parameter value.
1 parent 377c4ca commit ffc174c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

tools/clang/lib/Sema/SemaHLSL.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13213,6 +13213,17 @@ static int ValidateAttributeIntArg(Sema &S, const AttributeList &Attr,
1321313213
if (E->isTypeDependent() || E->isValueDependent() ||
1321413214
!E->isCXX11ConstantExpr(S.Context, &ArgNum)) {
1321513215
displayError = true;
13216+
if (DeclRefExpr *D = dyn_cast<DeclRefExpr>(E)) {
13217+
if (auto *Var = llvm::dyn_cast<VarDecl>(D->getDecl())) {
13218+
if (const Expr *Init = Var->getAnyInitializer()) {
13219+
if (Init->isCXX11ConstantExpr(S.Context, &ArgNum) &&
13220+
ArgNum.isInt()) {
13221+
value = ArgNum.getInt().getSExtValue();
13222+
displayError = false;
13223+
}
13224+
}
13225+
}
13226+
}
1321613227
} else {
1321713228
if (ArgNum.isInt()) {
1321813229
value = ArgNum.getInt().getSExtValue();

0 commit comments

Comments
 (0)