From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13713 invoked by alias); 7 Oct 2014 05:46:47 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 13625 invoked by uid 55); 7 Oct 2014 05:46:40 -0000 From: "hubicka at ucw dot cz" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: lto X-Bugzilla-Version: 4.9.1 X-Bugzilla-Keywords: diagnostic, lto, wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: hubicka at ucw dot cz X-Bugzilla-Status: ASSIGNED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: hubicka at gcc dot gnu.org X-Bugzilla-Target-Milestone: 4.8.4 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-10/txt/msg00440.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61886 --- Comment #18 from Jan Hubicka --- 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))