From: Jakub Jelinek Date: Fri, 5 Jun 2009 15:35:13 +0000 (+0200) Subject: re PR middle-end/40340 (Fortification warning no longer emitted in inlines) X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9f706f23d133a3e4eb5130996461e5cfb2cb706a;p=platform%2Fupstream%2Fgcc.git 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 --- 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 + + 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 Leehod Baruch @@ -21,7 +37,7 @@ * dwarf2out.c (dwarf2out_begin_function): Mark discriminator as possibly unused. -2009-06-04 Jakub Jelinek +2009-06-05 Jakub Jelinek * 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. diff --git a/gcc/tree.c b/gcc/tree.c index 5e562a5..352c553 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -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); }