SPIR-V: Return undefined values from implicit returns instead of dummy

Previously if a non-void function implictly returned, a dummy variable
was created as return value. Now instead it returns the result of the
OpUndef instruction. This better conveys the presence of undefined
behavior to SPIR-V consuming tools (and humans).

It also saves one ID per occurrence...
This commit is contained in:
Miro Knejp
2015-08-11 02:45:24 +02:00
parent 65c78a0b62
commit 28f9b1c28d
4 changed files with 77 additions and 74 deletions

View File

@@ -791,9 +791,7 @@ void Builder::leaveFunction(bool main)
if (function.getReturnType() == makeVoidType())
makeReturn(true);
else {
Id retStorage = createVariable(StorageClassFunction, function.getReturnType(), "dummyReturn");
Id retValue = createLoad(retStorage);
makeReturn(true, retValue);
makeReturn(true, createUndefined(function.getReturnType()));
}
}
}
@@ -844,6 +842,14 @@ Id Builder::createVariable(StorageClass storageClass, Id type, const char* name)
return inst->getResultId();
}
// Comments in header
Id Builder::createUndefined(Id type)
{
Instruction* inst = new Instruction(getUniqueId(), type, OpUndef);
buildPoint->addInstruction(inst);
return inst->getResultId();
}
// Comments in header
void Builder::createStore(Id rValue, Id lValue)
{