https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61886
--- Comment #18 from Jan Hubicka <hubicka at ucw dot cz> ---
Hi,
actually I can just add the location to the first argument to avoid the need
to build extra tree...
Somewhat ugly, but seems to work.
Index: internal-fn.c
===================================================================
--- internal-fn.c (revision 215958)
+++ internal-fn.c (working copy)
@@ -37,6 +37,8 @@ along with GCC; see the file COPYING3.
#include "stringpool.h"
#include "tree-ssanames.h"
#include "diagnostic-core.h"
+#include "builtins.h"
+#include "pretty-print.h"
/* The names of each internal function, indexed by function number. */
const char *const internal_fn_name_array[] = {
@@ -915,6 +917,28 @@ expand_BUILTIN_EXPECT (gimple stmt)
emit_move_insn (target, val);
}
+static void
+expand_OUTPUT_ERROR (gimple stmt)
+{
+ const char * arg0 = c_getstr (gimple_call_arg (stmt, 0));
+ const char * arg1 = c_getstr (gimple_call_arg (stmt, 1));
+ error_at (gimple_location (stmt),
+ "%KCall to %qs declared with attribute error: %s",
+ gimple_call_arg (stmt, 0),
+ arg0, identifier_to_locale (arg1));
+}
+
+static void
+expand_OUTPUT_WARNING (gimple stmt)
+{
+ const char * arg0 = c_getstr (gimple_call_arg (stmt, 0));
+ const char * arg1 = c_getstr (gimple_call_arg (stmt, 1));
+ warning_at (gimple_location (stmt),
+ 0, "%Kcall to %qs declared with attribute warning: %s",
+ gimple_call_arg (stmt, 0),
+ arg0, identifier_to_locale (arg1));
+}
+
/* Routines to expand each internal function, indexed by function number.
Each routine has the prototype:
Index: cgraphunit.c
===================================================================
--- cgraphunit.c (revision 215958)
+++ cgraphunit.c (working copy)
@@ -211,6 +211,8 @@ along with GCC; see the file COPYING3.
#include "tree-nested.h"
#include "gimplify.h"
#include "dbgcnt.h"
+#include "expr.h"
+#include "internal-fn.h"
/* Queue of cgraph nodes scheduled to be added into cgraph. This is a
secondary queue used during optimization to accommodate passes that
@@ -976,8 +978,33 @@ analyze_functions (void)
cnode->analyze ();
for (edge = cnode->callees; edge; edge = edge->next_callee)
- if (edge->callee->definition)
- enqueue_node (edge->callee);
+ {
+ tree attr, err_attr = NULL;
+ if (edge->callee->definition)
+ enqueue_node (edge->callee);
+ if ((attr = lookup_attribute ("warning",
+ DECL_ATTRIBUTES (edge->callee->decl))) != NULL
+ || (err_attr = lookup_attribute ("warning",
+ DECL_ATTRIBUTES (edge->callee->decl))))
+ {
+ gimple_stmt_iterator gsi = gsi_for_stmt (edge->call_stmt);
+ const char *arg0 = lang_hooks.decl_printable_name
(edge->callee->decl, 1);
+ const char *arg1= TREE_STRING_POINTER
+ (TREE_VALUE (TREE_VALUE (attr ? attr : err_attr)));
+ tree arg0_expr = build_string_literal (strlen (arg0), arg0);
+
+ gimple call = gimple_build_call_internal
+ (attr ? IFN_OUTPUT_WARNING : IFN_OUTPUT_ERROR, 2,
+ arg0_expr,
+ build_string_literal (strlen (arg1), arg1));
+ gsi_insert_before (&gsi, call, GSI_SAME_STMT);
+ gimple_set_location (call, gimple_location (edge->call_stmt));
+ gimple_set_block (call, gimple_block (edge->call_stmt));
+ /* Disgnostic code needs tree to pick inline stack from. */
+ SET_EXPR_LOCATION (arg0_expr, gimple_location
(edge->call_stmt));
+ TREE_SET_BLOCK (arg0_expr, gimple_block (edge->call_stmt));
+ }
+ }
if (optimize && flag_devirtualize)
{
cgraph_edge *next;
Index: builtin-types.def
===================================================================
--- builtin-types.def (revision 215958)
+++ builtin-types.def (working copy)
@@ -581,3 +581,5 @@ DEF_FUNCTION_TYPE_2 (BT_FN_VOID_VPTR_LDO
BT_VOLATILE_PTR, BT_LONGDOUBLE)
DEF_FUNCTION_TYPE_2 (BT_FN_VOID_VPTR_SIZE, BT_VOID,
BT_VOLATILE_PTR, BT_SIZE)
+DEF_FUNCTION_TYPE_2 (BT_FN_VOID_CONST_STRING_CONST_STRING,
+ BT_VOID, BT_CONST_STRING, BT_CONST_STRING)
Index: expr.c
===================================================================
--- expr.c (revision 215958)
+++ expr.c (working copy)
@@ -10346,21 +10346,7 @@ expand_expr_real_1 (tree exp, rtx target
if (CALL_EXPR_VA_ARG_PACK (exp))
error ("%Kinvalid use of %<__builtin_va_arg_pack ()%>", exp);
{
- tree fndecl = get_callee_fndecl (exp), attr;
-
- if (fndecl
- && (attr = lookup_attribute ("error",
- DECL_ATTRIBUTES (fndecl))) != NULL)
- error ("%Kcall to %qs declared with attribute error: %s",
- exp, identifier_to_locale (lang_hooks.decl_printable_name (fndecl,
1)),
- TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
- if (fndecl
- && (attr = lookup_attribute ("warning",
- DECL_ATTRIBUTES (fndecl))) != NULL)
- warning_at (tree_nonartificial_location (exp),
- 0, "%Kcall to %qs declared with attribute warning: %s",
- exp, identifier_to_locale (lang_hooks.decl_printable_name
(fndecl, 1)),
- TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
+ tree fndecl = get_callee_fndecl (exp);
/* Check for a built-in function. */
if (fndecl && DECL_BUILT_IN (fndecl))