diff options
author | Richard Guenther <rguenther@suse.de> | 2009-03-03 13:05:53 +0000 |
---|---|---|
committer | Richard Biener <rguenth@gcc.gnu.org> | 2009-03-03 13:05:53 +0000 |
commit | 9bd9f73827bfddb9485bcc9a8a2c80d4ed5c9cd8 (patch) | |
tree | adb9abf659e3d9d8949be2fad8b9306ded1d415d | |
parent | f07049c8f1741e8a56f8e6dc3702216a652a532d (diff) | |
download | gcc-9bd9f73827bfddb9485bcc9a8a2c80d4ed5c9cd8.zip gcc-9bd9f73827bfddb9485bcc9a8a2c80d4ed5c9cd8.tar.gz gcc-9bd9f73827bfddb9485bcc9a8a2c80d4ed5c9cd8.tar.bz2 |
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
-rw-r--r-- | gcc/ChangeLog | 12 | ||||
-rw-r--r-- | gcc/builtins.c | 27 | ||||
-rw-r--r-- | gcc/expr.c | 7 | ||||
-rw-r--r-- | gcc/tree.c | 36 | ||||
-rw-r--r-- | gcc/tree.h | 1 |
5 files changed, 68 insertions, 15 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 72da01f..e71e642 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,15 @@ +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> PR tree-optimization/39343 diff --git a/gcc/builtins.c b/gcc/builtins.c index 55639cd..cc9d93e 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -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)) { - warning (0, "%Kcall to %D will always overflow destination buffer", - exp, get_callee_fndecl (exp)); + warning_at (tree_nonartificial_location (exp), + 0, "%Kcall to %D will always overflow destination buffer", + exp, get_callee_fndecl (exp)); return NULL_RTX; } @@ -12073,6 +12074,7 @@ maybe_emit_chk_warning (tree exp, enum built_in_function fcode) { int is_strlen = 0; tree len, size; + location_t loc = tree_nonartificial_location (exp); switch (fcode) { @@ -12119,8 +12121,8 @@ maybe_emit_chk_warning (tree exp, enum built_in_function fcode) src = c_strlen (src, 1); if (! src || ! host_integerp (src, 1)) { - warning (0, "%Kcall to %D might overflow destination buffer", - exp, get_callee_fndecl (exp)); + warning_at (loc, 0, "%Kcall to %D might overflow destination buffer", + exp, get_callee_fndecl (exp)); return; } else if (tree_int_cst_lt (src, size)) @@ -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)) return; - warning (0, "%Kcall to %D will always overflow destination buffer", - exp, get_callee_fndecl (exp)); + warning_at (loc, 0, "%Kcall to %D will always overflow destination buffer", + exp, get_callee_fndecl (exp)); } /* 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) return; if (! tree_int_cst_lt (len, size)) - { - warning (0, "%Kcall to %D will always overflow destination buffer", - exp, get_callee_fndecl (exp)); - } + warning_at (tree_nonartificial_location (exp), + 0, "%Kcall to %D will always overflow destination buffer", + exp, get_callee_fndecl (exp)); } /* Emit warning if a free is called with address of a variable. */ @@ -12209,9 +12210,11 @@ maybe_emit_free_warning (tree exp) return; 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 - 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, @@ -8061,9 +8061,10 @@ expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode, if (fndecl && (attr = lookup_attribute ("warning", DECL_ATTRIBUTES (fndecl))) != NULL) - warning (0, "%Kcall to %qs declared with attribute warning: %s", - exp, lang_hooks.decl_printable_name (fndecl, 1), - TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)))); + warning_at (tree_nonartificial_location (exp), + 0, "%Kcall to %qs declared with attribute warning: %s", + exp, lang_hooks.decl_printable_name (fndecl, 1), + TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)))); /* Check for a built-in function. */ if (fndecl && DECL_BUILT_IN (fndecl)) @@ -9071,6 +9071,42 @@ block_nonartificial_location (tree block) 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 nodes. */ @@ -4946,6 +4946,7 @@ extern void set_expr_locus (tree, source_location *); extern tree *tree_block (tree); extern location_t *block_nonartificial_location (tree); +extern location_t tree_nonartificial_location (tree); /* In function.c */ extern void expand_main_function (void); |