+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
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;
}
{
int is_strlen = 0;
tree len, size;
+ location_t loc = tree_nonartificial_location (exp);
switch (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))
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
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. */
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,
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))
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. */