Bug 57548 - calling gnu multiversioned function at file scope causes ICE
Summary: calling gnu multiversioned function at file scope causes ICE
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: 4.9.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-06 20:10 UTC by mib.bugzilla
Modified: 2013-08-02 17:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description mib.bugzilla 2013-06-06 20:10:35 UTC
/rdrive/ref/gcc/bin/g++48 -c mv1.cpp
mv1.cpp:28:13: internal compiler error: Segmentation fault
 int j = fum();
             ^
0x84eaa07 crash_signal
        /rusers/sys_cron/grab_gcc/downloads_rel/4.8.1/gcc-4.8.1/gcc/toplev.c:332
0x868bd44 ix86_can_inline_p
        /rusers/sys_cron/grab_gcc/downloads_rel/4.8.1/gcc-4.8.1/gcc/config/i386/i386.c:4498
0x8102760 build_over_call
        /rusers/sys_cron/grab_gcc/downloads_rel/4.8.1/gcc-4.8.1/gcc/cp/call.c:7044
0x8106154 build_new_function_call(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool, int)
        /rusers/sys_cron/grab_gcc/downloads_rel/4.8.1/gcc-4.8.1/gcc/cp/call.c:3918
0x81bbdef finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool, bool, int)
        /rusers/sys_cron/grab_gcc/downloads_rel/4.8.1/gcc-4.8.1/gcc/cp/semantics.c:2220
0x8176dd7 cp_parser_postfix_expression
        /rusers/sys_cron/grab_gcc/downloads_rel/4.8.1/gcc-4.8.1/gcc/cp/parser.c:5855
0x8178a82 cp_parser_unary_expression
        /rusers/sys_cron/grab_gcc/downloads_rel/4.8.1/gcc-4.8.1/gcc/cp/parser.c:6729
0x8179532 cp_parser_binary_expression
        /rusers/sys_cron/grab_gcc/downloads_rel/4.8.1/gcc-4.8.1/gcc/cp/parser.c:7421
0x8179ab0 cp_parser_assignment_expression
        /rusers/sys_cron/grab_gcc/downloads_rel/4.8.1/gcc-4.8.1/gcc/cp/parser.c:7657
0x8179f29 cp_parser_assignment_expression
        /rusers/sys_cron/grab_gcc/downloads_rel/4.8.1/gcc-4.8.1/gcc/cp/parser.c:7707
0x8179f29 cp_parser_constant_expression
        /rusers/sys_cron/grab_gcc/downloads_rel/4.8.1/gcc-4.8.1/gcc/cp/parser.c:7917
0x818303a cp_parser_init_declarator
        /rusers/sys_cron/grab_gcc/downloads_rel/4.8.1/gcc-4.8.1/gcc/cp/parser.c:16095
0x8184d49 cp_parser_simple_declaration
        /rusers/sys_cron/grab_gcc/downloads_rel/4.8.1/gcc-4.8.1/gcc/cp/parser.c:10670
0x81726d6 cp_parser_block_declaration
        /rusers/sys_cron/grab_gcc/downloads_rel/4.8.1/gcc-4.8.1/gcc/cp/parser.c:10551
0x818c2b4 cp_parser_declaration
        /rusers/sys_cron/grab_gcc/downloads_rel/4.8.1/gcc-4.8.1/gcc/cp/parser.c:10448
0x818c676 cp_parser_declaration_seq_opt
        /rusers/sys_cron/grab_gcc/downloads_rel/4.8.1/gcc-4.8.1/gcc/cp/parser.c:10334
0x818cac4 cp_parser_translation_unit
        /rusers/sys_cron/grab_gcc/downloads_rel/4.8.1/gcc-4.8.1/gcc/cp/parser.c:3813
0x818cac4 c_parse_file()
        /rusers/sys_cron/grab_gcc/downloads_rel/4.8.1/gcc-4.8.1/gcc/cp/parser.c:28338
