https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98062
Bug ID: 98062 Summary: [11 regression] Crash in type_as_string from plugin Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: plugins Assignee: unassigned at gcc dot gnu.org Reporter: s...@li-snyder.org Target Milestone: --- hi - A plugin i'm working on crashes with gcc 11 because pp_cxx_trait_expression doesn't handle the CPTK_IS_NOTHROW_CONSTRUCTIBLE enum. Here's a simple reproducer. First, here's the plugin: -- p.cc --------------------------------------------------- #include "gcc-plugin.h" #include "cp/cp-tree.h" int plugin_is_GPL_compatible; void type_callback (void* gcc_data, void*) { tree t = (tree)gcc_data; tree binfo = TYPE_BINFO (t); if (binfo && BINFO_N_BASE_BINFOS (binfo) > 0) { tree base_binfo = BINFO_BASE_BINFO (binfo, 0); tree bt = BINFO_TYPE (base_binfo); if (bt) { type_as_string (bt, 0); } } } extern "C" { int plugin_init(struct plugin_name_args *, struct plugin_gcc_version *) { register_callback ("a", PLUGIN_FINISH_TYPE, type_callback, nullptr); return 0; } } // extern "C" ----------------------------------------------------------------------- Compile with $ g++ -fPIC -shared -o libp.so p.cc -I`g++ -print-file-name=plugin`/include Run it with this input: -- x.cc ------------------------------------------------------------------ template <bool v> class B {}; template<typename _Tp> struct is_nothrow_default_constructible : public B<__is_nothrow_constructible(_Tp)> { }; -------------------------------------------------------------------------- $ g++ -fplugin=libp.so -c x.cc *** 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 | a x.cc:7:1: internal compiler error: in pp_cxx_trait_expression, at cp/cxx-pretty-print.c:2671 7 | }; | ^ 0x61483f pp_cxx_trait_expression(cxx_pretty_printer*, tree_node*) /home/sss/gcc/gcc/gcc/cp/cxx-pretty-print.c:2671 0x6e82ef dump_template_parms /home/sss/gcc/gcc/gcc/cp/error.c:1945 0x6ec3dc type_as_string(tree_node*, int) /home/sss/gcc/gcc/gcc/cp/error.c:3024 0xbd60c9 invoke_plugin_callbacks_full(int, void*) /home/sss/gcc/gcc/gcc/plugin.c:588 0x73ed8f invoke_plugin_callbacks /home/sss/gcc/gcc/gcc/plugin.h:191 0x73ed8f cp_parser_type_specifier /home/sss/gcc/gcc/gcc/cp/parser.c:17964 0x73f7fb cp_parser_decl_specifier_seq /home/sss/gcc/gcc/gcc/cp/parser.c:14585 0x766536 cp_parser_single_declaration /home/sss/gcc/gcc/gcc/cp/parser.c:29908 0x766897 cp_parser_template_declaration_after_parameters /home/sss/gcc/gcc/gcc/cp/parser.c:29571 0x766e9a cp_parser_explicit_template_declaration /home/sss/gcc/gcc/gcc/cp/parser.c:29837 0x7697d9 cp_parser_declaration /home/sss/gcc/gcc/gcc/cp/parser.c:13609 0x76a04d cp_parser_translation_unit /home/sss/gcc/gcc/gcc/cp/parser.c:4806 0x76a04d c_parse_file() /home/sss/gcc/gcc/gcc/cp/parser.c:44630 0x837bed c_common_parse_file() /home/sss/gcc/gcc/gcc/c-family/c-opts.c:1198 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <https://gcc.gnu.org/bugs/> for instructions. This patch fixes the crash: diff --git a/gcc/cp/cxx-pretty-print.c b/gcc/cp/cxx-pretty-print.c index 058b9c2f4fc..b1e10f9e2a8 100644 --- a/gcc/cp/cxx-pretty-print.c +++ b/gcc/cp/cxx-pretty-print.c @@ -2666,6 +2666,9 @@ pp_cxx_trait_expression (cxx_pretty_printer *pp, tree t) case CPTK_IS_CONSTRUCTIBLE: pp_cxx_ws_string (pp, "__is_constructible"); break; + case CPTK_IS_NOTHROW_CONSTRUCTIBLE: + pp_cxx_ws_string (pp, "__is_nothrow_constructible"); + break; default: gcc_unreachable (); However, there are still a few other CPTK_ enums that aren't handled in pp_cxx_trait_expression --- probably PTK_IS_NOTHROW_ASSIGNABLE should be there, at least.