]>
Commit | Line | Data |
---|---|---|
0090dad2 | 1 | /* Perform the semantic phase of parsing, i.e., the process of |
2 | building tree structure, checking semantic consistency, and | |
3 | building RTL. These routines are used both during actual parsing | |
9031d10b | 4 | and during the instantiation of template functions. |
0090dad2 | 5 | |
d353bf18 | 6 | Copyright (C) 1998-2015 Free Software Foundation, Inc. |
0090dad2 | 7 | Written by Mark Mitchell (mmitchell@usa.net) based on code found |
9031d10b | 8 | formerly in parse.y and pt.c. |
0090dad2 | 9 | |
6f0d25a6 | 10 | This file is part of GCC. |
0090dad2 | 11 | |
6f0d25a6 | 12 | GCC is free software; you can redistribute it and/or modify it |
0090dad2 | 13 | under the terms of the GNU General Public License as published by |
aa139c3f | 14 | the Free Software Foundation; either version 3, or (at your option) |
0090dad2 | 15 | any later version. |
9031d10b | 16 | |
6f0d25a6 | 17 | GCC is distributed in the hope that it will be useful, but |
0090dad2 | 18 | WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
20 | General Public License for more details. | |
9031d10b | 21 | |
aa139c3f | 22 | You should have received a copy of the GNU General Public License |
23 | along with GCC; see the file COPYING3. If not see | |
24 | <http://www.gnu.org/licenses/>. */ | |
0090dad2 | 25 | |
26 | #include "config.h" | |
b3ef7553 | 27 | #include "system.h" |
805e22b2 | 28 | #include "coretypes.h" |
29 | #include "tm.h" | |
b20a8bb4 | 30 | #include "alias.h" |
0090dad2 | 31 | #include "tree.h" |
9ed99284 | 32 | #include "stmt.h" |
33 | #include "varasm.h" | |
34 | #include "stor-layout.h" | |
35 | #include "stringpool.h" | |
0090dad2 | 36 | #include "cp-tree.h" |
7bedc3a0 | 37 | #include "c-family/c-common.h" |
6c536c4f | 38 | #include "c-family/c-objc.h" |
1e3b023c | 39 | #include "tree-inline.h" |
ac7549c7 | 40 | #include "intl.h" |
d6a718e6 | 41 | #include "toplev.h" |
a3d5bae2 | 42 | #include "flags.h" |
a6260fc7 | 43 | #include "timevar.h" |
4ee9c684 | 44 | #include "diagnostic.h" |
1140c305 | 45 | #include "hard-reg-set.h" |
1140c305 | 46 | #include "function.h" |
6cb758f0 | 47 | #include "cgraph.h" |
2363ef00 | 48 | #include "tree-iterator.h" |
853b7640 | 49 | #include "target.h" |
a8783bee | 50 | #include "gimplify.h" |
0f71a633 | 51 | #include "bitmap.h" |
7740abd8 | 52 | #include "omp-low.h" |
f7715905 | 53 | #include "builtins.h" |
40750995 | 54 | #include "convert.h" |
ca4c3545 | 55 | #include "gomp-constants.h" |
0090dad2 | 56 | |
57 | /* There routines provide a modular interface to perform many parsing | |
58 | operations. They may therefore be used during actual parsing, or | |
59 | during template instantiation, which may be regarded as a | |
c1946583 | 60 | degenerate form of parsing. */ |
0090dad2 | 61 | |
807be5b4 | 62 | static tree maybe_convert_cond (tree); |
4ee9c684 | 63 | static tree finalize_nrv_r (tree *, int *, void *); |
a8b75081 | 64 | static tree capture_decltype (tree); |
90e3d9ba | 65 | |
019cf886 | 66 | |
4f62c42e | 67 | /* Deferred Access Checking Overview |
68 | --------------------------------- | |
69 | ||
70 | Most C++ expressions and declarations require access checking | |
71 | to be performed during parsing. However, in several cases, | |
72 | this has to be treated differently. | |
73 | ||
74 | For member declarations, access checking has to be deferred | |
75 | until more information about the declaration is known. For | |
76 | example: | |
77 | ||
78 | class A { | |
653e5405 | 79 | typedef int X; |
4f62c42e | 80 | public: |
653e5405 | 81 | X f(); |
4f62c42e | 82 | }; |
83 | ||
84 | A::X A::f(); | |
85 | A::X g(); | |
86 | ||
87 | When we are parsing the function return type `A::X', we don't | |
88 | really know if this is allowed until we parse the function name. | |
89 | ||
90 | Furthermore, some contexts require that access checking is | |
91 | never performed at all. These include class heads, and template | |
92 | instantiations. | |
93 | ||
94 | Typical use of access checking functions is described here: | |
9031d10b | 95 | |
4f62c42e | 96 | 1. When we enter a context that requires certain access checking |
97 | mode, the function `push_deferring_access_checks' is called with | |
98 | DEFERRING argument specifying the desired mode. Access checking | |
99 | may be performed immediately (dk_no_deferred), deferred | |
100 | (dk_deferred), or not performed (dk_no_check). | |
101 | ||
102 | 2. When a declaration such as a type, or a variable, is encountered, | |
103 | the function `perform_or_defer_access_check' is called. It | |
f1f41a6c | 104 | maintains a vector of all deferred checks. |
4f62c42e | 105 | |
106 | 3. The global `current_class_type' or `current_function_decl' is then | |
107 | setup by the parser. `enforce_access' relies on these information | |
108 | to check access. | |
109 | ||
110 | 4. Upon exiting the context mentioned in step 1, | |
111 | `perform_deferred_access_checks' is called to check all declaration | |
f1f41a6c | 112 | stored in the vector. `pop_deferring_access_checks' is then |
4f62c42e | 113 | called to restore the previous access checking mode. |
114 | ||
115 | In case of parsing error, we simply call `pop_deferring_access_checks' | |
116 | without `perform_deferred_access_checks'. */ | |
117 | ||
fb1e4f4a | 118 | typedef struct GTY(()) deferred_access { |
f1f41a6c | 119 | /* A vector representing name-lookups for which we have deferred |
fc40d314 | 120 | checking access controls. We cannot check the accessibility of |
121 | names used in a decl-specifier-seq until we know what is being | |
122 | declared because code like: | |
123 | ||
9031d10b | 124 | class A { |
653e5405 | 125 | class B {}; |
126 | B* f(); | |
fc40d314 | 127 | } |
128 | ||
129 | A::B* A::f() { return 0; } | |
130 | ||
3369eb76 | 131 | is valid, even though `A::B' is not generally accessible. */ |
f1f41a6c | 132 | vec<deferred_access_check, va_gc> * GTY(()) deferred_access_checks; |
9031d10b | 133 | |
fc40d314 | 134 | /* The current mode of access checks. */ |
135 | enum deferring_kind deferring_access_checks_kind; | |
9031d10b | 136 | |
fc40d314 | 137 | } deferred_access; |
fc40d314 | 138 | |
9b57b06b | 139 | /* Data for deferred access checking. */ |
f1f41a6c | 140 | static GTY(()) vec<deferred_access, va_gc> *deferred_access_stack; |
fc40d314 | 141 | static GTY(()) unsigned deferred_access_no_check; |
9b57b06b | 142 | |
143 | /* Save the current deferred access states and start deferred | |
144 | access checking iff DEFER_P is true. */ | |
145 | ||
2a0d3beb | 146 | void |
147 | push_deferring_access_checks (deferring_kind deferring) | |
9b57b06b | 148 | { |
4cab8273 | 149 | /* For context like template instantiation, access checking |
150 | disabling applies to all nested context. */ | |
fc40d314 | 151 | if (deferred_access_no_check || deferring == dk_no_check) |
152 | deferred_access_no_check++; | |
9b57b06b | 153 | else |
fc40d314 | 154 | { |
e82e4eb5 | 155 | deferred_access e = {NULL, deferring}; |
f1f41a6c | 156 | vec_safe_push (deferred_access_stack, e); |
fc40d314 | 157 | } |
9b57b06b | 158 | } |
159 | ||
4b768002 | 160 | /* Save the current deferred access states and start deferred access |
161 | checking, continuing the set of deferred checks in CHECKS. */ | |
162 | ||
163 | void | |
164 | reopen_deferring_access_checks (vec<deferred_access_check, va_gc> * checks) | |
165 | { | |
166 | push_deferring_access_checks (dk_deferred); | |
167 | if (!deferred_access_no_check) | |
168 | deferred_access_stack->last().deferred_access_checks = checks; | |
169 | } | |
170 | ||
9b57b06b | 171 | /* Resume deferring access checks again after we stopped doing |
172 | this previously. */ | |
173 | ||
2a0d3beb | 174 | void |
175 | resume_deferring_access_checks (void) | |
9b57b06b | 176 | { |
fc40d314 | 177 | if (!deferred_access_no_check) |
f1f41a6c | 178 | deferred_access_stack->last().deferring_access_checks_kind = dk_deferred; |
9b57b06b | 179 | } |
180 | ||
181 | /* Stop deferring access checks. */ | |
182 | ||
2a0d3beb | 183 | void |
184 | stop_deferring_access_checks (void) | |
9b57b06b | 185 | { |
fc40d314 | 186 | if (!deferred_access_no_check) |
f1f41a6c | 187 | deferred_access_stack->last().deferring_access_checks_kind = dk_no_deferred; |
9b57b06b | 188 | } |
189 | ||
190 | /* Discard the current deferred access checks and restore the | |
191 | previous states. */ | |
192 | ||
2a0d3beb | 193 | void |
194 | pop_deferring_access_checks (void) | |
9b57b06b | 195 | { |
fc40d314 | 196 | if (deferred_access_no_check) |
197 | deferred_access_no_check--; | |
198 | else | |
f1f41a6c | 199 | deferred_access_stack->pop (); |
9b57b06b | 200 | } |
201 | ||
9031d10b | 202 | /* Returns a TREE_LIST representing the deferred checks. |
203 | The TREE_PURPOSE of each node is the type through which the | |
9b57b06b | 204 | access occurred; the TREE_VALUE is the declaration named. |
205 | */ | |
206 | ||
f1f41a6c | 207 | vec<deferred_access_check, va_gc> * |
2a0d3beb | 208 | get_deferred_access_checks (void) |
9b57b06b | 209 | { |
fc40d314 | 210 | if (deferred_access_no_check) |
211 | return NULL; | |
212 | else | |
f1f41a6c | 213 | return (deferred_access_stack->last().deferred_access_checks); |
9b57b06b | 214 | } |
215 | ||
216 | /* Take current deferred checks and combine with the | |
217 | previous states if we also defer checks previously. | |
218 | Otherwise perform checks now. */ | |
219 | ||
2a0d3beb | 220 | void |
221 | pop_to_parent_deferring_access_checks (void) | |
9b57b06b | 222 | { |
fc40d314 | 223 | if (deferred_access_no_check) |
224 | deferred_access_no_check--; | |
225 | else | |
226 | { | |
f1f41a6c | 227 | vec<deferred_access_check, va_gc> *checks; |
fc40d314 | 228 | deferred_access *ptr; |
229 | ||
f1f41a6c | 230 | checks = (deferred_access_stack->last ().deferred_access_checks); |
fc40d314 | 231 | |
f1f41a6c | 232 | deferred_access_stack->pop (); |
233 | ptr = &deferred_access_stack->last (); | |
fc40d314 | 234 | if (ptr->deferring_access_checks_kind == dk_no_deferred) |
235 | { | |
236 | /* Check access. */ | |
eb833cbe | 237 | perform_access_checks (checks, tf_warning_or_error); |
fc40d314 | 238 | } |
239 | else | |
240 | { | |
241 | /* Merge with parent. */ | |
3369eb76 | 242 | int i, j; |
243 | deferred_access_check *chk, *probe; | |
9031d10b | 244 | |
f1f41a6c | 245 | FOR_EACH_VEC_SAFE_ELT (checks, i, chk) |
fc40d314 | 246 | { |
f1f41a6c | 247 | FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, j, probe) |
3369eb76 | 248 | { |
249 | if (probe->binfo == chk->binfo && | |
250 | probe->decl == chk->decl && | |
251 | probe->diag_decl == chk->diag_decl) | |
252 | goto found; | |
253 | } | |
fc40d314 | 254 | /* Insert into parent's checks. */ |
f1f41a6c | 255 | vec_safe_push (ptr->deferred_access_checks, *chk); |
fc40d314 | 256 | found:; |
257 | } | |
258 | } | |
259 | } | |
9b57b06b | 260 | } |
261 | ||
23010bc8 | 262 | /* Perform the access checks in CHECKS. The TREE_PURPOSE of each node |
263 | is the BINFO indicating the qualifying scope used to access the | |
eb833cbe | 264 | DECL node stored in the TREE_VALUE of the node. If CHECKS is empty |
265 | or we aren't in SFINAE context or all the checks succeed return TRUE, | |
266 | otherwise FALSE. */ | |
23010bc8 | 267 | |
eb833cbe | 268 | bool |
f1f41a6c | 269 | perform_access_checks (vec<deferred_access_check, va_gc> *checks, |
eb833cbe | 270 | tsubst_flags_t complain) |
23010bc8 | 271 | { |
3369eb76 | 272 | int i; |
273 | deferred_access_check *chk; | |
5d56c2e0 | 274 | location_t loc = input_location; |
eb833cbe | 275 | bool ok = true; |
3369eb76 | 276 | |
277 | if (!checks) | |
eb833cbe | 278 | return true; |
3369eb76 | 279 | |
f1f41a6c | 280 | FOR_EACH_VEC_SAFE_ELT (checks, i, chk) |
5d56c2e0 | 281 | { |
282 | input_location = chk->loc; | |
eb833cbe | 283 | ok &= enforce_access (chk->binfo, chk->decl, chk->diag_decl, complain); |
5d56c2e0 | 284 | } |
285 | ||
286 | input_location = loc; | |
eb833cbe | 287 | return (complain & tf_error) ? true : ok; |
23010bc8 | 288 | } |
289 | ||
895bc691 | 290 | /* Perform the deferred access checks. |
291 | ||
292 | After performing the checks, we still have to keep the list | |
293 | `deferred_access_stack->deferred_access_checks' since we may want | |
294 | to check access for them again later in a different context. | |
295 | For example: | |
296 | ||
297 | class A { | |
298 | typedef int X; | |
299 | static X a; | |
300 | }; | |
301 | A::X A::a, x; // No error for `A::a', error for `x' | |
302 | ||
303 | We have to perform deferred access of `A::X', first with `A::a', | |
eb833cbe | 304 | next with `x'. Return value like perform_access_checks above. */ |
9b57b06b | 305 | |
eb833cbe | 306 | bool |
307 | perform_deferred_access_checks (tsubst_flags_t complain) | |
9b57b06b | 308 | { |
eb833cbe | 309 | return perform_access_checks (get_deferred_access_checks (), complain); |
9b57b06b | 310 | } |
311 | ||
312 | /* Defer checking the accessibility of DECL, when looked up in | |
eb833cbe | 313 | BINFO. DIAG_DECL is the declaration to use to print diagnostics. |
314 | Return value like perform_access_checks above. */ | |
9b57b06b | 315 | |
eb833cbe | 316 | bool |
317 | perform_or_defer_access_check (tree binfo, tree decl, tree diag_decl, | |
318 | tsubst_flags_t complain) | |
9b57b06b | 319 | { |
3369eb76 | 320 | int i; |
fc40d314 | 321 | deferred_access *ptr; |
3369eb76 | 322 | deferred_access_check *chk; |
3369eb76 | 323 | |
9b57b06b | 324 | |
fc40d314 | 325 | /* Exit if we are in a context that no access checking is performed. |
326 | */ | |
327 | if (deferred_access_no_check) | |
eb833cbe | 328 | return true; |
9031d10b | 329 | |
b4df430b | 330 | gcc_assert (TREE_CODE (binfo) == TREE_BINFO); |
c344b0fe | 331 | |
f1f41a6c | 332 | ptr = &deferred_access_stack->last (); |
9031d10b | 333 | |
9b57b06b | 334 | /* If we are not supposed to defer access checks, just check now. */ |
fc40d314 | 335 | if (ptr->deferring_access_checks_kind == dk_no_deferred) |
9b57b06b | 336 | { |
eb833cbe | 337 | bool ok = enforce_access (binfo, decl, diag_decl, complain); |
338 | return (complain & tf_error) ? true : ok; | |
9b57b06b | 339 | } |
9031d10b | 340 | |
9b57b06b | 341 | /* See if we are already going to perform this check. */ |
f1f41a6c | 342 | FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, i, chk) |
3369eb76 | 343 | { |
344 | if (chk->decl == decl && chk->binfo == binfo && | |
345 | chk->diag_decl == diag_decl) | |
346 | { | |
eb833cbe | 347 | return true; |
3369eb76 | 348 | } |
349 | } | |
9b57b06b | 350 | /* If not, record the check. */ |
e82e4eb5 | 351 | deferred_access_check new_access = {binfo, decl, diag_decl, input_location}; |
f1f41a6c | 352 | vec_safe_push (ptr->deferred_access_checks, new_access); |
8d96fd47 | 353 | |
354 | return true; | |
355 | } | |
356 | ||
3160db1d | 357 | /* Returns nonzero if the current statement is a full expression, |
5c3247a9 | 358 | i.e. temporaries created during that statement should be destroyed |
359 | at the end of the statement. */ | |
8036397f | 360 | |
5c3247a9 | 361 | int |
807be5b4 | 362 | stmts_are_full_exprs_p (void) |
5c3247a9 | 363 | { |
a08e60ae | 364 | return current_stmt_tree ()->stmts_are_full_exprs_p; |
365 | } | |
366 | ||
d1725120 | 367 | /* T is a statement. Add it to the statement-tree. This is the C++ |
368 | version. The C/ObjC frontends have a slightly different version of | |
369 | this function. */ | |
370 | ||
371 | tree | |
372 | add_stmt (tree t) | |
373 | { | |
374 | enum tree_code code = TREE_CODE (t); | |
375 | ||
376 | if (EXPR_P (t) && code != LABEL_EXPR) | |
377 | { | |
378 | if (!EXPR_HAS_LOCATION (t)) | |
379 | SET_EXPR_LOCATION (t, input_location); | |
380 | ||
381 | /* When we expand a statement-tree, we must know whether or not the | |
382 | statements are full-expressions. We record that fact here. */ | |
383 | STMT_IS_FULL_EXPR_P (t) = stmts_are_full_exprs_p (); | |
384 | } | |
385 | ||
3f136c5f | 386 | if (code == LABEL_EXPR || code == CASE_LABEL_EXPR) |
387 | STATEMENT_LIST_HAS_LABEL (cur_stmt_list) = 1; | |
388 | ||
d1725120 | 389 | /* Add T to the statement-tree. Non-side-effect statements need to be |
390 | recorded during statement expressions. */ | |
f1f41a6c | 391 | gcc_checking_assert (!stmt_list_stack->is_empty ()); |
d1725120 | 392 | append_to_statement_list_force (t, &cur_stmt_list); |
393 | ||
394 | return t; | |
395 | } | |
396 | ||
b75409ba | 397 | /* Returns the stmt_tree to which statements are currently being added. */ |
a08e60ae | 398 | |
399 | stmt_tree | |
807be5b4 | 400 | current_stmt_tree (void) |
a08e60ae | 401 | { |
9031d10b | 402 | return (cfun |
403 | ? &cfun->language->base.x_stmt_tree | |
a08e60ae | 404 | : &scope_chain->x_stmt_tree); |
5c3247a9 | 405 | } |
8036397f | 406 | |
73d4090e | 407 | /* If statements are full expressions, wrap STMT in a CLEANUP_POINT_EXPR. */ |
408 | ||
409 | static tree | |
410 | maybe_cleanup_point_expr (tree expr) | |
411 | { | |
412 | if (!processing_template_decl && stmts_are_full_exprs_p ()) | |
acbc760a | 413 | expr = fold_build_cleanup_point_expr (TREE_TYPE (expr), expr); |
73d4090e | 414 | return expr; |
415 | } | |
416 | ||
acbc760a | 417 | /* Like maybe_cleanup_point_expr except have the type of the new expression be |
c6e1336c | 418 | void so we don't need to create a temporary variable to hold the inner |
419 | expression. The reason why we do this is because the original type might be | |
420 | an aggregate and we cannot create a temporary variable for that type. */ | |
acbc760a | 421 | |
3f1ab65c | 422 | tree |
acbc760a | 423 | maybe_cleanup_point_expr_void (tree expr) |
424 | { | |
425 | if (!processing_template_decl && stmts_are_full_exprs_p ()) | |
426 | expr = fold_build_cleanup_point_expr (void_type_node, expr); | |
427 | return expr; | |
428 | } | |
429 | ||
430 | ||
431 | ||
73d4090e | 432 | /* Create a declaration statement for the declaration given by the DECL. */ |
433 | ||
434 | void | |
7dd37241 | 435 | add_decl_expr (tree decl) |
73d4090e | 436 | { |
e60a6f7b | 437 | tree r = build_stmt (input_location, DECL_EXPR, decl); |
56dfff01 | 438 | if (DECL_INITIAL (decl) |
439 | || (DECL_SIZE (decl) && TREE_SIDE_EFFECTS (DECL_SIZE (decl)))) | |
acbc760a | 440 | r = maybe_cleanup_point_expr_void (r); |
73d4090e | 441 | add_stmt (r); |
442 | } | |
443 | ||
5c3247a9 | 444 | /* Finish a scope. */ |
8036397f | 445 | |
d7e71db9 | 446 | tree |
2363ef00 | 447 | do_poplevel (tree stmt_list) |
8036397f | 448 | { |
2363ef00 | 449 | tree block = NULL; |
8036397f | 450 | |
5c3247a9 | 451 | if (stmts_are_full_exprs_p ()) |
2363ef00 | 452 | block = poplevel (kept_level_p (), 1, 0); |
5c3247a9 | 453 | |
2363ef00 | 454 | stmt_list = pop_stmt_list (stmt_list); |
9031d10b | 455 | |
2363ef00 | 456 | if (!processing_template_decl) |
457 | { | |
e60a6f7b | 458 | stmt_list = c_build_bind_expr (input_location, block, stmt_list); |
2363ef00 | 459 | /* ??? See c_end_compound_stmt re statement expressions. */ |
8036397f | 460 | } |
461 | ||
2363ef00 | 462 | return stmt_list; |
8036397f | 463 | } |
464 | ||
9031d10b | 465 | /* Begin a new scope. */ |
8036397f | 466 | |
2363ef00 | 467 | static tree |
6e9029b4 | 468 | do_pushlevel (scope_kind sk) |
8036397f | 469 | { |
2363ef00 | 470 | tree ret = push_stmt_list (); |
5c3247a9 | 471 | if (stmts_are_full_exprs_p ()) |
2363ef00 | 472 | begin_scope (sk, NULL); |
473 | return ret; | |
474 | } | |
dddab69e | 475 | |
476 | /* Queue a cleanup. CLEANUP is an expression/statement to be executed | |
477 | when the current scope is exited. EH_ONLY is true when this is not | |
478 | meant to apply to normal control flow transfer. */ | |
479 | ||
480 | void | |
481 | push_cleanup (tree decl, tree cleanup, bool eh_only) | |
482 | { | |
e60a6f7b | 483 | tree stmt = build_stmt (input_location, CLEANUP_STMT, NULL, cleanup, decl); |
dddab69e | 484 | CLEANUP_EH_ONLY (stmt) = eh_only; |
485 | add_stmt (stmt); | |
486 | CLEANUP_BODY (stmt) = push_stmt_list (); | |
487 | } | |
2363ef00 | 488 | |
9ea3e924 | 489 | /* Simple infinite loop tracking for -Wreturn-type. We keep a stack of all |
490 | the current loops, represented by 'NULL_TREE' if we've seen a possible | |
491 | exit, and 'error_mark_node' if not. This is currently used only to | |
492 | suppress the warning about a function with no return statements, and | |
493 | therefore we don't bother noting returns as possible exits. We also | |
494 | don't bother with gotos. */ | |
495 | ||
496 | static void | |
497 | begin_maybe_infinite_loop (tree cond) | |
498 | { | |
499 | /* Only track this while parsing a function, not during instantiation. */ | |
500 | if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl) | |
501 | && !processing_template_decl)) | |
502 | return; | |
503 | bool maybe_infinite = true; | |
504 | if (cond) | |
505 | { | |
21131a05 | 506 | cond = fold_non_dependent_expr (cond); |
9ea3e924 | 507 | maybe_infinite = integer_nonzerop (cond); |
508 | } | |
509 | vec_safe_push (cp_function_chain->infinite_loops, | |
510 | maybe_infinite ? error_mark_node : NULL_TREE); | |
511 | ||
512 | } | |
513 | ||
514 | /* A break is a possible exit for the current loop. */ | |
515 | ||
516 | void | |
517 | break_maybe_infinite_loop (void) | |
518 | { | |
519 | if (!cfun) | |
520 | return; | |
521 | cp_function_chain->infinite_loops->last() = NULL_TREE; | |
522 | } | |
523 | ||
524 | /* If we reach the end of the loop without seeing a possible exit, we have | |
525 | an infinite loop. */ | |
526 | ||
527 | static void | |
528 | end_maybe_infinite_loop (tree cond) | |
529 | { | |
530 | if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl) | |
531 | && !processing_template_decl)) | |
532 | return; | |
533 | tree current = cp_function_chain->infinite_loops->pop(); | |
534 | if (current != NULL_TREE) | |
535 | { | |
536 | cond = fold_non_dependent_expr (cond); | |
9ea3e924 | 537 | if (integer_nonzerop (cond)) |
538 | current_function_infinite_loop = 1; | |
539 | } | |
540 | } | |
541 | ||
542 | ||
2b4cffe7 | 543 | /* Begin a conditional that might contain a declaration. When generating |
544 | normal code, we want the declaration to appear before the statement | |
545 | containing the conditional. When generating template code, we want the | |
7dd37241 | 546 | conditional to be rendered as the raw DECL_EXPR. */ |
2363ef00 | 547 | |
548 | static void | |
2b4cffe7 | 549 | begin_cond (tree *cond_p) |
2363ef00 | 550 | { |
2b4cffe7 | 551 | if (processing_template_decl) |
552 | *cond_p = push_stmt_list (); | |
553 | } | |
554 | ||
555 | /* Finish such a conditional. */ | |
556 | ||
557 | static void | |
558 | finish_cond (tree *cond_p, tree expr) | |
559 | { | |
560 | if (processing_template_decl) | |
8036397f | 561 | { |
2b4cffe7 | 562 | tree cond = pop_stmt_list (*cond_p); |
d95d815d | 563 | |
c9e4cdb5 | 564 | if (expr == NULL_TREE) |
565 | /* Empty condition in 'for'. */ | |
566 | gcc_assert (empty_expr_stmt_p (cond)); | |
567 | else if (check_for_bare_parameter_packs (expr)) | |
568 | expr = error_mark_node; | |
569 | else if (!empty_expr_stmt_p (cond)) | |
570 | expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), cond, expr); | |
8036397f | 571 | } |
2b4cffe7 | 572 | *cond_p = expr; |
8036397f | 573 | } |
574 | ||
2363ef00 | 575 | /* If *COND_P specifies a conditional with a declaration, transform the |
576 | loop such that | |
653e5405 | 577 | while (A x = 42) { } |
578 | for (; A x = 42;) { } | |
2363ef00 | 579 | becomes |
653e5405 | 580 | while (true) { A x = 42; if (!x) break; } |
581 | for (;;) { A x = 42; if (!x) break; } | |
2b4cffe7 | 582 | The statement list for BODY will be empty if the conditional did |
583 | not declare anything. */ | |
9031d10b | 584 | |
2363ef00 | 585 | static void |
2b4cffe7 | 586 | simplify_loop_decl_cond (tree *cond_p, tree body) |
2363ef00 | 587 | { |
2b4cffe7 | 588 | tree cond, if_stmt; |
2363ef00 | 589 | |
2b4cffe7 | 590 | if (!TREE_SIDE_EFFECTS (body)) |
591 | return; | |
2363ef00 | 592 | |
2b4cffe7 | 593 | cond = *cond_p; |
594 | *cond_p = boolean_true_node; | |
9031d10b | 595 | |
2b4cffe7 | 596 | if_stmt = begin_if_stmt (); |
ebd21de4 | 597 | cond = cp_build_unary_op (TRUTH_NOT_EXPR, cond, 0, tf_warning_or_error); |
2b4cffe7 | 598 | finish_if_stmt_cond (cond, if_stmt); |
599 | finish_break_stmt (); | |
600 | finish_then_clause (if_stmt); | |
601 | finish_if_stmt (if_stmt); | |
602 | } | |
2363ef00 | 603 | |
8036397f | 604 | /* Finish a goto-statement. */ |
605 | ||
4aa0811f | 606 | tree |
807be5b4 | 607 | finish_goto_stmt (tree destination) |
8036397f | 608 | { |
694683bb | 609 | if (identifier_p (destination)) |
8036397f | 610 | destination = lookup_label (destination); |
611 | ||
612 | /* We warn about unused labels with -Wunused. That means we have to | |
613 | mark the used labels as used. */ | |
614 | if (TREE_CODE (destination) == LABEL_DECL) | |
615 | TREE_USED (destination) = 1; | |
0eb00403 | 616 | else |
617 | { | |
51d9ad16 | 618 | if (check_no_cilk (destination, |
619 | "Cilk array notation cannot be used as a computed goto expression", | |
620 | "%<_Cilk_spawn%> statement cannot be used as a computed goto expression")) | |
621 | destination = error_mark_node; | |
95f11b21 | 622 | destination = mark_rvalue_use (destination); |
0eb00403 | 623 | if (!processing_template_decl) |
30f461c5 | 624 | { |
c4698a21 | 625 | destination = cp_convert (ptr_type_node, destination, |
626 | tf_warning_or_error); | |
30f461c5 | 627 | if (error_operand_p (destination)) |
628 | return NULL_TREE; | |
9f071b17 | 629 | destination |
630 | = fold_build_cleanup_point_expr (TREE_TYPE (destination), | |
631 | destination); | |
30f461c5 | 632 | } |
0eb00403 | 633 | } |
9031d10b | 634 | |
8036397f | 635 | check_goto (destination); |
636 | ||
e60a6f7b | 637 | return add_stmt (build_stmt (input_location, GOTO_EXPR, destination)); |
8036397f | 638 | } |
639 | ||
18a4cb16 | 640 | /* COND is the condition-expression for an if, while, etc., |
168f96cc | 641 | statement. Convert it to a boolean value, if appropriate. |
642 | In addition, verify sequence points if -Wsequence-point is enabled. */ | |
18a4cb16 | 643 | |
9140e457 | 644 | static tree |
807be5b4 | 645 | maybe_convert_cond (tree cond) |
18a4cb16 | 646 | { |
647 | /* Empty conditions remain empty. */ | |
648 | if (!cond) | |
649 | return NULL_TREE; | |
650 | ||
651 | /* Wait until we instantiate templates before doing conversion. */ | |
652 | if (processing_template_decl) | |
653 | return cond; | |
654 | ||
168f96cc | 655 | if (warn_sequence_point) |
656 | verify_sequence_points (cond); | |
657 | ||
18a4cb16 | 658 | /* Do the conversion. */ |
659 | cond = convert_from_reference (cond); | |
60a0513e | 660 | |
661 | if (TREE_CODE (cond) == MODIFY_EXPR | |
662 | && !TREE_NO_WARNING (cond) | |
663 | && warn_parentheses) | |
664 | { | |
665 | warning (OPT_Wparentheses, | |
666 | "suggest parentheses around assignment used as truth value"); | |
667 | TREE_NO_WARNING (cond) = 1; | |
668 | } | |
669 | ||
18a4cb16 | 670 | return condition_conversion (cond); |
671 | } | |
672 | ||
3da16ddc | 673 | /* Finish an expression-statement, whose EXPRESSION is as indicated. */ |
7f826305 | 674 | |
4aa0811f | 675 | tree |
807be5b4 | 676 | finish_expr_stmt (tree expr) |
0090dad2 | 677 | { |
4aa0811f | 678 | tree r = NULL_TREE; |
679 | ||
d8bbef5c | 680 | if (expr != NULL_TREE) |
0090dad2 | 681 | { |
942ab15b | 682 | if (!processing_template_decl) |
2569a1be | 683 | { |
684 | if (warn_sequence_point) | |
685 | verify_sequence_points (expr); | |
dab3247a | 686 | expr = convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error); |
2569a1be | 687 | } |
11dfb79c | 688 | else if (!type_dependent_expression_p (expr)) |
dab3247a | 689 | convert_to_void (build_non_dependent_expr (expr), ICV_STATEMENT, |
ebd21de4 | 690 | tf_warning_or_error); |
2363ef00 | 691 | |
830a6615 | 692 | if (check_for_bare_parameter_packs (expr)) |
613687b1 | 693 | expr = error_mark_node; |
d95d815d | 694 | |
2363ef00 | 695 | /* Simplification of inner statement expressions, compound exprs, |
1f849cd8 | 696 | etc can result in us already having an EXPR_STMT. */ |
73d4090e | 697 | if (TREE_CODE (expr) != CLEANUP_POINT_EXPR) |
698 | { | |
699 | if (TREE_CODE (expr) != EXPR_STMT) | |
e60a6f7b | 700 | expr = build_stmt (input_location, EXPR_STMT, expr); |
acbc760a | 701 | expr = maybe_cleanup_point_expr_void (expr); |
73d4090e | 702 | } |
703 | ||
2363ef00 | 704 | r = add_stmt (expr); |
8036397f | 705 | } |
9f4bf220 | 706 | |
4aa0811f | 707 | return r; |
8036397f | 708 | } |
709 | ||
8036397f | 710 | |
0090dad2 | 711 | /* Begin an if-statement. Returns a newly created IF_STMT if |
712 | appropriate. */ | |
713 | ||
714 | tree | |
807be5b4 | 715 | begin_if_stmt (void) |
0090dad2 | 716 | { |
2363ef00 | 717 | tree r, scope; |
16878d88 | 718 | scope = do_pushlevel (sk_cond); |
852787ab | 719 | r = build_stmt (input_location, IF_STMT, NULL_TREE, |
720 | NULL_TREE, NULL_TREE, scope); | |
2b4cffe7 | 721 | begin_cond (&IF_COND (r)); |
0090dad2 | 722 | return r; |
723 | } | |
724 | ||
725 | /* Process the COND of an if-statement, which may be given by | |
726 | IF_STMT. */ | |
727 | ||
9031d10b | 728 | void |
807be5b4 | 729 | finish_if_stmt_cond (tree cond, tree if_stmt) |
0090dad2 | 730 | { |
2b4cffe7 | 731 | finish_cond (&IF_COND (if_stmt), maybe_convert_cond (cond)); |
732 | add_stmt (if_stmt); | |
2363ef00 | 733 | THEN_CLAUSE (if_stmt) = push_stmt_list (); |
0090dad2 | 734 | } |
735 | ||
736 | /* Finish the then-clause of an if-statement, which may be given by | |
737 | IF_STMT. */ | |
738 | ||
739 | tree | |
807be5b4 | 740 | finish_then_clause (tree if_stmt) |
0090dad2 | 741 | { |
2363ef00 | 742 | THEN_CLAUSE (if_stmt) = pop_stmt_list (THEN_CLAUSE (if_stmt)); |
8036397f | 743 | return if_stmt; |
0090dad2 | 744 | } |
745 | ||
746 | /* Begin the else-clause of an if-statement. */ | |
747 | ||
2363ef00 | 748 | void |
749 | begin_else_clause (tree if_stmt) | |
0090dad2 | 750 | { |
2363ef00 | 751 | ELSE_CLAUSE (if_stmt) = push_stmt_list (); |
0090dad2 | 752 | } |
753 | ||
754 | /* Finish the else-clause of an if-statement, which may be given by | |
755 | IF_STMT. */ | |
756 | ||
757 | void | |
807be5b4 | 758 | finish_else_clause (tree if_stmt) |
0090dad2 | 759 | { |
2363ef00 | 760 | ELSE_CLAUSE (if_stmt) = pop_stmt_list (ELSE_CLAUSE (if_stmt)); |
0090dad2 | 761 | } |
762 | ||
2b686fc5 | 763 | /* Finish an if-statement. */ |
0090dad2 | 764 | |
9031d10b | 765 | void |
2363ef00 | 766 | finish_if_stmt (tree if_stmt) |
0090dad2 | 767 | { |
852787ab | 768 | tree scope = IF_SCOPE (if_stmt); |
769 | IF_SCOPE (if_stmt) = NULL; | |
2363ef00 | 770 | add_stmt (do_poplevel (scope)); |
8036397f | 771 | } |
772 | ||
0090dad2 | 773 | /* Begin a while-statement. Returns a newly created WHILE_STMT if |
774 | appropriate. */ | |
775 | ||
776 | tree | |
807be5b4 | 777 | begin_while_stmt (void) |
0090dad2 | 778 | { |
779 | tree r; | |
e60a6f7b | 780 | r = build_stmt (input_location, WHILE_STMT, NULL_TREE, NULL_TREE); |
a08e60ae | 781 | add_stmt (r); |
2363ef00 | 782 | WHILE_BODY (r) = do_pushlevel (sk_block); |
2b4cffe7 | 783 | begin_cond (&WHILE_COND (r)); |
0090dad2 | 784 | return r; |
785 | } | |
786 | ||
7702ef60 | 787 | /* Process the COND of a while-statement, which may be given by |
0090dad2 | 788 | WHILE_STMT. */ |
789 | ||
9031d10b | 790 | void |
bb7b305c | 791 | finish_while_stmt_cond (tree cond, tree while_stmt, bool ivdep) |
0090dad2 | 792 | { |
51d9ad16 | 793 | if (check_no_cilk (cond, |
794 | "Cilk array notation cannot be used as a condition for while statement", | |
795 | "%<_Cilk_spawn%> statement cannot be used as a condition for while statement")) | |
796 | cond = error_mark_node; | |
9ea3e924 | 797 | cond = maybe_convert_cond (cond); |
798 | finish_cond (&WHILE_COND (while_stmt), cond); | |
799 | begin_maybe_infinite_loop (cond); | |
bb7b305c | 800 | if (ivdep && cond != error_mark_node) |
801 | WHILE_COND (while_stmt) = build2 (ANNOTATE_EXPR, | |
802 | TREE_TYPE (WHILE_COND (while_stmt)), | |
803 | WHILE_COND (while_stmt), | |
804 | build_int_cst (integer_type_node, | |
805 | annot_expr_ivdep_kind)); | |
2b4cffe7 | 806 | simplify_loop_decl_cond (&WHILE_COND (while_stmt), WHILE_BODY (while_stmt)); |
0090dad2 | 807 | } |
808 | ||
809 | /* Finish a while-statement, which may be given by WHILE_STMT. */ | |
810 | ||
9031d10b | 811 | void |
807be5b4 | 812 | finish_while_stmt (tree while_stmt) |
0090dad2 | 813 | { |
9ea3e924 | 814 | end_maybe_infinite_loop (boolean_true_node); |
2363ef00 | 815 | WHILE_BODY (while_stmt) = do_poplevel (WHILE_BODY (while_stmt)); |
0090dad2 | 816 | } |
817 | ||
818 | /* Begin a do-statement. Returns a newly created DO_STMT if | |
819 | appropriate. */ | |
820 | ||
821 | tree | |
807be5b4 | 822 | begin_do_stmt (void) |
0090dad2 | 823 | { |
e60a6f7b | 824 | tree r = build_stmt (input_location, DO_STMT, NULL_TREE, NULL_TREE); |
9ea3e924 | 825 | begin_maybe_infinite_loop (boolean_true_node); |
a08e60ae | 826 | add_stmt (r); |
2363ef00 | 827 | DO_BODY (r) = push_stmt_list (); |
8036397f | 828 | return r; |
0090dad2 | 829 | } |
830 | ||
831 | /* Finish the body of a do-statement, which may be given by DO_STMT. */ | |
832 | ||
833 | void | |
807be5b4 | 834 | finish_do_body (tree do_stmt) |
0090dad2 | 835 | { |
ffe8fd56 | 836 | tree body = DO_BODY (do_stmt) = pop_stmt_list (DO_BODY (do_stmt)); |
837 | ||
838 | if (TREE_CODE (body) == STATEMENT_LIST && STATEMENT_LIST_TAIL (body)) | |
839 | body = STATEMENT_LIST_TAIL (body)->stmt; | |
840 | ||
841 | if (IS_EMPTY_STMT (body)) | |
842 | warning (OPT_Wempty_body, | |
843 | "suggest explicit braces around empty body in %<do%> statement"); | |
0090dad2 | 844 | } |
845 | ||
846 | /* Finish a do-statement, which may be given by DO_STMT, and whose | |
847 | COND is as indicated. */ | |
848 | ||
849 | void | |
bb7b305c | 850 | finish_do_stmt (tree cond, tree do_stmt, bool ivdep) |
0090dad2 | 851 | { |
51d9ad16 | 852 | if (check_no_cilk (cond, |
853 | "Cilk array notation cannot be used as a condition for a do-while statement", | |
854 | "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement")) | |
855 | cond = error_mark_node; | |
18a4cb16 | 856 | cond = maybe_convert_cond (cond); |
9ea3e924 | 857 | end_maybe_infinite_loop (cond); |
bb7b305c | 858 | if (ivdep && cond != error_mark_node) |
859 | cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond, | |
860 | build_int_cst (integer_type_node, annot_expr_ivdep_kind)); | |
8036397f | 861 | DO_COND (do_stmt) = cond; |
8036397f | 862 | } |
18a4cb16 | 863 | |
0090dad2 | 864 | /* Finish a return-statement. The EXPRESSION returned, if any, is as |
865 | indicated. */ | |
866 | ||
4aa0811f | 867 | tree |
807be5b4 | 868 | finish_return_stmt (tree expr) |
0090dad2 | 869 | { |
4aa0811f | 870 | tree r; |
81a3c55b | 871 | bool no_warning; |
4aa0811f | 872 | |
81a3c55b | 873 | expr = check_return_expr (expr, &no_warning); |
8487df40 | 874 | |
f5829705 | 875 | if (error_operand_p (expr) |
876 | || (flag_openmp && !check_omp_return ())) | |
dbe1241e | 877 | { |
878 | /* Suppress -Wreturn-type for this function. */ | |
879 | if (warn_return_type) | |
880 | TREE_NO_WARNING (current_function_decl) = true; | |
881 | return error_mark_node; | |
882 | } | |
883 | ||
8036397f | 884 | if (!processing_template_decl) |
51046b65 | 885 | { |
168f96cc | 886 | if (warn_sequence_point) |
887 | verify_sequence_points (expr); | |
888 | ||
853b7640 | 889 | if (DECL_DESTRUCTOR_P (current_function_decl) |
9031d10b | 890 | || (DECL_CONSTRUCTOR_P (current_function_decl) |
853b7640 | 891 | && targetm.cxx.cdtor_returns_this ())) |
51046b65 | 892 | { |
893 | /* Similarly, all destructors must run destructors for | |
894 | base-classes before returning. So, all returns in a | |
2b686fc5 | 895 | destructor get sent to the DTOR_LABEL; finish_function emits |
51046b65 | 896 | code to return a value there. */ |
853b7640 | 897 | return finish_goto_stmt (cdtor_label); |
51046b65 | 898 | } |
899 | } | |
73d4090e | 900 | |
e60a6f7b | 901 | r = build_stmt (input_location, RETURN_EXPR, expr); |
81a3c55b | 902 | TREE_NO_WARNING (r) |= no_warning; |
acbc760a | 903 | r = maybe_cleanup_point_expr_void (r); |
73d4090e | 904 | r = add_stmt (r); |
4aa0811f | 905 | |
906 | return r; | |
8036397f | 907 | } |
51046b65 | 908 | |
fa7d5870 | 909 | /* Begin the scope of a for-statement or a range-for-statement. |
910 | Both the returned trees are to be used in a call to | |
911 | begin_for_stmt or begin_range_for_stmt. */ | |
0090dad2 | 912 | |
913 | tree | |
fa7d5870 | 914 | begin_for_scope (tree *init) |
915 | { | |
916 | tree scope = NULL_TREE; | |
917 | if (flag_new_for_scope > 0) | |
918 | scope = do_pushlevel (sk_for); | |
919 | ||
920 | if (processing_template_decl) | |
921 | *init = push_stmt_list (); | |
922 | else | |
923 | *init = NULL_TREE; | |
924 | ||
925 | return scope; | |
926 | } | |
927 | ||
928 | /* Begin a for-statement. Returns a new FOR_STMT. | |
929 | SCOPE and INIT should be the return of begin_for_scope, | |
930 | or both NULL_TREE */ | |
931 | ||
932 | tree | |
933 | begin_for_stmt (tree scope, tree init) | |
0090dad2 | 934 | { |
935 | tree r; | |
936 | ||
e60a6f7b | 937 | r = build_stmt (input_location, FOR_STMT, NULL_TREE, NULL_TREE, |
e45c9c55 | 938 | NULL_TREE, NULL_TREE, NULL_TREE); |
2363ef00 | 939 | |
fa7d5870 | 940 | if (scope == NULL_TREE) |
941 | { | |
1bf4f2e0 | 942 | gcc_assert (!init || !(flag_new_for_scope > 0)); |
943 | if (!init) | |
944 | scope = begin_for_scope (&init); | |
fa7d5870 | 945 | } |
946 | FOR_INIT_STMT (r) = init; | |
e45c9c55 | 947 | FOR_SCOPE (r) = scope; |
5250373a | 948 | |
0090dad2 | 949 | return r; |
950 | } | |
951 | ||
952 | /* Finish the for-init-statement of a for-statement, which may be | |
953 | given by FOR_STMT. */ | |
954 | ||
955 | void | |
807be5b4 | 956 | finish_for_init_stmt (tree for_stmt) |
0090dad2 | 957 | { |
5250373a | 958 | if (processing_template_decl) |
959 | FOR_INIT_STMT (for_stmt) = pop_stmt_list (FOR_INIT_STMT (for_stmt)); | |
2363ef00 | 960 | add_stmt (for_stmt); |
961 | FOR_BODY (for_stmt) = do_pushlevel (sk_block); | |
2b4cffe7 | 962 | begin_cond (&FOR_COND (for_stmt)); |
0090dad2 | 963 | } |
964 | ||
965 | /* Finish the COND of a for-statement, which may be given by | |
966 | FOR_STMT. */ | |
967 | ||
968 | void | |
bb7b305c | 969 | finish_for_cond (tree cond, tree for_stmt, bool ivdep) |
0090dad2 | 970 | { |
51d9ad16 | 971 | if (check_no_cilk (cond, |
972 | "Cilk array notation cannot be used in a condition for a for-loop", | |
973 | "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop")) | |
974 | cond = error_mark_node; | |
9ea3e924 | 975 | cond = maybe_convert_cond (cond); |
976 | finish_cond (&FOR_COND (for_stmt), cond); | |
977 | begin_maybe_infinite_loop (cond); | |
bb7b305c | 978 | if (ivdep && cond != error_mark_node) |
979 | FOR_COND (for_stmt) = build2 (ANNOTATE_EXPR, | |
980 | TREE_TYPE (FOR_COND (for_stmt)), | |
981 | FOR_COND (for_stmt), | |
982 | build_int_cst (integer_type_node, | |
983 | annot_expr_ivdep_kind)); | |
2b4cffe7 | 984 | simplify_loop_decl_cond (&FOR_COND (for_stmt), FOR_BODY (for_stmt)); |
0090dad2 | 985 | } |
986 | ||
987 | /* Finish the increment-EXPRESSION in a for-statement, which may be | |
988 | given by FOR_STMT. */ | |
989 | ||
990 | void | |
807be5b4 | 991 | finish_for_expr (tree expr, tree for_stmt) |
0090dad2 | 992 | { |
73d4090e | 993 | if (!expr) |
994 | return; | |
a9d1411a | 995 | /* If EXPR is an overloaded function, issue an error; there is no |
996 | context available to use to perform overload resolution. */ | |
73d4090e | 997 | if (type_unknown_p (expr)) |
a9d1411a | 998 | { |
999 | cxx_incomplete_type_error (expr, TREE_TYPE (expr)); | |
1000 | expr = error_mark_node; | |
1001 | } | |
1b660ce9 | 1002 | if (!processing_template_decl) |
1003 | { | |
1004 | if (warn_sequence_point) | |
653e5405 | 1005 | verify_sequence_points (expr); |
dab3247a | 1006 | expr = convert_to_void (expr, ICV_THIRD_IN_FOR, |
ebd21de4 | 1007 | tf_warning_or_error); |
1b660ce9 | 1008 | } |
1009 | else if (!type_dependent_expression_p (expr)) | |
dab3247a | 1010 | convert_to_void (build_non_dependent_expr (expr), ICV_THIRD_IN_FOR, |
ebd21de4 | 1011 | tf_warning_or_error); |
acbc760a | 1012 | expr = maybe_cleanup_point_expr_void (expr); |
830a6615 | 1013 | if (check_for_bare_parameter_packs (expr)) |
613687b1 | 1014 | expr = error_mark_node; |
8036397f | 1015 | FOR_EXPR (for_stmt) = expr; |
0090dad2 | 1016 | } |
1017 | ||
1018 | /* Finish the body of a for-statement, which may be given by | |
1019 | FOR_STMT. The increment-EXPR for the loop must be | |
9dd72ec4 | 1020 | provided. |
1021 | It can also finish RANGE_FOR_STMT. */ | |
0090dad2 | 1022 | |
1023 | void | |
807be5b4 | 1024 | finish_for_stmt (tree for_stmt) |
0090dad2 | 1025 | { |
9ea3e924 | 1026 | end_maybe_infinite_loop (boolean_true_node); |
1027 | ||
9dd72ec4 | 1028 | if (TREE_CODE (for_stmt) == RANGE_FOR_STMT) |
5d3abe4e | 1029 | RANGE_FOR_BODY (for_stmt) = do_poplevel (RANGE_FOR_BODY (for_stmt)); |
9dd72ec4 | 1030 | else |
5d3abe4e | 1031 | FOR_BODY (for_stmt) = do_poplevel (FOR_BODY (for_stmt)); |
2363ef00 | 1032 | |
0090dad2 | 1033 | /* Pop the scope for the body of the loop. */ |
5d3abe4e | 1034 | if (flag_new_for_scope > 0) |
2363ef00 | 1035 | { |
e45c9c55 | 1036 | tree scope; |
1037 | tree *scope_ptr = (TREE_CODE (for_stmt) == RANGE_FOR_STMT | |
1038 | ? &RANGE_FOR_SCOPE (for_stmt) | |
1039 | : &FOR_SCOPE (for_stmt)); | |
1040 | scope = *scope_ptr; | |
1041 | *scope_ptr = NULL; | |
2363ef00 | 1042 | add_stmt (do_poplevel (scope)); |
1043 | } | |
0090dad2 | 1044 | } |
1045 | ||
9dd72ec4 | 1046 | /* Begin a range-for-statement. Returns a new RANGE_FOR_STMT. |
fa7d5870 | 1047 | SCOPE and INIT should be the return of begin_for_scope, |
1048 | or both NULL_TREE . | |
9dd72ec4 | 1049 | To finish it call finish_for_stmt(). */ |
1050 | ||
1051 | tree | |
fa7d5870 | 1052 | begin_range_for_stmt (tree scope, tree init) |
9dd72ec4 | 1053 | { |
1054 | tree r; | |
5d3abe4e | 1055 | |
9ea3e924 | 1056 | begin_maybe_infinite_loop (boolean_false_node); |
1057 | ||
9dd72ec4 | 1058 | r = build_stmt (input_location, RANGE_FOR_STMT, |
e45c9c55 | 1059 | NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE); |
5d3abe4e | 1060 | |
fa7d5870 | 1061 | if (scope == NULL_TREE) |
1062 | { | |
1bf4f2e0 | 1063 | gcc_assert (!init || !(flag_new_for_scope > 0)); |
1064 | if (!init) | |
1065 | scope = begin_for_scope (&init); | |
fa7d5870 | 1066 | } |
1067 | ||
1068 | /* RANGE_FOR_STMTs do not use nor save the init tree, so we | |
1069 | pop it now. */ | |
1070 | if (init) | |
1071 | pop_stmt_list (init); | |
e45c9c55 | 1072 | RANGE_FOR_SCOPE (r) = scope; |
9dd72ec4 | 1073 | |
1074 | return r; | |
1075 | } | |
1076 | ||
1077 | /* Finish the head of a range-based for statement, which may | |
1078 | be given by RANGE_FOR_STMT. DECL must be the declaration | |
1079 | and EXPR must be the loop expression. */ | |
1080 | ||
1081 | void | |
1082 | finish_range_for_decl (tree range_for_stmt, tree decl, tree expr) | |
1083 | { | |
1084 | RANGE_FOR_DECL (range_for_stmt) = decl; | |
1085 | RANGE_FOR_EXPR (range_for_stmt) = expr; | |
1086 | add_stmt (range_for_stmt); | |
1087 | RANGE_FOR_BODY (range_for_stmt) = do_pushlevel (sk_block); | |
1088 | } | |
1089 | ||
0090dad2 | 1090 | /* Finish a break-statement. */ |
1091 | ||
4aa0811f | 1092 | tree |
807be5b4 | 1093 | finish_break_stmt (void) |
0090dad2 | 1094 | { |
e8653c02 | 1095 | /* In switch statements break is sometimes stylistically used after |
1096 | a return statement. This can lead to spurious warnings about | |
1097 | control reaching the end of a non-void function when it is | |
1098 | inlined. Note that we are calling block_may_fallthru with | |
1099 | language specific tree nodes; this works because | |
1100 | block_may_fallthru returns true when given something it does not | |
1101 | understand. */ | |
1102 | if (!block_may_fallthru (cur_stmt_list)) | |
3ab4693e | 1103 | return void_node; |
e60a6f7b | 1104 | return add_stmt (build_stmt (input_location, BREAK_STMT)); |
8036397f | 1105 | } |
1106 | ||
0090dad2 | 1107 | /* Finish a continue-statement. */ |
1108 | ||
4aa0811f | 1109 | tree |
807be5b4 | 1110 | finish_continue_stmt (void) |
0090dad2 | 1111 | { |
e60a6f7b | 1112 | return add_stmt (build_stmt (input_location, CONTINUE_STMT)); |
0090dad2 | 1113 | } |
1114 | ||
8036397f | 1115 | /* Begin a switch-statement. Returns a new SWITCH_STMT if |
1116 | appropriate. */ | |
1117 | ||
1118 | tree | |
807be5b4 | 1119 | begin_switch_stmt (void) |
8036397f | 1120 | { |
2363ef00 | 1121 | tree r, scope; |
1122 | ||
16878d88 | 1123 | scope = do_pushlevel (sk_cond); |
1f919c50 | 1124 | r = build_stmt (input_location, SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE, scope); |
1125 | ||
ffc8e524 | 1126 | begin_cond (&SWITCH_STMT_COND (r)); |
2363ef00 | 1127 | |
581d6863 | 1128 | return r; |
0090dad2 | 1129 | } |
1130 | ||
581d6863 | 1131 | /* Finish the cond of a switch-statement. */ |
0090dad2 | 1132 | |
581d6863 | 1133 | void |
807be5b4 | 1134 | finish_switch_cond (tree cond, tree switch_stmt) |
0090dad2 | 1135 | { |
79dc3b8e | 1136 | tree orig_type = NULL; |
51d9ad16 | 1137 | |
1138 | if (check_no_cilk (cond, | |
1139 | "Cilk array notation cannot be used as a condition for switch statement", | |
1140 | "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement")) | |
1141 | cond = error_mark_node; | |
1142 | ||
8036397f | 1143 | if (!processing_template_decl) |
922fb6c7 | 1144 | { |
8036397f | 1145 | /* Convert the condition to an integer or enumeration type. */ |
35771a9a | 1146 | cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, true); |
8036397f | 1147 | if (cond == NULL_TREE) |
922fb6c7 | 1148 | { |
8036397f | 1149 | error ("switch quantity not an integer"); |
1150 | cond = error_mark_node; | |
1151 | } | |
5213d6c9 | 1152 | /* We want unlowered type here to handle enum bit-fields. */ |
1153 | orig_type = unlowered_expr_type (cond); | |
6e08defb | 1154 | if (TREE_CODE (orig_type) != ENUMERAL_TYPE) |
1155 | orig_type = TREE_TYPE (cond); | |
8036397f | 1156 | if (cond != error_mark_node) |
1157 | { | |
a681799d | 1158 | /* [stmt.switch] |
1159 | ||
1160 | Integral promotions are performed. */ | |
1161 | cond = perform_integral_promotions (cond); | |
73d4090e | 1162 | cond = maybe_cleanup_point_expr (cond); |
922fb6c7 | 1163 | } |
0090dad2 | 1164 | } |
830a6615 | 1165 | if (check_for_bare_parameter_packs (cond)) |
613687b1 | 1166 | cond = error_mark_node; |
168f96cc | 1167 | else if (!processing_template_decl && warn_sequence_point) |
1168 | verify_sequence_points (cond); | |
1169 | ||
ffc8e524 | 1170 | finish_cond (&SWITCH_STMT_COND (switch_stmt), cond); |
1171 | SWITCH_STMT_TYPE (switch_stmt) = orig_type; | |
2b4cffe7 | 1172 | add_stmt (switch_stmt); |
225ec6aa | 1173 | push_switch (switch_stmt); |
ffc8e524 | 1174 | SWITCH_STMT_BODY (switch_stmt) = push_stmt_list (); |
0090dad2 | 1175 | } |
1176 | ||
1177 | /* Finish the body of a switch-statement, which may be given by | |
1178 | SWITCH_STMT. The COND to switch on is indicated. */ | |
1179 | ||
1180 | void | |
807be5b4 | 1181 | finish_switch_stmt (tree switch_stmt) |
0090dad2 | 1182 | { |
2363ef00 | 1183 | tree scope; |
1184 | ||
ffc8e524 | 1185 | SWITCH_STMT_BODY (switch_stmt) = |
1186 | pop_stmt_list (SWITCH_STMT_BODY (switch_stmt)); | |
9031d10b | 1187 | pop_switch (); |
2363ef00 | 1188 | |
1f919c50 | 1189 | scope = SWITCH_STMT_SCOPE (switch_stmt); |
1190 | SWITCH_STMT_SCOPE (switch_stmt) = NULL; | |
2363ef00 | 1191 | add_stmt (do_poplevel (scope)); |
0090dad2 | 1192 | } |
1193 | ||
0090dad2 | 1194 | /* Begin a try-block. Returns a newly-created TRY_BLOCK if |
1195 | appropriate. */ | |
1196 | ||
1197 | tree | |
807be5b4 | 1198 | begin_try_block (void) |
0090dad2 | 1199 | { |
e60a6f7b | 1200 | tree r = build_stmt (input_location, TRY_BLOCK, NULL_TREE, NULL_TREE); |
a08e60ae | 1201 | add_stmt (r); |
2363ef00 | 1202 | TRY_STMTS (r) = push_stmt_list (); |
8036397f | 1203 | return r; |
0090dad2 | 1204 | } |
1205 | ||
78f7169a | 1206 | /* Likewise, for a function-try-block. The block returned in |
1207 | *COMPOUND_STMT is an artificial outer scope, containing the | |
1208 | function-try-block. */ | |
2c440a13 | 1209 | |
1210 | tree | |
78f7169a | 1211 | begin_function_try_block (tree *compound_stmt) |
2c440a13 | 1212 | { |
78f7169a | 1213 | tree r; |
1214 | /* This outer scope does not exist in the C++ standard, but we need | |
1215 | a place to put __FUNCTION__ and similar variables. */ | |
1216 | *compound_stmt = begin_compound_stmt (0); | |
1217 | r = begin_try_block (); | |
8036397f | 1218 | FN_TRY_BLOCK_P (r) = 1; |
8036397f | 1219 | return r; |
2c440a13 | 1220 | } |
1221 | ||
0090dad2 | 1222 | /* Finish a try-block, which may be given by TRY_BLOCK. */ |
1223 | ||
1224 | void | |
807be5b4 | 1225 | finish_try_block (tree try_block) |
0090dad2 | 1226 | { |
2363ef00 | 1227 | TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block)); |
1228 | TRY_HANDLERS (try_block) = push_stmt_list (); | |
0090dad2 | 1229 | } |
1230 | ||
938566e5 | 1231 | /* Finish the body of a cleanup try-block, which may be given by |
1232 | TRY_BLOCK. */ | |
1233 | ||
0a8302dc | 1234 | void |
807be5b4 | 1235 | finish_cleanup_try_block (tree try_block) |
0a8302dc | 1236 | { |
2363ef00 | 1237 | TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block)); |
0a8302dc | 1238 | } |
1239 | ||
b48733fd | 1240 | /* Finish an implicitly generated try-block, with a cleanup is given |
1241 | by CLEANUP. */ | |
1242 | ||
1243 | void | |
807be5b4 | 1244 | finish_cleanup (tree cleanup, tree try_block) |
b48733fd | 1245 | { |
8036397f | 1246 | TRY_HANDLERS (try_block) = cleanup; |
1247 | CLEANUP_P (try_block) = 1; | |
b48733fd | 1248 | } |
1249 | ||
2c440a13 | 1250 | /* Likewise, for a function-try-block. */ |
1251 | ||
1252 | void | |
807be5b4 | 1253 | finish_function_try_block (tree try_block) |
2c440a13 | 1254 | { |
2363ef00 | 1255 | finish_try_block (try_block); |
1256 | /* FIXME : something queer about CTOR_INITIALIZER somehow following | |
1257 | the try block, but moving it inside. */ | |
e0e489c4 | 1258 | in_function_try_handler = 1; |
2c440a13 | 1259 | } |
1260 | ||
0090dad2 | 1261 | /* Finish a handler-sequence for a try-block, which may be given by |
1262 | TRY_BLOCK. */ | |
1263 | ||
1264 | void | |
807be5b4 | 1265 | finish_handler_sequence (tree try_block) |
0090dad2 | 1266 | { |
2363ef00 | 1267 | TRY_HANDLERS (try_block) = pop_stmt_list (TRY_HANDLERS (try_block)); |
8036397f | 1268 | check_handlers (TRY_HANDLERS (try_block)); |
0090dad2 | 1269 | } |
1270 | ||
78f7169a | 1271 | /* Finish the handler-seq for a function-try-block, given by |
1272 | TRY_BLOCK. COMPOUND_STMT is the outer block created by | |
1273 | begin_function_try_block. */ | |
2c440a13 | 1274 | |
1275 | void | |
78f7169a | 1276 | finish_function_handler_sequence (tree try_block, tree compound_stmt) |
2c440a13 | 1277 | { |
e0e489c4 | 1278 | in_function_try_handler = 0; |
2363ef00 | 1279 | finish_handler_sequence (try_block); |
78f7169a | 1280 | finish_compound_stmt (compound_stmt); |
8036397f | 1281 | } |
1282 | ||
0090dad2 | 1283 | /* Begin a handler. Returns a HANDLER if appropriate. */ |
1284 | ||
1285 | tree | |
807be5b4 | 1286 | begin_handler (void) |
0090dad2 | 1287 | { |
1288 | tree r; | |
2363ef00 | 1289 | |
e60a6f7b | 1290 | r = build_stmt (input_location, HANDLER, NULL_TREE, NULL_TREE); |
a08e60ae | 1291 | add_stmt (r); |
2363ef00 | 1292 | |
6993fb0a | 1293 | /* Create a binding level for the eh_info and the exception object |
1294 | cleanup. */ | |
2363ef00 | 1295 | HANDLER_BODY (r) = do_pushlevel (sk_catch); |
1296 | ||
0090dad2 | 1297 | return r; |
1298 | } | |
1299 | ||
1300 | /* Finish the handler-parameters for a handler, which may be given by | |
e0e489c4 | 1301 | HANDLER. DECL is the declaration for the catch parameter, or NULL |
1302 | if this is a `catch (...)' clause. */ | |
0090dad2 | 1303 | |
6993fb0a | 1304 | void |
807be5b4 | 1305 | finish_handler_parms (tree decl, tree handler) |
e0e489c4 | 1306 | { |
6993fb0a | 1307 | tree type = NULL_TREE; |
e0e489c4 | 1308 | if (processing_template_decl) |
1309 | { | |
1310 | if (decl) | |
1311 | { | |
1312 | decl = pushdecl (decl); | |
1313 | decl = push_template_decl (decl); | |
2363ef00 | 1314 | HANDLER_PARMS (handler) = decl; |
6993fb0a | 1315 | type = TREE_TYPE (decl); |
e0e489c4 | 1316 | } |
1317 | } | |
8036397f | 1318 | else |
6993fb0a | 1319 | type = expand_start_catch_block (decl); |
6993fb0a | 1320 | HANDLER_TYPE (handler) = type; |
8036397f | 1321 | } |
1322 | ||
1323 | /* Finish a handler, which may be given by HANDLER. The BLOCKs are | |
1324 | the return value from the matching call to finish_handler_parms. */ | |
1325 | ||
1326 | void | |
807be5b4 | 1327 | finish_handler (tree handler) |
8036397f | 1328 | { |
1329 | if (!processing_template_decl) | |
6993fb0a | 1330 | expand_end_catch_block (); |
2363ef00 | 1331 | HANDLER_BODY (handler) = do_poplevel (HANDLER_BODY (handler)); |
8036397f | 1332 | } |
1333 | ||
632f8185 | 1334 | /* Begin a compound statement. FLAGS contains some bits that control the |
6cd5db64 | 1335 | behavior and context. If BCS_NO_SCOPE is set, the compound statement |
632f8185 | 1336 | does not define a scope. If BCS_FN_BODY is set, this is the outermost |
9031d10b | 1337 | block of a function. If BCS_TRY_BLOCK is set, this is the block |
632f8185 | 1338 | created on behalf of a TRY statement. Returns a token to be passed to |
1339 | finish_compound_stmt. */ | |
0090dad2 | 1340 | |
1341 | tree | |
2363ef00 | 1342 | begin_compound_stmt (unsigned int flags) |
0090dad2 | 1343 | { |
2363ef00 | 1344 | tree r; |
019cf886 | 1345 | |
2363ef00 | 1346 | if (flags & BCS_NO_SCOPE) |
1347 | { | |
1348 | r = push_stmt_list (); | |
1349 | STATEMENT_LIST_NO_SCOPE (r) = 1; | |
1350 | ||
1351 | /* Normally, we try hard to keep the BLOCK for a statement-expression. | |
1352 | But, if it's a statement-expression with a scopeless block, there's | |
1353 | nothing to keep, and we don't want to accidentally keep a block | |
9031d10b | 1354 | *inside* the scopeless block. */ |
2363ef00 | 1355 | keep_next_level (false); |
1356 | } | |
b48733fd | 1357 | else |
2363ef00 | 1358 | r = do_pushlevel (flags & BCS_TRY_BLOCK ? sk_try : sk_block); |
1359 | ||
632f8185 | 1360 | /* When processing a template, we need to remember where the braces were, |
1361 | so that we can set up identical scopes when instantiating the template | |
1362 | later. BIND_EXPR is a handy candidate for this. | |
1363 | Note that do_poplevel won't create a BIND_EXPR itself here (and thus | |
1364 | result in nested BIND_EXPRs), since we don't build BLOCK nodes when | |
1365 | processing templates. */ | |
1366 | if (processing_template_decl) | |
2363ef00 | 1367 | { |
831d52a2 | 1368 | r = build3 (BIND_EXPR, NULL, NULL, r, NULL); |
632f8185 | 1369 | BIND_EXPR_TRY_BLOCK (r) = (flags & BCS_TRY_BLOCK) != 0; |
1370 | BIND_EXPR_BODY_BLOCK (r) = (flags & BCS_FN_BODY) != 0; | |
2363ef00 | 1371 | TREE_SIDE_EFFECTS (r) = 1; |
1372 | } | |
0090dad2 | 1373 | |
1374 | return r; | |
1375 | } | |
1376 | ||
632f8185 | 1377 | /* Finish a compound-statement, which is given by STMT. */ |
0090dad2 | 1378 | |
2363ef00 | 1379 | void |
1380 | finish_compound_stmt (tree stmt) | |
0090dad2 | 1381 | { |
632f8185 | 1382 | if (TREE_CODE (stmt) == BIND_EXPR) |
3bb40bd8 | 1383 | { |
1384 | tree body = do_poplevel (BIND_EXPR_BODY (stmt)); | |
1385 | /* If the STATEMENT_LIST is empty and this BIND_EXPR isn't special, | |
1386 | discard the BIND_EXPR so it can be merged with the containing | |
1387 | STATEMENT_LIST. */ | |
1388 | if (TREE_CODE (body) == STATEMENT_LIST | |
1389 | && STATEMENT_LIST_HEAD (body) == NULL | |
1390 | && !BIND_EXPR_BODY_BLOCK (stmt) | |
1391 | && !BIND_EXPR_TRY_BLOCK (stmt)) | |
1392 | stmt = body; | |
1393 | else | |
1394 | BIND_EXPR_BODY (stmt) = body; | |
1395 | } | |
2363ef00 | 1396 | else if (STATEMENT_LIST_NO_SCOPE (stmt)) |
1397 | stmt = pop_stmt_list (stmt); | |
68f8f8cc | 1398 | else |
b2341f36 | 1399 | { |
1400 | /* Destroy any ObjC "super" receivers that may have been | |
1401 | created. */ | |
1402 | objc_clear_super_receiver (); | |
1403 | ||
1404 | stmt = do_poplevel (stmt); | |
1405 | } | |
0090dad2 | 1406 | |
2363ef00 | 1407 | /* ??? See c_end_compound_stmt wrt statement expressions. */ |
1408 | add_stmt (stmt); | |
0090dad2 | 1409 | } |
1410 | ||
4ee9c684 | 1411 | /* Finish an asm-statement, whose components are a STRING, some |
78f55ca8 | 1412 | OUTPUT_OPERANDS, some INPUT_OPERANDS, some CLOBBERS and some |
1413 | LABELS. Also note whether the asm-statement should be | |
1414 | considered volatile. */ | |
690a42fb | 1415 | |
4aa0811f | 1416 | tree |
4ee9c684 | 1417 | finish_asm_stmt (int volatile_p, tree string, tree output_operands, |
78f55ca8 | 1418 | tree input_operands, tree clobbers, tree labels) |
8036397f | 1419 | { |
1420 | tree r; | |
bf14e7f5 | 1421 | tree t; |
89552023 | 1422 | int ninputs = list_length (input_operands); |
1423 | int noutputs = list_length (output_operands); | |
bf14e7f5 | 1424 | |
bf14e7f5 | 1425 | if (!processing_template_decl) |
37c0f956 | 1426 | { |
8b0d0af6 | 1427 | const char *constraint; |
1428 | const char **oconstraints; | |
1429 | bool allows_mem, allows_reg, is_inout; | |
1430 | tree operand; | |
37c0f956 | 1431 | int i; |
37c0f956 | 1432 | |
fd70b918 | 1433 | oconstraints = XALLOCAVEC (const char *, noutputs); |
8b0d0af6 | 1434 | |
1435 | string = resolve_asm_operand_names (string, output_operands, | |
78f55ca8 | 1436 | input_operands, labels); |
8b0d0af6 | 1437 | |
1438 | for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i) | |
37c0f956 | 1439 | { |
8b0d0af6 | 1440 | operand = TREE_VALUE (t); |
1441 | ||
1442 | /* ??? Really, this should not be here. Users should be using a | |
1443 | proper lvalue, dammit. But there's a long history of using | |
1444 | casts in the output operands. In cases like longlong.h, this | |
1445 | becomes a primitive form of typechecking -- if the cast can be | |
1446 | removed, then the output operand had a type of the proper width; | |
1447 | otherwise we'll get an error. Gross, but ... */ | |
1448 | STRIP_NOPS (operand); | |
1449 | ||
fbb73d9b | 1450 | operand = mark_lvalue_use (operand); |
1451 | ||
ebd21de4 | 1452 | if (!lvalue_or_else (operand, lv_asm, tf_warning_or_error)) |
8b0d0af6 | 1453 | operand = error_mark_node; |
1454 | ||
074ab442 | 1455 | if (operand != error_mark_node |
89552023 | 1456 | && (TREE_READONLY (operand) |
1457 | || CP_TYPE_CONST_P (TREE_TYPE (operand)) | |
074ab442 | 1458 | /* Functions are not modifiable, even though they are |
1459 | lvalues. */ | |
1460 | || TREE_CODE (TREE_TYPE (operand)) == FUNCTION_TYPE | |
1461 | || TREE_CODE (TREE_TYPE (operand)) == METHOD_TYPE | |
1462 | /* If it's an aggregate and any field is const, then it is | |
1463 | effectively const. */ | |
1464 | || (CLASS_TYPE_P (TREE_TYPE (operand)) | |
1465 | && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand))))) | |
a1f90215 | 1466 | cxx_readonly_error (operand, lv_asm); |
89552023 | 1467 | |
8b0d0af6 | 1468 | constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t))); |
1469 | oconstraints[i] = constraint; | |
1470 | ||
1471 | if (parse_output_constraint (&constraint, i, ninputs, noutputs, | |
1472 | &allows_mem, &allows_reg, &is_inout)) | |
1473 | { | |
1474 | /* If the operand is going to end up in memory, | |
1475 | mark it addressable. */ | |
1476 | if (!allows_reg && !cxx_mark_addressable (operand)) | |
1477 | operand = error_mark_node; | |
1478 | } | |
1479 | else | |
1480 | operand = error_mark_node; | |
1481 | ||
1482 | TREE_VALUE (t) = operand; | |
1483 | } | |
1484 | ||
1485 | for (i = 0, t = input_operands; t; ++i, t = TREE_CHAIN (t)) | |
1486 | { | |
1487 | constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t))); | |
d2fd2706 | 1488 | bool constraint_parsed |
1489 | = parse_input_constraint (&constraint, i, ninputs, noutputs, 0, | |
1490 | oconstraints, &allows_mem, &allows_reg); | |
1491 | /* If the operand is going to end up in memory, don't call | |
1492 | decay_conversion. */ | |
1493 | if (constraint_parsed && !allows_reg && allows_mem) | |
1494 | operand = mark_lvalue_use (TREE_VALUE (t)); | |
1495 | else | |
1496 | operand = decay_conversion (TREE_VALUE (t), tf_warning_or_error); | |
8b0d0af6 | 1497 | |
37c0f956 | 1498 | /* If the type of the operand hasn't been determined (e.g., |
1499 | because it involves an overloaded function), then issue | |
1500 | an error message. There's no context available to | |
1501 | resolve the overloading. */ | |
8b0d0af6 | 1502 | if (TREE_TYPE (operand) == unknown_type_node) |
37c0f956 | 1503 | { |
9031d10b | 1504 | error ("type of asm operand %qE could not be determined", |
653e5405 | 1505 | TREE_VALUE (t)); |
8b0d0af6 | 1506 | operand = error_mark_node; |
37c0f956 | 1507 | } |
37c0f956 | 1508 | |
d2fd2706 | 1509 | if (constraint_parsed) |
37c0f956 | 1510 | { |
8b0d0af6 | 1511 | /* If the operand is going to end up in memory, |
1512 | mark it addressable. */ | |
c6e95001 | 1513 | if (!allows_reg && allows_mem) |
1514 | { | |
1515 | /* Strip the nops as we allow this case. FIXME, this really | |
1516 | should be rejected or made deprecated. */ | |
1517 | STRIP_NOPS (operand); | |
1518 | if (!cxx_mark_addressable (operand)) | |
1519 | operand = error_mark_node; | |
1520 | } | |
a756eaf1 | 1521 | else if (!allows_reg && !allows_mem) |
1522 | { | |
1523 | /* If constraint allows neither register nor memory, | |
1524 | try harder to get a constant. */ | |
1525 | tree constop = maybe_constant_value (operand); | |
1526 | if (TREE_CONSTANT (constop)) | |
1527 | operand = constop; | |
1528 | } | |
37c0f956 | 1529 | } |
8b0d0af6 | 1530 | else |
1531 | operand = error_mark_node; | |
37c0f956 | 1532 | |
8b0d0af6 | 1533 | TREE_VALUE (t) = operand; |
37c0f956 | 1534 | } |
1535 | } | |
bf14e7f5 | 1536 | |
e60a6f7b | 1537 | r = build_stmt (input_location, ASM_EXPR, string, |
389acd0a | 1538 | output_operands, input_operands, |
78f55ca8 | 1539 | clobbers, labels); |
89552023 | 1540 | ASM_VOLATILE_P (r) = volatile_p || noutputs == 0; |
acbc760a | 1541 | r = maybe_cleanup_point_expr_void (r); |
4aa0811f | 1542 | return add_stmt (r); |
0090dad2 | 1543 | } |
01b3f071 | 1544 | |
e1c8f1c5 | 1545 | /* Finish a label with the indicated NAME. Returns the new label. */ |
edf2a96a | 1546 | |
0a3b29ad | 1547 | tree |
807be5b4 | 1548 | finish_label_stmt (tree name) |
edf2a96a | 1549 | { |
92ddaf90 | 1550 | tree decl = define_label (input_location, name); |
b34664af | 1551 | |
e1c8f1c5 | 1552 | if (decl == error_mark_node) |
b34664af | 1553 | return error_mark_node; |
1554 | ||
e60a6f7b | 1555 | add_stmt (build_stmt (input_location, LABEL_EXPR, decl)); |
e1c8f1c5 | 1556 | |
1557 | return decl; | |
edf2a96a | 1558 | } |
1559 | ||
2d46e540 | 1560 | /* Finish a series of declarations for local labels. G++ allows users |
1561 | to declare "local" labels, i.e., labels with scope. This extension | |
1562 | is useful when writing code involving statement-expressions. */ | |
1563 | ||
1564 | void | |
807be5b4 | 1565 | finish_label_decl (tree name) |
2d46e540 | 1566 | { |
cc961cff | 1567 | if (!at_function_scope_p ()) |
1568 | { | |
1569 | error ("__label__ declarations are only allowed in function scopes"); | |
1570 | return; | |
1571 | } | |
1572 | ||
1573 | add_decl_expr (declare_local_label (name)); | |
2d46e540 | 1574 | } |
1575 | ||
a9bc793b | 1576 | /* When DECL goes out of scope, make sure that CLEANUP is executed. */ |
b48733fd | 1577 | |
9031d10b | 1578 | void |
807be5b4 | 1579 | finish_decl_cleanup (tree decl, tree cleanup) |
b48733fd | 1580 | { |
2363ef00 | 1581 | push_cleanup (decl, cleanup, false); |
8036397f | 1582 | } |
1583 | ||
a9bc793b | 1584 | /* If the current scope exits with an exception, run CLEANUP. */ |
2243fa67 | 1585 | |
a9bc793b | 1586 | void |
807be5b4 | 1587 | finish_eh_cleanup (tree cleanup) |
2243fa67 | 1588 | { |
2363ef00 | 1589 | push_cleanup (NULL, cleanup, true); |
8036397f | 1590 | } |
1591 | ||
6507cda8 | 1592 | /* The MEM_INITS is a list of mem-initializers, in reverse of the |
1593 | order they were written by the user. Each node is as for | |
1594 | emit_mem_initializers. */ | |
5fea3263 | 1595 | |
1596 | void | |
6507cda8 | 1597 | finish_mem_initializers (tree mem_inits) |
5fea3263 | 1598 | { |
6507cda8 | 1599 | /* Reorder the MEM_INITS so that they are in the order they appeared |
1600 | in the source program. */ | |
1601 | mem_inits = nreverse (mem_inits); | |
5fea3263 | 1602 | |
fb75f6dc | 1603 | if (processing_template_decl) |
d95d815d | 1604 | { |
1605 | tree mem; | |
1606 | ||
1607 | for (mem = mem_inits; mem; mem = TREE_CHAIN (mem)) | |
1608 | { | |
1609 | /* If the TREE_PURPOSE is a TYPE_PACK_EXPANSION, skip the | |
1610 | check for bare parameter packs in the TREE_VALUE, because | |
1611 | any parameter packs in the TREE_VALUE have already been | |
1612 | bound as part of the TREE_PURPOSE. See | |
1613 | make_pack_expansion for more information. */ | |
613687b1 | 1614 | if (TREE_CODE (TREE_PURPOSE (mem)) != TYPE_PACK_EXPANSION |
830a6615 | 1615 | && check_for_bare_parameter_packs (TREE_VALUE (mem))) |
613687b1 | 1616 | TREE_VALUE (mem) = error_mark_node; |
d95d815d | 1617 | } |
1618 | ||
255b5d15 | 1619 | add_stmt (build_min_nt_loc (UNKNOWN_LOCATION, |
1620 | CTOR_INITIALIZER, mem_inits)); | |
d95d815d | 1621 | } |
7e3e1bb9 | 1622 | else |
6507cda8 | 1623 | emit_mem_initializers (mem_inits); |
019cf886 | 1624 | } |
1625 | ||
07850d16 | 1626 | /* Obfuscate EXPR if it looks like an id-expression or member access so |
1627 | that the call to finish_decltype in do_auto_deduction will give the | |
1628 | right result. */ | |
1629 | ||
1630 | tree | |
1631 | force_paren_expr (tree expr) | |
1632 | { | |
1633 | /* This is only needed for decltype(auto) in C++14. */ | |
4e454776 | 1634 | if (cxx_dialect < cxx14) |
07850d16 | 1635 | return expr; |
1636 | ||
312942d8 | 1637 | /* If we're in unevaluated context, we can't be deducing a |
1638 | return/initializer type, so we don't need to mess with this. */ | |
1639 | if (cp_unevaluated_operand) | |
1640 | return expr; | |
1641 | ||
07850d16 | 1642 | if (!DECL_P (expr) && TREE_CODE (expr) != COMPONENT_REF |
1643 | && TREE_CODE (expr) != SCOPE_REF) | |
1644 | return expr; | |
1645 | ||
312942d8 | 1646 | if (TREE_CODE (expr) == COMPONENT_REF) |
1647 | REF_PARENTHESIZED_P (expr) = true; | |
1648 | else if (type_dependent_expression_p (expr)) | |
07850d16 | 1649 | expr = build1 (PAREN_EXPR, TREE_TYPE (expr), expr); |
1650 | else | |
1651 | { | |
1652 | cp_lvalue_kind kind = lvalue_kind (expr); | |
1653 | if ((kind & ~clk_class) != clk_none) | |
1654 | { | |
1655 | tree type = unlowered_expr_type (expr); | |
1656 | bool rval = !!(kind & clk_rvalueref); | |
1657 | type = cp_build_reference_type (type, rval); | |
800c612b | 1658 | /* This inhibits warnings in, eg, cxx_mark_addressable |
1659 | (c++/60955). */ | |
1660 | warning_sentinel s (extra_warnings); | |
312942d8 | 1661 | expr = build_static_cast (type, expr, tf_error); |
a5369bbd | 1662 | if (expr != error_mark_node) |
1663 | REF_PARENTHESIZED_P (expr) = true; | |
07850d16 | 1664 | } |
1665 | } | |
1666 | ||
1667 | return expr; | |
1668 | } | |
1669 | ||
01b3f071 | 1670 | /* Finish a parenthesized expression EXPR. */ |
1671 | ||
1672 | tree | |
807be5b4 | 1673 | finish_parenthesized_expr (tree expr) |
01b3f071 | 1674 | { |
ce45a448 | 1675 | if (EXPR_P (expr)) |
aff9e656 | 1676 | /* This inhibits warnings in c_common_truthvalue_conversion. */ |
6cec67d6 | 1677 | TREE_NO_WARNING (expr) = 1; |
01b3f071 | 1678 | |
38ba19fa | 1679 | if (TREE_CODE (expr) == OFFSET_REF |
1680 | || TREE_CODE (expr) == SCOPE_REF) | |
30efa7ed | 1681 | /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be |
1682 | enclosed in parentheses. */ | |
1683 | PTRMEM_OK_P (expr) = 0; | |
9031d10b | 1684 | |
a9aacc0c | 1685 | if (TREE_CODE (expr) == STRING_CST) |
1686 | PAREN_STRING_LITERAL_P (expr) = 1; | |
9031d10b | 1687 | |
07850d16 | 1688 | expr = force_paren_expr (expr); |
1689 | ||
01b3f071 | 1690 | return expr; |
1691 | } | |
1692 | ||
0a3b29ad | 1693 | /* Finish a reference to a non-static data member (DECL) that is not |
1694 | preceded by `.' or `->'. */ | |
1695 | ||
1696 | tree | |
26d880e6 | 1697 | finish_non_static_data_member (tree decl, tree object, tree qualifying_scope) |
0a3b29ad | 1698 | { |
b4df430b | 1699 | gcc_assert (TREE_CODE (decl) == FIELD_DECL); |
0a3b29ad | 1700 | |
70269a57 | 1701 | if (!object) |
76418e04 | 1702 | { |
76418e04 | 1703 | tree scope = qualifying_scope; |
1704 | if (scope == NULL_TREE) | |
1705 | scope = context_for_name_lookup (decl); | |
1706 | object = maybe_dummy_object (scope, NULL); | |
1707 | } | |
1708 | ||
f1ec53b6 | 1709 | object = maybe_resolve_dummy (object, true); |
6e2ac691 | 1710 | if (object == error_mark_node) |
1711 | return error_mark_node; | |
1712 | ||
dc66dd88 | 1713 | /* DR 613/850: Can use non-static data members without an associated |
70269a57 | 1714 | object in sizeof/decltype/alignof. */ |
1715 | if (is_dummy_object (object) && cp_unevaluated_operand == 0 | |
1716 | && (!processing_template_decl || !current_class_ref)) | |
0a3b29ad | 1717 | { |
9031d10b | 1718 | if (current_function_decl |
0a3b29ad | 1719 | && DECL_STATIC_FUNCTION_P (current_function_decl)) |
a323e529 | 1720 | error ("invalid use of member %qD in static member function", decl); |
0a3b29ad | 1721 | else |
a323e529 | 1722 | error ("invalid use of non-static data member %qD", decl); |
1723 | inform (DECL_SOURCE_LOCATION (decl), "declared here"); | |
0a3b29ad | 1724 | |
1725 | return error_mark_node; | |
1726 | } | |
a8b75081 | 1727 | |
76418e04 | 1728 | if (current_class_ptr) |
1729 | TREE_USED (current_class_ptr) = 1; | |
37009aa5 | 1730 | if (processing_template_decl && !qualifying_scope) |
0a3b29ad | 1731 | { |
26d880e6 | 1732 | tree type = TREE_TYPE (decl); |
0a3b29ad | 1733 | |
26d880e6 | 1734 | if (TREE_CODE (type) == REFERENCE_TYPE) |
9cd0fcd1 | 1735 | /* Quals on the object don't matter. */; |
6dcf5c5f | 1736 | else if (PACK_EXPANSION_P (type)) |
1737 | /* Don't bother trying to represent this. */ | |
1738 | type = NULL_TREE; | |
26d880e6 | 1739 | else |
1740 | { | |
331bc0ad | 1741 | /* Set the cv qualifiers. */ |
f153f053 | 1742 | int quals = cp_type_quals (TREE_TYPE (object)); |
9031d10b | 1743 | |
26d880e6 | 1744 | if (DECL_MUTABLE_P (decl)) |
1745 | quals &= ~TYPE_QUAL_CONST; | |
03aa2b89 | 1746 | |
26d880e6 | 1747 | quals |= cp_type_quals (TREE_TYPE (decl)); |
1748 | type = cp_build_qualified_type (type, quals); | |
1749 | } | |
9031d10b | 1750 | |
9cd0fcd1 | 1751 | return (convert_from_reference |
1752 | (build_min (COMPONENT_REF, type, object, decl, NULL_TREE))); | |
26d880e6 | 1753 | } |
a55b2063 | 1754 | /* If PROCESSING_TEMPLATE_DECL is nonzero here, then |
1755 | QUALIFYING_SCOPE is also non-null. Wrap this in a SCOPE_REF | |
1756 | for now. */ | |
1757 | else if (processing_template_decl) | |
1758 | return build_qualified_name (TREE_TYPE (decl), | |
1759 | qualifying_scope, | |
a59543d9 | 1760 | decl, |
a55b2063 | 1761 | /*template_p=*/false); |
26d880e6 | 1762 | else |
1763 | { | |
1764 | tree access_type = TREE_TYPE (object); | |
5fd824ed | 1765 | |
579bb663 | 1766 | perform_or_defer_access_check (TYPE_BINFO (access_type), decl, |
eb833cbe | 1767 | decl, tf_warning_or_error); |
0a3b29ad | 1768 | |
1769 | /* If the data member was named `C::M', convert `*this' to `C' | |
1770 | first. */ | |
1771 | if (qualifying_scope) | |
1772 | { | |
1773 | tree binfo = NULL_TREE; | |
1774 | object = build_scoped_ref (object, qualifying_scope, | |
1775 | &binfo); | |
1776 | } | |
1777 | ||
1778 | return build_class_member_access_expr (object, decl, | |
1779 | /*access_path=*/NULL_TREE, | |
ebd21de4 | 1780 | /*preserve_reference=*/false, |
1781 | tf_warning_or_error); | |
0a3b29ad | 1782 | } |
1783 | } | |
1784 | ||
b08c3803 | 1785 | /* If we are currently parsing a template and we encountered a typedef |
1786 | TYPEDEF_DECL that is being accessed though CONTEXT, this function | |
1787 | adds the typedef to a list tied to the current template. | |
3817a00d | 1788 | At template instantiation time, that list is walked and access check |
b08c3803 | 1789 | performed for each typedef. |
1790 | LOCATION is the location of the usage point of TYPEDEF_DECL. */ | |
1791 | ||
1792 | void | |
1793 | add_typedef_to_current_template_for_access_check (tree typedef_decl, | |
1794 | tree context, | |
1795 | location_t location) | |
1796 | { | |
1797 | tree template_info = NULL; | |
1798 | tree cs = current_scope (); | |
1799 | ||
1800 | if (!is_typedef_decl (typedef_decl) | |
1801 | || !context | |
1802 | || !CLASS_TYPE_P (context) | |
1803 | || !cs) | |
1804 | return; | |
1805 | ||
1806 | if (CLASS_TYPE_P (cs) || TREE_CODE (cs) == FUNCTION_DECL) | |
1807 | template_info = get_template_info (cs); | |
1808 | ||
1809 | if (template_info | |
1810 | && TI_TEMPLATE (template_info) | |
1811 | && !currently_open_class (context)) | |
1812 | append_type_to_template_for_access_check (cs, typedef_decl, | |
1813 | context, location); | |
1814 | } | |
1815 | ||
ef4534a3 | 1816 | /* DECL was the declaration to which a qualified-id resolved. Issue |
1817 | an error message if it is not accessible. If OBJECT_TYPE is | |
1818 | non-NULL, we have just seen `x->' or `x.' and OBJECT_TYPE is the | |
1819 | type of `*x', or `x', respectively. If the DECL was named as | |
1820 | `A::B' then NESTED_NAME_SPECIFIER is `A'. */ | |
1821 | ||
1822 | void | |
9031d10b | 1823 | check_accessibility_of_qualified_id (tree decl, |
1824 | tree object_type, | |
ef4534a3 | 1825 | tree nested_name_specifier) |
1826 | { | |
1827 | tree scope; | |
1828 | tree qualifying_type = NULL_TREE; | |
3cb98335 | 1829 | |
41771881 | 1830 | /* If we are parsing a template declaration and if decl is a typedef, |
1831 | add it to a list tied to the template. | |
1832 | At template instantiation time, that list will be walked and | |
1833 | access check performed. */ | |
b08c3803 | 1834 | add_typedef_to_current_template_for_access_check (decl, |
1835 | nested_name_specifier | |
1836 | ? nested_name_specifier | |
1837 | : DECL_CONTEXT (decl), | |
1838 | input_location); | |
41771881 | 1839 | |
4a44ba29 | 1840 | /* If we're not checking, return immediately. */ |
3cb98335 | 1841 | if (deferred_access_no_check) |
1842 | return; | |
9031d10b | 1843 | |
ef4534a3 | 1844 | /* Determine the SCOPE of DECL. */ |
1845 | scope = context_for_name_lookup (decl); | |
1846 | /* If the SCOPE is not a type, then DECL is not a member. */ | |
1847 | if (!TYPE_P (scope)) | |
1848 | return; | |
1849 | /* Compute the scope through which DECL is being accessed. */ | |
9031d10b | 1850 | if (object_type |
ef4534a3 | 1851 | /* OBJECT_TYPE might not be a class type; consider: |
1852 | ||
1853 | class A { typedef int I; }; | |
1854 | I *p; | |
1855 | p->A::I::~I(); | |
1856 | ||
653e5405 | 1857 | In this case, we will have "A::I" as the DECL, but "I" as the |
ef4534a3 | 1858 | OBJECT_TYPE. */ |
1859 | && CLASS_TYPE_P (object_type) | |
1860 | && DERIVED_FROM_P (scope, object_type)) | |
1861 | /* If we are processing a `->' or `.' expression, use the type of the | |
1862 | left-hand side. */ | |
1863 | qualifying_type = object_type; | |
1864 | else if (nested_name_specifier) | |
1865 | { | |
1866 | /* If the reference is to a non-static member of the | |
1867 | current class, treat it as if it were referenced through | |
1868 | `this'. */ | |
8aa69b7b | 1869 | tree ct; |
ef4534a3 | 1870 | if (DECL_NONSTATIC_MEMBER_P (decl) |
1871 | && current_class_ptr | |
8aa69b7b | 1872 | && DERIVED_FROM_P (scope, ct = current_nonlambda_class_type ())) |
1873 | qualifying_type = ct; | |
ef4534a3 | 1874 | /* Otherwise, use the type indicated by the |
1875 | nested-name-specifier. */ | |
1876 | else | |
1877 | qualifying_type = nested_name_specifier; | |
1878 | } | |
1879 | else | |
1880 | /* Otherwise, the name must be from the current class or one of | |
1881 | its bases. */ | |
1882 | qualifying_type = currently_open_derived_class (scope); | |
1883 | ||
62740469 | 1884 | if (qualifying_type |
1885 | /* It is possible for qualifying type to be a TEMPLATE_TYPE_PARM | |
1886 | or similar in a default argument value. */ | |
1887 | && CLASS_TYPE_P (qualifying_type) | |
1888 | && !dependent_type_p (qualifying_type)) | |
579bb663 | 1889 | perform_or_defer_access_check (TYPE_BINFO (qualifying_type), decl, |
eb833cbe | 1890 | decl, tf_warning_or_error); |
ef4534a3 | 1891 | } |
1892 | ||
1893 | /* EXPR is the result of a qualified-id. The QUALIFYING_CLASS was the | |
1894 | class named to the left of the "::" operator. DONE is true if this | |
1895 | expression is a complete postfix-expression; it is false if this | |
1896 | expression is followed by '->', '[', '(', etc. ADDRESS_P is true | |
fbb01da7 | 1897 | iff this expression is the operand of '&'. TEMPLATE_P is true iff |
1898 | the qualified-id was of the form "A::template B". TEMPLATE_ARG_P | |
1899 | is true iff this qualified name appears as a template argument. */ | |
ef4534a3 | 1900 | |
1901 | tree | |
074ab442 | 1902 | finish_qualified_id_expr (tree qualifying_class, |
1903 | tree expr, | |
fbb01da7 | 1904 | bool done, |
074ab442 | 1905 | bool address_p, |
fbb01da7 | 1906 | bool template_p, |
20ce13a9 | 1907 | bool template_arg_p, |
1908 | tsubst_flags_t complain) | |
ef4534a3 | 1909 | { |
528638c9 | 1910 | gcc_assert (TYPE_P (qualifying_class)); |
1911 | ||
2be3e2ee | 1912 | if (error_operand_p (expr)) |
1913 | return error_mark_node; | |
1914 | ||
7442ab85 | 1915 | if ((DECL_P (expr) || BASELINK_P (expr)) |
1916 | && !mark_used (expr, complain)) | |
1917 | return error_mark_node; | |
528638c9 | 1918 | |
fbb01da7 | 1919 | if (template_p) |
1920 | check_template_keyword (expr); | |
1921 | ||
ef4534a3 | 1922 | /* If EXPR occurs as the operand of '&', use special handling that |
1923 | permits a pointer-to-member. */ | |
1924 | if (address_p && done) | |
1925 | { | |
1926 | if (TREE_CODE (expr) == SCOPE_REF) | |
1927 | expr = TREE_OPERAND (expr, 1); | |
9031d10b | 1928 | expr = build_offset_ref (qualifying_class, expr, |
20ce13a9 | 1929 | /*address_p=*/true, complain); |
ef4534a3 | 1930 | return expr; |
1931 | } | |
1932 | ||
e8f9fda1 | 1933 | /* No need to check access within an enum. */ |
1934 | if (TREE_CODE (qualifying_class) == ENUMERAL_TYPE) | |
1935 | return expr; | |
1936 | ||
fbb01da7 | 1937 | /* Within the scope of a class, turn references to non-static |
1938 | members into expression of the form "this->...". */ | |
1939 | if (template_arg_p) | |
1940 | /* But, within a template argument, we do not want make the | |
1941 | transformation, as there is no "this" pointer. */ | |
1942 | ; | |
1943 | else if (TREE_CODE (expr) == FIELD_DECL) | |
352aca0e | 1944 | { |
1945 | push_deferring_access_checks (dk_no_check); | |
70269a57 | 1946 | expr = finish_non_static_data_member (expr, NULL_TREE, |
352aca0e | 1947 | qualifying_class); |
1948 | pop_deferring_access_checks (); | |
1949 | } | |
ef4534a3 | 1950 | else if (BASELINK_P (expr) && !processing_template_decl) |
1951 | { | |
ef4534a3 | 1952 | /* See if any of the functions are non-static members. */ |
eac53a7c | 1953 | /* If so, the expression may be relative to 'this'. */ |
1f07118e | 1954 | if (!shared_member_p (expr) |
d9cca713 | 1955 | && current_class_ptr |
1956 | && DERIVED_FROM_P (qualifying_class, | |
1957 | current_nonlambda_class_type ())) | |
9031d10b | 1958 | expr = (build_class_member_access_expr |
d9cca713 | 1959 | (maybe_dummy_object (qualifying_class, NULL), |
ef4534a3 | 1960 | expr, |
1961 | BASELINK_ACCESS_BINFO (expr), | |
ebd21de4 | 1962 | /*preserve_reference=*/false, |
20ce13a9 | 1963 | complain)); |
ef4534a3 | 1964 | else if (done) |
1bc16cab | 1965 | /* The expression is a qualified name whose address is not |
1966 | being taken. */ | |
20ce13a9 | 1967 | expr = build_offset_ref (qualifying_class, expr, /*address_p=*/false, |
1968 | complain); | |
ef4534a3 | 1969 | } |
d0b4bf06 | 1970 | else if (BASELINK_P (expr)) |
1971 | ; | |
1972 | else | |
1973 | { | |
d0b4bf06 | 1974 | /* In a template, return a SCOPE_REF for most qualified-ids |
1975 | so that we can check access at instantiation time. But if | |
1976 | we're looking at a member of the current instantiation, we | |
1977 | know we have access and building up the SCOPE_REF confuses | |
1978 | non-type template argument handling. */ | |
1979 | if (processing_template_decl | |
1980 | && !currently_open_class (qualifying_class)) | |
1981 | expr = build_qualified_name (TREE_TYPE (expr), | |
1982 | qualifying_class, expr, | |
1983 | template_p); | |
dbea931d | 1984 | |
1985 | expr = convert_from_reference (expr); | |
d0b4bf06 | 1986 | } |
ef4534a3 | 1987 | |
1988 | return expr; | |
1989 | } | |
1990 | ||
615d03b4 | 1991 | /* Begin a statement-expression. The value returned must be passed to |
1992 | finish_stmt_expr. */ | |
01b3f071 | 1993 | |
9031d10b | 1994 | tree |
807be5b4 | 1995 | begin_stmt_expr (void) |
01b3f071 | 1996 | { |
2363ef00 | 1997 | return push_stmt_list (); |
8036397f | 1998 | } |
1999 | ||
942ab15b | 2000 | /* Process the final expression of a statement expression. EXPR can be |
d6534f57 | 2001 | NULL, if the final expression is empty. Return a STATEMENT_LIST |
2002 | containing all the statements in the statement-expression, or | |
2003 | ERROR_MARK_NODE if there was an error. */ | |
942ab15b | 2004 | |
2005 | tree | |
2363ef00 | 2006 | finish_stmt_expr_expr (tree expr, tree stmt_expr) |
942ab15b | 2007 | { |
41dbd8dc | 2008 | if (error_operand_p (expr)) |
4100761f | 2009 | { |
2010 | /* The type of the statement-expression is the type of the last | |
2011 | expression. */ | |
2012 | TREE_TYPE (stmt_expr) = error_mark_node; | |
2013 | return error_mark_node; | |
2014 | } | |
9031d10b | 2015 | |
d6534f57 | 2016 | /* If the last statement does not have "void" type, then the value |
074ab442 | 2017 | of the last statement is the value of the entire expression. */ |
942ab15b | 2018 | if (expr) |
2019 | { | |
c3d09d4d | 2020 | tree type = TREE_TYPE (expr); |
2021 | ||
2022 | if (processing_template_decl) | |
2023 | { | |
e60a6f7b | 2024 | expr = build_stmt (input_location, EXPR_STMT, expr); |
c3d09d4d | 2025 | expr = add_stmt (expr); |
2026 | /* Mark the last statement so that we can recognize it as such at | |
2027 | template-instantiation time. */ | |
2028 | EXPR_STMT_STMT_EXPR_RESULT (expr) = 1; | |
2029 | } | |
2030 | else if (VOID_TYPE_P (type)) | |
942ab15b | 2031 | { |
c3d09d4d | 2032 | /* Just treat this like an ordinary statement. */ |
2033 | expr = finish_expr_stmt (expr); | |
2034 | } | |
2035 | else | |
2036 | { | |
2037 | /* It actually has a value we need to deal with. First, force it | |
2038 | to be an rvalue so that we won't need to build up a copy | |
2039 | constructor call later when we try to assign it to something. */ | |
9e505437 | 2040 | expr = force_rvalue (expr, tf_warning_or_error); |
d6534f57 | 2041 | if (error_operand_p (expr)) |
2042 | return error_mark_node; | |
c3d09d4d | 2043 | |
2044 | /* Update for array-to-pointer decay. */ | |
bbdcc797 | 2045 | type = TREE_TYPE (expr); |
c3d09d4d | 2046 | |
2047 | /* Wrap it in a CLEANUP_POINT_EXPR and add it to the list like a | |
2048 | normal statement, but don't convert to void or actually add | |
2049 | the EXPR_STMT. */ | |
2050 | if (TREE_CODE (expr) != CLEANUP_POINT_EXPR) | |
2051 | expr = maybe_cleanup_point_expr (expr); | |
2052 | add_stmt (expr); | |
d6534f57 | 2053 | } |
c3d09d4d | 2054 | |
d6534f57 | 2055 | /* The type of the statement-expression is the type of the last |
2056 | expression. */ | |
2057 | TREE_TYPE (stmt_expr) = type; | |
942ab15b | 2058 | } |
9031d10b | 2059 | |
d6534f57 | 2060 | return stmt_expr; |
942ab15b | 2061 | } |
2062 | ||
face0cb7 | 2063 | /* Finish a statement-expression. EXPR should be the value returned |
2064 | by the previous begin_stmt_expr. Returns an expression | |
2065 | representing the statement-expression. */ | |
01b3f071 | 2066 | |
9031d10b | 2067 | tree |
2363ef00 | 2068 | finish_stmt_expr (tree stmt_expr, bool has_no_scope) |
01b3f071 | 2069 | { |
d6534f57 | 2070 | tree type; |
2071 | tree result; | |
2363ef00 | 2072 | |
d6534f57 | 2073 | if (error_operand_p (stmt_expr)) |
96f59d23 | 2074 | { |
2075 | pop_stmt_list (stmt_expr); | |
2076 | return error_mark_node; | |
2077 | } | |
2363ef00 | 2078 | |
d6534f57 | 2079 | gcc_assert (TREE_CODE (stmt_expr) == STATEMENT_LIST); |
2363ef00 | 2080 | |
d6534f57 | 2081 | type = TREE_TYPE (stmt_expr); |
2082 | result = pop_stmt_list (stmt_expr); | |
c3d09d4d | 2083 | TREE_TYPE (result) = type; |
76a24869 | 2084 | |
942ab15b | 2085 | if (processing_template_decl) |
2363ef00 | 2086 | { |
2087 | result = build_min (STMT_EXPR, type, result); | |
2088 | TREE_SIDE_EFFECTS (result) = 1; | |
2089 | STMT_EXPR_NO_SCOPE (result) = has_no_scope; | |
2090 | } | |
c3d09d4d | 2091 | else if (CLASS_TYPE_P (type)) |
942ab15b | 2092 | { |
c3d09d4d | 2093 | /* Wrap the statement-expression in a TARGET_EXPR so that the |
2094 | temporary object created by the final expression is destroyed at | |
2095 | the end of the full-expression containing the | |
2096 | statement-expression. */ | |
9e505437 | 2097 | result = force_target_expr (type, result, tf_warning_or_error); |
942ab15b | 2098 | } |
2363ef00 | 2099 | |
01b3f071 | 2100 | return result; |
2101 | } | |
2102 | ||
ffc6c453 | 2103 | /* Returns the expression which provides the value of STMT_EXPR. */ |
2104 | ||
2105 | tree | |
2106 | stmt_expr_value_expr (tree stmt_expr) | |
2107 | { | |
2108 | tree t = STMT_EXPR_STMT (stmt_expr); | |
2109 | ||
2110 | if (TREE_CODE (t) == BIND_EXPR) | |
2111 | t = BIND_EXPR_BODY (t); | |
2112 | ||
e377c26a | 2113 | if (TREE_CODE (t) == STATEMENT_LIST && STATEMENT_LIST_TAIL (t)) |
ffc6c453 | 2114 | t = STATEMENT_LIST_TAIL (t)->stmt; |
2115 | ||
2116 | if (TREE_CODE (t) == EXPR_STMT) | |
2117 | t = EXPR_STMT_EXPR (t); | |
2118 | ||
2119 | return t; | |
2120 | } | |
2121 | ||
d9655b31 | 2122 | /* Return TRUE iff EXPR_STMT is an empty list of |
2123 | expression statements. */ | |
2124 | ||
2125 | bool | |
2126 | empty_expr_stmt_p (tree expr_stmt) | |
2127 | { | |
2128 | tree body = NULL_TREE; | |
2129 | ||
3ab4693e | 2130 | if (expr_stmt == void_node) |
7a86e244 | 2131 | return true; |
2132 | ||
d9655b31 | 2133 | if (expr_stmt) |
2134 | { | |
2135 | if (TREE_CODE (expr_stmt) == EXPR_STMT) | |
2136 | body = EXPR_STMT_EXPR (expr_stmt); | |
2137 | else if (TREE_CODE (expr_stmt) == STATEMENT_LIST) | |
2138 | body = expr_stmt; | |
2139 | } | |
2140 | ||
7a86e244 | 2141 | if (body) |
2142 | { | |
2143 | if (TREE_CODE (body) == STATEMENT_LIST) | |
2144 | return tsi_end_p (tsi_start (body)); | |
2145 | else | |
2146 | return empty_expr_stmt_p (body); | |
2147 | } | |
d9655b31 | 2148 | return false; |
2149 | } | |
2150 | ||
0886adbc | 2151 | /* Perform Koenig lookup. FN is the postfix-expression representing |
b1ea83f4 | 2152 | the function (or functions) to call; ARGS are the arguments to the |
4a7973e1 | 2153 | call. Returns the functions to be considered by overload resolution. */ |
0886adbc | 2154 | |
2155 | tree | |
4a7973e1 | 2156 | perform_koenig_lookup (tree fn, vec<tree, va_gc> *args, |
8411500a | 2157 | tsubst_flags_t complain) |
0886adbc | 2158 | { |
2159 | tree identifier = NULL_TREE; | |
2160 | tree functions = NULL_TREE; | |
32f71e4f | 2161 | tree tmpl_args = NULL_TREE; |
d69c0c73 | 2162 | bool template_id = false; |
32f71e4f | 2163 | |
2164 | if (TREE_CODE (fn) == TEMPLATE_ID_EXPR) | |
2165 | { | |
d69c0c73 | 2166 | /* Use a separate flag to handle null args. */ |
2167 | template_id = true; | |
32f71e4f | 2168 | tmpl_args = TREE_OPERAND (fn, 1); |
2169 | fn = TREE_OPERAND (fn, 0); | |
2170 | } | |
0886adbc | 2171 | |
2172 | /* Find the name of the overloaded function. */ | |
694683bb | 2173 | if (identifier_p (fn)) |
0886adbc | 2174 | identifier = fn; |
2175 | else if (is_overloaded_fn (fn)) | |
2176 | { | |
2177 | functions = fn; | |
2178 | identifier = DECL_NAME (get_first_fn (functions)); | |
2179 | } | |
2180 | else if (DECL_P (fn)) | |
2181 | { | |
2182 | functions = fn; | |
2183 | identifier = DECL_NAME (fn); | |
2184 | } | |
2185 | ||
2186 | /* A call to a namespace-scope function using an unqualified name. | |
2187 | ||
2188 | Do Koenig lookup -- unless any of the arguments are | |
2189 | type-dependent. */ | |
32f71e4f | 2190 | if (!any_type_dependent_arguments_p (args) |
2191 | && !any_dependent_template_arguments_p (tmpl_args)) | |
0886adbc | 2192 | { |
4a7973e1 | 2193 | fn = lookup_arg_dependent (identifier, functions, args); |
0886adbc | 2194 | if (!fn) |
8411500a | 2195 | { |
2196 | /* The unqualified name could not be resolved. */ | |
2197 | if (complain) | |
2198 | fn = unqualified_fn_lookup_error (identifier); | |
2199 | else | |
2200 | fn = identifier; | |
2201 | } | |
0886adbc | 2202 | } |
0886adbc | 2203 | |
d69c0c73 | 2204 | if (fn && template_id) |
2205 | fn = build2 (TEMPLATE_ID_EXPR, unknown_type_node, fn, tmpl_args); | |
32f71e4f | 2206 | |
0886adbc | 2207 | return fn; |
2208 | } | |
2209 | ||
f352a3fb | 2210 | /* Generate an expression for `FN (ARGS)'. This may change the |
2211 | contents of ARGS. | |
f70cb9e6 | 2212 | |
2213 | If DISALLOW_VIRTUAL is true, the call to FN will be not generated | |
2214 | as a virtual call, even if FN is virtual. (This flag is set when | |
2215 | encountering an expression where the function name is explicitly | |
2216 | qualified. For example a call to `X::f' never generates a virtual | |
2217 | call.) | |
2218 | ||
2219 | Returns code for the call. */ | |
01b3f071 | 2220 | |
9031d10b | 2221 | tree |
f1f41a6c | 2222 | finish_call_expr (tree fn, vec<tree, va_gc> **args, bool disallow_virtual, |
f352a3fb | 2223 | bool koenig_p, tsubst_flags_t complain) |
01b3f071 | 2224 | { |
13795292 | 2225 | tree result; |
2226 | tree orig_fn; | |
f1f41a6c | 2227 | vec<tree, va_gc> *orig_args = NULL; |
13795292 | 2228 | |
f352a3fb | 2229 | if (fn == error_mark_node) |
f70cb9e6 | 2230 | return error_mark_node; |
2231 | ||
1b8d97ae | 2232 | gcc_assert (!TYPE_P (fn)); |
8257afbc | 2233 | |
13795292 | 2234 | orig_fn = fn; |
13795292 | 2235 | |
2236 | if (processing_template_decl) | |
2237 | { | |
daf9237f | 2238 | /* If the call expression is dependent, build a CALL_EXPR node |
2239 | with no type; type_dependent_expression_p recognizes | |
2240 | expressions with no type as being dependent. */ | |
13795292 | 2241 | if (type_dependent_expression_p (fn) |
daf9237f | 2242 | || any_type_dependent_arguments_p (*args) |
51e6e22c | 2243 | /* For a non-static member function that doesn't have an |
2244 | explicit object argument, we need to specifically | |
daf9237f | 2245 | test the type dependency of the "this" pointer because it |
2246 | is not included in *ARGS even though it is considered to | |
2247 | be part of the list of arguments. Note that this is | |
2248 | related to CWG issues 515 and 1005. */ | |
51e6e22c | 2249 | || (TREE_CODE (fn) != COMPONENT_REF |
2250 | && non_static_member_function_p (fn) | |
daf9237f | 2251 | && current_class_ref |
2252 | && type_dependent_expression_p (current_class_ref))) | |
cbce34a5 | 2253 | { |
f352a3fb | 2254 | result = build_nt_call_vec (fn, *args); |
3df42822 | 2255 | SET_EXPR_LOCATION (result, EXPR_LOC_OR_LOC (fn, input_location)); |
ba026663 | 2256 | KOENIG_LOOKUP_P (result) = koenig_p; |
2889212c | 2257 | if (cfun) |
2258 | { | |
2259 | do | |
2260 | { | |
2261 | tree fndecl = OVL_CURRENT (fn); | |
2262 | if (TREE_CODE (fndecl) != FUNCTION_DECL | |
2263 | || !TREE_THIS_VOLATILE (fndecl)) | |
2264 | break; | |
2265 | fn = OVL_NEXT (fn); | |
2266 | } | |
2267 | while (fn); | |
2268 | if (!fn) | |
2269 | current_function_returns_abnormally = 1; | |
2270 | } | |
cbce34a5 | 2271 | return result; |
2272 | } | |
f352a3fb | 2273 | orig_args = make_tree_vector_copy (*args); |
13795292 | 2274 | if (!BASELINK_P (fn) |
2275 | && TREE_CODE (fn) != PSEUDO_DTOR_EXPR | |
2276 | && TREE_TYPE (fn) != unknown_type_node) | |
2277 | fn = build_non_dependent_expr (fn); | |
f352a3fb | 2278 | make_args_non_dependent (*args); |
13795292 | 2279 | } |
2280 | ||
4e81a9f3 | 2281 | if (TREE_CODE (fn) == COMPONENT_REF) |
2282 | { | |
2283 | tree member = TREE_OPERAND (fn, 1); | |
2284 | if (BASELINK_P (member)) | |
2285 | { | |
2286 | tree object = TREE_OPERAND (fn, 0); | |
2287 | return build_new_method_call (object, member, | |
2288 | args, NULL_TREE, | |
2289 | (disallow_virtual | |
2290 | ? LOOKUP_NORMAL | LOOKUP_NONVIRTUAL | |
2291 | : LOOKUP_NORMAL), | |
2292 | /*fn_p=*/NULL, | |
2293 | complain); | |
2294 | } | |
2295 | } | |
2296 | ||
d6097162 | 2297 | /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'. */ |
2298 | if (TREE_CODE (fn) == ADDR_EXPR | |
2299 | && TREE_CODE (TREE_OPERAND (fn, 0)) == OVERLOAD) | |
2300 | fn = TREE_OPERAND (fn, 0); | |
2301 | ||
0e5cde0c | 2302 | if (is_overloaded_fn (fn)) |
2303 | fn = baselink_for_fns (fn); | |
0a3b29ad | 2304 | |
13795292 | 2305 | result = NULL_TREE; |
f70cb9e6 | 2306 | if (BASELINK_P (fn)) |
83a31b40 | 2307 | { |
f70cb9e6 | 2308 | tree object; |
2309 | ||
2310 | /* A call to a member function. From [over.call.func]: | |
2311 | ||
2312 | If the keyword this is in scope and refers to the class of | |
2313 | that member function, or a derived class thereof, then the | |
2314 | function call is transformed into a qualified function call | |
2315 | using (*this) as the postfix-expression to the left of the | |
2316 | . operator.... [Otherwise] a contrived object of type T | |
9031d10b | 2317 | becomes the implied object argument. |
f70cb9e6 | 2318 | |
f7659496 | 2319 | In this situation: |
f70cb9e6 | 2320 | |
2321 | struct A { void f(); }; | |
2322 | struct B : public A {}; | |
2323 | struct C : public A { void g() { B::f(); }}; | |
2324 | ||
f7659496 | 2325 | "the class of that member function" refers to `A'. But 11.2 |
2326 | [class.access.base] says that we need to convert 'this' to B* as | |
2327 | part of the access, so we pass 'B' to maybe_dummy_object. */ | |
01b3f071 | 2328 | |
f7659496 | 2329 | object = maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)), |
2330 | NULL); | |
01b3f071 | 2331 | |
13795292 | 2332 | if (processing_template_decl) |
2333 | { | |
2334 | if (type_dependent_expression_p (object)) | |
f352a3fb | 2335 | { |
2336 | tree ret = build_nt_call_vec (orig_fn, orig_args); | |
2337 | release_tree_vector (orig_args); | |
2338 | return ret; | |
2339 | } | |
13795292 | 2340 | object = build_non_dependent_expr (object); |
2341 | } | |
2342 | ||
2343 | result = build_new_method_call (object, fn, args, NULL_TREE, | |
9031d10b | 2344 | (disallow_virtual |
884a66e4 | 2345 | ? LOOKUP_NORMAL|LOOKUP_NONVIRTUAL |
2346 | : LOOKUP_NORMAL), | |
ebd21de4 | 2347 | /*fn_p=*/NULL, |
2348 | complain); | |
f70cb9e6 | 2349 | } |
2350 | else if (is_overloaded_fn (fn)) | |
87daa93b | 2351 | { |
2352 | /* If the function is an overloaded builtin, resolve it. */ | |
2353 | if (TREE_CODE (fn) == FUNCTION_DECL | |
65441f6f | 2354 | && (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL |
2355 | || DECL_BUILT_IN_CLASS (fn) == BUILT_IN_MD)) | |
e60a6f7b | 2356 | result = resolve_overloaded_builtin (input_location, fn, *args); |
87daa93b | 2357 | |
2358 | if (!result) | |
121296ee | 2359 | { |
2360 | if (warn_sizeof_pointer_memaccess | |
b6a74ba4 | 2361 | && (complain & tf_warning) |
f1f41a6c | 2362 | && !vec_safe_is_empty (*args) |
121296ee | 2363 | && !processing_template_decl) |
2364 | { | |
57f872a2 | 2365 | location_t sizeof_arg_loc[3]; |
2366 | tree sizeof_arg[3]; | |
2367 | unsigned int i; | |
2368 | for (i = 0; i < 3; i++) | |
2369 | { | |
2370 | tree t; | |
2371 | ||
2372 | sizeof_arg_loc[i] = UNKNOWN_LOCATION; | |
2373 | sizeof_arg[i] = NULL_TREE; | |
f1f41a6c | 2374 | if (i >= (*args)->length ()) |
57f872a2 | 2375 | continue; |
f1f41a6c | 2376 | t = (**args)[i]; |
57f872a2 | 2377 | if (TREE_CODE (t) != SIZEOF_EXPR) |
2378 | continue; | |
2379 | if (SIZEOF_EXPR_TYPE_P (t)) | |
2380 | sizeof_arg[i] = TREE_TYPE (TREE_OPERAND (t, 0)); | |
2381 | else | |
2382 | sizeof_arg[i] = TREE_OPERAND (t, 0); | |
2383 | sizeof_arg_loc[i] = EXPR_LOCATION (t); | |
2384 | } | |
121296ee | 2385 | sizeof_pointer_memaccess_warning |
57f872a2 | 2386 | (sizeof_arg_loc, fn, *args, |
121296ee | 2387 | sizeof_arg, same_type_ignoring_top_level_qualifiers_p); |
2388 | } | |
2389 | ||
2390 | /* A call to a namespace-scope function. */ | |
2391 | result = build_new_function_call (fn, args, koenig_p, complain); | |
2392 | } | |
87daa93b | 2393 | } |
0a3b29ad | 2394 | else if (TREE_CODE (fn) == PSEUDO_DTOR_EXPR) |
2395 | { | |
f1f41a6c | 2396 | if (!vec_safe_is_empty (*args)) |
0a3b29ad | 2397 | error ("arguments to destructor are not allowed"); |
2398 | /* Mark the pseudo-destructor call as having side-effects so | |
2399 | that we do not issue warnings about its use. */ | |
2400 | result = build1 (NOP_EXPR, | |
2401 | void_type_node, | |
2402 | TREE_OPERAND (fn, 0)); | |
2403 | TREE_SIDE_EFFECTS (result) = 1; | |
0a3b29ad | 2404 | } |
f70cb9e6 | 2405 | else if (CLASS_TYPE_P (TREE_TYPE (fn))) |
13795292 | 2406 | /* If the "function" is really an object of class type, it might |
2407 | have an overloaded `operator ()'. */ | |
f352a3fb | 2408 | result = build_op_call (fn, args, complain); |
87daa93b | 2409 | |
13795292 | 2410 | if (!result) |
2411 | /* A call where the function is unknown. */ | |
f352a3fb | 2412 | result = cp_build_function_call_vec (fn, args, complain); |
f70cb9e6 | 2413 | |
f5126e46 | 2414 | if (processing_template_decl && result != error_mark_node) |
cbce34a5 | 2415 | { |
86ccc124 | 2416 | if (INDIRECT_REF_P (result)) |
f5126e46 | 2417 | result = TREE_OPERAND (result, 0); |
f352a3fb | 2418 | result = build_call_vec (TREE_TYPE (result), orig_fn, orig_args); |
330f36dc | 2419 | SET_EXPR_LOCATION (result, input_location); |
ba026663 | 2420 | KOENIG_LOOKUP_P (result) = koenig_p; |
f352a3fb | 2421 | release_tree_vector (orig_args); |
f5126e46 | 2422 | result = convert_from_reference (result); |
cbce34a5 | 2423 | } |
f352a3fb | 2424 | |
b75fa3a6 | 2425 | if (koenig_p) |
2426 | { | |
2427 | /* Free garbage OVERLOADs from arg-dependent lookup. */ | |
2428 | tree next = NULL_TREE; | |
2429 | for (fn = orig_fn; | |
2430 | fn && TREE_CODE (fn) == OVERLOAD && OVL_ARG_DEPENDENT (fn); | |
2431 | fn = next) | |
2432 | { | |
2433 | if (processing_template_decl) | |
2434 | /* In a template, we'll re-use them at instantiation time. */ | |
2435 | OVL_ARG_DEPENDENT (fn) = false; | |
2436 | else | |
2437 | { | |
2438 | next = OVL_CHAIN (fn); | |
2439 | ggc_free (fn); | |
2440 | } | |
2441 | } | |
2442 | } | |
2443 | ||
13795292 | 2444 | return result; |
01b3f071 | 2445 | } |
2446 | ||
2447 | /* Finish a call to a postfix increment or decrement or EXPR. (Which | |
2448 | is indicated by CODE, which should be POSTINCREMENT_EXPR or | |
2449 | POSTDECREMENT_EXPR.) */ | |
2450 | ||
9031d10b | 2451 | tree |
807be5b4 | 2452 | finish_increment_expr (tree expr, enum tree_code code) |
01b3f071 | 2453 | { |
ef0b0c72 | 2454 | return build_x_unary_op (input_location, code, expr, tf_warning_or_error); |
01b3f071 | 2455 | } |
2456 | ||
2457 | /* Finish a use of `this'. Returns an expression for `this'. */ | |
2458 | ||
9031d10b | 2459 | tree |
807be5b4 | 2460 | finish_this_expr (void) |
01b3f071 | 2461 | { |
ed7bf2d1 | 2462 | tree result = NULL_TREE; |
01b3f071 | 2463 | |
43936711 | 2464 | if (current_class_ptr) |
2465 | { | |
2466 | tree type = TREE_TYPE (current_class_ref); | |
2467 | ||
2468 | /* In a lambda expression, 'this' refers to the captured 'this'. */ | |
2469 | if (LAMBDA_TYPE_P (type)) | |
f1ec53b6 | 2470 | result = lambda_expr_this_capture (CLASSTYPE_LAMBDA_EXPR (type), true); |
43936711 | 2471 | else |
2472 | result = current_class_ptr; | |
43936711 | 2473 | } |
01b3f071 | 2474 | |
ed7bf2d1 | 2475 | if (result) |
2476 | /* The keyword 'this' is a prvalue expression. */ | |
2477 | return rvalue (result); | |
8d8b140c | 2478 | |
ed7bf2d1 | 2479 | tree fn = current_nonlambda_function (); |
2480 | if (fn && DECL_STATIC_FUNCTION_P (fn)) | |
2481 | error ("%<this%> is unavailable for static member functions"); | |
2482 | else if (fn) | |
2483 | error ("invalid use of %<this%> in non-member function"); | |
2484 | else | |
2485 | error ("invalid use of %<this%> at top level"); | |
2486 | return error_mark_node; | |
01b3f071 | 2487 | } |
2488 | ||
0a3b29ad | 2489 | /* Finish a pseudo-destructor expression. If SCOPE is NULL, the |
2490 | expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is | |
2491 | the TYPE for the type given. If SCOPE is non-NULL, the expression | |
2492 | was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */ | |
01b3f071 | 2493 | |
9031d10b | 2494 | tree |
1e482cf7 | 2495 | finish_pseudo_destructor_expr (tree object, tree scope, tree destructor, |
2496 | location_t loc) | |
01b3f071 | 2497 | { |
a355acc3 | 2498 | if (object == error_mark_node || destructor == error_mark_node) |
0a3b29ad | 2499 | return error_mark_node; |
8318ad7a | 2500 | |
b4df430b | 2501 | gcc_assert (TYPE_P (destructor)); |
01b3f071 | 2502 | |
0a3b29ad | 2503 | if (!processing_template_decl) |
2504 | { | |
2505 | if (scope == error_mark_node) | |
2506 | { | |
1e482cf7 | 2507 | error_at (loc, "invalid qualifying scope in pseudo-destructor name"); |
0a3b29ad | 2508 | return error_mark_node; |
2509 | } | |
d800169d | 2510 | if (is_auto (destructor)) |
2511 | destructor = TREE_TYPE (object); | |
d05f521d | 2512 | if (scope && TYPE_P (scope) && !check_dtor_name (scope, destructor)) |
2513 | { | |
1e482cf7 | 2514 | error_at (loc, |
2515 | "qualified type %qT does not match destructor name ~%qT", | |
2516 | scope, destructor); | |
d05f521d | 2517 | return error_mark_node; |
2518 | } | |
2519 | ||
9031d10b | 2520 | |
d45cef9b | 2521 | /* [expr.pseudo] says both: |
2522 | ||
653e5405 | 2523 | The type designated by the pseudo-destructor-name shall be |
d45cef9b | 2524 | the same as the object type. |
2525 | ||
653e5405 | 2526 | and: |
d45cef9b | 2527 | |
653e5405 | 2528 | The cv-unqualified versions of the object type and of the |
d45cef9b | 2529 | type designated by the pseudo-destructor-name shall be the |
2530 | same type. | |
2531 | ||
653e5405 | 2532 | We implement the more generous second sentence, since that is |
2533 | what most other compilers do. */ | |
9031d10b | 2534 | if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object), |
d45cef9b | 2535 | destructor)) |
0a3b29ad | 2536 | { |
1e482cf7 | 2537 | error_at (loc, "%qE is not of type %qT", object, destructor); |
0a3b29ad | 2538 | return error_mark_node; |
2539 | } | |
2540 | } | |
01b3f071 | 2541 | |
1e482cf7 | 2542 | return build3_loc (loc, PSEUDO_DTOR_EXPR, void_type_node, object, |
2543 | scope, destructor); | |
01b3f071 | 2544 | } |
2545 | ||
d8bbef5c | 2546 | /* Finish an expression of the form CODE EXPR. */ |
2547 | ||
2548 | tree | |
60427596 | 2549 | finish_unary_op_expr (location_t loc, enum tree_code code, tree expr, |
2550 | tsubst_flags_t complain) | |
d8bbef5c | 2551 | { |
60427596 | 2552 | tree result = build_x_unary_op (loc, code, expr, complain); |
2553 | if ((complain & tf_warning) | |
2554 | && TREE_OVERFLOW_P (result) && !TREE_OVERFLOW_P (expr)) | |
e60a6f7b | 2555 | overflow_warning (input_location, result); |
f170d67f | 2556 | |
d8bbef5c | 2557 | return result; |
2558 | } | |
2559 | ||
0a3b29ad | 2560 | /* Finish a compound-literal expression. TYPE is the type to which |
f82f1250 | 2561 | the CONSTRUCTOR in COMPOUND_LITERAL is being cast. */ |
0a3b29ad | 2562 | |
2563 | tree | |
95034afb | 2564 | finish_compound_literal (tree type, tree compound_literal, |
2565 | tsubst_flags_t complain) | |
0a3b29ad | 2566 | { |
cc88e3b2 | 2567 | if (type == error_mark_node) |
2568 | return error_mark_node; | |
2569 | ||
604fac7f | 2570 | if (TREE_CODE (type) == REFERENCE_TYPE) |
2571 | { | |
2572 | compound_literal | |
2573 | = finish_compound_literal (TREE_TYPE (type), compound_literal, | |
2574 | complain); | |
2575 | return cp_build_c_cast (type, compound_literal, complain); | |
2576 | } | |
2577 | ||
ac4d57eb | 2578 | if (!TYPE_OBJ_P (type)) |
2579 | { | |
95034afb | 2580 | if (complain & tf_error) |
2581 | error ("compound literal of non-object type %qT", type); | |
ac4d57eb | 2582 | return error_mark_node; |
2583 | } | |
2584 | ||
0a3b29ad | 2585 | if (processing_template_decl) |
0a3b29ad | 2586 | { |
788f3e3e | 2587 | TREE_TYPE (compound_literal) = type; |
2588 | /* Mark the expression as a compound literal. */ | |
2589 | TREE_HAS_CONSTRUCTOR (compound_literal) = 1; | |
2590 | return compound_literal; | |
0a3b29ad | 2591 | } |
2592 | ||
23e81e2e | 2593 | type = complete_type (type); |
f82f1250 | 2594 | |
2595 | if (TYPE_NON_AGGREGATE_CLASS (type)) | |
2596 | { | |
2597 | /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST | |
2598 | everywhere that deals with function arguments would be a pain, so | |
2599 | just wrap it in a TREE_LIST. The parser set a flag so we know | |
2600 | that it came from T{} rather than T({}). */ | |
2601 | CONSTRUCTOR_IS_DIRECT_INIT (compound_literal) = 1; | |
2602 | compound_literal = build_tree_list (NULL_TREE, compound_literal); | |
95034afb | 2603 | return build_functional_cast (type, compound_literal, complain); |
f82f1250 | 2604 | } |
2605 | ||
bc7a08da | 2606 | if (TREE_CODE (type) == ARRAY_TYPE |
2607 | && check_array_initializer (NULL_TREE, type, compound_literal)) | |
2608 | return error_mark_node; | |
b52bd4ae | 2609 | compound_literal = reshape_init (type, compound_literal, complain); |
7e783eb3 | 2610 | if (SCALAR_TYPE_P (type) |
af8f1e3f | 2611 | && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal) |
718affe2 | 2612 | && !check_narrowing (type, compound_literal, complain)) |
2613 | return error_mark_node; | |
2e8bc2ba | 2614 | if (TREE_CODE (type) == ARRAY_TYPE |
2615 | && TYPE_DOMAIN (type) == NULL_TREE) | |
2616 | { | |
2617 | cp_complete_array_type_or_error (&type, compound_literal, | |
2618 | false, complain); | |
2619 | if (type == error_mark_node) | |
2620 | return error_mark_node; | |
2621 | } | |
b52bd4ae | 2622 | compound_literal = digest_init (type, compound_literal, complain); |
b3d801b4 | 2623 | if (TREE_CODE (compound_literal) == CONSTRUCTOR) |
2624 | TREE_HAS_CONSTRUCTOR (compound_literal) = true; | |
4f662622 | 2625 | /* Put static/constant array temporaries in static variables, but always |
2626 | represent class temporaries with TARGET_EXPR so we elide copies. */ | |
2627 | if ((!at_function_scope_p () || CP_TYPE_CONST_P (type)) | |
2628 | && TREE_CODE (type) == ARRAY_TYPE | |
3035a6c8 | 2629 | && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type) |
4f662622 | 2630 | && initializer_constant_valid_p (compound_literal, type)) |
2631 | { | |
2632 | tree decl = create_temporary_var (type); | |
2633 | DECL_INITIAL (decl) = compound_literal; | |
2634 | TREE_STATIC (decl) = 1; | |
2635 | if (literal_type_p (type) && CP_TYPE_CONST_NON_VOLATILE_P (type)) | |
2636 | { | |
2637 | /* 5.19 says that a constant expression can include an | |
2638 | lvalue-rvalue conversion applied to "a glvalue of literal type | |
2639 | that refers to a non-volatile temporary object initialized | |
2640 | with a constant expression". Rather than try to communicate | |
2641 | that this VAR_DECL is a temporary, just mark it constexpr. */ | |
2642 | DECL_DECLARED_CONSTEXPR_P (decl) = true; | |
2643 | DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true; | |
2644 | TREE_CONSTANT (decl) = true; | |
2645 | } | |
2646 | cp_apply_type_quals_to_decl (cp_type_quals (type), decl); | |
2647 | decl = pushdecl_top_level (decl); | |
2648 | DECL_NAME (decl) = make_anon_name (); | |
2649 | SET_DECL_ASSEMBLER_NAME (decl, DECL_NAME (decl)); | |
575852de | 2650 | /* Make sure the destructor is callable. */ |
2651 | tree clean = cxx_maybe_build_cleanup (decl, complain); | |
2652 | if (clean == error_mark_node) | |
2653 | return error_mark_node; | |
4f662622 | 2654 | return decl; |
2655 | } | |
2656 | else | |
9e505437 | 2657 | return get_target_expr_sfinae (compound_literal, complain); |
0a3b29ad | 2658 | } |
2659 | ||
334ec926 | 2660 | /* Return the declaration for the function-name variable indicated by |
2661 | ID. */ | |
2662 | ||
2663 | tree | |
2664 | finish_fname (tree id) | |
2665 | { | |
2666 | tree decl; | |
9031d10b | 2667 | |
e3b80d49 | 2668 | decl = fname_decl (input_location, C_RID_CODE (id), id); |
591f4417 | 2669 | if (processing_template_decl && current_function_decl |
2670 | && decl != error_mark_node) | |
c08d51be | 2671 | decl = DECL_NAME (decl); |
334ec926 | 2672 | return decl; |
2673 | } | |
2674 | ||
ce2a6403 | 2675 | /* Finish a translation unit. */ |
d8bbef5c | 2676 | |
9031d10b | 2677 | void |
807be5b4 | 2678 | finish_translation_unit (void) |
d8bbef5c | 2679 | { |
2680 | /* In case there were missing closebraces, | |
2681 | get us back to the global binding level. */ | |
656a7ba0 | 2682 | pop_everything (); |
d8bbef5c | 2683 | while (current_namespace != global_namespace) |
2684 | pop_namespace (); | |
65b7f83f | 2685 | |
47cd6605 | 2686 | /* Do file scope __FUNCTION__ et al. */ |
65b7f83f | 2687 | finish_fname_decls (); |
d8bbef5c | 2688 | } |
2689 | ||
01b3f071 | 2690 | /* Finish a template type parameter, specified as AGGR IDENTIFIER. |
2691 | Returns the parameter. */ | |
2692 | ||
9031d10b | 2693 | tree |
807be5b4 | 2694 | finish_template_type_parm (tree aggr, tree identifier) |
01b3f071 | 2695 | { |
771665d8 | 2696 | if (aggr != class_type_node) |
01b3f071 | 2697 | { |
2b9e3597 | 2698 | permerror (input_location, "template type parameters must use the keyword %<class%> or %<typename%>"); |
01b3f071 | 2699 | aggr = class_type_node; |
2700 | } | |
2701 | ||
2702 | return build_tree_list (aggr, identifier); | |
2703 | } | |
2704 | ||
2705 | /* Finish a template template parameter, specified as AGGR IDENTIFIER. | |
2706 | Returns the parameter. */ | |
2707 | ||
9031d10b | 2708 | tree |
807be5b4 | 2709 | finish_template_template_parm (tree aggr, tree identifier) |
01b3f071 | 2710 | { |
e60a6f7b | 2711 | tree decl = build_decl (input_location, |
2712 | TYPE_DECL, identifier, NULL_TREE); | |
01b3f071 | 2713 | tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE); |
2714 | DECL_TEMPLATE_PARMS (tmpl) = current_template_parms; | |
2715 | DECL_TEMPLATE_RESULT (tmpl) = decl; | |
ecdd3d84 | 2716 | DECL_ARTIFICIAL (decl) = 1; |
01b3f071 | 2717 | end_template_decl (); |
2718 | ||
b4df430b | 2719 | gcc_assert (DECL_TEMPLATE_PARMS (tmpl)); |
88eba637 | 2720 | |
faab44d2 | 2721 | check_default_tmpl_args (decl, DECL_TEMPLATE_PARMS (tmpl), |
2722 | /*is_primary=*/true, /*is_partial=*/false, | |
2723 | /*is_friend=*/0); | |
2724 | ||
01b3f071 | 2725 | return finish_template_type_parm (aggr, tmpl); |
2726 | } | |
d8bbef5c | 2727 | |
4c487414 | 2728 | /* ARGUMENT is the default-argument value for a template template |
2729 | parameter. If ARGUMENT is invalid, issue error messages and return | |
2730 | the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */ | |
2731 | ||
2732 | tree | |
2733 | check_template_template_default_arg (tree argument) | |
2734 | { | |
2735 | if (TREE_CODE (argument) != TEMPLATE_DECL | |
2736 | && TREE_CODE (argument) != TEMPLATE_TEMPLATE_PARM | |
4c487414 | 2737 | && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE) |
2738 | { | |
eae805b4 | 2739 | if (TREE_CODE (argument) == TYPE_DECL) |
d312e151 | 2740 | error ("invalid use of type %qT as a default value for a template " |
2741 | "template-parameter", TREE_TYPE (argument)); | |
eae805b4 | 2742 | else |
2743 | error ("invalid default argument for a template template parameter"); | |
4c487414 | 2744 | return error_mark_node; |
2745 | } | |
2746 | ||
2747 | return argument; | |
2748 | } | |
2749 | ||
d8bbef5c | 2750 | /* Begin a class definition, as indicated by T. */ |
2751 | ||
2752 | tree | |
6935b87a | 2753 | begin_class_definition (tree t) |
d8bbef5c | 2754 | { |
5623f36d | 2755 | if (error_operand_p (t) || error_operand_p (TYPE_MAIN_DECL (t))) |
6cd31fa5 | 2756 | return error_mark_node; |
2757 | ||
df9d14a6 | 2758 | if (processing_template_parmlist) |
2759 | { | |
03d6ca9e | 2760 | error ("definition of %q#T inside template parameter list", t); |
df9d14a6 | 2761 | return error_mark_node; |
2762 | } | |
8df5a43d | 2763 | |
2764 | /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733 | |
2765 | are passed the same as decimal scalar types. */ | |
f71a3189 | 2766 | if (TREE_CODE (t) == RECORD_TYPE |
2767 | && !processing_template_decl) | |
8df5a43d | 2768 | { |
f71a3189 | 2769 | tree ns = TYPE_CONTEXT (t); |
2770 | if (ns && TREE_CODE (ns) == NAMESPACE_DECL | |
2771 | && DECL_CONTEXT (ns) == std_node | |
1bd1e44f | 2772 | && DECL_NAME (ns) |
f71a3189 | 2773 | && !strcmp (IDENTIFIER_POINTER (DECL_NAME (ns)), "decimal")) |
2774 | { | |
2775 | const char *n = TYPE_NAME_STRING (t); | |
2776 | if ((strcmp (n, "decimal32") == 0) | |
2777 | || (strcmp (n, "decimal64") == 0) | |
2778 | || (strcmp (n, "decimal128") == 0)) | |
2779 | TYPE_TRANSPARENT_AGGR (t) = 1; | |
2780 | } | |
8df5a43d | 2781 | } |
2782 | ||
bf2bb055 | 2783 | /* A non-implicit typename comes from code like: |
2784 | ||
2785 | template <typename T> struct A { | |
653e5405 | 2786 | template <typename U> struct A<T>::B ... |
bf2bb055 | 2787 | |
2788 | This is erroneous. */ | |
2789 | else if (TREE_CODE (t) == TYPENAME_TYPE) | |
2790 | { | |
03d6ca9e | 2791 | error ("invalid definition of qualified type %qT", t); |
bf2bb055 | 2792 | t = error_mark_node; |
2793 | } | |
2794 | ||
95397ff9 | 2795 | if (t == error_mark_node || ! MAYBE_CLASS_TYPE_P (t)) |
d8bbef5c | 2796 | { |
95397ff9 | 2797 | t = make_class_type (RECORD_TYPE); |
3f3fa556 | 2798 | pushtag (make_anon_name (), t, /*tag_scope=*/ts_current); |
d8bbef5c | 2799 | } |
eae9825c | 2800 | |
fb868a5d | 2801 | if (TYPE_BEING_DEFINED (t)) |
d8bbef5c | 2802 | { |
95397ff9 | 2803 | t = make_class_type (TREE_CODE (t)); |
3f3fa556 | 2804 | pushtag (TYPE_IDENTIFIER (t), t, /*tag_scope=*/ts_current); |
d8bbef5c | 2805 | } |
f646a0ac | 2806 | maybe_process_partial_specialization (t); |
f815eb0f | 2807 | pushclass (t); |
d8bbef5c | 2808 | TYPE_BEING_DEFINED (t) = 1; |
265a34f4 | 2809 | class_binding_level->defining_class_p = 1; |
4a2849cb | 2810 | |
1940f978 | 2811 | if (flag_pack_struct) |
2812 | { | |
2813 | tree v; | |
2814 | TYPE_PACKED (t) = 1; | |
2815 | /* Even though the type is being defined for the first time | |
2816 | here, there might have been a forward declaration, so there | |
2817 | might be cv-qualified variants of T. */ | |
2818 | for (v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v)) | |
2819 | TYPE_PACKED (v) = 1; | |
2820 | } | |
d8bbef5c | 2821 | /* Reset the interface data, at the earliest possible |
2822 | moment, as it might have been set via a class foo; | |
2823 | before. */ | |
83c4eacf | 2824 | if (! TYPE_ANONYMOUS_P (t)) |
2825 | { | |
3df42822 | 2826 | struct c_fileinfo *finfo = \ |
2827 | get_fileinfo (LOCATION_FILE (input_location)); | |
62bf98ad | 2828 | CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only; |
83c4eacf | 2829 | SET_CLASSTYPE_INTERFACE_UNKNOWN_X |
62bf98ad | 2830 | (t, finfo->interface_unknown); |
83c4eacf | 2831 | } |
d8bbef5c | 2832 | reset_specialization(); |
9031d10b | 2833 | |
d70cc5b5 | 2834 | /* Make a declaration for this class in its own scope. */ |
2835 | build_self_reference (); | |
2836 | ||
eae9825c | 2837 | return t; |
d8bbef5c | 2838 | } |
2839 | ||
0f2952a1 | 2840 | /* Finish the member declaration given by DECL. */ |
2841 | ||
2842 | void | |
807be5b4 | 2843 | finish_member_declaration (tree decl) |
0f2952a1 | 2844 | { |
2845 | if (decl == error_mark_node || decl == NULL_TREE) | |
2846 | return; | |
2847 | ||
2848 | if (decl == void_type_node) | |
2849 | /* The COMPONENT was a friend, not a member, and so there's | |
2850 | nothing for us to do. */ | |
2851 | return; | |
2852 | ||
2853 | /* We should see only one DECL at a time. */ | |
1767a056 | 2854 | gcc_assert (DECL_CHAIN (decl) == NULL_TREE); |
0f2952a1 | 2855 | |
2856 | /* Set up access control for DECL. */ | |
9031d10b | 2857 | TREE_PRIVATE (decl) |
0f2952a1 | 2858 | = (current_access_specifier == access_private_node); |
9031d10b | 2859 | TREE_PROTECTED (decl) |
0f2952a1 | 2860 | = (current_access_specifier == access_protected_node); |
2861 | if (TREE_CODE (decl) == TEMPLATE_DECL) | |
2862 | { | |
b8e0d419 | 2863 | TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl); |
2864 | TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl); | |
0f2952a1 | 2865 | } |
2866 | ||
c28ddc97 | 2867 | /* Mark the DECL as a member of the current class, unless it's |
2868 | a member of an enumeration. */ | |
2869 | if (TREE_CODE (decl) != CONST_DECL) | |
2870 | DECL_CONTEXT (decl) = current_class_type; | |
0f2952a1 | 2871 | |
a4f66688 | 2872 | /* Check for bare parameter packs in the member variable declaration. */ |
4eaf1b43 | 2873 | if (TREE_CODE (decl) == FIELD_DECL) |
613687b1 | 2874 | { |
830a6615 | 2875 | if (check_for_bare_parameter_packs (TREE_TYPE (decl))) |
613687b1 | 2876 | TREE_TYPE (decl) = error_mark_node; |
830a6615 | 2877 | if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl))) |
613687b1 | 2878 | DECL_ATTRIBUTES (decl) = NULL_TREE; |
2879 | } | |
a4f66688 | 2880 | |
f0edcca6 | 2881 | /* [dcl.link] |
2882 | ||
2883 | A C language linkage is ignored for the names of class members | |
2884 | and the member function type of class member functions. */ | |
2885 | if (DECL_LANG_SPECIFIC (decl) && DECL_LANGUAGE (decl) == lang_c) | |
4b1984f5 | 2886 | SET_DECL_LANGUAGE (decl, lang_cplusplus); |
f0edcca6 | 2887 | |
0f2952a1 | 2888 | /* Put functions on the TYPE_METHODS list and everything else on the |
2889 | TYPE_FIELDS list. Note that these are built up in reverse order. | |
2890 | We reverse them (to obtain declaration order) in finish_struct. */ | |
398c50e2 | 2891 | if (DECL_DECLARES_FUNCTION_P (decl)) |
0f2952a1 | 2892 | { |
2893 | /* We also need to add this function to the | |
2894 | CLASSTYPE_METHOD_VEC. */ | |
e36e7923 | 2895 | if (add_method (current_class_type, decl, NULL_TREE)) |
2896 | { | |
041558e3 | 2897 | gcc_assert (TYPE_MAIN_VARIANT (current_class_type) == current_class_type); |
1767a056 | 2898 | DECL_CHAIN (decl) = TYPE_METHODS (current_class_type); |
e36e7923 | 2899 | TYPE_METHODS (current_class_type) = decl; |
ca1c7bb3 | 2900 | |
e36e7923 | 2901 | maybe_add_class_template_decl_list (current_class_type, decl, |
2902 | /*friend_p=*/0); | |
2903 | } | |
0f2952a1 | 2904 | } |
3d1f8279 | 2905 | /* Enter the DECL into the scope of the class, if the class |
2906 | isn't a closure (whose fields are supposed to be unnamed). */ | |
2907 | else if (CLASSTYPE_LAMBDA_EXPR (current_class_type) | |
2908 | || pushdecl_class_level (decl)) | |
0f2952a1 | 2909 | { |
807f85cf | 2910 | if (TREE_CODE (decl) == USING_DECL) |
2911 | { | |
807f85cf | 2912 | /* For now, ignore class-scope USING_DECLS, so that |
2913 | debugging backends do not see them. */ | |
2914 | DECL_IGNORED_P (decl) = 1; | |
2915 | } | |
2916 | ||
0f2952a1 | 2917 | /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields |
2918 | go at the beginning. The reason is that lookup_field_1 | |
2919 | searches the list in order, and we want a field name to | |
2920 | override a type name so that the "struct stat hack" will | |
2921 | work. In particular: | |
2922 | ||
2923 | struct S { enum E { }; int E } s; | |
2924 | s.E = 3; | |
2925 | ||
6c0cc2cd | 2926 | is valid. In addition, the FIELD_DECLs must be maintained in |
0f2952a1 | 2927 | declaration order so that class layout works as expected. |
2928 | However, we don't need that order until class layout, so we | |
2929 | save a little time by putting FIELD_DECLs on in reverse order | |
2930 | here, and then reversing them in finish_struct_1. (We could | |
2931 | also keep a pointer to the correct insertion points in the | |
2932 | list.) */ | |
2933 | ||
2934 | if (TREE_CODE (decl) == TYPE_DECL) | |
9031d10b | 2935 | TYPE_FIELDS (current_class_type) |
0f2952a1 | 2936 | = chainon (TYPE_FIELDS (current_class_type), decl); |
2937 | else | |
2938 | { | |
1767a056 | 2939 | DECL_CHAIN (decl) = TYPE_FIELDS (current_class_type); |
0f2952a1 | 2940 | TYPE_FIELDS (current_class_type) = decl; |
2941 | } | |
1eaf178d | 2942 | |
9031d10b | 2943 | maybe_add_class_template_decl_list (current_class_type, decl, |
ca1c7bb3 | 2944 | /*friend_p=*/0); |
0f2952a1 | 2945 | } |
b11ef6ee | 2946 | |
2947 | if (pch_file) | |
2948 | note_decl_for_pch (decl); | |
2949 | } | |
2950 | ||
2951 | /* DECL has been declared while we are building a PCH file. Perform | |
2952 | actions that we might normally undertake lazily, but which can be | |
2953 | performed now so that they do not have to be performed in | |
2954 | translation units which include the PCH file. */ | |
2955 | ||
2956 | void | |
2957 | note_decl_for_pch (tree decl) | |
2958 | { | |
2959 | gcc_assert (pch_file); | |
2960 | ||
b11ef6ee | 2961 | /* There's a good chance that we'll have to mangle names at some |
2962 | point, even if only for emission in debugging information. */ | |
4cace8cb | 2963 | if (VAR_OR_FUNCTION_DECL_P (decl) |
ec689dc3 | 2964 | && !processing_template_decl) |
b11ef6ee | 2965 | mangle_decl (decl); |
0f2952a1 | 2966 | } |
2967 | ||
aa977dcc | 2968 | /* Finish processing a complete template declaration. The PARMS are |
34197853 | 2969 | the template parameters. */ |
2970 | ||
2971 | void | |
807be5b4 | 2972 | finish_template_decl (tree parms) |
34197853 | 2973 | { |
2974 | if (parms) | |
2975 | end_template_decl (); | |
2976 | else | |
2977 | end_specialization (); | |
2978 | } | |
2979 | ||
9abe66a7 | 2980 | /* Finish processing a template-id (which names a type) of the form |
34197853 | 2981 | NAME < ARGS >. Return the TYPE_DECL for the type named by the |
3160db1d | 2982 | template-id. If ENTERING_SCOPE is nonzero we are about to enter |
34197853 | 2983 | the scope of template-id indicated. */ |
2984 | ||
2985 | tree | |
807be5b4 | 2986 | finish_template_type (tree name, tree args, int entering_scope) |
34197853 | 2987 | { |
370478b1 | 2988 | tree type; |
34197853 | 2989 | |
370478b1 | 2990 | type = lookup_template_class (name, args, |
b992fe70 | 2991 | NULL_TREE, NULL_TREE, entering_scope, |
0fbca5e8 | 2992 | tf_warning_or_error | tf_user); |
370478b1 | 2993 | if (type == error_mark_node) |
2994 | return type; | |
2995 | else if (CLASS_TYPE_P (type) && !alias_type_or_template_p (type)) | |
2996 | return TYPE_STUB_DECL (type); | |
2997 | else | |
2998 | return TYPE_NAME (type); | |
34197853 | 2999 | } |
343a4a9c | 3000 | |
69f578cd | 3001 | /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER. |
3002 | Return a TREE_LIST containing the ACCESS_SPECIFIER and the | |
3003 | BASE_CLASS, or NULL_TREE if an error occurred. The | |
4109ca29 | 3004 | ACCESS_SPECIFIER is one of |
57c28194 | 3005 | access_{default,public,protected_private}_node. For a virtual base |
3006 | we set TREE_TYPE. */ | |
69f578cd | 3007 | |
9031d10b | 3008 | tree |
95f3173a | 3009 | finish_base_specifier (tree base, tree access, bool virtual_p) |
69f578cd | 3010 | { |
69f578cd | 3011 | tree result; |
3012 | ||
95f3173a | 3013 | if (base == error_mark_node) |
ca62cc3f | 3014 | { |
3015 | error ("invalid base-class specification"); | |
3016 | result = NULL_TREE; | |
3017 | } | |
95397ff9 | 3018 | else if (! MAYBE_CLASS_TYPE_P (base)) |
3019 | { | |
3020 | error ("%qT is not a class type", base); | |
3021 | result = NULL_TREE; | |
3022 | } | |
69f578cd | 3023 | else |
46a79a8f | 3024 | { |
95f3173a | 3025 | if (cp_type_quals (base) != 0) |
653e5405 | 3026 | { |
e966d1b8 | 3027 | /* DR 484: Can a base-specifier name a cv-qualified |
3028 | class type? */ | |
653e5405 | 3029 | base = TYPE_MAIN_VARIANT (base); |
3030 | } | |
95f3173a | 3031 | result = build_tree_list (access, base); |
57c28194 | 3032 | if (virtual_p) |
3033 | TREE_TYPE (result) = integer_type_node; | |
46a79a8f | 3034 | } |
69f578cd | 3035 | |
3036 | return result; | |
3037 | } | |
0f2952a1 | 3038 | |
0e5cde0c | 3039 | /* If FNS is a member function, a set of member functions, or a |
3040 | template-id referring to one or more member functions, return a | |
3041 | BASELINK for FNS, incorporating the current access context. | |
3042 | Otherwise, return FNS unchanged. */ | |
3043 | ||
3044 | tree | |
3045 | baselink_for_fns (tree fns) | |
3046 | { | |
47744737 | 3047 | tree scope; |
0e5cde0c | 3048 | tree cl; |
3049 | ||
3050 | if (BASELINK_P (fns) | |
0e5cde0c | 3051 | || error_operand_p (fns)) |
3052 | return fns; | |
47744737 | 3053 | |
3054 | scope = ovl_scope (fns); | |
3055 | if (!CLASS_TYPE_P (scope)) | |
0e5cde0c | 3056 | return fns; |
3057 | ||
47744737 | 3058 | cl = currently_open_derived_class (scope); |
0e5cde0c | 3059 | if (!cl) |
47744737 | 3060 | cl = scope; |
0e5cde0c | 3061 | cl = TYPE_BINFO (cl); |
f302e37a | 3062 | return build_baselink (cl, cl, fns, /*optype=*/NULL_TREE); |
0e5cde0c | 3063 | } |
3064 | ||
46d5a169 | 3065 | /* Returns true iff DECL is a variable from a function outside |
a8b75081 | 3066 | the current one. */ |
3067 | ||
3068 | static bool | |
46d5a169 | 3069 | outer_var_p (tree decl) |
a8b75081 | 3070 | { |
80a58eb0 | 3071 | return ((VAR_P (decl) || TREE_CODE (decl) == PARM_DECL) |
a8b75081 | 3072 | && DECL_FUNCTION_SCOPE_P (decl) |
7c99bd48 | 3073 | && (DECL_CONTEXT (decl) != current_function_decl |
3074 | || parsing_nsdmi ())); | |
a8b75081 | 3075 | } |
3076 | ||
46d5a169 | 3077 | /* As above, but also checks that DECL is automatic. */ |
3078 | ||
4bfc9037 | 3079 | bool |
46d5a169 | 3080 | outer_automatic_var_p (tree decl) |
3081 | { | |
3082 | return (outer_var_p (decl) | |
3083 | && !TREE_STATIC (decl)); | |
3084 | } | |
3085 | ||
4bfc9037 | 3086 | /* DECL satisfies outer_automatic_var_p. Possibly complain about it or |
3087 | rewrite it for lambda capture. */ | |
3088 | ||
3089 | tree | |
3090 | process_outer_var_ref (tree decl, tsubst_flags_t complain) | |
3091 | { | |
3092 | if (cp_unevaluated_operand) | |
3093 | /* It's not a use (3.2) if we're in an unevaluated context. */ | |
3094 | return decl; | |
3d1c3406 | 3095 | if (decl == error_mark_node) |
3096 | return decl; | |
4bfc9037 | 3097 | |
3098 | tree context = DECL_CONTEXT (decl); | |
3099 | tree containing_function = current_function_decl; | |
3100 | tree lambda_stack = NULL_TREE; | |
3101 | tree lambda_expr = NULL_TREE; | |
3102 | tree initializer = convert_from_reference (decl); | |
3103 | ||
3104 | /* Mark it as used now even if the use is ill-formed. */ | |
4430f688 | 3105 | if (!mark_used (decl, complain) && !(complain & tf_error)) |
3106 | return error_mark_node; | |
4bfc9037 | 3107 | |
3108 | /* Core issue 696: "[At the July 2009 meeting] the CWG expressed | |
3109 | support for an approach in which a reference to a local | |
3110 | [constant] automatic variable in a nested class or lambda body | |
3111 | would enter the expression as an rvalue, which would reduce | |
3112 | the complexity of the problem" | |
3113 | ||
3114 | FIXME update for final resolution of core issue 696. */ | |
3115 | if (decl_maybe_constant_var_p (decl)) | |
3116 | { | |
3117 | if (processing_template_decl) | |
3118 | /* In a template, the constant value may not be in a usable | |
3119 | form, so wait until instantiation time. */ | |
3120 | return decl; | |
3121 | else if (decl_constant_var_p (decl)) | |
64d82fbc | 3122 | { |
3123 | tree t = maybe_constant_value (convert_from_reference (decl)); | |
3124 | if (TREE_CONSTANT (t)) | |
3125 | return t; | |
3126 | } | |
4bfc9037 | 3127 | } |
3128 | ||
3129 | if (parsing_nsdmi ()) | |
3130 | containing_function = NULL_TREE; | |
3131 | else | |
3132 | /* If we are in a lambda function, we can move out until we hit | |
3133 | 1. the context, | |
3134 | 2. a non-lambda function, or | |
3135 | 3. a non-default capturing lambda function. */ | |
3136 | while (context != containing_function | |
3137 | && LAMBDA_FUNCTION_P (containing_function)) | |
3138 | { | |
f5ba54d8 | 3139 | tree closure = DECL_CONTEXT (containing_function); |
3140 | lambda_expr = CLASSTYPE_LAMBDA_EXPR (closure); | |
3141 | ||
3142 | if (TYPE_CLASS_SCOPE_P (closure)) | |
3143 | /* A lambda in an NSDMI (c++/64496). */ | |
3144 | break; | |
4bfc9037 | 3145 | |
3146 | if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) | |
3147 | == CPLD_NONE) | |
3148 | break; | |
3149 | ||
3150 | lambda_stack = tree_cons (NULL_TREE, | |
3151 | lambda_expr, | |
3152 | lambda_stack); | |
3153 | ||
3154 | containing_function | |
3155 | = decl_function_context (containing_function); | |
3156 | } | |
3157 | ||
f4ae4202 | 3158 | if (lambda_expr && VAR_P (decl) |
4bfc9037 | 3159 | && DECL_ANON_UNION_VAR_P (decl)) |
3160 | { | |
3161 | if (complain & tf_error) | |
3162 | error ("cannot capture member %qD of anonymous union", decl); | |
3163 | return error_mark_node; | |
3164 | } | |
3165 | if (context == containing_function) | |
3166 | { | |
3167 | decl = add_default_capture (lambda_stack, | |
3168 | /*id=*/DECL_NAME (decl), | |
3169 | initializer); | |
3170 | } | |
3171 | else if (lambda_expr) | |
3172 | { | |
3173 | if (complain & tf_error) | |
f5ba54d8 | 3174 | { |
3175 | error ("%qD is not captured", decl); | |
3176 | tree closure = LAMBDA_EXPR_CLOSURE (lambda_expr); | |
3177 | if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) | |
3178 | == CPLD_NONE) | |
3179 | inform (location_of (closure), | |
3180 | "the lambda has no capture-default"); | |
3181 | else if (TYPE_CLASS_SCOPE_P (closure)) | |
3182 | inform (0, "lambda in local class %q+T cannot " | |
3183 | "capture variables from the enclosing context", | |
3184 | TYPE_CONTEXT (closure)); | |
3185 | inform (input_location, "%q+#D declared here", decl); | |
3186 | } | |
4bfc9037 | 3187 | return error_mark_node; |
3188 | } | |
3189 | else | |
3190 | { | |
3191 | if (complain & tf_error) | |
3192 | error (VAR_P (decl) | |
3193 | ? G_("use of local variable with automatic storage from containing function") | |
3194 | : G_("use of parameter from containing function")); | |
3195 | inform (input_location, "%q+#D declared here", decl); | |
3196 | return error_mark_node; | |
3197 | } | |
3198 | return decl; | |
3199 | } | |
3200 | ||
0886adbc | 3201 | /* ID_EXPRESSION is a representation of parsed, but unprocessed, |
3202 | id-expression. (See cp_parser_id_expression for details.) SCOPE, | |
3203 | if non-NULL, is the type or namespace used to explicitly qualify | |
3204 | ID_EXPRESSION. DECL is the entity to which that name has been | |
9031d10b | 3205 | resolved. |
0886adbc | 3206 | |
3207 | *CONSTANT_EXPRESSION_P is true if we are presently parsing a | |
3208 | constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will | |
3209 | be set to true if this expression isn't permitted in a | |
3210 | constant-expression, but it is otherwise not set by this function. | |
3211 | *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a | |
3212 | constant-expression, but a non-constant expression is also | |
3213 | permissible. | |
3214 | ||
fbb01da7 | 3215 | DONE is true if this expression is a complete postfix-expression; |
3216 | it is false if this expression is followed by '->', '[', '(', etc. | |
3217 | ADDRESS_P is true iff this expression is the operand of '&'. | |
3218 | TEMPLATE_P is true iff the qualified-id was of the form | |
3219 | "A::template B". TEMPLATE_ARG_P is true iff this qualified name | |
3220 | appears as a template argument. | |
3221 | ||
0886adbc | 3222 | If an error occurs, and it is the kind of error that might cause |
3223 | the parser to abort a tentative parse, *ERROR_MSG is filled in. It | |
3224 | is the caller's responsibility to issue the message. *ERROR_MSG | |
3225 | will be a string with static storage duration, so the caller need | |
3226 | not "free" it. | |
3227 | ||
3228 | Return an expression for the entity, after issuing appropriate | |
3229 | diagnostics. This function is also responsible for transforming a | |
3230 | reference to a non-static member into a COMPONENT_REF that makes | |
9031d10b | 3231 | the use of "this" explicit. |
0886adbc | 3232 | |
3233 | Upon return, *IDK will be filled in appropriately. */ | |
0886adbc | 3234 | tree |
9031d10b | 3235 | finish_id_expression (tree id_expression, |
0886adbc | 3236 | tree decl, |
3237 | tree scope, | |
3238 | cp_id_kind *idk, | |
f47c1747 | 3239 | bool integral_constant_expression_p, |
3240 | bool allow_non_integral_constant_expression_p, | |
3241 | bool *non_integral_constant_expression_p, | |
fbb01da7 | 3242 | bool template_p, |
3243 | bool done, | |
3244 | bool address_p, | |
3245 | bool template_arg_p, | |
ad9ae192 | 3246 | const char **error_msg, |
3247 | location_t location) | |
0886adbc | 3248 | { |
8fc22c4b | 3249 | decl = strip_using_decl (decl); |
3250 | ||
0886adbc | 3251 | /* Initialize the output parameters. */ |
3252 | *idk = CP_ID_KIND_NONE; | |
3253 | *error_msg = NULL; | |
3254 | ||
3255 | if (id_expression == error_mark_node) | |
3256 | return error_mark_node; | |
3257 | /* If we have a template-id, then no further lookup is | |
3258 | required. If the template-id was for a template-class, we | |
3259 | will sometimes have a TYPE_DECL at this point. */ | |
3260 | else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR | |
c0b419db | 3261 | || TREE_CODE (decl) == TYPE_DECL) |
0886adbc | 3262 | ; |
3263 | /* Look up the name. */ | |
9031d10b | 3264 | else |
0886adbc | 3265 | { |
3266 | if (decl == error_mark_node) | |
3267 | { | |
3268 | /* Name lookup failed. */ | |
9031d10b | 3269 | if (scope |
3270 | && (!TYPE_P (scope) | |
7ef14399 | 3271 | || (!dependent_type_p (scope) |
694683bb | 3272 | && !(identifier_p (id_expression) |
7ef14399 | 3273 | && IDENTIFIER_TYPENAME_P (id_expression) |
3274 | && dependent_type_p (TREE_TYPE (id_expression)))))) | |
0886adbc | 3275 | { |
7ef14399 | 3276 | /* If the qualifying type is non-dependent (and the name |
3277 | does not name a conversion operator to a dependent | |
3278 | type), issue an error. */ | |
ad9ae192 | 3279 | qualified_name_lookup_error (scope, id_expression, decl, location); |
0886adbc | 3280 | return error_mark_node; |
3281 | } | |
3282 | else if (!scope) | |
3283 | { | |
3284 | /* It may be resolved via Koenig lookup. */ | |
3285 | *idk = CP_ID_KIND_UNQUALIFIED; | |
3286 | return id_expression; | |
3287 | } | |
7ef14399 | 3288 | else |
3289 | decl = id_expression; | |
0886adbc | 3290 | } |
3291 | /* If DECL is a variable that would be out of scope under | |
3292 | ANSI/ISO rules, but in scope in the ARM, name lookup | |
3293 | will succeed. Issue a diagnostic here. */ | |
3294 | else | |
3295 | decl = check_for_out_of_scope_variable (decl); | |
3296 | ||
3297 | /* Remember that the name was used in the definition of | |
3298 | the current class so that we can check later to see if | |
3299 | the meaning would have been different after the class | |
3300 | was entirely defined. */ | |
694683bb | 3301 | if (!scope && decl != error_mark_node && identifier_p (id_expression)) |
0886adbc | 3302 | maybe_note_name_used_in_class (id_expression, decl); |
f3d3cc67 | 3303 | |
a8b75081 | 3304 | /* Disallow uses of local variables from containing functions, except |
3305 | within lambda-expressions. */ | |
4bfc9037 | 3306 | if (outer_automatic_var_p (decl)) |
107f1bcc | 3307 | { |
3308 | decl = process_outer_var_ref (decl, tf_warning_or_error); | |
3309 | if (decl == error_mark_node) | |
3310 | return error_mark_node; | |
3311 | } | |
1c72f3b7 | 3312 | |
3313 | /* Also disallow uses of function parameters outside the function | |
3314 | body, except inside an unevaluated context (i.e. decltype). */ | |
3315 | if (TREE_CODE (decl) == PARM_DECL | |
3316 | && DECL_CONTEXT (decl) == NULL_TREE | |
3317 | && !cp_unevaluated_operand) | |
3318 | { | |
0e6d86f3 | 3319 | *error_msg = "use of parameter outside function body"; |
1c72f3b7 | 3320 | return error_mark_node; |
3321 | } | |
0886adbc | 3322 | } |
3323 | ||
3324 | /* If we didn't find anything, or what we found was a type, | |
3325 | then this wasn't really an id-expression. */ | |
3326 | if (TREE_CODE (decl) == TEMPLATE_DECL | |
3327 | && !DECL_FUNCTION_TEMPLATE_P (decl)) | |
3328 | { | |
3329 | *error_msg = "missing template arguments"; | |
3330 | return error_mark_node; | |
3331 | } | |
3332 | else if (TREE_CODE (decl) == TYPE_DECL | |
3333 | || TREE_CODE (decl) == NAMESPACE_DECL) | |
3334 | { | |
3335 | *error_msg = "expected primary-expression"; | |
3336 | return error_mark_node; | |
3337 | } | |
3338 | ||
3339 | /* If the name resolved to a template parameter, there is no | |
7fc97909 | 3340 | need to look it up again later. */ |
3341 | if ((TREE_CODE (decl) == CONST_DECL && DECL_TEMPLATE_PARM_P (decl)) | |
3342 | || TREE_CODE (decl) == TEMPLATE_PARM_INDEX) | |
0886adbc | 3343 | { |
729f89ff | 3344 | tree r; |
9031d10b | 3345 | |
0886adbc | 3346 | *idk = CP_ID_KIND_NONE; |
7fc97909 | 3347 | if (TREE_CODE (decl) == TEMPLATE_PARM_INDEX) |
3348 | decl = TEMPLATE_PARM_DECL (decl); | |
729f89ff | 3349 | r = convert_from_reference (DECL_INITIAL (decl)); |
9031d10b | 3350 | |
3351 | if (integral_constant_expression_p | |
4a072583 | 3352 | && !dependent_type_p (TREE_TYPE (decl)) |
729f89ff | 3353 | && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r)))) |
7fc97909 | 3354 | { |
f47c1747 | 3355 | if (!allow_non_integral_constant_expression_p) |
03d6ca9e | 3356 | error ("template parameter %qD of type %qT is not allowed in " |
7fc97909 | 3357 | "an integral constant expression because it is not of " |
3358 | "integral or enumeration type", decl, TREE_TYPE (decl)); | |
f47c1747 | 3359 | *non_integral_constant_expression_p = true; |
7fc97909 | 3360 | } |
729f89ff | 3361 | return r; |
7fc97909 | 3362 | } |
0886adbc | 3363 | else |
3364 | { | |
3365 | bool dependent_p; | |
3366 | ||
3367 | /* If the declaration was explicitly qualified indicate | |
3368 | that. The semantics of `A::f(3)' are different than | |
3369 | `f(3)' if `f' is virtual. */ | |
9031d10b | 3370 | *idk = (scope |
0886adbc | 3371 | ? CP_ID_KIND_QUALIFIED |
3372 | : (TREE_CODE (decl) == TEMPLATE_ID_EXPR | |
3373 | ? CP_ID_KIND_TEMPLATE_ID | |
3374 | : CP_ID_KIND_UNQUALIFIED)); | |
3375 | ||
3376 | ||
3377 | /* [temp.dep.expr] | |
3378 | ||
3379 | An id-expression is type-dependent if it contains an | |
3380 | identifier that was declared with a dependent type. | |
3381 | ||
0886adbc | 3382 | The standard is not very specific about an id-expression that |
3383 | names a set of overloaded functions. What if some of them | |
3384 | have dependent types and some of them do not? Presumably, | |
3385 | such a name should be treated as a dependent name. */ | |
3386 | /* Assume the name is not dependent. */ | |
3387 | dependent_p = false; | |
3388 | if (!processing_template_decl) | |
3389 | /* No names are dependent outside a template. */ | |
3390 | ; | |
c28ddc97 | 3391 | else if (TREE_CODE (decl) == CONST_DECL) |
3392 | /* We don't want to treat enumerators as dependent. */ | |
3393 | ; | |
0886adbc | 3394 | /* A template-id where the name of the template was not resolved |
3395 | is definitely dependent. */ | |
3396 | else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR | |
694683bb | 3397 | && (identifier_p (TREE_OPERAND (decl, 0)))) |
0886adbc | 3398 | dependent_p = true; |
3399 | /* For anything except an overloaded function, just check its | |
3400 | type. */ | |
3401 | else if (!is_overloaded_fn (decl)) | |
9031d10b | 3402 | dependent_p |
0886adbc | 3403 | = dependent_type_p (TREE_TYPE (decl)); |
3404 | /* For a set of overloaded functions, check each of the | |
3405 | functions. */ | |
3406 | else | |
3407 | { | |
3408 | tree fns = decl; | |
3409 | ||
3410 | if (BASELINK_P (fns)) | |
3411 | fns = BASELINK_FUNCTIONS (fns); | |
3412 | ||
3413 | /* For a template-id, check to see if the template | |
3414 | arguments are dependent. */ | |
3415 | if (TREE_CODE (fns) == TEMPLATE_ID_EXPR) | |
3416 | { | |
3417 | tree args = TREE_OPERAND (fns, 1); | |
3418 | dependent_p = any_dependent_template_arguments_p (args); | |
3419 | /* The functions are those referred to by the | |
3420 | template-id. */ | |
3421 | fns = TREE_OPERAND (fns, 0); | |
3422 | } | |
3423 | ||
3424 | /* If there are no dependent template arguments, go through | |
63eff20d | 3425 | the overloaded functions. */ |
0886adbc | 3426 | while (fns && !dependent_p) |
3427 | { | |
3428 | tree fn = OVL_CURRENT (fns); | |
3429 | ||
3430 | /* Member functions of dependent classes are | |
3431 | dependent. */ | |
3432 | if (TREE_CODE (fn) == FUNCTION_DECL | |
3433 | && type_dependent_expression_p (fn)) | |
3434 | dependent_p = true; | |
3435 | else if (TREE_CODE (fn) == TEMPLATE_DECL | |
3436 | && dependent_template_p (fn)) | |
3437 | dependent_p = true; | |
3438 | ||
3439 | fns = OVL_NEXT (fns); | |
3440 | } | |
3441 | } | |
3442 | ||
3443 | /* If the name was dependent on a template parameter, we will | |
3444 | resolve the name at instantiation time. */ | |
3445 | if (dependent_p) | |
3446 | { | |
3447 | /* Create a SCOPE_REF for qualified names, if the scope is | |
3448 | dependent. */ | |
3449 | if (scope) | |
3450 | { | |
fbb01da7 | 3451 | if (TYPE_P (scope)) |
3452 | { | |
3453 | if (address_p && done) | |
3454 | decl = finish_qualified_id_expr (scope, decl, | |
3455 | done, address_p, | |
3456 | template_p, | |
20ce13a9 | 3457 | template_arg_p, |
3458 | tf_warning_or_error); | |
eac53a7c | 3459 | else |
3460 | { | |
3461 | tree type = NULL_TREE; | |
3462 | if (DECL_P (decl) && !dependent_scope_p (scope)) | |
3463 | type = TREE_TYPE (decl); | |
3464 | decl = build_qualified_name (type, | |
3465 | scope, | |
3466 | id_expression, | |
3467 | template_p); | |
3468 | } | |
fbb01da7 | 3469 | } |
3470 | if (TREE_TYPE (decl)) | |
3471 | decl = convert_from_reference (decl); | |
3472 | return decl; | |
0886adbc | 3473 | } |
3474 | /* A TEMPLATE_ID already contains all the information we | |
3475 | need. */ | |
3476 | if (TREE_CODE (id_expression) == TEMPLATE_ID_EXPR) | |
3477 | return id_expression; | |
c08d51be | 3478 | *idk = CP_ID_KIND_UNQUALIFIED_DEPENDENT; |
2c584053 | 3479 | /* If we found a variable, then name lookup during the |
3480 | instantiation will always resolve to the same VAR_DECL | |
3481 | (or an instantiation thereof). */ | |
80a58eb0 | 3482 | if (VAR_P (decl) |
29ac02b7 | 3483 | || TREE_CODE (decl) == PARM_DECL) |
ca0553d6 | 3484 | { |
3485 | mark_used (decl); | |
3486 | return convert_from_reference (decl); | |
3487 | } | |
9a4312bd | 3488 | /* The same is true for FIELD_DECL, but we also need to |
3489 | make sure that the syntax is correct. */ | |
3490 | else if (TREE_CODE (decl) == FIELD_DECL) | |
edb111a3 | 3491 | { |
3492 | /* Since SCOPE is NULL here, this is an unqualified name. | |
3493 | Access checking has been performed during name lookup | |
3494 | already. Turn off checking to avoid duplicate errors. */ | |
3495 | push_deferring_access_checks (dk_no_check); | |
3496 | decl = finish_non_static_data_member | |
70269a57 | 3497 | (decl, NULL_TREE, |
edb111a3 | 3498 | /*qualifying_scope=*/NULL_TREE); |
3499 | pop_deferring_access_checks (); | |
3500 | return decl; | |
3501 | } | |
c08d51be | 3502 | return id_expression; |
0886adbc | 3503 | } |
3504 | ||
135f8bad | 3505 | if (TREE_CODE (decl) == NAMESPACE_DECL) |
03aa2b89 | 3506 | { |
03d6ca9e | 3507 | error ("use of namespace %qD as expression", decl); |
03aa2b89 | 3508 | return error_mark_node; |
3509 | } | |
3510 | else if (DECL_CLASS_TEMPLATE_P (decl)) | |
3511 | { | |
03d6ca9e | 3512 | error ("use of class template %qT as expression", decl); |
03aa2b89 | 3513 | return error_mark_node; |
3514 | } | |
3515 | else if (TREE_CODE (decl) == TREE_LIST) | |
3516 | { | |
3517 | /* Ambiguous reference to base members. */ | |
03d6ca9e | 3518 | error ("request for member %qD is ambiguous in " |
03aa2b89 | 3519 | "multiple inheritance lattice", id_expression); |
3520 | print_candidates (decl); | |
3521 | return error_mark_node; | |
3522 | } | |
135f8bad | 3523 | |
3524 | /* Mark variable-like entities as used. Functions are similarly | |
3525 | marked either below or after overload resolution. */ | |
80a58eb0 | 3526 | if ((VAR_P (decl) |
68204971 | 3527 | || TREE_CODE (decl) == PARM_DECL |
3528 | || TREE_CODE (decl) == CONST_DECL | |
3529 | || TREE_CODE (decl) == RESULT_DECL) | |
3530 | && !mark_used (decl)) | |
3531 | return error_mark_node; | |
135f8bad | 3532 | |
d58b8a94 | 3533 | /* Only certain kinds of names are allowed in constant |
c28ddc97 | 3534 | expression. Template parameters have already |
d58b8a94 | 3535 | been handled above. */ |
1d4070b9 | 3536 | if (! error_operand_p (decl) |
3537 | && integral_constant_expression_p | |
d58b8a94 | 3538 | && ! decl_constant_var_p (decl) |
c28ddc97 | 3539 | && TREE_CODE (decl) != CONST_DECL |
d58b8a94 | 3540 | && ! builtin_valid_in_constant_expr_p (decl)) |
3541 | { | |
3542 | if (!allow_non_integral_constant_expression_p) | |
3543 | { | |
3544 | error ("%qD cannot appear in a constant-expression", decl); | |
3545 | return error_mark_node; | |
3546 | } | |
3547 | *non_integral_constant_expression_p = true; | |
3548 | } | |
3549 | ||
462819c8 | 3550 | tree wrap; |
80a58eb0 | 3551 | if (VAR_P (decl) |
462819c8 | 3552 | && !cp_unevaluated_operand |
e506b2b9 | 3553 | && !processing_template_decl |
5e68df57 | 3554 | && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)) |
800478e6 | 3555 | && CP_DECL_THREAD_LOCAL_P (decl) |
462819c8 | 3556 | && (wrap = get_tls_wrapper_fn (decl))) |
3557 | { | |
3558 | /* Replace an evaluated use of the thread_local variable with | |
3559 | a call to its wrapper. */ | |
3560 | decl = build_cxx_call (wrap, 0, NULL, tf_warning_or_error); | |
3561 | } | |
30afdfe9 | 3562 | else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR |
3563 | && variable_template_p (TREE_OPERAND (decl, 0))) | |
3564 | { | |
3565 | decl = finish_template_variable (decl); | |
8b2ddcd8 | 3566 | mark_used (decl); |
30afdfe9 | 3567 | } |
462819c8 | 3568 | else if (scope) |
135f8bad | 3569 | { |
9031d10b | 3570 | decl = (adjust_result_of_qualified_name_lookup |
09616866 | 3571 | (decl, scope, current_nonlambda_class_type())); |
58cae612 | 3572 | |
3573 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
3574 | mark_used (decl); | |
3575 | ||
d0b4bf06 | 3576 | if (TYPE_P (scope)) |
fbb01da7 | 3577 | decl = finish_qualified_id_expr (scope, |
3578 | decl, | |
3579 | done, | |
3580 | address_p, | |
3581 | template_p, | |
20ce13a9 | 3582 | template_arg_p, |
3583 | tf_warning_or_error); | |
729f89ff | 3584 | else |
d0b4bf06 | 3585 | decl = convert_from_reference (decl); |
135f8bad | 3586 | } |
03aa2b89 | 3587 | else if (TREE_CODE (decl) == FIELD_DECL) |
edb111a3 | 3588 | { |
3589 | /* Since SCOPE is NULL here, this is an unqualified name. | |
3590 | Access checking has been performed during name lookup | |
3591 | already. Turn off checking to avoid duplicate errors. */ | |
3592 | push_deferring_access_checks (dk_no_check); | |
70269a57 | 3593 | decl = finish_non_static_data_member (decl, NULL_TREE, |
edb111a3 | 3594 | /*qualifying_scope=*/NULL_TREE); |
3595 | pop_deferring_access_checks (); | |
3596 | } | |
03aa2b89 | 3597 | else if (is_overloaded_fn (decl)) |
3598 | { | |
0e5cde0c | 3599 | tree first_fn; |
0886adbc | 3600 | |
1f07118e | 3601 | first_fn = get_first_fn (decl); |
03aa2b89 | 3602 | if (TREE_CODE (first_fn) == TEMPLATE_DECL) |
3603 | first_fn = DECL_TEMPLATE_RESULT (first_fn); | |
135f8bad | 3604 | |
bfb588d6 | 3605 | if (!really_overloaded_fn (decl) |
3606 | && !mark_used (first_fn)) | |
3607 | return error_mark_node; | |
135f8bad | 3608 | |
fbb01da7 | 3609 | if (!template_arg_p |
3610 | && TREE_CODE (first_fn) == FUNCTION_DECL | |
2c9f7d9e | 3611 | && DECL_FUNCTION_MEMBER_P (first_fn) |
3612 | && !shared_member_p (decl)) | |
03aa2b89 | 3613 | { |
3614 | /* A set of member functions. */ | |
3615 | decl = maybe_dummy_object (DECL_CONTEXT (first_fn), 0); | |
fbb01da7 | 3616 | return finish_class_member_access_expr (decl, id_expression, |
ebd21de4 | 3617 | /*template_p=*/false, |
3618 | tf_warning_or_error); | |
03aa2b89 | 3619 | } |
0e5cde0c | 3620 | |
3621 | decl = baselink_for_fns (decl); | |
03aa2b89 | 3622 | } |
3623 | else | |
3624 | { | |
03aa2b89 | 3625 | if (DECL_P (decl) && DECL_NONLOCAL (decl) |
c2d52c0c | 3626 | && DECL_CLASS_SCOPE_P (decl)) |
03aa2b89 | 3627 | { |
c2d52c0c | 3628 | tree context = context_for_name_lookup (decl); |
3629 | if (context != current_class_type) | |
3630 | { | |
3631 | tree path = currently_open_derived_class (context); | |
3632 | perform_or_defer_access_check (TYPE_BINFO (path), | |
eb833cbe | 3633 | decl, decl, |
3634 | tf_warning_or_error); | |
c2d52c0c | 3635 | } |
03aa2b89 | 3636 | } |
9031d10b | 3637 | |
729f89ff | 3638 | decl = convert_from_reference (decl); |
03aa2b89 | 3639 | } |
0886adbc | 3640 | } |
3641 | ||
0886adbc | 3642 | return decl; |
3643 | } | |
3644 | ||
902b4e01 | 3645 | /* Implement the __typeof keyword: Return the type of EXPR, suitable for |
3646 | use as a type-specifier. */ | |
3647 | ||
63e22e88 | 3648 | tree |
807be5b4 | 3649 | finish_typeof (tree expr) |
63e22e88 | 3650 | { |
1cfa8cdd | 3651 | tree type; |
3652 | ||
7d0f6734 | 3653 | if (type_dependent_expression_p (expr)) |
63e22e88 | 3654 | { |
95397ff9 | 3655 | type = cxx_make_type (TYPEOF_TYPE); |
82bb2115 | 3656 | TYPEOF_TYPE_EXPR (type) = expr; |
34da8800 | 3657 | SET_TYPE_STRUCTURAL_EQUALITY (type); |
63e22e88 | 3658 | |
1cfa8cdd | 3659 | return type; |
63e22e88 | 3660 | } |
3661 | ||
fbb73d9b | 3662 | expr = mark_type_use (expr); |
3663 | ||
66a0bac0 | 3664 | type = unlowered_expr_type (expr); |
1cfa8cdd | 3665 | |
3666 | if (!type || type == unknown_type_node) | |
3667 | { | |
03d6ca9e | 3668 | error ("type of %qE is unknown", expr); |
1cfa8cdd | 3669 | return error_mark_node; |
3670 | } | |
3671 | ||
3672 | return type; | |
63e22e88 | 3673 | } |
019cf886 | 3674 | |
8de5c43e | 3675 | /* Implement the __underlying_type keyword: Return the underlying |
3676 | type of TYPE, suitable for use as a type-specifier. */ | |
3677 | ||
3678 | tree | |
3679 | finish_underlying_type (tree type) | |
3680 | { | |
3681 | tree underlying_type; | |
3682 | ||
3683 | if (processing_template_decl) | |
3684 | { | |
3685 | underlying_type = cxx_make_type (UNDERLYING_TYPE); | |
3686 | UNDERLYING_TYPE_TYPE (underlying_type) = type; | |
3687 | SET_TYPE_STRUCTURAL_EQUALITY (underlying_type); | |
3688 | ||
3689 | return underlying_type; | |
3690 | } | |
3691 | ||
3692 | complete_type (type); | |
3693 | ||
3694 | if (TREE_CODE (type) != ENUMERAL_TYPE) | |
3695 | { | |
8c7d88f7 | 3696 | error ("%qT is not an enumeration type", type); |
8de5c43e | 3697 | return error_mark_node; |
3698 | } | |
3699 | ||
3700 | underlying_type = ENUM_UNDERLYING_TYPE (type); | |
3701 | ||
3702 | /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE | |
3703 | includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information. | |
3704 | See finish_enum_value_list for details. */ | |
3705 | if (!ENUM_FIXED_UNDERLYING_TYPE_P (type)) | |
3706 | underlying_type | |
3707 | = c_common_type_for_mode (TYPE_MODE (underlying_type), | |
3708 | TYPE_UNSIGNED (underlying_type)); | |
3709 | ||
3710 | return underlying_type; | |
3711 | } | |
3712 | ||
e6014a82 | 3713 | /* Implement the __direct_bases keyword: Return the direct base classes |
3714 | of type */ | |
3715 | ||
3716 | tree | |
3717 | calculate_direct_bases (tree type) | |
3718 | { | |
f1f41a6c | 3719 | vec<tree, va_gc> *vector = make_tree_vector(); |
e6014a82 | 3720 | tree bases_vec = NULL_TREE; |
f1f41a6c | 3721 | vec<tree, va_gc> *base_binfos; |
e6014a82 | 3722 | tree binfo; |
3723 | unsigned i; | |
3724 | ||
3725 | complete_type (type); | |
3726 | ||
3727 | if (!NON_UNION_CLASS_TYPE_P (type)) | |
3728 | return make_tree_vec (0); | |
3729 | ||
3730 | base_binfos = BINFO_BASE_BINFOS (TYPE_BINFO (type)); | |
3731 | ||
3732 | /* Virtual bases are initialized first */ | |
f1f41a6c | 3733 | for (i = 0; base_binfos->iterate (i, &binfo); i++) |
e6014a82 | 3734 | { |
3735 | if (BINFO_VIRTUAL_P (binfo)) | |
3736 | { | |
f1f41a6c | 3737 | vec_safe_push (vector, binfo); |
e6014a82 | 3738 | } |
3739 | } | |
3740 | ||
3741 | /* Now non-virtuals */ | |
f1f41a6c | 3742 | for (i = 0; base_binfos->iterate (i, &binfo); i++) |
e6014a82 | 3743 | { |
3744 | if (!BINFO_VIRTUAL_P (binfo)) | |
3745 | { | |
f1f41a6c | 3746 | vec_safe_push (vector, binfo); |
e6014a82 | 3747 | } |
3748 | } | |
3749 | ||
3750 | ||
f1f41a6c | 3751 | bases_vec = make_tree_vec (vector->length ()); |
e6014a82 | 3752 | |
f1f41a6c | 3753 | for (i = 0; i < vector->length (); ++i) |
e6014a82 | 3754 | { |
f1f41a6c | 3755 | TREE_VEC_ELT (bases_vec, i) = BINFO_TYPE ((*vector)[i]); |
e6014a82 | 3756 | } |
3757 | return bases_vec; | |
3758 | } | |
3759 | ||
3760 | /* Implement the __bases keyword: Return the base classes | |
3761 | of type */ | |
3762 | ||
3763 | /* Find morally non-virtual base classes by walking binfo hierarchy */ | |
3764 | /* Virtual base classes are handled separately in finish_bases */ | |
3765 | ||
3766 | static tree | |
a49c5913 | 3767 | dfs_calculate_bases_pre (tree binfo, void * /*data_*/) |
e6014a82 | 3768 | { |
3769 | /* Don't walk bases of virtual bases */ | |
3770 | return BINFO_VIRTUAL_P (binfo) ? dfs_skip_bases : NULL_TREE; | |
3771 | } | |
3772 | ||
3773 | static tree | |
3774 | dfs_calculate_bases_post (tree binfo, void *data_) | |
3775 | { | |
f1f41a6c | 3776 | vec<tree, va_gc> **data = ((vec<tree, va_gc> **) data_); |
e6014a82 | 3777 | if (!BINFO_VIRTUAL_P (binfo)) |
3778 | { | |
f1f41a6c | 3779 | vec_safe_push (*data, BINFO_TYPE (binfo)); |
e6014a82 | 3780 | } |
3781 | return NULL_TREE; | |
3782 | } | |
3783 | ||
3784 | /* Calculates the morally non-virtual base classes of a class */ | |
f1f41a6c | 3785 | static vec<tree, va_gc> * |
e6014a82 | 3786 | calculate_bases_helper (tree type) |
3787 | { | |
f1f41a6c | 3788 | vec<tree, va_gc> *vector = make_tree_vector(); |
e6014a82 | 3789 | |
3790 | /* Now add non-virtual base classes in order of construction */ | |
3791 | dfs_walk_all (TYPE_BINFO (type), | |
3792 | dfs_calculate_bases_pre, dfs_calculate_bases_post, &vector); | |
3793 | return vector; | |
3794 | } | |
3795 | ||
3796 | tree | |
3797 | calculate_bases (tree type) | |
3798 | { | |
f1f41a6c | 3799 | vec<tree, va_gc> *vector = make_tree_vector(); |
e6014a82 | 3800 | tree bases_vec = NULL_TREE; |
3801 | unsigned i; | |
f1f41a6c | 3802 | vec<tree, va_gc> *vbases; |
3803 | vec<tree, va_gc> *nonvbases; | |
e6014a82 | 3804 | tree binfo; |
3805 | ||
3806 | complete_type (type); | |
3807 | ||
3808 | if (!NON_UNION_CLASS_TYPE_P (type)) | |
3809 | return make_tree_vec (0); | |
3810 | ||
3811 | /* First go through virtual base classes */ | |
3812 | for (vbases = CLASSTYPE_VBASECLASSES (type), i = 0; | |
f1f41a6c | 3813 | vec_safe_iterate (vbases, i, &binfo); i++) |
e6014a82 | 3814 | { |
f1f41a6c | 3815 | vec<tree, va_gc> *vbase_bases; |
3816 | vbase_bases = calculate_bases_helper (BINFO_TYPE (binfo)); | |
3817 | vec_safe_splice (vector, vbase_bases); | |
e6014a82 | 3818 | release_tree_vector (vbase_bases); |
3819 | } | |
3820 | ||
3821 | /* Now for the non-virtual bases */ | |
3822 | nonvbases = calculate_bases_helper (type); | |
f1f41a6c | 3823 | vec_safe_splice (vector, nonvbases); |
e6014a82 | 3824 | release_tree_vector (nonvbases); |
3825 | ||
3826 | /* Last element is entire class, so don't copy */ | |
f1f41a6c | 3827 | bases_vec = make_tree_vec (vector->length () - 1); |
e6014a82 | 3828 | |
f1f41a6c | 3829 | for (i = 0; i < vector->length () - 1; ++i) |
e6014a82 | 3830 | { |
f1f41a6c | 3831 | TREE_VEC_ELT (bases_vec, i) = (*vector)[i]; |
e6014a82 | 3832 | } |
3833 | release_tree_vector (vector); | |
3834 | return bases_vec; | |
3835 | } | |
3836 | ||
3837 | tree | |
3838 | finish_bases (tree type, bool direct) | |
3839 | { | |
3840 | tree bases = NULL_TREE; | |
3841 | ||
3842 | if (!processing_template_decl) | |
3843 | { | |
3844 | /* Parameter packs can only be used in templates */ | |
3845 | error ("Parameter pack __bases only valid in template declaration"); | |
3846 | return error_mark_node; | |
3847 | } | |
3848 | ||
3849 | bases = cxx_make_type (BASES); | |
3850 | BASES_TYPE (bases) = type; | |
3851 | BASES_DIRECT (bases) = direct; | |
3852 | SET_TYPE_STRUCTURAL_EQUALITY (bases); | |
3853 | ||
3854 | return bases; | |
3855 | } | |
3856 | ||
bf75f33a | 3857 | /* Perform C++-specific checks for __builtin_offsetof before calling |
3858 | fold_offsetof. */ | |
3859 | ||
3860 | tree | |
65dd83dc | 3861 | finish_offsetof (tree expr, location_t loc) |
bf75f33a | 3862 | { |
fbbb80c7 | 3863 | /* If we're processing a template, we can't finish the semantics yet. |
3864 | Otherwise we can fold the entire expression now. */ | |
3865 | if (processing_template_decl) | |
3866 | { | |
3867 | expr = build1 (OFFSETOF_EXPR, size_type_node, expr); | |
3868 | SET_EXPR_LOCATION (expr, loc); | |
3869 | return expr; | |
3870 | } | |
3871 | ||
8d7dd437 | 3872 | if (TREE_CODE (expr) == PSEUDO_DTOR_EXPR) |
3873 | { | |
3874 | error ("cannot apply %<offsetof%> to destructor %<~%T%>", | |
3875 | TREE_OPERAND (expr, 2)); | |
3876 | return error_mark_node; | |
3877 | } | |
bf75f33a | 3878 | if (TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE |
3879 | || TREE_CODE (TREE_TYPE (expr)) == METHOD_TYPE | |
4fdaf896 | 3880 | || TREE_TYPE (expr) == unknown_type_node) |
bf75f33a | 3881 | { |
555b8b62 | 3882 | if (INDIRECT_REF_P (expr)) |
f0599f80 | 3883 | error ("second operand of %<offsetof%> is neither a single " |
3884 | "identifier nor a sequence of member accesses and " | |
3885 | "array references"); | |
3886 | else | |
3887 | { | |
3888 | if (TREE_CODE (expr) == COMPONENT_REF | |
3889 | || TREE_CODE (expr) == COMPOUND_EXPR) | |
3890 | expr = TREE_OPERAND (expr, 1); | |
3891 | error ("cannot apply %<offsetof%> to member function %qD", expr); | |
3892 | } | |
bf75f33a | 3893 | return error_mark_node; |
3894 | } | |
8ce416a1 | 3895 | if (REFERENCE_REF_P (expr)) |
f23ce5f0 | 3896 | expr = TREE_OPERAND (expr, 0); |
972f6131 | 3897 | if (TREE_CODE (expr) == COMPONENT_REF) |
3898 | { | |
3899 | tree object = TREE_OPERAND (expr, 0); | |
3900 | if (!complete_type_or_else (TREE_TYPE (object), object)) | |
3901 | return error_mark_node; | |
65dd83dc | 3902 | if (warn_invalid_offsetof |
3903 | && CLASS_TYPE_P (TREE_TYPE (object)) | |
3904 | && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (object)) | |
3905 | && cp_unevaluated_operand == 0) | |
3906 | pedwarn (loc, OPT_Winvalid_offsetof, | |
3907 | "offsetof within non-standard-layout type %qT is undefined", | |
3908 | TREE_TYPE (object)); | |
972f6131 | 3909 | } |
7549df0d | 3910 | return fold_offsetof (expr); |
bf75f33a | 3911 | } |
3912 | ||
b9e35020 | 3913 | /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This |
3914 | function is broken out from the above for the benefit of the tree-ssa | |
3915 | project. */ | |
3916 | ||
3917 | void | |
3918 | simplify_aggr_init_expr (tree *tp) | |
3919 | { | |
3920 | tree aggr_init_expr = *tp; | |
3921 | ||
952cb193 | 3922 | /* Form an appropriate CALL_EXPR. */ |
c2f47e15 | 3923 | tree fn = AGGR_INIT_EXPR_FN (aggr_init_expr); |
3924 | tree slot = AGGR_INIT_EXPR_SLOT (aggr_init_expr); | |
bbdcc797 | 3925 | tree type = TREE_TYPE (slot); |
b9e35020 | 3926 | |
3927 | tree call_expr; | |
3928 | enum style_t { ctor, arg, pcc } style; | |
805e22b2 | 3929 | |
952cb193 | 3930 | if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr)) |
805e22b2 | 3931 | style = ctor; |
3932 | #ifdef PCC_STATIC_STRUCT_RETURN | |
3933 | else if (1) | |
3934 | style = pcc; | |
3935 | #endif | |
805e22b2 | 3936 | else |
2e3e31d2 | 3937 | { |
3938 | gcc_assert (TREE_ADDRESSABLE (type)); | |
3939 | style = arg; | |
3940 | } | |
805e22b2 | 3941 | |
389dd41b | 3942 | call_expr = build_call_array_loc (input_location, |
3943 | TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))), | |
3944 | fn, | |
3945 | aggr_init_expr_nargs (aggr_init_expr), | |
3946 | AGGR_INIT_EXPR_ARGP (aggr_init_expr)); | |
c0f83203 | 3947 | TREE_NOTHROW (call_expr) = TREE_NOTHROW (aggr_init_expr); |
10621300 | 3948 | CALL_EXPR_LIST_INIT_P (call_expr) = CALL_EXPR_LIST_INIT_P (aggr_init_expr); |
c2f47e15 | 3949 | |
ea523851 | 3950 | if (style == ctor) |
952cb193 | 3951 | { |
ea523851 | 3952 | /* Replace the first argument to the ctor with the address of the |
3953 | slot. */ | |
9b86eec0 | 3954 | cxx_mark_addressable (slot); |
c2f47e15 | 3955 | CALL_EXPR_ARG (call_expr, 0) = |
3956 | build1 (ADDR_EXPR, build_pointer_type (type), slot); | |
952cb193 | 3957 | } |
c2f47e15 | 3958 | else if (style == arg) |
ea523851 | 3959 | { |
3960 | /* Just mark it addressable here, and leave the rest to | |
3961 | expand_call{,_inline}. */ | |
3962 | cxx_mark_addressable (slot); | |
3963 | CALL_EXPR_RETURN_SLOT_OPT (call_expr) = true; | |
de56f7e4 | 3964 | call_expr = build2 (INIT_EXPR, TREE_TYPE (call_expr), slot, call_expr); |
ea523851 | 3965 | } |
805e22b2 | 3966 | else if (style == pcc) |
952cb193 | 3967 | { |
805e22b2 | 3968 | /* If we're using the non-reentrant PCC calling convention, then we |
3969 | need to copy the returned value out of the static buffer into the | |
3970 | SLOT. */ | |
4cab8273 | 3971 | push_deferring_access_checks (dk_no_check); |
de56f7e4 | 3972 | call_expr = build_aggr_init (slot, call_expr, |
3973 | DIRECT_BIND | LOOKUP_ONLYCONVERTING, | |
3974 | tf_warning_or_error); | |
4cab8273 | 3975 | pop_deferring_access_checks (); |
de56f7e4 | 3976 | call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (slot), call_expr, slot); |
91d81115 | 3977 | } |
3978 | ||
a63dcad5 | 3979 | if (AGGR_INIT_ZERO_FIRST (aggr_init_expr)) |
3980 | { | |
3981 | tree init = build_zero_init (type, NULL_TREE, | |
3982 | /*static_storage_p=*/false); | |
3983 | init = build2 (INIT_EXPR, void_type_node, slot, init); | |
de56f7e4 | 3984 | call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (call_expr), |
3985 | init, call_expr); | |
a63dcad5 | 3986 | } |
3987 | ||
de56f7e4 | 3988 | *tp = call_expr; |
952cb193 | 3989 | } |
3990 | ||
2b82dde2 | 3991 | /* Emit all thunks to FN that should be emitted when FN is emitted. */ |
3992 | ||
84e10000 | 3993 | void |
807be5b4 | 3994 | emit_associated_thunks (tree fn) |
2b82dde2 | 3995 | { |
3996 | /* When we use vcall offsets, we emit thunks with the virtual | |
3997 | functions to which they thunk. The whole point of vcall offsets | |
3998 | is so that you can know statically the entire set of thunks that | |
3999 | will ever be needed for a given virtual function, thereby | |
4000 | enabling you to output all the thunks with the function itself. */ | |
34e5cced | 4001 | if (DECL_VIRTUAL_P (fn) |
4002 | /* Do not emit thunks for extern template instantiations. */ | |
4003 | && ! DECL_REALLY_EXTERN (fn)) | |
2b82dde2 | 4004 | { |
641985fa | 4005 | tree thunk; |
9031d10b | 4006 | |
1767a056 | 4007 | for (thunk = DECL_THUNKS (fn); thunk; thunk = DECL_CHAIN (thunk)) |
805e22b2 | 4008 | { |
6709b660 | 4009 | if (!THUNK_ALIAS (thunk)) |
805e22b2 | 4010 | { |
4880ab99 | 4011 | use_thunk (thunk, /*emit_p=*/1); |
4012 | if (DECL_RESULT_THUNK_P (thunk)) | |
4013 | { | |
4014 | tree probe; | |
9031d10b | 4015 | |
4880ab99 | 4016 | for (probe = DECL_THUNKS (thunk); |
1767a056 | 4017 | probe; probe = DECL_CHAIN (probe)) |
4880ab99 | 4018 | use_thunk (probe, /*emit_p=*/1); |
4019 | } | |
805e22b2 | 4020 | } |
4880ab99 | 4021 | else |
b4df430b | 4022 | gcc_assert (!DECL_THUNKS (thunk)); |
805e22b2 | 4023 | } |
2b82dde2 | 4024 | } |
4025 | } | |
4026 | ||
019cf886 | 4027 | /* Generate RTL for FN. */ |
4028 | ||
ed772161 | 4029 | bool |
4030 | expand_or_defer_fn_1 (tree fn) | |
6cb758f0 | 4031 | { |
4032 | /* When the parser calls us after finishing the body of a template | |
7f233616 | 4033 | function, we don't really want to expand the body. */ |
4034 | if (processing_template_decl) | |
6cb758f0 | 4035 | { |
4036 | /* Normally, collection only occurs in rest_of_compilation. So, | |
4037 | if we don't collect here, we never collect junk generated | |
4038 | during the processing of templates until we hit a | |
dd63dd90 | 4039 | non-template function. It's not safe to do this inside a |
4040 | nested class, though, as the parser may have local state that | |
4041 | is not a GC root. */ | |
4042 | if (!function_depth) | |
4043 | ggc_collect (); | |
ed772161 | 4044 | return false; |
6cb758f0 | 4045 | } |
4046 | ||
bfec3452 | 4047 | gcc_assert (DECL_SAVED_TREE (fn)); |
75a70cf9 | 4048 | |
caa6fdce | 4049 | /* We make a decision about linkage for these functions at the end |
4050 | of the compilation. Until that point, we do not want the back | |
4051 | end to output them -- but we do want it to see the bodies of | |
aa255322 | 4052 | these functions so that it can inline them as appropriate. */ |
caa6fdce | 4053 | if (DECL_DECLARED_INLINE_P (fn) || DECL_IMPLICIT_INSTANTIATION (fn)) |
4054 | { | |
d9803664 | 4055 | if (DECL_INTERFACE_KNOWN (fn)) |
4056 | /* We've already made a decision as to how this function will | |
4057 | be handled. */; | |
4058 | else if (!at_eof) | |
2381bbfa | 4059 | tentative_decl_linkage (fn); |
caa6fdce | 4060 | else |
4061 | import_export_decl (fn); | |
aa255322 | 4062 | |
4063 | /* If the user wants us to keep all inline functions, then mark | |
4064 | this function as needed so that finish_file will make sure to | |
aed4eb5d | 4065 | output it later. Similarly, all dllexport'd functions must |
4066 | be emitted; there may be callers in other DLLs. */ | |
9c3d0685 | 4067 | if (DECL_DECLARED_INLINE_P (fn) |
4068 | && !DECL_REALLY_EXTERN (fn) | |
4069 | && (flag_keep_inline_functions | |
4070 | || (flag_keep_inline_dllexport | |
4071 | && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn))))) | |
ab185a23 | 4072 | { |
4073 | mark_needed (fn); | |
4074 | DECL_EXTERNAL (fn) = 0; | |
4075 | } | |
caa6fdce | 4076 | } |
4077 | ||
468088ac | 4078 | /* If this is a constructor or destructor body, we have to clone |
4079 | it. */ | |
4080 | if (maybe_clone_body (fn)) | |
4081 | { | |
4082 | /* We don't want to process FN again, so pretend we've written | |
4083 | it out, even though we haven't. */ | |
4084 | TREE_ASM_WRITTEN (fn) = 1; | |
4085 | /* If this is an instantiation of a constexpr function, keep | |
4086 | DECL_SAVED_TREE for explain_invalid_constexpr_fn. */ | |
4087 | if (!is_instantiation_of_constexpr (fn)) | |
4088 | DECL_SAVED_TREE (fn) = NULL_TREE; | |
4089 | return false; | |
4090 | } | |
4091 | ||
6cb758f0 | 4092 | /* There's no reason to do any of the work here if we're only doing |
4093 | semantic analysis; this code just generates RTL. */ | |
4094 | if (flag_syntax_only) | |
ed772161 | 4095 | return false; |
4096 | ||
4097 | return true; | |
4098 | } | |
6cb758f0 | 4099 | |
ed772161 | 4100 | void |
4101 | expand_or_defer_fn (tree fn) | |
4102 | { | |
4103 | if (expand_or_defer_fn_1 (fn)) | |
4104 | { | |
4105 | function_depth++; | |
70024a5e | 4106 | |
ed772161 | 4107 | /* Expand or defer, at the whim of the compilation unit manager. */ |
35ee1c66 | 4108 | cgraph_node::finalize_function (fn, function_depth > 1); |
28454517 | 4109 | emit_associated_thunks (fn); |
70024a5e | 4110 | |
ed772161 | 4111 | function_depth--; |
4112 | } | |
6cb758f0 | 4113 | } |
4114 | ||
4ee9c684 | 4115 | struct nrv_data |
4116 | { | |
c1f445d2 | 4117 | nrv_data () : visited (37) {} |
4118 | ||
4ee9c684 | 4119 | tree var; |
4120 | tree result; | |
770ff93b | 4121 | hash_table<nofree_ptr_hash <tree_node> > visited; |
4ee9c684 | 4122 | }; |
80ac742d | 4123 | |
4ee9c684 | 4124 | /* Helper function for walk_tree, used by finalize_nrv below. */ |
4125 | ||
4126 | static tree | |
4127 | finalize_nrv_r (tree* tp, int* walk_subtrees, void* data) | |
80ac742d | 4128 | { |
4ee9c684 | 4129 | struct nrv_data *dp = (struct nrv_data *)data; |
d1455aa3 | 4130 | tree_node **slot; |
4cfd9030 | 4131 | |
4132 | /* No need to walk into types. There wouldn't be any need to walk into | |
4133 | non-statements, except that we have to consider STMT_EXPRs. */ | |
80ac742d | 4134 | if (TYPE_P (*tp)) |
4135 | *walk_subtrees = 0; | |
4ee9c684 | 4136 | /* Change all returns to just refer to the RESULT_DECL; this is a nop, |
4137 | but differs from using NULL_TREE in that it indicates that we care | |
4138 | about the value of the RESULT_DECL. */ | |
c857cd60 | 4139 | else if (TREE_CODE (*tp) == RETURN_EXPR) |
4140 | TREE_OPERAND (*tp, 0) = dp->result; | |
4ee9c684 | 4141 | /* Change all cleanups for the NRV to only run when an exception is |
4142 | thrown. */ | |
4cfd9030 | 4143 | else if (TREE_CODE (*tp) == CLEANUP_STMT |
4ee9c684 | 4144 | && CLEANUP_DECL (*tp) == dp->var) |
a9bc793b | 4145 | CLEANUP_EH_ONLY (*tp) = 1; |
7dd37241 | 4146 | /* Replace the DECL_EXPR for the NRV with an initialization of the |
4ee9c684 | 4147 | RESULT_DECL, if needed. */ |
7dd37241 | 4148 | else if (TREE_CODE (*tp) == DECL_EXPR |
4149 | && DECL_EXPR_DECL (*tp) == dp->var) | |
4ee9c684 | 4150 | { |
4151 | tree init; | |
4152 | if (DECL_INITIAL (dp->var) | |
4153 | && DECL_INITIAL (dp->var) != error_mark_node) | |
d7daeaeb | 4154 | init = build2 (INIT_EXPR, void_type_node, dp->result, |
4155 | DECL_INITIAL (dp->var)); | |
4ee9c684 | 4156 | else |
e60a6f7b | 4157 | init = build_empty_stmt (EXPR_LOCATION (*tp)); |
d7daeaeb | 4158 | DECL_INITIAL (dp->var) = NULL_TREE; |
1cf1742e | 4159 | SET_EXPR_LOCATION (init, EXPR_LOCATION (*tp)); |
4ee9c684 | 4160 | *tp = init; |
4161 | } | |
4162 | /* And replace all uses of the NRV with the RESULT_DECL. */ | |
4163 | else if (*tp == dp->var) | |
4164 | *tp = dp->result; | |
4165 | ||
4166 | /* Avoid walking into the same tree more than once. Unfortunately, we | |
4167 | can't just use walk_tree_without duplicates because it would only call | |
4168 | us for the first occurrence of dp->var in the function body. */ | |
d1455aa3 | 4169 | slot = dp->visited.find_slot (*tp, INSERT); |
4ee9c684 | 4170 | if (*slot) |
4171 | *walk_subtrees = 0; | |
4172 | else | |
4173 | *slot = *tp; | |
80ac742d | 4174 | |
4175 | /* Keep iterating. */ | |
4176 | return NULL_TREE; | |
4177 | } | |
4178 | ||
4ee9c684 | 4179 | /* Called from finish_function to implement the named return value |
c857cd60 | 4180 | optimization by overriding all the RETURN_EXPRs and pertinent |
4ee9c684 | 4181 | CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the |
4182 | RESULT_DECL for the function. */ | |
6528331d | 4183 | |
90e3d9ba | 4184 | void |
4ee9c684 | 4185 | finalize_nrv (tree *tp, tree var, tree result) |
6528331d | 4186 | { |
4ee9c684 | 4187 | struct nrv_data data; |
4188 | ||
93d0e758 | 4189 | /* Copy name from VAR to RESULT. */ |
4ee9c684 | 4190 | DECL_NAME (result) = DECL_NAME (var); |
4ee9c684 | 4191 | /* Don't forget that we take its address. */ |
4192 | TREE_ADDRESSABLE (result) = TREE_ADDRESSABLE (var); | |
93d0e758 | 4193 | /* Finally set DECL_VALUE_EXPR to avoid assigning |
4194 | a stack slot at -O0 for the original var and debug info | |
4195 | uses RESULT location for VAR. */ | |
4196 | SET_DECL_VALUE_EXPR (var, result); | |
4197 | DECL_HAS_VALUE_EXPR_P (var) = 1; | |
4ee9c684 | 4198 | |
4199 | data.var = var; | |
4200 | data.result = result; | |
20a8f962 | 4201 | cp_walk_tree (tp, finalize_nrv_r, &data, 0); |
1f1fa73c | 4202 | } |
8487df40 | 4203 | \f |
fd6481cf | 4204 | /* Create CP_OMP_CLAUSE_INFO for clause C. Returns true if it is invalid. */ |
4205 | ||
4206 | bool | |
4207 | cxx_omp_create_clause_info (tree c, tree type, bool need_default_ctor, | |
bc7bff74 | 4208 | bool need_copy_ctor, bool need_copy_assignment, |
4209 | bool need_dtor) | |
fd6481cf | 4210 | { |
4211 | int save_errorcount = errorcount; | |
4212 | tree info, t; | |
4213 | ||
4214 | /* Always allocate 3 elements for simplicity. These are the | |
4215 | function decls for the ctor, dtor, and assignment op. | |
4216 | This layout is known to the three lang hooks, | |
4217 | cxx_omp_clause_default_init, cxx_omp_clause_copy_init, | |
4218 | and cxx_omp_clause_assign_op. */ | |
4219 | info = make_tree_vec (3); | |
4220 | CP_OMP_CLAUSE_INFO (c) = info; | |
4221 | ||
2ee92e27 | 4222 | if (need_default_ctor || need_copy_ctor) |
fd6481cf | 4223 | { |
4224 | if (need_default_ctor) | |
2ee92e27 | 4225 | t = get_default_ctor (type); |
fd6481cf | 4226 | else |
9b222de3 | 4227 | t = get_copy_ctor (type, tf_warning_or_error); |
2ee92e27 | 4228 | |
4229 | if (t && !trivial_fn_p (t)) | |
4230 | TREE_VEC_ELT (info, 0) = t; | |
fd6481cf | 4231 | } |
4232 | ||
bc7bff74 | 4233 | if (need_dtor && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)) |
9b222de3 | 4234 | TREE_VEC_ELT (info, 1) = get_dtor (type, tf_warning_or_error); |
fd6481cf | 4235 | |
2ee92e27 | 4236 | if (need_copy_assignment) |
fd6481cf | 4237 | { |
2ee92e27 | 4238 | t = get_copy_assign (type); |
4239 | ||
4240 | if (t && !trivial_fn_p (t)) | |
4241 | TREE_VEC_ELT (info, 2) = t; | |
fd6481cf | 4242 | } |
4243 | ||
4244 | return errorcount != save_errorcount; | |
4245 | } | |
4246 | ||
bc7bff74 | 4247 | /* Helper function for handle_omp_array_sections. Called recursively |
4248 | to handle multiple array-section-subscripts. C is the clause, | |
4249 | T current expression (initially OMP_CLAUSE_DECL), which is either | |
4250 | a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound | |
4251 | expression if specified, TREE_VALUE length expression if specified, | |
4252 | TREE_CHAIN is what it has been specified after, or some decl. | |
4253 | TYPES vector is populated with array section types, MAYBE_ZERO_LEN | |
4254 | set to true if any of the array-section-subscript could have length | |
4255 | of zero (explicit or implicit), FIRST_NON_ONE is the index of the | |
4256 | first array-section-subscript which is known not to have length | |
4257 | of one. Given say: | |
4258 | map(a[:b][2:1][:c][:2][:d][e:f][2:5]) | |
4259 | FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c] | |
4260 | all are or may have length of 1, array-section-subscript [:2] is the | |
4261 | first one knonwn not to have length 1. For array-section-subscript | |
4262 | <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't | |
4263 | 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we | |
4264 | can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above | |
4265 | case though, as some lengths could be zero. */ | |
4266 | ||
4267 | static tree | |
4268 | handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types, | |
4269 | bool &maybe_zero_len, unsigned int &first_non_one) | |
4270 | { | |
4271 | tree ret, low_bound, length, type; | |
4272 | if (TREE_CODE (t) != TREE_LIST) | |
4273 | { | |
4274 | if (error_operand_p (t)) | |
4275 | return error_mark_node; | |
4276 | if (type_dependent_expression_p (t)) | |
4277 | return NULL_TREE; | |
f4ae4202 | 4278 | if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL) |
bc7bff74 | 4279 | { |
4280 | if (processing_template_decl) | |
4281 | return NULL_TREE; | |
4282 | if (DECL_P (t)) | |
4283 | error_at (OMP_CLAUSE_LOCATION (c), | |
4284 | "%qD is not a variable in %qs clause", t, | |
4285 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
4286 | else | |
4287 | error_at (OMP_CLAUSE_LOCATION (c), | |
4288 | "%qE is not a variable in %qs clause", t, | |
4289 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
4290 | return error_mark_node; | |
4291 | } | |
4292 | else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND | |
800478e6 | 4293 | && VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t)) |
bc7bff74 | 4294 | { |
4295 | error_at (OMP_CLAUSE_LOCATION (c), | |
4296 | "%qD is threadprivate variable in %qs clause", t, | |
4297 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
4298 | return error_mark_node; | |
4299 | } | |
4300 | t = convert_from_reference (t); | |
4301 | return t; | |
4302 | } | |
4303 | ||
4304 | ret = handle_omp_array_sections_1 (c, TREE_CHAIN (t), types, | |
4305 | maybe_zero_len, first_non_one); | |
4306 | if (ret == error_mark_node || ret == NULL_TREE) | |
4307 | return ret; | |
4308 | ||
4309 | type = TREE_TYPE (ret); | |
4310 | low_bound = TREE_PURPOSE (t); | |
4311 | length = TREE_VALUE (t); | |
4312 | if ((low_bound && type_dependent_expression_p (low_bound)) | |
4313 | || (length && type_dependent_expression_p (length))) | |
4314 | return NULL_TREE; | |
4315 | ||
4316 | if (low_bound == error_mark_node || length == error_mark_node) | |
4317 | return error_mark_node; | |
4318 | ||
4319 | if (low_bound && !INTEGRAL_TYPE_P (TREE_TYPE (low_bound))) | |
4320 | { | |
4321 | error_at (OMP_CLAUSE_LOCATION (c), | |
4322 | "low bound %qE of array section does not have integral type", | |
4323 | low_bound); | |
4324 | return error_mark_node; | |
4325 | } | |
4326 | if (length && !INTEGRAL_TYPE_P (TREE_TYPE (length))) | |
4327 | { | |
4328 | error_at (OMP_CLAUSE_LOCATION (c), | |
4329 | "length %qE of array section does not have integral type", | |
4330 | length); | |
4331 | return error_mark_node; | |
4332 | } | |
4fc4088b | 4333 | if (low_bound) |
4334 | low_bound = mark_rvalue_use (low_bound); | |
4335 | if (length) | |
4336 | length = mark_rvalue_use (length); | |
bc7bff74 | 4337 | if (low_bound |
4338 | && TREE_CODE (low_bound) == INTEGER_CST | |
4339 | && TYPE_PRECISION (TREE_TYPE (low_bound)) | |
4340 | > TYPE_PRECISION (sizetype)) | |
4341 | low_bound = fold_convert (sizetype, low_bound); | |
4342 | if (length | |
4343 | && TREE_CODE (length) == INTEGER_CST | |
4344 | && TYPE_PRECISION (TREE_TYPE (length)) | |
4345 | > TYPE_PRECISION (sizetype)) | |
4346 | length = fold_convert (sizetype, length); | |
4347 | if (low_bound == NULL_TREE) | |
4348 | low_bound = integer_zero_node; | |
4349 | ||
4350 | if (length != NULL_TREE) | |
4351 | { | |
4352 | if (!integer_nonzerop (length)) | |
4353 | maybe_zero_len = true; | |
4354 | if (first_non_one == types.length () | |
4355 | && (TREE_CODE (length) != INTEGER_CST || integer_onep (length))) | |
4356 | first_non_one++; | |
4357 | } | |
4358 | if (TREE_CODE (type) == ARRAY_TYPE) | |
4359 | { | |
4360 | if (length == NULL_TREE | |
4361 | && (TYPE_DOMAIN (type) == NULL_TREE | |
4362 | || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE)) | |
4363 | { | |
4364 | error_at (OMP_CLAUSE_LOCATION (c), | |
4365 | "for unknown bound array type length expression must " | |
4366 | "be specified"); | |
4367 | return error_mark_node; | |
4368 | } | |
4369 | if (TREE_CODE (low_bound) == INTEGER_CST | |
4370 | && tree_int_cst_sgn (low_bound) == -1) | |
4371 | { | |
4372 | error_at (OMP_CLAUSE_LOCATION (c), | |
4373 | "negative low bound in array section in %qs clause", | |
4374 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
4375 | return error_mark_node; | |
4376 | } | |
4377 | if (length != NULL_TREE | |
4378 | && TREE_CODE (length) == INTEGER_CST | |
4379 | && tree_int_cst_sgn (length) == -1) | |
4380 | { | |
4381 | error_at (OMP_CLAUSE_LOCATION (c), | |
4382 | "negative length in array section in %qs clause", | |
4383 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
4384 | return error_mark_node; | |
4385 | } | |
4386 | if (TYPE_DOMAIN (type) | |
4387 | && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) | |
4388 | && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) | |
4389 | == INTEGER_CST) | |
4390 | { | |
4391 | tree size = size_binop (PLUS_EXPR, | |
4392 | TYPE_MAX_VALUE (TYPE_DOMAIN (type)), | |
4393 | size_one_node); | |
4394 | if (TREE_CODE (low_bound) == INTEGER_CST) | |
4395 | { | |
4396 | if (tree_int_cst_lt (size, low_bound)) | |
4397 | { | |
4398 | error_at (OMP_CLAUSE_LOCATION (c), | |
4399 | "low bound %qE above array section size " | |
4400 | "in %qs clause", low_bound, | |
4401 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
4402 | return error_mark_node; | |
4403 | } | |
4404 | if (tree_int_cst_equal (size, low_bound)) | |
4405 | maybe_zero_len = true; | |
4406 | else if (length == NULL_TREE | |
4407 | && first_non_one == types.length () | |
4408 | && tree_int_cst_equal | |
4409 | (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), | |
4410 | low_bound)) | |
4411 | first_non_one++; | |
4412 | } | |
4413 | else if (length == NULL_TREE) | |
4414 | { | |
4415 | maybe_zero_len = true; | |
4416 | if (first_non_one == types.length ()) | |
4417 | first_non_one++; | |
4418 | } | |
4419 | if (length && TREE_CODE (length) == INTEGER_CST) | |
4420 | { | |
4421 | if (tree_int_cst_lt (size, length)) | |
4422 | { | |
4423 | error_at (OMP_CLAUSE_LOCATION (c), | |
4424 | "length %qE above array section size " | |
4425 | "in %qs clause", length, | |
4426 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
4427 | return error_mark_node; | |
4428 | } | |
4429 | if (TREE_CODE (low_bound) == INTEGER_CST) | |
4430 | { | |
4431 | tree lbpluslen | |
4432 | = size_binop (PLUS_EXPR, | |
4433 | fold_convert (sizetype, low_bound), | |
4434 | fold_convert (sizetype, length)); | |
4435 | if (TREE_CODE (lbpluslen) == INTEGER_CST | |
4436 | && tree_int_cst_lt (size, lbpluslen)) | |
4437 | { | |
4438 | error_at (OMP_CLAUSE_LOCATION (c), | |
4439 | "high bound %qE above array section size " | |
4440 | "in %qs clause", lbpluslen, | |
4441 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
4442 | return error_mark_node; | |
4443 | } | |
4444 | } | |
4445 | } | |
4446 | } | |
4447 | else if (length == NULL_TREE) | |
4448 | { | |
4449 | maybe_zero_len = true; | |
4450 | if (first_non_one == types.length ()) | |
4451 | first_non_one++; | |
4452 | } | |
4453 | ||
4454 | /* For [lb:] we will need to evaluate lb more than once. */ | |
4455 | if (length == NULL_TREE && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND) | |
4456 | { | |
4457 | tree lb = cp_save_expr (low_bound); | |
4458 | if (lb != low_bound) | |
4459 | { | |
4460 | TREE_PURPOSE (t) = lb; | |
4461 | low_bound = lb; | |
4462 | } | |
4463 | } | |
4464 | } | |
4465 | else if (TREE_CODE (type) == POINTER_TYPE) | |
4466 | { | |
4467 | if (length == NULL_TREE) | |
4468 | { | |
4469 | error_at (OMP_CLAUSE_LOCATION (c), | |
4470 | "for pointer type length expression must be specified"); | |
4471 | return error_mark_node; | |
4472 | } | |
4473 | /* If there is a pointer type anywhere but in the very first | |
4474 | array-section-subscript, the array section can't be contiguous. */ | |
4475 | if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND | |
4476 | && TREE_CODE (TREE_CHAIN (t)) == TREE_LIST) | |
4477 | { | |
4478 | error_at (OMP_CLAUSE_LOCATION (c), | |
4479 | "array section is not contiguous in %qs clause", | |
4480 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
4481 | return error_mark_node; | |
4482 | } | |
4483 | } | |
4484 | else | |
4485 | { | |
4486 | error_at (OMP_CLAUSE_LOCATION (c), | |
4487 | "%qE does not have pointer or array type", ret); | |
4488 | return error_mark_node; | |
4489 | } | |
4490 | if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND) | |
4491 | types.safe_push (TREE_TYPE (ret)); | |
4492 | /* We will need to evaluate lb more than once. */ | |
4493 | tree lb = cp_save_expr (low_bound); | |
4494 | if (lb != low_bound) | |
4495 | { | |
4496 | TREE_PURPOSE (t) = lb; | |
4497 | low_bound = lb; | |
4498 | } | |
4499 | ret = grok_array_decl (OMP_CLAUSE_LOCATION (c), ret, low_bound, false); | |
4500 | return ret; | |
4501 | } | |
4502 | ||
4503 | /* Handle array sections for clause C. */ | |
4504 | ||
4505 | static bool | |
4506 | handle_omp_array_sections (tree c) | |
4507 | { | |
4508 | bool maybe_zero_len = false; | |
4509 | unsigned int first_non_one = 0; | |
c2078b80 | 4510 | auto_vec<tree> types; |
bc7bff74 | 4511 | tree first = handle_omp_array_sections_1 (c, OMP_CLAUSE_DECL (c), types, |
4512 | maybe_zero_len, first_non_one); | |
4513 | if (first == error_mark_node) | |
c2078b80 | 4514 | return true; |
bc7bff74 | 4515 | if (first == NULL_TREE) |
c2078b80 | 4516 | return false; |
bc7bff74 | 4517 | if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND) |
4518 | { | |
4519 | tree t = OMP_CLAUSE_DECL (c); | |
4520 | tree tem = NULL_TREE; | |
bc7bff74 | 4521 | if (processing_template_decl) |
4522 | return false; | |
4523 | /* Need to evaluate side effects in the length expressions | |
4524 | if any. */ | |
4525 | while (TREE_CODE (t) == TREE_LIST) | |
4526 | { | |
4527 | if (TREE_VALUE (t) && TREE_SIDE_EFFECTS (TREE_VALUE (t))) | |
4528 | { | |
4529 | if (tem == NULL_TREE) | |
4530 | tem = TREE_VALUE (t); | |
4531 | else | |
4532 | tem = build2 (COMPOUND_EXPR, TREE_TYPE (tem), | |
4533 | TREE_VALUE (t), tem); | |
4534 | } | |
4535 | t = TREE_CHAIN (t); | |
4536 | } | |
4537 | if (tem) | |
4538 | first = build2 (COMPOUND_EXPR, TREE_TYPE (first), tem, first); | |
4539 | OMP_CLAUSE_DECL (c) = first; | |
4540 | } | |
4541 | else | |
4542 | { | |
4543 | unsigned int num = types.length (), i; | |
4544 | tree t, side_effects = NULL_TREE, size = NULL_TREE; | |
4545 | tree condition = NULL_TREE; | |
4546 | ||
4547 | if (int_size_in_bytes (TREE_TYPE (first)) <= 0) | |
4548 | maybe_zero_len = true; | |
4549 | if (processing_template_decl && maybe_zero_len) | |
c2078b80 | 4550 | return false; |
bc7bff74 | 4551 | |
4552 | for (i = num, t = OMP_CLAUSE_DECL (c); i > 0; | |
4553 | t = TREE_CHAIN (t)) | |
4554 | { | |
4555 | tree low_bound = TREE_PURPOSE (t); | |
4556 | tree length = TREE_VALUE (t); | |
4557 | ||
4558 | i--; | |
4559 | if (low_bound | |
4560 | && TREE_CODE (low_bound) == INTEGER_CST | |
4561 | && TYPE_PRECISION (TREE_TYPE (low_bound)) | |
4562 | > TYPE_PRECISION (sizetype)) | |
4563 | low_bound = fold_convert (sizetype, low_bound); | |
4564 | if (length | |
4565 | && TREE_CODE (length) == INTEGER_CST | |
4566 | && TYPE_PRECISION (TREE_TYPE (length)) | |
4567 | > TYPE_PRECISION (sizetype)) | |
4568 | length = fold_convert (sizetype, length); | |
4569 | if (low_bound == NULL_TREE) | |
4570 | low_bound = integer_zero_node; | |
4571 | if (!maybe_zero_len && i > first_non_one) | |
4572 | { | |
4573 | if (integer_nonzerop (low_bound)) | |
4574 | goto do_warn_noncontiguous; | |
4575 | if (length != NULL_TREE | |
4576 | && TREE_CODE (length) == INTEGER_CST | |
4577 | && TYPE_DOMAIN (types[i]) | |
4578 | && TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])) | |
4579 | && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types[i]))) | |
4580 | == INTEGER_CST) | |
4581 | { | |
4582 | tree size; | |
4583 | size = size_binop (PLUS_EXPR, | |
4584 | TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])), | |
4585 | size_one_node); | |
4586 | if (!tree_int_cst_equal (length, size)) | |
4587 | { | |
4588 | do_warn_noncontiguous: | |
4589 | error_at (OMP_CLAUSE_LOCATION (c), | |
4590 | "array section is not contiguous in %qs " | |
4591 | "clause", | |
4592 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
bc7bff74 | 4593 | return true; |
4594 | } | |
4595 | } | |
4596 | if (!processing_template_decl | |
4597 | && length != NULL_TREE | |
4598 | && TREE_SIDE_EFFECTS (length)) | |
4599 | { | |
4600 | if (side_effects == NULL_TREE) | |
4601 | side_effects = length; | |
4602 | else | |
4603 | side_effects = build2 (COMPOUND_EXPR, | |
4604 | TREE_TYPE (side_effects), | |
4605 | length, side_effects); | |
4606 | } | |
4607 | } | |
4608 | else if (processing_template_decl) | |
4609 | continue; | |
4610 | else | |
4611 | { | |
4612 | tree l; | |
4613 | ||
4614 | if (i > first_non_one && length && integer_nonzerop (length)) | |
4615 | continue; | |
4616 | if (length) | |
4617 | l = fold_convert (sizetype, length); | |
4618 | else | |
4619 | { | |
4620 | l = size_binop (PLUS_EXPR, | |
4621 | TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])), | |
4622 | size_one_node); | |
4623 | l = size_binop (MINUS_EXPR, l, | |
4624 | fold_convert (sizetype, low_bound)); | |
4625 | } | |
4626 | if (i > first_non_one) | |
4627 | { | |
4628 | l = fold_build2 (NE_EXPR, boolean_type_node, l, | |
4629 | size_zero_node); | |
4630 | if (condition == NULL_TREE) | |
4631 | condition = l; | |
4632 | else | |
4633 | condition = fold_build2 (BIT_AND_EXPR, boolean_type_node, | |
4634 | l, condition); | |
4635 | } | |
4636 | else if (size == NULL_TREE) | |
4637 | { | |
4638 | size = size_in_bytes (TREE_TYPE (types[i])); | |
4639 | size = size_binop (MULT_EXPR, size, l); | |
4640 | if (condition) | |
4641 | size = fold_build3 (COND_EXPR, sizetype, condition, | |
4642 | size, size_zero_node); | |
4643 | } | |
4644 | else | |
4645 | size = size_binop (MULT_EXPR, size, l); | |
4646 | } | |
4647 | } | |
bc7bff74 | 4648 | if (!processing_template_decl) |
4649 | { | |
4650 | if (side_effects) | |
4651 | size = build2 (COMPOUND_EXPR, sizetype, side_effects, size); | |
4652 | OMP_CLAUSE_DECL (c) = first; | |
4653 | OMP_CLAUSE_SIZE (c) = size; | |
4654 | if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP) | |
4655 | return false; | |
4656 | tree c2 = build_omp_clause (OMP_CLAUSE_LOCATION (c), | |
4657 | OMP_CLAUSE_MAP); | |
ca4c3545 | 4658 | OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_POINTER); |
bc7bff74 | 4659 | if (!cxx_mark_addressable (t)) |
4660 | return false; | |
4661 | OMP_CLAUSE_DECL (c2) = t; | |
4662 | t = build_fold_addr_expr (first); | |
4663 | t = fold_convert_loc (OMP_CLAUSE_LOCATION (c), | |
4664 | ptrdiff_type_node, t); | |
4665 | tree ptr = OMP_CLAUSE_DECL (c2); | |
4666 | ptr = convert_from_reference (ptr); | |
4667 | if (!POINTER_TYPE_P (TREE_TYPE (ptr))) | |
4668 | ptr = build_fold_addr_expr (ptr); | |
4669 | t = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR, | |
4670 | ptrdiff_type_node, t, | |
4671 | fold_convert_loc (OMP_CLAUSE_LOCATION (c), | |
4672 | ptrdiff_type_node, ptr)); | |
4673 | OMP_CLAUSE_SIZE (c2) = t; | |
4674 | OMP_CLAUSE_CHAIN (c2) = OMP_CLAUSE_CHAIN (c); | |
4675 | OMP_CLAUSE_CHAIN (c) = c2; | |
4676 | ptr = OMP_CLAUSE_DECL (c2); | |
4677 | if (TREE_CODE (TREE_TYPE (ptr)) == REFERENCE_TYPE | |
4678 | && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (ptr)))) | |
4679 | { | |
4680 | tree c3 = build_omp_clause (OMP_CLAUSE_LOCATION (c), | |
4681 | OMP_CLAUSE_MAP); | |
ca4c3545 | 4682 | OMP_CLAUSE_SET_MAP_KIND (c3, GOMP_MAP_POINTER); |
bc7bff74 | 4683 | OMP_CLAUSE_DECL (c3) = ptr; |
4684 | OMP_CLAUSE_DECL (c2) = convert_from_reference (ptr); | |
4685 | OMP_CLAUSE_SIZE (c3) = size_zero_node; | |
4686 | OMP_CLAUSE_CHAIN (c3) = OMP_CLAUSE_CHAIN (c2); | |
4687 | OMP_CLAUSE_CHAIN (c2) = c3; | |
4688 | } | |
4689 | } | |
4690 | } | |
4691 | return false; | |
4692 | } | |
4693 | ||
4694 | /* Return identifier to look up for omp declare reduction. */ | |
4695 | ||
4696 | tree | |
4697 | omp_reduction_id (enum tree_code reduction_code, tree reduction_id, tree type) | |
4698 | { | |
4699 | const char *p = NULL; | |
4700 | const char *m = NULL; | |
4701 | switch (reduction_code) | |
4702 | { | |
4703 | case PLUS_EXPR: | |
4704 | case MULT_EXPR: | |
4705 | case MINUS_EXPR: | |
4706 | case BIT_AND_EXPR: | |
4707 | case BIT_XOR_EXPR: | |
4708 | case BIT_IOR_EXPR: | |
4709 | case TRUTH_ANDIF_EXPR: | |
4710 | case TRUTH_ORIF_EXPR: | |
4711 | reduction_id = ansi_opname (reduction_code); | |
4712 | break; | |
4713 | case MIN_EXPR: | |
4714 | p = "min"; | |
4715 | break; | |
4716 | case MAX_EXPR: | |
4717 | p = "max"; | |
4718 | break; | |
4719 | default: | |
4720 | break; | |
4721 | } | |
4722 | ||
4723 | if (p == NULL) | |
4724 | { | |
4725 | if (TREE_CODE (reduction_id) != IDENTIFIER_NODE) | |
4726 | return error_mark_node; | |
4727 | p = IDENTIFIER_POINTER (reduction_id); | |
4728 | } | |
4729 | ||
4730 | if (type != NULL_TREE) | |
4731 | m = mangle_type_string (TYPE_MAIN_VARIANT (type)); | |
4732 | ||
4733 | const char prefix[] = "omp declare reduction "; | |
4734 | size_t lenp = sizeof (prefix); | |
4735 | if (strncmp (p, prefix, lenp - 1) == 0) | |
4736 | lenp = 1; | |
4737 | size_t len = strlen (p); | |
4738 | size_t lenm = m ? strlen (m) + 1 : 0; | |
4739 | char *name = XALLOCAVEC (char, lenp + len + lenm); | |
4740 | if (lenp > 1) | |
4741 | memcpy (name, prefix, lenp - 1); | |
4742 | memcpy (name + lenp - 1, p, len + 1); | |
4743 | if (m) | |
4744 | { | |
4745 | name[lenp + len - 1] = '~'; | |
4746 | memcpy (name + lenp + len, m, lenm); | |
4747 | } | |
4748 | return get_identifier (name); | |
4749 | } | |
4750 | ||
4751 | /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial | |
4752 | FUNCTION_DECL or NULL_TREE if not found. */ | |
4753 | ||
4754 | static tree | |
4755 | omp_reduction_lookup (location_t loc, tree id, tree type, tree *baselinkp, | |
4756 | vec<tree> *ambiguousp) | |
4757 | { | |
4758 | tree orig_id = id; | |
4759 | tree baselink = NULL_TREE; | |
4760 | if (identifier_p (id)) | |
4761 | { | |
4762 | cp_id_kind idk; | |
4763 | bool nonint_cst_expression_p; | |
4764 | const char *error_msg; | |
4765 | id = omp_reduction_id (ERROR_MARK, id, type); | |
4766 | tree decl = lookup_name (id); | |
4767 | if (decl == NULL_TREE) | |
4768 | decl = error_mark_node; | |
4769 | id = finish_id_expression (id, decl, NULL_TREE, &idk, false, true, | |
4770 | &nonint_cst_expression_p, false, true, false, | |
4771 | false, &error_msg, loc); | |
4772 | if (idk == CP_ID_KIND_UNQUALIFIED | |
4773 | && identifier_p (id)) | |
4774 | { | |
4775 | vec<tree, va_gc> *args = NULL; | |
4776 | vec_safe_push (args, build_reference_type (type)); | |
4a7973e1 | 4777 | id = perform_koenig_lookup (id, args, tf_none); |
bc7bff74 | 4778 | } |
4779 | } | |
4780 | else if (TREE_CODE (id) == SCOPE_REF) | |
4781 | id = lookup_qualified_name (TREE_OPERAND (id, 0), | |
4782 | omp_reduction_id (ERROR_MARK, | |
4783 | TREE_OPERAND (id, 1), | |
4784 | type), | |
4785 | false, false); | |
4786 | tree fns = id; | |
4787 | if (id && is_overloaded_fn (id)) | |
4788 | id = get_fns (id); | |
4789 | for (; id; id = OVL_NEXT (id)) | |
4790 | { | |
4791 | tree fndecl = OVL_CURRENT (id); | |
4792 | if (TREE_CODE (fndecl) == FUNCTION_DECL) | |
4793 | { | |
4794 | tree argtype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl))); | |
4795 | if (same_type_p (TREE_TYPE (argtype), type)) | |
4796 | break; | |
4797 | } | |
4798 | } | |
4799 | if (id && BASELINK_P (fns)) | |
4800 | { | |
4801 | if (baselinkp) | |
4802 | *baselinkp = fns; | |
4803 | else | |
4804 | baselink = fns; | |
4805 | } | |
4806 | if (id == NULL_TREE && CLASS_TYPE_P (type) && TYPE_BINFO (type)) | |
4807 | { | |
4808 | vec<tree> ambiguous = vNULL; | |
4809 | tree binfo = TYPE_BINFO (type), base_binfo, ret = NULL_TREE; | |
4810 | unsigned int ix; | |
4811 | if (ambiguousp == NULL) | |
4812 | ambiguousp = &ambiguous; | |
4813 | for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++) | |
4814 | { | |
4815 | id = omp_reduction_lookup (loc, orig_id, BINFO_TYPE (base_binfo), | |
4816 | baselinkp ? baselinkp : &baselink, | |
4817 | ambiguousp); | |
4818 | if (id == NULL_TREE) | |
4819 | continue; | |
4820 | if (!ambiguousp->is_empty ()) | |
4821 | ambiguousp->safe_push (id); | |
4822 | else if (ret != NULL_TREE) | |
4823 | { | |
4824 | ambiguousp->safe_push (ret); | |
4825 | ambiguousp->safe_push (id); | |
4826 | ret = NULL_TREE; | |
4827 | } | |
4828 | else | |
4829 | ret = id; | |
4830 | } | |
4831 | if (ambiguousp != &ambiguous) | |
4832 | return ret; | |
4833 | if (!ambiguous.is_empty ()) | |
4834 | { | |
4835 | const char *str = _("candidates are:"); | |
4836 | unsigned int idx; | |
4837 | tree udr; | |
4838 | error_at (loc, "user defined reduction lookup is ambiguous"); | |
4839 | FOR_EACH_VEC_ELT (ambiguous, idx, udr) | |
4840 | { | |
4841 | inform (DECL_SOURCE_LOCATION (udr), "%s %#D", str, udr); | |
4842 | if (idx == 0) | |
4843 | str = get_spaces (str); | |
4844 | } | |
4845 | ambiguous.release (); | |
4846 | ret = error_mark_node; | |
4847 | baselink = NULL_TREE; | |
4848 | } | |
4849 | id = ret; | |
4850 | } | |
4851 | if (id && baselink) | |
4852 | perform_or_defer_access_check (BASELINK_BINFO (baselink), | |
4853 | id, id, tf_warning_or_error); | |
4854 | return id; | |
4855 | } | |
4856 | ||
4857 | /* Helper function for cp_parser_omp_declare_reduction_exprs | |
4858 | and tsubst_omp_udr. | |
4859 | Remove CLEANUP_STMT for data (omp_priv variable). | |
4860 | Also append INIT_EXPR for DECL_INITIAL of omp_priv after its | |
4861 | DECL_EXPR. */ | |
4862 | ||
4863 | tree | |
4864 | cp_remove_omp_priv_cleanup_stmt (tree *tp, int *walk_subtrees, void *data) | |
4865 | { | |
4866 | if (TYPE_P (*tp)) | |
4867 | *walk_subtrees = 0; | |
4868 | else if (TREE_CODE (*tp) == CLEANUP_STMT && CLEANUP_DECL (*tp) == (tree) data) | |
4869 | *tp = CLEANUP_BODY (*tp); | |
4870 | else if (TREE_CODE (*tp) == DECL_EXPR) | |
4871 | { | |
4872 | tree decl = DECL_EXPR_DECL (*tp); | |
4873 | if (!processing_template_decl | |
4874 | && decl == (tree) data | |
4875 | && DECL_INITIAL (decl) | |
4876 | && DECL_INITIAL (decl) != error_mark_node) | |
4877 | { | |
4878 | tree list = NULL_TREE; | |
4879 | append_to_statement_list_force (*tp, &list); | |
4880 | tree init_expr = build2 (INIT_EXPR, void_type_node, | |
4881 | decl, DECL_INITIAL (decl)); | |
4882 | DECL_INITIAL (decl) = NULL_TREE; | |
4883 | append_to_statement_list_force (init_expr, &list); | |
4884 | *tp = list; | |
4885 | } | |
4886 | } | |
4887 | return NULL_TREE; | |
4888 | } | |
4889 | ||
4890 | /* Data passed from cp_check_omp_declare_reduction to | |
4891 | cp_check_omp_declare_reduction_r. */ | |
4892 | ||
4893 | struct cp_check_omp_declare_reduction_data | |
4894 | { | |
4895 | location_t loc; | |
4896 | tree stmts[7]; | |
4897 | bool combiner_p; | |
4898 | }; | |
4899 | ||
4900 | /* Helper function for cp_check_omp_declare_reduction, called via | |
4901 | cp_walk_tree. */ | |
4902 | ||
4903 | static tree | |
4904 | cp_check_omp_declare_reduction_r (tree *tp, int *, void *data) | |
4905 | { | |
4906 | struct cp_check_omp_declare_reduction_data *udr_data | |
4907 | = (struct cp_check_omp_declare_reduction_data *) data; | |
4908 | if (SSA_VAR_P (*tp) | |
4909 | && !DECL_ARTIFICIAL (*tp) | |
4910 | && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 0 : 3]) | |
4911 | && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 1 : 4])) | |
4912 | { | |
4913 | location_t loc = udr_data->loc; | |
4914 | if (udr_data->combiner_p) | |
4915 | error_at (loc, "%<#pragma omp declare reduction%> combiner refers to " | |
4916 | "variable %qD which is not %<omp_out%> nor %<omp_in%>", | |
4917 | *tp); | |
4918 | else | |
4919 | error_at (loc, "%<#pragma omp declare reduction%> initializer refers " | |
4920 | "to variable %qD which is not %<omp_priv%> nor " | |
4921 | "%<omp_orig%>", | |
4922 | *tp); | |
4923 | return *tp; | |
4924 | } | |
4925 | return NULL_TREE; | |
4926 | } | |
4927 | ||
4928 | /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions. */ | |
4929 | ||
4930 | void | |
4931 | cp_check_omp_declare_reduction (tree udr) | |
4932 | { | |
4933 | tree type = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr))); | |
4934 | gcc_assert (TREE_CODE (type) == REFERENCE_TYPE); | |
4935 | type = TREE_TYPE (type); | |
4936 | int i; | |
4937 | location_t loc = DECL_SOURCE_LOCATION (udr); | |
4938 | ||
4939 | if (type == error_mark_node) | |
4940 | return; | |
4941 | if (ARITHMETIC_TYPE_P (type)) | |
4942 | { | |
4943 | static enum tree_code predef_codes[] | |
4944 | = { PLUS_EXPR, MULT_EXPR, MINUS_EXPR, BIT_AND_EXPR, BIT_XOR_EXPR, | |
4945 | BIT_IOR_EXPR, TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR }; | |
4946 | for (i = 0; i < 8; i++) | |
4947 | { | |
4948 | tree id = omp_reduction_id (predef_codes[i], NULL_TREE, NULL_TREE); | |
4949 | const char *n1 = IDENTIFIER_POINTER (DECL_NAME (udr)); | |
4950 | const char *n2 = IDENTIFIER_POINTER (id); | |
4951 | if (strncmp (n1, n2, IDENTIFIER_LENGTH (id)) == 0 | |
4952 | && (n1[IDENTIFIER_LENGTH (id)] == '~' | |
4953 | || n1[IDENTIFIER_LENGTH (id)] == '\0')) | |
4954 | break; | |
4955 | } | |
4956 | ||
4957 | if (i == 8 | |
4958 | && TREE_CODE (type) != COMPLEX_EXPR) | |
4959 | { | |
4960 | const char prefix_minmax[] = "omp declare reduction m"; | |
4961 | size_t prefix_size = sizeof (prefix_minmax) - 1; | |
4962 | const char *n = IDENTIFIER_POINTER (DECL_NAME (udr)); | |
4963 | if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr)), | |
4964 | prefix_minmax, prefix_size) == 0 | |
4965 | && ((n[prefix_size] == 'i' && n[prefix_size + 1] == 'n') | |
4966 | || (n[prefix_size] == 'a' && n[prefix_size + 1] == 'x')) | |
4967 | && (n[prefix_size + 2] == '~' || n[prefix_size + 2] == '\0')) | |
4968 | i = 0; | |
4969 | } | |
4970 | if (i < 8) | |
4971 | { | |
4972 | error_at (loc, "predeclared arithmetic type %qT in " | |
4973 | "%<#pragma omp declare reduction%>", type); | |
4974 | return; | |
4975 | } | |
4976 | } | |
4977 | else if (TREE_CODE (type) == FUNCTION_TYPE | |
4978 | || TREE_CODE (type) == METHOD_TYPE | |
4979 | || TREE_CODE (type) == ARRAY_TYPE) | |
4980 | { | |
4981 | error_at (loc, "function or array type %qT in " | |
4982 | "%<#pragma omp declare reduction%>", type); | |
4983 | return; | |
4984 | } | |
4985 | else if (TREE_CODE (type) == REFERENCE_TYPE) | |
4986 | { | |
4987 | error_at (loc, "reference type %qT in %<#pragma omp declare reduction%>", | |
4988 | type); | |
4989 | return; | |
4990 | } | |
4991 | else if (TYPE_QUALS_NO_ADDR_SPACE (type)) | |
4992 | { | |
4993 | error_at (loc, "const, volatile or __restrict qualified type %qT in " | |
4994 | "%<#pragma omp declare reduction%>", type); | |
4995 | return; | |
4996 | } | |
4997 | ||
4998 | tree body = DECL_SAVED_TREE (udr); | |
4999 | if (body == NULL_TREE || TREE_CODE (body) != STATEMENT_LIST) | |
5000 | return; | |
5001 | ||
5002 | tree_stmt_iterator tsi; | |
5003 | struct cp_check_omp_declare_reduction_data data; | |
5004 | memset (data.stmts, 0, sizeof data.stmts); | |
5005 | for (i = 0, tsi = tsi_start (body); | |
5006 | i < 7 && !tsi_end_p (tsi); | |
5007 | i++, tsi_next (&tsi)) | |
5008 | data.stmts[i] = tsi_stmt (tsi); | |
5009 | data.loc = loc; | |
5010 | gcc_assert (tsi_end_p (tsi)); | |
5011 | if (i >= 3) | |
5012 | { | |
5013 | gcc_assert (TREE_CODE (data.stmts[0]) == DECL_EXPR | |
5014 | && TREE_CODE (data.stmts[1]) == DECL_EXPR); | |
5015 | if (TREE_NO_WARNING (DECL_EXPR_DECL (data.stmts[0]))) | |
5016 | return; | |
5017 | data.combiner_p = true; | |
5018 | if (cp_walk_tree (&data.stmts[2], cp_check_omp_declare_reduction_r, | |
5019 | &data, NULL)) | |
5020 | TREE_NO_WARNING (DECL_EXPR_DECL (data.stmts[0])) = 1; | |
5021 | } | |
5022 | if (i >= 6) | |
5023 | { | |
5024 | gcc_assert (TREE_CODE (data.stmts[3]) == DECL_EXPR | |
5025 | && TREE_CODE (data.stmts[4]) == DECL_EXPR); | |
5026 | data.combiner_p = false; | |
5027 | if (cp_walk_tree (&data.stmts[5], cp_check_omp_declare_reduction_r, | |
5028 | &data, NULL) | |
5029 | || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data.stmts[3])), | |
5030 | cp_check_omp_declare_reduction_r, &data, NULL)) | |
5031 | TREE_NO_WARNING (DECL_EXPR_DECL (data.stmts[0])) = 1; | |
5032 | if (i == 7) | |
5033 | gcc_assert (TREE_CODE (data.stmts[6]) == DECL_EXPR); | |
5034 | } | |
5035 | } | |
5036 | ||
5037 | /* Helper function of finish_omp_clauses. Clone STMT as if we were making | |
5038 | an inline call. But, remap | |
5039 | the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER | |
5040 | and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */ | |
5041 | ||
5042 | static tree | |
5043 | clone_omp_udr (tree stmt, tree omp_decl1, tree omp_decl2, | |
5044 | tree decl, tree placeholder) | |
5045 | { | |
5046 | copy_body_data id; | |
06ecf488 | 5047 | hash_map<tree, tree> decl_map; |
bc7bff74 | 5048 | |
06ecf488 | 5049 | decl_map.put (omp_decl1, placeholder); |
5050 | decl_map.put (omp_decl2, decl); | |
bc7bff74 | 5051 | memset (&id, 0, sizeof (id)); |
5052 | id.src_fn = DECL_CONTEXT (omp_decl1); | |
5053 | id.dst_fn = current_function_decl; | |
5054 | id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn); | |
06ecf488 | 5055 | id.decl_map = &decl_map; |
bc7bff74 | 5056 | |
5057 | id.copy_decl = copy_decl_no_change; | |
5058 | id.transform_call_graph_edges = CB_CGE_DUPLICATE; | |
5059 | id.transform_new_cfg = true; | |
5060 | id.transform_return_to_modify = false; | |
5061 | id.transform_lang_insert_block = NULL; | |
5062 | id.eh_lp_nr = 0; | |
5063 | walk_tree (&stmt, copy_tree_body_r, &id, NULL); | |
bc7bff74 | 5064 | return stmt; |
5065 | } | |
5066 | ||
5067 | /* Helper function of finish_omp_clauses, called via cp_walk_tree. | |
5068 | Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */ | |
5069 | ||
5070 | static tree | |
5071 | find_omp_placeholder_r (tree *tp, int *, void *data) | |
5072 | { | |
5073 | if (*tp == (tree) data) | |
5074 | return *tp; | |
5075 | return NULL_TREE; | |
5076 | } | |
5077 | ||
5078 | /* Helper function of finish_omp_clauses. Handle OMP_CLAUSE_REDUCTION C. | |
5079 | Return true if there is some error and the clause should be removed. */ | |
5080 | ||
5081 | static bool | |
5082 | finish_omp_reduction_clause (tree c, bool *need_default_ctor, bool *need_dtor) | |
5083 | { | |
5084 | tree t = OMP_CLAUSE_DECL (c); | |
5085 | bool predefined = false; | |
5086 | tree type = TREE_TYPE (t); | |
5087 | if (TREE_CODE (type) == REFERENCE_TYPE) | |
5088 | type = TREE_TYPE (type); | |
dac04683 | 5089 | if (type == error_mark_node) |
5090 | return true; | |
5091 | else if (ARITHMETIC_TYPE_P (type)) | |
bc7bff74 | 5092 | switch (OMP_CLAUSE_REDUCTION_CODE (c)) |
5093 | { | |
5094 | case PLUS_EXPR: | |
5095 | case MULT_EXPR: | |
5096 | case MINUS_EXPR: | |
5097 | predefined = true; | |
5098 | break; | |
5099 | case MIN_EXPR: | |
5100 | case MAX_EXPR: | |
5101 | if (TREE_CODE (type) == COMPLEX_TYPE) | |
5102 | break; | |
5103 | predefined = true; | |
5104 | break; | |
5105 | case BIT_AND_EXPR: | |
5106 | case BIT_IOR_EXPR: | |
5107 | case BIT_XOR_EXPR: | |
d6779b5f | 5108 | if (FLOAT_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE) |
5109 | break; | |
5110 | predefined = true; | |
5111 | break; | |
bc7bff74 | 5112 | case TRUTH_ANDIF_EXPR: |
5113 | case TRUTH_ORIF_EXPR: | |
5114 | if (FLOAT_TYPE_P (type)) | |
5115 | break; | |
5116 | predefined = true; | |
5117 | break; | |
5118 | default: | |
5119 | break; | |
5120 | } | |
5121 | else if (TREE_CODE (type) == ARRAY_TYPE || TYPE_READONLY (type)) | |
5122 | { | |
5123 | error ("%qE has invalid type for %<reduction%>", t); | |
5124 | return true; | |
5125 | } | |
5126 | else if (!processing_template_decl) | |
5127 | { | |
5128 | t = require_complete_type (t); | |
5129 | if (t == error_mark_node) | |
5130 | return true; | |
5131 | OMP_CLAUSE_DECL (c) = t; | |
5132 | } | |
5133 | ||
5134 | if (predefined) | |
5135 | { | |
5136 | OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE; | |
5137 | return false; | |
5138 | } | |
5139 | else if (processing_template_decl) | |
5140 | return false; | |
5141 | ||
5142 | tree id = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c); | |
5143 | ||
5144 | type = TYPE_MAIN_VARIANT (TREE_TYPE (t)); | |
5145 | if (TREE_CODE (type) == REFERENCE_TYPE) | |
5146 | type = TREE_TYPE (type); | |
5147 | OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE; | |
5148 | if (id == NULL_TREE) | |
5149 | id = omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c), | |
5150 | NULL_TREE, NULL_TREE); | |
5151 | id = omp_reduction_lookup (OMP_CLAUSE_LOCATION (c), id, type, NULL, NULL); | |
5152 | if (id) | |
5153 | { | |
5154 | if (id == error_mark_node) | |
5155 | return true; | |
5156 | id = OVL_CURRENT (id); | |
5157 | mark_used (id); | |
5158 | tree body = DECL_SAVED_TREE (id); | |
eed21ac4 | 5159 | if (!body) |
5160 | return true; | |
bc7bff74 | 5161 | if (TREE_CODE (body) == STATEMENT_LIST) |
5162 | { | |
5163 | tree_stmt_iterator tsi; | |
5164 | tree placeholder = NULL_TREE; | |
5165 | int i; | |
5166 | tree stmts[7]; | |
5167 | tree atype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id))); | |
5168 | atype = TREE_TYPE (atype); | |
5169 | bool need_static_cast = !same_type_p (type, atype); | |
5170 | memset (stmts, 0, sizeof stmts); | |
5171 | for (i = 0, tsi = tsi_start (body); | |
5172 | i < 7 && !tsi_end_p (tsi); | |
5173 | i++, tsi_next (&tsi)) | |
5174 | stmts[i] = tsi_stmt (tsi); | |
5175 | gcc_assert (tsi_end_p (tsi)); | |
5176 | ||
5177 | if (i >= 3) | |
5178 | { | |
5179 | gcc_assert (TREE_CODE (stmts[0]) == DECL_EXPR | |
5180 | && TREE_CODE (stmts[1]) == DECL_EXPR); | |
5181 | placeholder = build_lang_decl (VAR_DECL, NULL_TREE, type); | |
5182 | DECL_ARTIFICIAL (placeholder) = 1; | |
5183 | DECL_IGNORED_P (placeholder) = 1; | |
5184 | OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = placeholder; | |
5185 | if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[0]))) | |
5186 | cxx_mark_addressable (placeholder); | |
5187 | if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[1])) | |
5188 | && TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c))) | |
5189 | != REFERENCE_TYPE) | |
5190 | cxx_mark_addressable (OMP_CLAUSE_DECL (c)); | |
5191 | tree omp_out = placeholder; | |
5192 | tree omp_in = convert_from_reference (OMP_CLAUSE_DECL (c)); | |
5193 | if (need_static_cast) | |
5194 | { | |
5195 | tree rtype = build_reference_type (atype); | |
5196 | omp_out = build_static_cast (rtype, omp_out, | |
5197 | tf_warning_or_error); | |
5198 | omp_in = build_static_cast (rtype, omp_in, | |
5199 | tf_warning_or_error); | |
5200 | if (omp_out == error_mark_node || omp_in == error_mark_node) | |
5201 | return true; | |
5202 | omp_out = convert_from_reference (omp_out); | |
5203 | omp_in = convert_from_reference (omp_in); | |
5204 | } | |
5205 | OMP_CLAUSE_REDUCTION_MERGE (c) | |
5206 | = clone_omp_udr (stmts[2], DECL_EXPR_DECL (stmts[0]), | |
5207 | DECL_EXPR_DECL (stmts[1]), omp_in, omp_out); | |
5208 | } | |
5209 | if (i >= 6) | |
5210 | { | |
5211 | gcc_assert (TREE_CODE (stmts[3]) == DECL_EXPR | |
5212 | && TREE_CODE (stmts[4]) == DECL_EXPR); | |
5213 | if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[3]))) | |
5214 | cxx_mark_addressable (OMP_CLAUSE_DECL (c)); | |
5215 | if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[4]))) | |
5216 | cxx_mark_addressable (placeholder); | |
5217 | tree omp_priv = convert_from_reference (OMP_CLAUSE_DECL (c)); | |
5218 | tree omp_orig = placeholder; | |
5219 | if (need_static_cast) | |
5220 | { | |
5221 | if (i == 7) | |
5222 | { | |
5223 | error_at (OMP_CLAUSE_LOCATION (c), | |
5224 | "user defined reduction with constructor " | |
5225 | "initializer for base class %qT", atype); | |
5226 | return true; | |
5227 | } | |
5228 | tree rtype = build_reference_type (atype); | |
5229 | omp_priv = build_static_cast (rtype, omp_priv, | |
5230 | tf_warning_or_error); | |
5231 | omp_orig = build_static_cast (rtype, omp_orig, | |
5232 | tf_warning_or_error); | |
5233 | if (omp_priv == error_mark_node | |
5234 | || omp_orig == error_mark_node) | |
5235 | return true; | |
5236 | omp_priv = convert_from_reference (omp_priv); | |
5237 | omp_orig = convert_from_reference (omp_orig); | |
5238 | } | |
5239 | if (i == 6) | |
5240 | *need_default_ctor = true; | |
5241 | OMP_CLAUSE_REDUCTION_INIT (c) | |
5242 | = clone_omp_udr (stmts[5], DECL_EXPR_DECL (stmts[4]), | |
5243 | DECL_EXPR_DECL (stmts[3]), | |
5244 | omp_priv, omp_orig); | |
5245 | if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c), | |
5246 | find_omp_placeholder_r, placeholder, NULL)) | |
5247 | OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c) = 1; | |
5248 | } | |
5249 | else if (i >= 3) | |
5250 | { | |
5251 | if (CLASS_TYPE_P (type) && !pod_type_p (type)) | |
5252 | *need_default_ctor = true; | |
5253 | else | |
5254 | { | |
5255 | tree init; | |
5256 | tree v = convert_from_reference (t); | |
5257 | if (AGGREGATE_TYPE_P (TREE_TYPE (v))) | |
5258 | init = build_constructor (TREE_TYPE (v), NULL); | |
5259 | else | |
5260 | init = fold_convert (TREE_TYPE (v), integer_zero_node); | |
5261 | OMP_CLAUSE_REDUCTION_INIT (c) | |
5262 | = build2 (INIT_EXPR, TREE_TYPE (v), v, init); | |
5263 | } | |
5264 | } | |
5265 | } | |
5266 | } | |
5267 | if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)) | |
5268 | *need_dtor = true; | |
5269 | else | |
5270 | { | |
5271 | error ("user defined reduction not found for %qD", t); | |
5272 | return true; | |
5273 | } | |
5274 | return false; | |
5275 | } | |
5276 | ||
8487df40 | 5277 | /* For all elements of CLAUSES, validate them vs OpenMP constraints. |
5278 | Remove any elements from the list that are invalid. */ | |
5279 | ||
5280 | tree | |
5281 | finish_omp_clauses (tree clauses) | |
5282 | { | |
5283 | bitmap_head generic_head, firstprivate_head, lastprivate_head; | |
bc7bff74 | 5284 | bitmap_head aligned_head; |
6ce915ef | 5285 | tree c, t, *pc; |
bc7bff74 | 5286 | bool branch_seen = false; |
5287 | bool copyprivate_seen = false; | |
8487df40 | 5288 | |
5289 | bitmap_obstack_initialize (NULL); | |
5290 | bitmap_initialize (&generic_head, &bitmap_default_obstack); | |
5291 | bitmap_initialize (&firstprivate_head, &bitmap_default_obstack); | |
5292 | bitmap_initialize (&lastprivate_head, &bitmap_default_obstack); | |
bc7bff74 | 5293 | bitmap_initialize (&aligned_head, &bitmap_default_obstack); |
8487df40 | 5294 | |
5295 | for (pc = &clauses, c = clauses; c ; c = *pc) | |
5296 | { | |
5297 | bool remove = false; | |
5298 | ||
5299 | switch (OMP_CLAUSE_CODE (c)) | |
5300 | { | |
5301 | case OMP_CLAUSE_SHARED: | |
8487df40 | 5302 | goto check_dup_generic; |
5303 | case OMP_CLAUSE_PRIVATE: | |
8487df40 | 5304 | goto check_dup_generic; |
5305 | case OMP_CLAUSE_REDUCTION: | |
8487df40 | 5306 | goto check_dup_generic; |
5307 | case OMP_CLAUSE_COPYPRIVATE: | |
bc7bff74 | 5308 | copyprivate_seen = true; |
8487df40 | 5309 | goto check_dup_generic; |
5310 | case OMP_CLAUSE_COPYIN: | |
bc7bff74 | 5311 | goto check_dup_generic; |
5312 | case OMP_CLAUSE_LINEAR: | |
5313 | t = OMP_CLAUSE_DECL (c); | |
5314 | if (!type_dependent_expression_p (t) | |
5315 | && !INTEGRAL_TYPE_P (TREE_TYPE (t)) | |
5316 | && TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE) | |
5317 | { | |
5318 | error ("linear clause applied to non-integral non-pointer " | |
5319 | "variable with %qT type", TREE_TYPE (t)); | |
5320 | remove = true; | |
5321 | break; | |
5322 | } | |
5323 | t = OMP_CLAUSE_LINEAR_STEP (c); | |
5324 | if (t == NULL_TREE) | |
5325 | t = integer_one_node; | |
5326 | if (t == error_mark_node) | |
df205251 | 5327 | { |
5328 | remove = true; | |
5329 | break; | |
5330 | } | |
bc7bff74 | 5331 | else if (!type_dependent_expression_p (t) |
5332 | && !INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
5333 | { | |
5334 | error ("linear step expression must be integral"); | |
5335 | remove = true; | |
df205251 | 5336 | break; |
bc7bff74 | 5337 | } |
5338 | else | |
5339 | { | |
5340 | t = mark_rvalue_use (t); | |
5341 | if (!processing_template_decl) | |
5342 | { | |
d09768a4 | 5343 | if (TREE_CODE (OMP_CLAUSE_DECL (c)) == PARM_DECL) |
5344 | t = maybe_constant_value (t); | |
bc7bff74 | 5345 | t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); |
5346 | if (TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c))) | |
5347 | == POINTER_TYPE) | |
5348 | { | |
5349 | t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR, | |
5350 | OMP_CLAUSE_DECL (c), t); | |
5351 | t = fold_build2_loc (OMP_CLAUSE_LOCATION (c), | |
5352 | MINUS_EXPR, sizetype, t, | |
5353 | OMP_CLAUSE_DECL (c)); | |
5354 | if (t == error_mark_node) | |
df205251 | 5355 | { |
5356 | remove = true; | |
5357 | break; | |
5358 | } | |
bc7bff74 | 5359 | } |
9580cb79 | 5360 | else |
5361 | t = fold_convert (TREE_TYPE (OMP_CLAUSE_DECL (c)), t); | |
bc7bff74 | 5362 | } |
5363 | OMP_CLAUSE_LINEAR_STEP (c) = t; | |
5364 | } | |
8487df40 | 5365 | goto check_dup_generic; |
5366 | check_dup_generic: | |
5367 | t = OMP_CLAUSE_DECL (c); | |
80a58eb0 | 5368 | if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL) |
8487df40 | 5369 | { |
5370 | if (processing_template_decl) | |
5371 | break; | |
6c1a068b | 5372 | if (DECL_P (t)) |
bc7bff74 | 5373 | error ("%qD is not a variable in clause %qs", t, |
5374 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
6c1a068b | 5375 | else |
bc7bff74 | 5376 | error ("%qE is not a variable in clause %qs", t, |
5377 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
8487df40 | 5378 | remove = true; |
5379 | } | |
5380 | else if (bitmap_bit_p (&generic_head, DECL_UID (t)) | |
5381 | || bitmap_bit_p (&firstprivate_head, DECL_UID (t)) | |
5382 | || bitmap_bit_p (&lastprivate_head, DECL_UID (t))) | |
5383 | { | |
6c1a068b | 5384 | error ("%qD appears more than once in data clauses", t); |
8487df40 | 5385 | remove = true; |
5386 | } | |
5387 | else | |
5388 | bitmap_set_bit (&generic_head, DECL_UID (t)); | |
5389 | break; | |
5390 | ||
5391 | case OMP_CLAUSE_FIRSTPRIVATE: | |
5392 | t = OMP_CLAUSE_DECL (c); | |
80a58eb0 | 5393 | if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL) |
8487df40 | 5394 | { |
5395 | if (processing_template_decl) | |
5396 | break; | |
fc47df68 | 5397 | if (DECL_P (t)) |
5398 | error ("%qD is not a variable in clause %<firstprivate%>", t); | |
5399 | else | |
5400 | error ("%qE is not a variable in clause %<firstprivate%>", t); | |
8487df40 | 5401 | remove = true; |
5402 | } | |
5403 | else if (bitmap_bit_p (&generic_head, DECL_UID (t)) | |
5404 | || bitmap_bit_p (&firstprivate_head, DECL_UID (t))) | |
5405 | { | |
fc47df68 | 5406 | error ("%qD appears more than once in data clauses", t); |
8487df40 | 5407 | remove = true; |
5408 | } | |
5409 | else | |
5410 | bitmap_set_bit (&firstprivate_head, DECL_UID (t)); | |
5411 | break; | |
5412 | ||
5413 | case OMP_CLAUSE_LASTPRIVATE: | |
5414 | t = OMP_CLAUSE_DECL (c); | |
80a58eb0 | 5415 | if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL) |
8487df40 | 5416 | { |
5417 | if (processing_template_decl) | |
5418 | break; | |
fc47df68 | 5419 | if (DECL_P (t)) |
5420 | error ("%qD is not a variable in clause %<lastprivate%>", t); | |
5421 | else | |
5422 | error ("%qE is not a variable in clause %<lastprivate%>", t); | |
8487df40 | 5423 | remove = true; |
5424 | } | |
5425 | else if (bitmap_bit_p (&generic_head, DECL_UID (t)) | |
5426 | || bitmap_bit_p (&lastprivate_head, DECL_UID (t))) | |
5427 | { | |
fc47df68 | 5428 | error ("%qD appears more than once in data clauses", t); |
8487df40 | 5429 | remove = true; |
5430 | } | |
5431 | else | |
5432 | bitmap_set_bit (&lastprivate_head, DECL_UID (t)); | |
5433 | break; | |
5434 | ||
5435 | case OMP_CLAUSE_IF: | |
5436 | t = OMP_CLAUSE_IF_EXPR (c); | |
5437 | t = maybe_convert_cond (t); | |
5438 | if (t == error_mark_node) | |
5439 | remove = true; | |
a1e95a65 | 5440 | else if (!processing_template_decl) |
5441 | t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); | |
8487df40 | 5442 | OMP_CLAUSE_IF_EXPR (c) = t; |
5443 | break; | |
5444 | ||
2169f33b | 5445 | case OMP_CLAUSE_FINAL: |
5446 | t = OMP_CLAUSE_FINAL_EXPR (c); | |
5447 | t = maybe_convert_cond (t); | |
5448 | if (t == error_mark_node) | |
5449 | remove = true; | |
a1e95a65 | 5450 | else if (!processing_template_decl) |
5451 | t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); | |
2169f33b | 5452 | OMP_CLAUSE_FINAL_EXPR (c) = t; |
5453 | break; | |
5454 | ||
8487df40 | 5455 | case OMP_CLAUSE_NUM_THREADS: |
5456 | t = OMP_CLAUSE_NUM_THREADS_EXPR (c); | |
5457 | if (t == error_mark_node) | |
5458 | remove = true; | |
a8cb6ebc | 5459 | else if (!type_dependent_expression_p (t) |
5460 | && !INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
8487df40 | 5461 | { |
5462 | error ("num_threads expression must be integral"); | |
5463 | remove = true; | |
5464 | } | |
80678da6 | 5465 | else |
a1e95a65 | 5466 | { |
5467 | t = mark_rvalue_use (t); | |
5468 | if (!processing_template_decl) | |
5469 | t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); | |
5470 | OMP_CLAUSE_NUM_THREADS_EXPR (c) = t; | |
5471 | } | |
8487df40 | 5472 | break; |
5473 | ||
5474 | case OMP_CLAUSE_SCHEDULE: | |
5475 | t = OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c); | |
5476 | if (t == NULL) | |
5477 | ; | |
5478 | else if (t == error_mark_node) | |
5479 | remove = true; | |
a8cb6ebc | 5480 | else if (!type_dependent_expression_p (t) |
40750995 | 5481 | && (OMP_CLAUSE_SCHEDULE_KIND (c) |
5482 | != OMP_CLAUSE_SCHEDULE_CILKFOR) | |
a8cb6ebc | 5483 | && !INTEGRAL_TYPE_P (TREE_TYPE (t))) |
8487df40 | 5484 | { |
5485 | error ("schedule chunk size expression must be integral"); | |
5486 | remove = true; | |
5487 | } | |
80678da6 | 5488 | else |
a1e95a65 | 5489 | { |
5490 | t = mark_rvalue_use (t); | |
5491 | if (!processing_template_decl) | |
40750995 | 5492 | { |
5493 | if (OMP_CLAUSE_SCHEDULE_KIND (c) | |
5494 | == OMP_CLAUSE_SCHEDULE_CILKFOR) | |
5495 | { | |
5496 | t = convert_to_integer (long_integer_type_node, t); | |
5497 | if (t == error_mark_node) | |
5498 | { | |
5499 | remove = true; | |
5500 | break; | |
5501 | } | |
5502 | } | |
5503 | t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); | |
5504 | } | |
a1e95a65 | 5505 | OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t; |
5506 | } | |
8487df40 | 5507 | break; |
5508 | ||
bc7bff74 | 5509 | case OMP_CLAUSE_SIMDLEN: |
5510 | case OMP_CLAUSE_SAFELEN: | |
5511 | t = OMP_CLAUSE_OPERAND (c, 0); | |
5512 | if (t == error_mark_node) | |
5513 | remove = true; | |
5514 | else if (!type_dependent_expression_p (t) | |
5515 | && !INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
5516 | { | |
5517 | error ("%qs length expression must be integral", | |
5518 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
5519 | remove = true; | |
5520 | } | |
5521 | else | |
5522 | { | |
5523 | t = mark_rvalue_use (t); | |
5524 | t = maybe_constant_value (t); | |
5525 | if (!processing_template_decl) | |
5526 | { | |
5527 | if (TREE_CODE (t) != INTEGER_CST | |
5528 | || tree_int_cst_sgn (t) != 1) | |
5529 | { | |
5530 | error ("%qs length expression must be positive constant" | |
5531 | " integer expression", | |
5532 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
5533 | remove = true; | |
5534 | } | |
5535 | } | |
5536 | OMP_CLAUSE_OPERAND (c, 0) = t; | |
5537 | } | |
5538 | break; | |
5539 | ||
5540 | case OMP_CLAUSE_NUM_TEAMS: | |
5541 | t = OMP_CLAUSE_NUM_TEAMS_EXPR (c); | |
5542 | if (t == error_mark_node) | |
5543 | remove = true; | |
5544 | else if (!type_dependent_expression_p (t) | |
5545 | && !INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
5546 | { | |
5547 | error ("%<num_teams%> expression must be integral"); | |
5548 | remove = true; | |
5549 | } | |
5550 | else | |
5551 | { | |
5552 | t = mark_rvalue_use (t); | |
5553 | if (!processing_template_decl) | |
5554 | t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); | |
5555 | OMP_CLAUSE_NUM_TEAMS_EXPR (c) = t; | |
5556 | } | |
5557 | break; | |
5558 | ||
ca4c3545 | 5559 | case OMP_CLAUSE_ASYNC: |
5560 | t = OMP_CLAUSE_ASYNC_EXPR (c); | |
5561 | if (t == error_mark_node) | |
5562 | remove = true; | |
5563 | else if (!type_dependent_expression_p (t) | |
5564 | && !INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
5565 | { | |
5566 | error ("%<async%> expression must be integral"); | |
5567 | remove = true; | |
5568 | } | |
5569 | else | |
5570 | { | |
5571 | t = mark_rvalue_use (t); | |
5572 | if (!processing_template_decl) | |
5573 | t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); | |
5574 | OMP_CLAUSE_ASYNC_EXPR (c) = t; | |
5575 | } | |
5576 | break; | |
5577 | ||
5578 | case OMP_CLAUSE_VECTOR_LENGTH: | |
5579 | t = OMP_CLAUSE_VECTOR_LENGTH_EXPR (c); | |
5580 | t = maybe_convert_cond (t); | |
5581 | if (t == error_mark_node) | |
5582 | remove = true; | |
5583 | else if (!processing_template_decl) | |
5584 | t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); | |
5585 | OMP_CLAUSE_VECTOR_LENGTH_EXPR (c) = t; | |
5586 | break; | |
5587 | ||
5588 | case OMP_CLAUSE_WAIT: | |
5589 | t = OMP_CLAUSE_WAIT_EXPR (c); | |
5590 | if (t == error_mark_node) | |
5591 | remove = true; | |
5592 | else if (!processing_template_decl) | |
5593 | t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); | |
5594 | OMP_CLAUSE_WAIT_EXPR (c) = t; | |
5595 | break; | |
5596 | ||
bc7bff74 | 5597 | case OMP_CLAUSE_THREAD_LIMIT: |
5598 | t = OMP_CLAUSE_THREAD_LIMIT_EXPR (c); | |
5599 | if (t == error_mark_node) | |
5600 | remove = true; | |
5601 | else if (!type_dependent_expression_p (t) | |
5602 | && !INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
5603 | { | |
5604 | error ("%<thread_limit%> expression must be integral"); | |
5605 | remove = true; | |
5606 | } | |
5607 | else | |
5608 | { | |
5609 | t = mark_rvalue_use (t); | |
5610 | if (!processing_template_decl) | |
5611 | t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); | |
5612 | OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t; | |
5613 | } | |
5614 | break; | |
5615 | ||
5616 | case OMP_CLAUSE_DEVICE: | |
5617 | t = OMP_CLAUSE_DEVICE_ID (c); | |
5618 | if (t == error_mark_node) | |
5619 | remove = true; | |
5620 | else if (!type_dependent_expression_p (t) | |
5621 | && !INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
5622 | { | |
5623 | error ("%<device%> id must be integral"); | |
5624 | remove = true; | |
5625 | } | |
5626 | else | |
5627 | { | |
5628 | t = mark_rvalue_use (t); | |
5629 | if (!processing_template_decl) | |
5630 | t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); | |
5631 | OMP_CLAUSE_DEVICE_ID (c) = t; | |
5632 | } | |
5633 | break; | |
5634 | ||
5635 | case OMP_CLAUSE_DIST_SCHEDULE: | |
5636 | t = OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c); | |
5637 | if (t == NULL) | |
5638 | ; | |
5639 | else if (t == error_mark_node) | |
5640 | remove = true; | |
5641 | else if (!type_dependent_expression_p (t) | |
5642 | && !INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
5643 | { | |
5644 | error ("%<dist_schedule%> chunk size expression must be " | |
5645 | "integral"); | |
5646 | remove = true; | |
5647 | } | |
5648 | else | |
5649 | { | |
5650 | t = mark_rvalue_use (t); | |
5651 | if (!processing_template_decl) | |
5652 | t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); | |
5653 | OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t; | |
5654 | } | |
5655 | break; | |
5656 | ||
5657 | case OMP_CLAUSE_ALIGNED: | |
5658 | t = OMP_CLAUSE_DECL (c); | |
f4ae4202 | 5659 | if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL) |
bc7bff74 | 5660 | { |
5661 | if (processing_template_decl) | |
5662 | break; | |
5663 | if (DECL_P (t)) | |
5664 | error ("%qD is not a variable in %<aligned%> clause", t); | |
5665 | else | |
5666 | error ("%qE is not a variable in %<aligned%> clause", t); | |
5667 | remove = true; | |
5668 | } | |
23871d0c | 5669 | else if (!type_dependent_expression_p (t) |
5670 | && TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE | |
5671 | && TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE | |
5672 | && (TREE_CODE (TREE_TYPE (t)) != REFERENCE_TYPE | |
5673 | || (!POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (t))) | |
5674 | && (TREE_CODE (TREE_TYPE (TREE_TYPE (t))) | |
5675 | != ARRAY_TYPE)))) | |
5676 | { | |
5677 | error_at (OMP_CLAUSE_LOCATION (c), | |
5678 | "%qE in %<aligned%> clause is neither a pointer nor " | |
5679 | "an array nor a reference to pointer or array", t); | |
5680 | remove = true; | |
5681 | } | |
bc7bff74 | 5682 | else if (bitmap_bit_p (&aligned_head, DECL_UID (t))) |
5683 | { | |
5684 | error ("%qD appears more than once in %<aligned%> clauses", t); | |
5685 | remove = true; | |
5686 | } | |
5687 | else | |
5688 | bitmap_set_bit (&aligned_head, DECL_UID (t)); | |
5689 | t = OMP_CLAUSE_ALIGNED_ALIGNMENT (c); | |
5690 | if (t == error_mark_node) | |
5691 | remove = true; | |
5692 | else if (t == NULL_TREE) | |
5693 | break; | |
5694 | else if (!type_dependent_expression_p (t) | |
5695 | && !INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
5696 | { | |
5697 | error ("%<aligned%> clause alignment expression must " | |
5698 | "be integral"); | |
5699 | remove = true; | |
5700 | } | |
5701 | else | |
5702 | { | |
5703 | t = mark_rvalue_use (t); | |
5704 | t = maybe_constant_value (t); | |
5705 | if (!processing_template_decl) | |
5706 | { | |
5707 | if (TREE_CODE (t) != INTEGER_CST | |
5708 | || tree_int_cst_sgn (t) != 1) | |
5709 | { | |
5710 | error ("%<aligned%> clause alignment expression must be " | |
5711 | "positive constant integer expression"); | |
5712 | remove = true; | |
5713 | } | |
5714 | } | |
5715 | OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = t; | |
5716 | } | |
5717 | break; | |
5718 | ||
5719 | case OMP_CLAUSE_DEPEND: | |
5720 | t = OMP_CLAUSE_DECL (c); | |
5721 | if (TREE_CODE (t) == TREE_LIST) | |
5722 | { | |
5723 | if (handle_omp_array_sections (c)) | |
5724 | remove = true; | |
5725 | break; | |
5726 | } | |
5727 | if (t == error_mark_node) | |
5728 | remove = true; | |
f4ae4202 | 5729 | else if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL) |
bc7bff74 | 5730 | { |
5731 | if (processing_template_decl) | |
5732 | break; | |
5733 | if (DECL_P (t)) | |
5734 | error ("%qD is not a variable in %<depend%> clause", t); | |
5735 | else | |
5736 | error ("%qE is not a variable in %<depend%> clause", t); | |
5737 | remove = true; | |
5738 | } | |
5739 | else if (!processing_template_decl | |
5740 | && !cxx_mark_addressable (t)) | |
5741 | remove = true; | |
5742 | break; | |
5743 | ||
5744 | case OMP_CLAUSE_MAP: | |
5745 | case OMP_CLAUSE_TO: | |
5746 | case OMP_CLAUSE_FROM: | |
ca4c3545 | 5747 | case OMP_CLAUSE__CACHE_: |
bc7bff74 | 5748 | t = OMP_CLAUSE_DECL (c); |
5749 | if (TREE_CODE (t) == TREE_LIST) | |
5750 | { | |
5751 | if (handle_omp_array_sections (c)) | |
5752 | remove = true; | |
5753 | else | |
5754 | { | |
5755 | t = OMP_CLAUSE_DECL (c); | |
66579ffa | 5756 | if (TREE_CODE (t) != TREE_LIST |
5757 | && !type_dependent_expression_p (t) | |
5758 | && !cp_omp_mappable_type (TREE_TYPE (t))) | |
bc7bff74 | 5759 | { |
5760 | error_at (OMP_CLAUSE_LOCATION (c), | |
5761 | "array section does not have mappable type " | |
5762 | "in %qs clause", | |
5763 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
5764 | remove = true; | |
5765 | } | |
5766 | } | |
5767 | break; | |
5768 | } | |
5769 | if (t == error_mark_node) | |
5770 | remove = true; | |
f4ae4202 | 5771 | else if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL) |
bc7bff74 | 5772 | { |
5773 | if (processing_template_decl) | |
5774 | break; | |
5775 | if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP | |
ca4c3545 | 5776 | && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER) |
bc7bff74 | 5777 | break; |
5778 | if (DECL_P (t)) | |
5779 | error ("%qD is not a variable in %qs clause", t, | |
5780 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
5781 | else | |
5782 | error ("%qE is not a variable in %qs clause", t, | |
5783 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
5784 | remove = true; | |
5785 | } | |
800478e6 | 5786 | else if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t)) |
bc7bff74 | 5787 | { |
5788 | error ("%qD is threadprivate variable in %qs clause", t, | |
5789 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
5790 | remove = true; | |
5791 | } | |
5792 | else if (!processing_template_decl | |
5793 | && TREE_CODE (TREE_TYPE (t)) != REFERENCE_TYPE | |
5794 | && !cxx_mark_addressable (t)) | |
5795 | remove = true; | |
5796 | else if (!(OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP | |
ca4c3545 | 5797 | && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER) |
66579ffa | 5798 | && !type_dependent_expression_p (t) |
bc7bff74 | 5799 | && !cp_omp_mappable_type ((TREE_CODE (TREE_TYPE (t)) |
5800 | == REFERENCE_TYPE) | |
5801 | ? TREE_TYPE (TREE_TYPE (t)) | |
5802 | : TREE_TYPE (t))) | |
5803 | { | |
5804 | error_at (OMP_CLAUSE_LOCATION (c), | |
5805 | "%qD does not have a mappable type in %qs clause", t, | |
5806 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
5807 | remove = true; | |
5808 | } | |
5809 | else if (bitmap_bit_p (&generic_head, DECL_UID (t))) | |
5810 | { | |
5811 | if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP) | |
5812 | error ("%qD appears more than once in motion clauses", t); | |
5813 | else | |
5814 | error ("%qD appears more than once in map clauses", t); | |
5815 | remove = true; | |
5816 | } | |
5817 | else | |
5818 | bitmap_set_bit (&generic_head, DECL_UID (t)); | |
5819 | break; | |
5820 | ||
5821 | case OMP_CLAUSE_UNIFORM: | |
5822 | t = OMP_CLAUSE_DECL (c); | |
5823 | if (TREE_CODE (t) != PARM_DECL) | |
5824 | { | |
5825 | if (processing_template_decl) | |
5826 | break; | |
5827 | if (DECL_P (t)) | |
5828 | error ("%qD is not an argument in %<uniform%> clause", t); | |
5829 | else | |
5830 | error ("%qE is not an argument in %<uniform%> clause", t); | |
5831 | remove = true; | |
df205251 | 5832 | break; |
bc7bff74 | 5833 | } |
df205251 | 5834 | goto check_dup_generic; |
bc7bff74 | 5835 | |
8487df40 | 5836 | case OMP_CLAUSE_NOWAIT: |
5837 | case OMP_CLAUSE_ORDERED: | |
5838 | case OMP_CLAUSE_DEFAULT: | |
fd6481cf | 5839 | case OMP_CLAUSE_UNTIED: |
5840 | case OMP_CLAUSE_COLLAPSE: | |
2169f33b | 5841 | case OMP_CLAUSE_MERGEABLE: |
bc7bff74 | 5842 | case OMP_CLAUSE_PARALLEL: |
5843 | case OMP_CLAUSE_FOR: | |
5844 | case OMP_CLAUSE_SECTIONS: | |
5845 | case OMP_CLAUSE_TASKGROUP: | |
5846 | case OMP_CLAUSE_PROC_BIND: | |
40750995 | 5847 | case OMP_CLAUSE__CILK_FOR_COUNT_: |
bc7bff74 | 5848 | break; |
5849 | ||
5850 | case OMP_CLAUSE_INBRANCH: | |
5851 | case OMP_CLAUSE_NOTINBRANCH: | |
5852 | if (branch_seen) | |
5853 | { | |
5854 | error ("%<inbranch%> clause is incompatible with " | |
5855 | "%<notinbranch%>"); | |
5856 | remove = true; | |
5857 | } | |
5858 | branch_seen = true; | |
8487df40 | 5859 | break; |
5860 | ||
5861 | default: | |
5862 | gcc_unreachable (); | |
5863 | } | |
5864 | ||
5865 | if (remove) | |
5866 | *pc = OMP_CLAUSE_CHAIN (c); | |
5867 | else | |
5868 | pc = &OMP_CLAUSE_CHAIN (c); | |
5869 | } | |
5870 | ||
5871 | for (pc = &clauses, c = clauses; c ; c = *pc) | |
5872 | { | |
bc620c5c | 5873 | enum omp_clause_code c_kind = OMP_CLAUSE_CODE (c); |
8487df40 | 5874 | bool remove = false; |
5875 | bool need_complete_non_reference = false; | |
5876 | bool need_default_ctor = false; | |
5877 | bool need_copy_ctor = false; | |
5878 | bool need_copy_assignment = false; | |
5879 | bool need_implicitly_determined = false; | |
bc7bff74 | 5880 | bool need_dtor = false; |
8487df40 | 5881 | tree type, inner_type; |
5882 | ||
5883 | switch (c_kind) | |
5884 | { | |
5885 | case OMP_CLAUSE_SHARED: | |
8487df40 | 5886 | need_implicitly_determined = true; |
5887 | break; | |
5888 | case OMP_CLAUSE_PRIVATE: | |
8487df40 | 5889 | need_complete_non_reference = true; |
5890 | need_default_ctor = true; | |
bc7bff74 | 5891 | need_dtor = true; |
8487df40 | 5892 | need_implicitly_determined = true; |
5893 | break; | |
5894 | case OMP_CLAUSE_FIRSTPRIVATE: | |
8487df40 | 5895 | need_complete_non_reference = true; |
5896 | need_copy_ctor = true; | |
bc7bff74 | 5897 | need_dtor = true; |
8487df40 | 5898 | need_implicitly_determined = true; |
5899 | break; | |
5900 | case OMP_CLAUSE_LASTPRIVATE: | |
8487df40 | 5901 | need_complete_non_reference = true; |
5902 | need_copy_assignment = true; | |
5903 | need_implicitly_determined = true; | |
5904 | break; | |
5905 | case OMP_CLAUSE_REDUCTION: | |
8487df40 | 5906 | need_implicitly_determined = true; |
5907 | break; | |
5908 | case OMP_CLAUSE_COPYPRIVATE: | |
8487df40 | 5909 | need_copy_assignment = true; |
5910 | break; | |
5911 | case OMP_CLAUSE_COPYIN: | |
8487df40 | 5912 | need_copy_assignment = true; |
5913 | break; | |
bc7bff74 | 5914 | case OMP_CLAUSE_NOWAIT: |
5915 | if (copyprivate_seen) | |
5916 | { | |
5917 | error_at (OMP_CLAUSE_LOCATION (c), | |
5918 | "%<nowait%> clause must not be used together " | |
5919 | "with %<copyprivate%>"); | |
5920 | *pc = OMP_CLAUSE_CHAIN (c); | |
5921 | continue; | |
5922 | } | |
5923 | /* FALLTHRU */ | |
8487df40 | 5924 | default: |
5925 | pc = &OMP_CLAUSE_CHAIN (c); | |
5926 | continue; | |
5927 | } | |
5928 | ||
5929 | t = OMP_CLAUSE_DECL (c); | |
5930 | if (processing_template_decl | |
80a58eb0 | 5931 | && !VAR_P (t) && TREE_CODE (t) != PARM_DECL) |
8487df40 | 5932 | { |
5933 | pc = &OMP_CLAUSE_CHAIN (c); | |
5934 | continue; | |
5935 | } | |
5936 | ||
5937 | switch (c_kind) | |
5938 | { | |
5939 | case OMP_CLAUSE_LASTPRIVATE: | |
5940 | if (!bitmap_bit_p (&firstprivate_head, DECL_UID (t))) | |
bc7bff74 | 5941 | { |
5942 | need_default_ctor = true; | |
5943 | need_dtor = true; | |
5944 | } | |
8487df40 | 5945 | break; |
5946 | ||
5947 | case OMP_CLAUSE_REDUCTION: | |
bc7bff74 | 5948 | if (finish_omp_reduction_clause (c, &need_default_ctor, |
5949 | &need_dtor)) | |
5950 | remove = true; | |
5951 | else | |
5952 | t = OMP_CLAUSE_DECL (c); | |
8487df40 | 5953 | break; |
5954 | ||
5955 | case OMP_CLAUSE_COPYIN: | |
800478e6 | 5956 | if (!VAR_P (t) || !CP_DECL_THREAD_LOCAL_P (t)) |
8487df40 | 5957 | { |
5958 | error ("%qE must be %<threadprivate%> for %<copyin%>", t); | |
5959 | remove = true; | |
5960 | } | |
5961 | break; | |
5962 | ||
5963 | default: | |
5964 | break; | |
5965 | } | |
5966 | ||
58d3add9 | 5967 | if (need_complete_non_reference || need_copy_assignment) |
8487df40 | 5968 | { |
5969 | t = require_complete_type (t); | |
5970 | if (t == error_mark_node) | |
5971 | remove = true; | |
58d3add9 | 5972 | else if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE |
5973 | && need_complete_non_reference) | |
8487df40 | 5974 | { |
bc7bff74 | 5975 | error ("%qE has reference type for %qs", t, |
5976 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
8487df40 | 5977 | remove = true; |
5978 | } | |
5979 | } | |
5980 | if (need_implicitly_determined) | |
5981 | { | |
5982 | const char *share_name = NULL; | |
5983 | ||
800478e6 | 5984 | if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t)) |
8487df40 | 5985 | share_name = "threadprivate"; |
5986 | else switch (cxx_omp_predetermined_sharing (t)) | |
5987 | { | |
5988 | case OMP_CLAUSE_DEFAULT_UNSPECIFIED: | |
5989 | break; | |
5990 | case OMP_CLAUSE_DEFAULT_SHARED: | |
2169f33b | 5991 | /* const vars may be specified in firstprivate clause. */ |
5992 | if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE | |
5993 | && cxx_omp_const_qual_no_mutable (t)) | |
5994 | break; | |
8487df40 | 5995 | share_name = "shared"; |
5996 | break; | |
5997 | case OMP_CLAUSE_DEFAULT_PRIVATE: | |
5998 | share_name = "private"; | |
5999 | break; | |
6000 | default: | |
6001 | gcc_unreachable (); | |
6002 | } | |
6003 | if (share_name) | |
6004 | { | |
6005 | error ("%qE is predetermined %qs for %qs", | |
bc7bff74 | 6006 | t, share_name, omp_clause_code_name[OMP_CLAUSE_CODE (c)]); |
8487df40 | 6007 | remove = true; |
6008 | } | |
6009 | } | |
6010 | ||
6011 | /* We're interested in the base element, not arrays. */ | |
6012 | inner_type = type = TREE_TYPE (t); | |
6013 | while (TREE_CODE (inner_type) == ARRAY_TYPE) | |
6014 | inner_type = TREE_TYPE (inner_type); | |
6015 | ||
bc7bff74 | 6016 | if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION |
6017 | && TREE_CODE (inner_type) == REFERENCE_TYPE) | |
6018 | inner_type = TREE_TYPE (inner_type); | |
6019 | ||
3b49899c | 6020 | /* Check for special function availability by building a call to one. |
8487df40 | 6021 | Save the results, because later we won't be in the right context |
6022 | for making these queries. */ | |
6023 | if (CLASS_TYPE_P (inner_type) | |
58d3add9 | 6024 | && COMPLETE_TYPE_P (inner_type) |
bc7bff74 | 6025 | && (need_default_ctor || need_copy_ctor |
6026 | || need_copy_assignment || need_dtor) | |
fd6481cf | 6027 | && !type_dependent_expression_p (t) |
6028 | && cxx_omp_create_clause_info (c, inner_type, need_default_ctor, | |
bc7bff74 | 6029 | need_copy_ctor, need_copy_assignment, |
6030 | need_dtor)) | |
fd6481cf | 6031 | remove = true; |
8487df40 | 6032 | |
6033 | if (remove) | |
6034 | *pc = OMP_CLAUSE_CHAIN (c); | |
6035 | else | |
6036 | pc = &OMP_CLAUSE_CHAIN (c); | |
6037 | } | |
6038 | ||
6039 | bitmap_obstack_release (NULL); | |
6040 | return clauses; | |
6041 | } | |
6042 | ||
6043 | /* For all variables in the tree_list VARS, mark them as thread local. */ | |
6044 | ||
6045 | void | |
6046 | finish_omp_threadprivate (tree vars) | |
6047 | { | |
6048 | tree t; | |
6049 | ||
6050 | /* Mark every variable in VARS to be assigned thread local storage. */ | |
6051 | for (t = vars; t; t = TREE_CHAIN (t)) | |
6052 | { | |
6053 | tree v = TREE_PURPOSE (t); | |
6054 | ||
927fed67 | 6055 | if (error_operand_p (v)) |
6056 | ; | |
80a58eb0 | 6057 | else if (!VAR_P (v)) |
927fed67 | 6058 | error ("%<threadprivate%> %qD is not file, namespace " |
6059 | "or block scope variable", v); | |
8487df40 | 6060 | /* If V had already been marked threadprivate, it doesn't matter |
6061 | whether it had been used prior to this point. */ | |
927fed67 | 6062 | else if (TREE_USED (v) |
8487df40 | 6063 | && (DECL_LANG_SPECIFIC (v) == NULL |
6064 | || !CP_DECL_THREADPRIVATE_P (v))) | |
6065 | error ("%qE declared %<threadprivate%> after first use", v); | |
6066 | else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v)) | |
6067 | error ("automatic variable %qE cannot be %<threadprivate%>", v); | |
c7623d7c | 6068 | else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v)))) |
8487df40 | 6069 | error ("%<threadprivate%> %qE has incomplete type", v); |
fd6481cf | 6070 | else if (TREE_STATIC (v) && TYPE_P (CP_DECL_CONTEXT (v)) |
6071 | && CP_DECL_CONTEXT (v) != current_class_type) | |
6072 | error ("%<threadprivate%> %qE directive not " | |
6073 | "in %qT definition", v, CP_DECL_CONTEXT (v)); | |
8487df40 | 6074 | else |
6075 | { | |
6076 | /* Allocate a LANG_SPECIFIC structure for V, if needed. */ | |
6077 | if (DECL_LANG_SPECIFIC (v) == NULL) | |
6078 | { | |
6079 | retrofit_lang_decl (v); | |
6080 | ||
6081 | /* Make sure that DECL_DISCRIMINATOR_P continues to be true | |
6082 | after the allocation of the lang_decl structure. */ | |
6083 | if (DECL_DISCRIMINATOR_P (v)) | |
39e70cbf | 6084 | DECL_LANG_SPECIFIC (v)->u.base.u2sel = 1; |
8487df40 | 6085 | } |
6086 | ||
800478e6 | 6087 | if (! CP_DECL_THREAD_LOCAL_P (v)) |
8487df40 | 6088 | { |
800478e6 | 6089 | CP_DECL_THREAD_LOCAL_P (v) = true; |
5e68df57 | 6090 | set_decl_tls_model (v, decl_default_tls_model (v)); |
8487df40 | 6091 | /* If rtl has been already set for this var, call |
6092 | make_decl_rtl once again, so that encode_section_info | |
6093 | has a chance to look at the new decl flags. */ | |
6094 | if (DECL_RTL_SET_P (v)) | |
6095 | make_decl_rtl (v); | |
6096 | } | |
6097 | CP_DECL_THREADPRIVATE_P (v) = 1; | |
6098 | } | |
6099 | } | |
6100 | } | |
6101 | ||
6102 | /* Build an OpenMP structured block. */ | |
6103 | ||
6104 | tree | |
6105 | begin_omp_structured_block (void) | |
6106 | { | |
6107 | return do_pushlevel (sk_omp); | |
6108 | } | |
6109 | ||
6110 | tree | |
6111 | finish_omp_structured_block (tree block) | |
6112 | { | |
6113 | return do_poplevel (block); | |
6114 | } | |
6115 | ||
ca4c3545 | 6116 | /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound |
6117 | statement. LOC is the location of the OACC_DATA. */ | |
6118 | ||
6119 | tree | |
6120 | finish_oacc_data (tree clauses, tree block) | |
6121 | { | |
6122 | tree stmt; | |
6123 | ||
6124 | block = finish_omp_structured_block (block); | |
6125 | ||
6126 | stmt = make_node (OACC_DATA); | |
6127 | TREE_TYPE (stmt) = void_type_node; | |
6128 | OACC_DATA_CLAUSES (stmt) = clauses; | |
6129 | OACC_DATA_BODY (stmt) = block; | |
6130 | ||
6131 | return add_stmt (stmt); | |
6132 | } | |
6133 | ||
6134 | /* Generate OACC_KERNELS, with CLAUSES and BLOCK as its compound | |
6135 | statement. LOC is the location of the OACC_KERNELS. */ | |
6136 | ||
6137 | tree | |
6138 | finish_oacc_kernels (tree clauses, tree block) | |
6139 | { | |
6140 | tree stmt; | |
6141 | ||
6142 | block = finish_omp_structured_block (block); | |
6143 | ||
6144 | stmt = make_node (OACC_KERNELS); | |
6145 | TREE_TYPE (stmt) = void_type_node; | |
6146 | OACC_KERNELS_CLAUSES (stmt) = clauses; | |
6147 | OACC_KERNELS_BODY (stmt) = block; | |
6148 | ||
6149 | return add_stmt (stmt); | |
6150 | } | |
6151 | ||
6152 | /* Generate OACC_PARALLEL, with CLAUSES and BLOCK as its compound | |
6153 | statement. LOC is the location of the OACC_PARALLEL. */ | |
6154 | ||
6155 | tree | |
6156 | finish_oacc_parallel (tree clauses, tree block) | |
6157 | { | |
6158 | tree stmt; | |
6159 | ||
6160 | block = finish_omp_structured_block (block); | |
6161 | ||
6162 | stmt = make_node (OACC_PARALLEL); | |
6163 | TREE_TYPE (stmt) = void_type_node; | |
6164 | OACC_PARALLEL_CLAUSES (stmt) = clauses; | |
6165 | OACC_PARALLEL_BODY (stmt) = block; | |
6166 | ||
6167 | return add_stmt (stmt); | |
6168 | } | |
6169 | ||
3b49899c | 6170 | /* Similarly, except force the retention of the BLOCK. */ |
8487df40 | 6171 | |
6172 | tree | |
6173 | begin_omp_parallel (void) | |
6174 | { | |
6175 | keep_next_level (true); | |
6176 | return begin_omp_structured_block (); | |
6177 | } | |
6178 | ||
6179 | tree | |
6180 | finish_omp_parallel (tree clauses, tree body) | |
6181 | { | |
6182 | tree stmt; | |
6183 | ||
6184 | body = finish_omp_structured_block (body); | |
1f1fa73c | 6185 | |
8487df40 | 6186 | stmt = make_node (OMP_PARALLEL); |
6187 | TREE_TYPE (stmt) = void_type_node; | |
6188 | OMP_PARALLEL_CLAUSES (stmt) = clauses; | |
6189 | OMP_PARALLEL_BODY (stmt) = body; | |
41fb2c18 | 6190 | |
8487df40 | 6191 | return add_stmt (stmt); |
6192 | } | |
6193 | ||
fd6481cf | 6194 | tree |
6195 | begin_omp_task (void) | |
6196 | { | |
6197 | keep_next_level (true); | |
6198 | return begin_omp_structured_block (); | |
6199 | } | |
6200 | ||
6201 | tree | |
6202 | finish_omp_task (tree clauses, tree body) | |
6203 | { | |
6204 | tree stmt; | |
6205 | ||
6206 | body = finish_omp_structured_block (body); | |
6207 | ||
6208 | stmt = make_node (OMP_TASK); | |
6209 | TREE_TYPE (stmt) = void_type_node; | |
6210 | OMP_TASK_CLAUSES (stmt) = clauses; | |
6211 | OMP_TASK_BODY (stmt) = body; | |
6212 | ||
6213 | return add_stmt (stmt); | |
6214 | } | |
6215 | ||
6216 | /* Helper function for finish_omp_for. Convert Ith random access iterator | |
6217 | into integral iterator. Return FALSE if successful. */ | |
6218 | ||
6219 | static bool | |
6220 | handle_omp_for_class_iterator (int i, location_t locus, tree declv, tree initv, | |
6221 | tree condv, tree incrv, tree *body, | |
40750995 | 6222 | tree *pre_body, tree clauses, tree *lastp) |
fd6481cf | 6223 | { |
6224 | tree diff, iter_init, iter_incr = NULL, last; | |
6225 | tree incr_var = NULL, orig_pre_body, orig_body, c; | |
6226 | tree decl = TREE_VEC_ELT (declv, i); | |
6227 | tree init = TREE_VEC_ELT (initv, i); | |
6228 | tree cond = TREE_VEC_ELT (condv, i); | |
6229 | tree incr = TREE_VEC_ELT (incrv, i); | |
6230 | tree iter = decl; | |
6231 | location_t elocus = locus; | |
6232 | ||
6233 | if (init && EXPR_HAS_LOCATION (init)) | |
6234 | elocus = EXPR_LOCATION (init); | |
6235 | ||
6236 | switch (TREE_CODE (cond)) | |
6237 | { | |
6238 | case GT_EXPR: | |
6239 | case GE_EXPR: | |
6240 | case LT_EXPR: | |
6241 | case LE_EXPR: | |
40750995 | 6242 | case NE_EXPR: |
4390875c | 6243 | if (TREE_OPERAND (cond, 1) == iter) |
6244 | cond = build2 (swap_tree_comparison (TREE_CODE (cond)), | |
6245 | TREE_TYPE (cond), iter, TREE_OPERAND (cond, 0)); | |
fd6481cf | 6246 | if (TREE_OPERAND (cond, 0) != iter) |
6247 | cond = error_mark_node; | |
6248 | else | |
6249 | { | |
255b5d15 | 6250 | tree tem = build_x_binary_op (EXPR_LOCATION (cond), |
6251 | TREE_CODE (cond), | |
ef0b0c72 | 6252 | iter, ERROR_MARK, |
fd6481cf | 6253 | TREE_OPERAND (cond, 1), ERROR_MARK, |
6254 | NULL, tf_warning_or_error); | |
6255 | if (error_operand_p (tem)) | |
6256 | return true; | |
6257 | } | |
6258 | break; | |
6259 | default: | |
6260 | cond = error_mark_node; | |
6261 | break; | |
6262 | } | |
6263 | if (cond == error_mark_node) | |
6264 | { | |
ccb59bb6 | 6265 | error_at (elocus, "invalid controlling predicate"); |
fd6481cf | 6266 | return true; |
6267 | } | |
255b5d15 | 6268 | diff = build_x_binary_op (elocus, MINUS_EXPR, TREE_OPERAND (cond, 1), |
fd6481cf | 6269 | ERROR_MARK, iter, ERROR_MARK, NULL, |
6270 | tf_warning_or_error); | |
6271 | if (error_operand_p (diff)) | |
6272 | return true; | |
6273 | if (TREE_CODE (TREE_TYPE (diff)) != INTEGER_TYPE) | |
6274 | { | |
ccb59bb6 | 6275 | error_at (elocus, "difference between %qE and %qD does not have integer type", |
6276 | TREE_OPERAND (cond, 1), iter); | |
fd6481cf | 6277 | return true; |
6278 | } | |
6279 | ||
6280 | switch (TREE_CODE (incr)) | |
6281 | { | |
6282 | case PREINCREMENT_EXPR: | |
6283 | case PREDECREMENT_EXPR: | |
6284 | case POSTINCREMENT_EXPR: | |
6285 | case POSTDECREMENT_EXPR: | |
6286 | if (TREE_OPERAND (incr, 0) != iter) | |
6287 | { | |
6288 | incr = error_mark_node; | |
6289 | break; | |
6290 | } | |
255b5d15 | 6291 | iter_incr = build_x_unary_op (EXPR_LOCATION (incr), |
6292 | TREE_CODE (incr), iter, | |
fd6481cf | 6293 | tf_warning_or_error); |
6294 | if (error_operand_p (iter_incr)) | |
6295 | return true; | |
6296 | else if (TREE_CODE (incr) == PREINCREMENT_EXPR | |
6297 | || TREE_CODE (incr) == POSTINCREMENT_EXPR) | |
6298 | incr = integer_one_node; | |
6299 | else | |
6300 | incr = integer_minus_one_node; | |
6301 | break; | |
6302 | case MODIFY_EXPR: | |
6303 | if (TREE_OPERAND (incr, 0) != iter) | |
6304 | incr = error_mark_node; | |
6305 | else if (TREE_CODE (TREE_OPERAND (incr, 1)) == PLUS_EXPR | |
6306 | || TREE_CODE (TREE_OPERAND (incr, 1)) == MINUS_EXPR) | |
6307 | { | |
6308 | tree rhs = TREE_OPERAND (incr, 1); | |
6309 | if (TREE_OPERAND (rhs, 0) == iter) | |
6310 | { | |
6311 | if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 1))) | |
6312 | != INTEGER_TYPE) | |
6313 | incr = error_mark_node; | |
6314 | else | |
6315 | { | |
255b5d15 | 6316 | iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs), |
6317 | iter, TREE_CODE (rhs), | |
fd6481cf | 6318 | TREE_OPERAND (rhs, 1), |
6319 | tf_warning_or_error); | |
6320 | if (error_operand_p (iter_incr)) | |
6321 | return true; | |
6322 | incr = TREE_OPERAND (rhs, 1); | |
c4698a21 | 6323 | incr = cp_convert (TREE_TYPE (diff), incr, |
6324 | tf_warning_or_error); | |
fd6481cf | 6325 | if (TREE_CODE (rhs) == MINUS_EXPR) |
6326 | { | |
6327 | incr = build1 (NEGATE_EXPR, TREE_TYPE (diff), incr); | |
6328 | incr = fold_if_not_in_template (incr); | |
6329 | } | |
6330 | if (TREE_CODE (incr) != INTEGER_CST | |
6331 | && (TREE_CODE (incr) != NOP_EXPR | |
6332 | || (TREE_CODE (TREE_OPERAND (incr, 0)) | |
6333 | != INTEGER_CST))) | |
6334 | iter_incr = NULL; | |
6335 | } | |
6336 | } | |
6337 | else if (TREE_OPERAND (rhs, 1) == iter) | |
6338 | { | |
6339 | if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 0))) != INTEGER_TYPE | |
6340 | || TREE_CODE (rhs) != PLUS_EXPR) | |
6341 | incr = error_mark_node; | |
6342 | else | |
6343 | { | |
255b5d15 | 6344 | iter_incr = build_x_binary_op (EXPR_LOCATION (rhs), |
6345 | PLUS_EXPR, | |
fd6481cf | 6346 | TREE_OPERAND (rhs, 0), |
6347 | ERROR_MARK, iter, | |
6348 | ERROR_MARK, NULL, | |
6349 | tf_warning_or_error); | |
6350 | if (error_operand_p (iter_incr)) | |
6351 | return true; | |
255b5d15 | 6352 | iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs), |
6353 | iter, NOP_EXPR, | |
fd6481cf | 6354 | iter_incr, |
6355 | tf_warning_or_error); | |
6356 | if (error_operand_p (iter_incr)) | |
6357 | return true; | |
6358 | incr = TREE_OPERAND (rhs, 0); | |
6359 | iter_incr = NULL; | |
6360 | } | |
6361 | } | |
6362 | else | |
6363 | incr = error_mark_node; | |
6364 | } | |
6365 | else | |
6366 | incr = error_mark_node; | |
6367 | break; | |
6368 | default: | |
6369 | incr = error_mark_node; | |
6370 | break; | |
6371 | } | |
6372 | ||
6373 | if (incr == error_mark_node) | |
6374 | { | |
ccb59bb6 | 6375 | error_at (elocus, "invalid increment expression"); |
fd6481cf | 6376 | return true; |
6377 | } | |
6378 | ||
c4698a21 | 6379 | incr = cp_convert (TREE_TYPE (diff), incr, tf_warning_or_error); |
fd6481cf | 6380 | for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c)) |
6381 | if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE | |
6382 | && OMP_CLAUSE_DECL (c) == iter) | |
6383 | break; | |
6384 | ||
6385 | decl = create_temporary_var (TREE_TYPE (diff)); | |
6386 | pushdecl (decl); | |
6387 | add_decl_expr (decl); | |
6388 | last = create_temporary_var (TREE_TYPE (diff)); | |
6389 | pushdecl (last); | |
6390 | add_decl_expr (last); | |
6391 | if (c && iter_incr == NULL) | |
6392 | { | |
6393 | incr_var = create_temporary_var (TREE_TYPE (diff)); | |
6394 | pushdecl (incr_var); | |
6395 | add_decl_expr (incr_var); | |
6396 | } | |
6397 | gcc_assert (stmts_are_full_exprs_p ()); | |
6398 | ||
6399 | orig_pre_body = *pre_body; | |
6400 | *pre_body = push_stmt_list (); | |
6401 | if (orig_pre_body) | |
6402 | add_stmt (orig_pre_body); | |
6403 | if (init != NULL) | |
255b5d15 | 6404 | finish_expr_stmt (build_x_modify_expr (elocus, |
6405 | iter, NOP_EXPR, init, | |
fd6481cf | 6406 | tf_warning_or_error)); |
6407 | init = build_int_cst (TREE_TYPE (diff), 0); | |
6408 | if (c && iter_incr == NULL) | |
6409 | { | |
255b5d15 | 6410 | finish_expr_stmt (build_x_modify_expr (elocus, |
6411 | incr_var, NOP_EXPR, | |
fd6481cf | 6412 | incr, tf_warning_or_error)); |
6413 | incr = incr_var; | |
255b5d15 | 6414 | iter_incr = build_x_modify_expr (elocus, |
6415 | iter, PLUS_EXPR, incr, | |
fd6481cf | 6416 | tf_warning_or_error); |
6417 | } | |
255b5d15 | 6418 | finish_expr_stmt (build_x_modify_expr (elocus, |
6419 | last, NOP_EXPR, init, | |
fd6481cf | 6420 | tf_warning_or_error)); |
6421 | *pre_body = pop_stmt_list (*pre_body); | |
6422 | ||
8e70fb09 | 6423 | cond = cp_build_binary_op (elocus, |
6424 | TREE_CODE (cond), decl, diff, | |
fd6481cf | 6425 | tf_warning_or_error); |
8458f4ca | 6426 | incr = build_modify_expr (elocus, decl, NULL_TREE, PLUS_EXPR, |
e60a6f7b | 6427 | elocus, incr, NULL_TREE); |
fd6481cf | 6428 | |
6429 | orig_body = *body; | |
6430 | *body = push_stmt_list (); | |
6431 | iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), decl, last); | |
255b5d15 | 6432 | iter_init = build_x_modify_expr (elocus, |
6433 | iter, PLUS_EXPR, iter_init, | |
fd6481cf | 6434 | tf_warning_or_error); |
6435 | iter_init = build1 (NOP_EXPR, void_type_node, iter_init); | |
6436 | finish_expr_stmt (iter_init); | |
255b5d15 | 6437 | finish_expr_stmt (build_x_modify_expr (elocus, |
6438 | last, NOP_EXPR, decl, | |
fd6481cf | 6439 | tf_warning_or_error)); |
6440 | add_stmt (orig_body); | |
6441 | *body = pop_stmt_list (*body); | |
6442 | ||
6443 | if (c) | |
6444 | { | |
6445 | OMP_CLAUSE_LASTPRIVATE_STMT (c) = push_stmt_list (); | |
6446 | finish_expr_stmt (iter_incr); | |
6447 | OMP_CLAUSE_LASTPRIVATE_STMT (c) | |
6448 | = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c)); | |
6449 | } | |
6450 | ||
6451 | TREE_VEC_ELT (declv, i) = decl; | |
6452 | TREE_VEC_ELT (initv, i) = init; | |
6453 | TREE_VEC_ELT (condv, i) = cond; | |
6454 | TREE_VEC_ELT (incrv, i) = incr; | |
40750995 | 6455 | *lastp = last; |
fd6481cf | 6456 | |
6457 | return false; | |
6458 | } | |
6459 | ||
8487df40 | 6460 | /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR |
6461 | are directly for their associated operands in the statement. DECL | |
6462 | and INIT are a combo; if DECL is NULL then INIT ought to be a | |
6463 | MODIFY_EXPR, and the DECL should be extracted. PRE_BODY are | |
6464 | optional statements that need to go before the loop into its | |
6465 | sk_omp scope. */ | |
6466 | ||
6467 | tree | |
bc7bff74 | 6468 | finish_omp_for (location_t locus, enum tree_code code, tree declv, tree initv, |
6469 | tree condv, tree incrv, tree body, tree pre_body, tree clauses) | |
fd6481cf | 6470 | { |
6471 | tree omp_for = NULL, orig_incr = NULL; | |
40750995 | 6472 | tree decl = NULL, init, cond, incr, orig_decl = NULL_TREE, block = NULL_TREE; |
6473 | tree last = NULL_TREE; | |
fd6481cf | 6474 | location_t elocus; |
6475 | int i; | |
6476 | ||
6477 | gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (initv)); | |
6478 | gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (condv)); | |
6479 | gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (incrv)); | |
6480 | for (i = 0; i < TREE_VEC_LENGTH (declv); i++) | |
6481 | { | |
6482 | decl = TREE_VEC_ELT (declv, i); | |
6483 | init = TREE_VEC_ELT (initv, i); | |
6484 | cond = TREE_VEC_ELT (condv, i); | |
6485 | incr = TREE_VEC_ELT (incrv, i); | |
6486 | elocus = locus; | |
6487 | ||
6488 | if (decl == NULL) | |
6489 | { | |
6490 | if (init != NULL) | |
6491 | switch (TREE_CODE (init)) | |
8487df40 | 6492 | { |
fd6481cf | 6493 | case MODIFY_EXPR: |
8487df40 | 6494 | decl = TREE_OPERAND (init, 0); |
fd6481cf | 6495 | init = TREE_OPERAND (init, 1); |
6496 | break; | |
6497 | case MODOP_EXPR: | |
6498 | if (TREE_CODE (TREE_OPERAND (init, 1)) == NOP_EXPR) | |
6499 | { | |
6500 | decl = TREE_OPERAND (init, 0); | |
6501 | init = TREE_OPERAND (init, 2); | |
6502 | } | |
6503 | break; | |
6504 | default: | |
6505 | break; | |
8487df40 | 6506 | } |
8487df40 | 6507 | |
fd6481cf | 6508 | if (decl == NULL) |
6509 | { | |
ccb59bb6 | 6510 | error_at (locus, |
6511 | "expected iteration declaration or initialization"); | |
fd6481cf | 6512 | return NULL; |
6513 | } | |
8487df40 | 6514 | } |
8487df40 | 6515 | |
fd6481cf | 6516 | if (init && EXPR_HAS_LOCATION (init)) |
6517 | elocus = EXPR_LOCATION (init); | |
8487df40 | 6518 | |
6519 | if (cond == NULL) | |
6520 | { | |
ccb59bb6 | 6521 | error_at (elocus, "missing controlling predicate"); |
8487df40 | 6522 | return NULL; |
6523 | } | |
6524 | ||
6525 | if (incr == NULL) | |
6526 | { | |
ccb59bb6 | 6527 | error_at (elocus, "missing increment expression"); |
8487df40 | 6528 | return NULL; |
6529 | } | |
6530 | ||
fd6481cf | 6531 | TREE_VEC_ELT (declv, i) = decl; |
6532 | TREE_VEC_ELT (initv, i) = init; | |
6533 | } | |
6534 | ||
6535 | if (dependent_omp_for_p (declv, initv, condv, incrv)) | |
6536 | { | |
6537 | tree stmt; | |
6538 | ||
bc7bff74 | 6539 | stmt = make_node (code); |
8487df40 | 6540 | |
fd6481cf | 6541 | for (i = 0; i < TREE_VEC_LENGTH (declv); i++) |
6542 | { | |
6543 | /* This is really just a place-holder. We'll be decomposing this | |
6544 | again and going through the cp_build_modify_expr path below when | |
6545 | we instantiate the thing. */ | |
6546 | TREE_VEC_ELT (initv, i) | |
6547 | = build2 (MODIFY_EXPR, void_type_node, TREE_VEC_ELT (declv, i), | |
6548 | TREE_VEC_ELT (initv, i)); | |
6549 | } | |
8487df40 | 6550 | |
6551 | TREE_TYPE (stmt) = void_type_node; | |
fd6481cf | 6552 | OMP_FOR_INIT (stmt) = initv; |
6553 | OMP_FOR_COND (stmt) = condv; | |
6554 | OMP_FOR_INCR (stmt) = incrv; | |
8487df40 | 6555 | OMP_FOR_BODY (stmt) = body; |
6556 | OMP_FOR_PRE_BODY (stmt) = pre_body; | |
fd6481cf | 6557 | OMP_FOR_CLAUSES (stmt) = clauses; |
8487df40 | 6558 | |
6559 | SET_EXPR_LOCATION (stmt, locus); | |
6560 | return add_stmt (stmt); | |
6561 | } | |
6562 | ||
fd6481cf | 6563 | if (processing_template_decl) |
6564 | orig_incr = make_tree_vec (TREE_VEC_LENGTH (incrv)); | |
8487df40 | 6565 | |
fd6481cf | 6566 | for (i = 0; i < TREE_VEC_LENGTH (declv); ) |
a46a7e42 | 6567 | { |
fd6481cf | 6568 | decl = TREE_VEC_ELT (declv, i); |
6569 | init = TREE_VEC_ELT (initv, i); | |
6570 | cond = TREE_VEC_ELT (condv, i); | |
6571 | incr = TREE_VEC_ELT (incrv, i); | |
6572 | if (orig_incr) | |
6573 | TREE_VEC_ELT (orig_incr, i) = incr; | |
6574 | elocus = locus; | |
6575 | ||
6576 | if (init && EXPR_HAS_LOCATION (init)) | |
a46a7e42 | 6577 | elocus = EXPR_LOCATION (init); |
a46a7e42 | 6578 | |
fd6481cf | 6579 | if (!DECL_P (decl)) |
6580 | { | |
ccb59bb6 | 6581 | error_at (elocus, "expected iteration declaration or initialization"); |
fd6481cf | 6582 | return NULL; |
6583 | } | |
b25fbb3e | 6584 | |
fd6481cf | 6585 | if (incr && TREE_CODE (incr) == MODOP_EXPR) |
6586 | { | |
6587 | if (orig_incr) | |
6588 | TREE_VEC_ELT (orig_incr, i) = incr; | |
6589 | incr = cp_build_modify_expr (TREE_OPERAND (incr, 0), | |
6590 | TREE_CODE (TREE_OPERAND (incr, 1)), | |
6591 | TREE_OPERAND (incr, 2), | |
6592 | tf_warning_or_error); | |
6593 | } | |
6594 | ||
6595 | if (CLASS_TYPE_P (TREE_TYPE (decl))) | |
6596 | { | |
bc7bff74 | 6597 | if (code == OMP_SIMD) |
6598 | { | |
6599 | error_at (elocus, "%<#pragma omp simd%> used with class " | |
6600 | "iteration variable %qE", decl); | |
6601 | return NULL; | |
6602 | } | |
40750995 | 6603 | if (code == CILK_FOR && i == 0) |
6604 | orig_decl = decl; | |
fd6481cf | 6605 | if (handle_omp_for_class_iterator (i, locus, declv, initv, condv, |
40750995 | 6606 | incrv, &body, &pre_body, |
6607 | clauses, &last)) | |
fd6481cf | 6608 | return NULL; |
6609 | continue; | |
6610 | } | |
6611 | ||
6612 | if (!INTEGRAL_TYPE_P (TREE_TYPE (decl)) | |
c21c015b | 6613 | && !TYPE_PTR_P (TREE_TYPE (decl))) |
fd6481cf | 6614 | { |
ccb59bb6 | 6615 | error_at (elocus, "invalid type for iteration variable %qE", decl); |
fd6481cf | 6616 | return NULL; |
6617 | } | |
b25fbb3e | 6618 | |
962cad33 | 6619 | if (!processing_template_decl) |
bacfcc02 | 6620 | { |
6621 | init = fold_build_cleanup_point_expr (TREE_TYPE (init), init); | |
6622 | init = cp_build_modify_expr (decl, NOP_EXPR, init, tf_warning_or_error); | |
6623 | } | |
6624 | else | |
6625 | init = build2 (MODIFY_EXPR, void_type_node, decl, init); | |
267f2f49 | 6626 | if (cond |
6627 | && TREE_SIDE_EFFECTS (cond) | |
6628 | && COMPARISON_CLASS_P (cond) | |
6629 | && !processing_template_decl) | |
fd6481cf | 6630 | { |
267f2f49 | 6631 | tree t = TREE_OPERAND (cond, 0); |
6632 | if (TREE_SIDE_EFFECTS (t) | |
6633 | && t != decl | |
6634 | && (TREE_CODE (t) != NOP_EXPR | |
6635 | || TREE_OPERAND (t, 0) != decl)) | |
6636 | TREE_OPERAND (cond, 0) | |
6637 | = fold_build_cleanup_point_expr (TREE_TYPE (t), t); | |
fd6481cf | 6638 | |
267f2f49 | 6639 | t = TREE_OPERAND (cond, 1); |
6640 | if (TREE_SIDE_EFFECTS (t) | |
6641 | && t != decl | |
6642 | && (TREE_CODE (t) != NOP_EXPR | |
6643 | || TREE_OPERAND (t, 0) != decl)) | |
6644 | TREE_OPERAND (cond, 1) | |
fd6481cf | 6645 | = fold_build_cleanup_point_expr (TREE_TYPE (t), t); |
6646 | } | |
6647 | if (decl == error_mark_node || init == error_mark_node) | |
6648 | return NULL; | |
6649 | ||
6650 | TREE_VEC_ELT (declv, i) = decl; | |
6651 | TREE_VEC_ELT (initv, i) = init; | |
6652 | TREE_VEC_ELT (condv, i) = cond; | |
6653 | TREE_VEC_ELT (incrv, i) = incr; | |
6654 | i++; | |
b25fbb3e | 6655 | } |
fd6481cf | 6656 | |
6657 | if (IS_EMPTY_STMT (pre_body)) | |
6658 | pre_body = NULL; | |
6659 | ||
40750995 | 6660 | if (code == CILK_FOR && !processing_template_decl) |
6661 | block = push_stmt_list (); | |
6662 | ||
bc7bff74 | 6663 | omp_for = c_finish_omp_for (locus, code, declv, initv, condv, incrv, |
fd6481cf | 6664 | body, pre_body); |
6665 | ||
6666 | if (omp_for == NULL) | |
40750995 | 6667 | { |
6668 | if (block) | |
6669 | pop_stmt_list (block); | |
6670 | return NULL; | |
6671 | } | |
fd6481cf | 6672 | |
6673 | for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)); i++) | |
b25fbb3e | 6674 | { |
267f2f49 | 6675 | decl = TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i), 0); |
6676 | incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i); | |
b25fbb3e | 6677 | |
fd6481cf | 6678 | if (TREE_CODE (incr) != MODIFY_EXPR) |
6679 | continue; | |
6680 | ||
6681 | if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr, 1)) | |
267f2f49 | 6682 | && BINARY_CLASS_P (TREE_OPERAND (incr, 1)) |
6683 | && !processing_template_decl) | |
fd6481cf | 6684 | { |
267f2f49 | 6685 | tree t = TREE_OPERAND (TREE_OPERAND (incr, 1), 0); |
6686 | if (TREE_SIDE_EFFECTS (t) | |
6687 | && t != decl | |
6688 | && (TREE_CODE (t) != NOP_EXPR | |
6689 | || TREE_OPERAND (t, 0) != decl)) | |
6690 | TREE_OPERAND (TREE_OPERAND (incr, 1), 0) | |
6691 | = fold_build_cleanup_point_expr (TREE_TYPE (t), t); | |
fd6481cf | 6692 | |
267f2f49 | 6693 | t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1); |
6694 | if (TREE_SIDE_EFFECTS (t) | |
6695 | && t != decl | |
6696 | && (TREE_CODE (t) != NOP_EXPR | |
6697 | || TREE_OPERAND (t, 0) != decl)) | |
6698 | TREE_OPERAND (TREE_OPERAND (incr, 1), 1) | |
6699 | = fold_build_cleanup_point_expr (TREE_TYPE (t), t); | |
fd6481cf | 6700 | } |
6701 | ||
6702 | if (orig_incr) | |
6703 | TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i) = TREE_VEC_ELT (orig_incr, i); | |
b25fbb3e | 6704 | } |
40750995 | 6705 | OMP_FOR_CLAUSES (omp_for) = clauses; |
6706 | ||
6707 | if (block) | |
6708 | { | |
6709 | tree omp_par = make_node (OMP_PARALLEL); | |
6710 | TREE_TYPE (omp_par) = void_type_node; | |
6711 | OMP_PARALLEL_CLAUSES (omp_par) = NULL_TREE; | |
6712 | tree bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL); | |
6713 | TREE_SIDE_EFFECTS (bind) = 1; | |
6714 | BIND_EXPR_BODY (bind) = pop_stmt_list (block); | |
6715 | OMP_PARALLEL_BODY (omp_par) = bind; | |
6716 | if (OMP_FOR_PRE_BODY (omp_for)) | |
6717 | { | |
6718 | add_stmt (OMP_FOR_PRE_BODY (omp_for)); | |
6719 | OMP_FOR_PRE_BODY (omp_for) = NULL_TREE; | |
6720 | } | |
6721 | init = TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0); | |
6722 | decl = TREE_OPERAND (init, 0); | |
6723 | cond = TREE_VEC_ELT (OMP_FOR_COND (omp_for), 0); | |
6724 | incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0); | |
6725 | tree t = TREE_OPERAND (cond, 1), c, clauses, *pc; | |
6726 | clauses = OMP_FOR_CLAUSES (omp_for); | |
6727 | OMP_FOR_CLAUSES (omp_for) = NULL_TREE; | |
6728 | for (pc = &clauses; *pc; ) | |
6729 | if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_SCHEDULE) | |
6730 | { | |
6731 | gcc_assert (OMP_FOR_CLAUSES (omp_for) == NULL_TREE); | |
6732 | OMP_FOR_CLAUSES (omp_for) = *pc; | |
6733 | *pc = OMP_CLAUSE_CHAIN (*pc); | |
6734 | OMP_CLAUSE_CHAIN (OMP_FOR_CLAUSES (omp_for)) = NULL_TREE; | |
6735 | } | |
6736 | else | |
6737 | { | |
6738 | gcc_assert (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_FIRSTPRIVATE); | |
6739 | pc = &OMP_CLAUSE_CHAIN (*pc); | |
6740 | } | |
6741 | if (TREE_CODE (t) != INTEGER_CST) | |
6742 | { | |
6743 | TREE_OPERAND (cond, 1) = get_temp_regvar (TREE_TYPE (t), t); | |
6744 | c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE); | |
6745 | OMP_CLAUSE_DECL (c) = TREE_OPERAND (cond, 1); | |
6746 | OMP_CLAUSE_CHAIN (c) = clauses; | |
6747 | clauses = c; | |
6748 | } | |
6749 | if (TREE_CODE (incr) == MODIFY_EXPR) | |
6750 | { | |
6751 | t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1); | |
6752 | if (TREE_CODE (t) != INTEGER_CST) | |
6753 | { | |
6754 | TREE_OPERAND (TREE_OPERAND (incr, 1), 1) | |
6755 | = get_temp_regvar (TREE_TYPE (t), t); | |
6756 | c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE); | |
6757 | OMP_CLAUSE_DECL (c) = TREE_OPERAND (TREE_OPERAND (incr, 1), 1); | |
6758 | OMP_CLAUSE_CHAIN (c) = clauses; | |
6759 | clauses = c; | |
6760 | } | |
6761 | } | |
6762 | t = TREE_OPERAND (init, 1); | |
6763 | if (TREE_CODE (t) != INTEGER_CST) | |
6764 | { | |
6765 | TREE_OPERAND (init, 1) = get_temp_regvar (TREE_TYPE (t), t); | |
6766 | c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE); | |
6767 | OMP_CLAUSE_DECL (c) = TREE_OPERAND (init, 1); | |
6768 | OMP_CLAUSE_CHAIN (c) = clauses; | |
6769 | clauses = c; | |
6770 | } | |
6771 | if (orig_decl && orig_decl != decl) | |
6772 | { | |
6773 | c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE); | |
6774 | OMP_CLAUSE_DECL (c) = orig_decl; | |
6775 | OMP_CLAUSE_CHAIN (c) = clauses; | |
6776 | clauses = c; | |
6777 | } | |
6778 | if (last) | |
6779 | { | |
6780 | c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE); | |
6781 | OMP_CLAUSE_DECL (c) = last; | |
6782 | OMP_CLAUSE_CHAIN (c) = clauses; | |
6783 | clauses = c; | |
6784 | } | |
6785 | c = build_omp_clause (input_location, OMP_CLAUSE_PRIVATE); | |
6786 | OMP_CLAUSE_DECL (c) = decl; | |
6787 | OMP_CLAUSE_CHAIN (c) = clauses; | |
6788 | clauses = c; | |
6789 | c = build_omp_clause (input_location, OMP_CLAUSE__CILK_FOR_COUNT_); | |
6790 | OMP_CLAUSE_OPERAND (c, 0) | |
6791 | = cilk_for_number_of_iterations (omp_for); | |
6792 | OMP_CLAUSE_CHAIN (c) = clauses; | |
6793 | OMP_PARALLEL_CLAUSES (omp_par) = finish_omp_clauses (c); | |
6794 | add_stmt (omp_par); | |
6795 | return omp_par; | |
6796 | } | |
6797 | else if (code == CILK_FOR && processing_template_decl) | |
6798 | { | |
6799 | tree c, clauses = OMP_FOR_CLAUSES (omp_for); | |
6800 | if (orig_decl && orig_decl != decl) | |
6801 | { | |
6802 | c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE); | |
6803 | OMP_CLAUSE_DECL (c) = orig_decl; | |
6804 | OMP_CLAUSE_CHAIN (c) = clauses; | |
6805 | clauses = c; | |
6806 | } | |
6807 | if (last) | |
6808 | { | |
6809 | c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE); | |
6810 | OMP_CLAUSE_DECL (c) = last; | |
6811 | OMP_CLAUSE_CHAIN (c) = clauses; | |
6812 | clauses = c; | |
6813 | } | |
6814 | OMP_FOR_CLAUSES (omp_for) = clauses; | |
6815 | } | |
b25fbb3e | 6816 | return omp_for; |
8487df40 | 6817 | } |
6818 | ||
6819 | void | |
2169f33b | 6820 | finish_omp_atomic (enum tree_code code, enum tree_code opcode, tree lhs, |
bc7bff74 | 6821 | tree rhs, tree v, tree lhs1, tree rhs1, bool seq_cst) |
8487df40 | 6822 | { |
221e68f2 | 6823 | tree orig_lhs; |
6824 | tree orig_rhs; | |
2169f33b | 6825 | tree orig_v; |
6826 | tree orig_lhs1; | |
6827 | tree orig_rhs1; | |
221e68f2 | 6828 | bool dependent_p; |
6d2e04be | 6829 | tree stmt; |
6830 | ||
221e68f2 | 6831 | orig_lhs = lhs; |
6832 | orig_rhs = rhs; | |
2169f33b | 6833 | orig_v = v; |
6834 | orig_lhs1 = lhs1; | |
6835 | orig_rhs1 = rhs1; | |
221e68f2 | 6836 | dependent_p = false; |
6837 | stmt = NULL_TREE; | |
6838 | ||
6839 | /* Even in a template, we can detect invalid uses of the atomic | |
6840 | pragma if neither LHS nor RHS is type-dependent. */ | |
6841 | if (processing_template_decl) | |
6d2e04be | 6842 | { |
221e68f2 | 6843 | dependent_p = (type_dependent_expression_p (lhs) |
2169f33b | 6844 | || (rhs && type_dependent_expression_p (rhs)) |
6845 | || (v && type_dependent_expression_p (v)) | |
6846 | || (lhs1 && type_dependent_expression_p (lhs1)) | |
6847 | || (rhs1 && type_dependent_expression_p (rhs1))); | |
221e68f2 | 6848 | if (!dependent_p) |
6d2e04be | 6849 | { |
6850 | lhs = build_non_dependent_expr (lhs); | |
2169f33b | 6851 | if (rhs) |
6852 | rhs = build_non_dependent_expr (rhs); | |
6853 | if (v) | |
6854 | v = build_non_dependent_expr (v); | |
6855 | if (lhs1) | |
6856 | lhs1 = build_non_dependent_expr (lhs1); | |
6857 | if (rhs1) | |
6858 | rhs1 = build_non_dependent_expr (rhs1); | |
6d2e04be | 6859 | } |
221e68f2 | 6860 | } |
6861 | if (!dependent_p) | |
6862 | { | |
bc7bff74 | 6863 | bool swapped = false; |
6864 | if (rhs1 && cp_tree_equal (lhs, rhs)) | |
6865 | { | |
a4f59596 | 6866 | std::swap (rhs, rhs1); |
bc7bff74 | 6867 | swapped = !commutative_tree_code (opcode); |
6868 | } | |
6869 | if (rhs1 && !cp_tree_equal (lhs, rhs1)) | |
6870 | { | |
6871 | if (code == OMP_ATOMIC) | |
6872 | error ("%<#pragma omp atomic update%> uses two different " | |
6873 | "expressions for memory"); | |
6874 | else | |
6875 | error ("%<#pragma omp atomic capture%> uses two different " | |
6876 | "expressions for memory"); | |
6877 | return; | |
6878 | } | |
6879 | if (lhs1 && !cp_tree_equal (lhs, lhs1)) | |
6880 | { | |
6881 | if (code == OMP_ATOMIC) | |
6882 | error ("%<#pragma omp atomic update%> uses two different " | |
6883 | "expressions for memory"); | |
6884 | else | |
6885 | error ("%<#pragma omp atomic capture%> uses two different " | |
6886 | "expressions for memory"); | |
6887 | return; | |
6888 | } | |
2169f33b | 6889 | stmt = c_finish_omp_atomic (input_location, code, opcode, lhs, rhs, |
bc7bff74 | 6890 | v, lhs1, rhs1, swapped, seq_cst); |
221e68f2 | 6891 | if (stmt == error_mark_node) |
6892 | return; | |
6d2e04be | 6893 | } |
221e68f2 | 6894 | if (processing_template_decl) |
2169f33b | 6895 | { |
6896 | if (code == OMP_ATOMIC_READ) | |
6897 | { | |
255b5d15 | 6898 | stmt = build_min_nt_loc (EXPR_LOCATION (orig_lhs), |
6899 | OMP_ATOMIC_READ, orig_lhs); | |
bc7bff74 | 6900 | OMP_ATOMIC_SEQ_CST (stmt) = seq_cst; |
2169f33b | 6901 | stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt); |
6902 | } | |
6903 | else | |
6904 | { | |
6905 | if (opcode == NOP_EXPR) | |
6906 | stmt = build2 (MODIFY_EXPR, void_type_node, orig_lhs, orig_rhs); | |
6907 | else | |
6908 | stmt = build2 (opcode, void_type_node, orig_lhs, orig_rhs); | |
6909 | if (orig_rhs1) | |
255b5d15 | 6910 | stmt = build_min_nt_loc (EXPR_LOCATION (orig_rhs1), |
6911 | COMPOUND_EXPR, orig_rhs1, stmt); | |
2169f33b | 6912 | if (code != OMP_ATOMIC) |
6913 | { | |
255b5d15 | 6914 | stmt = build_min_nt_loc (EXPR_LOCATION (orig_lhs1), |
6915 | code, orig_lhs1, stmt); | |
bc7bff74 | 6916 | OMP_ATOMIC_SEQ_CST (stmt) = seq_cst; |
2169f33b | 6917 | stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt); |
6918 | } | |
6919 | } | |
6920 | stmt = build2 (OMP_ATOMIC, void_type_node, integer_zero_node, stmt); | |
bc7bff74 | 6921 | OMP_ATOMIC_SEQ_CST (stmt) = seq_cst; |
2169f33b | 6922 | } |
392f696d | 6923 | finish_expr_stmt (stmt); |
8487df40 | 6924 | } |
6925 | ||
6926 | void | |
6927 | finish_omp_barrier (void) | |
6928 | { | |
b9a16870 | 6929 | tree fn = builtin_decl_explicit (BUILT_IN_GOMP_BARRIER); |
f1f41a6c | 6930 | vec<tree, va_gc> *vec = make_tree_vector (); |
f352a3fb | 6931 | tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error); |
6932 | release_tree_vector (vec); | |
8487df40 | 6933 | finish_expr_stmt (stmt); |
6934 | } | |
6935 | ||
6936 | void | |
6937 | finish_omp_flush (void) | |
6938 | { | |
b9a16870 | 6939 | tree fn = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE); |
f1f41a6c | 6940 | vec<tree, va_gc> *vec = make_tree_vector (); |
f352a3fb | 6941 | tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error); |
6942 | release_tree_vector (vec); | |
8487df40 | 6943 | finish_expr_stmt (stmt); |
6944 | } | |
6945 | ||
fd6481cf | 6946 | void |
6947 | finish_omp_taskwait (void) | |
8487df40 | 6948 | { |
b9a16870 | 6949 | tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT); |
f1f41a6c | 6950 | vec<tree, va_gc> *vec = make_tree_vector (); |
f352a3fb | 6951 | tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error); |
6952 | release_tree_vector (vec); | |
fd6481cf | 6953 | finish_expr_stmt (stmt); |
8487df40 | 6954 | } |
2169f33b | 6955 | |
6956 | void | |
6957 | finish_omp_taskyield (void) | |
6958 | { | |
b9a16870 | 6959 | tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD); |
f1f41a6c | 6960 | vec<tree, va_gc> *vec = make_tree_vector (); |
2169f33b | 6961 | tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error); |
6962 | release_tree_vector (vec); | |
6963 | finish_expr_stmt (stmt); | |
6964 | } | |
bc7bff74 | 6965 | |
6966 | void | |
6967 | finish_omp_cancel (tree clauses) | |
6968 | { | |
6969 | tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL); | |
6970 | int mask = 0; | |
6971 | if (find_omp_clause (clauses, OMP_CLAUSE_PARALLEL)) | |
6972 | mask = 1; | |
6973 | else if (find_omp_clause (clauses, OMP_CLAUSE_FOR)) | |
6974 | mask = 2; | |
6975 | else if (find_omp_clause (clauses, OMP_CLAUSE_SECTIONS)) | |
6976 | mask = 4; | |
6977 | else if (find_omp_clause (clauses, OMP_CLAUSE_TASKGROUP)) | |
6978 | mask = 8; | |
6979 | else | |
6980 | { | |
6981 | error ("%<#pragma omp cancel must specify one of " | |
6982 | "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses"); | |
6983 | return; | |
6984 | } | |
6985 | vec<tree, va_gc> *vec = make_tree_vector (); | |
6986 | tree ifc = find_omp_clause (clauses, OMP_CLAUSE_IF); | |
6987 | if (ifc != NULL_TREE) | |
6988 | { | |
6989 | tree type = TREE_TYPE (OMP_CLAUSE_IF_EXPR (ifc)); | |
6990 | ifc = fold_build2_loc (OMP_CLAUSE_LOCATION (ifc), NE_EXPR, | |
6991 | boolean_type_node, OMP_CLAUSE_IF_EXPR (ifc), | |
6992 | build_zero_cst (type)); | |
6993 | } | |
6994 | else | |
6995 | ifc = boolean_true_node; | |
6996 | vec->quick_push (build_int_cst (integer_type_node, mask)); | |
6997 | vec->quick_push (ifc); | |
6998 | tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error); | |
6999 | release_tree_vector (vec); | |
7000 | finish_expr_stmt (stmt); | |
7001 | } | |
7002 | ||
7003 | void | |
7004 | finish_omp_cancellation_point (tree clauses) | |
7005 | { | |
7006 | tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT); | |
7007 | int mask = 0; | |
7008 | if (find_omp_clause (clauses, OMP_CLAUSE_PARALLEL)) | |
7009 | mask = 1; | |
7010 | else if (find_omp_clause (clauses, OMP_CLAUSE_FOR)) | |
7011 | mask = 2; | |
7012 | else if (find_omp_clause (clauses, OMP_CLAUSE_SECTIONS)) | |
7013 | mask = 4; | |
7014 | else if (find_omp_clause (clauses, OMP_CLAUSE_TASKGROUP)) | |
7015 | mask = 8; | |
7016 | else | |
7017 | { | |
7018 | error ("%<#pragma omp cancellation point must specify one of " | |
7019 | "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses"); | |
7020 | return; | |
7021 | } | |
7022 | vec<tree, va_gc> *vec | |
7023 | = make_tree_vector_single (build_int_cst (integer_type_node, mask)); | |
7024 | tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error); | |
7025 | release_tree_vector (vec); | |
7026 | finish_expr_stmt (stmt); | |
7027 | } | |
8487df40 | 7028 | \f |
4c0315d0 | 7029 | /* Begin a __transaction_atomic or __transaction_relaxed statement. |
7030 | If PCOMPOUND is non-null, this is for a function-transaction-block, and we | |
7031 | should create an extra compound stmt. */ | |
7032 | ||
7033 | tree | |
7034 | begin_transaction_stmt (location_t loc, tree *pcompound, int flags) | |
7035 | { | |
7036 | tree r; | |
7037 | ||
7038 | if (pcompound) | |
7039 | *pcompound = begin_compound_stmt (0); | |
7040 | ||
7041 | r = build_stmt (loc, TRANSACTION_EXPR, NULL_TREE); | |
7042 | ||
7043 | /* Only add the statement to the function if support enabled. */ | |
7044 | if (flag_tm) | |
7045 | add_stmt (r); | |
7046 | else | |
7047 | error_at (loc, ((flags & TM_STMT_ATTR_RELAXED) != 0 | |
7048 | ? G_("%<__transaction_relaxed%> without " | |
7049 | "transactional memory support enabled") | |
7050 | : G_("%<__transaction_atomic%> without " | |
7051 | "transactional memory support enabled"))); | |
7052 | ||
7053 | TRANSACTION_EXPR_BODY (r) = push_stmt_list (); | |
06bdd360 | 7054 | TREE_SIDE_EFFECTS (r) = 1; |
4c0315d0 | 7055 | return r; |
7056 | } | |
7057 | ||
7058 | /* End a __transaction_atomic or __transaction_relaxed statement. | |
7059 | If COMPOUND_STMT is non-null, this is for a function-transaction-block, | |
f770bf53 | 7060 | and we should end the compound. If NOEX is non-NULL, we wrap the body in |
7061 | a MUST_NOT_THROW_EXPR with NOEX as condition. */ | |
4c0315d0 | 7062 | |
7063 | void | |
f770bf53 | 7064 | finish_transaction_stmt (tree stmt, tree compound_stmt, int flags, tree noex) |
4c0315d0 | 7065 | { |
7066 | TRANSACTION_EXPR_BODY (stmt) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt)); | |
7067 | TRANSACTION_EXPR_OUTER (stmt) = (flags & TM_STMT_ATTR_OUTER) != 0; | |
7068 | TRANSACTION_EXPR_RELAXED (stmt) = (flags & TM_STMT_ATTR_RELAXED) != 0; | |
7069 | TRANSACTION_EXPR_IS_STMT (stmt) = 1; | |
7070 | ||
f770bf53 | 7071 | /* noexcept specifications are not allowed for function transactions. */ |
7072 | gcc_assert (!(noex && compound_stmt)); | |
7073 | if (noex) | |
7074 | { | |
7075 | tree body = build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt), | |
7076 | noex); | |
fd19a5dc | 7077 | /* This may not be true when the STATEMENT_LIST is empty. */ |
7078 | if (EXPR_P (body)) | |
7079 | SET_EXPR_LOCATION (body, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt))); | |
f770bf53 | 7080 | TREE_SIDE_EFFECTS (body) = 1; |
7081 | TRANSACTION_EXPR_BODY (stmt) = body; | |
7082 | } | |
7083 | ||
4c0315d0 | 7084 | if (compound_stmt) |
7085 | finish_compound_stmt (compound_stmt); | |
4c0315d0 | 7086 | } |
7087 | ||
f770bf53 | 7088 | /* Build a __transaction_atomic or __transaction_relaxed expression. If |
7089 | NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as | |
7090 | condition. */ | |
4c0315d0 | 7091 | |
7092 | tree | |
f770bf53 | 7093 | build_transaction_expr (location_t loc, tree expr, int flags, tree noex) |
4c0315d0 | 7094 | { |
7095 | tree ret; | |
f770bf53 | 7096 | if (noex) |
7097 | { | |
7098 | expr = build_must_not_throw_expr (expr, noex); | |
f5829705 | 7099 | if (EXPR_P (expr)) |
7100 | SET_EXPR_LOCATION (expr, loc); | |
f770bf53 | 7101 | TREE_SIDE_EFFECTS (expr) = 1; |
7102 | } | |
4c0315d0 | 7103 | ret = build1 (TRANSACTION_EXPR, TREE_TYPE (expr), expr); |
7104 | if (flags & TM_STMT_ATTR_RELAXED) | |
7105 | TRANSACTION_EXPR_RELAXED (ret) = 1; | |
06bdd360 | 7106 | TREE_SIDE_EFFECTS (ret) = 1; |
4c0315d0 | 7107 | SET_EXPR_LOCATION (ret, loc); |
7108 | return ret; | |
7109 | } | |
7110 | \f | |
41fb2c18 | 7111 | void |
807be5b4 | 7112 | init_cp_semantics (void) |
41fb2c18 | 7113 | { |
41fb2c18 | 7114 | } |
7a05c4b1 | 7115 | \f |
7116 | /* Build a STATIC_ASSERT for a static assertion with the condition | |
7117 | CONDITION and the message text MESSAGE. LOCATION is the location | |
7118 | of the static assertion in the source code. When MEMBER_P, this | |
7119 | static assertion is a member of a class. */ | |
7120 | void | |
7121 | finish_static_assert (tree condition, tree message, location_t location, | |
7122 | bool member_p) | |
7123 | { | |
530f9e00 | 7124 | if (message == NULL_TREE |
7125 | || message == error_mark_node | |
7126 | || condition == NULL_TREE | |
7127 | || condition == error_mark_node) | |
7128 | return; | |
7129 | ||
830a6615 | 7130 | if (check_for_bare_parameter_packs (condition)) |
7131 | condition = error_mark_node; | |
7132 | ||
7a05c4b1 | 7133 | if (type_dependent_expression_p (condition) |
7134 | || value_dependent_expression_p (condition)) | |
7135 | { | |
7136 | /* We're in a template; build a STATIC_ASSERT and put it in | |
7137 | the right place. */ | |
7138 | tree assertion; | |
7139 | ||
7140 | assertion = make_node (STATIC_ASSERT); | |
7141 | STATIC_ASSERT_CONDITION (assertion) = condition; | |
7142 | STATIC_ASSERT_MESSAGE (assertion) = message; | |
7143 | STATIC_ASSERT_SOURCE_LOCATION (assertion) = location; | |
7144 | ||
7145 | if (member_p) | |
7146 | maybe_add_class_template_decl_list (current_class_type, | |
7147 | assertion, | |
7148 | /*friend_p=*/0); | |
7149 | else | |
7150 | add_stmt (assertion); | |
7151 | ||
7152 | return; | |
7153 | } | |
7154 | ||
7155 | /* Fold the expression and convert it to a boolean value. */ | |
21131a05 | 7156 | condition = instantiate_non_dependent_expr (condition); |
c4698a21 | 7157 | condition = cp_convert (boolean_type_node, condition, tf_warning_or_error); |
ce984e5e | 7158 | condition = maybe_constant_value (condition); |
7a05c4b1 | 7159 | |
7160 | if (TREE_CODE (condition) == INTEGER_CST && !integer_zerop (condition)) | |
7161 | /* Do nothing; the condition is satisfied. */ | |
7162 | ; | |
7163 | else | |
7164 | { | |
7165 | location_t saved_loc = input_location; | |
7166 | ||
7167 | input_location = location; | |
7168 | if (TREE_CODE (condition) == INTEGER_CST | |
7169 | && integer_zerop (condition)) | |
1f6b3916 | 7170 | { |
7171 | int sz = TREE_INT_CST_LOW (TYPE_SIZE_UNIT | |
7172 | (TREE_TYPE (TREE_TYPE (message)))); | |
7173 | int len = TREE_STRING_LENGTH (message) / sz - 1; | |
7174 | /* Report the error. */ | |
7175 | if (len == 0) | |
7176 | error ("static assertion failed"); | |
7177 | else | |
7178 | error ("static assertion failed: %s", | |
7179 | TREE_STRING_POINTER (message)); | |
7180 | } | |
7a05c4b1 | 7181 | else if (condition && condition != error_mark_node) |
ce984e5e | 7182 | { |
7183 | error ("non-constant condition for static assertion"); | |
4e839e56 | 7184 | if (require_potential_rvalue_constant_expression (condition)) |
7185 | cxx_constant_value (condition); | |
ce984e5e | 7186 | } |
7a05c4b1 | 7187 | input_location = saved_loc; |
7188 | } | |
7189 | } | |
34da8800 | 7190 | \f |
7191 | /* Implements the C++0x decltype keyword. Returns the type of EXPR, | |
7192 | suitable for use as a type-specifier. | |
7193 | ||
7194 | ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an | |
7195 | id-expression or a class member access, FALSE when it was parsed as | |
7196 | a full expression. */ | |
3986b463 | 7197 | |
34da8800 | 7198 | tree |
c2b6be66 | 7199 | finish_decltype_type (tree expr, bool id_expression_or_member_access_p, |
7200 | tsubst_flags_t complain) | |
34da8800 | 7201 | { |
ca3ea3bd | 7202 | tree type = NULL_TREE; |
34da8800 | 7203 | |
a7905afa | 7204 | if (!expr || error_operand_p (expr)) |
7205 | return error_mark_node; | |
7206 | ||
711178fb | 7207 | if (TYPE_P (expr) |
7208 | || TREE_CODE (expr) == TYPE_DECL | |
7209 | || (TREE_CODE (expr) == BIT_NOT_EXPR | |
7210 | && TYPE_P (TREE_OPERAND (expr, 0)))) | |
7211 | { | |
c2b6be66 | 7212 | if (complain & tf_error) |
7213 | error ("argument to decltype must be an expression"); | |
711178fb | 7214 | return error_mark_node; |
7215 | } | |
7216 | ||
288dc77b | 7217 | /* Depending on the resolution of DR 1172, we may later need to distinguish |
7218 | instantiation-dependent but not type-dependent expressions so that, say, | |
7219 | A<decltype(sizeof(T))>::U doesn't require 'typename'. */ | |
7220 | if (instantiation_dependent_expression_p (expr)) | |
34da8800 | 7221 | { |
95397ff9 | 7222 | type = cxx_make_type (DECLTYPE_TYPE); |
34da8800 | 7223 | DECLTYPE_TYPE_EXPR (type) = expr; |
7224 | DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type) | |
7225 | = id_expression_or_member_access_p; | |
7226 | SET_TYPE_STRUCTURAL_EQUALITY (type); | |
7227 | ||
7228 | return type; | |
7229 | } | |
7230 | ||
7231 | /* The type denoted by decltype(e) is defined as follows: */ | |
7232 | ||
eebd67e7 | 7233 | expr = resolve_nondeduced_context (expr); |
8b25863e | 7234 | |
5c874cd3 | 7235 | if (invalid_nonstatic_memfn_p (input_location, expr, complain)) |
e1079908 | 7236 | return error_mark_node; |
7237 | ||
07bbe61e | 7238 | if (type_unknown_p (expr)) |
7239 | { | |
7240 | if (complain & tf_error) | |
7241 | error ("decltype cannot resolve address of overloaded function"); | |
7242 | return error_mark_node; | |
7243 | } | |
7244 | ||
8b25863e | 7245 | /* To get the size of a static data member declared as an array of |
7246 | unknown bound, we need to instantiate it. */ | |
80a58eb0 | 7247 | if (VAR_P (expr) |
8b25863e | 7248 | && VAR_HAD_UNKNOWN_BOUND (expr) |
7249 | && DECL_TEMPLATE_INSTANTIATION (expr)) | |
7250 | instantiate_decl (expr, /*defer_ok*/true, /*expl_inst_mem*/false); | |
7251 | ||
34da8800 | 7252 | if (id_expression_or_member_access_p) |
7253 | { | |
7254 | /* If e is an id-expression or a class member access (5.2.5 | |
7255 | [expr.ref]), decltype(e) is defined as the type of the entity | |
7256 | named by e. If there is no such entity, or e names a set of | |
7257 | overloaded functions, the program is ill-formed. */ | |
694683bb | 7258 | if (identifier_p (expr)) |
34da8800 | 7259 | expr = lookup_name (expr); |
7260 | ||
86ccc124 | 7261 | if (INDIRECT_REF_P (expr)) |
34da8800 | 7262 | /* This can happen when the expression is, e.g., "a.b". Just |
7263 | look at the underlying operand. */ | |
7264 | expr = TREE_OPERAND (expr, 0); | |
7265 | ||
7266 | if (TREE_CODE (expr) == OFFSET_REF | |
0943ab30 | 7267 | || TREE_CODE (expr) == MEMBER_REF |
7268 | || TREE_CODE (expr) == SCOPE_REF) | |
34da8800 | 7269 | /* We're only interested in the field itself. If it is a |
7270 | BASELINK, we will need to see through it in the next | |
7271 | step. */ | |
7272 | expr = TREE_OPERAND (expr, 1); | |
7273 | ||
a00f651a | 7274 | if (BASELINK_P (expr)) |
07bbe61e | 7275 | /* See through BASELINK nodes to the underlying function. */ |
34da8800 | 7276 | expr = BASELINK_FUNCTIONS (expr); |
7277 | ||
34da8800 | 7278 | switch (TREE_CODE (expr)) |
7279 | { | |
7280 | case FIELD_DECL: | |
557902f7 | 7281 | if (DECL_BIT_FIELD_TYPE (expr)) |
34da8800 | 7282 | { |
7283 | type = DECL_BIT_FIELD_TYPE (expr); | |
7284 | break; | |
7285 | } | |
7286 | /* Fall through for fields that aren't bitfields. */ | |
7287 | ||
7288 | case FUNCTION_DECL: | |
7289 | case VAR_DECL: | |
7290 | case CONST_DECL: | |
7291 | case PARM_DECL: | |
7292 | case RESULT_DECL: | |
6c2d37e1 | 7293 | case TEMPLATE_PARM_INDEX: |
fbb73d9b | 7294 | expr = mark_type_use (expr); |
34da8800 | 7295 | type = TREE_TYPE (expr); |
7296 | break; | |
7297 | ||
7298 | case ERROR_MARK: | |
7299 | type = error_mark_node; | |
7300 | break; | |
7301 | ||
7302 | case COMPONENT_REF: | |
cc248c6e | 7303 | case COMPOUND_EXPR: |
fbb73d9b | 7304 | mark_type_use (expr); |
34da8800 | 7305 | type = is_bitfield_expr_with_lowered_type (expr); |
7306 | if (!type) | |
7307 | type = TREE_TYPE (TREE_OPERAND (expr, 1)); | |
7308 | break; | |
7309 | ||
7310 | case BIT_FIELD_REF: | |
7311 | gcc_unreachable (); | |
7312 | ||
7313 | case INTEGER_CST: | |
44a7454c | 7314 | case PTRMEM_CST: |
34da8800 | 7315 | /* We can get here when the id-expression refers to an |
44a7454c | 7316 | enumerator or non-type template parameter. */ |
34da8800 | 7317 | type = TREE_TYPE (expr); |
7318 | break; | |
7319 | ||
7320 | default: | |
a1554f13 | 7321 | /* Handle instantiated template non-type arguments. */ |
7322 | type = TREE_TYPE (expr); | |
7323 | break; | |
34da8800 | 7324 | } |
7325 | } | |
7326 | else | |
7327 | { | |
dbeb1e25 | 7328 | /* Within a lambda-expression: |
7329 | ||
7330 | Every occurrence of decltype((x)) where x is a possibly | |
7331 | parenthesized id-expression that names an entity of | |
7332 | automatic storage duration is treated as if x were | |
7333 | transformed into an access to a corresponding data member | |
7334 | of the closure type that would have been declared if x | |
7335 | were a use of the denoted entity. */ | |
7336 | if (outer_automatic_var_p (expr) | |
7337 | && current_function_decl | |
7338 | && LAMBDA_FUNCTION_P (current_function_decl)) | |
7339 | type = capture_decltype (expr); | |
7340 | else if (error_operand_p (expr)) | |
7341 | type = error_mark_node; | |
7342 | else if (expr == current_class_ptr) | |
7343 | /* If the expression is just "this", we want the | |
7344 | cv-unqualified pointer for the "this" type. */ | |
7345 | type = TYPE_MAIN_VARIANT (TREE_TYPE (expr)); | |
7346 | else | |
7347 | { | |
7348 | /* Otherwise, where T is the type of e, if e is an lvalue, | |
7349 | decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */ | |
7350 | cp_lvalue_kind clk = lvalue_kind (expr); | |
7351 | type = unlowered_expr_type (expr); | |
7352 | gcc_assert (TREE_CODE (type) != REFERENCE_TYPE); | |
e779f859 | 7353 | |
7354 | /* For vector types, pick a non-opaque variant. */ | |
76249021 | 7355 | if (VECTOR_TYPE_P (type)) |
e779f859 | 7356 | type = strip_typedefs (type); |
7357 | ||
dbeb1e25 | 7358 | if (clk != clk_none && !(clk & clk_class)) |
7359 | type = cp_build_reference_type (type, (clk & clk_rvalueref)); | |
7360 | } | |
34da8800 | 7361 | } |
7362 | ||
34da8800 | 7363 | return type; |
7364 | } | |
9b57b06b | 7365 | |
0aa5d886 | 7366 | /* Called from trait_expr_value to evaluate either __has_nothrow_assign or |
7367 | __has_nothrow_copy, depending on assign_p. */ | |
481451eb | 7368 | |
7369 | static bool | |
0aa5d886 | 7370 | classtype_has_nothrow_assign_or_copy_p (tree type, bool assign_p) |
481451eb | 7371 | { |
0aa5d886 | 7372 | tree fns; |
481451eb | 7373 | |
0aa5d886 | 7374 | if (assign_p) |
7375 | { | |
7376 | int ix; | |
7377 | ix = lookup_fnfields_1 (type, ansi_assopname (NOP_EXPR)); | |
7378 | if (ix < 0) | |
481451eb | 7379 | return false; |
f1f41a6c | 7380 | fns = (*CLASSTYPE_METHOD_VEC (type))[ix]; |
0aa5d886 | 7381 | } |
ab8002de | 7382 | else if (TYPE_HAS_COPY_CTOR (type)) |
0aa5d886 | 7383 | { |
7384 | /* If construction of the copy constructor was postponed, create | |
7385 | it now. */ | |
7386 | if (CLASSTYPE_LAZY_COPY_CTOR (type)) | |
7387 | lazily_declare_fn (sfk_copy_constructor, type); | |
a8b75081 | 7388 | if (CLASSTYPE_LAZY_MOVE_CTOR (type)) |
7389 | lazily_declare_fn (sfk_move_constructor, type); | |
0aa5d886 | 7390 | fns = CLASSTYPE_CONSTRUCTORS (type); |
481451eb | 7391 | } |
7392 | else | |
7393 | return false; | |
7394 | ||
0aa5d886 | 7395 | for (; fns; fns = OVL_NEXT (fns)) |
e88a1fbf | 7396 | { |
7397 | tree fn = OVL_CURRENT (fns); | |
7398 | ||
7399 | if (assign_p) | |
7400 | { | |
7401 | if (copy_fn_p (fn) == 0) | |
7402 | continue; | |
7403 | } | |
7404 | else if (copy_fn_p (fn) <= 0) | |
7405 | continue; | |
7406 | ||
a7ddc63a | 7407 | maybe_instantiate_noexcept (fn); |
e88a1fbf | 7408 | if (!TYPE_NOTHROW_P (TREE_TYPE (fn))) |
7409 | return false; | |
7410 | } | |
0aa5d886 | 7411 | |
481451eb | 7412 | return true; |
7413 | } | |
7414 | ||
7415 | /* Actually evaluates the trait. */ | |
7416 | ||
7417 | static bool | |
7418 | trait_expr_value (cp_trait_kind kind, tree type1, tree type2) | |
7419 | { | |
7420 | enum tree_code type_code1; | |
7421 | tree t; | |
7422 | ||
7423 | type_code1 = TREE_CODE (type1); | |
7424 | ||
7425 | switch (kind) | |
7426 | { | |
7427 | case CPTK_HAS_NOTHROW_ASSIGN: | |
c1c67b4f | 7428 | type1 = strip_array_types (type1); |
0aa5d886 | 7429 | return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE |
7430 | && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN, type1, type2) | |
7431 | || (CLASS_TYPE_P (type1) | |
7432 | && classtype_has_nothrow_assign_or_copy_p (type1, | |
7433 | true)))); | |
481451eb | 7434 | |
7435 | case CPTK_HAS_TRIVIAL_ASSIGN: | |
c1c67b4f | 7436 | /* ??? The standard seems to be missing the "or array of such a class |
7437 | type" wording for this trait. */ | |
7438 | type1 = strip_array_types (type1); | |
481451eb | 7439 | return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE |
c1c67b4f | 7440 | && (trivial_type_p (type1) |
481451eb | 7441 | || (CLASS_TYPE_P (type1) |
ab8002de | 7442 | && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1)))); |
481451eb | 7443 | |
7444 | case CPTK_HAS_NOTHROW_CONSTRUCTOR: | |
7445 | type1 = strip_array_types (type1); | |
7446 | return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR, type1, type2) | |
7447 | || (CLASS_TYPE_P (type1) | |
2ee92e27 | 7448 | && (t = locate_ctor (type1)) |
ca4b338d | 7449 | && (maybe_instantiate_noexcept (t), |
7450 | TYPE_NOTHROW_P (TREE_TYPE (t))))); | |
481451eb | 7451 | |
7452 | case CPTK_HAS_TRIVIAL_CONSTRUCTOR: | |
7453 | type1 = strip_array_types (type1); | |
c1c67b4f | 7454 | return (trivial_type_p (type1) |
481451eb | 7455 | || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DFLT (type1))); |
7456 | ||
7457 | case CPTK_HAS_NOTHROW_COPY: | |
c1c67b4f | 7458 | type1 = strip_array_types (type1); |
481451eb | 7459 | return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY, type1, type2) |
7460 | || (CLASS_TYPE_P (type1) | |
0aa5d886 | 7461 | && classtype_has_nothrow_assign_or_copy_p (type1, false))); |
481451eb | 7462 | |
7463 | case CPTK_HAS_TRIVIAL_COPY: | |
c1c67b4f | 7464 | /* ??? The standard seems to be missing the "or array of such a class |
7465 | type" wording for this trait. */ | |
7466 | type1 = strip_array_types (type1); | |
7467 | return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE | |
ab8002de | 7468 | || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1))); |
481451eb | 7469 | |
7470 | case CPTK_HAS_TRIVIAL_DESTRUCTOR: | |
7471 | type1 = strip_array_types (type1); | |
c1c67b4f | 7472 | return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE |
481451eb | 7473 | || (CLASS_TYPE_P (type1) |
7474 | && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1))); | |
7475 | ||
7476 | case CPTK_HAS_VIRTUAL_DESTRUCTOR: | |
0f16033e | 7477 | return type_has_virtual_destructor (type1); |
481451eb | 7478 | |
7479 | case CPTK_IS_ABSTRACT: | |
793fb8f3 | 7480 | return (ABSTRACT_CLASS_TYPE_P (type1)); |
481451eb | 7481 | |
7482 | case CPTK_IS_BASE_OF: | |
7483 | return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2) | |
7664f7a0 | 7484 | && (same_type_ignoring_top_level_qualifiers_p (type1, type2) |
7485 | || DERIVED_FROM_P (type1, type2))); | |
481451eb | 7486 | |
7487 | case CPTK_IS_CLASS: | |
7488 | return (NON_UNION_CLASS_TYPE_P (type1)); | |
7489 | ||
481451eb | 7490 | case CPTK_IS_EMPTY: |
7491 | return (NON_UNION_CLASS_TYPE_P (type1) && CLASSTYPE_EMPTY_P (type1)); | |
7492 | ||
7493 | case CPTK_IS_ENUM: | |
7494 | return (type_code1 == ENUMERAL_TYPE); | |
7495 | ||
aa4313eb | 7496 | case CPTK_IS_FINAL: |
7497 | return (CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1)); | |
7498 | ||
23407dc9 | 7499 | case CPTK_IS_LITERAL_TYPE: |
7500 | return (literal_type_p (type1)); | |
7501 | ||
481451eb | 7502 | case CPTK_IS_POD: |
7503 | return (pod_type_p (type1)); | |
7504 | ||
7505 | case CPTK_IS_POLYMORPHIC: | |
7506 | return (CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1)); | |
7507 | ||
c1c67b4f | 7508 | case CPTK_IS_STD_LAYOUT: |
7509 | return (std_layout_type_p (type1)); | |
7510 | ||
7511 | case CPTK_IS_TRIVIAL: | |
7512 | return (trivial_type_p (type1)); | |
7513 | ||
f76a9aa8 | 7514 | case CPTK_IS_TRIVIALLY_ASSIGNABLE: |
7515 | return is_trivially_xible (MODIFY_EXPR, type1, type2); | |
7516 | ||
7517 | case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: | |
7518 | return is_trivially_xible (INIT_EXPR, type1, type2); | |
7519 | ||
717e52f9 | 7520 | case CPTK_IS_TRIVIALLY_COPYABLE: |
7521 | return (trivially_copyable_p (type1)); | |
7522 | ||
481451eb | 7523 | case CPTK_IS_UNION: |
7524 | return (type_code1 == UNION_TYPE); | |
7525 | ||
7526 | default: | |
7527 | gcc_unreachable (); | |
7528 | return false; | |
7529 | } | |
7530 | } | |
7531 | ||
8215802e | 7532 | /* If TYPE is an array of unknown bound, or (possibly cv-qualified) |
f76a9aa8 | 7533 | void, or a complete type, returns true, otherwise false. */ |
ad0f709b | 7534 | |
f76a9aa8 | 7535 | static bool |
ad0f709b | 7536 | check_trait_type (tree type) |
7537 | { | |
f76a9aa8 | 7538 | if (type == NULL_TREE) |
7539 | return true; | |
7540 | ||
7541 | if (TREE_CODE (type) == TREE_LIST) | |
7542 | return (check_trait_type (TREE_VALUE (type)) | |
7543 | && check_trait_type (TREE_CHAIN (type))); | |
7544 | ||
e6bc5891 | 7545 | if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type) |
7546 | && COMPLETE_TYPE_P (TREE_TYPE (type))) | |
f76a9aa8 | 7547 | return true; |
ad0f709b | 7548 | |
7549 | if (VOID_TYPE_P (type)) | |
f76a9aa8 | 7550 | return true; |
ad0f709b | 7551 | |
f76a9aa8 | 7552 | return !!complete_type_or_else (strip_array_types (type), NULL_TREE); |
ad0f709b | 7553 | } |
7554 | ||
481451eb | 7555 | /* Process a trait expression. */ |
7556 | ||
7557 | tree | |
7558 | finish_trait_expr (cp_trait_kind kind, tree type1, tree type2) | |
7559 | { | |
481451eb | 7560 | if (type1 == error_mark_node |
f76a9aa8 | 7561 | || type2 == error_mark_node) |
481451eb | 7562 | return error_mark_node; |
7563 | ||
7564 | if (processing_template_decl) | |
7565 | { | |
7566 | tree trait_expr = make_node (TRAIT_EXPR); | |
7567 | TREE_TYPE (trait_expr) = boolean_type_node; | |
7568 | TRAIT_EXPR_TYPE1 (trait_expr) = type1; | |
7569 | TRAIT_EXPR_TYPE2 (trait_expr) = type2; | |
7570 | TRAIT_EXPR_KIND (trait_expr) = kind; | |
7571 | return trait_expr; | |
7572 | } | |
7573 | ||
ad0f709b | 7574 | switch (kind) |
481451eb | 7575 | { |
ad0f709b | 7576 | case CPTK_HAS_NOTHROW_ASSIGN: |
7577 | case CPTK_HAS_TRIVIAL_ASSIGN: | |
7578 | case CPTK_HAS_NOTHROW_CONSTRUCTOR: | |
7579 | case CPTK_HAS_TRIVIAL_CONSTRUCTOR: | |
7580 | case CPTK_HAS_NOTHROW_COPY: | |
7581 | case CPTK_HAS_TRIVIAL_COPY: | |
7582 | case CPTK_HAS_TRIVIAL_DESTRUCTOR: | |
7583 | case CPTK_HAS_VIRTUAL_DESTRUCTOR: | |
7584 | case CPTK_IS_ABSTRACT: | |
7585 | case CPTK_IS_EMPTY: | |
aa4313eb | 7586 | case CPTK_IS_FINAL: |
23407dc9 | 7587 | case CPTK_IS_LITERAL_TYPE: |
ad0f709b | 7588 | case CPTK_IS_POD: |
7589 | case CPTK_IS_POLYMORPHIC: | |
c1c67b4f | 7590 | case CPTK_IS_STD_LAYOUT: |
7591 | case CPTK_IS_TRIVIAL: | |
717e52f9 | 7592 | case CPTK_IS_TRIVIALLY_COPYABLE: |
ad0f709b | 7593 | if (!check_trait_type (type1)) |
8215802e | 7594 | return error_mark_node; |
ad0f709b | 7595 | break; |
f76a9aa8 | 7596 | |
7597 | case CPTK_IS_TRIVIALLY_ASSIGNABLE: | |
7598 | case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: | |
7599 | if (!check_trait_type (type1) | |
7600 | || !check_trait_type (type2)) | |
7601 | return error_mark_node; | |
7602 | break; | |
ad0f709b | 7603 | |
7604 | case CPTK_IS_BASE_OF: | |
7605 | if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2) | |
7606 | && !same_type_ignoring_top_level_qualifiers_p (type1, type2) | |
8215802e | 7607 | && !complete_type_or_else (type2, NULL_TREE)) |
7608 | /* We already issued an error. */ | |
7609 | return error_mark_node; | |
ad0f709b | 7610 | break; |
7611 | ||
7612 | case CPTK_IS_CLASS: | |
7613 | case CPTK_IS_ENUM: | |
7614 | case CPTK_IS_UNION: | |
7615 | break; | |
7616 | ||
ad0f709b | 7617 | default: |
7618 | gcc_unreachable (); | |
481451eb | 7619 | } |
7620 | ||
7621 | return (trait_expr_value (kind, type1, type2) | |
7622 | ? boolean_true_node : boolean_false_node); | |
7623 | } | |
7624 | ||
3ae3a17f | 7625 | /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64, |
7626 | which is ignored for C++. */ | |
7627 | ||
7628 | void | |
7629 | set_float_const_decimal64 (void) | |
7630 | { | |
7631 | } | |
7632 | ||
7633 | void | |
7634 | clear_float_const_decimal64 (void) | |
7635 | { | |
7636 | } | |
7637 | ||
7638 | bool | |
7639 | float_const_decimal64_p (void) | |
7640 | { | |
7641 | return 0; | |
7642 | } | |
7643 | ||
c99de541 | 7644 | \f |
09b42213 | 7645 | /* Return true if T designates the implied `this' parameter. */ |
17814aca | 7646 | |
7647 | bool | |
09b42213 | 7648 | is_this_parameter (tree t) |
4905dfb6 | 7649 | { |
09b42213 | 7650 | if (!DECL_P (t) || DECL_NAME (t) != this_identifier) |
4905dfb6 | 7651 | return false; |
09b42213 | 7652 | gcc_assert (TREE_CODE (t) == PARM_DECL || is_capture_proxy (t)); |
8be31d90 | 7653 | return true; |
7654 | } | |
7655 | ||
86359a65 | 7656 | /* Insert the deduced return type for an auto function. */ |
a8b75081 | 7657 | |
7658 | void | |
86359a65 | 7659 | apply_deduced_return_type (tree fco, tree return_type) |
a8b75081 | 7660 | { |
a8b75081 | 7661 | tree result; |
7662 | ||
a8b75081 | 7663 | if (return_type == error_mark_node) |
7664 | return; | |
7665 | ||
86359a65 | 7666 | if (LAMBDA_FUNCTION_P (fco)) |
7667 | { | |
7668 | tree lambda = CLASSTYPE_LAMBDA_EXPR (current_class_type); | |
7669 | LAMBDA_EXPR_RETURN_TYPE (lambda) = return_type; | |
7670 | } | |
7671 | ||
7672 | if (DECL_CONV_FN_P (fco)) | |
7673 | DECL_NAME (fco) = mangle_conv_op_name_for_type (return_type); | |
7674 | ||
93529b28 | 7675 | TREE_TYPE (fco) = change_return_type (return_type, TREE_TYPE (fco)); |
a8b75081 | 7676 | |
7677 | result = DECL_RESULT (fco); | |
7678 | if (result == NULL_TREE) | |
7679 | return; | |
86359a65 | 7680 | if (TREE_TYPE (result) == return_type) |
7681 | return; | |
a8b75081 | 7682 | |
7683 | /* We already have a DECL_RESULT from start_preparsed_function. | |
7684 | Now we need to redo the work it and allocate_struct_function | |
7685 | did to reflect the new type. */ | |
a75d43a4 | 7686 | gcc_assert (current_function_decl == fco); |
a8b75081 | 7687 | result = build_decl (input_location, RESULT_DECL, NULL_TREE, |
7688 | TYPE_MAIN_VARIANT (return_type)); | |
7689 | DECL_ARTIFICIAL (result) = 1; | |
7690 | DECL_IGNORED_P (result) = 1; | |
7691 | cp_apply_type_quals_to_decl (cp_type_quals (return_type), | |
7692 | result); | |
7693 | ||
7694 | DECL_RESULT (fco) = result; | |
7695 | ||
86359a65 | 7696 | if (!processing_template_decl) |
a8b75081 | 7697 | { |
90fe9d0c | 7698 | if (!VOID_TYPE_P (TREE_TYPE (result))) |
7699 | complete_type_or_else (TREE_TYPE (result), NULL_TREE); | |
86359a65 | 7700 | bool aggr = aggregate_value_p (result, fco); |
a8b75081 | 7701 | #ifdef PCC_STATIC_STRUCT_RETURN |
86359a65 | 7702 | cfun->returns_pcc_struct = aggr; |
a8b75081 | 7703 | #endif |
86359a65 | 7704 | cfun->returns_struct = aggr; |
a8b75081 | 7705 | } |
7706 | ||
7707 | } | |
7708 | ||
7709 | /* DECL is a local variable or parameter from the surrounding scope of a | |
7710 | lambda-expression. Returns the decltype for a use of the capture field | |
7711 | for DECL even if it hasn't been captured yet. */ | |
7712 | ||
7713 | static tree | |
7714 | capture_decltype (tree decl) | |
7715 | { | |
7716 | tree lam = CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (current_function_decl)); | |
7717 | /* FIXME do lookup instead of list walk? */ | |
7718 | tree cap = value_member (decl, LAMBDA_EXPR_CAPTURE_LIST (lam)); | |
7719 | tree type; | |
7720 | ||
7721 | if (cap) | |
7722 | type = TREE_TYPE (TREE_PURPOSE (cap)); | |
7723 | else | |
7724 | switch (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam)) | |
7725 | { | |
7726 | case CPLD_NONE: | |
7727 | error ("%qD is not captured", decl); | |
7728 | return error_mark_node; | |
7729 | ||
7730 | case CPLD_COPY: | |
7731 | type = TREE_TYPE (decl); | |
7732 | if (TREE_CODE (type) == REFERENCE_TYPE | |
7733 | && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE) | |
7734 | type = TREE_TYPE (type); | |
7735 | break; | |
7736 | ||
7737 | case CPLD_REFERENCE: | |
7738 | type = TREE_TYPE (decl); | |
7739 | if (TREE_CODE (type) != REFERENCE_TYPE) | |
7740 | type = build_reference_type (TREE_TYPE (decl)); | |
7741 | break; | |
7742 | ||
7743 | default: | |
7744 | gcc_unreachable (); | |
7745 | } | |
7746 | ||
7747 | if (TREE_CODE (type) != REFERENCE_TYPE) | |
7748 | { | |
7749 | if (!LAMBDA_EXPR_MUTABLE_P (lam)) | |
ce494fcf | 7750 | type = cp_build_qualified_type (type, (cp_type_quals (type) |
a8b75081 | 7751 | |TYPE_QUAL_CONST)); |
7752 | type = build_reference_type (type); | |
7753 | } | |
7754 | return type; | |
7755 | } | |
7756 | ||
9b57b06b | 7757 | #include "gt-cp-semantics.h" |