| 1 |
/* Parser for GIMPLE. |
| 2 |
Copyright (C) 2016-2025 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
This file is part of GCC. |
| 5 |
|
| 6 |
GCC is free software; you can redistribute it and/or modify it under |
| 7 |
the terms of the GNU General Public License as published by the Free |
| 8 |
Software Foundation; either version 3, or (at your option) any later |
| 9 |
version. |
| 10 |
|
| 11 |
GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 |
WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 |
for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License |
| 17 |
along with GCC; see the file COPYING3. If not see |
| 18 |
<http://www.gnu.org/licenses/>. */ |
| 19 |
|
| 20 |
#include "config.h" |
| 21 |
#include "system.h" |
| 22 |
#include "coretypes.h" |
| 23 |
#include "target.h" |
| 24 |
#include "function.h" |
| 25 |
#include "c-tree.h" |
| 26 |
#include "timevar.h" |
| 27 |
#include "stringpool.h" |
| 28 |
#include "cgraph.h" |
| 29 |
#include "attribs.h" |
| 30 |
#include "stor-layout.h" |
| 31 |
#include "varasm.h" |
| 32 |
#include "trans-mem.h" |
| 33 |
#include "c-family/c-pragma.h" |
| 34 |
#include "c-lang.h" |
| 35 |
#include "c-family/c-objc.h" |
| 36 |
#include "plugin.h" |
| 37 |
#include "builtins.h" |
| 38 |
#include "gomp-constants.h" |
| 39 |
#include "c-family/c-indentation.h" |
| 40 |
#include "gimple-expr.h" |
| 41 |
#include "context.h" |
| 42 |
#include "gcc-rich-location.h" |
| 43 |
#include "c-parser.h" |
| 44 |
#include "tree-vrp.h" |
| 45 |
#include "tree-pass.h" |
| 46 |
#include "tree-pretty-print.h" |
| 47 |
#include "tree.h" |
| 48 |
#include "basic-block.h" |
| 49 |
#include "gimple.h" |
| 50 |
#include "gimple-pretty-print.h" |
| 51 |
#include "tree-ssa.h" |
| 52 |
#include "pass_manager.h" |
| 53 |
#include "tree-ssanames.h" |
| 54 |
#include "gimple-ssa.h" |
| 55 |
#include "tree-dfa.h" |
| 56 |
#include "internal-fn.h" |
| 57 |
#include "cfg.h" |
| 58 |
#include "cfghooks.h" |
| 59 |
#include "bitmap.h" |
| 60 |
#include "cfganal.h" |
| 61 |
#include "tree-cfg.h" |
| 62 |
#include "gimple-iterator.h" |
| 63 |
#include "cfgloop.h" |
| 64 |
#include "tree-phinodes.h" |
| 65 |
#include "tree-into-ssa.h" |
| 66 |
|
| 67 |
|
| 68 |
/* GIMPLE parser state. */ |
| 69 |
|
| 70 |
class gimple_parser |
| 71 |
{ |
| 72 |
public: |
| 73 |
gimple_parser (c_parser *p) : parser (p), edges(), current_bb(NULL) {} |
| 74 |
/* c_parser is not visible here, use composition and fake inheritance |
| 75 |
via a conversion operator. */ |
| 76 |
operator c_parser *() { return parser; } |
| 77 |
c_parser *parser; |
| 78 |
|
| 79 |
/* CFG build state. */ |
| 80 |
class gimple_parser_edge |
| 81 |
{ |
| 82 |
public: |
| 83 |
int src; |
| 84 |
int dest; |
| 85 |
int flags; |
| 86 |
profile_probability probability; |
| 87 |
}; |
| 88 |
auto_vec<gimple_parser_edge> edges; |
| 89 |
basic_block current_bb; |
| 90 |
|
| 91 |
void push_edge (int, int, int, profile_probability); |
| 92 |
}; |
| 93 |
|
| 94 |
void |
| 95 |
gimple_parser::push_edge (int src, int dest, int flags, |
| 96 |
profile_probability prob) |
| 97 |
{ |
| 98 |
gimple_parser_edge e; |
| 99 |
e.src = src; |
| 100 |
e.dest = dest; |
| 101 |
e.flags = flags; |
| 102 |
e.probability = prob; |
| 103 |
edges.safe_push (e); |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
/* Gimple parsing functions. */ |
| 108 |
static bool c_parser_gimple_compound_statement (gimple_parser &, gimple_seq *); |
| 109 |
static void c_parser_gimple_label (gimple_parser &, gimple_seq *); |
| 110 |
static void c_parser_gimple_statement (gimple_parser &, gimple_seq *); |
| 111 |
static struct c_expr c_parser_gimple_binary_expression (gimple_parser &, tree); |
| 112 |
static struct c_expr c_parser_gimple_unary_expression (gimple_parser &); |
| 113 |
static struct c_expr c_parser_gimple_postfix_expression (gimple_parser &); |
| 114 |
static struct c_expr c_parser_gimple_postfix_expression_after_primary |
| 115 |
(gimple_parser &, location_t, struct c_expr); |
| 116 |
static void c_parser_gimple_declaration (gimple_parser &); |
| 117 |
static void c_parser_gimple_goto_stmt (gimple_parser &, location_t, |
| 118 |
tree, gimple_seq *); |
| 119 |
static void c_parser_gimple_try_stmt (gimple_parser &, gimple_seq *); |
| 120 |
static void c_parser_gimple_if_stmt (gimple_parser &, gimple_seq *); |
| 121 |
static void c_parser_gimple_switch_stmt (gimple_parser &, gimple_seq *); |
| 122 |
static void c_parser_gimple_return_stmt (gimple_parser &, gimple_seq *); |
| 123 |
static void c_finish_gimple_return (location_t, tree); |
| 124 |
static tree c_parser_gimple_paren_condition (gimple_parser &); |
| 125 |
static void c_parser_gimple_expr_list (gimple_parser &, vec<tree> *); |
| 126 |
|
| 127 |
|
| 128 |
/* Much like parser_build_unary_op, but avoid applying default conversions. */ |
| 129 |
|
| 130 |
static c_expr |
| 131 |
gimple_parser_build_unary_op (location_t loc, |
| 132 |
enum tree_code code, struct c_expr arg) |
| 133 |
{ |
| 134 |
struct c_expr result; |
| 135 |
|
| 136 |
result.original_code = code; |
| 137 |
result.original_type = NULL; |
| 138 |
result.m_decimal = 0; |
| 139 |
|
| 140 |
if (reject_gcc_builtin (arg.value)) |
| 141 |
{ |
| 142 |
result.value = error_mark_node; |
| 143 |
} |
| 144 |
else |
| 145 |
{ |
| 146 |
result.value = build_unary_op (loc, code, arg.value, true); |
| 147 |
|
| 148 |
if (TREE_OVERFLOW_P (result.value) && !TREE_OVERFLOW_P (arg.value)) |
| 149 |
overflow_warning (loc, result.value, arg.value); |
| 150 |
} |
| 151 |
|
| 152 |
/* We are typically called when parsing a prefix token at LOC acting on |
| 153 |
ARG. Reflect this by updating the source range of the result to |
| 154 |
start at LOC and end at the end of ARG. */ |
| 155 |
set_c_expr_source_range (&result, |
| 156 |
loc, arg.get_finish ()); |
| 157 |
|
| 158 |
return result; |
| 159 |
} |
| 160 |
|
| 161 |
/* See if VAL is an identifier matching __BB<num> and return <num> |
| 162 |
in *INDEX. */ |
| 163 |
|
| 164 |
static bool |
| 165 |
c_parser_gimple_parse_bb_spec (tree val, int *index) |
| 166 |
{ |
| 167 |
if (!startswith (IDENTIFIER_POINTER (val), "__BB")) |
| 168 |
return false; |
| 169 |
|
| 170 |
const char *bb = IDENTIFIER_POINTER (val) + 4; |
| 171 |
if (! ISDIGIT (*bb)) |
| 172 |
return false; |
| 173 |
|
| 174 |
char *pend; |
| 175 |
errno = 0; |
| 176 |
const unsigned long number = strtoul (bb, &pend, 10); |
| 177 |
if (errno == ERANGE |
| 178 |
|| *pend != '\0' |
| 179 |
|| number > INT_MAX) |
| 180 |
return false; |
| 181 |
|
| 182 |
*index = number; |
| 183 |
return true; |
| 184 |
} |
| 185 |
|
| 186 |
/* See if VAL is an identifier matching __BB<num> and return <num> |
| 187 |
in *INDEX. Return true if so and parse also FREQUENCY of |
| 188 |
the edge. */ |
| 189 |
|
| 190 |
|
| 191 |
static bool |
| 192 |
c_parser_gimple_parse_bb_spec_edge_probability (tree val, |
| 193 |
gimple_parser &parser, |
| 194 |
int *index, |
| 195 |
profile_probability |
| 196 |
*probability) |
| 197 |
{ |
| 198 |
bool return_p = c_parser_gimple_parse_bb_spec (val, index); |
| 199 |
if (return_p) |
| 200 |
{ |
| 201 |
*probability = profile_probability::uninitialized (); |
| 202 |
/* Parse frequency if provided. */ |
| 203 |
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 204 |
{ |
| 205 |
tree f; |
| 206 |
c_parser_consume_token (parser); |
| 207 |
if (!c_parser_next_token_is (parser, CPP_NAME)) |
| 208 |
{ |
| 209 |
c_parser_error (parser, "expected frequency quality"); |
| 210 |
return false; |
| 211 |
} |
| 212 |
|
| 213 |
profile_quality quality; |
| 214 |
const char *v |
| 215 |
= IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 216 |
if (!parse_profile_quality (v, &quality)) |
| 217 |
{ |
| 218 |
c_parser_error (parser, "unknown profile quality"); |
| 219 |
return false; |
| 220 |
} |
| 221 |
|
| 222 |
c_parser_consume_token (parser); |
| 223 |
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
| 224 |
return false; |
| 225 |
|
| 226 |
if (!c_parser_next_token_is (parser, CPP_NUMBER) |
| 227 |
|| (TREE_CODE (f = c_parser_peek_token (parser)->value) |
| 228 |
!= INTEGER_CST)) |
| 229 |
{ |
| 230 |
c_parser_error (parser, "expected frequency value"); |
| 231 |
return false; |
| 232 |
} |
| 233 |
|
| 234 |
unsigned int value = TREE_INT_CST_LOW (f); |
| 235 |
*probability = profile_probability (value, quality); |
| 236 |
|
| 237 |
c_parser_consume_token (parser); |
| 238 |
if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) |
| 239 |
return false; |
| 240 |
|
| 241 |
if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) |
| 242 |
return false; |
| 243 |
} |
| 244 |
|
| 245 |
return true; |
| 246 |
} |
| 247 |
|
| 248 |
return false; |
| 249 |
|
| 250 |
} |
| 251 |
|
| 252 |
/* Parse the body of a function declaration marked with "__GIMPLE". */ |
| 253 |
|
| 254 |
void |
| 255 |
c_parser_parse_gimple_body (c_parser *cparser, char *gimple_pass, |
| 256 |
enum c_declspec_il cdil, |
| 257 |
profile_count entry_bb_count) |
| 258 |
{ |
| 259 |
gimple_parser parser (cparser); |
| 260 |
gimple_seq seq = NULL; |
| 261 |
gimple_seq body = NULL; |
| 262 |
tree stmt = push_stmt_list (); |
| 263 |
push_scope (); |
| 264 |
location_t loc1 = c_parser_peek_token (parser)->location; |
| 265 |
|
| 266 |
cfun->pass_startwith = gimple_pass; |
| 267 |
init_tree_ssa (cfun); |
| 268 |
|
| 269 |
if (cdil == cdil_gimple) |
| 270 |
/* While we have SSA names in the IL we do not have a CFG built yet |
| 271 |
and PHIs are represented using a PHI internal function. We do |
| 272 |
have lowered control flow and exception handling (well, we do not |
| 273 |
have parser support for EH yet). But as we still have BINDs |
| 274 |
we have to go through lowering again. */ |
| 275 |
cfun->curr_properties = PROP_gimple_any; |
| 276 |
else |
| 277 |
{ |
| 278 |
/* We have at least cdil_gimple_cfg. */ |
| 279 |
gimple_register_cfg_hooks (); |
| 280 |
init_empty_tree_cfg (); |
| 281 |
parser.current_bb = ENTRY_BLOCK_PTR_FOR_FN (cfun); |
| 282 |
/* Initialize the bare loop structure - we are going to only |
| 283 |
mark headers and leave the rest to fixup. */ |
| 284 |
set_loops_for_fn (cfun, ggc_cleared_alloc<struct loops> ()); |
| 285 |
init_loops_structure (cfun, loops_for_fn (cfun), 1); |
| 286 |
loops_state_set (cfun, LOOPS_NEED_FIXUP|LOOPS_MAY_HAVE_MULTIPLE_LATCHES); |
| 287 |
cfun->curr_properties |
| 288 |
|= PROP_gimple_lcf | PROP_gimple_leh | PROP_cfg | PROP_loops; |
| 289 |
if (cdil == cdil_gimple_ssa) |
| 290 |
{ |
| 291 |
init_ssa_operands (cfun); |
| 292 |
cfun->curr_properties |= PROP_ssa; |
| 293 |
} |
| 294 |
} |
| 295 |
|
| 296 |
if (! c_parser_gimple_compound_statement (parser, &seq) |
| 297 |
&& cdil == cdil_gimple) |
| 298 |
{ |
| 299 |
gimple *ret = gimple_build_return (NULL); |
| 300 |
gimple_seq_add_stmt_without_update (&seq, ret); |
| 301 |
} |
| 302 |
|
| 303 |
tree block = pop_scope (); |
| 304 |
stmt = pop_stmt_list (stmt); |
| 305 |
stmt = c_build_bind_expr (loc1, block, stmt); |
| 306 |
|
| 307 |
block = DECL_INITIAL (current_function_decl); |
| 308 |
BLOCK_SUBBLOCKS (block) = NULL_TREE; |
| 309 |
BLOCK_CHAIN (block) = NULL_TREE; |
| 310 |
TREE_ASM_WRITTEN (block) = 1; |
| 311 |
|
| 312 |
if (cdil == cdil_gimple) |
| 313 |
{ |
| 314 |
gbind *bind_stmt = gimple_build_bind (BIND_EXPR_VARS (stmt), NULL, |
| 315 |
BIND_EXPR_BLOCK (stmt)); |
| 316 |
gimple_bind_set_body (bind_stmt, seq); |
| 317 |
gimple_seq_add_stmt_without_update (&body, bind_stmt); |
| 318 |
gimple_set_body (current_function_decl, body); |
| 319 |
} |
| 320 |
else |
| 321 |
{ |
| 322 |
/* Control-flow and binds are lowered, record local decls. */ |
| 323 |
for (tree var = BIND_EXPR_VARS (stmt); var; var = DECL_CHAIN (var)) |
| 324 |
if (VAR_P (var) |
| 325 |
&& !DECL_EXTERNAL (var)) |
| 326 |
{ |
| 327 |
add_local_decl (cfun, var); |
| 328 |
/* When the middle-end re-gimplifies any expression we might |
| 329 |
run into the assertion that we've seen the decl in a BIND. */ |
| 330 |
if (!TREE_STATIC (var)) |
| 331 |
DECL_SEEN_IN_BIND_EXPR_P (var) = 1; |
| 332 |
} |
| 333 |
/* We have a CFG. Build the edges. */ |
| 334 |
for (unsigned i = 0; i < parser.edges.length (); ++i) |
| 335 |
{ |
| 336 |
edge e = make_edge (BASIC_BLOCK_FOR_FN (cfun, parser.edges[i].src), |
| 337 |
BASIC_BLOCK_FOR_FN (cfun, parser.edges[i].dest), |
| 338 |
parser.edges[i].flags); |
| 339 |
e->probability = parser.edges[i].probability; |
| 340 |
} |
| 341 |
/* Add edges for case labels. */ |
| 342 |
basic_block bb; |
| 343 |
FOR_EACH_BB_FN (bb, cfun) |
| 344 |
if (EDGE_COUNT (bb->succs) == 0) |
| 345 |
{ |
| 346 |
if (gswitch *sw = safe_dyn_cast <gswitch *> (*gsi_last_bb (bb))) |
| 347 |
for (unsigned i = 0; i < gimple_switch_num_labels (sw); ++i) |
| 348 |
{ |
| 349 |
basic_block label_bb = gimple_switch_label_bb (cfun, sw, i); |
| 350 |
make_edge (bb, label_bb, 0); |
| 351 |
} |
| 352 |
} |
| 353 |
/* Need those for loop fixup. */ |
| 354 |
calculate_dominance_info (CDI_DOMINATORS); |
| 355 |
/* With SSA lower PHIs parsed as internal function calls and |
| 356 |
update stmts. */ |
| 357 |
if (cdil == cdil_gimple_ssa) |
| 358 |
{ |
| 359 |
/* Create PHI nodes, they are parsed into __PHI internal calls. */ |
| 360 |
FOR_EACH_BB_FN (bb, cfun) |
| 361 |
for (gimple_stmt_iterator gsi = gsi_start_bb (bb); |
| 362 |
!gsi_end_p (gsi);) |
| 363 |
{ |
| 364 |
gimple *stmt = gsi_stmt (gsi); |
| 365 |
if (!gimple_call_internal_p (stmt, IFN_PHI)) |
| 366 |
break; |
| 367 |
|
| 368 |
gphi *phi = create_phi_node (gimple_call_lhs (stmt), bb); |
| 369 |
for (unsigned i = 0; i < gimple_call_num_args (stmt); i += 2) |
| 370 |
{ |
| 371 |
int srcidx = TREE_INT_CST_LOW (gimple_call_arg (stmt, i)); |
| 372 |
edge e = find_edge (BASIC_BLOCK_FOR_FN (cfun, srcidx), bb); |
| 373 |
if (!e) |
| 374 |
c_parser_error (parser, "edge not found"); |
| 375 |
else |
| 376 |
add_phi_arg (phi, gimple_call_arg (stmt, i + 1), e, |
| 377 |
UNKNOWN_LOCATION); |
| 378 |
} |
| 379 |
gsi_remove (&gsi, true); |
| 380 |
} |
| 381 |
/* Fill SSA name gaps, putting them on the freelist and diagnose |
| 382 |
SSA names without definition. */ |
| 383 |
for (unsigned i = 1; i < num_ssa_names; ++i) |
| 384 |
if (!ssa_name (i)) |
| 385 |
{ |
| 386 |
tree name = make_ssa_name_fn (cfun, integer_type_node, NULL, i); |
| 387 |
release_ssa_name_fn (cfun, name); |
| 388 |
} |
| 389 |
else if (!SSA_NAME_DEF_STMT (ssa_name (i))) |
| 390 |
error ("SSA name %qE with version %d has no definition", |
| 391 |
ssa_name (i), i); |
| 392 |
/* No explicit virtual operands (yet). */ |
| 393 |
bitmap_obstack_initialize (NULL); |
| 394 |
update_ssa (TODO_update_ssa_only_virtuals); |
| 395 |
bitmap_obstack_release (NULL); |
| 396 |
/* ??? By flushing the freelist after virtual operand SSA rewrite |
| 397 |
we keep the gaps available for re-use like needed for the |
| 398 |
PR89595 testcase but then usually virtual operands would have |
| 399 |
taken most of them. The fix is obviously to make virtual |
| 400 |
operands explicit in the SSA IL. */ |
| 401 |
flush_ssaname_freelist (); |
| 402 |
} |
| 403 |
fix_loop_structure (NULL); |
| 404 |
} |
| 405 |
|
| 406 |
if (cfun->curr_properties & PROP_cfg) |
| 407 |
{ |
| 408 |
ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = entry_bb_count; |
| 409 |
gcov_type t = param_gimple_fe_computed_hot_bb_threshold; |
| 410 |
set_hot_bb_threshold (t); |
| 411 |
update_max_bb_count (); |
| 412 |
cgraph_node::get_create (cfun->decl); |
| 413 |
cgraph_edge::rebuild_edges (); |
| 414 |
} |
| 415 |
|
| 416 |
/* Perform IL validation and if any error is found abort compilation |
| 417 |
of this function by zapping its body. */ |
| 418 |
if ((cfun->curr_properties & PROP_cfg) |
| 419 |
&& verify_gimple_in_cfg (cfun, false, false)) |
| 420 |
init_empty_tree_cfg (); |
| 421 |
else if (!(cfun->curr_properties & PROP_cfg) |
| 422 |
&& verify_gimple_in_seq (gimple_body (current_function_decl), false)) |
| 423 |
gimple_set_body (current_function_decl, NULL); |
| 424 |
|
| 425 |
dump_function (TDI_gimple, current_function_decl); |
| 426 |
} |
| 427 |
|
| 428 |
/* Parse a compound statement in gimple function body. |
| 429 |
|
| 430 |
gimple-statement: |
| 431 |
gimple-statement |
| 432 |
gimple-declaration-statement |
| 433 |
gimple-if-statement |
| 434 |
gimple-switch-statement |
| 435 |
gimple-labeled-statement |
| 436 |
gimple-expression-statement |
| 437 |
gimple-goto-statement |
| 438 |
gimple-phi-statement |
| 439 |
gimple-return-statement |
| 440 |
*/ |
| 441 |
|
| 442 |
static bool |
| 443 |
c_parser_gimple_compound_statement (gimple_parser &parser, gimple_seq *seq) |
| 444 |
{ |
| 445 |
bool return_p = false; |
| 446 |
|
| 447 |
if (! c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>")) |
| 448 |
return false; |
| 449 |
|
| 450 |
/* A compund statement starts with optional declarations. */ |
| 451 |
while (c_parser_next_tokens_start_declaration (parser)) |
| 452 |
{ |
| 453 |
c_parser_gimple_declaration (parser); |
| 454 |
if (! c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) |
| 455 |
return false; |
| 456 |
} |
| 457 |
|
| 458 |
while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE)) |
| 459 |
{ |
| 460 |
if (c_parser_error (parser)) |
| 461 |
{ |
| 462 |
c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); |
| 463 |
return return_p; |
| 464 |
} |
| 465 |
else if (c_parser_next_token_is (parser, CPP_EOF)) |
| 466 |
{ |
| 467 |
c_parser_error (parser, "expected declaration or statement"); |
| 468 |
return return_p; |
| 469 |
} |
| 470 |
|
| 471 |
switch (c_parser_peek_token (parser)->type) |
| 472 |
{ |
| 473 |
case CPP_KEYWORD: |
| 474 |
switch (c_parser_peek_token (parser)->keyword) |
| 475 |
{ |
| 476 |
case RID_AT_TRY: |
| 477 |
c_parser_gimple_try_stmt (parser, seq); |
| 478 |
break; |
| 479 |
case RID_IF: |
| 480 |
c_parser_gimple_if_stmt (parser, seq); |
| 481 |
break; |
| 482 |
case RID_SWITCH: |
| 483 |
c_parser_gimple_switch_stmt (parser, seq); |
| 484 |
break; |
| 485 |
case RID_GOTO: |
| 486 |
{ |
| 487 |
location_t loc = c_parser_peek_token (parser)->location; |
| 488 |
c_parser_consume_token (parser); |
| 489 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 490 |
{ |
| 491 |
tree label = c_parser_peek_token (parser)->value; |
| 492 |
c_parser_consume_token (parser); |
| 493 |
c_parser_gimple_goto_stmt (parser, loc, label, seq); |
| 494 |
if (! c_parser_require (parser, CPP_SEMICOLON, |
| 495 |
"expected %<;%>")) |
| 496 |
return return_p; |
| 497 |
} |
| 498 |
} |
| 499 |
break; |
| 500 |
case RID_RETURN: |
| 501 |
return_p = true; |
| 502 |
c_parser_gimple_return_stmt (parser, seq); |
| 503 |
if (! c_parser_require (parser, CPP_SEMICOLON, |
| 504 |
"expected %<;%>")) |
| 505 |
return return_p; |
| 506 |
if (cfun->curr_properties & PROP_cfg) |
| 507 |
parser.push_edge (parser.current_bb->index, EXIT_BLOCK, 0, |
| 508 |
profile_probability::uninitialized ()); |
| 509 |
break; |
| 510 |
default: |
| 511 |
goto expr_stmt; |
| 512 |
} |
| 513 |
break; |
| 514 |
case CPP_NAME: |
| 515 |
if (c_parser_peek_2nd_token (parser)->type == CPP_COLON) |
| 516 |
{ |
| 517 |
c_parser_gimple_label (parser, seq); |
| 518 |
break; |
| 519 |
} |
| 520 |
if (c_parser_next_token_is (parser, CPP_NAME) |
| 521 |
&& c_parser_peek_token (parser)->id_kind == C_ID_ID |
| 522 |
&& strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value), |
| 523 |
"try") == 0) |
| 524 |
{ |
| 525 |
c_parser_gimple_try_stmt (parser, seq); |
| 526 |
break; |
| 527 |
} |
| 528 |
/* Basic block specification. |
| 529 |
__BB (index, ...) */ |
| 530 |
if ((cfun->curr_properties & PROP_cfg) |
| 531 |
&& !strcmp (IDENTIFIER_POINTER |
| 532 |
(c_parser_peek_token (parser)->value), "__BB")) |
| 533 |
{ |
| 534 |
c_parser_consume_token (parser); |
| 535 |
if (! c_parser_require (parser, CPP_OPEN_PAREN, |
| 536 |
"expected %<(%>")) |
| 537 |
return return_p; |
| 538 |
if (c_parser_next_token_is_not (parser, CPP_NUMBER)) |
| 539 |
{ |
| 540 |
c_parser_error (parser, "expected block index"); |
| 541 |
return return_p; |
| 542 |
} |
| 543 |
tree tnum = c_parser_peek_token (parser)->value; |
| 544 |
if (TREE_CODE (tnum) != INTEGER_CST) |
| 545 |
{ |
| 546 |
c_parser_error (parser, "expected block index"); |
| 547 |
return return_p; |
| 548 |
} |
| 549 |
int index = TREE_INT_CST_LOW (tnum); |
| 550 |
if (index < NUM_FIXED_BLOCKS |
| 551 |
|| (index < last_basic_block_for_fn (cfun) |
| 552 |
&& BASIC_BLOCK_FOR_FN (cfun, index) != NULL)) |
| 553 |
{ |
| 554 |
c_parser_error (parser, "invalid block index"); |
| 555 |
return return_p; |
| 556 |
} |
| 557 |
int is_loop_header_of = -1; |
| 558 |
profile_count bb_count = profile_count::uninitialized (); |
| 559 |
c_parser_consume_token (parser); |
| 560 |
while (c_parser_next_token_is (parser, CPP_COMMA)) |
| 561 |
{ |
| 562 |
c_parser_consume_token (parser); |
| 563 |
if (! c_parser_next_token_is (parser, CPP_NAME)) |
| 564 |
{ |
| 565 |
c_parser_error (parser, "expected block specifier"); |
| 566 |
return return_p; |
| 567 |
} |
| 568 |
/* loop_header (NUM) */ |
| 569 |
if (!strcmp (IDENTIFIER_POINTER |
| 570 |
(c_parser_peek_token (parser)->value), |
| 571 |
"loop_header")) |
| 572 |
{ |
| 573 |
c_parser_consume_token (parser); |
| 574 |
if (! c_parser_require (parser, CPP_OPEN_PAREN, |
| 575 |
"expected %<(%>")) |
| 576 |
return return_p; |
| 577 |
tree loop_num; |
| 578 |
if (! c_parser_next_token_is (parser, CPP_NUMBER) |
| 579 |
|| TREE_CODE (loop_num |
| 580 |
= c_parser_peek_token (parser)->value) |
| 581 |
!= INTEGER_CST) |
| 582 |
{ |
| 583 |
c_parser_error (parser, "expected loop number"); |
| 584 |
return return_p; |
| 585 |
} |
| 586 |
c_parser_consume_token (parser); |
| 587 |
is_loop_header_of = TREE_INT_CST_LOW (loop_num); |
| 588 |
if (! c_parser_require (parser, CPP_CLOSE_PAREN, |
| 589 |
"expected %<)%>")) |
| 590 |
return return_p; |
| 591 |
} |
| 592 |
/* Parse profile: quality(value) */ |
| 593 |
else |
| 594 |
{ |
| 595 |
tree q; |
| 596 |
profile_quality quality; |
| 597 |
tree v = c_parser_peek_token (parser)->value; |
| 598 |
if (!parse_profile_quality (IDENTIFIER_POINTER (v), |
| 599 |
&quality)) |
| 600 |
{ |
| 601 |
c_parser_error (parser, "unknown block specifier"); |
| 602 |
return false; |
| 603 |
} |
| 604 |
|
| 605 |
c_parser_consume_token (parser); |
| 606 |
if (!c_parser_require (parser, CPP_OPEN_PAREN, |
| 607 |
"expected %<(%>")) |
| 608 |
return false; |
| 609 |
|
| 610 |
if (!c_parser_next_token_is (parser, CPP_NUMBER) |
| 611 |
|| (TREE_CODE (q = c_parser_peek_token (parser)->value) |
| 612 |
!= INTEGER_CST)) |
| 613 |
{ |
| 614 |
c_parser_error (parser, "expected count value"); |
| 615 |
return false; |
| 616 |
} |
| 617 |
|
| 618 |
bb_count |
| 619 |
= profile_count::from_gcov_type (TREE_INT_CST_LOW (q), |
| 620 |
quality); |
| 621 |
c_parser_consume_token (parser); |
| 622 |
if (! c_parser_require (parser, CPP_CLOSE_PAREN, |
| 623 |
"expected %<)%>")) |
| 624 |
return return_p; |
| 625 |
} |
| 626 |
} |
| 627 |
if (! c_parser_require (parser, CPP_CLOSE_PAREN, |
| 628 |
"expected %<)%>") |
| 629 |
|| ! c_parser_require (parser, CPP_COLON, |
| 630 |
"expected %<:%>")) |
| 631 |
return return_p; |
| 632 |
|
| 633 |
/* Put stmts parsed in the current block. */ |
| 634 |
if (!gimple_seq_empty_p (*seq)) |
| 635 |
{ |
| 636 |
if (!parser.current_bb) |
| 637 |
c_parser_error (parser, "stmts without block"); |
| 638 |
else |
| 639 |
{ |
| 640 |
gimple_stmt_iterator gsi |
| 641 |
= gsi_start_bb (parser.current_bb); |
| 642 |
gsi_insert_seq_after (&gsi, *seq, GSI_CONTINUE_LINKING); |
| 643 |
} |
| 644 |
*seq = NULL; |
| 645 |
} |
| 646 |
|
| 647 |
/* Build an empty block with specified index, linking them |
| 648 |
in source order. */ |
| 649 |
basic_block bb = alloc_block (); |
| 650 |
bb->index = index; |
| 651 |
link_block (bb, (parser.current_bb ? parser.current_bb |
| 652 |
: ENTRY_BLOCK_PTR_FOR_FN (cfun))); |
| 653 |
if (basic_block_info_for_fn (cfun)->length () <= (size_t)index) |
| 654 |
vec_safe_grow_cleared (basic_block_info_for_fn (cfun), |
| 655 |
index + 1, true); |
| 656 |
SET_BASIC_BLOCK_FOR_FN (cfun, index, bb); |
| 657 |
if (last_basic_block_for_fn (cfun) <= index) |
| 658 |
last_basic_block_for_fn (cfun) = index + 1; |
| 659 |
n_basic_blocks_for_fn (cfun)++; |
| 660 |
if (parser.current_bb->index == ENTRY_BLOCK) |
| 661 |
parser.push_edge (ENTRY_BLOCK, bb->index, EDGE_FALLTHRU, |
| 662 |
profile_probability::always ()); |
| 663 |
|
| 664 |
/* We leave the proper setting to fixup. */ |
| 665 |
class loop *loop_father = loops_for_fn (cfun)->tree_root; |
| 666 |
/* If the new block is a loop header, allocate a loop |
| 667 |
struct. Fixup will take care of proper placement within |
| 668 |
the loop tree. */ |
| 669 |
if (is_loop_header_of != -1) |
| 670 |
{ |
| 671 |
if (number_of_loops (cfun) > (unsigned)is_loop_header_of |
| 672 |
&& get_loop (cfun, is_loop_header_of) != NULL) |
| 673 |
{ |
| 674 |
c_parser_error (parser, "duplicate loop header"); |
| 675 |
} |
| 676 |
else |
| 677 |
{ |
| 678 |
class loop *loop = alloc_loop (); |
| 679 |
loop->num = is_loop_header_of; |
| 680 |
loop->header = bb; |
| 681 |
if (number_of_loops (cfun) <= (unsigned)is_loop_header_of) |
| 682 |
vec_safe_grow_cleared (loops_for_fn (cfun)->larray, |
| 683 |
is_loop_header_of + 1, true); |
| 684 |
(*loops_for_fn (cfun)->larray)[is_loop_header_of] = loop; |
| 685 |
flow_loop_tree_node_add (loops_for_fn (cfun)->tree_root, |
| 686 |
loop); |
| 687 |
} |
| 688 |
loop_father = get_loop (cfun, is_loop_header_of); |
| 689 |
} |
| 690 |
bb->loop_father = loop_father; |
| 691 |
bb->count = bb_count; |
| 692 |
|
| 693 |
/* Stmts now go to the new block. */ |
| 694 |
parser.current_bb = bb; |
| 695 |
break; |
| 696 |
} |
| 697 |
goto expr_stmt; |
| 698 |
|
| 699 |
case CPP_SEMICOLON: |
| 700 |
{ |
| 701 |
/* Empty stmt. */ |
| 702 |
location_t loc = c_parser_peek_token (parser)->location; |
| 703 |
c_parser_consume_token (parser); |
| 704 |
gimple *nop = gimple_build_nop (); |
| 705 |
gimple_set_location (nop, loc); |
| 706 |
gimple_seq_add_stmt_without_update (seq, nop); |
| 707 |
break; |
| 708 |
} |
| 709 |
|
| 710 |
case CPP_CLOSE_PAREN: |
| 711 |
case CPP_CLOSE_SQUARE: |
| 712 |
/* Avoid infinite loop in error recovery: |
| 713 |
c_parser_skip_until_found stops at a closing nesting |
| 714 |
delimiter without consuming it, but here we need to consume |
| 715 |
it to proceed further. */ |
| 716 |
c_parser_error (parser, "expected statement"); |
| 717 |
c_parser_consume_token (parser); |
| 718 |
break; |
| 719 |
|
| 720 |
default: |
| 721 |
expr_stmt: |
| 722 |
c_parser_gimple_statement (parser, seq); |
| 723 |
if (! c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) |
| 724 |
c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); |
| 725 |
} |
| 726 |
} |
| 727 |
c_parser_consume_token (parser); |
| 728 |
|
| 729 |
/* Put stmts parsed in the current block. */ |
| 730 |
if ((cfun->curr_properties & PROP_cfg) |
| 731 |
&& !gimple_seq_empty_p (*seq)) |
| 732 |
{ |
| 733 |
if (!parser.current_bb) |
| 734 |
c_parser_error (parser, "stmts without block"); |
| 735 |
else |
| 736 |
{ |
| 737 |
gimple_stmt_iterator gsi = gsi_start_bb (parser.current_bb); |
| 738 |
gsi_insert_seq_after (&gsi, *seq, GSI_CONTINUE_LINKING); |
| 739 |
} |
| 740 |
*seq = NULL; |
| 741 |
} |
| 742 |
|
| 743 |
return return_p; |
| 744 |
} |
| 745 |
|
| 746 |
/* Parse a gimple statement. |
| 747 |
|
| 748 |
gimple-statement: |
| 749 |
gimple-call-expression |
| 750 |
gimple-assign-statement |
| 751 |
gimple-phi-statement |
| 752 |
|
| 753 |
gimple-assign-statement: |
| 754 |
gimple-unary-expression = gimple-assign-rhs |
| 755 |
|
| 756 |
gimple-assign-rhs: |
| 757 |
gimple-cast-expression |
| 758 |
gimple-unary-expression |
| 759 |
gimple-binary-expression |
| 760 |
gimple-call-expression |
| 761 |
|
| 762 |
gimple-phi-statement: |
| 763 |
identifier = __PHI ( label : gimple_primary-expression, ... ) |
| 764 |
|
| 765 |
gimple-call-expr: |
| 766 |
gimple-primary-expression ( argument-list ) |
| 767 |
|
| 768 |
gimple-cast-expression: |
| 769 |
( type-name ) gimple-primary-expression |
| 770 |
|
| 771 |
*/ |
| 772 |
|
| 773 |
static void |
| 774 |
c_parser_gimple_statement (gimple_parser &parser, gimple_seq *seq) |
| 775 |
{ |
| 776 |
struct c_expr lhs, rhs; |
| 777 |
gimple *assign = NULL; |
| 778 |
location_t loc; |
| 779 |
tree arg = NULL_TREE; |
| 780 |
auto_vec<tree> vargs; |
| 781 |
|
| 782 |
lhs = c_parser_gimple_unary_expression (parser); |
| 783 |
loc = EXPR_LOCATION (lhs.value); |
| 784 |
rhs.set_error (); |
| 785 |
|
| 786 |
/* GIMPLE call statement without LHS. */ |
| 787 |
if (c_parser_next_token_is (parser, CPP_SEMICOLON) |
| 788 |
&& TREE_CODE (lhs.value) == CALL_EXPR) |
| 789 |
{ |
| 790 |
gimple *call; |
| 791 |
call = gimple_build_call_from_tree (lhs.value, NULL); |
| 792 |
gimple_seq_add_stmt_without_update (seq, call); |
| 793 |
gimple_set_location (call, loc); |
| 794 |
return; |
| 795 |
} |
| 796 |
|
| 797 |
/* All following cases are statements with LHS. */ |
| 798 |
if (! c_parser_require (parser, CPP_EQ, "expected %<=%>")) |
| 799 |
return; |
| 800 |
|
| 801 |
/* Cast expression. */ |
| 802 |
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) |
| 803 |
&& c_token_starts_typename (c_parser_peek_2nd_token (parser))) |
| 804 |
{ |
| 805 |
c_parser_consume_token (parser); |
| 806 |
struct c_type_name *type_name = c_parser_type_name (parser); |
| 807 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
| 808 |
if (type_name == NULL) |
| 809 |
return; |
| 810 |
/* ??? The actual type used in the cast expression is ignored as |
| 811 |
in GIMPLE it is encoded by the type of the LHS. */ |
| 812 |
rhs = c_parser_gimple_postfix_expression (parser); |
| 813 |
if (lhs.value != error_mark_node |
| 814 |
&& rhs.value != error_mark_node) |
| 815 |
{ |
| 816 |
enum tree_code code = NOP_EXPR; |
| 817 |
if (FLOAT_TYPE_P (TREE_TYPE (lhs.value)) |
| 818 |
&& ! FLOAT_TYPE_P (TREE_TYPE (rhs.value))) |
| 819 |
code = FLOAT_EXPR; |
| 820 |
else if (! FLOAT_TYPE_P (TREE_TYPE (lhs.value)) |
| 821 |
&& FLOAT_TYPE_P (TREE_TYPE (rhs.value))) |
| 822 |
code = FIX_TRUNC_EXPR; |
| 823 |
assign = gimple_build_assign (lhs.value, code, rhs.value); |
| 824 |
gimple_seq_add_stmt_without_update (seq, assign); |
| 825 |
gimple_set_location (assign, loc); |
| 826 |
return; |
| 827 |
} |
| 828 |
} |
| 829 |
|
| 830 |
/* Unary expression. */ |
| 831 |
switch (c_parser_peek_token (parser)->type) |
| 832 |
{ |
| 833 |
case CPP_NAME: |
| 834 |
{ |
| 835 |
tree id = c_parser_peek_token (parser)->value; |
| 836 |
if (strcmp (IDENTIFIER_POINTER (id), "__ABS") == 0 |
| 837 |
|| strcmp (IDENTIFIER_POINTER (id), "__ABSU") == 0 |
| 838 |
|| strcmp (IDENTIFIER_POINTER (id), "__MIN") == 0 |
| 839 |
|| strcmp (IDENTIFIER_POINTER (id), "__MAX") == 0 |
| 840 |
|| strcmp (IDENTIFIER_POINTER (id), "__BIT_INSERT") == 0 |
| 841 |
|| strcmp (IDENTIFIER_POINTER (id), "__VEC_PERM") == 0) |
| 842 |
goto build_unary_expr; |
| 843 |
break; |
| 844 |
} |
| 845 |
case CPP_KEYWORD: |
| 846 |
if (c_parser_peek_token (parser)->keyword != RID_REALPART |
| 847 |
&& c_parser_peek_token (parser)->keyword != RID_IMAGPART) |
| 848 |
break; |
| 849 |
/* Fallthru. */ |
| 850 |
case CPP_AND: |
| 851 |
case CPP_PLUS: |
| 852 |
case CPP_MINUS: |
| 853 |
case CPP_COMPL: |
| 854 |
case CPP_NOT: |
| 855 |
case CPP_MULT: /* pointer deref */ |
| 856 |
build_unary_expr: |
| 857 |
rhs = c_parser_gimple_unary_expression (parser); |
| 858 |
if (rhs.value != error_mark_node) |
| 859 |
{ |
| 860 |
assign = gimple_build_assign (lhs.value, rhs.value); |
| 861 |
gimple_set_location (assign, loc); |
| 862 |
gimple_seq_add_stmt_without_update (seq, assign); |
| 863 |
} |
| 864 |
return; |
| 865 |
|
| 866 |
default:; |
| 867 |
} |
| 868 |
|
| 869 |
/* GIMPLE PHI statement. */ |
| 870 |
if (c_parser_next_token_is_keyword (parser, RID_PHI)) |
| 871 |
{ |
| 872 |
c_parser_consume_token (parser); |
| 873 |
|
| 874 |
if (! c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
| 875 |
return; |
| 876 |
|
| 877 |
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 878 |
c_parser_consume_token (parser); |
| 879 |
|
| 880 |
while (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN)) |
| 881 |
{ |
| 882 |
if (c_parser_next_token_is (parser, CPP_NAME) |
| 883 |
&& c_parser_peek_2nd_token (parser)->type == CPP_COLON) |
| 884 |
{ |
| 885 |
arg = c_parser_peek_token (parser)->value; |
| 886 |
c_parser_consume_token (parser); |
| 887 |
if (c_parser_next_token_is (parser, CPP_COLON)) |
| 888 |
c_parser_consume_token (parser); |
| 889 |
int src_index = -1; |
| 890 |
if (!c_parser_gimple_parse_bb_spec (arg, &src_index)) |
| 891 |
c_parser_error (parser, "invalid source block specification"); |
| 892 |
vargs.safe_push (size_int (src_index)); |
| 893 |
} |
| 894 |
else if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 895 |
c_parser_consume_token (parser); |
| 896 |
else |
| 897 |
{ |
| 898 |
arg = c_parser_gimple_unary_expression (parser).value; |
| 899 |
vargs.safe_push (arg); |
| 900 |
} |
| 901 |
} |
| 902 |
|
| 903 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 904 |
"expected %<)%>"); |
| 905 |
|
| 906 |
/* Build internal function for PHI. */ |
| 907 |
gcall *call_stmt = gimple_build_call_internal_vec (IFN_PHI, vargs); |
| 908 |
gimple_call_set_lhs (call_stmt, lhs.value); |
| 909 |
gimple_set_location (call_stmt, UNKNOWN_LOCATION); |
| 910 |
gimple_seq_add_stmt_without_update (seq, call_stmt); |
| 911 |
return; |
| 912 |
} |
| 913 |
|
| 914 |
/* GIMPLE call with lhs. */ |
| 915 |
if (c_parser_next_token_is (parser, CPP_DOT) |
| 916 |
|| (c_parser_next_token_is (parser, CPP_NAME) |
| 917 |
&& c_parser_peek_2nd_token (parser)->type == CPP_OPEN_PAREN |
| 918 |
&& lookup_name (c_parser_peek_token (parser)->value))) |
| 919 |
{ |
| 920 |
rhs = c_parser_gimple_unary_expression (parser); |
| 921 |
if (rhs.value != error_mark_node) |
| 922 |
{ |
| 923 |
gimple *call = gimple_build_call_from_tree (rhs.value, NULL); |
| 924 |
gimple_call_set_lhs (call, lhs.value); |
| 925 |
gimple_seq_add_stmt_without_update (seq, call); |
| 926 |
gimple_set_location (call, loc); |
| 927 |
} |
| 928 |
return; |
| 929 |
} |
| 930 |
|
| 931 |
rhs = c_parser_gimple_binary_expression (parser, TREE_TYPE (lhs.value)); |
| 932 |
if (lhs.value != error_mark_node |
| 933 |
&& rhs.value != error_mark_node) |
| 934 |
{ |
| 935 |
/* If we parsed an identifier and the next token is a '?' then parse |
| 936 |
a conditional expression. */ |
| 937 |
if (SSA_VAR_P (rhs.value) && c_parser_next_token_is (parser, CPP_QUERY)) |
| 938 |
{ |
| 939 |
struct c_expr trueval, falseval; |
| 940 |
c_parser_consume_token (parser); |
| 941 |
trueval = c_parser_gimple_postfix_expression (parser); |
| 942 |
falseval.set_error (); |
| 943 |
if (c_parser_require (parser, CPP_COLON, "expected %<:%>")) |
| 944 |
falseval = c_parser_gimple_postfix_expression (parser); |
| 945 |
if (trueval.value == error_mark_node |
| 946 |
|| falseval.value == error_mark_node) |
| 947 |
return; |
| 948 |
rhs.value = build3_loc (loc, |
| 949 |
VECTOR_TYPE_P (TREE_TYPE (rhs.value)) |
| 950 |
? VEC_COND_EXPR : COND_EXPR, |
| 951 |
TREE_TYPE (trueval.value), |
| 952 |
rhs.value, trueval.value, falseval.value); |
| 953 |
} |
| 954 |
if (get_gimple_rhs_class (TREE_CODE (rhs.value)) == GIMPLE_INVALID_RHS) |
| 955 |
{ |
| 956 |
c_parser_error (parser, "unexpected RHS for assignment"); |
| 957 |
return; |
| 958 |
} |
| 959 |
assign = gimple_build_assign (lhs.value, rhs.value); |
| 960 |
gimple_seq_add_stmt_without_update (seq, assign); |
| 961 |
gimple_set_location (assign, loc); |
| 962 |
} |
| 963 |
return; |
| 964 |
} |
| 965 |
|
| 966 |
/* Parse gimple binary expr. |
| 967 |
|
| 968 |
gimple-binary-expression: |
| 969 |
gimple-unary-expression * gimple-unary-expression |
| 970 |
gimple-unary-expression __MULT_HIGHPART gimple-unary-expression |
| 971 |
gimple-unary-expression / gimple-unary-expression |
| 972 |
gimple-unary-expression % gimple-unary-expression |
| 973 |
gimple-unary-expression + gimple-unary-expression |
| 974 |
gimple-unary-expression - gimple-unary-expression |
| 975 |
gimple-unary-expression << gimple-unary-expression |
| 976 |
gimple-unary-expression >> gimple-unary-expression |
| 977 |
gimple-unary-expression < gimple-unary-expression |
| 978 |
gimple-unary-expression > gimple-unary-expression |
| 979 |
gimple-unary-expression <= gimple-unary-expression |
| 980 |
gimple-unary-expression >= gimple-unary-expression |
| 981 |
gimple-unary-expression == gimple-unary-expression |
| 982 |
gimple-unary-expression != gimple-unary-expression |
| 983 |
gimple-unary-expression & gimple-unary-expression |
| 984 |
gimple-unary-expression ^ gimple-unary-expression |
| 985 |
gimple-unary-expression | gimple-unary-expression |
| 986 |
|
| 987 |
*/ |
| 988 |
|
| 989 |
static c_expr |
| 990 |
c_parser_gimple_binary_expression (gimple_parser &parser, tree ret_type) |
| 991 |
{ |
| 992 |
/* Location of the binary operator. */ |
| 993 |
struct c_expr ret, lhs, rhs; |
| 994 |
enum tree_code code = ERROR_MARK; |
| 995 |
ret.set_error (); |
| 996 |
lhs = c_parser_gimple_postfix_expression (parser); |
| 997 |
if (c_parser_error (parser)) |
| 998 |
return ret; |
| 999 |
switch (c_parser_peek_token (parser)->type) |
| 1000 |
{ |
| 1001 |
case CPP_MULT: |
| 1002 |
code = MULT_EXPR; |
| 1003 |
break; |
| 1004 |
case CPP_DIV: |
| 1005 |
code = TRUNC_DIV_EXPR; |
| 1006 |
break; |
| 1007 |
case CPP_MOD: |
| 1008 |
code = TRUNC_MOD_EXPR; |
| 1009 |
break; |
| 1010 |
case CPP_PLUS: |
| 1011 |
if (POINTER_TYPE_P (TREE_TYPE (lhs.value))) |
| 1012 |
code = POINTER_PLUS_EXPR; |
| 1013 |
else |
| 1014 |
code = PLUS_EXPR; |
| 1015 |
break; |
| 1016 |
case CPP_MINUS: |
| 1017 |
if (POINTER_TYPE_P (TREE_TYPE (lhs.value))) |
| 1018 |
code = POINTER_DIFF_EXPR; |
| 1019 |
else |
| 1020 |
code = MINUS_EXPR; |
| 1021 |
break; |
| 1022 |
case CPP_LSHIFT: |
| 1023 |
code = LSHIFT_EXPR; |
| 1024 |
break; |
| 1025 |
case CPP_RSHIFT: |
| 1026 |
code = RSHIFT_EXPR; |
| 1027 |
break; |
| 1028 |
case CPP_LESS: |
| 1029 |
code = LT_EXPR; |
| 1030 |
break; |
| 1031 |
case CPP_GREATER: |
| 1032 |
code = GT_EXPR; |
| 1033 |
break; |
| 1034 |
case CPP_LESS_EQ: |
| 1035 |
code = LE_EXPR; |
| 1036 |
break; |
| 1037 |
case CPP_GREATER_EQ: |
| 1038 |
code = GE_EXPR; |
| 1039 |
break; |
| 1040 |
case CPP_EQ_EQ: |
| 1041 |
code = EQ_EXPR; |
| 1042 |
break; |
| 1043 |
case CPP_NOT_EQ: |
| 1044 |
code = NE_EXPR; |
| 1045 |
break; |
| 1046 |
case CPP_AND: |
| 1047 |
code = BIT_AND_EXPR; |
| 1048 |
break; |
| 1049 |
case CPP_XOR: |
| 1050 |
code = BIT_XOR_EXPR; |
| 1051 |
break; |
| 1052 |
case CPP_OR: |
| 1053 |
code = BIT_IOR_EXPR; |
| 1054 |
break; |
| 1055 |
case CPP_AND_AND: |
| 1056 |
c_parser_error (parser, "%<&&%> not valid in GIMPLE"); |
| 1057 |
return ret; |
| 1058 |
case CPP_OR_OR: |
| 1059 |
c_parser_error (parser, "%<||%> not valid in GIMPLE"); |
| 1060 |
return ret; |
| 1061 |
case CPP_NAME: |
| 1062 |
{ |
| 1063 |
tree id = c_parser_peek_token (parser)->value; |
| 1064 |
if (strcmp (IDENTIFIER_POINTER (id), "__MULT_HIGHPART") == 0) |
| 1065 |
{ |
| 1066 |
code = MULT_HIGHPART_EXPR; |
| 1067 |
break; |
| 1068 |
} |
| 1069 |
else if (strcmp (IDENTIFIER_POINTER (id), "__UNLT") == 0) |
| 1070 |
{ |
| 1071 |
code = UNLT_EXPR; |
| 1072 |
break; |
| 1073 |
} |
| 1074 |
else if (strcmp (IDENTIFIER_POINTER (id), "__UNLE") == 0) |
| 1075 |
{ |
| 1076 |
code = UNLE_EXPR; |
| 1077 |
break; |
| 1078 |
} |
| 1079 |
else if (strcmp (IDENTIFIER_POINTER (id), "__UNGT") == 0) |
| 1080 |
{ |
| 1081 |
code = UNGT_EXPR; |
| 1082 |
break; |
| 1083 |
} |
| 1084 |
else if (strcmp (IDENTIFIER_POINTER (id), "__UNGE") == 0) |
| 1085 |
{ |
| 1086 |
code = UNGE_EXPR; |
| 1087 |
break; |
| 1088 |
} |
| 1089 |
else if (strcmp (IDENTIFIER_POINTER (id), "__UNEQ") == 0) |
| 1090 |
{ |
| 1091 |
code = UNEQ_EXPR; |
| 1092 |
break; |
| 1093 |
} |
| 1094 |
else if (strcmp (IDENTIFIER_POINTER (id), "__UNORDERED") == 0) |
| 1095 |
{ |
| 1096 |
code = UNORDERED_EXPR; |
| 1097 |
break; |
| 1098 |
} |
| 1099 |
else if (strcmp (IDENTIFIER_POINTER (id), "__ORDERED") == 0) |
| 1100 |
{ |
| 1101 |
code = ORDERED_EXPR; |
| 1102 |
break; |
| 1103 |
} |
| 1104 |
else if (strcmp (IDENTIFIER_POINTER (id), "__LTGT") == 0) |
| 1105 |
{ |
| 1106 |
code = LTGT_EXPR; |
| 1107 |
break; |
| 1108 |
} |
| 1109 |
else if (strcmp (IDENTIFIER_POINTER (id), "__FLOOR_DIV") == 0) |
| 1110 |
{ |
| 1111 |
code = FLOOR_DIV_EXPR; |
| 1112 |
break; |
| 1113 |
} |
| 1114 |
else if (strcmp (IDENTIFIER_POINTER (id), "__ROUND_DIV") == 0) |
| 1115 |
{ |
| 1116 |
code = ROUND_DIV_EXPR; |
| 1117 |
break; |
| 1118 |
} |
| 1119 |
else if (strcmp (IDENTIFIER_POINTER (id), "__EXACT_DIV") == 0) |
| 1120 |
{ |
| 1121 |
code = EXACT_DIV_EXPR; |
| 1122 |
break; |
| 1123 |
} |
| 1124 |
else if (strcmp (IDENTIFIER_POINTER (id), "__CEIL_DIV") == 0) |
| 1125 |
{ |
| 1126 |
code = CEIL_DIV_EXPR; |
| 1127 |
break; |
| 1128 |
} |
| 1129 |
else if (strcmp (IDENTIFIER_POINTER (id), "__FLOOR_MOD") == 0) |
| 1130 |
{ |
| 1131 |
code = FLOOR_MOD_EXPR; |
| 1132 |
break; |
| 1133 |
} |
| 1134 |
else if (strcmp (IDENTIFIER_POINTER (id), "__ROUND_MOD") == 0) |
| 1135 |
{ |
| 1136 |
code = ROUND_MOD_EXPR; |
| 1137 |
break; |
| 1138 |
} |
| 1139 |
else if (strcmp (IDENTIFIER_POINTER (id), "__CEIL_MOD") == 0) |
| 1140 |
{ |
| 1141 |
code = CEIL_MOD_EXPR; |
| 1142 |
break; |
| 1143 |
} |
| 1144 |
} |
| 1145 |
/* Fallthru. */ |
| 1146 |
default: |
| 1147 |
/* Not a binary expression. */ |
| 1148 |
return lhs; |
| 1149 |
} |
| 1150 |
location_t ret_loc = c_parser_peek_token (parser)->location; |
| 1151 |
c_parser_consume_token (parser); |
| 1152 |
rhs = c_parser_gimple_postfix_expression (parser); |
| 1153 |
if (lhs.value != error_mark_node && rhs.value != error_mark_node) |
| 1154 |
ret.value = build2_loc (ret_loc, code, ret_type, lhs.value, rhs.value); |
| 1155 |
return ret; |
| 1156 |
} |
| 1157 |
|
| 1158 |
/* Parse a gimple parentized binary expression. */ |
| 1159 |
|
| 1160 |
static c_expr |
| 1161 |
c_parser_gimple_parentized_binary_expression (gimple_parser &parser, |
| 1162 |
location_t op_loc, |
| 1163 |
tree_code code) |
| 1164 |
{ |
| 1165 |
struct c_expr ret; |
| 1166 |
ret.set_error (); |
| 1167 |
|
| 1168 |
c_parser_consume_token (parser); |
| 1169 |
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
| 1170 |
return ret; |
| 1171 |
c_expr op1 = c_parser_gimple_postfix_expression (parser); |
| 1172 |
if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) |
| 1173 |
return ret; |
| 1174 |
c_expr op2 = c_parser_gimple_postfix_expression (parser); |
| 1175 |
if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) |
| 1176 |
return ret; |
| 1177 |
|
| 1178 |
if (op1.value != error_mark_node && op2.value != error_mark_node) |
| 1179 |
ret.value = build2_loc (op_loc, |
| 1180 |
code, TREE_TYPE (op1.value), op1.value, op2.value); |
| 1181 |
return ret; |
| 1182 |
} |
| 1183 |
|
| 1184 |
/* Parse a gimple parentized binary expression. */ |
| 1185 |
|
| 1186 |
static c_expr |
| 1187 |
c_parser_gimple_parentized_ternary_expression (gimple_parser &parser, |
| 1188 |
location_t op_loc, |
| 1189 |
tree_code code) |
| 1190 |
{ |
| 1191 |
struct c_expr ret; |
| 1192 |
ret.set_error (); |
| 1193 |
|
| 1194 |
c_parser_consume_token (parser); |
| 1195 |
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
| 1196 |
return ret; |
| 1197 |
c_expr op1 = c_parser_gimple_postfix_expression (parser); |
| 1198 |
if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) |
| 1199 |
return ret; |
| 1200 |
c_expr op2 = c_parser_gimple_postfix_expression (parser); |
| 1201 |
if (!c_parser_require (parser, CPP_COMMA, "expected %<)%>")) |
| 1202 |
return ret; |
| 1203 |
c_expr op3 = c_parser_gimple_postfix_expression (parser); |
| 1204 |
if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) |
| 1205 |
return ret; |
| 1206 |
|
| 1207 |
if (op1.value != error_mark_node |
| 1208 |
&& op2.value != error_mark_node |
| 1209 |
&& op3.value != error_mark_node) |
| 1210 |
ret.value = build3_loc (op_loc, |
| 1211 |
code, TREE_TYPE (op1.value), |
| 1212 |
op1.value, op2.value, op3.value); |
| 1213 |
return ret; |
| 1214 |
} |
| 1215 |
|
| 1216 |
/* Parse gimple unary expression. |
| 1217 |
|
| 1218 |
gimple-unary-expression: |
| 1219 |
gimple-postfix-expression |
| 1220 |
unary-operator gimple-postfix-expression |
| 1221 |
|
| 1222 |
unary-operator: one of |
| 1223 |
& * + - ~ abs_expr |
| 1224 |
*/ |
| 1225 |
|
| 1226 |
static c_expr |
| 1227 |
c_parser_gimple_unary_expression (gimple_parser &parser) |
| 1228 |
{ |
| 1229 |
struct c_expr ret, op; |
| 1230 |
location_t op_loc = c_parser_peek_token (parser)->location; |
| 1231 |
location_t finish; |
| 1232 |
ret.set_error (); |
| 1233 |
switch (c_parser_peek_token (parser)->type) |
| 1234 |
{ |
| 1235 |
case CPP_AND: |
| 1236 |
c_parser_consume_token (parser); |
| 1237 |
op = c_parser_gimple_postfix_expression (parser); |
| 1238 |
mark_exp_read (op.value); |
| 1239 |
return gimple_parser_build_unary_op (op_loc, ADDR_EXPR, op); |
| 1240 |
case CPP_MULT: |
| 1241 |
{ |
| 1242 |
c_parser_consume_token (parser); |
| 1243 |
op = c_parser_gimple_postfix_expression (parser); |
| 1244 |
if (op.value == error_mark_node) |
| 1245 |
return ret; |
| 1246 |
if (! POINTER_TYPE_P (TREE_TYPE (op.value))) |
| 1247 |
{ |
| 1248 |
error_at (op_loc, "expected pointer as argument of unary %<*%>"); |
| 1249 |
return ret; |
| 1250 |
} |
| 1251 |
finish = op.get_finish (); |
| 1252 |
location_t combined_loc = make_location (op_loc, op_loc, finish); |
| 1253 |
ret.value = build_simple_mem_ref_loc (combined_loc, op.value); |
| 1254 |
TREE_SIDE_EFFECTS (ret.value) |
| 1255 |
= TREE_THIS_VOLATILE (ret.value) |
| 1256 |
= TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (op.value))); |
| 1257 |
ret.src_range.m_start = op_loc; |
| 1258 |
ret.src_range.m_finish = finish; |
| 1259 |
return ret; |
| 1260 |
} |
| 1261 |
case CPP_PLUS: |
| 1262 |
c_parser_consume_token (parser); |
| 1263 |
op = c_parser_gimple_postfix_expression (parser); |
| 1264 |
return gimple_parser_build_unary_op (op_loc, CONVERT_EXPR, op); |
| 1265 |
case CPP_MINUS: |
| 1266 |
c_parser_consume_token (parser); |
| 1267 |
op = c_parser_gimple_postfix_expression (parser); |
| 1268 |
return gimple_parser_build_unary_op (op_loc, NEGATE_EXPR, op); |
| 1269 |
case CPP_COMPL: |
| 1270 |
c_parser_consume_token (parser); |
| 1271 |
op = c_parser_gimple_postfix_expression (parser); |
| 1272 |
return gimple_parser_build_unary_op (op_loc, BIT_NOT_EXPR, op); |
| 1273 |
case CPP_NOT: |
| 1274 |
c_parser_error (parser, "%<!%> not valid in GIMPLE"); |
| 1275 |
return ret; |
| 1276 |
case CPP_KEYWORD: |
| 1277 |
switch (c_parser_peek_token (parser)->keyword) |
| 1278 |
{ |
| 1279 |
case RID_REALPART: |
| 1280 |
c_parser_consume_token (parser); |
| 1281 |
op = c_parser_gimple_postfix_expression (parser); |
| 1282 |
return gimple_parser_build_unary_op (op_loc, REALPART_EXPR, op); |
| 1283 |
case RID_IMAGPART: |
| 1284 |
c_parser_consume_token (parser); |
| 1285 |
op = c_parser_gimple_postfix_expression (parser); |
| 1286 |
return gimple_parser_build_unary_op (op_loc, IMAGPART_EXPR, op); |
| 1287 |
default: |
| 1288 |
return c_parser_gimple_postfix_expression (parser); |
| 1289 |
} |
| 1290 |
case CPP_NAME: |
| 1291 |
{ |
| 1292 |
tree id = c_parser_peek_token (parser)->value; |
| 1293 |
if (strcmp (IDENTIFIER_POINTER (id), "__ABS") == 0) |
| 1294 |
{ |
| 1295 |
c_parser_consume_token (parser); |
| 1296 |
op = c_parser_gimple_postfix_expression (parser); |
| 1297 |
return gimple_parser_build_unary_op (op_loc, ABS_EXPR, op); |
| 1298 |
} |
| 1299 |
else if (strcmp (IDENTIFIER_POINTER (id), "__ABSU") == 0) |
| 1300 |
{ |
| 1301 |
c_parser_consume_token (parser); |
| 1302 |
op = c_parser_gimple_postfix_expression (parser); |
| 1303 |
return gimple_parser_build_unary_op (op_loc, ABSU_EXPR, op); |
| 1304 |
} |
| 1305 |
else if (strcmp (IDENTIFIER_POINTER (id), "__MIN") == 0) |
| 1306 |
return c_parser_gimple_parentized_binary_expression (parser, |
| 1307 |
op_loc, |
| 1308 |
MIN_EXPR); |
| 1309 |
else if (strcmp (IDENTIFIER_POINTER (id), "__MAX") == 0) |
| 1310 |
return c_parser_gimple_parentized_binary_expression (parser, |
| 1311 |
op_loc, |
| 1312 |
MAX_EXPR); |
| 1313 |
else if (strcmp (IDENTIFIER_POINTER (id), "__VEC_PERM") == 0) |
| 1314 |
return c_parser_gimple_parentized_ternary_expression |
| 1315 |
(parser, op_loc, VEC_PERM_EXPR); |
| 1316 |
else if (strcmp (IDENTIFIER_POINTER (id), "__BIT_INSERT") == 0) |
| 1317 |
{ |
| 1318 |
/* __BIT_INSERT '(' postfix-expression, postfix-expression, |
| 1319 |
integer ')' */ |
| 1320 |
location_t loc = c_parser_peek_token (parser)->location; |
| 1321 |
c_parser_consume_token (parser); |
| 1322 |
if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
| 1323 |
{ |
| 1324 |
c_expr op0 = c_parser_gimple_postfix_expression (parser); |
| 1325 |
c_parser_skip_until_found (parser, CPP_COMMA, |
| 1326 |
"expected %<,%>"); |
| 1327 |
c_expr op1 = c_parser_gimple_postfix_expression (parser); |
| 1328 |
c_parser_skip_until_found (parser, CPP_COMMA, |
| 1329 |
"expected %<,%>"); |
| 1330 |
c_expr op2 = c_parser_gimple_postfix_expression (parser); |
| 1331 |
if (TREE_CODE (op2.value) != INTEGER_CST |
| 1332 |
|| !int_fits_type_p (op2.value, bitsizetype)) |
| 1333 |
c_parser_error (parser, "expected constant offset"); |
| 1334 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 1335 |
"expected %<)%>"); |
| 1336 |
if (op0.value != error_mark_node |
| 1337 |
&& op1.value != error_mark_node |
| 1338 |
&& TREE_CODE (op2.value) == INTEGER_CST) |
| 1339 |
ret.value = build3_loc (loc, BIT_INSERT_EXPR, |
| 1340 |
TREE_TYPE (op0.value), |
| 1341 |
op0.value, op1.value, |
| 1342 |
fold_convert (bitsizetype, |
| 1343 |
op2.value)); |
| 1344 |
} |
| 1345 |
return ret; |
| 1346 |
} |
| 1347 |
else |
| 1348 |
return c_parser_gimple_postfix_expression (parser); |
| 1349 |
} |
| 1350 |
default: |
| 1351 |
return c_parser_gimple_postfix_expression (parser); |
| 1352 |
} |
| 1353 |
} |
| 1354 |
|
| 1355 |
/* Decompose ID into base name (ID until ver_offset) and VERSION. Return |
| 1356 |
true if ID matches a SSA name. */ |
| 1357 |
|
| 1358 |
static bool |
| 1359 |
c_parser_parse_ssa_name_id (tree id, unsigned *version, unsigned *ver_offset) |
| 1360 |
{ |
| 1361 |
const char *token = IDENTIFIER_POINTER (id); |
| 1362 |
const char *var_version = strrchr (token, '_'); |
| 1363 |
if (! var_version) |
| 1364 |
return false; |
| 1365 |
|
| 1366 |
*ver_offset = var_version - token; |
| 1367 |
for (const char *p = var_version + 1; *p; ++p) |
| 1368 |
if (! ISDIGIT (*p)) |
| 1369 |
return false; |
| 1370 |
*version = atoi (var_version + 1); |
| 1371 |
return *version > 0; |
| 1372 |
} |
| 1373 |
|
| 1374 |
/* Get at the actual SSA name ID with VERSION starting at VER_OFFSET. |
| 1375 |
TYPE is the type if the SSA name is being declared. */ |
| 1376 |
|
| 1377 |
static tree |
| 1378 |
c_parser_parse_ssa_name (gimple_parser &parser, |
| 1379 |
tree id, tree type, unsigned version, |
| 1380 |
unsigned ver_offset) |
| 1381 |
{ |
| 1382 |
tree name = NULL_TREE; |
| 1383 |
const char *token = IDENTIFIER_POINTER (id); |
| 1384 |
|
| 1385 |
if (ver_offset == 0) |
| 1386 |
{ |
| 1387 |
/* Anonymous unnamed SSA name. */ |
| 1388 |
if (version < num_ssa_names) |
| 1389 |
name = ssa_name (version); |
| 1390 |
if (! name) |
| 1391 |
{ |
| 1392 |
if (! type) |
| 1393 |
{ |
| 1394 |
c_parser_error (parser, "SSA name undeclared"); |
| 1395 |
return error_mark_node; |
| 1396 |
} |
| 1397 |
name = make_ssa_name_fn (cfun, type, NULL, version); |
| 1398 |
} |
| 1399 |
} |
| 1400 |
else |
| 1401 |
{ |
| 1402 |
if (version < num_ssa_names) |
| 1403 |
name = ssa_name (version); |
| 1404 |
if (! name) |
| 1405 |
{ |
| 1406 |
/* Separate var name from version. */ |
| 1407 |
char *var_name = XNEWVEC (char, ver_offset + 1); |
| 1408 |
memcpy (var_name, token, ver_offset); |
| 1409 |
var_name[ver_offset] = '\0'; |
| 1410 |
/* lookup for parent decl. */ |
| 1411 |
id = get_identifier (var_name); |
| 1412 |
tree parent = lookup_name (id); |
| 1413 |
XDELETEVEC (var_name); |
| 1414 |
if (! parent || parent == error_mark_node) |
| 1415 |
{ |
| 1416 |
c_parser_error (parser, "base variable or SSA name undeclared"); |
| 1417 |
return error_mark_node; |
| 1418 |
} |
| 1419 |
if (!(VAR_P (parent) |
| 1420 |
|| TREE_CODE (parent) == PARM_DECL |
| 1421 |
|| TREE_CODE (parent) == RESULT_DECL)) |
| 1422 |
{ |
| 1423 |
error ("invalid base %qE for SSA name", parent); |
| 1424 |
return error_mark_node; |
| 1425 |
} |
| 1426 |
name = make_ssa_name_fn (cfun, parent, |
| 1427 |
gimple_build_nop (), version); |
| 1428 |
} |
| 1429 |
} |
| 1430 |
|
| 1431 |
return name; |
| 1432 |
} |
| 1433 |
|
| 1434 |
/* Parse a gimple call to an internal function. |
| 1435 |
|
| 1436 |
gimple-call-internal: |
| 1437 |
. identifier ( gimple-argument-expression-list[opt] ) */ |
| 1438 |
|
| 1439 |
static struct c_expr |
| 1440 |
c_parser_gimple_call_internal (gimple_parser &parser) |
| 1441 |
{ |
| 1442 |
struct c_expr expr; |
| 1443 |
expr.set_error (); |
| 1444 |
|
| 1445 |
gcc_assert (c_parser_next_token_is (parser, CPP_DOT)); |
| 1446 |
c_parser_consume_token (parser); |
| 1447 |
location_t loc = c_parser_peek_token (parser)->location; |
| 1448 |
if (!c_parser_next_token_is (parser, CPP_NAME) |
| 1449 |
|| c_parser_peek_token (parser)->id_kind != C_ID_ID) |
| 1450 |
{ |
| 1451 |
c_parser_error (parser, "expecting internal function name"); |
| 1452 |
return expr; |
| 1453 |
} |
| 1454 |
tree id = c_parser_peek_token (parser)->value; |
| 1455 |
internal_fn ifn = lookup_internal_fn (IDENTIFIER_POINTER (id)); |
| 1456 |
c_parser_consume_token (parser); |
| 1457 |
if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
| 1458 |
{ |
| 1459 |
auto_vec<tree> exprlist; |
| 1460 |
if (!c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 1461 |
c_parser_gimple_expr_list (parser, &exprlist); |
| 1462 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); |
| 1463 |
if (ifn == IFN_LAST) |
| 1464 |
error_at (loc, "unknown internal function %qE", id); |
| 1465 |
else |
| 1466 |
{ |
| 1467 |
expr.value = build_call_expr_internal_loc_array |
| 1468 |
(loc, ifn, void_type_node, exprlist.length (), |
| 1469 |
exprlist.address ()); |
| 1470 |
expr.original_code = ERROR_MARK; |
| 1471 |
expr.original_type = NULL; |
| 1472 |
expr.m_decimal = 0; |
| 1473 |
} |
| 1474 |
} |
| 1475 |
return expr; |
| 1476 |
} |
| 1477 |
|
| 1478 |
/* Parse '<' type [',' alignment] '>' and return a type on success |
| 1479 |
and NULL_TREE on error. */ |
| 1480 |
|
| 1481 |
static tree |
| 1482 |
c_parser_gimple_typespec (gimple_parser &parser) |
| 1483 |
{ |
| 1484 |
struct c_type_name *type_name = NULL; |
| 1485 |
tree alignment = NULL_TREE; |
| 1486 |
if (c_parser_require (parser, CPP_LESS, "expected %<<%>")) |
| 1487 |
{ |
| 1488 |
type_name = c_parser_type_name (parser); |
| 1489 |
/* Optional alignment. */ |
| 1490 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 1491 |
{ |
| 1492 |
c_parser_consume_token (parser); |
| 1493 |
alignment |
| 1494 |
= c_parser_gimple_postfix_expression (parser).value; |
| 1495 |
} |
| 1496 |
c_parser_skip_until_found (parser, |
| 1497 |
CPP_GREATER, "expected %<>%>"); |
| 1498 |
} |
| 1499 |
if (!type_name) |
| 1500 |
return NULL_TREE; |
| 1501 |
tree tem; |
| 1502 |
tree type = groktypename (type_name, &tem, NULL); |
| 1503 |
if (alignment) |
| 1504 |
type = build_aligned_type (type, tree_to_uhwi (alignment)); |
| 1505 |
return type; |
| 1506 |
} |
| 1507 |
|
| 1508 |
/* Parse gimple postfix expression. |
| 1509 |
|
| 1510 |
gimple-postfix-expression: |
| 1511 |
gimple-primary-expression |
| 1512 |
gimple-primary-expression [ gimple-primary-expression ] |
| 1513 |
gimple-primary-expression ( gimple-argument-expression-list[opt] ) |
| 1514 |
gimple-postfix-expression . identifier |
| 1515 |
gimple-postfix-expression -> identifier |
| 1516 |
|
| 1517 |
gimple-argument-expression-list: |
| 1518 |
gimple-unary-expression |
| 1519 |
gimple-argument-expression-list , gimple-unary-expression |
| 1520 |
|
| 1521 |
gimple-primary-expression: |
| 1522 |
identifier |
| 1523 |
constant |
| 1524 |
string-literal |
| 1525 |
constructor |
| 1526 |
gimple-call-internal |
| 1527 |
|
| 1528 |
*/ |
| 1529 |
|
| 1530 |
static struct c_expr |
| 1531 |
c_parser_gimple_postfix_expression (gimple_parser &parser) |
| 1532 |
{ |
| 1533 |
location_t loc = c_parser_peek_token (parser)->location; |
| 1534 |
source_range tok_range = c_parser_peek_token (parser)->get_range (); |
| 1535 |
struct c_expr expr; |
| 1536 |
expr.set_error (); |
| 1537 |
switch (c_parser_peek_token (parser)->type) |
| 1538 |
{ |
| 1539 |
case CPP_NUMBER: |
| 1540 |
expr.value = c_parser_peek_token (parser)->value; |
| 1541 |
set_c_expr_source_range (&expr, tok_range); |
| 1542 |
loc = c_parser_peek_token (parser)->location; |
| 1543 |
c_parser_consume_token (parser); |
| 1544 |
break; |
| 1545 |
case CPP_CHAR: |
| 1546 |
case CPP_CHAR16: |
| 1547 |
case CPP_CHAR32: |
| 1548 |
case CPP_UTF8CHAR: |
| 1549 |
case CPP_WCHAR: |
| 1550 |
expr.value = c_parser_peek_token (parser)->value; |
| 1551 |
set_c_expr_source_range (&expr, tok_range); |
| 1552 |
c_parser_consume_token (parser); |
| 1553 |
break; |
| 1554 |
case CPP_STRING: |
| 1555 |
case CPP_STRING16: |
| 1556 |
case CPP_STRING32: |
| 1557 |
case CPP_WSTRING: |
| 1558 |
case CPP_UTF8STRING: |
| 1559 |
expr = c_parser_string_literal (parser, false, true); |
| 1560 |
break; |
| 1561 |
case CPP_DOT: |
| 1562 |
expr = c_parser_gimple_call_internal (parser); |
| 1563 |
break; |
| 1564 |
case CPP_NAME: |
| 1565 |
if (c_parser_peek_token (parser)->id_kind == C_ID_ID) |
| 1566 |
{ |
| 1567 |
tree id = c_parser_peek_token (parser)->value; |
| 1568 |
if (strcmp (IDENTIFIER_POINTER (id), "__MEM") == 0) |
| 1569 |
{ |
| 1570 |
/* __MEM '<' type-name [ ',' number ] '>' |
| 1571 |
'(' [ '(' type-name ')' ] unary-expression |
| 1572 |
[ '+' number ] ')' */ |
| 1573 |
location_t loc = c_parser_peek_token (parser)->location; |
| 1574 |
c_parser_consume_token (parser); |
| 1575 |
tree type = c_parser_gimple_typespec (parser); |
| 1576 |
struct c_expr ptr, alias_off, step, index, index2; |
| 1577 |
ptr.value = error_mark_node; |
| 1578 |
alias_off.value = NULL_TREE; |
| 1579 |
step.value = NULL_TREE; |
| 1580 |
index.value = NULL_TREE; |
| 1581 |
index2.value = NULL_TREE; |
| 1582 |
if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
| 1583 |
{ |
| 1584 |
tree alias_type = NULL_TREE; |
| 1585 |
/* Optional alias-type cast. */ |
| 1586 |
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 1587 |
{ |
| 1588 |
c_parser_consume_token (parser); |
| 1589 |
struct c_type_name *alias_type_name |
| 1590 |
= c_parser_type_name (parser); |
| 1591 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 1592 |
"expected %<)%>"); |
| 1593 |
if (alias_type_name) |
| 1594 |
{ |
| 1595 |
tree tem; |
| 1596 |
alias_type = groktypename (alias_type_name, |
| 1597 |
&tem, NULL); |
| 1598 |
} |
| 1599 |
} |
| 1600 |
ptr = c_parser_gimple_unary_expression (parser); |
| 1601 |
if (ptr.value == error_mark_node |
| 1602 |
|| ! POINTER_TYPE_P (TREE_TYPE (ptr.value))) |
| 1603 |
{ |
| 1604 |
if (ptr.value != error_mark_node) |
| 1605 |
error_at (ptr.get_start (), |
| 1606 |
"invalid type of %<__MEM%> operand"); |
| 1607 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 1608 |
"expected %<)%>"); |
| 1609 |
return expr; |
| 1610 |
} |
| 1611 |
if (! alias_type) |
| 1612 |
alias_type = TREE_TYPE (ptr.value); |
| 1613 |
/* Optional constant offset. */ |
| 1614 |
if (c_parser_next_token_is (parser, CPP_PLUS)) |
| 1615 |
{ |
| 1616 |
c_parser_consume_token (parser); |
| 1617 |
alias_off = c_parser_gimple_postfix_expression (parser); |
| 1618 |
} |
| 1619 |
if (c_parser_next_token_is (parser, CPP_MULT)) |
| 1620 |
{ |
| 1621 |
std::swap (index, alias_off); |
| 1622 |
c_parser_consume_token (parser); |
| 1623 |
step = c_parser_gimple_postfix_expression (parser); |
| 1624 |
} |
| 1625 |
else if (c_parser_next_token_is (parser, CPP_PLUS)) |
| 1626 |
{ |
| 1627 |
c_parser_consume_token (parser); |
| 1628 |
index = c_parser_gimple_postfix_expression (parser); |
| 1629 |
if (c_parser_next_token_is (parser, CPP_MULT)) |
| 1630 |
{ |
| 1631 |
c_parser_consume_token (parser); |
| 1632 |
step = c_parser_gimple_postfix_expression (parser); |
| 1633 |
} |
| 1634 |
else |
| 1635 |
std::swap (index, index2); |
| 1636 |
} |
| 1637 |
else if (alias_off.value |
| 1638 |
&& TREE_CODE (alias_off.value) != INTEGER_CST) |
| 1639 |
std::swap (alias_off, index2); |
| 1640 |
if (c_parser_next_token_is (parser, CPP_PLUS)) |
| 1641 |
{ |
| 1642 |
c_parser_consume_token (parser); |
| 1643 |
index2 = c_parser_gimple_postfix_expression (parser); |
| 1644 |
} |
| 1645 |
if (alias_off.value) |
| 1646 |
{ |
| 1647 |
if (TREE_CODE (alias_off.value) != INTEGER_CST) |
| 1648 |
error_at (alias_off.get_start (), |
| 1649 |
"expected constant offset for %<__MEM%> " |
| 1650 |
"operand"); |
| 1651 |
alias_off.value = fold_convert (alias_type, |
| 1652 |
alias_off.value); |
| 1653 |
} |
| 1654 |
else |
| 1655 |
alias_off.value = build_int_cst (alias_type, 0); |
| 1656 |
if (step.value) |
| 1657 |
{ |
| 1658 |
if (TREE_CODE (step.value) != INTEGER_CST) |
| 1659 |
error_at (step.get_start (), |
| 1660 |
"expected constant step for %<__MEM%> " |
| 1661 |
"operand"); |
| 1662 |
} |
| 1663 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 1664 |
"expected %<)%>"); |
| 1665 |
} |
| 1666 |
if (! type || c_parser_error (parser)) |
| 1667 |
{ |
| 1668 |
c_parser_set_error (parser, false); |
| 1669 |
return expr; |
| 1670 |
} |
| 1671 |
if (index.value || step.value || index2.value) |
| 1672 |
expr.value = build5_loc (loc, TARGET_MEM_REF, |
| 1673 |
type, ptr.value, alias_off.value, |
| 1674 |
index.value, step.value, index2.value); |
| 1675 |
else |
| 1676 |
expr.value = build2_loc (loc, MEM_REF, |
| 1677 |
type, ptr.value, alias_off.value); |
| 1678 |
break; |
| 1679 |
} |
| 1680 |
else if (strcmp (IDENTIFIER_POINTER (id), "__VIEW_CONVERT") == 0) |
| 1681 |
{ |
| 1682 |
/* __VIEW_CONVERT '<' type-name [ ',' number ] '>' |
| 1683 |
'(' postfix-expression ')' */ |
| 1684 |
location_t loc = c_parser_peek_token (parser)->location; |
| 1685 |
c_parser_consume_token (parser); |
| 1686 |
tree type = c_parser_gimple_typespec (parser); |
| 1687 |
if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
| 1688 |
{ |
| 1689 |
c_expr op = c_parser_gimple_postfix_expression (parser); |
| 1690 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 1691 |
"expected %<)%>"); |
| 1692 |
if (type && op.value != error_mark_node) |
| 1693 |
expr.value = build1_loc (loc, VIEW_CONVERT_EXPR, |
| 1694 |
type, op.value); |
| 1695 |
} |
| 1696 |
break; |
| 1697 |
} |
| 1698 |
else if (strcmp (IDENTIFIER_POINTER (id), "__BIT_FIELD_REF") == 0) |
| 1699 |
{ |
| 1700 |
/* __BIT_FIELD_REF '<' type-name [ ',' number ] '>' |
| 1701 |
'(' postfix-expression, integer, integer ')' */ |
| 1702 |
location_t loc = c_parser_peek_token (parser)->location; |
| 1703 |
c_parser_consume_token (parser); |
| 1704 |
tree type = c_parser_gimple_typespec (parser); |
| 1705 |
if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
| 1706 |
{ |
| 1707 |
c_expr op0 = c_parser_gimple_postfix_expression (parser); |
| 1708 |
c_parser_skip_until_found (parser, CPP_COMMA, |
| 1709 |
"expected %<,%>"); |
| 1710 |
c_expr op1 = c_parser_gimple_postfix_expression (parser); |
| 1711 |
if (TREE_CODE (op1.value) != INTEGER_CST |
| 1712 |
|| !int_fits_type_p (op1.value, bitsizetype)) |
| 1713 |
c_parser_error (parser, "expected constant size"); |
| 1714 |
c_parser_skip_until_found (parser, CPP_COMMA, |
| 1715 |
"expected %<,%>"); |
| 1716 |
c_expr op2 = c_parser_gimple_postfix_expression (parser); |
| 1717 |
if (TREE_CODE (op2.value) != INTEGER_CST |
| 1718 |
|| !int_fits_type_p (op2.value, bitsizetype)) |
| 1719 |
c_parser_error (parser, "expected constant offset"); |
| 1720 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 1721 |
"expected %<)%>"); |
| 1722 |
if (type |
| 1723 |
&& op0.value != error_mark_node |
| 1724 |
&& TREE_CODE (op1.value) == INTEGER_CST |
| 1725 |
&& TREE_CODE (op2.value) == INTEGER_CST) |
| 1726 |
expr.value = build3_loc (loc, BIT_FIELD_REF, type, |
| 1727 |
op0.value, |
| 1728 |
fold_convert (bitsizetype, |
| 1729 |
op1.value), |
| 1730 |
fold_convert (bitsizetype, |
| 1731 |
op2.value)); |
| 1732 |
} |
| 1733 |
break; |
| 1734 |
} |
| 1735 |
else if (strcmp (IDENTIFIER_POINTER (id), "_Literal") == 0) |
| 1736 |
{ |
| 1737 |
/* _Literal '(' type-name ')' ( [ '-' ] constant | constructor ) */ |
| 1738 |
c_parser_consume_token (parser); |
| 1739 |
tree type = NULL_TREE; |
| 1740 |
if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
| 1741 |
{ |
| 1742 |
struct c_type_name *type_name = c_parser_type_name (parser); |
| 1743 |
tree tem; |
| 1744 |
if (type_name) |
| 1745 |
type = groktypename (type_name, &tem, NULL); |
| 1746 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 1747 |
"expected %<)%>"); |
| 1748 |
} |
| 1749 |
if (! type) |
| 1750 |
{ |
| 1751 |
c_parser_error (parser, "invalid _Literal"); |
| 1752 |
return expr; |
| 1753 |
} |
| 1754 |
if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
| 1755 |
{ |
| 1756 |
c_parser_consume_token (parser); |
| 1757 |
if (!AGGREGATE_TYPE_P (type) |
| 1758 |
&& !VECTOR_TYPE_P (type)) |
| 1759 |
{ |
| 1760 |
c_parser_error (parser, "invalid type for _Literal with " |
| 1761 |
"constructor"); |
| 1762 |
c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, |
| 1763 |
"expected %<}%>"); |
| 1764 |
return expr; |
| 1765 |
} |
| 1766 |
vec<constructor_elt, va_gc> *v = NULL; |
| 1767 |
bool constant_p = true; |
| 1768 |
if (VECTOR_TYPE_P (type) |
| 1769 |
&& !c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 1770 |
{ |
| 1771 |
vec_alloc (v, TYPE_VECTOR_SUBPARTS (type).to_constant ()); |
| 1772 |
do |
| 1773 |
{ |
| 1774 |
tree val |
| 1775 |
= c_parser_gimple_postfix_expression (parser).value; |
| 1776 |
if (! val |
| 1777 |
|| val == error_mark_node |
| 1778 |
|| (! CONSTANT_CLASS_P (val) |
| 1779 |
&& ! SSA_VAR_P (val))) |
| 1780 |
{ |
| 1781 |
c_parser_error (parser, "invalid _Literal"); |
| 1782 |
return expr; |
| 1783 |
} |
| 1784 |
CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, val); |
| 1785 |
if (! CONSTANT_CLASS_P (val)) |
| 1786 |
constant_p = false; |
| 1787 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 1788 |
c_parser_consume_token (parser); |
| 1789 |
else |
| 1790 |
break; |
| 1791 |
} |
| 1792 |
while (1); |
| 1793 |
} |
| 1794 |
if (c_parser_require (parser, CPP_CLOSE_BRACE, |
| 1795 |
"expected %<}%>")) |
| 1796 |
{ |
| 1797 |
if (v && constant_p) |
| 1798 |
expr.value = build_vector_from_ctor (type, v); |
| 1799 |
else |
| 1800 |
expr.value = build_constructor (type, v); |
| 1801 |
} |
| 1802 |
else |
| 1803 |
{ |
| 1804 |
c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, |
| 1805 |
"expected %<}%>"); |
| 1806 |
return expr; |
| 1807 |
} |
| 1808 |
} |
| 1809 |
else |
| 1810 |
{ |
| 1811 |
bool neg_p, addr_p; |
| 1812 |
if ((neg_p = c_parser_next_token_is (parser, CPP_MINUS))) |
| 1813 |
c_parser_consume_token (parser); |
| 1814 |
if ((addr_p = c_parser_next_token_is (parser, CPP_AND))) |
| 1815 |
c_parser_consume_token (parser); |
| 1816 |
tree val = c_parser_gimple_postfix_expression (parser).value; |
| 1817 |
if (! val |
| 1818 |
|| val == error_mark_node |
| 1819 |
|| (!CONSTANT_CLASS_P (val) && !addr_p)) |
| 1820 |
{ |
| 1821 |
c_parser_error (parser, "invalid _Literal"); |
| 1822 |
return expr; |
| 1823 |
} |
| 1824 |
if (addr_p) |
| 1825 |
{ |
| 1826 |
val = build1 (ADDR_EXPR, type, val); |
| 1827 |
if (!is_gimple_invariant_address (val)) |
| 1828 |
{ |
| 1829 |
c_parser_error (parser, "invalid _Literal"); |
| 1830 |
return expr; |
| 1831 |
} |
| 1832 |
} |
| 1833 |
if (neg_p) |
| 1834 |
{ |
| 1835 |
val = const_unop (NEGATE_EXPR, TREE_TYPE (val), val); |
| 1836 |
if (! val) |
| 1837 |
{ |
| 1838 |
c_parser_error (parser, "invalid _Literal"); |
| 1839 |
return expr; |
| 1840 |
} |
| 1841 |
} |
| 1842 |
expr.value = fold_convert (type, val); |
| 1843 |
} |
| 1844 |
return expr; |
| 1845 |
} |
| 1846 |
|
| 1847 |
/* SSA name. */ |
| 1848 |
unsigned version, ver_offset; |
| 1849 |
if (! lookup_name (id) |
| 1850 |
&& c_parser_parse_ssa_name_id (id, &version, &ver_offset)) |
| 1851 |
{ |
| 1852 |
c_parser_consume_token (parser); |
| 1853 |
expr.value = c_parser_parse_ssa_name (parser, id, NULL_TREE, |
| 1854 |
version, ver_offset); |
| 1855 |
if (expr.value == error_mark_node) |
| 1856 |
return expr; |
| 1857 |
set_c_expr_source_range (&expr, tok_range); |
| 1858 |
/* For default definition SSA names. */ |
| 1859 |
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) |
| 1860 |
&& c_parser_peek_2nd_token (parser)->type == CPP_NAME |
| 1861 |
&& strcmp ("D", |
| 1862 |
IDENTIFIER_POINTER |
| 1863 |
(c_parser_peek_2nd_token (parser)->value)) == 0 |
| 1864 |
&& c_parser_peek_nth_token (parser, 3)->type == CPP_CLOSE_PAREN) |
| 1865 |
{ |
| 1866 |
c_parser_consume_token (parser); |
| 1867 |
c_parser_consume_token (parser); |
| 1868 |
c_parser_consume_token (parser); |
| 1869 |
if (! SSA_NAME_IS_DEFAULT_DEF (expr.value)) |
| 1870 |
{ |
| 1871 |
if (!SSA_NAME_VAR (expr.value)) |
| 1872 |
{ |
| 1873 |
error_at (loc, "anonymous SSA name cannot have" |
| 1874 |
" default definition"); |
| 1875 |
expr.value = error_mark_node; |
| 1876 |
return expr; |
| 1877 |
} |
| 1878 |
set_ssa_default_def (cfun, SSA_NAME_VAR (expr.value), |
| 1879 |
expr.value); |
| 1880 |
SSA_NAME_DEF_STMT (expr.value) = gimple_build_nop (); |
| 1881 |
} |
| 1882 |
} |
| 1883 |
} |
| 1884 |
else |
| 1885 |
{ |
| 1886 |
c_parser_consume_token (parser); |
| 1887 |
expr.value |
| 1888 |
= build_external_ref (loc, id, |
| 1889 |
(c_parser_peek_token (parser)->type |
| 1890 |
== CPP_OPEN_PAREN), &expr.original_type); |
| 1891 |
set_c_expr_source_range (&expr, tok_range); |
| 1892 |
} |
| 1893 |
break; |
| 1894 |
} |
| 1895 |
/* Fallthru. */ |
| 1896 |
default: |
| 1897 |
c_parser_error (parser, "expected expression"); |
| 1898 |
expr.set_error (); |
| 1899 |
break; |
| 1900 |
} |
| 1901 |
if (expr.value == error_mark_node) |
| 1902 |
return expr; |
| 1903 |
return c_parser_gimple_postfix_expression_after_primary |
| 1904 |
(parser, EXPR_LOC_OR_LOC (expr.value, loc), expr); |
| 1905 |
} |
| 1906 |
|
| 1907 |
/* Parse a gimple postfix expression after the initial primary or compound |
| 1908 |
literal. */ |
| 1909 |
|
| 1910 |
static struct c_expr |
| 1911 |
c_parser_gimple_postfix_expression_after_primary (gimple_parser &parser, |
| 1912 |
location_t expr_loc, |
| 1913 |
struct c_expr expr) |
| 1914 |
{ |
| 1915 |
location_t start; |
| 1916 |
location_t finish; |
| 1917 |
tree ident; |
| 1918 |
location_t comp_loc; |
| 1919 |
|
| 1920 |
while (true) |
| 1921 |
{ |
| 1922 |
location_t op_loc = c_parser_peek_token (parser)->location; |
| 1923 |
switch (c_parser_peek_token (parser)->type) |
| 1924 |
{ |
| 1925 |
case CPP_OPEN_SQUARE: |
| 1926 |
{ |
| 1927 |
c_parser_consume_token (parser); |
| 1928 |
tree idx = c_parser_gimple_unary_expression (parser).value; |
| 1929 |
|
| 1930 |
if (! c_parser_require (parser, CPP_CLOSE_SQUARE, "expected %<]%>")) |
| 1931 |
{ |
| 1932 |
c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); |
| 1933 |
break; |
| 1934 |
} |
| 1935 |
|
| 1936 |
start = expr.get_start (); |
| 1937 |
finish = c_parser_tokens_buf (parser, 0)->location; |
| 1938 |
expr.value = build_array_ref (op_loc, expr.value, idx); |
| 1939 |
set_c_expr_source_range (&expr, start, finish); |
| 1940 |
expr.m_decimal = 0; |
| 1941 |
|
| 1942 |
expr.original_code = ERROR_MARK; |
| 1943 |
expr.original_type = NULL; |
| 1944 |
break; |
| 1945 |
} |
| 1946 |
case CPP_OPEN_PAREN: |
| 1947 |
{ |
| 1948 |
/* Function call. */ |
| 1949 |
c_parser_consume_token (parser); |
| 1950 |
auto_vec<tree> exprlist; |
| 1951 |
if (! c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 1952 |
c_parser_gimple_expr_list (parser, &exprlist); |
| 1953 |
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 1954 |
"expected %<)%>"); |
| 1955 |
if (!FUNC_OR_METHOD_TYPE_P (TREE_TYPE (expr.value))) |
| 1956 |
{ |
| 1957 |
c_parser_error (parser, "invalid call to non-function"); |
| 1958 |
expr.set_error (); |
| 1959 |
break; |
| 1960 |
} |
| 1961 |
expr.value = build_call_array_loc |
| 1962 |
(expr_loc, TREE_TYPE (TREE_TYPE (expr.value)), |
| 1963 |
expr.value, exprlist.length (), exprlist.address ()); |
| 1964 |
expr.m_decimal = 0; |
| 1965 |
expr.original_code = ERROR_MARK; |
| 1966 |
expr.original_type = NULL; |
| 1967 |
break; |
| 1968 |
} |
| 1969 |
case CPP_DOT: |
| 1970 |
{ |
| 1971 |
/* Structure element reference. */ |
| 1972 |
c_parser_consume_token (parser); |
| 1973 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 1974 |
{ |
| 1975 |
c_token *comp_tok = c_parser_peek_token (parser); |
| 1976 |
ident = comp_tok->value; |
| 1977 |
comp_loc = comp_tok->location; |
| 1978 |
} |
| 1979 |
else |
| 1980 |
{ |
| 1981 |
c_parser_error (parser, "expected identifier"); |
| 1982 |
expr.set_error (); |
| 1983 |
expr.original_code = ERROR_MARK; |
| 1984 |
expr.original_type = NULL; |
| 1985 |
return expr; |
| 1986 |
} |
| 1987 |
start = expr.get_start (); |
| 1988 |
finish = c_parser_peek_token (parser)->get_finish (); |
| 1989 |
c_parser_consume_token (parser); |
| 1990 |
expr.value = build_component_ref (op_loc, expr.value, ident, |
| 1991 |
comp_loc, UNKNOWN_LOCATION); |
| 1992 |
set_c_expr_source_range (&expr, start, finish); |
| 1993 |
expr.m_decimal = 0; |
| 1994 |
expr.original_code = ERROR_MARK; |
| 1995 |
if (TREE_CODE (expr.value) != COMPONENT_REF) |
| 1996 |
expr.original_type = NULL; |
| 1997 |
else |
| 1998 |
{ |
| 1999 |
/* Remember the original type of a bitfield. */ |
| 2000 |
tree field = TREE_OPERAND (expr.value, 1); |
| 2001 |
if (TREE_CODE (field) != FIELD_DECL) |
| 2002 |
expr.original_type = NULL; |
| 2003 |
else |
| 2004 |
expr.original_type = DECL_BIT_FIELD_TYPE (field); |
| 2005 |
} |
| 2006 |
break; |
| 2007 |
} |
| 2008 |
case CPP_DEREF: |
| 2009 |
{ |
| 2010 |
/* Structure element reference. */ |
| 2011 |
if (!POINTER_TYPE_P (TREE_TYPE (expr.value))) |
| 2012 |
{ |
| 2013 |
c_parser_error (parser, "dereference of non-pointer"); |
| 2014 |
expr.set_error (); |
| 2015 |
expr.original_code = ERROR_MARK; |
| 2016 |
expr.original_type = NULL; |
| 2017 |
return expr; |
| 2018 |
} |
| 2019 |
c_parser_consume_token (parser); |
| 2020 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 2021 |
{ |
| 2022 |
c_token *comp_tok = c_parser_peek_token (parser); |
| 2023 |
ident = comp_tok->value; |
| 2024 |
comp_loc = comp_tok->location; |
| 2025 |
} |
| 2026 |
else |
| 2027 |
{ |
| 2028 |
c_parser_error (parser, "expected identifier"); |
| 2029 |
expr.set_error (); |
| 2030 |
expr.original_code = ERROR_MARK; |
| 2031 |
expr.original_type = NULL; |
| 2032 |
return expr; |
| 2033 |
} |
| 2034 |
start = expr.get_start (); |
| 2035 |
finish = c_parser_peek_token (parser)->get_finish (); |
| 2036 |
c_parser_consume_token (parser); |
| 2037 |
expr.value = build_component_ref (op_loc, |
| 2038 |
build_simple_mem_ref_loc |
| 2039 |
(op_loc, expr.value), |
| 2040 |
ident, comp_loc, |
| 2041 |
expr.get_location ()); |
| 2042 |
set_c_expr_source_range (&expr, start, finish); |
| 2043 |
expr.m_decimal = 0; |
| 2044 |
expr.original_code = ERROR_MARK; |
| 2045 |
if (TREE_CODE (expr.value) != COMPONENT_REF) |
| 2046 |
expr.original_type = NULL; |
| 2047 |
else |
| 2048 |
{ |
| 2049 |
/* Remember the original type of a bitfield. */ |
| 2050 |
tree field = TREE_OPERAND (expr.value, 1); |
| 2051 |
if (TREE_CODE (field) != FIELD_DECL) |
| 2052 |
expr.original_type = NULL; |
| 2053 |
else |
| 2054 |
expr.original_type = DECL_BIT_FIELD_TYPE (field); |
| 2055 |
} |
| 2056 |
break; |
| 2057 |
} |
| 2058 |
default: |
| 2059 |
return expr; |
| 2060 |
} |
| 2061 |
} |
| 2062 |
} |
| 2063 |
|
| 2064 |
/* Parse expression list. |
| 2065 |
|
| 2066 |
gimple-expr-list: |
| 2067 |
gimple-unary-expression |
| 2068 |
gimple-expr-list , gimple-unary-expression |
| 2069 |
|
| 2070 |
*/ |
| 2071 |
|
| 2072 |
static void |
| 2073 |
c_parser_gimple_expr_list (gimple_parser &parser, vec<tree> *ret) |
| 2074 |
{ |
| 2075 |
struct c_expr expr; |
| 2076 |
|
| 2077 |
expr = c_parser_gimple_unary_expression (parser); |
| 2078 |
ret->safe_push (expr.value); |
| 2079 |
while (c_parser_next_token_is (parser, CPP_COMMA)) |
| 2080 |
{ |
| 2081 |
c_parser_consume_token (parser); |
| 2082 |
expr = c_parser_gimple_unary_expression (parser); |
| 2083 |
ret->safe_push (expr.value); |
| 2084 |
} |
| 2085 |
} |
| 2086 |
|
| 2087 |
/* Parse gimple label. |
| 2088 |
|
| 2089 |
gimple-label: |
| 2090 |
identifier : |
| 2091 |
case constant-expression : |
| 2092 |
default : |
| 2093 |
|
| 2094 |
*/ |
| 2095 |
|
| 2096 |
static void |
| 2097 |
c_parser_gimple_label (gimple_parser &parser, gimple_seq *seq) |
| 2098 |
{ |
| 2099 |
tree name = c_parser_peek_token (parser)->value; |
| 2100 |
location_t loc1 = c_parser_peek_token (parser)->location; |
| 2101 |
gcc_assert (c_parser_next_token_is (parser, CPP_NAME)); |
| 2102 |
c_parser_consume_token (parser); |
| 2103 |
gcc_assert (c_parser_next_token_is (parser, CPP_COLON)); |
| 2104 |
c_parser_consume_token (parser); |
| 2105 |
tree label = define_label (loc1, name); |
| 2106 |
if (label) |
| 2107 |
gimple_seq_add_stmt_without_update (seq, gimple_build_label (label)); |
| 2108 |
return; |
| 2109 |
} |
| 2110 |
|
| 2111 |
/* Parse gimple/RTL pass list. |
| 2112 |
|
| 2113 |
gimple-or-rtl-pass-list: |
| 2114 |
startwith("pass-name")[,{cfg,ssa}] |
| 2115 |
*/ |
| 2116 |
|
| 2117 |
void |
| 2118 |
c_parser_gimple_or_rtl_pass_list (c_parser *parser, c_declspecs *specs) |
| 2119 |
{ |
| 2120 |
char *pass = NULL; |
| 2121 |
|
| 2122 |
/* Accept __GIMPLE/__RTL. */ |
| 2123 |
if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN)) |
| 2124 |
return; |
| 2125 |
c_parser_consume_token (parser); |
| 2126 |
|
| 2127 |
specs->entry_bb_count = profile_count::uninitialized (); |
| 2128 |
while (c_parser_next_token_is (parser, CPP_NAME)) |
| 2129 |
{ |
| 2130 |
profile_quality quality; |
| 2131 |
const char *op = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 2132 |
c_parser_consume_token (parser); |
| 2133 |
if (! strcmp (op, "startwith")) |
| 2134 |
{ |
| 2135 |
if (! c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
| 2136 |
return; |
| 2137 |
if (c_parser_next_token_is_not (parser, CPP_STRING)) |
| 2138 |
{ |
| 2139 |
error_at (c_parser_peek_token (parser)->location, |
| 2140 |
"expected pass name"); |
| 2141 |
return; |
| 2142 |
} |
| 2143 |
pass = xstrdup (TREE_STRING_POINTER |
| 2144 |
(c_parser_string_literal (parser, false, |
| 2145 |
false).value)); |
| 2146 |
if (! c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<(%>")) |
| 2147 |
return; |
| 2148 |
} |
| 2149 |
else if (parse_profile_quality (op, &quality)) |
| 2150 |
{ |
| 2151 |
tree q; |
| 2152 |
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
| 2153 |
return; |
| 2154 |
|
| 2155 |
if (!c_parser_next_token_is (parser, CPP_NUMBER) |
| 2156 |
|| (TREE_CODE (q = c_parser_peek_token (parser)->value) |
| 2157 |
!= INTEGER_CST)) |
| 2158 |
{ |
| 2159 |
c_parser_error (parser, "expected count value"); |
| 2160 |
return; |
| 2161 |
} |
| 2162 |
|
| 2163 |
specs->entry_bb_count |
| 2164 |
= profile_count::from_gcov_type (TREE_INT_CST_LOW (q), quality); |
| 2165 |
c_parser_consume_token (parser); |
| 2166 |
if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) |
| 2167 |
return; |
| 2168 |
} |
| 2169 |
else if (specs->declspec_il != cdil_gimple) |
| 2170 |
/* Allow only one IL specifier and none on RTL. */ |
| 2171 |
; |
| 2172 |
else if (! strcmp (op, "cfg")) |
| 2173 |
specs->declspec_il = cdil_gimple_cfg; |
| 2174 |
else if (! strcmp (op, "ssa")) |
| 2175 |
specs->declspec_il = cdil_gimple_ssa; |
| 2176 |
else |
| 2177 |
{ |
| 2178 |
error_at (c_parser_peek_token (parser)->location, |
| 2179 |
"invalid operation"); |
| 2180 |
return; |
| 2181 |
} |
| 2182 |
if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 2183 |
c_parser_consume_token (parser); |
| 2184 |
} |
| 2185 |
|
| 2186 |
if (! c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) |
| 2187 |
return; |
| 2188 |
|
| 2189 |
specs->gimple_or_rtl_pass = pass; |
| 2190 |
} |
| 2191 |
|
| 2192 |
/* Parse gimple local declaration. |
| 2193 |
|
| 2194 |
declaration-specifiers: |
| 2195 |
storage-class-specifier declaration-specifiers[opt] |
| 2196 |
type-specifier declaration-specifiers[opt] |
| 2197 |
type-qualifier declaration-specifiers[opt] |
| 2198 |
function-specifier declaration-specifiers[opt] |
| 2199 |
alignment-specifier declaration-specifiers[opt] |
| 2200 |
|
| 2201 |
storage-class-specifier: |
| 2202 |
typedef |
| 2203 |
extern |
| 2204 |
static |
| 2205 |
auto |
| 2206 |
register |
| 2207 |
|
| 2208 |
type-specifier: |
| 2209 |
void |
| 2210 |
char |
| 2211 |
short |
| 2212 |
int |
| 2213 |
long |
| 2214 |
float |
| 2215 |
double |
| 2216 |
signed |
| 2217 |
unsigned |
| 2218 |
_Bool |
| 2219 |
_Complex |
| 2220 |
|
| 2221 |
type-qualifier: |
| 2222 |
const |
| 2223 |
restrict |
| 2224 |
volatile |
| 2225 |
address-space-qualifier |
| 2226 |
_Atomic |
| 2227 |
|
| 2228 |
*/ |
| 2229 |
|
| 2230 |
static void |
| 2231 |
c_parser_gimple_declaration (gimple_parser &parser) |
| 2232 |
{ |
| 2233 |
struct c_declarator *declarator; |
| 2234 |
struct c_declspecs *specs = build_null_declspecs (); |
| 2235 |
c_parser_declspecs (parser, specs, true, true, true, |
| 2236 |
true, true, true, true, cla_nonabstract_decl); |
| 2237 |
finish_declspecs (specs); |
| 2238 |
|
| 2239 |
/* Provide better error recovery. Note that a type name here is usually |
| 2240 |
better diagnosed as a redeclaration. */ |
| 2241 |
if (c_parser_next_token_starts_declspecs (parser) |
| 2242 |
&& ! c_parser_next_token_is (parser, CPP_NAME)) |
| 2243 |
{ |
| 2244 |
c_parser_error (parser, "expected %<;%>"); |
| 2245 |
c_parser_set_error (parser, false); |
| 2246 |
return; |
| 2247 |
} |
| 2248 |
|
| 2249 |
bool dummy = false; |
| 2250 |
declarator = c_parser_declarator (parser, |
| 2251 |
specs->typespec_kind != ctsk_none, |
| 2252 |
C_DTR_NORMAL, &dummy); |
| 2253 |
|
| 2254 |
if (!c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 2255 |
{ |
| 2256 |
c_parser_error (parser, "expected %<;%>"); |
| 2257 |
return; |
| 2258 |
} |
| 2259 |
if (declarator) |
| 2260 |
{ |
| 2261 |
/* Handle SSA name decls specially, they do not go into the identifier |
| 2262 |
table but we simply build the SSA name for later lookup. */ |
| 2263 |
unsigned version, ver_offset; |
| 2264 |
/* Handle SSA pointer declarations in a very simplistic ways, we |
| 2265 |
probably would like to call grokdeclarator in a special mode to |
| 2266 |
just build the type of the decl - start_decl already pushes |
| 2267 |
the identifier to the bindings for lookup, something we do not |
| 2268 |
want. */ |
| 2269 |
struct c_declarator *id_declarator = declarator; |
| 2270 |
while (id_declarator->kind == cdk_pointer) |
| 2271 |
id_declarator = id_declarator->declarator; |
| 2272 |
if (id_declarator->kind == cdk_id |
| 2273 |
&& (declarator->kind == cdk_pointer |
| 2274 |
|| is_gimple_reg_type (specs->type)) |
| 2275 |
&& c_parser_parse_ssa_name_id (id_declarator->u.id.id, |
| 2276 |
&version, &ver_offset) |
| 2277 |
/* The following restricts it to unnamed anonymous SSA names |
| 2278 |
which fails parsing of named ones in dumps (we could |
| 2279 |
decide to not dump their name for -gimple). */ |
| 2280 |
&& ver_offset == 0) |
| 2281 |
{ |
| 2282 |
struct c_declarator *p = declarator; |
| 2283 |
tree type = specs->type; |
| 2284 |
while (p->kind == cdk_pointer) |
| 2285 |
{ |
| 2286 |
type = build_pointer_type (type); |
| 2287 |
p = p->declarator; |
| 2288 |
} |
| 2289 |
c_parser_parse_ssa_name (parser, id_declarator->u.id.id, type, |
| 2290 |
version, ver_offset); |
| 2291 |
} |
| 2292 |
else |
| 2293 |
{ |
| 2294 |
tree postfix_attrs = NULL_TREE; |
| 2295 |
tree all_prefix_attrs = specs->attrs; |
| 2296 |
specs->attrs = NULL; |
| 2297 |
tree decl = start_decl (declarator, specs, false, |
| 2298 |
chainon (postfix_attrs, all_prefix_attrs)); |
| 2299 |
if (decl) |
| 2300 |
finish_decl (decl, UNKNOWN_LOCATION, NULL_TREE, NULL_TREE, |
| 2301 |
NULL_TREE); |
| 2302 |
} |
| 2303 |
} |
| 2304 |
} |
| 2305 |
|
| 2306 |
/* Parse gimple goto statement. */ |
| 2307 |
|
| 2308 |
static void |
| 2309 |
c_parser_gimple_goto_stmt (gimple_parser &parser, |
| 2310 |
location_t loc, tree label, gimple_seq *seq) |
| 2311 |
{ |
| 2312 |
if (cfun->curr_properties & PROP_cfg) |
| 2313 |
{ |
| 2314 |
int dest_index; |
| 2315 |
profile_probability prob; |
| 2316 |
if (c_parser_gimple_parse_bb_spec_edge_probability (label, parser, |
| 2317 |
&dest_index, &prob)) |
| 2318 |
{ |
| 2319 |
parser.push_edge (parser.current_bb->index, dest_index, |
| 2320 |
EDGE_FALLTHRU, prob); |
| 2321 |
return; |
| 2322 |
} |
| 2323 |
} |
| 2324 |
tree decl = lookup_label_for_goto (loc, label); |
| 2325 |
gimple_seq_add_stmt_without_update (seq, gimple_build_goto (decl)); |
| 2326 |
} |
| 2327 |
|
| 2328 |
/* Parse a parenthesized condition. |
| 2329 |
gimple-condition: |
| 2330 |
( gimple-binary-expression ) */ |
| 2331 |
|
| 2332 |
static tree |
| 2333 |
c_parser_gimple_paren_condition (gimple_parser &parser) |
| 2334 |
{ |
| 2335 |
if (! c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
| 2336 |
return error_mark_node; |
| 2337 |
tree cond |
| 2338 |
= c_parser_gimple_binary_expression (parser, boolean_type_node).value; |
| 2339 |
if (cond != error_mark_node |
| 2340 |
&& ! COMPARISON_CLASS_P (cond) |
| 2341 |
&& ! CONSTANT_CLASS_P (cond) |
| 2342 |
&& ! SSA_VAR_P (cond)) |
| 2343 |
{ |
| 2344 |
c_parser_error (parser, "comparison required"); |
| 2345 |
cond = error_mark_node; |
| 2346 |
} |
| 2347 |
if (! c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) |
| 2348 |
return error_mark_node; |
| 2349 |
return cond; |
| 2350 |
} |
| 2351 |
|
| 2352 |
/* Parse gimple try statement. |
| 2353 |
|
| 2354 |
try-statement: |
| 2355 |
try { ... } finally { ... } |
| 2356 |
try { ... } finally { ... } else { ... } |
| 2357 |
|
| 2358 |
This could support try/catch as well, but it's not implemented yet. |
| 2359 |
*/ |
| 2360 |
|
| 2361 |
static void |
| 2362 |
c_parser_gimple_try_stmt (gimple_parser &parser, gimple_seq *seq) |
| 2363 |
{ |
| 2364 |
gimple_seq tryseq = NULL; |
| 2365 |
c_parser_consume_token (parser); |
| 2366 |
c_parser_gimple_compound_statement (parser, &tryseq); |
| 2367 |
|
| 2368 |
if ((c_parser_next_token_is (parser, CPP_KEYWORD) |
| 2369 |
&& c_parser_peek_token (parser)->keyword == RID_AT_FINALLY) |
| 2370 |
|| (c_parser_next_token_is (parser, CPP_NAME) |
| 2371 |
&& c_parser_peek_token (parser)->id_kind == C_ID_ID |
| 2372 |
&& strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value), |
| 2373 |
"finally") == 0)) |
| 2374 |
{ |
| 2375 |
gimple_seq finseq = NULL; |
| 2376 |
c_parser_consume_token (parser); |
| 2377 |
c_parser_gimple_compound_statement (parser, &finseq); |
| 2378 |
|
| 2379 |
if (c_parser_next_token_is (parser, CPP_KEYWORD) |
| 2380 |
&& c_parser_peek_token (parser)->keyword == RID_ELSE) |
| 2381 |
{ |
| 2382 |
gimple_seq elsseq = NULL; |
| 2383 |
c_parser_consume_token (parser); |
| 2384 |
c_parser_gimple_compound_statement (parser, &elsseq); |
| 2385 |
|
| 2386 |
geh_else *stmt = gimple_build_eh_else (finseq, elsseq); |
| 2387 |
finseq = NULL; |
| 2388 |
gimple_seq_add_stmt_without_update (&finseq, stmt); |
| 2389 |
} |
| 2390 |
|
| 2391 |
gtry *stmt = gimple_build_try (tryseq, finseq, GIMPLE_TRY_FINALLY); |
| 2392 |
gimple_seq_add_stmt_without_update (seq, stmt); |
| 2393 |
} |
| 2394 |
else if (c_parser_next_token_is (parser, CPP_KEYWORD) |
| 2395 |
&& c_parser_peek_token (parser)->keyword == RID_AT_CATCH) |
| 2396 |
c_parser_error (parser, "%<catch%> is not supported"); |
| 2397 |
else |
| 2398 |
c_parser_error (parser, "expected %<finally%> or %<catch%>"); |
| 2399 |
} |
| 2400 |
|
| 2401 |
/* Parse gimple if-else statement. |
| 2402 |
|
| 2403 |
if-statement: |
| 2404 |
if ( gimple-binary-expression ) gimple-goto-statement |
| 2405 |
if ( gimple-binary-expression ) gimple-goto-statement \ |
| 2406 |
else gimple-goto-statement |
| 2407 |
*/ |
| 2408 |
|
| 2409 |
static void |
| 2410 |
c_parser_gimple_if_stmt (gimple_parser &parser, gimple_seq *seq) |
| 2411 |
{ |
| 2412 |
tree t_label = NULL_TREE, f_label = NULL_TREE, label; |
| 2413 |
location_t loc; |
| 2414 |
c_parser_consume_token (parser); |
| 2415 |
tree cond = c_parser_gimple_paren_condition (parser); |
| 2416 |
|
| 2417 |
if (c_parser_next_token_is_keyword (parser, RID_GOTO)) |
| 2418 |
{ |
| 2419 |
loc = c_parser_peek_token (parser)->location; |
| 2420 |
c_parser_consume_token (parser); |
| 2421 |
if (! c_parser_next_token_is (parser, CPP_NAME)) |
| 2422 |
{ |
| 2423 |
c_parser_error (parser, "expected label"); |
| 2424 |
return; |
| 2425 |
} |
| 2426 |
label = c_parser_peek_token (parser)->value; |
| 2427 |
c_parser_consume_token (parser); |
| 2428 |
int dest_index; |
| 2429 |
profile_probability prob; |
| 2430 |
if ((cfun->curr_properties & PROP_cfg) |
| 2431 |
&& c_parser_gimple_parse_bb_spec_edge_probability (label, parser, |
| 2432 |
&dest_index, &prob)) |
| 2433 |
parser.push_edge (parser.current_bb->index, dest_index, |
| 2434 |
EDGE_TRUE_VALUE, prob); |
| 2435 |
else |
| 2436 |
t_label = lookup_label_for_goto (loc, label); |
| 2437 |
if (! c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) |
| 2438 |
return; |
| 2439 |
} |
| 2440 |
else |
| 2441 |
{ |
| 2442 |
c_parser_error (parser, "expected goto expression"); |
| 2443 |
return; |
| 2444 |
} |
| 2445 |
|
| 2446 |
if (c_parser_next_token_is_keyword (parser, RID_ELSE)) |
| 2447 |
c_parser_consume_token (parser); |
| 2448 |
else |
| 2449 |
{ |
| 2450 |
c_parser_error (parser, "expected else statement"); |
| 2451 |
return; |
| 2452 |
} |
| 2453 |
|
| 2454 |
if (c_parser_next_token_is_keyword (parser, RID_GOTO)) |
| 2455 |
{ |
| 2456 |
loc = c_parser_peek_token (parser)->location; |
| 2457 |
c_parser_consume_token (parser); |
| 2458 |
if (! c_parser_next_token_is (parser, CPP_NAME)) |
| 2459 |
{ |
| 2460 |
c_parser_error (parser, "expected label"); |
| 2461 |
return; |
| 2462 |
} |
| 2463 |
label = c_parser_peek_token (parser)->value; |
| 2464 |
c_parser_consume_token (parser); |
| 2465 |
int dest_index; |
| 2466 |
profile_probability prob; |
| 2467 |
if ((cfun->curr_properties & PROP_cfg) |
| 2468 |
&& c_parser_gimple_parse_bb_spec_edge_probability (label, parser, |
| 2469 |
&dest_index, &prob)) |
| 2470 |
parser.push_edge (parser.current_bb->index, dest_index, |
| 2471 |
EDGE_FALSE_VALUE, prob); |
| 2472 |
else |
| 2473 |
f_label = lookup_label_for_goto (loc, label); |
| 2474 |
if (! c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) |
| 2475 |
return; |
| 2476 |
} |
| 2477 |
else |
| 2478 |
{ |
| 2479 |
c_parser_error (parser, "expected goto expression"); |
| 2480 |
return; |
| 2481 |
} |
| 2482 |
|
| 2483 |
if (cond != error_mark_node) |
| 2484 |
gimple_seq_add_stmt_without_update (seq, gimple_build_cond_from_tree (cond, t_label, |
| 2485 |
f_label)); |
| 2486 |
} |
| 2487 |
|
| 2488 |
/* Parse gimple switch-statement. |
| 2489 |
|
| 2490 |
gimple-switch-statement: |
| 2491 |
switch (gimple-postfix-expression) gimple-case-statement |
| 2492 |
|
| 2493 |
gimple-case-statement: |
| 2494 |
gimple-case-statement |
| 2495 |
gimple-label-statement : gimple-goto-statment |
| 2496 |
*/ |
| 2497 |
|
| 2498 |
static void |
| 2499 |
c_parser_gimple_switch_stmt (gimple_parser &parser, gimple_seq *seq) |
| 2500 |
{ |
| 2501 |
c_expr cond_expr; |
| 2502 |
tree case_label, label; |
| 2503 |
auto_vec<tree> labels; |
| 2504 |
tree default_label = NULL_TREE; |
| 2505 |
c_parser_consume_token (parser); |
| 2506 |
|
| 2507 |
if (! c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) |
| 2508 |
return; |
| 2509 |
cond_expr = c_parser_gimple_postfix_expression (parser); |
| 2510 |
if (! c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) |
| 2511 |
return; |
| 2512 |
|
| 2513 |
if (! c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>")) |
| 2514 |
return; |
| 2515 |
|
| 2516 |
while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE)) |
| 2517 |
{ |
| 2518 |
if (c_parser_next_token_is (parser, CPP_EOF)) |
| 2519 |
{ |
| 2520 |
c_parser_error (parser, "expected statement"); |
| 2521 |
return; |
| 2522 |
} |
| 2523 |
|
| 2524 |
switch (c_parser_peek_token (parser)->keyword) |
| 2525 |
{ |
| 2526 |
case RID_CASE: |
| 2527 |
{ |
| 2528 |
c_expr exp1; |
| 2529 |
location_t loc = c_parser_peek_token (parser)->location; |
| 2530 |
c_parser_consume_token (parser); |
| 2531 |
|
| 2532 |
if (c_parser_next_token_is (parser, CPP_NAME) |
| 2533 |
|| c_parser_peek_token (parser)->type == CPP_NUMBER) |
| 2534 |
exp1 = c_parser_gimple_postfix_expression (parser); |
| 2535 |
else |
| 2536 |
{ |
| 2537 |
c_parser_error (parser, "expected expression"); |
| 2538 |
return; |
| 2539 |
} |
| 2540 |
|
| 2541 |
if (c_parser_next_token_is (parser, CPP_COLON)) |
| 2542 |
{ |
| 2543 |
c_parser_consume_token (parser); |
| 2544 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 2545 |
{ |
| 2546 |
label = c_parser_peek_token (parser)->value; |
| 2547 |
c_parser_consume_token (parser); |
| 2548 |
tree decl = lookup_label_for_goto (loc, label); |
| 2549 |
case_label = build_case_label (exp1.value, NULL_TREE, |
| 2550 |
decl); |
| 2551 |
labels.safe_push (case_label); |
| 2552 |
if (! c_parser_require (parser, CPP_SEMICOLON, |
| 2553 |
"expected %<;%>")) |
| 2554 |
return; |
| 2555 |
} |
| 2556 |
else if (! c_parser_require (parser, CPP_NAME, |
| 2557 |
"expected label")) |
| 2558 |
return; |
| 2559 |
} |
| 2560 |
else if (! c_parser_require (parser, CPP_SEMICOLON, |
| 2561 |
"expected %<:%>")) |
| 2562 |
return; |
| 2563 |
break; |
| 2564 |
} |
| 2565 |
case RID_DEFAULT: |
| 2566 |
{ |
| 2567 |
location_t loc = c_parser_peek_token (parser)->location; |
| 2568 |
c_parser_consume_token (parser); |
| 2569 |
if (c_parser_next_token_is (parser, CPP_COLON)) |
| 2570 |
{ |
| 2571 |
c_parser_consume_token (parser); |
| 2572 |
if (c_parser_next_token_is (parser, CPP_NAME)) |
| 2573 |
{ |
| 2574 |
label = c_parser_peek_token (parser)->value; |
| 2575 |
c_parser_consume_token (parser); |
| 2576 |
tree decl = lookup_label_for_goto (loc, label); |
| 2577 |
default_label = build_case_label (NULL_TREE, NULL_TREE, |
| 2578 |
decl); |
| 2579 |
if (! c_parser_require (parser, CPP_SEMICOLON, |
| 2580 |
"expected %<;%>")) |
| 2581 |
return; |
| 2582 |
} |
| 2583 |
else if (! c_parser_require (parser, CPP_NAME, |
| 2584 |
"expected label")) |
| 2585 |
return; |
| 2586 |
} |
| 2587 |
else if (! c_parser_require (parser, CPP_SEMICOLON, |
| 2588 |
"expected %<:%>")) |
| 2589 |
return; |
| 2590 |
break; |
| 2591 |
} |
| 2592 |
default: |
| 2593 |
c_parser_error (parser, "expected case label"); |
| 2594 |
return; |
| 2595 |
} |
| 2596 |
|
| 2597 |
} |
| 2598 |
if (! c_parser_require (parser, CPP_CLOSE_BRACE, "expected %<}%>")) |
| 2599 |
return; |
| 2600 |
|
| 2601 |
if (cond_expr.value != error_mark_node) |
| 2602 |
{ |
| 2603 |
gswitch *s = gimple_build_switch (cond_expr.value, default_label, labels); |
| 2604 |
gimple_seq_add_stmt_without_update (seq, s); |
| 2605 |
} |
| 2606 |
} |
| 2607 |
|
| 2608 |
/* Parse gimple return statement. */ |
| 2609 |
|
| 2610 |
static void |
| 2611 |
c_parser_gimple_return_stmt (gimple_parser &parser, gimple_seq *seq) |
| 2612 |
{ |
| 2613 |
location_t loc = c_parser_peek_token (parser)->location; |
| 2614 |
gimple *ret = NULL; |
| 2615 |
c_parser_consume_token (parser); |
| 2616 |
if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 2617 |
{ |
| 2618 |
c_finish_gimple_return (loc, NULL_TREE); |
| 2619 |
ret = gimple_build_return (NULL); |
| 2620 |
gimple_seq_add_stmt_without_update (seq, ret); |
| 2621 |
} |
| 2622 |
else |
| 2623 |
{ |
| 2624 |
location_t xloc = c_parser_peek_token (parser)->location; |
| 2625 |
c_expr expr = c_parser_gimple_unary_expression (parser); |
| 2626 |
if (expr.value != error_mark_node) |
| 2627 |
{ |
| 2628 |
c_finish_gimple_return (xloc, expr.value); |
| 2629 |
ret = gimple_build_return (expr.value); |
| 2630 |
gimple_seq_add_stmt_without_update (seq, ret); |
| 2631 |
} |
| 2632 |
} |
| 2633 |
} |
| 2634 |
|
| 2635 |
/* Support function for c_parser_gimple_return_stmt. */ |
| 2636 |
|
| 2637 |
static void |
| 2638 |
c_finish_gimple_return (location_t loc, tree retval) |
| 2639 |
{ |
| 2640 |
tree valtype = TREE_TYPE (TREE_TYPE (current_function_decl)); |
| 2641 |
|
| 2642 |
/* Use the expansion point to handle cases such as returning NULL |
| 2643 |
in a function returning void. */ |
| 2644 |
location_t xloc = expansion_point_location_if_in_system_header (loc); |
| 2645 |
|
| 2646 |
if (TREE_THIS_VOLATILE (current_function_decl)) |
| 2647 |
warning_at (xloc, 0, |
| 2648 |
"function declared %<noreturn%> has a %<return%> statement"); |
| 2649 |
|
| 2650 |
if (! retval) |
| 2651 |
current_function_returns_null = 1; |
| 2652 |
else if (valtype == 0 || VOID_TYPE_P (valtype)) |
| 2653 |
{ |
| 2654 |
current_function_returns_null = 1; |
| 2655 |
if (TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE) |
| 2656 |
{ |
| 2657 |
error_at |
| 2658 |
(xloc, "%<return%> with a value, in function returning void"); |
| 2659 |
inform (DECL_SOURCE_LOCATION (current_function_decl), |
| 2660 |
"declared here"); |
| 2661 |
} |
| 2662 |
} |
| 2663 |
else if (TREE_CODE (valtype) != TREE_CODE (TREE_TYPE (retval))) |
| 2664 |
{ |
| 2665 |
error_at |
| 2666 |
(xloc, "invalid conversion in return statement"); |
| 2667 |
inform (DECL_SOURCE_LOCATION (current_function_decl), |
| 2668 |
"declared here"); |
| 2669 |
} |
| 2670 |
return; |
| 2671 |
} |