reader/spirv: Don't create detatched AST nodes

EmitControlBarrier() was calling MakeOperand() to create ast::Expressions that held a ScalarConstructorExpression, which held a IntLiteral.
The literal value was then taken, and the rest was discarded.

Detached AST nodes will become an ICE, so do the work to find the literal value.

Bug: tint:469
Change-Id: I522bfe8db84e853e189c714b18598feb0d49e58b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48049
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
Ben Clayton 2021-04-17 06:01:41 +00:00 committed by Commit Bot service account
parent 169512e499
commit f32719ff85
1 changed files with 5 additions and 7 deletions

View File

@ -4201,14 +4201,12 @@ bool FunctionEmitter::EmitControlBarrier(
const spvtools::opt::Instruction& inst) {
uint32_t operands[3];
for (int i = 0; i < 3; i++) {
if (auto* op = MakeOperand(inst, i).expr) {
auto* lit = As<ast::ScalarConstructorExpression>(op)->literal();
if (auto* int_lit = lit->As<ast::IntLiteral>()) {
operands[i] = int_lit->value_as_u32();
continue;
}
auto id = inst.GetSingleWordInOperand(i);
if (auto* constant = constant_mgr_->FindDeclaredConstant(id)) {
operands[i] = constant->GetU32();
} else {
return Fail() << "invalid or missing operands for control barrier";
}
return Fail() << "invalid or missing operands for control barrier";
}
uint32_t execution = operands[0];