1 1.1 mrg /* Perform the semantic phase of parsing, i.e., the process of 2 1.1 mrg building tree structure, checking semantic consistency, and 3 1.1 mrg building RTL. These routines are used both during actual parsing 4 1.1 mrg and during the instantiation of template functions. 5 1.1 mrg 6 1.1 mrg Copyright (C) 1998-2022 Free Software Foundation, Inc. 7 1.1 mrg Written by Mark Mitchell (mmitchell (at) usa.net) based on code found 8 1.1 mrg formerly in parse.y and pt.cc. 9 1.1 mrg 10 1.1 mrg This file is part of GCC. 11 1.1 mrg 12 1.1 mrg GCC is free software; you can redistribute it and/or modify it 13 1.1 mrg under the terms of the GNU General Public License as published by 14 1.1 mrg the Free Software Foundation; either version 3, or (at your option) 15 1.1 mrg any later version. 16 1.1 mrg 17 1.1 mrg GCC is distributed in the hope that it will be useful, but 18 1.1 mrg WITHOUT ANY WARRANTY; without even the implied warranty of 19 1.1 mrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 1.1 mrg General Public License for more details. 21 1.1 mrg 22 1.1 mrg You should have received a copy of the GNU General Public License 23 1.1 mrg along with GCC; see the file COPYING3. If not see 24 1.1 mrg <http://www.gnu.org/licenses/>. */ 25 1.1 mrg 26 1.1 mrg #include "config.h" 27 1.1 mrg #include "system.h" 28 1.1 mrg #include "coretypes.h" 29 1.1 mrg #include "target.h" 30 1.1 mrg #include "bitmap.h" 31 1.1 mrg #include "cp-tree.h" 32 1.1 mrg #include "stringpool.h" 33 1.1 mrg #include "cgraph.h" 34 1.1 mrg #include "stmt.h" 35 1.1 mrg #include "varasm.h" 36 1.1 mrg #include "stor-layout.h" 37 1.1 mrg #include "c-family/c-objc.h" 38 1.1 mrg #include "tree-inline.h" 39 1.1 mrg #include "intl.h" 40 1.1 mrg #include "tree-iterator.h" 41 1.1 mrg #include "omp-general.h" 42 1.1 mrg #include "convert.h" 43 1.1 mrg #include "stringpool.h" 44 1.1 mrg #include "attribs.h" 45 1.1 mrg #include "gomp-constants.h" 46 1.1 mrg #include "predict.h" 47 1.1 mrg #include "memmodel.h" 48 1.1 mrg 49 1.1 mrg /* There routines provide a modular interface to perform many parsing 50 1.1 mrg operations. They may therefore be used during actual parsing, or 51 1.1 mrg during template instantiation, which may be regarded as a 52 1.1 mrg degenerate form of parsing. */ 53 1.1 mrg 54 1.1 mrg static tree maybe_convert_cond (tree); 55 1.1 mrg static tree finalize_nrv_r (tree *, int *, void *); 56 1.1 mrg static tree capture_decltype (tree); 57 1.1 mrg 58 1.1 mrg /* Used for OpenMP non-static data member privatization. */ 59 1.1 mrg 60 1.1 mrg static hash_map<tree, tree> *omp_private_member_map; 61 1.1 mrg static vec<tree> omp_private_member_vec; 62 1.1 mrg static bool omp_private_member_ignore_next; 63 1.1 mrg 64 1.1 mrg 65 1.1 mrg /* Deferred Access Checking Overview 66 1.1 mrg --------------------------------- 67 1.1 mrg 68 1.1 mrg Most C++ expressions and declarations require access checking 69 1.1 mrg to be performed during parsing. However, in several cases, 70 1.1 mrg this has to be treated differently. 71 1.1 mrg 72 1.1 mrg For member declarations, access checking has to be deferred 73 1.1 mrg until more information about the declaration is known. For 74 1.1 mrg example: 75 1.1 mrg 76 1.1 mrg class A { 77 1.1 mrg typedef int X; 78 1.1 mrg public: 79 1.1 mrg X f(); 80 1.1 mrg }; 81 1.1 mrg 82 1.1 mrg A::X A::f(); 83 1.1 mrg A::X g(); 84 1.1 mrg 85 1.1 mrg When we are parsing the function return type `A::X', we don't 86 1.1 mrg really know if this is allowed until we parse the function name. 87 1.1 mrg 88 1.1 mrg Furthermore, some contexts require that access checking is 89 1.1 mrg never performed at all. These include class heads, and template 90 1.1 mrg instantiations. 91 1.1 mrg 92 1.1 mrg Typical use of access checking functions is described here: 93 1.1 mrg 94 1.1 mrg 1. When we enter a context that requires certain access checking 95 1.1 mrg mode, the function `push_deferring_access_checks' is called with 96 1.1 mrg DEFERRING argument specifying the desired mode. Access checking 97 1.1 mrg may be performed immediately (dk_no_deferred), deferred 98 1.1 mrg (dk_deferred), or not performed (dk_no_check). 99 1.1 mrg 100 1.1 mrg 2. When a declaration such as a type, or a variable, is encountered, 101 1.1 mrg the function `perform_or_defer_access_check' is called. It 102 1.1 mrg maintains a vector of all deferred checks. 103 1.1 mrg 104 1.1 mrg 3. The global `current_class_type' or `current_function_decl' is then 105 1.1 mrg setup by the parser. `enforce_access' relies on these information 106 1.1 mrg to check access. 107 1.1 mrg 108 1.1 mrg 4. Upon exiting the context mentioned in step 1, 109 1.1 mrg `perform_deferred_access_checks' is called to check all declaration 110 1.1 mrg stored in the vector. `pop_deferring_access_checks' is then 111 1.1 mrg called to restore the previous access checking mode. 112 1.1 mrg 113 1.1 mrg In case of parsing error, we simply call `pop_deferring_access_checks' 114 1.1 mrg without `perform_deferred_access_checks'. */ 115 1.1 mrg 116 1.1 mrg struct GTY(()) deferred_access { 117 1.1 mrg /* A vector representing name-lookups for which we have deferred 118 1.1 mrg checking access controls. We cannot check the accessibility of 119 1.1 mrg names used in a decl-specifier-seq until we know what is being 120 1.1 mrg declared because code like: 121 1.1 mrg 122 1.1 mrg class A { 123 1.1 mrg class B {}; 124 1.1 mrg B* f(); 125 1.1 mrg } 126 1.1 mrg 127 1.1 mrg A::B* A::f() { return 0; } 128 1.1 mrg 129 1.1 mrg is valid, even though `A::B' is not generally accessible. */ 130 1.1 mrg vec<deferred_access_check, va_gc> *deferred_access_checks; 131 1.1 mrg 132 1.1 mrg /* The current mode of access checks. */ 133 1.1 mrg enum deferring_kind deferring_access_checks_kind; 134 1.1 mrg }; 135 1.1 mrg 136 1.1 mrg /* Data for deferred access checking. */ 137 1.1 mrg static GTY(()) vec<deferred_access, va_gc> *deferred_access_stack; 138 1.1 mrg static GTY(()) unsigned deferred_access_no_check; 139 1.1 mrg 140 1.1 mrg /* Save the current deferred access states and start deferred 141 1.1 mrg access checking iff DEFER_P is true. */ 142 1.1 mrg 143 1.1 mrg void 144 1.1 mrg push_deferring_access_checks (deferring_kind deferring) 145 1.1 mrg { 146 1.1 mrg /* For context like template instantiation, access checking 147 1.1 mrg disabling applies to all nested context. */ 148 1.1 mrg if (deferred_access_no_check || deferring == dk_no_check) 149 1.1 mrg deferred_access_no_check++; 150 1.1 mrg else 151 1.1 mrg { 152 1.1 mrg deferred_access e = {NULL, deferring}; 153 1.1 mrg vec_safe_push (deferred_access_stack, e); 154 1.1 mrg } 155 1.1 mrg } 156 1.1 mrg 157 1.1 mrg /* Save the current deferred access states and start deferred access 158 1.1 mrg checking, continuing the set of deferred checks in CHECKS. */ 159 1.1 mrg 160 1.1 mrg void 161 1.1 mrg reopen_deferring_access_checks (vec<deferred_access_check, va_gc> * checks) 162 1.1 mrg { 163 1.1 mrg push_deferring_access_checks (dk_deferred); 164 1.1 mrg if (!deferred_access_no_check) 165 1.1 mrg deferred_access_stack->last().deferred_access_checks = checks; 166 1.1 mrg } 167 1.1 mrg 168 1.1 mrg /* Resume deferring access checks again after we stopped doing 169 1.1 mrg this previously. */ 170 1.1 mrg 171 1.1 mrg void 172 1.1 mrg resume_deferring_access_checks (void) 173 1.1 mrg { 174 1.1 mrg if (!deferred_access_no_check) 175 1.1 mrg deferred_access_stack->last().deferring_access_checks_kind = dk_deferred; 176 1.1 mrg } 177 1.1 mrg 178 1.1 mrg /* Stop deferring access checks. */ 179 1.1 mrg 180 1.1 mrg void 181 1.1 mrg stop_deferring_access_checks (void) 182 1.1 mrg { 183 1.1 mrg if (!deferred_access_no_check) 184 1.1 mrg deferred_access_stack->last().deferring_access_checks_kind = dk_no_deferred; 185 1.1 mrg } 186 1.1 mrg 187 1.1 mrg /* Discard the current deferred access checks and restore the 188 1.1 mrg previous states. */ 189 1.1 mrg 190 1.1 mrg void 191 1.1 mrg pop_deferring_access_checks (void) 192 1.1 mrg { 193 1.1 mrg if (deferred_access_no_check) 194 1.1 mrg deferred_access_no_check--; 195 1.1 mrg else 196 1.1 mrg deferred_access_stack->pop (); 197 1.1 mrg } 198 1.1 mrg 199 1.1 mrg /* Returns a TREE_LIST representing the deferred checks. 200 1.1 mrg The TREE_PURPOSE of each node is the type through which the 201 1.1 mrg access occurred; the TREE_VALUE is the declaration named. 202 1.1 mrg */ 203 1.1 mrg 204 1.1 mrg vec<deferred_access_check, va_gc> * 205 1.1 mrg get_deferred_access_checks (void) 206 1.1 mrg { 207 1.1 mrg if (deferred_access_no_check) 208 1.1 mrg return NULL; 209 1.1 mrg else 210 1.1 mrg return (deferred_access_stack->last().deferred_access_checks); 211 1.1 mrg } 212 1.1 mrg 213 1.1 mrg /* Take current deferred checks and combine with the 214 1.1 mrg previous states if we also defer checks previously. 215 1.1 mrg Otherwise perform checks now. */ 216 1.1 mrg 217 1.1 mrg void 218 1.1 mrg pop_to_parent_deferring_access_checks (void) 219 1.1 mrg { 220 1.1 mrg if (deferred_access_no_check) 221 1.1 mrg deferred_access_no_check--; 222 1.1 mrg else 223 1.1 mrg { 224 1.1 mrg vec<deferred_access_check, va_gc> *checks; 225 1.1 mrg deferred_access *ptr; 226 1.1 mrg 227 1.1 mrg checks = (deferred_access_stack->last ().deferred_access_checks); 228 1.1 mrg 229 1.1 mrg deferred_access_stack->pop (); 230 1.1 mrg ptr = &deferred_access_stack->last (); 231 1.1 mrg if (ptr->deferring_access_checks_kind == dk_no_deferred) 232 1.1 mrg { 233 1.1 mrg /* Check access. */ 234 1.1 mrg perform_access_checks (checks, tf_warning_or_error); 235 1.1 mrg } 236 1.1 mrg else 237 1.1 mrg { 238 1.1 mrg /* Merge with parent. */ 239 1.1 mrg int i, j; 240 1.1 mrg deferred_access_check *chk, *probe; 241 1.1 mrg 242 1.1 mrg FOR_EACH_VEC_SAFE_ELT (checks, i, chk) 243 1.1 mrg { 244 1.1 mrg FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, j, probe) 245 1.1 mrg { 246 1.1 mrg if (probe->binfo == chk->binfo && 247 1.1 mrg probe->decl == chk->decl && 248 1.1 mrg probe->diag_decl == chk->diag_decl) 249 1.1 mrg goto found; 250 1.1 mrg } 251 1.1 mrg /* Insert into parent's checks. */ 252 1.1 mrg vec_safe_push (ptr->deferred_access_checks, *chk); 253 1.1 mrg found:; 254 1.1 mrg } 255 1.1 mrg } 256 1.1 mrg } 257 1.1 mrg } 258 1.1 mrg 259 1.1 mrg /* Called from enforce_access. A class has attempted (but failed) to access 260 1.1 mrg DECL. It is already established that a baseclass of that class, 261 1.1 mrg PARENT_BINFO, has private access to DECL. Examine certain special cases 262 1.1 mrg to find a decl that accurately describes the source of the problem. If 263 1.1 mrg none of the special cases apply, simply return DECL as the source of the 264 1.1 mrg problem. */ 265 1.1 mrg 266 1.1 mrg static tree 267 1.1 mrg get_class_access_diagnostic_decl (tree parent_binfo, tree decl) 268 1.1 mrg { 269 1.1 mrg /* When a class is denied access to a decl in a baseclass, most of the 270 1.1 mrg time it is because the decl itself was declared as private at the point 271 1.1 mrg of declaration. 272 1.1 mrg 273 1.1 mrg However, in C++, there are (at least) two situations in which a decl 274 1.1 mrg can be private even though it was not originally defined as such. 275 1.1 mrg These two situations only apply if a baseclass had private access to 276 1.1 mrg DECL (this function is only called if that is the case). */ 277 1.1 mrg 278 1.1 mrg /* We should first check whether the reason the parent had private access 279 1.1 mrg to DECL was simply because DECL was created and declared as private in 280 1.1 mrg the parent. If it was, then DECL is definitively the source of the 281 1.1 mrg problem. */ 282 1.1 mrg if (SAME_BINFO_TYPE_P (context_for_name_lookup (decl), 283 1.1 mrg BINFO_TYPE (parent_binfo))) 284 1.1 mrg return decl; 285 1.1 mrg 286 1.1 mrg /* 1. If the "using" keyword is used to inherit DECL within the parent, 287 1.1 mrg this may cause DECL to be private, so we should return the using 288 1.1 mrg statement as the source of the problem. 289 1.1 mrg 290 1.1 mrg Scan the fields of PARENT_BINFO and see if there are any using decls. If 291 1.1 mrg there are, see if they inherit DECL. If they do, that's where DECL must 292 1.1 mrg have been declared private. */ 293 1.1 mrg 294 1.1 mrg for (tree parent_field = TYPE_FIELDS (BINFO_TYPE (parent_binfo)); 295 1.1 mrg parent_field; 296 1.1 mrg parent_field = DECL_CHAIN (parent_field)) 297 1.1 mrg /* Not necessary, but also check TREE_PRIVATE for the sake of 298 1.1 mrg eliminating obviously non-relevant using decls. */ 299 1.1 mrg if (TREE_CODE (parent_field) == USING_DECL 300 1.1 mrg && TREE_PRIVATE (parent_field)) 301 1.1 mrg { 302 1.1 mrg tree decl_stripped = strip_using_decl (parent_field); 303 1.1 mrg 304 1.1 mrg /* The using statement might be overloaded. If so, we need to 305 1.1 mrg check all of the overloads. */ 306 1.1 mrg for (ovl_iterator iter (decl_stripped); iter; ++iter) 307 1.1 mrg /* If equal, the using statement inherits DECL, and so is the 308 1.1 mrg source of the access failure, so return it. */ 309 1.1 mrg if (*iter == decl) 310 1.1 mrg return parent_field; 311 1.1 mrg } 312 1.1 mrg 313 1.1 mrg /* 2. If DECL was privately inherited by the parent class, then DECL will 314 1.1 mrg be inaccessible, even though it may originally have been accessible to 315 1.1 mrg deriving classes. In that case, the fault lies with the parent, since it 316 1.1 mrg used a private inheritance, so we return the parent as the source of the 317 1.1 mrg problem. 318 1.1 mrg 319 1.1 mrg Since this is the last check, we just assume it's true. At worst, it 320 1.1 mrg will simply point to the class that failed to give access, which is 321 1.1 mrg technically true. */ 322 1.1 mrg return TYPE_NAME (BINFO_TYPE (parent_binfo)); 323 1.1 mrg } 324 1.1 mrg 325 1.1 mrg /* If the current scope isn't allowed to access DECL along 326 1.1 mrg BASETYPE_PATH, give an error, or if we're parsing a function or class 327 1.1 mrg template, defer the access check to be performed at instantiation time. 328 1.1 mrg The most derived class in BASETYPE_PATH is the one used to qualify DECL. 329 1.1 mrg DIAG_DECL is the declaration to use in the error diagnostic. */ 330 1.1 mrg 331 1.1 mrg static bool 332 1.1 mrg enforce_access (tree basetype_path, tree decl, tree diag_decl, 333 1.1 mrg tsubst_flags_t complain, access_failure_info *afi = NULL) 334 1.1 mrg { 335 1.1 mrg gcc_assert (TREE_CODE (basetype_path) == TREE_BINFO); 336 1.1 mrg 337 1.1 mrg if (flag_new_inheriting_ctors 338 1.1 mrg && DECL_INHERITED_CTOR (decl)) 339 1.1 mrg { 340 1.1 mrg /* 7.3.3/18: The additional constructors are accessible if they would be 341 1.1 mrg accessible when used to construct an object of the corresponding base 342 1.1 mrg class. */ 343 1.1 mrg decl = strip_inheriting_ctors (decl); 344 1.1 mrg basetype_path = lookup_base (basetype_path, DECL_CONTEXT (decl), 345 1.1 mrg ba_any, NULL, complain); 346 1.1 mrg } 347 1.1 mrg 348 1.1 mrg tree cs = current_scope (); 349 1.1 mrg if (processing_template_decl 350 1.1 mrg && (CLASS_TYPE_P (cs) || TREE_CODE (cs) == FUNCTION_DECL)) 351 1.1 mrg if (tree template_info = get_template_info (cs)) 352 1.1 mrg { 353 1.1 mrg /* When parsing a function or class template, we in general need to 354 1.1 mrg defer access checks until template instantiation time, since a friend 355 1.1 mrg declaration may grant access only to a particular specialization of 356 1.1 mrg the template. */ 357 1.1 mrg 358 1.1 mrg if (accessible_p (basetype_path, decl, /*consider_local_p=*/true)) 359 1.1 mrg /* But if the member is deemed accessible at parse time, then we can 360 1.1 mrg assume it'll be accessible at instantiation time. */ 361 1.1 mrg return true; 362 1.1 mrg 363 1.1 mrg /* Access of a dependent decl should be rechecked after tsubst'ing 364 1.1 mrg into the user of the decl, rather than explicitly deferring the 365 1.1 mrg check here. */ 366 1.1 mrg gcc_assert (!uses_template_parms (decl)); 367 1.1 mrg if (TREE_CODE (decl) == FIELD_DECL) 368 1.1 mrg gcc_assert (!uses_template_parms (DECL_CONTEXT (decl))); 369 1.1 mrg 370 1.1 mrg /* Defer this access check until instantiation time. */ 371 1.1 mrg deferred_access_check access_check; 372 1.1 mrg access_check.binfo = basetype_path; 373 1.1 mrg access_check.decl = decl; 374 1.1 mrg access_check.diag_decl = diag_decl; 375 1.1 mrg access_check.loc = input_location; 376 1.1 mrg vec_safe_push (TI_DEFERRED_ACCESS_CHECKS (template_info), access_check); 377 1.1 mrg return true; 378 1.1 mrg } 379 1.1 mrg 380 1.1 mrg if (!accessible_p (basetype_path, decl, /*consider_local_p=*/true)) 381 1.1 mrg { 382 1.1 mrg if (flag_new_inheriting_ctors) 383 1.1 mrg diag_decl = strip_inheriting_ctors (diag_decl); 384 1.1 mrg if (complain & tf_error) 385 1.1 mrg { 386 1.1 mrg access_kind access_failure_reason = ak_none; 387 1.1 mrg 388 1.1 mrg /* By default, using the decl as the source of the problem will 389 1.1 mrg usually give correct results. */ 390 1.1 mrg tree diag_location = diag_decl; 391 1.1 mrg 392 1.1 mrg /* However, if a parent of BASETYPE_PATH had private access to decl, 393 1.1 mrg then it actually might be the case that the source of the problem 394 1.1 mrg is not DECL. */ 395 1.1 mrg tree parent_binfo = get_parent_with_private_access (decl, 396 1.1 mrg basetype_path); 397 1.1 mrg 398 1.1 mrg /* So if a parent did have private access, then we need to do 399 1.1 mrg special checks to obtain the best diagnostic location decl. */ 400 1.1 mrg if (parent_binfo != NULL_TREE) 401 1.1 mrg { 402 1.1 mrg diag_location = get_class_access_diagnostic_decl (parent_binfo, 403 1.1 mrg diag_decl); 404 1.1 mrg 405 1.1 mrg /* We also at this point know that the reason access failed was 406 1.1 mrg because decl was private. */ 407 1.1 mrg access_failure_reason = ak_private; 408 1.1 mrg } 409 1.1 mrg 410 1.1 mrg /* Finally, generate an error message. */ 411 1.1 mrg complain_about_access (decl, diag_decl, diag_location, true, 412 1.1 mrg access_failure_reason); 413 1.1 mrg } 414 1.1 mrg if (afi) 415 1.1 mrg afi->record_access_failure (basetype_path, decl, diag_decl); 416 1.1 mrg return false; 417 1.1 mrg } 418 1.1 mrg 419 1.1 mrg return true; 420 1.1 mrg } 421 1.1 mrg 422 1.1 mrg /* Perform the access checks in CHECKS. The TREE_PURPOSE of each node 423 1.1 mrg is the BINFO indicating the qualifying scope used to access the 424 1.1 mrg DECL node stored in the TREE_VALUE of the node. If CHECKS is empty 425 1.1 mrg or we aren't in SFINAE context or all the checks succeed return TRUE, 426 1.1 mrg otherwise FALSE. */ 427 1.1 mrg 428 1.1 mrg bool 429 1.1 mrg perform_access_checks (vec<deferred_access_check, va_gc> *checks, 430 1.1 mrg tsubst_flags_t complain) 431 1.1 mrg { 432 1.1 mrg int i; 433 1.1 mrg deferred_access_check *chk; 434 1.1 mrg location_t loc = input_location; 435 1.1 mrg bool ok = true; 436 1.1 mrg 437 1.1 mrg if (!checks) 438 1.1 mrg return true; 439 1.1 mrg 440 1.1 mrg FOR_EACH_VEC_SAFE_ELT (checks, i, chk) 441 1.1 mrg { 442 1.1 mrg input_location = chk->loc; 443 1.1 mrg ok &= enforce_access (chk->binfo, chk->decl, chk->diag_decl, complain); 444 1.1 mrg } 445 1.1 mrg 446 1.1 mrg input_location = loc; 447 1.1 mrg return (complain & tf_error) ? true : ok; 448 1.1 mrg } 449 1.1 mrg 450 1.1 mrg /* Perform the deferred access checks. 451 1.1 mrg 452 1.1 mrg After performing the checks, we still have to keep the list 453 1.1 mrg `deferred_access_stack->deferred_access_checks' since we may want 454 1.1 mrg to check access for them again later in a different context. 455 1.1 mrg For example: 456 1.1 mrg 457 1.1 mrg class A { 458 1.1 mrg typedef int X; 459 1.1 mrg static X a; 460 1.1 mrg }; 461 1.1 mrg A::X A::a, x; // No error for `A::a', error for `x' 462 1.1 mrg 463 1.1 mrg We have to perform deferred access of `A::X', first with `A::a', 464 1.1 mrg next with `x'. Return value like perform_access_checks above. */ 465 1.1 mrg 466 1.1 mrg bool 467 1.1 mrg perform_deferred_access_checks (tsubst_flags_t complain) 468 1.1 mrg { 469 1.1 mrg return perform_access_checks (get_deferred_access_checks (), complain); 470 1.1 mrg } 471 1.1 mrg 472 1.1 mrg /* Defer checking the accessibility of DECL, when looked up in 473 1.1 mrg BINFO. DIAG_DECL is the declaration to use to print diagnostics. 474 1.1 mrg Return value like perform_access_checks above. 475 1.1 mrg If non-NULL, report failures to AFI. */ 476 1.1 mrg 477 1.1 mrg bool 478 1.1 mrg perform_or_defer_access_check (tree binfo, tree decl, tree diag_decl, 479 1.1 mrg tsubst_flags_t complain, 480 1.1 mrg access_failure_info *afi) 481 1.1 mrg { 482 1.1 mrg int i; 483 1.1 mrg deferred_access *ptr; 484 1.1 mrg deferred_access_check *chk; 485 1.1 mrg 486 1.1 mrg /* Exit if we are in a context that no access checking is performed. */ 487 1.1 mrg if (deferred_access_no_check) 488 1.1 mrg return true; 489 1.1 mrg 490 1.1 mrg gcc_assert (TREE_CODE (binfo) == TREE_BINFO); 491 1.1 mrg 492 1.1 mrg ptr = &deferred_access_stack->last (); 493 1.1 mrg 494 1.1 mrg /* If we are not supposed to defer access checks, just check now. */ 495 1.1 mrg if (ptr->deferring_access_checks_kind == dk_no_deferred) 496 1.1 mrg { 497 1.1 mrg bool ok = enforce_access (binfo, decl, diag_decl, complain, afi); 498 1.1 mrg return (complain & tf_error) ? true : ok; 499 1.1 mrg } 500 1.1 mrg 501 1.1 mrg /* See if we are already going to perform this check. */ 502 1.1 mrg FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, i, chk) 503 1.1 mrg { 504 1.1 mrg if (chk->decl == decl && chk->binfo == binfo && 505 1.1 mrg chk->diag_decl == diag_decl) 506 1.1 mrg { 507 1.1 mrg return true; 508 1.1 mrg } 509 1.1 mrg } 510 1.1 mrg /* If not, record the check. */ 511 1.1 mrg deferred_access_check new_access = {binfo, decl, diag_decl, input_location}; 512 1.1 mrg vec_safe_push (ptr->deferred_access_checks, new_access); 513 1.1 mrg 514 1.1 mrg return true; 515 1.1 mrg } 516 1.1 mrg 517 1.1 mrg /* Returns nonzero if the current statement is a full expression, 518 1.1 mrg i.e. temporaries created during that statement should be destroyed 519 1.1 mrg at the end of the statement. */ 520 1.1 mrg 521 1.1 mrg int 522 1.1 mrg stmts_are_full_exprs_p (void) 523 1.1 mrg { 524 1.1 mrg return current_stmt_tree ()->stmts_are_full_exprs_p; 525 1.1 mrg } 526 1.1 mrg 527 1.1 mrg /* T is a statement. Add it to the statement-tree. This is the C++ 528 1.1 mrg version. The C/ObjC frontends have a slightly different version of 529 1.1 mrg this function. */ 530 1.1 mrg 531 1.1 mrg tree 532 1.1 mrg add_stmt (tree t) 533 1.1 mrg { 534 1.1 mrg enum tree_code code = TREE_CODE (t); 535 1.1 mrg 536 1.1 mrg if (EXPR_P (t) && code != LABEL_EXPR) 537 1.1 mrg { 538 1.1 mrg if (!EXPR_HAS_LOCATION (t)) 539 1.1 mrg SET_EXPR_LOCATION (t, input_location); 540 1.1 mrg 541 1.1 mrg /* When we expand a statement-tree, we must know whether or not the 542 1.1 mrg statements are full-expressions. We record that fact here. */ 543 1.1 mrg if (STATEMENT_CODE_P (TREE_CODE (t))) 544 1.1 mrg STMT_IS_FULL_EXPR_P (t) = stmts_are_full_exprs_p (); 545 1.1 mrg } 546 1.1 mrg 547 1.1 mrg if (code == LABEL_EXPR || code == CASE_LABEL_EXPR) 548 1.1 mrg STATEMENT_LIST_HAS_LABEL (cur_stmt_list) = 1; 549 1.1 mrg 550 1.1 mrg /* Add T to the statement-tree. Non-side-effect statements need to be 551 1.1 mrg recorded during statement expressions. */ 552 1.1 mrg gcc_checking_assert (!stmt_list_stack->is_empty ()); 553 1.1 mrg append_to_statement_list_force (t, &cur_stmt_list); 554 1.1 mrg 555 1.1 mrg return t; 556 1.1 mrg } 557 1.1 mrg 558 1.1 mrg /* Returns the stmt_tree to which statements are currently being added. */ 559 1.1 mrg 560 1.1 mrg stmt_tree 561 1.1 mrg current_stmt_tree (void) 562 1.1 mrg { 563 1.1 mrg return (cfun 564 1.1 mrg ? &cfun->language->base.x_stmt_tree 565 1.1 mrg : &scope_chain->x_stmt_tree); 566 1.1 mrg } 567 1.1 mrg 568 1.1 mrg /* If statements are full expressions, wrap STMT in a CLEANUP_POINT_EXPR. */ 569 1.1 mrg 570 1.1 mrg static tree 571 1.1 mrg maybe_cleanup_point_expr (tree expr) 572 1.1 mrg { 573 1.1 mrg if (!processing_template_decl && stmts_are_full_exprs_p ()) 574 1.1 mrg expr = fold_build_cleanup_point_expr (TREE_TYPE (expr), expr); 575 1.1 mrg return expr; 576 1.1 mrg } 577 1.1 mrg 578 1.1 mrg /* Like maybe_cleanup_point_expr except have the type of the new expression be 579 1.1 mrg void so we don't need to create a temporary variable to hold the inner 580 1.1 mrg expression. The reason why we do this is because the original type might be 581 1.1 mrg an aggregate and we cannot create a temporary variable for that type. */ 582 1.1 mrg 583 1.1 mrg tree 584 1.1 mrg maybe_cleanup_point_expr_void (tree expr) 585 1.1 mrg { 586 1.1 mrg if (!processing_template_decl && stmts_are_full_exprs_p ()) 587 1.1 mrg expr = fold_build_cleanup_point_expr (void_type_node, expr); 588 1.1 mrg return expr; 589 1.1 mrg } 590 1.1 mrg 591 1.1 mrg 592 1.1 mrg 593 1.1 mrg /* Create a declaration statement for the declaration given by the DECL. */ 594 1.1 mrg 595 1.1 mrg void 596 1.1 mrg add_decl_expr (tree decl) 597 1.1 mrg { 598 1.1 mrg tree r = build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl); 599 1.1 mrg if (DECL_INITIAL (decl) 600 1.1 mrg || (DECL_SIZE (decl) && TREE_SIDE_EFFECTS (DECL_SIZE (decl)))) 601 1.1 mrg r = maybe_cleanup_point_expr_void (r); 602 1.1 mrg add_stmt (r); 603 1.1 mrg } 604 1.1 mrg 605 1.1 mrg /* Set EXPR_LOCATION of the cleanups of any CLEANUP_STMT in STMTS to LOC. */ 606 1.1 mrg 607 1.1 mrg static void 608 1.1 mrg set_cleanup_locs (tree stmts, location_t loc) 609 1.1 mrg { 610 1.1 mrg if (TREE_CODE (stmts) == CLEANUP_STMT) 611 1.1 mrg { 612 1.1 mrg tree t = CLEANUP_EXPR (stmts); 613 1.1 mrg protected_set_expr_location (t, loc); 614 1.1 mrg /* Avoid locus differences for C++ cdtor calls depending on whether 615 1.1 mrg cdtor_returns_this: a conversion to void is added to discard the return 616 1.1 mrg value, and this conversion ends up carrying the location, and when it 617 1.1 mrg gets discarded, the location is lost. So hold it in the call as 618 1.1 mrg well. */ 619 1.1 mrg if (TREE_CODE (t) == NOP_EXPR 620 1.1 mrg && TREE_TYPE (t) == void_type_node 621 1.1 mrg && TREE_CODE (TREE_OPERAND (t, 0)) == CALL_EXPR) 622 1.1 mrg protected_set_expr_location (TREE_OPERAND (t, 0), loc); 623 1.1 mrg set_cleanup_locs (CLEANUP_BODY (stmts), loc); 624 1.1 mrg } 625 1.1 mrg else if (TREE_CODE (stmts) == STATEMENT_LIST) 626 1.1 mrg for (tree stmt : tsi_range (stmts)) 627 1.1 mrg set_cleanup_locs (stmt, loc); 628 1.1 mrg } 629 1.1 mrg 630 1.1 mrg /* True iff the innermost block scope is a try block. */ 631 1.1 mrg 632 1.1 mrg static bool 633 1.1 mrg at_try_scope () 634 1.1 mrg { 635 1.1 mrg cp_binding_level *b = current_binding_level; 636 1.1 mrg while (b && b->kind == sk_cleanup) 637 1.1 mrg b = b->level_chain; 638 1.1 mrg return b && b->kind == sk_try; 639 1.1 mrg } 640 1.1 mrg 641 1.1 mrg /* Finish a scope. */ 642 1.1 mrg 643 1.1 mrg tree 644 1.1 mrg do_poplevel (tree stmt_list) 645 1.1 mrg { 646 1.1 mrg tree block = NULL; 647 1.1 mrg 648 1.1 mrg bool was_try = at_try_scope (); 649 1.1 mrg 650 1.1 mrg if (stmts_are_full_exprs_p ()) 651 1.1 mrg block = poplevel (kept_level_p (), 1, 0); 652 1.1 mrg 653 1.1 mrg /* This needs to come after poplevel merges sk_cleanup statement_lists. */ 654 1.1 mrg maybe_splice_retval_cleanup (stmt_list, was_try); 655 1.1 mrg 656 1.1 mrg stmt_list = pop_stmt_list (stmt_list); 657 1.1 mrg 658 1.1 mrg /* input_location is the last token of the scope, usually a }. */ 659 1.1 mrg set_cleanup_locs (stmt_list, input_location); 660 1.1 mrg 661 1.1 mrg if (!processing_template_decl) 662 1.1 mrg { 663 1.1 mrg stmt_list = c_build_bind_expr (input_location, block, stmt_list); 664 1.1 mrg /* ??? See c_end_compound_stmt re statement expressions. */ 665 1.1 mrg } 666 1.1 mrg 667 1.1 mrg return stmt_list; 668 1.1 mrg } 669 1.1 mrg 670 1.1 mrg /* Begin a new scope. */ 671 1.1 mrg 672 1.1 mrg static tree 673 1.1 mrg do_pushlevel (scope_kind sk) 674 1.1 mrg { 675 1.1 mrg tree ret = push_stmt_list (); 676 1.1 mrg if (stmts_are_full_exprs_p ()) 677 1.1 mrg begin_scope (sk, NULL); 678 1.1 mrg return ret; 679 1.1 mrg } 680 1.1 mrg 681 1.1 mrg /* Queue a cleanup. CLEANUP is an expression/statement to be executed 682 1.1 mrg when the current scope is exited. EH_ONLY is true when this is not 683 1.1 mrg meant to apply to normal control flow transfer. DECL is the VAR_DECL 684 1.1 mrg being cleaned up, if any, or null for temporaries or subobjects. */ 685 1.1 mrg 686 1.1 mrg void 687 1.1 mrg push_cleanup (tree decl, tree cleanup, bool eh_only) 688 1.1 mrg { 689 1.1 mrg tree stmt = build_stmt (input_location, CLEANUP_STMT, NULL, cleanup, decl); 690 1.1 mrg CLEANUP_EH_ONLY (stmt) = eh_only; 691 1.1 mrg add_stmt (stmt); 692 1.1 mrg CLEANUP_BODY (stmt) = push_stmt_list (); 693 1.1 mrg } 694 1.1 mrg 695 1.1 mrg /* Simple infinite loop tracking for -Wreturn-type. We keep a stack of all 696 1.1 mrg the current loops, represented by 'NULL_TREE' if we've seen a possible 697 1.1 mrg exit, and 'error_mark_node' if not. This is currently used only to 698 1.1 mrg suppress the warning about a function with no return statements, and 699 1.1 mrg therefore we don't bother noting returns as possible exits. We also 700 1.1 mrg don't bother with gotos. */ 701 1.1 mrg 702 1.1 mrg static void 703 1.1 mrg begin_maybe_infinite_loop (tree cond) 704 1.1 mrg { 705 1.1 mrg /* Only track this while parsing a function, not during instantiation. */ 706 1.1 mrg if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl) 707 1.1 mrg && !processing_template_decl)) 708 1.1 mrg return; 709 1.1 mrg bool maybe_infinite = true; 710 1.1 mrg if (cond) 711 1.1 mrg { 712 1.1 mrg cond = fold_non_dependent_expr (cond); 713 1.1 mrg maybe_infinite = integer_nonzerop (cond); 714 1.1 mrg } 715 1.1 mrg vec_safe_push (cp_function_chain->infinite_loops, 716 1.1 mrg maybe_infinite ? error_mark_node : NULL_TREE); 717 1.1 mrg 718 1.1 mrg } 719 1.1 mrg 720 1.1 mrg /* A break is a possible exit for the current loop. */ 721 1.1 mrg 722 1.1 mrg void 723 1.1 mrg break_maybe_infinite_loop (void) 724 1.1 mrg { 725 1.1 mrg if (!cfun) 726 1.1 mrg return; 727 1.1 mrg cp_function_chain->infinite_loops->last() = NULL_TREE; 728 1.1 mrg } 729 1.1 mrg 730 1.1 mrg /* If we reach the end of the loop without seeing a possible exit, we have 731 1.1 mrg an infinite loop. */ 732 1.1 mrg 733 1.1 mrg static void 734 1.1 mrg end_maybe_infinite_loop (tree cond) 735 1.1 mrg { 736 1.1 mrg if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl) 737 1.1 mrg && !processing_template_decl)) 738 1.1 mrg return; 739 1.1 mrg tree current = cp_function_chain->infinite_loops->pop(); 740 1.1 mrg if (current != NULL_TREE) 741 1.1 mrg { 742 1.1 mrg cond = fold_non_dependent_expr (cond); 743 1.1 mrg if (integer_nonzerop (cond)) 744 1.1 mrg current_function_infinite_loop = 1; 745 1.1 mrg } 746 1.1 mrg } 747 1.1 mrg 748 1.1 mrg 749 1.1 mrg /* Begin a conditional that might contain a declaration. When generating 750 1.1 mrg normal code, we want the declaration to appear before the statement 751 1.1 mrg containing the conditional. When generating template code, we want the 752 1.1 mrg conditional to be rendered as the raw DECL_EXPR. */ 753 1.1 mrg 754 1.1 mrg static void 755 1.1 mrg begin_cond (tree *cond_p) 756 1.1 mrg { 757 1.1 mrg if (processing_template_decl) 758 1.1 mrg *cond_p = push_stmt_list (); 759 1.1 mrg } 760 1.1 mrg 761 1.1 mrg /* Finish such a conditional. */ 762 1.1 mrg 763 1.1 mrg static void 764 1.1 mrg finish_cond (tree *cond_p, tree expr) 765 1.1 mrg { 766 1.1 mrg if (processing_template_decl) 767 1.1 mrg { 768 1.1 mrg tree cond = pop_stmt_list (*cond_p); 769 1.1 mrg 770 1.1 mrg if (expr == NULL_TREE) 771 1.1 mrg /* Empty condition in 'for'. */ 772 1.1 mrg gcc_assert (empty_expr_stmt_p (cond)); 773 1.1 mrg else if (check_for_bare_parameter_packs (expr)) 774 1.1 mrg expr = error_mark_node; 775 1.1 mrg else if (!empty_expr_stmt_p (cond)) 776 1.1 mrg expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), cond, expr); 777 1.1 mrg } 778 1.1 mrg *cond_p = expr; 779 1.1 mrg } 780 1.1 mrg 781 1.1 mrg /* If *COND_P specifies a conditional with a declaration, transform the 782 1.1 mrg loop such that 783 1.1 mrg while (A x = 42) { } 784 1.1 mrg for (; A x = 42;) { } 785 1.1 mrg becomes 786 1.1 mrg while (true) { A x = 42; if (!x) break; } 787 1.1 mrg for (;;) { A x = 42; if (!x) break; } 788 1.1 mrg The statement list for BODY will be empty if the conditional did 789 1.1 mrg not declare anything. */ 790 1.1 mrg 791 1.1 mrg static void 792 1.1 mrg simplify_loop_decl_cond (tree *cond_p, tree body) 793 1.1 mrg { 794 1.1 mrg tree cond, if_stmt; 795 1.1 mrg 796 1.1 mrg if (!TREE_SIDE_EFFECTS (body)) 797 1.1 mrg return; 798 1.1 mrg 799 1.1 mrg cond = *cond_p; 800 1.1 mrg *cond_p = boolean_true_node; 801 1.1 mrg 802 1.1 mrg if_stmt = begin_if_stmt (); 803 1.1 mrg cond_p = &cond; 804 1.1 mrg while (TREE_CODE (*cond_p) == ANNOTATE_EXPR) 805 1.1 mrg cond_p = &TREE_OPERAND (*cond_p, 0); 806 1.1 mrg *cond_p = cp_build_unary_op (TRUTH_NOT_EXPR, *cond_p, false, 807 1.1 mrg tf_warning_or_error); 808 1.1 mrg finish_if_stmt_cond (cond, if_stmt); 809 1.1 mrg finish_break_stmt (); 810 1.1 mrg finish_then_clause (if_stmt); 811 1.1 mrg finish_if_stmt (if_stmt); 812 1.1 mrg } 813 1.1 mrg 814 1.1 mrg /* Finish a goto-statement. */ 815 1.1 mrg 816 1.1 mrg tree 817 1.1 mrg finish_goto_stmt (tree destination) 818 1.1 mrg { 819 1.1 mrg if (identifier_p (destination)) 820 1.1 mrg destination = lookup_label (destination); 821 1.1 mrg 822 1.1 mrg /* We warn about unused labels with -Wunused. That means we have to 823 1.1 mrg mark the used labels as used. */ 824 1.1 mrg if (TREE_CODE (destination) == LABEL_DECL) 825 1.1 mrg TREE_USED (destination) = 1; 826 1.1 mrg else 827 1.1 mrg { 828 1.1 mrg destination = mark_rvalue_use (destination); 829 1.1 mrg if (!processing_template_decl) 830 1.1 mrg { 831 1.1 mrg destination = cp_convert (ptr_type_node, destination, 832 1.1 mrg tf_warning_or_error); 833 1.1 mrg if (error_operand_p (destination)) 834 1.1 mrg return NULL_TREE; 835 1.1 mrg destination 836 1.1 mrg = fold_build_cleanup_point_expr (TREE_TYPE (destination), 837 1.1 mrg destination); 838 1.1 mrg } 839 1.1 mrg } 840 1.1 mrg 841 1.1 mrg check_goto (destination); 842 1.1 mrg 843 1.1 mrg add_stmt (build_predict_expr (PRED_GOTO, NOT_TAKEN)); 844 1.1 mrg return add_stmt (build_stmt (input_location, GOTO_EXPR, destination)); 845 1.1 mrg } 846 1.1 mrg 847 1.1 mrg /* COND is the condition-expression for an if, while, etc., 848 1.1 mrg statement. Convert it to a boolean value, if appropriate. 849 1.1 mrg In addition, verify sequence points if -Wsequence-point is enabled. */ 850 1.1 mrg 851 1.1 mrg static tree 852 1.1 mrg maybe_convert_cond (tree cond) 853 1.1 mrg { 854 1.1 mrg /* Empty conditions remain empty. */ 855 1.1 mrg if (!cond) 856 1.1 mrg return NULL_TREE; 857 1.1 mrg 858 1.1 mrg /* Wait until we instantiate templates before doing conversion. */ 859 1.1 mrg if (type_dependent_expression_p (cond)) 860 1.1 mrg return cond; 861 1.1 mrg 862 1.1 mrg if (warn_sequence_point && !processing_template_decl) 863 1.1 mrg verify_sequence_points (cond); 864 1.1 mrg 865 1.1 mrg /* Do the conversion. */ 866 1.1 mrg cond = convert_from_reference (cond); 867 1.1 mrg 868 1.1 mrg if (TREE_CODE (cond) == MODIFY_EXPR 869 1.1 mrg && warn_parentheses 870 1.1 mrg && !warning_suppressed_p (cond, OPT_Wparentheses) 871 1.1 mrg && warning_at (cp_expr_loc_or_input_loc (cond), 872 1.1 mrg OPT_Wparentheses, "suggest parentheses around " 873 1.1 mrg "assignment used as truth value")) 874 1.1 mrg suppress_warning (cond, OPT_Wparentheses); 875 1.1 mrg 876 1.1 mrg return condition_conversion (cond); 877 1.1 mrg } 878 1.1 mrg 879 1.1 mrg /* Finish an expression-statement, whose EXPRESSION is as indicated. */ 880 1.1 mrg 881 1.1 mrg tree 882 1.1 mrg finish_expr_stmt (tree expr) 883 1.1 mrg { 884 1.1 mrg tree r = NULL_TREE; 885 1.1 mrg location_t loc = EXPR_LOCATION (expr); 886 1.1 mrg 887 1.1 mrg if (expr != NULL_TREE) 888 1.1 mrg { 889 1.1 mrg /* If we ran into a problem, make sure we complained. */ 890 1.1 mrg gcc_assert (expr != error_mark_node || seen_error ()); 891 1.1 mrg 892 1.1 mrg if (!processing_template_decl) 893 1.1 mrg { 894 1.1 mrg if (warn_sequence_point) 895 1.1 mrg verify_sequence_points (expr); 896 1.1 mrg expr = convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error); 897 1.1 mrg } 898 1.1 mrg else if (!type_dependent_expression_p (expr)) 899 1.1 mrg convert_to_void (build_non_dependent_expr (expr), ICV_STATEMENT, 900 1.1 mrg tf_warning_or_error); 901 1.1 mrg 902 1.1 mrg if (check_for_bare_parameter_packs (expr)) 903 1.1 mrg expr = error_mark_node; 904 1.1 mrg 905 1.1 mrg /* Simplification of inner statement expressions, compound exprs, 906 1.1 mrg etc can result in us already having an EXPR_STMT. */ 907 1.1 mrg if (TREE_CODE (expr) != CLEANUP_POINT_EXPR) 908 1.1 mrg { 909 1.1 mrg if (TREE_CODE (expr) != EXPR_STMT) 910 1.1 mrg expr = build_stmt (loc, EXPR_STMT, expr); 911 1.1 mrg expr = maybe_cleanup_point_expr_void (expr); 912 1.1 mrg } 913 1.1 mrg 914 1.1 mrg r = add_stmt (expr); 915 1.1 mrg } 916 1.1 mrg 917 1.1 mrg return r; 918 1.1 mrg } 919 1.1 mrg 920 1.1 mrg 921 1.1 mrg /* Begin an if-statement. Returns a newly created IF_STMT if 922 1.1 mrg appropriate. */ 923 1.1 mrg 924 1.1 mrg tree 925 1.1 mrg begin_if_stmt (void) 926 1.1 mrg { 927 1.1 mrg tree r, scope; 928 1.1 mrg scope = do_pushlevel (sk_cond); 929 1.1 mrg r = build_stmt (input_location, IF_STMT, NULL_TREE, 930 1.1 mrg NULL_TREE, NULL_TREE, scope); 931 1.1 mrg current_binding_level->this_entity = r; 932 1.1 mrg begin_cond (&IF_COND (r)); 933 1.1 mrg return r; 934 1.1 mrg } 935 1.1 mrg 936 1.1 mrg /* Returns true if FN, a CALL_EXPR, is a call to 937 1.1 mrg std::is_constant_evaluated or __builtin_is_constant_evaluated. */ 938 1.1 mrg 939 1.1 mrg static bool 940 1.1 mrg is_std_constant_evaluated_p (tree fn) 941 1.1 mrg { 942 1.1 mrg /* std::is_constant_evaluated takes no arguments. */ 943 1.1 mrg if (call_expr_nargs (fn) != 0) 944 1.1 mrg return false; 945 1.1 mrg 946 1.1 mrg tree fndecl = cp_get_callee_fndecl_nofold (fn); 947 1.1 mrg if (fndecl == NULL_TREE) 948 1.1 mrg return false; 949 1.1 mrg 950 1.1 mrg if (fndecl_built_in_p (fndecl, CP_BUILT_IN_IS_CONSTANT_EVALUATED, 951 1.1 mrg BUILT_IN_FRONTEND)) 952 1.1 mrg return true; 953 1.1 mrg 954 1.1 mrg if (!decl_in_std_namespace_p (fndecl)) 955 1.1 mrg return false; 956 1.1 mrg 957 1.1 mrg tree name = DECL_NAME (fndecl); 958 1.1 mrg return name && id_equal (name, "is_constant_evaluated"); 959 1.1 mrg } 960 1.1 mrg 961 1.1 mrg /* Callback function for maybe_warn_for_constant_evaluated that looks 962 1.1 mrg for calls to std::is_constant_evaluated in TP. */ 963 1.1 mrg 964 1.1 mrg static tree 965 1.1 mrg find_std_constant_evaluated_r (tree *tp, int *walk_subtrees, void *) 966 1.1 mrg { 967 1.1 mrg tree t = *tp; 968 1.1 mrg 969 1.1 mrg if (TYPE_P (t) || TREE_CONSTANT (t)) 970 1.1 mrg { 971 1.1 mrg *walk_subtrees = false; 972 1.1 mrg return NULL_TREE; 973 1.1 mrg } 974 1.1 mrg 975 1.1 mrg switch (TREE_CODE (t)) 976 1.1 mrg { 977 1.1 mrg case CALL_EXPR: 978 1.1 mrg if (is_std_constant_evaluated_p (t)) 979 1.1 mrg return t; 980 1.1 mrg break; 981 1.1 mrg case EXPR_STMT: 982 1.1 mrg /* Don't warn in statement expressions. */ 983 1.1 mrg *walk_subtrees = false; 984 1.1 mrg return NULL_TREE; 985 1.1 mrg default: 986 1.1 mrg break; 987 1.1 mrg } 988 1.1 mrg 989 1.1 mrg return NULL_TREE; 990 1.1 mrg } 991 1.1 mrg 992 1.1 mrg /* In certain contexts, std::is_constant_evaluated() is always true (for 993 1.1 mrg instance, in a consteval function or in a constexpr if), or always false 994 1.1 mrg (e.g., in a non-constexpr non-consteval function) so give the user a clue. */ 995 1.1 mrg 996 1.1 mrg static void 997 1.1 mrg maybe_warn_for_constant_evaluated (tree cond, bool constexpr_if) 998 1.1 mrg { 999 1.1 mrg if (!warn_tautological_compare) 1000 1.1 mrg return; 1001 1.1 mrg 1002 1.1 mrg /* Suppress warning for std::is_constant_evaluated if the conditional 1003 1.1 mrg comes from a macro. */ 1004 1.1 mrg if (from_macro_expansion_at (EXPR_LOCATION (cond))) 1005 1.1 mrg return; 1006 1.1 mrg 1007 1.1 mrg cond = cp_walk_tree_without_duplicates (&cond, find_std_constant_evaluated_r, 1008 1.1 mrg NULL); 1009 1.1 mrg if (cond) 1010 1.1 mrg { 1011 1.1 mrg if (constexpr_if) 1012 1.1 mrg warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare, 1013 1.1 mrg "%<std::is_constant_evaluated%> always evaluates to " 1014 1.1 mrg "true in %<if constexpr%>"); 1015 1.1 mrg else if (!maybe_constexpr_fn (current_function_decl)) 1016 1.1 mrg warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare, 1017 1.1 mrg "%<std::is_constant_evaluated%> always evaluates to " 1018 1.1 mrg "false in a non-%<constexpr%> function"); 1019 1.1 mrg else if (DECL_IMMEDIATE_FUNCTION_P (current_function_decl)) 1020 1.1 mrg warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare, 1021 1.1 mrg "%<std::is_constant_evaluated%> always evaluates to " 1022 1.1 mrg "true in a %<consteval%> function"); 1023 1.1 mrg } 1024 1.1 mrg } 1025 1.1 mrg 1026 1.1 mrg /* Process the COND of an if-statement, which may be given by 1027 1.1 mrg IF_STMT. */ 1028 1.1 mrg 1029 1.1 mrg tree 1030 1.1 mrg finish_if_stmt_cond (tree cond, tree if_stmt) 1031 1.1 mrg { 1032 1.1 mrg cond = maybe_convert_cond (cond); 1033 1.1 mrg maybe_warn_for_constant_evaluated (cond, IF_STMT_CONSTEXPR_P (if_stmt)); 1034 1.1 mrg if (IF_STMT_CONSTEXPR_P (if_stmt) 1035 1.1 mrg && !type_dependent_expression_p (cond) 1036 1.1 mrg && require_constant_expression (cond) 1037 1.1 mrg && !instantiation_dependent_expression_p (cond) 1038 1.1 mrg /* Wait until instantiation time, since only then COND has been 1039 1.1 mrg converted to bool. */ 1040 1.1 mrg && TYPE_MAIN_VARIANT (TREE_TYPE (cond)) == boolean_type_node) 1041 1.1 mrg { 1042 1.1 mrg cond = instantiate_non_dependent_expr (cond); 1043 1.1 mrg cond = cxx_constant_value (cond, NULL_TREE); 1044 1.1 mrg } 1045 1.1 mrg finish_cond (&IF_COND (if_stmt), cond); 1046 1.1 mrg add_stmt (if_stmt); 1047 1.1 mrg THEN_CLAUSE (if_stmt) = push_stmt_list (); 1048 1.1 mrg return cond; 1049 1.1 mrg } 1050 1.1 mrg 1051 1.1 mrg /* Finish the then-clause of an if-statement, which may be given by 1052 1.1 mrg IF_STMT. */ 1053 1.1 mrg 1054 1.1 mrg tree 1055 1.1 mrg finish_then_clause (tree if_stmt) 1056 1.1 mrg { 1057 1.1 mrg THEN_CLAUSE (if_stmt) = pop_stmt_list (THEN_CLAUSE (if_stmt)); 1058 1.1 mrg return if_stmt; 1059 1.1 mrg } 1060 1.1 mrg 1061 1.1 mrg /* Begin the else-clause of an if-statement. */ 1062 1.1 mrg 1063 1.1 mrg void 1064 1.1 mrg begin_else_clause (tree if_stmt) 1065 1.1 mrg { 1066 1.1 mrg ELSE_CLAUSE (if_stmt) = push_stmt_list (); 1067 1.1 mrg } 1068 1.1 mrg 1069 1.1 mrg /* Finish the else-clause of an if-statement, which may be given by 1070 1.1 mrg IF_STMT. */ 1071 1.1 mrg 1072 1.1 mrg void 1073 1.1 mrg finish_else_clause (tree if_stmt) 1074 1.1 mrg { 1075 1.1 mrg ELSE_CLAUSE (if_stmt) = pop_stmt_list (ELSE_CLAUSE (if_stmt)); 1076 1.1 mrg } 1077 1.1 mrg 1078 1.1 mrg /* Callback for cp_walk_tree to mark all {VAR,PARM}_DECLs in a tree as 1079 1.1 mrg read. */ 1080 1.1 mrg 1081 1.1 mrg static tree 1082 1.1 mrg maybe_mark_exp_read_r (tree *tp, int *, void *) 1083 1.1 mrg { 1084 1.1 mrg tree t = *tp; 1085 1.1 mrg if (VAR_P (t) || TREE_CODE (t) == PARM_DECL) 1086 1.1 mrg mark_exp_read (t); 1087 1.1 mrg return NULL_TREE; 1088 1.1 mrg } 1089 1.1 mrg 1090 1.1 mrg /* Finish an if-statement. */ 1091 1.1 mrg 1092 1.1 mrg void 1093 1.1 mrg finish_if_stmt (tree if_stmt) 1094 1.1 mrg { 1095 1.1 mrg tree scope = IF_SCOPE (if_stmt); 1096 1.1 mrg IF_SCOPE (if_stmt) = NULL; 1097 1.1 mrg if (IF_STMT_CONSTEXPR_P (if_stmt)) 1098 1.1 mrg { 1099 1.1 mrg /* Prevent various -Wunused warnings. We might not instantiate 1100 1.1 mrg either of these branches, so we would not mark the variables 1101 1.1 mrg used in that branch as read. */ 1102 1.1 mrg cp_walk_tree_without_duplicates (&THEN_CLAUSE (if_stmt), 1103 1.1 mrg maybe_mark_exp_read_r, NULL); 1104 1.1 mrg cp_walk_tree_without_duplicates (&ELSE_CLAUSE (if_stmt), 1105 1.1 mrg maybe_mark_exp_read_r, NULL); 1106 1.1 mrg } 1107 1.1 mrg add_stmt (do_poplevel (scope)); 1108 1.1 mrg } 1109 1.1 mrg 1110 1.1 mrg /* Begin a while-statement. Returns a newly created WHILE_STMT if 1111 1.1 mrg appropriate. */ 1112 1.1 mrg 1113 1.1 mrg tree 1114 1.1 mrg begin_while_stmt (void) 1115 1.1 mrg { 1116 1.1 mrg tree r; 1117 1.1 mrg r = build_stmt (input_location, WHILE_STMT, NULL_TREE, NULL_TREE); 1118 1.1 mrg add_stmt (r); 1119 1.1 mrg WHILE_BODY (r) = do_pushlevel (sk_block); 1120 1.1 mrg begin_cond (&WHILE_COND (r)); 1121 1.1 mrg return r; 1122 1.1 mrg } 1123 1.1 mrg 1124 1.1 mrg /* Process the COND of a while-statement, which may be given by 1125 1.1 mrg WHILE_STMT. */ 1126 1.1 mrg 1127 1.1 mrg void 1128 1.1 mrg finish_while_stmt_cond (tree cond, tree while_stmt, bool ivdep, 1129 1.1 mrg unsigned short unroll) 1130 1.1 mrg { 1131 1.1 mrg cond = maybe_convert_cond (cond); 1132 1.1 mrg finish_cond (&WHILE_COND (while_stmt), cond); 1133 1.1 mrg begin_maybe_infinite_loop (cond); 1134 1.1 mrg if (ivdep && cond != error_mark_node) 1135 1.1 mrg WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR, 1136 1.1 mrg TREE_TYPE (WHILE_COND (while_stmt)), 1137 1.1 mrg WHILE_COND (while_stmt), 1138 1.1 mrg build_int_cst (integer_type_node, 1139 1.1 mrg annot_expr_ivdep_kind), 1140 1.1 mrg integer_zero_node); 1141 1.1 mrg if (unroll && cond != error_mark_node) 1142 1.1 mrg WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR, 1143 1.1 mrg TREE_TYPE (WHILE_COND (while_stmt)), 1144 1.1 mrg WHILE_COND (while_stmt), 1145 1.1 mrg build_int_cst (integer_type_node, 1146 1.1 mrg annot_expr_unroll_kind), 1147 1.1 mrg build_int_cst (integer_type_node, 1148 1.1 mrg unroll)); 1149 1.1 mrg simplify_loop_decl_cond (&WHILE_COND (while_stmt), WHILE_BODY (while_stmt)); 1150 1.1 mrg } 1151 1.1 mrg 1152 1.1 mrg /* Finish a while-statement, which may be given by WHILE_STMT. */ 1153 1.1 mrg 1154 1.1 mrg void 1155 1.1 mrg finish_while_stmt (tree while_stmt) 1156 1.1 mrg { 1157 1.1 mrg end_maybe_infinite_loop (boolean_true_node); 1158 1.1 mrg WHILE_BODY (while_stmt) = do_poplevel (WHILE_BODY (while_stmt)); 1159 1.1 mrg } 1160 1.1 mrg 1161 1.1 mrg /* Begin a do-statement. Returns a newly created DO_STMT if 1162 1.1 mrg appropriate. */ 1163 1.1 mrg 1164 1.1 mrg tree 1165 1.1 mrg begin_do_stmt (void) 1166 1.1 mrg { 1167 1.1 mrg tree r = build_stmt (input_location, DO_STMT, NULL_TREE, NULL_TREE); 1168 1.1 mrg begin_maybe_infinite_loop (boolean_true_node); 1169 1.1 mrg add_stmt (r); 1170 1.1 mrg DO_BODY (r) = push_stmt_list (); 1171 1.1 mrg return r; 1172 1.1 mrg } 1173 1.1 mrg 1174 1.1 mrg /* Finish the body of a do-statement, which may be given by DO_STMT. */ 1175 1.1 mrg 1176 1.1 mrg void 1177 1.1 mrg finish_do_body (tree do_stmt) 1178 1.1 mrg { 1179 1.1 mrg tree body = DO_BODY (do_stmt) = pop_stmt_list (DO_BODY (do_stmt)); 1180 1.1 mrg 1181 1.1 mrg if (TREE_CODE (body) == STATEMENT_LIST && STATEMENT_LIST_TAIL (body)) 1182 1.1 mrg body = STATEMENT_LIST_TAIL (body)->stmt; 1183 1.1 mrg 1184 1.1 mrg if (IS_EMPTY_STMT (body)) 1185 1.1 mrg warning (OPT_Wempty_body, 1186 1.1 mrg "suggest explicit braces around empty body in %<do%> statement"); 1187 1.1 mrg } 1188 1.1 mrg 1189 1.1 mrg /* Finish a do-statement, which may be given by DO_STMT, and whose 1190 1.1 mrg COND is as indicated. */ 1191 1.1 mrg 1192 1.1 mrg void 1193 1.1 mrg finish_do_stmt (tree cond, tree do_stmt, bool ivdep, unsigned short unroll) 1194 1.1 mrg { 1195 1.1 mrg cond = maybe_convert_cond (cond); 1196 1.1 mrg end_maybe_infinite_loop (cond); 1197 1.1 mrg /* Unlike other iteration statements, the condition may not contain 1198 1.1 mrg a declaration, so we don't call finish_cond which checks for 1199 1.1 mrg unexpanded parameter packs. */ 1200 1.1 mrg if (check_for_bare_parameter_packs (cond)) 1201 1.1 mrg cond = error_mark_node; 1202 1.1 mrg if (ivdep && cond != error_mark_node) 1203 1.1 mrg cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond, 1204 1.1 mrg build_int_cst (integer_type_node, annot_expr_ivdep_kind), 1205 1.1 mrg integer_zero_node); 1206 1.1 mrg if (unroll && cond != error_mark_node) 1207 1.1 mrg cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond, 1208 1.1 mrg build_int_cst (integer_type_node, annot_expr_unroll_kind), 1209 1.1 mrg build_int_cst (integer_type_node, unroll)); 1210 1.1 mrg DO_COND (do_stmt) = cond; 1211 1.1 mrg } 1212 1.1 mrg 1213 1.1 mrg /* Finish a return-statement. The EXPRESSION returned, if any, is as 1214 1.1 mrg indicated. */ 1215 1.1 mrg 1216 1.1 mrg tree 1217 1.1 mrg finish_return_stmt (tree expr) 1218 1.1 mrg { 1219 1.1 mrg tree r; 1220 1.1 mrg bool no_warning; 1221 1.1 mrg 1222 1.1 mrg expr = check_return_expr (expr, &no_warning); 1223 1.1 mrg 1224 1.1 mrg if (error_operand_p (expr) 1225 1.1 mrg || (flag_openmp && !check_omp_return ())) 1226 1.1 mrg { 1227 1.1 mrg /* Suppress -Wreturn-type for this function. */ 1228 1.1 mrg if (warn_return_type) 1229 1.1 mrg suppress_warning (current_function_decl, OPT_Wreturn_type); 1230 1.1 mrg return error_mark_node; 1231 1.1 mrg } 1232 1.1 mrg 1233 1.1 mrg if (!processing_template_decl) 1234 1.1 mrg { 1235 1.1 mrg if (warn_sequence_point) 1236 1.1 mrg verify_sequence_points (expr); 1237 1.1 mrg 1238 1.1 mrg if (DECL_DESTRUCTOR_P (current_function_decl) 1239 1.1 mrg || (DECL_CONSTRUCTOR_P (current_function_decl) 1240 1.1 mrg && targetm.cxx.cdtor_returns_this ())) 1241 1.1 mrg { 1242 1.1 mrg /* Similarly, all destructors must run destructors for 1243 1.1 mrg base-classes before returning. So, all returns in a 1244 1.1 mrg destructor get sent to the DTOR_LABEL; finish_function emits 1245 1.1 mrg code to return a value there. */ 1246 1.1 mrg return finish_goto_stmt (cdtor_label); 1247 1.1 mrg } 1248 1.1 mrg } 1249 1.1 mrg 1250 1.1 mrg r = build_stmt (input_location, RETURN_EXPR, expr); 1251 1.1 mrg if (no_warning) 1252 1.1 mrg suppress_warning (r, OPT_Wreturn_type); 1253 1.1 mrg r = maybe_cleanup_point_expr_void (r); 1254 1.1 mrg r = add_stmt (r); 1255 1.1 mrg 1256 1.1 mrg return r; 1257 1.1 mrg } 1258 1.1 mrg 1259 1.1 mrg /* Begin the scope of a for-statement or a range-for-statement. 1260 1.1 mrg Both the returned trees are to be used in a call to 1261 1.1 mrg begin_for_stmt or begin_range_for_stmt. */ 1262 1.1 mrg 1263 1.1 mrg tree 1264 1.1 mrg begin_for_scope (tree *init) 1265 1.1 mrg { 1266 1.1 mrg tree scope = do_pushlevel (sk_for); 1267 1.1 mrg 1268 1.1 mrg if (processing_template_decl) 1269 1.1 mrg *init = push_stmt_list (); 1270 1.1 mrg else 1271 1.1 mrg *init = NULL_TREE; 1272 1.1 mrg 1273 1.1 mrg return scope; 1274 1.1 mrg } 1275 1.1 mrg 1276 1.1 mrg /* Begin a for-statement. Returns a new FOR_STMT. 1277 1.1 mrg SCOPE and INIT should be the return of begin_for_scope, 1278 1.1 mrg or both NULL_TREE */ 1279 1.1 mrg 1280 1.1 mrg tree 1281 1.1 mrg begin_for_stmt (tree scope, tree init) 1282 1.1 mrg { 1283 1.1 mrg tree r; 1284 1.1 mrg 1285 1.1 mrg r = build_stmt (input_location, FOR_STMT, NULL_TREE, NULL_TREE, 1286 1.1 mrg NULL_TREE, NULL_TREE, NULL_TREE); 1287 1.1 mrg 1288 1.1 mrg if (scope == NULL_TREE) 1289 1.1 mrg { 1290 1.1 mrg gcc_assert (!init); 1291 1.1 mrg scope = begin_for_scope (&init); 1292 1.1 mrg } 1293 1.1 mrg 1294 1.1 mrg FOR_INIT_STMT (r) = init; 1295 1.1 mrg FOR_SCOPE (r) = scope; 1296 1.1 mrg 1297 1.1 mrg return r; 1298 1.1 mrg } 1299 1.1 mrg 1300 1.1 mrg /* Finish the init-statement of a for-statement, which may be 1301 1.1 mrg given by FOR_STMT. */ 1302 1.1 mrg 1303 1.1 mrg void 1304 1.1 mrg finish_init_stmt (tree for_stmt) 1305 1.1 mrg { 1306 1.1 mrg if (processing_template_decl) 1307 1.1 mrg FOR_INIT_STMT (for_stmt) = pop_stmt_list (FOR_INIT_STMT (for_stmt)); 1308 1.1 mrg add_stmt (for_stmt); 1309 1.1 mrg FOR_BODY (for_stmt) = do_pushlevel (sk_block); 1310 1.1 mrg begin_cond (&FOR_COND (for_stmt)); 1311 1.1 mrg } 1312 1.1 mrg 1313 1.1 mrg /* Finish the COND of a for-statement, which may be given by 1314 1.1 mrg FOR_STMT. */ 1315 1.1 mrg 1316 1.1 mrg void 1317 1.1 mrg finish_for_cond (tree cond, tree for_stmt, bool ivdep, unsigned short unroll) 1318 1.1 mrg { 1319 1.1 mrg cond = maybe_convert_cond (cond); 1320 1.1 mrg finish_cond (&FOR_COND (for_stmt), cond); 1321 1.1 mrg begin_maybe_infinite_loop (cond); 1322 1.1 mrg if (ivdep && cond != error_mark_node) 1323 1.1 mrg FOR_COND (for_stmt) = build3 (ANNOTATE_EXPR, 1324 1.1 mrg TREE_TYPE (FOR_COND (for_stmt)), 1325 1.1 mrg FOR_COND (for_stmt), 1326 1.1 mrg build_int_cst (integer_type_node, 1327 1.1 mrg annot_expr_ivdep_kind), 1328 1.1 mrg integer_zero_node); 1329 1.1 mrg if (unroll && cond != error_mark_node) 1330 1.1 mrg FOR_COND (for_stmt) = build3 (ANNOTATE_EXPR, 1331 1.1 mrg TREE_TYPE (FOR_COND (for_stmt)), 1332 1.1 mrg FOR_COND (for_stmt), 1333 1.1 mrg build_int_cst (integer_type_node, 1334 1.1 mrg annot_expr_unroll_kind), 1335 1.1 mrg build_int_cst (integer_type_node, 1336 1.1 mrg unroll)); 1337 1.1 mrg simplify_loop_decl_cond (&FOR_COND (for_stmt), FOR_BODY (for_stmt)); 1338 1.1 mrg } 1339 1.1 mrg 1340 1.1 mrg /* Finish the increment-EXPRESSION in a for-statement, which may be 1341 1.1 mrg given by FOR_STMT. */ 1342 1.1 mrg 1343 1.1 mrg void 1344 1.1 mrg finish_for_expr (tree expr, tree for_stmt) 1345 1.1 mrg { 1346 1.1 mrg if (!expr) 1347 1.1 mrg return; 1348 1.1 mrg /* If EXPR is an overloaded function, issue an error; there is no 1349 1.1 mrg context available to use to perform overload resolution. */ 1350 1.1 mrg if (type_unknown_p (expr)) 1351 1.1 mrg { 1352 1.1 mrg cxx_incomplete_type_error (expr, TREE_TYPE (expr)); 1353 1.1 mrg expr = error_mark_node; 1354 1.1 mrg } 1355 1.1 mrg if (!processing_template_decl) 1356 1.1 mrg { 1357 1.1 mrg if (warn_sequence_point) 1358 1.1 mrg verify_sequence_points (expr); 1359 1.1 mrg expr = convert_to_void (expr, ICV_THIRD_IN_FOR, 1360 1.1 mrg tf_warning_or_error); 1361 1.1 mrg } 1362 1.1 mrg else if (!type_dependent_expression_p (expr)) 1363 1.1 mrg convert_to_void (build_non_dependent_expr (expr), ICV_THIRD_IN_FOR, 1364 1.1 mrg tf_warning_or_error); 1365 1.1 mrg expr = maybe_cleanup_point_expr_void (expr); 1366 1.1 mrg if (check_for_bare_parameter_packs (expr)) 1367 1.1 mrg expr = error_mark_node; 1368 1.1 mrg FOR_EXPR (for_stmt) = expr; 1369 1.1 mrg } 1370 1.1 mrg 1371 1.1 mrg /* Finish the body of a for-statement, which may be given by 1372 1.1 mrg FOR_STMT. The increment-EXPR for the loop must be 1373 1.1 mrg provided. 1374 1.1 mrg It can also finish RANGE_FOR_STMT. */ 1375 1.1 mrg 1376 1.1 mrg void 1377 1.1 mrg finish_for_stmt (tree for_stmt) 1378 1.1 mrg { 1379 1.1 mrg end_maybe_infinite_loop (boolean_true_node); 1380 1.1 mrg 1381 1.1 mrg if (TREE_CODE (for_stmt) == RANGE_FOR_STMT) 1382 1.1 mrg RANGE_FOR_BODY (for_stmt) = do_poplevel (RANGE_FOR_BODY (for_stmt)); 1383 1.1 mrg else 1384 1.1 mrg FOR_BODY (for_stmt) = do_poplevel (FOR_BODY (for_stmt)); 1385 1.1 mrg 1386 1.1 mrg /* Pop the scope for the body of the loop. */ 1387 1.1 mrg tree *scope_ptr = (TREE_CODE (for_stmt) == RANGE_FOR_STMT 1388 1.1 mrg ? &RANGE_FOR_SCOPE (for_stmt) 1389 1.1 mrg : &FOR_SCOPE (for_stmt)); 1390 1.1 mrg tree scope = *scope_ptr; 1391 1.1 mrg *scope_ptr = NULL; 1392 1.1 mrg 1393 1.1 mrg /* During parsing of the body, range for uses "__for_{range,begin,end} " 1394 1.1 mrg decl names to make those unaccessible by code in the body. 1395 1.1 mrg Change it to ones with underscore instead of space, so that it can 1396 1.1 mrg be inspected in the debugger. */ 1397 1.1 mrg tree range_for_decl[3] = { NULL_TREE, NULL_TREE, NULL_TREE }; 1398 1.1 mrg gcc_assert (CPTI_FOR_BEGIN__IDENTIFIER == CPTI_FOR_RANGE__IDENTIFIER + 1 1399 1.1 mrg && CPTI_FOR_END__IDENTIFIER == CPTI_FOR_RANGE__IDENTIFIER + 2 1400 1.1 mrg && CPTI_FOR_RANGE_IDENTIFIER == CPTI_FOR_RANGE__IDENTIFIER + 3 1401 1.1 mrg && CPTI_FOR_BEGIN_IDENTIFIER == CPTI_FOR_BEGIN__IDENTIFIER + 3 1402 1.1 mrg && CPTI_FOR_END_IDENTIFIER == CPTI_FOR_END__IDENTIFIER + 3); 1403 1.1 mrg for (int i = 0; i < 3; i++) 1404 1.1 mrg { 1405 1.1 mrg tree id = cp_global_trees[CPTI_FOR_RANGE__IDENTIFIER + i]; 1406 1.1 mrg if (IDENTIFIER_BINDING (id) 1407 1.1 mrg && IDENTIFIER_BINDING (id)->scope == current_binding_level) 1408 1.1 mrg { 1409 1.1 mrg range_for_decl[i] = IDENTIFIER_BINDING (id)->value; 1410 1.1 mrg gcc_assert (VAR_P (range_for_decl[i]) 1411 1.1 mrg && DECL_ARTIFICIAL (range_for_decl[i])); 1412 1.1 mrg } 1413 1.1 mrg } 1414 1.1 mrg 1415 1.1 mrg add_stmt (do_poplevel (scope)); 1416 1.1 mrg 1417 1.1 mrg /* If we're being called from build_vec_init, don't mess with the names of 1418 1.1 mrg the variables for an enclosing range-for. */ 1419 1.1 mrg if (!stmts_are_full_exprs_p ()) 1420 1.1 mrg return; 1421 1.1 mrg 1422 1.1 mrg for (int i = 0; i < 3; i++) 1423 1.1 mrg if (range_for_decl[i]) 1424 1.1 mrg DECL_NAME (range_for_decl[i]) 1425 1.1 mrg = cp_global_trees[CPTI_FOR_RANGE_IDENTIFIER + i]; 1426 1.1 mrg } 1427 1.1 mrg 1428 1.1 mrg /* Begin a range-for-statement. Returns a new RANGE_FOR_STMT. 1429 1.1 mrg SCOPE and INIT should be the return of begin_for_scope, 1430 1.1 mrg or both NULL_TREE . 1431 1.1 mrg To finish it call finish_for_stmt(). */ 1432 1.1 mrg 1433 1.1 mrg tree 1434 1.1 mrg begin_range_for_stmt (tree scope, tree init) 1435 1.1 mrg { 1436 1.1 mrg begin_maybe_infinite_loop (boolean_false_node); 1437 1.1 mrg 1438 1.1 mrg tree r = build_stmt (input_location, RANGE_FOR_STMT, NULL_TREE, NULL_TREE, 1439 1.1 mrg NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE); 1440 1.1 mrg 1441 1.1 mrg if (scope == NULL_TREE) 1442 1.1 mrg { 1443 1.1 mrg gcc_assert (!init); 1444 1.1 mrg scope = begin_for_scope (&init); 1445 1.1 mrg } 1446 1.1 mrg 1447 1.1 mrg /* Since C++20, RANGE_FOR_STMTs can use the init tree, so save it. */ 1448 1.1 mrg RANGE_FOR_INIT_STMT (r) = init; 1449 1.1 mrg RANGE_FOR_SCOPE (r) = scope; 1450 1.1 mrg 1451 1.1 mrg return r; 1452 1.1 mrg } 1453 1.1 mrg 1454 1.1 mrg /* Finish the head of a range-based for statement, which may 1455 1.1 mrg be given by RANGE_FOR_STMT. DECL must be the declaration 1456 1.1 mrg and EXPR must be the loop expression. */ 1457 1.1 mrg 1458 1.1 mrg void 1459 1.1 mrg finish_range_for_decl (tree range_for_stmt, tree decl, tree expr) 1460 1.1 mrg { 1461 1.1 mrg if (processing_template_decl) 1462 1.1 mrg RANGE_FOR_INIT_STMT (range_for_stmt) 1463 1.1 mrg = pop_stmt_list (RANGE_FOR_INIT_STMT (range_for_stmt)); 1464 1.1 mrg RANGE_FOR_DECL (range_for_stmt) = decl; 1465 1.1 mrg RANGE_FOR_EXPR (range_for_stmt) = expr; 1466 1.1 mrg add_stmt (range_for_stmt); 1467 1.1 mrg RANGE_FOR_BODY (range_for_stmt) = do_pushlevel (sk_block); 1468 1.1 mrg } 1469 1.1 mrg 1470 1.1 mrg /* Finish a break-statement. */ 1471 1.1 mrg 1472 1.1 mrg tree 1473 1.1 mrg finish_break_stmt (void) 1474 1.1 mrg { 1475 1.1 mrg /* In switch statements break is sometimes stylistically used after 1476 1.1 mrg a return statement. This can lead to spurious warnings about 1477 1.1 mrg control reaching the end of a non-void function when it is 1478 1.1 mrg inlined. Note that we are calling block_may_fallthru with 1479 1.1 mrg language specific tree nodes; this works because 1480 1.1 mrg block_may_fallthru returns true when given something it does not 1481 1.1 mrg understand. */ 1482 1.1 mrg if (!block_may_fallthru (cur_stmt_list)) 1483 1.1 mrg return void_node; 1484 1.1 mrg note_break_stmt (); 1485 1.1 mrg return add_stmt (build_stmt (input_location, BREAK_STMT)); 1486 1.1 mrg } 1487 1.1 mrg 1488 1.1 mrg /* Finish a continue-statement. */ 1489 1.1 mrg 1490 1.1 mrg tree 1491 1.1 mrg finish_continue_stmt (void) 1492 1.1 mrg { 1493 1.1 mrg return add_stmt (build_stmt (input_location, CONTINUE_STMT)); 1494 1.1 mrg } 1495 1.1 mrg 1496 1.1 mrg /* Begin a switch-statement. Returns a new SWITCH_STMT if 1497 1.1 mrg appropriate. */ 1498 1.1 mrg 1499 1.1 mrg tree 1500 1.1 mrg begin_switch_stmt (void) 1501 1.1 mrg { 1502 1.1 mrg tree r, scope; 1503 1.1 mrg 1504 1.1 mrg scope = do_pushlevel (sk_cond); 1505 1.1 mrg r = build_stmt (input_location, SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE, scope); 1506 1.1 mrg 1507 1.1 mrg begin_cond (&SWITCH_STMT_COND (r)); 1508 1.1 mrg 1509 1.1 mrg return r; 1510 1.1 mrg } 1511 1.1 mrg 1512 1.1 mrg /* Finish the cond of a switch-statement. */ 1513 1.1 mrg 1514 1.1 mrg void 1515 1.1 mrg finish_switch_cond (tree cond, tree switch_stmt) 1516 1.1 mrg { 1517 1.1 mrg tree orig_type = NULL; 1518 1.1 mrg 1519 1.1 mrg if (!processing_template_decl) 1520 1.1 mrg { 1521 1.1 mrg /* Convert the condition to an integer or enumeration type. */ 1522 1.1 mrg tree orig_cond = cond; 1523 1.1 mrg cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, true); 1524 1.1 mrg if (cond == NULL_TREE) 1525 1.1 mrg { 1526 1.1 mrg error_at (cp_expr_loc_or_input_loc (orig_cond), 1527 1.1 mrg "switch quantity not an integer"); 1528 1.1 mrg cond = error_mark_node; 1529 1.1 mrg } 1530 1.1 mrg /* We want unlowered type here to handle enum bit-fields. */ 1531 1.1 mrg orig_type = unlowered_expr_type (cond); 1532 1.1 mrg if (TREE_CODE (orig_type) != ENUMERAL_TYPE) 1533 1.1 mrg orig_type = TREE_TYPE (cond); 1534 1.1 mrg if (cond != error_mark_node) 1535 1.1 mrg { 1536 1.1 mrg /* [stmt.switch] 1537 1.1 mrg 1538 1.1 mrg Integral promotions are performed. */ 1539 1.1 mrg cond = perform_integral_promotions (cond); 1540 1.1 mrg cond = maybe_cleanup_point_expr (cond); 1541 1.1 mrg } 1542 1.1 mrg } 1543 1.1 mrg if (check_for_bare_parameter_packs (cond)) 1544 1.1 mrg cond = error_mark_node; 1545 1.1 mrg else if (!processing_template_decl && warn_sequence_point) 1546 1.1 mrg verify_sequence_points (cond); 1547 1.1 mrg 1548 1.1 mrg finish_cond (&SWITCH_STMT_COND (switch_stmt), cond); 1549 1.1 mrg SWITCH_STMT_TYPE (switch_stmt) = orig_type; 1550 1.1 mrg add_stmt (switch_stmt); 1551 1.1 mrg push_switch (switch_stmt); 1552 1.1 mrg SWITCH_STMT_BODY (switch_stmt) = push_stmt_list (); 1553 1.1 mrg } 1554 1.1 mrg 1555 1.1 mrg /* Finish the body of a switch-statement, which may be given by 1556 1.1 mrg SWITCH_STMT. The COND to switch on is indicated. */ 1557 1.1 mrg 1558 1.1 mrg void 1559 1.1 mrg finish_switch_stmt (tree switch_stmt) 1560 1.1 mrg { 1561 1.1 mrg tree scope; 1562 1.1 mrg 1563 1.1 mrg SWITCH_STMT_BODY (switch_stmt) = 1564 1.1 mrg pop_stmt_list (SWITCH_STMT_BODY (switch_stmt)); 1565 1.1 mrg pop_switch (); 1566 1.1 mrg 1567 1.1 mrg scope = SWITCH_STMT_SCOPE (switch_stmt); 1568 1.1 mrg SWITCH_STMT_SCOPE (switch_stmt) = NULL; 1569 1.1 mrg add_stmt (do_poplevel (scope)); 1570 1.1 mrg } 1571 1.1 mrg 1572 1.1 mrg /* Begin a try-block. Returns a newly-created TRY_BLOCK if 1573 1.1 mrg appropriate. */ 1574 1.1 mrg 1575 1.1 mrg tree 1576 1.1 mrg begin_try_block (void) 1577 1.1 mrg { 1578 1.1 mrg tree r = build_stmt (input_location, TRY_BLOCK, NULL_TREE, NULL_TREE); 1579 1.1 mrg add_stmt (r); 1580 1.1 mrg TRY_STMTS (r) = push_stmt_list (); 1581 1.1 mrg return r; 1582 1.1 mrg } 1583 1.1 mrg 1584 1.1 mrg /* Likewise, for a function-try-block. The block returned in 1585 1.1 mrg *COMPOUND_STMT is an artificial outer scope, containing the 1586 1.1 mrg function-try-block. */ 1587 1.1 mrg 1588 1.1 mrg tree 1589 1.1 mrg begin_function_try_block (tree *compound_stmt) 1590 1.1 mrg { 1591 1.1 mrg tree r; 1592 1.1 mrg /* This outer scope does not exist in the C++ standard, but we need 1593 1.1 mrg a place to put __FUNCTION__ and similar variables. */ 1594 1.1 mrg *compound_stmt = begin_compound_stmt (0); 1595 1.1 mrg r = begin_try_block (); 1596 1.1 mrg FN_TRY_BLOCK_P (r) = 1; 1597 1.1 mrg return r; 1598 1.1 mrg } 1599 1.1 mrg 1600 1.1 mrg /* Finish a try-block, which may be given by TRY_BLOCK. */ 1601 1.1 mrg 1602 1.1 mrg void 1603 1.1 mrg finish_try_block (tree try_block) 1604 1.1 mrg { 1605 1.1 mrg TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block)); 1606 1.1 mrg TRY_HANDLERS (try_block) = push_stmt_list (); 1607 1.1 mrg } 1608 1.1 mrg 1609 1.1 mrg /* Finish the body of a cleanup try-block, which may be given by 1610 1.1 mrg TRY_BLOCK. */ 1611 1.1 mrg 1612 1.1 mrg void 1613 1.1 mrg finish_cleanup_try_block (tree try_block) 1614 1.1 mrg { 1615 1.1 mrg TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block)); 1616 1.1 mrg } 1617 1.1 mrg 1618 1.1 mrg /* Finish an implicitly generated try-block, with a cleanup is given 1619 1.1 mrg by CLEANUP. */ 1620 1.1 mrg 1621 1.1 mrg void 1622 1.1 mrg finish_cleanup (tree cleanup, tree try_block) 1623 1.1 mrg { 1624 1.1 mrg TRY_HANDLERS (try_block) = cleanup; 1625 1.1 mrg CLEANUP_P (try_block) = 1; 1626 1.1 mrg } 1627 1.1 mrg 1628 1.1 mrg /* Likewise, for a function-try-block. */ 1629 1.1 mrg 1630 1.1 mrg void 1631 1.1 mrg finish_function_try_block (tree try_block) 1632 1.1 mrg { 1633 1.1 mrg finish_try_block (try_block); 1634 1.1 mrg /* FIXME : something queer about CTOR_INITIALIZER somehow following 1635 1.1 mrg the try block, but moving it inside. */ 1636 1.1 mrg in_function_try_handler = 1; 1637 1.1 mrg } 1638 1.1 mrg 1639 1.1 mrg /* Finish a handler-sequence for a try-block, which may be given by 1640 1.1 mrg TRY_BLOCK. */ 1641 1.1 mrg 1642 1.1 mrg void 1643 1.1 mrg finish_handler_sequence (tree try_block) 1644 1.1 mrg { 1645 1.1 mrg TRY_HANDLERS (try_block) = pop_stmt_list (TRY_HANDLERS (try_block)); 1646 1.1 mrg check_handlers (TRY_HANDLERS (try_block)); 1647 1.1 mrg } 1648 1.1 mrg 1649 1.1 mrg /* Finish the handler-seq for a function-try-block, given by 1650 1.1 mrg TRY_BLOCK. COMPOUND_STMT is the outer block created by 1651 1.1 mrg begin_function_try_block. */ 1652 1.1 mrg 1653 1.1 mrg void 1654 1.1 mrg finish_function_handler_sequence (tree try_block, tree compound_stmt) 1655 1.1 mrg { 1656 1.1 mrg in_function_try_handler = 0; 1657 1.1 mrg finish_handler_sequence (try_block); 1658 1.1 mrg finish_compound_stmt (compound_stmt); 1659 1.1 mrg } 1660 1.1 mrg 1661 1.1 mrg /* Begin a handler. Returns a HANDLER if appropriate. */ 1662 1.1 mrg 1663 1.1 mrg tree 1664 1.1 mrg begin_handler (void) 1665 1.1 mrg { 1666 1.1 mrg tree r; 1667 1.1 mrg 1668 1.1 mrg r = build_stmt (input_location, HANDLER, NULL_TREE, NULL_TREE); 1669 1.1 mrg add_stmt (r); 1670 1.1 mrg 1671 1.1 mrg /* Create a binding level for the eh_info and the exception object 1672 1.1 mrg cleanup. */ 1673 1.1 mrg HANDLER_BODY (r) = do_pushlevel (sk_catch); 1674 1.1 mrg 1675 1.1 mrg return r; 1676 1.1 mrg } 1677 1.1 mrg 1678 1.1 mrg /* Finish the handler-parameters for a handler, which may be given by 1679 1.1 mrg HANDLER. DECL is the declaration for the catch parameter, or NULL 1680 1.1 mrg if this is a `catch (...)' clause. */ 1681 1.1 mrg 1682 1.1 mrg void 1683 1.1 mrg finish_handler_parms (tree decl, tree handler) 1684 1.1 mrg { 1685 1.1 mrg tree type = NULL_TREE; 1686 1.1 mrg if (processing_template_decl) 1687 1.1 mrg { 1688 1.1 mrg if (decl) 1689 1.1 mrg { 1690 1.1 mrg decl = pushdecl (decl); 1691 1.1 mrg decl = push_template_decl (decl); 1692 1.1 mrg HANDLER_PARMS (handler) = decl; 1693 1.1 mrg type = TREE_TYPE (decl); 1694 1.1 mrg } 1695 1.1 mrg } 1696 1.1 mrg else 1697 1.1 mrg { 1698 1.1 mrg type = expand_start_catch_block (decl); 1699 1.1 mrg if (warn_catch_value 1700 1.1 mrg && type != NULL_TREE 1701 1.1 mrg && type != error_mark_node 1702 1.1 mrg && !TYPE_REF_P (TREE_TYPE (decl))) 1703 1.1 mrg { 1704 1.1 mrg tree orig_type = TREE_TYPE (decl); 1705 1.1 mrg if (CLASS_TYPE_P (orig_type)) 1706 1.1 mrg { 1707 1.1 mrg if (TYPE_POLYMORPHIC_P (orig_type)) 1708 1.1 mrg warning_at (DECL_SOURCE_LOCATION (decl), 1709 1.1 mrg OPT_Wcatch_value_, 1710 1.1 mrg "catching polymorphic type %q#T by value", 1711 1.1 mrg orig_type); 1712 1.1 mrg else if (warn_catch_value > 1) 1713 1.1 mrg warning_at (DECL_SOURCE_LOCATION (decl), 1714 1.1 mrg OPT_Wcatch_value_, 1715 1.1 mrg "catching type %q#T by value", orig_type); 1716 1.1 mrg } 1717 1.1 mrg else if (warn_catch_value > 2) 1718 1.1 mrg warning_at (DECL_SOURCE_LOCATION (decl), 1719 1.1 mrg OPT_Wcatch_value_, 1720 1.1 mrg "catching non-reference type %q#T", orig_type); 1721 1.1 mrg } 1722 1.1 mrg } 1723 1.1 mrg HANDLER_TYPE (handler) = type; 1724 1.1 mrg } 1725 1.1 mrg 1726 1.1 mrg /* Finish a handler, which may be given by HANDLER. The BLOCKs are 1727 1.1 mrg the return value from the matching call to finish_handler_parms. */ 1728 1.1 mrg 1729 1.1 mrg void 1730 1.1 mrg finish_handler (tree handler) 1731 1.1 mrg { 1732 1.1 mrg if (!processing_template_decl) 1733 1.1 mrg expand_end_catch_block (); 1734 1.1 mrg HANDLER_BODY (handler) = do_poplevel (HANDLER_BODY (handler)); 1735 1.1 mrg } 1736 1.1 mrg 1737 1.1 mrg /* Begin a compound statement. FLAGS contains some bits that control the 1738 1.1 mrg behavior and context. If BCS_NO_SCOPE is set, the compound statement 1739 1.1 mrg does not define a scope. If BCS_FN_BODY is set, this is the outermost 1740 1.1 mrg block of a function. If BCS_TRY_BLOCK is set, this is the block 1741 1.1 mrg created on behalf of a TRY statement. Returns a token to be passed to 1742 1.1 mrg finish_compound_stmt. */ 1743 1.1 mrg 1744 1.1 mrg tree 1745 1.1 mrg begin_compound_stmt (unsigned int flags) 1746 1.1 mrg { 1747 1.1 mrg tree r; 1748 1.1 mrg 1749 1.1 mrg if (flags & BCS_NO_SCOPE) 1750 1.1 mrg { 1751 1.1 mrg r = push_stmt_list (); 1752 1.1 mrg STATEMENT_LIST_NO_SCOPE (r) = 1; 1753 1.1 mrg 1754 1.1 mrg /* Normally, we try hard to keep the BLOCK for a statement-expression. 1755 1.1 mrg But, if it's a statement-expression with a scopeless block, there's 1756 1.1 mrg nothing to keep, and we don't want to accidentally keep a block 1757 1.1 mrg *inside* the scopeless block. */ 1758 1.1 mrg keep_next_level (false); 1759 1.1 mrg } 1760 1.1 mrg else 1761 1.1 mrg { 1762 1.1 mrg scope_kind sk = sk_block; 1763 1.1 mrg if (flags & BCS_TRY_BLOCK) 1764 1.1 mrg sk = sk_try; 1765 1.1 mrg else if (flags & BCS_TRANSACTION) 1766 1.1 mrg sk = sk_transaction; 1767 1.1 mrg r = do_pushlevel (sk); 1768 1.1 mrg } 1769 1.1 mrg 1770 1.1 mrg /* When processing a template, we need to remember where the braces were, 1771 1.1 mrg so that we can set up identical scopes when instantiating the template 1772 1.1 mrg later. BIND_EXPR is a handy candidate for this. 1773 1.1 mrg Note that do_poplevel won't create a BIND_EXPR itself here (and thus 1774 1.1 mrg result in nested BIND_EXPRs), since we don't build BLOCK nodes when 1775 1.1 mrg processing templates. */ 1776 1.1 mrg if (processing_template_decl) 1777 1.1 mrg { 1778 1.1 mrg r = build3 (BIND_EXPR, NULL, NULL, r, NULL); 1779 1.1 mrg BIND_EXPR_TRY_BLOCK (r) = (flags & BCS_TRY_BLOCK) != 0; 1780 1.1 mrg BIND_EXPR_BODY_BLOCK (r) = (flags & BCS_FN_BODY) != 0; 1781 1.1 mrg TREE_SIDE_EFFECTS (r) = 1; 1782 1.1 mrg } 1783 1.1 mrg 1784 1.1 mrg return r; 1785 1.1 mrg } 1786 1.1 mrg 1787 1.1 mrg /* Finish a compound-statement, which is given by STMT. */ 1788 1.1 mrg 1789 1.1 mrg void 1790 1.1 mrg finish_compound_stmt (tree stmt) 1791 1.1 mrg { 1792 1.1 mrg if (TREE_CODE (stmt) == BIND_EXPR) 1793 1.1 mrg { 1794 1.1 mrg tree body = do_poplevel (BIND_EXPR_BODY (stmt)); 1795 1.1 mrg /* If the STATEMENT_LIST is empty and this BIND_EXPR isn't special, 1796 1.1 mrg discard the BIND_EXPR so it can be merged with the containing 1797 1.1 mrg STATEMENT_LIST. */ 1798 1.1 mrg if (TREE_CODE (body) == STATEMENT_LIST 1799 1.1 mrg && STATEMENT_LIST_HEAD (body) == NULL 1800 1.1 mrg && !BIND_EXPR_BODY_BLOCK (stmt) 1801 1.1 mrg && !BIND_EXPR_TRY_BLOCK (stmt)) 1802 1.1 mrg stmt = body; 1803 1.1 mrg else 1804 1.1 mrg BIND_EXPR_BODY (stmt) = body; 1805 1.1 mrg } 1806 1.1 mrg else if (STATEMENT_LIST_NO_SCOPE (stmt)) 1807 1.1 mrg stmt = pop_stmt_list (stmt); 1808 1.1 mrg else 1809 1.1 mrg { 1810 1.1 mrg /* Destroy any ObjC "super" receivers that may have been 1811 1.1 mrg created. */ 1812 1.1 mrg objc_clear_super_receiver (); 1813 1.1 mrg 1814 1.1 mrg stmt = do_poplevel (stmt); 1815 1.1 mrg } 1816 1.1 mrg 1817 1.1 mrg /* ??? See c_end_compound_stmt wrt statement expressions. */ 1818 1.1 mrg add_stmt (stmt); 1819 1.1 mrg } 1820 1.1 mrg 1821 1.1 mrg /* Finish an asm-statement, whose components are a STRING, some 1822 1.1 mrg OUTPUT_OPERANDS, some INPUT_OPERANDS, some CLOBBERS and some 1823 1.1 mrg LABELS. Also note whether the asm-statement should be 1824 1.1 mrg considered volatile, and whether it is asm inline. */ 1825 1.1 mrg 1826 1.1 mrg tree 1827 1.1 mrg finish_asm_stmt (location_t loc, int volatile_p, tree string, 1828 1.1 mrg tree output_operands, tree input_operands, tree clobbers, 1829 1.1 mrg tree labels, bool inline_p) 1830 1.1 mrg { 1831 1.1 mrg tree r; 1832 1.1 mrg tree t; 1833 1.1 mrg int ninputs = list_length (input_operands); 1834 1.1 mrg int noutputs = list_length (output_operands); 1835 1.1 mrg 1836 1.1 mrg if (!processing_template_decl) 1837 1.1 mrg { 1838 1.1 mrg const char *constraint; 1839 1.1 mrg const char **oconstraints; 1840 1.1 mrg bool allows_mem, allows_reg, is_inout; 1841 1.1 mrg tree operand; 1842 1.1 mrg int i; 1843 1.1 mrg 1844 1.1 mrg oconstraints = XALLOCAVEC (const char *, noutputs); 1845 1.1 mrg 1846 1.1 mrg string = resolve_asm_operand_names (string, output_operands, 1847 1.1 mrg input_operands, labels); 1848 1.1 mrg 1849 1.1 mrg for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i) 1850 1.1 mrg { 1851 1.1 mrg operand = TREE_VALUE (t); 1852 1.1 mrg 1853 1.1 mrg /* ??? Really, this should not be here. Users should be using a 1854 1.1 mrg proper lvalue, dammit. But there's a long history of using 1855 1.1 mrg casts in the output operands. In cases like longlong.h, this 1856 1.1 mrg becomes a primitive form of typechecking -- if the cast can be 1857 1.1 mrg removed, then the output operand had a type of the proper width; 1858 1.1 mrg otherwise we'll get an error. Gross, but ... */ 1859 1.1 mrg STRIP_NOPS (operand); 1860 1.1 mrg 1861 1.1 mrg operand = mark_lvalue_use (operand); 1862 1.1 mrg 1863 1.1 mrg if (!lvalue_or_else (operand, lv_asm, tf_warning_or_error)) 1864 1.1 mrg operand = error_mark_node; 1865 1.1 mrg 1866 1.1 mrg if (operand != error_mark_node 1867 1.1 mrg && (TREE_READONLY (operand) 1868 1.1 mrg || CP_TYPE_CONST_P (TREE_TYPE (operand)) 1869 1.1 mrg /* Functions are not modifiable, even though they are 1870 1.1 mrg lvalues. */ 1871 1.1 mrg || FUNC_OR_METHOD_TYPE_P (TREE_TYPE (operand)) 1872 1.1 mrg /* If it's an aggregate and any field is const, then it is 1873 1.1 mrg effectively const. */ 1874 1.1 mrg || (CLASS_TYPE_P (TREE_TYPE (operand)) 1875 1.1 mrg && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand))))) 1876 1.1 mrg cxx_readonly_error (loc, operand, lv_asm); 1877 1.1 mrg 1878 1.1 mrg tree *op = &operand; 1879 1.1 mrg while (TREE_CODE (*op) == COMPOUND_EXPR) 1880 1.1 mrg op = &TREE_OPERAND (*op, 1); 1881 1.1 mrg switch (TREE_CODE (*op)) 1882 1.1 mrg { 1883 1.1 mrg case PREINCREMENT_EXPR: 1884 1.1 mrg case PREDECREMENT_EXPR: 1885 1.1 mrg case MODIFY_EXPR: 1886 1.1 mrg *op = genericize_compound_lvalue (*op); 1887 1.1 mrg op = &TREE_OPERAND (*op, 1); 1888 1.1 mrg break; 1889 1.1 mrg default: 1890 1.1 mrg break; 1891 1.1 mrg } 1892 1.1 mrg 1893 1.1 mrg constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t))); 1894 1.1 mrg oconstraints[i] = constraint; 1895 1.1 mrg 1896 1.1 mrg if (parse_output_constraint (&constraint, i, ninputs, noutputs, 1897 1.1 mrg &allows_mem, &allows_reg, &is_inout)) 1898 1.1 mrg { 1899 1.1 mrg /* If the operand is going to end up in memory, 1900 1.1 mrg mark it addressable. */ 1901 1.1 mrg if (!allows_reg && !cxx_mark_addressable (*op)) 1902 1.1 mrg operand = error_mark_node; 1903 1.1 mrg } 1904 1.1 mrg else 1905 1.1 mrg operand = error_mark_node; 1906 1.1 mrg 1907 1.1 mrg TREE_VALUE (t) = operand; 1908 1.1 mrg } 1909 1.1 mrg 1910 1.1 mrg for (i = 0, t = input_operands; t; ++i, t = TREE_CHAIN (t)) 1911 1.1 mrg { 1912 1.1 mrg constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t))); 1913 1.1 mrg bool constraint_parsed 1914 1.1 mrg = parse_input_constraint (&constraint, i, ninputs, noutputs, 0, 1915 1.1 mrg oconstraints, &allows_mem, &allows_reg); 1916 1.1 mrg /* If the operand is going to end up in memory, don't call 1917 1.1 mrg decay_conversion. */ 1918 1.1 mrg if (constraint_parsed && !allows_reg && allows_mem) 1919 1.1 mrg operand = mark_lvalue_use (TREE_VALUE (t)); 1920 1.1 mrg else 1921 1.1 mrg operand = decay_conversion (TREE_VALUE (t), tf_warning_or_error); 1922 1.1 mrg 1923 1.1 mrg /* If the type of the operand hasn't been determined (e.g., 1924 1.1 mrg because it involves an overloaded function), then issue 1925 1.1 mrg an error message. There's no context available to 1926 1.1 mrg resolve the overloading. */ 1927 1.1 mrg if (TREE_TYPE (operand) == unknown_type_node) 1928 1.1 mrg { 1929 1.1 mrg error_at (loc, 1930 1.1 mrg "type of %<asm%> operand %qE could not be determined", 1931 1.1 mrg TREE_VALUE (t)); 1932 1.1 mrg operand = error_mark_node; 1933 1.1 mrg } 1934 1.1 mrg 1935 1.1 mrg if (constraint_parsed) 1936 1.1 mrg { 1937 1.1 mrg /* If the operand is going to end up in memory, 1938 1.1 mrg mark it addressable. */ 1939 1.1 mrg if (!allows_reg && allows_mem) 1940 1.1 mrg { 1941 1.1 mrg /* Strip the nops as we allow this case. FIXME, this really 1942 1.1 mrg should be rejected or made deprecated. */ 1943 1.1 mrg STRIP_NOPS (operand); 1944 1.1 mrg 1945 1.1 mrg tree *op = &operand; 1946 1.1 mrg while (TREE_CODE (*op) == COMPOUND_EXPR) 1947 1.1 mrg op = &TREE_OPERAND (*op, 1); 1948 1.1 mrg switch (TREE_CODE (*op)) 1949 1.1 mrg { 1950 1.1 mrg case PREINCREMENT_EXPR: 1951 1.1 mrg case PREDECREMENT_EXPR: 1952 1.1 mrg case MODIFY_EXPR: 1953 1.1 mrg *op = genericize_compound_lvalue (*op); 1954 1.1 mrg op = &TREE_OPERAND (*op, 1); 1955 1.1 mrg break; 1956 1.1 mrg default: 1957 1.1 mrg break; 1958 1.1 mrg } 1959 1.1 mrg 1960 1.1 mrg if (!cxx_mark_addressable (*op)) 1961 1.1 mrg operand = error_mark_node; 1962 1.1 mrg } 1963 1.1 mrg else if (!allows_reg && !allows_mem) 1964 1.1 mrg { 1965 1.1 mrg /* If constraint allows neither register nor memory, 1966 1.1 mrg try harder to get a constant. */ 1967 1.1 mrg tree constop = maybe_constant_value (operand); 1968 1.1 mrg if (TREE_CONSTANT (constop)) 1969 1.1 mrg operand = constop; 1970 1.1 mrg } 1971 1.1 mrg } 1972 1.1 mrg else 1973 1.1 mrg operand = error_mark_node; 1974 1.1 mrg 1975 1.1 mrg TREE_VALUE (t) = operand; 1976 1.1 mrg } 1977 1.1 mrg } 1978 1.1 mrg 1979 1.1 mrg r = build_stmt (loc, ASM_EXPR, string, 1980 1.1 mrg output_operands, input_operands, 1981 1.1 mrg clobbers, labels); 1982 1.1 mrg ASM_VOLATILE_P (r) = volatile_p || noutputs == 0; 1983 1.1 mrg ASM_INLINE_P (r) = inline_p; 1984 1.1 mrg r = maybe_cleanup_point_expr_void (r); 1985 1.1 mrg return add_stmt (r); 1986 1.1 mrg } 1987 1.1 mrg 1988 1.1 mrg /* Finish a label with the indicated NAME. Returns the new label. */ 1989 1.1 mrg 1990 1.1 mrg tree 1991 1.1 mrg finish_label_stmt (tree name) 1992 1.1 mrg { 1993 1.1 mrg tree decl = define_label (input_location, name); 1994 1.1 mrg 1995 1.1 mrg if (decl == error_mark_node) 1996 1.1 mrg return error_mark_node; 1997 1.1 mrg 1998 1.1 mrg add_stmt (build_stmt (input_location, LABEL_EXPR, decl)); 1999 1.1 mrg 2000 1.1 mrg return decl; 2001 1.1 mrg } 2002 1.1 mrg 2003 1.1 mrg /* Finish a series of declarations for local labels. G++ allows users 2004 1.1 mrg to declare "local" labels, i.e., labels with scope. This extension 2005 1.1 mrg is useful when writing code involving statement-expressions. */ 2006 1.1 mrg 2007 1.1 mrg void 2008 1.1 mrg finish_label_decl (tree name) 2009 1.1 mrg { 2010 1.1 mrg if (!at_function_scope_p ()) 2011 1.1 mrg { 2012 1.1 mrg error ("%<__label__%> declarations are only allowed in function scopes"); 2013 1.1 mrg return; 2014 1.1 mrg } 2015 1.1 mrg 2016 1.1 mrg add_decl_expr (declare_local_label (name)); 2017 1.1 mrg } 2018 1.1 mrg 2019 1.1 mrg /* When DECL goes out of scope, make sure that CLEANUP is executed. */ 2020 1.1 mrg 2021 1.1 mrg void 2022 1.1 mrg finish_decl_cleanup (tree decl, tree cleanup) 2023 1.1 mrg { 2024 1.1 mrg push_cleanup (decl, cleanup, false); 2025 1.1 mrg } 2026 1.1 mrg 2027 1.1 mrg /* If the current scope exits with an exception, run CLEANUP. */ 2028 1.1 mrg 2029 1.1 mrg void 2030 1.1 mrg finish_eh_cleanup (tree cleanup) 2031 1.1 mrg { 2032 1.1 mrg push_cleanup (NULL, cleanup, true); 2033 1.1 mrg } 2034 1.1 mrg 2035 1.1 mrg /* The MEM_INITS is a list of mem-initializers, in reverse of the 2036 1.1 mrg order they were written by the user. Each node is as for 2037 1.1 mrg emit_mem_initializers. */ 2038 1.1 mrg 2039 1.1 mrg void 2040 1.1 mrg finish_mem_initializers (tree mem_inits) 2041 1.1 mrg { 2042 1.1 mrg /* Reorder the MEM_INITS so that they are in the order they appeared 2043 1.1 mrg in the source program. */ 2044 1.1 mrg mem_inits = nreverse (mem_inits); 2045 1.1 mrg 2046 1.1 mrg if (processing_template_decl) 2047 1.1 mrg { 2048 1.1 mrg tree mem; 2049 1.1 mrg 2050 1.1 mrg for (mem = mem_inits; mem; mem = TREE_CHAIN (mem)) 2051 1.1 mrg { 2052 1.1 mrg /* If the TREE_PURPOSE is a TYPE_PACK_EXPANSION, skip the 2053 1.1 mrg check for bare parameter packs in the TREE_VALUE, because 2054 1.1 mrg any parameter packs in the TREE_VALUE have already been 2055 1.1 mrg bound as part of the TREE_PURPOSE. See 2056 1.1 mrg make_pack_expansion for more information. */ 2057 1.1 mrg if (TREE_CODE (TREE_PURPOSE (mem)) != TYPE_PACK_EXPANSION 2058 1.1 mrg && check_for_bare_parameter_packs (TREE_VALUE (mem))) 2059 1.1 mrg TREE_VALUE (mem) = error_mark_node; 2060 1.1 mrg } 2061 1.1 mrg 2062 1.1 mrg add_stmt (build_min_nt_loc (UNKNOWN_LOCATION, 2063 1.1 mrg CTOR_INITIALIZER, mem_inits)); 2064 1.1 mrg } 2065 1.1 mrg else 2066 1.1 mrg emit_mem_initializers (mem_inits); 2067 1.1 mrg } 2068 1.1 mrg 2069 1.1 mrg /* Obfuscate EXPR if it looks like an id-expression or member access so 2070 1.1 mrg that the call to finish_decltype in do_auto_deduction will give the 2071 1.1 mrg right result. If EVEN_UNEVAL, do this even in unevaluated context. */ 2072 1.1 mrg 2073 1.1 mrg tree 2074 1.1 mrg force_paren_expr (tree expr, bool even_uneval) 2075 1.1 mrg { 2076 1.1 mrg /* This is only needed for decltype(auto) in C++14. */ 2077 1.1 mrg if (cxx_dialect < cxx14) 2078 1.1 mrg return expr; 2079 1.1 mrg 2080 1.1 mrg /* If we're in unevaluated context, we can't be deducing a 2081 1.1 mrg return/initializer type, so we don't need to mess with this. */ 2082 1.1 mrg if (cp_unevaluated_operand && !even_uneval) 2083 1.1 mrg return expr; 2084 1.1 mrg 2085 1.1 mrg if (TREE_CODE (expr) == COMPONENT_REF 2086 1.1 mrg || TREE_CODE (expr) == SCOPE_REF 2087 1.1 mrg || REFERENCE_REF_P (expr)) 2088 1.1 mrg REF_PARENTHESIZED_P (expr) = true; 2089 1.1 mrg else if (DECL_P (tree_strip_any_location_wrapper (expr))) 2090 1.1 mrg { 2091 1.1 mrg location_t loc = cp_expr_location (expr); 2092 1.1 mrg const tree_code code = processing_template_decl ? PAREN_EXPR 2093 1.1 mrg : VIEW_CONVERT_EXPR; 2094 1.1 mrg expr = build1_loc (loc, code, TREE_TYPE (expr), expr); 2095 1.1 mrg REF_PARENTHESIZED_P (expr) = true; 2096 1.1 mrg } 2097 1.1 mrg return expr; 2098 1.1 mrg } 2099 1.1 mrg 2100 1.1 mrg /* If T is an id-expression obfuscated by force_paren_expr, undo the 2101 1.1 mrg obfuscation and return the underlying id-expression. Otherwise 2102 1.1 mrg return T. */ 2103 1.1 mrg 2104 1.1 mrg tree 2105 1.1 mrg maybe_undo_parenthesized_ref (tree t) 2106 1.1 mrg { 2107 1.1 mrg if (cxx_dialect < cxx14) 2108 1.1 mrg return t; 2109 1.1 mrg 2110 1.1 mrg if ((TREE_CODE (t) == PAREN_EXPR || TREE_CODE (t) == VIEW_CONVERT_EXPR) 2111 1.1 mrg && REF_PARENTHESIZED_P (t)) 2112 1.1 mrg t = TREE_OPERAND (t, 0); 2113 1.1 mrg 2114 1.1 mrg return t; 2115 1.1 mrg } 2116 1.1 mrg 2117 1.1 mrg /* Finish a parenthesized expression EXPR. */ 2118 1.1 mrg 2119 1.1 mrg cp_expr 2120 1.1 mrg finish_parenthesized_expr (cp_expr expr) 2121 1.1 mrg { 2122 1.1 mrg if (EXPR_P (expr)) 2123 1.1 mrg /* This inhibits warnings in c_common_truthvalue_conversion. */ 2124 1.1 mrg suppress_warning (expr, OPT_Wparentheses); 2125 1.1 mrg 2126 1.1 mrg if (TREE_CODE (expr) == OFFSET_REF 2127 1.1 mrg || TREE_CODE (expr) == SCOPE_REF) 2128 1.1 mrg /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be 2129 1.1 mrg enclosed in parentheses. */ 2130 1.1 mrg PTRMEM_OK_P (expr) = 0; 2131 1.1 mrg 2132 1.1 mrg tree stripped_expr = tree_strip_any_location_wrapper (expr); 2133 1.1 mrg if (TREE_CODE (stripped_expr) == STRING_CST) 2134 1.1 mrg PAREN_STRING_LITERAL_P (stripped_expr) = 1; 2135 1.1 mrg 2136 1.1 mrg expr = cp_expr (force_paren_expr (expr), expr.get_location ()); 2137 1.1 mrg 2138 1.1 mrg return expr; 2139 1.1 mrg } 2140 1.1 mrg 2141 1.1 mrg /* Finish a reference to a non-static data member (DECL) that is not 2142 1.1 mrg preceded by `.' or `->'. */ 2143 1.1 mrg 2144 1.1 mrg tree 2145 1.1 mrg finish_non_static_data_member (tree decl, tree object, tree qualifying_scope) 2146 1.1 mrg { 2147 1.1 mrg gcc_assert (TREE_CODE (decl) == FIELD_DECL); 2148 1.1 mrg bool try_omp_private = !object && omp_private_member_map; 2149 1.1 mrg tree ret; 2150 1.1 mrg 2151 1.1 mrg if (!object) 2152 1.1 mrg { 2153 1.1 mrg tree scope = qualifying_scope; 2154 1.1 mrg if (scope == NULL_TREE) 2155 1.1 mrg { 2156 1.1 mrg scope = context_for_name_lookup (decl); 2157 1.1 mrg if (!TYPE_P (scope)) 2158 1.1 mrg { 2159 1.1 mrg /* Can happen during error recovery (c++/85014). */ 2160 1.1 mrg gcc_assert (seen_error ()); 2161 1.1 mrg return error_mark_node; 2162 1.1 mrg } 2163 1.1 mrg } 2164 1.1 mrg object = maybe_dummy_object (scope, NULL); 2165 1.1 mrg } 2166 1.1 mrg 2167 1.1 mrg object = maybe_resolve_dummy (object, true); 2168 1.1 mrg if (object == error_mark_node) 2169 1.1 mrg return error_mark_node; 2170 1.1 mrg 2171 1.1 mrg /* DR 613/850: Can use non-static data members without an associated 2172 1.1 mrg object in sizeof/decltype/alignof. */ 2173 1.1 mrg if (is_dummy_object (object) && cp_unevaluated_operand == 0 2174 1.1 mrg && (!processing_template_decl || !current_class_ref)) 2175 1.1 mrg { 2176 1.1 mrg if (current_function_decl 2177 1.1 mrg && DECL_STATIC_FUNCTION_P (current_function_decl)) 2178 1.1 mrg error ("invalid use of member %qD in static member function", decl); 2179 1.1 mrg else 2180 1.1 mrg error ("invalid use of non-static data member %qD", decl); 2181 1.1 mrg inform (DECL_SOURCE_LOCATION (decl), "declared here"); 2182 1.1 mrg 2183 1.1 mrg return error_mark_node; 2184 1.1 mrg } 2185 1.1 mrg 2186 1.1 mrg if (current_class_ptr) 2187 1.1 mrg TREE_USED (current_class_ptr) = 1; 2188 1.1 mrg if (processing_template_decl) 2189 1.1 mrg { 2190 1.1 mrg tree type = TREE_TYPE (decl); 2191 1.1 mrg 2192 1.1 mrg if (TYPE_REF_P (type)) 2193 1.1 mrg /* Quals on the object don't matter. */; 2194 1.1 mrg else if (PACK_EXPANSION_P (type)) 2195 1.1 mrg /* Don't bother trying to represent this. */ 2196 1.1 mrg type = NULL_TREE; 2197 1.1 mrg else 2198 1.1 mrg { 2199 1.1 mrg /* Set the cv qualifiers. */ 2200 1.1 mrg int quals = cp_type_quals (TREE_TYPE (object)); 2201 1.1 mrg 2202 1.1 mrg if (DECL_MUTABLE_P (decl)) 2203 1.1 mrg quals &= ~TYPE_QUAL_CONST; 2204 1.1 mrg 2205 1.1 mrg quals |= cp_type_quals (TREE_TYPE (decl)); 2206 1.1 mrg type = cp_build_qualified_type (type, quals); 2207 1.1 mrg } 2208 1.1 mrg 2209 1.1 mrg if (qualifying_scope) 2210 1.1 mrg /* Wrap this in a SCOPE_REF for now. */ 2211 1.1 mrg ret = build_qualified_name (type, qualifying_scope, decl, 2212 1.1 mrg /*template_p=*/false); 2213 1.1 mrg else 2214 1.1 mrg ret = (convert_from_reference 2215 1.1 mrg (build_min (COMPONENT_REF, type, object, decl, NULL_TREE))); 2216 1.1 mrg } 2217 1.1 mrg /* If PROCESSING_TEMPLATE_DECL is nonzero here, then 2218 1.1 mrg QUALIFYING_SCOPE is also non-null. */ 2219 1.1 mrg else 2220 1.1 mrg { 2221 1.1 mrg tree access_type = TREE_TYPE (object); 2222 1.1 mrg 2223 1.1 mrg perform_or_defer_access_check (TYPE_BINFO (access_type), decl, 2224 1.1 mrg decl, tf_warning_or_error); 2225 1.1 mrg 2226 1.1 mrg /* If the data member was named `C::M', convert `*this' to `C' 2227 1.1 mrg first. */ 2228 1.1 mrg if (qualifying_scope) 2229 1.1 mrg { 2230 1.1 mrg tree binfo = NULL_TREE; 2231 1.1 mrg object = build_scoped_ref (object, qualifying_scope, 2232 1.1 mrg &binfo); 2233 1.1 mrg } 2234 1.1 mrg 2235 1.1 mrg ret = build_class_member_access_expr (object, decl, 2236 1.1 mrg /*access_path=*/NULL_TREE, 2237 1.1 mrg /*preserve_reference=*/false, 2238 1.1 mrg tf_warning_or_error); 2239 1.1 mrg } 2240 1.1 mrg if (try_omp_private) 2241 1.1 mrg { 2242 1.1 mrg tree *v = omp_private_member_map->get (decl); 2243 1.1 mrg if (v) 2244 1.1 mrg ret = convert_from_reference (*v); 2245 1.1 mrg } 2246 1.1 mrg return ret; 2247 1.1 mrg } 2248 1.1 mrg 2249 1.1 mrg /* DECL was the declaration to which a qualified-id resolved. Issue 2250 1.1 mrg an error message if it is not accessible. If OBJECT_TYPE is 2251 1.1 mrg non-NULL, we have just seen `x->' or `x.' and OBJECT_TYPE is the 2252 1.1 mrg type of `*x', or `x', respectively. If the DECL was named as 2253 1.1 mrg `A::B' then NESTED_NAME_SPECIFIER is `A'. Return value is like 2254 1.1 mrg perform_access_checks above. */ 2255 1.1 mrg 2256 1.1 mrg bool 2257 1.1 mrg check_accessibility_of_qualified_id (tree decl, 2258 1.1 mrg tree object_type, 2259 1.1 mrg tree nested_name_specifier, 2260 1.1 mrg tsubst_flags_t complain) 2261 1.1 mrg { 2262 1.1 mrg /* If we're not checking, return immediately. */ 2263 1.1 mrg if (deferred_access_no_check) 2264 1.1 mrg return true; 2265 1.1 mrg 2266 1.1 mrg /* Determine the SCOPE of DECL. */ 2267 1.1 mrg tree scope = context_for_name_lookup (decl); 2268 1.1 mrg /* If the SCOPE is not a type, then DECL is not a member. */ 2269 1.1 mrg if (!TYPE_P (scope) 2270 1.1 mrg /* If SCOPE is dependent then we can't perform this access check now, 2271 1.1 mrg and since we'll perform this access check again after substitution 2272 1.1 mrg there's no need to explicitly defer it. */ 2273 1.1 mrg || dependent_type_p (scope)) 2274 1.1 mrg return true; 2275 1.1 mrg 2276 1.1 mrg tree qualifying_type = NULL_TREE; 2277 1.1 mrg /* Compute the scope through which DECL is being accessed. */ 2278 1.1 mrg if (object_type 2279 1.1 mrg /* OBJECT_TYPE might not be a class type; consider: 2280 1.1 mrg 2281 1.1 mrg class A { typedef int I; }; 2282 1.1 mrg I *p; 2283 1.1 mrg p->A::I::~I(); 2284 1.1 mrg 2285 1.1 mrg In this case, we will have "A::I" as the DECL, but "I" as the 2286 1.1 mrg OBJECT_TYPE. */ 2287 1.1 mrg && CLASS_TYPE_P (object_type) 2288 1.1 mrg && DERIVED_FROM_P (scope, object_type)) 2289 1.1 mrg { 2290 1.1 mrg /* If we are processing a `->' or `.' expression, use the type of the 2291 1.1 mrg left-hand side. */ 2292 1.1 mrg if (tree open = currently_open_class (object_type)) 2293 1.1 mrg qualifying_type = open; 2294 1.1 mrg else 2295 1.1 mrg qualifying_type = object_type; 2296 1.1 mrg } 2297 1.1 mrg else if (nested_name_specifier) 2298 1.1 mrg { 2299 1.1 mrg /* If the reference is to a non-static member of the 2300 1.1 mrg current class, treat it as if it were referenced through 2301 1.1 mrg `this'. */ 2302 1.1 mrg if (DECL_NONSTATIC_MEMBER_P (decl) 2303 1.1 mrg && current_class_ptr) 2304 1.1 mrg if (tree current = current_nonlambda_class_type ()) 2305 1.1 mrg { 2306 1.1 mrg if (dependent_type_p (current)) 2307 1.1 mrg /* In general we can't know whether this access goes through 2308 1.1 mrg `this' until instantiation time. Punt now, or else we might 2309 1.1 mrg create a deferred access check that's not relative to `this' 2310 1.1 mrg when it ought to be. We'll check this access again after 2311 1.1 mrg substitution, e.g. from tsubst_qualified_id. */ 2312 1.1 mrg return true; 2313 1.1 mrg 2314 1.1 mrg if (DERIVED_FROM_P (scope, current)) 2315 1.1 mrg qualifying_type = current; 2316 1.1 mrg } 2317 1.1 mrg /* Otherwise, use the type indicated by the 2318 1.1 mrg nested-name-specifier. */ 2319 1.1 mrg if (!qualifying_type) 2320 1.1 mrg qualifying_type = nested_name_specifier; 2321 1.1 mrg } 2322 1.1 mrg else 2323 1.1 mrg /* Otherwise, the name must be from the current class or one of 2324 1.1 mrg its bases. */ 2325 1.1 mrg qualifying_type = currently_open_derived_class (scope); 2326 1.1 mrg 2327 1.1 mrg if (qualifying_type 2328 1.1 mrg /* It is possible for qualifying type to be a TEMPLATE_TYPE_PARM 2329 1.1 mrg or similar in a default argument value. */ 2330 1.1 mrg && CLASS_TYPE_P (qualifying_type)) 2331 1.1 mrg return perform_or_defer_access_check (TYPE_BINFO (qualifying_type), decl, 2332 1.1 mrg decl, complain); 2333 1.1 mrg 2334 1.1 mrg return true; 2335 1.1 mrg } 2336 1.1 mrg 2337 1.1 mrg /* EXPR is the result of a qualified-id. The QUALIFYING_CLASS was the 2338 1.1 mrg class named to the left of the "::" operator. DONE is true if this 2339 1.1 mrg expression is a complete postfix-expression; it is false if this 2340 1.1 mrg expression is followed by '->', '[', '(', etc. ADDRESS_P is true 2341 1.1 mrg iff this expression is the operand of '&'. TEMPLATE_P is true iff 2342 1.1 mrg the qualified-id was of the form "A::template B". TEMPLATE_ARG_P 2343 1.1 mrg is true iff this qualified name appears as a template argument. */ 2344 1.1 mrg 2345 1.1 mrg tree 2346 1.1 mrg finish_qualified_id_expr (tree qualifying_class, 2347 1.1 mrg tree expr, 2348 1.1 mrg bool done, 2349 1.1 mrg bool address_p, 2350 1.1 mrg bool template_p, 2351 1.1 mrg bool template_arg_p, 2352 1.1 mrg tsubst_flags_t complain) 2353 1.1 mrg { 2354 1.1 mrg gcc_assert (TYPE_P (qualifying_class)); 2355 1.1 mrg 2356 1.1 mrg if (error_operand_p (expr)) 2357 1.1 mrg return error_mark_node; 2358 1.1 mrg 2359 1.1 mrg if (DECL_P (expr) 2360 1.1 mrg /* Functions are marked after overload resolution; avoid redundant 2361 1.1 mrg warnings. */ 2362 1.1 mrg && TREE_CODE (expr) != FUNCTION_DECL 2363 1.1 mrg && !mark_used (expr, complain)) 2364 1.1 mrg return error_mark_node; 2365 1.1 mrg 2366 1.1 mrg if (template_p) 2367 1.1 mrg { 2368 1.1 mrg if (TREE_CODE (expr) == UNBOUND_CLASS_TEMPLATE) 2369 1.1 mrg { 2370 1.1 mrg /* cp_parser_lookup_name thought we were looking for a type, 2371 1.1 mrg but we're actually looking for a declaration. */ 2372 1.1 mrg qualifying_class = TYPE_CONTEXT (expr); 2373 1.1 mrg expr = TYPE_IDENTIFIER (expr); 2374 1.1 mrg } 2375 1.1 mrg else 2376 1.1 mrg check_template_keyword (expr); 2377 1.1 mrg } 2378 1.1 mrg 2379 1.1 mrg /* If EXPR occurs as the operand of '&', use special handling that 2380 1.1 mrg permits a pointer-to-member. */ 2381 1.1 mrg if (address_p && done 2382 1.1 mrg && TREE_CODE (qualifying_class) != ENUMERAL_TYPE) 2383 1.1 mrg { 2384 1.1 mrg if (TREE_CODE (expr) == SCOPE_REF) 2385 1.1 mrg expr = TREE_OPERAND (expr, 1); 2386 1.1 mrg expr = build_offset_ref (qualifying_class, expr, 2387 1.1 mrg /*address_p=*/true, complain); 2388 1.1 mrg return expr; 2389 1.1 mrg } 2390 1.1 mrg 2391 1.1 mrg /* No need to check access within an enum. */ 2392 1.1 mrg if (TREE_CODE (qualifying_class) == ENUMERAL_TYPE 2393 1.1 mrg && TREE_CODE (expr) != IDENTIFIER_NODE) 2394 1.1 mrg return expr; 2395 1.1 mrg 2396 1.1 mrg /* Within the scope of a class, turn references to non-static 2397 1.1 mrg members into expression of the form "this->...". */ 2398 1.1 mrg if (template_arg_p) 2399 1.1 mrg /* But, within a template argument, we do not want make the 2400 1.1 mrg transformation, as there is no "this" pointer. */ 2401 1.1 mrg ; 2402 1.1 mrg else if (TREE_CODE (expr) == FIELD_DECL) 2403 1.1 mrg { 2404 1.1 mrg push_deferring_access_checks (dk_no_check); 2405 1.1 mrg expr = finish_non_static_data_member (expr, NULL_TREE, 2406 1.1 mrg qualifying_class); 2407 1.1 mrg pop_deferring_access_checks (); 2408 1.1 mrg } 2409 1.1 mrg else if (BASELINK_P (expr)) 2410 1.1 mrg { 2411 1.1 mrg /* See if any of the functions are non-static members. */ 2412 1.1 mrg /* If so, the expression may be relative to 'this'. */ 2413 1.1 mrg if (!shared_member_p (expr) 2414 1.1 mrg && current_class_ptr 2415 1.1 mrg && DERIVED_FROM_P (qualifying_class, 2416 1.1 mrg current_nonlambda_class_type ())) 2417 1.1 mrg expr = (build_class_member_access_expr 2418 1.1 mrg (maybe_dummy_object (qualifying_class, NULL), 2419 1.1 mrg expr, 2420 1.1 mrg BASELINK_ACCESS_BINFO (expr), 2421 1.1 mrg /*preserve_reference=*/false, 2422 1.1 mrg complain)); 2423 1.1 mrg else if (done) 2424 1.1 mrg /* The expression is a qualified name whose address is not 2425 1.1 mrg being taken. */ 2426 1.1 mrg expr = build_offset_ref (qualifying_class, expr, /*address_p=*/false, 2427 1.1 mrg complain); 2428 1.1 mrg } 2429 1.1 mrg else if (!template_p 2430 1.1 mrg && TREE_CODE (expr) == TEMPLATE_DECL 2431 1.1 mrg && !DECL_FUNCTION_TEMPLATE_P (expr)) 2432 1.1 mrg { 2433 1.1 mrg if (complain & tf_error) 2434 1.1 mrg error ("%qE missing template arguments", expr); 2435 1.1 mrg return error_mark_node; 2436 1.1 mrg } 2437 1.1 mrg else 2438 1.1 mrg { 2439 1.1 mrg /* In a template, return a SCOPE_REF for most qualified-ids 2440 1.1 mrg so that we can check access at instantiation time. But if 2441 1.1 mrg we're looking at a member of the current instantiation, we 2442 1.1 mrg know we have access and building up the SCOPE_REF confuses 2443 1.1 mrg non-type template argument handling. */ 2444 1.1 mrg if (processing_template_decl 2445 1.1 mrg && (!currently_open_class (qualifying_class) 2446 1.1 mrg || TREE_CODE (expr) == IDENTIFIER_NODE 2447 1.1 mrg || TREE_CODE (expr) == TEMPLATE_ID_EXPR 2448 1.1 mrg || TREE_CODE (expr) == BIT_NOT_EXPR)) 2449 1.1 mrg expr = build_qualified_name (TREE_TYPE (expr), 2450 1.1 mrg qualifying_class, expr, 2451 1.1 mrg template_p); 2452 1.1 mrg else if (tree wrap = maybe_get_tls_wrapper_call (expr)) 2453 1.1 mrg expr = wrap; 2454 1.1 mrg 2455 1.1 mrg expr = convert_from_reference (expr); 2456 1.1 mrg } 2457 1.1 mrg 2458 1.1 mrg return expr; 2459 1.1 mrg } 2460 1.1 mrg 2461 1.1 mrg /* Begin a statement-expression. The value returned must be passed to 2462 1.1 mrg finish_stmt_expr. */ 2463 1.1 mrg 2464 1.1 mrg tree 2465 1.1 mrg begin_stmt_expr (void) 2466 1.1 mrg { 2467 1.1 mrg return push_stmt_list (); 2468 1.1 mrg } 2469 1.1 mrg 2470 1.1 mrg /* Process the final expression of a statement expression. EXPR can be 2471 1.1 mrg NULL, if the final expression is empty. Return a STATEMENT_LIST 2472 1.1 mrg containing all the statements in the statement-expression, or 2473 1.1 mrg ERROR_MARK_NODE if there was an error. */ 2474 1.1 mrg 2475 1.1 mrg tree 2476 1.1 mrg finish_stmt_expr_expr (tree expr, tree stmt_expr) 2477 1.1 mrg { 2478 1.1 mrg if (error_operand_p (expr)) 2479 1.1 mrg { 2480 1.1 mrg /* The type of the statement-expression is the type of the last 2481 1.1 mrg expression. */ 2482 1.1 mrg TREE_TYPE (stmt_expr) = error_mark_node; 2483 1.1 mrg return error_mark_node; 2484 1.1 mrg } 2485 1.1 mrg 2486 1.1 mrg /* If the last statement does not have "void" type, then the value 2487 1.1 mrg of the last statement is the value of the entire expression. */ 2488 1.1 mrg if (expr) 2489 1.1 mrg { 2490 1.1 mrg tree type = TREE_TYPE (expr); 2491 1.1 mrg 2492 1.1 mrg if (type && type_unknown_p (type)) 2493 1.1 mrg { 2494 1.1 mrg error ("a statement expression is an insufficient context" 2495 1.1 mrg " for overload resolution"); 2496 1.1 mrg TREE_TYPE (stmt_expr) = error_mark_node; 2497 1.1 mrg return error_mark_node; 2498 1.1 mrg } 2499 1.1 mrg else if (processing_template_decl) 2500 1.1 mrg { 2501 1.1 mrg expr = build_stmt (input_location, EXPR_STMT, expr); 2502 1.1 mrg expr = add_stmt (expr); 2503 1.1 mrg /* Mark the last statement so that we can recognize it as such at 2504 1.1 mrg template-instantiation time. */ 2505 1.1 mrg EXPR_STMT_STMT_EXPR_RESULT (expr) = 1; 2506 1.1 mrg } 2507 1.1 mrg else if (VOID_TYPE_P (type)) 2508 1.1 mrg { 2509 1.1 mrg /* Just treat this like an ordinary statement. */ 2510 1.1 mrg expr = finish_expr_stmt (expr); 2511 1.1 mrg } 2512 1.1 mrg else 2513 1.1 mrg { 2514 1.1 mrg /* It actually has a value we need to deal with. First, force it 2515 1.1 mrg to be an rvalue so that we won't need to build up a copy 2516 1.1 mrg constructor call later when we try to assign it to something. */ 2517 1.1 mrg expr = force_rvalue (expr, tf_warning_or_error); 2518 1.1 mrg if (error_operand_p (expr)) 2519 1.1 mrg return error_mark_node; 2520 1.1 mrg 2521 1.1 mrg /* Update for array-to-pointer decay. */ 2522 1.1 mrg type = TREE_TYPE (expr); 2523 1.1 mrg 2524 1.1 mrg /* Wrap it in a CLEANUP_POINT_EXPR and add it to the list like a 2525 1.1 mrg normal statement, but don't convert to void or actually add 2526 1.1 mrg the EXPR_STMT. */ 2527 1.1 mrg if (TREE_CODE (expr) != CLEANUP_POINT_EXPR) 2528 1.1 mrg expr = maybe_cleanup_point_expr (expr); 2529 1.1 mrg add_stmt (expr); 2530 1.1 mrg } 2531 1.1 mrg 2532 1.1 mrg /* The type of the statement-expression is the type of the last 2533 1.1 mrg expression. */ 2534 1.1 mrg TREE_TYPE (stmt_expr) = type; 2535 1.1 mrg } 2536 1.1 mrg 2537 1.1 mrg return stmt_expr; 2538 1.1 mrg } 2539 1.1 mrg 2540 1.1 mrg /* Finish a statement-expression. EXPR should be the value returned 2541 1.1 mrg by the previous begin_stmt_expr. Returns an expression 2542 1.1 mrg representing the statement-expression. */ 2543 1.1 mrg 2544 1.1 mrg tree 2545 1.1 mrg finish_stmt_expr (tree stmt_expr, bool has_no_scope) 2546 1.1 mrg { 2547 1.1 mrg tree type; 2548 1.1 mrg tree result; 2549 1.1 mrg 2550 1.1 mrg if (error_operand_p (stmt_expr)) 2551 1.1 mrg { 2552 1.1 mrg pop_stmt_list (stmt_expr); 2553 1.1 mrg return error_mark_node; 2554 1.1 mrg } 2555 1.1 mrg 2556 1.1 mrg gcc_assert (TREE_CODE (stmt_expr) == STATEMENT_LIST); 2557 1.1 mrg 2558 1.1 mrg type = TREE_TYPE (stmt_expr); 2559 1.1 mrg result = pop_stmt_list (stmt_expr); 2560 1.1 mrg TREE_TYPE (result) = type; 2561 1.1 mrg 2562 1.1 mrg if (processing_template_decl) 2563 1.1 mrg { 2564 1.1 mrg result = build_min (STMT_EXPR, type, result); 2565 1.1 mrg TREE_SIDE_EFFECTS (result) = 1; 2566 1.1 mrg STMT_EXPR_NO_SCOPE (result) = has_no_scope; 2567 1.1 mrg } 2568 1.1 mrg else if (CLASS_TYPE_P (type)) 2569 1.1 mrg { 2570 1.1 mrg /* Wrap the statement-expression in a TARGET_EXPR so that the 2571 1.1 mrg temporary object created by the final expression is destroyed at 2572 1.1 mrg the end of the full-expression containing the 2573 1.1 mrg statement-expression. */ 2574 1.1 mrg result = force_target_expr (type, result, tf_warning_or_error); 2575 1.1 mrg } 2576 1.1 mrg 2577 1.1 mrg return result; 2578 1.1 mrg } 2579 1.1 mrg 2580 1.1 mrg /* Returns the expression which provides the value of STMT_EXPR. */ 2581 1.1 mrg 2582 1.1 mrg tree 2583 1.1 mrg stmt_expr_value_expr (tree stmt_expr) 2584 1.1 mrg { 2585 1.1 mrg tree t = STMT_EXPR_STMT (stmt_expr); 2586 1.1 mrg 2587 1.1 mrg if (TREE_CODE (t) == BIND_EXPR) 2588 1.1 mrg t = BIND_EXPR_BODY (t); 2589 1.1 mrg 2590 1.1 mrg if (TREE_CODE (t) == STATEMENT_LIST && STATEMENT_LIST_TAIL (t)) 2591 1.1 mrg t = STATEMENT_LIST_TAIL (t)->stmt; 2592 1.1 mrg 2593 1.1 mrg if (TREE_CODE (t) == EXPR_STMT) 2594 1.1 mrg t = EXPR_STMT_EXPR (t); 2595 1.1 mrg 2596 1.1 mrg return t; 2597 1.1 mrg } 2598 1.1 mrg 2599 1.1 mrg /* Return TRUE iff EXPR_STMT is an empty list of 2600 1.1 mrg expression statements. */ 2601 1.1 mrg 2602 1.1 mrg bool 2603 1.1 mrg empty_expr_stmt_p (tree expr_stmt) 2604 1.1 mrg { 2605 1.1 mrg tree body = NULL_TREE; 2606 1.1 mrg 2607 1.1 mrg if (expr_stmt == void_node) 2608 1.1 mrg return true; 2609 1.1 mrg 2610 1.1 mrg if (expr_stmt) 2611 1.1 mrg { 2612 1.1 mrg if (TREE_CODE (expr_stmt) == EXPR_STMT) 2613 1.1 mrg body = EXPR_STMT_EXPR (expr_stmt); 2614 1.1 mrg else if (TREE_CODE (expr_stmt) == STATEMENT_LIST) 2615 1.1 mrg body = expr_stmt; 2616 1.1 mrg } 2617 1.1 mrg 2618 1.1 mrg if (body) 2619 1.1 mrg { 2620 1.1 mrg if (TREE_CODE (body) == STATEMENT_LIST) 2621 1.1 mrg return tsi_end_p (tsi_start (body)); 2622 1.1 mrg else 2623 1.1 mrg return empty_expr_stmt_p (body); 2624 1.1 mrg } 2625 1.1 mrg return false; 2626 1.1 mrg } 2627 1.1 mrg 2628 1.1 mrg /* Perform Koenig lookup. FN_EXPR is the postfix-expression representing 2629 1.1 mrg the function (or functions) to call; ARGS are the arguments to the 2630 1.1 mrg call. Returns the functions to be considered by overload resolution. */ 2631 1.1 mrg 2632 1.1 mrg cp_expr 2633 1.1 mrg perform_koenig_lookup (cp_expr fn_expr, vec<tree, va_gc> *args, 2634 1.1 mrg tsubst_flags_t complain) 2635 1.1 mrg { 2636 1.1 mrg tree identifier = NULL_TREE; 2637 1.1 mrg tree functions = NULL_TREE; 2638 1.1 mrg tree tmpl_args = NULL_TREE; 2639 1.1 mrg bool template_id = false; 2640 1.1 mrg location_t loc = fn_expr.get_location (); 2641 1.1 mrg tree fn = fn_expr.get_value (); 2642 1.1 mrg 2643 1.1 mrg STRIP_ANY_LOCATION_WRAPPER (fn); 2644 1.1 mrg 2645 1.1 mrg if (TREE_CODE (fn) == TEMPLATE_ID_EXPR) 2646 1.1 mrg { 2647 1.1 mrg /* Use a separate flag to handle null args. */ 2648 1.1 mrg template_id = true; 2649 1.1 mrg tmpl_args = TREE_OPERAND (fn, 1); 2650 1.1 mrg fn = TREE_OPERAND (fn, 0); 2651 1.1 mrg } 2652 1.1 mrg 2653 1.1 mrg /* Find the name of the overloaded function. */ 2654 1.1 mrg if (identifier_p (fn)) 2655 1.1 mrg identifier = fn; 2656 1.1 mrg else 2657 1.1 mrg { 2658 1.1 mrg functions = fn; 2659 1.1 mrg identifier = OVL_NAME (functions); 2660 1.1 mrg } 2661 1.1 mrg 2662 1.1 mrg /* A call to a namespace-scope function using an unqualified name. 2663 1.1 mrg 2664 1.1 mrg Do Koenig lookup -- unless any of the arguments are 2665 1.1 mrg type-dependent. */ 2666 1.1 mrg if (!any_type_dependent_arguments_p (args) 2667 1.1 mrg && !any_dependent_template_arguments_p (tmpl_args)) 2668 1.1 mrg { 2669 1.1 mrg fn = lookup_arg_dependent (identifier, functions, args); 2670 1.1 mrg if (!fn) 2671 1.1 mrg { 2672 1.1 mrg /* The unqualified name could not be resolved. */ 2673 1.1 mrg if (complain & tf_error) 2674 1.1 mrg fn = unqualified_fn_lookup_error (cp_expr (identifier, loc)); 2675 1.1 mrg else 2676 1.1 mrg fn = identifier; 2677 1.1 mrg } 2678 1.1 mrg } 2679 1.1 mrg 2680 1.1 mrg if (fn && template_id && fn != error_mark_node) 2681 1.1 mrg fn = build2 (TEMPLATE_ID_EXPR, unknown_type_node, fn, tmpl_args); 2682 1.1 mrg 2683 1.1 mrg return cp_expr (fn, loc); 2684 1.1 mrg } 2685 1.1 mrg 2686 1.1 mrg /* Generate an expression for `FN (ARGS)'. This may change the 2687 1.1 mrg contents of ARGS. 2688 1.1 mrg 2689 1.1 mrg If DISALLOW_VIRTUAL is true, the call to FN will be not generated 2690 1.1 mrg as a virtual call, even if FN is virtual. (This flag is set when 2691 1.1 mrg encountering an expression where the function name is explicitly 2692 1.1 mrg qualified. For example a call to `X::f' never generates a virtual 2693 1.1 mrg call.) 2694 1.1 mrg 2695 1.1 mrg Returns code for the call. */ 2696 1.1 mrg 2697 1.1 mrg tree 2698 1.1 mrg finish_call_expr (tree fn, vec<tree, va_gc> **args, bool disallow_virtual, 2699 1.1 mrg bool koenig_p, tsubst_flags_t complain) 2700 1.1 mrg { 2701 1.1 mrg tree result; 2702 1.1 mrg tree orig_fn; 2703 1.1 mrg vec<tree, va_gc> *orig_args = *args; 2704 1.1 mrg 2705 1.1 mrg if (fn == error_mark_node) 2706 1.1 mrg return error_mark_node; 2707 1.1 mrg 2708 1.1 mrg gcc_assert (!TYPE_P (fn)); 2709 1.1 mrg 2710 1.1 mrg /* If FN may be a FUNCTION_DECL obfuscated by force_paren_expr, undo 2711 1.1 mrg it so that we can tell this is a call to a known function. */ 2712 1.1 mrg fn = maybe_undo_parenthesized_ref (fn); 2713 1.1 mrg 2714 1.1 mrg STRIP_ANY_LOCATION_WRAPPER (fn); 2715 1.1 mrg 2716 1.1 mrg orig_fn = fn; 2717 1.1 mrg 2718 1.1 mrg if (processing_template_decl) 2719 1.1 mrg { 2720 1.1 mrg /* If FN is a local extern declaration (or set thereof) in a template, 2721 1.1 mrg look it up again at instantiation time. */ 2722 1.1 mrg if (is_overloaded_fn (fn)) 2723 1.1 mrg { 2724 1.1 mrg tree ifn = get_first_fn (fn); 2725 1.1 mrg if (TREE_CODE (ifn) == FUNCTION_DECL 2726 1.1 mrg && dependent_local_decl_p (ifn)) 2727 1.1 mrg orig_fn = DECL_NAME (ifn); 2728 1.1 mrg } 2729 1.1 mrg 2730 1.1 mrg /* If the call expression is dependent, build a CALL_EXPR node 2731 1.1 mrg with no type; type_dependent_expression_p recognizes 2732 1.1 mrg expressions with no type as being dependent. */ 2733 1.1 mrg if (type_dependent_expression_p (fn) 2734 1.1 mrg || any_type_dependent_arguments_p (*args)) 2735 1.1 mrg { 2736 1.1 mrg result = build_min_nt_call_vec (orig_fn, *args); 2737 1.1 mrg SET_EXPR_LOCATION (result, cp_expr_loc_or_input_loc (fn)); 2738 1.1 mrg KOENIG_LOOKUP_P (result) = koenig_p; 2739 1.1 mrg if (is_overloaded_fn (fn)) 2740 1.1 mrg fn = get_fns (fn); 2741 1.1 mrg 2742 1.1 mrg if (cfun) 2743 1.1 mrg { 2744 1.1 mrg bool abnormal = true; 2745 1.1 mrg for (lkp_iterator iter (fn); abnormal && iter; ++iter) 2746 1.1 mrg { 2747 1.1 mrg tree fndecl = STRIP_TEMPLATE (*iter); 2748 1.1 mrg if (TREE_CODE (fndecl) != FUNCTION_DECL 2749 1.1 mrg || !TREE_THIS_VOLATILE (fndecl)) 2750 1.1 mrg abnormal = false; 2751 1.1 mrg } 2752 1.1 mrg /* FIXME: Stop warning about falling off end of non-void 2753 1.1 mrg function. But this is wrong. Even if we only see 2754 1.1 mrg no-return fns at this point, we could select a 2755 1.1 mrg future-defined return fn during instantiation. Or 2756 1.1 mrg vice-versa. */ 2757 1.1 mrg if (abnormal) 2758 1.1 mrg current_function_returns_abnormally = 1; 2759 1.1 mrg } 2760 1.1 mrg return result; 2761 1.1 mrg } 2762 1.1 mrg orig_args = make_tree_vector_copy (*args); 2763 1.1 mrg if (!BASELINK_P (fn) 2764 1.1 mrg && TREE_CODE (fn) != PSEUDO_DTOR_EXPR 2765 1.1 mrg && TREE_TYPE (fn) != unknown_type_node) 2766 1.1 mrg fn = build_non_dependent_expr (fn); 2767 1.1 mrg make_args_non_dependent (*args); 2768 1.1 mrg } 2769 1.1 mrg 2770 1.1 mrg if (TREE_CODE (fn) == COMPONENT_REF) 2771 1.1 mrg { 2772 1.1 mrg tree member = TREE_OPERAND (fn, 1); 2773 1.1 mrg if (BASELINK_P (member)) 2774 1.1 mrg { 2775 1.1 mrg tree object = TREE_OPERAND (fn, 0); 2776 1.1 mrg return build_new_method_call (object, member, 2777 1.1 mrg args, NULL_TREE, 2778 1.1 mrg (disallow_virtual 2779 1.1 mrg ? LOOKUP_NORMAL | LOOKUP_NONVIRTUAL 2780 1.1 mrg : LOOKUP_NORMAL), 2781 1.1 mrg /*fn_p=*/NULL, 2782 1.1 mrg complain); 2783 1.1 mrg } 2784 1.1 mrg } 2785 1.1 mrg 2786 1.1 mrg /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'. */ 2787 1.1 mrg if (TREE_CODE (fn) == ADDR_EXPR 2788 1.1 mrg && TREE_CODE (TREE_OPERAND (fn, 0)) == OVERLOAD) 2789 1.1 mrg fn = TREE_OPERAND (fn, 0); 2790 1.1 mrg 2791 1.1 mrg if (is_overloaded_fn (fn)) 2792 1.1 mrg fn = baselink_for_fns (fn); 2793 1.1 mrg 2794 1.1 mrg result = NULL_TREE; 2795 1.1 mrg if (BASELINK_P (fn)) 2796 1.1 mrg { 2797 1.1 mrg tree object; 2798 1.1 mrg 2799 1.1 mrg /* A call to a member function. From [over.call.func]: 2800 1.1 mrg 2801 1.1 mrg If the keyword this is in scope and refers to the class of 2802 1.1 mrg that member function, or a derived class thereof, then the 2803 1.1 mrg function call is transformed into a qualified function call 2804 1.1 mrg using (*this) as the postfix-expression to the left of the 2805 1.1 mrg . operator.... [Otherwise] a contrived object of type T 2806 1.1 mrg becomes the implied object argument. 2807 1.1 mrg 2808 1.1 mrg In this situation: 2809 1.1 mrg 2810 1.1 mrg struct A { void f(); }; 2811 1.1 mrg struct B : public A {}; 2812 1.1 mrg struct C : public A { void g() { B::f(); }}; 2813 1.1 mrg 2814 1.1 mrg "the class of that member function" refers to `A'. But 11.2 2815 1.1 mrg [class.access.base] says that we need to convert 'this' to B* as 2816 1.1 mrg part of the access, so we pass 'B' to maybe_dummy_object. */ 2817 1.1 mrg 2818 1.1 mrg if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (get_first_fn (fn))) 2819 1.1 mrg { 2820 1.1 mrg /* A constructor call always uses a dummy object. (This constructor 2821 1.1 mrg call which has the form A::A () is actually invalid and we are 2822 1.1 mrg going to reject it later in build_new_method_call.) */ 2823 1.1 mrg object = build_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn))); 2824 1.1 mrg } 2825 1.1 mrg else 2826 1.1 mrg object = maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)), 2827 1.1 mrg NULL); 2828 1.1 mrg 2829 1.1 mrg result = build_new_method_call (object, fn, args, NULL_TREE, 2830 1.1 mrg (disallow_virtual 2831 1.1 mrg ? LOOKUP_NORMAL|LOOKUP_NONVIRTUAL 2832 1.1 mrg : LOOKUP_NORMAL), 2833 1.1 mrg /*fn_p=*/NULL, 2834 1.1 mrg complain); 2835 1.1 mrg } 2836 1.1 mrg else if (concept_check_p (fn)) 2837 1.1 mrg { 2838 1.1 mrg /* FN is actually a template-id referring to a concept definition. */ 2839 1.1 mrg tree id = unpack_concept_check (fn); 2840 1.1 mrg tree tmpl = TREE_OPERAND (id, 0); 2841 1.1 mrg tree args = TREE_OPERAND (id, 1); 2842 1.1 mrg 2843 1.1 mrg if (!function_concept_p (tmpl)) 2844 1.1 mrg { 2845 1.1 mrg error_at (EXPR_LOC_OR_LOC (fn, input_location), 2846 1.1 mrg "cannot call a concept as a function"); 2847 1.1 mrg return error_mark_node; 2848 1.1 mrg } 2849 1.1 mrg 2850 1.1 mrg /* Ensure the result is wrapped as a call expression. */ 2851 1.1 mrg result = build_concept_check (tmpl, args, tf_warning_or_error); 2852 1.1 mrg } 2853 1.1 mrg else if (is_overloaded_fn (fn)) 2854 1.1 mrg { 2855 1.1 mrg /* If the function is an overloaded builtin, resolve it. */ 2856 1.1 mrg if (TREE_CODE (fn) == FUNCTION_DECL 2857 1.1 mrg && (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL 2858 1.1 mrg || DECL_BUILT_IN_CLASS (fn) == BUILT_IN_MD)) 2859 1.1 mrg result = resolve_overloaded_builtin (input_location, fn, *args); 2860 1.1 mrg 2861 1.1 mrg if (!result) 2862 1.1 mrg { 2863 1.1 mrg if (warn_sizeof_pointer_memaccess 2864 1.1 mrg && (complain & tf_warning) 2865 1.1 mrg && !vec_safe_is_empty (*args) 2866 1.1 mrg && !processing_template_decl) 2867 1.1 mrg { 2868 1.1 mrg location_t sizeof_arg_loc[3]; 2869 1.1 mrg tree sizeof_arg[3]; 2870 1.1 mrg unsigned int i; 2871 1.1 mrg for (i = 0; i < 3; i++) 2872 1.1 mrg { 2873 1.1 mrg tree t; 2874 1.1 mrg 2875 1.1 mrg sizeof_arg_loc[i] = UNKNOWN_LOCATION; 2876 1.1 mrg sizeof_arg[i] = NULL_TREE; 2877 1.1 mrg if (i >= (*args)->length ()) 2878 1.1 mrg continue; 2879 1.1 mrg t = (**args)[i]; 2880 1.1 mrg if (TREE_CODE (t) != SIZEOF_EXPR) 2881 1.1 mrg continue; 2882 1.1 mrg if (SIZEOF_EXPR_TYPE_P (t)) 2883 1.1 mrg sizeof_arg[i] = TREE_TYPE (TREE_OPERAND (t, 0)); 2884 1.1 mrg else 2885 1.1 mrg sizeof_arg[i] = TREE_OPERAND (t, 0); 2886 1.1 mrg sizeof_arg_loc[i] = EXPR_LOCATION (t); 2887 1.1 mrg } 2888 1.1 mrg sizeof_pointer_memaccess_warning 2889 1.1 mrg (sizeof_arg_loc, fn, *args, 2890 1.1 mrg sizeof_arg, same_type_ignoring_top_level_qualifiers_p); 2891 1.1 mrg } 2892 1.1 mrg 2893 1.1 mrg if ((complain & tf_warning) 2894 1.1 mrg && TREE_CODE (fn) == FUNCTION_DECL 2895 1.1 mrg && fndecl_built_in_p (fn, BUILT_IN_MEMSET) 2896 1.1 mrg && vec_safe_length (*args) == 3 2897 1.1 mrg && !any_type_dependent_arguments_p (*args)) 2898 1.1 mrg { 2899 1.1 mrg tree arg0 = (*orig_args)[0]; 2900 1.1 mrg tree arg1 = (*orig_args)[1]; 2901 1.1 mrg tree arg2 = (*orig_args)[2]; 2902 1.1 mrg int literal_mask = ((literal_integer_zerop (arg1) << 1) 2903 1.1 mrg | (literal_integer_zerop (arg2) << 2)); 2904 1.1 mrg warn_for_memset (input_location, arg0, arg2, literal_mask); 2905 1.1 mrg } 2906 1.1 mrg 2907 1.1 mrg /* A call to a namespace-scope function. */ 2908 1.1 mrg result = build_new_function_call (fn, args, complain); 2909 1.1 mrg } 2910 1.1 mrg } 2911 1.1 mrg else if (TREE_CODE (fn) == PSEUDO_DTOR_EXPR) 2912 1.1 mrg { 2913 1.1 mrg if (!vec_safe_is_empty (*args)) 2914 1.1 mrg error ("arguments to destructor are not allowed"); 2915 1.1 mrg /* C++20/DR: If the postfix-expression names a pseudo-destructor (in 2916 1.1 mrg which case the postfix-expression is a possibly-parenthesized class 2917 1.1 mrg member access), the function call destroys the object of scalar type 2918 1.1 mrg denoted by the object expression of the class member access. */ 2919 1.1 mrg tree ob = TREE_OPERAND (fn, 0); 2920 1.1 mrg if (obvalue_p (ob)) 2921 1.1 mrg result = build_trivial_dtor_call (ob, true); 2922 1.1 mrg else 2923 1.1 mrg /* No location to clobber. */ 2924 1.1 mrg result = convert_to_void (ob, ICV_STATEMENT, complain); 2925 1.1 mrg } 2926 1.1 mrg else if (CLASS_TYPE_P (TREE_TYPE (fn))) 2927 1.1 mrg /* If the "function" is really an object of class type, it might 2928 1.1 mrg have an overloaded `operator ()'. */ 2929 1.1 mrg result = build_op_call (fn, args, complain); 2930 1.1 mrg 2931 1.1 mrg if (!result) 2932 1.1 mrg /* A call where the function is unknown. */ 2933 1.1 mrg result = cp_build_function_call_vec (fn, args, complain); 2934 1.1 mrg 2935 1.1 mrg if (processing_template_decl && result != error_mark_node) 2936 1.1 mrg { 2937 1.1 mrg if (INDIRECT_REF_P (result)) 2938 1.1 mrg result = TREE_OPERAND (result, 0); 2939 1.1 mrg 2940 1.1 mrg /* Prune all but the selected function from the original overload 2941 1.1 mrg set so that we can avoid some duplicate work at instantiation time. */ 2942 1.1 mrg if (TREE_CODE (result) == CALL_EXPR 2943 1.1 mrg && really_overloaded_fn (orig_fn)) 2944 1.1 mrg { 2945 1.1 mrg tree sel_fn = CALL_EXPR_FN (result); 2946 1.1 mrg if (TREE_CODE (sel_fn) == COMPONENT_REF) 2947 1.1 mrg { 2948 1.1 mrg /* The non-dependent result of build_new_method_call. */ 2949 1.1 mrg sel_fn = TREE_OPERAND (sel_fn, 1); 2950 1.1 mrg gcc_assert (BASELINK_P (sel_fn)); 2951 1.1 mrg } 2952 1.1 mrg else if (TREE_CODE (sel_fn) == ADDR_EXPR) 2953 1.1 mrg /* Our original callee wasn't wrapped in an ADDR_EXPR, 2954 1.1 mrg so strip this ADDR_EXPR added by build_over_call. */ 2955 1.1 mrg sel_fn = TREE_OPERAND (sel_fn, 0); 2956 1.1 mrg orig_fn = sel_fn; 2957 1.1 mrg } 2958 1.1 mrg 2959 1.1 mrg result = build_call_vec (TREE_TYPE (result), orig_fn, orig_args); 2960 1.1 mrg SET_EXPR_LOCATION (result, input_location); 2961 1.1 mrg KOENIG_LOOKUP_P (result) = koenig_p; 2962 1.1 mrg release_tree_vector (orig_args); 2963 1.1 mrg result = convert_from_reference (result); 2964 1.1 mrg } 2965 1.1 mrg 2966 1.1 mrg return result; 2967 1.1 mrg } 2968 1.1 mrg 2969 1.1 mrg /* Finish a call to a postfix increment or decrement or EXPR. (Which 2970 1.1 mrg is indicated by CODE, which should be POSTINCREMENT_EXPR or 2971 1.1 mrg POSTDECREMENT_EXPR.) */ 2972 1.1 mrg 2973 1.1 mrg cp_expr 2974 1.1 mrg finish_increment_expr (cp_expr expr, enum tree_code code) 2975 1.1 mrg { 2976 1.1 mrg /* input_location holds the location of the trailing operator token. 2977 1.1 mrg Build a location of the form: 2978 1.1 mrg expr++ 2979 1.1 mrg ~~~~^~ 2980 1.1 mrg with the caret at the operator token, ranging from the start 2981 1.1 mrg of EXPR to the end of the operator token. */ 2982 1.1 mrg location_t combined_loc = make_location (input_location, 2983 1.1 mrg expr.get_start (), 2984 1.1 mrg get_finish (input_location)); 2985 1.1 mrg cp_expr result = build_x_unary_op (combined_loc, code, expr, 2986 1.1 mrg NULL_TREE, tf_warning_or_error); 2987 1.1 mrg /* TODO: build_x_unary_op doesn't honor the location, so set it here. */ 2988 1.1 mrg result.set_location (combined_loc); 2989 1.1 mrg return result; 2990 1.1 mrg } 2991 1.1 mrg 2992 1.1 mrg /* Finish a use of `this'. Returns an expression for `this'. */ 2993 1.1 mrg 2994 1.1 mrg tree 2995 1.1 mrg finish_this_expr (void) 2996 1.1 mrg { 2997 1.1 mrg tree result = NULL_TREE; 2998 1.1 mrg 2999 1.1 mrg if (current_class_ptr) 3000 1.1 mrg { 3001 1.1 mrg tree type = TREE_TYPE (current_class_ref); 3002 1.1 mrg 3003 1.1 mrg /* In a lambda expression, 'this' refers to the captured 'this'. */ 3004 1.1 mrg if (LAMBDA_TYPE_P (type)) 3005 1.1 mrg result = lambda_expr_this_capture (CLASSTYPE_LAMBDA_EXPR (type), true); 3006 1.1 mrg else 3007 1.1 mrg result = current_class_ptr; 3008 1.1 mrg } 3009 1.1 mrg 3010 1.1 mrg if (result) 3011 1.1 mrg /* The keyword 'this' is a prvalue expression. */ 3012 1.1 mrg return rvalue (result); 3013 1.1 mrg 3014 1.1 mrg tree fn = current_nonlambda_function (); 3015 1.1 mrg if (fn && DECL_STATIC_FUNCTION_P (fn)) 3016 1.1 mrg error ("%<this%> is unavailable for static member functions"); 3017 1.1 mrg else if (fn) 3018 1.1 mrg error ("invalid use of %<this%> in non-member function"); 3019 1.1 mrg else 3020 1.1 mrg error ("invalid use of %<this%> at top level"); 3021 1.1 mrg return error_mark_node; 3022 1.1 mrg } 3023 1.1 mrg 3024 1.1 mrg /* Finish a pseudo-destructor expression. If SCOPE is NULL, the 3025 1.1 mrg expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is 3026 1.1 mrg the TYPE for the type given. If SCOPE is non-NULL, the expression 3027 1.1 mrg was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */ 3028 1.1 mrg 3029 1.1 mrg tree 3030 1.1 mrg finish_pseudo_destructor_expr (tree object, tree scope, tree destructor, 3031 1.1 mrg location_t loc) 3032 1.1 mrg { 3033 1.1 mrg if (object == error_mark_node || destructor == error_mark_node) 3034 1.1 mrg return error_mark_node; 3035 1.1 mrg 3036 1.1 mrg gcc_assert (TYPE_P (destructor)); 3037 1.1 mrg 3038 1.1 mrg if (!processing_template_decl) 3039 1.1 mrg { 3040 1.1 mrg if (scope == error_mark_node) 3041 1.1 mrg { 3042 1.1 mrg error_at (loc, "invalid qualifying scope in pseudo-destructor name"); 3043 1.1 mrg return error_mark_node; 3044 1.1 mrg } 3045 1.1 mrg if (is_auto (destructor)) 3046 1.1 mrg destructor = TREE_TYPE (object); 3047 1.1 mrg if (scope && TYPE_P (scope) && !check_dtor_name (scope, destructor)) 3048 1.1 mrg { 3049 1.1 mrg error_at (loc, 3050 1.1 mrg "qualified type %qT does not match destructor name ~%qT", 3051 1.1 mrg scope, destructor); 3052 1.1 mrg return error_mark_node; 3053 1.1 mrg } 3054 1.1 mrg 3055 1.1 mrg 3056 1.1 mrg /* [expr.pseudo] says both: 3057 1.1 mrg 3058 1.1 mrg The type designated by the pseudo-destructor-name shall be 3059 1.1 mrg the same as the object type. 3060 1.1 mrg 3061 1.1 mrg and: 3062 1.1 mrg 3063 1.1 mrg The cv-unqualified versions of the object type and of the 3064 1.1 mrg type designated by the pseudo-destructor-name shall be the 3065 1.1 mrg same type. 3066 1.1 mrg 3067 1.1 mrg We implement the more generous second sentence, since that is 3068 1.1 mrg what most other compilers do. */ 3069 1.1 mrg if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object), 3070 1.1 mrg destructor)) 3071 1.1 mrg { 3072 1.1 mrg error_at (loc, "%qE is not of type %qT", object, destructor); 3073 1.1 mrg return error_mark_node; 3074 1.1 mrg } 3075 1.1 mrg } 3076 1.1 mrg 3077 1.1 mrg tree type = (type_dependent_expression_p (object) 3078 1.1 mrg ? NULL_TREE : void_type_node); 3079 1.1 mrg 3080 1.1 mrg return build3_loc (loc, PSEUDO_DTOR_EXPR, type, object, 3081 1.1 mrg scope, destructor); 3082 1.1 mrg } 3083 1.1 mrg 3084 1.1 mrg /* Finish an expression of the form CODE EXPR. */ 3085 1.1 mrg 3086 1.1 mrg cp_expr 3087 1.1 mrg finish_unary_op_expr (location_t op_loc, enum tree_code code, cp_expr expr, 3088 1.1 mrg tsubst_flags_t complain) 3089 1.1 mrg { 3090 1.1 mrg /* Build a location of the form: 3091 1.1 mrg ++expr 3092 1.1 mrg ^~~~~~ 3093 1.1 mrg with the caret at the operator token, ranging from the start 3094 1.1 mrg of the operator token to the end of EXPR. */ 3095 1.1 mrg location_t combined_loc = make_location (op_loc, 3096 1.1 mrg op_loc, expr.get_finish ()); 3097 1.1 mrg cp_expr result = build_x_unary_op (combined_loc, code, expr, 3098 1.1 mrg NULL_TREE, complain); 3099 1.1 mrg /* TODO: build_x_unary_op doesn't always honor the location. */ 3100 1.1 mrg result.set_location (combined_loc); 3101 1.1 mrg 3102 1.1 mrg if (result == error_mark_node) 3103 1.1 mrg return result; 3104 1.1 mrg 3105 1.1 mrg if (!(complain & tf_warning)) 3106 1.1 mrg return result; 3107 1.1 mrg 3108 1.1 mrg tree result_ovl = result; 3109 1.1 mrg tree expr_ovl = expr; 3110 1.1 mrg 3111 1.1 mrg if (!processing_template_decl) 3112 1.1 mrg expr_ovl = cp_fully_fold (expr_ovl); 3113 1.1 mrg 3114 1.1 mrg if (!CONSTANT_CLASS_P (expr_ovl) 3115 1.1 mrg || TREE_OVERFLOW_P (expr_ovl)) 3116 1.1 mrg return result; 3117 1.1 mrg 3118 1.1 mrg if (!processing_template_decl) 3119 1.1 mrg result_ovl = cp_fully_fold (result_ovl); 3120 1.1 mrg 3121 1.1 mrg if (CONSTANT_CLASS_P (result_ovl) && TREE_OVERFLOW_P (result_ovl)) 3122 1.1 mrg overflow_warning (combined_loc, result_ovl); 3123 1.1 mrg 3124 1.1 mrg return result; 3125 1.1 mrg } 3126 1.1 mrg 3127 1.1 mrg /* Return true if CONSTRUCTOR EXPR after pack expansion could have no 3128 1.1 mrg elements. */ 3129 1.1 mrg 3130 1.1 mrg static bool 3131 1.1 mrg maybe_zero_constructor_nelts (tree expr) 3132 1.1 mrg { 3133 1.1 mrg if (CONSTRUCTOR_NELTS (expr) == 0) 3134 1.1 mrg return true; 3135 1.1 mrg if (!processing_template_decl) 3136 1.1 mrg return false; 3137 1.1 mrg for (constructor_elt &elt : CONSTRUCTOR_ELTS (expr)) 3138 1.1 mrg if (!PACK_EXPANSION_P (elt.value)) 3139 1.1 mrg return false; 3140 1.1 mrg return true; 3141 1.1 mrg } 3142 1.1 mrg 3143 1.1 mrg /* Finish a compound-literal expression or C++11 functional cast with aggregate 3144 1.1 mrg initializer. TYPE is the type to which the CONSTRUCTOR in COMPOUND_LITERAL 3145 1.1 mrg is being cast. */ 3146 1.1 mrg 3147 1.1 mrg tree 3148 1.1 mrg finish_compound_literal (tree type, tree compound_literal, 3149 1.1 mrg tsubst_flags_t complain, 3150 1.1 mrg fcl_t fcl_context) 3151 1.1 mrg { 3152 1.1 mrg if (type == error_mark_node) 3153 1.1 mrg return error_mark_node; 3154 1.1 mrg 3155 1.1 mrg if (TYPE_REF_P (type)) 3156 1.1 mrg { 3157 1.1 mrg compound_literal 3158 1.1 mrg = finish_compound_literal (TREE_TYPE (type), compound_literal, 3159 1.1 mrg complain, fcl_context); 3160 1.1 mrg /* The prvalue is then used to direct-initialize the reference. */ 3161 1.1 mrg tree r = (perform_implicit_conversion_flags 3162 1.1 mrg (type, compound_literal, complain, LOOKUP_NORMAL)); 3163 1.1 mrg return convert_from_reference (r); 3164 1.1 mrg } 3165 1.1 mrg 3166 1.1 mrg if (!TYPE_OBJ_P (type)) 3167 1.1 mrg { 3168 1.1 mrg /* DR2351 */ 3169 1.1 mrg if (VOID_TYPE_P (type) && CONSTRUCTOR_NELTS (compound_literal) == 0) 3170 1.1 mrg return void_node; 3171 1.1 mrg else if (VOID_TYPE_P (type) 3172 1.1 mrg && processing_template_decl 3173 1.1 mrg && maybe_zero_constructor_nelts (compound_literal)) 3174 1.1 mrg /* If there are only packs in compound_literal, it could 3175 1.1 mrg be void{} after pack expansion. */; 3176 1.1 mrg else 3177 1.1 mrg { 3178 1.1 mrg if (complain & tf_error) 3179 1.1 mrg error ("compound literal of non-object type %qT", type); 3180 1.1 mrg return error_mark_node; 3181 1.1 mrg } 3182 1.1 mrg } 3183 1.1 mrg 3184 1.1 mrg if (template_placeholder_p (type)) 3185 1.1 mrg { 3186 1.1 mrg type = do_auto_deduction (type, compound_literal, type, complain, 3187 1.1 mrg adc_variable_type); 3188 1.1 mrg if (type == error_mark_node) 3189 1.1 mrg return error_mark_node; 3190 1.1 mrg } 3191 1.1 mrg /* C++23 auto{x}. */ 3192 1.1 mrg else if (is_auto (type) 3193 1.1 mrg && !AUTO_IS_DECLTYPE (type) 3194 1.1 mrg && CONSTRUCTOR_NELTS (compound_literal) == 1) 3195 1.1 mrg { 3196 1.1 mrg if (is_constrained_auto (type)) 3197 1.1 mrg { 3198 1.1 mrg if (complain & tf_error) 3199 1.1 mrg error ("%<auto{x}%> cannot be constrained"); 3200 1.1 mrg return error_mark_node; 3201 1.1 mrg } 3202 1.1 mrg else if (cxx_dialect < cxx23) 3203 1.1 mrg pedwarn (input_location, OPT_Wc__23_extensions, 3204 1.1 mrg "%<auto{x}%> only available with " 3205 1.1 mrg "%<-std=c++2b%> or %<-std=gnu++2b%>"); 3206 1.1 mrg type = do_auto_deduction (type, compound_literal, type, complain, 3207 1.1 mrg adc_variable_type); 3208 1.1 mrg if (type == error_mark_node) 3209 1.1 mrg return error_mark_node; 3210 1.1 mrg } 3211 1.1 mrg 3212 1.1 mrg /* Used to hold a copy of the compound literal in a template. */ 3213 1.1 mrg tree orig_cl = NULL_TREE; 3214 1.1 mrg 3215 1.1 mrg if (processing_template_decl) 3216 1.1 mrg { 3217 1.1 mrg const bool dependent_p 3218 1.1 mrg = (instantiation_dependent_expression_p (compound_literal) 3219 1.1 mrg || dependent_type_p (type)); 3220 1.1 mrg if (dependent_p) 3221 1.1 mrg /* We're about to return, no need to copy. */ 3222 1.1 mrg orig_cl = compound_literal; 3223 1.1 mrg else 3224 1.1 mrg /* We're going to need a copy. */ 3225 1.1 mrg orig_cl = unshare_constructor (compound_literal); 3226 1.1 mrg TREE_TYPE (orig_cl) = type; 3227 1.1 mrg /* Mark the expression as a compound literal. */ 3228 1.1 mrg TREE_HAS_CONSTRUCTOR (orig_cl) = 1; 3229 1.1 mrg /* And as instantiation-dependent. */ 3230 1.1 mrg CONSTRUCTOR_IS_DEPENDENT (orig_cl) = dependent_p; 3231 1.1 mrg if (fcl_context == fcl_c99) 3232 1.1 mrg CONSTRUCTOR_C99_COMPOUND_LITERAL (orig_cl) = 1; 3233 1.1 mrg /* If the compound literal is dependent, we're done for now. */ 3234 1.1 mrg if (dependent_p) 3235 1.1 mrg return orig_cl; 3236 1.1 mrg /* Otherwise, do go on to e.g. check narrowing. */ 3237 1.1 mrg } 3238 1.1 mrg 3239 1.1 mrg type = complete_type (type); 3240 1.1 mrg 3241 1.1 mrg if (TYPE_NON_AGGREGATE_CLASS (type)) 3242 1.1 mrg { 3243 1.1 mrg /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST 3244 1.1 mrg everywhere that deals with function arguments would be a pain, so 3245 1.1 mrg just wrap it in a TREE_LIST. The parser set a flag so we know 3246 1.1 mrg that it came from T{} rather than T({}). */ 3247 1.1 mrg CONSTRUCTOR_IS_DIRECT_INIT (compound_literal) = 1; 3248 1.1 mrg compound_literal = build_tree_list (NULL_TREE, compound_literal); 3249 1.1 mrg return build_functional_cast (input_location, type, 3250 1.1 mrg compound_literal, complain); 3251 1.1 mrg } 3252 1.1 mrg 3253 1.1 mrg if (TREE_CODE (type) == ARRAY_TYPE 3254 1.1 mrg && check_array_initializer (NULL_TREE, type, compound_literal)) 3255 1.1 mrg return error_mark_node; 3256 1.1 mrg compound_literal = reshape_init (type, compound_literal, complain); 3257 1.1 mrg if (SCALAR_TYPE_P (type) 3258 1.1 mrg && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal) 3259 1.1 mrg && !check_narrowing (type, compound_literal, complain)) 3260 1.1 mrg return error_mark_node; 3261 1.1 mrg if (TREE_CODE (type) == ARRAY_TYPE 3262 1.1 mrg && TYPE_DOMAIN (type) == NULL_TREE) 3263 1.1 mrg { 3264 1.1 mrg cp_complete_array_type_or_error (&type, compound_literal, 3265 1.1 mrg false, complain); 3266 1.1 mrg if (type == error_mark_node) 3267 1.1 mrg return error_mark_node; 3268 1.1 mrg } 3269 1.1 mrg compound_literal = digest_init_flags (type, compound_literal, 3270 1.1 mrg LOOKUP_NORMAL | LOOKUP_NO_NARROWING, 3271 1.1 mrg complain); 3272 1.1 mrg if (compound_literal == error_mark_node) 3273 1.1 mrg return error_mark_node; 3274 1.1 mrg 3275 1.1 mrg /* If we're in a template, return the original compound literal. */ 3276 1.1 mrg if (orig_cl) 3277 1.1 mrg return orig_cl; 3278 1.1 mrg 3279 1.1 mrg if (TREE_CODE (compound_literal) == CONSTRUCTOR) 3280 1.1 mrg { 3281 1.1 mrg TREE_HAS_CONSTRUCTOR (compound_literal) = true; 3282 1.1 mrg if (fcl_context == fcl_c99) 3283 1.1 mrg CONSTRUCTOR_C99_COMPOUND_LITERAL (compound_literal) = 1; 3284 1.1 mrg } 3285 1.1 mrg 3286 1.1 mrg /* Put static/constant array temporaries in static variables. */ 3287 1.1 mrg /* FIXME all C99 compound literals should be variables rather than C++ 3288 1.1 mrg temporaries, unless they are used as an aggregate initializer. */ 3289 1.1 mrg if ((!at_function_scope_p () || CP_TYPE_CONST_P (type)) 3290 1.1 mrg && fcl_context == fcl_c99 3291 1.1 mrg && TREE_CODE (type) == ARRAY_TYPE 3292 1.1 mrg && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type) 3293 1.1 mrg && initializer_constant_valid_p (compound_literal, type)) 3294 1.1 mrg { 3295 1.1 mrg tree decl = create_temporary_var (type); 3296 1.1 mrg DECL_CONTEXT (decl) = NULL_TREE; 3297 1.1 mrg DECL_INITIAL (decl) = compound_literal; 3298 1.1 mrg TREE_STATIC (decl) = 1; 3299 1.1 mrg if (literal_type_p (type) && CP_TYPE_CONST_NON_VOLATILE_P (type)) 3300 1.1 mrg { 3301 1.1 mrg /* 5.19 says that a constant expression can include an 3302 1.1 mrg lvalue-rvalue conversion applied to "a glvalue of literal type 3303 1.1 mrg that refers to a non-volatile temporary object initialized 3304 1.1 mrg with a constant expression". Rather than try to communicate 3305 1.1 mrg that this VAR_DECL is a temporary, just mark it constexpr. */ 3306 1.1 mrg DECL_DECLARED_CONSTEXPR_P (decl) = true; 3307 1.1 mrg DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true; 3308 1.1 mrg TREE_CONSTANT (decl) = true; 3309 1.1 mrg } 3310 1.1 mrg cp_apply_type_quals_to_decl (cp_type_quals (type), decl); 3311 1.1 mrg decl = pushdecl_top_level (decl); 3312 1.1 mrg DECL_NAME (decl) = make_anon_name (); 3313 1.1 mrg SET_DECL_ASSEMBLER_NAME (decl, DECL_NAME (decl)); 3314 1.1 mrg /* Make sure the destructor is callable. */ 3315 1.1 mrg tree clean = cxx_maybe_build_cleanup (decl, complain); 3316 1.1 mrg if (clean == error_mark_node) 3317 1.1 mrg return error_mark_node; 3318 1.1 mrg return decl; 3319 1.1 mrg } 3320 1.1 mrg 3321 1.1 mrg /* Represent other compound literals with TARGET_EXPR so we produce 3322 1.1 mrg a prvalue, and can elide copies. */ 3323 1.1 mrg if (!VECTOR_TYPE_P (type) 3324 1.1 mrg && (TREE_CODE (compound_literal) == CONSTRUCTOR 3325 1.1 mrg || TREE_CODE (compound_literal) == VEC_INIT_EXPR)) 3326 1.1 mrg { 3327 1.1 mrg /* The CONSTRUCTOR is now an initializer, not a compound literal. */ 3328 1.1 mrg if (TREE_CODE (compound_literal) == CONSTRUCTOR) 3329 1.1 mrg TREE_HAS_CONSTRUCTOR (compound_literal) = false; 3330 1.1 mrg compound_literal = get_target_expr_sfinae (compound_literal, complain); 3331 1.1 mrg } 3332 1.1 mrg else 3333 1.1 mrg /* For e.g. int{42} just make sure it's a prvalue. */ 3334 1.1 mrg compound_literal = rvalue (compound_literal); 3335 1.1 mrg 3336 1.1 mrg return compound_literal; 3337 1.1 mrg } 3338 1.1 mrg 3339 1.1 mrg /* Return the declaration for the function-name variable indicated by 3340 1.1 mrg ID. */ 3341 1.1 mrg 3342 1.1 mrg tree 3343 1.1 mrg finish_fname (tree id) 3344 1.1 mrg { 3345 1.1 mrg tree decl; 3346 1.1 mrg 3347 1.1 mrg decl = fname_decl (input_location, C_RID_CODE (id), id); 3348 1.1 mrg if (processing_template_decl && current_function_decl 3349 1.1 mrg && decl != error_mark_node) 3350 1.1 mrg decl = DECL_NAME (decl); 3351 1.1 mrg return decl; 3352 1.1 mrg } 3353 1.1 mrg 3354 1.1 mrg /* Finish a translation unit. */ 3355 1.1 mrg 3356 1.1 mrg void 3357 1.1 mrg finish_translation_unit (void) 3358 1.1 mrg { 3359 1.1 mrg /* In case there were missing closebraces, 3360 1.1 mrg get us back to the global binding level. */ 3361 1.1 mrg pop_everything (); 3362 1.1 mrg while (current_namespace != global_namespace) 3363 1.1 mrg pop_namespace (); 3364 1.1 mrg 3365 1.1 mrg /* Do file scope __FUNCTION__ et al. */ 3366 1.1 mrg finish_fname_decls (); 3367 1.1 mrg 3368 1.1 mrg if (vec_safe_length (scope_chain->omp_declare_target_attribute)) 3369 1.1 mrg { 3370 1.1 mrg if (!errorcount) 3371 1.1 mrg error ("%<#pragma omp declare target%> without corresponding " 3372 1.1 mrg "%<#pragma omp end declare target%>"); 3373 1.1 mrg vec_safe_truncate (scope_chain->omp_declare_target_attribute, 0); 3374 1.1 mrg } 3375 1.1 mrg } 3376 1.1 mrg 3377 1.1 mrg /* Finish a template type parameter, specified as AGGR IDENTIFIER. 3378 1.1 mrg Returns the parameter. */ 3379 1.1 mrg 3380 1.1 mrg tree 3381 1.1 mrg finish_template_type_parm (tree aggr, tree identifier) 3382 1.1 mrg { 3383 1.1 mrg if (aggr != class_type_node) 3384 1.1 mrg { 3385 1.1 mrg permerror (input_location, "template type parameters must use the keyword %<class%> or %<typename%>"); 3386 1.1 mrg aggr = class_type_node; 3387 1.1 mrg } 3388 1.1 mrg 3389 1.1 mrg return build_tree_list (aggr, identifier); 3390 1.1 mrg } 3391 1.1 mrg 3392 1.1 mrg /* Finish a template template parameter, specified as AGGR IDENTIFIER. 3393 1.1 mrg Returns the parameter. */ 3394 1.1 mrg 3395 1.1 mrg tree 3396 1.1 mrg finish_template_template_parm (tree aggr, tree identifier) 3397 1.1 mrg { 3398 1.1 mrg tree decl = build_decl (input_location, 3399 1.1 mrg TYPE_DECL, identifier, NULL_TREE); 3400 1.1 mrg 3401 1.1 mrg tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE); 3402 1.1 mrg DECL_TEMPLATE_PARMS (tmpl) = current_template_parms; 3403 1.1 mrg DECL_TEMPLATE_RESULT (tmpl) = decl; 3404 1.1 mrg DECL_ARTIFICIAL (decl) = 1; 3405 1.1 mrg 3406 1.1 mrg /* Associate the constraints with the underlying declaration, 3407 1.1 mrg not the template. */ 3408 1.1 mrg tree reqs = TEMPLATE_PARMS_CONSTRAINTS (current_template_parms); 3409 1.1 mrg tree constr = build_constraints (reqs, NULL_TREE); 3410 1.1 mrg set_constraints (decl, constr); 3411 1.1 mrg 3412 1.1 mrg end_template_decl (); 3413 1.1 mrg 3414 1.1 mrg gcc_assert (DECL_TEMPLATE_PARMS (tmpl)); 3415 1.1 mrg 3416 1.1 mrg check_default_tmpl_args (decl, DECL_TEMPLATE_PARMS (tmpl), 3417 1.1 mrg /*is_primary=*/true, /*is_partial=*/false, 3418 1.1 mrg /*is_friend=*/0); 3419 1.1 mrg 3420 1.1 mrg return finish_template_type_parm (aggr, tmpl); 3421 1.1 mrg } 3422 1.1 mrg 3423 1.1 mrg /* ARGUMENT is the default-argument value for a template template 3424 1.1 mrg parameter. If ARGUMENT is invalid, issue error messages and return 3425 1.1 mrg the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */ 3426 1.1 mrg 3427 1.1 mrg tree 3428 1.1 mrg check_template_template_default_arg (tree argument) 3429 1.1 mrg { 3430 1.1 mrg if (TREE_CODE (argument) != TEMPLATE_DECL 3431 1.1 mrg && TREE_CODE (argument) != TEMPLATE_TEMPLATE_PARM 3432 1.1 mrg && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE) 3433 1.1 mrg { 3434 1.1 mrg if (TREE_CODE (argument) == TYPE_DECL) 3435 1.1 mrg error ("invalid use of type %qT as a default value for a template " 3436 1.1 mrg "template-parameter", TREE_TYPE (argument)); 3437 1.1 mrg else 3438 1.1 mrg error ("invalid default argument for a template template parameter"); 3439 1.1 mrg return error_mark_node; 3440 1.1 mrg } 3441 1.1 mrg 3442 1.1 mrg return argument; 3443 1.1 mrg } 3444 1.1 mrg 3445 1.1 mrg /* Begin a class definition, as indicated by T. */ 3446 1.1 mrg 3447 1.1 mrg tree 3448 1.1 mrg begin_class_definition (tree t) 3449 1.1 mrg { 3450 1.1 mrg if (error_operand_p (t) || error_operand_p (TYPE_MAIN_DECL (t))) 3451 1.1 mrg return error_mark_node; 3452 1.1 mrg 3453 1.1 mrg if (processing_template_parmlist && !LAMBDA_TYPE_P (t)) 3454 1.1 mrg { 3455 1.1 mrg error ("definition of %q#T inside template parameter list", t); 3456 1.1 mrg return error_mark_node; 3457 1.1 mrg } 3458 1.1 mrg 3459 1.1 mrg /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733 3460 1.1 mrg are passed the same as decimal scalar types. */ 3461 1.1 mrg if (TREE_CODE (t) == RECORD_TYPE 3462 1.1 mrg && !processing_template_decl) 3463 1.1 mrg { 3464 1.1 mrg tree ns = TYPE_CONTEXT (t); 3465 1.1 mrg if (ns && TREE_CODE (ns) == NAMESPACE_DECL 3466 1.1 mrg && DECL_CONTEXT (ns) == std_node 3467 1.1 mrg && DECL_NAME (ns) 3468 1.1 mrg && id_equal (DECL_NAME (ns), "decimal")) 3469 1.1 mrg { 3470 1.1 mrg const char *n = TYPE_NAME_STRING (t); 3471 1.1 mrg if ((strcmp (n, "decimal32") == 0) 3472 1.1 mrg || (strcmp (n, "decimal64") == 0) 3473 1.1 mrg || (strcmp (n, "decimal128") == 0)) 3474 1.1 mrg TYPE_TRANSPARENT_AGGR (t) = 1; 3475 1.1 mrg } 3476 1.1 mrg } 3477 1.1 mrg 3478 1.1 mrg /* A non-implicit typename comes from code like: 3479 1.1 mrg 3480 1.1 mrg template <typename T> struct A { 3481 1.1 mrg template <typename U> struct A<T>::B ... 3482 1.1 mrg 3483 1.1 mrg This is erroneous. */ 3484 1.1 mrg else if (TREE_CODE (t) == TYPENAME_TYPE) 3485 1.1 mrg { 3486 1.1 mrg error ("invalid definition of qualified type %qT", t); 3487 1.1 mrg t = error_mark_node; 3488 1.1 mrg } 3489 1.1 mrg 3490 1.1 mrg if (t == error_mark_node || ! MAYBE_CLASS_TYPE_P (t)) 3491 1.1 mrg { 3492 1.1 mrg t = make_class_type (RECORD_TYPE); 3493 1.1 mrg pushtag (make_anon_name (), t); 3494 1.1 mrg } 3495 1.1 mrg 3496 1.1 mrg if (TYPE_BEING_DEFINED (t)) 3497 1.1 mrg { 3498 1.1 mrg t = make_class_type (TREE_CODE (t)); 3499 1.1 mrg pushtag (TYPE_IDENTIFIER (t), t); 3500 1.1 mrg } 3501 1.1 mrg 3502 1.1 mrg if (modules_p ()) 3503 1.1 mrg { 3504 1.1 mrg if (!module_may_redeclare (TYPE_NAME (t))) 3505 1.1 mrg { 3506 1.1 mrg error ("cannot declare %qD in a different module", TYPE_NAME (t)); 3507 1.1 mrg inform (DECL_SOURCE_LOCATION (TYPE_NAME (t)), "declared here"); 3508 1.1 mrg return error_mark_node; 3509 1.1 mrg } 3510 1.1 mrg set_instantiating_module (TYPE_NAME (t)); 3511 1.1 mrg set_defining_module (TYPE_NAME (t)); 3512 1.1 mrg } 3513 1.1 mrg 3514 1.1 mrg maybe_process_partial_specialization (t); 3515 1.1 mrg pushclass (t); 3516 1.1 mrg TYPE_BEING_DEFINED (t) = 1; 3517 1.1 mrg class_binding_level->defining_class_p = 1; 3518 1.1 mrg 3519 1.1 mrg if (flag_pack_struct) 3520 1.1 mrg { 3521 1.1 mrg tree v; 3522 1.1 mrg TYPE_PACKED (t) = 1; 3523 1.1 mrg /* Even though the type is being defined for the first time 3524 1.1 mrg here, there might have been a forward declaration, so there 3525 1.1 mrg might be cv-qualified variants of T. */ 3526 1.1 mrg for (v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v)) 3527 1.1 mrg TYPE_PACKED (v) = 1; 3528 1.1 mrg } 3529 1.1 mrg /* Reset the interface data, at the earliest possible 3530 1.1 mrg moment, as it might have been set via a class foo; 3531 1.1 mrg before. */ 3532 1.1 mrg if (! TYPE_UNNAMED_P (t)) 3533 1.1 mrg { 3534 1.1 mrg struct c_fileinfo *finfo = \ 3535 1.1 mrg get_fileinfo (LOCATION_FILE (input_location)); 3536 1.1 mrg CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only; 3537 1.1 mrg SET_CLASSTYPE_INTERFACE_UNKNOWN_X 3538 1.1 mrg (t, finfo->interface_unknown); 3539 1.1 mrg } 3540 1.1 mrg reset_specialization (); 3541 1.1 mrg 3542 1.1 mrg /* Make a declaration for this class in its own scope. */ 3543 1.1 mrg build_self_reference (); 3544 1.1 mrg 3545 1.1 mrg return t; 3546 1.1 mrg } 3547 1.1 mrg 3548 1.1 mrg /* Finish the member declaration given by DECL. */ 3549 1.1 mrg 3550 1.1 mrg void 3551 1.1 mrg finish_member_declaration (tree decl) 3552 1.1 mrg { 3553 1.1 mrg if (decl == error_mark_node || decl == NULL_TREE) 3554 1.1 mrg return; 3555 1.1 mrg 3556 1.1 mrg if (decl == void_type_node) 3557 1.1 mrg /* The COMPONENT was a friend, not a member, and so there's 3558 1.1 mrg nothing for us to do. */ 3559 1.1 mrg return; 3560 1.1 mrg 3561 1.1 mrg /* We should see only one DECL at a time. */ 3562 1.1 mrg gcc_assert (DECL_CHAIN (decl) == NULL_TREE); 3563 1.1 mrg 3564 1.1 mrg /* Don't add decls after definition. */ 3565 1.1 mrg gcc_assert (TYPE_BEING_DEFINED (current_class_type) 3566 1.1 mrg /* We can add lambda types when late parsing default 3567 1.1 mrg arguments. */ 3568 1.1 mrg || LAMBDA_TYPE_P (TREE_TYPE (decl))); 3569 1.1 mrg 3570 1.1 mrg /* Set up access control for DECL. */ 3571 1.1 mrg TREE_PRIVATE (decl) 3572 1.1 mrg = (current_access_specifier == access_private_node); 3573 1.1 mrg TREE_PROTECTED (decl) 3574 1.1 mrg = (current_access_specifier == access_protected_node); 3575 1.1 mrg if (TREE_CODE (decl) == TEMPLATE_DECL) 3576 1.1 mrg { 3577 1.1 mrg TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl); 3578 1.1 mrg TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl); 3579 1.1 mrg } 3580 1.1 mrg 3581 1.1 mrg /* Mark the DECL as a member of the current class, unless it's 3582 1.1 mrg a member of an enumeration. */ 3583 1.1 mrg if (TREE_CODE (decl) != CONST_DECL) 3584 1.1 mrg DECL_CONTEXT (decl) = current_class_type; 3585 1.1 mrg 3586 1.1 mrg /* Remember the single FIELD_DECL an anonymous aggregate type is used for. */ 3587 1.1 mrg if (TREE_CODE (decl) == FIELD_DECL 3588 1.1 mrg && ANON_AGGR_TYPE_P (TREE_TYPE (decl))) 3589 1.1 mrg { 3590 1.1 mrg gcc_assert (!ANON_AGGR_TYPE_FIELD (TYPE_MAIN_VARIANT (TREE_TYPE (decl)))); 3591 1.1 mrg ANON_AGGR_TYPE_FIELD (TYPE_MAIN_VARIANT (TREE_TYPE (decl))) = decl; 3592 1.1 mrg } 3593 1.1 mrg 3594 1.1 mrg if (TREE_CODE (decl) == USING_DECL) 3595 1.1 mrg /* Avoid debug info for class-scope USING_DECLS for now, we'll 3596 1.1 mrg call cp_emit_debug_info_for_using later. */ 3597 1.1 mrg DECL_IGNORED_P (decl) = 1; 3598 1.1 mrg 3599 1.1 mrg /* Check for bare parameter packs in the non-static data member 3600 1.1 mrg declaration. */ 3601 1.1 mrg if (TREE_CODE (decl) == FIELD_DECL) 3602 1.1 mrg { 3603 1.1 mrg if (check_for_bare_parameter_packs (TREE_TYPE (decl))) 3604 1.1 mrg TREE_TYPE (decl) = error_mark_node; 3605 1.1 mrg if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl))) 3606 1.1 mrg DECL_ATTRIBUTES (decl) = NULL_TREE; 3607 1.1 mrg } 3608 1.1 mrg 3609 1.1 mrg /* [dcl.link] 3610 1.1 mrg 3611 1.1 mrg A C language linkage is ignored for the names of class members 3612 1.1 mrg and the member function type of class member functions. */ 3613 1.1 mrg if (DECL_LANG_SPECIFIC (decl)) 3614 1.1 mrg SET_DECL_LANGUAGE (decl, lang_cplusplus); 3615 1.1 mrg 3616 1.1 mrg bool add = false; 3617 1.1 mrg 3618 1.1 mrg /* Functions and non-functions are added differently. */ 3619 1.1 mrg if (DECL_DECLARES_FUNCTION_P (decl)) 3620 1.1 mrg add = add_method (current_class_type, decl, false); 3621 1.1 mrg /* Enter the DECL into the scope of the class, if the class 3622 1.1 mrg isn't a closure (whose fields are supposed to be unnamed). */ 3623 1.1 mrg else if (CLASSTYPE_LAMBDA_EXPR (current_class_type) 3624 1.1 mrg || maybe_push_used_methods (decl) 3625 1.1 mrg || pushdecl_class_level (decl)) 3626 1.1 mrg add = true; 3627 1.1 mrg 3628 1.1 mrg if (add) 3629 1.1 mrg { 3630 1.1 mrg /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields 3631 1.1 mrg go at the beginning. The reason is that 3632 1.1 mrg legacy_nonfn_member_lookup searches the list in order, and we 3633 1.1 mrg want a field name to override a type name so that the "struct 3634 1.1 mrg stat hack" will work. In particular: 3635 1.1 mrg 3636 1.1 mrg struct S { enum E { }; static const int E = 5; int ary[S::E]; } s; 3637 1.1 mrg 3638 1.1 mrg is valid. */ 3639 1.1 mrg 3640 1.1 mrg if (TREE_CODE (decl) == TYPE_DECL) 3641 1.1 mrg TYPE_FIELDS (current_class_type) 3642 1.1 mrg = chainon (TYPE_FIELDS (current_class_type), decl); 3643 1.1 mrg else 3644 1.1 mrg { 3645 1.1 mrg DECL_CHAIN (decl) = TYPE_FIELDS (current_class_type); 3646 1.1 mrg TYPE_FIELDS (current_class_type) = decl; 3647 1.1 mrg } 3648 1.1 mrg 3649 1.1 mrg maybe_add_class_template_decl_list (current_class_type, decl, 3650 1.1 mrg /*friend_p=*/0); 3651 1.1 mrg } 3652 1.1 mrg } 3653 1.1 mrg 3654 1.1 mrg /* Finish processing a complete template declaration. The PARMS are 3655 1.1 mrg the template parameters. */ 3656 1.1 mrg 3657 1.1 mrg void 3658 1.1 mrg finish_template_decl (tree parms) 3659 1.1 mrg { 3660 1.1 mrg if (parms) 3661 1.1 mrg end_template_decl (); 3662 1.1 mrg else 3663 1.1 mrg end_specialization (); 3664 1.1 mrg } 3665 1.1 mrg 3666 1.1 mrg // Returns the template type of the class scope being entered. If we're 3667 1.1 mrg // entering a constrained class scope. TYPE is the class template 3668 1.1 mrg // scope being entered and we may need to match the intended type with 3669 1.1 mrg // a constrained specialization. For example: 3670 1.1 mrg // 3671 1.1 mrg // template<Object T> 3672 1.1 mrg // struct S { void f(); }; #1 3673 1.1 mrg // 3674 1.1 mrg // template<Object T> 3675 1.1 mrg // void S<T>::f() { } #2 3676 1.1 mrg // 3677 1.1 mrg // We check, in #2, that S<T> refers precisely to the type declared by 3678 1.1 mrg // #1 (i.e., that the constraints match). Note that the following should 3679 1.1 mrg // be an error since there is no specialization of S<T> that is 3680 1.1 mrg // unconstrained, but this is not diagnosed here. 3681 1.1 mrg // 3682 1.1 mrg // template<typename T> 3683 1.1 mrg // void S<T>::f() { } 3684 1.1 mrg // 3685 1.1 mrg // We cannot diagnose this problem here since this function also matches 3686 1.1 mrg // qualified template names that are not part of a definition. For example: 3687 1.1 mrg // 3688 1.1 mrg // template<Integral T, Floating_point U> 3689 1.1 mrg // typename pair<T, U>::first_type void f(T, U); 3690 1.1 mrg // 3691 1.1 mrg // Here, it is unlikely that there is a partial specialization of 3692 1.1 mrg // pair constrained for for Integral and Floating_point arguments. 3693 1.1 mrg // 3694 1.1 mrg // The general rule is: if a constrained specialization with matching 3695 1.1 mrg // constraints is found return that type. Also note that if TYPE is not a 3696 1.1 mrg // class-type (e.g. a typename type), then no fixup is needed. 3697 1.1 mrg 3698 1.1 mrg static tree 3699 1.1 mrg fixup_template_type (tree type) 3700 1.1 mrg { 3701 1.1 mrg // Find the template parameter list at the a depth appropriate to 3702 1.1 mrg // the scope we're trying to enter. 3703 1.1 mrg tree parms = current_template_parms; 3704 1.1 mrg int depth = template_class_depth (type); 3705 1.1 mrg for (int n = current_template_depth; n > depth && parms; --n) 3706 1.1 mrg parms = TREE_CHAIN (parms); 3707 1.1 mrg if (!parms) 3708 1.1 mrg return type; 3709 1.1 mrg tree cur_reqs = TEMPLATE_PARMS_CONSTRAINTS (parms); 3710 1.1 mrg tree cur_constr = build_constraints (cur_reqs, NULL_TREE); 3711 1.1 mrg 3712 1.1 mrg // Search for a specialization whose type and constraints match. 3713 1.1 mrg tree tmpl = CLASSTYPE_TI_TEMPLATE (type); 3714 1.1 mrg tree specs = DECL_TEMPLATE_SPECIALIZATIONS (tmpl); 3715 1.1 mrg while (specs) 3716 1.1 mrg { 3717 1.1 mrg tree spec_constr = get_constraints (TREE_VALUE (specs)); 3718 1.1 mrg 3719 1.1 mrg // If the type and constraints match a specialization, then we 3720 1.1 mrg // are entering that type. 3721 1.1 mrg if (same_type_p (type, TREE_TYPE (specs)) 3722 1.1 mrg && equivalent_constraints (cur_constr, spec_constr)) 3723 1.1 mrg return TREE_TYPE (specs); 3724 1.1 mrg specs = TREE_CHAIN (specs); 3725 1.1 mrg } 3726 1.1 mrg 3727 1.1 mrg // If no specialization matches, then must return the type 3728 1.1 mrg // previously found. 3729 1.1 mrg return type; 3730 1.1 mrg } 3731 1.1 mrg 3732 1.1 mrg /* Finish processing a template-id (which names a type) of the form 3733 1.1 mrg NAME < ARGS >. Return the TYPE_DECL for the type named by the 3734 1.1 mrg template-id. If ENTERING_SCOPE is nonzero we are about to enter 3735 1.1 mrg the scope of template-id indicated. */ 3736 1.1 mrg 3737 1.1 mrg tree 3738 1.1 mrg finish_template_type (tree name, tree args, int entering_scope) 3739 1.1 mrg { 3740 1.1 mrg tree type; 3741 1.1 mrg 3742 1.1 mrg type = lookup_template_class (name, args, 3743 1.1 mrg NULL_TREE, NULL_TREE, entering_scope, 3744 1.1 mrg tf_warning_or_error | tf_user); 3745 1.1 mrg 3746 1.1 mrg /* If we might be entering the scope of a partial specialization, 3747 1.1 mrg find the one with the right constraints. */ 3748 1.1 mrg if (flag_concepts 3749 1.1 mrg && entering_scope 3750 1.1 mrg && CLASS_TYPE_P (type) 3751 1.1 mrg && CLASSTYPE_TEMPLATE_INFO (type) 3752 1.1 mrg && dependent_type_p (type) 3753 1.1 mrg && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type))) 3754 1.1 mrg type = fixup_template_type (type); 3755 1.1 mrg 3756 1.1 mrg if (type == error_mark_node) 3757 1.1 mrg return type; 3758 1.1 mrg else if (CLASS_TYPE_P (type) && !alias_type_or_template_p (type)) 3759 1.1 mrg return TYPE_STUB_DECL (type); 3760 1.1 mrg else 3761 1.1 mrg return TYPE_NAME (type); 3762 1.1 mrg } 3763 1.1 mrg 3764 1.1 mrg /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER. 3765 1.1 mrg Return a TREE_LIST containing the ACCESS_SPECIFIER and the 3766 1.1 mrg BASE_CLASS, or NULL_TREE if an error occurred. The 3767 1.1 mrg ACCESS_SPECIFIER is one of 3768 1.1 mrg access_{default,public,protected_private}_node. For a virtual base 3769 1.1 mrg we set TREE_TYPE. */ 3770 1.1 mrg 3771 1.1 mrg tree 3772 1.1 mrg finish_base_specifier (tree base, tree access, bool virtual_p) 3773 1.1 mrg { 3774 1.1 mrg tree result; 3775 1.1 mrg 3776 1.1 mrg if (base == error_mark_node) 3777 1.1 mrg { 3778 1.1 mrg error ("invalid base-class specification"); 3779 1.1 mrg result = NULL_TREE; 3780 1.1 mrg } 3781 1.1 mrg else if (! MAYBE_CLASS_TYPE_P (base)) 3782 1.1 mrg { 3783 1.1 mrg error ("%qT is not a class type", base); 3784 1.1 mrg result = NULL_TREE; 3785 1.1 mrg } 3786 1.1 mrg else 3787 1.1 mrg { 3788 1.1 mrg if (cp_type_quals (base) != 0) 3789 1.1 mrg { 3790 1.1 mrg /* DR 484: Can a base-specifier name a cv-qualified 3791 1.1 mrg class type? */ 3792 1.1 mrg base = TYPE_MAIN_VARIANT (base); 3793 1.1 mrg } 3794 1.1 mrg result = build_tree_list (access, base); 3795 1.1 mrg if (virtual_p) 3796 1.1 mrg TREE_TYPE (result) = integer_type_node; 3797 1.1 mrg } 3798 1.1 mrg 3799 1.1 mrg return result; 3800 1.1 mrg } 3801 1.1 mrg 3802 1.1 mrg /* If FNS is a member function, a set of member functions, or a 3803 1.1 mrg template-id referring to one or more member functions, return a 3804 1.1 mrg BASELINK for FNS, incorporating the current access context. 3805 1.1 mrg Otherwise, return FNS unchanged. */ 3806 1.1 mrg 3807 1.1 mrg tree 3808 1.1 mrg baselink_for_fns (tree fns) 3809 1.1 mrg { 3810 1.1 mrg tree scope; 3811 1.1 mrg tree cl; 3812 1.1 mrg 3813 1.1 mrg if (BASELINK_P (fns) 3814 1.1 mrg || error_operand_p (fns)) 3815 1.1 mrg return fns; 3816 1.1 mrg 3817 1.1 mrg scope = ovl_scope (fns); 3818 1.1 mrg if (!CLASS_TYPE_P (scope)) 3819 1.1 mrg return fns; 3820 1.1 mrg 3821 1.1 mrg cl = currently_open_derived_class (scope); 3822 1.1 mrg if (!cl) 3823 1.1 mrg cl = scope; 3824 1.1 mrg tree access_path = TYPE_BINFO (cl); 3825 1.1 mrg tree conv_path = (cl == scope ? access_path 3826 1.1 mrg : lookup_base (cl, scope, ba_any, NULL, tf_none)); 3827 1.1 mrg return build_baselink (conv_path, access_path, fns, /*optype=*/NULL_TREE); 3828 1.1 mrg } 3829 1.1 mrg 3830 1.1 mrg /* Returns true iff DECL is a variable from a function outside 3831 1.1 mrg the current one. */ 3832 1.1 mrg 3833 1.1 mrg static bool 3834 1.1 mrg outer_var_p (tree decl) 3835 1.1 mrg { 3836 1.1 mrg return ((VAR_P (decl) || TREE_CODE (decl) == PARM_DECL) 3837 1.1 mrg && DECL_FUNCTION_SCOPE_P (decl) 3838 1.1 mrg /* Don't get confused by temporaries. */ 3839 1.1 mrg && DECL_NAME (decl) 3840 1.1 mrg && (DECL_CONTEXT (decl) != current_function_decl 3841 1.1 mrg || parsing_nsdmi ())); 3842 1.1 mrg } 3843 1.1 mrg 3844 1.1 mrg /* As above, but also checks that DECL is automatic. */ 3845 1.1 mrg 3846 1.1 mrg bool 3847 1.1 mrg outer_automatic_var_p (tree decl) 3848 1.1 mrg { 3849 1.1 mrg return (outer_var_p (decl) 3850 1.1 mrg && !TREE_STATIC (decl)); 3851 1.1 mrg } 3852 1.1 mrg 3853 1.1 mrg /* DECL satisfies outer_automatic_var_p. Possibly complain about it or 3854 1.1 mrg rewrite it for lambda capture. 3855 1.1 mrg 3856 1.1 mrg If ODR_USE is true, we're being called from mark_use, and we complain about 3857 1.1 mrg use of constant variables. If ODR_USE is false, we're being called for the 3858 1.1 mrg id-expression, and we do lambda capture. */ 3859 1.1 mrg 3860 1.1 mrg tree 3861 1.1 mrg process_outer_var_ref (tree decl, tsubst_flags_t complain, bool odr_use) 3862 1.1 mrg { 3863 1.1 mrg if (cp_unevaluated_operand) 3864 1.1 mrg { 3865 1.1 mrg tree type = TREE_TYPE (decl); 3866 1.1 mrg if (!dependent_type_p (type) 3867 1.1 mrg && variably_modified_type_p (type, NULL_TREE)) 3868 1.1 mrg /* VLAs are used even in unevaluated context. */; 3869 1.1 mrg else 3870 1.1 mrg /* It's not a use (3.2) if we're in an unevaluated context. */ 3871 1.1 mrg return decl; 3872 1.1 mrg } 3873 1.1 mrg if (decl == error_mark_node) 3874 1.1 mrg return decl; 3875 1.1 mrg 3876 1.1 mrg tree context = DECL_CONTEXT (decl); 3877 1.1 mrg tree containing_function = current_function_decl; 3878 1.1 mrg tree lambda_stack = NULL_TREE; 3879 1.1 mrg tree lambda_expr = NULL_TREE; 3880 1.1 mrg tree initializer = convert_from_reference (decl); 3881 1.1 mrg 3882 1.1 mrg /* Mark it as used now even if the use is ill-formed. */ 3883 1.1 mrg if (!mark_used (decl, complain)) 3884 1.1 mrg return error_mark_node; 3885 1.1 mrg 3886 1.1 mrg if (parsing_nsdmi ()) 3887 1.1 mrg containing_function = NULL_TREE; 3888 1.1 mrg 3889 1.1 mrg if (containing_function && LAMBDA_FUNCTION_P (containing_function)) 3890 1.1 mrg { 3891 1.1 mrg /* Check whether we've already built a proxy. */ 3892 1.1 mrg tree var = decl; 3893 1.1 mrg while (is_normal_capture_proxy (var)) 3894 1.1 mrg var = DECL_CAPTURED_VARIABLE (var); 3895 1.1 mrg tree d = retrieve_local_specialization (var); 3896 1.1 mrg 3897 1.1 mrg if (d && d != decl && is_capture_proxy (d)) 3898 1.1 mrg { 3899 1.1 mrg if (DECL_CONTEXT (d) == containing_function) 3900 1.1 mrg /* We already have an inner proxy. */ 3901 1.1 mrg return d; 3902 1.1 mrg else 3903 1.1 mrg /* We need to capture an outer proxy. */ 3904 1.1 mrg return process_outer_var_ref (d, complain, odr_use); 3905 1.1 mrg } 3906 1.1 mrg } 3907 1.1 mrg 3908 1.1 mrg /* If we are in a lambda function, we can move out until we hit 3909 1.1 mrg 1. the context, 3910 1.1 mrg 2. a non-lambda function, or 3911 1.1 mrg 3. a non-default capturing lambda function. */ 3912 1.1 mrg while (context != containing_function 3913 1.1 mrg /* containing_function can be null with invalid generic lambdas. */ 3914 1.1 mrg && containing_function 3915 1.1 mrg && LAMBDA_FUNCTION_P (containing_function)) 3916 1.1 mrg { 3917 1.1 mrg tree closure = DECL_CONTEXT (containing_function); 3918 1.1 mrg lambda_expr = CLASSTYPE_LAMBDA_EXPR (closure); 3919 1.1 mrg 3920 1.1 mrg if (TYPE_CLASS_SCOPE_P (closure)) 3921 1.1 mrg /* A lambda in an NSDMI (c++/64496). */ 3922 1.1 mrg break; 3923 1.1 mrg 3924 1.1 mrg if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE) 3925 1.1 mrg break; 3926 1.1 mrg 3927 1.1 mrg lambda_stack = tree_cons (NULL_TREE, lambda_expr, lambda_stack); 3928 1.1 mrg 3929 1.1 mrg containing_function = decl_function_context (containing_function); 3930 1.1 mrg } 3931 1.1 mrg 3932 1.1 mrg /* In a lambda within a template, wait until instantiation time to implicitly 3933 1.1 mrg capture a parameter pack. We want to wait because we don't know if we're 3934 1.1 mrg capturing the whole pack or a single element, and it's OK to wait because 3935 1.1 mrg find_parameter_packs_r walks into the lambda body. */ 3936 1.1 mrg if (context == containing_function 3937 1.1 mrg && DECL_PACK_P (decl)) 3938 1.1 mrg return decl; 3939 1.1 mrg 3940 1.1 mrg if (lambda_expr && VAR_P (decl) && DECL_ANON_UNION_VAR_P (decl)) 3941 1.1 mrg { 3942 1.1 mrg if (complain & tf_error) 3943 1.1 mrg error ("cannot capture member %qD of anonymous union", decl); 3944 1.1 mrg return error_mark_node; 3945 1.1 mrg } 3946 1.1 mrg /* Do lambda capture when processing the id-expression, not when 3947 1.1 mrg odr-using a variable. */ 3948 1.1 mrg if (!odr_use && context == containing_function) 3949 1.1 mrg decl = add_default_capture (lambda_stack, 3950 1.1 mrg /*id=*/DECL_NAME (decl), initializer); 3951 1.1 mrg /* Only an odr-use of an outer automatic variable causes an 3952 1.1 mrg error, and a constant variable can decay to a prvalue 3953 1.1 mrg constant without odr-use. So don't complain yet. */ 3954 1.1 mrg else if (!odr_use && decl_constant_var_p (decl)) 3955 1.1 mrg return decl; 3956 1.1 mrg else if (lambda_expr) 3957 1.1 mrg { 3958 1.1 mrg if (complain & tf_error) 3959 1.1 mrg { 3960 1.1 mrg error ("%qD is not captured", decl); 3961 1.1 mrg tree closure = LAMBDA_EXPR_CLOSURE (lambda_expr); 3962 1.1 mrg if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE) 3963 1.1 mrg inform (location_of (closure), 3964 1.1 mrg "the lambda has no capture-default"); 3965 1.1 mrg else if (TYPE_CLASS_SCOPE_P (closure)) 3966 1.1 mrg inform (UNKNOWN_LOCATION, "lambda in local class %q+T cannot " 3967 1.1 mrg "capture variables from the enclosing context", 3968 1.1 mrg TYPE_CONTEXT (closure)); 3969 1.1 mrg inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl); 3970 1.1 mrg } 3971 1.1 mrg return error_mark_node; 3972 1.1 mrg } 3973 1.1 mrg else 3974 1.1 mrg { 3975 1.1 mrg if (complain & tf_error) 3976 1.1 mrg { 3977 1.1 mrg error (VAR_P (decl) 3978 1.1 mrg ? G_("use of local variable with automatic storage from " 3979 1.1 mrg "containing function") 3980 1.1 mrg : G_("use of parameter from containing function")); 3981 1.1 mrg inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl); 3982 1.1 mrg } 3983 1.1 mrg return error_mark_node; 3984 1.1 mrg } 3985 1.1 mrg return decl; 3986 1.1 mrg } 3987 1.1 mrg 3988 1.1 mrg /* ID_EXPRESSION is a representation of parsed, but unprocessed, 3989 1.1 mrg id-expression. (See cp_parser_id_expression for details.) SCOPE, 3990 1.1 mrg if non-NULL, is the type or namespace used to explicitly qualify 3991 1.1 mrg ID_EXPRESSION. DECL is the entity to which that name has been 3992 1.1 mrg resolved. 3993 1.1 mrg 3994 1.1 mrg *CONSTANT_EXPRESSION_P is true if we are presently parsing a 3995 1.1 mrg constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will 3996 1.1 mrg be set to true if this expression isn't permitted in a 3997 1.1 mrg constant-expression, but it is otherwise not set by this function. 3998 1.1 mrg *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a 3999 1.1 mrg constant-expression, but a non-constant expression is also 4000 1.1 mrg permissible. 4001 1.1 mrg 4002 1.1 mrg DONE is true if this expression is a complete postfix-expression; 4003 1.1 mrg it is false if this expression is followed by '->', '[', '(', etc. 4004 1.1 mrg ADDRESS_P is true iff this expression is the operand of '&'. 4005 1.1 mrg TEMPLATE_P is true iff the qualified-id was of the form 4006 1.1 mrg "A::template B". TEMPLATE_ARG_P is true iff this qualified name 4007 1.1 mrg appears as a template argument. 4008 1.1 mrg 4009 1.1 mrg If an error occurs, and it is the kind of error that might cause 4010 1.1 mrg the parser to abort a tentative parse, *ERROR_MSG is filled in. It 4011 1.1 mrg is the caller's responsibility to issue the message. *ERROR_MSG 4012 1.1 mrg will be a string with static storage duration, so the caller need 4013 1.1 mrg not "free" it. 4014 1.1 mrg 4015 1.1 mrg Return an expression for the entity, after issuing appropriate 4016 1.1 mrg diagnostics. This function is also responsible for transforming a 4017 1.1 mrg reference to a non-static member into a COMPONENT_REF that makes 4018 1.1 mrg the use of "this" explicit. 4019 1.1 mrg 4020 1.1 mrg Upon return, *IDK will be filled in appropriately. */ 4021 1.1 mrg static cp_expr 4022 1.1 mrg finish_id_expression_1 (tree id_expression, 4023 1.1 mrg tree decl, 4024 1.1 mrg tree scope, 4025 1.1 mrg cp_id_kind *idk, 4026 1.1 mrg bool integral_constant_expression_p, 4027 1.1 mrg bool allow_non_integral_constant_expression_p, 4028 1.1 mrg bool *non_integral_constant_expression_p, 4029 1.1 mrg bool template_p, 4030 1.1 mrg bool done, 4031 1.1 mrg bool address_p, 4032 1.1 mrg bool template_arg_p, 4033 1.1 mrg const char **error_msg, 4034 1.1 mrg location_t location) 4035 1.1 mrg { 4036 1.1 mrg decl = strip_using_decl (decl); 4037 1.1 mrg 4038 1.1 mrg /* Initialize the output parameters. */ 4039 1.1 mrg *idk = CP_ID_KIND_NONE; 4040 1.1 mrg *error_msg = NULL; 4041 1.1 mrg 4042 1.1 mrg if (id_expression == error_mark_node) 4043 1.1 mrg return error_mark_node; 4044 1.1 mrg /* If we have a template-id, then no further lookup is 4045 1.1 mrg required. If the template-id was for a template-class, we 4046 1.1 mrg will sometimes have a TYPE_DECL at this point. */ 4047 1.1 mrg else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR 4048 1.1 mrg || TREE_CODE (decl) == TYPE_DECL) 4049 1.1 mrg ; 4050 1.1 mrg /* Look up the name. */ 4051 1.1 mrg else 4052 1.1 mrg { 4053 1.1 mrg if (decl == error_mark_node) 4054 1.1 mrg { 4055 1.1 mrg /* Name lookup failed. */ 4056 1.1 mrg if (scope 4057 1.1 mrg && (!TYPE_P (scope) 4058 1.1 mrg || (!dependent_type_p (scope) 4059 1.1 mrg && !(identifier_p (id_expression) 4060 1.1 mrg && IDENTIFIER_CONV_OP_P (id_expression) 4061 1.1 mrg && dependent_type_p (TREE_TYPE (id_expression)))))) 4062 1.1 mrg { 4063 1.1 mrg /* If the qualifying type is non-dependent (and the name 4064 1.1 mrg does not name a conversion operator to a dependent 4065 1.1 mrg type), issue an error. */ 4066 1.1 mrg qualified_name_lookup_error (scope, id_expression, decl, location); 4067 1.1 mrg return error_mark_node; 4068 1.1 mrg } 4069 1.1 mrg else if (!scope) 4070 1.1 mrg { 4071 1.1 mrg /* It may be resolved via Koenig lookup. */ 4072 1.1 mrg *idk = CP_ID_KIND_UNQUALIFIED; 4073 1.1 mrg return id_expression; 4074 1.1 mrg } 4075 1.1 mrg else 4076 1.1 mrg decl = id_expression; 4077 1.1 mrg } 4078 1.1 mrg 4079 1.1 mrg /* Remember that the name was used in the definition of 4080 1.1 mrg the current class so that we can check later to see if 4081 1.1 mrg the meaning would have been different after the class 4082 1.1 mrg was entirely defined. */ 4083 1.1 mrg if (!scope && decl != error_mark_node && identifier_p (id_expression)) 4084 1.1 mrg maybe_note_name_used_in_class (id_expression, decl); 4085 1.1 mrg 4086 1.1 mrg /* A use in unevaluated operand might not be instantiated appropriately 4087 1.1 mrg if tsubst_copy builds a dummy parm, or if we never instantiate a 4088 1.1 mrg generic lambda, so mark it now. */ 4089 1.1 mrg if (processing_template_decl && cp_unevaluated_operand) 4090 1.1 mrg mark_type_use (decl); 4091 1.1 mrg 4092 1.1 mrg /* Disallow uses of local variables from containing functions, except 4093 1.1 mrg within lambda-expressions. */ 4094 1.1 mrg if (outer_automatic_var_p (decl)) 4095 1.1 mrg { 4096 1.1 mrg decl = process_outer_var_ref (decl, tf_warning_or_error); 4097 1.1 mrg if (decl == error_mark_node) 4098 1.1 mrg return error_mark_node; 4099 1.1 mrg } 4100 1.1 mrg 4101 1.1 mrg /* Also disallow uses of function parameters outside the function 4102 1.1 mrg body, except inside an unevaluated context (i.e. decltype). */ 4103 1.1 mrg if (TREE_CODE (decl) == PARM_DECL 4104 1.1 mrg && DECL_CONTEXT (decl) == NULL_TREE 4105 1.1 mrg && !cp_unevaluated_operand) 4106 1.1 mrg { 4107 1.1 mrg *error_msg = G_("use of parameter outside function body"); 4108 1.1 mrg return error_mark_node; 4109 1.1 mrg } 4110 1.1 mrg } 4111 1.1 mrg 4112 1.1 mrg /* If we didn't find anything, or what we found was a type, 4113 1.1 mrg then this wasn't really an id-expression. */ 4114 1.1 mrg if (TREE_CODE (decl) == TEMPLATE_DECL 4115 1.1 mrg && !DECL_FUNCTION_TEMPLATE_P (decl)) 4116 1.1 mrg { 4117 1.1 mrg *error_msg = G_("missing template arguments"); 4118 1.1 mrg return error_mark_node; 4119 1.1 mrg } 4120 1.1 mrg else if (TREE_CODE (decl) == TYPE_DECL 4121 1.1 mrg || TREE_CODE (decl) == NAMESPACE_DECL) 4122 1.1 mrg { 4123 1.1 mrg *error_msg = G_("expected primary-expression"); 4124 1.1 mrg return error_mark_node; 4125 1.1 mrg } 4126 1.1 mrg 4127 1.1 mrg /* If the name resolved to a template parameter, there is no 4128 1.1 mrg need to look it up again later. */ 4129 1.1 mrg if ((TREE_CODE (decl) == CONST_DECL && DECL_TEMPLATE_PARM_P (decl)) 4130 1.1 mrg || TREE_CODE (decl) == TEMPLATE_PARM_INDEX) 4131 1.1 mrg { 4132 1.1 mrg tree r; 4133 1.1 mrg 4134 1.1 mrg *idk = CP_ID_KIND_NONE; 4135 1.1 mrg if (TREE_CODE (decl) == TEMPLATE_PARM_INDEX) 4136 1.1 mrg decl = TEMPLATE_PARM_DECL (decl); 4137 1.1 mrg r = DECL_INITIAL (decl); 4138 1.1 mrg if (CLASS_TYPE_P (TREE_TYPE (r)) && !CP_TYPE_CONST_P (TREE_TYPE (r))) 4139 1.1 mrg { 4140 1.1 mrg /* If the entity is a template parameter object for a template 4141 1.1 mrg parameter of type T, the type of the expression is const T. */ 4142 1.1 mrg tree ctype = TREE_TYPE (r); 4143 1.1 mrg ctype = cp_build_qualified_type (ctype, (cp_type_quals (ctype) 4144 1.1 mrg | TYPE_QUAL_CONST)); 4145 1.1 mrg r = build1 (VIEW_CONVERT_EXPR, ctype, r); 4146 1.1 mrg } 4147 1.1 mrg r = convert_from_reference (r); 4148 1.1 mrg if (integral_constant_expression_p 4149 1.1 mrg && !dependent_type_p (TREE_TYPE (decl)) 4150 1.1 mrg && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r)))) 4151 1.1 mrg { 4152 1.1 mrg if (!allow_non_integral_constant_expression_p) 4153 1.1 mrg error ("template parameter %qD of type %qT is not allowed in " 4154 1.1 mrg "an integral constant expression because it is not of " 4155 1.1 mrg "integral or enumeration type", decl, TREE_TYPE (decl)); 4156 1.1 mrg *non_integral_constant_expression_p = true; 4157 1.1 mrg } 4158 1.1 mrg return r; 4159 1.1 mrg } 4160 1.1 mrg else 4161 1.1 mrg { 4162 1.1 mrg bool dependent_p = type_dependent_expression_p (decl); 4163 1.1 mrg 4164 1.1 mrg /* If the declaration was explicitly qualified indicate 4165 1.1 mrg that. The semantics of `A::f(3)' are different than 4166 1.1 mrg `f(3)' if `f' is virtual. */ 4167 1.1 mrg *idk = (scope 4168 1.1 mrg ? CP_ID_KIND_QUALIFIED 4169 1.1 mrg : (TREE_CODE (decl) == TEMPLATE_ID_EXPR 4170 1.1 mrg ? CP_ID_KIND_TEMPLATE_ID 4171 1.1 mrg : (dependent_p 4172 1.1 mrg ? CP_ID_KIND_UNQUALIFIED_DEPENDENT 4173 1.1 mrg : CP_ID_KIND_UNQUALIFIED))); 4174 1.1 mrg 4175 1.1 mrg if (dependent_p 4176 1.1 mrg && !scope 4177 1.1 mrg && DECL_P (decl) 4178 1.1 mrg && any_dependent_type_attributes_p (DECL_ATTRIBUTES (decl))) 4179 1.1 mrg /* Dependent type attributes on the decl mean that the TREE_TYPE is 4180 1.1 mrg wrong, so just return the identifier. */ 4181 1.1 mrg return id_expression; 4182 1.1 mrg 4183 1.1 mrg if (DECL_CLASS_TEMPLATE_P (decl)) 4184 1.1 mrg { 4185 1.1 mrg error ("use of class template %qT as expression", decl); 4186 1.1 mrg return error_mark_node; 4187 1.1 mrg } 4188 1.1 mrg 4189 1.1 mrg if (TREE_CODE (decl) == TREE_LIST) 4190 1.1 mrg { 4191 1.1 mrg /* Ambiguous reference to base members. */ 4192 1.1 mrg error ("request for member %qD is ambiguous in " 4193 1.1 mrg "multiple inheritance lattice", id_expression); 4194 1.1 mrg print_candidates (decl); 4195 1.1 mrg return error_mark_node; 4196 1.1 mrg } 4197 1.1 mrg 4198 1.1 mrg /* Mark variable-like entities as used. Functions are similarly 4199 1.1 mrg marked either below or after overload resolution. */ 4200 1.1 mrg if ((VAR_P (decl) 4201 1.1 mrg || TREE_CODE (decl) == PARM_DECL 4202 1.1 mrg || TREE_CODE (decl) == CONST_DECL 4203 1.1 mrg || TREE_CODE (decl) == RESULT_DECL) 4204 1.1 mrg && !mark_used (decl)) 4205 1.1 mrg return error_mark_node; 4206 1.1 mrg 4207 1.1 mrg /* Only certain kinds of names are allowed in constant 4208 1.1 mrg expression. Template parameters have already 4209 1.1 mrg been handled above. */ 4210 1.1 mrg if (! error_operand_p (decl) 4211 1.1 mrg && !dependent_p 4212 1.1 mrg && integral_constant_expression_p 4213 1.1 mrg && !decl_constant_var_p (decl) 4214 1.1 mrg && TREE_CODE (decl) != CONST_DECL 4215 1.1 mrg && !builtin_valid_in_constant_expr_p (decl) 4216 1.1 mrg && !concept_check_p (decl)) 4217 1.1 mrg { 4218 1.1 mrg if (!allow_non_integral_constant_expression_p) 4219 1.1 mrg { 4220 1.1 mrg error ("%qD cannot appear in a constant-expression", decl); 4221 1.1 mrg return error_mark_node; 4222 1.1 mrg } 4223 1.1 mrg *non_integral_constant_expression_p = true; 4224 1.1 mrg } 4225 1.1 mrg 4226 1.1 mrg if (tree wrap = maybe_get_tls_wrapper_call (decl)) 4227 1.1 mrg /* Replace an evaluated use of the thread_local variable with 4228 1.1 mrg a call to its wrapper. */ 4229 1.1 mrg decl = wrap; 4230 1.1 mrg else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR 4231 1.1 mrg && !dependent_p 4232 1.1 mrg && variable_template_p (TREE_OPERAND (decl, 0)) 4233 1.1 mrg && !concept_check_p (decl)) 4234 1.1 mrg { 4235 1.1 mrg decl = finish_template_variable (decl); 4236 1.1 mrg mark_used (decl); 4237 1.1 mrg decl = convert_from_reference (decl); 4238 1.1 mrg } 4239 1.1 mrg else if (concept_check_p (decl)) 4240 1.1 mrg { 4241 1.1 mrg /* Nothing more to do. All of the analysis for concept checks 4242 1.1 mrg is done by build_conept_id, called from the parser. */ 4243 1.1 mrg } 4244 1.1 mrg else if (scope) 4245 1.1 mrg { 4246 1.1 mrg if (TREE_CODE (decl) == SCOPE_REF) 4247 1.1 mrg { 4248 1.1 mrg gcc_assert (same_type_p (scope, TREE_OPERAND (decl, 0))); 4249 1.1 mrg decl = TREE_OPERAND (decl, 1); 4250 1.1 mrg } 4251 1.1 mrg 4252 1.1 mrg decl = (adjust_result_of_qualified_name_lookup 4253 1.1 mrg (decl, scope, current_nonlambda_class_type())); 4254 1.1 mrg 4255 1.1 mrg cp_warn_deprecated_use_scopes (scope); 4256 1.1 mrg 4257 1.1 mrg if (TYPE_P (scope)) 4258 1.1 mrg decl = finish_qualified_id_expr (scope, 4259 1.1 mrg decl, 4260 1.1 mrg done, 4261 1.1 mrg address_p, 4262 1.1 mrg template_p, 4263 1.1 mrg template_arg_p, 4264 1.1 mrg tf_warning_or_error); 4265 1.1 mrg else 4266 1.1 mrg decl = convert_from_reference (decl); 4267 1.1 mrg } 4268 1.1 mrg else if (TREE_CODE (decl) == FIELD_DECL) 4269 1.1 mrg { 4270 1.1 mrg /* Since SCOPE is NULL here, this is an unqualified name. 4271 1.1 mrg Access checking has been performed during name lookup 4272 1.1 mrg already. Turn off checking to avoid duplicate errors. */ 4273 1.1 mrg push_deferring_access_checks (dk_no_check); 4274 1.1 mrg decl = finish_non_static_data_member (decl, NULL_TREE, 4275 1.1 mrg /*qualifying_scope=*/NULL_TREE); 4276 1.1 mrg pop_deferring_access_checks (); 4277 1.1 mrg } 4278 1.1 mrg else if (is_overloaded_fn (decl)) 4279 1.1 mrg { 4280 1.1 mrg /* We only need to look at the first function, 4281 1.1 mrg because all the fns share the attribute we're 4282 1.1 mrg concerned with (all member fns or all non-members). */ 4283 1.1 mrg tree first_fn = get_first_fn (decl); 4284 1.1 mrg first_fn = STRIP_TEMPLATE (first_fn); 4285 1.1 mrg 4286 1.1 mrg if (!template_arg_p 4287 1.1 mrg && (TREE_CODE (first_fn) == USING_DECL 4288 1.1 mrg || (TREE_CODE (first_fn) == FUNCTION_DECL 4289 1.1 mrg && DECL_FUNCTION_MEMBER_P (first_fn) 4290 1.1 mrg && !shared_member_p (decl)))) 4291 1.1 mrg { 4292 1.1 mrg /* A set of member functions. */ 4293 1.1 mrg decl = maybe_dummy_object (DECL_CONTEXT (first_fn), 0); 4294 1.1 mrg return finish_class_member_access_expr (decl, id_expression, 4295 1.1 mrg /*template_p=*/false, 4296 1.1 mrg tf_warning_or_error); 4297 1.1 mrg } 4298 1.1 mrg 4299 1.1 mrg decl = baselink_for_fns (decl); 4300 1.1 mrg } 4301 1.1 mrg else 4302 1.1 mrg { 4303 1.1 mrg if (DECL_P (decl) && DECL_NONLOCAL (decl) 4304 1.1 mrg && DECL_CLASS_SCOPE_P (decl)) 4305 1.1 mrg { 4306 1.1 mrg tree context = context_for_name_lookup (decl); 4307 1.1 mrg if (context != current_class_type) 4308 1.1 mrg { 4309 1.1 mrg tree path = currently_open_derived_class (context); 4310 1.1 mrg if (!path) 4311 1.1 mrg /* PATH can be null for using an enum of an unrelated 4312 1.1 mrg class; we checked its access in lookup_using_decl. 4313 1.1 mrg 4314 1.1 mrg ??? Should this case make a clone instead, like 4315 1.1 mrg handle_using_decl? */ 4316 1.1 mrg gcc_assert (TREE_CODE (decl) == CONST_DECL); 4317 1.1 mrg else 4318 1.1 mrg perform_or_defer_access_check (TYPE_BINFO (path), 4319 1.1 mrg decl, decl, 4320 1.1 mrg tf_warning_or_error); 4321 1.1 mrg } 4322 1.1 mrg } 4323 1.1 mrg 4324 1.1 mrg decl = convert_from_reference (decl); 4325 1.1 mrg } 4326 1.1 mrg } 4327 1.1 mrg 4328 1.1 mrg return cp_expr (decl, location); 4329 1.1 mrg } 4330 1.1 mrg 4331 1.1 mrg /* As per finish_id_expression_1, but adding a wrapper node 4332 1.1 mrg around the result if needed to express LOCATION. */ 4333 1.1 mrg 4334 1.1 mrg cp_expr 4335 1.1 mrg finish_id_expression (tree id_expression, 4336 1.1 mrg tree decl, 4337 1.1 mrg tree scope, 4338 1.1 mrg cp_id_kind *idk, 4339 1.1 mrg bool integral_constant_expression_p, 4340 1.1 mrg bool allow_non_integral_constant_expression_p, 4341 1.1 mrg bool *non_integral_constant_expression_p, 4342 1.1 mrg bool template_p, 4343 1.1 mrg bool done, 4344 1.1 mrg bool address_p, 4345 1.1 mrg bool template_arg_p, 4346 1.1 mrg const char **error_msg, 4347 1.1 mrg location_t location) 4348 1.1 mrg { 4349 1.1 mrg cp_expr result 4350 1.1 mrg = finish_id_expression_1 (id_expression, decl, scope, idk, 4351 1.1 mrg integral_constant_expression_p, 4352 1.1 mrg allow_non_integral_constant_expression_p, 4353 1.1 mrg non_integral_constant_expression_p, 4354 1.1 mrg template_p, done, address_p, template_arg_p, 4355 1.1 mrg error_msg, location); 4356 1.1 mrg return result.maybe_add_location_wrapper (); 4357 1.1 mrg } 4358 1.1 mrg 4359 1.1 mrg /* Implement the __typeof keyword: Return the type of EXPR, suitable for 4360 1.1 mrg use as a type-specifier. */ 4361 1.1 mrg 4362 1.1 mrg tree 4363 1.1 mrg finish_typeof (tree expr) 4364 1.1 mrg { 4365 1.1 mrg tree type; 4366 1.1 mrg 4367 1.1 mrg if (type_dependent_expression_p (expr)) 4368 1.1 mrg { 4369 1.1 mrg type = cxx_make_type (TYPEOF_TYPE); 4370 1.1 mrg TYPEOF_TYPE_EXPR (type) = expr; 4371 1.1 mrg SET_TYPE_STRUCTURAL_EQUALITY (type); 4372 1.1 mrg 4373 1.1 mrg return type; 4374 1.1 mrg } 4375 1.1 mrg 4376 1.1 mrg expr = mark_type_use (expr); 4377 1.1 mrg 4378 1.1 mrg type = unlowered_expr_type (expr); 4379 1.1 mrg 4380 1.1 mrg if (!type || type == unknown_type_node) 4381 1.1 mrg { 4382 1.1 mrg error ("type of %qE is unknown", expr); 4383 1.1 mrg return error_mark_node; 4384 1.1 mrg } 4385 1.1 mrg 4386 1.1 mrg return type; 4387 1.1 mrg } 4388 1.1 mrg 4389 1.1 mrg /* Implement the __underlying_type keyword: Return the underlying 4390 1.1 mrg type of TYPE, suitable for use as a type-specifier. */ 4391 1.1 mrg 4392 1.1 mrg tree 4393 1.1 mrg finish_underlying_type (tree type) 4394 1.1 mrg { 4395 1.1 mrg tree underlying_type; 4396 1.1 mrg 4397 1.1 mrg if (processing_template_decl) 4398 1.1 mrg { 4399 1.1 mrg underlying_type = cxx_make_type (UNDERLYING_TYPE); 4400 1.1 mrg UNDERLYING_TYPE_TYPE (underlying_type) = type; 4401 1.1 mrg SET_TYPE_STRUCTURAL_EQUALITY (underlying_type); 4402 1.1 mrg 4403 1.1 mrg return underlying_type; 4404 1.1 mrg } 4405 1.1 mrg 4406 1.1 mrg if (!complete_type_or_else (type, NULL_TREE)) 4407 1.1 mrg return error_mark_node; 4408 1.1 mrg 4409 1.1 mrg if (TREE_CODE (type) != ENUMERAL_TYPE) 4410 1.1 mrg { 4411 1.1 mrg error ("%qT is not an enumeration type", type); 4412 1.1 mrg return error_mark_node; 4413 1.1 mrg } 4414 1.1 mrg 4415 1.1 mrg underlying_type = ENUM_UNDERLYING_TYPE (type); 4416 1.1 mrg 4417 1.1 mrg /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE 4418 1.1 mrg includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information. 4419 1.1 mrg See finish_enum_value_list for details. */ 4420 1.1 mrg if (!ENUM_FIXED_UNDERLYING_TYPE_P (type)) 4421 1.1 mrg underlying_type 4422 1.1 mrg = c_common_type_for_mode (TYPE_MODE (underlying_type), 4423 1.1 mrg TYPE_UNSIGNED (underlying_type)); 4424 1.1 mrg 4425 1.1 mrg return underlying_type; 4426 1.1 mrg } 4427 1.1 mrg 4428 1.1 mrg /* Implement the __direct_bases keyword: Return the direct base classes 4429 1.1 mrg of type. */ 4430 1.1 mrg 4431 1.1 mrg tree 4432 1.1 mrg calculate_direct_bases (tree type, tsubst_flags_t complain) 4433 1.1 mrg { 4434 1.1 mrg if (!complete_type_or_maybe_complain (type, NULL_TREE, complain) 4435 1.1 mrg || !NON_UNION_CLASS_TYPE_P (type)) 4436 1.1 mrg return make_tree_vec (0); 4437 1.1 mrg 4438 1.1 mrg releasing_vec vector; 4439 1.1 mrg vec<tree, va_gc> *base_binfos = BINFO_BASE_BINFOS (TYPE_BINFO (type)); 4440 1.1 mrg tree binfo; 4441 1.1 mrg unsigned i; 4442 1.1 mrg 4443 1.1 mrg /* Virtual bases are initialized first */ 4444 1.1 mrg for (i = 0; base_binfos->iterate (i, &binfo); i++) 4445 1.1 mrg if (BINFO_VIRTUAL_P (binfo)) 4446 1.1 mrg vec_safe_push (vector, binfo); 4447 1.1 mrg 4448 1.1 mrg /* Now non-virtuals */ 4449 1.1 mrg for (i = 0; base_binfos->iterate (i, &binfo); i++) 4450 1.1 mrg if (!BINFO_VIRTUAL_P (binfo)) 4451 1.1 mrg vec_safe_push (vector, binfo); 4452 1.1 mrg 4453 1.1 mrg tree bases_vec = make_tree_vec (vector->length ()); 4454 1.1 mrg 4455 1.1 mrg for (i = 0; i < vector->length (); ++i) 4456 1.1 mrg TREE_VEC_ELT (bases_vec, i) = BINFO_TYPE ((*vector)[i]); 4457 1.1 mrg 4458 1.1 mrg return bases_vec; 4459 1.1 mrg } 4460 1.1 mrg 4461 1.1 mrg /* Implement the __bases keyword: Return the base classes 4462 1.1 mrg of type */ 4463 1.1 mrg 4464 1.1 mrg /* Find morally non-virtual base classes by walking binfo hierarchy */ 4465 1.1 mrg /* Virtual base classes are handled separately in finish_bases */ 4466 1.1 mrg 4467 1.1 mrg static tree 4468 1.1 mrg dfs_calculate_bases_pre (tree binfo, void * /*data_*/) 4469 1.1 mrg { 4470 1.1 mrg /* Don't walk bases of virtual bases */ 4471 1.1 mrg return BINFO_VIRTUAL_P (binfo) ? dfs_skip_bases : NULL_TREE; 4472 1.1 mrg } 4473 1.1 mrg 4474 1.1 mrg static tree 4475 1.1 mrg dfs_calculate_bases_post (tree binfo, void *data_) 4476 1.1 mrg { 4477 1.1 mrg vec<tree, va_gc> **data = ((vec<tree, va_gc> **) data_); 4478 1.1 mrg if (!BINFO_VIRTUAL_P (binfo)) 4479 1.1 mrg vec_safe_push (*data, BINFO_TYPE (binfo)); 4480 1.1 mrg return NULL_TREE; 4481 1.1 mrg } 4482 1.1 mrg 4483 1.1 mrg /* Calculates the morally non-virtual base classes of a class */ 4484 1.1 mrg static vec<tree, va_gc> * 4485 1.1 mrg calculate_bases_helper (tree type) 4486 1.1 mrg { 4487 1.1 mrg vec<tree, va_gc> *vector = make_tree_vector (); 4488 1.1 mrg 4489 1.1 mrg /* Now add non-virtual base classes in order of construction */ 4490 1.1 mrg if (TYPE_BINFO (type)) 4491 1.1 mrg dfs_walk_all (TYPE_BINFO (type), 4492 1.1 mrg dfs_calculate_bases_pre, dfs_calculate_bases_post, &vector); 4493 1.1 mrg return vector; 4494 1.1 mrg } 4495 1.1 mrg 4496 1.1 mrg tree 4497 1.1 mrg calculate_bases (tree type, tsubst_flags_t complain) 4498 1.1 mrg { 4499 1.1 mrg if (!complete_type_or_maybe_complain (type, NULL_TREE, complain) 4500 1.1 mrg || !NON_UNION_CLASS_TYPE_P (type)) 4501 1.1 mrg return make_tree_vec (0); 4502 1.1 mrg 4503 1.1 mrg releasing_vec vector; 4504 1.1 mrg tree bases_vec = NULL_TREE; 4505 1.1 mrg unsigned i; 4506 1.1 mrg vec<tree, va_gc> *vbases; 4507 1.1 mrg tree binfo; 4508 1.1 mrg 4509 1.1 mrg /* First go through virtual base classes */ 4510 1.1 mrg for (vbases = CLASSTYPE_VBASECLASSES (type), i = 0; 4511 1.1 mrg vec_safe_iterate (vbases, i, &binfo); i++) 4512 1.1 mrg { 4513 1.1 mrg releasing_vec vbase_bases 4514 1.1 mrg = calculate_bases_helper (BINFO_TYPE (binfo)); 4515 1.1 mrg vec_safe_splice (vector, vbase_bases); 4516 1.1 mrg } 4517 1.1 mrg 4518 1.1 mrg /* Now for the non-virtual bases */ 4519 1.1 mrg releasing_vec nonvbases = calculate_bases_helper (type); 4520 1.1 mrg vec_safe_splice (vector, nonvbases); 4521 1.1 mrg 4522 1.1 mrg /* Note that during error recovery vector->length can even be zero. */ 4523 1.1 mrg if (vector->length () > 1) 4524 1.1 mrg { 4525 1.1 mrg /* Last element is entire class, so don't copy */ 4526 1.1 mrg bases_vec = make_tree_vec (vector->length () - 1); 4527 1.1 mrg 4528 1.1 mrg for (i = 0; i < vector->length () - 1; ++i) 4529 1.1 mrg TREE_VEC_ELT (bases_vec, i) = (*vector)[i]; 4530 1.1 mrg } 4531 1.1 mrg else 4532 1.1 mrg bases_vec = make_tree_vec (0); 4533 1.1 mrg 4534 1.1 mrg return bases_vec; 4535 1.1 mrg } 4536 1.1 mrg 4537 1.1 mrg tree 4538 1.1 mrg finish_bases (tree type, bool direct) 4539 1.1 mrg { 4540 1.1 mrg tree bases = NULL_TREE; 4541 1.1 mrg 4542 1.1 mrg if (!processing_template_decl) 4543 1.1 mrg { 4544 1.1 mrg /* Parameter packs can only be used in templates */ 4545 1.1 mrg error ("parameter pack %<__bases%> only valid in template declaration"); 4546 1.1 mrg return error_mark_node; 4547 1.1 mrg } 4548 1.1 mrg 4549 1.1 mrg bases = cxx_make_type (BASES); 4550 1.1 mrg BASES_TYPE (bases) = type; 4551 1.1 mrg BASES_DIRECT (bases) = direct; 4552 1.1 mrg SET_TYPE_STRUCTURAL_EQUALITY (bases); 4553 1.1 mrg 4554 1.1 mrg return bases; 4555 1.1 mrg } 4556 1.1 mrg 4557 1.1 mrg /* Perform C++-specific checks for __builtin_offsetof before calling 4558 1.1 mrg fold_offsetof. */ 4559 1.1 mrg 4560 1.1 mrg tree 4561 1.1 mrg finish_offsetof (tree object_ptr, tree expr, location_t loc) 4562 1.1 mrg { 4563 1.1 mrg /* If we're processing a template, we can't finish the semantics yet. 4564 1.1 mrg Otherwise we can fold the entire expression now. */ 4565 1.1 mrg if (processing_template_decl) 4566 1.1 mrg { 4567 1.1 mrg expr = build2 (OFFSETOF_EXPR, size_type_node, expr, object_ptr); 4568 1.1 mrg SET_EXPR_LOCATION (expr, loc); 4569 1.1 mrg return expr; 4570 1.1 mrg } 4571 1.1 mrg 4572 1.1 mrg if (expr == error_mark_node) 4573 1.1 mrg return error_mark_node; 4574 1.1 mrg 4575 1.1 mrg if (TREE_CODE (expr) == PSEUDO_DTOR_EXPR) 4576 1.1 mrg { 4577 1.1 mrg error ("cannot apply %<offsetof%> to destructor %<~%T%>", 4578 1.1 mrg TREE_OPERAND (expr, 2)); 4579 1.1 mrg return error_mark_node; 4580 1.1 mrg } 4581 1.1 mrg if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (expr)) 4582 1.1 mrg || TREE_TYPE (expr) == unknown_type_node) 4583 1.1 mrg { 4584 1.1 mrg while (TREE_CODE (expr) == COMPONENT_REF 4585 1.1 mrg || TREE_CODE (expr) == COMPOUND_EXPR) 4586 1.1 mrg expr = TREE_OPERAND (expr, 1); 4587 1.1 mrg 4588 1.1 mrg if (DECL_P (expr)) 4589 1.1 mrg { 4590 1.1 mrg error ("cannot apply %<offsetof%> to member function %qD", expr); 4591 1.1 mrg inform (DECL_SOURCE_LOCATION (expr), "declared here"); 4592 1.1 mrg } 4593 1.1 mrg else 4594 1.1 mrg error ("cannot apply %<offsetof%> to member function"); 4595 1.1 mrg return error_mark_node; 4596 1.1 mrg } 4597 1.1 mrg if (TREE_CODE (expr) == CONST_DECL) 4598 1.1 mrg { 4599 1.1 mrg error ("cannot apply %<offsetof%> to an enumerator %qD", expr); 4600 1.1 mrg return error_mark_node; 4601 1.1 mrg } 4602 1.1 mrg if (REFERENCE_REF_P (expr)) 4603 1.1 mrg expr = TREE_OPERAND (expr, 0); 4604 1.1 mrg if (!complete_type_or_else (TREE_TYPE (TREE_TYPE (object_ptr)), object_ptr)) 4605 1.1 mrg return error_mark_node; 4606 1.1 mrg if (warn_invalid_offsetof 4607 1.1 mrg && CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (object_ptr))) 4608 1.1 mrg && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (TREE_TYPE (object_ptr))) 4609 1.1 mrg && cp_unevaluated_operand == 0) 4610 1.1 mrg warning_at (loc, OPT_Winvalid_offsetof, "%<offsetof%> within " 4611 1.1 mrg "non-standard-layout type %qT is conditionally-supported", 4612 1.1 mrg TREE_TYPE (TREE_TYPE (object_ptr))); 4613 1.1 mrg return fold_offsetof (expr); 4614 1.1 mrg } 4615 1.1 mrg 4616 1.1 mrg /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This 4617 1.1 mrg function is broken out from the above for the benefit of the tree-ssa 4618 1.1 mrg project. */ 4619 1.1 mrg 4620 1.1 mrg void 4621 1.1 mrg simplify_aggr_init_expr (tree *tp) 4622 1.1 mrg { 4623 1.1 mrg tree aggr_init_expr = *tp; 4624 1.1 mrg 4625 1.1 mrg /* Form an appropriate CALL_EXPR. */ 4626 1.1 mrg tree fn = AGGR_INIT_EXPR_FN (aggr_init_expr); 4627 1.1 mrg tree slot = AGGR_INIT_EXPR_SLOT (aggr_init_expr); 4628 1.1 mrg tree type = TREE_TYPE (slot); 4629 1.1 mrg 4630 1.1 mrg tree call_expr; 4631 1.1 mrg enum style_t { ctor, arg, pcc } style; 4632 1.1 mrg 4633 1.1 mrg if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr)) 4634 1.1 mrg style = ctor; 4635 1.1 mrg #ifdef PCC_STATIC_STRUCT_RETURN 4636 1.1 mrg else if (1) 4637 1.1 mrg style = pcc; 4638 1.1 mrg #endif 4639 1.1 mrg else 4640 1.1 mrg { 4641 1.1 mrg gcc_assert (TREE_ADDRESSABLE (type)); 4642 1.1 mrg style = arg; 4643 1.1 mrg } 4644 1.1 mrg 4645 1.1 mrg call_expr = build_call_array_loc (input_location, 4646 1.1 mrg TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))), 4647 1.1 mrg fn, 4648 1.1 mrg aggr_init_expr_nargs (aggr_init_expr), 4649 1.1 mrg AGGR_INIT_EXPR_ARGP (aggr_init_expr)); 4650 1.1 mrg TREE_NOTHROW (call_expr) = TREE_NOTHROW (aggr_init_expr); 4651 1.1 mrg CALL_FROM_THUNK_P (call_expr) = AGGR_INIT_FROM_THUNK_P (aggr_init_expr); 4652 1.1 mrg CALL_EXPR_OPERATOR_SYNTAX (call_expr) 4653 1.1 mrg = CALL_EXPR_OPERATOR_SYNTAX (aggr_init_expr); 4654 1.1 mrg CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (aggr_init_expr); 4655 1.1 mrg CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (aggr_init_expr); 4656 1.1 mrg 4657 1.1 mrg if (style == ctor) 4658 1.1 mrg { 4659 1.1 mrg /* Replace the first argument to the ctor with the address of the 4660 1.1 mrg slot. */ 4661 1.1 mrg cxx_mark_addressable (slot); 4662 1.1 mrg CALL_EXPR_ARG (call_expr, 0) = 4663 1.1 mrg build1 (ADDR_EXPR, build_pointer_type (type), slot); 4664 1.1 mrg } 4665 1.1 mrg else if (style == arg) 4666 1.1 mrg { 4667 1.1 mrg /* Just mark it addressable here, and leave the rest to 4668 1.1 mrg expand_call{,_inline}. */ 4669 1.1 mrg cxx_mark_addressable (slot); 4670 1.1 mrg CALL_EXPR_RETURN_SLOT_OPT (call_expr) = true; 4671 1.1 mrg call_expr = build2 (INIT_EXPR, TREE_TYPE (call_expr), slot, call_expr); 4672 1.1 mrg } 4673 1.1 mrg else if (style == pcc) 4674 1.1 mrg { 4675 1.1 mrg /* If we're using the non-reentrant PCC calling convention, then we 4676 1.1 mrg need to copy the returned value out of the static buffer into the 4677 1.1 mrg SLOT. */ 4678 1.1 mrg push_deferring_access_checks (dk_no_check); 4679 1.1 mrg call_expr = build_aggr_init (slot, call_expr, 4680 1.1 mrg DIRECT_BIND | LOOKUP_ONLYCONVERTING, 4681 1.1 mrg tf_warning_or_error); 4682 1.1 mrg pop_deferring_access_checks (); 4683 1.1 mrg call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (slot), call_expr, slot); 4684 1.1 mrg } 4685 1.1 mrg 4686 1.1 mrg if (AGGR_INIT_ZERO_FIRST (aggr_init_expr)) 4687 1.1 mrg { 4688 1.1 mrg tree init = build_zero_init (type, NULL_TREE, 4689 1.1 mrg /*static_storage_p=*/false); 4690 1.1 mrg init = build2 (INIT_EXPR, void_type_node, slot, init); 4691 1.1 mrg call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (call_expr), 4692 1.1 mrg init, call_expr); 4693 1.1 mrg } 4694 1.1 mrg 4695 1.1 mrg *tp = call_expr; 4696 1.1 mrg } 4697 1.1 mrg 4698 1.1 mrg /* Emit all thunks to FN that should be emitted when FN is emitted. */ 4699 1.1 mrg 4700 1.1 mrg void 4701 1.1 mrg emit_associated_thunks (tree fn) 4702 1.1 mrg { 4703 1.1 mrg /* When we use vcall offsets, we emit thunks with the virtual 4704 1.1 mrg functions to which they thunk. The whole point of vcall offsets 4705 1.1 mrg is so that you can know statically the entire set of thunks that 4706 1.1 mrg will ever be needed for a given virtual function, thereby 4707 1.1 mrg enabling you to output all the thunks with the function itself. */ 4708 1.1 mrg if (DECL_VIRTUAL_P (fn) 4709 1.1 mrg /* Do not emit thunks for extern template instantiations. */ 4710 1.1 mrg && ! DECL_REALLY_EXTERN (fn) 4711 1.1 mrg /* Do not emit thunks for tentative decls, those will be processed 4712 1.1 mrg again at_eof if really needed. */ 4713 1.1 mrg && (DECL_INTERFACE_KNOWN (fn) || !DECL_DEFER_OUTPUT (fn))) 4714 1.1 mrg { 4715 1.1 mrg tree thunk; 4716 1.1 mrg 4717 1.1 mrg for (thunk = DECL_THUNKS (fn); thunk; thunk = DECL_CHAIN (thunk)) 4718 1.1 mrg { 4719 1.1 mrg if (!THUNK_ALIAS (thunk)) 4720 1.1 mrg { 4721 1.1 mrg use_thunk (thunk, /*emit_p=*/1); 4722 1.1 mrg if (DECL_RESULT_THUNK_P (thunk)) 4723 1.1 mrg { 4724 1.1 mrg tree probe; 4725 1.1 mrg 4726 1.1 mrg for (probe = DECL_THUNKS (thunk); 4727 1.1 mrg probe; probe = DECL_CHAIN (probe)) 4728 1.1 mrg use_thunk (probe, /*emit_p=*/1); 4729 1.1 mrg } 4730 1.1 mrg } 4731 1.1 mrg else 4732 1.1 mrg gcc_assert (!DECL_THUNKS (thunk)); 4733 1.1 mrg } 4734 1.1 mrg } 4735 1.1 mrg } 4736 1.1 mrg 4737 1.1 mrg /* Generate RTL for FN. */ 4738 1.1 mrg 4739 1.1 mrg bool 4740 1.1 mrg expand_or_defer_fn_1 (tree fn) 4741 1.1 mrg { 4742 1.1 mrg /* When the parser calls us after finishing the body of a template 4743 1.1 mrg function, we don't really want to expand the body. */ 4744 1.1 mrg if (processing_template_decl) 4745 1.1 mrg { 4746 1.1 mrg /* Normally, collection only occurs in rest_of_compilation. So, 4747 1.1 mrg if we don't collect here, we never collect junk generated 4748 1.1 mrg during the processing of templates until we hit a 4749 1.1 mrg non-template function. It's not safe to do this inside a 4750 1.1 mrg nested class, though, as the parser may have local state that 4751 1.1 mrg is not a GC root. */ 4752 1.1 mrg if (!function_depth) 4753 1.1 mrg ggc_collect (); 4754 1.1 mrg return false; 4755 1.1 mrg } 4756 1.1 mrg 4757 1.1 mrg gcc_assert (DECL_SAVED_TREE (fn)); 4758 1.1 mrg 4759 1.1 mrg /* We make a decision about linkage for these functions at the end 4760 1.1 mrg of the compilation. Until that point, we do not want the back 4761 1.1 mrg end to output them -- but we do want it to see the bodies of 4762 1.1 mrg these functions so that it can inline them as appropriate. */ 4763 1.1 mrg if (DECL_DECLARED_INLINE_P (fn) || DECL_IMPLICIT_INSTANTIATION (fn)) 4764 1.1 mrg { 4765 1.1 mrg if (DECL_INTERFACE_KNOWN (fn)) 4766 1.1 mrg /* We've already made a decision as to how this function will 4767 1.1 mrg be handled. */; 4768 1.1 mrg else if (!at_eof 4769 1.1 mrg || DECL_IMMEDIATE_FUNCTION_P (fn) 4770 1.1 mrg || DECL_OMP_DECLARE_REDUCTION_P (fn)) 4771 1.1 mrg tentative_decl_linkage (fn); 4772 1.1 mrg else 4773 1.1 mrg import_export_decl (fn); 4774 1.1 mrg 4775 1.1 mrg /* If the user wants us to keep all inline functions, then mark 4776 1.1 mrg this function as needed so that finish_file will make sure to 4777 1.1 mrg output it later. Similarly, all dllexport'd functions must 4778 1.1 mrg be emitted; there may be callers in other DLLs. */ 4779 1.1 mrg if (DECL_DECLARED_INLINE_P (fn) 4780 1.1 mrg && !DECL_REALLY_EXTERN (fn) 4781 1.1 mrg && !DECL_IMMEDIATE_FUNCTION_P (fn) 4782 1.1 mrg && !DECL_OMP_DECLARE_REDUCTION_P (fn) 4783 1.1 mrg && (flag_keep_inline_functions 4784 1.1 mrg || (flag_keep_inline_dllexport 4785 1.1 mrg && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn))))) 4786 1.1 mrg { 4787 1.1 mrg mark_needed (fn); 4788 1.1 mrg DECL_EXTERNAL (fn) = 0; 4789 1.1 mrg } 4790 1.1 mrg } 4791 1.1 mrg 4792 1.1 mrg /* If this is a constructor or destructor body, we have to clone 4793 1.1 mrg it. */ 4794 1.1 mrg if (maybe_clone_body (fn)) 4795 1.1 mrg { 4796 1.1 mrg /* We don't want to process FN again, so pretend we've written 4797 1.1 mrg it out, even though we haven't. */ 4798 1.1 mrg TREE_ASM_WRITTEN (fn) = 1; 4799 1.1 mrg /* If this is a constexpr function, keep DECL_SAVED_TREE. */ 4800 1.1 mrg if (!DECL_DECLARED_CONSTEXPR_P (fn) 4801 1.1 mrg && !(modules_p () && DECL_DECLARED_INLINE_P (fn))) 4802 1.1 mrg DECL_SAVED_TREE (fn) = NULL_TREE; 4803 1.1 mrg return false; 4804 1.1 mrg } 4805 1.1 mrg 4806 1.1 mrg /* There's no reason to do any of the work here if we're only doing 4807 1.1 mrg semantic analysis; this code just generates RTL. */ 4808 1.1 mrg if (flag_syntax_only) 4809 1.1 mrg { 4810 1.1 mrg /* Pretend that this function has been written out so that we don't try 4811 1.1 mrg to expand it again. */ 4812 1.1 mrg TREE_ASM_WRITTEN (fn) = 1; 4813 1.1 mrg return false; 4814 1.1 mrg } 4815 1.1 mrg 4816 1.1 mrg if (DECL_OMP_DECLARE_REDUCTION_P (fn)) 4817 1.1 mrg return false; 4818 1.1 mrg 4819 1.1 mrg return true; 4820 1.1 mrg } 4821 1.1 mrg 4822 1.1 mrg void 4823 1.1 mrg expand_or_defer_fn (tree fn) 4824 1.1 mrg { 4825 1.1 mrg if (expand_or_defer_fn_1 (fn)) 4826 1.1 mrg { 4827 1.1 mrg function_depth++; 4828 1.1 mrg 4829 1.1 mrg /* Expand or defer, at the whim of the compilation unit manager. */ 4830 1.1 mrg cgraph_node::finalize_function (fn, function_depth > 1); 4831 1.1 mrg emit_associated_thunks (fn); 4832 1.1 mrg 4833 1.1 mrg function_depth--; 4834 1.1 mrg 4835 1.1 mrg if (DECL_IMMEDIATE_FUNCTION_P (fn)) 4836 1.1 mrg { 4837 1.1 mrg if (cgraph_node *node = cgraph_node::get (fn)) 4838 1.1 mrg { 4839 1.1 mrg node->body_removed = true; 4840 1.1 mrg node->analyzed = false; 4841 1.1 mrg node->definition = false; 4842 1.1 mrg node->force_output = false; 4843 1.1 mrg } 4844 1.1 mrg } 4845 1.1 mrg } 4846 1.1 mrg } 4847 1.1 mrg 4848 1.1 mrg class nrv_data 4849 1.1 mrg { 4850 1.1 mrg public: 4851 1.1 mrg nrv_data () : visited (37) {} 4852 1.1 mrg 4853 1.1 mrg tree var; 4854 1.1 mrg tree result; 4855 1.1 mrg hash_table<nofree_ptr_hash <tree_node> > visited; 4856 1.1 mrg bool in_nrv_cleanup; 4857 1.1 mrg }; 4858 1.1 mrg 4859 1.1 mrg /* Helper function for walk_tree, used by finalize_nrv below. */ 4860 1.1 mrg 4861 1.1 mrg static tree 4862 1.1 mrg finalize_nrv_r (tree* tp, int* walk_subtrees, void* data) 4863 1.1 mrg { 4864 1.1 mrg class nrv_data *dp = (class nrv_data *)data; 4865 1.1 mrg tree_node **slot; 4866 1.1 mrg 4867 1.1 mrg /* No need to walk into types. There wouldn't be any need to walk into 4868 1.1 mrg non-statements, except that we have to consider STMT_EXPRs. */ 4869 1.1 mrg if (TYPE_P (*tp)) 4870 1.1 mrg *walk_subtrees = 0; 4871 1.1 mrg /* Change all returns to just refer to the RESULT_DECL; this is a nop, 4872 1.1 mrg but differs from using NULL_TREE in that it indicates that we care 4873 1.1 mrg about the value of the RESULT_DECL. But preserve anything appended 4874 1.1 mrg by check_return_expr. */ 4875 1.1 mrg else if (TREE_CODE (*tp) == RETURN_EXPR) 4876 1.1 mrg { 4877 1.1 mrg tree *p = &TREE_OPERAND (*tp, 0); 4878 1.1 mrg while (TREE_CODE (*p) == COMPOUND_EXPR) 4879 1.1 mrg p = &TREE_OPERAND (*p, 0); 4880 1.1 mrg gcc_checking_assert (TREE_CODE (*p) == INIT_EXPR 4881 1.1 mrg && TREE_OPERAND (*p, 0) == dp->result); 4882 1.1 mrg *p = dp->result; 4883 1.1 mrg } 4884 1.1 mrg /* Change all cleanups for the NRV to only run when an exception is 4885 1.1 mrg thrown. */ 4886 1.1 mrg else if (TREE_CODE (*tp) == CLEANUP_STMT 4887 1.1 mrg && CLEANUP_DECL (*tp) == dp->var) 4888 1.1 mrg { 4889 1.1 mrg dp->in_nrv_cleanup = true; 4890 1.1 mrg cp_walk_tree (&CLEANUP_BODY (*tp), finalize_nrv_r, data, 0); 4891 1.1 mrg dp->in_nrv_cleanup = false; 4892 1.1 mrg cp_walk_tree (&CLEANUP_EXPR (*tp), finalize_nrv_r, data, 0); 4893 1.1 mrg *walk_subtrees = 0; 4894 1.1 mrg 4895 1.1 mrg CLEANUP_EH_ONLY (*tp) = true; 4896 1.1 mrg 4897 1.1 mrg /* If a cleanup might throw, we need to clear current_retval_sentinel on 4898 1.1 mrg the exception path so an outer cleanup added by 4899 1.1 mrg maybe_splice_retval_cleanup doesn't run. */ 4900 1.1 mrg if (current_retval_sentinel 4901 1.1 mrg && cp_function_chain->throwing_cleanup) 4902 1.1 mrg { 4903 1.1 mrg tree clear = build2 (MODIFY_EXPR, boolean_type_node, 4904 1.1 mrg current_retval_sentinel, 4905 1.1 mrg boolean_false_node); 4906 1.1 mrg 4907 1.1 mrg /* We're already only on the EH path, just prepend it. */ 4908 1.1 mrg tree &exp = CLEANUP_EXPR (*tp); 4909 1.1 mrg exp = build2 (COMPOUND_EXPR, void_type_node, clear, exp); 4910 1.1 mrg } 4911 1.1 mrg } 4912 1.1 mrg /* Disable maybe_splice_retval_cleanup within the NRV cleanup scope, we don't 4913 1.1 mrg want to destroy the retval before the variable goes out of scope. */ 4914 1.1 mrg else if (TREE_CODE (*tp) == CLEANUP_STMT 4915 1.1 mrg && dp->in_nrv_cleanup 4916 1.1 mrg && CLEANUP_DECL (*tp) == dp->result) 4917 1.1 mrg CLEANUP_EXPR (*tp) = void_node; 4918 1.1 mrg /* Replace the DECL_EXPR for the NRV with an initialization of the 4919 1.1 mrg RESULT_DECL, if needed. */ 4920 1.1 mrg else if (TREE_CODE (*tp) == DECL_EXPR 4921 1.1 mrg && DECL_EXPR_DECL (*tp) == dp->var) 4922 1.1 mrg { 4923 1.1 mrg tree init; 4924 1.1 mrg if (DECL_INITIAL (dp->var) 4925 1.1 mrg && DECL_INITIAL (dp->var) != error_mark_node) 4926 1.1 mrg init = build2 (INIT_EXPR, void_type_node, dp->result, 4927 1.1 mrg DECL_INITIAL (dp->var)); 4928 1.1 mrg else 4929 1.1 mrg init = build_empty_stmt (EXPR_LOCATION (*tp)); 4930 1.1 mrg DECL_INITIAL (dp->var) = NULL_TREE; 4931 1.1 mrg SET_EXPR_LOCATION (init, EXPR_LOCATION (*tp)); 4932 1.1 mrg *tp = init; 4933 1.1 mrg } 4934 1.1 mrg /* And replace all uses of the NRV with the RESULT_DECL. */ 4935 1.1 mrg else if (*tp == dp->var) 4936 1.1 mrg *tp = dp->result; 4937 1.1 mrg 4938 1.1 mrg /* Avoid walking into the same tree more than once. Unfortunately, we 4939 1.1 mrg can't just use walk_tree_without duplicates because it would only call 4940 1.1 mrg us for the first occurrence of dp->var in the function body. */ 4941 1.1 mrg slot = dp->visited.find_slot (*tp, INSERT); 4942 1.1 mrg if (*slot) 4943 1.1 mrg *walk_subtrees = 0; 4944 1.1 mrg else 4945 1.1 mrg *slot = *tp; 4946 1.1 mrg 4947 1.1 mrg /* Keep iterating. */ 4948 1.1 mrg return NULL_TREE; 4949 1.1 mrg } 4950 1.1 mrg 4951 1.1 mrg /* Called from finish_function to implement the named return value 4952 1.1 mrg optimization by overriding all the RETURN_EXPRs and pertinent 4953 1.1 mrg CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the 4954 1.1 mrg RESULT_DECL for the function. */ 4955 1.1 mrg 4956 1.1 mrg void 4957 1.1 mrg finalize_nrv (tree *tp, tree var, tree result) 4958 1.1 mrg { 4959 1.1 mrg class nrv_data data; 4960 1.1 mrg 4961 1.1 mrg /* Copy name from VAR to RESULT. */ 4962 1.1 mrg DECL_NAME (result) = DECL_NAME (var); 4963 1.1 mrg /* Don't forget that we take its address. */ 4964 1.1 mrg TREE_ADDRESSABLE (result) = TREE_ADDRESSABLE (var); 4965 1.1 mrg /* Finally set DECL_VALUE_EXPR to avoid assigning 4966 1.1 mrg a stack slot at -O0 for the original var and debug info 4967 1.1 mrg uses RESULT location for VAR. */ 4968 1.1 mrg SET_DECL_VALUE_EXPR (var, result); 4969 1.1 mrg DECL_HAS_VALUE_EXPR_P (var) = 1; 4970 1.1 mrg 4971 1.1 mrg data.var = var; 4972 1.1 mrg data.result = result; 4973 1.1 mrg data.in_nrv_cleanup = false; 4974 1.1 mrg cp_walk_tree (tp, finalize_nrv_r, &data, 0); 4975 1.1 mrg } 4976 1.1 mrg 4977 1.1 mrg /* Create CP_OMP_CLAUSE_INFO for clause C. Returns true if it is invalid. */ 4979 1.1 mrg 4980 1.1 mrg bool 4981 1.1 mrg cxx_omp_create_clause_info (tree c, tree type, bool need_default_ctor, 4982 1.1 mrg bool need_copy_ctor, bool need_copy_assignment, 4983 1.1 mrg bool need_dtor) 4984 1.1 mrg { 4985 1.1 mrg int save_errorcount = errorcount; 4986 1.1 mrg tree info, t; 4987 1.1 mrg 4988 1.1 mrg /* Always allocate 3 elements for simplicity. These are the 4989 1.1 mrg function decls for the ctor, dtor, and assignment op. 4990 1.1 mrg This layout is known to the three lang hooks, 4991 1.1 mrg cxx_omp_clause_default_init, cxx_omp_clause_copy_init, 4992 1.1 mrg and cxx_omp_clause_assign_op. */ 4993 1.1 mrg info = make_tree_vec (3); 4994 1.1 mrg CP_OMP_CLAUSE_INFO (c) = info; 4995 1.1 mrg 4996 1.1 mrg if (need_default_ctor || need_copy_ctor) 4997 1.1 mrg { 4998 1.1 mrg if (need_default_ctor) 4999 1.1 mrg t = get_default_ctor (type); 5000 1.1 mrg else 5001 1.1 mrg t = get_copy_ctor (type, tf_warning_or_error); 5002 1.1 mrg 5003 1.1 mrg if (t && !trivial_fn_p (t)) 5004 1.1 mrg TREE_VEC_ELT (info, 0) = t; 5005 1.1 mrg } 5006 1.1 mrg 5007 1.1 mrg if (need_dtor && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)) 5008 1.1 mrg TREE_VEC_ELT (info, 1) = get_dtor (type, tf_warning_or_error); 5009 1.1 mrg 5010 1.1 mrg if (need_copy_assignment) 5011 1.1 mrg { 5012 1.1 mrg t = get_copy_assign (type); 5013 1.1 mrg 5014 1.1 mrg if (t && !trivial_fn_p (t)) 5015 1.1 mrg TREE_VEC_ELT (info, 2) = t; 5016 1.1 mrg } 5017 1.1 mrg 5018 1.1 mrg return errorcount != save_errorcount; 5019 1.1 mrg } 5020 1.1 mrg 5021 1.1 mrg /* If DECL is DECL_OMP_PRIVATIZED_MEMBER, return corresponding 5022 1.1 mrg FIELD_DECL, otherwise return DECL itself. */ 5023 1.1 mrg 5024 1.1 mrg static tree 5025 1.1 mrg omp_clause_decl_field (tree decl) 5026 1.1 mrg { 5027 1.1 mrg if (VAR_P (decl) 5028 1.1 mrg && DECL_HAS_VALUE_EXPR_P (decl) 5029 1.1 mrg && DECL_ARTIFICIAL (decl) 5030 1.1 mrg && DECL_LANG_SPECIFIC (decl) 5031 1.1 mrg && DECL_OMP_PRIVATIZED_MEMBER (decl)) 5032 1.1 mrg { 5033 1.1 mrg tree f = DECL_VALUE_EXPR (decl); 5034 1.1 mrg if (INDIRECT_REF_P (f)) 5035 1.1 mrg f = TREE_OPERAND (f, 0); 5036 1.1 mrg if (TREE_CODE (f) == COMPONENT_REF) 5037 1.1 mrg { 5038 1.1 mrg f = TREE_OPERAND (f, 1); 5039 1.1 mrg gcc_assert (TREE_CODE (f) == FIELD_DECL); 5040 1.1 mrg return f; 5041 1.1 mrg } 5042 1.1 mrg } 5043 1.1 mrg return NULL_TREE; 5044 1.1 mrg } 5045 1.1 mrg 5046 1.1 mrg /* Adjust DECL if needed for printing using %qE. */ 5047 1.1 mrg 5048 1.1 mrg static tree 5049 1.1 mrg omp_clause_printable_decl (tree decl) 5050 1.1 mrg { 5051 1.1 mrg tree t = omp_clause_decl_field (decl); 5052 1.1 mrg if (t) 5053 1.1 mrg return t; 5054 1.1 mrg return decl; 5055 1.1 mrg } 5056 1.1 mrg 5057 1.1 mrg /* For a FIELD_DECL F and corresponding DECL_OMP_PRIVATIZED_MEMBER 5058 1.1 mrg VAR_DECL T that doesn't need a DECL_EXPR added, record it for 5059 1.1 mrg privatization. */ 5060 1.1 mrg 5061 1.1 mrg static void 5062 1.1 mrg omp_note_field_privatization (tree f, tree t) 5063 1.1 mrg { 5064 1.1 mrg if (!omp_private_member_map) 5065 1.1 mrg omp_private_member_map = new hash_map<tree, tree>; 5066 1.1 mrg tree &v = omp_private_member_map->get_or_insert (f); 5067 1.1 mrg if (v == NULL_TREE) 5068 1.1 mrg { 5069 1.1 mrg v = t; 5070 1.1 mrg omp_private_member_vec.safe_push (f); 5071 1.1 mrg /* Signal that we don't want to create DECL_EXPR for this dummy var. */ 5072 1.1 mrg omp_private_member_vec.safe_push (integer_zero_node); 5073 1.1 mrg } 5074 1.1 mrg } 5075 1.1 mrg 5076 1.1 mrg /* Privatize FIELD_DECL T, return corresponding DECL_OMP_PRIVATIZED_MEMBER 5077 1.1 mrg dummy VAR_DECL. */ 5078 1.1 mrg 5079 1.1 mrg tree 5080 1.1 mrg omp_privatize_field (tree t, bool shared) 5081 1.1 mrg { 5082 1.1 mrg tree m = finish_non_static_data_member (t, NULL_TREE, NULL_TREE); 5083 1.1 mrg if (m == error_mark_node) 5084 1.1 mrg return error_mark_node; 5085 1.1 mrg if (!omp_private_member_map && !shared) 5086 1.1 mrg omp_private_member_map = new hash_map<tree, tree>; 5087 1.1 mrg if (TYPE_REF_P (TREE_TYPE (t))) 5088 1.1 mrg { 5089 1.1 mrg gcc_assert (INDIRECT_REF_P (m)); 5090 1.1 mrg m = TREE_OPERAND (m, 0); 5091 1.1 mrg } 5092 1.1 mrg tree vb = NULL_TREE; 5093 1.1 mrg tree &v = shared ? vb : omp_private_member_map->get_or_insert (t); 5094 1.1 mrg if (v == NULL_TREE) 5095 1.1 mrg { 5096 1.1 mrg v = create_temporary_var (TREE_TYPE (m)); 5097 1.1 mrg retrofit_lang_decl (v); 5098 1.1 mrg DECL_OMP_PRIVATIZED_MEMBER (v) = 1; 5099 1.1 mrg SET_DECL_VALUE_EXPR (v, m); 5100 1.1 mrg DECL_HAS_VALUE_EXPR_P (v) = 1; 5101 1.1 mrg if (!shared) 5102 1.1 mrg omp_private_member_vec.safe_push (t); 5103 1.1 mrg } 5104 1.1 mrg return v; 5105 1.1 mrg } 5106 1.1 mrg 5107 1.1 mrg /* Helper function for handle_omp_array_sections. Called recursively 5108 1.1 mrg to handle multiple array-section-subscripts. C is the clause, 5109 1.1 mrg T current expression (initially OMP_CLAUSE_DECL), which is either 5110 1.1 mrg a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound 5111 1.1 mrg expression if specified, TREE_VALUE length expression if specified, 5112 1.1 mrg TREE_CHAIN is what it has been specified after, or some decl. 5113 1.1 mrg TYPES vector is populated with array section types, MAYBE_ZERO_LEN 5114 1.1 mrg set to true if any of the array-section-subscript could have length 5115 1.1 mrg of zero (explicit or implicit), FIRST_NON_ONE is the index of the 5116 1.1 mrg first array-section-subscript which is known not to have length 5117 1.1 mrg of one. Given say: 5118 1.1 mrg map(a[:b][2:1][:c][:2][:d][e:f][2:5]) 5119 1.1 mrg FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c] 5120 1.1 mrg all are or may have length of 1, array-section-subscript [:2] is the 5121 1.1 mrg first one known not to have length 1. For array-section-subscript 5122 1.1 mrg <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't 5123 1.1 mrg 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we 5124 1.1 mrg can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above 5125 1.1 mrg case though, as some lengths could be zero. */ 5126 1.1 mrg 5127 1.1 mrg static tree 5128 1.1 mrg handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types, 5129 1.1 mrg bool &maybe_zero_len, unsigned int &first_non_one, 5130 1.1 mrg enum c_omp_region_type ort) 5131 1.1 mrg { 5132 1.1 mrg tree ret, low_bound, length, type; 5133 1.1 mrg if (TREE_CODE (t) != TREE_LIST) 5134 1.1 mrg { 5135 1.1 mrg if (error_operand_p (t)) 5136 1.1 mrg return error_mark_node; 5137 1.1 mrg if (REFERENCE_REF_P (t) 5138 1.1 mrg && TREE_CODE (TREE_OPERAND (t, 0)) == COMPONENT_REF) 5139 1.1 mrg t = TREE_OPERAND (t, 0); 5140 1.1 mrg ret = t; 5141 1.1 mrg while (TREE_CODE (t) == INDIRECT_REF) 5142 1.1 mrg { 5143 1.1 mrg t = TREE_OPERAND (t, 0); 5144 1.1 mrg STRIP_NOPS (t); 5145 1.1 mrg if (TREE_CODE (t) == POINTER_PLUS_EXPR) 5146 1.1 mrg t = TREE_OPERAND (t, 0); 5147 1.1 mrg } 5148 1.1 mrg while (TREE_CODE (t) == COMPOUND_EXPR) 5149 1.1 mrg { 5150 1.1 mrg t = TREE_OPERAND (t, 1); 5151 1.1 mrg STRIP_NOPS (t); 5152 1.1 mrg } 5153 1.1 mrg if (TREE_CODE (t) == COMPONENT_REF 5154 1.1 mrg && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP 5155 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO 5156 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM) 5157 1.1 mrg && !type_dependent_expression_p (t)) 5158 1.1 mrg { 5159 1.1 mrg if (TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL 5160 1.1 mrg && DECL_BIT_FIELD (TREE_OPERAND (t, 1))) 5161 1.1 mrg { 5162 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 5163 1.1 mrg "bit-field %qE in %qs clause", 5164 1.1 mrg t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 5165 1.1 mrg return error_mark_node; 5166 1.1 mrg } 5167 1.1 mrg while (TREE_CODE (t) == COMPONENT_REF) 5168 1.1 mrg { 5169 1.1 mrg if (TREE_TYPE (TREE_OPERAND (t, 0)) 5170 1.1 mrg && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == UNION_TYPE) 5171 1.1 mrg { 5172 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 5173 1.1 mrg "%qE is a member of a union", t); 5174 1.1 mrg return error_mark_node; 5175 1.1 mrg } 5176 1.1 mrg t = TREE_OPERAND (t, 0); 5177 1.1 mrg while (TREE_CODE (t) == MEM_REF 5178 1.1 mrg || TREE_CODE (t) == INDIRECT_REF 5179 1.1 mrg || TREE_CODE (t) == ARRAY_REF) 5180 1.1 mrg { 5181 1.1 mrg t = TREE_OPERAND (t, 0); 5182 1.1 mrg STRIP_NOPS (t); 5183 1.1 mrg if (TREE_CODE (t) == POINTER_PLUS_EXPR) 5184 1.1 mrg t = TREE_OPERAND (t, 0); 5185 1.1 mrg } 5186 1.1 mrg } 5187 1.1 mrg if (REFERENCE_REF_P (t)) 5188 1.1 mrg t = TREE_OPERAND (t, 0); 5189 1.1 mrg } 5190 1.1 mrg if (TREE_CODE (t) == FIELD_DECL) 5191 1.1 mrg ret = finish_non_static_data_member (t, NULL_TREE, NULL_TREE); 5192 1.1 mrg else if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL) 5193 1.1 mrg { 5194 1.1 mrg if (processing_template_decl && TREE_CODE (t) != OVERLOAD) 5195 1.1 mrg return NULL_TREE; 5196 1.1 mrg if (DECL_P (t)) 5197 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 5198 1.1 mrg "%qD is not a variable in %qs clause", t, 5199 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 5200 1.1 mrg else 5201 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 5202 1.1 mrg "%qE is not a variable in %qs clause", t, 5203 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 5204 1.1 mrg return error_mark_node; 5205 1.1 mrg } 5206 1.1 mrg else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY 5207 1.1 mrg && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND 5208 1.1 mrg && VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t)) 5209 1.1 mrg { 5210 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 5211 1.1 mrg "%qD is threadprivate variable in %qs clause", t, 5212 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 5213 1.1 mrg return error_mark_node; 5214 1.1 mrg } 5215 1.1 mrg if (type_dependent_expression_p (ret)) 5216 1.1 mrg return NULL_TREE; 5217 1.1 mrg ret = convert_from_reference (ret); 5218 1.1 mrg return ret; 5219 1.1 mrg } 5220 1.1 mrg 5221 1.1 mrg if ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP 5222 1.1 mrg && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION 5223 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION 5224 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION) 5225 1.1 mrg && TREE_CODE (TREE_CHAIN (t)) == FIELD_DECL) 5226 1.1 mrg TREE_CHAIN (t) = omp_privatize_field (TREE_CHAIN (t), false); 5227 1.1 mrg ret = handle_omp_array_sections_1 (c, TREE_CHAIN (t), types, 5228 1.1 mrg maybe_zero_len, first_non_one, ort); 5229 1.1 mrg if (ret == error_mark_node || ret == NULL_TREE) 5230 1.1 mrg return ret; 5231 1.1 mrg 5232 1.1 mrg type = TREE_TYPE (ret); 5233 1.1 mrg low_bound = TREE_PURPOSE (t); 5234 1.1 mrg length = TREE_VALUE (t); 5235 1.1 mrg if ((low_bound && type_dependent_expression_p (low_bound)) 5236 1.1 mrg || (length && type_dependent_expression_p (length))) 5237 1.1 mrg return NULL_TREE; 5238 1.1 mrg 5239 1.1 mrg if (low_bound == error_mark_node || length == error_mark_node) 5240 1.1 mrg return error_mark_node; 5241 1.1 mrg 5242 1.1 mrg if (low_bound && !INTEGRAL_TYPE_P (TREE_TYPE (low_bound))) 5243 1.1 mrg { 5244 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 5245 1.1 mrg "low bound %qE of array section does not have integral type", 5246 1.1 mrg low_bound); 5247 1.1 mrg return error_mark_node; 5248 1.1 mrg } 5249 1.1 mrg if (length && !INTEGRAL_TYPE_P (TREE_TYPE (length))) 5250 1.1 mrg { 5251 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 5252 1.1 mrg "length %qE of array section does not have integral type", 5253 1.1 mrg length); 5254 1.1 mrg return error_mark_node; 5255 1.1 mrg } 5256 1.1 mrg if (low_bound) 5257 1.1 mrg low_bound = mark_rvalue_use (low_bound); 5258 1.1 mrg if (length) 5259 1.1 mrg length = mark_rvalue_use (length); 5260 1.1 mrg /* We need to reduce to real constant-values for checks below. */ 5261 1.1 mrg if (length) 5262 1.1 mrg length = fold_simple (length); 5263 1.1 mrg if (low_bound) 5264 1.1 mrg low_bound = fold_simple (low_bound); 5265 1.1 mrg if (low_bound 5266 1.1 mrg && TREE_CODE (low_bound) == INTEGER_CST 5267 1.1 mrg && TYPE_PRECISION (TREE_TYPE (low_bound)) 5268 1.1 mrg > TYPE_PRECISION (sizetype)) 5269 1.1 mrg low_bound = fold_convert (sizetype, low_bound); 5270 1.1 mrg if (length 5271 1.1 mrg && TREE_CODE (length) == INTEGER_CST 5272 1.1 mrg && TYPE_PRECISION (TREE_TYPE (length)) 5273 1.1 mrg > TYPE_PRECISION (sizetype)) 5274 1.1 mrg length = fold_convert (sizetype, length); 5275 1.1 mrg if (low_bound == NULL_TREE) 5276 1.1 mrg low_bound = integer_zero_node; 5277 1.1 mrg 5278 1.1 mrg if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP 5279 1.1 mrg && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH 5280 1.1 mrg || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)) 5281 1.1 mrg { 5282 1.1 mrg if (length != integer_one_node) 5283 1.1 mrg { 5284 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 5285 1.1 mrg "expected single pointer in %qs clause", 5286 1.1 mrg user_omp_clause_code_name (c, ort == C_ORT_ACC)); 5287 1.1 mrg return error_mark_node; 5288 1.1 mrg } 5289 1.1 mrg } 5290 1.1 mrg if (length != NULL_TREE) 5291 1.1 mrg { 5292 1.1 mrg if (!integer_nonzerop (length)) 5293 1.1 mrg { 5294 1.1 mrg if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY 5295 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND 5296 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION 5297 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION 5298 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION) 5299 1.1 mrg { 5300 1.1 mrg if (integer_zerop (length)) 5301 1.1 mrg { 5302 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 5303 1.1 mrg "zero length array section in %qs clause", 5304 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 5305 1.1 mrg return error_mark_node; 5306 1.1 mrg } 5307 1.1 mrg } 5308 1.1 mrg else 5309 1.1 mrg maybe_zero_len = true; 5310 1.1 mrg } 5311 1.1 mrg if (first_non_one == types.length () 5312 1.1 mrg && (TREE_CODE (length) != INTEGER_CST || integer_onep (length))) 5313 1.1 mrg first_non_one++; 5314 1.1 mrg } 5315 1.1 mrg if (TREE_CODE (type) == ARRAY_TYPE) 5316 1.1 mrg { 5317 1.1 mrg if (length == NULL_TREE 5318 1.1 mrg && (TYPE_DOMAIN (type) == NULL_TREE 5319 1.1 mrg || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE)) 5320 1.1 mrg { 5321 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 5322 1.1 mrg "for unknown bound array type length expression must " 5323 1.1 mrg "be specified"); 5324 1.1 mrg return error_mark_node; 5325 1.1 mrg } 5326 1.1 mrg if (TREE_CODE (low_bound) == INTEGER_CST 5327 1.1 mrg && tree_int_cst_sgn (low_bound) == -1) 5328 1.1 mrg { 5329 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 5330 1.1 mrg "negative low bound in array section in %qs clause", 5331 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 5332 1.1 mrg return error_mark_node; 5333 1.1 mrg } 5334 1.1 mrg if (length != NULL_TREE 5335 1.1 mrg && TREE_CODE (length) == INTEGER_CST 5336 1.1 mrg && tree_int_cst_sgn (length) == -1) 5337 1.1 mrg { 5338 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 5339 1.1 mrg "negative length in array section in %qs clause", 5340 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 5341 1.1 mrg return error_mark_node; 5342 1.1 mrg } 5343 1.1 mrg if (TYPE_DOMAIN (type) 5344 1.1 mrg && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) 5345 1.1 mrg && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) 5346 1.1 mrg == INTEGER_CST) 5347 1.1 mrg { 5348 1.1 mrg tree size 5349 1.1 mrg = fold_convert (sizetype, TYPE_MAX_VALUE (TYPE_DOMAIN (type))); 5350 1.1 mrg size = size_binop (PLUS_EXPR, size, size_one_node); 5351 1.1 mrg if (TREE_CODE (low_bound) == INTEGER_CST) 5352 1.1 mrg { 5353 1.1 mrg if (tree_int_cst_lt (size, low_bound)) 5354 1.1 mrg { 5355 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 5356 1.1 mrg "low bound %qE above array section size " 5357 1.1 mrg "in %qs clause", low_bound, 5358 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 5359 1.1 mrg return error_mark_node; 5360 1.1 mrg } 5361 1.1 mrg if (tree_int_cst_equal (size, low_bound)) 5362 1.1 mrg { 5363 1.1 mrg if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY 5364 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND 5365 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION 5366 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION 5367 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION) 5368 1.1 mrg { 5369 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 5370 1.1 mrg "zero length array section in %qs clause", 5371 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 5372 1.1 mrg return error_mark_node; 5373 1.1 mrg } 5374 1.1 mrg maybe_zero_len = true; 5375 1.1 mrg } 5376 1.1 mrg else if (length == NULL_TREE 5377 1.1 mrg && first_non_one == types.length () 5378 1.1 mrg && tree_int_cst_equal 5379 1.1 mrg (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), 5380 1.1 mrg low_bound)) 5381 1.1 mrg first_non_one++; 5382 1.1 mrg } 5383 1.1 mrg else if (length == NULL_TREE) 5384 1.1 mrg { 5385 1.1 mrg if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY 5386 1.1 mrg && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND 5387 1.1 mrg && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION 5388 1.1 mrg && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION 5389 1.1 mrg && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION) 5390 1.1 mrg maybe_zero_len = true; 5391 1.1 mrg if (first_non_one == types.length ()) 5392 1.1 mrg first_non_one++; 5393 1.1 mrg } 5394 1.1 mrg if (length && TREE_CODE (length) == INTEGER_CST) 5395 1.1 mrg { 5396 1.1 mrg if (tree_int_cst_lt (size, length)) 5397 1.1 mrg { 5398 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 5399 1.1 mrg "length %qE above array section size " 5400 1.1 mrg "in %qs clause", length, 5401 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 5402 1.1 mrg return error_mark_node; 5403 1.1 mrg } 5404 1.1 mrg if (TREE_CODE (low_bound) == INTEGER_CST) 5405 1.1 mrg { 5406 1.1 mrg tree lbpluslen 5407 1.1 mrg = size_binop (PLUS_EXPR, 5408 1.1 mrg fold_convert (sizetype, low_bound), 5409 1.1 mrg fold_convert (sizetype, length)); 5410 1.1 mrg if (TREE_CODE (lbpluslen) == INTEGER_CST 5411 1.1 mrg && tree_int_cst_lt (size, lbpluslen)) 5412 1.1 mrg { 5413 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 5414 1.1 mrg "high bound %qE above array section size " 5415 1.1 mrg "in %qs clause", lbpluslen, 5416 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 5417 1.1 mrg return error_mark_node; 5418 1.1 mrg } 5419 1.1 mrg } 5420 1.1 mrg } 5421 1.1 mrg } 5422 1.1 mrg else if (length == NULL_TREE) 5423 1.1 mrg { 5424 1.1 mrg if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY 5425 1.1 mrg && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND 5426 1.1 mrg && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION 5427 1.1 mrg && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION 5428 1.1 mrg && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION) 5429 1.1 mrg maybe_zero_len = true; 5430 1.1 mrg if (first_non_one == types.length ()) 5431 1.1 mrg first_non_one++; 5432 1.1 mrg } 5433 1.1 mrg 5434 1.1 mrg /* For [lb:] we will need to evaluate lb more than once. */ 5435 1.1 mrg if (length == NULL_TREE && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND) 5436 1.1 mrg { 5437 1.1 mrg tree lb = cp_save_expr (low_bound); 5438 1.1 mrg if (lb != low_bound) 5439 1.1 mrg { 5440 1.1 mrg TREE_PURPOSE (t) = lb; 5441 1.1 mrg low_bound = lb; 5442 1.1 mrg } 5443 1.1 mrg } 5444 1.1 mrg } 5445 1.1 mrg else if (TYPE_PTR_P (type)) 5446 1.1 mrg { 5447 1.1 mrg if (length == NULL_TREE) 5448 1.1 mrg { 5449 1.1 mrg if (TREE_CODE (ret) == PARM_DECL && DECL_ARRAY_PARAMETER_P (ret)) 5450 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 5451 1.1 mrg "for array function parameter length expression " 5452 1.1 mrg "must be specified"); 5453 1.1 mrg else 5454 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 5455 1.1 mrg "for pointer type length expression must be specified"); 5456 1.1 mrg return error_mark_node; 5457 1.1 mrg } 5458 1.1 mrg if (length != NULL_TREE 5459 1.1 mrg && TREE_CODE (length) == INTEGER_CST 5460 1.1 mrg && tree_int_cst_sgn (length) == -1) 5461 1.1 mrg { 5462 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 5463 1.1 mrg "negative length in array section in %qs clause", 5464 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 5465 1.1 mrg return error_mark_node; 5466 1.1 mrg } 5467 1.1 mrg /* If there is a pointer type anywhere but in the very first 5468 1.1 mrg array-section-subscript, the array section could be non-contiguous. */ 5469 1.1 mrg if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY 5470 1.1 mrg && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND 5471 1.1 mrg && TREE_CODE (TREE_CHAIN (t)) == TREE_LIST) 5472 1.1 mrg { 5473 1.1 mrg /* If any prior dimension has a non-one length, then deem this 5474 1.1 mrg array section as non-contiguous. */ 5475 1.1 mrg for (tree d = TREE_CHAIN (t); TREE_CODE (d) == TREE_LIST; 5476 1.1 mrg d = TREE_CHAIN (d)) 5477 1.1 mrg { 5478 1.1 mrg tree d_length = TREE_VALUE (d); 5479 1.1 mrg if (d_length == NULL_TREE || !integer_onep (d_length)) 5480 1.1 mrg { 5481 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 5482 1.1 mrg "array section is not contiguous in %qs clause", 5483 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 5484 1.1 mrg return error_mark_node; 5485 1.1 mrg } 5486 1.1 mrg } 5487 1.1 mrg } 5488 1.1 mrg } 5489 1.1 mrg else 5490 1.1 mrg { 5491 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 5492 1.1 mrg "%qE does not have pointer or array type", ret); 5493 1.1 mrg return error_mark_node; 5494 1.1 mrg } 5495 1.1 mrg if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND) 5496 1.1 mrg types.safe_push (TREE_TYPE (ret)); 5497 1.1 mrg /* We will need to evaluate lb more than once. */ 5498 1.1 mrg tree lb = cp_save_expr (low_bound); 5499 1.1 mrg if (lb != low_bound) 5500 1.1 mrg { 5501 1.1 mrg TREE_PURPOSE (t) = lb; 5502 1.1 mrg low_bound = lb; 5503 1.1 mrg } 5504 1.1 mrg /* Temporarily disable -fstrong-eval-order for array reductions. 5505 1.1 mrg The SAVE_EXPR and COMPOUND_EXPR added if low_bound has side-effects 5506 1.1 mrg is something the middle-end can't cope with and more importantly, 5507 1.1 mrg it needs to be the actual base variable that is privatized, not some 5508 1.1 mrg temporary assigned previous value of it. That, together with OpenMP 5509 1.1 mrg saying how many times the side-effects are evaluated is unspecified, 5510 1.1 mrg makes int *a, *b; ... reduction(+:a[a = b, 3:10]) really unspecified. */ 5511 1.1 mrg warning_sentinel s (flag_strong_eval_order, 5512 1.1 mrg OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION 5513 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION 5514 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION); 5515 1.1 mrg ret = grok_array_decl (OMP_CLAUSE_LOCATION (c), ret, low_bound, NULL, 5516 1.1 mrg tf_warning_or_error); 5517 1.1 mrg return ret; 5518 1.1 mrg } 5519 1.1 mrg 5520 1.1 mrg /* Handle array sections for clause C. */ 5521 1.1 mrg 5522 1.1 mrg static bool 5523 1.1 mrg handle_omp_array_sections (tree c, enum c_omp_region_type ort) 5524 1.1 mrg { 5525 1.1 mrg bool maybe_zero_len = false; 5526 1.1 mrg unsigned int first_non_one = 0; 5527 1.1 mrg auto_vec<tree, 10> types; 5528 1.1 mrg tree *tp = &OMP_CLAUSE_DECL (c); 5529 1.1 mrg if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND 5530 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY) 5531 1.1 mrg && TREE_CODE (*tp) == TREE_LIST 5532 1.1 mrg && TREE_PURPOSE (*tp) 5533 1.1 mrg && TREE_CODE (TREE_PURPOSE (*tp)) == TREE_VEC) 5534 1.1 mrg tp = &TREE_VALUE (*tp); 5535 1.1 mrg tree first = handle_omp_array_sections_1 (c, *tp, types, 5536 1.1 mrg maybe_zero_len, first_non_one, 5537 1.1 mrg ort); 5538 1.1 mrg if (first == error_mark_node) 5539 1.1 mrg return true; 5540 1.1 mrg if (first == NULL_TREE) 5541 1.1 mrg return false; 5542 1.1 mrg if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND 5543 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY) 5544 1.1 mrg { 5545 1.1 mrg tree t = *tp; 5546 1.1 mrg tree tem = NULL_TREE; 5547 1.1 mrg if (processing_template_decl) 5548 1.1 mrg return false; 5549 1.1 mrg /* Need to evaluate side effects in the length expressions 5550 1.1 mrg if any. */ 5551 1.1 mrg while (TREE_CODE (t) == TREE_LIST) 5552 1.1 mrg { 5553 1.1 mrg if (TREE_VALUE (t) && TREE_SIDE_EFFECTS (TREE_VALUE (t))) 5554 1.1 mrg { 5555 1.1 mrg if (tem == NULL_TREE) 5556 1.1 mrg tem = TREE_VALUE (t); 5557 1.1 mrg else 5558 1.1 mrg tem = build2 (COMPOUND_EXPR, TREE_TYPE (tem), 5559 1.1 mrg TREE_VALUE (t), tem); 5560 1.1 mrg } 5561 1.1 mrg t = TREE_CHAIN (t); 5562 1.1 mrg } 5563 1.1 mrg if (tem) 5564 1.1 mrg first = build2 (COMPOUND_EXPR, TREE_TYPE (first), tem, first); 5565 1.1 mrg *tp = first; 5566 1.1 mrg } 5567 1.1 mrg else 5568 1.1 mrg { 5569 1.1 mrg unsigned int num = types.length (), i; 5570 1.1 mrg tree t, side_effects = NULL_TREE, size = NULL_TREE; 5571 1.1 mrg tree condition = NULL_TREE; 5572 1.1 mrg 5573 1.1 mrg if (int_size_in_bytes (TREE_TYPE (first)) <= 0) 5574 1.1 mrg maybe_zero_len = true; 5575 1.1 mrg if (processing_template_decl && maybe_zero_len) 5576 1.1 mrg return false; 5577 1.1 mrg 5578 1.1 mrg for (i = num, t = OMP_CLAUSE_DECL (c); i > 0; 5579 1.1 mrg t = TREE_CHAIN (t)) 5580 1.1 mrg { 5581 1.1 mrg tree low_bound = TREE_PURPOSE (t); 5582 1.1 mrg tree length = TREE_VALUE (t); 5583 1.1 mrg 5584 1.1 mrg i--; 5585 1.1 mrg if (low_bound 5586 1.1 mrg && TREE_CODE (low_bound) == INTEGER_CST 5587 1.1 mrg && TYPE_PRECISION (TREE_TYPE (low_bound)) 5588 1.1 mrg > TYPE_PRECISION (sizetype)) 5589 1.1 mrg low_bound = fold_convert (sizetype, low_bound); 5590 1.1 mrg if (length 5591 1.1 mrg && TREE_CODE (length) == INTEGER_CST 5592 1.1 mrg && TYPE_PRECISION (TREE_TYPE (length)) 5593 1.1 mrg > TYPE_PRECISION (sizetype)) 5594 1.1 mrg length = fold_convert (sizetype, length); 5595 1.1 mrg if (low_bound == NULL_TREE) 5596 1.1 mrg low_bound = integer_zero_node; 5597 1.1 mrg if (!maybe_zero_len && i > first_non_one) 5598 1.1 mrg { 5599 1.1 mrg if (integer_nonzerop (low_bound)) 5600 1.1 mrg goto do_warn_noncontiguous; 5601 1.1 mrg if (length != NULL_TREE 5602 1.1 mrg && TREE_CODE (length) == INTEGER_CST 5603 1.1 mrg && TYPE_DOMAIN (types[i]) 5604 1.1 mrg && TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])) 5605 1.1 mrg && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types[i]))) 5606 1.1 mrg == INTEGER_CST) 5607 1.1 mrg { 5608 1.1 mrg tree size; 5609 1.1 mrg size = size_binop (PLUS_EXPR, 5610 1.1 mrg TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])), 5611 1.1 mrg size_one_node); 5612 1.1 mrg if (!tree_int_cst_equal (length, size)) 5613 1.1 mrg { 5614 1.1 mrg do_warn_noncontiguous: 5615 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 5616 1.1 mrg "array section is not contiguous in %qs " 5617 1.1 mrg "clause", 5618 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 5619 1.1 mrg return true; 5620 1.1 mrg } 5621 1.1 mrg } 5622 1.1 mrg if (!processing_template_decl 5623 1.1 mrg && length != NULL_TREE 5624 1.1 mrg && TREE_SIDE_EFFECTS (length)) 5625 1.1 mrg { 5626 1.1 mrg if (side_effects == NULL_TREE) 5627 1.1 mrg side_effects = length; 5628 1.1 mrg else 5629 1.1 mrg side_effects = build2 (COMPOUND_EXPR, 5630 1.1 mrg TREE_TYPE (side_effects), 5631 1.1 mrg length, side_effects); 5632 1.1 mrg } 5633 1.1 mrg } 5634 1.1 mrg else if (processing_template_decl) 5635 1.1 mrg continue; 5636 1.1 mrg else 5637 1.1 mrg { 5638 1.1 mrg tree l; 5639 1.1 mrg 5640 1.1 mrg if (i > first_non_one 5641 1.1 mrg && ((length && integer_nonzerop (length)) 5642 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION 5643 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION 5644 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)) 5645 1.1 mrg continue; 5646 1.1 mrg if (length) 5647 1.1 mrg l = fold_convert (sizetype, length); 5648 1.1 mrg else 5649 1.1 mrg { 5650 1.1 mrg l = size_binop (PLUS_EXPR, 5651 1.1 mrg TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])), 5652 1.1 mrg size_one_node); 5653 1.1 mrg l = size_binop (MINUS_EXPR, l, 5654 1.1 mrg fold_convert (sizetype, low_bound)); 5655 1.1 mrg } 5656 1.1 mrg if (i > first_non_one) 5657 1.1 mrg { 5658 1.1 mrg l = fold_build2 (NE_EXPR, boolean_type_node, l, 5659 1.1 mrg size_zero_node); 5660 1.1 mrg if (condition == NULL_TREE) 5661 1.1 mrg condition = l; 5662 1.1 mrg else 5663 1.1 mrg condition = fold_build2 (BIT_AND_EXPR, boolean_type_node, 5664 1.1 mrg l, condition); 5665 1.1 mrg } 5666 1.1 mrg else if (size == NULL_TREE) 5667 1.1 mrg { 5668 1.1 mrg size = size_in_bytes (TREE_TYPE (types[i])); 5669 1.1 mrg tree eltype = TREE_TYPE (types[num - 1]); 5670 1.1 mrg while (TREE_CODE (eltype) == ARRAY_TYPE) 5671 1.1 mrg eltype = TREE_TYPE (eltype); 5672 1.1 mrg if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION 5673 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION 5674 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION) 5675 1.1 mrg size = size_binop (EXACT_DIV_EXPR, size, 5676 1.1 mrg size_in_bytes (eltype)); 5677 1.1 mrg size = size_binop (MULT_EXPR, size, l); 5678 1.1 mrg if (condition) 5679 1.1 mrg size = fold_build3 (COND_EXPR, sizetype, condition, 5680 1.1 mrg size, size_zero_node); 5681 1.1 mrg } 5682 1.1 mrg else 5683 1.1 mrg size = size_binop (MULT_EXPR, size, l); 5684 1.1 mrg } 5685 1.1 mrg } 5686 1.1 mrg if (!processing_template_decl) 5687 1.1 mrg { 5688 1.1 mrg if (side_effects) 5689 1.1 mrg size = build2 (COMPOUND_EXPR, sizetype, side_effects, size); 5690 1.1 mrg if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION 5691 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION 5692 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION) 5693 1.1 mrg { 5694 1.1 mrg size = size_binop (MINUS_EXPR, size, size_one_node); 5695 1.1 mrg size = save_expr (size); 5696 1.1 mrg tree index_type = build_index_type (size); 5697 1.1 mrg tree eltype = TREE_TYPE (first); 5698 1.1 mrg while (TREE_CODE (eltype) == ARRAY_TYPE) 5699 1.1 mrg eltype = TREE_TYPE (eltype); 5700 1.1 mrg tree type = build_array_type (eltype, index_type); 5701 1.1 mrg tree ptype = build_pointer_type (eltype); 5702 1.1 mrg if (TYPE_REF_P (TREE_TYPE (t)) 5703 1.1 mrg && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t)))) 5704 1.1 mrg t = convert_from_reference (t); 5705 1.1 mrg else if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE) 5706 1.1 mrg t = build_fold_addr_expr (t); 5707 1.1 mrg tree t2 = build_fold_addr_expr (first); 5708 1.1 mrg t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c), 5709 1.1 mrg ptrdiff_type_node, t2); 5710 1.1 mrg t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR, 5711 1.1 mrg ptrdiff_type_node, t2, 5712 1.1 mrg fold_convert_loc (OMP_CLAUSE_LOCATION (c), 5713 1.1 mrg ptrdiff_type_node, t)); 5714 1.1 mrg if (tree_fits_shwi_p (t2)) 5715 1.1 mrg t = build2 (MEM_REF, type, t, 5716 1.1 mrg build_int_cst (ptype, tree_to_shwi (t2))); 5717 1.1 mrg else 5718 1.1 mrg { 5719 1.1 mrg t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c), 5720 1.1 mrg sizetype, t2); 5721 1.1 mrg t = build2_loc (OMP_CLAUSE_LOCATION (c), POINTER_PLUS_EXPR, 5722 1.1 mrg TREE_TYPE (t), t, t2); 5723 1.1 mrg t = build2 (MEM_REF, type, t, build_int_cst (ptype, 0)); 5724 1.1 mrg } 5725 1.1 mrg OMP_CLAUSE_DECL (c) = t; 5726 1.1 mrg return false; 5727 1.1 mrg } 5728 1.1 mrg OMP_CLAUSE_DECL (c) = first; 5729 1.1 mrg if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR) 5730 1.1 mrg return false; 5731 1.1 mrg OMP_CLAUSE_SIZE (c) = size; 5732 1.1 mrg if (TREE_CODE (t) == FIELD_DECL) 5733 1.1 mrg t = finish_non_static_data_member (t, NULL_TREE, NULL_TREE); 5734 1.1 mrg if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP 5735 1.1 mrg || (TREE_CODE (t) == COMPONENT_REF 5736 1.1 mrg && TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)) 5737 1.1 mrg return false; 5738 1.1 mrg switch (OMP_CLAUSE_MAP_KIND (c)) 5739 1.1 mrg { 5740 1.1 mrg case GOMP_MAP_ALLOC: 5741 1.1 mrg case GOMP_MAP_IF_PRESENT: 5742 1.1 mrg case GOMP_MAP_TO: 5743 1.1 mrg case GOMP_MAP_FROM: 5744 1.1 mrg case GOMP_MAP_TOFROM: 5745 1.1 mrg case GOMP_MAP_ALWAYS_TO: 5746 1.1 mrg case GOMP_MAP_ALWAYS_FROM: 5747 1.1 mrg case GOMP_MAP_ALWAYS_TOFROM: 5748 1.1 mrg case GOMP_MAP_RELEASE: 5749 1.1 mrg case GOMP_MAP_DELETE: 5750 1.1 mrg case GOMP_MAP_FORCE_TO: 5751 1.1 mrg case GOMP_MAP_FORCE_FROM: 5752 1.1 mrg case GOMP_MAP_FORCE_TOFROM: 5753 1.1 mrg case GOMP_MAP_FORCE_PRESENT: 5754 1.1 mrg OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1; 5755 1.1 mrg break; 5756 1.1 mrg default: 5757 1.1 mrg break; 5758 1.1 mrg } 5759 1.1 mrg bool reference_always_pointer = true; 5760 1.1 mrg tree c2 = build_omp_clause (OMP_CLAUSE_LOCATION (c), 5761 1.1 mrg OMP_CLAUSE_MAP); 5762 1.1 mrg if (TREE_CODE (t) == COMPONENT_REF) 5763 1.1 mrg { 5764 1.1 mrg OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_ATTACH_DETACH); 5765 1.1 mrg 5766 1.1 mrg if ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP 5767 1.1 mrg && TYPE_REF_P (TREE_TYPE (t))) 5768 1.1 mrg { 5769 1.1 mrg if (TREE_CODE (TREE_TYPE (TREE_TYPE (t))) == ARRAY_TYPE) 5770 1.1 mrg OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_ALWAYS_POINTER); 5771 1.1 mrg else 5772 1.1 mrg t = convert_from_reference (t); 5773 1.1 mrg 5774 1.1 mrg reference_always_pointer = false; 5775 1.1 mrg } 5776 1.1 mrg } 5777 1.1 mrg else if (REFERENCE_REF_P (t) 5778 1.1 mrg && TREE_CODE (TREE_OPERAND (t, 0)) == COMPONENT_REF) 5779 1.1 mrg { 5780 1.1 mrg gomp_map_kind k; 5781 1.1 mrg if ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP 5782 1.1 mrg && TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE) 5783 1.1 mrg k = GOMP_MAP_ATTACH_DETACH; 5784 1.1 mrg else 5785 1.1 mrg { 5786 1.1 mrg t = TREE_OPERAND (t, 0); 5787 1.1 mrg k = (ort == C_ORT_ACC 5788 1.1 mrg ? GOMP_MAP_ATTACH_DETACH : GOMP_MAP_ALWAYS_POINTER); 5789 1.1 mrg } 5790 1.1 mrg OMP_CLAUSE_SET_MAP_KIND (c2, k); 5791 1.1 mrg } 5792 1.1 mrg else 5793 1.1 mrg OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_FIRSTPRIVATE_POINTER); 5794 1.1 mrg OMP_CLAUSE_MAP_IMPLICIT (c2) = OMP_CLAUSE_MAP_IMPLICIT (c); 5795 1.1 mrg if (OMP_CLAUSE_MAP_KIND (c2) != GOMP_MAP_FIRSTPRIVATE_POINTER 5796 1.1 mrg && !cxx_mark_addressable (t)) 5797 1.1 mrg return false; 5798 1.1 mrg OMP_CLAUSE_DECL (c2) = t; 5799 1.1 mrg t = build_fold_addr_expr (first); 5800 1.1 mrg t = fold_convert_loc (OMP_CLAUSE_LOCATION (c), 5801 1.1 mrg ptrdiff_type_node, t); 5802 1.1 mrg tree ptr = OMP_CLAUSE_DECL (c2); 5803 1.1 mrg ptr = convert_from_reference (ptr); 5804 1.1 mrg if (!INDIRECT_TYPE_P (TREE_TYPE (ptr))) 5805 1.1 mrg ptr = build_fold_addr_expr (ptr); 5806 1.1 mrg t = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR, 5807 1.1 mrg ptrdiff_type_node, t, 5808 1.1 mrg fold_convert_loc (OMP_CLAUSE_LOCATION (c), 5809 1.1 mrg ptrdiff_type_node, ptr)); 5810 1.1 mrg OMP_CLAUSE_SIZE (c2) = t; 5811 1.1 mrg OMP_CLAUSE_CHAIN (c2) = OMP_CLAUSE_CHAIN (c); 5812 1.1 mrg OMP_CLAUSE_CHAIN (c) = c2; 5813 1.1 mrg 5814 1.1 mrg ptr = OMP_CLAUSE_DECL (c2); 5815 1.1 mrg if (reference_always_pointer 5816 1.1 mrg && OMP_CLAUSE_MAP_KIND (c2) != GOMP_MAP_FIRSTPRIVATE_POINTER 5817 1.1 mrg && TYPE_REF_P (TREE_TYPE (ptr)) 5818 1.1 mrg && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (ptr)))) 5819 1.1 mrg { 5820 1.1 mrg tree c3 = build_omp_clause (OMP_CLAUSE_LOCATION (c), 5821 1.1 mrg OMP_CLAUSE_MAP); 5822 1.1 mrg OMP_CLAUSE_SET_MAP_KIND (c3, OMP_CLAUSE_MAP_KIND (c2)); 5823 1.1 mrg OMP_CLAUSE_MAP_IMPLICIT (c2) = OMP_CLAUSE_MAP_IMPLICIT (c); 5824 1.1 mrg OMP_CLAUSE_DECL (c3) = ptr; 5825 1.1 mrg if (OMP_CLAUSE_MAP_KIND (c2) == GOMP_MAP_ALWAYS_POINTER 5826 1.1 mrg || OMP_CLAUSE_MAP_KIND (c2) == GOMP_MAP_ATTACH_DETACH) 5827 1.1 mrg { 5828 1.1 mrg OMP_CLAUSE_DECL (c2) = build_simple_mem_ref (ptr); 5829 1.1 mrg OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_ALWAYS_POINTER); 5830 1.1 mrg } 5831 1.1 mrg else 5832 1.1 mrg OMP_CLAUSE_DECL (c2) = convert_from_reference (ptr); 5833 1.1 mrg OMP_CLAUSE_SIZE (c3) = size_zero_node; 5834 1.1 mrg OMP_CLAUSE_CHAIN (c3) = OMP_CLAUSE_CHAIN (c2); 5835 1.1 mrg OMP_CLAUSE_CHAIN (c2) = c3; 5836 1.1 mrg } 5837 1.1 mrg } 5838 1.1 mrg } 5839 1.1 mrg return false; 5840 1.1 mrg } 5841 1.1 mrg 5842 1.1 mrg /* Return identifier to look up for omp declare reduction. */ 5843 1.1 mrg 5844 1.1 mrg tree 5845 1.1 mrg omp_reduction_id (enum tree_code reduction_code, tree reduction_id, tree type) 5846 1.1 mrg { 5847 1.1 mrg const char *p = NULL; 5848 1.1 mrg const char *m = NULL; 5849 1.1 mrg switch (reduction_code) 5850 1.1 mrg { 5851 1.1 mrg case PLUS_EXPR: 5852 1.1 mrg case MULT_EXPR: 5853 1.1 mrg case MINUS_EXPR: 5854 1.1 mrg case BIT_AND_EXPR: 5855 1.1 mrg case BIT_XOR_EXPR: 5856 1.1 mrg case BIT_IOR_EXPR: 5857 1.1 mrg case TRUTH_ANDIF_EXPR: 5858 1.1 mrg case TRUTH_ORIF_EXPR: 5859 1.1 mrg reduction_id = ovl_op_identifier (false, reduction_code); 5860 1.1 mrg break; 5861 1.1 mrg case MIN_EXPR: 5862 1.1 mrg p = "min"; 5863 1.1 mrg break; 5864 1.1 mrg case MAX_EXPR: 5865 1.1 mrg p = "max"; 5866 1.1 mrg break; 5867 1.1 mrg default: 5868 1.1 mrg break; 5869 1.1 mrg } 5870 1.1 mrg 5871 1.1 mrg if (p == NULL) 5872 1.1 mrg { 5873 1.1 mrg if (TREE_CODE (reduction_id) != IDENTIFIER_NODE) 5874 1.1 mrg return error_mark_node; 5875 1.1 mrg p = IDENTIFIER_POINTER (reduction_id); 5876 1.1 mrg } 5877 1.1 mrg 5878 1.1 mrg if (type != NULL_TREE) 5879 1.1 mrg m = mangle_type_string (TYPE_MAIN_VARIANT (type)); 5880 1.1 mrg 5881 1.1 mrg const char prefix[] = "omp declare reduction "; 5882 1.1 mrg size_t lenp = sizeof (prefix); 5883 1.1 mrg if (strncmp (p, prefix, lenp - 1) == 0) 5884 1.1 mrg lenp = 1; 5885 1.1 mrg size_t len = strlen (p); 5886 1.1 mrg size_t lenm = m ? strlen (m) + 1 : 0; 5887 1.1 mrg char *name = XALLOCAVEC (char, lenp + len + lenm); 5888 1.1 mrg if (lenp > 1) 5889 1.1 mrg memcpy (name, prefix, lenp - 1); 5890 1.1 mrg memcpy (name + lenp - 1, p, len + 1); 5891 1.1 mrg if (m) 5892 1.1 mrg { 5893 1.1 mrg name[lenp + len - 1] = '~'; 5894 1.1 mrg memcpy (name + lenp + len, m, lenm); 5895 1.1 mrg } 5896 1.1 mrg return get_identifier (name); 5897 1.1 mrg } 5898 1.1 mrg 5899 1.1 mrg /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial 5900 1.1 mrg FUNCTION_DECL or NULL_TREE if not found. */ 5901 1.1 mrg 5902 1.1 mrg static tree 5903 1.1 mrg omp_reduction_lookup (location_t loc, tree id, tree type, tree *baselinkp, 5904 1.1 mrg vec<tree> *ambiguousp) 5905 1.1 mrg { 5906 1.1 mrg tree orig_id = id; 5907 1.1 mrg tree baselink = NULL_TREE; 5908 1.1 mrg if (identifier_p (id)) 5909 1.1 mrg { 5910 1.1 mrg cp_id_kind idk; 5911 1.1 mrg bool nonint_cst_expression_p; 5912 1.1 mrg const char *error_msg; 5913 1.1 mrg id = omp_reduction_id (ERROR_MARK, id, type); 5914 1.1 mrg tree decl = lookup_name (id); 5915 1.1 mrg if (decl == NULL_TREE) 5916 1.1 mrg decl = error_mark_node; 5917 1.1 mrg id = finish_id_expression (id, decl, NULL_TREE, &idk, false, true, 5918 1.1 mrg &nonint_cst_expression_p, false, true, false, 5919 1.1 mrg false, &error_msg, loc); 5920 1.1 mrg if (idk == CP_ID_KIND_UNQUALIFIED 5921 1.1 mrg && identifier_p (id)) 5922 1.1 mrg { 5923 1.1 mrg vec<tree, va_gc> *args = NULL; 5924 1.1 mrg vec_safe_push (args, build_reference_type (type)); 5925 1.1 mrg id = perform_koenig_lookup (id, args, tf_none); 5926 1.1 mrg } 5927 1.1 mrg } 5928 1.1 mrg else if (TREE_CODE (id) == SCOPE_REF) 5929 1.1 mrg id = lookup_qualified_name (TREE_OPERAND (id, 0), 5930 1.1 mrg omp_reduction_id (ERROR_MARK, 5931 1.1 mrg TREE_OPERAND (id, 1), 5932 1.1 mrg type), 5933 1.1 mrg LOOK_want::NORMAL, false); 5934 1.1 mrg tree fns = id; 5935 1.1 mrg id = NULL_TREE; 5936 1.1 mrg if (fns && is_overloaded_fn (fns)) 5937 1.1 mrg { 5938 1.1 mrg for (lkp_iterator iter (get_fns (fns)); iter; ++iter) 5939 1.1 mrg { 5940 1.1 mrg tree fndecl = *iter; 5941 1.1 mrg if (TREE_CODE (fndecl) == FUNCTION_DECL) 5942 1.1 mrg { 5943 1.1 mrg tree argtype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl))); 5944 1.1 mrg if (same_type_p (TREE_TYPE (argtype), type)) 5945 1.1 mrg { 5946 1.1 mrg id = fndecl; 5947 1.1 mrg break; 5948 1.1 mrg } 5949 1.1 mrg } 5950 1.1 mrg } 5951 1.1 mrg 5952 1.1 mrg if (id && BASELINK_P (fns)) 5953 1.1 mrg { 5954 1.1 mrg if (baselinkp) 5955 1.1 mrg *baselinkp = fns; 5956 1.1 mrg else 5957 1.1 mrg baselink = fns; 5958 1.1 mrg } 5959 1.1 mrg } 5960 1.1 mrg 5961 1.1 mrg if (!id && CLASS_TYPE_P (type) && TYPE_BINFO (type)) 5962 1.1 mrg { 5963 1.1 mrg auto_vec<tree> ambiguous; 5964 1.1 mrg tree binfo = TYPE_BINFO (type), base_binfo, ret = NULL_TREE; 5965 1.1 mrg unsigned int ix; 5966 1.1 mrg if (ambiguousp == NULL) 5967 1.1 mrg ambiguousp = &ambiguous; 5968 1.1 mrg for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++) 5969 1.1 mrg { 5970 1.1 mrg id = omp_reduction_lookup (loc, orig_id, BINFO_TYPE (base_binfo), 5971 1.1 mrg baselinkp ? baselinkp : &baselink, 5972 1.1 mrg ambiguousp); 5973 1.1 mrg if (id == NULL_TREE) 5974 1.1 mrg continue; 5975 1.1 mrg if (!ambiguousp->is_empty ()) 5976 1.1 mrg ambiguousp->safe_push (id); 5977 1.1 mrg else if (ret != NULL_TREE) 5978 1.1 mrg { 5979 1.1 mrg ambiguousp->safe_push (ret); 5980 1.1 mrg ambiguousp->safe_push (id); 5981 1.1 mrg ret = NULL_TREE; 5982 1.1 mrg } 5983 1.1 mrg else 5984 1.1 mrg ret = id; 5985 1.1 mrg } 5986 1.1 mrg if (ambiguousp != &ambiguous) 5987 1.1 mrg return ret; 5988 1.1 mrg if (!ambiguous.is_empty ()) 5989 1.1 mrg { 5990 1.1 mrg const char *str = _("candidates are:"); 5991 1.1 mrg unsigned int idx; 5992 1.1 mrg tree udr; 5993 1.1 mrg error_at (loc, "user defined reduction lookup is ambiguous"); 5994 1.1 mrg FOR_EACH_VEC_ELT (ambiguous, idx, udr) 5995 1.1 mrg { 5996 1.1 mrg inform (DECL_SOURCE_LOCATION (udr), "%s %#qD", str, udr); 5997 1.1 mrg if (idx == 0) 5998 1.1 mrg str = get_spaces (str); 5999 1.1 mrg } 6000 1.1 mrg ret = error_mark_node; 6001 1.1 mrg baselink = NULL_TREE; 6002 1.1 mrg } 6003 1.1 mrg id = ret; 6004 1.1 mrg } 6005 1.1 mrg if (id && baselink) 6006 1.1 mrg perform_or_defer_access_check (BASELINK_BINFO (baselink), 6007 1.1 mrg id, id, tf_warning_or_error); 6008 1.1 mrg return id; 6009 1.1 mrg } 6010 1.1 mrg 6011 1.1 mrg /* Helper function for cp_parser_omp_declare_reduction_exprs 6012 1.1 mrg and tsubst_omp_udr. 6013 1.1 mrg Remove CLEANUP_STMT for data (omp_priv variable). 6014 1.1 mrg Also append INIT_EXPR for DECL_INITIAL of omp_priv after its 6015 1.1 mrg DECL_EXPR. */ 6016 1.1 mrg 6017 1.1 mrg tree 6018 1.1 mrg cp_remove_omp_priv_cleanup_stmt (tree *tp, int *walk_subtrees, void *data) 6019 1.1 mrg { 6020 1.1 mrg if (TYPE_P (*tp)) 6021 1.1 mrg *walk_subtrees = 0; 6022 1.1 mrg else if (TREE_CODE (*tp) == CLEANUP_STMT && CLEANUP_DECL (*tp) == (tree) data) 6023 1.1 mrg *tp = CLEANUP_BODY (*tp); 6024 1.1 mrg else if (TREE_CODE (*tp) == DECL_EXPR) 6025 1.1 mrg { 6026 1.1 mrg tree decl = DECL_EXPR_DECL (*tp); 6027 1.1 mrg if (!processing_template_decl 6028 1.1 mrg && decl == (tree) data 6029 1.1 mrg && DECL_INITIAL (decl) 6030 1.1 mrg && DECL_INITIAL (decl) != error_mark_node) 6031 1.1 mrg { 6032 1.1 mrg tree list = NULL_TREE; 6033 1.1 mrg append_to_statement_list_force (*tp, &list); 6034 1.1 mrg tree init_expr = build2 (INIT_EXPR, void_type_node, 6035 1.1 mrg decl, DECL_INITIAL (decl)); 6036 1.1 mrg DECL_INITIAL (decl) = NULL_TREE; 6037 1.1 mrg append_to_statement_list_force (init_expr, &list); 6038 1.1 mrg *tp = list; 6039 1.1 mrg } 6040 1.1 mrg } 6041 1.1 mrg return NULL_TREE; 6042 1.1 mrg } 6043 1.1 mrg 6044 1.1 mrg /* Data passed from cp_check_omp_declare_reduction to 6045 1.1 mrg cp_check_omp_declare_reduction_r. */ 6046 1.1 mrg 6047 1.1 mrg struct cp_check_omp_declare_reduction_data 6048 1.1 mrg { 6049 1.1 mrg location_t loc; 6050 1.1 mrg tree stmts[7]; 6051 1.1 mrg bool combiner_p; 6052 1.1 mrg }; 6053 1.1 mrg 6054 1.1 mrg /* Helper function for cp_check_omp_declare_reduction, called via 6055 1.1 mrg cp_walk_tree. */ 6056 1.1 mrg 6057 1.1 mrg static tree 6058 1.1 mrg cp_check_omp_declare_reduction_r (tree *tp, int *, void *data) 6059 1.1 mrg { 6060 1.1 mrg struct cp_check_omp_declare_reduction_data *udr_data 6061 1.1 mrg = (struct cp_check_omp_declare_reduction_data *) data; 6062 1.1 mrg if (SSA_VAR_P (*tp) 6063 1.1 mrg && !DECL_ARTIFICIAL (*tp) 6064 1.1 mrg && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 0 : 3]) 6065 1.1 mrg && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 1 : 4])) 6066 1.1 mrg { 6067 1.1 mrg location_t loc = udr_data->loc; 6068 1.1 mrg if (udr_data->combiner_p) 6069 1.1 mrg error_at (loc, "%<#pragma omp declare reduction%> combiner refers to " 6070 1.1 mrg "variable %qD which is not %<omp_out%> nor %<omp_in%>", 6071 1.1 mrg *tp); 6072 1.1 mrg else 6073 1.1 mrg error_at (loc, "%<#pragma omp declare reduction%> initializer refers " 6074 1.1 mrg "to variable %qD which is not %<omp_priv%> nor " 6075 1.1 mrg "%<omp_orig%>", 6076 1.1 mrg *tp); 6077 1.1 mrg return *tp; 6078 1.1 mrg } 6079 1.1 mrg return NULL_TREE; 6080 1.1 mrg } 6081 1.1 mrg 6082 1.1 mrg /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions. */ 6083 1.1 mrg 6084 1.1 mrg bool 6085 1.1 mrg cp_check_omp_declare_reduction (tree udr) 6086 1.1 mrg { 6087 1.1 mrg tree type = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr))); 6088 1.1 mrg gcc_assert (TYPE_REF_P (type)); 6089 1.1 mrg type = TREE_TYPE (type); 6090 1.1 mrg int i; 6091 1.1 mrg location_t loc = DECL_SOURCE_LOCATION (udr); 6092 1.1 mrg 6093 1.1 mrg if (type == error_mark_node) 6094 1.1 mrg return false; 6095 1.1 mrg if (ARITHMETIC_TYPE_P (type)) 6096 1.1 mrg { 6097 1.1 mrg static enum tree_code predef_codes[] 6098 1.1 mrg = { PLUS_EXPR, MULT_EXPR, MINUS_EXPR, BIT_AND_EXPR, BIT_XOR_EXPR, 6099 1.1 mrg BIT_IOR_EXPR, TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR }; 6100 1.1 mrg for (i = 0; i < 8; i++) 6101 1.1 mrg { 6102 1.1 mrg tree id = omp_reduction_id (predef_codes[i], NULL_TREE, NULL_TREE); 6103 1.1 mrg const char *n1 = IDENTIFIER_POINTER (DECL_NAME (udr)); 6104 1.1 mrg const char *n2 = IDENTIFIER_POINTER (id); 6105 1.1 mrg if (strncmp (n1, n2, IDENTIFIER_LENGTH (id)) == 0 6106 1.1 mrg && (n1[IDENTIFIER_LENGTH (id)] == '~' 6107 1.1 mrg || n1[IDENTIFIER_LENGTH (id)] == '\0')) 6108 1.1 mrg break; 6109 1.1 mrg } 6110 1.1 mrg 6111 1.1 mrg if (i == 8 6112 1.1 mrg && TREE_CODE (type) != COMPLEX_EXPR) 6113 1.1 mrg { 6114 1.1 mrg const char prefix_minmax[] = "omp declare reduction m"; 6115 1.1 mrg size_t prefix_size = sizeof (prefix_minmax) - 1; 6116 1.1 mrg const char *n = IDENTIFIER_POINTER (DECL_NAME (udr)); 6117 1.1 mrg if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr)), 6118 1.1 mrg prefix_minmax, prefix_size) == 0 6119 1.1 mrg && ((n[prefix_size] == 'i' && n[prefix_size + 1] == 'n') 6120 1.1 mrg || (n[prefix_size] == 'a' && n[prefix_size + 1] == 'x')) 6121 1.1 mrg && (n[prefix_size + 2] == '~' || n[prefix_size + 2] == '\0')) 6122 1.1 mrg i = 0; 6123 1.1 mrg } 6124 1.1 mrg if (i < 8) 6125 1.1 mrg { 6126 1.1 mrg error_at (loc, "predeclared arithmetic type %qT in " 6127 1.1 mrg "%<#pragma omp declare reduction%>", type); 6128 1.1 mrg return false; 6129 1.1 mrg } 6130 1.1 mrg } 6131 1.1 mrg else if (FUNC_OR_METHOD_TYPE_P (type) 6132 1.1 mrg || TREE_CODE (type) == ARRAY_TYPE) 6133 1.1 mrg { 6134 1.1 mrg error_at (loc, "function or array type %qT in " 6135 1.1 mrg "%<#pragma omp declare reduction%>", type); 6136 1.1 mrg return false; 6137 1.1 mrg } 6138 1.1 mrg else if (TYPE_REF_P (type)) 6139 1.1 mrg { 6140 1.1 mrg error_at (loc, "reference type %qT in %<#pragma omp declare reduction%>", 6141 1.1 mrg type); 6142 1.1 mrg return false; 6143 1.1 mrg } 6144 1.1 mrg else if (TYPE_QUALS_NO_ADDR_SPACE (type)) 6145 1.1 mrg { 6146 1.1 mrg error_at (loc, "%<const%>, %<volatile%> or %<__restrict%>-qualified " 6147 1.1 mrg "type %qT in %<#pragma omp declare reduction%>", type); 6148 1.1 mrg return false; 6149 1.1 mrg } 6150 1.1 mrg 6151 1.1 mrg tree body = DECL_SAVED_TREE (udr); 6152 1.1 mrg if (body == NULL_TREE || TREE_CODE (body) != STATEMENT_LIST) 6153 1.1 mrg return true; 6154 1.1 mrg 6155 1.1 mrg tree_stmt_iterator tsi; 6156 1.1 mrg struct cp_check_omp_declare_reduction_data data; 6157 1.1 mrg memset (data.stmts, 0, sizeof data.stmts); 6158 1.1 mrg for (i = 0, tsi = tsi_start (body); 6159 1.1 mrg i < 7 && !tsi_end_p (tsi); 6160 1.1 mrg i++, tsi_next (&tsi)) 6161 1.1 mrg data.stmts[i] = tsi_stmt (tsi); 6162 1.1 mrg data.loc = loc; 6163 1.1 mrg gcc_assert (tsi_end_p (tsi)); 6164 1.1 mrg if (i >= 3) 6165 1.1 mrg { 6166 1.1 mrg gcc_assert (TREE_CODE (data.stmts[0]) == DECL_EXPR 6167 1.1 mrg && TREE_CODE (data.stmts[1]) == DECL_EXPR); 6168 1.1 mrg if (warning_suppressed_p (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */)) 6169 1.1 mrg return true; 6170 1.1 mrg data.combiner_p = true; 6171 1.1 mrg if (cp_walk_tree (&data.stmts[2], cp_check_omp_declare_reduction_r, 6172 1.1 mrg &data, NULL)) 6173 1.1 mrg suppress_warning (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */); 6174 1.1 mrg } 6175 1.1 mrg if (i >= 6) 6176 1.1 mrg { 6177 1.1 mrg gcc_assert (TREE_CODE (data.stmts[3]) == DECL_EXPR 6178 1.1 mrg && TREE_CODE (data.stmts[4]) == DECL_EXPR); 6179 1.1 mrg data.combiner_p = false; 6180 1.1 mrg if (cp_walk_tree (&data.stmts[5], cp_check_omp_declare_reduction_r, 6181 1.1 mrg &data, NULL) 6182 1.1 mrg || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data.stmts[3])), 6183 1.1 mrg cp_check_omp_declare_reduction_r, &data, NULL)) 6184 1.1 mrg suppress_warning (DECL_EXPR_DECL (data.stmts[0]) /* Wat warning? */); 6185 1.1 mrg if (i == 7) 6186 1.1 mrg gcc_assert (TREE_CODE (data.stmts[6]) == DECL_EXPR); 6187 1.1 mrg } 6188 1.1 mrg return true; 6189 1.1 mrg } 6190 1.1 mrg 6191 1.1 mrg /* Helper function of finish_omp_clauses. Clone STMT as if we were making 6192 1.1 mrg an inline call. But, remap 6193 1.1 mrg the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER 6194 1.1 mrg and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */ 6195 1.1 mrg 6196 1.1 mrg static tree 6197 1.1 mrg clone_omp_udr (tree stmt, tree omp_decl1, tree omp_decl2, 6198 1.1 mrg tree decl, tree placeholder) 6199 1.1 mrg { 6200 1.1 mrg copy_body_data id; 6201 1.1 mrg hash_map<tree, tree> decl_map; 6202 1.1 mrg 6203 1.1 mrg decl_map.put (omp_decl1, placeholder); 6204 1.1 mrg decl_map.put (omp_decl2, decl); 6205 1.1 mrg memset (&id, 0, sizeof (id)); 6206 1.1 mrg id.src_fn = DECL_CONTEXT (omp_decl1); 6207 1.1 mrg id.dst_fn = current_function_decl; 6208 1.1 mrg id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn); 6209 1.1 mrg id.decl_map = &decl_map; 6210 1.1 mrg 6211 1.1 mrg id.copy_decl = copy_decl_no_change; 6212 1.1 mrg id.transform_call_graph_edges = CB_CGE_DUPLICATE; 6213 1.1 mrg id.transform_new_cfg = true; 6214 1.1 mrg id.transform_return_to_modify = false; 6215 1.1 mrg id.eh_lp_nr = 0; 6216 1.1 mrg walk_tree (&stmt, copy_tree_body_r, &id, NULL); 6217 1.1 mrg return stmt; 6218 1.1 mrg } 6219 1.1 mrg 6220 1.1 mrg /* Helper function of finish_omp_clauses, called via cp_walk_tree. 6221 1.1 mrg Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */ 6222 1.1 mrg 6223 1.1 mrg static tree 6224 1.1 mrg find_omp_placeholder_r (tree *tp, int *, void *data) 6225 1.1 mrg { 6226 1.1 mrg if (*tp == (tree) data) 6227 1.1 mrg return *tp; 6228 1.1 mrg return NULL_TREE; 6229 1.1 mrg } 6230 1.1 mrg 6231 1.1 mrg /* Helper function of finish_omp_clauses. Handle OMP_CLAUSE_REDUCTION C. 6232 1.1 mrg Return true if there is some error and the clause should be removed. */ 6233 1.1 mrg 6234 1.1 mrg static bool 6235 1.1 mrg finish_omp_reduction_clause (tree c, bool *need_default_ctor, bool *need_dtor) 6236 1.1 mrg { 6237 1.1 mrg tree t = OMP_CLAUSE_DECL (c); 6238 1.1 mrg bool predefined = false; 6239 1.1 mrg if (TREE_CODE (t) == TREE_LIST) 6240 1.1 mrg { 6241 1.1 mrg gcc_assert (processing_template_decl); 6242 1.1 mrg return false; 6243 1.1 mrg } 6244 1.1 mrg tree type = TREE_TYPE (t); 6245 1.1 mrg if (TREE_CODE (t) == MEM_REF) 6246 1.1 mrg type = TREE_TYPE (type); 6247 1.1 mrg if (TYPE_REF_P (type)) 6248 1.1 mrg type = TREE_TYPE (type); 6249 1.1 mrg if (TREE_CODE (type) == ARRAY_TYPE) 6250 1.1 mrg { 6251 1.1 mrg tree oatype = type; 6252 1.1 mrg gcc_assert (TREE_CODE (t) != MEM_REF); 6253 1.1 mrg while (TREE_CODE (type) == ARRAY_TYPE) 6254 1.1 mrg type = TREE_TYPE (type); 6255 1.1 mrg if (!processing_template_decl) 6256 1.1 mrg { 6257 1.1 mrg t = require_complete_type (t); 6258 1.1 mrg if (t == error_mark_node 6259 1.1 mrg || !complete_type_or_else (oatype, NULL_TREE)) 6260 1.1 mrg return true; 6261 1.1 mrg tree size = size_binop (EXACT_DIV_EXPR, TYPE_SIZE_UNIT (oatype), 6262 1.1 mrg TYPE_SIZE_UNIT (type)); 6263 1.1 mrg if (integer_zerop (size)) 6264 1.1 mrg { 6265 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 6266 1.1 mrg "%qE in %<reduction%> clause is a zero size array", 6267 1.1 mrg omp_clause_printable_decl (t)); 6268 1.1 mrg return true; 6269 1.1 mrg } 6270 1.1 mrg size = size_binop (MINUS_EXPR, size, size_one_node); 6271 1.1 mrg size = save_expr (size); 6272 1.1 mrg tree index_type = build_index_type (size); 6273 1.1 mrg tree atype = build_array_type (type, index_type); 6274 1.1 mrg tree ptype = build_pointer_type (type); 6275 1.1 mrg if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE) 6276 1.1 mrg t = build_fold_addr_expr (t); 6277 1.1 mrg t = build2 (MEM_REF, atype, t, build_int_cst (ptype, 0)); 6278 1.1 mrg OMP_CLAUSE_DECL (c) = t; 6279 1.1 mrg } 6280 1.1 mrg } 6281 1.1 mrg if (type == error_mark_node) 6282 1.1 mrg return true; 6283 1.1 mrg else if (ARITHMETIC_TYPE_P (type)) 6284 1.1 mrg switch (OMP_CLAUSE_REDUCTION_CODE (c)) 6285 1.1 mrg { 6286 1.1 mrg case PLUS_EXPR: 6287 1.1 mrg case MULT_EXPR: 6288 1.1 mrg case MINUS_EXPR: 6289 1.1 mrg case TRUTH_ANDIF_EXPR: 6290 1.1 mrg case TRUTH_ORIF_EXPR: 6291 1.1 mrg predefined = true; 6292 1.1 mrg break; 6293 1.1 mrg case MIN_EXPR: 6294 1.1 mrg case MAX_EXPR: 6295 1.1 mrg if (TREE_CODE (type) == COMPLEX_TYPE) 6296 1.1 mrg break; 6297 1.1 mrg predefined = true; 6298 1.1 mrg break; 6299 1.1 mrg case BIT_AND_EXPR: 6300 1.1 mrg case BIT_IOR_EXPR: 6301 1.1 mrg case BIT_XOR_EXPR: 6302 1.1 mrg if (FLOAT_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE) 6303 1.1 mrg break; 6304 1.1 mrg predefined = true; 6305 1.1 mrg break; 6306 1.1 mrg default: 6307 1.1 mrg break; 6308 1.1 mrg } 6309 1.1 mrg else if (TYPE_READONLY (type)) 6310 1.1 mrg { 6311 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 6312 1.1 mrg "%qE has const type for %<reduction%>", 6313 1.1 mrg omp_clause_printable_decl (t)); 6314 1.1 mrg return true; 6315 1.1 mrg } 6316 1.1 mrg else if (!processing_template_decl) 6317 1.1 mrg { 6318 1.1 mrg t = require_complete_type (t); 6319 1.1 mrg if (t == error_mark_node) 6320 1.1 mrg return true; 6321 1.1 mrg OMP_CLAUSE_DECL (c) = t; 6322 1.1 mrg } 6323 1.1 mrg 6324 1.1 mrg if (predefined) 6325 1.1 mrg { 6326 1.1 mrg OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE; 6327 1.1 mrg return false; 6328 1.1 mrg } 6329 1.1 mrg else if (processing_template_decl) 6330 1.1 mrg { 6331 1.1 mrg if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == error_mark_node) 6332 1.1 mrg return true; 6333 1.1 mrg return false; 6334 1.1 mrg } 6335 1.1 mrg 6336 1.1 mrg tree id = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c); 6337 1.1 mrg 6338 1.1 mrg type = TYPE_MAIN_VARIANT (type); 6339 1.1 mrg OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE; 6340 1.1 mrg if (id == NULL_TREE) 6341 1.1 mrg id = omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c), 6342 1.1 mrg NULL_TREE, NULL_TREE); 6343 1.1 mrg id = omp_reduction_lookup (OMP_CLAUSE_LOCATION (c), id, type, NULL, NULL); 6344 1.1 mrg if (id) 6345 1.1 mrg { 6346 1.1 mrg if (id == error_mark_node) 6347 1.1 mrg return true; 6348 1.1 mrg mark_used (id); 6349 1.1 mrg tree body = DECL_SAVED_TREE (id); 6350 1.1 mrg if (!body) 6351 1.1 mrg return true; 6352 1.1 mrg if (TREE_CODE (body) == STATEMENT_LIST) 6353 1.1 mrg { 6354 1.1 mrg tree_stmt_iterator tsi; 6355 1.1 mrg tree placeholder = NULL_TREE, decl_placeholder = NULL_TREE; 6356 1.1 mrg int i; 6357 1.1 mrg tree stmts[7]; 6358 1.1 mrg tree atype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id))); 6359 1.1 mrg atype = TREE_TYPE (atype); 6360 1.1 mrg bool need_static_cast = !same_type_p (type, atype); 6361 1.1 mrg memset (stmts, 0, sizeof stmts); 6362 1.1 mrg for (i = 0, tsi = tsi_start (body); 6363 1.1 mrg i < 7 && !tsi_end_p (tsi); 6364 1.1 mrg i++, tsi_next (&tsi)) 6365 1.1 mrg stmts[i] = tsi_stmt (tsi); 6366 1.1 mrg gcc_assert (tsi_end_p (tsi)); 6367 1.1 mrg 6368 1.1 mrg if (i >= 3) 6369 1.1 mrg { 6370 1.1 mrg gcc_assert (TREE_CODE (stmts[0]) == DECL_EXPR 6371 1.1 mrg && TREE_CODE (stmts[1]) == DECL_EXPR); 6372 1.1 mrg placeholder = build_lang_decl (VAR_DECL, NULL_TREE, type); 6373 1.1 mrg DECL_ARTIFICIAL (placeholder) = 1; 6374 1.1 mrg DECL_IGNORED_P (placeholder) = 1; 6375 1.1 mrg OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = placeholder; 6376 1.1 mrg if (TREE_CODE (t) == MEM_REF) 6377 1.1 mrg { 6378 1.1 mrg decl_placeholder = build_lang_decl (VAR_DECL, NULL_TREE, 6379 1.1 mrg type); 6380 1.1 mrg DECL_ARTIFICIAL (decl_placeholder) = 1; 6381 1.1 mrg DECL_IGNORED_P (decl_placeholder) = 1; 6382 1.1 mrg OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) = decl_placeholder; 6383 1.1 mrg } 6384 1.1 mrg if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[0]))) 6385 1.1 mrg cxx_mark_addressable (placeholder); 6386 1.1 mrg if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[1])) 6387 1.1 mrg && (decl_placeholder 6388 1.1 mrg || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c))))) 6389 1.1 mrg cxx_mark_addressable (decl_placeholder ? decl_placeholder 6390 1.1 mrg : OMP_CLAUSE_DECL (c)); 6391 1.1 mrg tree omp_out = placeholder; 6392 1.1 mrg tree omp_in = decl_placeholder ? decl_placeholder 6393 1.1 mrg : convert_from_reference (OMP_CLAUSE_DECL (c)); 6394 1.1 mrg if (need_static_cast) 6395 1.1 mrg { 6396 1.1 mrg tree rtype = build_reference_type (atype); 6397 1.1 mrg omp_out = build_static_cast (input_location, 6398 1.1 mrg rtype, omp_out, 6399 1.1 mrg tf_warning_or_error); 6400 1.1 mrg omp_in = build_static_cast (input_location, 6401 1.1 mrg rtype, omp_in, 6402 1.1 mrg tf_warning_or_error); 6403 1.1 mrg if (omp_out == error_mark_node || omp_in == error_mark_node) 6404 1.1 mrg return true; 6405 1.1 mrg omp_out = convert_from_reference (omp_out); 6406 1.1 mrg omp_in = convert_from_reference (omp_in); 6407 1.1 mrg } 6408 1.1 mrg OMP_CLAUSE_REDUCTION_MERGE (c) 6409 1.1 mrg = clone_omp_udr (stmts[2], DECL_EXPR_DECL (stmts[0]), 6410 1.1 mrg DECL_EXPR_DECL (stmts[1]), omp_in, omp_out); 6411 1.1 mrg } 6412 1.1 mrg if (i >= 6) 6413 1.1 mrg { 6414 1.1 mrg gcc_assert (TREE_CODE (stmts[3]) == DECL_EXPR 6415 1.1 mrg && TREE_CODE (stmts[4]) == DECL_EXPR); 6416 1.1 mrg if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[3])) 6417 1.1 mrg && (decl_placeholder 6418 1.1 mrg || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c))))) 6419 1.1 mrg cxx_mark_addressable (decl_placeholder ? decl_placeholder 6420 1.1 mrg : OMP_CLAUSE_DECL (c)); 6421 1.1 mrg if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[4]))) 6422 1.1 mrg cxx_mark_addressable (placeholder); 6423 1.1 mrg tree omp_priv = decl_placeholder ? decl_placeholder 6424 1.1 mrg : convert_from_reference (OMP_CLAUSE_DECL (c)); 6425 1.1 mrg tree omp_orig = placeholder; 6426 1.1 mrg if (need_static_cast) 6427 1.1 mrg { 6428 1.1 mrg if (i == 7) 6429 1.1 mrg { 6430 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 6431 1.1 mrg "user defined reduction with constructor " 6432 1.1 mrg "initializer for base class %qT", atype); 6433 1.1 mrg return true; 6434 1.1 mrg } 6435 1.1 mrg tree rtype = build_reference_type (atype); 6436 1.1 mrg omp_priv = build_static_cast (input_location, 6437 1.1 mrg rtype, omp_priv, 6438 1.1 mrg tf_warning_or_error); 6439 1.1 mrg omp_orig = build_static_cast (input_location, 6440 1.1 mrg rtype, omp_orig, 6441 1.1 mrg tf_warning_or_error); 6442 1.1 mrg if (omp_priv == error_mark_node 6443 1.1 mrg || omp_orig == error_mark_node) 6444 1.1 mrg return true; 6445 1.1 mrg omp_priv = convert_from_reference (omp_priv); 6446 1.1 mrg omp_orig = convert_from_reference (omp_orig); 6447 1.1 mrg } 6448 1.1 mrg if (i == 6) 6449 1.1 mrg *need_default_ctor = true; 6450 1.1 mrg OMP_CLAUSE_REDUCTION_INIT (c) 6451 1.1 mrg = clone_omp_udr (stmts[5], DECL_EXPR_DECL (stmts[4]), 6452 1.1 mrg DECL_EXPR_DECL (stmts[3]), 6453 1.1 mrg omp_priv, omp_orig); 6454 1.1 mrg if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c), 6455 1.1 mrg find_omp_placeholder_r, placeholder, NULL)) 6456 1.1 mrg OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c) = 1; 6457 1.1 mrg } 6458 1.1 mrg else if (i >= 3) 6459 1.1 mrg { 6460 1.1 mrg if (CLASS_TYPE_P (type) && !pod_type_p (type)) 6461 1.1 mrg *need_default_ctor = true; 6462 1.1 mrg else 6463 1.1 mrg { 6464 1.1 mrg tree init; 6465 1.1 mrg tree v = decl_placeholder ? decl_placeholder 6466 1.1 mrg : convert_from_reference (t); 6467 1.1 mrg if (AGGREGATE_TYPE_P (TREE_TYPE (v))) 6468 1.1 mrg init = build_constructor (TREE_TYPE (v), NULL); 6469 1.1 mrg else 6470 1.1 mrg init = fold_convert (TREE_TYPE (v), integer_zero_node); 6471 1.1 mrg OMP_CLAUSE_REDUCTION_INIT (c) 6472 1.1 mrg = build2 (INIT_EXPR, TREE_TYPE (v), v, init); 6473 1.1 mrg } 6474 1.1 mrg } 6475 1.1 mrg } 6476 1.1 mrg } 6477 1.1 mrg if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)) 6478 1.1 mrg *need_dtor = true; 6479 1.1 mrg else 6480 1.1 mrg { 6481 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 6482 1.1 mrg "user defined reduction not found for %qE", 6483 1.1 mrg omp_clause_printable_decl (t)); 6484 1.1 mrg return true; 6485 1.1 mrg } 6486 1.1 mrg if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF) 6487 1.1 mrg gcc_assert (TYPE_SIZE_UNIT (type) 6488 1.1 mrg && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST); 6489 1.1 mrg return false; 6490 1.1 mrg } 6491 1.1 mrg 6492 1.1 mrg /* Called from finish_struct_1. linear(this) or linear(this:step) 6493 1.1 mrg clauses might not be finalized yet because the class has been incomplete 6494 1.1 mrg when parsing #pragma omp declare simd methods. Fix those up now. */ 6495 1.1 mrg 6496 1.1 mrg void 6497 1.1 mrg finish_omp_declare_simd_methods (tree t) 6498 1.1 mrg { 6499 1.1 mrg if (processing_template_decl) 6500 1.1 mrg return; 6501 1.1 mrg 6502 1.1 mrg for (tree x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x)) 6503 1.1 mrg { 6504 1.1 mrg if (TREE_CODE (x) == USING_DECL 6505 1.1 mrg || !DECL_NONSTATIC_MEMBER_FUNCTION_P (x)) 6506 1.1 mrg continue; 6507 1.1 mrg tree ods = lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (x)); 6508 1.1 mrg if (!ods || !TREE_VALUE (ods)) 6509 1.1 mrg continue; 6510 1.1 mrg for (tree c = TREE_VALUE (TREE_VALUE (ods)); c; c = OMP_CLAUSE_CHAIN (c)) 6511 1.1 mrg if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR 6512 1.1 mrg && integer_zerop (OMP_CLAUSE_DECL (c)) 6513 1.1 mrg && OMP_CLAUSE_LINEAR_STEP (c) 6514 1.1 mrg && TYPE_PTR_P (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c)))) 6515 1.1 mrg { 6516 1.1 mrg tree s = OMP_CLAUSE_LINEAR_STEP (c); 6517 1.1 mrg s = fold_convert_loc (OMP_CLAUSE_LOCATION (c), sizetype, s); 6518 1.1 mrg s = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MULT_EXPR, 6519 1.1 mrg sizetype, s, TYPE_SIZE_UNIT (t)); 6520 1.1 mrg OMP_CLAUSE_LINEAR_STEP (c) = s; 6521 1.1 mrg } 6522 1.1 mrg } 6523 1.1 mrg } 6524 1.1 mrg 6525 1.1 mrg /* Adjust sink depend clause to take into account pointer offsets. 6526 1.1 mrg 6527 1.1 mrg Return TRUE if there was a problem processing the offset, and the 6528 1.1 mrg whole clause should be removed. */ 6529 1.1 mrg 6530 1.1 mrg static bool 6531 1.1 mrg cp_finish_omp_clause_depend_sink (tree sink_clause) 6532 1.1 mrg { 6533 1.1 mrg tree t = OMP_CLAUSE_DECL (sink_clause); 6534 1.1 mrg gcc_assert (TREE_CODE (t) == TREE_LIST); 6535 1.1 mrg 6536 1.1 mrg /* Make sure we don't adjust things twice for templates. */ 6537 1.1 mrg if (processing_template_decl) 6538 1.1 mrg return false; 6539 1.1 mrg 6540 1.1 mrg for (; t; t = TREE_CHAIN (t)) 6541 1.1 mrg { 6542 1.1 mrg tree decl = TREE_VALUE (t); 6543 1.1 mrg if (TYPE_PTR_P (TREE_TYPE (decl))) 6544 1.1 mrg { 6545 1.1 mrg tree offset = TREE_PURPOSE (t); 6546 1.1 mrg bool neg = wi::neg_p (wi::to_wide (offset)); 6547 1.1 mrg offset = fold_unary (ABS_EXPR, TREE_TYPE (offset), offset); 6548 1.1 mrg decl = mark_rvalue_use (decl); 6549 1.1 mrg decl = convert_from_reference (decl); 6550 1.1 mrg tree t2 = pointer_int_sum (OMP_CLAUSE_LOCATION (sink_clause), 6551 1.1 mrg neg ? MINUS_EXPR : PLUS_EXPR, 6552 1.1 mrg decl, offset); 6553 1.1 mrg t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (sink_clause), 6554 1.1 mrg MINUS_EXPR, sizetype, 6555 1.1 mrg fold_convert (sizetype, t2), 6556 1.1 mrg fold_convert (sizetype, decl)); 6557 1.1 mrg if (t2 == error_mark_node) 6558 1.1 mrg return true; 6559 1.1 mrg TREE_PURPOSE (t) = t2; 6560 1.1 mrg } 6561 1.1 mrg } 6562 1.1 mrg return false; 6563 1.1 mrg } 6564 1.1 mrg 6565 1.1 mrg /* Finish OpenMP iterators ITER. Return true if they are errorneous 6566 1.1 mrg and clauses containing them should be removed. */ 6567 1.1 mrg 6568 1.1 mrg static bool 6569 1.1 mrg cp_omp_finish_iterators (tree iter) 6570 1.1 mrg { 6571 1.1 mrg bool ret = false; 6572 1.1 mrg for (tree it = iter; it; it = TREE_CHAIN (it)) 6573 1.1 mrg { 6574 1.1 mrg tree var = TREE_VEC_ELT (it, 0); 6575 1.1 mrg tree begin = TREE_VEC_ELT (it, 1); 6576 1.1 mrg tree end = TREE_VEC_ELT (it, 2); 6577 1.1 mrg tree step = TREE_VEC_ELT (it, 3); 6578 1.1 mrg tree orig_step; 6579 1.1 mrg tree type = TREE_TYPE (var); 6580 1.1 mrg location_t loc = DECL_SOURCE_LOCATION (var); 6581 1.1 mrg if (type == error_mark_node) 6582 1.1 mrg { 6583 1.1 mrg ret = true; 6584 1.1 mrg continue; 6585 1.1 mrg } 6586 1.1 mrg if (type_dependent_expression_p (var)) 6587 1.1 mrg continue; 6588 1.1 mrg if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type)) 6589 1.1 mrg { 6590 1.1 mrg error_at (loc, "iterator %qD has neither integral nor pointer type", 6591 1.1 mrg var); 6592 1.1 mrg ret = true; 6593 1.1 mrg continue; 6594 1.1 mrg } 6595 1.1 mrg else if (TYPE_READONLY (type)) 6596 1.1 mrg { 6597 1.1 mrg error_at (loc, "iterator %qD has const qualified type", var); 6598 1.1 mrg ret = true; 6599 1.1 mrg continue; 6600 1.1 mrg } 6601 1.1 mrg if (type_dependent_expression_p (begin) 6602 1.1 mrg || type_dependent_expression_p (end) 6603 1.1 mrg || type_dependent_expression_p (step)) 6604 1.1 mrg continue; 6605 1.1 mrg else if (error_operand_p (step)) 6606 1.1 mrg { 6607 1.1 mrg ret = true; 6608 1.1 mrg continue; 6609 1.1 mrg } 6610 1.1 mrg else if (!INTEGRAL_TYPE_P (TREE_TYPE (step))) 6611 1.1 mrg { 6612 1.1 mrg error_at (EXPR_LOC_OR_LOC (step, loc), 6613 1.1 mrg "iterator step with non-integral type"); 6614 1.1 mrg ret = true; 6615 1.1 mrg continue; 6616 1.1 mrg } 6617 1.1 mrg 6618 1.1 mrg begin = mark_rvalue_use (begin); 6619 1.1 mrg end = mark_rvalue_use (end); 6620 1.1 mrg step = mark_rvalue_use (step); 6621 1.1 mrg begin = cp_build_c_cast (input_location, type, begin, 6622 1.1 mrg tf_warning_or_error); 6623 1.1 mrg end = cp_build_c_cast (input_location, type, end, 6624 1.1 mrg tf_warning_or_error); 6625 1.1 mrg orig_step = step; 6626 1.1 mrg if (!processing_template_decl) 6627 1.1 mrg step = orig_step = save_expr (step); 6628 1.1 mrg tree stype = POINTER_TYPE_P (type) ? sizetype : type; 6629 1.1 mrg step = cp_build_c_cast (input_location, stype, step, 6630 1.1 mrg tf_warning_or_error); 6631 1.1 mrg if (POINTER_TYPE_P (type) && !processing_template_decl) 6632 1.1 mrg { 6633 1.1 mrg begin = save_expr (begin); 6634 1.1 mrg step = pointer_int_sum (loc, PLUS_EXPR, begin, step); 6635 1.1 mrg step = fold_build2_loc (loc, MINUS_EXPR, sizetype, 6636 1.1 mrg fold_convert (sizetype, step), 6637 1.1 mrg fold_convert (sizetype, begin)); 6638 1.1 mrg step = fold_convert (ssizetype, step); 6639 1.1 mrg } 6640 1.1 mrg if (!processing_template_decl) 6641 1.1 mrg { 6642 1.1 mrg begin = maybe_constant_value (begin); 6643 1.1 mrg end = maybe_constant_value (end); 6644 1.1 mrg step = maybe_constant_value (step); 6645 1.1 mrg orig_step = maybe_constant_value (orig_step); 6646 1.1 mrg } 6647 1.1 mrg if (integer_zerop (step)) 6648 1.1 mrg { 6649 1.1 mrg error_at (loc, "iterator %qD has zero step", var); 6650 1.1 mrg ret = true; 6651 1.1 mrg continue; 6652 1.1 mrg } 6653 1.1 mrg 6654 1.1 mrg if (begin == error_mark_node 6655 1.1 mrg || end == error_mark_node 6656 1.1 mrg || step == error_mark_node 6657 1.1 mrg || orig_step == error_mark_node) 6658 1.1 mrg { 6659 1.1 mrg ret = true; 6660 1.1 mrg continue; 6661 1.1 mrg } 6662 1.1 mrg 6663 1.1 mrg if (!processing_template_decl) 6664 1.1 mrg { 6665 1.1 mrg begin = fold_build_cleanup_point_expr (TREE_TYPE (begin), begin); 6666 1.1 mrg end = fold_build_cleanup_point_expr (TREE_TYPE (end), end); 6667 1.1 mrg step = fold_build_cleanup_point_expr (TREE_TYPE (step), step); 6668 1.1 mrg orig_step = fold_build_cleanup_point_expr (TREE_TYPE (orig_step), 6669 1.1 mrg orig_step); 6670 1.1 mrg } 6671 1.1 mrg hash_set<tree> pset; 6672 1.1 mrg tree it2; 6673 1.1 mrg for (it2 = TREE_CHAIN (it); it2; it2 = TREE_CHAIN (it2)) 6674 1.1 mrg { 6675 1.1 mrg tree var2 = TREE_VEC_ELT (it2, 0); 6676 1.1 mrg tree begin2 = TREE_VEC_ELT (it2, 1); 6677 1.1 mrg tree end2 = TREE_VEC_ELT (it2, 2); 6678 1.1 mrg tree step2 = TREE_VEC_ELT (it2, 3); 6679 1.1 mrg location_t loc2 = DECL_SOURCE_LOCATION (var2); 6680 1.1 mrg if (cp_walk_tree (&begin2, find_omp_placeholder_r, var, &pset)) 6681 1.1 mrg { 6682 1.1 mrg error_at (EXPR_LOC_OR_LOC (begin2, loc2), 6683 1.1 mrg "begin expression refers to outer iterator %qD", var); 6684 1.1 mrg break; 6685 1.1 mrg } 6686 1.1 mrg else if (cp_walk_tree (&end2, find_omp_placeholder_r, var, &pset)) 6687 1.1 mrg { 6688 1.1 mrg error_at (EXPR_LOC_OR_LOC (end2, loc2), 6689 1.1 mrg "end expression refers to outer iterator %qD", var); 6690 1.1 mrg break; 6691 1.1 mrg } 6692 1.1 mrg else if (cp_walk_tree (&step2, find_omp_placeholder_r, var, &pset)) 6693 1.1 mrg { 6694 1.1 mrg error_at (EXPR_LOC_OR_LOC (step2, loc2), 6695 1.1 mrg "step expression refers to outer iterator %qD", var); 6696 1.1 mrg break; 6697 1.1 mrg } 6698 1.1 mrg } 6699 1.1 mrg if (it2) 6700 1.1 mrg { 6701 1.1 mrg ret = true; 6702 1.1 mrg continue; 6703 1.1 mrg } 6704 1.1 mrg TREE_VEC_ELT (it, 1) = begin; 6705 1.1 mrg TREE_VEC_ELT (it, 2) = end; 6706 1.1 mrg if (processing_template_decl) 6707 1.1 mrg TREE_VEC_ELT (it, 3) = orig_step; 6708 1.1 mrg else 6709 1.1 mrg { 6710 1.1 mrg TREE_VEC_ELT (it, 3) = step; 6711 1.1 mrg TREE_VEC_ELT (it, 4) = orig_step; 6712 1.1 mrg } 6713 1.1 mrg } 6714 1.1 mrg return ret; 6715 1.1 mrg } 6716 1.1 mrg 6717 1.1 mrg /* Ensure that pointers are used in OpenACC attach and detach clauses. 6718 1.1 mrg Return true if an error has been detected. */ 6719 1.1 mrg 6720 1.1 mrg static bool 6721 1.1 mrg cp_oacc_check_attachments (tree c) 6722 1.1 mrg { 6723 1.1 mrg if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP) 6724 1.1 mrg return false; 6725 1.1 mrg 6726 1.1 mrg /* OpenACC attach / detach clauses must be pointers. */ 6727 1.1 mrg if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH 6728 1.1 mrg || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH) 6729 1.1 mrg { 6730 1.1 mrg tree t = OMP_CLAUSE_DECL (c); 6731 1.1 mrg tree type; 6732 1.1 mrg 6733 1.1 mrg while (TREE_CODE (t) == TREE_LIST) 6734 1.1 mrg t = TREE_CHAIN (t); 6735 1.1 mrg 6736 1.1 mrg type = TREE_TYPE (t); 6737 1.1 mrg 6738 1.1 mrg if (TREE_CODE (type) == REFERENCE_TYPE) 6739 1.1 mrg type = TREE_TYPE (type); 6740 1.1 mrg 6741 1.1 mrg if (TREE_CODE (type) != POINTER_TYPE) 6742 1.1 mrg { 6743 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), "expected pointer in %qs clause", 6744 1.1 mrg user_omp_clause_code_name (c, true)); 6745 1.1 mrg return true; 6746 1.1 mrg } 6747 1.1 mrg } 6748 1.1 mrg 6749 1.1 mrg return false; 6750 1.1 mrg } 6751 1.1 mrg 6752 1.1 mrg /* For all elements of CLAUSES, validate them vs OpenMP constraints. 6753 1.1 mrg Remove any elements from the list that are invalid. */ 6754 1.1 mrg 6755 1.1 mrg tree 6756 1.1 mrg finish_omp_clauses (tree clauses, enum c_omp_region_type ort) 6757 1.1 mrg { 6758 1.1 mrg bitmap_head generic_head, firstprivate_head, lastprivate_head; 6759 1.1 mrg bitmap_head aligned_head, map_head, map_field_head, map_firstprivate_head; 6760 1.1 mrg bitmap_head oacc_reduction_head, is_on_device_head; 6761 1.1 mrg tree c, t, *pc; 6762 1.1 mrg tree safelen = NULL_TREE; 6763 1.1 mrg bool branch_seen = false; 6764 1.1 mrg bool copyprivate_seen = false; 6765 1.1 mrg bool ordered_seen = false; 6766 1.1 mrg bool order_seen = false; 6767 1.1 mrg bool schedule_seen = false; 6768 1.1 mrg bool oacc_async = false; 6769 1.1 mrg bool indir_component_ref_p = false; 6770 1.1 mrg tree last_iterators = NULL_TREE; 6771 1.1 mrg bool last_iterators_remove = false; 6772 1.1 mrg /* 1 if normal/task reduction has been seen, -1 if inscan reduction 6773 1.1 mrg has been seen, -2 if mixed inscan/normal reduction diagnosed. */ 6774 1.1 mrg int reduction_seen = 0; 6775 1.1 mrg bool allocate_seen = false; 6776 1.1 mrg tree detach_seen = NULL_TREE; 6777 1.1 mrg bool mergeable_seen = false; 6778 1.1 mrg bool implicit_moved = false; 6779 1.1 mrg bool target_in_reduction_seen = false; 6780 1.1 mrg 6781 1.1 mrg bitmap_obstack_initialize (NULL); 6782 1.1 mrg bitmap_initialize (&generic_head, &bitmap_default_obstack); 6783 1.1 mrg bitmap_initialize (&firstprivate_head, &bitmap_default_obstack); 6784 1.1 mrg bitmap_initialize (&lastprivate_head, &bitmap_default_obstack); 6785 1.1 mrg bitmap_initialize (&aligned_head, &bitmap_default_obstack); 6786 1.1 mrg /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead. */ 6787 1.1 mrg bitmap_initialize (&map_head, &bitmap_default_obstack); 6788 1.1 mrg bitmap_initialize (&map_field_head, &bitmap_default_obstack); 6789 1.1 mrg bitmap_initialize (&map_firstprivate_head, &bitmap_default_obstack); 6790 1.1 mrg /* If ort == C_ORT_OMP used as nontemporal_head or use_device_xxx_head 6791 1.1 mrg instead and for ort == C_ORT_OMP_TARGET used as in_reduction_head. */ 6792 1.1 mrg bitmap_initialize (&oacc_reduction_head, &bitmap_default_obstack); 6793 1.1 mrg bitmap_initialize (&is_on_device_head, &bitmap_default_obstack); 6794 1.1 mrg 6795 1.1 mrg if (ort & C_ORT_ACC) 6796 1.1 mrg for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c)) 6797 1.1 mrg if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ASYNC) 6798 1.1 mrg { 6799 1.1 mrg oacc_async = true; 6800 1.1 mrg break; 6801 1.1 mrg } 6802 1.1 mrg 6803 1.1 mrg for (pc = &clauses, c = clauses; c ; c = *pc) 6804 1.1 mrg { 6805 1.1 mrg bool remove = false; 6806 1.1 mrg bool field_ok = false; 6807 1.1 mrg 6808 1.1 mrg switch (OMP_CLAUSE_CODE (c)) 6809 1.1 mrg { 6810 1.1 mrg case OMP_CLAUSE_SHARED: 6811 1.1 mrg field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP); 6812 1.1 mrg goto check_dup_generic; 6813 1.1 mrg case OMP_CLAUSE_PRIVATE: 6814 1.1 mrg field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP); 6815 1.1 mrg goto check_dup_generic; 6816 1.1 mrg case OMP_CLAUSE_REDUCTION: 6817 1.1 mrg if (reduction_seen == 0) 6818 1.1 mrg reduction_seen = OMP_CLAUSE_REDUCTION_INSCAN (c) ? -1 : 1; 6819 1.1 mrg else if (reduction_seen != -2 6820 1.1 mrg && reduction_seen != (OMP_CLAUSE_REDUCTION_INSCAN (c) 6821 1.1 mrg ? -1 : 1)) 6822 1.1 mrg { 6823 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 6824 1.1 mrg "%<inscan%> and non-%<inscan%> %<reduction%> clauses " 6825 1.1 mrg "on the same construct"); 6826 1.1 mrg reduction_seen = -2; 6827 1.1 mrg } 6828 1.1 mrg /* FALLTHRU */ 6829 1.1 mrg case OMP_CLAUSE_IN_REDUCTION: 6830 1.1 mrg case OMP_CLAUSE_TASK_REDUCTION: 6831 1.1 mrg field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP); 6832 1.1 mrg t = OMP_CLAUSE_DECL (c); 6833 1.1 mrg if (TREE_CODE (t) == TREE_LIST) 6834 1.1 mrg { 6835 1.1 mrg if (handle_omp_array_sections (c, ort)) 6836 1.1 mrg { 6837 1.1 mrg remove = true; 6838 1.1 mrg break; 6839 1.1 mrg } 6840 1.1 mrg if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION 6841 1.1 mrg && OMP_CLAUSE_REDUCTION_INSCAN (c)) 6842 1.1 mrg { 6843 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 6844 1.1 mrg "%<inscan%> %<reduction%> clause with array " 6845 1.1 mrg "section"); 6846 1.1 mrg remove = true; 6847 1.1 mrg break; 6848 1.1 mrg } 6849 1.1 mrg if (TREE_CODE (t) == TREE_LIST) 6850 1.1 mrg { 6851 1.1 mrg while (TREE_CODE (t) == TREE_LIST) 6852 1.1 mrg t = TREE_CHAIN (t); 6853 1.1 mrg } 6854 1.1 mrg else 6855 1.1 mrg { 6856 1.1 mrg gcc_assert (TREE_CODE (t) == MEM_REF); 6857 1.1 mrg t = TREE_OPERAND (t, 0); 6858 1.1 mrg if (TREE_CODE (t) == POINTER_PLUS_EXPR) 6859 1.1 mrg t = TREE_OPERAND (t, 0); 6860 1.1 mrg if (TREE_CODE (t) == ADDR_EXPR 6861 1.1 mrg || INDIRECT_REF_P (t)) 6862 1.1 mrg t = TREE_OPERAND (t, 0); 6863 1.1 mrg } 6864 1.1 mrg tree n = omp_clause_decl_field (t); 6865 1.1 mrg if (n) 6866 1.1 mrg t = n; 6867 1.1 mrg goto check_dup_generic_t; 6868 1.1 mrg } 6869 1.1 mrg if (oacc_async) 6870 1.1 mrg cxx_mark_addressable (t); 6871 1.1 mrg goto check_dup_generic; 6872 1.1 mrg case OMP_CLAUSE_COPYPRIVATE: 6873 1.1 mrg copyprivate_seen = true; 6874 1.1 mrg field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP); 6875 1.1 mrg goto check_dup_generic; 6876 1.1 mrg case OMP_CLAUSE_COPYIN: 6877 1.1 mrg goto check_dup_generic; 6878 1.1 mrg case OMP_CLAUSE_LINEAR: 6879 1.1 mrg field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP); 6880 1.1 mrg t = OMP_CLAUSE_DECL (c); 6881 1.1 mrg if (ort != C_ORT_OMP_DECLARE_SIMD 6882 1.1 mrg && OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_DEFAULT) 6883 1.1 mrg { 6884 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 6885 1.1 mrg "modifier should not be specified in %<linear%> " 6886 1.1 mrg "clause on %<simd%> or %<for%> constructs"); 6887 1.1 mrg OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT; 6888 1.1 mrg } 6889 1.1 mrg if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL) 6890 1.1 mrg && !type_dependent_expression_p (t)) 6891 1.1 mrg { 6892 1.1 mrg tree type = TREE_TYPE (t); 6893 1.1 mrg if ((OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF 6894 1.1 mrg || OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_UVAL) 6895 1.1 mrg && !TYPE_REF_P (type)) 6896 1.1 mrg { 6897 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 6898 1.1 mrg "linear clause with %qs modifier applied to " 6899 1.1 mrg "non-reference variable with %qT type", 6900 1.1 mrg OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF 6901 1.1 mrg ? "ref" : "uval", TREE_TYPE (t)); 6902 1.1 mrg remove = true; 6903 1.1 mrg break; 6904 1.1 mrg } 6905 1.1 mrg if (TYPE_REF_P (type)) 6906 1.1 mrg type = TREE_TYPE (type); 6907 1.1 mrg if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_REF) 6908 1.1 mrg { 6909 1.1 mrg if (!INTEGRAL_TYPE_P (type) 6910 1.1 mrg && !TYPE_PTR_P (type)) 6911 1.1 mrg { 6912 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 6913 1.1 mrg "linear clause applied to non-integral " 6914 1.1 mrg "non-pointer variable with %qT type", 6915 1.1 mrg TREE_TYPE (t)); 6916 1.1 mrg remove = true; 6917 1.1 mrg break; 6918 1.1 mrg } 6919 1.1 mrg } 6920 1.1 mrg } 6921 1.1 mrg t = OMP_CLAUSE_LINEAR_STEP (c); 6922 1.1 mrg if (t == NULL_TREE) 6923 1.1 mrg t = integer_one_node; 6924 1.1 mrg if (t == error_mark_node) 6925 1.1 mrg { 6926 1.1 mrg remove = true; 6927 1.1 mrg break; 6928 1.1 mrg } 6929 1.1 mrg else if (!type_dependent_expression_p (t) 6930 1.1 mrg && !INTEGRAL_TYPE_P (TREE_TYPE (t)) 6931 1.1 mrg && (ort != C_ORT_OMP_DECLARE_SIMD 6932 1.1 mrg || TREE_CODE (t) != PARM_DECL 6933 1.1 mrg || !TYPE_REF_P (TREE_TYPE (t)) 6934 1.1 mrg || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t))))) 6935 1.1 mrg { 6936 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 6937 1.1 mrg "linear step expression must be integral"); 6938 1.1 mrg remove = true; 6939 1.1 mrg break; 6940 1.1 mrg } 6941 1.1 mrg else 6942 1.1 mrg { 6943 1.1 mrg t = mark_rvalue_use (t); 6944 1.1 mrg if (ort == C_ORT_OMP_DECLARE_SIMD && TREE_CODE (t) == PARM_DECL) 6945 1.1 mrg { 6946 1.1 mrg OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c) = 1; 6947 1.1 mrg goto check_dup_generic; 6948 1.1 mrg } 6949 1.1 mrg if (!processing_template_decl 6950 1.1 mrg && (VAR_P (OMP_CLAUSE_DECL (c)) 6951 1.1 mrg || TREE_CODE (OMP_CLAUSE_DECL (c)) == PARM_DECL)) 6952 1.1 mrg { 6953 1.1 mrg if (ort == C_ORT_OMP_DECLARE_SIMD) 6954 1.1 mrg { 6955 1.1 mrg t = maybe_constant_value (t); 6956 1.1 mrg if (TREE_CODE (t) != INTEGER_CST) 6957 1.1 mrg { 6958 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 6959 1.1 mrg "%<linear%> clause step %qE is neither " 6960 1.1 mrg "constant nor a parameter", t); 6961 1.1 mrg remove = true; 6962 1.1 mrg break; 6963 1.1 mrg } 6964 1.1 mrg } 6965 1.1 mrg t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 6966 1.1 mrg tree type = TREE_TYPE (OMP_CLAUSE_DECL (c)); 6967 1.1 mrg if (TYPE_REF_P (type)) 6968 1.1 mrg type = TREE_TYPE (type); 6969 1.1 mrg if (OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF) 6970 1.1 mrg { 6971 1.1 mrg type = build_pointer_type (type); 6972 1.1 mrg tree d = fold_convert (type, OMP_CLAUSE_DECL (c)); 6973 1.1 mrg t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR, 6974 1.1 mrg d, t); 6975 1.1 mrg t = fold_build2_loc (OMP_CLAUSE_LOCATION (c), 6976 1.1 mrg MINUS_EXPR, sizetype, 6977 1.1 mrg fold_convert (sizetype, t), 6978 1.1 mrg fold_convert (sizetype, d)); 6979 1.1 mrg if (t == error_mark_node) 6980 1.1 mrg { 6981 1.1 mrg remove = true; 6982 1.1 mrg break; 6983 1.1 mrg } 6984 1.1 mrg } 6985 1.1 mrg else if (TYPE_PTR_P (type) 6986 1.1 mrg /* Can't multiply the step yet if *this 6987 1.1 mrg is still incomplete type. */ 6988 1.1 mrg && (ort != C_ORT_OMP_DECLARE_SIMD 6989 1.1 mrg || TREE_CODE (OMP_CLAUSE_DECL (c)) != PARM_DECL 6990 1.1 mrg || !DECL_ARTIFICIAL (OMP_CLAUSE_DECL (c)) 6991 1.1 mrg || DECL_NAME (OMP_CLAUSE_DECL (c)) 6992 1.1 mrg != this_identifier 6993 1.1 mrg || !TYPE_BEING_DEFINED (TREE_TYPE (type)))) 6994 1.1 mrg { 6995 1.1 mrg tree d = convert_from_reference (OMP_CLAUSE_DECL (c)); 6996 1.1 mrg t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR, 6997 1.1 mrg d, t); 6998 1.1 mrg t = fold_build2_loc (OMP_CLAUSE_LOCATION (c), 6999 1.1 mrg MINUS_EXPR, sizetype, 7000 1.1 mrg fold_convert (sizetype, t), 7001 1.1 mrg fold_convert (sizetype, d)); 7002 1.1 mrg if (t == error_mark_node) 7003 1.1 mrg { 7004 1.1 mrg remove = true; 7005 1.1 mrg break; 7006 1.1 mrg } 7007 1.1 mrg } 7008 1.1 mrg else 7009 1.1 mrg t = fold_convert (type, t); 7010 1.1 mrg } 7011 1.1 mrg OMP_CLAUSE_LINEAR_STEP (c) = t; 7012 1.1 mrg } 7013 1.1 mrg goto check_dup_generic; 7014 1.1 mrg check_dup_generic: 7015 1.1 mrg t = omp_clause_decl_field (OMP_CLAUSE_DECL (c)); 7016 1.1 mrg if (t) 7017 1.1 mrg { 7018 1.1 mrg if (!remove && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED) 7019 1.1 mrg omp_note_field_privatization (t, OMP_CLAUSE_DECL (c)); 7020 1.1 mrg } 7021 1.1 mrg else 7022 1.1 mrg t = OMP_CLAUSE_DECL (c); 7023 1.1 mrg check_dup_generic_t: 7024 1.1 mrg if (t == current_class_ptr 7025 1.1 mrg && ((ort != C_ORT_OMP_DECLARE_SIMD && ort != C_ORT_ACC) 7026 1.1 mrg || (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_LINEAR 7027 1.1 mrg && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_UNIFORM))) 7028 1.1 mrg { 7029 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7030 1.1 mrg "%<this%> allowed in OpenMP only in %<declare simd%>" 7031 1.1 mrg " clauses"); 7032 1.1 mrg remove = true; 7033 1.1 mrg break; 7034 1.1 mrg } 7035 1.1 mrg if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL 7036 1.1 mrg && (!field_ok || TREE_CODE (t) != FIELD_DECL)) 7037 1.1 mrg { 7038 1.1 mrg if (processing_template_decl && TREE_CODE (t) != OVERLOAD) 7039 1.1 mrg break; 7040 1.1 mrg if (DECL_P (t)) 7041 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7042 1.1 mrg "%qD is not a variable in clause %qs", t, 7043 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 7044 1.1 mrg else 7045 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7046 1.1 mrg "%qE is not a variable in clause %qs", t, 7047 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 7048 1.1 mrg remove = true; 7049 1.1 mrg } 7050 1.1 mrg else if ((ort == C_ORT_ACC 7051 1.1 mrg && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION) 7052 1.1 mrg || (ort == C_ORT_OMP 7053 1.1 mrg && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR 7054 1.1 mrg || (OMP_CLAUSE_CODE (c) 7055 1.1 mrg == OMP_CLAUSE_USE_DEVICE_ADDR))) 7056 1.1 mrg || (ort == C_ORT_OMP_TARGET 7057 1.1 mrg && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION)) 7058 1.1 mrg { 7059 1.1 mrg if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION 7060 1.1 mrg && (bitmap_bit_p (&generic_head, DECL_UID (t)) 7061 1.1 mrg || bitmap_bit_p (&firstprivate_head, DECL_UID (t)))) 7062 1.1 mrg { 7063 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7064 1.1 mrg "%qD appears more than once in data-sharing " 7065 1.1 mrg "clauses", t); 7066 1.1 mrg remove = true; 7067 1.1 mrg break; 7068 1.1 mrg } 7069 1.1 mrg if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION) 7070 1.1 mrg target_in_reduction_seen = true; 7071 1.1 mrg if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t))) 7072 1.1 mrg { 7073 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7074 1.1 mrg ort == C_ORT_ACC 7075 1.1 mrg ? "%qD appears more than once in reduction clauses" 7076 1.1 mrg : "%qD appears more than once in data clauses", 7077 1.1 mrg t); 7078 1.1 mrg remove = true; 7079 1.1 mrg } 7080 1.1 mrg else 7081 1.1 mrg bitmap_set_bit (&oacc_reduction_head, DECL_UID (t)); 7082 1.1 mrg } 7083 1.1 mrg else if (bitmap_bit_p (&generic_head, DECL_UID (t)) 7084 1.1 mrg || bitmap_bit_p (&firstprivate_head, DECL_UID (t)) 7085 1.1 mrg || bitmap_bit_p (&lastprivate_head, DECL_UID (t)) 7086 1.1 mrg || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t))) 7087 1.1 mrg { 7088 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7089 1.1 mrg "%qD appears more than once in data clauses", t); 7090 1.1 mrg remove = true; 7091 1.1 mrg } 7092 1.1 mrg else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE 7093 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR 7094 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR) 7095 1.1 mrg && bitmap_bit_p (&map_head, DECL_UID (t))) 7096 1.1 mrg { 7097 1.1 mrg if (ort == C_ORT_ACC) 7098 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7099 1.1 mrg "%qD appears more than once in data clauses", t); 7100 1.1 mrg else 7101 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7102 1.1 mrg "%qD appears both in data and map clauses", t); 7103 1.1 mrg remove = true; 7104 1.1 mrg } 7105 1.1 mrg else 7106 1.1 mrg bitmap_set_bit (&generic_head, DECL_UID (t)); 7107 1.1 mrg if (!field_ok) 7108 1.1 mrg break; 7109 1.1 mrg handle_field_decl: 7110 1.1 mrg if (!remove 7111 1.1 mrg && TREE_CODE (t) == FIELD_DECL 7112 1.1 mrg && t == OMP_CLAUSE_DECL (c)) 7113 1.1 mrg { 7114 1.1 mrg OMP_CLAUSE_DECL (c) 7115 1.1 mrg = omp_privatize_field (t, (OMP_CLAUSE_CODE (c) 7116 1.1 mrg == OMP_CLAUSE_SHARED)); 7117 1.1 mrg if (OMP_CLAUSE_DECL (c) == error_mark_node) 7118 1.1 mrg remove = true; 7119 1.1 mrg } 7120 1.1 mrg break; 7121 1.1 mrg 7122 1.1 mrg case OMP_CLAUSE_FIRSTPRIVATE: 7123 1.1 mrg if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c) && !implicit_moved) 7124 1.1 mrg { 7125 1.1 mrg move_implicit: 7126 1.1 mrg implicit_moved = true; 7127 1.1 mrg /* Move firstprivate and map clauses with 7128 1.1 mrg OMP_CLAUSE_{FIRSTPRIVATE,MAP}_IMPLICIT set to the end of 7129 1.1 mrg clauses chain. */ 7130 1.1 mrg tree cl1 = NULL_TREE, cl2 = NULL_TREE; 7131 1.1 mrg tree *pc1 = pc, *pc2 = &cl1, *pc3 = &cl2; 7132 1.1 mrg while (*pc1) 7133 1.1 mrg if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_FIRSTPRIVATE 7134 1.1 mrg && OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (*pc1)) 7135 1.1 mrg { 7136 1.1 mrg *pc3 = *pc1; 7137 1.1 mrg pc3 = &OMP_CLAUSE_CHAIN (*pc3); 7138 1.1 mrg *pc1 = OMP_CLAUSE_CHAIN (*pc1); 7139 1.1 mrg } 7140 1.1 mrg else if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_MAP 7141 1.1 mrg && OMP_CLAUSE_MAP_IMPLICIT (*pc1)) 7142 1.1 mrg { 7143 1.1 mrg *pc2 = *pc1; 7144 1.1 mrg pc2 = &OMP_CLAUSE_CHAIN (*pc2); 7145 1.1 mrg *pc1 = OMP_CLAUSE_CHAIN (*pc1); 7146 1.1 mrg } 7147 1.1 mrg else 7148 1.1 mrg pc1 = &OMP_CLAUSE_CHAIN (*pc1); 7149 1.1 mrg *pc3 = NULL; 7150 1.1 mrg *pc2 = cl2; 7151 1.1 mrg *pc1 = cl1; 7152 1.1 mrg continue; 7153 1.1 mrg } 7154 1.1 mrg t = omp_clause_decl_field (OMP_CLAUSE_DECL (c)); 7155 1.1 mrg if (t) 7156 1.1 mrg omp_note_field_privatization (t, OMP_CLAUSE_DECL (c)); 7157 1.1 mrg else 7158 1.1 mrg t = OMP_CLAUSE_DECL (c); 7159 1.1 mrg if (ort != C_ORT_ACC && t == current_class_ptr) 7160 1.1 mrg { 7161 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7162 1.1 mrg "%<this%> allowed in OpenMP only in %<declare simd%>" 7163 1.1 mrg " clauses"); 7164 1.1 mrg remove = true; 7165 1.1 mrg break; 7166 1.1 mrg } 7167 1.1 mrg if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL 7168 1.1 mrg && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP 7169 1.1 mrg || TREE_CODE (t) != FIELD_DECL)) 7170 1.1 mrg { 7171 1.1 mrg if (processing_template_decl && TREE_CODE (t) != OVERLOAD) 7172 1.1 mrg break; 7173 1.1 mrg if (DECL_P (t)) 7174 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7175 1.1 mrg "%qD is not a variable in clause %<firstprivate%>", 7176 1.1 mrg t); 7177 1.1 mrg else 7178 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7179 1.1 mrg "%qE is not a variable in clause %<firstprivate%>", 7180 1.1 mrg t); 7181 1.1 mrg remove = true; 7182 1.1 mrg } 7183 1.1 mrg else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c) 7184 1.1 mrg && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c) 7185 1.1 mrg && bitmap_bit_p (&map_firstprivate_head, DECL_UID (t))) 7186 1.1 mrg remove = true; 7187 1.1 mrg else if (bitmap_bit_p (&generic_head, DECL_UID (t)) 7188 1.1 mrg || bitmap_bit_p (&firstprivate_head, DECL_UID (t)) 7189 1.1 mrg || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t))) 7190 1.1 mrg { 7191 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7192 1.1 mrg "%qD appears more than once in data clauses", t); 7193 1.1 mrg remove = true; 7194 1.1 mrg } 7195 1.1 mrg else if (bitmap_bit_p (&map_head, DECL_UID (t))) 7196 1.1 mrg { 7197 1.1 mrg if (ort == C_ORT_ACC) 7198 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7199 1.1 mrg "%qD appears more than once in data clauses", t); 7200 1.1 mrg else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c) 7201 1.1 mrg && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c)) 7202 1.1 mrg /* Silently drop the clause. */; 7203 1.1 mrg else 7204 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7205 1.1 mrg "%qD appears both in data and map clauses", t); 7206 1.1 mrg remove = true; 7207 1.1 mrg } 7208 1.1 mrg else 7209 1.1 mrg bitmap_set_bit (&firstprivate_head, DECL_UID (t)); 7210 1.1 mrg goto handle_field_decl; 7211 1.1 mrg 7212 1.1 mrg case OMP_CLAUSE_LASTPRIVATE: 7213 1.1 mrg t = omp_clause_decl_field (OMP_CLAUSE_DECL (c)); 7214 1.1 mrg if (t) 7215 1.1 mrg omp_note_field_privatization (t, OMP_CLAUSE_DECL (c)); 7216 1.1 mrg else 7217 1.1 mrg t = OMP_CLAUSE_DECL (c); 7218 1.1 mrg if (ort != C_ORT_ACC && t == current_class_ptr) 7219 1.1 mrg { 7220 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7221 1.1 mrg "%<this%> allowed in OpenMP only in %<declare simd%>" 7222 1.1 mrg " clauses"); 7223 1.1 mrg remove = true; 7224 1.1 mrg break; 7225 1.1 mrg } 7226 1.1 mrg if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL 7227 1.1 mrg && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP 7228 1.1 mrg || TREE_CODE (t) != FIELD_DECL)) 7229 1.1 mrg { 7230 1.1 mrg if (processing_template_decl && TREE_CODE (t) != OVERLOAD) 7231 1.1 mrg break; 7232 1.1 mrg if (DECL_P (t)) 7233 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7234 1.1 mrg "%qD is not a variable in clause %<lastprivate%>", 7235 1.1 mrg t); 7236 1.1 mrg else 7237 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7238 1.1 mrg "%qE is not a variable in clause %<lastprivate%>", 7239 1.1 mrg t); 7240 1.1 mrg remove = true; 7241 1.1 mrg } 7242 1.1 mrg else if (bitmap_bit_p (&generic_head, DECL_UID (t)) 7243 1.1 mrg || bitmap_bit_p (&lastprivate_head, DECL_UID (t))) 7244 1.1 mrg { 7245 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7246 1.1 mrg "%qD appears more than once in data clauses", t); 7247 1.1 mrg remove = true; 7248 1.1 mrg } 7249 1.1 mrg else 7250 1.1 mrg bitmap_set_bit (&lastprivate_head, DECL_UID (t)); 7251 1.1 mrg goto handle_field_decl; 7252 1.1 mrg 7253 1.1 mrg case OMP_CLAUSE_IF: 7254 1.1 mrg t = OMP_CLAUSE_IF_EXPR (c); 7255 1.1 mrg t = maybe_convert_cond (t); 7256 1.1 mrg if (t == error_mark_node) 7257 1.1 mrg remove = true; 7258 1.1 mrg else if (!processing_template_decl) 7259 1.1 mrg t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 7260 1.1 mrg OMP_CLAUSE_IF_EXPR (c) = t; 7261 1.1 mrg break; 7262 1.1 mrg 7263 1.1 mrg case OMP_CLAUSE_FINAL: 7264 1.1 mrg t = OMP_CLAUSE_FINAL_EXPR (c); 7265 1.1 mrg t = maybe_convert_cond (t); 7266 1.1 mrg if (t == error_mark_node) 7267 1.1 mrg remove = true; 7268 1.1 mrg else if (!processing_template_decl) 7269 1.1 mrg t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 7270 1.1 mrg OMP_CLAUSE_FINAL_EXPR (c) = t; 7271 1.1 mrg break; 7272 1.1 mrg 7273 1.1 mrg case OMP_CLAUSE_GANG: 7274 1.1 mrg /* Operand 1 is the gang static: argument. */ 7275 1.1 mrg t = OMP_CLAUSE_OPERAND (c, 1); 7276 1.1 mrg if (t != NULL_TREE) 7277 1.1 mrg { 7278 1.1 mrg if (t == error_mark_node) 7279 1.1 mrg remove = true; 7280 1.1 mrg else if (!type_dependent_expression_p (t) 7281 1.1 mrg && !INTEGRAL_TYPE_P (TREE_TYPE (t))) 7282 1.1 mrg { 7283 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7284 1.1 mrg "%<gang%> static expression must be integral"); 7285 1.1 mrg remove = true; 7286 1.1 mrg } 7287 1.1 mrg else 7288 1.1 mrg { 7289 1.1 mrg t = mark_rvalue_use (t); 7290 1.1 mrg if (!processing_template_decl) 7291 1.1 mrg { 7292 1.1 mrg t = maybe_constant_value (t); 7293 1.1 mrg if (TREE_CODE (t) == INTEGER_CST 7294 1.1 mrg && tree_int_cst_sgn (t) != 1 7295 1.1 mrg && t != integer_minus_one_node) 7296 1.1 mrg { 7297 1.1 mrg warning_at (OMP_CLAUSE_LOCATION (c), 0, 7298 1.1 mrg "%<gang%> static value must be " 7299 1.1 mrg "positive"); 7300 1.1 mrg t = integer_one_node; 7301 1.1 mrg } 7302 1.1 mrg t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 7303 1.1 mrg } 7304 1.1 mrg } 7305 1.1 mrg OMP_CLAUSE_OPERAND (c, 1) = t; 7306 1.1 mrg } 7307 1.1 mrg /* Check operand 0, the num argument. */ 7308 1.1 mrg /* FALLTHRU */ 7309 1.1 mrg 7310 1.1 mrg case OMP_CLAUSE_WORKER: 7311 1.1 mrg case OMP_CLAUSE_VECTOR: 7312 1.1 mrg if (OMP_CLAUSE_OPERAND (c, 0) == NULL_TREE) 7313 1.1 mrg break; 7314 1.1 mrg /* FALLTHRU */ 7315 1.1 mrg 7316 1.1 mrg case OMP_CLAUSE_NUM_TASKS: 7317 1.1 mrg case OMP_CLAUSE_NUM_TEAMS: 7318 1.1 mrg case OMP_CLAUSE_NUM_THREADS: 7319 1.1 mrg case OMP_CLAUSE_NUM_GANGS: 7320 1.1 mrg case OMP_CLAUSE_NUM_WORKERS: 7321 1.1 mrg case OMP_CLAUSE_VECTOR_LENGTH: 7322 1.1 mrg t = OMP_CLAUSE_OPERAND (c, 0); 7323 1.1 mrg if (t == error_mark_node) 7324 1.1 mrg remove = true; 7325 1.1 mrg else if (!type_dependent_expression_p (t) 7326 1.1 mrg && !INTEGRAL_TYPE_P (TREE_TYPE (t))) 7327 1.1 mrg { 7328 1.1 mrg switch (OMP_CLAUSE_CODE (c)) 7329 1.1 mrg { 7330 1.1 mrg case OMP_CLAUSE_GANG: 7331 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7332 1.1 mrg "%<gang%> num expression must be integral"); break; 7333 1.1 mrg case OMP_CLAUSE_VECTOR: 7334 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7335 1.1 mrg "%<vector%> length expression must be integral"); 7336 1.1 mrg break; 7337 1.1 mrg case OMP_CLAUSE_WORKER: 7338 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7339 1.1 mrg "%<worker%> num expression must be integral"); 7340 1.1 mrg break; 7341 1.1 mrg default: 7342 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7343 1.1 mrg "%qs expression must be integral", 7344 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 7345 1.1 mrg } 7346 1.1 mrg remove = true; 7347 1.1 mrg } 7348 1.1 mrg else 7349 1.1 mrg { 7350 1.1 mrg t = mark_rvalue_use (t); 7351 1.1 mrg if (!processing_template_decl) 7352 1.1 mrg { 7353 1.1 mrg t = maybe_constant_value (t); 7354 1.1 mrg if (TREE_CODE (t) == INTEGER_CST 7355 1.1 mrg && tree_int_cst_sgn (t) != 1) 7356 1.1 mrg { 7357 1.1 mrg switch (OMP_CLAUSE_CODE (c)) 7358 1.1 mrg { 7359 1.1 mrg case OMP_CLAUSE_GANG: 7360 1.1 mrg warning_at (OMP_CLAUSE_LOCATION (c), 0, 7361 1.1 mrg "%<gang%> num value must be positive"); 7362 1.1 mrg break; 7363 1.1 mrg case OMP_CLAUSE_VECTOR: 7364 1.1 mrg warning_at (OMP_CLAUSE_LOCATION (c), 0, 7365 1.1 mrg "%<vector%> length value must be " 7366 1.1 mrg "positive"); 7367 1.1 mrg break; 7368 1.1 mrg case OMP_CLAUSE_WORKER: 7369 1.1 mrg warning_at (OMP_CLAUSE_LOCATION (c), 0, 7370 1.1 mrg "%<worker%> num value must be " 7371 1.1 mrg "positive"); 7372 1.1 mrg break; 7373 1.1 mrg default: 7374 1.1 mrg warning_at (OMP_CLAUSE_LOCATION (c), 0, 7375 1.1 mrg "%qs value must be positive", 7376 1.1 mrg omp_clause_code_name 7377 1.1 mrg [OMP_CLAUSE_CODE (c)]); 7378 1.1 mrg } 7379 1.1 mrg t = integer_one_node; 7380 1.1 mrg } 7381 1.1 mrg t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 7382 1.1 mrg } 7383 1.1 mrg OMP_CLAUSE_OPERAND (c, 0) = t; 7384 1.1 mrg } 7385 1.1 mrg if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TEAMS 7386 1.1 mrg && OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c) 7387 1.1 mrg && !remove) 7388 1.1 mrg { 7389 1.1 mrg t = OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c); 7390 1.1 mrg if (t == error_mark_node) 7391 1.1 mrg remove = true; 7392 1.1 mrg else if (!type_dependent_expression_p (t) 7393 1.1 mrg && !INTEGRAL_TYPE_P (TREE_TYPE (t))) 7394 1.1 mrg { 7395 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7396 1.1 mrg "%qs expression must be integral", 7397 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 7398 1.1 mrg remove = true; 7399 1.1 mrg } 7400 1.1 mrg else 7401 1.1 mrg { 7402 1.1 mrg t = mark_rvalue_use (t); 7403 1.1 mrg if (!processing_template_decl) 7404 1.1 mrg { 7405 1.1 mrg t = maybe_constant_value (t); 7406 1.1 mrg if (TREE_CODE (t) == INTEGER_CST 7407 1.1 mrg && tree_int_cst_sgn (t) != 1) 7408 1.1 mrg { 7409 1.1 mrg warning_at (OMP_CLAUSE_LOCATION (c), 0, 7410 1.1 mrg "%qs value must be positive", 7411 1.1 mrg omp_clause_code_name 7412 1.1 mrg [OMP_CLAUSE_CODE (c)]); 7413 1.1 mrg t = NULL_TREE; 7414 1.1 mrg } 7415 1.1 mrg else 7416 1.1 mrg t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 7417 1.1 mrg tree upper = OMP_CLAUSE_NUM_TEAMS_UPPER_EXPR (c); 7418 1.1 mrg if (t 7419 1.1 mrg && TREE_CODE (t) == INTEGER_CST 7420 1.1 mrg && TREE_CODE (upper) == INTEGER_CST 7421 1.1 mrg && tree_int_cst_lt (upper, t)) 7422 1.1 mrg { 7423 1.1 mrg warning_at (OMP_CLAUSE_LOCATION (c), 0, 7424 1.1 mrg "%<num_teams%> lower bound %qE bigger " 7425 1.1 mrg "than upper bound %qE", t, upper); 7426 1.1 mrg t = NULL_TREE; 7427 1.1 mrg } 7428 1.1 mrg } 7429 1.1 mrg OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c) = t; 7430 1.1 mrg } 7431 1.1 mrg } 7432 1.1 mrg break; 7433 1.1 mrg 7434 1.1 mrg case OMP_CLAUSE_SCHEDULE: 7435 1.1 mrg t = OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c); 7436 1.1 mrg if (t == NULL) 7437 1.1 mrg ; 7438 1.1 mrg else if (t == error_mark_node) 7439 1.1 mrg remove = true; 7440 1.1 mrg else if (!type_dependent_expression_p (t) 7441 1.1 mrg && !INTEGRAL_TYPE_P (TREE_TYPE (t))) 7442 1.1 mrg { 7443 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7444 1.1 mrg "schedule chunk size expression must be integral"); 7445 1.1 mrg remove = true; 7446 1.1 mrg } 7447 1.1 mrg else 7448 1.1 mrg { 7449 1.1 mrg t = mark_rvalue_use (t); 7450 1.1 mrg if (!processing_template_decl) 7451 1.1 mrg { 7452 1.1 mrg t = maybe_constant_value (t); 7453 1.1 mrg if (TREE_CODE (t) == INTEGER_CST 7454 1.1 mrg && tree_int_cst_sgn (t) != 1) 7455 1.1 mrg { 7456 1.1 mrg warning_at (OMP_CLAUSE_LOCATION (c), 0, 7457 1.1 mrg "chunk size value must be positive"); 7458 1.1 mrg t = integer_one_node; 7459 1.1 mrg } 7460 1.1 mrg t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 7461 1.1 mrg } 7462 1.1 mrg OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t; 7463 1.1 mrg } 7464 1.1 mrg if (!remove) 7465 1.1 mrg schedule_seen = true; 7466 1.1 mrg break; 7467 1.1 mrg 7468 1.1 mrg case OMP_CLAUSE_SIMDLEN: 7469 1.1 mrg case OMP_CLAUSE_SAFELEN: 7470 1.1 mrg t = OMP_CLAUSE_OPERAND (c, 0); 7471 1.1 mrg if (t == error_mark_node) 7472 1.1 mrg remove = true; 7473 1.1 mrg else if (!type_dependent_expression_p (t) 7474 1.1 mrg && !INTEGRAL_TYPE_P (TREE_TYPE (t))) 7475 1.1 mrg { 7476 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7477 1.1 mrg "%qs length expression must be integral", 7478 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 7479 1.1 mrg remove = true; 7480 1.1 mrg } 7481 1.1 mrg else 7482 1.1 mrg { 7483 1.1 mrg t = mark_rvalue_use (t); 7484 1.1 mrg if (!processing_template_decl) 7485 1.1 mrg { 7486 1.1 mrg t = maybe_constant_value (t); 7487 1.1 mrg if (TREE_CODE (t) != INTEGER_CST 7488 1.1 mrg || tree_int_cst_sgn (t) != 1) 7489 1.1 mrg { 7490 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7491 1.1 mrg "%qs length expression must be positive " 7492 1.1 mrg "constant integer expression", 7493 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 7494 1.1 mrg remove = true; 7495 1.1 mrg } 7496 1.1 mrg } 7497 1.1 mrg OMP_CLAUSE_OPERAND (c, 0) = t; 7498 1.1 mrg if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SAFELEN) 7499 1.1 mrg safelen = c; 7500 1.1 mrg } 7501 1.1 mrg break; 7502 1.1 mrg 7503 1.1 mrg case OMP_CLAUSE_ASYNC: 7504 1.1 mrg t = OMP_CLAUSE_ASYNC_EXPR (c); 7505 1.1 mrg if (t == error_mark_node) 7506 1.1 mrg remove = true; 7507 1.1 mrg else if (!type_dependent_expression_p (t) 7508 1.1 mrg && !INTEGRAL_TYPE_P (TREE_TYPE (t))) 7509 1.1 mrg { 7510 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7511 1.1 mrg "%<async%> expression must be integral"); 7512 1.1 mrg remove = true; 7513 1.1 mrg } 7514 1.1 mrg else 7515 1.1 mrg { 7516 1.1 mrg t = mark_rvalue_use (t); 7517 1.1 mrg if (!processing_template_decl) 7518 1.1 mrg t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 7519 1.1 mrg OMP_CLAUSE_ASYNC_EXPR (c) = t; 7520 1.1 mrg } 7521 1.1 mrg break; 7522 1.1 mrg 7523 1.1 mrg case OMP_CLAUSE_WAIT: 7524 1.1 mrg t = OMP_CLAUSE_WAIT_EXPR (c); 7525 1.1 mrg if (t == error_mark_node) 7526 1.1 mrg remove = true; 7527 1.1 mrg else if (!processing_template_decl) 7528 1.1 mrg t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 7529 1.1 mrg OMP_CLAUSE_WAIT_EXPR (c) = t; 7530 1.1 mrg break; 7531 1.1 mrg 7532 1.1 mrg case OMP_CLAUSE_THREAD_LIMIT: 7533 1.1 mrg t = OMP_CLAUSE_THREAD_LIMIT_EXPR (c); 7534 1.1 mrg if (t == error_mark_node) 7535 1.1 mrg remove = true; 7536 1.1 mrg else if (!type_dependent_expression_p (t) 7537 1.1 mrg && !INTEGRAL_TYPE_P (TREE_TYPE (t))) 7538 1.1 mrg { 7539 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7540 1.1 mrg "%<thread_limit%> expression must be integral"); 7541 1.1 mrg remove = true; 7542 1.1 mrg } 7543 1.1 mrg else 7544 1.1 mrg { 7545 1.1 mrg t = mark_rvalue_use (t); 7546 1.1 mrg if (!processing_template_decl) 7547 1.1 mrg { 7548 1.1 mrg t = maybe_constant_value (t); 7549 1.1 mrg if (TREE_CODE (t) == INTEGER_CST 7550 1.1 mrg && tree_int_cst_sgn (t) != 1) 7551 1.1 mrg { 7552 1.1 mrg warning_at (OMP_CLAUSE_LOCATION (c), 0, 7553 1.1 mrg "%<thread_limit%> value must be positive"); 7554 1.1 mrg t = integer_one_node; 7555 1.1 mrg } 7556 1.1 mrg t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 7557 1.1 mrg } 7558 1.1 mrg OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t; 7559 1.1 mrg } 7560 1.1 mrg break; 7561 1.1 mrg 7562 1.1 mrg case OMP_CLAUSE_DEVICE: 7563 1.1 mrg t = OMP_CLAUSE_DEVICE_ID (c); 7564 1.1 mrg if (t == error_mark_node) 7565 1.1 mrg remove = true; 7566 1.1 mrg else if (!type_dependent_expression_p (t) 7567 1.1 mrg && !INTEGRAL_TYPE_P (TREE_TYPE (t))) 7568 1.1 mrg { 7569 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7570 1.1 mrg "%<device%> id must be integral"); 7571 1.1 mrg remove = true; 7572 1.1 mrg } 7573 1.1 mrg else if (OMP_CLAUSE_DEVICE_ANCESTOR (c) 7574 1.1 mrg && TREE_CODE (t) == INTEGER_CST 7575 1.1 mrg && !integer_onep (t)) 7576 1.1 mrg { 7577 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7578 1.1 mrg "the %<device%> clause expression must evaluate to " 7579 1.1 mrg "%<1%>"); 7580 1.1 mrg remove = true; 7581 1.1 mrg } 7582 1.1 mrg else 7583 1.1 mrg { 7584 1.1 mrg t = mark_rvalue_use (t); 7585 1.1 mrg if (!processing_template_decl) 7586 1.1 mrg t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 7587 1.1 mrg OMP_CLAUSE_DEVICE_ID (c) = t; 7588 1.1 mrg } 7589 1.1 mrg break; 7590 1.1 mrg 7591 1.1 mrg case OMP_CLAUSE_DIST_SCHEDULE: 7592 1.1 mrg t = OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c); 7593 1.1 mrg if (t == NULL) 7594 1.1 mrg ; 7595 1.1 mrg else if (t == error_mark_node) 7596 1.1 mrg remove = true; 7597 1.1 mrg else if (!type_dependent_expression_p (t) 7598 1.1 mrg && !INTEGRAL_TYPE_P (TREE_TYPE (t))) 7599 1.1 mrg { 7600 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7601 1.1 mrg "%<dist_schedule%> chunk size expression must be " 7602 1.1 mrg "integral"); 7603 1.1 mrg remove = true; 7604 1.1 mrg } 7605 1.1 mrg else 7606 1.1 mrg { 7607 1.1 mrg t = mark_rvalue_use (t); 7608 1.1 mrg if (!processing_template_decl) 7609 1.1 mrg t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 7610 1.1 mrg OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t; 7611 1.1 mrg } 7612 1.1 mrg break; 7613 1.1 mrg 7614 1.1 mrg case OMP_CLAUSE_ALIGNED: 7615 1.1 mrg t = OMP_CLAUSE_DECL (c); 7616 1.1 mrg if (t == current_class_ptr && ort != C_ORT_OMP_DECLARE_SIMD) 7617 1.1 mrg { 7618 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7619 1.1 mrg "%<this%> allowed in OpenMP only in %<declare simd%>" 7620 1.1 mrg " clauses"); 7621 1.1 mrg remove = true; 7622 1.1 mrg break; 7623 1.1 mrg } 7624 1.1 mrg if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL) 7625 1.1 mrg { 7626 1.1 mrg if (processing_template_decl && TREE_CODE (t) != OVERLOAD) 7627 1.1 mrg break; 7628 1.1 mrg if (DECL_P (t)) 7629 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7630 1.1 mrg "%qD is not a variable in %<aligned%> clause", t); 7631 1.1 mrg else 7632 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7633 1.1 mrg "%qE is not a variable in %<aligned%> clause", t); 7634 1.1 mrg remove = true; 7635 1.1 mrg } 7636 1.1 mrg else if (!type_dependent_expression_p (t) 7637 1.1 mrg && !TYPE_PTR_P (TREE_TYPE (t)) 7638 1.1 mrg && TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE 7639 1.1 mrg && (!TYPE_REF_P (TREE_TYPE (t)) 7640 1.1 mrg || (!INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t))) 7641 1.1 mrg && (TREE_CODE (TREE_TYPE (TREE_TYPE (t))) 7642 1.1 mrg != ARRAY_TYPE)))) 7643 1.1 mrg { 7644 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7645 1.1 mrg "%qE in %<aligned%> clause is neither a pointer nor " 7646 1.1 mrg "an array nor a reference to pointer or array", t); 7647 1.1 mrg remove = true; 7648 1.1 mrg } 7649 1.1 mrg else if (bitmap_bit_p (&aligned_head, DECL_UID (t))) 7650 1.1 mrg { 7651 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7652 1.1 mrg "%qD appears more than once in %<aligned%> clauses", 7653 1.1 mrg t); 7654 1.1 mrg remove = true; 7655 1.1 mrg } 7656 1.1 mrg else 7657 1.1 mrg bitmap_set_bit (&aligned_head, DECL_UID (t)); 7658 1.1 mrg t = OMP_CLAUSE_ALIGNED_ALIGNMENT (c); 7659 1.1 mrg if (t == error_mark_node) 7660 1.1 mrg remove = true; 7661 1.1 mrg else if (t == NULL_TREE) 7662 1.1 mrg break; 7663 1.1 mrg else if (!type_dependent_expression_p (t) 7664 1.1 mrg && !INTEGRAL_TYPE_P (TREE_TYPE (t))) 7665 1.1 mrg { 7666 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7667 1.1 mrg "%<aligned%> clause alignment expression must " 7668 1.1 mrg "be integral"); 7669 1.1 mrg remove = true; 7670 1.1 mrg } 7671 1.1 mrg else 7672 1.1 mrg { 7673 1.1 mrg t = mark_rvalue_use (t); 7674 1.1 mrg if (!processing_template_decl) 7675 1.1 mrg { 7676 1.1 mrg t = maybe_constant_value (t); 7677 1.1 mrg if (TREE_CODE (t) != INTEGER_CST 7678 1.1 mrg || tree_int_cst_sgn (t) != 1) 7679 1.1 mrg { 7680 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7681 1.1 mrg "%<aligned%> clause alignment expression must " 7682 1.1 mrg "be positive constant integer expression"); 7683 1.1 mrg remove = true; 7684 1.1 mrg } 7685 1.1 mrg else 7686 1.1 mrg t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 7687 1.1 mrg } 7688 1.1 mrg OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = t; 7689 1.1 mrg } 7690 1.1 mrg break; 7691 1.1 mrg 7692 1.1 mrg case OMP_CLAUSE_NONTEMPORAL: 7693 1.1 mrg t = OMP_CLAUSE_DECL (c); 7694 1.1 mrg if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL) 7695 1.1 mrg { 7696 1.1 mrg if (processing_template_decl && TREE_CODE (t) != OVERLOAD) 7697 1.1 mrg break; 7698 1.1 mrg if (DECL_P (t)) 7699 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7700 1.1 mrg "%qD is not a variable in %<nontemporal%> clause", 7701 1.1 mrg t); 7702 1.1 mrg else 7703 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7704 1.1 mrg "%qE is not a variable in %<nontemporal%> clause", 7705 1.1 mrg t); 7706 1.1 mrg remove = true; 7707 1.1 mrg } 7708 1.1 mrg else if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t))) 7709 1.1 mrg { 7710 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7711 1.1 mrg "%qD appears more than once in %<nontemporal%> " 7712 1.1 mrg "clauses", t); 7713 1.1 mrg remove = true; 7714 1.1 mrg } 7715 1.1 mrg else 7716 1.1 mrg bitmap_set_bit (&oacc_reduction_head, DECL_UID (t)); 7717 1.1 mrg break; 7718 1.1 mrg 7719 1.1 mrg case OMP_CLAUSE_ALLOCATE: 7720 1.1 mrg t = omp_clause_decl_field (OMP_CLAUSE_DECL (c)); 7721 1.1 mrg if (t) 7722 1.1 mrg omp_note_field_privatization (t, OMP_CLAUSE_DECL (c)); 7723 1.1 mrg else 7724 1.1 mrg t = OMP_CLAUSE_DECL (c); 7725 1.1 mrg if (t == current_class_ptr) 7726 1.1 mrg { 7727 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7728 1.1 mrg "%<this%> not allowed in %<allocate%> clause"); 7729 1.1 mrg remove = true; 7730 1.1 mrg break; 7731 1.1 mrg } 7732 1.1 mrg if (!VAR_P (t) 7733 1.1 mrg && TREE_CODE (t) != PARM_DECL 7734 1.1 mrg && TREE_CODE (t) != FIELD_DECL) 7735 1.1 mrg { 7736 1.1 mrg if (processing_template_decl && TREE_CODE (t) != OVERLOAD) 7737 1.1 mrg break; 7738 1.1 mrg if (DECL_P (t)) 7739 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7740 1.1 mrg "%qD is not a variable in %<allocate%> clause", t); 7741 1.1 mrg else 7742 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7743 1.1 mrg "%qE is not a variable in %<allocate%> clause", t); 7744 1.1 mrg remove = true; 7745 1.1 mrg } 7746 1.1 mrg else if (bitmap_bit_p (&aligned_head, DECL_UID (t))) 7747 1.1 mrg { 7748 1.1 mrg warning_at (OMP_CLAUSE_LOCATION (c), 0, 7749 1.1 mrg "%qD appears more than once in %<allocate%> clauses", 7750 1.1 mrg t); 7751 1.1 mrg remove = true; 7752 1.1 mrg } 7753 1.1 mrg else 7754 1.1 mrg { 7755 1.1 mrg bitmap_set_bit (&aligned_head, DECL_UID (t)); 7756 1.1 mrg allocate_seen = true; 7757 1.1 mrg } 7758 1.1 mrg tree allocator, align; 7759 1.1 mrg align = OMP_CLAUSE_ALLOCATE_ALIGN (c); 7760 1.1 mrg if (error_operand_p (align)) 7761 1.1 mrg { 7762 1.1 mrg remove = true; 7763 1.1 mrg break; 7764 1.1 mrg } 7765 1.1 mrg if (align) 7766 1.1 mrg { 7767 1.1 mrg if (!type_dependent_expression_p (align) 7768 1.1 mrg && !INTEGRAL_TYPE_P (TREE_TYPE (align))) 7769 1.1 mrg { 7770 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7771 1.1 mrg "%<allocate%> clause %<align%> modifier " 7772 1.1 mrg "argument needs to be positive constant " 7773 1.1 mrg "power of two integer expression"); 7774 1.1 mrg remove = true; 7775 1.1 mrg } 7776 1.1 mrg else 7777 1.1 mrg { 7778 1.1 mrg align = mark_rvalue_use (align); 7779 1.1 mrg if (!processing_template_decl) 7780 1.1 mrg { 7781 1.1 mrg align = maybe_constant_value (align); 7782 1.1 mrg if (TREE_CODE (align) != INTEGER_CST 7783 1.1 mrg || !tree_fits_uhwi_p (align) 7784 1.1 mrg || !integer_pow2p (align)) 7785 1.1 mrg { 7786 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7787 1.1 mrg "%<allocate%> clause %<align%> modifier " 7788 1.1 mrg "argument needs to be positive constant " 7789 1.1 mrg "power of two integer expression"); 7790 1.1 mrg remove = true; 7791 1.1 mrg } 7792 1.1 mrg } 7793 1.1 mrg } 7794 1.1 mrg OMP_CLAUSE_ALLOCATE_ALIGN (c) = align; 7795 1.1 mrg } 7796 1.1 mrg allocator = OMP_CLAUSE_ALLOCATE_ALLOCATOR (c); 7797 1.1 mrg if (error_operand_p (allocator)) 7798 1.1 mrg { 7799 1.1 mrg remove = true; 7800 1.1 mrg break; 7801 1.1 mrg } 7802 1.1 mrg if (allocator == NULL_TREE) 7803 1.1 mrg goto handle_field_decl; 7804 1.1 mrg tree allocatort; 7805 1.1 mrg allocatort = TYPE_MAIN_VARIANT (TREE_TYPE (allocator)); 7806 1.1 mrg if (!type_dependent_expression_p (allocator) 7807 1.1 mrg && (TREE_CODE (allocatort) != ENUMERAL_TYPE 7808 1.1 mrg || TYPE_NAME (allocatort) == NULL_TREE 7809 1.1 mrg || TREE_CODE (TYPE_NAME (allocatort)) != TYPE_DECL 7810 1.1 mrg || (DECL_NAME (TYPE_NAME (allocatort)) 7811 1.1 mrg != get_identifier ("omp_allocator_handle_t")) 7812 1.1 mrg || (TYPE_CONTEXT (allocatort) 7813 1.1 mrg != DECL_CONTEXT (global_namespace)))) 7814 1.1 mrg { 7815 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7816 1.1 mrg "%<allocate%> clause allocator expression has " 7817 1.1 mrg "type %qT rather than %<omp_allocator_handle_t%>", 7818 1.1 mrg TREE_TYPE (allocator)); 7819 1.1 mrg remove = true; 7820 1.1 mrg break; 7821 1.1 mrg } 7822 1.1 mrg else 7823 1.1 mrg { 7824 1.1 mrg allocator = mark_rvalue_use (allocator); 7825 1.1 mrg if (!processing_template_decl) 7826 1.1 mrg allocator = maybe_constant_value (allocator); 7827 1.1 mrg OMP_CLAUSE_ALLOCATE_ALLOCATOR (c) = allocator; 7828 1.1 mrg } 7829 1.1 mrg goto handle_field_decl; 7830 1.1 mrg 7831 1.1 mrg case OMP_CLAUSE_DEPEND: 7832 1.1 mrg t = OMP_CLAUSE_DECL (c); 7833 1.1 mrg if (t == NULL_TREE) 7834 1.1 mrg { 7835 1.1 mrg gcc_assert (OMP_CLAUSE_DEPEND_KIND (c) 7836 1.1 mrg == OMP_CLAUSE_DEPEND_SOURCE); 7837 1.1 mrg break; 7838 1.1 mrg } 7839 1.1 mrg if (OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_SINK) 7840 1.1 mrg { 7841 1.1 mrg if (cp_finish_omp_clause_depend_sink (c)) 7842 1.1 mrg remove = true; 7843 1.1 mrg break; 7844 1.1 mrg } 7845 1.1 mrg /* FALLTHRU */ 7846 1.1 mrg case OMP_CLAUSE_AFFINITY: 7847 1.1 mrg t = OMP_CLAUSE_DECL (c); 7848 1.1 mrg if (TREE_CODE (t) == TREE_LIST 7849 1.1 mrg && TREE_PURPOSE (t) 7850 1.1 mrg && TREE_CODE (TREE_PURPOSE (t)) == TREE_VEC) 7851 1.1 mrg { 7852 1.1 mrg if (TREE_PURPOSE (t) != last_iterators) 7853 1.1 mrg last_iterators_remove 7854 1.1 mrg = cp_omp_finish_iterators (TREE_PURPOSE (t)); 7855 1.1 mrg last_iterators = TREE_PURPOSE (t); 7856 1.1 mrg t = TREE_VALUE (t); 7857 1.1 mrg if (last_iterators_remove) 7858 1.1 mrg t = error_mark_node; 7859 1.1 mrg } 7860 1.1 mrg else 7861 1.1 mrg last_iterators = NULL_TREE; 7862 1.1 mrg 7863 1.1 mrg if (TREE_CODE (t) == TREE_LIST) 7864 1.1 mrg { 7865 1.1 mrg if (handle_omp_array_sections (c, ort)) 7866 1.1 mrg remove = true; 7867 1.1 mrg else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND 7868 1.1 mrg && (OMP_CLAUSE_DEPEND_KIND (c) 7869 1.1 mrg == OMP_CLAUSE_DEPEND_DEPOBJ)) 7870 1.1 mrg { 7871 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7872 1.1 mrg "%<depend%> clause with %<depobj%> dependence " 7873 1.1 mrg "type on array section"); 7874 1.1 mrg remove = true; 7875 1.1 mrg } 7876 1.1 mrg break; 7877 1.1 mrg } 7878 1.1 mrg if (t == error_mark_node) 7879 1.1 mrg remove = true; 7880 1.1 mrg else if (processing_template_decl && TREE_CODE (t) != OVERLOAD) 7881 1.1 mrg break; 7882 1.1 mrg else if (!lvalue_p (t)) 7883 1.1 mrg { 7884 1.1 mrg if (DECL_P (t)) 7885 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7886 1.1 mrg "%qD is not lvalue expression nor array section " 7887 1.1 mrg "in %qs clause", t, 7888 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 7889 1.1 mrg else 7890 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7891 1.1 mrg "%qE is not lvalue expression nor array section " 7892 1.1 mrg "in %qs clause", t, 7893 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 7894 1.1 mrg remove = true; 7895 1.1 mrg } 7896 1.1 mrg else if (TREE_CODE (t) == COMPONENT_REF 7897 1.1 mrg && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL 7898 1.1 mrg && DECL_BIT_FIELD (TREE_OPERAND (t, 1))) 7899 1.1 mrg { 7900 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7901 1.1 mrg "bit-field %qE in %qs clause", t, 7902 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 7903 1.1 mrg remove = true; 7904 1.1 mrg } 7905 1.1 mrg else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND 7906 1.1 mrg && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ) 7907 1.1 mrg { 7908 1.1 mrg if (!c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t)) 7909 1.1 mrg ? TREE_TYPE (TREE_TYPE (t)) 7910 1.1 mrg : TREE_TYPE (t))) 7911 1.1 mrg { 7912 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7913 1.1 mrg "%qE does not have %<omp_depend_t%> type in " 7914 1.1 mrg "%<depend%> clause with %<depobj%> dependence " 7915 1.1 mrg "type", t); 7916 1.1 mrg remove = true; 7917 1.1 mrg } 7918 1.1 mrg } 7919 1.1 mrg else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND 7920 1.1 mrg && c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t)) 7921 1.1 mrg ? TREE_TYPE (TREE_TYPE (t)) 7922 1.1 mrg : TREE_TYPE (t))) 7923 1.1 mrg { 7924 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7925 1.1 mrg "%qE should not have %<omp_depend_t%> type in " 7926 1.1 mrg "%<depend%> clause with dependence type other than " 7927 1.1 mrg "%<depobj%>", t); 7928 1.1 mrg remove = true; 7929 1.1 mrg } 7930 1.1 mrg if (!remove) 7931 1.1 mrg { 7932 1.1 mrg tree addr = cp_build_addr_expr (t, tf_warning_or_error); 7933 1.1 mrg if (addr == error_mark_node) 7934 1.1 mrg remove = true; 7935 1.1 mrg else 7936 1.1 mrg { 7937 1.1 mrg t = cp_build_indirect_ref (OMP_CLAUSE_LOCATION (c), 7938 1.1 mrg addr, RO_UNARY_STAR, 7939 1.1 mrg tf_warning_or_error); 7940 1.1 mrg if (t == error_mark_node) 7941 1.1 mrg remove = true; 7942 1.1 mrg else if (TREE_CODE (OMP_CLAUSE_DECL (c)) == TREE_LIST 7943 1.1 mrg && TREE_PURPOSE (OMP_CLAUSE_DECL (c)) 7944 1.1 mrg && (TREE_CODE (TREE_PURPOSE (OMP_CLAUSE_DECL (c))) 7945 1.1 mrg == TREE_VEC)) 7946 1.1 mrg TREE_VALUE (OMP_CLAUSE_DECL (c)) = t; 7947 1.1 mrg else 7948 1.1 mrg OMP_CLAUSE_DECL (c) = t; 7949 1.1 mrg } 7950 1.1 mrg } 7951 1.1 mrg break; 7952 1.1 mrg case OMP_CLAUSE_DETACH: 7953 1.1 mrg t = OMP_CLAUSE_DECL (c); 7954 1.1 mrg if (detach_seen) 7955 1.1 mrg { 7956 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7957 1.1 mrg "too many %qs clauses on a task construct", 7958 1.1 mrg "detach"); 7959 1.1 mrg remove = true; 7960 1.1 mrg break; 7961 1.1 mrg } 7962 1.1 mrg else if (error_operand_p (t)) 7963 1.1 mrg { 7964 1.1 mrg remove = true; 7965 1.1 mrg break; 7966 1.1 mrg } 7967 1.1 mrg else 7968 1.1 mrg { 7969 1.1 mrg tree type = TYPE_MAIN_VARIANT (TREE_TYPE (t)); 7970 1.1 mrg if (!type_dependent_expression_p (t) 7971 1.1 mrg && (!INTEGRAL_TYPE_P (type) 7972 1.1 mrg || TREE_CODE (type) != ENUMERAL_TYPE 7973 1.1 mrg || TYPE_NAME (type) == NULL_TREE 7974 1.1 mrg || (DECL_NAME (TYPE_NAME (type)) 7975 1.1 mrg != get_identifier ("omp_event_handle_t")))) 7976 1.1 mrg { 7977 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 7978 1.1 mrg "%<detach%> clause event handle " 7979 1.1 mrg "has type %qT rather than " 7980 1.1 mrg "%<omp_event_handle_t%>", 7981 1.1 mrg type); 7982 1.1 mrg remove = true; 7983 1.1 mrg } 7984 1.1 mrg detach_seen = c; 7985 1.1 mrg cxx_mark_addressable (t); 7986 1.1 mrg } 7987 1.1 mrg break; 7988 1.1 mrg 7989 1.1 mrg case OMP_CLAUSE_MAP: 7990 1.1 mrg if (OMP_CLAUSE_MAP_IMPLICIT (c) && !implicit_moved) 7991 1.1 mrg goto move_implicit; 7992 1.1 mrg /* FALLTHRU */ 7993 1.1 mrg case OMP_CLAUSE_TO: 7994 1.1 mrg case OMP_CLAUSE_FROM: 7995 1.1 mrg case OMP_CLAUSE__CACHE_: 7996 1.1 mrg t = OMP_CLAUSE_DECL (c); 7997 1.1 mrg if (TREE_CODE (t) == TREE_LIST) 7998 1.1 mrg { 7999 1.1 mrg if (handle_omp_array_sections (c, ort)) 8000 1.1 mrg remove = true; 8001 1.1 mrg else 8002 1.1 mrg { 8003 1.1 mrg t = OMP_CLAUSE_DECL (c); 8004 1.1 mrg if (TREE_CODE (t) != TREE_LIST 8005 1.1 mrg && !type_dependent_expression_p (t) 8006 1.1 mrg && !cp_omp_mappable_type (TREE_TYPE (t))) 8007 1.1 mrg { 8008 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8009 1.1 mrg "array section does not have mappable type " 8010 1.1 mrg "in %qs clause", 8011 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 8012 1.1 mrg cp_omp_emit_unmappable_type_notes (TREE_TYPE (t)); 8013 1.1 mrg remove = true; 8014 1.1 mrg } 8015 1.1 mrg while (TREE_CODE (t) == ARRAY_REF) 8016 1.1 mrg t = TREE_OPERAND (t, 0); 8017 1.1 mrg if (TREE_CODE (t) == COMPONENT_REF 8018 1.1 mrg && TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE) 8019 1.1 mrg { 8020 1.1 mrg do 8021 1.1 mrg { 8022 1.1 mrg t = TREE_OPERAND (t, 0); 8023 1.1 mrg if (REFERENCE_REF_P (t)) 8024 1.1 mrg t = TREE_OPERAND (t, 0); 8025 1.1 mrg if (TREE_CODE (t) == MEM_REF 8026 1.1 mrg || TREE_CODE (t) == INDIRECT_REF) 8027 1.1 mrg { 8028 1.1 mrg t = TREE_OPERAND (t, 0); 8029 1.1 mrg STRIP_NOPS (t); 8030 1.1 mrg if (TREE_CODE (t) == POINTER_PLUS_EXPR) 8031 1.1 mrg t = TREE_OPERAND (t, 0); 8032 1.1 mrg } 8033 1.1 mrg } 8034 1.1 mrg while (TREE_CODE (t) == COMPONENT_REF 8035 1.1 mrg || TREE_CODE (t) == ARRAY_REF); 8036 1.1 mrg 8037 1.1 mrg if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP 8038 1.1 mrg && OMP_CLAUSE_MAP_IMPLICIT (c) 8039 1.1 mrg && (bitmap_bit_p (&map_head, DECL_UID (t)) 8040 1.1 mrg || bitmap_bit_p (&map_field_head, DECL_UID (t)) 8041 1.1 mrg || bitmap_bit_p (&map_firstprivate_head, 8042 1.1 mrg DECL_UID (t)))) 8043 1.1 mrg { 8044 1.1 mrg remove = true; 8045 1.1 mrg break; 8046 1.1 mrg } 8047 1.1 mrg if (bitmap_bit_p (&map_field_head, DECL_UID (t))) 8048 1.1 mrg break; 8049 1.1 mrg if (bitmap_bit_p (&map_head, DECL_UID (t))) 8050 1.1 mrg { 8051 1.1 mrg if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP) 8052 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8053 1.1 mrg "%qD appears more than once in motion" 8054 1.1 mrg " clauses", t); 8055 1.1 mrg else if (ort == C_ORT_ACC) 8056 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8057 1.1 mrg "%qD appears more than once in data" 8058 1.1 mrg " clauses", t); 8059 1.1 mrg else 8060 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8061 1.1 mrg "%qD appears more than once in map" 8062 1.1 mrg " clauses", t); 8063 1.1 mrg remove = true; 8064 1.1 mrg } 8065 1.1 mrg else 8066 1.1 mrg { 8067 1.1 mrg bitmap_set_bit (&map_head, DECL_UID (t)); 8068 1.1 mrg bitmap_set_bit (&map_field_head, DECL_UID (t)); 8069 1.1 mrg } 8070 1.1 mrg } 8071 1.1 mrg } 8072 1.1 mrg if (cp_oacc_check_attachments (c)) 8073 1.1 mrg remove = true; 8074 1.1 mrg if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP 8075 1.1 mrg && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH 8076 1.1 mrg || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)) 8077 1.1 mrg /* In this case, we have a single array element which is a 8078 1.1 mrg pointer, and we already set OMP_CLAUSE_SIZE in 8079 1.1 mrg handle_omp_array_sections above. For attach/detach clauses, 8080 1.1 mrg reset the OMP_CLAUSE_SIZE (representing a bias) to zero 8081 1.1 mrg here. */ 8082 1.1 mrg OMP_CLAUSE_SIZE (c) = size_zero_node; 8083 1.1 mrg break; 8084 1.1 mrg } 8085 1.1 mrg if (t == error_mark_node) 8086 1.1 mrg { 8087 1.1 mrg remove = true; 8088 1.1 mrg break; 8089 1.1 mrg } 8090 1.1 mrg /* OpenACC attach / detach clauses must be pointers. */ 8091 1.1 mrg if (cp_oacc_check_attachments (c)) 8092 1.1 mrg { 8093 1.1 mrg remove = true; 8094 1.1 mrg break; 8095 1.1 mrg } 8096 1.1 mrg if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP 8097 1.1 mrg && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH 8098 1.1 mrg || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)) 8099 1.1 mrg /* For attach/detach clauses, set OMP_CLAUSE_SIZE (representing a 8100 1.1 mrg bias) to zero here, so it is not set erroneously to the pointer 8101 1.1 mrg size later on in gimplify.cc. */ 8102 1.1 mrg OMP_CLAUSE_SIZE (c) = size_zero_node; 8103 1.1 mrg if (REFERENCE_REF_P (t) 8104 1.1 mrg && TREE_CODE (TREE_OPERAND (t, 0)) == COMPONENT_REF) 8105 1.1 mrg { 8106 1.1 mrg t = TREE_OPERAND (t, 0); 8107 1.1 mrg if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP 8108 1.1 mrg && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH) 8109 1.1 mrg OMP_CLAUSE_DECL (c) = t; 8110 1.1 mrg } 8111 1.1 mrg while (TREE_CODE (t) == INDIRECT_REF 8112 1.1 mrg || TREE_CODE (t) == ARRAY_REF) 8113 1.1 mrg { 8114 1.1 mrg t = TREE_OPERAND (t, 0); 8115 1.1 mrg STRIP_NOPS (t); 8116 1.1 mrg if (TREE_CODE (t) == POINTER_PLUS_EXPR) 8117 1.1 mrg t = TREE_OPERAND (t, 0); 8118 1.1 mrg } 8119 1.1 mrg while (TREE_CODE (t) == COMPOUND_EXPR) 8120 1.1 mrg { 8121 1.1 mrg t = TREE_OPERAND (t, 1); 8122 1.1 mrg STRIP_NOPS (t); 8123 1.1 mrg } 8124 1.1 mrg indir_component_ref_p = false; 8125 1.1 mrg if (TREE_CODE (t) == COMPONENT_REF 8126 1.1 mrg && (TREE_CODE (TREE_OPERAND (t, 0)) == INDIRECT_REF 8127 1.1 mrg || TREE_CODE (TREE_OPERAND (t, 0)) == ARRAY_REF)) 8128 1.1 mrg { 8129 1.1 mrg t = TREE_OPERAND (TREE_OPERAND (t, 0), 0); 8130 1.1 mrg indir_component_ref_p = true; 8131 1.1 mrg STRIP_NOPS (t); 8132 1.1 mrg if (TREE_CODE (t) == POINTER_PLUS_EXPR) 8133 1.1 mrg t = TREE_OPERAND (t, 0); 8134 1.1 mrg } 8135 1.1 mrg if (TREE_CODE (t) == COMPONENT_REF 8136 1.1 mrg && OMP_CLAUSE_CODE (c) != OMP_CLAUSE__CACHE_) 8137 1.1 mrg { 8138 1.1 mrg if (type_dependent_expression_p (t)) 8139 1.1 mrg break; 8140 1.1 mrg if (TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL 8141 1.1 mrg && DECL_BIT_FIELD (TREE_OPERAND (t, 1))) 8142 1.1 mrg { 8143 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8144 1.1 mrg "bit-field %qE in %qs clause", 8145 1.1 mrg t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 8146 1.1 mrg remove = true; 8147 1.1 mrg } 8148 1.1 mrg else if (!cp_omp_mappable_type (TREE_TYPE (t))) 8149 1.1 mrg { 8150 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8151 1.1 mrg "%qE does not have a mappable type in %qs clause", 8152 1.1 mrg t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 8153 1.1 mrg cp_omp_emit_unmappable_type_notes (TREE_TYPE (t)); 8154 1.1 mrg remove = true; 8155 1.1 mrg } 8156 1.1 mrg while (TREE_CODE (t) == COMPONENT_REF) 8157 1.1 mrg { 8158 1.1 mrg if (TREE_TYPE (TREE_OPERAND (t, 0)) 8159 1.1 mrg && (TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) 8160 1.1 mrg == UNION_TYPE)) 8161 1.1 mrg { 8162 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8163 1.1 mrg "%qE is a member of a union", t); 8164 1.1 mrg remove = true; 8165 1.1 mrg break; 8166 1.1 mrg } 8167 1.1 mrg t = TREE_OPERAND (t, 0); 8168 1.1 mrg if (TREE_CODE (t) == MEM_REF) 8169 1.1 mrg { 8170 1.1 mrg if (maybe_ne (mem_ref_offset (t), 0)) 8171 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8172 1.1 mrg "cannot dereference %qE in %qs clause", t, 8173 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 8174 1.1 mrg else 8175 1.1 mrg t = TREE_OPERAND (t, 0); 8176 1.1 mrg } 8177 1.1 mrg while (TREE_CODE (t) == MEM_REF 8178 1.1 mrg || TREE_CODE (t) == INDIRECT_REF 8179 1.1 mrg || TREE_CODE (t) == ARRAY_REF) 8180 1.1 mrg { 8181 1.1 mrg t = TREE_OPERAND (t, 0); 8182 1.1 mrg STRIP_NOPS (t); 8183 1.1 mrg if (TREE_CODE (t) == POINTER_PLUS_EXPR) 8184 1.1 mrg t = TREE_OPERAND (t, 0); 8185 1.1 mrg } 8186 1.1 mrg } 8187 1.1 mrg if (remove) 8188 1.1 mrg break; 8189 1.1 mrg if (REFERENCE_REF_P (t)) 8190 1.1 mrg t = TREE_OPERAND (t, 0); 8191 1.1 mrg if (VAR_P (t) || TREE_CODE (t) == PARM_DECL) 8192 1.1 mrg { 8193 1.1 mrg if (bitmap_bit_p (&map_field_head, DECL_UID (t)) 8194 1.1 mrg || (ort != C_ORT_ACC 8195 1.1 mrg && bitmap_bit_p (&map_head, DECL_UID (t)))) 8196 1.1 mrg goto handle_map_references; 8197 1.1 mrg } 8198 1.1 mrg } 8199 1.1 mrg if (!processing_template_decl 8200 1.1 mrg && TREE_CODE (t) == FIELD_DECL) 8201 1.1 mrg { 8202 1.1 mrg OMP_CLAUSE_DECL (c) = finish_non_static_data_member (t, NULL_TREE, 8203 1.1 mrg NULL_TREE); 8204 1.1 mrg break; 8205 1.1 mrg } 8206 1.1 mrg if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL) 8207 1.1 mrg { 8208 1.1 mrg if (processing_template_decl && TREE_CODE (t) != OVERLOAD) 8209 1.1 mrg break; 8210 1.1 mrg if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP 8211 1.1 mrg && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER 8212 1.1 mrg || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_POINTER 8213 1.1 mrg || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH_DETACH)) 8214 1.1 mrg break; 8215 1.1 mrg if (DECL_P (t)) 8216 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8217 1.1 mrg "%qD is not a variable in %qs clause", t, 8218 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 8219 1.1 mrg else 8220 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8221 1.1 mrg "%qE is not a variable in %qs clause", t, 8222 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 8223 1.1 mrg remove = true; 8224 1.1 mrg } 8225 1.1 mrg else if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t)) 8226 1.1 mrg { 8227 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8228 1.1 mrg "%qD is threadprivate variable in %qs clause", t, 8229 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 8230 1.1 mrg remove = true; 8231 1.1 mrg } 8232 1.1 mrg else if (!processing_template_decl 8233 1.1 mrg && !TYPE_REF_P (TREE_TYPE (t)) 8234 1.1 mrg && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP 8235 1.1 mrg || (OMP_CLAUSE_MAP_KIND (c) 8236 1.1 mrg != GOMP_MAP_FIRSTPRIVATE_POINTER)) 8237 1.1 mrg && !indir_component_ref_p 8238 1.1 mrg && !cxx_mark_addressable (t)) 8239 1.1 mrg remove = true; 8240 1.1 mrg else if (!(OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP 8241 1.1 mrg && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER 8242 1.1 mrg || (OMP_CLAUSE_MAP_KIND (c) 8243 1.1 mrg == GOMP_MAP_FIRSTPRIVATE_POINTER))) 8244 1.1 mrg && t == OMP_CLAUSE_DECL (c) 8245 1.1 mrg && !type_dependent_expression_p (t) 8246 1.1 mrg && !cp_omp_mappable_type (TYPE_REF_P (TREE_TYPE (t)) 8247 1.1 mrg ? TREE_TYPE (TREE_TYPE (t)) 8248 1.1 mrg : TREE_TYPE (t))) 8249 1.1 mrg { 8250 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8251 1.1 mrg "%qD does not have a mappable type in %qs clause", t, 8252 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 8253 1.1 mrg cp_omp_emit_unmappable_type_notes (TREE_TYPE (t)); 8254 1.1 mrg remove = true; 8255 1.1 mrg } 8256 1.1 mrg else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP 8257 1.1 mrg && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FORCE_DEVICEPTR 8258 1.1 mrg && !type_dependent_expression_p (t) 8259 1.1 mrg && !INDIRECT_TYPE_P (TREE_TYPE (t))) 8260 1.1 mrg { 8261 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8262 1.1 mrg "%qD is not a pointer variable", t); 8263 1.1 mrg remove = true; 8264 1.1 mrg } 8265 1.1 mrg else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP 8266 1.1 mrg && OMP_CLAUSE_MAP_IMPLICIT (c) 8267 1.1 mrg && (bitmap_bit_p (&map_head, DECL_UID (t)) 8268 1.1 mrg || bitmap_bit_p (&map_field_head, DECL_UID (t)) 8269 1.1 mrg || bitmap_bit_p (&map_firstprivate_head, 8270 1.1 mrg DECL_UID (t)))) 8271 1.1 mrg remove = true; 8272 1.1 mrg else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP 8273 1.1 mrg && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FIRSTPRIVATE_POINTER) 8274 1.1 mrg { 8275 1.1 mrg if (bitmap_bit_p (&generic_head, DECL_UID (t)) 8276 1.1 mrg || bitmap_bit_p (&firstprivate_head, DECL_UID (t)) 8277 1.1 mrg || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t))) 8278 1.1 mrg { 8279 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8280 1.1 mrg "%qD appears more than once in data clauses", t); 8281 1.1 mrg remove = true; 8282 1.1 mrg } 8283 1.1 mrg else if (bitmap_bit_p (&map_head, DECL_UID (t)) 8284 1.1 mrg && !bitmap_bit_p (&map_field_head, DECL_UID (t))) 8285 1.1 mrg { 8286 1.1 mrg if (ort == C_ORT_ACC) 8287 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8288 1.1 mrg "%qD appears more than once in data clauses", t); 8289 1.1 mrg else 8290 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8291 1.1 mrg "%qD appears both in data and map clauses", t); 8292 1.1 mrg remove = true; 8293 1.1 mrg } 8294 1.1 mrg else 8295 1.1 mrg bitmap_set_bit (&map_firstprivate_head, DECL_UID (t)); 8296 1.1 mrg } 8297 1.1 mrg else if (bitmap_bit_p (&map_head, DECL_UID (t)) 8298 1.1 mrg && !bitmap_bit_p (&map_field_head, DECL_UID (t))) 8299 1.1 mrg { 8300 1.1 mrg if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP) 8301 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8302 1.1 mrg "%qD appears more than once in motion clauses", t); 8303 1.1 mrg else if (ort == C_ORT_ACC) 8304 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8305 1.1 mrg "%qD appears more than once in data clauses", t); 8306 1.1 mrg else 8307 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8308 1.1 mrg "%qD appears more than once in map clauses", t); 8309 1.1 mrg remove = true; 8310 1.1 mrg } 8311 1.1 mrg else if (ort == C_ORT_ACC 8312 1.1 mrg && bitmap_bit_p (&generic_head, DECL_UID (t))) 8313 1.1 mrg { 8314 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8315 1.1 mrg "%qD appears more than once in data clauses", t); 8316 1.1 mrg remove = true; 8317 1.1 mrg } 8318 1.1 mrg else if (bitmap_bit_p (&firstprivate_head, DECL_UID (t)) 8319 1.1 mrg || bitmap_bit_p (&is_on_device_head, DECL_UID (t))) 8320 1.1 mrg { 8321 1.1 mrg if (ort == C_ORT_ACC) 8322 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8323 1.1 mrg "%qD appears more than once in data clauses", t); 8324 1.1 mrg else 8325 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8326 1.1 mrg "%qD appears both in data and map clauses", t); 8327 1.1 mrg remove = true; 8328 1.1 mrg } 8329 1.1 mrg else 8330 1.1 mrg { 8331 1.1 mrg bitmap_set_bit (&map_head, DECL_UID (t)); 8332 1.1 mrg 8333 1.1 mrg tree decl = OMP_CLAUSE_DECL (c); 8334 1.1 mrg if (t != decl 8335 1.1 mrg && (TREE_CODE (decl) == COMPONENT_REF 8336 1.1 mrg || (INDIRECT_REF_P (decl) 8337 1.1 mrg && TREE_CODE (TREE_OPERAND (decl, 0)) == COMPONENT_REF 8338 1.1 mrg && TYPE_REF_P (TREE_TYPE (TREE_OPERAND (decl, 0)))))) 8339 1.1 mrg bitmap_set_bit (&map_field_head, DECL_UID (t)); 8340 1.1 mrg } 8341 1.1 mrg handle_map_references: 8342 1.1 mrg if (!remove 8343 1.1 mrg && !processing_template_decl 8344 1.1 mrg && ort != C_ORT_DECLARE_SIMD 8345 1.1 mrg && TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))) 8346 1.1 mrg { 8347 1.1 mrg t = OMP_CLAUSE_DECL (c); 8348 1.1 mrg if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP) 8349 1.1 mrg { 8350 1.1 mrg OMP_CLAUSE_DECL (c) = build_simple_mem_ref (t); 8351 1.1 mrg if (OMP_CLAUSE_SIZE (c) == NULL_TREE) 8352 1.1 mrg OMP_CLAUSE_SIZE (c) 8353 1.1 mrg = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t))); 8354 1.1 mrg } 8355 1.1 mrg else if (OMP_CLAUSE_MAP_KIND (c) 8356 1.1 mrg != GOMP_MAP_FIRSTPRIVATE_POINTER 8357 1.1 mrg && (OMP_CLAUSE_MAP_KIND (c) 8358 1.1 mrg != GOMP_MAP_FIRSTPRIVATE_REFERENCE) 8359 1.1 mrg && (OMP_CLAUSE_MAP_KIND (c) 8360 1.1 mrg != GOMP_MAP_ALWAYS_POINTER) 8361 1.1 mrg && (OMP_CLAUSE_MAP_KIND (c) 8362 1.1 mrg != GOMP_MAP_ATTACH_DETACH)) 8363 1.1 mrg { 8364 1.1 mrg tree c2 = build_omp_clause (OMP_CLAUSE_LOCATION (c), 8365 1.1 mrg OMP_CLAUSE_MAP); 8366 1.1 mrg if (TREE_CODE (t) == COMPONENT_REF) 8367 1.1 mrg OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_ALWAYS_POINTER); 8368 1.1 mrg else 8369 1.1 mrg OMP_CLAUSE_SET_MAP_KIND (c2, 8370 1.1 mrg GOMP_MAP_FIRSTPRIVATE_REFERENCE); 8371 1.1 mrg OMP_CLAUSE_DECL (c2) = t; 8372 1.1 mrg OMP_CLAUSE_SIZE (c2) = size_zero_node; 8373 1.1 mrg OMP_CLAUSE_CHAIN (c2) = OMP_CLAUSE_CHAIN (c); 8374 1.1 mrg OMP_CLAUSE_CHAIN (c) = c2; 8375 1.1 mrg OMP_CLAUSE_DECL (c) = build_simple_mem_ref (t); 8376 1.1 mrg if (OMP_CLAUSE_SIZE (c) == NULL_TREE) 8377 1.1 mrg OMP_CLAUSE_SIZE (c) 8378 1.1 mrg = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t))); 8379 1.1 mrg c = c2; 8380 1.1 mrg } 8381 1.1 mrg } 8382 1.1 mrg break; 8383 1.1 mrg 8384 1.1 mrg case OMP_CLAUSE_TO_DECLARE: 8385 1.1 mrg case OMP_CLAUSE_LINK: 8386 1.1 mrg t = OMP_CLAUSE_DECL (c); 8387 1.1 mrg if (TREE_CODE (t) == FUNCTION_DECL 8388 1.1 mrg && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO_DECLARE) 8389 1.1 mrg ; 8390 1.1 mrg else if (!VAR_P (t)) 8391 1.1 mrg { 8392 1.1 mrg if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO_DECLARE) 8393 1.1 mrg { 8394 1.1 mrg if (TREE_CODE (t) == TEMPLATE_ID_EXPR) 8395 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8396 1.1 mrg "template %qE in clause %qs", t, 8397 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 8398 1.1 mrg else if (really_overloaded_fn (t)) 8399 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8400 1.1 mrg "overloaded function name %qE in clause %qs", t, 8401 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 8402 1.1 mrg else 8403 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8404 1.1 mrg "%qE is neither a variable nor a function name " 8405 1.1 mrg "in clause %qs", t, 8406 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 8407 1.1 mrg } 8408 1.1 mrg else 8409 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8410 1.1 mrg "%qE is not a variable in clause %qs", t, 8411 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 8412 1.1 mrg remove = true; 8413 1.1 mrg } 8414 1.1 mrg else if (DECL_THREAD_LOCAL_P (t)) 8415 1.1 mrg { 8416 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8417 1.1 mrg "%qD is threadprivate variable in %qs clause", t, 8418 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 8419 1.1 mrg remove = true; 8420 1.1 mrg } 8421 1.1 mrg else if (!cp_omp_mappable_type (TREE_TYPE (t))) 8422 1.1 mrg { 8423 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8424 1.1 mrg "%qD does not have a mappable type in %qs clause", t, 8425 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 8426 1.1 mrg cp_omp_emit_unmappable_type_notes (TREE_TYPE (t)); 8427 1.1 mrg remove = true; 8428 1.1 mrg } 8429 1.1 mrg if (remove) 8430 1.1 mrg break; 8431 1.1 mrg if (bitmap_bit_p (&generic_head, DECL_UID (t))) 8432 1.1 mrg { 8433 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8434 1.1 mrg "%qE appears more than once on the same " 8435 1.1 mrg "%<declare target%> directive", t); 8436 1.1 mrg remove = true; 8437 1.1 mrg } 8438 1.1 mrg else 8439 1.1 mrg bitmap_set_bit (&generic_head, DECL_UID (t)); 8440 1.1 mrg break; 8441 1.1 mrg 8442 1.1 mrg case OMP_CLAUSE_UNIFORM: 8443 1.1 mrg t = OMP_CLAUSE_DECL (c); 8444 1.1 mrg if (TREE_CODE (t) != PARM_DECL) 8445 1.1 mrg { 8446 1.1 mrg if (processing_template_decl) 8447 1.1 mrg break; 8448 1.1 mrg if (DECL_P (t)) 8449 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8450 1.1 mrg "%qD is not an argument in %<uniform%> clause", t); 8451 1.1 mrg else 8452 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8453 1.1 mrg "%qE is not an argument in %<uniform%> clause", t); 8454 1.1 mrg remove = true; 8455 1.1 mrg break; 8456 1.1 mrg } 8457 1.1 mrg /* map_head bitmap is used as uniform_head if declare_simd. */ 8458 1.1 mrg bitmap_set_bit (&map_head, DECL_UID (t)); 8459 1.1 mrg goto check_dup_generic; 8460 1.1 mrg 8461 1.1 mrg case OMP_CLAUSE_GRAINSIZE: 8462 1.1 mrg t = OMP_CLAUSE_GRAINSIZE_EXPR (c); 8463 1.1 mrg if (t == error_mark_node) 8464 1.1 mrg remove = true; 8465 1.1 mrg else if (!type_dependent_expression_p (t) 8466 1.1 mrg && !INTEGRAL_TYPE_P (TREE_TYPE (t))) 8467 1.1 mrg { 8468 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8469 1.1 mrg "%<grainsize%> expression must be integral"); 8470 1.1 mrg remove = true; 8471 1.1 mrg } 8472 1.1 mrg else 8473 1.1 mrg { 8474 1.1 mrg t = mark_rvalue_use (t); 8475 1.1 mrg if (!processing_template_decl) 8476 1.1 mrg { 8477 1.1 mrg t = maybe_constant_value (t); 8478 1.1 mrg if (TREE_CODE (t) == INTEGER_CST 8479 1.1 mrg && tree_int_cst_sgn (t) != 1) 8480 1.1 mrg { 8481 1.1 mrg warning_at (OMP_CLAUSE_LOCATION (c), 0, 8482 1.1 mrg "%<grainsize%> value must be positive"); 8483 1.1 mrg t = integer_one_node; 8484 1.1 mrg } 8485 1.1 mrg t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 8486 1.1 mrg } 8487 1.1 mrg OMP_CLAUSE_GRAINSIZE_EXPR (c) = t; 8488 1.1 mrg } 8489 1.1 mrg break; 8490 1.1 mrg 8491 1.1 mrg case OMP_CLAUSE_PRIORITY: 8492 1.1 mrg t = OMP_CLAUSE_PRIORITY_EXPR (c); 8493 1.1 mrg if (t == error_mark_node) 8494 1.1 mrg remove = true; 8495 1.1 mrg else if (!type_dependent_expression_p (t) 8496 1.1 mrg && !INTEGRAL_TYPE_P (TREE_TYPE (t))) 8497 1.1 mrg { 8498 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8499 1.1 mrg "%<priority%> expression must be integral"); 8500 1.1 mrg remove = true; 8501 1.1 mrg } 8502 1.1 mrg else 8503 1.1 mrg { 8504 1.1 mrg t = mark_rvalue_use (t); 8505 1.1 mrg if (!processing_template_decl) 8506 1.1 mrg { 8507 1.1 mrg t = maybe_constant_value (t); 8508 1.1 mrg if (TREE_CODE (t) == INTEGER_CST 8509 1.1 mrg && tree_int_cst_sgn (t) == -1) 8510 1.1 mrg { 8511 1.1 mrg warning_at (OMP_CLAUSE_LOCATION (c), 0, 8512 1.1 mrg "%<priority%> value must be non-negative"); 8513 1.1 mrg t = integer_one_node; 8514 1.1 mrg } 8515 1.1 mrg t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 8516 1.1 mrg } 8517 1.1 mrg OMP_CLAUSE_PRIORITY_EXPR (c) = t; 8518 1.1 mrg } 8519 1.1 mrg break; 8520 1.1 mrg 8521 1.1 mrg case OMP_CLAUSE_HINT: 8522 1.1 mrg t = OMP_CLAUSE_HINT_EXPR (c); 8523 1.1 mrg if (t == error_mark_node) 8524 1.1 mrg remove = true; 8525 1.1 mrg else if (!type_dependent_expression_p (t) 8526 1.1 mrg && !INTEGRAL_TYPE_P (TREE_TYPE (t))) 8527 1.1 mrg { 8528 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8529 1.1 mrg "%<hint%> expression must be integral"); 8530 1.1 mrg remove = true; 8531 1.1 mrg } 8532 1.1 mrg else 8533 1.1 mrg { 8534 1.1 mrg t = mark_rvalue_use (t); 8535 1.1 mrg if (!processing_template_decl) 8536 1.1 mrg { 8537 1.1 mrg t = maybe_constant_value (t); 8538 1.1 mrg t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 8539 1.1 mrg if (TREE_CODE (t) != INTEGER_CST) 8540 1.1 mrg { 8541 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8542 1.1 mrg "%<hint%> expression must be constant integer " 8543 1.1 mrg "expression"); 8544 1.1 mrg remove = true; 8545 1.1 mrg } 8546 1.1 mrg } 8547 1.1 mrg OMP_CLAUSE_HINT_EXPR (c) = t; 8548 1.1 mrg } 8549 1.1 mrg break; 8550 1.1 mrg 8551 1.1 mrg case OMP_CLAUSE_FILTER: 8552 1.1 mrg t = OMP_CLAUSE_FILTER_EXPR (c); 8553 1.1 mrg if (t == error_mark_node) 8554 1.1 mrg remove = true; 8555 1.1 mrg else if (!type_dependent_expression_p (t) 8556 1.1 mrg && !INTEGRAL_TYPE_P (TREE_TYPE (t))) 8557 1.1 mrg { 8558 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8559 1.1 mrg "%<filter%> expression must be integral"); 8560 1.1 mrg remove = true; 8561 1.1 mrg } 8562 1.1 mrg else 8563 1.1 mrg { 8564 1.1 mrg t = mark_rvalue_use (t); 8565 1.1 mrg if (!processing_template_decl) 8566 1.1 mrg { 8567 1.1 mrg t = maybe_constant_value (t); 8568 1.1 mrg t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 8569 1.1 mrg } 8570 1.1 mrg OMP_CLAUSE_FILTER_EXPR (c) = t; 8571 1.1 mrg } 8572 1.1 mrg break; 8573 1.1 mrg 8574 1.1 mrg case OMP_CLAUSE_IS_DEVICE_PTR: 8575 1.1 mrg case OMP_CLAUSE_USE_DEVICE_PTR: 8576 1.1 mrg field_ok = (ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP; 8577 1.1 mrg t = OMP_CLAUSE_DECL (c); 8578 1.1 mrg if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR) 8579 1.1 mrg bitmap_set_bit (&is_on_device_head, DECL_UID (t)); 8580 1.1 mrg if (!type_dependent_expression_p (t)) 8581 1.1 mrg { 8582 1.1 mrg tree type = TREE_TYPE (t); 8583 1.1 mrg if (!TYPE_PTR_P (type) 8584 1.1 mrg && (!TYPE_REF_P (type) || !TYPE_PTR_P (TREE_TYPE (type)))) 8585 1.1 mrg { 8586 1.1 mrg if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR 8587 1.1 mrg && ort == C_ORT_OMP) 8588 1.1 mrg { 8589 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8590 1.1 mrg "%qs variable is neither a pointer " 8591 1.1 mrg "nor reference to pointer", 8592 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 8593 1.1 mrg remove = true; 8594 1.1 mrg } 8595 1.1 mrg else if (TREE_CODE (type) != ARRAY_TYPE 8596 1.1 mrg && (!TYPE_REF_P (type) 8597 1.1 mrg || TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE)) 8598 1.1 mrg { 8599 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8600 1.1 mrg "%qs variable is neither a pointer, nor an " 8601 1.1 mrg "array nor reference to pointer or array", 8602 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 8603 1.1 mrg remove = true; 8604 1.1 mrg } 8605 1.1 mrg } 8606 1.1 mrg } 8607 1.1 mrg goto check_dup_generic; 8608 1.1 mrg 8609 1.1 mrg case OMP_CLAUSE_HAS_DEVICE_ADDR: 8610 1.1 mrg t = OMP_CLAUSE_DECL (c); 8611 1.1 mrg if (TREE_CODE (t) == TREE_LIST) 8612 1.1 mrg { 8613 1.1 mrg if (handle_omp_array_sections (c, ort)) 8614 1.1 mrg remove = true; 8615 1.1 mrg else 8616 1.1 mrg { 8617 1.1 mrg t = OMP_CLAUSE_DECL (c); 8618 1.1 mrg while (TREE_CODE (t) == INDIRECT_REF 8619 1.1 mrg || TREE_CODE (t) == ARRAY_REF) 8620 1.1 mrg t = TREE_OPERAND (t, 0); 8621 1.1 mrg } 8622 1.1 mrg } 8623 1.1 mrg bitmap_set_bit (&is_on_device_head, DECL_UID (t)); 8624 1.1 mrg if (VAR_P (t) || TREE_CODE (t) == PARM_DECL) 8625 1.1 mrg cxx_mark_addressable (t); 8626 1.1 mrg goto check_dup_generic_t; 8627 1.1 mrg 8628 1.1 mrg case OMP_CLAUSE_USE_DEVICE_ADDR: 8629 1.1 mrg field_ok = true; 8630 1.1 mrg t = OMP_CLAUSE_DECL (c); 8631 1.1 mrg if (!processing_template_decl 8632 1.1 mrg && (VAR_P (t) || TREE_CODE (t) == PARM_DECL) 8633 1.1 mrg && !TYPE_REF_P (TREE_TYPE (t)) 8634 1.1 mrg && !cxx_mark_addressable (t)) 8635 1.1 mrg remove = true; 8636 1.1 mrg goto check_dup_generic; 8637 1.1 mrg 8638 1.1 mrg case OMP_CLAUSE_NOWAIT: 8639 1.1 mrg case OMP_CLAUSE_DEFAULT: 8640 1.1 mrg case OMP_CLAUSE_UNTIED: 8641 1.1 mrg case OMP_CLAUSE_COLLAPSE: 8642 1.1 mrg case OMP_CLAUSE_PARALLEL: 8643 1.1 mrg case OMP_CLAUSE_FOR: 8644 1.1 mrg case OMP_CLAUSE_SECTIONS: 8645 1.1 mrg case OMP_CLAUSE_TASKGROUP: 8646 1.1 mrg case OMP_CLAUSE_PROC_BIND: 8647 1.1 mrg case OMP_CLAUSE_DEVICE_TYPE: 8648 1.1 mrg case OMP_CLAUSE_NOGROUP: 8649 1.1 mrg case OMP_CLAUSE_THREADS: 8650 1.1 mrg case OMP_CLAUSE_SIMD: 8651 1.1 mrg case OMP_CLAUSE_DEFAULTMAP: 8652 1.1 mrg case OMP_CLAUSE_BIND: 8653 1.1 mrg case OMP_CLAUSE_AUTO: 8654 1.1 mrg case OMP_CLAUSE_INDEPENDENT: 8655 1.1 mrg case OMP_CLAUSE_SEQ: 8656 1.1 mrg case OMP_CLAUSE_IF_PRESENT: 8657 1.1 mrg case OMP_CLAUSE_FINALIZE: 8658 1.1 mrg case OMP_CLAUSE_NOHOST: 8659 1.1 mrg break; 8660 1.1 mrg 8661 1.1 mrg case OMP_CLAUSE_MERGEABLE: 8662 1.1 mrg mergeable_seen = true; 8663 1.1 mrg break; 8664 1.1 mrg 8665 1.1 mrg case OMP_CLAUSE_TILE: 8666 1.1 mrg for (tree list = OMP_CLAUSE_TILE_LIST (c); !remove && list; 8667 1.1 mrg list = TREE_CHAIN (list)) 8668 1.1 mrg { 8669 1.1 mrg t = TREE_VALUE (list); 8670 1.1 mrg 8671 1.1 mrg if (t == error_mark_node) 8672 1.1 mrg remove = true; 8673 1.1 mrg else if (!type_dependent_expression_p (t) 8674 1.1 mrg && !INTEGRAL_TYPE_P (TREE_TYPE (t))) 8675 1.1 mrg { 8676 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8677 1.1 mrg "%<tile%> argument needs integral type"); 8678 1.1 mrg remove = true; 8679 1.1 mrg } 8680 1.1 mrg else 8681 1.1 mrg { 8682 1.1 mrg t = mark_rvalue_use (t); 8683 1.1 mrg if (!processing_template_decl) 8684 1.1 mrg { 8685 1.1 mrg /* Zero is used to indicate '*', we permit you 8686 1.1 mrg to get there via an ICE of value zero. */ 8687 1.1 mrg t = maybe_constant_value (t); 8688 1.1 mrg if (!tree_fits_shwi_p (t) 8689 1.1 mrg || tree_to_shwi (t) < 0) 8690 1.1 mrg { 8691 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8692 1.1 mrg "%<tile%> argument needs positive " 8693 1.1 mrg "integral constant"); 8694 1.1 mrg remove = true; 8695 1.1 mrg } 8696 1.1 mrg t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 8697 1.1 mrg } 8698 1.1 mrg } 8699 1.1 mrg 8700 1.1 mrg /* Update list item. */ 8701 1.1 mrg TREE_VALUE (list) = t; 8702 1.1 mrg } 8703 1.1 mrg break; 8704 1.1 mrg 8705 1.1 mrg case OMP_CLAUSE_ORDERED: 8706 1.1 mrg ordered_seen = true; 8707 1.1 mrg break; 8708 1.1 mrg 8709 1.1 mrg case OMP_CLAUSE_ORDER: 8710 1.1 mrg if (order_seen) 8711 1.1 mrg remove = true; 8712 1.1 mrg else 8713 1.1 mrg order_seen = true; 8714 1.1 mrg break; 8715 1.1 mrg 8716 1.1 mrg case OMP_CLAUSE_INBRANCH: 8717 1.1 mrg case OMP_CLAUSE_NOTINBRANCH: 8718 1.1 mrg if (branch_seen) 8719 1.1 mrg { 8720 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8721 1.1 mrg "%<inbranch%> clause is incompatible with " 8722 1.1 mrg "%<notinbranch%>"); 8723 1.1 mrg remove = true; 8724 1.1 mrg } 8725 1.1 mrg branch_seen = true; 8726 1.1 mrg break; 8727 1.1 mrg 8728 1.1 mrg case OMP_CLAUSE_INCLUSIVE: 8729 1.1 mrg case OMP_CLAUSE_EXCLUSIVE: 8730 1.1 mrg t = omp_clause_decl_field (OMP_CLAUSE_DECL (c)); 8731 1.1 mrg if (!t) 8732 1.1 mrg t = OMP_CLAUSE_DECL (c); 8733 1.1 mrg if (t == current_class_ptr) 8734 1.1 mrg { 8735 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8736 1.1 mrg "%<this%> allowed in OpenMP only in %<declare simd%>" 8737 1.1 mrg " clauses"); 8738 1.1 mrg remove = true; 8739 1.1 mrg break; 8740 1.1 mrg } 8741 1.1 mrg if (!VAR_P (t) 8742 1.1 mrg && TREE_CODE (t) != PARM_DECL 8743 1.1 mrg && TREE_CODE (t) != FIELD_DECL) 8744 1.1 mrg { 8745 1.1 mrg if (processing_template_decl && TREE_CODE (t) != OVERLOAD) 8746 1.1 mrg break; 8747 1.1 mrg if (DECL_P (t)) 8748 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8749 1.1 mrg "%qD is not a variable in clause %qs", t, 8750 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 8751 1.1 mrg else 8752 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8753 1.1 mrg "%qE is not a variable in clause %qs", t, 8754 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 8755 1.1 mrg remove = true; 8756 1.1 mrg } 8757 1.1 mrg break; 8758 1.1 mrg 8759 1.1 mrg default: 8760 1.1 mrg gcc_unreachable (); 8761 1.1 mrg } 8762 1.1 mrg 8763 1.1 mrg if (remove) 8764 1.1 mrg *pc = OMP_CLAUSE_CHAIN (c); 8765 1.1 mrg else 8766 1.1 mrg pc = &OMP_CLAUSE_CHAIN (c); 8767 1.1 mrg } 8768 1.1 mrg 8769 1.1 mrg if (reduction_seen < 0 && (ordered_seen || schedule_seen)) 8770 1.1 mrg reduction_seen = -2; 8771 1.1 mrg 8772 1.1 mrg for (pc = &clauses, c = clauses; c ; c = *pc) 8773 1.1 mrg { 8774 1.1 mrg enum omp_clause_code c_kind = OMP_CLAUSE_CODE (c); 8775 1.1 mrg bool remove = false; 8776 1.1 mrg bool need_complete_type = false; 8777 1.1 mrg bool need_default_ctor = false; 8778 1.1 mrg bool need_copy_ctor = false; 8779 1.1 mrg bool need_copy_assignment = false; 8780 1.1 mrg bool need_implicitly_determined = false; 8781 1.1 mrg bool need_dtor = false; 8782 1.1 mrg tree type, inner_type; 8783 1.1 mrg 8784 1.1 mrg switch (c_kind) 8785 1.1 mrg { 8786 1.1 mrg case OMP_CLAUSE_SHARED: 8787 1.1 mrg need_implicitly_determined = true; 8788 1.1 mrg break; 8789 1.1 mrg case OMP_CLAUSE_PRIVATE: 8790 1.1 mrg need_complete_type = true; 8791 1.1 mrg need_default_ctor = true; 8792 1.1 mrg need_dtor = true; 8793 1.1 mrg need_implicitly_determined = true; 8794 1.1 mrg break; 8795 1.1 mrg case OMP_CLAUSE_FIRSTPRIVATE: 8796 1.1 mrg need_complete_type = true; 8797 1.1 mrg need_copy_ctor = true; 8798 1.1 mrg need_dtor = true; 8799 1.1 mrg need_implicitly_determined = true; 8800 1.1 mrg break; 8801 1.1 mrg case OMP_CLAUSE_LASTPRIVATE: 8802 1.1 mrg need_complete_type = true; 8803 1.1 mrg need_copy_assignment = true; 8804 1.1 mrg need_implicitly_determined = true; 8805 1.1 mrg break; 8806 1.1 mrg case OMP_CLAUSE_REDUCTION: 8807 1.1 mrg if (reduction_seen == -2) 8808 1.1 mrg OMP_CLAUSE_REDUCTION_INSCAN (c) = 0; 8809 1.1 mrg if (OMP_CLAUSE_REDUCTION_INSCAN (c)) 8810 1.1 mrg need_copy_assignment = true; 8811 1.1 mrg need_implicitly_determined = true; 8812 1.1 mrg break; 8813 1.1 mrg case OMP_CLAUSE_IN_REDUCTION: 8814 1.1 mrg case OMP_CLAUSE_TASK_REDUCTION: 8815 1.1 mrg case OMP_CLAUSE_INCLUSIVE: 8816 1.1 mrg case OMP_CLAUSE_EXCLUSIVE: 8817 1.1 mrg need_implicitly_determined = true; 8818 1.1 mrg break; 8819 1.1 mrg case OMP_CLAUSE_LINEAR: 8820 1.1 mrg if (ort != C_ORT_OMP_DECLARE_SIMD) 8821 1.1 mrg need_implicitly_determined = true; 8822 1.1 mrg else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c) 8823 1.1 mrg && !bitmap_bit_p (&map_head, 8824 1.1 mrg DECL_UID (OMP_CLAUSE_LINEAR_STEP (c)))) 8825 1.1 mrg { 8826 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8827 1.1 mrg "%<linear%> clause step is a parameter %qD not " 8828 1.1 mrg "specified in %<uniform%> clause", 8829 1.1 mrg OMP_CLAUSE_LINEAR_STEP (c)); 8830 1.1 mrg *pc = OMP_CLAUSE_CHAIN (c); 8831 1.1 mrg continue; 8832 1.1 mrg } 8833 1.1 mrg break; 8834 1.1 mrg case OMP_CLAUSE_COPYPRIVATE: 8835 1.1 mrg need_copy_assignment = true; 8836 1.1 mrg break; 8837 1.1 mrg case OMP_CLAUSE_COPYIN: 8838 1.1 mrg need_copy_assignment = true; 8839 1.1 mrg break; 8840 1.1 mrg case OMP_CLAUSE_SIMDLEN: 8841 1.1 mrg if (safelen 8842 1.1 mrg && !processing_template_decl 8843 1.1 mrg && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen), 8844 1.1 mrg OMP_CLAUSE_SIMDLEN_EXPR (c))) 8845 1.1 mrg { 8846 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8847 1.1 mrg "%<simdlen%> clause value is bigger than " 8848 1.1 mrg "%<safelen%> clause value"); 8849 1.1 mrg OMP_CLAUSE_SIMDLEN_EXPR (c) 8850 1.1 mrg = OMP_CLAUSE_SAFELEN_EXPR (safelen); 8851 1.1 mrg } 8852 1.1 mrg pc = &OMP_CLAUSE_CHAIN (c); 8853 1.1 mrg continue; 8854 1.1 mrg case OMP_CLAUSE_SCHEDULE: 8855 1.1 mrg if (ordered_seen 8856 1.1 mrg && (OMP_CLAUSE_SCHEDULE_KIND (c) 8857 1.1 mrg & OMP_CLAUSE_SCHEDULE_NONMONOTONIC)) 8858 1.1 mrg { 8859 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8860 1.1 mrg "%<nonmonotonic%> schedule modifier specified " 8861 1.1 mrg "together with %<ordered%> clause"); 8862 1.1 mrg OMP_CLAUSE_SCHEDULE_KIND (c) 8863 1.1 mrg = (enum omp_clause_schedule_kind) 8864 1.1 mrg (OMP_CLAUSE_SCHEDULE_KIND (c) 8865 1.1 mrg & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC); 8866 1.1 mrg } 8867 1.1 mrg if (reduction_seen == -2) 8868 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8869 1.1 mrg "%qs clause specified together with %<inscan%> " 8870 1.1 mrg "%<reduction%> clause", "schedule"); 8871 1.1 mrg pc = &OMP_CLAUSE_CHAIN (c); 8872 1.1 mrg continue; 8873 1.1 mrg case OMP_CLAUSE_NOGROUP: 8874 1.1 mrg if (reduction_seen) 8875 1.1 mrg { 8876 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8877 1.1 mrg "%<nogroup%> clause must not be used together with " 8878 1.1 mrg "%<reduction%> clause"); 8879 1.1 mrg *pc = OMP_CLAUSE_CHAIN (c); 8880 1.1 mrg continue; 8881 1.1 mrg } 8882 1.1 mrg pc = &OMP_CLAUSE_CHAIN (c); 8883 1.1 mrg continue; 8884 1.1 mrg case OMP_CLAUSE_ORDERED: 8885 1.1 mrg if (reduction_seen == -2) 8886 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8887 1.1 mrg "%qs clause specified together with %<inscan%> " 8888 1.1 mrg "%<reduction%> clause", "ordered"); 8889 1.1 mrg pc = &OMP_CLAUSE_CHAIN (c); 8890 1.1 mrg continue; 8891 1.1 mrg case OMP_CLAUSE_ORDER: 8892 1.1 mrg if (ordered_seen) 8893 1.1 mrg { 8894 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8895 1.1 mrg "%<order%> clause must not be used together " 8896 1.1 mrg "with %<ordered%>"); 8897 1.1 mrg *pc = OMP_CLAUSE_CHAIN (c); 8898 1.1 mrg continue; 8899 1.1 mrg } 8900 1.1 mrg pc = &OMP_CLAUSE_CHAIN (c); 8901 1.1 mrg continue; 8902 1.1 mrg case OMP_CLAUSE_DETACH: 8903 1.1 mrg if (mergeable_seen) 8904 1.1 mrg { 8905 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8906 1.1 mrg "%<detach%> clause must not be used together with " 8907 1.1 mrg "%<mergeable%> clause"); 8908 1.1 mrg *pc = OMP_CLAUSE_CHAIN (c); 8909 1.1 mrg continue; 8910 1.1 mrg } 8911 1.1 mrg pc = &OMP_CLAUSE_CHAIN (c); 8912 1.1 mrg continue; 8913 1.1 mrg case OMP_CLAUSE_MAP: 8914 1.1 mrg if (target_in_reduction_seen && !processing_template_decl) 8915 1.1 mrg { 8916 1.1 mrg t = OMP_CLAUSE_DECL (c); 8917 1.1 mrg while (handled_component_p (t) 8918 1.1 mrg || TREE_CODE (t) == INDIRECT_REF 8919 1.1 mrg || TREE_CODE (t) == ADDR_EXPR 8920 1.1 mrg || TREE_CODE (t) == MEM_REF 8921 1.1 mrg || TREE_CODE (t) == NON_LVALUE_EXPR) 8922 1.1 mrg t = TREE_OPERAND (t, 0); 8923 1.1 mrg if (DECL_P (t) 8924 1.1 mrg && bitmap_bit_p (&oacc_reduction_head, DECL_UID (t))) 8925 1.1 mrg OMP_CLAUSE_MAP_IN_REDUCTION (c) = 1; 8926 1.1 mrg } 8927 1.1 mrg pc = &OMP_CLAUSE_CHAIN (c); 8928 1.1 mrg continue; 8929 1.1 mrg case OMP_CLAUSE_NOWAIT: 8930 1.1 mrg if (copyprivate_seen) 8931 1.1 mrg { 8932 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 8933 1.1 mrg "%<nowait%> clause must not be used together " 8934 1.1 mrg "with %<copyprivate%>"); 8935 1.1 mrg *pc = OMP_CLAUSE_CHAIN (c); 8936 1.1 mrg continue; 8937 1.1 mrg } 8938 1.1 mrg /* FALLTHRU */ 8939 1.1 mrg default: 8940 1.1 mrg pc = &OMP_CLAUSE_CHAIN (c); 8941 1.1 mrg continue; 8942 1.1 mrg } 8943 1.1 mrg 8944 1.1 mrg t = OMP_CLAUSE_DECL (c); 8945 1.1 mrg switch (c_kind) 8946 1.1 mrg { 8947 1.1 mrg case OMP_CLAUSE_LASTPRIVATE: 8948 1.1 mrg if (DECL_P (t) 8949 1.1 mrg && !bitmap_bit_p (&firstprivate_head, DECL_UID (t))) 8950 1.1 mrg { 8951 1.1 mrg need_default_ctor = true; 8952 1.1 mrg need_dtor = true; 8953 1.1 mrg } 8954 1.1 mrg break; 8955 1.1 mrg 8956 1.1 mrg case OMP_CLAUSE_REDUCTION: 8957 1.1 mrg case OMP_CLAUSE_IN_REDUCTION: 8958 1.1 mrg case OMP_CLAUSE_TASK_REDUCTION: 8959 1.1 mrg if (allocate_seen) 8960 1.1 mrg { 8961 1.1 mrg if (TREE_CODE (t) == MEM_REF) 8962 1.1 mrg { 8963 1.1 mrg t = TREE_OPERAND (t, 0); 8964 1.1 mrg if (TREE_CODE (t) == POINTER_PLUS_EXPR) 8965 1.1 mrg t = TREE_OPERAND (t, 0); 8966 1.1 mrg if (TREE_CODE (t) == ADDR_EXPR 8967 1.1 mrg || TREE_CODE (t) == INDIRECT_REF) 8968 1.1 mrg t = TREE_OPERAND (t, 0); 8969 1.1 mrg if (DECL_P (t)) 8970 1.1 mrg bitmap_clear_bit (&aligned_head, DECL_UID (t)); 8971 1.1 mrg } 8972 1.1 mrg else if (TREE_CODE (t) == TREE_LIST) 8973 1.1 mrg { 8974 1.1 mrg while (TREE_CODE (t) == TREE_LIST) 8975 1.1 mrg t = TREE_CHAIN (t); 8976 1.1 mrg if (DECL_P (t)) 8977 1.1 mrg bitmap_clear_bit (&aligned_head, DECL_UID (t)); 8978 1.1 mrg t = OMP_CLAUSE_DECL (c); 8979 1.1 mrg } 8980 1.1 mrg else if (DECL_P (t)) 8981 1.1 mrg bitmap_clear_bit (&aligned_head, DECL_UID (t)); 8982 1.1 mrg t = OMP_CLAUSE_DECL (c); 8983 1.1 mrg } 8984 1.1 mrg if (processing_template_decl 8985 1.1 mrg && !VAR_P (t) && TREE_CODE (t) != PARM_DECL) 8986 1.1 mrg break; 8987 1.1 mrg if (finish_omp_reduction_clause (c, &need_default_ctor, 8988 1.1 mrg &need_dtor)) 8989 1.1 mrg remove = true; 8990 1.1 mrg else 8991 1.1 mrg t = OMP_CLAUSE_DECL (c); 8992 1.1 mrg break; 8993 1.1 mrg 8994 1.1 mrg case OMP_CLAUSE_COPYIN: 8995 1.1 mrg if (processing_template_decl 8996 1.1 mrg && !VAR_P (t) && TREE_CODE (t) != PARM_DECL) 8997 1.1 mrg break; 8998 1.1 mrg if (!VAR_P (t) || !CP_DECL_THREAD_LOCAL_P (t)) 8999 1.1 mrg { 9000 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 9001 1.1 mrg "%qE must be %<threadprivate%> for %<copyin%>", t); 9002 1.1 mrg remove = true; 9003 1.1 mrg } 9004 1.1 mrg break; 9005 1.1 mrg 9006 1.1 mrg default: 9007 1.1 mrg break; 9008 1.1 mrg } 9009 1.1 mrg 9010 1.1 mrg if (processing_template_decl 9011 1.1 mrg && !VAR_P (t) && TREE_CODE (t) != PARM_DECL) 9012 1.1 mrg { 9013 1.1 mrg pc = &OMP_CLAUSE_CHAIN (c); 9014 1.1 mrg continue; 9015 1.1 mrg } 9016 1.1 mrg 9017 1.1 mrg if (need_complete_type || need_copy_assignment) 9018 1.1 mrg { 9019 1.1 mrg t = require_complete_type (t); 9020 1.1 mrg if (t == error_mark_node) 9021 1.1 mrg remove = true; 9022 1.1 mrg else if (!processing_template_decl 9023 1.1 mrg && TYPE_REF_P (TREE_TYPE (t)) 9024 1.1 mrg && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t)), t)) 9025 1.1 mrg remove = true; 9026 1.1 mrg } 9027 1.1 mrg if (need_implicitly_determined) 9028 1.1 mrg { 9029 1.1 mrg const char *share_name = NULL; 9030 1.1 mrg 9031 1.1 mrg if (allocate_seen 9032 1.1 mrg && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED 9033 1.1 mrg && DECL_P (t)) 9034 1.1 mrg bitmap_clear_bit (&aligned_head, DECL_UID (t)); 9035 1.1 mrg 9036 1.1 mrg if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t)) 9037 1.1 mrg share_name = "threadprivate"; 9038 1.1 mrg else switch (cxx_omp_predetermined_sharing_1 (t)) 9039 1.1 mrg { 9040 1.1 mrg case OMP_CLAUSE_DEFAULT_UNSPECIFIED: 9041 1.1 mrg break; 9042 1.1 mrg case OMP_CLAUSE_DEFAULT_SHARED: 9043 1.1 mrg if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED 9044 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE) 9045 1.1 mrg && c_omp_predefined_variable (t)) 9046 1.1 mrg /* The __func__ variable and similar function-local predefined 9047 1.1 mrg variables may be listed in a shared or firstprivate 9048 1.1 mrg clause. */ 9049 1.1 mrg break; 9050 1.1 mrg if (VAR_P (t) 9051 1.1 mrg && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE 9052 1.1 mrg && TREE_STATIC (t) 9053 1.1 mrg && cxx_omp_const_qual_no_mutable (t)) 9054 1.1 mrg { 9055 1.1 mrg tree ctx = CP_DECL_CONTEXT (t); 9056 1.1 mrg /* const qualified static data members without mutable 9057 1.1 mrg member may be specified in firstprivate clause. */ 9058 1.1 mrg if (TYPE_P (ctx) && MAYBE_CLASS_TYPE_P (ctx)) 9059 1.1 mrg break; 9060 1.1 mrg } 9061 1.1 mrg share_name = "shared"; 9062 1.1 mrg break; 9063 1.1 mrg case OMP_CLAUSE_DEFAULT_PRIVATE: 9064 1.1 mrg share_name = "private"; 9065 1.1 mrg break; 9066 1.1 mrg default: 9067 1.1 mrg gcc_unreachable (); 9068 1.1 mrg } 9069 1.1 mrg if (share_name) 9070 1.1 mrg { 9071 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 9072 1.1 mrg "%qE is predetermined %qs for %qs", 9073 1.1 mrg omp_clause_printable_decl (t), share_name, 9074 1.1 mrg omp_clause_code_name[OMP_CLAUSE_CODE (c)]); 9075 1.1 mrg remove = true; 9076 1.1 mrg } 9077 1.1 mrg else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED 9078 1.1 mrg && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE 9079 1.1 mrg && cxx_omp_const_qual_no_mutable (t)) 9080 1.1 mrg { 9081 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 9082 1.1 mrg "%<const%> qualified %qE without %<mutable%> member " 9083 1.1 mrg "may appear only in %<shared%> or %<firstprivate%> " 9084 1.1 mrg "clauses", omp_clause_printable_decl (t)); 9085 1.1 mrg remove = true; 9086 1.1 mrg } 9087 1.1 mrg } 9088 1.1 mrg 9089 1.1 mrg if (detach_seen 9090 1.1 mrg && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED 9091 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE 9092 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE 9093 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE) 9094 1.1 mrg && OMP_CLAUSE_DECL (c) == OMP_CLAUSE_DECL (detach_seen)) 9095 1.1 mrg { 9096 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 9097 1.1 mrg "the event handle of a %<detach%> clause " 9098 1.1 mrg "should not be in a data-sharing clause"); 9099 1.1 mrg remove = true; 9100 1.1 mrg } 9101 1.1 mrg 9102 1.1 mrg /* We're interested in the base element, not arrays. */ 9103 1.1 mrg inner_type = type = TREE_TYPE (t); 9104 1.1 mrg if ((need_complete_type 9105 1.1 mrg || need_copy_assignment 9106 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION 9107 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION 9108 1.1 mrg || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION) 9109 1.1 mrg && TYPE_REF_P (inner_type)) 9110 1.1 mrg inner_type = TREE_TYPE (inner_type); 9111 1.1 mrg while (TREE_CODE (inner_type) == ARRAY_TYPE) 9112 1.1 mrg inner_type = TREE_TYPE (inner_type); 9113 1.1 mrg 9114 1.1 mrg /* Check for special function availability by building a call to one. 9115 1.1 mrg Save the results, because later we won't be in the right context 9116 1.1 mrg for making these queries. */ 9117 1.1 mrg if (CLASS_TYPE_P (inner_type) 9118 1.1 mrg && COMPLETE_TYPE_P (inner_type) 9119 1.1 mrg && (need_default_ctor || need_copy_ctor 9120 1.1 mrg || need_copy_assignment || need_dtor) 9121 1.1 mrg && !type_dependent_expression_p (t) 9122 1.1 mrg && cxx_omp_create_clause_info (c, inner_type, need_default_ctor, 9123 1.1 mrg need_copy_ctor, need_copy_assignment, 9124 1.1 mrg need_dtor)) 9125 1.1 mrg remove = true; 9126 1.1 mrg 9127 1.1 mrg if (!remove 9128 1.1 mrg && c_kind == OMP_CLAUSE_SHARED 9129 1.1 mrg && processing_template_decl) 9130 1.1 mrg { 9131 1.1 mrg t = omp_clause_decl_field (OMP_CLAUSE_DECL (c)); 9132 1.1 mrg if (t) 9133 1.1 mrg OMP_CLAUSE_DECL (c) = t; 9134 1.1 mrg } 9135 1.1 mrg 9136 1.1 mrg if (remove) 9137 1.1 mrg *pc = OMP_CLAUSE_CHAIN (c); 9138 1.1 mrg else 9139 1.1 mrg pc = &OMP_CLAUSE_CHAIN (c); 9140 1.1 mrg } 9141 1.1 mrg 9142 1.1 mrg if (allocate_seen) 9143 1.1 mrg for (pc = &clauses, c = clauses; c ; c = *pc) 9144 1.1 mrg { 9145 1.1 mrg bool remove = false; 9146 1.1 mrg if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ALLOCATE 9147 1.1 mrg && !OMP_CLAUSE_ALLOCATE_COMBINED (c) 9148 1.1 mrg && DECL_P (OMP_CLAUSE_DECL (c)) 9149 1.1 mrg && bitmap_bit_p (&aligned_head, DECL_UID (OMP_CLAUSE_DECL (c)))) 9150 1.1 mrg { 9151 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 9152 1.1 mrg "%qD specified in %<allocate%> clause but not in " 9153 1.1 mrg "an explicit privatization clause", OMP_CLAUSE_DECL (c)); 9154 1.1 mrg remove = true; 9155 1.1 mrg } 9156 1.1 mrg if (remove) 9157 1.1 mrg *pc = OMP_CLAUSE_CHAIN (c); 9158 1.1 mrg else 9159 1.1 mrg pc = &OMP_CLAUSE_CHAIN (c); 9160 1.1 mrg } 9161 1.1 mrg 9162 1.1 mrg bitmap_obstack_release (NULL); 9163 1.1 mrg return clauses; 9164 1.1 mrg } 9165 1.1 mrg 9166 1.1 mrg /* Start processing OpenMP clauses that can include any 9167 1.1 mrg privatization clauses for non-static data members. */ 9168 1.1 mrg 9169 1.1 mrg tree 9170 1.1 mrg push_omp_privatization_clauses (bool ignore_next) 9171 1.1 mrg { 9172 1.1 mrg if (omp_private_member_ignore_next) 9173 1.1 mrg { 9174 1.1 mrg omp_private_member_ignore_next = ignore_next; 9175 1.1 mrg return NULL_TREE; 9176 1.1 mrg } 9177 1.1 mrg omp_private_member_ignore_next = ignore_next; 9178 1.1 mrg if (omp_private_member_map) 9179 1.1 mrg omp_private_member_vec.safe_push (error_mark_node); 9180 1.1 mrg return push_stmt_list (); 9181 1.1 mrg } 9182 1.1 mrg 9183 1.1 mrg /* Revert remapping of any non-static data members since 9184 1.1 mrg the last push_omp_privatization_clauses () call. */ 9185 1.1 mrg 9186 1.1 mrg void 9187 1.1 mrg pop_omp_privatization_clauses (tree stmt) 9188 1.1 mrg { 9189 1.1 mrg if (stmt == NULL_TREE) 9190 1.1 mrg return; 9191 1.1 mrg stmt = pop_stmt_list (stmt); 9192 1.1 mrg if (omp_private_member_map) 9193 1.1 mrg { 9194 1.1 mrg while (!omp_private_member_vec.is_empty ()) 9195 1.1 mrg { 9196 1.1 mrg tree t = omp_private_member_vec.pop (); 9197 1.1 mrg if (t == error_mark_node) 9198 1.1 mrg { 9199 1.1 mrg add_stmt (stmt); 9200 1.1 mrg return; 9201 1.1 mrg } 9202 1.1 mrg bool no_decl_expr = t == integer_zero_node; 9203 1.1 mrg if (no_decl_expr) 9204 1.1 mrg t = omp_private_member_vec.pop (); 9205 1.1 mrg tree *v = omp_private_member_map->get (t); 9206 1.1 mrg gcc_assert (v); 9207 1.1 mrg if (!no_decl_expr) 9208 1.1 mrg add_decl_expr (*v); 9209 1.1 mrg omp_private_member_map->remove (t); 9210 1.1 mrg } 9211 1.1 mrg delete omp_private_member_map; 9212 1.1 mrg omp_private_member_map = NULL; 9213 1.1 mrg } 9214 1.1 mrg add_stmt (stmt); 9215 1.1 mrg } 9216 1.1 mrg 9217 1.1 mrg /* Remember OpenMP privatization clauses mapping and clear it. 9218 1.1 mrg Used for lambdas. */ 9219 1.1 mrg 9220 1.1 mrg void 9221 1.1 mrg save_omp_privatization_clauses (vec<tree> &save) 9222 1.1 mrg { 9223 1.1 mrg save = vNULL; 9224 1.1 mrg if (omp_private_member_ignore_next) 9225 1.1 mrg save.safe_push (integer_one_node); 9226 1.1 mrg omp_private_member_ignore_next = false; 9227 1.1 mrg if (!omp_private_member_map) 9228 1.1 mrg return; 9229 1.1 mrg 9230 1.1 mrg while (!omp_private_member_vec.is_empty ()) 9231 1.1 mrg { 9232 1.1 mrg tree t = omp_private_member_vec.pop (); 9233 1.1 mrg if (t == error_mark_node) 9234 1.1 mrg { 9235 1.1 mrg save.safe_push (t); 9236 1.1 mrg continue; 9237 1.1 mrg } 9238 1.1 mrg tree n = t; 9239 1.1 mrg if (t == integer_zero_node) 9240 1.1 mrg t = omp_private_member_vec.pop (); 9241 1.1 mrg tree *v = omp_private_member_map->get (t); 9242 1.1 mrg gcc_assert (v); 9243 1.1 mrg save.safe_push (*v); 9244 1.1 mrg save.safe_push (t); 9245 1.1 mrg if (n != t) 9246 1.1 mrg save.safe_push (n); 9247 1.1 mrg } 9248 1.1 mrg delete omp_private_member_map; 9249 1.1 mrg omp_private_member_map = NULL; 9250 1.1 mrg } 9251 1.1 mrg 9252 1.1 mrg /* Restore OpenMP privatization clauses mapping saved by the 9253 1.1 mrg above function. */ 9254 1.1 mrg 9255 1.1 mrg void 9256 1.1 mrg restore_omp_privatization_clauses (vec<tree> &save) 9257 1.1 mrg { 9258 1.1 mrg gcc_assert (omp_private_member_vec.is_empty ()); 9259 1.1 mrg omp_private_member_ignore_next = false; 9260 1.1 mrg if (save.is_empty ()) 9261 1.1 mrg return; 9262 1.1 mrg if (save.length () == 1 && save[0] == integer_one_node) 9263 1.1 mrg { 9264 1.1 mrg omp_private_member_ignore_next = true; 9265 1.1 mrg save.release (); 9266 1.1 mrg return; 9267 1.1 mrg } 9268 1.1 mrg 9269 1.1 mrg omp_private_member_map = new hash_map <tree, tree>; 9270 1.1 mrg while (!save.is_empty ()) 9271 1.1 mrg { 9272 1.1 mrg tree t = save.pop (); 9273 1.1 mrg tree n = t; 9274 1.1 mrg if (t != error_mark_node) 9275 1.1 mrg { 9276 1.1 mrg if (t == integer_one_node) 9277 1.1 mrg { 9278 1.1 mrg omp_private_member_ignore_next = true; 9279 1.1 mrg gcc_assert (save.is_empty ()); 9280 1.1 mrg break; 9281 1.1 mrg } 9282 1.1 mrg if (t == integer_zero_node) 9283 1.1 mrg t = save.pop (); 9284 1.1 mrg tree &v = omp_private_member_map->get_or_insert (t); 9285 1.1 mrg v = save.pop (); 9286 1.1 mrg } 9287 1.1 mrg omp_private_member_vec.safe_push (t); 9288 1.1 mrg if (n != t) 9289 1.1 mrg omp_private_member_vec.safe_push (n); 9290 1.1 mrg } 9291 1.1 mrg save.release (); 9292 1.1 mrg } 9293 1.1 mrg 9294 1.1 mrg /* For all variables in the tree_list VARS, mark them as thread local. */ 9295 1.1 mrg 9296 1.1 mrg void 9297 1.1 mrg finish_omp_threadprivate (tree vars) 9298 1.1 mrg { 9299 1.1 mrg tree t; 9300 1.1 mrg 9301 1.1 mrg /* Mark every variable in VARS to be assigned thread local storage. */ 9302 1.1 mrg for (t = vars; t; t = TREE_CHAIN (t)) 9303 1.1 mrg { 9304 1.1 mrg tree v = TREE_PURPOSE (t); 9305 1.1 mrg 9306 1.1 mrg if (error_operand_p (v)) 9307 1.1 mrg ; 9308 1.1 mrg else if (!VAR_P (v)) 9309 1.1 mrg error ("%<threadprivate%> %qD is not file, namespace " 9310 1.1 mrg "or block scope variable", v); 9311 1.1 mrg /* If V had already been marked threadprivate, it doesn't matter 9312 1.1 mrg whether it had been used prior to this point. */ 9313 1.1 mrg else if (TREE_USED (v) 9314 1.1 mrg && (DECL_LANG_SPECIFIC (v) == NULL 9315 1.1 mrg || !CP_DECL_THREADPRIVATE_P (v))) 9316 1.1 mrg error ("%qE declared %<threadprivate%> after first use", v); 9317 1.1 mrg else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v)) 9318 1.1 mrg error ("automatic variable %qE cannot be %<threadprivate%>", v); 9319 1.1 mrg else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v)))) 9320 1.1 mrg error ("%<threadprivate%> %qE has incomplete type", v); 9321 1.1 mrg else if (TREE_STATIC (v) && TYPE_P (CP_DECL_CONTEXT (v)) 9322 1.1 mrg && CP_DECL_CONTEXT (v) != current_class_type) 9323 1.1 mrg error ("%<threadprivate%> %qE directive not " 9324 1.1 mrg "in %qT definition", v, CP_DECL_CONTEXT (v)); 9325 1.1 mrg else 9326 1.1 mrg { 9327 1.1 mrg /* Allocate a LANG_SPECIFIC structure for V, if needed. */ 9328 1.1 mrg if (DECL_LANG_SPECIFIC (v) == NULL) 9329 1.1 mrg retrofit_lang_decl (v); 9330 1.1 mrg 9331 1.1 mrg if (! CP_DECL_THREAD_LOCAL_P (v)) 9332 1.1 mrg { 9333 1.1 mrg CP_DECL_THREAD_LOCAL_P (v) = true; 9334 1.1 mrg set_decl_tls_model (v, decl_default_tls_model (v)); 9335 1.1 mrg /* If rtl has been already set for this var, call 9336 1.1 mrg make_decl_rtl once again, so that encode_section_info 9337 1.1 mrg has a chance to look at the new decl flags. */ 9338 1.1 mrg if (DECL_RTL_SET_P (v)) 9339 1.1 mrg make_decl_rtl (v); 9340 1.1 mrg } 9341 1.1 mrg CP_DECL_THREADPRIVATE_P (v) = 1; 9342 1.1 mrg } 9343 1.1 mrg } 9344 1.1 mrg } 9345 1.1 mrg 9346 1.1 mrg /* Build an OpenMP structured block. */ 9347 1.1 mrg 9348 1.1 mrg tree 9349 1.1 mrg begin_omp_structured_block (void) 9350 1.1 mrg { 9351 1.1 mrg return do_pushlevel (sk_omp); 9352 1.1 mrg } 9353 1.1 mrg 9354 1.1 mrg tree 9355 1.1 mrg finish_omp_structured_block (tree block) 9356 1.1 mrg { 9357 1.1 mrg return do_poplevel (block); 9358 1.1 mrg } 9359 1.1 mrg 9360 1.1 mrg /* Similarly, except force the retention of the BLOCK. */ 9361 1.1 mrg 9362 1.1 mrg tree 9363 1.1 mrg begin_omp_parallel (void) 9364 1.1 mrg { 9365 1.1 mrg keep_next_level (true); 9366 1.1 mrg return begin_omp_structured_block (); 9367 1.1 mrg } 9368 1.1 mrg 9369 1.1 mrg /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound 9370 1.1 mrg statement. */ 9371 1.1 mrg 9372 1.1 mrg tree 9373 1.1 mrg finish_oacc_data (tree clauses, tree block) 9374 1.1 mrg { 9375 1.1 mrg tree stmt; 9376 1.1 mrg 9377 1.1 mrg block = finish_omp_structured_block (block); 9378 1.1 mrg 9379 1.1 mrg stmt = make_node (OACC_DATA); 9380 1.1 mrg TREE_TYPE (stmt) = void_type_node; 9381 1.1 mrg OACC_DATA_CLAUSES (stmt) = clauses; 9382 1.1 mrg OACC_DATA_BODY (stmt) = block; 9383 1.1 mrg 9384 1.1 mrg return add_stmt (stmt); 9385 1.1 mrg } 9386 1.1 mrg 9387 1.1 mrg /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound 9388 1.1 mrg statement. */ 9389 1.1 mrg 9390 1.1 mrg tree 9391 1.1 mrg finish_oacc_host_data (tree clauses, tree block) 9392 1.1 mrg { 9393 1.1 mrg tree stmt; 9394 1.1 mrg 9395 1.1 mrg block = finish_omp_structured_block (block); 9396 1.1 mrg 9397 1.1 mrg stmt = make_node (OACC_HOST_DATA); 9398 1.1 mrg TREE_TYPE (stmt) = void_type_node; 9399 1.1 mrg OACC_HOST_DATA_CLAUSES (stmt) = clauses; 9400 1.1 mrg OACC_HOST_DATA_BODY (stmt) = block; 9401 1.1 mrg 9402 1.1 mrg return add_stmt (stmt); 9403 1.1 mrg } 9404 1.1 mrg 9405 1.1 mrg /* Generate OMP construct CODE, with BODY and CLAUSES as its compound 9406 1.1 mrg statement. */ 9407 1.1 mrg 9408 1.1 mrg tree 9409 1.1 mrg finish_omp_construct (enum tree_code code, tree body, tree clauses) 9410 1.1 mrg { 9411 1.1 mrg body = finish_omp_structured_block (body); 9412 1.1 mrg 9413 1.1 mrg tree stmt = make_node (code); 9414 1.1 mrg TREE_TYPE (stmt) = void_type_node; 9415 1.1 mrg OMP_BODY (stmt) = body; 9416 1.1 mrg OMP_CLAUSES (stmt) = clauses; 9417 1.1 mrg 9418 1.1 mrg return add_stmt (stmt); 9419 1.1 mrg } 9420 1.1 mrg 9421 1.1 mrg /* Used to walk OpenMP target directive body. */ 9422 1.1 mrg 9423 1.1 mrg struct omp_target_walk_data 9424 1.1 mrg { 9425 1.1 mrg /* Holds the 'this' expression found in current function. */ 9426 1.1 mrg tree current_object; 9427 1.1 mrg 9428 1.1 mrg /* True if the 'this' expression was accessed in the target body. */ 9429 1.1 mrg bool this_expr_accessed; 9430 1.1 mrg 9431 1.1 mrg /* For non-static functions, record which pointer-typed members were 9432 1.1 mrg accessed, and the whole expression. */ 9433 1.1 mrg hash_map<tree, tree> ptr_members_accessed; 9434 1.1 mrg 9435 1.1 mrg /* Record which lambda objects were accessed in target body. */ 9436 1.1 mrg hash_set<tree> lambda_objects_accessed; 9437 1.1 mrg 9438 1.1 mrg /* For lambda functions, the __closure object expression of the current 9439 1.1 mrg function, and the set of captured variables accessed in target body. */ 9440 1.1 mrg tree current_closure; 9441 1.1 mrg hash_set<tree> closure_vars_accessed; 9442 1.1 mrg 9443 1.1 mrg /* Local variables declared inside a BIND_EXPR, used to filter out such 9444 1.1 mrg variables when recording lambda_objects_accessed. */ 9445 1.1 mrg hash_set<tree> local_decls; 9446 1.1 mrg }; 9447 1.1 mrg 9448 1.1 mrg /* Helper function of finish_omp_target_clauses, called via 9449 1.1 mrg cp_walk_tree_without_duplicates. Traverse body of OpenMP target 9450 1.1 mrg directive *TP, and fill out omp_target_walk_data passed in *PTR. */ 9451 1.1 mrg 9452 1.1 mrg static tree 9453 1.1 mrg finish_omp_target_clauses_r (tree *tp, int *walk_subtrees, void *ptr) 9454 1.1 mrg { 9455 1.1 mrg tree t = *tp; 9456 1.1 mrg struct omp_target_walk_data *data = (struct omp_target_walk_data *) ptr; 9457 1.1 mrg tree current_object = data->current_object; 9458 1.1 mrg tree current_closure = data->current_closure; 9459 1.1 mrg 9460 1.1 mrg /* References inside of these expression codes shouldn't incur any 9461 1.1 mrg form of mapping, so return early. */ 9462 1.1 mrg if (TREE_CODE (t) == SIZEOF_EXPR 9463 1.1 mrg || TREE_CODE (t) == ALIGNOF_EXPR) 9464 1.1 mrg { 9465 1.1 mrg *walk_subtrees = 0; 9466 1.1 mrg return NULL_TREE; 9467 1.1 mrg } 9468 1.1 mrg 9469 1.1 mrg if (TREE_CODE (t) == OMP_CLAUSE) 9470 1.1 mrg return NULL_TREE; 9471 1.1 mrg 9472 1.1 mrg if (current_object) 9473 1.1 mrg { 9474 1.1 mrg tree this_expr = TREE_OPERAND (current_object, 0); 9475 1.1 mrg 9476 1.1 mrg if (operand_equal_p (t, this_expr)) 9477 1.1 mrg { 9478 1.1 mrg data->this_expr_accessed = true; 9479 1.1 mrg *walk_subtrees = 0; 9480 1.1 mrg return NULL_TREE; 9481 1.1 mrg } 9482 1.1 mrg 9483 1.1 mrg if (TREE_CODE (t) == COMPONENT_REF 9484 1.1 mrg && POINTER_TYPE_P (TREE_TYPE (t)) 9485 1.1 mrg && operand_equal_p (TREE_OPERAND (t, 0), current_object) 9486 1.1 mrg && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL) 9487 1.1 mrg { 9488 1.1 mrg data->this_expr_accessed = true; 9489 1.1 mrg tree fld = TREE_OPERAND (t, 1); 9490 1.1 mrg if (data->ptr_members_accessed.get (fld) == NULL) 9491 1.1 mrg { 9492 1.1 mrg if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE) 9493 1.1 mrg t = convert_from_reference (t); 9494 1.1 mrg data->ptr_members_accessed.put (fld, t); 9495 1.1 mrg } 9496 1.1 mrg *walk_subtrees = 0; 9497 1.1 mrg return NULL_TREE; 9498 1.1 mrg } 9499 1.1 mrg } 9500 1.1 mrg 9501 1.1 mrg /* When the current_function_decl is a lambda function, the closure object 9502 1.1 mrg argument's type seems to not yet have fields layed out, so a recording 9503 1.1 mrg of DECL_VALUE_EXPRs during the target body walk seems the only way to 9504 1.1 mrg find them. */ 9505 1.1 mrg if (current_closure 9506 1.1 mrg && (TREE_CODE (t) == VAR_DECL 9507 1.1 mrg || TREE_CODE (t) == PARM_DECL 9508 1.1 mrg || TREE_CODE (t) == RESULT_DECL) 9509 1.1 mrg && DECL_HAS_VALUE_EXPR_P (t) 9510 1.1 mrg && TREE_CODE (DECL_VALUE_EXPR (t)) == COMPONENT_REF 9511 1.1 mrg && operand_equal_p (current_closure, 9512 1.1 mrg TREE_OPERAND (DECL_VALUE_EXPR (t), 0))) 9513 1.1 mrg { 9514 1.1 mrg if (!data->closure_vars_accessed.contains (t)) 9515 1.1 mrg data->closure_vars_accessed.add (t); 9516 1.1 mrg *walk_subtrees = 0; 9517 1.1 mrg return NULL_TREE; 9518 1.1 mrg } 9519 1.1 mrg 9520 1.1 mrg if (TREE_CODE (t) == BIND_EXPR) 9521 1.1 mrg { 9522 1.1 mrg tree block = BIND_EXPR_BLOCK (t); 9523 1.1 mrg for (tree var = BLOCK_VARS (block); var; var = DECL_CHAIN (var)) 9524 1.1 mrg if (!data->local_decls.contains (var)) 9525 1.1 mrg data->local_decls.add (var); 9526 1.1 mrg return NULL_TREE; 9527 1.1 mrg } 9528 1.1 mrg 9529 1.1 mrg if (TREE_TYPE (t) && LAMBDA_TYPE_P (TREE_TYPE (t))) 9530 1.1 mrg { 9531 1.1 mrg tree lt = TREE_TYPE (t); 9532 1.1 mrg gcc_assert (CLASS_TYPE_P (lt)); 9533 1.1 mrg 9534 1.1 mrg if (!data->lambda_objects_accessed.contains (t) 9535 1.1 mrg /* Do not prepare to create target maps for locally declared 9536 1.1 mrg lambdas or anonymous ones. */ 9537 1.1 mrg && !data->local_decls.contains (t) 9538 1.1 mrg && TREE_CODE (t) != TARGET_EXPR) 9539 1.1 mrg data->lambda_objects_accessed.add (t); 9540 1.1 mrg *walk_subtrees = 0; 9541 1.1 mrg return NULL_TREE; 9542 1.1 mrg } 9543 1.1 mrg 9544 1.1 mrg return NULL_TREE; 9545 1.1 mrg } 9546 1.1 mrg 9547 1.1 mrg /* Helper function for finish_omp_target, and also from tsubst_expr. 9548 1.1 mrg Create additional clauses for mapping of non-static members, lambda objects, 9549 1.1 mrg etc. */ 9550 1.1 mrg 9551 1.1 mrg void 9552 1.1 mrg finish_omp_target_clauses (location_t loc, tree body, tree *clauses_ptr) 9553 1.1 mrg { 9554 1.1 mrg omp_target_walk_data data; 9555 1.1 mrg data.this_expr_accessed = false; 9556 1.1 mrg data.current_object = NULL_TREE; 9557 1.1 mrg 9558 1.1 mrg if (DECL_NONSTATIC_MEMBER_P (current_function_decl) && current_class_ptr) 9559 1.1 mrg if (tree ct = current_nonlambda_class_type ()) 9560 1.1 mrg { 9561 1.1 mrg tree object = maybe_dummy_object (ct, NULL); 9562 1.1 mrg object = maybe_resolve_dummy (object, true); 9563 1.1 mrg data.current_object = object; 9564 1.1 mrg } 9565 1.1 mrg 9566 1.1 mrg if (DECL_LAMBDA_FUNCTION_P (current_function_decl)) 9567 1.1 mrg { 9568 1.1 mrg tree closure = DECL_ARGUMENTS (current_function_decl); 9569 1.1 mrg data.current_closure = build_indirect_ref (loc, closure, RO_UNARY_STAR); 9570 1.1 mrg } 9571 1.1 mrg else 9572 1.1 mrg data.current_closure = NULL_TREE; 9573 1.1 mrg 9574 1.1 mrg cp_walk_tree_without_duplicates (&body, finish_omp_target_clauses_r, &data); 9575 1.1 mrg 9576 1.1 mrg auto_vec<tree, 16> new_clauses; 9577 1.1 mrg 9578 1.1 mrg tree omp_target_this_expr = NULL_TREE; 9579 1.1 mrg tree *explicit_this_deref_map = NULL; 9580 1.1 mrg if (data.this_expr_accessed) 9581 1.1 mrg { 9582 1.1 mrg omp_target_this_expr = TREE_OPERAND (data.current_object, 0); 9583 1.1 mrg 9584 1.1 mrg /* See if explicit user-specified map(this[:]) clause already exists. 9585 1.1 mrg If not, we create an implicit map(tofrom:this[:1]) clause. */ 9586 1.1 mrg for (tree *cp = clauses_ptr; *cp; cp = &OMP_CLAUSE_CHAIN (*cp)) 9587 1.1 mrg if (OMP_CLAUSE_CODE (*cp) == OMP_CLAUSE_MAP 9588 1.1 mrg && (TREE_CODE (OMP_CLAUSE_DECL (*cp)) == INDIRECT_REF 9589 1.1 mrg || TREE_CODE (OMP_CLAUSE_DECL (*cp)) == MEM_REF) 9590 1.1 mrg && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*cp), 0), 9591 1.1 mrg omp_target_this_expr)) 9592 1.1 mrg { 9593 1.1 mrg explicit_this_deref_map = cp; 9594 1.1 mrg break; 9595 1.1 mrg } 9596 1.1 mrg } 9597 1.1 mrg 9598 1.1 mrg if (DECL_LAMBDA_FUNCTION_P (current_function_decl) 9599 1.1 mrg && (data.this_expr_accessed 9600 1.1 mrg || !data.closure_vars_accessed.is_empty ())) 9601 1.1 mrg { 9602 1.1 mrg /* For lambda functions, we need to first create a copy of the 9603 1.1 mrg __closure object. */ 9604 1.1 mrg tree closure = DECL_ARGUMENTS (current_function_decl); 9605 1.1 mrg tree c = build_omp_clause (loc, OMP_CLAUSE_MAP); 9606 1.1 mrg OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TO); 9607 1.1 mrg OMP_CLAUSE_DECL (c) 9608 1.1 mrg = build_indirect_ref (loc, closure, RO_UNARY_STAR); 9609 1.1 mrg OMP_CLAUSE_SIZE (c) 9610 1.1 mrg = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure))); 9611 1.1 mrg new_clauses.safe_push (c); 9612 1.1 mrg 9613 1.1 mrg tree closure_obj = OMP_CLAUSE_DECL (c); 9614 1.1 mrg tree closure_type = TREE_TYPE (closure_obj); 9615 1.1 mrg 9616 1.1 mrg gcc_assert (LAMBDA_TYPE_P (closure_type) 9617 1.1 mrg && CLASS_TYPE_P (closure_type)); 9618 1.1 mrg 9619 1.1 mrg tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP); 9620 1.1 mrg OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_FIRSTPRIVATE_POINTER); 9621 1.1 mrg OMP_CLAUSE_DECL (c2) = closure; 9622 1.1 mrg OMP_CLAUSE_SIZE (c2) = size_zero_node; 9623 1.1 mrg new_clauses.safe_push (c2); 9624 1.1 mrg } 9625 1.1 mrg 9626 1.1 mrg if (data.this_expr_accessed) 9627 1.1 mrg { 9628 1.1 mrg /* If the this-expr was accessed, create a map(*this) clause. */ 9629 1.1 mrg enum gomp_map_kind kind = GOMP_MAP_TOFROM; 9630 1.1 mrg if (explicit_this_deref_map) 9631 1.1 mrg { 9632 1.1 mrg tree this_map = *explicit_this_deref_map; 9633 1.1 mrg tree nc = OMP_CLAUSE_CHAIN (this_map); 9634 1.1 mrg gcc_assert (nc != NULL_TREE 9635 1.1 mrg && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP 9636 1.1 mrg && (OMP_CLAUSE_MAP_KIND (nc) 9637 1.1 mrg == GOMP_MAP_FIRSTPRIVATE_POINTER)); 9638 1.1 mrg kind = OMP_CLAUSE_MAP_KIND (this_map); 9639 1.1 mrg /* Remove the original 'map(*this) map(firstprivate_ptr:this)' 9640 1.1 mrg two-map sequence away from the chain. */ 9641 1.1 mrg *explicit_this_deref_map = OMP_CLAUSE_CHAIN (nc); 9642 1.1 mrg } 9643 1.1 mrg tree c = build_omp_clause (loc, OMP_CLAUSE_MAP); 9644 1.1 mrg OMP_CLAUSE_SET_MAP_KIND (c, kind); 9645 1.1 mrg OMP_CLAUSE_DECL (c) 9646 1.1 mrg = build_indirect_ref (loc, omp_target_this_expr, RO_UNARY_STAR); 9647 1.1 mrg OMP_CLAUSE_SIZE (c) 9648 1.1 mrg = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (omp_target_this_expr))); 9649 1.1 mrg new_clauses.safe_push (c); 9650 1.1 mrg 9651 1.1 mrg /* If we're in a lambda function, the this-pointer will actually be 9652 1.1 mrg '__closure->this', a mapped member of __closure, hence always_pointer. 9653 1.1 mrg Otherwise it's a firstprivate pointer. */ 9654 1.1 mrg enum gomp_map_kind ptr_kind 9655 1.1 mrg = (DECL_LAMBDA_FUNCTION_P (current_function_decl) 9656 1.1 mrg ? GOMP_MAP_ALWAYS_POINTER 9657 1.1 mrg : GOMP_MAP_FIRSTPRIVATE_POINTER); 9658 1.1 mrg c = build_omp_clause (loc, OMP_CLAUSE_MAP); 9659 1.1 mrg OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind); 9660 1.1 mrg OMP_CLAUSE_DECL (c) = omp_target_this_expr; 9661 1.1 mrg OMP_CLAUSE_SIZE (c) = size_zero_node; 9662 1.1 mrg new_clauses.safe_push (c); 9663 1.1 mrg } 9664 1.1 mrg 9665 1.1 mrg if (DECL_LAMBDA_FUNCTION_P (current_function_decl)) 9666 1.1 mrg { 9667 1.1 mrg if (omp_target_this_expr) 9668 1.1 mrg { 9669 1.1 mrg STRIP_NOPS (omp_target_this_expr); 9670 1.1 mrg gcc_assert (DECL_HAS_VALUE_EXPR_P (omp_target_this_expr)); 9671 1.1 mrg omp_target_this_expr = DECL_VALUE_EXPR (omp_target_this_expr); 9672 1.1 mrg } 9673 1.1 mrg 9674 1.1 mrg for (hash_set<tree>::iterator i = data.closure_vars_accessed.begin (); 9675 1.1 mrg i != data.closure_vars_accessed.end (); ++i) 9676 1.1 mrg { 9677 1.1 mrg tree orig_decl = *i; 9678 1.1 mrg tree closure_expr = DECL_VALUE_EXPR (orig_decl); 9679 1.1 mrg 9680 1.1 mrg if (TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE 9681 1.1 mrg || TREE_CODE (TREE_TYPE (orig_decl)) == REFERENCE_TYPE) 9682 1.1 mrg { 9683 1.1 mrg /* this-pointer is processed above, outside this loop. */ 9684 1.1 mrg if (omp_target_this_expr 9685 1.1 mrg && operand_equal_p (closure_expr, omp_target_this_expr)) 9686 1.1 mrg continue; 9687 1.1 mrg 9688 1.1 mrg bool ptr_p = TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE; 9689 1.1 mrg enum gomp_map_kind kind, ptr_kind, nc_kind; 9690 1.1 mrg tree size; 9691 1.1 mrg 9692 1.1 mrg if (ptr_p) 9693 1.1 mrg { 9694 1.1 mrg /* For pointers, default mapped as zero-length array 9695 1.1 mrg section. */ 9696 1.1 mrg kind = GOMP_MAP_ALLOC; 9697 1.1 mrg nc_kind = GOMP_MAP_FIRSTPRIVATE_POINTER; 9698 1.1 mrg ptr_kind = GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION; 9699 1.1 mrg size = size_zero_node; 9700 1.1 mrg } 9701 1.1 mrg else 9702 1.1 mrg { 9703 1.1 mrg /* For references, default mapped as appearing on map 9704 1.1 mrg clause. */ 9705 1.1 mrg kind = GOMP_MAP_TOFROM; 9706 1.1 mrg nc_kind = GOMP_MAP_FIRSTPRIVATE_REFERENCE; 9707 1.1 mrg ptr_kind = GOMP_MAP_ALWAYS_POINTER; 9708 1.1 mrg size = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure_expr))); 9709 1.1 mrg } 9710 1.1 mrg 9711 1.1 mrg for (tree *p = clauses_ptr; *p; p = &OMP_CLAUSE_CHAIN (*p)) 9712 1.1 mrg if (OMP_CLAUSE_CODE (*p) == OMP_CLAUSE_MAP 9713 1.1 mrg && (TREE_CODE (OMP_CLAUSE_DECL (*p)) == INDIRECT_REF 9714 1.1 mrg || TREE_CODE (OMP_CLAUSE_DECL (*p)) == MEM_REF) 9715 1.1 mrg && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*p), 0), 9716 1.1 mrg orig_decl)) 9717 1.1 mrg { 9718 1.1 mrg /* If this was already specified by user as a map, 9719 1.1 mrg save the user specified map kind, delete the 9720 1.1 mrg "map(*ptr/ref), map(firstprivate ptr/ref)" sequence, 9721 1.1 mrg and insert our own sequence: 9722 1.1 mrg "map(*__closure->ptr/ref), map(<ptr_kind>:__closure->ref" 9723 1.1 mrg */ 9724 1.1 mrg tree nc = OMP_CLAUSE_CHAIN (*p); 9725 1.1 mrg gcc_assert (nc != NULL_TREE 9726 1.1 mrg && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP 9727 1.1 mrg && OMP_CLAUSE_MAP_KIND (nc) == nc_kind); 9728 1.1 mrg /* Update with user specified kind and size. */ 9729 1.1 mrg kind = OMP_CLAUSE_MAP_KIND (*p); 9730 1.1 mrg size = OMP_CLAUSE_SIZE (*p); 9731 1.1 mrg *p = OMP_CLAUSE_CHAIN (nc); 9732 1.1 mrg break; 9733 1.1 mrg } 9734 1.1 mrg 9735 1.1 mrg tree c = build_omp_clause (loc, OMP_CLAUSE_MAP); 9736 1.1 mrg OMP_CLAUSE_SET_MAP_KIND (c, kind); 9737 1.1 mrg OMP_CLAUSE_DECL (c) 9738 1.1 mrg = build_indirect_ref (loc, closure_expr, RO_UNARY_STAR); 9739 1.1 mrg OMP_CLAUSE_SIZE (c) = size; 9740 1.1 mrg if (ptr_p) 9741 1.1 mrg OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1; 9742 1.1 mrg new_clauses.safe_push (c); 9743 1.1 mrg 9744 1.1 mrg c = build_omp_clause (loc, OMP_CLAUSE_MAP); 9745 1.1 mrg OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind); 9746 1.1 mrg OMP_CLAUSE_DECL (c) = closure_expr; 9747 1.1 mrg OMP_CLAUSE_SIZE (c) = size_zero_node; 9748 1.1 mrg new_clauses.safe_push (c); 9749 1.1 mrg } 9750 1.1 mrg } 9751 1.1 mrg } 9752 1.1 mrg 9753 1.1 mrg if (!data.ptr_members_accessed.is_empty ()) 9754 1.1 mrg for (hash_map<tree, tree>::iterator i = data.ptr_members_accessed.begin (); 9755 1.1 mrg i != data.ptr_members_accessed.end (); ++i) 9756 1.1 mrg { 9757 1.1 mrg /* For each referenced member that is of pointer or reference-to-pointer 9758 1.1 mrg type, create the equivalent of map(alloc:this->ptr[:0]). */ 9759 1.1 mrg tree field_decl = (*i).first; 9760 1.1 mrg tree ptr_member = (*i).second; 9761 1.1 mrg 9762 1.1 mrg for (tree c = *clauses_ptr; c; c = OMP_CLAUSE_CHAIN (c)) 9763 1.1 mrg { 9764 1.1 mrg if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP) 9765 1.1 mrg continue; 9766 1.1 mrg /* If map(this->ptr[:N]) already exists, avoid creating another 9767 1.1 mrg such map. */ 9768 1.1 mrg tree decl = OMP_CLAUSE_DECL (c); 9769 1.1 mrg if ((TREE_CODE (decl) == INDIRECT_REF 9770 1.1 mrg || TREE_CODE (decl) == MEM_REF) 9771 1.1 mrg && operand_equal_p (TREE_OPERAND (decl, 0), ptr_member)) 9772 1.1 mrg goto next_ptr_member; 9773 1.1 mrg } 9774 1.1 mrg 9775 1.1 mrg if (!cxx_mark_addressable (ptr_member)) 9776 1.1 mrg gcc_unreachable (); 9777 1.1 mrg 9778 1.1 mrg if (TREE_CODE (TREE_TYPE (field_decl)) == REFERENCE_TYPE) 9779 1.1 mrg { 9780 1.1 mrg /* For reference to pointers, we need to map the referenced 9781 1.1 mrg pointer first for things to be correct. */ 9782 1.1 mrg tree ptr_member_type = TREE_TYPE (ptr_member); 9783 1.1 mrg 9784 1.1 mrg /* Map pointer target as zero-length array section. */ 9785 1.1 mrg tree c = build_omp_clause (loc, OMP_CLAUSE_MAP); 9786 1.1 mrg OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC); 9787 1.1 mrg OMP_CLAUSE_DECL (c) 9788 1.1 mrg = build1 (INDIRECT_REF, TREE_TYPE (ptr_member_type), ptr_member); 9789 1.1 mrg OMP_CLAUSE_SIZE (c) = size_zero_node; 9790 1.1 mrg OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1; 9791 1.1 mrg 9792 1.1 mrg /* Map pointer to zero-length array section. */ 9793 1.1 mrg tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP); 9794 1.1 mrg OMP_CLAUSE_SET_MAP_KIND 9795 1.1 mrg (c2, GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION); 9796 1.1 mrg OMP_CLAUSE_DECL (c2) = ptr_member; 9797 1.1 mrg OMP_CLAUSE_SIZE (c2) = size_zero_node; 9798 1.1 mrg 9799 1.1 mrg /* Attach reference-to-pointer field to pointer. */ 9800 1.1 mrg tree c3 = build_omp_clause (loc, OMP_CLAUSE_MAP); 9801 1.1 mrg OMP_CLAUSE_SET_MAP_KIND (c3, GOMP_MAP_ATTACH); 9802 1.1 mrg OMP_CLAUSE_DECL (c3) = TREE_OPERAND (ptr_member, 0); 9803 1.1 mrg OMP_CLAUSE_SIZE (c3) = size_zero_node; 9804 1.1 mrg 9805 1.1 mrg new_clauses.safe_push (c); 9806 1.1 mrg new_clauses.safe_push (c2); 9807 1.1 mrg new_clauses.safe_push (c3); 9808 1.1 mrg } 9809 1.1 mrg else if (TREE_CODE (TREE_TYPE (field_decl)) == POINTER_TYPE) 9810 1.1 mrg { 9811 1.1 mrg /* Map pointer target as zero-length array section. */ 9812 1.1 mrg tree c = build_omp_clause (loc, OMP_CLAUSE_MAP); 9813 1.1 mrg OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC); 9814 1.1 mrg OMP_CLAUSE_DECL (c) = build_indirect_ref (loc, ptr_member, 9815 1.1 mrg RO_UNARY_STAR); 9816 1.1 mrg OMP_CLAUSE_SIZE (c) = size_zero_node; 9817 1.1 mrg OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1; 9818 1.1 mrg 9819 1.1 mrg /* Attach zero-length array section to pointer. */ 9820 1.1 mrg tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP); 9821 1.1 mrg OMP_CLAUSE_SET_MAP_KIND 9822 1.1 mrg (c2, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION); 9823 1.1 mrg OMP_CLAUSE_DECL (c2) = ptr_member; 9824 1.1 mrg OMP_CLAUSE_SIZE (c2) = size_zero_node; 9825 1.1 mrg 9826 1.1 mrg new_clauses.safe_push (c); 9827 1.1 mrg new_clauses.safe_push (c2); 9828 1.1 mrg } 9829 1.1 mrg else 9830 1.1 mrg gcc_unreachable (); 9831 1.1 mrg 9832 1.1 mrg next_ptr_member: 9833 1.1 mrg ; 9834 1.1 mrg } 9835 1.1 mrg 9836 1.1 mrg for (hash_set<tree>::iterator i = data.lambda_objects_accessed.begin (); 9837 1.1 mrg i != data.lambda_objects_accessed.end (); ++i) 9838 1.1 mrg { 9839 1.1 mrg tree lobj = *i; 9840 1.1 mrg if (TREE_CODE (lobj) == TARGET_EXPR) 9841 1.1 mrg lobj = TREE_OPERAND (lobj, 0); 9842 1.1 mrg 9843 1.1 mrg tree lt = TREE_TYPE (lobj); 9844 1.1 mrg gcc_assert (LAMBDA_TYPE_P (lt) && CLASS_TYPE_P (lt)); 9845 1.1 mrg 9846 1.1 mrg tree lc = build_omp_clause (loc, OMP_CLAUSE_MAP); 9847 1.1 mrg OMP_CLAUSE_SET_MAP_KIND (lc, GOMP_MAP_TO); 9848 1.1 mrg OMP_CLAUSE_DECL (lc) = lobj; 9849 1.1 mrg OMP_CLAUSE_SIZE (lc) = TYPE_SIZE_UNIT (lt); 9850 1.1 mrg new_clauses.safe_push (lc); 9851 1.1 mrg 9852 1.1 mrg for (tree fld = TYPE_FIELDS (lt); fld; fld = DECL_CHAIN (fld)) 9853 1.1 mrg { 9854 1.1 mrg if (TREE_CODE (TREE_TYPE (fld)) == POINTER_TYPE) 9855 1.1 mrg { 9856 1.1 mrg tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld), 9857 1.1 mrg lobj, fld, NULL_TREE); 9858 1.1 mrg tree c = build_omp_clause (loc, OMP_CLAUSE_MAP); 9859 1.1 mrg OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC); 9860 1.1 mrg OMP_CLAUSE_DECL (c) 9861 1.1 mrg = build_indirect_ref (loc, exp, RO_UNARY_STAR); 9862 1.1 mrg OMP_CLAUSE_SIZE (c) = size_zero_node; 9863 1.1 mrg OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1; 9864 1.1 mrg new_clauses.safe_push (c); 9865 1.1 mrg 9866 1.1 mrg c = build_omp_clause (loc, OMP_CLAUSE_MAP); 9867 1.1 mrg OMP_CLAUSE_SET_MAP_KIND 9868 1.1 mrg (c, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION); 9869 1.1 mrg OMP_CLAUSE_DECL (c) = exp; 9870 1.1 mrg OMP_CLAUSE_SIZE (c) = size_zero_node; 9871 1.1 mrg new_clauses.safe_push (c); 9872 1.1 mrg } 9873 1.1 mrg else if (TREE_CODE (TREE_TYPE (fld)) == REFERENCE_TYPE) 9874 1.1 mrg { 9875 1.1 mrg tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld), 9876 1.1 mrg lobj, fld, NULL_TREE); 9877 1.1 mrg tree c = build_omp_clause (loc, OMP_CLAUSE_MAP); 9878 1.1 mrg OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TOFROM); 9879 1.1 mrg OMP_CLAUSE_DECL (c) 9880 1.1 mrg = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (exp)), exp); 9881 1.1 mrg OMP_CLAUSE_SIZE (c) 9882 1.1 mrg = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (exp))); 9883 1.1 mrg new_clauses.safe_push (c); 9884 1.1 mrg 9885 1.1 mrg c = build_omp_clause (loc, OMP_CLAUSE_MAP); 9886 1.1 mrg OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALWAYS_POINTER); 9887 1.1 mrg OMP_CLAUSE_DECL (c) = exp; 9888 1.1 mrg OMP_CLAUSE_SIZE (c) = size_zero_node; 9889 1.1 mrg new_clauses.safe_push (c); 9890 1.1 mrg } 9891 1.1 mrg } 9892 1.1 mrg } 9893 1.1 mrg 9894 1.1 mrg tree c = *clauses_ptr; 9895 1.1 mrg for (int i = new_clauses.length () - 1; i >= 0; i--) 9896 1.1 mrg { 9897 1.1 mrg OMP_CLAUSE_CHAIN (new_clauses[i]) = c; 9898 1.1 mrg c = new_clauses[i]; 9899 1.1 mrg } 9900 1.1 mrg *clauses_ptr = c; 9901 1.1 mrg } 9902 1.1 mrg 9903 1.1 mrg /* Called from cp_parser_omp_target. Create additional implicit clauses for 9904 1.1 mrg OpenMP target directives, and do sanity checks. */ 9905 1.1 mrg 9906 1.1 mrg tree 9907 1.1 mrg finish_omp_target (location_t loc, tree clauses, tree body, bool combined_p) 9908 1.1 mrg { 9909 1.1 mrg if (!processing_template_decl) 9910 1.1 mrg finish_omp_target_clauses (loc, body, &clauses); 9911 1.1 mrg 9912 1.1 mrg tree stmt = make_node (OMP_TARGET); 9913 1.1 mrg TREE_TYPE (stmt) = void_type_node; 9914 1.1 mrg OMP_TARGET_CLAUSES (stmt) = clauses; 9915 1.1 mrg OMP_TARGET_BODY (stmt) = body; 9916 1.1 mrg OMP_TARGET_COMBINED (stmt) = combined_p; 9917 1.1 mrg SET_EXPR_LOCATION (stmt, loc); 9918 1.1 mrg 9919 1.1 mrg tree c = clauses; 9920 1.1 mrg while (c) 9921 1.1 mrg { 9922 1.1 mrg if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP) 9923 1.1 mrg switch (OMP_CLAUSE_MAP_KIND (c)) 9924 1.1 mrg { 9925 1.1 mrg case GOMP_MAP_TO: 9926 1.1 mrg case GOMP_MAP_ALWAYS_TO: 9927 1.1 mrg case GOMP_MAP_FROM: 9928 1.1 mrg case GOMP_MAP_ALWAYS_FROM: 9929 1.1 mrg case GOMP_MAP_TOFROM: 9930 1.1 mrg case GOMP_MAP_ALWAYS_TOFROM: 9931 1.1 mrg case GOMP_MAP_ALLOC: 9932 1.1 mrg case GOMP_MAP_FIRSTPRIVATE_POINTER: 9933 1.1 mrg case GOMP_MAP_FIRSTPRIVATE_REFERENCE: 9934 1.1 mrg case GOMP_MAP_ALWAYS_POINTER: 9935 1.1 mrg case GOMP_MAP_ATTACH_DETACH: 9936 1.1 mrg case GOMP_MAP_ATTACH: 9937 1.1 mrg case GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION: 9938 1.1 mrg case GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION: 9939 1.1 mrg break; 9940 1.1 mrg default: 9941 1.1 mrg error_at (OMP_CLAUSE_LOCATION (c), 9942 1.1 mrg "%<#pragma omp target%> with map-type other " 9943 1.1 mrg "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> " 9944 1.1 mrg "on %<map%> clause"); 9945 1.1 mrg break; 9946 1.1 mrg } 9947 1.1 mrg c = OMP_CLAUSE_CHAIN (c); 9948 1.1 mrg } 9949 1.1 mrg return add_stmt (stmt); 9950 1.1 mrg } 9951 1.1 mrg 9952 1.1 mrg tree 9953 1.1 mrg finish_omp_parallel (tree clauses, tree body) 9954 1.1 mrg { 9955 1.1 mrg tree stmt; 9956 1.1 mrg 9957 1.1 mrg body = finish_omp_structured_block (body); 9958 1.1 mrg 9959 1.1 mrg stmt = make_node (OMP_PARALLEL); 9960 1.1 mrg TREE_TYPE (stmt) = void_type_node; 9961 1.1 mrg OMP_PARALLEL_CLAUSES (stmt) = clauses; 9962 1.1 mrg OMP_PARALLEL_BODY (stmt) = body; 9963 1.1 mrg 9964 1.1 mrg return add_stmt (stmt); 9965 1.1 mrg } 9966 1.1 mrg 9967 1.1 mrg tree 9968 1.1 mrg begin_omp_task (void) 9969 1.1 mrg { 9970 1.1 mrg keep_next_level (true); 9971 1.1 mrg return begin_omp_structured_block (); 9972 1.1 mrg } 9973 1.1 mrg 9974 1.1 mrg tree 9975 1.1 mrg finish_omp_task (tree clauses, tree body) 9976 1.1 mrg { 9977 1.1 mrg tree stmt; 9978 1.1 mrg 9979 1.1 mrg body = finish_omp_structured_block (body); 9980 1.1 mrg 9981 1.1 mrg stmt = make_node (OMP_TASK); 9982 1.1 mrg TREE_TYPE (stmt) = void_type_node; 9983 1.1 mrg OMP_TASK_CLAUSES (stmt) = clauses; 9984 1.1 mrg OMP_TASK_BODY (stmt) = body; 9985 1.1 mrg 9986 1.1 mrg return add_stmt (stmt); 9987 1.1 mrg } 9988 1.1 mrg 9989 1.1 mrg /* Helper function for finish_omp_for. Convert Ith random access iterator 9990 1.1 mrg into integral iterator. Return FALSE if successful. */ 9991 1.1 mrg 9992 1.1 mrg static bool 9993 1.1 mrg handle_omp_for_class_iterator (int i, location_t locus, enum tree_code code, 9994 1.1 mrg tree declv, tree orig_declv, tree initv, 9995 1.1 mrg tree condv, tree incrv, tree *body, 9996 1.1 mrg tree *pre_body, tree &clauses, 9997 1.1 mrg int collapse, int ordered) 9998 1.1 mrg { 9999 1.1 mrg tree diff, iter_init, iter_incr = NULL, last; 10000 1.1 mrg tree incr_var = NULL, orig_pre_body, orig_body, c; 10001 1.1 mrg tree decl = TREE_VEC_ELT (declv, i); 10002 1.1 mrg tree init = TREE_VEC_ELT (initv, i); 10003 1.1 mrg tree cond = TREE_VEC_ELT (condv, i); 10004 1.1 mrg tree incr = TREE_VEC_ELT (incrv, i); 10005 1.1 mrg tree iter = decl; 10006 1.1 mrg location_t elocus = locus; 10007 1.1 mrg 10008 1.1 mrg if (init && EXPR_HAS_LOCATION (init)) 10009 1.1 mrg elocus = EXPR_LOCATION (init); 10010 1.1 mrg 10011 1.1 mrg switch (TREE_CODE (cond)) 10012 1.1 mrg { 10013 1.1 mrg case GT_EXPR: 10014 1.1 mrg case GE_EXPR: 10015 1.1 mrg case LT_EXPR: 10016 1.1 mrg case LE_EXPR: 10017 1.1 mrg case NE_EXPR: 10018 1.1 mrg if (TREE_OPERAND (cond, 1) == iter) 10019 1.1 mrg cond = build2 (swap_tree_comparison (TREE_CODE (cond)), 10020 1.1 mrg TREE_TYPE (cond), iter, TREE_OPERAND (cond, 0)); 10021 1.1 mrg if (TREE_OPERAND (cond, 0) != iter) 10022 1.1 mrg cond = error_mark_node; 10023 1.1 mrg else 10024 1.1 mrg { 10025 1.1 mrg tree tem = build_x_binary_op (EXPR_LOCATION (cond), 10026 1.1 mrg TREE_CODE (cond), 10027 1.1 mrg iter, ERROR_MARK, 10028 1.1 mrg TREE_OPERAND (cond, 1), ERROR_MARK, 10029 1.1 mrg NULL_TREE, NULL, tf_warning_or_error); 10030 1.1 mrg if (error_operand_p (tem)) 10031 1.1 mrg return true; 10032 1.1 mrg } 10033 1.1 mrg break; 10034 1.1 mrg default: 10035 1.1 mrg cond = error_mark_node; 10036 1.1 mrg break; 10037 1.1 mrg } 10038 1.1 mrg if (cond == error_mark_node) 10039 1.1 mrg { 10040 1.1 mrg error_at (elocus, "invalid controlling predicate"); 10041 1.1 mrg return true; 10042 1.1 mrg } 10043 1.1 mrg diff = build_x_binary_op (elocus, MINUS_EXPR, 10044 1.1 mrg TREE_OPERAND (cond, 1), ERROR_MARK, 10045 1.1 mrg iter, ERROR_MARK, 10046 1.1 mrg NULL_TREE, NULL, tf_warning_or_error); 10047 1.1 mrg diff = cp_fully_fold (diff); 10048 1.1 mrg if (error_operand_p (diff)) 10049 1.1 mrg return true; 10050 1.1 mrg if (TREE_CODE (TREE_TYPE (diff)) != INTEGER_TYPE) 10051 1.1 mrg { 10052 1.1 mrg error_at (elocus, "difference between %qE and %qD does not have integer type", 10053 1.1 mrg TREE_OPERAND (cond, 1), iter); 10054 1.1 mrg return true; 10055 1.1 mrg } 10056 1.1 mrg if (!c_omp_check_loop_iv_exprs (locus, code, orig_declv, i, 10057 1.1 mrg TREE_VEC_ELT (declv, i), NULL_TREE, 10058 1.1 mrg cond, cp_walk_subtrees)) 10059 1.1 mrg return true; 10060 1.1 mrg 10061 1.1 mrg switch (TREE_CODE (incr)) 10062 1.1 mrg { 10063 1.1 mrg case PREINCREMENT_EXPR: 10064 1.1 mrg case PREDECREMENT_EXPR: 10065 1.1 mrg case POSTINCREMENT_EXPR: 10066 1.1 mrg case POSTDECREMENT_EXPR: 10067 1.1 mrg if (TREE_OPERAND (incr, 0) != iter) 10068 1.1 mrg { 10069 1.1 mrg incr = error_mark_node; 10070 1.1 mrg break; 10071 1.1 mrg } 10072 1.1 mrg iter_incr = build_x_unary_op (EXPR_LOCATION (incr), 10073 1.1 mrg TREE_CODE (incr), iter, 10074 1.1 mrg NULL_TREE, tf_warning_or_error); 10075 1.1 mrg if (error_operand_p (iter_incr)) 10076 1.1 mrg return true; 10077 1.1 mrg else if (TREE_CODE (incr) == PREINCREMENT_EXPR 10078 1.1 mrg || TREE_CODE (incr) == POSTINCREMENT_EXPR) 10079 1.1 mrg incr = integer_one_node; 10080 1.1 mrg else 10081 1.1 mrg incr = integer_minus_one_node; 10082 1.1 mrg break; 10083 1.1 mrg case MODIFY_EXPR: 10084 1.1 mrg if (TREE_OPERAND (incr, 0) != iter) 10085 1.1 mrg incr = error_mark_node; 10086 1.1 mrg else if (TREE_CODE (TREE_OPERAND (incr, 1)) == PLUS_EXPR 10087 1.1 mrg || TREE_CODE (TREE_OPERAND (incr, 1)) == MINUS_EXPR) 10088 1.1 mrg { 10089 1.1 mrg tree rhs = TREE_OPERAND (incr, 1); 10090 1.1 mrg if (TREE_OPERAND (rhs, 0) == iter) 10091 1.1 mrg { 10092 1.1 mrg if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 1))) 10093 1.1 mrg != INTEGER_TYPE) 10094 1.1 mrg incr = error_mark_node; 10095 1.1 mrg else 10096 1.1 mrg { 10097 1.1 mrg iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs), 10098 1.1 mrg iter, TREE_CODE (rhs), 10099 1.1 mrg TREE_OPERAND (rhs, 1), 10100 1.1 mrg NULL_TREE, 10101 1.1 mrg tf_warning_or_error); 10102 1.1 mrg if (error_operand_p (iter_incr)) 10103 1.1 mrg return true; 10104 1.1 mrg incr = TREE_OPERAND (rhs, 1); 10105 1.1 mrg incr = cp_convert (TREE_TYPE (diff), incr, 10106 1.1 mrg tf_warning_or_error); 10107 1.1 mrg if (TREE_CODE (rhs) == MINUS_EXPR) 10108 1.1 mrg { 10109 1.1 mrg incr = build1 (NEGATE_EXPR, TREE_TYPE (diff), incr); 10110 1.1 mrg incr = fold_simple (incr); 10111 1.1 mrg } 10112 1.1 mrg if (TREE_CODE (incr) != INTEGER_CST 10113 1.1 mrg && (TREE_CODE (incr) != NOP_EXPR 10114 1.1 mrg || (TREE_CODE (TREE_OPERAND (incr, 0)) 10115 1.1 mrg != INTEGER_CST))) 10116 1.1 mrg iter_incr = NULL; 10117 1.1 mrg } 10118 1.1 mrg } 10119 1.1 mrg else if (TREE_OPERAND (rhs, 1) == iter) 10120 1.1 mrg { 10121 1.1 mrg if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 0))) != INTEGER_TYPE 10122 1.1 mrg || TREE_CODE (rhs) != PLUS_EXPR) 10123 1.1 mrg incr = error_mark_node; 10124 1.1 mrg else 10125 1.1 mrg { 10126 1.1 mrg iter_incr = build_x_binary_op (EXPR_LOCATION (rhs), 10127 1.1 mrg PLUS_EXPR, 10128 1.1 mrg TREE_OPERAND (rhs, 0), 10129 1.1 mrg ERROR_MARK, iter, 10130 1.1 mrg ERROR_MARK, NULL_TREE, NULL, 10131 1.1 mrg tf_warning_or_error); 10132 1.1 mrg if (error_operand_p (iter_incr)) 10133 1.1 mrg return true; 10134 1.1 mrg iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs), 10135 1.1 mrg iter, NOP_EXPR, 10136 1.1 mrg iter_incr, NULL_TREE, 10137 1.1 mrg tf_warning_or_error); 10138 1.1 mrg if (error_operand_p (iter_incr)) 10139 1.1 mrg return true; 10140 1.1 mrg incr = TREE_OPERAND (rhs, 0); 10141 1.1 mrg iter_incr = NULL; 10142 1.1 mrg } 10143 1.1 mrg } 10144 1.1 mrg else 10145 1.1 mrg incr = error_mark_node; 10146 1.1 mrg } 10147 1.1 mrg else 10148 1.1 mrg incr = error_mark_node; 10149 1.1 mrg break; 10150 1.1 mrg default: 10151 1.1 mrg incr = error_mark_node; 10152 1.1 mrg break; 10153 1.1 mrg } 10154 1.1 mrg 10155 1.1 mrg if (incr == error_mark_node) 10156 1.1 mrg { 10157 1.1 mrg error_at (elocus, "invalid increment expression"); 10158 1.1 mrg return true; 10159 1.1 mrg } 10160 1.1 mrg 10161 1.1 mrg incr = cp_convert (TREE_TYPE (diff), incr, tf_warning_or_error); 10162 1.1 mrg incr = cp_fully_fold (incr); 10163 1.1 mrg tree loop_iv_seen = NULL_TREE; 10164 1.1 mrg for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c)) 10165 1.1 mrg if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE 10166 1.1 mrg && OMP_CLAUSE_DECL (c) == iter) 10167 1.1 mrg { 10168 1.1 mrg if (code == OMP_TASKLOOP || code == OMP_LOOP) 10169 1.1 mrg { 10170 1.1 mrg loop_iv_seen = c; 10171 1.1 mrg OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c) = 1; 10172 1.1 mrg } 10173 1.1 mrg break; 10174 1.1 mrg } 10175 1.1 mrg else if ((code == OMP_TASKLOOP || code == OMP_LOOP) 10176 1.1 mrg && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE 10177 1.1 mrg && OMP_CLAUSE_DECL (c) == iter) 10178 1.1 mrg { 10179 1.1 mrg loop_iv_seen = c; 10180 1.1 mrg if (code == OMP_TASKLOOP) 10181 1.1 mrg OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c) = 1; 10182 1.1 mrg } 10183 1.1 mrg 10184 1.1 mrg decl = create_temporary_var (TREE_TYPE (diff)); 10185 1.1 mrg pushdecl (decl); 10186 1.1 mrg add_decl_expr (decl); 10187 1.1 mrg last = create_temporary_var (TREE_TYPE (diff)); 10188 1.1 mrg pushdecl (last); 10189 1.1 mrg add_decl_expr (last); 10190 1.1 mrg if (c && iter_incr == NULL && TREE_CODE (incr) != INTEGER_CST 10191 1.1 mrg && (!ordered || (i < collapse && collapse > 1))) 10192 1.1 mrg { 10193 1.1 mrg incr_var = create_temporary_var (TREE_TYPE (diff)); 10194 1.1 mrg pushdecl (incr_var); 10195 1.1 mrg add_decl_expr (incr_var); 10196 1.1 mrg } 10197 1.1 mrg gcc_assert (stmts_are_full_exprs_p ()); 10198 1.1 mrg tree diffvar = NULL_TREE; 10199 1.1 mrg if (code == OMP_TASKLOOP) 10200 1.1 mrg { 10201 1.1 mrg if (!loop_iv_seen) 10202 1.1 mrg { 10203 1.1 mrg tree ivc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE); 10204 1.1 mrg OMP_CLAUSE_DECL (ivc) = iter; 10205 1.1 mrg cxx_omp_finish_clause (ivc, NULL, false); 10206 1.1 mrg OMP_CLAUSE_CHAIN (ivc) = clauses; 10207 1.1 mrg clauses = ivc; 10208 1.1 mrg } 10209 1.1 mrg tree lvc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE); 10210 1.1 mrg OMP_CLAUSE_DECL (lvc) = last; 10211 1.1 mrg OMP_CLAUSE_CHAIN (lvc) = clauses; 10212 1.1 mrg clauses = lvc; 10213 1.1 mrg diffvar = create_temporary_var (TREE_TYPE (diff)); 10214 1.1 mrg pushdecl (diffvar); 10215 1.1 mrg add_decl_expr (diffvar); 10216 1.1 mrg } 10217 1.1 mrg else if (code == OMP_LOOP) 10218 1.1 mrg { 10219 1.1 mrg if (!loop_iv_seen) 10220 1.1 mrg { 10221 1.1 mrg /* While iterators on the loop construct are predetermined 10222 1.1 mrg lastprivate, if the decl is not declared inside of the 10223 1.1 mrg loop, OMP_CLAUSE_LASTPRIVATE should have been added 10224 1.1 mrg already. */ 10225 1.1 mrg loop_iv_seen = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE); 10226 1.1 mrg OMP_CLAUSE_DECL (loop_iv_seen) = iter; 10227 1.1 mrg OMP_CLAUSE_CHAIN (loop_iv_seen) = clauses; 10228 1.1 mrg clauses = loop_iv_seen; 10229 1.1 mrg } 10230 1.1 mrg else if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_PRIVATE) 10231 1.1 mrg { 10232 1.1 mrg OMP_CLAUSE_PRIVATE_DEBUG (loop_iv_seen) = 0; 10233 1.1 mrg OMP_CLAUSE_PRIVATE_OUTER_REF (loop_iv_seen) = 0; 10234 1.1 mrg OMP_CLAUSE_CODE (loop_iv_seen) = OMP_CLAUSE_FIRSTPRIVATE; 10235 1.1 mrg } 10236 1.1 mrg if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_FIRSTPRIVATE) 10237 1.1 mrg cxx_omp_finish_clause (loop_iv_seen, NULL, false); 10238 1.1 mrg } 10239 1.1 mrg 10240 1.1 mrg orig_pre_body = *pre_body; 10241 1.1 mrg *pre_body = push_stmt_list (); 10242 1.1 mrg if (orig_pre_body) 10243 1.1 mrg add_stmt (orig_pre_body); 10244 1.1 mrg if (init != NULL) 10245 1.1 mrg finish_expr_stmt (build_x_modify_expr (elocus, 10246 1.1 mrg iter, NOP_EXPR, init, 10247 1.1 mrg NULL_TREE, tf_warning_or_error)); 10248 1.1 mrg init = build_int_cst (TREE_TYPE (diff), 0); 10249 1.1 mrg if (c && iter_incr == NULL 10250 1.1 mrg && (!ordered || (i < collapse && collapse > 1))) 10251 1.1 mrg { 10252 1.1 mrg if (incr_var) 10253 1.1 mrg { 10254 1.1 mrg finish_expr_stmt (build_x_modify_expr (elocus, 10255 1.1 mrg incr_var, NOP_EXPR, 10256 1.1 mrg incr, NULL_TREE, 10257 1.1 mrg tf_warning_or_error)); 10258 1.1 mrg incr = incr_var; 10259 1.1 mrg } 10260 1.1 mrg iter_incr = build_x_modify_expr (elocus, 10261 1.1 mrg iter, PLUS_EXPR, incr, 10262 1.1 mrg NULL_TREE, tf_warning_or_error); 10263 1.1 mrg } 10264 1.1 mrg if (c && ordered && i < collapse && collapse > 1) 10265 1.1 mrg iter_incr = incr; 10266 1.1 mrg finish_expr_stmt (build_x_modify_expr (elocus, 10267 1.1 mrg last, NOP_EXPR, init, 10268 1.1 mrg NULL_TREE, tf_warning_or_error)); 10269 1.1 mrg if (diffvar) 10270 1.1 mrg { 10271 1.1 mrg finish_expr_stmt (build_x_modify_expr (elocus, 10272 1.1 mrg diffvar, NOP_EXPR, 10273 1.1 mrg diff, NULL_TREE, tf_warning_or_error)); 10274 1.1 mrg diff = diffvar; 10275 1.1 mrg } 10276 1.1 mrg *pre_body = pop_stmt_list (*pre_body); 10277 1.1 mrg 10278 1.1 mrg cond = cp_build_binary_op (elocus, 10279 1.1 mrg TREE_CODE (cond), decl, diff, 10280 1.1 mrg tf_warning_or_error); 10281 1.1 mrg incr = build_modify_expr (elocus, decl, NULL_TREE, PLUS_EXPR, 10282 1.1 mrg elocus, incr, NULL_TREE); 10283 1.1 mrg 10284 1.1 mrg orig_body = *body; 10285 1.1 mrg *body = push_stmt_list (); 10286 1.1 mrg iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), decl, last); 10287 1.1 mrg iter_init = build_x_modify_expr (elocus, 10288 1.1 mrg iter, PLUS_EXPR, iter_init, 10289 1.1 mrg NULL_TREE, tf_warning_or_error); 10290 1.1 mrg if (iter_init != error_mark_node) 10291 1.1 mrg iter_init = build1 (NOP_EXPR, void_type_node, iter_init); 10292 1.1 mrg finish_expr_stmt (iter_init); 10293 1.1 mrg finish_expr_stmt (build_x_modify_expr (elocus, 10294 1.1 mrg last, NOP_EXPR, decl, 10295 1.1 mrg NULL_TREE, tf_warning_or_error)); 10296 1.1 mrg add_stmt (orig_body); 10297 1.1 mrg *body = pop_stmt_list (*body); 10298 1.1 mrg 10299 1.1 mrg if (c) 10300 1.1 mrg { 10301 1.1 mrg OMP_CLAUSE_LASTPRIVATE_STMT (c) = push_stmt_list (); 10302 1.1 mrg if (!ordered) 10303 1.1 mrg finish_expr_stmt (iter_incr); 10304 1.1 mrg else 10305 1.1 mrg { 10306 1.1 mrg iter_init = decl; 10307 1.1 mrg if (i < collapse && collapse > 1 && !error_operand_p (iter_incr)) 10308 1.1 mrg iter_init = build2 (PLUS_EXPR, TREE_TYPE (diff), 10309 1.1 mrg iter_init, iter_incr); 10310 1.1 mrg iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), iter_init, last); 10311 1.1 mrg iter_init = build_x_modify_expr (elocus, 10312 1.1 mrg iter, PLUS_EXPR, iter_init, 10313 1.1 mrg NULL_TREE, tf_warning_or_error); 10314 1.1 mrg if (iter_init != error_mark_node) 10315 1.1 mrg iter_init = build1 (NOP_EXPR, void_type_node, iter_init); 10316 1.1 mrg finish_expr_stmt (iter_init); 10317 1.1 mrg } 10318 1.1 mrg OMP_CLAUSE_LASTPRIVATE_STMT (c) 10319 1.1 mrg = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c)); 10320 1.1 mrg } 10321 1.1 mrg 10322 1.1 mrg if (TREE_CODE (TREE_VEC_ELT (orig_declv, i)) == TREE_LIST) 10323 1.1 mrg { 10324 1.1 mrg tree t = TREE_VEC_ELT (orig_declv, i); 10325 1.1 mrg gcc_assert (TREE_PURPOSE (t) == NULL_TREE 10326 1.1 mrg && TREE_VALUE (t) == NULL_TREE 10327 1.1 mrg && TREE_CODE (TREE_CHAIN (t)) == TREE_VEC); 10328 1.1 mrg TREE_PURPOSE (t) = TREE_VEC_ELT (declv, i); 10329 1.1 mrg TREE_VALUE (t) = last; 10330 1.1 mrg } 10331 1.1 mrg else 10332 1.1 mrg TREE_VEC_ELT (orig_declv, i) 10333 1.1 mrg = tree_cons (TREE_VEC_ELT (declv, i), last, NULL_TREE); 10334 1.1 mrg TREE_VEC_ELT (declv, i) = decl; 10335 1.1 mrg TREE_VEC_ELT (initv, i) = init; 10336 1.1 mrg TREE_VEC_ELT (condv, i) = cond; 10337 1.1 mrg TREE_VEC_ELT (incrv, i) = incr; 10338 1.1 mrg 10339 1.1 mrg return false; 10340 1.1 mrg } 10341 1.1 mrg 10342 1.1 mrg /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR 10343 1.1 mrg are directly for their associated operands in the statement. DECL 10344 1.1 mrg and INIT are a combo; if DECL is NULL then INIT ought to be a 10345 1.1 mrg MODIFY_EXPR, and the DECL should be extracted. PRE_BODY are 10346 1.1 mrg optional statements that need to go before the loop into its 10347 1.1 mrg sk_omp scope. */ 10348 1.1 mrg 10349 1.1 mrg tree 10350 1.1 mrg finish_omp_for (location_t locus, enum tree_code code, tree declv, 10351 1.1 mrg tree orig_declv, tree initv, tree condv, tree incrv, 10352 1.1 mrg tree body, tree pre_body, vec<tree> *orig_inits, tree clauses) 10353 1.1 mrg { 10354 1.1 mrg tree omp_for = NULL, orig_incr = NULL; 10355 1.1 mrg tree decl = NULL, init, cond, incr; 10356 1.1 mrg location_t elocus; 10357 1.1 mrg int i; 10358 1.1 mrg int collapse = 1; 10359 1.1 mrg int ordered = 0; 10360 1.1 mrg 10361 1.1 mrg gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (initv)); 10362 1.1 mrg gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (condv)); 10363 1.1 mrg gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (incrv)); 10364 1.1 mrg if (TREE_VEC_LENGTH (declv) > 1) 10365 1.1 mrg { 10366 1.1 mrg tree c; 10367 1.1 mrg 10368 1.1 mrg c = omp_find_clause (clauses, OMP_CLAUSE_TILE); 10369 1.1 mrg if (c) 10370 1.1 mrg collapse = list_length (OMP_CLAUSE_TILE_LIST (c)); 10371 1.1 mrg else 10372 1.1 mrg { 10373 1.1 mrg c = omp_find_clause (clauses, OMP_CLAUSE_COLLAPSE); 10374 1.1 mrg if (c) 10375 1.1 mrg collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (c)); 10376 1.1 mrg if (collapse != TREE_VEC_LENGTH (declv)) 10377 1.1 mrg ordered = TREE_VEC_LENGTH (declv); 10378 1.1 mrg } 10379 1.1 mrg } 10380 1.1 mrg for (i = 0; i < TREE_VEC_LENGTH (declv); i++) 10381 1.1 mrg { 10382 1.1 mrg decl = TREE_VEC_ELT (declv, i); 10383 1.1 mrg init = TREE_VEC_ELT (initv, i); 10384 1.1 mrg cond = TREE_VEC_ELT (condv, i); 10385 1.1 mrg incr = TREE_VEC_ELT (incrv, i); 10386 1.1 mrg elocus = locus; 10387 1.1 mrg 10388 1.1 mrg if (decl == NULL) 10389 1.1 mrg { 10390 1.1 mrg if (init != NULL) 10391 1.1 mrg switch (TREE_CODE (init)) 10392 1.1 mrg { 10393 1.1 mrg case MODIFY_EXPR: 10394 1.1 mrg decl = TREE_OPERAND (init, 0); 10395 1.1 mrg init = TREE_OPERAND (init, 1); 10396 1.1 mrg break; 10397 1.1 mrg case MODOP_EXPR: 10398 1.1 mrg if (TREE_CODE (TREE_OPERAND (init, 1)) == NOP_EXPR) 10399 1.1 mrg { 10400 1.1 mrg decl = TREE_OPERAND (init, 0); 10401 1.1 mrg init = TREE_OPERAND (init, 2); 10402 1.1 mrg } 10403 1.1 mrg break; 10404 1.1 mrg default: 10405 1.1 mrg break; 10406 1.1 mrg } 10407 1.1 mrg 10408 1.1 mrg if (decl == NULL) 10409 1.1 mrg { 10410 1.1 mrg error_at (locus, 10411 1.1 mrg "expected iteration declaration or initialization"); 10412 1.1 mrg return NULL; 10413 1.1 mrg } 10414 1.1 mrg } 10415 1.1 mrg 10416 1.1 mrg if (init && EXPR_HAS_LOCATION (init)) 10417 1.1 mrg elocus = EXPR_LOCATION (init); 10418 1.1 mrg 10419 1.1 mrg if (cond == global_namespace) 10420 1.1 mrg continue; 10421 1.1 mrg 10422 1.1 mrg if (cond == NULL) 10423 1.1 mrg { 10424 1.1 mrg error_at (elocus, "missing controlling predicate"); 10425 1.1 mrg return NULL; 10426 1.1 mrg } 10427 1.1 mrg 10428 1.1 mrg if (incr == NULL) 10429 1.1 mrg { 10430 1.1 mrg error_at (elocus, "missing increment expression"); 10431 1.1 mrg return NULL; 10432 1.1 mrg } 10433 1.1 mrg 10434 1.1 mrg TREE_VEC_ELT (declv, i) = decl; 10435 1.1 mrg TREE_VEC_ELT (initv, i) = init; 10436 1.1 mrg } 10437 1.1 mrg 10438 1.1 mrg if (orig_inits) 10439 1.1 mrg { 10440 1.1 mrg bool fail = false; 10441 1.1 mrg tree orig_init; 10442 1.1 mrg FOR_EACH_VEC_ELT (*orig_inits, i, orig_init) 10443 1.1 mrg if (orig_init 10444 1.1 mrg && !c_omp_check_loop_iv_exprs (locus, code, 10445 1.1 mrg orig_declv ? orig_declv : declv, i, 10446 1.1 mrg TREE_VEC_ELT (declv, i), orig_init, 10447 1.1 mrg NULL_TREE, cp_walk_subtrees)) 10448 1.1 mrg fail = true; 10449 1.1 mrg if (fail) 10450 1.1 mrg return NULL; 10451 1.1 mrg } 10452 1.1 mrg 10453 1.1 mrg if (dependent_omp_for_p (declv, initv, condv, incrv)) 10454 1.1 mrg { 10455 1.1 mrg tree stmt; 10456 1.1 mrg 10457 1.1 mrg stmt = make_node (code); 10458 1.1 mrg 10459 1.1 mrg for (i = 0; i < TREE_VEC_LENGTH (declv); i++) 10460 1.1 mrg { 10461 1.1 mrg /* This is really just a place-holder. We'll be decomposing this 10462 1.1 mrg again and going through the cp_build_modify_expr path below when 10463 1.1 mrg we instantiate the thing. */ 10464 1.1 mrg TREE_VEC_ELT (initv, i) 10465 1.1 mrg = build2 (MODIFY_EXPR, void_type_node, TREE_VEC_ELT (declv, i), 10466 1.1 mrg TREE_VEC_ELT (initv, i)); 10467 1.1 mrg } 10468 1.1 mrg 10469 1.1 mrg TREE_TYPE (stmt) = void_type_node; 10470 1.1 mrg OMP_FOR_INIT (stmt) = initv; 10471 1.1 mrg OMP_FOR_COND (stmt) = condv; 10472 1.1 mrg OMP_FOR_INCR (stmt) = incrv; 10473 1.1 mrg OMP_FOR_BODY (stmt) = body; 10474 1.1 mrg OMP_FOR_PRE_BODY (stmt) = pre_body; 10475 1.1 mrg OMP_FOR_CLAUSES (stmt) = clauses; 10476 1.1 mrg 10477 1.1 mrg SET_EXPR_LOCATION (stmt, locus); 10478 1.1 mrg return add_stmt (stmt); 10479 1.1 mrg } 10480 1.1 mrg 10481 1.1 mrg if (!orig_declv) 10482 1.1 mrg orig_declv = copy_node (declv); 10483 1.1 mrg 10484 1.1 mrg if (processing_template_decl) 10485 1.1 mrg orig_incr = make_tree_vec (TREE_VEC_LENGTH (incrv)); 10486 1.1 mrg 10487 1.1 mrg for (i = 0; i < TREE_VEC_LENGTH (declv); ) 10488 1.1 mrg { 10489 1.1 mrg decl = TREE_VEC_ELT (declv, i); 10490 1.1 mrg init = TREE_VEC_ELT (initv, i); 10491 1.1 mrg cond = TREE_VEC_ELT (condv, i); 10492 1.1 mrg incr = TREE_VEC_ELT (incrv, i); 10493 1.1 mrg if (orig_incr) 10494 1.1 mrg TREE_VEC_ELT (orig_incr, i) = incr; 10495 1.1 mrg elocus = locus; 10496 1.1 mrg 10497 1.1 mrg if (init && EXPR_HAS_LOCATION (init)) 10498 1.1 mrg elocus = EXPR_LOCATION (init); 10499 1.1 mrg 10500 1.1 mrg if (!DECL_P (decl)) 10501 1.1 mrg { 10502 1.1 mrg error_at (elocus, "expected iteration declaration or initialization"); 10503 1.1 mrg return NULL; 10504 1.1 mrg } 10505 1.1 mrg 10506 1.1 mrg if (incr && TREE_CODE (incr) == MODOP_EXPR) 10507 1.1 mrg { 10508 1.1 mrg if (orig_incr) 10509 1.1 mrg TREE_VEC_ELT (orig_incr, i) = incr; 10510 1.1 mrg incr = cp_build_modify_expr (elocus, TREE_OPERAND (incr, 0), 10511 1.1 mrg TREE_CODE (TREE_OPERAND (incr, 1)), 10512 1.1 mrg TREE_OPERAND (incr, 2), 10513 1.1 mrg tf_warning_or_error); 10514 1.1 mrg } 10515 1.1 mrg 10516 1.1 mrg if (CLASS_TYPE_P (TREE_TYPE (decl))) 10517 1.1 mrg { 10518 1.1 mrg if (code == OMP_SIMD) 10519 1.1 mrg { 10520 1.1 mrg error_at (elocus, "%<#pragma omp simd%> used with class " 10521 1.1 mrg "iteration variable %qE", decl); 10522 1.1 mrg return NULL; 10523 1.1 mrg } 10524 1.1 mrg if (handle_omp_for_class_iterator (i, locus, code, declv, orig_declv, 10525 1.1 mrg initv, condv, incrv, &body, 10526 1.1 mrg &pre_body, clauses, 10527 1.1 mrg collapse, ordered)) 10528 1.1 mrg return NULL; 10529 1.1 mrg continue; 10530 1.1 mrg } 10531 1.1 mrg 10532 1.1 mrg if (!INTEGRAL_TYPE_P (TREE_TYPE (decl)) 10533 1.1 mrg && !TYPE_PTR_P (TREE_TYPE (decl))) 10534 1.1 mrg { 10535 1.1 mrg error_at (elocus, "invalid type for iteration variable %qE", decl); 10536 1.1 mrg return NULL; 10537 1.1 mrg } 10538 1.1 mrg 10539 1.1 mrg if (!processing_template_decl && TREE_CODE (init) != TREE_VEC) 10540 1.1 mrg init = cp_build_modify_expr (elocus, decl, NOP_EXPR, init, 10541 1.1 mrg tf_warning_or_error); 10542 1.1 mrg else 10543 1.1 mrg init = build2 (MODIFY_EXPR, void_type_node, decl, init); 10544 1.1 mrg if (decl == error_mark_node || init == error_mark_node) 10545 1.1 mrg return NULL; 10546 1.1 mrg 10547 1.1 mrg TREE_VEC_ELT (declv, i) = decl; 10548 1.1 mrg TREE_VEC_ELT (initv, i) = init; 10549 1.1 mrg TREE_VEC_ELT (condv, i) = cond; 10550 1.1 mrg TREE_VEC_ELT (incrv, i) = incr; 10551 1.1 mrg i++; 10552 1.1 mrg } 10553 1.1 mrg 10554 1.1 mrg if (pre_body && IS_EMPTY_STMT (pre_body)) 10555 1.1 mrg pre_body = NULL; 10556 1.1 mrg 10557 1.1 mrg omp_for = c_finish_omp_for (locus, code, declv, orig_declv, initv, condv, 10558 1.1 mrg incrv, body, pre_body, 10559 1.1 mrg !processing_template_decl); 10560 1.1 mrg 10561 1.1 mrg /* Check for iterators appearing in lb, b or incr expressions. */ 10562 1.1 mrg if (omp_for && !c_omp_check_loop_iv (omp_for, orig_declv, cp_walk_subtrees)) 10563 1.1 mrg omp_for = NULL_TREE; 10564 1.1 mrg 10565 1.1 mrg if (omp_for == NULL) 10566 1.1 mrg return NULL; 10567 1.1 mrg 10568 1.1 mrg add_stmt (omp_for); 10569 1.1 mrg 10570 1.1 mrg for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)); i++) 10571 1.1 mrg { 10572 1.1 mrg init = TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i); 10573 1.1 mrg decl = TREE_OPERAND (init, 0); 10574 1.1 mrg cond = TREE_VEC_ELT (OMP_FOR_COND (omp_for), i); 10575 1.1 mrg incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i); 10576 1.1 mrg 10577 1.1 mrg if (!processing_template_decl) 10578 1.1 mrg { 10579 1.1 mrg if (TREE_CODE (TREE_OPERAND (init, 1)) == TREE_VEC) 10580 1.1 mrg { 10581 1.1 mrg tree t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 1); 10582 1.1 mrg TREE_VEC_ELT (TREE_OPERAND (init, 1), 1) 10583 1.1 mrg = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 10584 1.1 mrg t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 2); 10585 1.1 mrg TREE_VEC_ELT (TREE_OPERAND (init, 1), 2) 10586 1.1 mrg = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 10587 1.1 mrg } 10588 1.1 mrg else 10589 1.1 mrg { 10590 1.1 mrg tree t = TREE_OPERAND (init, 1); 10591 1.1 mrg TREE_OPERAND (init, 1) 10592 1.1 mrg = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 10593 1.1 mrg } 10594 1.1 mrg if (TREE_CODE (TREE_OPERAND (cond, 1)) == TREE_VEC) 10595 1.1 mrg { 10596 1.1 mrg tree t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1); 10597 1.1 mrg TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1) 10598 1.1 mrg = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 10599 1.1 mrg t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2); 10600 1.1 mrg TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2) 10601 1.1 mrg = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 10602 1.1 mrg } 10603 1.1 mrg else 10604 1.1 mrg { 10605 1.1 mrg tree t = TREE_OPERAND (cond, 1); 10606 1.1 mrg TREE_OPERAND (cond, 1) 10607 1.1 mrg = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 10608 1.1 mrg } 10609 1.1 mrg } 10610 1.1 mrg 10611 1.1 mrg if (TREE_CODE (incr) != MODIFY_EXPR) 10612 1.1 mrg continue; 10613 1.1 mrg 10614 1.1 mrg if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr, 1)) 10615 1.1 mrg && BINARY_CLASS_P (TREE_OPERAND (incr, 1)) 10616 1.1 mrg && !processing_template_decl) 10617 1.1 mrg { 10618 1.1 mrg tree t = TREE_OPERAND (TREE_OPERAND (incr, 1), 0); 10619 1.1 mrg if (TREE_SIDE_EFFECTS (t) 10620 1.1 mrg && t != decl 10621 1.1 mrg && (TREE_CODE (t) != NOP_EXPR 10622 1.1 mrg || TREE_OPERAND (t, 0) != decl)) 10623 1.1 mrg TREE_OPERAND (TREE_OPERAND (incr, 1), 0) 10624 1.1 mrg = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 10625 1.1 mrg 10626 1.1 mrg t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1); 10627 1.1 mrg if (TREE_SIDE_EFFECTS (t) 10628 1.1 mrg && t != decl 10629 1.1 mrg && (TREE_CODE (t) != NOP_EXPR 10630 1.1 mrg || TREE_OPERAND (t, 0) != decl)) 10631 1.1 mrg TREE_OPERAND (TREE_OPERAND (incr, 1), 1) 10632 1.1 mrg = fold_build_cleanup_point_expr (TREE_TYPE (t), t); 10633 1.1 mrg } 10634 1.1 mrg 10635 1.1 mrg if (orig_incr) 10636 1.1 mrg TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i) = TREE_VEC_ELT (orig_incr, i); 10637 1.1 mrg } 10638 1.1 mrg OMP_FOR_CLAUSES (omp_for) = clauses; 10639 1.1 mrg 10640 1.1 mrg /* For simd loops with non-static data member iterators, we could have added 10641 1.1 mrg OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP. As we know the 10642 1.1 mrg step at this point, fill it in. */ 10643 1.1 mrg if (code == OMP_SIMD && !processing_template_decl 10644 1.1 mrg && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)) == 1) 10645 1.1 mrg for (tree c = omp_find_clause (clauses, OMP_CLAUSE_LINEAR); c; 10646 1.1 mrg c = omp_find_clause (OMP_CLAUSE_CHAIN (c), OMP_CLAUSE_LINEAR)) 10647 1.1 mrg if (OMP_CLAUSE_LINEAR_STEP (c) == NULL_TREE) 10648 1.1 mrg { 10649 1.1 mrg decl = TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0), 0); 10650 1.1 mrg gcc_assert (decl == OMP_CLAUSE_DECL (c)); 10651 1.1 mrg incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0); 10652 1.1 mrg tree step, stept; 10653 1.1 mrg switch (TREE_CODE (incr)) 10654 1.1 mrg { 10655 1.1 mrg case PREINCREMENT_EXPR: 10656 1.1 mrg case POSTINCREMENT_EXPR: 10657 1.1 mrg /* c_omp_for_incr_canonicalize_ptr() should have been 10658 1.1 mrg called to massage things appropriately. */ 10659 1.1 mrg gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl))); 10660 1.1 mrg OMP_CLAUSE_LINEAR_STEP (c) = build_int_cst (TREE_TYPE (decl), 1); 10661 1.1 mrg break; 10662 1.1 mrg case PREDECREMENT_EXPR: 10663 1.1 mrg case POSTDECREMENT_EXPR: 10664 1.1 mrg /* c_omp_for_incr_canonicalize_ptr() should have been 10665 1.1 mrg called to massage things appropriately. */ 10666 1.1 mrg gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl))); 10667 1.1 mrg OMP_CLAUSE_LINEAR_STEP (c) 10668 1.1 mrg = build_int_cst (TREE_TYPE (decl), -1); 10669 1.1 mrg break; 10670 1.1 mrg case MODIFY_EXPR: 10671 1.1 mrg gcc_assert (TREE_OPERAND (incr, 0) == decl); 10672 1.1 mrg incr = TREE_OPERAND (incr, 1); 10673 1.1 mrg switch (TREE_CODE (incr)) 10674 1.1 mrg { 10675 1.1 mrg case PLUS_EXPR: 10676 1.1 mrg if (TREE_OPERAND (incr, 1) == decl) 10677 1.1 mrg step = TREE_OPERAND (incr, 0); 10678 1.1 mrg else 10679 1.1 mrg step = TREE_OPERAND (incr, 1); 10680 1.1 mrg break; 10681 1.1 mrg case MINUS_EXPR: 10682 1.1 mrg case POINTER_PLUS_EXPR: 10683 1.1 mrg gcc_assert (TREE_OPERAND (incr, 0) == decl); 10684 1.1 mrg step = TREE_OPERAND (incr, 1); 10685 1.1 mrg break; 10686 1.1 mrg default: 10687 1.1 mrg gcc_unreachable (); 10688 1.1 mrg } 10689 1.1 mrg stept = TREE_TYPE (decl); 10690 1.1 mrg if (INDIRECT_TYPE_P (stept)) 10691 1.1 mrg stept = sizetype; 10692 1.1 mrg step = fold_convert (stept, step); 10693 1.1 mrg if (TREE_CODE (incr) == MINUS_EXPR) 10694 1.1 mrg step = fold_build1 (NEGATE_EXPR, stept, step); 10695 1.1 mrg OMP_CLAUSE_LINEAR_STEP (c) = step; 10696 1.1 mrg break; 10697 1.1 mrg default: 10698 1.1 mrg gcc_unreachable (); 10699 1.1 mrg } 10700 1.1 mrg } 10701 1.1 mrg /* Override saved methods on OMP_LOOP's OMP_CLAUSE_LASTPRIVATE_LOOP_IV 10702 1.1 mrg clauses, we need copy ctor for those rather than default ctor, 10703 1.1 mrg plus as for other lastprivates assignment op and dtor. */ 10704 1.1 mrg if (code == OMP_LOOP && !processing_template_decl) 10705 1.1 mrg for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c)) 10706 1.1 mrg if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE 10707 1.1 mrg && OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c) 10708 1.1 mrg && cxx_omp_create_clause_info (c, TREE_TYPE (OMP_CLAUSE_DECL (c)), 10709 1.1 mrg false, true, true, true)) 10710 1.1 mrg CP_OMP_CLAUSE_INFO (c) = NULL_TREE; 10711 1.1 mrg 10712 1.1 mrg return omp_for; 10713 1.1 mrg } 10714 1.1 mrg 10715 1.1 mrg /* Fix up range for decls. Those decls were pushed into BIND's BIND_EXPR_VARS 10716 1.1 mrg and need to be moved into the BIND_EXPR inside of the OMP_FOR's body. */ 10717 1.1 mrg 10718 1.1 mrg tree 10719 1.1 mrg finish_omp_for_block (tree bind, tree omp_for) 10720 1.1 mrg { 10721 1.1 mrg if (omp_for == NULL_TREE 10722 1.1 mrg || !OMP_FOR_ORIG_DECLS (omp_for) 10723 1.1 mrg || bind == NULL_TREE 10724 1.1 mrg || TREE_CODE (bind) != BIND_EXPR) 10725 1.1 mrg return bind; 10726 1.1 mrg tree b = NULL_TREE; 10727 1.1 mrg for (int i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (omp_for)); i++) 10728 1.1 mrg if (TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i)) == TREE_LIST 10729 1.1 mrg && TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i))) 10730 1.1 mrg { 10731 1.1 mrg tree v = TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i)); 10732 1.1 mrg gcc_assert (BIND_EXPR_BLOCK (bind) 10733 1.1 mrg && (BIND_EXPR_VARS (bind) 10734 1.1 mrg == BLOCK_VARS (BIND_EXPR_BLOCK (bind)))); 10735 1.1 mrg for (int j = 2; j < TREE_VEC_LENGTH (v); j++) 10736 1.1 mrg for (tree *p = &BIND_EXPR_VARS (bind); *p; p = &DECL_CHAIN (*p)) 10737 1.1 mrg { 10738 1.1 mrg if (*p == TREE_VEC_ELT (v, j)) 10739 1.1 mrg { 10740 1.1 mrg tree var = *p; 10741 1.1 mrg *p = DECL_CHAIN (*p); 10742 1.1 mrg if (b == NULL_TREE) 10743 1.1 mrg { 10744 1.1 mrg b = make_node (BLOCK); 10745 1.1 mrg b = build3 (BIND_EXPR, void_type_node, NULL_TREE, 10746 1.1 mrg OMP_FOR_BODY (omp_for), b); 10747 1.1 mrg TREE_SIDE_EFFECTS (b) = 1; 10748 1.1 mrg OMP_FOR_BODY (omp_for) = b; 10749 1.1 mrg } 10750 1.1 mrg DECL_CHAIN (var) = BIND_EXPR_VARS (b); 10751 1.1 mrg BIND_EXPR_VARS (b) = var; 10752 1.1 mrg BLOCK_VARS (BIND_EXPR_BLOCK (b)) = var; 10753 1.1 mrg } 10754 1.1 mrg } 10755 1.1 mrg BLOCK_VARS (BIND_EXPR_BLOCK (bind)) = BIND_EXPR_VARS (bind); 10756 1.1 mrg } 10757 1.1 mrg return bind; 10758 1.1 mrg } 10759 1.1 mrg 10760 1.1 mrg void 10761 1.1 mrg finish_omp_atomic (location_t loc, enum tree_code code, enum tree_code opcode, 10762 1.1 mrg tree lhs, tree rhs, tree v, tree lhs1, tree rhs1, tree r, 10763 1.1 mrg tree clauses, enum omp_memory_order mo, bool weak) 10764 1.1 mrg { 10765 1.1 mrg tree orig_lhs; 10766 1.1 mrg tree orig_rhs; 10767 1.1 mrg tree orig_v; 10768 1.1 mrg tree orig_lhs1; 10769 1.1 mrg tree orig_rhs1; 10770 1.1 mrg tree orig_r; 10771 1.1 mrg bool dependent_p; 10772 1.1 mrg tree stmt; 10773 1.1 mrg 10774 1.1 mrg orig_lhs = lhs; 10775 1.1 mrg orig_rhs = rhs; 10776 1.1 mrg orig_v = v; 10777 1.1 mrg orig_lhs1 = lhs1; 10778 1.1 mrg orig_rhs1 = rhs1; 10779 1.1 mrg orig_r = r; 10780 1.1 mrg dependent_p = false; 10781 1.1 mrg stmt = NULL_TREE; 10782 1.1 mrg 10783 1.1 mrg /* Even in a template, we can detect invalid uses of the atomic 10784 1.1 mrg pragma if neither LHS nor RHS is type-dependent. */ 10785 1.1 mrg if (processing_template_decl) 10786 1.1 mrg { 10787 1.1 mrg dependent_p = (type_dependent_expression_p (lhs) 10788 1.1 mrg || (rhs && type_dependent_expression_p (rhs)) 10789 1.1 mrg || (v && type_dependent_expression_p (v)) 10790 1.1 mrg || (lhs1 && type_dependent_expression_p (lhs1)) 10791 1.1 mrg || (rhs1 && type_dependent_expression_p (rhs1)) 10792 1.1 mrg || (r 10793 1.1 mrg && r != void_list_node 10794 1.1 mrg && type_dependent_expression_p (r))); 10795 1.1 mrg if (clauses) 10796 1.1 mrg { 10797 1.1 mrg gcc_assert (TREE_CODE (clauses) == OMP_CLAUSE 10798 1.1 mrg && OMP_CLAUSE_CODE (clauses) == OMP_CLAUSE_HINT 10799 1.1 mrg && OMP_CLAUSE_CHAIN (clauses) == NULL_TREE); 10800 1.1 mrg if (type_dependent_expression_p (OMP_CLAUSE_HINT_EXPR (clauses)) 10801 1.1 mrg || TREE_CODE (OMP_CLAUSE_HINT_EXPR (clauses)) != INTEGER_CST) 10802 1.1 mrg dependent_p = true; 10803 1.1 mrg } 10804 1.1 mrg if (!dependent_p) 10805 1.1 mrg { 10806 1.1 mrg lhs = build_non_dependent_expr (lhs); 10807 1.1 mrg if (rhs) 10808 1.1 mrg rhs = build_non_dependent_expr (rhs); 10809 1.1 mrg if (v) 10810 1.1 mrg v = build_non_dependent_expr (v); 10811 1.1 mrg if (lhs1) 10812 1.1 mrg lhs1 = build_non_dependent_expr (lhs1); 10813 1.1 mrg if (rhs1) 10814 1.1 mrg rhs1 = build_non_dependent_expr (rhs1); 10815 1.1 mrg if (r && r != void_list_node) 10816 1.1 mrg r = build_non_dependent_expr (r); 10817 1.1 mrg } 10818 1.1 mrg } 10819 1.1 mrg if (!dependent_p) 10820 1.1 mrg { 10821 1.1 mrg bool swapped = false; 10822 1.1 mrg if (rhs1 && opcode != COND_EXPR && cp_tree_equal (lhs, rhs)) 10823 1.1 mrg { 10824 1.1 mrg std::swap (rhs, rhs1); 10825 1.1 mrg swapped = !commutative_tree_code (opcode); 10826 1.1 mrg } 10827 1.1 mrg if (rhs1 && opcode != COND_EXPR && !cp_tree_equal (lhs, rhs1)) 10828 1.1 mrg { 10829 1.1 mrg if (code == OMP_ATOMIC) 10830 1.1 mrg error ("%<#pragma omp atomic update%> uses two different " 10831 1.1 mrg "expressions for memory"); 10832 1.1 mrg else 10833 1.1 mrg error ("%<#pragma omp atomic capture%> uses two different " 10834 1.1 mrg "expressions for memory"); 10835 1.1 mrg return; 10836 1.1 mrg } 10837 1.1 mrg if (lhs1 && !cp_tree_equal (lhs, lhs1)) 10838 1.1 mrg { 10839 1.1 mrg if (code == OMP_ATOMIC) 10840 1.1 mrg error ("%<#pragma omp atomic update%> uses two different " 10841 1.1 mrg "expressions for memory"); 10842 1.1 mrg else 10843 1.1 mrg error ("%<#pragma omp atomic capture%> uses two different " 10844 1.1 mrg "expressions for memory"); 10845 1.1 mrg return; 10846 1.1 mrg } 10847 1.1 mrg stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs, 10848 1.1 mrg v, lhs1, rhs1, r, swapped, mo, weak, 10849 1.1 mrg processing_template_decl != 0); 10850 1.1 mrg if (stmt == error_mark_node) 10851 1.1 mrg return; 10852 1.1 mrg } 10853 1.1 mrg if (processing_template_decl) 10854 1.1 mrg { 10855 1.1 mrg if (code == OMP_ATOMIC_READ) 10856 1.1 mrg { 10857 1.1 mrg stmt = build_min_nt_loc (loc, OMP_ATOMIC_READ, orig_lhs); 10858 1.1 mrg OMP_ATOMIC_MEMORY_ORDER (stmt) = mo; 10859 1.1 mrg stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt); 10860 1.1 mrg } 10861 1.1 mrg else 10862 1.1 mrg { 10863 1.1 mrg if (opcode == NOP_EXPR) 10864 1.1 mrg stmt = build2 (MODIFY_EXPR, void_type_node, orig_lhs, orig_rhs); 10865 1.1 mrg else if (opcode == COND_EXPR) 10866 1.1 mrg { 10867 1.1 mrg stmt = build2 (EQ_EXPR, boolean_type_node, orig_lhs, orig_rhs); 10868 1.1 mrg if (orig_r) 10869 1.1 mrg stmt = build2 (MODIFY_EXPR, boolean_type_node, orig_r, 10870 1.1 mrg stmt); 10871 1.1 mrg stmt = build3 (COND_EXPR, void_type_node, stmt, orig_rhs1, 10872 1.1 mrg orig_lhs); 10873 1.1 mrg orig_rhs1 = NULL_TREE; 10874 1.1 mrg } 10875 1.1 mrg else 10876 1.1 mrg stmt = build2 (opcode, void_type_node, orig_lhs, orig_rhs); 10877 1.1 mrg if (orig_rhs1) 10878 1.1 mrg stmt = build_min_nt_loc (EXPR_LOCATION (orig_rhs1), 10879 1.1 mrg COMPOUND_EXPR, orig_rhs1, stmt); 10880 1.1 mrg if (code != OMP_ATOMIC) 10881 1.1 mrg { 10882 1.1 mrg stmt = build_min_nt_loc (loc, code, orig_lhs1, stmt); 10883 1.1 mrg OMP_ATOMIC_MEMORY_ORDER (stmt) = mo; 10884 1.1 mrg OMP_ATOMIC_WEAK (stmt) = weak; 10885 1.1 mrg stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt); 10886 1.1 mrg } 10887 1.1 mrg } 10888 1.1 mrg stmt = build2 (OMP_ATOMIC, void_type_node, 10889 1.1 mrg clauses ? clauses : integer_zero_node, stmt); 10890 1.1 mrg OMP_ATOMIC_MEMORY_ORDER (stmt) = mo; 10891 1.1 mrg OMP_ATOMIC_WEAK (stmt) = weak; 10892 1.1 mrg SET_EXPR_LOCATION (stmt, loc); 10893 1.1 mrg } 10894 1.1 mrg 10895 1.1 mrg /* Avoid -Wunused-value warnings here, the whole construct has side-effects 10896 1.1 mrg and even if it might be wrapped from fold-const.cc or c-omp.cc wrapped 10897 1.1 mrg in some tree that appears to be unused, the value is not unused. */ 10898 1.1 mrg warning_sentinel w (warn_unused_value); 10899 1.1 mrg finish_expr_stmt (stmt); 10900 1.1 mrg } 10901 1.1 mrg 10902 1.1 mrg void 10903 1.1 mrg finish_omp_barrier (void) 10904 1.1 mrg { 10905 1.1 mrg tree fn = builtin_decl_explicit (BUILT_IN_GOMP_BARRIER); 10906 1.1 mrg releasing_vec vec; 10907 1.1 mrg tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error); 10908 1.1 mrg finish_expr_stmt (stmt); 10909 1.1 mrg } 10910 1.1 mrg 10911 1.1 mrg void 10912 1.1 mrg finish_omp_depobj (location_t loc, tree depobj, 10913 1.1 mrg enum omp_clause_depend_kind kind, tree clause) 10914 1.1 mrg { 10915 1.1 mrg if (!error_operand_p (depobj) && !type_dependent_expression_p (depobj)) 10916 1.1 mrg { 10917 1.1 mrg if (!lvalue_p (depobj)) 10918 1.1 mrg { 10919 1.1 mrg error_at (EXPR_LOC_OR_LOC (depobj, loc), 10920 1.1 mrg "%<depobj%> expression is not lvalue expression"); 10921 1.1 mrg depobj = error_mark_node; 10922 1.1 mrg } 10923 1.1 mrg } 10924 1.1 mrg 10925 1.1 mrg if (processing_template_decl) 10926 1.1 mrg { 10927 1.1 mrg if (clause == NULL_TREE) 10928 1.1 mrg clause = build_int_cst (integer_type_node, kind); 10929 1.1 mrg add_stmt (build_min_nt_loc (loc, OMP_DEPOBJ, depobj, clause)); 10930 1.1 mrg return; 10931 1.1 mrg } 10932 1.1 mrg 10933 1.1 mrg if (!error_operand_p (depobj)) 10934 1.1 mrg { 10935 1.1 mrg tree addr = cp_build_addr_expr (depobj, tf_warning_or_error); 10936 1.1 mrg if (addr == error_mark_node) 10937 1.1 mrg depobj = error_mark_node; 10938 1.1 mrg else 10939 1.1 mrg depobj = cp_build_indirect_ref (loc, addr, RO_UNARY_STAR, 10940 1.1 mrg tf_warning_or_error); 10941 1.1 mrg } 10942 1.1 mrg 10943 1.1 mrg c_finish_omp_depobj (loc, depobj, kind, clause); 10944 1.1 mrg } 10945 1.1 mrg 10946 1.1 mrg void 10947 1.1 mrg finish_omp_flush (int mo) 10948 1.1 mrg { 10949 1.1 mrg tree fn = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE); 10950 1.1 mrg releasing_vec vec; 10951 1.1 mrg if (mo != MEMMODEL_LAST && mo != MEMMODEL_SEQ_CST) 10952 1.1 mrg { 10953 1.1 mrg fn = builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE); 10954 1.1 mrg vec->quick_push (build_int_cst (integer_type_node, mo)); 10955 1.1 mrg } 10956 1.1 mrg tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error); 10957 1.1 mrg finish_expr_stmt (stmt); 10958 1.1 mrg } 10959 1.1 mrg 10960 1.1 mrg void 10961 1.1 mrg finish_omp_taskwait (void) 10962 1.1 mrg { 10963 1.1 mrg tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT); 10964 1.1 mrg releasing_vec vec; 10965 1.1 mrg tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error); 10966 1.1 mrg finish_expr_stmt (stmt); 10967 1.1 mrg } 10968 1.1 mrg 10969 1.1 mrg void 10970 1.1 mrg finish_omp_taskyield (void) 10971 1.1 mrg { 10972 1.1 mrg tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD); 10973 1.1 mrg releasing_vec vec; 10974 1.1 mrg tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error); 10975 1.1 mrg finish_expr_stmt (stmt); 10976 1.1 mrg } 10977 1.1 mrg 10978 1.1 mrg void 10979 1.1 mrg finish_omp_cancel (tree clauses) 10980 1.1 mrg { 10981 1.1 mrg tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL); 10982 1.1 mrg int mask = 0; 10983 1.1 mrg if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL)) 10984 1.1 mrg mask = 1; 10985 1.1 mrg else if (omp_find_clause (clauses, OMP_CLAUSE_FOR)) 10986 1.1 mrg mask = 2; 10987 1.1 mrg else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS)) 10988 1.1 mrg mask = 4; 10989 1.1 mrg else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP)) 10990 1.1 mrg mask = 8; 10991 1.1 mrg else 10992 1.1 mrg { 10993 1.1 mrg error ("%<#pragma omp cancel%> must specify one of " 10994 1.1 mrg "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses"); 10995 1.1 mrg return; 10996 1.1 mrg } 10997 1.1 mrg releasing_vec vec; 10998 1.1 mrg tree ifc = omp_find_clause (clauses, OMP_CLAUSE_IF); 10999 1.1 mrg if (ifc != NULL_TREE) 11000 1.1 mrg { 11001 1.1 mrg if (OMP_CLAUSE_IF_MODIFIER (ifc) != ERROR_MARK 11002 1.1 mrg && OMP_CLAUSE_IF_MODIFIER (ifc) != VOID_CST) 11003 1.1 mrg error_at (OMP_CLAUSE_LOCATION (ifc), 11004 1.1 mrg "expected %<cancel%> %<if%> clause modifier"); 11005 1.1 mrg else 11006 1.1 mrg { 11007 1.1 mrg tree ifc2 = omp_find_clause (OMP_CLAUSE_CHAIN (ifc), OMP_CLAUSE_IF); 11008 1.1 mrg if (ifc2 != NULL_TREE) 11009 1.1 mrg { 11010 1.1 mrg gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc) == VOID_CST 11011 1.1 mrg && OMP_CLAUSE_IF_MODIFIER (ifc2) != ERROR_MARK 11012 1.1 mrg && OMP_CLAUSE_IF_MODIFIER (ifc2) != VOID_CST); 11013 1.1 mrg error_at (OMP_CLAUSE_LOCATION (ifc2), 11014 1.1 mrg "expected %<cancel%> %<if%> clause modifier"); 11015 1.1 mrg } 11016 1.1 mrg } 11017 1.1 mrg 11018 1.1 mrg if (!processing_template_decl) 11019 1.1 mrg ifc = maybe_convert_cond (OMP_CLAUSE_IF_EXPR (ifc)); 11020 1.1 mrg else 11021 1.1 mrg ifc = build_x_binary_op (OMP_CLAUSE_LOCATION (ifc), NE_EXPR, 11022 1.1 mrg OMP_CLAUSE_IF_EXPR (ifc), ERROR_MARK, 11023 1.1 mrg integer_zero_node, ERROR_MARK, 11024 1.1 mrg NULL_TREE, NULL, tf_warning_or_error); 11025 1.1 mrg } 11026 1.1 mrg else 11027 1.1 mrg ifc = boolean_true_node; 11028 1.1 mrg vec->quick_push (build_int_cst (integer_type_node, mask)); 11029 1.1 mrg vec->quick_push (ifc); 11030 1.1 mrg tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error); 11031 1.1 mrg finish_expr_stmt (stmt); 11032 1.1 mrg } 11033 1.1 mrg 11034 1.1 mrg void 11035 1.1 mrg finish_omp_cancellation_point (tree clauses) 11036 1.1 mrg { 11037 1.1 mrg tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT); 11038 1.1 mrg int mask = 0; 11039 1.1 mrg if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL)) 11040 1.1 mrg mask = 1; 11041 1.1 mrg else if (omp_find_clause (clauses, OMP_CLAUSE_FOR)) 11042 1.1 mrg mask = 2; 11043 1.1 mrg else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS)) 11044 1.1 mrg mask = 4; 11045 1.1 mrg else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP)) 11046 1.1 mrg mask = 8; 11047 1.1 mrg else 11048 1.1 mrg { 11049 1.1 mrg error ("%<#pragma omp cancellation point%> must specify one of " 11050 1.1 mrg "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses"); 11051 1.1 mrg return; 11052 1.1 mrg } 11053 1.1 mrg releasing_vec vec 11054 1.1 mrg = make_tree_vector_single (build_int_cst (integer_type_node, mask)); 11055 1.1 mrg tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error); 11056 1.1 mrg finish_expr_stmt (stmt); 11057 1.1 mrg } 11058 1.1 mrg 11059 1.1 mrg /* Begin a __transaction_atomic or __transaction_relaxed statement. 11061 1.1 mrg If PCOMPOUND is non-null, this is for a function-transaction-block, and we 11062 1.1 mrg should create an extra compound stmt. */ 11063 1.1 mrg 11064 1.1 mrg tree 11065 1.1 mrg begin_transaction_stmt (location_t loc, tree *pcompound, int flags) 11066 1.1 mrg { 11067 1.1 mrg tree r; 11068 1.1 mrg 11069 1.1 mrg if (pcompound) 11070 1.1 mrg *pcompound = begin_compound_stmt (0); 11071 1.1 mrg 11072 1.1 mrg r = build_stmt (loc, TRANSACTION_EXPR, NULL_TREE); 11073 1.1 mrg 11074 1.1 mrg /* Only add the statement to the function if support enabled. */ 11075 1.1 mrg if (flag_tm) 11076 1.1 mrg add_stmt (r); 11077 1.1 mrg else 11078 1.1 mrg error_at (loc, ((flags & TM_STMT_ATTR_RELAXED) != 0 11079 1.1 mrg ? G_("%<__transaction_relaxed%> without " 11080 1.1 mrg "transactional memory support enabled") 11081 1.1 mrg : G_("%<__transaction_atomic%> without " 11082 1.1 mrg "transactional memory support enabled"))); 11083 1.1 mrg 11084 1.1 mrg TRANSACTION_EXPR_BODY (r) = push_stmt_list (); 11085 1.1 mrg TREE_SIDE_EFFECTS (r) = 1; 11086 1.1 mrg return r; 11087 1.1 mrg } 11088 1.1 mrg 11089 1.1 mrg /* End a __transaction_atomic or __transaction_relaxed statement. 11090 1.1 mrg If COMPOUND_STMT is non-null, this is for a function-transaction-block, 11091 1.1 mrg and we should end the compound. If NOEX is non-NULL, we wrap the body in 11092 1.1 mrg a MUST_NOT_THROW_EXPR with NOEX as condition. */ 11093 1.1 mrg 11094 1.1 mrg void 11095 1.1 mrg finish_transaction_stmt (tree stmt, tree compound_stmt, int flags, tree noex) 11096 1.1 mrg { 11097 1.1 mrg TRANSACTION_EXPR_BODY (stmt) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt)); 11098 1.1 mrg TRANSACTION_EXPR_OUTER (stmt) = (flags & TM_STMT_ATTR_OUTER) != 0; 11099 1.1 mrg TRANSACTION_EXPR_RELAXED (stmt) = (flags & TM_STMT_ATTR_RELAXED) != 0; 11100 1.1 mrg TRANSACTION_EXPR_IS_STMT (stmt) = 1; 11101 1.1 mrg 11102 1.1 mrg /* noexcept specifications are not allowed for function transactions. */ 11103 1.1 mrg gcc_assert (!(noex && compound_stmt)); 11104 1.1 mrg if (noex) 11105 1.1 mrg { 11106 1.1 mrg tree body = build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt), 11107 1.1 mrg noex); 11108 1.1 mrg protected_set_expr_location 11109 1.1 mrg (body, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt))); 11110 1.1 mrg TREE_SIDE_EFFECTS (body) = 1; 11111 1.1 mrg TRANSACTION_EXPR_BODY (stmt) = body; 11112 1.1 mrg } 11113 1.1 mrg 11114 1.1 mrg if (compound_stmt) 11115 1.1 mrg finish_compound_stmt (compound_stmt); 11116 1.1 mrg } 11117 1.1 mrg 11118 1.1 mrg /* Build a __transaction_atomic or __transaction_relaxed expression. If 11119 1.1 mrg NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as 11120 1.1 mrg condition. */ 11121 1.1 mrg 11122 1.1 mrg tree 11123 1.1 mrg build_transaction_expr (location_t loc, tree expr, int flags, tree noex) 11124 1.1 mrg { 11125 1.1 mrg tree ret; 11126 1.1 mrg if (noex) 11127 1.1 mrg { 11128 1.1 mrg expr = build_must_not_throw_expr (expr, noex); 11129 1.1 mrg protected_set_expr_location (expr, loc); 11130 1.1 mrg TREE_SIDE_EFFECTS (expr) = 1; 11131 1.1 mrg } 11132 1.1 mrg ret = build1 (TRANSACTION_EXPR, TREE_TYPE (expr), expr); 11133 1.1 mrg if (flags & TM_STMT_ATTR_RELAXED) 11134 1.1 mrg TRANSACTION_EXPR_RELAXED (ret) = 1; 11135 1.1 mrg TREE_SIDE_EFFECTS (ret) = 1; 11136 1.1 mrg SET_EXPR_LOCATION (ret, loc); 11137 1.1 mrg return ret; 11138 1.1 mrg } 11139 1.1 mrg 11140 1.1 mrg void 11142 1.1 mrg init_cp_semantics (void) 11143 1.1 mrg { 11144 1.1 mrg } 11145 1.1 mrg 11146 1.1 mrg 11148 1.1 mrg /* If we have a condition in conjunctive normal form (CNF), find the first 11149 1.1 mrg failing clause. In other words, given an expression like 11150 1.1 mrg 11151 1.1 mrg true && true && false && true && false 11152 1.1 mrg 11153 1.1 mrg return the first 'false'. EXPR is the expression. */ 11154 1.1 mrg 11155 1.1 mrg static tree 11156 1.1 mrg find_failing_clause_r (tree expr) 11157 1.1 mrg { 11158 1.1 mrg if (TREE_CODE (expr) == TRUTH_ANDIF_EXPR) 11159 1.1 mrg { 11160 1.1 mrg /* First check the left side... */ 11161 1.1 mrg tree e = find_failing_clause_r (TREE_OPERAND (expr, 0)); 11162 1.1 mrg if (e == NULL_TREE) 11163 1.1 mrg /* ...if we didn't find a false clause, check the right side. */ 11164 1.1 mrg e = find_failing_clause_r (TREE_OPERAND (expr, 1)); 11165 1.1 mrg return e; 11166 1.1 mrg } 11167 1.1 mrg tree e = contextual_conv_bool (expr, tf_none); 11168 1.1 mrg e = fold_non_dependent_expr (e, tf_none, /*manifestly_const_eval=*/true); 11169 1.1 mrg if (integer_zerop (e)) 11170 1.1 mrg /* This is the failing clause. */ 11171 1.1 mrg return expr; 11172 1.1 mrg return NULL_TREE; 11173 1.1 mrg } 11174 1.1 mrg 11175 1.1 mrg /* Wrapper for find_failing_clause_r. */ 11176 1.1 mrg 11177 1.1 mrg static tree 11178 1.1 mrg find_failing_clause (tree expr) 11179 1.1 mrg { 11180 1.1 mrg if (TREE_CODE (expr) == TRUTH_ANDIF_EXPR) 11181 1.1 mrg if (tree e = find_failing_clause_r (expr)) 11182 1.1 mrg expr = e; 11183 1.1 mrg return expr; 11184 1.1 mrg } 11185 1.1 mrg 11186 1.1 mrg /* Build a STATIC_ASSERT for a static assertion with the condition 11187 1.1 mrg CONDITION and the message text MESSAGE. LOCATION is the location 11188 1.1 mrg of the static assertion in the source code. When MEMBER_P, this 11189 1.1 mrg static assertion is a member of a class. If SHOW_EXPR_P is true, 11190 1.1 mrg print the condition (because it was instantiation-dependent). */ 11191 1.1 mrg 11192 1.1 mrg void 11193 1.1 mrg finish_static_assert (tree condition, tree message, location_t location, 11194 1.1 mrg bool member_p, bool show_expr_p) 11195 1.1 mrg { 11196 1.1 mrg tsubst_flags_t complain = tf_warning_or_error; 11197 1.1 mrg 11198 1.1 mrg if (message == NULL_TREE 11199 1.1 mrg || message == error_mark_node 11200 1.1 mrg || condition == NULL_TREE 11201 1.1 mrg || condition == error_mark_node) 11202 1.1 mrg return; 11203 1.1 mrg 11204 1.1 mrg if (check_for_bare_parameter_packs (condition)) 11205 1.1 mrg condition = error_mark_node; 11206 1.1 mrg 11207 1.1 mrg if (instantiation_dependent_expression_p (condition)) 11208 1.1 mrg { 11209 1.1 mrg /* We're in a template; build a STATIC_ASSERT and put it in 11210 1.1 mrg the right place. */ 11211 1.1 mrg tree assertion; 11212 1.1 mrg 11213 1.1 mrg assertion = make_node (STATIC_ASSERT); 11214 1.1 mrg STATIC_ASSERT_CONDITION (assertion) = condition; 11215 1.1 mrg STATIC_ASSERT_MESSAGE (assertion) = message; 11216 1.1 mrg STATIC_ASSERT_SOURCE_LOCATION (assertion) = location; 11217 1.1 mrg 11218 1.1 mrg if (member_p) 11219 1.1 mrg maybe_add_class_template_decl_list (current_class_type, 11220 1.1 mrg assertion, 11221 1.1 mrg /*friend_p=*/0); 11222 1.1 mrg else 11223 1.1 mrg add_stmt (assertion); 11224 1.1 mrg 11225 1.1 mrg return; 11226 1.1 mrg } 11227 1.1 mrg 11228 1.1 mrg /* Save the condition in case it was a concept check. */ 11229 1.1 mrg tree orig_condition = condition; 11230 1.1 mrg 11231 1.1 mrg /* Fold the expression and convert it to a boolean value. */ 11232 1.1 mrg condition = contextual_conv_bool (condition, complain); 11233 1.1 mrg condition = fold_non_dependent_expr (condition, complain, 11234 1.1 mrg /*manifestly_const_eval=*/true); 11235 1.1 mrg 11236 1.1 mrg if (TREE_CODE (condition) == INTEGER_CST && !integer_zerop (condition)) 11237 1.1 mrg /* Do nothing; the condition is satisfied. */ 11238 1.1 mrg ; 11239 1.1 mrg else 11240 1.1 mrg { 11241 1.1 mrg iloc_sentinel ils (location); 11242 1.1 mrg 11243 1.1 mrg if (integer_zerop (condition)) 11244 1.1 mrg { 11245 1.1 mrg int sz = TREE_INT_CST_LOW (TYPE_SIZE_UNIT 11246 1.1 mrg (TREE_TYPE (TREE_TYPE (message)))); 11247 1.1 mrg int len = TREE_STRING_LENGTH (message) / sz - 1; 11248 1.1 mrg 11249 1.1 mrg /* See if we can find which clause was failing (for logical AND). */ 11250 1.1 mrg tree bad = find_failing_clause (orig_condition); 11251 1.1 mrg /* If not, or its location is unusable, fall back to the previous 11252 1.1 mrg location. */ 11253 1.1 mrg location_t cloc = cp_expr_loc_or_loc (bad, location); 11254 1.1 mrg /* Nobody wants to see the artificial (bool) cast. */ 11255 1.1 mrg bad = tree_strip_nop_conversions (bad); 11256 1.1 mrg 11257 1.1 mrg /* Report the error. */ 11258 1.1 mrg if (len == 0) 11259 1.1 mrg error_at (cloc, "static assertion failed"); 11260 1.1 mrg else 11261 1.1 mrg error_at (cloc, "static assertion failed: %s", 11262 1.1 mrg TREE_STRING_POINTER (message)); 11263 1.1 mrg 11264 1.1 mrg /* Actually explain the failure if this is a concept check or a 11265 1.1 mrg requires-expression. */ 11266 1.1 mrg if (concept_check_p (bad) 11267 1.1 mrg || TREE_CODE (bad) == REQUIRES_EXPR) 11268 1.1 mrg diagnose_constraints (location, bad, NULL_TREE); 11269 1.1 mrg else if (COMPARISON_CLASS_P (bad) 11270 1.1 mrg && ARITHMETIC_TYPE_P (TREE_TYPE (TREE_OPERAND (bad, 0)))) 11271 1.1 mrg { 11272 1.1 mrg tree op0 = fold_non_dependent_expr (TREE_OPERAND (bad, 0)); 11273 1.1 mrg tree op1 = fold_non_dependent_expr (TREE_OPERAND (bad, 1)); 11274 1.1 mrg tree cond = build2 (TREE_CODE (bad), boolean_type_node, op0, op1); 11275 1.1 mrg inform (cloc, "the comparison reduces to %qE", cond); 11276 1.1 mrg } 11277 1.1 mrg else if (show_expr_p) 11278 1.1 mrg inform (cloc, "%qE evaluates to false", bad); 11279 1.1 mrg } 11280 1.1 mrg else if (condition && condition != error_mark_node) 11281 1.1 mrg { 11282 1.1 mrg error ("non-constant condition for static assertion"); 11283 1.1 mrg if (require_rvalue_constant_expression (condition)) 11284 1.1 mrg cxx_constant_value (condition); 11285 1.1 mrg } 11286 1.1 mrg } 11287 1.1 mrg } 11288 1.1 mrg 11289 1.1 mrg /* Implements the C++0x decltype keyword. Returns the type of EXPR, 11291 1.1 mrg suitable for use as a type-specifier. 11292 1.1 mrg 11293 1.1 mrg ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an 11294 1.1 mrg id-expression or a class member access, FALSE when it was parsed as 11295 1.1 mrg a full expression. */ 11296 1.1 mrg 11297 1.1 mrg tree 11298 1.1 mrg finish_decltype_type (tree expr, bool id_expression_or_member_access_p, 11299 1.1 mrg tsubst_flags_t complain) 11300 1.1 mrg { 11301 1.1 mrg tree type = NULL_TREE; 11302 1.1 mrg 11303 1.1 mrg if (!expr || error_operand_p (expr)) 11304 1.1 mrg return error_mark_node; 11305 1.1 mrg 11306 1.1 mrg if (TYPE_P (expr) 11307 1.1 mrg || TREE_CODE (expr) == TYPE_DECL 11308 1.1 mrg || (TREE_CODE (expr) == BIT_NOT_EXPR 11309 1.1 mrg && TYPE_P (TREE_OPERAND (expr, 0)))) 11310 1.1 mrg { 11311 1.1 mrg if (complain & tf_error) 11312 1.1 mrg error ("argument to %<decltype%> must be an expression"); 11313 1.1 mrg return error_mark_node; 11314 1.1 mrg } 11315 1.1 mrg 11316 1.1 mrg /* decltype is an unevaluated context. */ 11317 1.1 mrg cp_unevaluated u; 11318 1.1 mrg 11319 1.1 mrg processing_template_decl_sentinel ptds (/*reset=*/false); 11320 1.1 mrg 11321 1.1 mrg /* Depending on the resolution of DR 1172, we may later need to distinguish 11322 1.1 mrg instantiation-dependent but not type-dependent expressions so that, say, 11323 1.1 mrg A<decltype(sizeof(T))>::U doesn't require 'typename'. */ 11324 1.1 mrg if (instantiation_dependent_uneval_expression_p (expr)) 11325 1.1 mrg { 11326 1.1 mrg type = cxx_make_type (DECLTYPE_TYPE); 11327 1.1 mrg DECLTYPE_TYPE_EXPR (type) = expr; 11328 1.1 mrg DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type) 11329 1.1 mrg = id_expression_or_member_access_p; 11330 1.1 mrg SET_TYPE_STRUCTURAL_EQUALITY (type); 11331 1.1 mrg 11332 1.1 mrg return type; 11333 1.1 mrg } 11334 1.1 mrg else if (processing_template_decl) 11335 1.1 mrg { 11336 1.1 mrg expr = instantiate_non_dependent_expr_sfinae (expr, complain|tf_decltype); 11337 1.1 mrg if (expr == error_mark_node) 11338 1.1 mrg return error_mark_node; 11339 1.1 mrg /* Keep processing_template_decl cleared for the rest of the function 11340 1.1 mrg (for sake of the call to lvalue_kind below, which handles templated 11341 1.1 mrg and non-templated COND_EXPR differently). */ 11342 1.1 mrg processing_template_decl = 0; 11343 1.1 mrg } 11344 1.1 mrg 11345 1.1 mrg /* The type denoted by decltype(e) is defined as follows: */ 11346 1.1 mrg 11347 1.1 mrg expr = resolve_nondeduced_context (expr, complain); 11348 1.1 mrg if (!mark_single_function (expr, complain)) 11349 1.1 mrg return error_mark_node; 11350 1.1 mrg 11351 1.1 mrg if (invalid_nonstatic_memfn_p (input_location, expr, complain)) 11352 1.1 mrg return error_mark_node; 11353 1.1 mrg 11354 1.1 mrg if (type_unknown_p (expr)) 11355 1.1 mrg { 11356 1.1 mrg if (complain & tf_error) 11357 1.1 mrg error ("%<decltype%> cannot resolve address of overloaded function"); 11358 1.1 mrg return error_mark_node; 11359 1.1 mrg } 11360 1.1 mrg 11361 1.1 mrg /* To get the size of a static data member declared as an array of 11362 1.1 mrg unknown bound, we need to instantiate it. */ 11363 1.1 mrg if (VAR_P (expr) 11364 1.1 mrg && VAR_HAD_UNKNOWN_BOUND (expr) 11365 1.1 mrg && DECL_TEMPLATE_INSTANTIATION (expr)) 11366 1.1 mrg instantiate_decl (expr, /*defer_ok*/true, /*expl_inst_mem*/false); 11367 1.1 mrg 11368 1.1 mrg if (id_expression_or_member_access_p) 11369 1.1 mrg { 11370 1.1 mrg /* If e is an id-expression or a class member access (5.2.5 11371 1.1 mrg [expr.ref]), decltype(e) is defined as the type of the entity 11372 1.1 mrg named by e. If there is no such entity, or e names a set of 11373 1.1 mrg overloaded functions, the program is ill-formed. */ 11374 1.1 mrg if (identifier_p (expr)) 11375 1.1 mrg expr = lookup_name (expr); 11376 1.1 mrg 11377 1.1 mrg if (INDIRECT_REF_P (expr) 11378 1.1 mrg || TREE_CODE (expr) == VIEW_CONVERT_EXPR) 11379 1.1 mrg /* This can happen when the expression is, e.g., "a.b". Just 11380 1.1 mrg look at the underlying operand. */ 11381 1.1 mrg expr = TREE_OPERAND (expr, 0); 11382 1.1 mrg 11383 1.1 mrg if (TREE_CODE (expr) == OFFSET_REF 11384 1.1 mrg || TREE_CODE (expr) == MEMBER_REF 11385 1.1 mrg || TREE_CODE (expr) == SCOPE_REF) 11386 1.1 mrg /* We're only interested in the field itself. If it is a 11387 1.1 mrg BASELINK, we will need to see through it in the next 11388 1.1 mrg step. */ 11389 1.1 mrg expr = TREE_OPERAND (expr, 1); 11390 1.1 mrg 11391 1.1 mrg if (BASELINK_P (expr)) 11392 1.1 mrg /* See through BASELINK nodes to the underlying function. */ 11393 1.1 mrg expr = BASELINK_FUNCTIONS (expr); 11394 1.1 mrg 11395 1.1 mrg /* decltype of a decomposition name drops references in the tuple case 11396 1.1 mrg (unlike decltype of a normal variable) and keeps cv-qualifiers from 11397 1.1 mrg the containing object in the other cases (unlike decltype of a member 11398 1.1 mrg access expression). */ 11399 1.1 mrg if (DECL_DECOMPOSITION_P (expr)) 11400 1.1 mrg { 11401 1.1 mrg if (DECL_HAS_VALUE_EXPR_P (expr)) 11402 1.1 mrg /* Expr is an array or struct subobject proxy, handle 11403 1.1 mrg bit-fields properly. */ 11404 1.1 mrg return unlowered_expr_type (expr); 11405 1.1 mrg else 11406 1.1 mrg /* Expr is a reference variable for the tuple case. */ 11407 1.1 mrg return lookup_decomp_type (expr); 11408 1.1 mrg } 11409 1.1 mrg 11410 1.1 mrg switch (TREE_CODE (expr)) 11411 1.1 mrg { 11412 1.1 mrg case FIELD_DECL: 11413 1.1 mrg if (DECL_BIT_FIELD_TYPE (expr)) 11414 1.1 mrg { 11415 1.1 mrg type = DECL_BIT_FIELD_TYPE (expr); 11416 1.1 mrg break; 11417 1.1 mrg } 11418 1.1 mrg /* Fall through for fields that aren't bitfields. */ 11419 1.1 mrg gcc_fallthrough (); 11420 1.1 mrg 11421 1.1 mrg case FUNCTION_DECL: 11422 1.1 mrg case VAR_DECL: 11423 1.1 mrg case CONST_DECL: 11424 1.1 mrg case PARM_DECL: 11425 1.1 mrg case RESULT_DECL: 11426 1.1 mrg case TEMPLATE_PARM_INDEX: 11427 1.1 mrg expr = mark_type_use (expr); 11428 1.1 mrg type = TREE_TYPE (expr); 11429 1.1 mrg break; 11430 1.1 mrg 11431 1.1 mrg case ERROR_MARK: 11432 1.1 mrg type = error_mark_node; 11433 1.1 mrg break; 11434 1.1 mrg 11435 1.1 mrg case COMPONENT_REF: 11436 1.1 mrg case COMPOUND_EXPR: 11437 1.1 mrg mark_type_use (expr); 11438 1.1 mrg type = is_bitfield_expr_with_lowered_type (expr); 11439 1.1 mrg if (!type) 11440 1.1 mrg type = TREE_TYPE (TREE_OPERAND (expr, 1)); 11441 1.1 mrg break; 11442 1.1 mrg 11443 1.1 mrg case BIT_FIELD_REF: 11444 1.1 mrg gcc_unreachable (); 11445 1.1 mrg 11446 1.1 mrg case INTEGER_CST: 11447 1.1 mrg case PTRMEM_CST: 11448 1.1 mrg /* We can get here when the id-expression refers to an 11449 1.1 mrg enumerator or non-type template parameter. */ 11450 1.1 mrg type = TREE_TYPE (expr); 11451 1.1 mrg break; 11452 1.1 mrg 11453 1.1 mrg default: 11454 1.1 mrg /* Handle instantiated template non-type arguments. */ 11455 1.1 mrg type = TREE_TYPE (expr); 11456 1.1 mrg break; 11457 1.1 mrg } 11458 1.1 mrg } 11459 1.1 mrg else 11460 1.1 mrg { 11461 1.1 mrg /* Within a lambda-expression: 11462 1.1 mrg 11463 1.1 mrg Every occurrence of decltype((x)) where x is a possibly 11464 1.1 mrg parenthesized id-expression that names an entity of 11465 1.1 mrg automatic storage duration is treated as if x were 11466 1.1 mrg transformed into an access to a corresponding data member 11467 1.1 mrg of the closure type that would have been declared if x 11468 1.1 mrg were a use of the denoted entity. */ 11469 1.1 mrg if (outer_automatic_var_p (expr) 11470 1.1 mrg && current_function_decl 11471 1.1 mrg && LAMBDA_FUNCTION_P (current_function_decl)) 11472 1.1 mrg type = capture_decltype (expr); 11473 1.1 mrg else if (error_operand_p (expr)) 11474 1.1 mrg type = error_mark_node; 11475 1.1 mrg else if (expr == current_class_ptr) 11476 1.1 mrg /* If the expression is just "this", we want the 11477 1.1 mrg cv-unqualified pointer for the "this" type. */ 11478 1.1 mrg type = TYPE_MAIN_VARIANT (TREE_TYPE (expr)); 11479 1.1 mrg else 11480 1.1 mrg { 11481 1.1 mrg /* Otherwise, where T is the type of e, if e is an lvalue, 11482 1.1 mrg decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */ 11483 1.1 mrg cp_lvalue_kind clk = lvalue_kind (expr); 11484 1.1 mrg type = unlowered_expr_type (expr); 11485 1.1 mrg gcc_assert (!TYPE_REF_P (type)); 11486 1.1 mrg 11487 1.1 mrg /* For vector types, pick a non-opaque variant. */ 11488 1.1 mrg if (VECTOR_TYPE_P (type)) 11489 1.1 mrg type = strip_typedefs (type); 11490 1.1 mrg 11491 1.1 mrg if (clk != clk_none && !(clk & clk_class)) 11492 1.1 mrg type = cp_build_reference_type (type, (clk & clk_rvalueref)); 11493 1.1 mrg } 11494 1.1 mrg } 11495 1.1 mrg 11496 1.1 mrg return type; 11497 1.1 mrg } 11498 1.1 mrg 11499 1.1 mrg /* Called from trait_expr_value to evaluate either __has_nothrow_assign or 11500 1.1 mrg __has_nothrow_copy, depending on assign_p. Returns true iff all 11501 1.1 mrg the copy {ctor,assign} fns are nothrow. */ 11502 1.1 mrg 11503 1.1 mrg static bool 11504 1.1 mrg classtype_has_nothrow_assign_or_copy_p (tree type, bool assign_p) 11505 1.1 mrg { 11506 1.1 mrg tree fns = NULL_TREE; 11507 1.1 mrg 11508 1.1 mrg if (assign_p || TYPE_HAS_COPY_CTOR (type)) 11509 1.1 mrg fns = get_class_binding (type, assign_p ? assign_op_identifier 11510 1.1 mrg : ctor_identifier); 11511 1.1 mrg 11512 1.1 mrg bool saw_copy = false; 11513 1.1 mrg for (ovl_iterator iter (fns); iter; ++iter) 11514 1.1 mrg { 11515 1.1 mrg tree fn = *iter; 11516 1.1 mrg 11517 1.1 mrg if (copy_fn_p (fn) > 0) 11518 1.1 mrg { 11519 1.1 mrg saw_copy = true; 11520 1.1 mrg if (!maybe_instantiate_noexcept (fn) 11521 1.1 mrg || !TYPE_NOTHROW_P (TREE_TYPE (fn))) 11522 1.1 mrg return false; 11523 1.1 mrg } 11524 1.1 mrg } 11525 1.1 mrg 11526 1.1 mrg return saw_copy; 11527 1.1 mrg } 11528 1.1 mrg 11529 1.1 mrg /* Return true if DERIVED is pointer interconvertible base of BASE. */ 11530 1.1 mrg 11531 1.1 mrg static bool 11532 1.1 mrg pointer_interconvertible_base_of_p (tree base, tree derived) 11533 1.1 mrg { 11534 1.1 mrg if (base == error_mark_node || derived == error_mark_node) 11535 1.1 mrg return false; 11536 1.1 mrg base = TYPE_MAIN_VARIANT (base); 11537 1.1 mrg derived = TYPE_MAIN_VARIANT (derived); 11538 1.1 mrg if (!NON_UNION_CLASS_TYPE_P (base) 11539 1.1 mrg || !NON_UNION_CLASS_TYPE_P (derived)) 11540 1.1 mrg return false; 11541 1.1 mrg 11542 1.1 mrg if (same_type_p (base, derived)) 11543 1.1 mrg return true; 11544 1.1 mrg 11545 1.1 mrg if (!std_layout_type_p (derived)) 11546 1.1 mrg return false; 11547 1.1 mrg 11548 1.1 mrg return uniquely_derived_from_p (base, derived); 11549 1.1 mrg } 11550 1.1 mrg 11551 1.1 mrg /* Helper function for fold_builtin_is_pointer_inverconvertible_with_class, 11552 1.1 mrg return true if MEMBERTYPE is the type of the first non-static data member 11553 1.1 mrg of TYPE or for unions of any members. */ 11554 1.1 mrg static bool 11555 1.1 mrg first_nonstatic_data_member_p (tree type, tree membertype) 11556 1.1 mrg { 11557 1.1 mrg for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) 11558 1.1 mrg { 11559 1.1 mrg if (TREE_CODE (field) != FIELD_DECL) 11560 1.1 mrg continue; 11561 1.1 mrg if (DECL_FIELD_IS_BASE (field) && is_empty_field (field)) 11562 1.1 mrg continue; 11563 1.1 mrg if (DECL_FIELD_IS_BASE (field)) 11564 1.1 mrg return first_nonstatic_data_member_p (TREE_TYPE (field), membertype); 11565 1.1 mrg if (ANON_AGGR_TYPE_P (TREE_TYPE (field))) 11566 1.1 mrg { 11567 1.1 mrg if ((TREE_CODE (TREE_TYPE (field)) == UNION_TYPE 11568 1.1 mrg || std_layout_type_p (TREE_TYPE (field))) 11569 1.1 mrg && first_nonstatic_data_member_p (TREE_TYPE (field), membertype)) 11570 1.1 mrg return true; 11571 1.1 mrg } 11572 1.1 mrg else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field), 11573 1.1 mrg membertype)) 11574 1.1 mrg return true; 11575 1.1 mrg if (TREE_CODE (type) != UNION_TYPE) 11576 1.1 mrg return false; 11577 1.1 mrg } 11578 1.1 mrg return false; 11579 1.1 mrg } 11580 1.1 mrg 11581 1.1 mrg /* Fold __builtin_is_pointer_interconvertible_with_class call. */ 11582 1.1 mrg 11583 1.1 mrg tree 11584 1.1 mrg fold_builtin_is_pointer_inverconvertible_with_class (location_t loc, int nargs, 11585 1.1 mrg tree *args) 11586 1.1 mrg { 11587 1.1 mrg /* Unless users call the builtin directly, the following 3 checks should be 11588 1.1 mrg ensured from std::is_pointer_interconvertible_with_class function 11589 1.1 mrg template. */ 11590 1.1 mrg if (nargs != 1) 11591 1.1 mrg { 11592 1.1 mrg error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> " 11593 1.1 mrg "needs a single argument"); 11594 1.1 mrg return boolean_false_node; 11595 1.1 mrg } 11596 1.1 mrg tree arg = args[0]; 11597 1.1 mrg if (error_operand_p (arg)) 11598 1.1 mrg return boolean_false_node; 11599 1.1 mrg if (!TYPE_PTRMEM_P (TREE_TYPE (arg))) 11600 1.1 mrg { 11601 1.1 mrg error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> " 11602 1.1 mrg "argument is not pointer to member"); 11603 1.1 mrg return boolean_false_node; 11604 1.1 mrg } 11605 1.1 mrg 11606 1.1 mrg if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg))) 11607 1.1 mrg return boolean_false_node; 11608 1.1 mrg 11609 1.1 mrg tree membertype = TREE_TYPE (TREE_TYPE (arg)); 11610 1.1 mrg tree basetype = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg)); 11611 1.1 mrg if (!complete_type_or_else (basetype, NULL_TREE)) 11612 1.1 mrg return boolean_false_node; 11613 1.1 mrg 11614 1.1 mrg if (TREE_CODE (basetype) != UNION_TYPE 11615 1.1 mrg && !std_layout_type_p (basetype)) 11616 1.1 mrg return boolean_false_node; 11617 1.1 mrg 11618 1.1 mrg if (!first_nonstatic_data_member_p (basetype, membertype)) 11619 1.1 mrg return boolean_false_node; 11620 1.1 mrg 11621 1.1 mrg if (TREE_CODE (arg) == PTRMEM_CST) 11622 1.1 mrg arg = cplus_expand_constant (arg); 11623 1.1 mrg 11624 1.1 mrg if (integer_nonzerop (arg)) 11625 1.1 mrg return boolean_false_node; 11626 1.1 mrg if (integer_zerop (arg)) 11627 1.1 mrg return boolean_true_node; 11628 1.1 mrg 11629 1.1 mrg return fold_build2 (EQ_EXPR, boolean_type_node, arg, 11630 1.1 mrg build_zero_cst (TREE_TYPE (arg))); 11631 1.1 mrg } 11632 1.1 mrg 11633 1.1 mrg /* Helper function for is_corresponding_member_aggr. Return true if 11634 1.1 mrg MEMBERTYPE pointer-to-data-member ARG can be found in anonymous 11635 1.1 mrg union or structure BASETYPE. */ 11636 1.1 mrg 11637 1.1 mrg static bool 11638 1.1 mrg is_corresponding_member_union (tree basetype, tree membertype, tree arg) 11639 1.1 mrg { 11640 1.1 mrg for (tree field = TYPE_FIELDS (basetype); field; field = DECL_CHAIN (field)) 11641 1.1 mrg if (TREE_CODE (field) != FIELD_DECL || DECL_BIT_FIELD_TYPE (field)) 11642 1.1 mrg continue; 11643 1.1 mrg else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field), 11644 1.1 mrg membertype)) 11645 1.1 mrg { 11646 1.1 mrg if (TREE_CODE (arg) != INTEGER_CST 11647 1.1 mrg || tree_int_cst_equal (arg, byte_position (field))) 11648 1.1 mrg return true; 11649 1.1 mrg } 11650 1.1 mrg else if (ANON_AGGR_TYPE_P (TREE_TYPE (field))) 11651 1.1 mrg { 11652 1.1 mrg tree narg = arg; 11653 1.1 mrg if (TREE_CODE (basetype) != UNION_TYPE 11654 1.1 mrg && TREE_CODE (narg) == INTEGER_CST) 11655 1.1 mrg narg = size_binop (MINUS_EXPR, arg, byte_position (field)); 11656 1.1 mrg if (is_corresponding_member_union (TREE_TYPE (field), 11657 1.1 mrg membertype, narg)) 11658 1.1 mrg return true; 11659 1.1 mrg } 11660 1.1 mrg return false; 11661 1.1 mrg } 11662 1.1 mrg 11663 1.1 mrg /* Helper function for fold_builtin_is_corresponding_member call. 11664 1.1 mrg Return boolean_false_node if MEMBERTYPE1 BASETYPE1::*ARG1 and 11665 1.1 mrg MEMBERTYPE2 BASETYPE2::*ARG2 aren't corresponding members, 11666 1.1 mrg boolean_true_node if they are corresponding members, or for 11667 1.1 mrg non-constant ARG2 the highest member offset for corresponding 11668 1.1 mrg members. */ 11669 1.1 mrg 11670 1.1 mrg static tree 11671 1.1 mrg is_corresponding_member_aggr (location_t loc, tree basetype1, tree membertype1, 11672 1.1 mrg tree arg1, tree basetype2, tree membertype2, 11673 1.1 mrg tree arg2) 11674 1.1 mrg { 11675 1.1 mrg tree field1 = TYPE_FIELDS (basetype1); 11676 1.1 mrg tree field2 = TYPE_FIELDS (basetype2); 11677 1.1 mrg tree ret = boolean_false_node; 11678 1.1 mrg while (1) 11679 1.1 mrg { 11680 1.1 mrg bool r = next_common_initial_sequence (field1, field2); 11681 1.1 mrg if (field1 == NULL_TREE || field2 == NULL_TREE) 11682 1.1 mrg break; 11683 1.1 mrg if (r 11684 1.1 mrg && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field1), 11685 1.1 mrg membertype1) 11686 1.1 mrg && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field2), 11687 1.1 mrg membertype2)) 11688 1.1 mrg { 11689 1.1 mrg tree pos = byte_position (field1); 11690 1.1 mrg if (TREE_CODE (arg1) == INTEGER_CST 11691 1.1 mrg && tree_int_cst_equal (arg1, pos)) 11692 1.1 mrg { 11693 1.1 mrg if (TREE_CODE (arg2) == INTEGER_CST) 11694 1.1 mrg return boolean_true_node; 11695 1.1 mrg return pos; 11696 1.1 mrg } 11697 1.1 mrg else if (TREE_CODE (arg1) != INTEGER_CST) 11698 1.1 mrg ret = pos; 11699 1.1 mrg } 11700 1.1 mrg else if (ANON_AGGR_TYPE_P (TREE_TYPE (field1)) 11701 1.1 mrg && ANON_AGGR_TYPE_P (TREE_TYPE (field2))) 11702 1.1 mrg { 11703 1.1 mrg if ((!lookup_attribute ("no_unique_address", 11704 1.1 mrg DECL_ATTRIBUTES (field1))) 11705 1.1 mrg != !lookup_attribute ("no_unique_address", 11706 1.1 mrg DECL_ATTRIBUTES (field2))) 11707 1.1 mrg break; 11708 1.1 mrg if (!tree_int_cst_equal (bit_position (field1), 11709 1.1 mrg bit_position (field2))) 11710 1.1 mrg break; 11711 1.1 mrg bool overlap = true; 11712 1.1 mrg tree pos = byte_position (field1); 11713 1.1 mrg if (TREE_CODE (arg1) == INTEGER_CST) 11714 1.1 mrg { 11715 1.1 mrg tree off1 = fold_convert (sizetype, arg1); 11716 1.1 mrg tree sz1 = TYPE_SIZE_UNIT (TREE_TYPE (field1)); 11717 1.1 mrg if (tree_int_cst_lt (off1, pos) 11718 1.1 mrg || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz1), off1)) 11719 1.1 mrg overlap = false; 11720 1.1 mrg } 11721 1.1 mrg if (TREE_CODE (arg2) == INTEGER_CST) 11722 1.1 mrg { 11723 1.1 mrg tree off2 = fold_convert (sizetype, arg2); 11724 1.1 mrg tree sz2 = TYPE_SIZE_UNIT (TREE_TYPE (field2)); 11725 1.1 mrg if (tree_int_cst_lt (off2, pos) 11726 1.1 mrg || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz2), off2)) 11727 1.1 mrg overlap = false; 11728 1.1 mrg } 11729 1.1 mrg if (overlap 11730 1.1 mrg && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field1)) 11731 1.1 mrg && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field2))) 11732 1.1 mrg { 11733 1.1 mrg tree narg1 = arg1; 11734 1.1 mrg if (TREE_CODE (arg1) == INTEGER_CST) 11735 1.1 mrg narg1 = size_binop (MINUS_EXPR, 11736 1.1 mrg fold_convert (sizetype, arg1), pos); 11737 1.1 mrg tree narg2 = arg2; 11738 1.1 mrg if (TREE_CODE (arg2) == INTEGER_CST) 11739 1.1 mrg narg2 = size_binop (MINUS_EXPR, 11740 1.1 mrg fold_convert (sizetype, arg2), pos); 11741 1.1 mrg tree t1 = TREE_TYPE (field1); 11742 1.1 mrg tree t2 = TREE_TYPE (field2); 11743 1.1 mrg tree nret = is_corresponding_member_aggr (loc, t1, membertype1, 11744 1.1 mrg narg1, t2, membertype2, 11745 1.1 mrg narg2); 11746 1.1 mrg if (nret != boolean_false_node) 11747 1.1 mrg { 11748 1.1 mrg if (nret == boolean_true_node) 11749 1.1 mrg return nret; 11750 1.1 mrg if (TREE_CODE (arg1) == INTEGER_CST) 11751 1.1 mrg return size_binop (PLUS_EXPR, nret, pos); 11752 1.1 mrg ret = size_binop (PLUS_EXPR, nret, pos); 11753 1.1 mrg } 11754 1.1 mrg } 11755 1.1 mrg else if (overlap 11756 1.1 mrg && TREE_CODE (TREE_TYPE (field1)) == UNION_TYPE 11757 1.1 mrg && TREE_CODE (TREE_TYPE (field2)) == UNION_TYPE) 11758 1.1 mrg { 11759 1.1 mrg tree narg1 = arg1; 11760 1.1 mrg if (TREE_CODE (arg1) == INTEGER_CST) 11761 1.1 mrg narg1 = size_binop (MINUS_EXPR, 11762 1.1 mrg fold_convert (sizetype, arg1), pos); 11763 1.1 mrg tree narg2 = arg2; 11764 1.1 mrg if (TREE_CODE (arg2) == INTEGER_CST) 11765 1.1 mrg narg2 = size_binop (MINUS_EXPR, 11766 1.1 mrg fold_convert (sizetype, arg2), pos); 11767 1.1 mrg if (is_corresponding_member_union (TREE_TYPE (field1), 11768 1.1 mrg membertype1, narg1) 11769 1.1 mrg && is_corresponding_member_union (TREE_TYPE (field2), 11770 1.1 mrg membertype2, narg2)) 11771 1.1 mrg { 11772 1.1 mrg sorry_at (loc, "%<__builtin_is_corresponding_member%> " 11773 1.1 mrg "not well defined for anonymous unions"); 11774 1.1 mrg return boolean_false_node; 11775 1.1 mrg } 11776 1.1 mrg } 11777 1.1 mrg } 11778 1.1 mrg if (!r) 11779 1.1 mrg break; 11780 1.1 mrg field1 = DECL_CHAIN (field1); 11781 1.1 mrg field2 = DECL_CHAIN (field2); 11782 1.1 mrg } 11783 1.1 mrg return ret; 11784 1.1 mrg } 11785 1.1 mrg 11786 1.1 mrg /* Fold __builtin_is_corresponding_member call. */ 11787 1.1 mrg 11788 1.1 mrg tree 11789 1.1 mrg fold_builtin_is_corresponding_member (location_t loc, int nargs, 11790 1.1 mrg tree *args) 11791 1.1 mrg { 11792 1.1 mrg /* Unless users call the builtin directly, the following 3 checks should be 11793 1.1 mrg ensured from std::is_corresponding_member function template. */ 11794 1.1 mrg if (nargs != 2) 11795 1.1 mrg { 11796 1.1 mrg error_at (loc, "%<__builtin_is_corresponding_member%> " 11797 1.1 mrg "needs two arguments"); 11798 1.1 mrg return boolean_false_node; 11799 1.1 mrg } 11800 1.1 mrg tree arg1 = args[0]; 11801 1.1 mrg tree arg2 = args[1]; 11802 1.1 mrg if (error_operand_p (arg1) || error_operand_p (arg2)) 11803 1.1 mrg return boolean_false_node; 11804 1.1 mrg if (!TYPE_PTRMEM_P (TREE_TYPE (arg1)) 11805 1.1 mrg || !TYPE_PTRMEM_P (TREE_TYPE (arg2))) 11806 1.1 mrg { 11807 1.1 mrg error_at (loc, "%<__builtin_is_corresponding_member%> " 11808 1.1 mrg "argument is not pointer to member"); 11809 1.1 mrg return boolean_false_node; 11810 1.1 mrg } 11811 1.1 mrg 11812 1.1 mrg if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg1)) 11813 1.1 mrg || !TYPE_PTRDATAMEM_P (TREE_TYPE (arg2))) 11814 1.1 mrg return boolean_false_node; 11815 1.1 mrg 11816 1.1 mrg tree membertype1 = TREE_TYPE (TREE_TYPE (arg1)); 11817 1.1 mrg tree basetype1 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg1)); 11818 1.1 mrg if (!complete_type_or_else (basetype1, NULL_TREE)) 11819 1.1 mrg return boolean_false_node; 11820 1.1 mrg 11821 1.1 mrg tree membertype2 = TREE_TYPE (TREE_TYPE (arg2)); 11822 1.1 mrg tree basetype2 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg2)); 11823 1.1 mrg if (!complete_type_or_else (basetype2, NULL_TREE)) 11824 1.1 mrg return boolean_false_node; 11825 1.1 mrg 11826 1.1 mrg if (!NON_UNION_CLASS_TYPE_P (basetype1) 11827 1.1 mrg || !NON_UNION_CLASS_TYPE_P (basetype2) 11828 1.1 mrg || !std_layout_type_p (basetype1) 11829 1.1 mrg || !std_layout_type_p (basetype2)) 11830 1.1 mrg return boolean_false_node; 11831 1.1 mrg 11832 1.1 mrg /* If the member types aren't layout compatible, then they 11833 1.1 mrg can't be corresponding members. */ 11834 1.1 mrg if (!layout_compatible_type_p (membertype1, membertype2)) 11835 1.1 mrg return boolean_false_node; 11836 1.1 mrg 11837 1.1 mrg if (TREE_CODE (arg1) == PTRMEM_CST) 11838 1.1 mrg arg1 = cplus_expand_constant (arg1); 11839 1.1 mrg if (TREE_CODE (arg2) == PTRMEM_CST) 11840 1.1 mrg arg2 = cplus_expand_constant (arg2); 11841 1.1 mrg 11842 1.1 mrg if (null_member_pointer_value_p (arg1) 11843 1.1 mrg || null_member_pointer_value_p (arg2)) 11844 1.1 mrg return boolean_false_node; 11845 1.1 mrg 11846 1.1 mrg if (TREE_CODE (arg1) == INTEGER_CST 11847 1.1 mrg && TREE_CODE (arg2) == INTEGER_CST 11848 1.1 mrg && !tree_int_cst_equal (arg1, arg2)) 11849 1.1 mrg return boolean_false_node; 11850 1.1 mrg 11851 1.1 mrg if (TREE_CODE (arg2) == INTEGER_CST 11852 1.1 mrg && TREE_CODE (arg1) != INTEGER_CST) 11853 1.1 mrg { 11854 1.1 mrg std::swap (arg1, arg2); 11855 1.1 mrg std::swap (membertype1, membertype2); 11856 1.1 mrg std::swap (basetype1, basetype2); 11857 1.1 mrg } 11858 1.1 mrg 11859 1.1 mrg tree ret = is_corresponding_member_aggr (loc, basetype1, membertype1, arg1, 11860 1.1 mrg basetype2, membertype2, arg2); 11861 1.1 mrg if (TREE_TYPE (ret) == boolean_type_node) 11862 1.1 mrg return ret; 11863 1.1 mrg /* If both arg1 and arg2 are INTEGER_CSTs, is_corresponding_member_aggr 11864 1.1 mrg already returns boolean_{true,false}_node whether those particular 11865 1.1 mrg members are corresponding members or not. Otherwise, if only 11866 1.1 mrg one of them is INTEGER_CST (canonicalized to first being INTEGER_CST 11867 1.1 mrg above), it returns boolean_false_node if it is certainly not a 11868 1.1 mrg corresponding member and otherwise we need to do a runtime check that 11869 1.1 mrg those two OFFSET_TYPE offsets are equal. 11870 1.1 mrg If neither of the operands is INTEGER_CST, is_corresponding_member_aggr 11871 1.1 mrg returns the largest offset at which the members would be corresponding 11872 1.1 mrg members, so perform arg1 <= ret && arg1 == arg2 runtime check. */ 11873 1.1 mrg gcc_assert (TREE_CODE (arg2) != INTEGER_CST); 11874 1.1 mrg if (TREE_CODE (arg1) == INTEGER_CST) 11875 1.1 mrg return fold_build2 (EQ_EXPR, boolean_type_node, arg1, 11876 1.1 mrg fold_convert (TREE_TYPE (arg1), arg2)); 11877 1.1 mrg ret = fold_build2 (LE_EXPR, boolean_type_node, 11878 1.1 mrg fold_convert (pointer_sized_int_node, arg1), 11879 1.1 mrg fold_convert (pointer_sized_int_node, ret)); 11880 1.1 mrg return fold_build2 (TRUTH_AND_EXPR, boolean_type_node, ret, 11881 1.1 mrg fold_build2 (EQ_EXPR, boolean_type_node, arg1, 11882 1.1 mrg fold_convert (TREE_TYPE (arg1), arg2))); 11883 1.1 mrg } 11884 1.1 mrg 11885 1.1 mrg /* Actually evaluates the trait. */ 11886 1.1 mrg 11887 1.1 mrg static bool 11888 1.1 mrg trait_expr_value (cp_trait_kind kind, tree type1, tree type2) 11889 1.1 mrg { 11890 1.1 mrg enum tree_code type_code1; 11891 1.1 mrg tree t; 11892 1.1 mrg 11893 1.1 mrg type_code1 = TREE_CODE (type1); 11894 1.1 mrg 11895 1.1 mrg switch (kind) 11896 1.1 mrg { 11897 1.1 mrg case CPTK_HAS_NOTHROW_ASSIGN: 11898 1.1 mrg type1 = strip_array_types (type1); 11899 1.1 mrg return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE 11900 1.1 mrg && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN, type1, type2) 11901 1.1 mrg || (CLASS_TYPE_P (type1) 11902 1.1 mrg && classtype_has_nothrow_assign_or_copy_p (type1, 11903 1.1 mrg true)))); 11904 1.1 mrg 11905 1.1 mrg case CPTK_HAS_TRIVIAL_ASSIGN: 11906 1.1 mrg /* ??? The standard seems to be missing the "or array of such a class 11907 1.1 mrg type" wording for this trait. */ 11908 1.1 mrg type1 = strip_array_types (type1); 11909 1.1 mrg return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE 11910 1.1 mrg && (trivial_type_p (type1) 11911 1.1 mrg || (CLASS_TYPE_P (type1) 11912 1.1 mrg && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1)))); 11913 1.1 mrg 11914 1.1 mrg case CPTK_HAS_NOTHROW_CONSTRUCTOR: 11915 1.1 mrg type1 = strip_array_types (type1); 11916 1.1 mrg return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR, type1, type2) 11917 1.1 mrg || (CLASS_TYPE_P (type1) 11918 1.1 mrg && (t = locate_ctor (type1)) 11919 1.1 mrg && maybe_instantiate_noexcept (t) 11920 1.1 mrg && TYPE_NOTHROW_P (TREE_TYPE (t)))); 11921 1.1 mrg 11922 1.1 mrg case CPTK_HAS_TRIVIAL_CONSTRUCTOR: 11923 1.1 mrg type1 = strip_array_types (type1); 11924 1.1 mrg return (trivial_type_p (type1) 11925 1.1 mrg || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DFLT (type1))); 11926 1.1 mrg 11927 1.1 mrg case CPTK_HAS_NOTHROW_COPY: 11928 1.1 mrg type1 = strip_array_types (type1); 11929 1.1 mrg return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY, type1, type2) 11930 1.1 mrg || (CLASS_TYPE_P (type1) 11931 1.1 mrg && classtype_has_nothrow_assign_or_copy_p (type1, false))); 11932 1.1 mrg 11933 1.1 mrg case CPTK_HAS_TRIVIAL_COPY: 11934 1.1 mrg /* ??? The standard seems to be missing the "or array of such a class 11935 1.1 mrg type" wording for this trait. */ 11936 1.1 mrg type1 = strip_array_types (type1); 11937 1.1 mrg return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE 11938 1.1 mrg || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1))); 11939 1.1 mrg 11940 1.1 mrg case CPTK_HAS_TRIVIAL_DESTRUCTOR: 11941 1.1 mrg type1 = strip_array_types (type1); 11942 1.1 mrg return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE 11943 1.1 mrg || (CLASS_TYPE_P (type1) 11944 1.1 mrg && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1))); 11945 1.1 mrg 11946 1.1 mrg case CPTK_HAS_VIRTUAL_DESTRUCTOR: 11947 1.1 mrg return type_has_virtual_destructor (type1); 11948 1.1 mrg 11949 1.1 mrg case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS: 11950 1.1 mrg return type_has_unique_obj_representations (type1); 11951 1.1 mrg 11952 1.1 mrg case CPTK_IS_ABSTRACT: 11953 1.1 mrg return ABSTRACT_CLASS_TYPE_P (type1); 11954 1.1 mrg 11955 1.1 mrg case CPTK_IS_AGGREGATE: 11956 1.1 mrg return CP_AGGREGATE_TYPE_P (type1); 11957 1.1 mrg 11958 1.1 mrg case CPTK_IS_BASE_OF: 11959 1.1 mrg return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2) 11960 1.1 mrg && (same_type_ignoring_top_level_qualifiers_p (type1, type2) 11961 1.1 mrg || DERIVED_FROM_P (type1, type2))); 11962 1.1 mrg 11963 1.1 mrg case CPTK_IS_CLASS: 11964 1.1 mrg return NON_UNION_CLASS_TYPE_P (type1); 11965 1.1 mrg 11966 1.1 mrg case CPTK_IS_EMPTY: 11967 1.1 mrg return NON_UNION_CLASS_TYPE_P (type1) && CLASSTYPE_EMPTY_P (type1); 11968 1.1 mrg 11969 1.1 mrg case CPTK_IS_ENUM: 11970 1.1 mrg return type_code1 == ENUMERAL_TYPE; 11971 1.1 mrg 11972 1.1 mrg case CPTK_IS_FINAL: 11973 1.1 mrg return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1); 11974 1.1 mrg 11975 1.1 mrg case CPTK_IS_LAYOUT_COMPATIBLE: 11976 1.1 mrg return layout_compatible_type_p (type1, type2); 11977 1.1 mrg 11978 1.1 mrg case CPTK_IS_LITERAL_TYPE: 11979 1.1 mrg return literal_type_p (type1); 11980 1.1 mrg 11981 1.1 mrg case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF: 11982 1.1 mrg return pointer_interconvertible_base_of_p (type1, type2); 11983 1.1 mrg 11984 1.1 mrg case CPTK_IS_POD: 11985 1.1 mrg return pod_type_p (type1); 11986 1.1 mrg 11987 1.1 mrg case CPTK_IS_POLYMORPHIC: 11988 1.1 mrg return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1); 11989 1.1 mrg 11990 1.1 mrg case CPTK_IS_SAME_AS: 11991 1.1 mrg return same_type_p (type1, type2); 11992 1.1 mrg 11993 1.1 mrg case CPTK_IS_STD_LAYOUT: 11994 1.1 mrg return std_layout_type_p (type1); 11995 1.1 mrg 11996 1.1 mrg case CPTK_IS_TRIVIAL: 11997 1.1 mrg return trivial_type_p (type1); 11998 1.1 mrg 11999 1.1 mrg case CPTK_IS_TRIVIALLY_ASSIGNABLE: 12000 1.1 mrg return is_trivially_xible (MODIFY_EXPR, type1, type2); 12001 1.1 mrg 12002 1.1 mrg case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: 12003 1.1 mrg return is_trivially_xible (INIT_EXPR, type1, type2); 12004 1.1 mrg 12005 1.1 mrg case CPTK_IS_TRIVIALLY_COPYABLE: 12006 1.1 mrg return trivially_copyable_p (type1); 12007 1.1 mrg 12008 1.1 mrg case CPTK_IS_UNION: 12009 1.1 mrg return type_code1 == UNION_TYPE; 12010 1.1 mrg 12011 1.1 mrg case CPTK_IS_ASSIGNABLE: 12012 1.1 mrg return is_xible (MODIFY_EXPR, type1, type2); 12013 1.1 mrg 12014 1.1 mrg case CPTK_IS_CONSTRUCTIBLE: 12015 1.1 mrg return is_xible (INIT_EXPR, type1, type2); 12016 1.1 mrg 12017 1.1 mrg case CPTK_IS_NOTHROW_ASSIGNABLE: 12018 1.1 mrg return is_nothrow_xible (MODIFY_EXPR, type1, type2); 12019 1.1 mrg 12020 1.1 mrg case CPTK_IS_NOTHROW_CONSTRUCTIBLE: 12021 1.1 mrg return is_nothrow_xible (INIT_EXPR, type1, type2); 12022 1.1 mrg 12023 1.1 mrg default: 12024 1.1 mrg gcc_unreachable (); 12025 1.1 mrg return false; 12026 1.1 mrg } 12027 1.1 mrg } 12028 1.1 mrg 12029 1.1 mrg /* If TYPE is an array of unknown bound, or (possibly cv-qualified) 12030 1.1 mrg void, or a complete type, returns true, otherwise false. */ 12031 1.1 mrg 12032 1.1 mrg static bool 12033 1.1 mrg check_trait_type (tree type) 12034 1.1 mrg { 12035 1.1 mrg if (type == NULL_TREE) 12036 1.1 mrg return true; 12037 1.1 mrg 12038 1.1 mrg if (TREE_CODE (type) == TREE_LIST) 12039 1.1 mrg return (check_trait_type (TREE_VALUE (type)) 12040 1.1 mrg && check_trait_type (TREE_CHAIN (type))); 12041 1.1 mrg 12042 1.1 mrg if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type) 12043 1.1 mrg && COMPLETE_TYPE_P (TREE_TYPE (type))) 12044 1.1 mrg return true; 12045 1.1 mrg 12046 1.1 mrg if (VOID_TYPE_P (type)) 12047 1.1 mrg return true; 12048 1.1 mrg 12049 1.1 mrg return !!complete_type_or_else (strip_array_types (type), NULL_TREE); 12050 1.1 mrg } 12051 1.1 mrg 12052 1.1 mrg /* True iff the conversion (if any) would be a direct reference 12053 1.1 mrg binding, not requiring complete types. This is LWG2939. */ 12054 1.1 mrg 12055 1.1 mrg static bool 12056 1.1 mrg same_type_ref_bind_p (cp_trait_kind kind, tree type1, tree type2) 12057 1.1 mrg { 12058 1.1 mrg tree from, to; 12059 1.1 mrg switch (kind) 12060 1.1 mrg { 12061 1.1 mrg /* These put the target type first. */ 12062 1.1 mrg case CPTK_IS_CONSTRUCTIBLE: 12063 1.1 mrg case CPTK_IS_NOTHROW_CONSTRUCTIBLE: 12064 1.1 mrg case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: 12065 1.1 mrg to = type1; 12066 1.1 mrg from = type2; 12067 1.1 mrg break; 12068 1.1 mrg 12069 1.1 mrg default: 12070 1.1 mrg gcc_unreachable (); 12071 1.1 mrg } 12072 1.1 mrg 12073 1.1 mrg if (TREE_CODE (to) != REFERENCE_TYPE || !from) 12074 1.1 mrg return false; 12075 1.1 mrg if (TREE_CODE (from) == TREE_VEC && TREE_VEC_LENGTH (from) == 1) 12076 1.1 mrg from = TREE_VEC_ELT (from, 0); 12077 1.1 mrg else if (TREE_CODE (from) == TREE_LIST && !TREE_CHAIN (from)) 12078 1.1 mrg from = TREE_VALUE (from); 12079 1.1 mrg return (TYPE_P (from) 12080 1.1 mrg && (same_type_ignoring_top_level_qualifiers_p 12081 1.1 mrg (non_reference (to), non_reference (from)))); 12082 1.1 mrg } 12083 1.1 mrg 12084 1.1 mrg /* Process a trait expression. */ 12085 1.1 mrg 12086 1.1 mrg tree 12087 1.1 mrg finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) 12088 1.1 mrg { 12089 1.1 mrg if (type1 == error_mark_node 12090 1.1 mrg || type2 == error_mark_node) 12091 1.1 mrg return error_mark_node; 12092 1.1 mrg 12093 1.1 mrg if (processing_template_decl) 12094 1.1 mrg { 12095 1.1 mrg tree trait_expr = make_node (TRAIT_EXPR); 12096 1.1 mrg TREE_TYPE (trait_expr) = boolean_type_node; 12097 1.1 mrg TRAIT_EXPR_TYPE1 (trait_expr) = type1; 12098 1.1 mrg TRAIT_EXPR_TYPE2 (trait_expr) = type2; 12099 1.1 mrg TRAIT_EXPR_KIND (trait_expr) = kind; 12100 1.1 mrg TRAIT_EXPR_LOCATION (trait_expr) = loc; 12101 1.1 mrg return trait_expr; 12102 1.1 mrg } 12103 1.1 mrg 12104 1.1 mrg switch (kind) 12105 1.1 mrg { 12106 1.1 mrg case CPTK_HAS_NOTHROW_ASSIGN: 12107 1.1 mrg case CPTK_HAS_TRIVIAL_ASSIGN: 12108 1.1 mrg case CPTK_HAS_NOTHROW_CONSTRUCTOR: 12109 1.1 mrg case CPTK_HAS_TRIVIAL_CONSTRUCTOR: 12110 1.1 mrg case CPTK_HAS_NOTHROW_COPY: 12111 1.1 mrg case CPTK_HAS_TRIVIAL_COPY: 12112 1.1 mrg case CPTK_HAS_TRIVIAL_DESTRUCTOR: 12113 1.1 mrg case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS: 12114 1.1 mrg case CPTK_HAS_VIRTUAL_DESTRUCTOR: 12115 1.1 mrg case CPTK_IS_ABSTRACT: 12116 1.1 mrg case CPTK_IS_AGGREGATE: 12117 1.1 mrg case CPTK_IS_EMPTY: 12118 1.1 mrg case CPTK_IS_FINAL: 12119 1.1 mrg case CPTK_IS_LITERAL_TYPE: 12120 1.1 mrg case CPTK_IS_POD: 12121 1.1 mrg case CPTK_IS_POLYMORPHIC: 12122 1.1 mrg case CPTK_IS_STD_LAYOUT: 12123 1.1 mrg case CPTK_IS_TRIVIAL: 12124 1.1 mrg case CPTK_IS_TRIVIALLY_COPYABLE: 12125 1.1 mrg if (!check_trait_type (type1)) 12126 1.1 mrg return error_mark_node; 12127 1.1 mrg break; 12128 1.1 mrg 12129 1.1 mrg case CPTK_IS_ASSIGNABLE: 12130 1.1 mrg case CPTK_IS_CONSTRUCTIBLE: 12131 1.1 mrg break; 12132 1.1 mrg 12133 1.1 mrg case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: 12134 1.1 mrg case CPTK_IS_NOTHROW_CONSTRUCTIBLE: 12135 1.1 mrg /* Don't check completeness for direct reference binding. */; 12136 1.1 mrg if (same_type_ref_bind_p (kind, type1, type2)) 12137 1.1 mrg break; 12138 1.1 mrg gcc_fallthrough (); 12139 1.1 mrg 12140 1.1 mrg case CPTK_IS_NOTHROW_ASSIGNABLE: 12141 1.1 mrg case CPTK_IS_TRIVIALLY_ASSIGNABLE: 12142 1.1 mrg if (!check_trait_type (type1) 12143 1.1 mrg || !check_trait_type (type2)) 12144 1.1 mrg return error_mark_node; 12145 1.1 mrg break; 12146 1.1 mrg 12147 1.1 mrg case CPTK_IS_BASE_OF: 12148 1.1 mrg case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF: 12149 1.1 mrg if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2) 12150 1.1 mrg && !same_type_ignoring_top_level_qualifiers_p (type1, type2) 12151 1.1 mrg && !complete_type_or_else (type2, NULL_TREE)) 12152 1.1 mrg /* We already issued an error. */ 12153 1.1 mrg return error_mark_node; 12154 1.1 mrg break; 12155 1.1 mrg 12156 1.1 mrg case CPTK_IS_CLASS: 12157 1.1 mrg case CPTK_IS_ENUM: 12158 1.1 mrg case CPTK_IS_UNION: 12159 1.1 mrg case CPTK_IS_SAME_AS: 12160 1.1 mrg break; 12161 1.1 mrg 12162 1.1 mrg case CPTK_IS_LAYOUT_COMPATIBLE: 12163 1.1 mrg if (!array_of_unknown_bound_p (type1) 12164 1.1 mrg && TREE_CODE (type1) != VOID_TYPE 12165 1.1 mrg && !complete_type_or_else (type1, NULL_TREE)) 12166 1.1 mrg /* We already issued an error. */ 12167 1.1 mrg return error_mark_node; 12168 1.1 mrg if (!array_of_unknown_bound_p (type2) 12169 1.1 mrg && TREE_CODE (type2) != VOID_TYPE 12170 1.1 mrg && !complete_type_or_else (type2, NULL_TREE)) 12171 1.1 mrg /* We already issued an error. */ 12172 1.1 mrg return error_mark_node; 12173 1.1 mrg break; 12174 1.1 mrg 12175 1.1 mrg default: 12176 1.1 mrg gcc_unreachable (); 12177 1.1 mrg } 12178 1.1 mrg 12179 1.1 mrg tree val = (trait_expr_value (kind, type1, type2) 12180 1.1 mrg ? boolean_true_node : boolean_false_node); 12181 1.1 mrg return maybe_wrap_with_location (val, loc); 12182 1.1 mrg } 12183 1.1 mrg 12184 1.1 mrg /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64, 12185 1.1 mrg which is ignored for C++. */ 12186 1.1 mrg 12187 1.1 mrg void 12188 1.1 mrg set_float_const_decimal64 (void) 12189 1.1 mrg { 12190 1.1 mrg } 12191 1.1 mrg 12192 1.1 mrg void 12193 1.1 mrg clear_float_const_decimal64 (void) 12194 1.1 mrg { 12195 1.1 mrg } 12196 1.1 mrg 12197 1.1 mrg bool 12198 1.1 mrg float_const_decimal64_p (void) 12199 1.1 mrg { 12200 1.1 mrg return 0; 12201 1.1 mrg } 12202 1.1 mrg 12203 1.1 mrg 12204 1.1 mrg /* Return true if T designates the implied `this' parameter. */ 12206 1.1 mrg 12207 1.1 mrg bool 12208 1.1 mrg is_this_parameter (tree t) 12209 1.1 mrg { 12210 1.1 mrg if (!DECL_P (t) || DECL_NAME (t) != this_identifier) 12211 1.1 mrg return false; 12212 1.1 mrg gcc_assert (TREE_CODE (t) == PARM_DECL 12213 1.1 mrg || (TREE_CODE (t) == VAR_DECL && DECL_HAS_VALUE_EXPR_P (t)) 12214 1.1 mrg || (cp_binding_oracle && TREE_CODE (t) == VAR_DECL)); 12215 1.1 mrg return true; 12216 1.1 mrg } 12217 1.1 mrg 12218 1.1 mrg /* Insert the deduced return type for an auto function. */ 12219 1.1 mrg 12220 1.1 mrg void 12221 1.1 mrg apply_deduced_return_type (tree fco, tree return_type) 12222 1.1 mrg { 12223 1.1 mrg tree result; 12224 1.1 mrg 12225 1.1 mrg if (return_type == error_mark_node) 12226 1.1 mrg return; 12227 1.1 mrg 12228 1.1 mrg if (DECL_CONV_FN_P (fco)) 12229 1.1 mrg DECL_NAME (fco) = make_conv_op_name (return_type); 12230 1.1 mrg 12231 1.1 mrg TREE_TYPE (fco) = change_return_type (return_type, TREE_TYPE (fco)); 12232 1.1 mrg 12233 1.1 mrg result = DECL_RESULT (fco); 12234 1.1 mrg if (result == NULL_TREE) 12235 1.1 mrg return; 12236 1.1 mrg if (TREE_TYPE (result) == return_type) 12237 1.1 mrg return; 12238 1.1 mrg 12239 1.1 mrg if (!processing_template_decl && !VOID_TYPE_P (return_type) 12240 1.1 mrg && !complete_type_or_else (return_type, NULL_TREE)) 12241 1.1 mrg return; 12242 1.1 mrg 12243 1.1 mrg /* We already have a DECL_RESULT from start_preparsed_function. 12244 1.1 mrg Now we need to redo the work it and allocate_struct_function 12245 1.1 mrg did to reflect the new type. */ 12246 1.1 mrg gcc_assert (current_function_decl == fco); 12247 1.1 mrg result = build_decl (input_location, RESULT_DECL, NULL_TREE, 12248 1.1 mrg TYPE_MAIN_VARIANT (return_type)); 12249 1.1 mrg DECL_ARTIFICIAL (result) = 1; 12250 1.1 mrg DECL_IGNORED_P (result) = 1; 12251 1.1 mrg cp_apply_type_quals_to_decl (cp_type_quals (return_type), 12252 1.1 mrg result); 12253 1.1 mrg 12254 1.1 mrg DECL_RESULT (fco) = result; 12255 1.1 mrg 12256 1.1 mrg if (!processing_template_decl) 12257 1.1 mrg { 12258 1.1 mrg bool aggr = aggregate_value_p (result, fco); 12259 1.1 mrg #ifdef PCC_STATIC_STRUCT_RETURN 12260 1.1 mrg cfun->returns_pcc_struct = aggr; 12261 1.1 mrg #endif 12262 1.1 mrg cfun->returns_struct = aggr; 12263 1.1 mrg } 12264 1.1 mrg } 12265 1.1 mrg 12266 1.1 mrg /* DECL is a local variable or parameter from the surrounding scope of a 12267 1.1 mrg lambda-expression. Returns the decltype for a use of the capture field 12268 1.1 mrg for DECL even if it hasn't been captured yet. */ 12269 1.1 mrg 12270 1.1 mrg static tree 12271 1.1 mrg capture_decltype (tree decl) 12272 1.1 mrg { 12273 1.1 mrg tree lam = CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (current_function_decl)); 12274 1.1 mrg tree cap = lookup_name (DECL_NAME (decl), LOOK_where::BLOCK, 12275 1.1 mrg LOOK_want::HIDDEN_LAMBDA); 12276 1.1 mrg tree type; 12277 1.1 mrg 12278 1.1 mrg if (cap && is_capture_proxy (cap)) 12279 1.1 mrg type = TREE_TYPE (cap); 12280 1.1 mrg else 12281 1.1 mrg switch (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam)) 12282 1.1 mrg { 12283 1.1 mrg case CPLD_NONE: 12284 1.1 mrg error ("%qD is not captured", decl); 12285 1.1 mrg return error_mark_node; 12286 1.1 mrg 12287 1.1 mrg case CPLD_COPY: 12288 1.1 mrg type = TREE_TYPE (decl); 12289 1.1 mrg if (TYPE_REF_P (type) 12290 1.1 mrg && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE) 12291 1.1 mrg type = TREE_TYPE (type); 12292 1.1 mrg break; 12293 1.1 mrg 12294 1.1 mrg case CPLD_REFERENCE: 12295 1.1 mrg type = TREE_TYPE (decl); 12296 1.1 mrg if (!TYPE_REF_P (type)) 12297 1.1 mrg type = build_reference_type (TREE_TYPE (decl)); 12298 1.1 mrg break; 12299 1.1 mrg 12300 1.1 mrg default: 12301 1.1 mrg gcc_unreachable (); 12302 1.1 mrg } 12303 1.1 mrg 12304 1.1 mrg if (!TYPE_REF_P (type)) 12305 1.1 mrg { 12306 1.1 mrg if (!LAMBDA_EXPR_MUTABLE_P (lam)) 12307 1.1 mrg type = cp_build_qualified_type (type, (cp_type_quals (type) 12308 1.1 mrg |TYPE_QUAL_CONST)); 12309 1.1 mrg type = build_reference_type (type); 12310 1.1 mrg } 12311 1.1 mrg return type; 12312 1.1 mrg } 12313 1.1 mrg 12314 1.1 mrg /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true, 12315 1.1 mrg this is a right unary fold. Otherwise it is a left unary fold. */ 12316 1.1 mrg 12317 1.1 mrg static tree 12318 1.1 mrg finish_unary_fold_expr (tree expr, int op, tree_code dir) 12319 1.1 mrg { 12320 1.1 mrg /* Build a pack expansion (assuming expr has pack type). */ 12321 1.1 mrg if (!uses_parameter_packs (expr)) 12322 1.1 mrg { 12323 1.1 mrg error_at (location_of (expr), "operand of fold expression has no " 12324 1.1 mrg "unexpanded parameter packs"); 12325 1.1 mrg return error_mark_node; 12326 1.1 mrg } 12327 1.1 mrg tree pack = make_pack_expansion (expr); 12328 1.1 mrg 12329 1.1 mrg /* Build the fold expression. */ 12330 1.1 mrg tree code = build_int_cstu (integer_type_node, abs (op)); 12331 1.1 mrg tree fold = build_min_nt_loc (input_location, dir, code, pack); 12332 1.1 mrg FOLD_EXPR_MODIFY_P (fold) = (op < 0); 12333 1.1 mrg TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE, 12334 1.1 mrg FOLD_EXPR_OP (fold), 12335 1.1 mrg FOLD_EXPR_MODIFY_P (fold)); 12336 1.1 mrg return fold; 12337 1.1 mrg } 12338 1.1 mrg 12339 1.1 mrg tree 12340 1.1 mrg finish_left_unary_fold_expr (tree expr, int op) 12341 1.1 mrg { 12342 1.1 mrg return finish_unary_fold_expr (expr, op, UNARY_LEFT_FOLD_EXPR); 12343 1.1 mrg } 12344 1.1 mrg 12345 1.1 mrg tree 12346 1.1 mrg finish_right_unary_fold_expr (tree expr, int op) 12347 1.1 mrg { 12348 1.1 mrg return finish_unary_fold_expr (expr, op, UNARY_RIGHT_FOLD_EXPR); 12349 1.1 mrg } 12350 1.1 mrg 12351 1.1 mrg /* Build a binary fold expression over EXPR1 and EXPR2. The 12352 1.1 mrg associativity of the fold is determined by EXPR1 and EXPR2 (whichever 12353 1.1 mrg has an unexpanded parameter pack). */ 12354 1.1 mrg 12355 1.1 mrg tree 12356 1.1 mrg finish_binary_fold_expr (tree pack, tree init, int op, tree_code dir) 12357 1.1 mrg { 12358 1.1 mrg pack = make_pack_expansion (pack); 12359 1.1 mrg tree code = build_int_cstu (integer_type_node, abs (op)); 12360 1.1 mrg tree fold = build_min_nt_loc (input_location, dir, code, pack, init); 12361 1.1 mrg FOLD_EXPR_MODIFY_P (fold) = (op < 0); 12362 1.1 mrg TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE, 12363 1.1 mrg FOLD_EXPR_OP (fold), 12364 1.1 mrg FOLD_EXPR_MODIFY_P (fold)); 12365 1.1 mrg return fold; 12366 1.1 mrg } 12367 1.1 mrg 12368 1.1 mrg tree 12369 1.1 mrg finish_binary_fold_expr (tree expr1, tree expr2, int op) 12370 1.1 mrg { 12371 1.1 mrg // Determine which expr has an unexpanded parameter pack and 12372 1.1 mrg // set the pack and initial term. 12373 1.1 mrg bool pack1 = uses_parameter_packs (expr1); 12374 1.1 mrg bool pack2 = uses_parameter_packs (expr2); 12375 1.1 mrg if (pack1 && !pack2) 12376 1.1 mrg return finish_binary_fold_expr (expr1, expr2, op, BINARY_RIGHT_FOLD_EXPR); 12377 1.1 mrg else if (pack2 && !pack1) 12378 1.1 mrg return finish_binary_fold_expr (expr2, expr1, op, BINARY_LEFT_FOLD_EXPR); 12379 1.1 mrg else 12380 1.1 mrg { 12381 1.1 mrg if (pack1) 12382 1.1 mrg error ("both arguments in binary fold have unexpanded parameter packs"); 12383 1.1 mrg else 12384 1.1 mrg error ("no unexpanded parameter packs in binary fold"); 12385 1.1 mrg } 12386 1.1 mrg return error_mark_node; 12387 1.1 mrg } 12388 1.1 mrg 12389 1.1 mrg /* Finish __builtin_launder (arg). */ 12390 1.1 mrg 12391 1.1 mrg tree 12392 1.1 mrg finish_builtin_launder (location_t loc, tree arg, tsubst_flags_t complain) 12393 1.1 mrg { 12394 1.1 mrg tree orig_arg = arg; 12395 1.1 mrg if (!type_dependent_expression_p (arg)) 12396 1.1 mrg arg = decay_conversion (arg, complain); 12397 1.1 mrg if (error_operand_p (arg)) 12398 1.1 mrg return error_mark_node; 12399 1.1 mrg if (!type_dependent_expression_p (arg) 12400 1.1 mrg && !TYPE_PTR_P (TREE_TYPE (arg))) 12401 1.1 mrg { 12402 1.1 mrg error_at (loc, "non-pointer argument to %<__builtin_launder%>"); 12403 1.1 mrg return error_mark_node; 12404 1.1 mrg } 12405 1.1 mrg if (processing_template_decl) 12406 1.1 mrg arg = orig_arg; 12407 1.1 mrg return build_call_expr_internal_loc (loc, IFN_LAUNDER, 12408 1.1 mrg TREE_TYPE (arg), 1, arg); 12409 1.1 mrg } 12410 1.1 mrg 12411 1.1 mrg /* Finish __builtin_convertvector (arg, type). */ 12412 1.1 mrg 12413 1.1 mrg tree 12414 1.1 mrg cp_build_vec_convert (tree arg, location_t loc, tree type, 12415 1.1 mrg tsubst_flags_t complain) 12416 1.1 mrg { 12417 1.1 mrg if (error_operand_p (type)) 12418 1.1 mrg return error_mark_node; 12419 1.1 mrg if (error_operand_p (arg)) 12420 1.1 mrg return error_mark_node; 12421 1.1 mrg 12422 1.1 mrg tree ret = NULL_TREE; 12423 1.1 mrg if (!type_dependent_expression_p (arg) && !dependent_type_p (type)) 12424 1.1 mrg ret = c_build_vec_convert (cp_expr_loc_or_input_loc (arg), 12425 1.1 mrg decay_conversion (arg, complain), 12426 1.1 mrg loc, type, (complain & tf_error) != 0); 12427 1.1 mrg 12428 1.1 mrg if (!processing_template_decl) 12429 1.1 mrg return ret; 12430 1.1 mrg 12431 1.1 mrg return build_call_expr_internal_loc (loc, IFN_VEC_CONVERT, type, 1, arg); 12432 1.1 mrg } 12433 1.1 mrg 12434 1.1 mrg /* Finish __builtin_bit_cast (type, arg). */ 12435 1.1 mrg 12436 1.1 mrg tree 12437 1.1 mrg cp_build_bit_cast (location_t loc, tree type, tree arg, 12438 1.1 mrg tsubst_flags_t complain) 12439 1.1 mrg { 12440 1.1 mrg if (error_operand_p (type)) 12441 1.1 mrg return error_mark_node; 12442 1.1 mrg if (!dependent_type_p (type)) 12443 1.1 mrg { 12444 1.1 mrg if (!complete_type_or_maybe_complain (type, NULL_TREE, complain)) 12445 1.1 mrg return error_mark_node; 12446 1.1 mrg if (TREE_CODE (type) == ARRAY_TYPE) 12447 1.1 mrg { 12448 1.1 mrg /* std::bit_cast for destination ARRAY_TYPE is not possible, 12449 1.1 mrg as functions may not return an array, so don't bother trying 12450 1.1 mrg to support this (and then deal with VLAs etc.). */ 12451 1.1 mrg error_at (loc, "%<__builtin_bit_cast%> destination type %qT " 12452 1.1 mrg "is an array type", type); 12453 1.1 mrg return error_mark_node; 12454 1.1 mrg } 12455 1.1 mrg if (!trivially_copyable_p (type)) 12456 1.1 mrg { 12457 1.1 mrg error_at (loc, "%<__builtin_bit_cast%> destination type %qT " 12458 1.1 mrg "is not trivially copyable", type); 12459 1.1 mrg return error_mark_node; 12460 1.1 mrg } 12461 1.1 mrg } 12462 1.1 mrg 12463 1.1 mrg if (error_operand_p (arg)) 12464 1.1 mrg return error_mark_node; 12465 1.1 mrg 12466 1.1 mrg if (!type_dependent_expression_p (arg)) 12467 1.1 mrg { 12468 1.1 mrg if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE) 12469 1.1 mrg { 12470 1.1 mrg /* Don't perform array-to-pointer conversion. */ 12471 1.1 mrg arg = mark_rvalue_use (arg, loc, true); 12472 1.1 mrg if (!complete_type_or_maybe_complain (TREE_TYPE (arg), arg, complain)) 12473 1.1 mrg return error_mark_node; 12474 1.1 mrg } 12475 1.1 mrg else 12476 1.1 mrg arg = decay_conversion (arg, complain); 12477 1.1 mrg 12478 1.1 mrg if (error_operand_p (arg)) 12479 1.1 mrg return error_mark_node; 12480 1.1 mrg 12481 1.1 mrg if (!trivially_copyable_p (TREE_TYPE (arg))) 12482 1.1 mrg { 12483 1.1 mrg error_at (cp_expr_loc_or_loc (arg, loc), 12484 1.1 mrg "%<__builtin_bit_cast%> source type %qT " 12485 1.1 mrg "is not trivially copyable", TREE_TYPE (arg)); 12486 1.1 mrg return error_mark_node; 12487 1.1 mrg } 12488 1.1 mrg if (!dependent_type_p (type) 12489 1.1 mrg && !cp_tree_equal (TYPE_SIZE_UNIT (type), 12490 1.1 mrg TYPE_SIZE_UNIT (TREE_TYPE (arg)))) 12491 1.1 mrg { 12492 1.1 mrg error_at (loc, "%<__builtin_bit_cast%> source size %qE " 12493 1.1 mrg "not equal to destination type size %qE", 12494 1.1 mrg TYPE_SIZE_UNIT (TREE_TYPE (arg)), 12495 1.1 mrg TYPE_SIZE_UNIT (type)); 12496 1.1 mrg return error_mark_node; 12497 1.1 mrg } 12498 1.1 mrg } 12499 1.1 mrg 12500 1.1 mrg tree ret = build_min (BIT_CAST_EXPR, type, arg); 12501 1.1 mrg SET_EXPR_LOCATION (ret, loc); 12502 1.1 mrg 12503 1.1 mrg if (!processing_template_decl && CLASS_TYPE_P (type)) 12504 ret = get_target_expr_sfinae (ret, complain); 12505 12506 return ret; 12507 } 12508 12509 #include "gt-cp-semantics.h" 12510