]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR tree-optimization/68680 (On-stack VLA does not cause instrumentation...
authorJakub Jelinek <jakub@redhat.com>
Thu, 11 Feb 2016 09:09:58 +0000 (10:09 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 11 Feb 2016 09:09:58 +0000 (10:09 +0100)
Backported from mainline
2015-12-04  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/68680
* calls.c (special_function_p): Return ECF_MAY_BE_ALLOCA for
BUILT_IN_ALLOCA{,_WITH_ALIGN}.  Don't check for __builtin_alloca
by name.

* gcc.target/i386/pr68680.c: New test.

From-SVN: r233322

gcc/ChangeLog
gcc/calls.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/i386/pr68680.c [new file with mode: 0644]

index 7508126e52f94f0d11fe9c245dc6d96a10a42c1a..091289fb107d4eaf52e7cf2aebf135d0ad899443 100644 (file)
@@ -1,6 +1,13 @@
 2016-02-11  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2015-12-04  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/68680
+       * calls.c (special_function_p): Return ECF_MAY_BE_ALLOCA for
+       BUILT_IN_ALLOCA{,_WITH_ALIGN}.  Don't check for __builtin_alloca
+       by name.
+
        2015-11-21  Jakub Jelinek  <jakub@redhat.com>
 
        PR debug/66432
index 8ada78fba7f014f04d2c907d56a0ec192c485c8b..3cfb34446fda2e24d51971c626afcdcd7fd746aa 100644 (file)
@@ -521,12 +521,9 @@ special_function_p (const_tree fndecl, int flags)
       /* We assume that alloca will always be called by name.  It
         makes no sense to pass it as a pointer-to-function to
         anything that does not understand its behavior.  */
-      if (((IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 6
-           && name[0] == 'a'
-           && ! strcmp (name, "alloca"))
-          || (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 16
-              && name[0] == '_'
-              && ! strcmp (name, "__builtin_alloca"))))
+      if (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 6
+         && name[0] == 'a'
+         && ! strcmp (name, "alloca"))
        flags |= ECF_MAY_BE_ALLOCA;
 
       /* Disregard prefix _, __, __x or __builtin_.  */
@@ -572,6 +569,17 @@ special_function_p (const_tree fndecl, int flags)
        flags |= ECF_NORETURN;
     }
 
+  if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
+    switch (DECL_FUNCTION_CODE (fndecl))
+      {
+      case BUILT_IN_ALLOCA:
+      case BUILT_IN_ALLOCA_WITH_ALIGN:
+       flags |= ECF_MAY_BE_ALLOCA;
+       break;
+      default:
+       break;
+      }
+
   return flags;
 }
 
index 3db0586c4bfe5a1b74781e85b5612f2f96e287cc..4a724f722b08934157b5e5354a1f31c7602cbb92 100644 (file)
@@ -1,6 +1,11 @@
 2016-02-11  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2015-12-04  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/68680
+       * gcc.target/i386/pr68680.c: New test.
+
        2015-12-03  Jakub Jelinek  <jakub@redhat.com>
 
        PR preprocessor/57580
diff --git a/gcc/testsuite/gcc.target/i386/pr68680.c b/gcc/testsuite/gcc.target/i386/pr68680.c
new file mode 100644 (file)
index 0000000..5524e15
--- /dev/null
@@ -0,0 +1,15 @@
+/* PR tree-optimization/68680 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fstack-protector-strong" } */
+
+int foo (char *);
+
+int
+bar (unsigned long x)
+{
+  char a[x];
+  return foo (a);
+}
+
+/* Verify that this function is stack protected.  */
+/* { dg-final { scan-assembler "stack_chk_fail" } } */