commit d2c301cc955a8a62a5c05bebfdbfd438c6793cf8 (tree)
parent 500bc6a791dce7a554d1b45d9363003df6f8e709
Author: Motiejus Jakštys <motiejus@jakstys.lt>
Date: Sun, 15 Feb 2026 19:49:54 +0000
astgen: fix cppcheck warnings for err_scope_used and param_insts
Use memset initialization to satisfy cppcheck's data flow analysis:
- err_scope_used: cppcheck can't track writes through is_used_or_discarded pointer
- param_insts: cppcheck warns about potentially uninitialized array elements
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat:
4 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/build.zig b/build.zig
@@ -669,13 +669,13 @@ pub fn build(b: *std.Build) !void {
// Subtract all AVX-512 features so the zig CC won't emit them.
const F = std.Target.x86.Feature;
const avx512_features = [_]F{
- .avx512f, .avx512bw,
- .avx512cd, .avx512dq,
- .avx512vl, .avx512bf16,
- .avx512bitalg, .avx512er,
- .avx512fp16, .avx512ifma,
- .avx512pf, .avx512vbmi,
- .avx512vbmi2, .avx512vnni,
+ .avx512f, .avx512bw,
+ .avx512cd, .avx512dq,
+ .avx512vl, .avx512bf16,
+ .avx512bitalg, .avx512er,
+ .avx512fp16, .avx512ifma,
+ .avx512pf, .avx512vbmi,
+ .avx512vbmi2, .avx512vnni,
.avx512vp2intersect, .avx512vpopcntdq,
.evex512,
};
diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig
@@ -7,7 +7,9 @@ const maxInt = std.math.maxInt;
const zig0 = if (@hasDecl(@import("root"), "zig0"))
@import("root").zig0
else
- struct { pub const enabled = false; };
+ struct {
+ pub const enabled = false;
+ };
test "zig fmt: remove extra whitespace at start and end of file with comment between" {
try testTransform(
diff --git a/lib/std/zig/tokenizer.zig b/lib/std/zig/tokenizer.zig
@@ -3,7 +3,9 @@ const std = @import("std");
const zig0 = if (@hasDecl(@import("root"), "zig0"))
@import("root").zig0
else
- struct { pub const enabled = false; };
+ struct {
+ pub const enabled = false;
+ };
pub const Token = struct {
tag: Tag,
diff --git a/stage0/astgen.c b/stage0/astgen.c
@@ -10286,7 +10286,8 @@ static uint32_t switchExprErrUnion(GenZir* parent_gz, Scope* scope,
memset(&err_scope, 0, sizeof(err_scope));
memset(&capture_scope_val, 0, sizeof(capture_scope_val));
- bool err_scope_used = false;
+ bool err_scope_used;
+ memset(&err_scope_used, 0, sizeof(err_scope_used));
err_scope = (ScopeLocalVal) {
.base = { .tag = SCOPE_LOCAL_VAL },
.parent = &case_scope.base,
@@ -14174,6 +14175,7 @@ static void fnDecl(AstGenCtx* ag, GenZir* gz, Scope* scope,
uint32_t param_scope_count = 0;
// Collect param instruction indices (AstGen.zig:4254, 4360).
uint32_t param_insts[256];
+ memset(param_insts, 0, sizeof(param_insts));
uint32_t param_insts_len = 0;
// noalias_bits tracking (AstGen.zig:4259).
uint32_t noalias_bits = 0;