llvm.org GIT mirror llvm / 5fab610
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247952 91177308-0d34-0410-b5e6-96231b3b80d8 David Blaikie 5 years ago
3 changed file(s) with 47 addition(s) and 27 deletion(s). Raw diff Collapse all Expand all
6868 MODULE_CODE_FUNCTION = 8,
6969
7070 // ALIAS: [alias type, aliasee val#, linkage, visibility]
71 MODULE_CODE_ALIAS = 9,
71 MODULE_CODE_ALIAS_OLD = 9,
7272
7373 // MODULE_CODE_PURGEVALS: [numvals]
7474 MODULE_CODE_PURGEVALS = 10,
7777 MODULE_CODE_COMDAT = 12, // COMDAT: [selection_kind, name]
7878
7979 MODULE_CODE_VSTOFFSET = 13, // VSTOFFSET: [offset]
80
81 // ALIAS: [alias value type, addrspace, aliasee val#, linkage, visibility]
82 MODULE_CODE_ALIAS = 14,
8083 };
8184
8285 /// PARAMATTR blocks have code for defining a parameter attribute set.
30283028
30293029
30303030 // Read a record.
3031 switch (Stream.readRecord(Entry.ID, Record)) {
3031 auto BitCode = Stream.readRecord(Entry.ID, Record);
3032 switch (BitCode) {
30323033 default: break; // Default behavior, ignore unknown content.
30333034 case bitc::MODULE_CODE_VERSION: { // VERSION: [version#]
30343035 if (Record.size() < 1)
32673268 }
32683269 break;
32693270 }
3270 // ALIAS: [alias type, aliasee val#, linkage]
3271 // ALIAS: [alias type, aliasee val#, linkage, visibility, dllstorageclass]
3272 case bitc::MODULE_CODE_ALIAS: {
3273 if (Record.size() < 3)
3274 return error("Invalid record");
3275 Type *Ty = getTypeByID(Record[0]);
3271 // ALIAS: [alias type, addrspace, aliasee val#, linkage]
3272 // ALIAS: [alias type, addrspace, aliasee val#, linkage, visibility, dllstorageclass]
3273 case bitc::MODULE_CODE_ALIAS:
3274 case bitc::MODULE_CODE_ALIAS_OLD: {
3275 bool NewRecord = BitCode == bitc::MODULE_CODE_ALIAS;
3276 if (Record.size() < (3 + NewRecord))
3277 return error("Invalid record");
3278 unsigned OpNum = 0;
3279 Type *Ty = getTypeByID(Record[OpNum++]);
32763280 if (!Ty)
32773281 return error("Invalid record");
3278 auto *PTy = dyn_cast(Ty);
3279 if (!PTy)
3280 return error("Invalid type for value");
3281
3282 auto *NewGA =
3283 GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
3284 getDecodedLinkage(Record[2]), "", TheModule);
3282
3283 unsigned AddrSpace;
3284 if (!NewRecord) {
3285 auto *PTy = dyn_cast(Ty);
3286 if (!PTy)
3287 return error("Invalid type for value");
3288 Ty = PTy->getElementType();
3289 AddrSpace = PTy->getAddressSpace();
3290 } else {
3291 AddrSpace = Record[OpNum++];
3292 }
3293
3294 auto Val = Record[OpNum++];
3295 auto Linkage = Record[OpNum++];
3296 auto *NewGA = GlobalAlias::create(
3297 Ty, AddrSpace, getDecodedLinkage(Linkage), "", TheModule);
32853298 // Old bitcode files didn't have visibility field.
32863299 // Local linkage must have default visibility.
3287 if (Record.size() > 3 && !NewGA->hasLocalLinkage())
3288 // FIXME: Change to an error if non-default in 4.0.
3289 NewGA->setVisibility(getDecodedVisibility(Record[3]));
3290 if (Record.size() > 4)
3291 NewGA->setDLLStorageClass(getDecodedDLLStorageClass(Record[4]));
3300 if (OpNum != Record.size()) {
3301 auto VisInd = OpNum++;
3302 if (!NewGA->hasLocalLinkage())
3303 // FIXME: Change to an error if non-default in 4.0.
3304 NewGA->setVisibility(getDecodedVisibility(Record[VisInd]));
3305 }
3306 if (OpNum != Record.size())
3307 NewGA->setDLLStorageClass(getDecodedDLLStorageClass(Record[OpNum++]));
32923308 else
3293 upgradeDLLImportExportLinkage(NewGA, Record[2]);
3294 if (Record.size() > 5)
3295 NewGA->setThreadLocalMode(getDecodedThreadLocalMode(Record[5]));
3296 if (Record.size() > 6)
3297 NewGA->setUnnamedAddr(Record[6]);
3309 upgradeDLLImportExportLinkage(NewGA, Linkage);
3310 if (OpNum != Record.size())
3311 NewGA->setThreadLocalMode(getDecodedThreadLocalMode(Record[OpNum++]));
3312 if (OpNum != Record.size())
3313 NewGA->setUnnamedAddr(Record[OpNum++]);
32983314 ValueList.push_back(NewGA);
3299 AliasInits.push_back(std::make_pair(NewGA, Record[1]));
3315 AliasInits.push_back(std::make_pair(NewGA, Val));
33003316 break;
33013317 }
33023318 /// MODULE_CODE_PURGEVALS: [numvals]
755755 // Emit the alias information.
756756 for (const GlobalAlias &A : M->aliases()) {
757757 // ALIAS: [alias type, aliasee val#, linkage, visibility]
758 Vals.push_back(VE.getTypeID(A.getType()));
758 Vals.push_back(VE.getTypeID(A.getValueType()));
759 Vals.push_back(A.getType()->getAddressSpace());
759760 Vals.push_back(VE.getValueID(A.getAliasee()));
760761 Vals.push_back(getEncodedLinkage(A));
761762 Vals.push_back(getEncodedVisibility(A));