Bug Summary

File:tools/polly/lib/External/isl/isl_reordering.c
Warning:line 218, column 7
Use of memory after it is freed

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name isl_reordering.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -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 -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-8/lib/clang/8.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/tools/polly/lib/External -I /build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External -I /build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/pet/include -I /build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/ppcg/include -I /build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/ppcg/imath -I /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/tools/polly/lib/External/ppcg -I /build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl -I /build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/include -I /build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/imath -I /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/tools/polly/lib/External/isl -I /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/tools/polly/include -I /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/tools/polly/lib/External/isl/include -I /build/llvm-toolchain-snapshot-8~svn345461/tools/polly/include -I /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/include -I /build/llvm-toolchain-snapshot-8~svn345461/include -U NDEBUG -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-8/lib/clang/8.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-comment -std=gnu99 -fconst-strings -fdebug-compilation-dir /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/tools/polly/lib/External -fdebug-prefix-map=/build/llvm-toolchain-snapshot-8~svn345461=. -ferror-limit 19 -fmessage-length 0 -stack-protector 2 -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-10-27-211344-32123-1 -x c /build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_reordering.c -faddrsig
1/*
2 * Copyright 2010 INRIA Saclay
3 *
4 * Use of this software is governed by the MIT license
5 *
6 * Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France,
7 * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod,
8 * 91893 Orsay, France
9 */
10
11#include <isl_ctx_private.h>
12#include <isl/id.h>
13#include <isl_space_private.h>
14#include <isl_reordering.h>
15
16__isl_give isl_reordering *isl_reordering_alloc(isl_ctx *ctx, int len)
17{
18 isl_reordering *exp;
19
20 exp = isl_alloc(ctx, struct isl_reordering,((struct isl_reordering *)isl_malloc_or_die(ctx, sizeof(struct
isl_reordering) + (len - 1) * sizeof(int)))
21 sizeof(struct isl_reordering) + (len - 1) * sizeof(int))((struct isl_reordering *)isl_malloc_or_die(ctx, sizeof(struct
isl_reordering) + (len - 1) * sizeof(int)))
;
22 if (!exp)
23 return NULL((void*)0);
24
25 exp->ref = 1;
26 exp->len = len;
27 exp->space = NULL((void*)0);
28
29 return exp;
30}
31
32__isl_give isl_reordering *isl_reordering_copy(__isl_keep isl_reordering *exp)
33{
34 if (!exp)
35 return NULL((void*)0);
36
37 exp->ref++;
38 return exp;
39}
40
41__isl_give isl_reordering *isl_reordering_dup(__isl_keep isl_reordering *r)
42{
43 int i;
44 isl_reordering *dup;
45
46 if (!r)
47 return NULL((void*)0);
48
49 dup = isl_reordering_alloc(isl_reordering_get_ctx(r), r->len);
50 if (!dup)
51 return NULL((void*)0);
52
53 dup->space = isl_reordering_get_space(r);
54 if (!dup->space)
55 return isl_reordering_free(dup);
56 for (i = 0; i < dup->len; ++i)
57 dup->pos[i] = r->pos[i];
58
59 return dup;
60}
61
62__isl_give isl_reordering *isl_reordering_cow(__isl_take isl_reordering *r)
63{
64 if (!r)
65 return NULL((void*)0);
66
67 if (r->ref == 1)
68 return r;
69 r->ref--;
70 return isl_reordering_dup(r);
71}
72
73__isl_null isl_reordering *isl_reordering_free(__isl_take isl_reordering *exp)
74{
75 if (!exp)
6
Taking false branch
76 return NULL((void*)0);
77
78 if (--exp->ref > 0)
7
Taking false branch
79 return NULL((void*)0);
80
81 isl_space_free(exp->space);
82 free(exp);
8
Memory is released
83 return NULL((void*)0);
84}
85
86/* Return the isl_ctx to which "r" belongs.
87 */
88isl_ctx *isl_reordering_get_ctx(__isl_keep isl_reordering *r)
89{
90 return isl_space_get_ctx(isl_reordering_peek_space(r));
91}
92
93/* Return the space of "r".
94 */
95__isl_keep isl_space *isl_reordering_peek_space(__isl_keep isl_reordering *r)
96{
97 if (!r)
98 return NULL((void*)0);
99 return r->space;
100}
101
102/* Return a copy of the space of "r".
103 */
104__isl_give isl_space *isl_reordering_get_space(__isl_keep isl_reordering *r)
105{
106 return isl_space_copy(isl_reordering_peek_space(r));
107}
108
109/* Construct a reordering that maps the parameters of "alignee"
110 * to the corresponding parameters in a new dimension specification
111 * that has the parameters of "aligner" first, followed by
112 * any remaining parameters of "alignee" that do not occur in "aligner".
113 */
114__isl_give isl_reordering *isl_parameter_alignment_reordering(
115 __isl_keep isl_space *alignee, __isl_keep isl_space *aligner)
116{
117 int i, j;
118 isl_reordering *exp;
119
120 if (!alignee || !aligner)
121 return NULL((void*)0);
122
123 exp = isl_reordering_alloc(alignee->ctx, alignee->nparam);
124 if (!exp)
125 return NULL((void*)0);
126
127 exp->space = isl_space_params(isl_space_copy(aligner));
128
129 for (i = 0; i < alignee->nparam; ++i) {
130 isl_id *id_i;
131 id_i = isl_space_get_dim_id(alignee, isl_dim_param, i);
132 if (!id_i)
133 isl_die(alignee->ctx, isl_error_invalid,do { isl_handle_error(alignee->ctx, isl_error_invalid, "cannot align unnamed parameters"
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_reordering.c"
, 134); goto error; } while (0)
134 "cannot align unnamed parameters", goto error)do { isl_handle_error(alignee->ctx, isl_error_invalid, "cannot align unnamed parameters"
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_reordering.c"
, 134); goto error; } while (0)
;
135 for (j = 0; j < aligner->nparam; ++j) {
136 isl_id *id_j;
137 id_j = isl_space_get_dim_id(aligner, isl_dim_param, j);
138 isl_id_free(id_j);
139 if (id_i == id_j)
140 break;
141 }
142 if (j < aligner->nparam) {
143 exp->pos[i] = j;
144 isl_id_free(id_i);
145 } else {
146 int pos;
147 pos = isl_space_dim(exp->space, isl_dim_param);
148 exp->space = isl_space_add_dims(exp->space,
149 isl_dim_param, 1);
150 exp->space = isl_space_set_dim_id(exp->space,
151 isl_dim_param, pos, id_i);
152 exp->pos[i] = pos;
153 }
154 }
155
156 if (!exp->space)
157 return isl_reordering_free(exp);
158 return exp;
159error:
160 isl_reordering_free(exp);
161 return NULL((void*)0);
162}
163
164__isl_give isl_reordering *isl_reordering_extend(__isl_take isl_reordering *exp,
165 unsigned extra)
166{
167 int i;
168 isl_ctx *ctx;
169 isl_space *space;
170 isl_reordering *res;
171 int offset;
172
173 if (!exp)
174 return NULL((void*)0);
175 if (extra == 0)
176 return exp;
177
178 ctx = isl_reordering_get_ctx(exp);
179 space = isl_reordering_peek_space(exp);
180 offset = isl_space_dim(space, isl_dim_all) - exp->len;
181 res = isl_reordering_alloc(ctx, exp->len + extra);
182 if (!res)
183 goto error;
184 res->space = isl_reordering_get_space(exp);
185 for (i = 0; i < exp->len; ++i)
186 res->pos[i] = exp->pos[i];
187 for (i = exp->len; i < res->len; ++i)
188 res->pos[i] = offset + i;
189
190 isl_reordering_free(exp);
191
192 return res;
193error:
194 isl_reordering_free(exp);
195 return NULL((void*)0);
196}
197
198__isl_give isl_reordering *isl_reordering_extend_space(
199 __isl_take isl_reordering *exp, __isl_take isl_space *space)
200{
201 isl_space *exp_space;
202 isl_reordering *res;
203
204 if (!exp || !space)
1
Assuming 'exp' is non-null
2
Assuming 'space' is non-null
3
Taking false branch
205 goto error;
206
207 res = isl_reordering_extend(isl_reordering_copy(exp),
208 isl_space_dim(space, isl_dim_all) - exp->len);
209 res = isl_reordering_cow(res);
210 if (!res)
4
Taking false branch
211 goto error;
212 isl_space_free(res->space);
213 exp_space = isl_reordering_peek_space(exp);
214 res->space = isl_space_replace_params(space, exp_space);
215
216 isl_reordering_free(exp);
5
Calling 'isl_reordering_free'
9
Returning; memory was released via 1st parameter
217
218 if (!res->space)
10
Use of memory after it is freed
219 return isl_reordering_free(res);
220
221 return res;
222error:
223 isl_reordering_free(exp);
224 isl_space_free(space);
225 return NULL((void*)0);
226}
227
228void isl_reordering_dump(__isl_keep isl_reordering *exp)
229{
230 int i;
231
232 isl_space_dump(exp->space);
233 for (i = 0; i < exp->len; ++i)
234 fprintf(stderrstderr, "%d -> %d; ", i, exp->pos[i]);
235 fprintf(stderrstderr, "\n");
236}