+2018-02-28 Martin Sebor <msebor@redhat.com>
+
+ * c-c++-common/Warray-bounds-2.c: Declare helper static to avoid
+ -fpic test failures.
+ * c-c++-common/Wrestrict-2.c: Same.
+ * c-c++-common/Wstringop-truncation.c: Same.
+ * gcc.dg/Warray-bounds-22.c: Same.
+ * gcc.dg/Wstringop-overflow.c: Same.
+ * gcc.dg/attr-alloc_size-3.c (unsigned_range): Same.
+ (signed_range): Same.
+ (unsigned_anti_range): Same.
+ * gcc.dg/attr-alloc_size-4.c (unsigned_range): Same.
+ (signed_range): Same.
+ (unsigned_anti_range): Same.
+ * gcc.dg/attr-alloc_size-7.c: Same.
+ * gcc.dg/attr-alloc_size-8.c: Same.
+ * gcc.dg/builtin-alloc-size.c: Same.
+ * gcc.dg/builtin-stpncpy.c: Same.
+ * gcc.dg/builtins-nonnull.c: Same.
+ * gcc.dg/nonnull-4.c (g16_1_3_5_7_11_13): Same.
+ * gcc.dg/pr79214.c: Same.
+ * gcc.dg/tree-ssa/builtin-snprintf-warn-1.c: Same.
+ * gcc.dg/tree-ssa/builtin-snprintf-warn-2.c: Same.
+ * gcc.dg/tree-ssa/builtin-sprintf-5.c: Same.
+ * gcc.dg/tree-ssa/builtin-sprintf-warn-11.c: Same.
+ * gcc.dg/tree-ssa/builtin-sprintf-warn-12.c: Same.
+ * gcc.dg/tree-ssa/builtin-sprintf-warn-13.c: Same.
+ * gcc.dg/tree-ssa/builtin-sprintf-warn-14.c: Same.
+ * gcc.dg/tree-ssa/builtin-sprintf-warn-15.c: Same.
+ * gcc.dg/tree-ssa/builtin-sprintf-warn-19.c: Same.
+ * gcc.dg/tree-ssa/builtin-sprintf-warn-3.c: Same.
+ * gcc.dg/tree-ssa/builtin-sprintf-warn-9.c: Same.
+
2018-02-28 David Edelsohn <dje.gcc@gmail.com>
PR target/84014
/* Exercise memcpy out-of-bounds offsets with an array of known size. */
-void wrap_memcpy_src_xsize (char *d, const char *s, ptrdiff_t i, size_t n)
+static void
+wrap_memcpy_src_xsize (char *d, const char *s, ptrdiff_t i, size_t n)
{
memcpy (d, s + i, n); /* { dg-warning "offset 46 is out of the bounds \\\[0, 45] of object .ar. with type .(struct )?Array." "memcpy" } */
}
/* Exercise memcpy out-of-bounds offsets with an array of unknown size. */
-void wrap_memcpy_src_diff_max (char *d, const char *s, ptrdiff_t i, size_t n)
+static void
+wrap_memcpy_src_diff_max (char *d, const char *s, ptrdiff_t i, size_t n)
{
memcpy (d, s + i, n); /* { dg-warning "pointer overflow between offset \[0-9\]+ and size 3" "memcpy" } */
}
wrap_memcpy_src_diff_max (d, s, MAX, 3);
}
-void wrap_memcpy_dst_xsize (char *d, const char *s, ptrdiff_t i, size_t n)
+static void
+wrap_memcpy_dst_xsize (char *d, const char *s, ptrdiff_t i, size_t n)
{
memcpy (d + i, s, n); /* { dg-warning "offset 47 is out of the bounds \\\[0, 45] of object .ar1. with type .(struct )?Array." "memcpy" } */
}
sink (&ar1);
}
-void wrap_memcpy_dst_diff_max (char *d, const char *s, ptrdiff_t i, size_t n)
+static void
+wrap_memcpy_dst_diff_max (char *d, const char *s, ptrdiff_t i, size_t n)
{
memcpy (d + i, s, n); /* { dg-warning "offset -?\[0-9\]+ is out of the bounds \\\[0, 45] of object .ar2. with type .(struct )?Array." "memcpy" } */
}
}
-void wrap_strcat_src_xsize (char *d, const char *s, ptrdiff_t i)
+static void wrap_strcat_src_xsize (char *d, const char *s, ptrdiff_t i)
{
strcat (d, s + i); /* { dg-warning "offset 46 is out of the bounds \\\[0, 45] of object .ar3. with type .(struct )?Array." "strcat" } */
}
sink (&ar3);
}
-void wrap_strcat_dst_xsize (char *d, const char *s, ptrdiff_t i)
+static void wrap_strcat_dst_xsize (char *d, const char *s, ptrdiff_t i)
{
strcat (d + i, s); /* { dg-warning "offset 47 is out of the bounds \\\[0, 45] of object .ar4. with type .(struct )?Array." "strcat" } */
}
}
-void wrap_strcpy_src_xsize (char *d, const char *s, ptrdiff_t i)
+static void wrap_strcpy_src_xsize (char *d, const char *s, ptrdiff_t i)
{
strcpy (d, s + i); /* { dg-warning "offset 48 is out of the bounds \\\[0, 45] of object .ar5. with type .(struct )?Array." "strcpy" } */
}
sink (&ar5);
}
-void wrap_strcpy_dst_xsize (char *d, const char *s, ptrdiff_t i)
+static void wrap_strcpy_dst_xsize (char *d, const char *s, ptrdiff_t i)
{
strcpy (d + i, s); /* { dg-warning "offset 49 is out of the bounds \\\[0, 45] of object .ar6. with type .(struct )?Array." "strcpy" } */
}
/* Exercise strncpy out-of-bounds offsets with an array of known size. */
-void wrap_strncpy_src_xsize (char *d, const char *s, ptrdiff_t i, size_t n)
+static void
+wrap_strncpy_src_xsize (char *d, const char *s, ptrdiff_t i, size_t n)
{
strncpy (d, s + i, n); /* { dg-warning "offset 46 is out of the bounds \\\[0, 45] of object .ar7. with type '(struct )?Array." "strncpy" } */
}
/* Exercise strncpy out-of-bounds offsets with an array of unknown size. */
-void wrap_strncpy_src_diff_max (char *d, const char *s, ptrdiff_t i, size_t n)
+static void
+wrap_strncpy_src_diff_max (char *d, const char *s, ptrdiff_t i, size_t n)
{
/* Unlike in the similar call to memcpy(), there is no pointer
overflow here because the size N is not added to the source
wrap_strncpy_src_diff_max (d, s, MAX, 3);
}
-void wrap_strncpy_dst_xsize (char *d, const char *s, ptrdiff_t i, size_t n)
+static void
+wrap_strncpy_dst_xsize (char *d, const char *s, ptrdiff_t i, size_t n)
{
strncpy (d + i, s, n); /* { dg-warning "offset 47 is out of the bounds \\\[0, 45] of object .ar8. with type .(struct )?Array." "strncpy" } */
}
sink (&ar8);
}
-void wrap_strncpy_dst_diff_max (char *d, const char *s, ptrdiff_t i, size_t n)
+static void
+wrap_strncpy_dst_diff_max (char *d, const char *s, ptrdiff_t i, size_t n)
{
strncpy (d + i, s, n); /* { dg-warning "offset -\[0-9\]+ is out of the bounds \\\[0, 45] of object .ar9. with type .(struct )?Array." "strncpy" } */
}
void call_strncpy_dst_diff_max (const char *s, size_t n)
{
- struct Array ar9; /* { dg-message ".ar9. declared here" } */
+ struct Array ar9; /* { dg-message ".ar9. declared here" "strncpy" } */
sink (&ar9);
wrap_strncpy_dst_diff_max (ar9.a17, s, MAX, n);
sink (&ar9);
}
-void wrap_strncpy_dstarray_diff_neg (char *d, const char *s, ptrdiff_t i,
- size_t n)
+static void
+wrap_strncpy_dstarray_diff_neg (char *d, const char *s, ptrdiff_t i, size_t n)
{
strncpy (d + i, s, n); /* { dg-warning "offset -\[0-9\]+ is out of the bounds \\\[0, 90] of object .ar10. with type .(struct )?Array ?\\\[2]." "strncpy" } */
}
#include <string.h>
-void wrap_memcpy (void *d, const void *s, size_t n)
+static void wrap_memcpy (void *d, const void *s, size_t n)
{
memcpy (d, s, n); /* { dg-warning "source argument is the same as destination" "memcpy" } */
}
}
-void wrap_strcat (char *d, const char *s)
+static void wrap_strcat (char *d, const char *s)
{
strcat (d, s); /* { dg-warning "source argument is the same as destination" "strcat" } */
}
}
-void wrap_strcpy (char *d, const char *s)
+static void wrap_strcpy (char *d, const char *s)
{
strcpy (d, s); /* { dg-warning "source argument is the same as destination" "strcpy" } */
}
}
-void wrap_strncat (char *d, const char *s, size_t n)
+static void wrap_strncat (char *d, const char *s, size_t n)
{
strncat (d, s, n); /* { dg-warning "source argument is the same as destination" "strncat" } */
}
}
-void wrap_strncpy (char *d, const char *s, size_t n)
+static void wrap_strncpy (char *d, const char *s, size_t n)
{
strncpy (d, s, n); /* { dg-warning "source argument is the same as destination" "strncpy" } */
}
}
#endif
-extern size_t unsigned_value (void)
+static size_t unsigned_value (void)
{
extern volatile size_t unsigned_value_source;
return unsigned_value_source;
}
-size_t unsigned_range (size_t min, size_t max)
+static size_t unsigned_range (size_t min, size_t max)
{
size_t val = unsigned_value ();
return val < min || max < val ? min : val;
typedef __PTRDIFF_TYPE__ ptrdiff_t;
typedef __SIZE_TYPE__ size_t;
-extern ptrdiff_t signed_value (void)
+static ptrdiff_t signed_value (void)
{
extern volatile ptrdiff_t signed_value_source;
return signed_value_source;
}
-ptrdiff_t signed_range (ptrdiff_t min, ptrdiff_t max)
+static ptrdiff_t signed_range (ptrdiff_t min, ptrdiff_t max)
{
ptrdiff_t val = signed_value ();
return val < min || max < val ? min : val;
void sink (void*);
-extern size_t unsigned_value (void)
+static size_t unsigned_value (void)
{
extern volatile size_t unsigned_value_source;
return unsigned_value_source;
}
-size_t unsigned_range (size_t min, size_t max)
+static size_t unsigned_range (size_t min, size_t max)
{
size_t val = unsigned_value ();
return val < min || max < val ? min : val;
void* f_size_1 (size_t) ALLOC_SIZE (1);
void* f_size_2 (size_t, size_t) ALLOC_SIZE (1, 2);
-size_t
+static size_t
unsigned_range (size_t min, size_t max)
{
extern size_t random_unsigned_value (void);
return val;
}
-long long
+static long long
signed_range (long long min, long long max)
{
extern long long random_signed_value (void);
return val;
}
-size_t
+static size_t
unsigned_anti_range (size_t min, size_t max)
{
extern size_t random_unsigned_value (void);
return val;
}
-long long
-signed_anti_range (long long min, long long max)
-{
- extern long long random_signed_value (void);
- long long val = random_signed_value ();
- if (min <= val && val <= max)
- val = min - 1;
- return val;
-}
-
#define UR(min, max) unsigned_range (min, max)
#define SR(min, max) signed_range (min, max)
void* f_size_1 (size_t) ALLOC_SIZE (1);
void* f_size_2 (size_t, size_t) ALLOC_SIZE (1, 2);
-size_t
+static size_t
unsigned_range (size_t min, size_t max)
{
extern size_t random_unsigned_value (void);
return val;
}
-int
+static int
signed_range (int min, int max)
{
extern int random_signed_value (void);
return val;
}
-size_t
+static size_t
unsigned_anti_range (size_t min, size_t max)
{
extern size_t random_unsigned_value (void);
return val;
}
-int
+static int
signed_anti_range (int min, int max)
{
extern int random_signed_value (void);
void sink (void*);
-size_t maxobjsize (void)
+static size_t maxobjsize (void)
{
return MAXOBJSZ;
}
/* { dg-require-effective-target alloca } */
/* { dg-options "-O2 -Walloc-size-larger-than=123 -Walloca-larger-than=234 -Wvla-larger-than=345" } */
-#define SIZE_MAX __SIZE_MAX__
-
typedef __SIZE_TYPE__ size_t;
void sink (void*);
-size_t alloc_size_limit (void)
+static size_t alloc_size_limit (void)
{
return 123;
}
-size_t alloca_limit (void)
+static size_t alloca_limit (void)
{
return 234;
}
-size_t vla_limit (void)
+static size_t vla_limit (void)
{
return 345;
}
void sink (void*);
-unsigned size (unsigned n)
+static unsigned size (unsigned n)
{
return n;
}
size_t value (void);
-size_t range (size_t min, size_t max)
+static size_t range (size_t min, size_t max)
{
size_t val = value ();
return val < min || max < val ? min : val;
typedef struct FILE FILE;
-char* null (void)
+static char* null (void)
{
return 0;
}
void*, void*, void*, void*,
void*, void*, void*, void*);
-void* null (void) { return 0; }
+static void* null (void) { return 0; }
void test (void)
{
char d[3];
char s[4];
-size_t range (void)
+static size_t range (void)
{
extern size_t size ();
size_t n = size ();
char buffer[1024];
#define buffer(size) (buffer + sizeof buffer - size)
-int value_range (int min, int max)
+static int value_range (int min, int max)
{
extern int value (void);
int val = value ();
char buffer[1024];
#define buffer(size) (buffer + sizeof buffer - size)
-int value_range (int min, int max)
+static int value_range (int min, int max)
{
extern int value (void);
int val = value ();
ASSERT (n, expect); \
} while (0)
-int ival (int i) { return i; }
+static int ival (int i) { return i; }
/* Generate a signed int value in the specified range. */
extern int int_value (void);
extern size_t size_value (void);
-int int_range (int min, int max)
+static int int_range (int min, int max)
{
int n = int_value ();
return n < min || max < n ? min : n;
}
-size_t size_range (size_t min, size_t max)
-{
- size_t n = size_value ();
- return n < min || max < n ? min : n;
-}
-
void sink (char*, char*);
int dummy_sprintf (char*, const char*, ...);
char buffer [256];
extern char *ptr;
-int int_range (int min, int max)
+static int int_range (int min, int max)
{
extern int int_value (void);
int n = int_value ();
return n < min || max < n ? min : n;
}
-unsigned uint_range (unsigned min, unsigned max)
+static unsigned uint_range (unsigned min, unsigned max)
{
extern unsigned uint_value (void);
unsigned n = uint_value ();
char buffer [256];
extern char *ptr;
-int int_range (int min, int max)
+static int int_range (int min, int max)
{
extern int int_value (void);
int n = int_value ();
return n < min || max < n ? min : n;
}
-unsigned uint_range (unsigned min, unsigned max)
-{
- extern unsigned uint_value (void);
- unsigned n = uint_value ();
- return n < min || max < n ? min : n;
-}
-
/* Evaluate to an array of SIZE characters when non-negative, or to
a pointer to an unknown object otherwise. */
#define buffer(size) \
extern int int_value (void);
-int int_range (int min, int max)
+static int int_range (int min, int max)
{
int n = int_value ();
return n < min || max < n ? min : n;
}
-const char*
+static const char*
choose_string (const char *s1, const char *s2, const char *s3)
{
int i = int_value ();
char buffer [1024];
extern char *ptr;
-int int_range (int min, int max)
+static int int_range (int min, int max)
{
extern int int_value (void);
int n = int_value ();
return n < min || max < n ? min : n;
}
-unsigned uint_range (unsigned min, unsigned max)
-{
- extern unsigned uint_value (void);
- unsigned n = uint_value ();
- return n < min || max < n ? min : n;
-}
-
/* Evaluate to an array of SIZE characters when non-negative, or to
a pointer to an unknown object otherwise. */
#define buffer(size) \
void sink (char*);
-long long integer_range (long long min, long long max)
+static long long integer_range (long long min, long long max)
{
extern long long integer_value (void);
long long n = integer_value ();
of the operand even when it's not constant (i.e., makes use of
inlining and constant propagation information). */
-int i (int x) { return x; }
-const char* s (const char *str) { return str; }
+static int i (int x) { return x; }
+static const char* s (const char *str) { return str; }
/* Function to "generate" a unique unknown number (as far as GCC can
tell) each time it's called. It prevents the optimizer from being
avoid diagnosing the output of sufficiently constrained arguments to
integer directives. */
-signed char
+static signed char
range_schar (signed char min, signed char max)
{
signed char val = rand ();
return val < min || max < val ? min : val;
}
-unsigned char
+static unsigned char
range_uchar (unsigned char min, unsigned char max)
{
unsigned char val = rand ();
return val < min || max < val ? min : val;
}
-signed short
+static signed short
range_sshrt (signed short min, signed short max)
{
signed short val = rand ();
return val < min || max < val ? min : val;
}
-unsigned short
+static unsigned short
range_ushrt (unsigned short min, unsigned short max)
{
unsigned short val = rand ();
return val < min || max < val ? min : val;
}
-signed int
+static signed int
range_sint (signed int min, signed int max)
{
signed int val = rand ();
return val < min || max < val ? min : val;
}
-unsigned int
+static unsigned int
range_uint (unsigned int min, unsigned int max)
{
unsigned int val = rand ();
of the operand even when it's not constant (i.e., makes use of
inlining and constant propagation information). */
-int i (int x) { return x; }
-const char* s (const char *str) { return str; }
+static int i (int x) { return x; }
+static const char* s (const char *str) { return str; }
/* Function to "generate" a unique unknown number (as far as GCC can
tell) each time it's called. It prevents the optimizer from being
extern int value (void);
/* Return a value in the range [MIN, MAX]. */
-int range (int min, int max)
+static int range (int min, int max)
{
int val = value ();
return val < min || max < val ? min : val;