A CONSTANTS_BLOCK (block 11) appears once at module level and once inside each
function body that has constants of its own. This page gives every record as
BitcodeReader::parseConstants reads it (BitcodeReader.cpp, lines
3363–3946) and as the writer emits it (writeConstants, BitcodeWriter.cpp
lines 2950–3213). The record codes and the cast, binary-operator, GEP and predicate
tables are on functions and constants.
How the block works
- Current type. The block keeps a current type, which is
i32when the block starts. ASETTYPErecord changes it; every other record makes one constant of the current type. The writer emits a SETTYPE whenever the type of the next constant differs from the last. - Numbering. Each constant takes the next value ID, continuing from the
values already numbered (the module’s global values, or, in a function, the module
values and the arguments). The block must define exactly the IDs that earlier records
expected; if the next number does not match the size of the value list at the end,
the reader reports
Invalid constant reference. - Operands are absolute. Value operands in constants are value IDs counted from the start of the value list, not relative to the constant, and may refer forward to a constant that comes later (the reader resolves these after the block). Type operands are type IDs.
- Unknown codes. A record code the reader does not know is read as
UNDEF: it makes anundefof the current type and keeps the numbering right (defaultshares the UNDEF case, line 3403). - Signed values. Integer operands use the sign-rotated form: a
non-negative value is shifted left one bit; a negative value is negated, shifted left
one bit and has the low bit set; the single value 1 stands for the minimum 64-bit
integer (
decodeSignRotatedValue, line 3259). - A sub-block or a stream error in the block is
Malformed block.
Records
The operand lists below are the reader’s. Fewer operands than it needs gives the error named in the last column. If the current type is wrong for the record, the same message applies. A value operand is a value ID; type is a type ID.
| Code | Record | Operands | Meaning and the reader’s checks |
|---|---|---|---|
1 | SETTYPE | [type] | Sets the current type. Empty, an unknown ID or an unset slot: Invalid settype record; void: Invalid constant type. Makes no constant. |
2 | NULL | — | The all-zero value of the current type (zeroinitializer, null, 0). Not allowed for void, function or label types, or for a target extension type without zero initialisation: Invalid type for a constant null value. |
3 | UNDEF | — | undef of the current type. |
4 | INTEGER | [value] | A sign-rotated integer (at most 64 bits) of the current integer or integer-vector type. Otherwise Invalid integer const record. A vector type means a splat of the value. |
5 | WIDE_INTEGER | [word…] | An integer wider than 64 bits as 64-bit words, least significant first, each sign-rotated. Invalid wide integer const record if the type is not an integer or the record is empty. The writer gives only the words in use. |
6 | FLOAT | [bits] (two for the wide types) | The bit pattern. half and bfloat: the low 16 bits; float: the low 32; double: all 64. x86_fp80: two operands, [the high 64 bits of the 80-bit value, the low 16 bits] (reader line 3478: (Record[1] & 0xffff) | (Record[0] << 16)). fp128 and ppc_fp128: [low 64 bits, high 64 bits]. A current type that is not a floating-point type gives poison. Empty: Invalid float const record. |
7 | AGGREGATE | [value…] | A structure, array or vector with the given element constants. Empty: Invalid aggregate record. Any other current type gives poison. |
8 | STRING | [byte…] | An array of bytes (or of b8 bytes, when the element type is a byte). Empty: Invalid string record. The current type must be an array type. |
9 | CSTRING | [byte…] | The same, with a zero byte added at the end; the writer uses it when the last element is 0 and leaves that byte out. |
10 | CE_BINOP | [opcode, lhs, rhs] or [opcode, lhs, rhs, flags] | A binary operator on two constants. The opcode is a binary opcode; an unknown one, or one for the wrong kind of type, gives poison. Flags: for add, sub, mul, shl bit 0 no unsigned wrap and bit 1 no signed wrap; for sdiv, udiv, lshr, ashr bit 0 exact. Fewer than 3 operands: Invalid binary op constexpr record. |
11 | CE_CAST | [opcode, type, value] | A cast of value (of type) to the current type. The opcode is a cast opcode; unknown: poison. Invalid cast constexpr record if fewer than 3 operands or the type is unknown. |
12 | CE_GEP_OLD | [type?, (type, value)…] | A getelementptr. See GEP records. |
13 | CE_SELECT | [cond, true, false] | Three values. Invalid select constexpr record if fewer. |
14 | CE_EXTRACTELT | [vector type, vector, index type, index] | The older form has 3 operands [vector type, vector, index]. The type must be a vector (Invalid extractelement constexpr record). |
15 | CE_INSERTELT | [vector, element, index type, index] | The older form has 3 operands, without the index type. The current type must be a vector (Invalid insertelement constexpr record). |
16 | CE_SHUFFLEVEC | [vector 1, vector 2, mask] | The current type must be a vector (Invalid shufflevector constexpr record). |
17 | CE_CMP | [operand type, lhs, rhs, predicate] | fcmp when the operand type is floating-point, else icmp; the predicate is the predicate number. Fewer than 4 operands: Invalid cmp constexpt record (the reader’s spelling). |
18 | INLINEASM_OLD | [flags, asm length, asm byte…, constraint length, constraint byte…] | See inline assembly. |
19 | CE_SHUFVEC_EX | [operand type, vector 1, vector 2, mask] | A shuffle whose result type differs from the operand type. Both types must be vectors; fewer than 4 operands: Invalid shufflevector constexpr record. |
20 | CE_INBOUNDS_GEP | [type?, (type, value)…] | As code 12 with the inbounds flag set. |
21 | BLOCKADDRESS | [function type, function, block number] | The address of a basic block of a function, counted from 0 in that function. Fewer than 3 operands, or an unknown type: Invalid blockaddress record. |
22 | DATA | [element…] | An array or vector of integers or floating-point numbers, each element the raw bit pattern in a 64-bit operand; only the low bits an element needs are used (little-endian). Empty: Invalid data record; an element type that cannot be stored this way: Invalid type for value. |
23 | INLINEASM_OLD2 | as 18 | See inline assembly. |
24 | CE_GEP_WITH_INRANGE_INDEX_OLD | [type, flags, (type, value)…] | See GEP records. |
25 | CE_UNOP | [opcode, value] | A unary operator; the only opcode is 0 (fneg), valid for floating-point types, otherwise poison. Fewer than 2 operands: Invalid unary op constexpr record. |
26 | POISON | — | poison of the current type. |
27 | DSO_LOCAL_EQUIVALENT | [type, global value] | dso_local_equivalent of a global. Invalid dso_local record if fewer than 2 operands or the type is unknown. |
28 | INLINEASM_OLD3 | as 18, flags with can-throw | See inline assembly. |
29 | NO_CFI_VALUE | [type, global value] | no_cfi of a global. Invalid no_cfi record on the same conditions. |
30 | INLINEASM | [function type, flags, asm length, asm byte…, constraint length, constraint byte…] | See inline assembly. |
31 | CE_GEP_WITH_INRANGE | [type, flags, width, lower, upper, (type, value)…] | See GEP records. |
32 | CE_GEP | [type, flags, (type, value)…] | See GEP records. |
33 | PTRAUTH | [pointer, key, discriminator, address discriminator] | A ptrauth constant; the four operands are value IDs. Fewer than 4: Invalid ptrauth record. |
34 | PTRAUTH2 | [pointer, key, discriminator, address discriminator, deactivation symbol] | The same with a fifth value. Fewer than 5: Invalid ptrauth record. This is the form the current writer emits. |
35 | BYTE | [value] | Like INTEGER, for a byte or byte-vector type. Invalid byte const record otherwise. A recent addition. |
36 | WIDE_BYTE | [word…] | Like WIDE_INTEGER, for bytes wider than 64 bits. Invalid wide byte const record otherwise. |
Codes 35 and 36 are in LLVMBitCodes.h (lines 453–454) and in the reader
(lines 3443–3457), which settles the two items other pages marked unconfirmed. A
record of any other code is read as UNDEF.
GEP records
One piece of reader code handles codes 12, 20, 24, 31 and 32 (lines 3604–3675). After a
fixed head, the operands are pairs of [type, value]: the first pair is the base pointer,
the rest are the indices. All must have known types
(Invalid getelementptr constexpr record).
| Code | Head |
|---|---|
12 CE_GEP_OLD | The source element type, only if the number of operands is odd; no flags. |
20 CE_INBOUNDS_GEP | As 12, with the inbounds flag implied. |
24 CE_GEP_WITH_INRANGE_INDEX_OLD | Source element type, then one word: bit 0 inbounds, the higher bits an in-range index (dropped by the reader). |
31 CE_GEP_WITH_INRANGE | Source element type, a GEP flags word, then an in-range constant range: the bit width, then two bounds (see constant ranges). |
32 CE_GEP | Source element type, a GEP flags word. |
Errors: fewer than 2 operands, Constant GEP record must have at least two
elements; no pointer operand, Invalid gep with no operands; a base
that is not a pointer or vector of pointers, GEP base operand must be pointer or
vector of pointer; with no source element type to be found,
Missing element type for old-style constant GEP. The current writer writes
code 32, or 31 when the GEP has an in-range part.
Inline assembly
A constant of this kind has the layout [function type]?, flags, asm length, asm
bytes, constraint length, constraint bytes; only code 30 has the function type, the
older codes take it from the current type’s element type (Missing element type for
old-style inlineasm). Lengths that run past the record are
Invalid inlineasm record, as is a record with fewer than 2 operands (3 for
code 30). The flags word:
| Bit | Meaning | Present in codes |
|---|---|---|
| 0 | has side effects | 18, 23, 28, 30 |
| 1 | align stack (for 18, any set bit above 0 means true) | 18, 23, 28, 30 |
| 2 | dialect: 0 AT&T, 1 Intel (for 23, the whole value shifted right by 2) | 23, 28, 30 |
| 3 | can throw (unwind) | 28, 30 |
The writer writes code 30, with bits 0 to 3 as above (lines 3004–3022).
What the writer emits
- Constants are grouped by type; each group starts with SETTYPE.
- Integers of at most 64 bits are INTEGER; wider ones WIDE_INTEGER (active words only); bytes use BYTE and WIDE_BYTE the same way.
- A string array with a trailing zero is CSTRING without the zero, other string arrays are STRING; other arrays and vectors of integers, bytes or floating-point numbers are DATA; structs and arrays of other constants are AGGREGATE.
- Constant expressions are written only as CE_CAST, CE_BINOP (with flags when set), CE_GEP or CE_GEP_WITH_INRANGE, CE_EXTRACTELT, CE_INSERTELT, CE_SHUFFLEVEC or CE_SHUFVEC_EX; the older select, compare and unary forms are read but no longer written. Besides these: BLOCKADDRESS, DSO_LOCAL_EQUIVALENT, NO_CFI_VALUE, PTRAUTH2 and INLINEASM.
- The module-level block defines abbreviations for AGGREGATE, STRING and CSTRING
(7-bit and Char6 forms); SETTYPE, INTEGER, BYTE and CE_CAST use abbreviations the writer
names
CONSTANTS_SETTYPE_ABBREV,CONSTANTS_INTEGER_ABBREV,CONSTANTS_BYTE_ABBREVandCONSTANTS_CE_CAST_Abbrev, which are defined outside the block (a BLOCKINFO block is not read for this page).
More errors of the constants reader
Messages of BitcodeReader.cpp (main branch, read 2026-11-19; line numbers
are that file’s) raised for constants and global initializers that the record table
above does not name, each with its condition. The constant expressions are built when
the block ends, from a work list (materializeValue), so these come from
the end of the CONSTANTS block or from the end of the module.
| Message | Line | Condition |
|---|---|---|
Too few records for range | 876, 881, 900 | A CE_GEP_WITH_INRANGE record (line 3632), or an attribute range, has fewer operands than its bit width, bounds and word counts announce |
Invalid value ID | 1632 | An operand of a constant expression names a value number that is beyond the value list, or whose slot was never filled |
ptrauth key operand must be ConstantInt, ptrauth disc operand must be ConstantInt | 1678, 1682 | The second or the third operand of a CST_CODE_PTRAUTH constant is not an integer constant |
no_cfi operand must be GlobalValue | 1699 | The operand of a NO_CFI_VALUE constant is not a global value |
dso_local operand must be GlobalValue | 1706 | The operand of a DSO_LOCAL_EQUIVALENT constant is not a global value |
blockaddress operand must be a function | 1713 | The first operand of a BLOCKADDRESS constant is not a function |
Invalid number of elements in struct initializer, Incorrect type in struct initializer | 1748, 1752 | An AGGREGATE for a structure type has a different number of operands from the structure’s elements, or an operand has another type than its element |
Invalid number of elements in array initializer, Incorrect type in array initializer | 1760, 1764 | The same for an array type (the count is the array’s length, the type the element type) |
Invalid number of elements in vector initializer, Incorrect type in vector initializer | 1772, 1776 | The same for a fixed vector type |
Constant GEP record must have at least two elements | 3612 | A CE_GEP, CE_GEP_WITH_INRANGE, CE_INBOUNDS_GEP, CE_GEP_OLD or CE_GEP_WITH_INRANGE_INDEX_OLD record has fewer than 2 operands |
GEP base operand must be pointer or vector of pointer | 3662 | The type of the base operand of a constant GEP is not a pointer type |
Invalid cmp constexpt record, Invalid cmp constexpr record | 3752, 3756 | CE_CMP with fewer than 4 operands (the first message, spelled constexpt in the source); or its operand type ID is unknown (constexpr) |
Missing element type for old-style inlineasm | 3786, 3813, 3845 | An old INLINEASM record (not the form that carries its function type) is read, and the pointer type of the asm has no recorded element type |
Alias and aliasee types don't match, Expected an alias or an ifunc | 3304, 3309 | When the aliasee constants are resolved: the aliasee’s type differs from the alias’s; or the pending global is neither an alias nor an ifunc |
Value referenced by initializer is an unsupported constant expression of type opcode | 1814 | A constant expression has an operand that is not a constant (for example a function-local value), so it could only be rebuilt as instructions, but the reader is not inside a function body and has no basic block to put them in (a global variable or alias initializer, or a constant of a module-level block) |
ptrauth deactivation symbol operand must be a pointer | 1689 | The optional fifth operand of a PTRAUTH constant (or the null pointer that stands for it, made from the type of the fourth) is not of pointer type |
Malformed global initializer set | 4099 | After the global initializers and aliasees are resolved, some remain in the pending lists |
Sources
- llvm/lib/Bitcode/Reader/BitcodeReader.cpp – lines 3259–3266, 3355–3361, 3363–3946
- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp – lines 2950–3213
- llvm/include/llvm/Bitcode/LLVMBitCodes.h – lines 408–455