[Bitcode] Encode alloca address space

Since D101045, allocas are no longer required to be part of the
default alloca address space. There may be allocas in multiple
different address spaces. However, the bitcode reader would
simply assume the default alloca address space, resulting in
either an error or incorrect IR.

Add an optional record for allocas which encodes the address
space.
This commit is contained in:
Nikita Popov
2022-03-11 16:06:02 +01:00
parent e61a1a9849
commit b190108693
3 changed files with 24 additions and 3 deletions

View File

@@ -5294,7 +5294,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
}
case bitc::FUNC_CODE_INST_ALLOCA: { // ALLOCA: [instty, opty, op, align]
if (Record.size() != 4)
if (Record.size() != 4 && Record.size() != 5)
return error("Invalid record");
using APV = AllocaPackedValues;
const uint64_t Rec = Record[3];
@@ -5321,9 +5321,8 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
if (!Ty || !Size)
return error("Invalid record");
// FIXME: Make this an optional field.
const DataLayout &DL = TheModule->getDataLayout();
unsigned AS = DL.getAllocaAddrSpace();
unsigned AS = Record.size() == 5 ? Record[4] : DL.getAllocaAddrSpace();
SmallPtrSet<Type *, 4> Visited;
if (!Align && !Ty->isSized(&Visited))