0x8227d5a c_common_parse_file()
        /rusers/sys_cron/grab_gcc/downloads_rel/4.8.1/gcc-4.8.1/gcc/c-family/c-opts.c:1046
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions. 

Test case:

int fum (); // Extra declaration that is merged with the second one.
int fum () __attribute__ ((target("default")));

#if 0
// gcc doesn't recognize cmov
int fum () __attribute__((target( "cmov")));
#endif
int fum () __attribute__((target( "mmx")));
int fum () __attribute__((target( "popcnt")));
int fum () __attribute__((target( "sse")));
int fum () __attribute__((target( "sse2")));
int fum () __attribute__((target( "sse3")));
int fum () __attribute__((target( "ssse3")));
int fum () __attribute__((target( "sse4.1")));
int fum () __attribute__((target( "sse4.2")));
int fum () __attribute__((target( "avx")));
int fum () __attribute__((target( "avx2")));

int fum () __attribute__((target("arch=core2")));
int fum () __attribute__((target("arch=corei7")));
int fum () __attribute__((target("arch=atom")));

int (*p)() = &fum;


int j = fum();
Comment 1 Sriraman Tallam 2013-06-07 18:17:18 UTC
Patch proposed to fix this problem:

The problem here is that the caller to fum not from a function and  current_function_decl is NULL when processing the
call.  The simple fix in call.c to check current_function_decl before
calling can_inline_p target hook.

	* cp/call.c (build_over_call):  Check if current_function_decl is
	NULL.
	* testsuite/g++.dg/ext/pr57548.C: New test.


Index: cp/call.c
===================================================================
--- cp/call.c	(revision 199662)
+++ cp/call.c	(working copy)
@@ -7053,7 +7053,8 @@ build_over_call (struct z_candidate *cand, int fla
      otherwise the call should go through the dispatcher.  */
 
   if (DECL_FUNCTION_VERSIONED (fn)
-      && !targetm.target_option.can_inline_p (current_function_decl, fn))
+      && (current_function_decl == NULL
+	  || !targetm.target_option.can_inline_p (current_function_decl, fn)))
     {
       fn = get_function_version_dispatcher (fn);
       if (fn == NULL)
Index: testsuite/g++.dg/ext/pr57548.C
===================================================================
--- testsuite/g++.dg/ext/pr57548.C	(revision 0)
+++ testsuite/g++.dg/ext/pr57548.C	(revision 0)
@@ -0,0 +1,25 @@
+/* { dg-do compile { target i?86-*-* x86_64-*-* } } */
+/* { dg-require-ifunc "" }  */
+
+int fum (); // Extra declaration that is merged with the second one.
+int fum () __attribute__ ((target("default")));
+
+
+int fum () __attribute__((target( "mmx")));
+int fum () __attribute__((target( "popcnt")));
+int fum () __attribute__((target( "sse")));
+int fum () __attribute__((target( "sse2")));
+int fum () __attribute__((target( "sse3")));
+int fum () __attribute__((target( "ssse3")));
+int fum () __attribute__((target( "sse4.1")));
+int fum () __attribute__((target( "sse4.2")));
+int fum () __attribute__((target( "avx")));
+int fum () __attribute__((target( "avx2")));
+
+int fum () __attribute__((target("arch=core2")));
+int fum () __attribute__((target("arch=corei7")));
+int fum () __attribute__((target("arch=atom")));
+
+int (*p)() = &fum;
+
+int j = fum();
Comment 2 Paolo Carlini 2013-08-02 16:40:42 UTC
What happened to the patch?
Comment 3 Sriraman Tallam 2013-08-02 17:36:40 UTC
(In reply to Paolo Carlini from comment #2)
> What happened to the patch?

http://gcc.gnu.org/ml/gcc-patches/2013-06/msg00426.html
Patch has been submitted on Jun 7 in rev. 199842 to trunk. Sorry for not updating this bug. It can be marked fixed.

Thanks
Sri
Comment 4 Paolo Carlini 2013-08-02 17:49:19 UTC
Ok, thanks.