https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62252

            Bug ID: 62252
           Summary: a callback to event PLUGIN_FINISH_TYPE segfaults
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: plugins
          Assignee: unassigned at gcc dot gnu.org
          Reporter: klemen.jan.enova at gmail dot com

The following plugin is a reduced version of
"testsuite/g++.dg/plugin/dumb_plugin.c".

I tested it with

- the ubuntu binary version of gcc-4.9
- ubuntu binary version of gcc-4.8 (g++-4.8 (Ubuntu 4.8.2-19ubuntu1) 4.8.2)
- the compiled version of gcc-4.9 taken from the 4.9 release
(https://github.com/gcc-mirror/gcc/releases/tag/gcc-4_9_0-release)

All tests segfault. 

---
kje@kje:~$ uname -a
Linux kje 3.13.0-34-generic #60-Ubuntu SMP Wed Aug 13 15:45:27 UTC 2014 x86_64
x86_64 x86_64 GNU/Linux
kje@kje:~/example$ cat example.c
#include "gcc-plugin.h"
//#include <stdlib.h>
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tree.h"
#include "tree-pass.h"
#include "intl.h"
#include "toplev.h"
#include "diagnostic.h"
#include "context.h"

int plugin_is_GPL_compatible;

void
handle_struct (void *event_data, void *data)
{
    tree type = (tree) event_data;
    warning(0, G_("Process struct %s"),
        IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
}

int
plugin_init (struct plugin_name_args *plugin_info,
             struct plugin_gcc_version *version)
{
  register_callback ("example", PLUGIN_FINISH_TYPE, handle_struct, NULL);

    return 0;
}
kje@kje:~/example$ cat example_test.c
struct S {
    int x;
};

int main(void)
{
    struct S s;
    s.x = 5;

    return 0;
}
kje@kje:~/example$ g++-4.9 --version
g++-4.9 (Ubuntu 4.9.1-3ubuntu2~14.04.1) 4.9.1
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

kje@kje:~/example$ g++-4.9 -fPIC -g
-I/usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.9.0/plugin/include -c example.c
kje@kje:~/example$ g++-4.9 -fPIC -g
-I/usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.9.0/plugin/include -shared
example.o -o example_plugin.so
kje@kje:~/example$ g++-4.9 -fplugin=./example_plugin.so example_test.c
example_test.c:3:1: warning: Process struct S
 };
 ^
*** WARNING *** there are active plugins, do not report this as a bug unless
you can reproduce it without enabling any plugins.
Event                            | Plugins
PLUGIN_FINISH_TYPE               | example
example_test.c: In function ‘int main()’:
example_test.c:7:9: internal compiler error: Segmentation fault
  struct S s;
         ^
0x7f1d3226c780 handle_struct(void*, void*)
    /home/kje/example/example.c:20
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-4.9/README.Bugs> for instructions.
The bug is not reproducible, so it is likely a hardware or OS problem.

---

If I use g++ compiled from (configure with --enable-languagues=c,c++) the
github repository 4.9 release, I get the whole call stack:

---

kje@kje:~/example$ g++ --version
g++ (GCC) 4.9.0
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

kje@kje:~/example$ g++ -fplugin=./example_plugin.so example_test.c
example_test.c:3:1: warning: Process struct S
 };
 ^
*** WARNING *** there are active plugins, do not report this as a bug unless
you can reproduce it without enabling any plugins.
Event                            | Plugins
PLUGIN_FINISH_TYPE               | example
example_test.c: In function ‘int main()’:
example_test.c:7:9: internal compiler error: Segmentation fault
  struct S s;
         ^
0x98cc2f crash_signal
    ../../../gcc4.9/gcc/toplev.c:337
0x7f520d010780 handle_struct(void*, void*)
    /home/kje/example/example.c:20
0x8fb0b9 invoke_plugin_callbacks_full(int, void*)
    ../../../gcc4.9/gcc/plugin.c:542
0x5e82b5 invoke_plugin_callbacks
    ../../../gcc4.9/gcc/plugin.h:59
0x5e82b5 cp_parser_type_specifier
    ../../../gcc4.9/gcc/cp/parser.c:14338
0x5fdbb0 cp_parser_decl_specifier_seq
    ../../../gcc4.9/gcc/cp/parser.c:11573
0x602e79 cp_parser_simple_declaration
    ../../../gcc4.9/gcc/cp/parser.c:11163
0x5ea903 cp_parser_block_declaration
    ../../../gcc4.9/gcc/cp/parser.c:11112
0x5eb961 cp_parser_declaration_statement
    ../../../gcc4.9/gcc/cp/parser.c:10759
0x5ebf9b cp_parser_statement
    ../../../gcc4.9/gcc/cp/parser.c:9492
0x5ecdc9 cp_parser_statement_seq_opt
    ../../../gcc4.9/gcc/cp/parser.c:9770
0x5ecf06 cp_parser_compound_statement
    ../../../gcc4.9/gcc/cp/parser.c:9724
0x5fb7d3 cp_parser_function_body
    ../../../gcc4.9/gcc/cp/parser.c:18751
0x5fb7d3 cp_parser_ctor_initializer_opt_and_function_body
    ../../../gcc4.9/gcc/cp/parser.c:18787
0x601272 cp_parser_function_definition_after_declarator
    ../../../gcc4.9/gcc/cp/parser.c:22912
0x6021ac cp_parser_function_definition_from_specifiers_and_declarator
    ../../../gcc4.9/gcc/cp/parser.c:22824
0x6021ac cp_parser_init_declarator
    ../../../gcc4.9/gcc/cp/parser.c:16634
0x603059 cp_parser_simple_declaration
    ../../../gcc4.9/gcc/cp/parser.c:11231
0x5ea903 cp_parser_block_declaration
    ../../../gcc4.9/gcc/cp/parser.c:11112
0x60a9c2 cp_parser_declaration
    ../../../gcc4.9/gcc/cp/parser.c:11009
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.

---

Reply via email to