Commit 9bd9f738 by Richard Guenther Committed by Richard Biener

re PR tree-optimization/39272 (-D_FORTIFY_SOURCE=2 no longer warns with new glibc headers)

2009-03-03  Richard Guenther  <rguenther@suse.de>

	PR middle-end/39272
	* tree.c (tree_nonartificial_location): New function.
	* tree.h (tree_nonartificial_location): Declare.
	* builtins.c (expand_builtin_memory_chk): Provide location
	of the call location for artificial function pieces.
	(maybe_emit_chk_warning): Likewise.
	(maybe_emit_sprintf_chk_warning): Likewise.
	(maybe_emit_free_warning): Likewise.
	* expr.c (expand_expr_real_1): Likewise.

From-SVN: r144573
parent f07049c8
2009-03-03 Richard Guenther <rguenther@suse.de>
PR middle-end/39272
* tree.c (tree_nonartificial_location): New function.
* tree.h (tree_nonartificial_location): Declare.
* builtins.c (expand_builtin_memory_chk): Provide location
of the call location for artificial function pieces.
(maybe_emit_chk_warning): Likewise.
(maybe_emit_sprintf_chk_warning): Likewise.
(maybe_emit_free_warning): Likewise.
* expr.c (expand_expr_real_1): Likewise.
2009-03-03 Jakub Jelinek <jakub@redhat.com> 2009-03-03 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/39343 PR tree-optimization/39343
......
...@@ -11965,8 +11965,9 @@ expand_builtin_memory_chk (tree exp, rtx target, enum machine_mode mode, ...@@ -11965,8 +11965,9 @@ expand_builtin_memory_chk (tree exp, rtx target, enum machine_mode mode,
if (! integer_all_onesp (size) && tree_int_cst_lt (size, len)) if (! integer_all_onesp (size) && tree_int_cst_lt (size, len))
{ {
warning (0, "%Kcall to %D will always overflow destination buffer", warning_at (tree_nonartificial_location (exp),
exp, get_callee_fndecl (exp)); 0, "%Kcall to %D will always overflow destination buffer",
exp, get_callee_fndecl (exp));
return NULL_RTX; return NULL_RTX;
} }
...@@ -12073,6 +12074,7 @@ maybe_emit_chk_warning (tree exp, enum built_in_function fcode) ...@@ -12073,6 +12074,7 @@ maybe_emit_chk_warning (tree exp, enum built_in_function fcode)
{ {
int is_strlen = 0; int is_strlen = 0;
tree len, size; tree len, size;
location_t loc = tree_nonartificial_location (exp);
switch (fcode) switch (fcode)
{ {
...@@ -12119,8 +12121,8 @@ maybe_emit_chk_warning (tree exp, enum built_in_function fcode) ...@@ -12119,8 +12121,8 @@ maybe_emit_chk_warning (tree exp, enum built_in_function fcode)
src = c_strlen (src, 1); src = c_strlen (src, 1);
if (! src || ! host_integerp (src, 1)) if (! src || ! host_integerp (src, 1))
{ {
warning (0, "%Kcall to %D might overflow destination buffer", warning_at (loc, 0, "%Kcall to %D might overflow destination buffer",
exp, get_callee_fndecl (exp)); exp, get_callee_fndecl (exp));
return; return;
} }
else if (tree_int_cst_lt (src, size)) else if (tree_int_cst_lt (src, size))
...@@ -12129,8 +12131,8 @@ maybe_emit_chk_warning (tree exp, enum built_in_function fcode) ...@@ -12129,8 +12131,8 @@ maybe_emit_chk_warning (tree exp, enum built_in_function fcode)
else if (! host_integerp (len, 1) || ! tree_int_cst_lt (size, len)) else if (! host_integerp (len, 1) || ! tree_int_cst_lt (size, len))
return; return;
warning (0, "%Kcall to %D will always overflow destination buffer", warning_at (loc, 0, "%Kcall to %D will always overflow destination buffer",
exp, get_callee_fndecl (exp)); exp, get_callee_fndecl (exp));
} }
/* Emit warning if a buffer overflow is detected at compile time /* Emit warning if a buffer overflow is detected at compile time
...@@ -12187,10 +12189,9 @@ maybe_emit_sprintf_chk_warning (tree exp, enum built_in_function fcode) ...@@ -12187,10 +12189,9 @@ maybe_emit_sprintf_chk_warning (tree exp, enum built_in_function fcode)
return; return;
if (! tree_int_cst_lt (len, size)) if (! tree_int_cst_lt (len, size))
{ warning_at (tree_nonartificial_location (exp),
warning (0, "%Kcall to %D will always overflow destination buffer", 0, "%Kcall to %D will always overflow destination buffer",
exp, get_callee_fndecl (exp)); exp, get_callee_fndecl (exp));
}
} }
/* Emit warning if a free is called with address of a variable. */ /* Emit warning if a free is called with address of a variable. */
...@@ -12209,9 +12210,11 @@ maybe_emit_free_warning (tree exp) ...@@ -12209,9 +12210,11 @@ maybe_emit_free_warning (tree exp)
return; return;
if (SSA_VAR_P (arg)) if (SSA_VAR_P (arg))
warning (0, "%Kattempt to free a non-heap object %qD", exp, arg); warning_at (tree_nonartificial_location (exp),
0, "%Kattempt to free a non-heap object %qD", exp, arg);
else else
warning (0, "%Kattempt to free a non-heap object", exp); warning_at (tree_nonartificial_location (exp),
0, "%Kattempt to free a non-heap object", exp);
} }
/* Fold a call to __builtin_object_size with arguments PTR and OST, /* Fold a call to __builtin_object_size with arguments PTR and OST,
......
...@@ -8061,9 +8061,10 @@ expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode, ...@@ -8061,9 +8061,10 @@ expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode,
if (fndecl if (fndecl
&& (attr = lookup_attribute ("warning", && (attr = lookup_attribute ("warning",
DECL_ATTRIBUTES (fndecl))) != NULL) DECL_ATTRIBUTES (fndecl))) != NULL)
warning (0, "%Kcall to %qs declared with attribute warning: %s", warning_at (tree_nonartificial_location (exp),
exp, lang_hooks.decl_printable_name (fndecl, 1), 0, "%Kcall to %qs declared with attribute warning: %s",
TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)))); exp, lang_hooks.decl_printable_name (fndecl, 1),
TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
/* Check for a built-in function. */ /* Check for a built-in function. */
if (fndecl && DECL_BUILT_IN (fndecl)) if (fndecl && DECL_BUILT_IN (fndecl))
......
...@@ -9071,6 +9071,42 @@ block_nonartificial_location (tree block) ...@@ -9071,6 +9071,42 @@ block_nonartificial_location (tree block)
return ret; return ret;
} }
/* If EXP is inlined from an __attribute__((__artificial__))
function, return the location of the original call expression. */
location_t
tree_nonartificial_location (tree exp)
{
tree block = 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);
}
/* These are the hash table functions for the hash table of OPTIMIZATION_NODEq /* These are the hash table functions for the hash table of OPTIMIZATION_NODEq
nodes. */ nodes. */
......
...@@ -4946,6 +4946,7 @@ extern void set_expr_locus (tree, source_location *); ...@@ -4946,6 +4946,7 @@ extern void set_expr_locus (tree, source_location *);
extern tree *tree_block (tree); extern tree *tree_block (tree);
extern location_t *block_nonartificial_location (tree); extern location_t *block_nonartificial_location (tree);
extern location_t tree_nonartificial_location (tree);
/* In function.c */ /* In function.c */
extern void expand_main_function (void); extern void expand_main_function (void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment