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