This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

String *-chk.c tests vs. PIC multilibs


It is sometimes useful to test PIC multilibs, as Kaveh routinely
does for his gcc-testresults@ mails.  As they show, most of the
testsuite works well with PIC, but there are a few extra failures.
This patch fixes:

FAIL: gcc.c-torture/execute/builtins/sprintf-chk.c execution,  -O1
FAIL: gcc.c-torture/execute/builtins/sprintf-chk.c execution,  -O2
FAIL: gcc.c-torture/execute/builtins/sprintf-chk.c execution,  -O3 -fomit-frame-pointer
FAIL: gcc.c-torture/execute/builtins/sprintf-chk.c execution,  -O3 -fomit-frame-pointer -funroll-loops
FAIL: gcc.c-torture/execute/builtins/sprintf-chk.c execution,  -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions
FAIL: gcc.c-torture/execute/builtins/sprintf-chk.c execution,  -O3 -g
FAIL: gcc.c-torture/execute/builtins/sprintf-chk.c execution,  -Os
FAIL: gcc.c-torture/execute/builtins/stpcpy-chk.c execution,  -O1
FAIL: gcc.c-torture/execute/builtins/stpcpy-chk.c execution,  -O2
FAIL: gcc.c-torture/execute/builtins/stpcpy-chk.c execution,  -O3 -fomit-frame-pointer
FAIL: gcc.c-torture/execute/builtins/stpcpy-chk.c execution,  -O3 -fomit-frame-pointer -funroll-loops
FAIL: gcc.c-torture/execute/builtins/stpcpy-chk.c execution,  -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions
FAIL: gcc.c-torture/execute/builtins/stpcpy-chk.c execution,  -O3 -g
FAIL: gcc.c-torture/execute/builtins/stpcpy-chk.c execution,  -Os
FAIL: gcc.c-torture/execute/builtins/strcpy-chk.c execution,  -O1
FAIL: gcc.c-torture/execute/builtins/strcpy-chk.c execution,  -O2
FAIL: gcc.c-torture/execute/builtins/strcpy-chk.c execution,  -O3 -fomit-frame-pointer
FAIL: gcc.c-torture/execute/builtins/strcpy-chk.c execution,  -O3 -fomit-frame-pointer -funroll-loops
FAIL: gcc.c-torture/execute/builtins/strcpy-chk.c execution,  -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions
FAIL: gcc.c-torture/execute/builtins/strcpy-chk.c execution,  -O3 -g
FAIL: gcc.c-torture/execute/builtins/strcpy-chk.c execution,  -Os

These tests are making sure that we can do compile-time checking of string
built-in functions if the source operand is a locally-binding char array
of undeclared bounds but known length:

const char s1[] = "123";

This doesn't work for PIC because s1 does not bind locally; it could be
overridden with an s1 of a different length.

The check works fine if s1 is declared static instead.  However, I think
we still want to test non-static s1 where possible, so this patch makes
it static only if __PIC__ && !__PIE__.

Bootstrapped & regression-tested on x86_64-linux-gnu.  Also tested with
PIC and non-PIC multilibs on i586-wrs-vxworks, where it fixes the above
failures.  OK to install?

Richard


gcc/testsuite/
	* gcc.c-torture/execute/builtins/chk.h (LOCAL): Define.
	* gcc.c-torture/execute/builtins/sprintf-chk.c (s1): Make LOCAL.
	* gcc.c-torture/execute/builtins/stpcpy-chk.c (s1): Likewise.
	* gcc.c-torture/execute/builtins/strcpy-chk.c (s1): Likewise.

Index: gcc/testsuite/gcc.c-torture/execute/builtins/chk.h
===================================================================
--- gcc/testsuite/gcc.c-torture/execute/builtins/chk.h	(revision 123084)
+++ gcc/testsuite/gcc.c-torture/execute/builtins/chk.h	(working copy)
@@ -79,3 +79,11 @@ #define __builtin_vsnprintf(dst, len, fm
 extern volatile int strncpy_disallowed, strcat_disallowed, strncat_disallowed;
 extern volatile int sprintf_disallowed, vsprintf_disallowed;
 extern volatile int snprintf_disallowed, vsnprintf_disallowed;
+
+/* A storage class that ensures that declarations bind locally.  We want
+   to test non-static declarations where we know it is safe to do so.  */
+#if __PIC__ && !__PIE__
+#define LOCAL static
+#else
+#define LOCAL
+#endif
Index: gcc/testsuite/gcc.c-torture/execute/builtins/sprintf-chk.c
===================================================================
--- gcc/testsuite/gcc.c-torture/execute/builtins/sprintf-chk.c	(revision 123084)
+++ gcc/testsuite/gcc.c-torture/execute/builtins/sprintf-chk.c	(working copy)
@@ -13,7 +13,7 @@ extern int sprintf (char *, const char *
 
 #include "chk.h"
 
-const char s1[] = "123";
+LOCAL const char s1[] = "123";
 char p[32] = "";
 char *s2 = "defg";
 char *s3 = "FGH";
Index: gcc/testsuite/gcc.c-torture/execute/builtins/stpcpy-chk.c
===================================================================
--- gcc/testsuite/gcc.c-torture/execute/builtins/stpcpy-chk.c	(revision 123084)
+++ gcc/testsuite/gcc.c-torture/execute/builtins/stpcpy-chk.c	(working copy)
@@ -11,7 +11,7 @@ extern int memcmp (const void *, const v
 
 #include "chk.h"
 
-const char s1[] = "123";
+LOCAL const char s1[] = "123";
 char p[32] = "";
 char *s2 = "defg";
 char *s3 = "FGH";
Index: gcc/testsuite/gcc.c-torture/execute/builtins/strcpy-chk.c
===================================================================
--- gcc/testsuite/gcc.c-torture/execute/builtins/strcpy-chk.c	(revision 123084)
+++ gcc/testsuite/gcc.c-torture/execute/builtins/strcpy-chk.c	(working copy)
@@ -11,7 +11,7 @@ extern int memcmp (const void *, const v
 
 #include "chk.h"
 
-const char s1[] = "123";
+LOCAL const char s1[] = "123";
 char p[32] = "";
 char *s2 = "defg";
 char *s3 = "FGH";


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]