[SPIRV] Fix crash when returning void (#4576)
* [SPIRV] Fix crash when returning void This fixes a bug where invalid SPIR-V would be emitted when returning a void value from a void function. According to the spec, the `Value` of `OpReturnValue` must not have type `OpTypeVoid`; therefore, `OpReturn` will now be emitted instead. Fixes #3596 * assert instead of branch
This commit is contained in:
Родитель
7a45cbbf8b
Коммит
9ce4a5317c
|
@ -2273,7 +2273,10 @@ void SpirvEmitter::doIfStmt(const IfStmt *ifStmt,
|
|||
}
|
||||
|
||||
void SpirvEmitter::doReturnStmt(const ReturnStmt *stmt) {
|
||||
if (const auto *retVal = stmt->getRetValue()) {
|
||||
const auto *retVal = stmt->getRetValue();
|
||||
bool returnsVoid = curFunction->getReturnType().getTypePtr()->isVoidType();
|
||||
if (!returnsVoid) {
|
||||
assert(retVal);
|
||||
// Update counter variable associated with function returns
|
||||
tryToAssignCounterVar(curFunction, retVal);
|
||||
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
// RUN: %dxc -T ps_6_0 -E main
|
||||
|
||||
void A() {
|
||||
}
|
||||
|
||||
void main() {
|
||||
// CHECK: OpReturn
|
||||
return A();
|
||||
}
|
|
@ -582,6 +582,7 @@ TEST_F(FileTest, ReturnFromDifferentStorageClass) {
|
|||
TEST_F(FileTest, ReturnFromDifferentMemoryLayout) {
|
||||
runFileTest("cf.return.memory-layout.hlsl");
|
||||
}
|
||||
TEST_F(FileTest, VoidReturn) { runFileTest("cf.return.void.hlsl"); }
|
||||
|
||||
// For control flows
|
||||
TEST_F(FileTest, ControlFlowNestedIfForStmt) { runFileTest("cf.if.for.hlsl"); }
|
||||
|
|
Загрузка…
Ссылка в новой задаче