Bug Summary

File:src/ti_decl.c
Warning:line 152, column 2
Value stored to 'serialThis' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name ti_decl.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -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 -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/home/kfp/aldor/aldor/aldor/src -fcoverage-compilation-dir=/home/kfp/aldor/aldor/aldor/src -resource-dir /usr/local/lib/clang/18 -D PACKAGE_NAME="aldor" -D PACKAGE_TARNAME="aldor" -D PACKAGE_VERSION="1.4.0" -D PACKAGE_STRING="aldor 1.4.0" -D PACKAGE_BUGREPORT="aldor@xinutec.org" -D PACKAGE_URL="" -D PACKAGE="aldor" -D VERSION="1.4.0" -D YYTEXT_POINTER=1 -D HAVE_STDIO_H=1 -D HAVE_STDLIB_H=1 -D HAVE_STRING_H=1 -D HAVE_INTTYPES_H=1 -D HAVE_STDINT_H=1 -D HAVE_STRINGS_H=1 -D HAVE_SYS_STAT_H=1 -D HAVE_SYS_TYPES_H=1 -D HAVE_UNISTD_H=1 -D STDC_HEADERS=1 -D HAVE_LIBREADLINE=1 -D HAVE_READLINE_READLINE_H=1 -D HAVE_READLINE_HISTORY=1 -D HAVE_READLINE_HISTORY_H=1 -D USE_GLOOP_SHELL=1 -D GENERATOR_COROUTINES=0 -D HAVE_DLFCN_H=1 -D LT_OBJDIR=".libs/" -I . -D VCSVERSION="2c53e759f1e00e345f8b172e7139debda72fda13" -internal-isystem /usr/local/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-empty-body -Wno-enum-compare -Wno-missing-field-initializers -Wno-unused -Wno-unused-parameter -Wno-error=format -Wno-error=type-limits -Wno-error=strict-aliasing -Wno-sign-compare -Wno-error=shift-negative-value -Wno-error=clobbered -std=c99 -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2026-01-15-223856-845667-1 -x c ti_decl.c
1/****************************************************************************
2 *
3 * ti_decl.c: Type inference -- declaration pass.
4 *
5 * Copyright (c) 1990-2007 Aldor Software Organization Ltd (Aldor.org).
6 *
7 ***************************************************************************/
8
9#include "debug.h"
10#include "fluid.h"
11#include "format.h"
12#include "stab.h"
13#include "store.h"
14#include "terror.h"
15#include "ti_bup.h"
16#include "ti_decl.h"
17#include "ti_tdn.h"
18#include "tinfer.h"
19#include "abpretty.h"
20
21
22struct _pendingDecl
23{
24 AbSyn absyn; /* AB_Declare node to be tibup'd */
25 Stab stab; /* Symbol table in which to tibup(absyn) */
26 TForm type; /* Type constraint on absyn */
27};
28typedef struct _pendingDecl *PendingDecl;
29
30DECLARE_LIST(PendingDecl)typedef struct PendingDeclListCons { PendingDecl first; struct
PendingDeclListCons *rest; } *PendingDeclList; struct PendingDecl_listOpsStruct
{ PendingDeclList (*Cons) (PendingDecl, PendingDeclList); PendingDeclList
(*Singleton) (PendingDecl); PendingDeclList (*List) (int n, ...
); PendingDeclList (*Listv) (va_list argp); PendingDeclList (
*ListNull) (PendingDecl, ...); Bool (*Equal) (PendingDeclList
, PendingDeclList, Bool (*f) (PendingDecl, PendingDecl)); PendingDecl
(*Find) (PendingDeclList, PendingDecl, Bool(*eq)(PendingDecl
,PendingDecl) , int *); PendingDecl (*Match) (PendingDeclList
, void *, Bool(*match)(PendingDecl, void *), int *); PendingDeclList
(*MatchAll) (PendingDeclList, void *, Bool(*match)(PendingDecl
, void *)); PendingDeclList (*FreeCons) (PendingDeclList); void
(*Free) (PendingDeclList); PendingDeclList (*FreeTo) (PendingDeclList
, PendingDeclList); void (*FreeDeeply) (PendingDeclList, void
(*f)(PendingDecl)); PendingDeclList (*FreeDeeplyTo) (PendingDeclList
, PendingDeclList, void (*f) (PendingDecl) ); PendingDeclList
(*FreeIfSat) (PendingDeclList, void (*f)(PendingDecl), Bool (
*s)(PendingDecl)); PendingDecl (*Elt) (PendingDeclList, Length
); PendingDeclList (*Drop) (PendingDeclList, Length); PendingDeclList
(*LastCons) (PendingDeclList); Length (*_Length) (PendingDeclList
); Bool (*IsLength) (PendingDeclList, Length); Bool (*IsShorter
) (PendingDeclList, Length); Bool (*IsLonger) (PendingDeclList
, Length); PendingDeclList (*Copy) (PendingDeclList); PendingDeclList
(*CopyTo) (PendingDeclList, PendingDeclList); PendingDeclList
(*CopyDeeply) (PendingDeclList, PendingDecl (*)(PendingDecl)
); PendingDeclList (*CopyDeeplyTo) (PendingDeclList, PendingDeclList
, PendingDecl (*)(PendingDecl)); PendingDeclList (*Map) (PendingDecl
(*f)(PendingDecl), PendingDeclList); PendingDeclList (*NMap)
(PendingDecl (*f)(PendingDecl), PendingDeclList); PendingDeclList
(*Reverse) (PendingDeclList); PendingDeclList (*NReverse) (PendingDeclList
); PendingDeclList (*Concat) (PendingDeclList, PendingDeclList
); PendingDeclList (*NConcat) (PendingDeclList, PendingDeclList
); Bool (*Memq) (PendingDeclList, PendingDecl); Bool (*Member
) (PendingDeclList, PendingDecl, Bool(*eq)(PendingDecl,PendingDecl
) ); Bool (*ContainsAllq) (PendingDeclList, PendingDeclList);
Bool (*ContainsAnyq) (PendingDeclList, PendingDeclList); Bool
(*ContainsAll) (PendingDeclList, PendingDeclList, Bool (*eq)
(PendingDecl, PendingDecl)); Bool (*ContainsAny) (PendingDeclList
, PendingDeclList, Bool (*eq)(PendingDecl, PendingDecl)); int
(*Posq) (PendingDeclList, PendingDecl); int (*Position) (PendingDeclList
, PendingDecl, Bool(*eq)(PendingDecl,PendingDecl) ); PendingDeclList
(*NRemove) (PendingDeclList, PendingDecl, Bool(*eq)(PendingDecl
,PendingDecl) ); void (*FillVector) (PendingDecl *, PendingDeclList
); int (*Print) (FILE *, PendingDeclList, int (*pr)(FILE *, PendingDecl
) ); int (*GPrint) (FILE *, PendingDeclList, int (*pr)(FILE *
, PendingDecl), char *l,char *m,char *r); int (*Format) (OStream
, CString, PendingDeclList); }; extern struct PendingDecl_listOpsStruct
const *PendingDecl_listPointer
;
31CREATE_LIST(PendingDecl)struct PendingDecl_listOpsStruct const *PendingDecl_listPointer
= (struct PendingDecl_listOpsStruct const *) &ptrlistOps
;
32
33/* tiDeclPending: decl nodes waiting for processing */
34static PendingDeclList pdPending = NULL((void*)0);
35
36/*****************************************************************************
37 *
38 * :: Selective debug stuff
39 *
40 ****************************************************************************/
41
42Bool tipDeclDebug = false((int) 0);
43#define tipDeclDEBUGif (!tipDeclDebug) { } else afprintf DEBUG_IF(tipDecl)if (!tipDeclDebug) { } else afprintf
44
45/*****************************************************************************
46 *
47 * :: Declarations for breadth-first declaration pass
48 *
49 ****************************************************************************/
50
51localstatic PendingDecl pdNew(Stab stab, AbSyn absyn, TForm type);
52localstatic void tidecl(Stab stab, AbSyn absyn, TForm type);
53localstatic void tideclAssign(Stab stab, AbSyn absyn, TForm type);
54localstatic void tideclDeclare(Stab stab, AbSyn absyn, TForm type);
55localstatic void tideclDefine(Stab stab, AbSyn absyn, TForm type);
56localstatic void tideclGeneric(Stab stab, AbSyn absyn, TForm type);
57
58/*****************************************************************************
59 *
60 * :: Support functions for breadth-first declaration pass
61 *
62 ****************************************************************************/
63
64localstatic PendingDecl
65pdNew(Stab stab, AbSyn absyn, TForm type)
66{
67 PendingDecl result = (PendingDecl)stoAlloc(OB_Other0, sizeof(*result));
68 result->absyn = absyn;
69 result->stab = stab;
70 result->type = type;
71 return result;
72}
73
74#define pdAbSyn(pd)((pd)->absyn) ((pd)->absyn)
75#define pdStab(pd)((pd)->stab) ((pd)->stab)
76#define pdType(pd)((pd)->type) ((pd)->type)
77
78
79/*****************************************************************************
80 *
81 * :: Declaration pass
82 *
83 ****************************************************************************/
84
85void
86tiDeclarations(Stab stab, AbSyn absyn, TForm type)
87{
88 Scope("tiDeclarations")String scopeName = ("tiDeclarations"); int fluidLevel0 = (scopeLevel
++, fluidLevel)
;
89 int passNo = 0;
90
91 PendingDeclList fluid(pdPending)fluidSave_pdPending = ( fluidStack = (fluidLevel==fluidLimit)
? fluidGrow() : fluidStack, fluidStack[fluidLevel].scopeName
= scopeName, fluidStack[fluidLevel].scopeLevel = scopeLevel,
fluidStack[fluidLevel].pglobal = (Pointer) &(pdPending),
fluidStack[fluidLevel].pstack = (Pointer) &fluidSave_pdPending
, fluidStack[fluidLevel].size = sizeof(pdPending), fluidLevel
++, (pdPending) )
;
92 PendingDeclList pds;
93
94 pdPending = NULL((void*)0);
95
96 /* Add the top-level node to the pending list */
97 pdPending = listCons(PendingDecl)(PendingDecl_listPointer->Cons)(pdNew(stab, absyn, type), pdPending);
98
99 /* Repeatedly process pending nodes */
100 while (pdPending) {
101 /* Grab the pending list for ourselves */
102 pds = listNReverse(PendingDecl)(PendingDecl_listPointer->NReverse)(pdPending);
103 pdPending = NULL((void*)0);
104 passNo++;
105
106 /* Debugging */
107 tipDeclDEBUGif (!tipDeclDebug) { } else afprintf(dbOut,"------>Decl: pass %d\n", passNo);
108
109 /* Process each node in the to-do list */
110 for (; pds; pds = listFreeCons(PendingDecl)(PendingDecl_listPointer->FreeCons)(pds)) {
111 PendingDecl pd = car(pds)((pds)->first);
112
113 tidecl(pdStab(pd)((pd)->stab), pdAbSyn(pd)((pd)->absyn), pdType(pd)((pd)->type));
114 stoFree(pd);
115 }
116
117 /* Debugging */
118 tipDeclDEBUGif (!tipDeclDebug) { } else afprintf(dbOut,"<------Decl: pass %d\n", passNo);
119 }
120
121 /* Clean up and return */
122 ReturnNothing{ fluidUnwind(fluidLevel0, ((int) 0)); return;; };
123}
124
125
126/*
127 * Add all child nodes to pdPending.
128 */
129localstatic void
130tidecl(Stab stab, AbSyn absyn, TForm type)
131{
132 static int serialNo = 0, depthNo = 0;
133 int serialThis;
134 assert(absyn)do { if (!(absyn)) _do_assert(("absyn"),"ti_decl.c",134); } while
(0)
;
135
136 /* This ought to be impossible but ... */
137 if (abState(absyn)((absyn)->abHdr.state) >= AB_State_HasPoss) return;
138
139 /* Use the local stab if present */
140 if (!abIsLeaf(absyn)(((absyn)->abHdr.tag) < AB_NODE_START) && abStab(absyn)((absyn)->abHdr.seman ? (absyn)->abHdr.seman->stab :
0)
) {
141 stab = abStab(absyn)((absyn)->abHdr.seman ? (absyn)->abHdr.seman->stab :
0)
;
142 stabSeeOuterImports(stab);
143 stabGetSubstable(stab);
144 typeInferTForms(stab);
145 }
146
147 /* Stab processing might have done our job for us */
148 if (abState(absyn)((absyn)->abHdr.state) >= AB_State_HasPoss) return;
149
150 /* Debugging stuff */
151 serialNo++, depthNo++;
152 serialThis = serialNo;
Value stored to 'serialThis' is never read
153
154 /* Ignore leaf nodes */
155 if (abIsLeaf(absyn)(((absyn)->abHdr.tag) < AB_NODE_START)) return;
156
157 /* Process, ignore or add to the pending queue */
158 switch (abTag(absyn)((absyn)->abHdr.tag)) {
159 case AB_Assign: tideclAssign(stab, absyn, type); break;
160 case AB_Declare: tideclDeclare(stab, absyn, type); break;
161 case AB_Define: tideclDefine(stab, absyn, type); break;
162 default: tideclGeneric(stab, absyn, type); break;
163 }
164
165 /* More debugging stuff */
166 depthNo--;
167}
168
169localstatic void
170tideclAssign(Stab stab, AbSyn absyn, TForm type)
171{
172 PendingDecl pd;
173 AbSyn lhs = absyn->abAssign.lhs;
174 AbSyn rhs = absyn->abAssign.rhs;
175
176 /* We are interested if we have "var:Type := expr" */
177 if (abTag(lhs)((lhs)->abHdr.tag) != AB_Declare) {
178 /* Process the lhs on the next pass */
179 pd = pdNew(stab, lhs, type);
180 pdPending = listCons(PendingDecl)(PendingDecl_listPointer->Cons)(pd, pdPending);
181 }
182 else
183 tideclDeclare(stab, lhs, type);
184
185 /* The RHS is always processed on the next pass */
186 pd = pdNew(stab, rhs, type);
187 pdPending = listCons(PendingDecl)(PendingDecl_listPointer->Cons)(pd, pdPending);
188}
189
190
191localstatic void
192tideclDeclare(Stab stab, AbSyn absyn, TForm type)
193{
194 /* Debugging */
195 if (DEBUG(tipDecl)tipDeclDebug) {
196 (void)fprintf(dbOut," -->Decl: ");
197 abPrettyPrint(dbOut, absyn);
198 fnewline(dbOut);
199 }
200
201 /* Tinfer the declaration now */
202 typeInferAs(stab, absyn, type);
203}
204
205
206localstatic void
207tideclDefine(Stab stab, AbSyn absyn, TForm type)
208{
209 PendingDecl pd;
210 AbSyn lhs = absyn->abDefine.lhs;
211 AbSyn rhs = absyn->abDefine.rhs;
212
213 /* We are interested if we have "var:Type == expr" */
214 if (abTag(lhs)((lhs)->abHdr.tag) != AB_Declare) {
215 /* Process the lhs on the next pass */
216 pd = pdNew(stab, lhs, type);
217 pdPending = listCons(PendingDecl)(PendingDecl_listPointer->Cons)(pd, pdPending);
218 }
219 else
220 tideclDeclare(stab, lhs, type);
221
222 /* The RHS is always processed on the next pass */
223 pd = pdNew(stab, rhs, type);
224 pdPending = listCons(PendingDecl)(PendingDecl_listPointer->Cons)(pd, pdPending);
225}
226
227
228localstatic void
229tideclGeneric(Stab stab, AbSyn absyn, TForm type)
230{
231 Length i;
232 PendingDecl pd;
233
234 /* Add all child nodes to the pending queue */
235 if (!abIsLeaf(absyn)(((absyn)->abHdr.tag) < AB_NODE_START)) {
236 for (i = 0; i < abArgc(absyn)((absyn)->abHdr.argc); i++) {
237 pd = pdNew(stab, abArgv(absyn)((absyn)->abGen.data.argv)[i], tfUnknown);
238 pdPending = listCons(PendingDecl)(PendingDecl_listPointer->Cons)(pd, pdPending);
239 }
240 }
241}
242