Bug Summary

File:build/gcc/ggc-common.c
Warning:line 545, column 7
Null pointer passed to 1st parameter expecting 'nonnull'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name ggc-common.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -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 static -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/objdir/gcc -resource-dir /usr/lib64/clang/13.0.0 -D IN_GCC -D HAVE_CONFIG_H -I . -I . -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/. -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/../include -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/../libcpp/include -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/../libcody -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/../libdecnumber -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/../libdecnumber/bid -I ../libdecnumber -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/../libbacktrace -internal-isystem /usr/bin/../lib64/gcc/x86_64-suse-linux/11/../../../../include/c++/11 -internal-isystem /usr/bin/../lib64/gcc/x86_64-suse-linux/11/../../../../include/c++/11/x86_64-suse-linux -internal-isystem /usr/bin/../lib64/gcc/x86_64-suse-linux/11/../../../../include/c++/11/backward -internal-isystem /usr/lib64/clang/13.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-narrowing -Wwrite-strings -Wno-error=format-diag -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -fdeprecated-macro -fdebug-compilation-dir=/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/objdir/gcc -ferror-limit 19 -fno-rtti -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-output=plist-html -analyzer-config silence-checkers=core.NullDereference -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/objdir/clang-static-analyzer/2021-11-20-133755-20252-1/report-jkyCiy.plist -x c++ /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ggc-common.c
1/* Simple garbage collection for the GNU compiler.
2 Copyright (C) 1999-2021 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
19
20/* Generic garbage collection (GC) functions and data, not specific to
21 any particular GC implementation. */
22
23#include "config.h"
24#define INCLUDE_MALLOC_H
25#include "system.h"
26#include "coretypes.h"
27#include "timevar.h"
28#include "diagnostic-core.h"
29#include "ggc-internal.h"
30#include "hosthooks.h"
31#include "plugin.h"
32#include "options.h"
33
34/* When true, protect the contents of the identifier hash table. */
35bool ggc_protect_identifiers = true;
36
37/* Statistics about the allocation. */
38static ggc_statistics *ggc_stats;
39
40struct traversal_state;
41
42static int compare_ptr_data (const void *, const void *);
43static void relocate_ptrs (void *, void *);
44static void write_pch_globals (const struct ggc_root_tab * const *tab,
45 struct traversal_state *state);
46
47/* Maintain global roots that are preserved during GC. */
48
49/* This extra vector of dynamically registered root_tab-s is used by
50 ggc_mark_roots and gives the ability to dynamically add new GGC root
51 tables, for instance from some plugins; this vector is on the heap
52 since it is used by GGC internally. */
53typedef const struct ggc_root_tab *const_ggc_root_tab_t;
54static vec<const_ggc_root_tab_t> extra_root_vec;
55
56/* Dynamically register a new GGC root table RT. This is useful for
57 plugins. */
58
59void
60ggc_register_root_tab (const struct ggc_root_tab* rt)
61{
62 if (rt)
63 extra_root_vec.safe_push (rt);
64}
65
66/* Mark all the roots in the table RT. */
67
68static void
69ggc_mark_root_tab (const_ggc_root_tab_t rt)
70{
71 size_t i;
72
73 for ( ; rt->base != NULLnullptr; rt++)
74 for (i = 0; i < rt->nelt; i++)
75 (*rt->cb) (*(void **) ((char *)rt->base + rt->stride * i));
76}
77
78/* Iterate through all registered roots and mark each element. */
79
80void
81ggc_mark_roots (void)
82{
83 const struct ggc_root_tab *const *rt;
84 const_ggc_root_tab_t rtp, rti;
85 size_t i;
86
87 for (rt = gt_ggc_deletable_rtab; *rt; rt++)
88 for (rti = *rt; rti->base != NULLnullptr; rti++)
89 memset (rti->base, 0, rti->stride);
90
91 for (rt = gt_ggc_rtab; *rt; rt++)
92 ggc_mark_root_tab (*rt);
93
94 FOR_EACH_VEC_ELT (extra_root_vec, i, rtp)for (i = 0; (extra_root_vec).iterate ((i), &(rtp)); ++(i)
)
95 ggc_mark_root_tab (rtp);
96
97 if (ggc_protect_identifiers)
98 ggc_mark_stringpool ();
99
100 gt_clear_caches ();
101
102 if (! ggc_protect_identifiers)
103 ggc_purge_stringpool ();
104
105 /* Some plugins may call ggc_set_mark from here. */
106 invoke_plugin_callbacks (PLUGIN_GGC_MARKING, NULLnullptr);
107}
108
109/* Allocate a block of memory, then clear it. */
110void *
111ggc_internal_cleared_alloc (size_t size, void (*f)(void *), size_t s, size_t n
112 MEM_STAT_DECL)
113{
114 void *buf = ggc_internal_alloc (size, f, s, n PASS_MEM_STAT);
115 memset (buf, 0, size);
116 return buf;
117}
118
119/* Resize a block of memory, possibly re-allocating it. */
120void *
121ggc_realloc (void *x, size_t size MEM_STAT_DECL)
122{
123 void *r;
124 size_t old_size;
125
126 if (x == NULLnullptr)
127 return ggc_internal_alloc (size PASS_MEM_STAT);
128
129 old_size = ggc_get_size (x);
130
131 if (size <= old_size)
132 {
133 /* Mark the unwanted memory as unaccessible. We also need to make
134 the "new" size accessible, since ggc_get_size returns the size of
135 the pool, not the size of the individually allocated object, the
136 size which was previously made accessible. Unfortunately, we
137 don't know that previously allocated size. Without that
138 knowledge we have to lose some initialization-tracking for the
139 old parts of the object. An alternative is to mark the whole
140 old_size as reachable, but that would lose tracking of writes
141 after the end of the object (by small offsets). Discard the
142 handle to avoid handle leak. */
143 VALGRIND_DISCARD (VALGRIND_MAKE_MEM_NOACCESS ((char *) x + size,
144 old_size - size));
145 VALGRIND_DISCARD (VALGRIND_MAKE_MEM_DEFINED (x, size));
146 return x;
147 }
148
149 r = ggc_internal_alloc (size PASS_MEM_STAT);
150
151 /* Since ggc_get_size returns the size of the pool, not the size of the
152 individually allocated object, we'd access parts of the old object
153 that were marked invalid with the memcpy below. We lose a bit of the
154 initialization-tracking since some of it may be uninitialized. */
155 VALGRIND_DISCARD (VALGRIND_MAKE_MEM_DEFINED (x, old_size));
156
157 memcpy (r, x, old_size);
158
159 /* The old object is not supposed to be used anymore. */
160 ggc_free (x);
161
162 return r;
163}
164
165void *
166ggc_cleared_alloc_htab_ignore_args (size_t c ATTRIBUTE_UNUSED__attribute__ ((__unused__)),
167 size_t n ATTRIBUTE_UNUSED__attribute__ ((__unused__)))
168{
169 gcc_assert (c * n == sizeof (struct htab))((void)(!(c * n == sizeof (struct htab)) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ggc-common.c"
, 169, __FUNCTION__), 0 : 0))
;
170 return ggc_cleared_alloc<htab> ();
171}
172
173/* TODO: once we actually use type information in GGC, create a new tag
174 gt_gcc_ptr_array and use it for pointer arrays. */
175void *
176ggc_cleared_alloc_ptr_array_two_args (size_t c, size_t n)
177{
178 gcc_assert (sizeof (PTR *) == n)((void)(!(sizeof (void * *) == n) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ggc-common.c"
, 178, __FUNCTION__), 0 : 0))
;
179 return ggc_cleared_vec_alloc<PTRvoid * *> (c);
180}
181
182/* These are for splay_tree_new_ggc. */
183void *
184ggc_splay_alloc (int sz, void *nl)
185{
186 gcc_assert (!nl)((void)(!(!nl) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ggc-common.c"
, 186, __FUNCTION__), 0 : 0))
;
187 return ggc_internal_alloc (sz);
188}
189
190void
191ggc_splay_dont_free (void * x ATTRIBUTE_UNUSED__attribute__ ((__unused__)), void *nl)
192{
193 gcc_assert (!nl)((void)(!(!nl) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ggc-common.c"
, 193, __FUNCTION__), 0 : 0))
;
194}
195
196void
197ggc_print_common_statistics (FILE *stream ATTRIBUTE_UNUSED__attribute__ ((__unused__)),
198 ggc_statistics *stats)
199{
200 /* Set the pointer so that during collection we will actually gather
201 the statistics. */
202 ggc_stats = stats;
203
204 /* Then do one collection to fill in the statistics. */
205 ggc_collect ();
206
207 /* At present, we don't really gather any interesting statistics. */
208
209 /* Don't gather statistics any more. */
210 ggc_stats = NULLnullptr;
211}
212
213/* Functions for saving and restoring GCable memory to disk. */
214
215struct ptr_data
216{
217 void *obj;
218 void *note_ptr_cookie;
219 gt_note_pointers note_ptr_fn;
220 gt_handle_reorder reorder_fn;
221 size_t size;
222 void *new_addr;
223};
224
225#define POINTER_HASH(x)(hashval_t)((intptr_t)x >> 3) (hashval_t)((intptr_t)x >> 3)
226
227/* Helper for hashing saving_htab. */
228
229struct saving_hasher : free_ptr_hash <ptr_data>
230{
231 typedef void *compare_type;
232 static inline hashval_t hash (const ptr_data *);
233 static inline bool equal (const ptr_data *, const void *);
234};
235
236inline hashval_t
237saving_hasher::hash (const ptr_data *p)
238{
239 return POINTER_HASH (p->obj)(hashval_t)((intptr_t)p->obj >> 3);
240}
241
242inline bool
243saving_hasher::equal (const ptr_data *p1, const void *p2)
244{
245 return p1->obj == p2;
246}
247
248static hash_table<saving_hasher> *saving_htab;
249
250/* Register an object in the hash table. */
251
252int
253gt_pch_note_object (void *obj, void *note_ptr_cookie,
254 gt_note_pointers note_ptr_fn)
255{
256 struct ptr_data **slot;
257
258 if (obj == NULLnullptr || obj == (void *) 1)
259 return 0;
260
261 slot = (struct ptr_data **)
262 saving_htab->find_slot_with_hash (obj, POINTER_HASH (obj)(hashval_t)((intptr_t)obj >> 3), INSERT);
263 if (*slot != NULLnullptr)
264 {
265 gcc_assert ((*slot)->note_ptr_fn == note_ptr_fn((void)(!((*slot)->note_ptr_fn == note_ptr_fn && (
*slot)->note_ptr_cookie == note_ptr_cookie) ? fancy_abort (
"/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ggc-common.c"
, 266, __FUNCTION__), 0 : 0))
266 && (*slot)->note_ptr_cookie == note_ptr_cookie)((void)(!((*slot)->note_ptr_fn == note_ptr_fn && (
*slot)->note_ptr_cookie == note_ptr_cookie) ? fancy_abort (
"/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ggc-common.c"
, 266, __FUNCTION__), 0 : 0))
;
267 return 0;
268 }
269
270 *slot = XCNEW (struct ptr_data)((struct ptr_data *) xcalloc (1, sizeof (struct ptr_data)));
271 (*slot)->obj = obj;
272 (*slot)->note_ptr_fn = note_ptr_fn;
273 (*slot)->note_ptr_cookie = note_ptr_cookie;
274 if (note_ptr_fn == gt_pch_p_S)
275 (*slot)->size = strlen ((const char *)obj) + 1;
276 else
277 (*slot)->size = ggc_get_size (obj);
278 return 1;
279}
280
281/* Register an object in the hash table. */
282
283void
284gt_pch_note_reorder (void *obj, void *note_ptr_cookie,
285 gt_handle_reorder reorder_fn)
286{
287 struct ptr_data *data;
288
289 if (obj == NULLnullptr || obj == (void *) 1)
290 return;
291
292 data = (struct ptr_data *)
293 saving_htab->find_with_hash (obj, POINTER_HASH (obj)(hashval_t)((intptr_t)obj >> 3));
294 gcc_assert (data && data->note_ptr_cookie == note_ptr_cookie)((void)(!(data && data->note_ptr_cookie == note_ptr_cookie
) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ggc-common.c"
, 294, __FUNCTION__), 0 : 0))
;
295
296 data->reorder_fn = reorder_fn;
297}
298
299/* Handy state for the traversal functions. */
300
301struct traversal_state
302{
303 FILE *f;
304 struct ggc_pch_data *d;
305 size_t count;
306 struct ptr_data **ptrs;
307 size_t ptrs_i;
308};
309
310/* Callbacks for htab_traverse. */
311
312int
313ggc_call_count (ptr_data **slot, traversal_state *state)
314{
315 struct ptr_data *d = *slot;
316
317 ggc_pch_count_object (state->d, d->obj, d->size,
318 d->note_ptr_fn == gt_pch_p_S);
319 state->count++;
320 return 1;
321}
322
323int
324ggc_call_alloc (ptr_data **slot, traversal_state *state)
325{
326 struct ptr_data *d = *slot;
327
328 d->new_addr = ggc_pch_alloc_object (state->d, d->obj, d->size,
329 d->note_ptr_fn == gt_pch_p_S);
330 state->ptrs[state->ptrs_i++] = d;
331 return 1;
332}
333
334/* Callback for qsort. */
335
336static int
337compare_ptr_data (const void *p1_p, const void *p2_p)
338{
339 const struct ptr_data *const p1 = *(const struct ptr_data *const *)p1_p;
340 const struct ptr_data *const p2 = *(const struct ptr_data *const *)p2_p;
341 return (((size_t)p1->new_addr > (size_t)p2->new_addr)
342 - ((size_t)p1->new_addr < (size_t)p2->new_addr));
343}
344
345/* Callbacks for note_ptr_fn. */
346
347static void
348relocate_ptrs (void *ptr_p, void *state_p)
349{
350 void **ptr = (void **)ptr_p;
351 struct traversal_state *state ATTRIBUTE_UNUSED__attribute__ ((__unused__))
352 = (struct traversal_state *)state_p;
353 struct ptr_data *result;
354
355 if (*ptr == NULLnullptr || *ptr == (void *)1)
356 return;
357
358 result = (struct ptr_data *)
359 saving_htab->find_with_hash (*ptr, POINTER_HASH (*ptr)(hashval_t)((intptr_t)*ptr >> 3));
360 gcc_assert (result)((void)(!(result) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/ggc-common.c"
, 360, __FUNCTION__), 0 : 0))
;
361 *ptr = result->new_addr;
362}
363
364/* Write out, after relocation, the pointers in TAB. */
365static void
366write_pch_globals (const struct ggc_root_tab * const *tab,
367 struct traversal_state *state)
368{
369 const struct ggc_root_tab *const *rt;
370 const struct ggc_root_tab *rti;
371 size_t i;
372
373 for (rt = tab; *rt; rt++)
374 for (rti = *rt; rti->base != NULLnullptr; rti++)
375 for (i = 0; i < rti->nelt; i++)
376 {
377 void *ptr = *(void **)((char *)rti->base + rti->stride * i);
378 struct ptr_data *new_ptr;
379 if (ptr == NULLnullptr || ptr == (void *)1)
380 {
381 if (fwrite (&ptr, sizeof (void *), 1, state->f)
382 != 1)
383 fatal_error (input_location, "cannot write PCH file: %m");
384 }
385 else
386 {
387 new_ptr = (struct ptr_data *)
388 saving_htab->find_with_hash (ptr, POINTER_HASH (ptr)(hashval_t)((intptr_t)ptr >> 3));
389 if (fwrite (&new_ptr->new_addr, sizeof (void *), 1, state->f)
390 != 1)
391 fatal_error (input_location, "cannot write PCH file: %m");
392 }
393 }
394}
395
396/* Hold the information we need to mmap the file back in. */
397
398struct mmap_info
399{
400 size_t offset;
401 size_t size;
402 void *preferred_base;
403};
404
405/* Write out the state of the compiler to F. */
406
407void
408gt_pch_save (FILE *f)
409{
410 const struct ggc_root_tab *const *rt;
411 const struct ggc_root_tab *rti;
412 size_t i;
413 struct traversal_state state;
414 char *this_object = NULLnullptr;
1
'this_object' initialized to a null pointer value
415 size_t this_object_size = 0;
416 struct mmap_info mmi;
417 const size_t mmap_offset_alignment = host_hooks.gt_pch_alloc_granularity ();
418
419 gt_pch_save_stringpool ();
420
421 timevar_push (TV_PCH_PTR_REALLOC);
422 saving_htab = new hash_table<saving_hasher> (50000);
423
424 for (rt = gt_ggc_rtab; *rt; rt++)
2
Loop condition is false. Execution continues on line 430
425 for (rti = *rt; rti->base != NULLnullptr; rti++)
426 for (i = 0; i < rti->nelt; i++)
427 (*rti->pchw)(*(void **)((char *)rti->base + rti->stride * i));
428
429 /* Prepare the objects for writing, determine addresses and such. */
430 state.f = f;
431 state.d = init_ggc_pch ();
432 state.count = 0;
433 saving_htab->traverse <traversal_state *, ggc_call_count> (&state);
434
435 mmi.size = ggc_pch_total_size (state.d);
436
437 /* Try to arrange things so that no relocation is necessary, but
438 don't try very hard. On most platforms, this will always work,
439 and on the rest it's a lot of work to do better.
440 (The extra work goes in HOST_HOOKS_GT_PCH_GET_ADDRESS and
441 HOST_HOOKS_GT_PCH_USE_ADDRESS.) */
442 mmi.preferred_base = host_hooks.gt_pch_get_address (mmi.size, fileno (f)fileno_unlocked (f));
443 /* If the host cannot supply any suitable address for this, we are stuck. */
444 if (mmi.preferred_base == NULLnullptr)
3
Assuming the condition is false
4
Taking false branch
445 fatal_error (input_location,
446 "cannot write PCH file: required memory segment unavailable");
447
448 ggc_pch_this_base (state.d, mmi.preferred_base);
449
450 state.ptrs = XNEWVEC (struct ptr_data *, state.count)((struct ptr_data * *) xmalloc (sizeof (struct ptr_data *) * (
state.count)))
;
451 state.ptrs_i = 0;
452
453 saving_htab->traverse <traversal_state *, ggc_call_alloc> (&state);
454 timevar_pop (TV_PCH_PTR_REALLOC);
455
456 timevar_push (TV_PCH_PTR_SORT);
457 qsort (state.ptrs, state.count, sizeof (*state.ptrs), compare_ptr_data)gcc_qsort (state.ptrs, state.count, sizeof (*state.ptrs), compare_ptr_data
)
;
458 timevar_pop (TV_PCH_PTR_SORT);
459
460 /* Write out all the scalar variables. */
461 for (rt = gt_pch_scalar_rtab; *rt; rt++)
5
Loop condition is false. Execution continues on line 467
462 for (rti = *rt; rti->base != NULLnullptr; rti++)
463 if (fwrite (rti->base, rti->stride, 1, f) != 1)
464 fatal_error (input_location, "cannot write PCH file: %m");
465
466 /* Write out all the global pointers, after translation. */
467 write_pch_globals (gt_ggc_rtab, &state);
468
469 /* Pad the PCH file so that the mmapped area starts on an allocation
470 granularity (usually page) boundary. */
471 {
472 long o;
473 o = ftell (state.f) + sizeof (mmi);
474 if (o == -1)
6
Assuming the condition is false
7
Taking false branch
475 fatal_error (input_location, "cannot get position in PCH file: %m");
476 mmi.offset = mmap_offset_alignment - o % mmap_offset_alignment;
477 if (mmi.offset == mmap_offset_alignment)
8
Assuming 'mmap_offset_alignment' is not equal to field 'offset'
9
Taking false branch
478 mmi.offset = 0;
479 mmi.offset += o;
480 }
481 if (fwrite (&mmi, sizeof (mmi), 1, state.f) != 1)
10
Assuming the condition is false
11
Taking false branch
482 fatal_error (input_location, "cannot write PCH file: %m");
483 if (mmi.offset != 0
12
Assuming field 'offset' is equal to 0
484 && fseek (state.f, mmi.offset, SEEK_SET0) != 0)
485 fatal_error (input_location, "cannot write padding to PCH file: %m");
486
487 ggc_pch_prepare_write (state.d, state.f);
488
489#if defined ENABLE_VALGRIND_ANNOTATIONS && defined VALGRIND_GET_VBITS
490 vec<char> vbits = vNULL;
491#endif
492
493 /* Actually write out the objects. */
494 for (i = 0; i < state.count; i++)
13
Assuming 'i' is < field 'count'
14
Loop condition is true. Entering loop body
495 {
496 if (this_object_size < state.ptrs[i]->size)
15
Assuming 'this_object_size' is >= field 'size'
16
Taking false branch
497 {
498 this_object_size = state.ptrs[i]->size;
499 this_object = XRESIZEVAR (char, this_object, this_object_size)((char *) xrealloc ((this_object), (this_object_size)));
500 }
501#if defined ENABLE_VALGRIND_ANNOTATIONS && defined VALGRIND_GET_VBITS
502 /* obj might contain uninitialized bytes, e.g. in the trailing
503 padding of the object. Avoid warnings by making the memory
504 temporarily defined and then restoring previous state. */
505 int get_vbits = 0;
506 size_t valid_size = state.ptrs[i]->size;
507 if (__builtin_expect (RUNNING_ON_VALGRIND, 0))
508 {
509 if (vbits.length () < valid_size)
510 vbits.safe_grow (valid_size, true);
511 get_vbits = VALGRIND_GET_VBITS (state.ptrs[i]->obj,
512 vbits.address (), valid_size);
513 if (get_vbits == 3)
514 {
515 /* We assume that first part of obj is addressable, and
516 the rest is unaddressable. Find out where the boundary is
517 using binary search. */
518 size_t lo = 0, hi = valid_size;
519 while (hi > lo)
520 {
521 size_t mid = (lo + hi) / 2;
522 get_vbits = VALGRIND_GET_VBITS ((char *) state.ptrs[i]->obj
523 + mid, vbits.address (),
524 1);
525 if (get_vbits == 3)
526 hi = mid;
527 else if (get_vbits == 1)
528 lo = mid + 1;
529 else
530 break;
531 }
532 if (get_vbits == 1 || get_vbits == 3)
533 {
534 valid_size = lo;
535 get_vbits = VALGRIND_GET_VBITS (state.ptrs[i]->obj,
536 vbits.address (),
537 valid_size);
538 }
539 }
540 if (get_vbits == 1)
541 VALGRIND_DISCARD (VALGRIND_MAKE_MEM_DEFINED (state.ptrs[i]->obj,
542 state.ptrs[i]->size));
543 }
544#endif
545 memcpy (this_object, state.ptrs[i]->obj, state.ptrs[i]->size);
17
Null pointer passed to 1st parameter expecting 'nonnull'
546 if (state.ptrs[i]->reorder_fn != NULLnullptr)
547 state.ptrs[i]->reorder_fn (state.ptrs[i]->obj,
548 state.ptrs[i]->note_ptr_cookie,
549 relocate_ptrs, &state);
550 state.ptrs[i]->note_ptr_fn (state.ptrs[i]->obj,
551 state.ptrs[i]->note_ptr_cookie,
552 relocate_ptrs, &state);
553 ggc_pch_write_object (state.d, state.f, state.ptrs[i]->obj,
554 state.ptrs[i]->new_addr, state.ptrs[i]->size,
555 state.ptrs[i]->note_ptr_fn == gt_pch_p_S);
556 if (state.ptrs[i]->note_ptr_fn != gt_pch_p_S)
557 memcpy (state.ptrs[i]->obj, this_object, state.ptrs[i]->size);
558#if defined ENABLE_VALGRIND_ANNOTATIONS && defined VALGRIND_GET_VBITS
559 if (__builtin_expect (get_vbits == 1, 0))
560 {
561 (void) VALGRIND_SET_VBITS (state.ptrs[i]->obj, vbits.address (),
562 valid_size);
563 if (valid_size != state.ptrs[i]->size)
564 VALGRIND_DISCARD (VALGRIND_MAKE_MEM_NOACCESS ((char *)
565 state.ptrs[i]->obj
566 + valid_size,
567 state.ptrs[i]->size
568 - valid_size));
569 }
570#endif
571 }
572#if defined ENABLE_VALGRIND_ANNOTATIONS && defined VALGRIND_GET_VBITS
573 vbits.release ();
574#endif
575
576 ggc_pch_finish (state.d, state.f);
577 gt_pch_fixup_stringpool ();
578
579 XDELETE (state.ptrs)free ((void*) (state.ptrs));
580 XDELETE (this_object)free ((void*) (this_object));
581 delete saving_htab;
582 saving_htab = NULLnullptr;
583}
584
585/* Read the state of the compiler back in from F. */
586
587void
588gt_pch_restore (FILE *f)
589{
590 const struct ggc_root_tab *const *rt;
591 const struct ggc_root_tab *rti;
592 size_t i;
593 struct mmap_info mmi;
594 int result;
595
596 /* We are about to reload the line maps along with the rest of the PCH
597 data, which means that the (loaded) ones cannot be guaranteed to be
598 in any valid state for reporting diagnostics that happen during the
599 load. Save the current table (and use it during the loading process
600 below). */
601 class line_maps *save_line_table = line_table;
602
603 /* Delete any deletable objects. This makes ggc_pch_read much
604 faster, as it can be sure that no GCable objects remain other
605 than the ones just read in. */
606 for (rt = gt_ggc_deletable_rtab; *rt; rt++)
607 for (rti = *rt; rti->base != NULLnullptr; rti++)
608 memset (rti->base, 0, rti->stride);
609
610 /* Read in all the scalar variables. */
611 for (rt = gt_pch_scalar_rtab; *rt; rt++)
612 for (rti = *rt; rti->base != NULLnullptr; rti++)
613 if (fread (rti->base, rti->stride, 1, f) != 1)
614 fatal_error (input_location, "cannot read PCH file: %m");
615
616 /* Read in all the global pointers, in 6 easy loops. */
617 bool error_reading_pointers = false;
618 for (rt = gt_ggc_rtab; *rt; rt++)
619 for (rti = *rt; rti->base != NULLnullptr; rti++)
620 for (i = 0; i < rti->nelt; i++)
621 if (fread ((char *)rti->base + rti->stride * i,
622 sizeof (void *), 1, f) != 1)
623 error_reading_pointers = true;
624
625 /* Stash the newly read-in line table pointer - it does not point to
626 anything meaningful yet, so swap the old one back in. */
627 class line_maps *new_line_table = line_table;
628 line_table = save_line_table;
629 if (error_reading_pointers)
630 fatal_error (input_location, "cannot read PCH file: %m");
631
632 if (fread (&mmi, sizeof (mmi), 1, f) != 1)
633 fatal_error (input_location, "cannot read PCH file: %m");
634
635 result = host_hooks.gt_pch_use_address (mmi.preferred_base, mmi.size,
636 fileno (f)fileno_unlocked (f), mmi.offset);
637
638 /* We could not mmap or otherwise allocate the required memory at the
639 address needed. */
640 if (result < 0)
641 {
642 sorry_at (input_location, "PCH relocation is not yet supported");
643 /* There is no point in continuing from here, we will only end up
644 with a crashed (most likely hanging) compiler. */
645 exit (-1);
646 }
647
648 /* (0) We allocated memory, but did not mmap the file, so we need to read
649 the data in manually. (>0) Otherwise the mmap succeed for the address
650 we wanted. */
651 if (result == 0)
652 {
653 if (fseek (f, mmi.offset, SEEK_SET0) != 0
654 || fread (mmi.preferred_base, mmi.size, 1, f) != 1)
655 fatal_error (input_location, "cannot read PCH file: %m");
656 }
657 else if (fseek (f, mmi.offset + mmi.size, SEEK_SET0) != 0)
658 fatal_error (input_location, "cannot read PCH file: %m");
659
660 ggc_pch_read (f, mmi.preferred_base);
661
662 gt_pch_restore_stringpool ();
663
664 /* Barring corruption of the PCH file, the restored line table should be
665 complete and usable. */
666 line_table = new_line_table;
667}
668
669/* Default version of HOST_HOOKS_GT_PCH_GET_ADDRESS when mmap is not present.
670 Select no address whatsoever, and let gt_pch_save choose what it will with
671 malloc, presumably. */
672
673void *
674default_gt_pch_get_address (size_t size ATTRIBUTE_UNUSED__attribute__ ((__unused__)),
675 int fd ATTRIBUTE_UNUSED__attribute__ ((__unused__)))
676{
677 return NULLnullptr;
678}
679
680/* Default version of HOST_HOOKS_GT_PCH_USE_ADDRESS when mmap is not present.
681 Allocate SIZE bytes with malloc. Return 0 if the address we got is the
682 same as base, indicating that the memory has been allocated but needs to
683 be read in from the file. Return -1 if the address differs, to relocation
684 of the PCH file would be required. */
685
686int
687default_gt_pch_use_address (void *base, size_t size, int fd ATTRIBUTE_UNUSED__attribute__ ((__unused__)),
688 size_t offset ATTRIBUTE_UNUSED__attribute__ ((__unused__)))
689{
690 void *addr = xmalloc (size);
691 return (addr == base) - 1;
692}
693
694/* Default version of HOST_HOOKS_GT_PCH_GET_ADDRESS. Return the
695 alignment required for allocating virtual memory. Usually this is the
696 same as pagesize. */
697
698size_t
699default_gt_pch_alloc_granularity (void)
700{
701 return getpagesize ();
702}
703
704#if HAVE_MMAP_FILE1
705/* Default version of HOST_HOOKS_GT_PCH_GET_ADDRESS when mmap is present.
706 We temporarily allocate SIZE bytes, and let the kernel place the data
707 wherever it will. If it worked, that's our spot, if not we're likely
708 to be in trouble. */
709
710void *
711mmap_gt_pch_get_address (size_t size, int fd)
712{
713 void *ret;
714
715 ret = mmap (NULLnullptr, size, PROT_READ0x1 | PROT_WRITE0x2, MAP_PRIVATE0x02, fd, 0);
716 if (ret == (void *) MAP_FAILED((void *) -1))
717 ret = NULLnullptr;
718 else
719 munmap ((caddr_t) ret, size);
720
721 return ret;
722}
723
724/* Default version of HOST_HOOKS_GT_PCH_USE_ADDRESS when mmap is present.
725 Map SIZE bytes of FD+OFFSET at BASE. Return 1 if we succeeded at
726 mapping the data at BASE, -1 if we couldn't.
727
728 This version assumes that the kernel honors the START operand of mmap
729 even without MAP_FIXED if START through START+SIZE are not currently
730 mapped with something. */
731
732int
733mmap_gt_pch_use_address (void *base, size_t size, int fd, size_t offset)
734{
735 void *addr;
736
737 /* We're called with size == 0 if we're not planning to load a PCH
738 file at all. This allows the hook to free any static space that
739 we might have allocated at link time. */
740 if (size == 0)
741 return -1;
742
743 addr = mmap ((caddr_t) base, size, PROT_READ0x1 | PROT_WRITE0x2, MAP_PRIVATE0x02,
744 fd, offset);
745
746 return addr == base ? 1 : -1;
747}
748#endif /* HAVE_MMAP_FILE */
749
750#if !defined ENABLE_GC_CHECKING1 && !defined ENABLE_GC_ALWAYS_COLLECT
751
752/* Modify the bound based on rlimits. */
753static double
754ggc_rlimit_bound (double limit)
755{
756#if defined(HAVE_GETRLIMIT1)
757 struct rlimit rlim;
758# if defined (RLIMIT_ASRLIMIT_AS)
759 /* RLIMIT_AS is what POSIX says is the limit on mmap. Presumably
760 any OS which has RLIMIT_AS also has a working mmap that GCC will use. */
761 if (getrlimit (RLIMIT_ASRLIMIT_AS, &rlim) == 0
762 && rlim.rlim_cur != (rlim_t) RLIM_INFINITY((__rlim_t) -1)
763 && rlim.rlim_cur < limit)
764 limit = rlim.rlim_cur;
765# elif defined (RLIMIT_DATARLIMIT_DATA)
766 /* ... but some older OSs bound mmap based on RLIMIT_DATA, or we
767 might be on an OS that has a broken mmap. (Others don't bound
768 mmap at all, apparently.) */
769 if (getrlimit (RLIMIT_DATARLIMIT_DATA, &rlim) == 0
770 && rlim.rlim_cur != (rlim_t) RLIM_INFINITY((__rlim_t) -1)
771 && rlim.rlim_cur < limit
772 /* Darwin has this horribly bogus default setting of
773 RLIMIT_DATA, to 6144Kb. No-one notices because RLIMIT_DATA
774 appears to be ignored. Ignore such silliness. If a limit
775 this small was actually effective for mmap, GCC wouldn't even
776 start up. */
777 && rlim.rlim_cur >= 8 * ONE_M(1024 * 1024))
778 limit = rlim.rlim_cur;
779# endif /* RLIMIT_AS or RLIMIT_DATA */
780#endif /* HAVE_GETRLIMIT */
781
782 return limit;
783}
784
785/* Heuristic to set a default for GGC_MIN_EXPAND. */
786static int
787ggc_min_expand_heuristic (void)
788{
789 double min_expand = physmem_total ();
790
791 /* Adjust for rlimits. */
792 min_expand = ggc_rlimit_bound (min_expand);
793
794 /* The heuristic is a percentage equal to 30% + 70%*(RAM/1GB), yielding
795 a lower bound of 30% and an upper bound of 100% (when RAM >= 1GB). */
796 min_expand /= ONE_G(1024 * (1024 * 1024));
797 min_expand *= 70;
798 min_expand = MIN (min_expand, 70)((min_expand) < (70) ? (min_expand) : (70));
799 min_expand += 30;
800
801 return min_expand;
802}
803
804/* Heuristic to set a default for GGC_MIN_HEAPSIZE. */
805static int
806ggc_min_heapsize_heuristic (void)
807{
808 double phys_kbytes = physmem_total ();
809 double limit_kbytes = ggc_rlimit_bound (phys_kbytes * 2);
810
811 phys_kbytes /= ONE_K1024; /* Convert to Kbytes. */
812 limit_kbytes /= ONE_K1024;
813
814 /* The heuristic is RAM/8, with a lower bound of 4M and an upper
815 bound of 128M (when RAM >= 1GB). */
816 phys_kbytes /= 8;
817
818#if defined(HAVE_GETRLIMIT1) && defined (RLIMIT_RSS__RLIMIT_RSS)
819 /* Try not to overrun the RSS limit while doing garbage collection.
820 The RSS limit is only advisory, so no margin is subtracted. */
821 {
822 struct rlimit rlim;
823 if (getrlimit (RLIMIT_RSS__RLIMIT_RSS, &rlim) == 0
824 && rlim.rlim_cur != (rlim_t) RLIM_INFINITY((__rlim_t) -1))
825 phys_kbytes = MIN (phys_kbytes, rlim.rlim_cur / ONE_K)((phys_kbytes) < (rlim.rlim_cur / 1024) ? (phys_kbytes) : (
rlim.rlim_cur / 1024))
;
826 }
827# endif
828
829 /* Don't blindly run over our data limit; do GC at least when the
830 *next* GC would be within 20Mb of the limit or within a quarter of
831 the limit, whichever is larger. If GCC does hit the data limit,
832 compilation will fail, so this tries to be conservative. */
833 limit_kbytes = MAX (0, limit_kbytes - MAX (limit_kbytes / 4, 20 * ONE_K))((0) > (limit_kbytes - ((limit_kbytes / 4) > (20 * 1024
) ? (limit_kbytes / 4) : (20 * 1024))) ? (0) : (limit_kbytes -
((limit_kbytes / 4) > (20 * 1024) ? (limit_kbytes / 4) : (
20 * 1024))))
;
834 limit_kbytes = (limit_kbytes * 100) / (110 + ggc_min_expand_heuristic ());
835 phys_kbytes = MIN (phys_kbytes, limit_kbytes)((phys_kbytes) < (limit_kbytes) ? (phys_kbytes) : (limit_kbytes
))
;
836
837 phys_kbytes = MAX (phys_kbytes, 4 * ONE_K)((phys_kbytes) > (4 * 1024) ? (phys_kbytes) : (4 * 1024));
838 phys_kbytes = MIN (phys_kbytes, 128 * ONE_K)((phys_kbytes) < (128 * 1024) ? (phys_kbytes) : (128 * 1024
))
;
839
840 return phys_kbytes;
841}
842#endif
843
844void
845init_ggc_heuristics (void)
846{
847#if !defined ENABLE_GC_CHECKING1 && !defined ENABLE_GC_ALWAYS_COLLECT
848 param_ggc_min_expandglobal_options.x_param_ggc_min_expand = ggc_min_expand_heuristic ();
849 param_ggc_min_heapsizeglobal_options.x_param_ggc_min_heapsize = ggc_min_heapsize_heuristic ();
850#endif
851}
852
853/* GGC memory usage. */
854class ggc_usage: public mem_usage
855{
856public:
857 /* Default constructor. */
858 ggc_usage (): m_freed (0), m_collected (0), m_overhead (0) {}
859 /* Constructor. */
860 ggc_usage (size_t allocated, size_t times, size_t peak,
861 size_t freed, size_t collected, size_t overhead)
862 : mem_usage (allocated, times, peak),
863 m_freed (freed), m_collected (collected), m_overhead (overhead) {}
864
865 /* Equality operator. */
866 inline bool
867 operator== (const ggc_usage &second) const
868 {
869 return (get_balance () == second.get_balance ()
870 && m_peak == second.m_peak
871 && m_times == second.m_times);
872 }
873
874 /* Comparison operator. */
875 inline bool
876 operator< (const ggc_usage &second) const
877 {
878 if (*this == second)
879 return false;
880
881 return (get_balance () == second.get_balance () ?
882 (m_peak == second.m_peak ? m_times < second.m_times
883 : m_peak < second.m_peak)
884 : get_balance () < second.get_balance ());
885 }
886
887 /* Register overhead of ALLOCATED and OVERHEAD bytes. */
888 inline void
889 register_overhead (size_t allocated, size_t overhead)
890 {
891 m_allocated += allocated;
892 m_overhead += overhead;
893 m_times++;
894 }
895
896 /* Release overhead of SIZE bytes. */
897 inline void
898 release_overhead (size_t size)
899 {
900 m_freed += size;
901 }
902
903 /* Sum the usage with SECOND usage. */
904 ggc_usage
905 operator+ (const ggc_usage &second)
906 {
907 return ggc_usage (m_allocated + second.m_allocated,
908 m_times + second.m_times,
909 m_peak + second.m_peak,
910 m_freed + second.m_freed,
911 m_collected + second.m_collected,
912 m_overhead + second.m_overhead);
913 }
914
915 /* Dump usage with PREFIX, where TOTAL is sum of all rows. */
916 inline void
917 dump (const char *prefix, ggc_usage &total) const
918 {
919 size_t balance = get_balance ();
920 fprintf (stderrstderr,
921 "%-48s " PRsa (9)"%" "9" "l" "u" "%c" ":%5.1f%%" PRsa (9)"%" "9" "l" "u" "%c" ":%5.1f%%"
922 PRsa (9)"%" "9" "l" "u" "%c" ":%5.1f%%" PRsa (9)"%" "9" "l" "u" "%c" ":%5.1f%%" PRsa (9)"%" "9" "l" "u" "%c" "\n",
923 prefix,
924 SIZE_AMOUNT (balance)(uint64_t)(((balance) < 10 * 1024 ? (balance) : ((balance)
< 10 * (1024 * 1024) ? (balance) / 1024 : (balance) / (1024
* 1024)))), ((balance) < 10 * 1024 ? ' ' : ((balance) <
10 * (1024 * 1024) ? 'k' : 'M'))
, get_percent (balance, total.get_balance ()),
925 SIZE_AMOUNT (m_collected)(uint64_t)(((m_collected) < 10 * 1024 ? (m_collected) : ((
m_collected) < 10 * (1024 * 1024) ? (m_collected) / 1024 :
(m_collected) / (1024 * 1024)))), ((m_collected) < 10 * 1024
? ' ' : ((m_collected) < 10 * (1024 * 1024) ? 'k' : 'M'))
,
926 get_percent (m_collected, total.m_collected),
927 SIZE_AMOUNT (m_freed)(uint64_t)(((m_freed) < 10 * 1024 ? (m_freed) : ((m_freed)
< 10 * (1024 * 1024) ? (m_freed) / 1024 : (m_freed) / (1024
* 1024)))), ((m_freed) < 10 * 1024 ? ' ' : ((m_freed) <
10 * (1024 * 1024) ? 'k' : 'M'))
, get_percent (m_freed, total.m_freed),
928 SIZE_AMOUNT (m_overhead)(uint64_t)(((m_overhead) < 10 * 1024 ? (m_overhead) : ((m_overhead
) < 10 * (1024 * 1024) ? (m_overhead) / 1024 : (m_overhead
) / (1024 * 1024)))), ((m_overhead) < 10 * 1024 ? ' ' : ((
m_overhead) < 10 * (1024 * 1024) ? 'k' : 'M'))
,
929 get_percent (m_overhead, total.m_overhead),
930 SIZE_AMOUNT (m_times)(uint64_t)(((m_times) < 10 * 1024 ? (m_times) : ((m_times)
< 10 * (1024 * 1024) ? (m_times) / 1024 : (m_times) / (1024
* 1024)))), ((m_times) < 10 * 1024 ? ' ' : ((m_times) <
10 * (1024 * 1024) ? 'k' : 'M'))
);
931 }
932
933 /* Dump usage coupled to LOC location, where TOTAL is sum of all rows. */
934 inline void
935 dump (mem_location *loc, ggc_usage &total) const
936 {
937 char *location_string = loc->to_string ();
938
939 dump (location_string, total);
940
941 free (location_string);
942 }
943
944 /* Dump footer. */
945 inline void
946 dump_footer ()
947 {
948 dump ("Total", *this);
949 }
950
951 /* Get balance which is GGC allocation leak. */
952 inline size_t
953 get_balance () const
954 {
955 return m_allocated + m_overhead - m_collected - m_freed;
956 }
957
958 typedef std::pair<mem_location *, ggc_usage *> mem_pair_t;
959
960 /* Compare wrapper used by qsort method. */
961 static int
962 compare (const void *first, const void *second)
963 {
964 const mem_pair_t mem1 = *(const mem_pair_t *) first;
965 const mem_pair_t mem2 = *(const mem_pair_t *) second;
966
967 size_t balance1 = mem1.second->get_balance ();
968 size_t balance2 = mem2.second->get_balance ();
969
970 return balance1 == balance2 ? 0 : (balance1 < balance2 ? 1 : -1);
971 }
972
973 /* Dump header with NAME. */
974 static inline void
975 dump_header (const char *name)
976 {
977 fprintf (stderrstderr, "%-48s %11s%17s%17s%16s%17s\n", name, "Leak", "Garbage",
978 "Freed", "Overhead", "Times");
979 }
980
981 /* Freed memory in bytes. */
982 size_t m_freed;
983 /* Collected memory in bytes. */
984 size_t m_collected;
985 /* Overhead memory in bytes. */
986 size_t m_overhead;
987};
988
989/* GCC memory description. */
990static mem_alloc_description<ggc_usage> ggc_mem_desc;
991
992/* Dump per-site memory statistics. */
993
994void
995dump_ggc_loc_statistics ()
996{
997 if (! GATHER_STATISTICS0)
998 return;
999
1000 ggc_collect (GGC_COLLECT_FORCE);
1001
1002 ggc_mem_desc.dump (GGC_ORIGIN);
1003}
1004
1005/* Record ALLOCATED and OVERHEAD bytes to descriptor NAME:LINE (FUNCTION). */
1006void
1007ggc_record_overhead (size_t allocated, size_t overhead, void *ptr MEM_STAT_DECL)
1008{
1009 ggc_usage *usage = ggc_mem_desc.register_descriptor (ptr, GGC_ORIGIN, false
1010 FINAL_PASS_MEM_STAT, 0,0,0);
1011
1012 ggc_mem_desc.register_object_overhead (usage, allocated + overhead, ptr);
1013 usage->register_overhead (allocated, overhead);
1014}
1015
1016/* Notice that the pointer has been freed. */
1017void
1018ggc_free_overhead (void *ptr)
1019{
1020 ggc_mem_desc.release_object_overhead (ptr);
1021}
1022
1023/* After live values has been marked, walk all recorded pointers and see if
1024 they are still live. */
1025void
1026ggc_prune_overhead_list (void)
1027{
1028 typedef hash_map<const void *, std::pair<ggc_usage *, size_t > > map_t;
1029
1030 map_t::iterator it = ggc_mem_desc.m_reverse_object_map->begin ();
1031
1032 for (; it != ggc_mem_desc.m_reverse_object_map->end (); ++it)
1033 if (!ggc_marked_p ((*it).first))
1034 {
1035 (*it).second.first->m_collected += (*it).second.second;
1036 ggc_mem_desc.m_reverse_object_map->remove ((*it).first);
1037 }
1038}
1039
1040/* Print memory used by heap if this info is available. */
1041
1042void
1043report_heap_memory_use ()
1044{
1045#if defined(HAVE_MALLINFO1) || defined(HAVE_MALLINFO21)
1046#ifdef HAVE_MALLINFO21
1047 #define MALLINFO_FNmallinfo2 mallinfo2
1048#else
1049 #define MALLINFO_FNmallinfo2 mallinfo
1050#endif
1051 if (!quiet_flagglobal_options.x_quiet_flag)
1052 fprintf (stderrstderr, " {heap " PRsa (0)"%" "0" "l" "u" "%c" "}",
1053 SIZE_AMOUNT (MALLINFO_FN ().arena)(uint64_t)(((mallinfo2 ().arena) < 10 * 1024 ? (mallinfo2 (
).arena) : ((mallinfo2 ().arena) < 10 * (1024 * 1024) ? (mallinfo2
().arena) / 1024 : (mallinfo2 ().arena) / (1024 * 1024)))), (
(mallinfo2 ().arena) < 10 * 1024 ? ' ' : ((mallinfo2 ().arena
) < 10 * (1024 * 1024) ? 'k' : 'M'))
);
1054#endif
1055}