| 1245 | } |
| 1246 | |
| 1247 | Error BitcodeReader::parseAttributeBlock() { |
| 1248 | if (Stream.EnterSubBlock(bitc::PARAMATTR_BLOCK_ID)) |
| 1249 | return error("Invalid record"); |
| 1250 | |
| 1251 | if (!MAttributes.empty()) |
| 1252 | return error("Invalid multiple blocks"); |
| 1253 | |
| 1254 | SmallVector<uint64_t, 64> Record; |
| 1255 | |
| 1256 | SmallVector<AttributeList, 8> Attrs; |
| 1257 | |
| 1258 | // Read all the records. |
| 1259 | while (true) { |
| 1260 | BitstreamEntry Entry = Stream.advanceSkippingSubblocks(); |
| 1261 | |
| 1262 | switch (Entry.Kind) { |
| 1263 | case BitstreamEntry::SubBlock: // Handled for us already. |
| 1264 | case BitstreamEntry::Error: |
| 1265 | return error("Malformed block"); |
| 1266 | case BitstreamEntry::EndBlock: |
| 1267 | return Error::success(); |
| 1268 | case BitstreamEntry::Record: |
| 1269 | // The interesting case. |
| 1270 | break; |
| 1271 | } |
| 1272 | |
| 1273 | // Read a record. |
| 1274 | Record.clear(); |
| 1275 | switch (Stream.readRecord(Entry.ID, Record)) { |
| 1276 | default: // Default behavior: ignore. |
| 1277 | break; |
| 1278 | case bitc::PARAMATTR_CODE_ENTRY_OLD: // ENTRY: [paramidx0, attr0, ...] |
| 1279 | // FIXME: Remove in 4.0. |
| 1280 | if (Record.size() & 1) |
| 1281 | return error("Invalid record"); |
| 1282 | |
| 1283 | for (unsigned i = 0, e = Record.size(); i != e; i += 2) { |
| 1284 | AttrBuilder B; |
| 1285 | decodeLLVMAttributesForBitcode(B, Record[i+1]); |
| 1286 | Attrs.push_back(AttributeList::get(Context, Record[i], B)); |
| 1287 | } |
| 1288 | |
| 1289 | MAttributes.push_back(AttributeList::get(Context, Attrs)); |
| 1290 | Attrs.clear(); |
| 1291 | break; |
| 1292 | case bitc::PARAMATTR_CODE_ENTRY: // ENTRY: [attrgrp0, attrgrp1, ...] |
| 1293 | for (unsigned i = 0, e = Record.size(); i != e; ++i) |
| 1294 | Attrs.push_back(MAttributeGroups[Record[i]]); |
| 1295 | |
| 1296 | MAttributes.push_back(AttributeList::get(Context, Attrs)); |
| 1297 | Attrs.clear(); |
| 1298 | break; |
| 1299 | } |
| 1300 | } |
| 1301 | } |
| 1302 | |
| 1303 | // Returns Attribute::None on unrecognized codes. |
| 1304 | static Attribute::AttrKind getAttrFromCode(uint64_t Code) { |
nothing calls this directly
no test coverage detected