Bug Summary

File:root/firefox-clang/third_party/llama.cpp/src/models/arwkv7.cpp
Warning:line 165, column 13
Value stored to 'cur' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -O2 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name arwkv7.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -target-feature +avx -target-feature +avx2 -target-feature +bmi2 -target-feature +f16c -target-feature +fma -target-feature +sse4.2 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/third_party/llama.cpp -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/third_party/llama.cpp -resource-dir /usr/lib/llvm-23/lib/clang/23 -include /root/firefox-clang/config/gcc_hidden.h -include /root/firefox-clang/obj-x86_64-pc-linux-gnu/mozilla-config.h -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/stl_wrappers -D _GLIBCXX_ASSERTIONS=1 -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D _GNU_SOURCE=1 -D GGML_USE_CPU=1 -D GGML_VERSION="GGML_VERSION" -D GGML_COMMIT="GGML_COMMIT" -D GGML_SHARED=1 -D LLAMA_SHARED=1 -D GGML_BUILD=1 -D LLAMA_BUILD=1 -D GGML_BACKEND_SHARED=1 -D GGML_BACKEND_BUILD=1 -D MOZ_HAS_MOZGLUE -I /root/firefox-clang/third_party/llama.cpp -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/third_party/llama.cpp -I /root/firefox-clang/third_party/llama.cpp/ggml -I /root/firefox-clang/third_party/llama.cpp/ggml/include -I /root/firefox-clang/third_party/llama.cpp/ggml/src -I /root/firefox-clang/third_party/llama.cpp/ggml/src/ggml-cpu -I /root/firefox-clang/third_party/llama.cpp/include -I /root/firefox-clang/third_party/llama.cpp/src -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/c++/16 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/x86_64-linux-gnu/c++/16 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/c++/16/backward -internal-isystem /usr/lib/llvm-23/lib/clang/23/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-error=pessimizing-move -Wno-error=large-by-value-copy=128 -Wno-error=implicit-int-float-conversion -Wno-error=thread-safety-analysis -Wno-error=tautological-type-limit-compare -Wno-invalid-offsetof -Wno-range-loop-analysis -Wno-deprecated-anon-enum-enum-conversion -Wno-deprecated-enum-enum-conversion -Wno-inline-new-delete -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-vla-cxx-extension -Wno-unknown-warning-option -Wno-character-conversion -Wno-sign-compare -Wno-unused-function -Wno-tautological-unsigned-enum-zero-compare -Wno-implicit-fallthrough -Wno-unreachable-code -std=gnu++20 -fdeprecated-macro -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fno-rtti -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fno-sized-deallocation -fno-aligned-allocation -fdiagnostics-absolute-paths -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -mllvm -dwarf-linkage-names=Abstract -faddrsig -fdwarf2-cfi-asm -o /tmp/scan-build-2026-09-01-224014-2642839-1 -x c++ /root/firefox-clang/third_party/llama.cpp/src/models/arwkv7.cpp
1#include "models.h"
2
3void llama_model_arwkv7::load_arch_hparams(llama_model_loader & ml) {
4 ml.get_key(LLM_KV_ATTENTION_LAYERNORM_EPS, hparams.f_norm_eps, false);
5 ml.get_key(LLM_KV_ATTENTION_LAYERNORM_RMS_EPS, hparams.f_norm_rms_eps, false);
6 ml.get_key(LLM_KV_WKV_HEAD_SIZE, hparams.wkv_head_size);
7 ml.get_key(LLM_KV_ATTENTION_DECAY_LORA_RANK, hparams.n_lora_decay);
8 ml.get_key(LLM_KV_ATTENTION_ICLR_LORA_RANK, hparams.n_lora_iclr);
9 ml.get_key(LLM_KV_ATTENTION_VALUE_RESIDUAL_MIX_LORA_RANK, hparams.n_lora_value_res_mix);
10 ml.get_key(LLM_KV_ATTENTION_GATE_LORA_RANK, hparams.n_lora_gate, false);
11 ml.get_key(LLM_KV_TOKEN_SHIFT_COUNT, hparams.token_shift_count, false);
12
13 switch (hparams.n_layer()) {
14 case 12:
15 switch (hparams.n_embd) {
16 case 768: type = LLM_TYPE_190M; break;
17 default: type = LLM_TYPE_UNKNOWN;
18 } break;
19 case 24:
20 switch (hparams.n_embd) {
21 case 1024: type = LLM_TYPE_450M; break;
22 case 2048: type = LLM_TYPE_1_5B; break;
23 default: type = LLM_TYPE_UNKNOWN;
24 } break;
25 case 28:
26 switch (hparams.n_embd) {
27 case 1536: type = LLM_TYPE_1_5B; break;
28 case 3584: type = LLM_TYPE_7B; break;
29 default: type = LLM_TYPE_UNKNOWN;
30 } break;
31 case 32:
32 switch (hparams.n_embd) {
33 case 2560: type = LLM_TYPE_2_9B; break;
34 case 4096: type = LLM_TYPE_7B; break;
35 default: type = LLM_TYPE_UNKNOWN;
36 } break;
37 case 61:
38 switch (hparams.n_embd) {
39 case 4096: type = LLM_TYPE_14B; break;
40 default: type = LLM_TYPE_UNKNOWN;
41 } break;
42 default: type = LLM_TYPE_UNKNOWN;
43 }
44}
45
46void llama_model_arwkv7::load_arch_tensors(llama_model_loader &) {
47 LLAMA_LOAD_LOCALSconst int n_layer = hparams.n_layer(); (void)(n_layer); const
int n_layer_all = hparams.n_layer_all; (void)(n_layer_all); const
int n_layer_nextn = hparams.n_layer_nextn; (void)(n_layer_nextn
); const int64_t n_head = hparams.n_head(); (void)(n_head); const
int64_t n_head_kv = hparams.n_head_kv(); (void)(n_head_kv); const
int64_t n_embd = hparams.n_embd; (void)(n_embd); const int64_t
n_embd_k_gqa = hparams.n_embd_k_gqa(); (void)(n_embd_k_gqa);
const int64_t n_embd_v_gqa = hparams.n_embd_v_gqa(); (void)(
n_embd_v_gqa); const int64_t n_embd_head_k = hparams.n_embd_head_k
(); (void)(n_embd_head_k); const int64_t n_embd_head_v = hparams
.n_embd_head_v(); (void)(n_embd_head_v); const int64_t n_ff =
hparams.n_ff(); (void)(n_ff); const int64_t n_embd_gqa = n_embd_v_gqa
; (void)(n_embd_gqa); const int64_t n_vocab = vocab.n_tokens(
); (void)(n_vocab); const int64_t n_token_types = vocab.n_token_types
(); (void)(n_token_types); const int64_t n_rot = hparams.n_rot
(); (void)(n_rot); const int64_t n_expert = hparams.n_expert;
(void)(n_expert); const int64_t n_expert_used = hparams.n_expert_used
; (void)(n_expert_used); const int64_t n_ctx_train = hparams.
n_ctx_train; (void)(n_ctx_train);
;
48
49 tok_embd = create_tensor(tn(LLM_TENSOR_TOKEN_EMBD, "weight"), {n_embd, n_vocab}, 0);
50
51 // output
52 output_norm = create_tensor(tn(LLM_TENSOR_OUTPUT_NORM, "weight"), {n_embd}, 0);
53 output = create_tensor(tn(LLM_TENSOR_OUTPUT, "weight"), {n_embd, n_vocab}, 0);
54
55 const int n_lora_decay = hparams.n_lora_decay;
56 const int n_lora_iclr = hparams.n_lora_iclr;
57 const int n_lora_value_res_mix = hparams.n_lora_value_res_mix;
58 const int n_lora_gate = hparams.n_lora_gate;
59 const int attn_hidden_size = n_embd;
60
61 for (int i = 0; i < n_layer; ++i) {
62 auto & layer = layers[i];
63
64 layer.attn_norm = create_tensor(tn(LLM_TENSOR_ATTN_NORM, "weight", i), {n_embd}, 0);
65
66 layer.time_mix_w0 = create_tensor(tn(LLM_TENSOR_TIME_MIX_W0, "weight", i), {n_embd}, 0);
67 layer.time_mix_w1 = create_tensor(tn(LLM_TENSOR_TIME_MIX_W1, "weight", i), {n_embd, n_lora_decay}, 0);
68 layer.time_mix_w2 = create_tensor(tn(LLM_TENSOR_TIME_MIX_W2, "weight", i), {n_lora_decay, n_embd}, 0);
69
70 layer.time_mix_a0 = create_tensor(tn(LLM_TENSOR_TIME_MIX_A0, "weight", i), {n_embd}, 0);
71 layer.time_mix_a1 = create_tensor(tn(LLM_TENSOR_TIME_MIX_A1, "weight", i), {n_embd, n_lora_iclr}, 0);
72 layer.time_mix_a2 = create_tensor(tn(LLM_TENSOR_TIME_MIX_A2, "weight", i), {n_lora_iclr, n_embd}, 0);
73
74 if (i == 0) {
75 // actually not used
76 layer.time_mix_v0 = create_tensor(tn(LLM_TENSOR_TIME_MIX_V0, "weight", i), {n_embd}, 0);
77 layer.time_mix_v1 = create_tensor(tn(LLM_TENSOR_TIME_MIX_V1, "weight", i), {n_embd, n_lora_iclr}, 0);
78 layer.time_mix_v2 = create_tensor(tn(LLM_TENSOR_TIME_MIX_V2, "weight", i), {n_lora_iclr, n_embd}, 0);
79 } else {
80 layer.time_mix_v0 = create_tensor(tn(LLM_TENSOR_TIME_MIX_V0, "weight", i), {n_embd}, 0);
81 layer.time_mix_v1 = create_tensor(tn(LLM_TENSOR_TIME_MIX_V1, "weight", i), {n_embd, n_lora_value_res_mix}, 0);
82 layer.time_mix_v2 = create_tensor(tn(LLM_TENSOR_TIME_MIX_V2, "weight", i), {n_lora_value_res_mix, n_embd}, 0);
83 }
84
85 layer.time_mix_g1 = create_tensor(tn(LLM_TENSOR_TIME_MIX_G1, "weight", i), {n_embd, n_lora_gate}, TENSOR_NOT_REQUIRED);
86 layer.time_mix_g2 = create_tensor(tn(LLM_TENSOR_TIME_MIX_G2, "weight", i), {n_lora_gate, n_embd}, TENSOR_NOT_REQUIRED);
87
88 tryif (true) {
89 layer.time_mix_lerp_fused = create_tensor(tn(LLM_TENSOR_TIME_MIX_LERP_FUSED, "weight", i), {n_embd, 1, 1, 6}, 0);
90 } catch(std::runtime_error & e)if (static const std::exception e, err, error, ex; false) {
91 // ARWKV models may not have gate tensors
92 layer.time_mix_lerp_fused = create_tensor(tn(LLM_TENSOR_TIME_MIX_LERP_FUSED, "weight", i), {n_embd, 1, 1, 5}, 0);
93 }
94
95 layer.time_mix_k_k = create_tensor(tn(LLM_TENSOR_TIME_MIX_K_K, "weight", i), {attn_hidden_size}, 0);
96 layer.time_mix_k_a = create_tensor(tn(LLM_TENSOR_TIME_MIX_K_A, "weight", i), {attn_hidden_size}, 0);
97 layer.time_mix_r_k = create_tensor(tn(LLM_TENSOR_TIME_MIX_R_K, "weight", i), {attn_hidden_size}, 0);
98
99 layer.time_mix_key = create_tensor(tn(LLM_TENSOR_TIME_MIX_KEY, "weight", i), {attn_hidden_size, n_embd}, 0);
100 layer.time_mix_value = create_tensor(tn(LLM_TENSOR_TIME_MIX_VALUE, "weight", i), {attn_hidden_size, n_embd}, 0);
101 layer.time_mix_receptance = create_tensor(tn(LLM_TENSOR_TIME_MIX_RECEPTANCE, "weight", i), {attn_hidden_size, n_embd}, 0);
102
103 layer.time_mix_ln = create_tensor(tn(LLM_TENSOR_TIME_MIX_LN, "weight", i), {n_embd}, TENSOR_NOT_REQUIRED);
104 layer.time_mix_ln_b = create_tensor(tn(LLM_TENSOR_TIME_MIX_LN, "bias", i), {n_embd}, TENSOR_NOT_REQUIRED);
105 layer.time_mix_output = create_tensor(tn(LLM_TENSOR_TIME_MIX_OUTPUT, "weight", i), {n_embd, attn_hidden_size}, 0);
106
107 layer.ffn_norm = create_tensor(tn(LLM_TENSOR_FFN_NORM, "weight", i), {n_embd}, 0);
108
109 layer.ffn_gate = create_tensor(tn(LLM_TENSOR_FFN_GATE, "weight", i), {n_embd, n_ff}, 0);
110 layer.ffn_down = create_tensor(tn(LLM_TENSOR_FFN_DOWN, "weight", i), { n_ff, n_embd}, 0);
111 layer.ffn_up = create_tensor(tn(LLM_TENSOR_FFN_UP, "weight", i), {n_embd, n_ff}, 0);
112 }
113
114}
115
116std::unique_ptr<llm_graph_context> llama_model_arwkv7::build_arch_graph(const llm_graph_params & params) const {
117 return std::make_unique<graph>(*this, params);
118}
119
120llama_model_arwkv7::graph::graph(const llama_model & model, const llm_graph_params & params) : llm_build_rwkv7_base(model, params) {
121 GGML_ASSERT(n_embd == hparams.n_embd_r())if (!(n_embd == hparams.n_embd_r())) ggml_abort("/root/firefox-clang/third_party/llama.cpp/src/models/arwkv7.cpp"
, 121, "GGML_ASSERT(%s) failed", "n_embd == hparams.n_embd_r()"
)
;
122
123 ggml_tensor * cur;
124 ggml_tensor * inpL;
125 ggml_tensor * v_first = nullptr;
126
127 inpL = build_inp_embd(model.tok_embd);
128
129 auto * rs_inp = build_rs_inp();
130
131 const auto n_embd = hparams.n_embd;
132 const auto n_seq_tokens = ubatch.n_seq_tokens;
133 const auto n_seqs = ubatch.n_seqs;
134
135 ggml_tensor * inp_out_ids = build_inp_out_ids();
136
137 for (int il = 0; il < n_layer; ++il) {
138 const llama_layer * layer = &model.layers[il];
139 inpL = ggml_reshape_3d(ctx0, inpL, n_embd, n_seq_tokens, n_seqs);
140
141 ggml_tensor * token_shift = build_rwkv_token_shift_load(rs_inp, ubatch, il);
142
143 ggml_tensor * att_norm = build_norm(inpL, layer->attn_norm, layer->attn_norm_b, LLM_NORM_RMS, il);
144 cb(att_norm, "attn_norm", il);
145
146 ggml_tensor * x_prev = ggml_concat(
147 ctx0,
148 token_shift,
149 ggml_view_3d(ctx0, att_norm, n_embd, n_seq_tokens - 1, n_seqs, att_norm->nb[1], att_norm->nb[2], 0),
150 1
151 );
152
153 cur = build_rwkv7_time_mix(rs_inp, att_norm, x_prev, v_first, ubatch, il);
154
155 token_shift = ggml_view_3d(ctx0, att_norm, n_embd, 1, n_seqs, att_norm->nb[1], att_norm->nb[2], (n_seq_tokens-1)*n_embd*ggml_element_size(att_norm));
156 ggml_build_forward_expand(gf, build_rwkv_token_shift_store(token_shift, ubatch, il));
157
158 ggml_tensor * ffn_inp = ggml_add(ctx0, cur, inpL);
159 cb(ffn_inp, "ffn_inp", il);
160
161 cur = ggml_reshape_2d(ctx0, cur, n_embd, n_tokens);
162 ffn_inp = ggml_reshape_2d(ctx0, ffn_inp, n_embd, n_tokens);
163
164 if (il == n_layer - 1 && inp_out_ids) {
165 cur = ggml_get_rows(ctx0, cur, inp_out_ids);
Value stored to 'cur' is never read
166 ffn_inp = ggml_get_rows(ctx0, ffn_inp, inp_out_ids);
167 }
168 // feed-forward network
169 cur = build_norm(ffn_inp,
170 model.layers[il].ffn_norm, NULL__null,
171 LLM_NORM_RMS, il);
172 cb(cur, "ffn_norm", il);
173
174 cur = build_ffn(cur,
175 model.layers[il].ffn_up, NULL__null, NULL__null,
176 model.layers[il].ffn_gate, NULL__null, NULL__null,
177 model.layers[il].ffn_down, NULL__null, NULL__null,
178 NULL__null,
179 LLM_FFN_SILU, LLM_FFN_PAR, il);
180 cb(cur, "ffn_out", il);
181
182 cur = ggml_add(ctx0, cur, ffn_inp);
183
184 cur = build_cvec(cur, il);
185 cb(cur, "l_out", il);
186
187 // input for next layer
188 inpL = cur;
189 }
190 cur = inpL;
191 cur = build_norm(cur, model.output_norm, model.output_norm_b, LLM_NORM_RMS, -1);
192
193 cb(cur, "result_norm", -1);
194 res->t_embd = cur;
195
196 cur = build_lora_mm(model.output, cur, model.output_s);
197
198 cb(cur, "result_output", -1);
199 res->t_logits = cur;
200
201 ggml_build_forward_expand(gf, cur);
202}