zig0: fix valgrind false positives and clang-analyzer warning
Enable .valgrind module option on test_mod and dumper_mod in addZig0TestStep so that std.mem.indexOfSentinel uses a scalar fallback when running under valgrind. Guard comptime CLZ against bits==0 to fix clang-analyzer shift warning. Auto-format sema.c. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1705,6 +1705,7 @@ fn addZig0TestStep(
|
||||
.root_source_file = b.path("stage0_test_root.zig"),
|
||||
.optimize = optimize,
|
||||
.target = target,
|
||||
.valgrind = if (valgrind) true else null,
|
||||
});
|
||||
test_mod.addIncludePath(b.path("stage0"));
|
||||
test_mod.linkSystemLibrary("c", .{});
|
||||
@@ -1735,6 +1736,7 @@ fn addZig0TestStep(
|
||||
.root_source_file = b.path("src/verbose_air.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
.valgrind = if (valgrind) true else null,
|
||||
});
|
||||
dumper_mod.addImport("zig_internals", zig_internals_mod);
|
||||
dumper_mod.linkSystemLibrary("c", .{});
|
||||
|
||||
@@ -192,7 +192,8 @@ static AirInstRef resolveInst(Sema* sema, ZirInstRef zir_ref) {
|
||||
// Appends an AIR instruction to sema's output arrays.
|
||||
// Returns the instruction index (not the ref).
|
||||
|
||||
static uint32_t semaAddInstAsIndex(Sema* sema, AirInstTag inst_tag, AirInstData data) {
|
||||
static uint32_t semaAddInstAsIndex(
|
||||
Sema* sema, AirInstTag inst_tag, AirInstData data) {
|
||||
if (sema->air_inst_len >= sema->air_inst_cap) {
|
||||
uint32_t new_cap = sema->air_inst_cap * 2;
|
||||
uint8_t* new_tags
|
||||
@@ -588,7 +589,8 @@ static TypeIndex semaTypeOf(Sema* sema, AirInstRef ref) {
|
||||
|
||||
// semaResolvePeerTypes: determine the common type of two AIR refs.
|
||||
// Ported from src/Sema.zig semaResolvePeerTypess (simplified).
|
||||
static TypeIndex semaResolvePeerTypes(Sema* sema, AirInstRef lhs, AirInstRef rhs) {
|
||||
static TypeIndex semaResolvePeerTypes(
|
||||
Sema* sema, AirInstRef lhs, AirInstRef rhs) {
|
||||
TypeIndex lhs_ty = semaTypeOf(sema, lhs);
|
||||
TypeIndex rhs_ty = semaTypeOf(sema, rhs);
|
||||
if (lhs_ty == rhs_ty)
|
||||
@@ -833,7 +835,7 @@ static AirInstRef zirBitCount(
|
||||
uint64_t result = 0;
|
||||
switch (air_tag) {
|
||||
case AIR_INST_CLZ:
|
||||
if (uval == 0)
|
||||
if (uval == 0 || bits == 0)
|
||||
result = bits;
|
||||
else {
|
||||
result = 0;
|
||||
@@ -2699,8 +2701,7 @@ static AirInstRef zirCall(
|
||||
memset(&data, 0, sizeof(data));
|
||||
data.pl_op.operand = arg_refs[param_idx];
|
||||
data.pl_op.payload = name_nts;
|
||||
(void)semaAddInst(
|
||||
&child_block, AIR_INST_DBG_ARG_INLINE, data);
|
||||
(void)semaAddInst(&child_block, AIR_INST_DBG_ARG_INLINE, data);
|
||||
}
|
||||
param_idx++;
|
||||
}
|
||||
@@ -3540,7 +3541,8 @@ static AirInstRef semaResolveSwitchComptime(
|
||||
// debug undefined pattern.
|
||||
AirInstData block_data;
|
||||
memset(&block_data, 0xaa, sizeof(block_data));
|
||||
uint32_t block_inst = semaAddInstAsIndex(sema, AIR_INST_BLOCK, block_data);
|
||||
uint32_t block_inst
|
||||
= semaAddInstAsIndex(sema, AIR_INST_BLOCK, block_data);
|
||||
|
||||
// Set up a label so break can find this block.
|
||||
SemaBlockLabel label;
|
||||
@@ -3594,7 +3596,8 @@ static AirInstRef semaResolveSwitchComptime(
|
||||
// Reserve BLOCK instruction (same as scalar case above).
|
||||
AirInstData block_data;
|
||||
memset(&block_data, 0xaa, sizeof(block_data));
|
||||
uint32_t block_inst = semaAddInstAsIndex(sema, AIR_INST_BLOCK, block_data);
|
||||
uint32_t block_inst
|
||||
= semaAddInstAsIndex(sema, AIR_INST_BLOCK, block_data);
|
||||
|
||||
SemaBlockLabel label;
|
||||
memset(&label, 0, sizeof(label));
|
||||
@@ -4231,7 +4234,8 @@ static bool analyzeBodyInner(
|
||||
memset(&br_data, 0, sizeof(br_data));
|
||||
br_data.br.block_inst = blk_inst;
|
||||
br_data.br.operand = AIR_REF_FROM_IP(IP_INDEX_VOID_VALUE);
|
||||
uint32_t br_inst = semaAddInstAsIndex(sema, AIR_INST_BR, br_data);
|
||||
uint32_t br_inst
|
||||
= semaAddInstAsIndex(sema, AIR_INST_BR, br_data);
|
||||
|
||||
// Write block extra: body_len2, then body insts.
|
||||
uint32_t body_len2 = new_insts_count + 1; // +1 for BR
|
||||
@@ -5153,10 +5157,11 @@ static bool analyzeBodyInner(
|
||||
- 1]
|
||||
== AIR_REF_TO_INST(coerced));
|
||||
uint32_t sub_bl = coerce_block.instructions_len + 1;
|
||||
uint32_t sub_br_idx = semaAddInstAsIndex(sema, AIR_INST_BR,
|
||||
(AirInstData) {
|
||||
.br = { .block_inst = label.merges.block_inst,
|
||||
.operand = coerced } });
|
||||
uint32_t sub_br_idx
|
||||
= semaAddInstAsIndex(sema, AIR_INST_BR,
|
||||
(AirInstData) { .br
|
||||
= { .block_inst = label.merges.block_inst,
|
||||
.operand = coerced } });
|
||||
uint32_t sub_extra = semaAddExtra(sema, sub_bl);
|
||||
for (uint32_t si = 0;
|
||||
si < coerce_block.instructions_len; si++) {
|
||||
|
||||
Reference in New Issue
Block a user