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: r148214
This commit is contained in:
Jakub Jelinek 2009-06-05 18:31:44 +02:00 committed by Jakub Jelinek
parent 3a86660fc5
commit 26c4720003
10 changed files with 162 additions and 27 deletions

View File

@ -1,3 +1,12 @@
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.
2009-06-03 Jakub Jelinek <jakub@redhat.com>
* dwarf2out.c (output_cfi_directive): Pass 1 instead of

View File

@ -1,9 +1,18 @@
2009-06-05 Jakub Jelinek <jakub@redhat.com>
PR middle-end/40340
* 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-04 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/39893
* gfortran.dg/assumed_charlen_dummy.f90: New Test.
2009-06-04 Richard Guenther <rguenther@suse.de>
PR c++/39371

View File

@ -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 } */

View File

@ -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 } */

View File

@ -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 } */

View File

@ -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 } */

View File

@ -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 } */

View File

@ -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

View File

@ -582,7 +582,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.

View File

@ -9078,32 +9078,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);
}