forked from OSchip/llvm-project
[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:
parent
bf19a11116
commit
6a51dbdb3c
|
@ -69,7 +69,7 @@ namespace bitc {
|
||||||
MODULE_CODE_FUNCTION = 8,
|
MODULE_CODE_FUNCTION = 8,
|
||||||
|
|
||||||
// ALIAS: [alias type, aliasee val#, linkage, visibility]
|
// ALIAS: [alias type, aliasee val#, linkage, visibility]
|
||||||
MODULE_CODE_ALIAS = 9,
|
MODULE_CODE_ALIAS_OLD = 9,
|
||||||
|
|
||||||
// MODULE_CODE_PURGEVALS: [numvals]
|
// MODULE_CODE_PURGEVALS: [numvals]
|
||||||
MODULE_CODE_PURGEVALS = 10,
|
MODULE_CODE_PURGEVALS = 10,
|
||||||
|
@ -78,6 +78,9 @@ namespace bitc {
|
||||||
MODULE_CODE_COMDAT = 12, // COMDAT: [selection_kind, name]
|
MODULE_CODE_COMDAT = 12, // COMDAT: [selection_kind, name]
|
||||||
|
|
||||||
MODULE_CODE_VSTOFFSET = 13, // VSTOFFSET: [offset]
|
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.
|
/// PARAMATTR blocks have code for defining a parameter attribute set.
|
||||||
|
|
|
@ -3029,7 +3029,8 @@ std::error_code BitcodeReader::parseModule(bool Resume,
|
||||||
|
|
||||||
|
|
||||||
// Read a record.
|
// 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.
|
default: break; // Default behavior, ignore unknown content.
|
||||||
case bitc::MODULE_CODE_VERSION: { // VERSION: [version#]
|
case bitc::MODULE_CODE_VERSION: { // VERSION: [version#]
|
||||||
if (Record.size() < 1)
|
if (Record.size() < 1)
|
||||||
|
@ -3268,36 +3269,51 @@ std::error_code BitcodeReader::parseModule(bool Resume,
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// ALIAS: [alias type, aliasee val#, linkage]
|
// ALIAS: [alias type, addrspace, aliasee val#, linkage]
|
||||||
// ALIAS: [alias type, aliasee val#, linkage, visibility, dllstorageclass]
|
// ALIAS: [alias type, addrspace, aliasee val#, linkage, visibility, dllstorageclass]
|
||||||
case bitc::MODULE_CODE_ALIAS: {
|
case bitc::MODULE_CODE_ALIAS:
|
||||||
if (Record.size() < 3)
|
case bitc::MODULE_CODE_ALIAS_OLD: {
|
||||||
|
bool NewRecord = BitCode == bitc::MODULE_CODE_ALIAS;
|
||||||
|
if (Record.size() < (3 + NewRecord))
|
||||||
return error("Invalid record");
|
return error("Invalid record");
|
||||||
Type *Ty = getTypeByID(Record[0]);
|
unsigned OpNum = 0;
|
||||||
|
Type *Ty = getTypeByID(Record[OpNum++]);
|
||||||
if (!Ty)
|
if (!Ty)
|
||||||
return error("Invalid record");
|
return error("Invalid record");
|
||||||
auto *PTy = dyn_cast<PointerType>(Ty);
|
|
||||||
if (!PTy)
|
|
||||||
return error("Invalid type for value");
|
|
||||||
|
|
||||||
auto *NewGA =
|
unsigned AddrSpace;
|
||||||
GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
|
if (!NewRecord) {
|
||||||
getDecodedLinkage(Record[2]), "", TheModule);
|
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.
|
// Old bitcode files didn't have visibility field.
|
||||||
// Local linkage must have default visibility.
|
// Local linkage must have default visibility.
|
||||||
if (Record.size() > 3 && !NewGA->hasLocalLinkage())
|
if (OpNum != Record.size()) {
|
||||||
// FIXME: Change to an error if non-default in 4.0.
|
auto VisInd = OpNum++;
|
||||||
NewGA->setVisibility(getDecodedVisibility(Record[3]));
|
if (!NewGA->hasLocalLinkage())
|
||||||
if (Record.size() > 4)
|
// FIXME: Change to an error if non-default in 4.0.
|
||||||
NewGA->setDLLStorageClass(getDecodedDLLStorageClass(Record[4]));
|
NewGA->setVisibility(getDecodedVisibility(Record[VisInd]));
|
||||||
|
}
|
||||||
|
if (OpNum != Record.size())
|
||||||
|
NewGA->setDLLStorageClass(getDecodedDLLStorageClass(Record[OpNum++]));
|
||||||
else
|
else
|
||||||
upgradeDLLImportExportLinkage(NewGA, Record[2]);
|
upgradeDLLImportExportLinkage(NewGA, Linkage);
|
||||||
if (Record.size() > 5)
|
if (OpNum != Record.size())
|
||||||
NewGA->setThreadLocalMode(getDecodedThreadLocalMode(Record[5]));
|
NewGA->setThreadLocalMode(getDecodedThreadLocalMode(Record[OpNum++]));
|
||||||
if (Record.size() > 6)
|
if (OpNum != Record.size())
|
||||||
NewGA->setUnnamedAddr(Record[6]);
|
NewGA->setUnnamedAddr(Record[OpNum++]);
|
||||||
ValueList.push_back(NewGA);
|
ValueList.push_back(NewGA);
|
||||||
AliasInits.push_back(std::make_pair(NewGA, Record[1]));
|
AliasInits.push_back(std::make_pair(NewGA, Val));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/// MODULE_CODE_PURGEVALS: [numvals]
|
/// MODULE_CODE_PURGEVALS: [numvals]
|
||||||
|
|
|
@ -756,7 +756,8 @@ static uint64_t WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
|
||||||
// Emit the alias information.
|
// Emit the alias information.
|
||||||
for (const GlobalAlias &A : M->aliases()) {
|
for (const GlobalAlias &A : M->aliases()) {
|
||||||
// ALIAS: [alias type, aliasee val#, linkage, visibility]
|
// 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(VE.getValueID(A.getAliasee()));
|
||||||
Vals.push_back(getEncodedLinkage(A));
|
Vals.push_back(getEncodedLinkage(A));
|
||||||
Vals.push_back(getEncodedVisibility(A));
|
Vals.push_back(getEncodedVisibility(A));
|
||||||
|
|
Loading…
Reference in New Issue