Fix segfaults caused by reading AST OptionalIndex fields (none=UINT32_MAX)
without converting to the C convention (none=0):
- extractVarDecl: convert GlobalVarDecl extra_data OptionalIndex fields
(type_node, align_node, addrspace_node, section_node) from UINT32_MAX
to 0 when none. Also handle simple_var_decl's opt_node_and_opt_node.
- fnDecl: extract align_expr, addrspace_expr, section_expr from
FnProtoOne/FnProto extra_data with proper OptionalIndex conversion.
Also fix FN_PROTO_SIMPLE param check to use UINT32_MAX.
- fnDecl: add separate type_gz, align_gz, linksection_gz, addrspace_gz
sub-blocks matching upstream AstGen.zig:4149-4192, and pass their
bodies to setDeclaration. Update decl_id selection to account for
has_type_body and has_special_body.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Port multiple missing/incorrect code paths to match upstream AstGen.zig:
- Fix continue label matching for labeled loops
- Fix comptimeExpr labeled block optimization
- Fix numberLiteral big integer and octal/binary parsing
- Fix addNodeExtended/addExtendedPayload undefined small field
- Fix blockExprExpr force_comptime parameter
- Port various missing builtins and instruction handlers
- Add union_decl/opaque_decl to test hash skip mask
- Remove all debug fprintf statements
- Fix int base type for -Wsign-conversion
All 25 corpus test files now pass.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- parser.c: Handle TOKEN_KEYWORD_INLINE in parseSwitchProng, producing
AST_NODE_SWITCH_CASE_INLINE_ONE / AST_NODE_SWITCH_CASE_INLINE nodes.
This fixes parsing of multi_array_list.zig which uses `inline else`.
- astgen.c: Implement float literal parsing in numberLiteral using
strtold with f64 round-trip check. Add addFloat helper and addPlNodeQuad
for float128 emission. Extend token scanning to include exponent markers.
- multi_array_list.zig still skipped: remaining diffs in bool_not,
bool_br_and, ret_is_non_err.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Port multiple features from AstGen.zig:
- fnProtoExpr/fnProtoExprInner: function types as expressions
- arrayTypeSentinelExpr: [N:sentinel]T array types
- Extern fn_decl without body (implicit CCC)
- 12 builtins: ptrFromInt, Vector, setRuntimeSafety, intFromError,
clz, branchHint, bitSizeOf, fieldParentPtr, splat, offsetOf,
inComptime, errorFromInt, errorCast alias
- Fix namespace scope parent: use caller's scope instead of gz->base,
allowing inner structs to reference outer locals (fixes S2, name, U)
- Fix addFunc/addFuncFancy: don't emit src_locs when body is empty
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The C parser uses OPT() macro which stores UINT32_MAX as the "none"
sentinel for optional AST node indices in extra_data. The rlExpr
(AstRlAnnotate) and exprRl functions were checking `!= 0` for these
fields, treating UINT32_MAX as a valid node index and causing segfaults.
Fixed optional field checks for fn_proto_one, fn_proto extra data
(param, align, addrspace, section, callconv), while cont_expr,
global_var_decl type_node, and slice_sentinel end_node.
Also added behavior test corpus files and FAIL: diagnostic to
the corpus test runner.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fix multiple bugs found via the array_list.zig corpus test:
- Fix anytype param ref/index double-conversion (addStrTok returns
a ref, don't add ZIR_REF_START_INDEX again)
- Implement is_generic param tracking via is_used_or_discarded
pointer in ScopeLocalVal
- Fix globalVarDecl declaration src_line: use type_gz.decl_line
instead of ag->source_line (which was advanced by init expression)
- Fix cppcheck warning: remove redundant (0u << 2) in bitmask
- Implement fetchRemoveRefEntries and ret_param_refs in addFunc
- Add func_fancy case to buildHashSkipMask in test
- Fix valgrind: zero elem_val_imm padding, skip addNodeExtended
undefined small field, handle more padding-sensitive tags
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Implement assignDestructure() and assignDestructureMaybeDecls() with
RL_DESTRUCTURE result location, DestructureComponent types, rvalue
handling for validate_destructure/elem_val_imm/store_node, and array
init optimization.
- Fix tryResolvePrimitiveIdent to allow bit_count==0 (u0/i0 types) and
reject leading zeros (u01, i007).
- Add nodeIsTriviallyZero and slice_length optimization for
arr[start..][0..len] patterns in AST_NODE_SLICE and
AST_NODE_SLICE_SENTINEL cases.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- blockExpr: call rvalue on void result for unlabeled blocks, matching
upstream AstGen.zig:2431. This was causing a missing STORE_NODE when
empty blocks like {} were used as struct field values with pointer RL.
- identifierExpr: call rvalueNoCoercePreRef after LOAD in local_ptr case,
matching upstream AstGen.zig:8453-8454.
- Implement AST_NODE_ARRAY_MULT (** operator) with ArrayMul payload,
matching upstream AstGen.zig:774-785.
- Enable parser_test.zig and astgen_test.zig corpus tests.
- Enable combined corpus test (all 5 files pass).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Port switchExprErrUnion optimization for both catch and if patterns,
fix missing rvalue call in decl table lookup, fix identAsString
ordering for underscore error captures, and fill value_placeholder
with 0xaa to match upstream undefined pattern.
Enables corpus build.zig test.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add error capture scope to orelseCatchExpr (catch |err| now creates
a ScopeLocalVal for the captured error variable)
- Add @panic, @errorName, @field builtins
- Increase blockExprStmts scope arrays from 64 to 128 entries
(build.zig has 93 var decls in a single block)
corpus build.zig still skipped: needs switchExprErrUnion optimization
(catch |err| switch(err) pattern).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>