Files
metal2vulkan/docs
Anees Iqbal 31b3470a3e Bitcode: read the pre-LLVM-4 metadata and typed-pointer records of AIR 1.8
A game launcher's metallib (AIR 1.8, language 1.1) parses since the container fix, but each
of its 7 functions stopped in the bitcode reader at METADATA_STRING_OLD. A structure-only census
of its 7 modules (job m3-max-73828) found six refused forms in all and nothing else unknown:
METADATA_STRING_OLD, METADATA_KIND inside the METADATA block, METADATA_OLD_NODE,
FUNC_INBOUNDS_GEP_OLD, LOAD without its type, and CALL without the explicit-type flag.

Each is now read as LLVM's reader reads it at llvmorg-23.1.2:

- STRING_OLD (MetadataLoader.cpp:2424-2433): one MDString of the operands as bytes, the next
  metadata id. Its llvm.vectorizer. loop-key upgrade (AutoUpgrade.cpp:6979-7026) renames keys
  the IR keeps in neither spelling, so the decoded loop hints are unchanged.
- KIND in the METADATA block (2457, parseMetadataKindRecord 2631-2643): the METADATA_KIND
  block's record. Both places now refuse a record with fewer than 2 operands and a kind id
  stated twice, as LLVM does.
- OLD_NODE (1401-1428): a uniqued node of (type, value) pairs. A metadata-typed operand is a
  metadata id, a void one is null, and any other is the module value of that type and id, as
  ValueAsMetadata. LLVM numbers no id for such a value; the arena keeps one Md::Value entry per
  value after the block's own ids, and MdIds moves every id LLVM numbers later (later module
  blocks, function blocks, attachments, call operands) past them.
- INBOUNDS_GEP_OLD (BitcodeReader.cpp:5383-5450), LOAD (6418-6436) and CALL (6886-6964)
  without their types: the source element, loaded or function type is the pointer operand's
  contained type. The reader follows LLVM's type ids (getContainedTypeID, 1510;
  getVirtualTypeID, 1532) for every value: TypeIds keeps the virtual ids for pointers made by
  alloca, GEP and the module's globals and functions, shuffles and cmpxchg; each instruction's
  result takes the id LLVM's reader gives it.

Still refused, by name: METADATA_OLD_FN_NODE; KIND and OLD_NODE in a function's block; an
OLD_NODE value in a module block after one whose old nodes kept values; a load atomic without
its type; GEP_OLD (not inbounds) and STORE_OLD. None is in the file. A typed-pointer load, call
or GEP whose operand has no contained type (an opaque pointer, a non-pointer) is BadType or a
malformed record.

Tests: typed_pointer_records_without_their_types_read_as_with_them decodes one typed-pointer
module in both spellings (a struct field, an array element, a loaded pointer, a cast, an
argument, and a function whose record names a pointer to its type) and asserts the tables are
equal, plus the refusals. legacy_metadata_records_read_as_their_modern_twins decodes the
function-test module with its metadata in the old records, asserts the body equals the modern
twin's, the arena's layout, and the shifted ids in a second module block and in a function
block, plus each refusal. Both fail without the fix: the old records were refused. The tests
that asserted those refusals now assert the remaining ones (OLD_FN_NODE).

docs/REFUSALS.md regenerated. Not yet run at this commit: the suite job follows.
2026-11-25 13:14:58 -08:00
..