and here is the forgotten patch (it is late...)
diff --git a/gcc/c/gimple-parser.cc b/gcc/c/gimple-parser.cc index 78e85d93487..b018bb6afb6 100644 --- a/gcc/c/gimple-parser.cc +++ b/gcc/c/gimple-parser.cc @@ -133,11 +133,21 @@ c_parser_gimple_parse_bb_spec (tree val, int *index) { if (!startswith (IDENTIFIER_POINTER (val), "__BB")) return false; - for (const char *p = IDENTIFIER_POINTER (val) + 4; *p; ++p) - if (!ISDIGIT (*p)) - return false; - *index = atoi (IDENTIFIER_POINTER (val) + 4); - return *index > 0; + + const char *bb = IDENTIFIER_POINTER (val) + 4; + if (! ISDIGIT (*bb)) + return false; + + char *pend; + errno = 0; + const unsigned long number = strtoul (bb, &pend, 10); + if (errno == ERANGE + || *pend != '\0' + || number > INT_MAX) + return false; + + *index = number; + return true; } /* See if VAL is an identifier matching __BB<num> and return <num> @@ -2384,11 +2394,20 @@ c_parser_gimple_if_stmt (gimple_parser &parser, gimple_seq *seq) c_parser_consume_token (parser); int dest_index; profile_probability prob; - if ((cfun->curr_properties & PROP_cfg) - && c_parser_gimple_parse_bb_spec_edge_probability (label, parser, - &dest_index, &prob)) - parser.push_edge (parser.current_bb->index, dest_index, - EDGE_TRUE_VALUE, prob); + if (cfun->curr_properties & PROP_cfg) + { + if (c_parser_gimple_parse_bb_spec_edge_probability (label, parser, + &dest_index, &prob)) + { + parser.push_edge (parser.current_bb->index, dest_index, + EDGE_TRUE_VALUE, prob); + } + else + { + c_parser_error (parser, "expected valid __BB#"); + return; + } + } else t_label = lookup_label_for_goto (loc, label); if (! c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) @@ -2421,11 +2440,20 @@ c_parser_gimple_if_stmt (gimple_parser &parser, gimple_seq *seq) c_parser_consume_token (parser); int dest_index; profile_probability prob; - if ((cfun->curr_properties & PROP_cfg) - && c_parser_gimple_parse_bb_spec_edge_probability (label, parser, - &dest_index, &prob)) - parser.push_edge (parser.current_bb->index, dest_index, - EDGE_FALSE_VALUE, prob); + if (cfun->curr_properties & PROP_cfg) + { + if (c_parser_gimple_parse_bb_spec_edge_probability (label, parser, + &dest_index, &prob)) + { + parser.push_edge (parser.current_bb->index, dest_index, + EDGE_FALSE_VALUE, prob); + } + else + { + c_parser_error (parser, "expected valid __BB#"); + return; + } + } else f_label = lookup_label_for_goto (loc, label); if (! c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) diff --git a/gcc/testsuite/gcc.dg/pr114541Andrew.c b/gcc/testsuite/gcc.dg/pr114541Andrew.c new file mode 100644 index 00000000000..bc92473a79e --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr114541Andrew.c @@ -0,0 +1,28 @@ +/* PR middle-end/114541 */ +/* { dg-do compile } */ +/* { dg-options "-O -fgimple -c" } */ + +void __GIMPLE (ssa,startwith ("dse2")) foo () +{ + int a; + +__BB(2): + if (a_5(D) > 4) + goto __BB4294967299; /* { dg-error "expected valid __BB# before ';' token" } */ + else + goto __BB4; + +__BB(3): + a_2 = 10; + goto __BB5; + +__BB(4): + a_3 = 20; + goto __BB5; + +__BB(5): + a_1 = __PHI (__BB3: a_2, __BB4: a_3); + a_4 = a_1 + 4; + +return; +}