re PR tree-optimization/68680 (On-stack VLA does not cause instrumentation with ...
authorJakub Jelinek <jakub@redhat.com>
Fri, 4 Dec 2015 16:32:22 +0000 (17:32 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 4 Dec 2015 16:32:22 +0000 (17:32 +0100)
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: r231279

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

index 446e74b34682ec0b6c69860a4aafa878e7c2700c..b6ff6e162f5ba3aad7357a57db8ebe36d91fde76 100644 (file)
@@ -1,5 +1,10 @@
 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.
+
        PR tree-optimization/68671
        * tree-ssa-reassoc.c (maybe_optimize_range_tests): For basic
        blocks starting with the successor of first bb we've modified
index 6cbe01970c1f260c8b3115ecbaac69bfa4ead19f..1eb4ec7549f1b45bf03ed0bd81213012af41deef 100644 (file)
@@ -502,12 +502,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 (name_decl) == 6
-           && name[0] == 'a'
-           && ! strcmp (name, "alloca"))
-          || (IDENTIFIER_LENGTH (name_decl) == 16
-              && name[0] == '_'
-              && ! strcmp (name, "__builtin_alloca"))))
+      if (IDENTIFIER_LENGTH (name_decl) == 6
+         && name[0] == 'a'
+         && ! strcmp (name, "alloca"))
        flags |= ECF_MAY_BE_ALLOCA;
 
       /* Disregard prefix _, __, __x or __builtin_.  */
@@ -553,6 +550,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 1a037e6c1dcfbf50366a86b01938b86373d057ec..b36591a1847606d782eb4d556edaa1f5f9e86e7a 100644 (file)
@@ -1,5 +1,8 @@
 2015-12-04  Jakub Jelinek  <jakub@redhat.com>
 
+       PR tree-optimization/68680
+       * gcc.target/i386/pr68680.c: New test.
+
        PR tree-optimization/68671
        * gcc.dg/pr68671.c: New test.
 
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" } } */