@@ -3029,7 +3029,8 @@ std::error_code BitcodeReader::parseModule(bool Resume,
3029
3029
3030
3030
3031
3031
// Read a record.
3032
- switch (Stream.readRecord (Entry.ID , Record)) {
3032
+ auto BitCode = Stream.readRecord (Entry.ID , Record);
3033
+ switch (BitCode) {
3033
3034
default : break ; // Default behavior, ignore unknown content.
3034
3035
case bitc::MODULE_CODE_VERSION: { // VERSION: [version#]
3035
3036
if (Record.size () < 1 )
@@ -3268,36 +3269,51 @@ std::error_code BitcodeReader::parseModule(bool Resume,
3268
3269
}
3269
3270
break ;
3270
3271
}
3271
- // ALIAS: [alias type, aliasee val#, linkage]
3272
- // ALIAS: [alias type, aliasee val#, linkage, visibility, dllstorageclass]
3273
- case bitc::MODULE_CODE_ALIAS: {
3274
- if (Record.size () < 3 )
3272
+ // ALIAS: [alias type, addrspace, aliasee val#, linkage]
3273
+ // ALIAS: [alias type, addrspace, aliasee val#, linkage, visibility, dllstorageclass]
3274
+ case bitc::MODULE_CODE_ALIAS:
3275
+ case bitc::MODULE_CODE_ALIAS_OLD: {
3276
+ bool NewRecord = BitCode == bitc::MODULE_CODE_ALIAS;
3277
+ if (Record.size () < (3 + NewRecord))
3275
3278
return error (" Invalid record" );
3276
- Type *Ty = getTypeByID (Record[0 ]);
3279
+ unsigned OpNum = 0 ;
3280
+ Type *Ty = getTypeByID (Record[OpNum++]);
3277
3281
if (!Ty)
3278
3282
return error (" Invalid record" );
3279
- auto *PTy = dyn_cast<PointerType>(Ty);
3280
- if (!PTy)
3281
- return error (" Invalid type for value" );
3282
3283
3283
- auto *NewGA =
3284
- GlobalAlias::create (PTy->getElementType (), PTy->getAddressSpace (),
3285
- getDecodedLinkage (Record[2 ]), " " , TheModule);
3284
+ unsigned AddrSpace;
3285
+ if (!NewRecord) {
3286
+ auto *PTy = dyn_cast<PointerType>(Ty);
3287
+ if (!PTy)
3288
+ return error (" Invalid type for value" );
3289
+ Ty = PTy->getElementType ();
3290
+ AddrSpace = PTy->getAddressSpace ();
3291
+ } else {
3292
+ AddrSpace = Record[OpNum++];
3293
+ }
3294
+
3295
+ auto Val = Record[OpNum++];
3296
+ auto Linkage = Record[OpNum++];
3297
+ auto *NewGA = GlobalAlias::create (
3298
+ Ty, AddrSpace, getDecodedLinkage (Linkage), " " , TheModule);
3286
3299
// Old bitcode files didn't have visibility field.
3287
3300
// Local linkage must have default visibility.
3288
- if (Record.size () > 3 && !NewGA->hasLocalLinkage ())
3289
- // FIXME: Change to an error if non-default in 4.0.
3290
- NewGA->setVisibility (getDecodedVisibility (Record[3 ]));
3291
- if (Record.size () > 4 )
3292
- NewGA->setDLLStorageClass (getDecodedDLLStorageClass (Record[4 ]));
3301
+ if (OpNum != Record.size ()) {
3302
+ auto VisInd = OpNum++;
3303
+ if (!NewGA->hasLocalLinkage ())
3304
+ // FIXME: Change to an error if non-default in 4.0.
3305
+ NewGA->setVisibility (getDecodedVisibility (Record[VisInd]));
3306
+ }
3307
+ if (OpNum != Record.size ())
3308
+ NewGA->setDLLStorageClass (getDecodedDLLStorageClass (Record[OpNum++]));
3293
3309
else
3294
- upgradeDLLImportExportLinkage (NewGA, Record[ 2 ] );
3295
- if (Record.size () > 5 )
3296
- NewGA->setThreadLocalMode (getDecodedThreadLocalMode (Record[5 ]));
3297
- if (Record.size () > 6 )
3298
- NewGA->setUnnamedAddr (Record[6 ]);
3310
+ upgradeDLLImportExportLinkage (NewGA, Linkage );
3311
+ if (OpNum != Record.size ())
3312
+ NewGA->setThreadLocalMode (getDecodedThreadLocalMode (Record[OpNum++ ]));
3313
+ if (OpNum != Record.size ())
3314
+ NewGA->setUnnamedAddr (Record[OpNum++ ]);
3299
3315
ValueList.push_back (NewGA);
3300
- AliasInits.push_back (std::make_pair (NewGA, Record[ 1 ] ));
3316
+ AliasInits.push_back (std::make_pair (NewGA, Val ));
3301
3317
break ;
3302
3318
}
3303
3319
// / MODULE_CODE_PURGEVALS: [numvals]
0 commit comments