public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "hubicka at ucw dot cz" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug lto/61886] [4.8/4.9/5 Regression] LTO breaks fread with _FORTIFY_SOURCE=2
Date: Tue, 07 Oct 2014 05:46:00 -0000	[thread overview]
Message-ID: <bug-61886-4-H4skbcXJTq@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-61886-4@http.gcc.gnu.org/bugzilla/>

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))


  parent reply	other threads:[~2014-10-07  5:46 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-61886-4@http.gcc.gnu.org/bugzilla/>
2014-07-23 10:58 ` [Bug lto/61886] [4.8/4.9/4.10 " rguenth at gcc dot gnu.org
2014-07-23 11:13 ` rguenth at gcc dot gnu.org
2014-07-23 13:08 ` rguenth at gcc dot gnu.org
2014-07-23 13:37 ` hubicka at gcc dot gnu.org
2014-08-27 10:00 ` [Bug lto/61886] [4.8/4.9/5 " rguenth at gcc dot gnu.org
2014-08-27 14:51 ` hubicka at ucw dot cz
2014-08-28  8:20 ` rguenther at suse dot de
2014-09-08  0:42 ` hubicka at ucw dot cz
2014-09-08  7:53 ` rguenther at suse dot de
2014-10-06 20:23 ` hubicka at ucw dot cz
2014-10-06 20:34 ` jakub at redhat dot com
2014-10-06 22:08 ` jakub at redhat dot com
2014-10-06 22:19 ` hubicka at ucw dot cz
2014-10-06 22:38 ` jakub at redhat dot com
2014-10-06 22:44 ` hubicka at ucw dot cz
2014-10-07  5:46 ` hubicka at ucw dot cz [this message]
2014-10-07  9:24 ` jakub at gcc dot gnu.org
2014-10-07  9:35 ` jakub at gcc dot gnu.org
2014-10-07 19:49 ` hubicka at ucw dot cz
2014-10-08  7:37 ` rguenther at suse dot de
2014-10-08  8:25 ` jakub at gcc dot gnu.org
2014-10-08 10:42 ` rguenther at suse dot de
2014-10-08 17:49 ` hubicka at ucw dot cz
2014-12-01 12:31 ` rguenth at gcc dot gnu.org
2014-12-19 13:37 ` jakub at gcc dot gnu.org
2015-01-19 13:16 ` rguenth at gcc dot gnu.org
2015-02-11  8:29 ` rguenth at gcc dot gnu.org
2015-02-11  8:33 ` rguenth at gcc dot gnu.org
2015-02-11  9:15 ` hubicka at ucw dot cz
2015-02-11 10:05 ` rguenther at suse dot de
2015-02-11 16:30 ` zackw at panix dot com
2015-03-03 19:12 ` hubicka at gcc dot gnu.org
2015-03-20 21:00 ` hubicka at gcc dot gnu.org
2015-06-23  8:21 ` [Bug lto/61886] [4.8/4.9/5/6 " rguenth at gcc dot gnu.org
2015-06-26 20:10 ` [Bug lto/61886] [4.9/5/6 " jakub at gcc dot gnu.org
2015-06-26 20:35 ` jakub at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-61886-4-H4skbcXJTq@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).