diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 72da01fc060..e71e642fd0e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,15 @@ +2009-03-03 Richard Guenther + + 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 PR tree-optimization/39343 diff --git a/gcc/builtins.c b/gcc/builtins.c index 55639cde728..cc9d93e2311 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, diff --git a/gcc/expr.c b/gcc/expr.c index 9eb1ae70a0d..0e8e0eeee5c 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -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)) diff --git a/gcc/tree.c b/gcc/tree.c index 423c8681cf2..d0117a0a4fe 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -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. */ diff --git a/gcc/tree.h b/gcc/tree.h index 761f4af2f77..1f70e0461ea 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -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);