1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

[opaque pointer types] Add an explicit pointee type to alias records in the IR

Since aliases actually use and verify their explicit type already, no
further invalid testing is required here. The
invalid.test:ALIAS-TYPE-MISMATCH case catches errors due to emitting a
non-pointee type in the new format or a non-pointer type in the old
format.

llvm-svn: 247952
This commit is contained in:
David Blaikie 2015-09-17 22:18:59 +00:00
parent 4af994c35b
commit adec03e01e
3 changed files with 45 additions and 25 deletions

View File

@ -69,7 +69,7 @@ namespace bitc {
MODULE_CODE_FUNCTION = 8,
// ALIAS: [alias type, aliasee val#, linkage, visibility]
MODULE_CODE_ALIAS = 9,
MODULE_CODE_ALIAS_OLD = 9,
// MODULE_CODE_PURGEVALS: [numvals]
MODULE_CODE_PURGEVALS = 10,
@ -78,6 +78,9 @@ namespace bitc {
MODULE_CODE_COMDAT = 12, // COMDAT: [selection_kind, name]
MODULE_CODE_VSTOFFSET = 13, // VSTOFFSET: [offset]
// ALIAS: [alias value type, addrspace, aliasee val#, linkage, visibility]
MODULE_CODE_ALIAS = 14,
};
/// PARAMATTR blocks have code for defining a parameter attribute set.

View File

@ -3029,7 +3029,8 @@ std::error_code BitcodeReader::parseModule(bool Resume,
// Read a record.
switch (Stream.readRecord(Entry.ID, Record)) {
auto BitCode = Stream.readRecord(Entry.ID, Record);
switch (BitCode) {
default: break; // Default behavior, ignore unknown content.
case bitc::MODULE_CODE_VERSION: { // VERSION: [version#]
if (Record.size() < 1)
@ -3268,36 +3269,51 @@ std::error_code BitcodeReader::parseModule(bool Resume,
}
break;
}
// ALIAS: [alias type, aliasee val#, linkage]
// ALIAS: [alias type, aliasee val#, linkage, visibility, dllstorageclass]
case bitc::MODULE_CODE_ALIAS: {
if (Record.size() < 3)
// ALIAS: [alias type, addrspace, aliasee val#, linkage]
// ALIAS: [alias type, addrspace, aliasee val#, linkage, visibility, dllstorageclass]
case bitc::MODULE_CODE_ALIAS:
case bitc::MODULE_CODE_ALIAS_OLD: {
bool NewRecord = BitCode == bitc::MODULE_CODE_ALIAS;
if (Record.size() < (3 + NewRecord))
return error("Invalid record");
Type *Ty = getTypeByID(Record[0]);
unsigned OpNum = 0;
Type *Ty = getTypeByID(Record[OpNum++]);
if (!Ty)
return error("Invalid record");
auto *PTy = dyn_cast<PointerType>(Ty);
if (!PTy)
return error("Invalid type for value");
auto *NewGA =
GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
getDecodedLinkage(Record[2]), "", TheModule);
unsigned AddrSpace;
if (!NewRecord) {
auto *PTy = dyn_cast<PointerType>(Ty);
if (!PTy)
return error("Invalid type for value");
Ty = PTy->getElementType();
AddrSpace = PTy->getAddressSpace();
} else {
AddrSpace = Record[OpNum++];
}
auto Val = Record[OpNum++];
auto Linkage = Record[OpNum++];
auto *NewGA = GlobalAlias::create(
Ty, AddrSpace, getDecodedLinkage(Linkage), "", TheModule);
// Old bitcode files didn't have visibility field.
// Local linkage must have default visibility.
if (Record.size() > 3 && !NewGA->hasLocalLinkage())
// FIXME: Change to an error if non-default in 4.0.
NewGA->setVisibility(getDecodedVisibility(Record[3]));
if (Record.size() > 4)
NewGA->setDLLStorageClass(getDecodedDLLStorageClass(Record[4]));
if (OpNum != Record.size()) {
auto VisInd = OpNum++;
if (!NewGA->hasLocalLinkage())
// FIXME: Change to an error if non-default in 4.0.
NewGA->setVisibility(getDecodedVisibility(Record[VisInd]));
}
if (OpNum != Record.size())
NewGA->setDLLStorageClass(getDecodedDLLStorageClass(Record[OpNum++]));
else
upgradeDLLImportExportLinkage(NewGA, Record[2]);
if (Record.size() > 5)
NewGA->setThreadLocalMode(getDecodedThreadLocalMode(Record[5]));
if (Record.size() > 6)
NewGA->setUnnamedAddr(Record[6]);
upgradeDLLImportExportLinkage(NewGA, Linkage);
if (OpNum != Record.size())
NewGA->setThreadLocalMode(getDecodedThreadLocalMode(Record[OpNum++]));
if (OpNum != Record.size())
NewGA->setUnnamedAddr(Record[OpNum++]);
ValueList.push_back(NewGA);
AliasInits.push_back(std::make_pair(NewGA, Record[1]));
AliasInits.push_back(std::make_pair(NewGA, Val));
break;
}
/// MODULE_CODE_PURGEVALS: [numvals]

View File

@ -756,7 +756,8 @@ static uint64_t WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
// Emit the alias information.
for (const GlobalAlias &A : M->aliases()) {
// ALIAS: [alias type, aliasee val#, linkage, visibility]
Vals.push_back(VE.getTypeID(A.getType()));
Vals.push_back(VE.getTypeID(A.getValueType()));
Vals.push_back(A.getType()->getAddressSpace());
Vals.push_back(VE.getValueID(A.getAliasee()));
Vals.push_back(getEncodedLinkage(A));
Vals.push_back(getEncodedVisibility(A));