From: Jakub Jelinek Date: Thu, 11 Feb 2016 09:09:58 +0000 (+0100) Subject: backport: re PR tree-optimization/68680 (On-stack VLA does not cause instrumentation... X-Git-Tag: releases/gcc-4.9.4~342 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f5dd203e0ee48d1e0e57eab25d8aad0f2206504;p=thirdparty%2Fgcc.git backport: re PR tree-optimization/68680 (On-stack VLA does not cause instrumentation with -fstack-protector) Backported from mainline 2015-12-04 Jakub Jelinek 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7508126e52f9..091289fb107d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,6 +1,13 @@ 2016-02-11 Jakub Jelinek Backported from mainline + 2015-12-04 Jakub Jelinek + + 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 PR debug/66432 diff --git a/gcc/calls.c b/gcc/calls.c index 8ada78fba7f0..3cfb34446fda 100644 --- a/gcc/calls.c +++ b/gcc/calls.c @@ -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; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3db0586c4bfe..4a724f722b08 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,6 +1,11 @@ 2016-02-11 Jakub Jelinek Backported from mainline + 2015-12-04 Jakub Jelinek + + PR tree-optimization/68680 + * gcc.target/i386/pr68680.c: New test. + 2015-12-03 Jakub Jelinek 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 index 000000000000..5524e156362e --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr68680.c @@ -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" } } */