void test_vlas (size_t num) { char str2[num]; /* { dg-warning "unbounded use" } */ useit(str2); num = 98; for (int i=0; i < 1234; ++i) { char str[num]; // OK, VLA in a loop, but it is a // known size *AND* the compiler takes // care of cleaning up between // iterations with // __builtin_stack_restore. useit(str); } }
void foo2 (__SIZE_TYPE__ len) { // Test that a direct call to __builtin_alloca_with_align is not confused // with a VLA. void *p = __builtin_alloca_with_align (len, 8); // { dg-warning "unbounded use of 'alloca'" } useit (p); }
int foobar (unsigned short length) { char *pbuf; __SIZE_TYPE__ size = (__SIZE_TYPE__) length; if (size < 4032) pbuf = (char *) __builtin_alloca(size); else pbuf = (char *) __builtin_malloc (size); useit(pbuf); return 0; }
void foo1 (size_t len, size_t len2, size_t len3) { int i; for (i=0; i < 123; ++i) { char *s = alloca (566); /* { dg-warning "'alloca' within a loop" } */ useit (s); } char *s = alloca (123); useit (s); // OK, constant argument to alloca s = alloca (num); // { dg-warning "large due to conversion" "" { target lp64 } } // { dg-warning "unbounded use of 'alloca'" "" { target { ! lp64 } } .-1 } useit (s); s = alloca (30000); /* { dg-warning "is too large" } */ useit (s); if (len < 2000) { s = alloca(len); // OK, bounded useit (s); } if (len + len2 < 2000) // OK, bounded { s = alloca(len + len2); useit (s); } if (len3 <= 2001) { s = alloca(len3); /* { dg-warning "may be too large" } */ useit(s); } }
/** * _gwy_morph_lib_itip_estimate0: * @image: Surface data. * @im_xsiz: Number of columns. * @im_ysiz: Number of rows. * @tip_xsiz: Tip number of columns. * @tip_ysiz: Tip numbe rof rows. * @xc: Tip apex column coordinate. * @yc: Tip apex row coordinate. * @tip0: Tip data to be refined. * @thresh: Threshold. * @use_edges: Whether to use also image edges. * @set_fraction: Function to output computation fraction (or %NULL). * @set_message: Functon to output computation state message (or %NULL). * * Performs partial tip estimation algorithm. * * Returns: The number of locations that produced refinement, -1 if aborted. **/ gint _gwy_morph_lib_itip_estimate0(gint **image, gint im_xsiz, gint im_ysiz, gint tip_xsiz, gint tip_ysiz, gint xc, gint yc, gint **tip0, gint thresh, gboolean use_edges, GwySetFractionFunc set_fraction, GwySetMessageFunc set_message) { gint i, j, n; gint arraysize; /* size of array allocated to store list of image maxima */ gint *x, *y; /* point to coordinates of image maxima */ gint iter = 0; gint count, sumcount; gint delta; /* defines what is meant by near neighborhood for purposes of point selection. */ gint maxcount = 20; GString *str; arraysize = 300; x = g_new(gint, arraysize); y = g_new(gint, arraysize); str = g_string_new(""); delta = MAX(MAX(tip_xsiz, tip_ysiz)/10, 1); if (set_message && !set_message(_("Searching for local maxima..."))) { g_free(x); g_free(y); return -1; } /* Create a list of coordinates to use */ n = 0; /* Number of image maxima found so far */ for (j = tip_ysiz - 1 - yc; j <= im_ysiz - 1 - yc; j++) { for (i = tip_xsiz - 1 - xc; i <= im_xsiz - 1 - xc; i++) { if (useit(i, j, image, im_xsiz, im_ysiz, delta)) { if (n == arraysize) { /* need more room in temporary arrays */ arraysize *= 2; /* increase array size by factor of 2 */ x = g_renew(gint, x, arraysize); y = g_renew(gint, y, arraysize); } x[n] = i; /* We found another one */ y[n] = j; n++; } } } g_string_printf(str, ngettext("Found one internal local maximum", "Found %d internal local maxima", n), n); if (set_message && !set_message(str->str)) { g_free(x); g_free(y); return -1; } if (set_fraction) set_fraction(0.0); /* Now refine tip at these coordinates recursively until no more change */ sumcount = 0; do { count = 0; iter++; g_string_printf(str, _("Iterating estimate (iteration %d)..."), iter); if (set_message && !set_message(str->str)) { g_free(x); g_free(y); return -1; } for (i = 0; i < n; i++) { if (itip_estimate_point(x[i], y[i], image, im_xsiz, im_ysiz, tip_xsiz, tip_ysiz, xc, yc, tip0, thresh, use_edges)) { count++; sumcount++; } if (set_fraction && !set_fraction((gdouble)i/(gdouble)n)) { g_free(x); g_free(y); return -1; } } g_string_printf(str, ngettext("One image location produced refinement", "%d image locations produced refinement", count), count); if (set_message && !set_message(str->str)) { g_free(x); g_free(y); return -1; } } while (count && count > maxcount); if (set_fraction) set_fraction(1.0); /* free temporary space */ g_string_free(str, TRUE); g_free(x); g_free(y); return sumcount; }
void foo3 (unsigned char a) { if (a == 0) useit (__builtin_alloca (a)); // { dg-warning "argument to 'alloca' is zero" } }