diff options
author | Jakub Jelinek <jakub@redhat.com> | 2009-06-05 17:35:13 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2009-06-05 17:35:13 +0200 |
commit | 9f706f23d133a3e4eb5130996461e5cfb2cb706a (patch) | |
tree | 12a9da39bc6bfc83111af358d8b58d60dbbd2f22 | |
parent | 8f439681a9e2e7fa095868097d0e0cc331734957 (diff) | |
download | gcc-9f706f23d133a3e4eb5130996461e5cfb2cb706a.zip gcc-9f706f23d133a3e4eb5130996461e5cfb2cb706a.tar.gz gcc-9f706f23d133a3e4eb5130996461e5cfb2cb706a.tar.bz2 |
re PR middle-end/40340 (Fortification warning no longer emitted in inlines)
PR middle-end/40340
* tree-ssa-live.c (remove_unused_scope_block_p): Don't prune
inlined_function_outer_scope_p blocks for artificial inlines
even at -g0/-g1.
* tree.c (tree_nonartificial_location): Rewrite using
block_nonartificial_location.
* gcc.dg/pr40340-1.c: New test.
* gcc.dg/pr40340-2.c: New test.
* gcc.dg/pr40340-3.c: New test.
* gcc.dg/pr40340-4.c: New test.
* gcc.dg/pr40340-5.c: New test.
* gcc.dg/pr40340.h: New file.
From-SVN: r148212
-rw-r--r-- | gcc/ChangeLog | 18 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr40340-1.c | 24 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr40340-2.c | 16 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr40340-3.c | 15 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr40340-4.c | 16 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr40340-5.c | 17 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr40340.h | 31 | ||||
-rw-r--r-- | gcc/tree-ssa-live.c | 20 | ||||
-rw-r--r-- | gcc/tree.c | 30 |
9 files changed, 160 insertions, 27 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b2d2502..b06f7e4 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,19 @@ +2009-06-05 Jakub Jelinek <jakub@redhat.com> + + PR middle-end/40340 + * tree-ssa-live.c (remove_unused_scope_block_p): Don't prune + inlined_function_outer_scope_p blocks for artificial inlines + even at -g0/-g1. + * tree.c (tree_nonartificial_location): Rewrite using + block_nonartificial_location. + + * gcc.dg/pr40340-1.c: New test. + * gcc.dg/pr40340-2.c: New test. + * gcc.dg/pr40340-3.c: New test. + * gcc.dg/pr40340-4.c: New test. + * gcc.dg/pr40340-5.c: New test. + * gcc.dg/pr40340.h: New file. + 2009-06-05 Revital Eres <eres@il.ibm.com> Leehod Baruch <leehod@il.ibm.com> @@ -21,7 +37,7 @@ * dwarf2out.c (dwarf2out_begin_function): Mark discriminator as possibly unused. -2009-06-04 Jakub Jelinek <jakub@redhat.com> +2009-06-05 Jakub Jelinek <jakub@redhat.com> * config/s390/s390.c (global_not_special_regno_p): New static inline. (save_gprs): Don't tell unwinder when a global register is saved. diff --git a/gcc/testsuite/gcc.dg/pr40340-1.c b/gcc/testsuite/gcc.dg/pr40340-1.c new file mode 100644 index 0000000..aae84c6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr40340-1.c @@ -0,0 +1,24 @@ +/* PR middle-end/40340 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wall -Wno-system-headers" } */ + +#include "pr40340.h" + +static inline +__attribute__ ((always_inline)) +void +test (char *p) +{ + memset (p, 0, 6); +} + +int +main (void) +{ + char buf[4]; + test (buf); + return 0; +} + +/* { dg-warning "will always overflow destination buffer" "" { target *-*-* } 10 } */ +/* { dg-message "file included" "In file included" { target *-*-* } 0 } */ diff --git a/gcc/testsuite/gcc.dg/pr40340-2.c b/gcc/testsuite/gcc.dg/pr40340-2.c new file mode 100644 index 0000000..a0d6e084 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr40340-2.c @@ -0,0 +1,16 @@ +/* PR middle-end/40340 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wall -Wno-system-headers" } */ + +#include "pr40340.h" + +int +main (void) +{ + char buf[4]; + memset (buf, 0, 6); + return 0; +} + +/* { dg-warning "will always overflow destination buffer" "" { target *-*-* } 10 } */ +/* { dg-message "file included" "In file included" { target *-*-* } 0 } */ diff --git a/gcc/testsuite/gcc.dg/pr40340-3.c b/gcc/testsuite/gcc.dg/pr40340-3.c new file mode 100644 index 0000000..5ef09e0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr40340-3.c @@ -0,0 +1,15 @@ +/* PR middle-end/40340 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wall -Wno-system-headers" } */ + +#define TEST2 +#include "pr40340.h" + +int +main (void) +{ + test2 (); + return 0; +} + +/* { dg-bogus "will always overflow destination buffer" "" { target *-*-* } 10 } */ diff --git a/gcc/testsuite/gcc.dg/pr40340-4.c b/gcc/testsuite/gcc.dg/pr40340-4.c new file mode 100644 index 0000000..d3f020c --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr40340-4.c @@ -0,0 +1,16 @@ +/* PR middle-end/40340 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wall -Wno-system-headers -g" } */ + +#define TEST3 +#include "pr40340.h" + +int +main (void) +{ + char buf[4]; + test3 (buf); + return 0; +} + +/* { dg-bogus "will always overflow destination buffer" "" { target *-*-* } 10 } */ diff --git a/gcc/testsuite/gcc.dg/pr40340-5.c b/gcc/testsuite/gcc.dg/pr40340-5.c new file mode 100644 index 0000000..f50514c --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr40340-5.c @@ -0,0 +1,17 @@ +/* PR middle-end/40340 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wall -Wsystem-headers -g" } */ + +#define TEST3 +#include "pr40340.h" + +int +main (void) +{ + char buf[4]; + test3 (buf); + return 0; +} + +/* { dg-warning "will always overflow destination buffer" "" { target *-*-* } 10 } */ +/* { dg-message "file included" "In file included" { target *-*-* } 0 } */ diff --git a/gcc/testsuite/gcc.dg/pr40340.h b/gcc/testsuite/gcc.dg/pr40340.h new file mode 100644 index 0000000..174e076 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr40340.h @@ -0,0 +1,31 @@ +#pragma GCC system_header +typedef __SIZE_TYPE__ size_t; +extern void *memset (void *s, int c, size_t n) + __attribute__ ((nothrow, nonnull (1))); +extern inline +__attribute__ ((always_inline, artificial, gnu_inline, nothrow)) +void * +memset (void *dest, int ch, size_t len) +{ + return __builtin___memset_chk (dest, ch, len, + __builtin_object_size (dest, 0)); +} + +#ifdef TEST2 +static void +__attribute__ ((noinline)) +test2 (void) +{ + char buf[4]; + memset (buf, 0, 6); +} +#endif + +#ifdef TEST3 +static inline void +__attribute__ ((always_inline)) +test3 (char *p) +{ + memset (p, 0, 6); +} +#endif diff --git a/gcc/tree-ssa-live.c b/gcc/tree-ssa-live.c index c7366ff..a710c65 100644 --- a/gcc/tree-ssa-live.c +++ b/gcc/tree-ssa-live.c @@ -536,7 +536,25 @@ remove_unused_scope_block_p (tree scope) /* For terse debug info we can eliminate info on unused variables. */ else if (debug_info_level == DINFO_LEVEL_NONE || debug_info_level == DINFO_LEVEL_TERSE) - ; + { + /* Even for -g0/-g1 don't prune outer scopes from artificial + functions, otherwise diagnostics using tree_nonartificial_location + will not be emitted properly. */ + if (inlined_function_outer_scope_p (scope)) + { + tree ao = scope; + + while (ao + && TREE_CODE (ao) == BLOCK + && BLOCK_ABSTRACT_ORIGIN (ao) != ao) + ao = BLOCK_ABSTRACT_ORIGIN (ao); + if (ao + && TREE_CODE (ao) == FUNCTION_DECL + && DECL_DECLARED_INLINE_P (ao) + && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao))) + unused = false; + } + } else if (BLOCK_VARS (scope) || BLOCK_NUM_NONLOCALIZED_VARS (scope)) unused = false; /* See if this block is important for representation of inlined function. @@ -9224,32 +9224,12 @@ block_nonartificial_location (tree block) location_t tree_nonartificial_location (tree exp) { - tree block = TREE_BLOCK (exp); + location_t *loc = block_nonartificial_location (TREE_BLOCK (exp)); - while (block - && TREE_CODE (block) == BLOCK - && BLOCK_ABSTRACT_ORIGIN (block)) - { - tree ao = BLOCK_ABSTRACT_ORIGIN (block); - - do - { - if (TREE_CODE (ao) == FUNCTION_DECL - && DECL_DECLARED_INLINE_P (ao) - && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao))) - return BLOCK_SOURCE_LOCATION (block); - else if (TREE_CODE (ao) == BLOCK - && BLOCK_SUPERCONTEXT (ao) != ao) - ao = BLOCK_SUPERCONTEXT (ao); - else - break; - } - while (ao); - - block = BLOCK_SUPERCONTEXT (block); - } - - return EXPR_LOCATION (exp); + if (loc) + return *loc; + else + return EXPR_LOCATION (exp); } |