Skip to content

Commit 5fbf9f6

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 5f18e2b commit 5fbf9f6

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
@@ -13164,6 +13164,17 @@ static int ValidateAttributeIntArg(Sema &S, const AttributeList &Attr,
1316413164
if (E->isTypeDependent() || E->isValueDependent() ||
1316513165
!E->isCXX11ConstantExpr(S.Context, &ArgNum)) {
1316613166
displayError = true;
13167+
if (DeclRefExpr *D = dyn_cast<DeclRefExpr>(E)) {
13168+
if (auto *Var = llvm::dyn_cast<VarDecl>(D->getDecl())) {
13169+
if (const Expr *Init = Var->getAnyInitializer()) {
13170+
if (Init->isCXX11ConstantExpr(S.Context, &ArgNum) &&
13171+
ArgNum.isInt()) {
13172+
value = ArgNum.getInt().getSExtValue();
13173+
displayError = false;
13174+
}
13175+
}
13176+
}
13177+
}
1316713178
} else {
1316813179
if (ArgNum.isInt()) {
1316913180
value = ArgNum.getInt().getSExtValue();

0 commit comments

Comments
 (0)