1 1.1 mrg /* Subroutines shared by all languages that are variants of C. 2 1.1 mrg Copyright (C) 1992-2022 Free Software Foundation, Inc. 3 1.1 mrg 4 1.1 mrg This file is part of GCC. 5 1.1 mrg 6 1.1 mrg GCC is free software; you can redistribute it and/or modify it under 7 1.1 mrg the terms of the GNU General Public License as published by the Free 8 1.1 mrg Software Foundation; either version 3, or (at your option) any later 9 1.1 mrg version. 10 1.1 mrg 11 1.1 mrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY 12 1.1 mrg WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 1.1 mrg FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 1.1 mrg for more details. 15 1.1 mrg 16 1.1 mrg You should have received a copy of the GNU General Public License 17 1.1 mrg along with GCC; see the file COPYING3. If not see 18 1.1 mrg <http://www.gnu.org/licenses/>. */ 19 1.1 mrg 20 1.1 mrg #define GCC_C_COMMON_C 21 1.1 mrg 22 1.1 mrg #include "config.h" 23 1.1 mrg #include "system.h" 24 1.1 mrg #include "coretypes.h" 25 1.1 mrg #include "target.h" 26 1.1 mrg #include "function.h" 27 1.1 mrg #include "tree.h" 28 1.1 mrg #include "memmodel.h" 29 1.1 mrg #include "c-common.h" 30 1.1 mrg #include "gimple-expr.h" 31 1.1 mrg #include "tm_p.h" 32 1.1 mrg #include "stringpool.h" 33 1.1 mrg #include "cgraph.h" 34 1.1 mrg #include "diagnostic.h" 35 1.1 mrg #include "intl.h" 36 1.1 mrg #include "stor-layout.h" 37 1.1 mrg #include "calls.h" 38 1.1 mrg #include "attribs.h" 39 1.1 mrg #include "varasm.h" 40 1.1 mrg #include "trans-mem.h" 41 1.1 mrg #include "c-objc.h" 42 1.1 mrg #include "common/common-target.h" 43 1.1 mrg #include "langhooks.h" 44 1.1 mrg #include "tree-inline.h" 45 1.1 mrg #include "toplev.h" 46 1.1 mrg #include "tree-iterator.h" 47 1.1 mrg #include "opts.h" 48 1.1 mrg #include "gimplify.h" 49 1.1 mrg #include "substring-locations.h" 50 1.1 mrg #include "spellcheck.h" 51 1.1 mrg #include "c-spellcheck.h" 52 1.1 mrg #include "selftest.h" 53 1.1 mrg #include "debug.h" 54 1.1 mrg #include "tree-vector-builder.h" 55 1.1 mrg #include "vec-perm-indices.h" 56 1.1 mrg 57 1.1 mrg cpp_reader *parse_in; /* Declared in c-pragma.h. */ 58 1.1 mrg 59 1.1 mrg /* Mode used to build pointers (VOIDmode means ptr_mode). */ 60 1.1 mrg 61 1.1 mrg machine_mode c_default_pointer_mode = VOIDmode; 62 1.1 mrg 63 1.1 mrg /* The following symbols are subsumed in the c_global_trees array, and 64 1.1 mrg listed here individually for documentation purposes. 65 1.1 mrg 66 1.1 mrg INTEGER_TYPE and REAL_TYPE nodes for the standard data types. 67 1.1 mrg 68 1.1 mrg tree short_integer_type_node; 69 1.1 mrg tree long_integer_type_node; 70 1.1 mrg tree long_long_integer_type_node; 71 1.1 mrg 72 1.1 mrg tree short_unsigned_type_node; 73 1.1 mrg tree long_unsigned_type_node; 74 1.1 mrg tree long_long_unsigned_type_node; 75 1.1 mrg 76 1.1 mrg tree truthvalue_type_node; 77 1.1 mrg tree truthvalue_false_node; 78 1.1 mrg tree truthvalue_true_node; 79 1.1 mrg 80 1.1 mrg tree ptrdiff_type_node; 81 1.1 mrg 82 1.1 mrg tree unsigned_char_type_node; 83 1.1 mrg tree signed_char_type_node; 84 1.1 mrg tree wchar_type_node; 85 1.1 mrg 86 1.1 mrg tree char8_type_node; 87 1.1 mrg tree char16_type_node; 88 1.1 mrg tree char32_type_node; 89 1.1 mrg 90 1.1 mrg tree float_type_node; 91 1.1 mrg tree double_type_node; 92 1.1 mrg tree long_double_type_node; 93 1.1 mrg 94 1.1 mrg tree complex_integer_type_node; 95 1.1 mrg tree complex_float_type_node; 96 1.1 mrg tree complex_double_type_node; 97 1.1 mrg tree complex_long_double_type_node; 98 1.1 mrg 99 1.1 mrg tree dfloat32_type_node; 100 1.1 mrg tree dfloat64_type_node; 101 1.1 mrg tree_dfloat128_type_node; 102 1.1 mrg 103 1.1 mrg tree intQI_type_node; 104 1.1 mrg tree intHI_type_node; 105 1.1 mrg tree intSI_type_node; 106 1.1 mrg tree intDI_type_node; 107 1.1 mrg tree intTI_type_node; 108 1.1 mrg 109 1.1 mrg tree unsigned_intQI_type_node; 110 1.1 mrg tree unsigned_intHI_type_node; 111 1.1 mrg tree unsigned_intSI_type_node; 112 1.1 mrg tree unsigned_intDI_type_node; 113 1.1 mrg tree unsigned_intTI_type_node; 114 1.1 mrg 115 1.1 mrg tree widest_integer_literal_type_node; 116 1.1 mrg tree widest_unsigned_literal_type_node; 117 1.1 mrg 118 1.1 mrg Nodes for types `void *' and `const void *'. 119 1.1 mrg 120 1.1 mrg tree ptr_type_node, const_ptr_type_node; 121 1.1 mrg 122 1.1 mrg Nodes for types `char *' and `const char *'. 123 1.1 mrg 124 1.1 mrg tree string_type_node, const_string_type_node; 125 1.1 mrg 126 1.1 mrg Type `char[SOMENUMBER]'. 127 1.1 mrg Used when an array of char is needed and the size is irrelevant. 128 1.1 mrg 129 1.1 mrg tree char_array_type_node; 130 1.1 mrg 131 1.1 mrg Type `wchar_t[SOMENUMBER]' or something like it. 132 1.1 mrg Used when a wide string literal is created. 133 1.1 mrg 134 1.1 mrg tree wchar_array_type_node; 135 1.1 mrg 136 1.1 mrg Type `char8_t[SOMENUMBER]' or something like it. 137 1.1 mrg Used when a UTF-8 string literal is created. 138 1.1 mrg 139 1.1 mrg tree char8_array_type_node; 140 1.1 mrg 141 1.1 mrg Type `char16_t[SOMENUMBER]' or something like it. 142 1.1 mrg Used when a UTF-16 string literal is created. 143 1.1 mrg 144 1.1 mrg tree char16_array_type_node; 145 1.1 mrg 146 1.1 mrg Type `char32_t[SOMENUMBER]' or something like it. 147 1.1 mrg Used when a UTF-32 string literal is created. 148 1.1 mrg 149 1.1 mrg tree char32_array_type_node; 150 1.1 mrg 151 1.1 mrg Type `int ()' -- used for implicit declaration of functions. 152 1.1 mrg 153 1.1 mrg tree default_function_type; 154 1.1 mrg 155 1.1 mrg A VOID_TYPE node, packaged in a TREE_LIST. 156 1.1 mrg 157 1.1 mrg tree void_list_node; 158 1.1 mrg 159 1.1 mrg The lazily created VAR_DECLs for __FUNCTION__, __PRETTY_FUNCTION__, 160 1.1 mrg and __func__. (C doesn't generate __FUNCTION__ and__PRETTY_FUNCTION__ 161 1.1 mrg VAR_DECLS, but C++ does.) 162 1.1 mrg 163 1.1 mrg tree function_name_decl_node; 164 1.1 mrg tree pretty_function_name_decl_node; 165 1.1 mrg tree c99_function_name_decl_node; 166 1.1 mrg 167 1.1 mrg Stack of nested function name VAR_DECLs. 168 1.1 mrg 169 1.1 mrg tree saved_function_name_decls; 170 1.1 mrg 171 1.1 mrg */ 172 1.1 mrg 173 1.1 mrg tree c_global_trees[CTI_MAX]; 174 1.1 mrg 175 1.1 mrg /* Switches common to the C front ends. */ 177 1.1 mrg 178 1.1 mrg /* Nonzero means don't output line number information. */ 179 1.1 mrg 180 1.1 mrg char flag_no_line_commands; 181 1.1 mrg 182 1.1 mrg /* Nonzero causes -E output not to be done, but directives such as 183 1.1 mrg #define that have side effects are still obeyed. */ 184 1.1 mrg 185 1.1 mrg char flag_no_output; 186 1.1 mrg 187 1.1 mrg /* Nonzero means dump macros in some fashion. */ 188 1.1 mrg 189 1.1 mrg char flag_dump_macros; 190 1.1 mrg 191 1.1 mrg /* Nonzero means pass #include lines through to the output. */ 192 1.1 mrg 193 1.1 mrg char flag_dump_includes; 194 1.1 mrg 195 1.1 mrg /* Nonzero means process PCH files while preprocessing. */ 196 1.1 mrg 197 1.1 mrg bool flag_pch_preprocess; 198 1.1 mrg 199 1.1 mrg /* The file name to which we should write a precompiled header, or 200 1.1 mrg NULL if no header will be written in this compile. */ 201 1.1 mrg 202 1.1 mrg const char *pch_file; 203 1.1 mrg 204 1.1 mrg /* Nonzero if an ISO standard was selected. It rejects macros in the 205 1.1 mrg user's namespace. */ 206 1.1 mrg int flag_iso; 207 1.1 mrg 208 1.1 mrg /* C/ObjC language option variables. */ 209 1.1 mrg 210 1.1 mrg 211 1.1 mrg /* Nonzero means allow type mismatches in conditional expressions; 212 1.1 mrg just make their values `void'. */ 213 1.1 mrg 214 1.1 mrg int flag_cond_mismatch; 215 1.1 mrg 216 1.1 mrg /* Nonzero means enable C89 Amendment 1 features. */ 217 1.1 mrg 218 1.1 mrg int flag_isoc94; 219 1.1 mrg 220 1.1 mrg /* Nonzero means use the ISO C99 (or C11) dialect of C. */ 221 1.1 mrg 222 1.1 mrg int flag_isoc99; 223 1.1 mrg 224 1.1 mrg /* Nonzero means use the ISO C11 dialect of C. */ 225 1.1 mrg 226 1.1 mrg int flag_isoc11; 227 1.1 mrg 228 1.1 mrg /* Nonzero means use the ISO C2X dialect of C. */ 229 1.1 mrg 230 1.1 mrg int flag_isoc2x; 231 1.1 mrg 232 1.1 mrg /* Nonzero means that we have builtin functions, and main is an int. */ 233 1.1 mrg 234 1.1 mrg int flag_hosted = 1; 235 1.1 mrg 236 1.1 mrg 237 1.1 mrg /* ObjC language option variables. */ 238 1.1 mrg 239 1.1 mrg 240 1.1 mrg /* Tells the compiler that this is a special run. Do not perform any 241 1.1 mrg compiling, instead we are to test some platform dependent features 242 1.1 mrg and output a C header file with appropriate definitions. */ 243 1.1 mrg 244 1.1 mrg int print_struct_values; 245 1.1 mrg 246 1.1 mrg /* Tells the compiler what is the constant string class for ObjC. */ 247 1.1 mrg 248 1.1 mrg const char *constant_string_class_name; 249 1.1 mrg 250 1.1 mrg 251 1.1 mrg /* C++ language option variables. */ 252 1.1 mrg 253 1.1 mrg /* The reference version of the ABI for -Wabi. */ 254 1.1 mrg 255 1.1 mrg int warn_abi_version = -1; 256 1.1 mrg 257 1.1 mrg /* The C++ dialect being used. Default set in c_common_post_options. */ 258 1.1 mrg 259 1.1 mrg enum cxx_dialect cxx_dialect = cxx_unset; 260 1.1 mrg 261 1.1 mrg /* Maximum template instantiation depth. This limit exists to limit the 262 1.1 mrg time it takes to notice excessively recursive template instantiations. 263 1.1 mrg 264 1.1 mrg The default is lower than the 1024 recommended by the C++0x standard 265 1.1 mrg because G++ runs out of stack before 1024 with highly recursive template 266 1.1 mrg argument deduction substitution (g++.dg/cpp0x/enum11.C). */ 267 1.1 mrg 268 1.1 mrg int max_tinst_depth = 900; 269 1.1 mrg 270 1.1 mrg /* The elements of `ridpointers' are identifier nodes for the reserved 271 1.1 mrg type names and storage classes. It is indexed by a RID_... value. */ 272 1.1 mrg tree *ridpointers; 273 1.1 mrg 274 1.1 mrg tree (*make_fname_decl) (location_t, tree, int); 275 1.1 mrg 276 1.1 mrg /* Nonzero means don't warn about problems that occur when the code is 277 1.1 mrg executed. */ 278 1.1 mrg int c_inhibit_evaluation_warnings; 279 1.1 mrg 280 1.1 mrg /* Whether we are building a boolean conversion inside 281 1.1 mrg convert_for_assignment, or some other late binary operation. If 282 1.1 mrg build_binary_op is called for C (from code shared by C and C++) in 283 1.1 mrg this case, then the operands have already been folded and the 284 1.1 mrg result will not be folded again, so C_MAYBE_CONST_EXPR should not 285 1.1 mrg be generated. */ 286 1.1 mrg bool in_late_binary_op; 287 1.1 mrg 288 1.1 mrg /* Whether lexing has been completed, so subsequent preprocessor 289 1.1 mrg errors should use the compiler's input_location. */ 290 1.1 mrg bool done_lexing = false; 291 1.1 mrg 292 1.1 mrg /* Information about how a function name is generated. */ 293 1.1 mrg struct fname_var_t 294 1.1 mrg { 295 1.1 mrg tree *const decl; /* pointer to the VAR_DECL. */ 296 1.1 mrg const unsigned rid; /* RID number for the identifier. */ 297 1.1 mrg const int pretty; /* How pretty is it? */ 298 1.1 mrg }; 299 1.1 mrg 300 1.1 mrg /* The three ways of getting then name of the current function. */ 301 1.1 mrg 302 1.1 mrg const struct fname_var_t fname_vars[] = 303 1.1 mrg { 304 1.1 mrg /* C99 compliant __func__, must be first. */ 305 1.1 mrg {&c99_function_name_decl_node, RID_C99_FUNCTION_NAME, 0}, 306 1.1 mrg /* GCC __FUNCTION__ compliant. */ 307 1.1 mrg {&function_name_decl_node, RID_FUNCTION_NAME, 0}, 308 1.1 mrg /* GCC __PRETTY_FUNCTION__ compliant. */ 309 1.1 mrg {&pretty_function_name_decl_node, RID_PRETTY_FUNCTION_NAME, 1}, 310 1.1 mrg {NULL, 0, 0}, 311 1.1 mrg }; 312 1.1 mrg 313 1.1 mrg /* Global visibility options. */ 314 1.1 mrg struct visibility_flags visibility_options; 315 1.1 mrg 316 1.1 mrg static tree check_case_value (location_t, tree); 317 1.1 mrg 318 1.1 mrg 319 1.1 mrg static void check_nonnull_arg (void *, tree, unsigned HOST_WIDE_INT); 320 1.1 mrg static bool nonnull_check_p (tree, unsigned HOST_WIDE_INT); 321 1.1 mrg 322 1.1 mrg /* Reserved words. The third field is a mask: keywords are disabled 323 1.1 mrg if they match the mask. 324 1.1 mrg 325 1.1 mrg Masks for languages: 326 1.1 mrg C --std=c89: D_C99 | D_CXXONLY | D_OBJC | D_CXX_OBJC 327 1.1 mrg C --std=c99: D_CXXONLY | D_OBJC 328 1.1 mrg ObjC is like C except that D_OBJC and D_CXX_OBJC are not set 329 1.1 mrg C++ --std=c++98: D_CONLY | D_CXX11 | D_CXX20 | D_OBJC 330 1.1 mrg C++ --std=c++11: D_CONLY | D_CXX20 | D_OBJC 331 1.1 mrg C++ --std=c++20: D_CONLY | D_OBJC 332 1.1 mrg ObjC++ is like C++ except that D_OBJC is not set 333 1.1 mrg 334 1.1 mrg If -fno-asm is used, D_ASM is added to the mask. If 335 1.1 mrg -fno-gnu-keywords is used, D_EXT is added. If -fno-asm and C in 336 1.1 mrg C89 mode, D_EXT89 is added for both -fno-asm and -fno-gnu-keywords. 337 1.1 mrg In C with -Wc++-compat, we warn if D_CXXWARN is set. 338 1.1 mrg 339 1.1 mrg Note the complication of the D_CXX_OBJC keywords. These are 340 1.1 mrg reserved words such as 'class'. In C++, 'class' is a reserved 341 1.1 mrg word. In Objective-C++ it is too. In Objective-C, it is a 342 1.1 mrg reserved word too, but only if it follows an '@' sign. 343 1.1 mrg */ 344 1.1 mrg const struct c_common_resword c_common_reswords[] = 345 1.1 mrg { 346 1.1 mrg { "_Alignas", RID_ALIGNAS, D_CONLY }, 347 1.1 mrg { "_Alignof", RID_ALIGNOF, D_CONLY }, 348 1.1 mrg { "_Atomic", RID_ATOMIC, D_CONLY }, 349 1.1 mrg { "_Bool", RID_BOOL, D_CONLY }, 350 1.1 mrg { "_Complex", RID_COMPLEX, 0 }, 351 1.1 mrg { "_Imaginary", RID_IMAGINARY, D_CONLY }, 352 1.1 mrg { "_Float16", RID_FLOAT16, D_CONLY }, 353 1.1 mrg { "_Float32", RID_FLOAT32, D_CONLY }, 354 1.1 mrg { "_Float64", RID_FLOAT64, D_CONLY }, 355 1.1 mrg { "_Float128", RID_FLOAT128, D_CONLY }, 356 1.1 mrg { "_Float32x", RID_FLOAT32X, D_CONLY }, 357 1.1 mrg { "_Float64x", RID_FLOAT64X, D_CONLY }, 358 1.1 mrg { "_Float128x", RID_FLOAT128X, D_CONLY }, 359 1.1 mrg { "_Decimal32", RID_DFLOAT32, D_CONLY }, 360 1.1 mrg { "_Decimal64", RID_DFLOAT64, D_CONLY }, 361 1.1 mrg { "_Decimal128", RID_DFLOAT128, D_CONLY }, 362 1.1 mrg { "_Fract", RID_FRACT, D_CONLY | D_EXT }, 363 1.1 mrg { "_Accum", RID_ACCUM, D_CONLY | D_EXT }, 364 1.1 mrg { "_Sat", RID_SAT, D_CONLY | D_EXT }, 365 1.1 mrg { "_Static_assert", RID_STATIC_ASSERT, D_CONLY }, 366 1.1 mrg { "_Noreturn", RID_NORETURN, D_CONLY }, 367 1.1 mrg { "_Generic", RID_GENERIC, D_CONLY }, 368 1.1 mrg { "_Thread_local", RID_THREAD, D_CONLY }, 369 1.1 mrg { "__FUNCTION__", RID_FUNCTION_NAME, 0 }, 370 1.1 mrg { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 }, 371 1.1 mrg { "__alignof", RID_ALIGNOF, 0 }, 372 1.1 mrg { "__alignof__", RID_ALIGNOF, 0 }, 373 1.1 mrg { "__asm", RID_ASM, 0 }, 374 1.1 mrg { "__asm__", RID_ASM, 0 }, 375 1.1 mrg { "__attribute", RID_ATTRIBUTE, 0 }, 376 1.1 mrg { "__attribute__", RID_ATTRIBUTE, 0 }, 377 1.1 mrg { "__auto_type", RID_AUTO_TYPE, D_CONLY }, 378 1.1 mrg { "__bases", RID_BASES, D_CXXONLY }, 379 1.1 mrg { "__builtin_addressof", RID_ADDRESSOF, D_CXXONLY }, 380 1.1 mrg { "__builtin_bit_cast", RID_BUILTIN_BIT_CAST, D_CXXONLY }, 381 1.1 mrg { "__builtin_call_with_static_chain", 382 1.1 mrg RID_BUILTIN_CALL_WITH_STATIC_CHAIN, D_CONLY }, 383 1.1 mrg { "__builtin_choose_expr", RID_CHOOSE_EXPR, D_CONLY }, 384 1.1 mrg { "__builtin_complex", RID_BUILTIN_COMPLEX, D_CONLY }, 385 1.1 mrg { "__builtin_convertvector", RID_BUILTIN_CONVERTVECTOR, 0 }, 386 1.1 mrg { "__builtin_has_attribute", RID_BUILTIN_HAS_ATTRIBUTE, 0 }, 387 1.1 mrg { "__builtin_launder", RID_BUILTIN_LAUNDER, D_CXXONLY }, 388 1.1 mrg { "__builtin_assoc_barrier", RID_BUILTIN_ASSOC_BARRIER, 0 }, 389 1.1 mrg { "__builtin_shuffle", RID_BUILTIN_SHUFFLE, 0 }, 390 1.1 mrg { "__builtin_shufflevector", RID_BUILTIN_SHUFFLEVECTOR, 0 }, 391 1.1 mrg { "__builtin_tgmath", RID_BUILTIN_TGMATH, D_CONLY }, 392 1.1 mrg { "__builtin_offsetof", RID_OFFSETOF, 0 }, 393 1.1 mrg { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P, D_CONLY }, 394 1.1 mrg { "__builtin_va_arg", RID_VA_ARG, 0 }, 395 1.1 mrg { "__complex", RID_COMPLEX, 0 }, 396 1.1 mrg { "__complex__", RID_COMPLEX, 0 }, 397 1.1 mrg { "__const", RID_CONST, 0 }, 398 1.1 mrg { "__const__", RID_CONST, 0 }, 399 1.1 mrg { "__constinit", RID_CONSTINIT, D_CXXONLY }, 400 1.1 mrg { "__decltype", RID_DECLTYPE, D_CXXONLY }, 401 1.1 mrg { "__direct_bases", RID_DIRECT_BASES, D_CXXONLY }, 402 1.1 mrg { "__extension__", RID_EXTENSION, 0 }, 403 1.1 mrg { "__func__", RID_C99_FUNCTION_NAME, 0 }, 404 1.1 mrg { "__has_nothrow_assign", RID_HAS_NOTHROW_ASSIGN, D_CXXONLY }, 405 1.1 mrg { "__has_nothrow_constructor", RID_HAS_NOTHROW_CONSTRUCTOR, D_CXXONLY }, 406 1.1 mrg { "__has_nothrow_copy", RID_HAS_NOTHROW_COPY, D_CXXONLY }, 407 1.1 mrg { "__has_trivial_assign", RID_HAS_TRIVIAL_ASSIGN, D_CXXONLY }, 408 1.1 mrg { "__has_trivial_constructor", RID_HAS_TRIVIAL_CONSTRUCTOR, D_CXXONLY }, 409 1.1 mrg { "__has_trivial_copy", RID_HAS_TRIVIAL_COPY, D_CXXONLY }, 410 1.1 mrg { "__has_trivial_destructor", RID_HAS_TRIVIAL_DESTRUCTOR, D_CXXONLY }, 411 1.1 mrg { "__has_unique_object_representations", RID_HAS_UNIQUE_OBJ_REPRESENTATIONS, 412 1.1 mrg D_CXXONLY }, 413 1.1 mrg { "__has_virtual_destructor", RID_HAS_VIRTUAL_DESTRUCTOR, D_CXXONLY }, 414 1.1 mrg { "__imag", RID_IMAGPART, 0 }, 415 1.1 mrg { "__imag__", RID_IMAGPART, 0 }, 416 1.1 mrg { "__inline", RID_INLINE, 0 }, 417 1.1 mrg { "__inline__", RID_INLINE, 0 }, 418 1.1 mrg { "__is_abstract", RID_IS_ABSTRACT, D_CXXONLY }, 419 1.1 mrg { "__is_aggregate", RID_IS_AGGREGATE, D_CXXONLY }, 420 1.1 mrg { "__is_base_of", RID_IS_BASE_OF, D_CXXONLY }, 421 1.1 mrg { "__is_class", RID_IS_CLASS, D_CXXONLY }, 422 1.1 mrg { "__is_empty", RID_IS_EMPTY, D_CXXONLY }, 423 1.1 mrg { "__is_enum", RID_IS_ENUM, D_CXXONLY }, 424 1.1 mrg { "__is_final", RID_IS_FINAL, D_CXXONLY }, 425 1.1 mrg { "__is_layout_compatible", RID_IS_LAYOUT_COMPATIBLE, D_CXXONLY }, 426 1.1 mrg { "__is_literal_type", RID_IS_LITERAL_TYPE, D_CXXONLY }, 427 1.1 mrg { "__is_pointer_interconvertible_base_of", 428 1.1 mrg RID_IS_POINTER_INTERCONVERTIBLE_BASE_OF, D_CXXONLY }, 429 1.1 mrg { "__is_pod", RID_IS_POD, D_CXXONLY }, 430 1.1 mrg { "__is_polymorphic", RID_IS_POLYMORPHIC, D_CXXONLY }, 431 1.1 mrg { "__is_same", RID_IS_SAME_AS, D_CXXONLY }, 432 1.1 mrg { "__is_same_as", RID_IS_SAME_AS, D_CXXONLY }, 433 1.1 mrg { "__is_standard_layout", RID_IS_STD_LAYOUT, D_CXXONLY }, 434 1.1 mrg { "__is_trivial", RID_IS_TRIVIAL, D_CXXONLY }, 435 1.1 mrg { "__is_trivially_assignable", RID_IS_TRIVIALLY_ASSIGNABLE, D_CXXONLY }, 436 1.1 mrg { "__is_trivially_constructible", RID_IS_TRIVIALLY_CONSTRUCTIBLE, D_CXXONLY }, 437 1.1 mrg { "__is_trivially_copyable", RID_IS_TRIVIALLY_COPYABLE, D_CXXONLY }, 438 1.1 mrg { "__is_union", RID_IS_UNION, D_CXXONLY }, 439 1.1 mrg { "__label__", RID_LABEL, 0 }, 440 1.1 mrg { "__null", RID_NULL, 0 }, 441 1.1 mrg { "__real", RID_REALPART, 0 }, 442 1.1 mrg { "__real__", RID_REALPART, 0 }, 443 1.1 mrg { "__restrict", RID_RESTRICT, 0 }, 444 1.1 mrg { "__restrict__", RID_RESTRICT, 0 }, 445 1.1 mrg { "__signed", RID_SIGNED, 0 }, 446 1.1 mrg { "__signed__", RID_SIGNED, 0 }, 447 1.1 mrg { "__thread", RID_THREAD, 0 }, 448 1.1 mrg { "__transaction_atomic", RID_TRANSACTION_ATOMIC, 0 }, 449 1.1 mrg { "__transaction_relaxed", RID_TRANSACTION_RELAXED, 0 }, 450 1.1 mrg { "__transaction_cancel", RID_TRANSACTION_CANCEL, 0 }, 451 1.1 mrg { "__typeof", RID_TYPEOF, 0 }, 452 1.1 mrg { "__typeof__", RID_TYPEOF, 0 }, 453 1.1 mrg { "__underlying_type", RID_UNDERLYING_TYPE, D_CXXONLY }, 454 1.1 mrg { "__volatile", RID_VOLATILE, 0 }, 455 1.1 mrg { "__volatile__", RID_VOLATILE, 0 }, 456 1.1 mrg { "__GIMPLE", RID_GIMPLE, D_CONLY }, 457 1.1 mrg { "__PHI", RID_PHI, D_CONLY }, 458 1.1 mrg { "__RTL", RID_RTL, D_CONLY }, 459 1.1 mrg { "alignas", RID_ALIGNAS, D_CXXONLY | D_CXX11 | D_CXXWARN }, 460 1.1 mrg { "alignof", RID_ALIGNOF, D_CXXONLY | D_CXX11 | D_CXXWARN }, 461 1.1 mrg { "asm", RID_ASM, D_ASM }, 462 1.1 mrg { "auto", RID_AUTO, 0 }, 463 1.1 mrg { "bool", RID_BOOL, D_CXXONLY | D_CXXWARN }, 464 1.1 mrg { "break", RID_BREAK, 0 }, 465 1.1 mrg { "case", RID_CASE, 0 }, 466 1.1 mrg { "catch", RID_CATCH, D_CXX_OBJC | D_CXXWARN }, 467 1.1 mrg { "char", RID_CHAR, 0 }, 468 1.1 mrg { "char8_t", RID_CHAR8, D_CXX_CHAR8_T_FLAGS | D_CXXWARN }, 469 1.1 mrg { "char16_t", RID_CHAR16, D_CXXONLY | D_CXX11 | D_CXXWARN }, 470 1.1 mrg { "char32_t", RID_CHAR32, D_CXXONLY | D_CXX11 | D_CXXWARN }, 471 1.1 mrg { "class", RID_CLASS, D_CXX_OBJC | D_CXXWARN }, 472 1.1 mrg { "const", RID_CONST, 0 }, 473 1.1 mrg { "consteval", RID_CONSTEVAL, D_CXXONLY | D_CXX20 | D_CXXWARN }, 474 1.1 mrg { "constexpr", RID_CONSTEXPR, D_CXXONLY | D_CXX11 | D_CXXWARN }, 475 1.1 mrg { "constinit", RID_CONSTINIT, D_CXXONLY | D_CXX20 | D_CXXWARN }, 476 1.1 mrg { "const_cast", RID_CONSTCAST, D_CXXONLY | D_CXXWARN }, 477 1.1 mrg { "continue", RID_CONTINUE, 0 }, 478 1.1 mrg { "decltype", RID_DECLTYPE, D_CXXONLY | D_CXX11 | D_CXXWARN }, 479 1.1 mrg { "default", RID_DEFAULT, 0 }, 480 1.1 mrg { "delete", RID_DELETE, D_CXXONLY | D_CXXWARN }, 481 1.1 mrg { "do", RID_DO, 0 }, 482 1.1 mrg { "double", RID_DOUBLE, 0 }, 483 1.1 mrg { "dynamic_cast", RID_DYNCAST, D_CXXONLY | D_CXXWARN }, 484 1.1 mrg { "else", RID_ELSE, 0 }, 485 1.1 mrg { "enum", RID_ENUM, 0 }, 486 1.1 mrg { "explicit", RID_EXPLICIT, D_CXXONLY | D_CXXWARN }, 487 1.1 mrg { "export", RID_EXPORT, D_CXXONLY | D_CXXWARN }, 488 1.1 mrg { "extern", RID_EXTERN, 0 }, 489 1.1 mrg { "false", RID_FALSE, D_CXXONLY | D_CXXWARN }, 490 1.1 mrg { "float", RID_FLOAT, 0 }, 491 1.1 mrg { "for", RID_FOR, 0 }, 492 1.1 mrg { "friend", RID_FRIEND, D_CXXONLY | D_CXXWARN }, 493 1.1 mrg { "goto", RID_GOTO, 0 }, 494 1.1 mrg { "if", RID_IF, 0 }, 495 1.1 mrg { "inline", RID_INLINE, D_EXT89 }, 496 1.1 mrg { "int", RID_INT, 0 }, 497 1.1 mrg { "long", RID_LONG, 0 }, 498 1.1 mrg { "mutable", RID_MUTABLE, D_CXXONLY | D_CXXWARN }, 499 1.1 mrg { "namespace", RID_NAMESPACE, D_CXXONLY | D_CXXWARN }, 500 1.1 mrg { "new", RID_NEW, D_CXXONLY | D_CXXWARN }, 501 1.1 mrg { "noexcept", RID_NOEXCEPT, D_CXXONLY | D_CXX11 | D_CXXWARN }, 502 1.1 mrg { "nullptr", RID_NULLPTR, D_CXXONLY | D_CXX11 | D_CXXWARN }, 503 1.1 mrg { "operator", RID_OPERATOR, D_CXXONLY | D_CXXWARN }, 504 1.1 mrg { "private", RID_PRIVATE, D_CXX_OBJC | D_CXXWARN }, 505 1.1 mrg { "protected", RID_PROTECTED, D_CXX_OBJC | D_CXXWARN }, 506 1.1 mrg { "public", RID_PUBLIC, D_CXX_OBJC | D_CXXWARN }, 507 1.1 mrg { "register", RID_REGISTER, 0 }, 508 1.1 mrg { "reinterpret_cast", RID_REINTCAST, D_CXXONLY | D_CXXWARN }, 509 1.1 mrg { "restrict", RID_RESTRICT, D_CONLY | D_C99 }, 510 1.1 mrg { "return", RID_RETURN, 0 }, 511 1.1 mrg { "short", RID_SHORT, 0 }, 512 1.1 mrg { "signed", RID_SIGNED, 0 }, 513 1.1 mrg { "sizeof", RID_SIZEOF, 0 }, 514 1.1 mrg { "static", RID_STATIC, 0 }, 515 1.1 mrg { "static_assert", RID_STATIC_ASSERT, D_CXXONLY | D_CXX11 | D_CXXWARN }, 516 1.1 mrg { "static_cast", RID_STATCAST, D_CXXONLY | D_CXXWARN }, 517 1.1 mrg { "struct", RID_STRUCT, 0 }, 518 1.1 mrg { "switch", RID_SWITCH, 0 }, 519 1.1 mrg { "template", RID_TEMPLATE, D_CXXONLY | D_CXXWARN }, 520 1.1 mrg { "this", RID_THIS, D_CXXONLY | D_CXXWARN }, 521 1.1 mrg { "thread_local", RID_THREAD, D_CXXONLY | D_CXX11 | D_CXXWARN }, 522 1.1 mrg { "throw", RID_THROW, D_CXX_OBJC | D_CXXWARN }, 523 1.1 mrg { "true", RID_TRUE, D_CXXONLY | D_CXXWARN }, 524 1.1 mrg { "try", RID_TRY, D_CXX_OBJC | D_CXXWARN }, 525 1.1 mrg { "typedef", RID_TYPEDEF, 0 }, 526 1.1 mrg { "typename", RID_TYPENAME, D_CXXONLY | D_CXXWARN }, 527 1.1 mrg { "typeid", RID_TYPEID, D_CXXONLY | D_CXXWARN }, 528 1.1 mrg { "typeof", RID_TYPEOF, D_ASM | D_EXT }, 529 1.1 mrg { "union", RID_UNION, 0 }, 530 1.1 mrg { "unsigned", RID_UNSIGNED, 0 }, 531 1.1 mrg { "using", RID_USING, D_CXXONLY | D_CXXWARN }, 532 1.1 mrg { "virtual", RID_VIRTUAL, D_CXXONLY | D_CXXWARN }, 533 1.1 mrg { "void", RID_VOID, 0 }, 534 1.1 mrg { "volatile", RID_VOLATILE, 0 }, 535 1.1 mrg { "wchar_t", RID_WCHAR, D_CXXONLY }, 536 1.1 mrg { "while", RID_WHILE, 0 }, 537 1.1 mrg { "__is_assignable", RID_IS_ASSIGNABLE, D_CXXONLY }, 538 1.1 mrg { "__is_constructible", RID_IS_CONSTRUCTIBLE, D_CXXONLY }, 539 1.1 mrg { "__is_nothrow_assignable", RID_IS_NOTHROW_ASSIGNABLE, D_CXXONLY }, 540 1.1 mrg { "__is_nothrow_constructible", RID_IS_NOTHROW_CONSTRUCTIBLE, D_CXXONLY }, 541 1.1 mrg 542 1.1 mrg /* C++ transactional memory. */ 543 1.1 mrg { "synchronized", RID_SYNCHRONIZED, D_CXX_OBJC | D_TRANSMEM }, 544 1.1 mrg { "atomic_noexcept", RID_ATOMIC_NOEXCEPT, D_CXXONLY | D_TRANSMEM }, 545 1.1 mrg { "atomic_cancel", RID_ATOMIC_CANCEL, D_CXXONLY | D_TRANSMEM }, 546 1.1 mrg { "atomic_commit", RID_TRANSACTION_ATOMIC, D_CXXONLY | D_TRANSMEM }, 547 1.1 mrg 548 1.1 mrg /* Concepts-related keywords */ 549 1.1 mrg { "concept", RID_CONCEPT, D_CXX_CONCEPTS_FLAGS | D_CXXWARN }, 550 1.1 mrg { "requires", RID_REQUIRES, D_CXX_CONCEPTS_FLAGS | D_CXXWARN }, 551 1.1 mrg 552 1.1 mrg /* Modules-related keywords, these are internal unspellable tokens, 553 1.1 mrg created by the preprocessor. */ 554 1.1 mrg { "module ", RID__MODULE, D_CXX_MODULES_FLAGS | D_CXXWARN }, 555 1.1 mrg { "import ", RID__IMPORT, D_CXX_MODULES_FLAGS | D_CXXWARN }, 556 1.1 mrg { "export ", RID__EXPORT, D_CXX_MODULES_FLAGS | D_CXXWARN }, 557 1.1 mrg 558 1.1 mrg /* Coroutines-related keywords */ 559 1.1 mrg { "co_await", RID_CO_AWAIT, D_CXX_COROUTINES_FLAGS | D_CXXWARN }, 560 1.1 mrg { "co_yield", RID_CO_YIELD, D_CXX_COROUTINES_FLAGS | D_CXXWARN }, 561 1.1 mrg { "co_return", RID_CO_RETURN, D_CXX_COROUTINES_FLAGS | D_CXXWARN }, 562 1.1 mrg 563 1.1 mrg /* These Objective-C keywords are recognized only immediately after 564 1.1 mrg an '@'. */ 565 1.1 mrg { "compatibility_alias", RID_AT_ALIAS, D_OBJC }, 566 1.1 mrg { "defs", RID_AT_DEFS, D_OBJC }, 567 1.1 mrg { "encode", RID_AT_ENCODE, D_OBJC }, 568 1.1 mrg { "end", RID_AT_END, D_OBJC }, 569 1.1 mrg { "implementation", RID_AT_IMPLEMENTATION, D_OBJC }, 570 1.1 mrg { "interface", RID_AT_INTERFACE, D_OBJC }, 571 1.1 mrg { "protocol", RID_AT_PROTOCOL, D_OBJC }, 572 1.1 mrg { "selector", RID_AT_SELECTOR, D_OBJC }, 573 1.1 mrg { "finally", RID_AT_FINALLY, D_OBJC }, 574 1.1 mrg { "optional", RID_AT_OPTIONAL, D_OBJC }, 575 1.1 mrg { "required", RID_AT_REQUIRED, D_OBJC }, 576 1.1 mrg { "property", RID_AT_PROPERTY, D_OBJC }, 577 1.1 mrg { "package", RID_AT_PACKAGE, D_OBJC }, 578 1.1 mrg { "synthesize", RID_AT_SYNTHESIZE, D_OBJC }, 579 1.1 mrg { "dynamic", RID_AT_DYNAMIC, D_OBJC }, 580 1.1 mrg /* These are recognized only in protocol-qualifier context 581 1.1 mrg (see above) */ 582 1.1 mrg { "bycopy", RID_BYCOPY, D_OBJC }, 583 1.1 mrg { "byref", RID_BYREF, D_OBJC }, 584 1.1 mrg { "in", RID_IN, D_OBJC }, 585 1.1 mrg { "inout", RID_INOUT, D_OBJC }, 586 1.1 mrg { "oneway", RID_ONEWAY, D_OBJC }, 587 1.1 mrg { "out", RID_OUT, D_OBJC }, 588 1.1 mrg /* These are recognized inside a property attribute list */ 589 1.1 mrg { "assign", RID_ASSIGN, D_OBJC }, 590 1.1 mrg { "atomic", RID_PROPATOMIC, D_OBJC }, 591 1.1 mrg { "copy", RID_COPY, D_OBJC }, 592 1.1 mrg { "getter", RID_GETTER, D_OBJC }, 593 1.1 mrg { "nonatomic", RID_NONATOMIC, D_OBJC }, 594 1.1 mrg { "readonly", RID_READONLY, D_OBJC }, 595 1.1 mrg { "readwrite", RID_READWRITE, D_OBJC }, 596 1.1 mrg { "retain", RID_RETAIN, D_OBJC }, 597 1.1 mrg { "setter", RID_SETTER, D_OBJC }, 598 1.1 mrg /* These are Objective C implementation of nullability, accepted only in 599 1.1 mrg specific contexts. */ 600 1.1 mrg { "null_unspecified", RID_NULL_UNSPECIFIED, D_OBJC }, 601 1.1 mrg { "nullable", RID_NULLABLE, D_OBJC }, 602 1.1 mrg { "nonnull", RID_NONNULL, D_OBJC }, 603 1.1 mrg { "null_resettable", RID_NULL_RESETTABLE, D_OBJC }, 604 1.1 mrg }; 605 1.1 mrg 606 1.1 mrg const unsigned int num_c_common_reswords = 607 1.1 mrg sizeof c_common_reswords / sizeof (struct c_common_resword); 608 1.1 mrg 609 1.1 mrg /* Return identifier for address space AS. */ 610 1.1 mrg 611 1.1 mrg const char * 612 1.1 mrg c_addr_space_name (addr_space_t as) 613 1.1 mrg { 614 1.1 mrg int rid = RID_FIRST_ADDR_SPACE + as; 615 1.1 mrg gcc_assert (ridpointers [rid]); 616 1.1 mrg return IDENTIFIER_POINTER (ridpointers [rid]); 617 1.1 mrg } 618 1.1 mrg 619 1.1 mrg /* Push current bindings for the function name VAR_DECLS. */ 620 1.1 mrg 621 1.1 mrg void 622 1.1 mrg start_fname_decls (void) 623 1.1 mrg { 624 1.1 mrg unsigned ix; 625 1.1 mrg tree saved = NULL_TREE; 626 1.1 mrg 627 1.1 mrg for (ix = 0; fname_vars[ix].decl; ix++) 628 1.1 mrg { 629 1.1 mrg tree decl = *fname_vars[ix].decl; 630 1.1 mrg 631 1.1 mrg if (decl) 632 1.1 mrg { 633 1.1 mrg saved = tree_cons (decl, build_int_cst (integer_type_node, ix), 634 1.1 mrg saved); 635 1.1 mrg *fname_vars[ix].decl = NULL_TREE; 636 1.1 mrg } 637 1.1 mrg } 638 1.1 mrg if (saved || saved_function_name_decls) 639 1.1 mrg /* Normally they'll have been NULL, so only push if we've got a 640 1.1 mrg stack, or they are non-NULL. */ 641 1.1 mrg saved_function_name_decls = tree_cons (saved, NULL_TREE, 642 1.1 mrg saved_function_name_decls); 643 1.1 mrg } 644 1.1 mrg 645 1.1 mrg /* Finish up the current bindings, adding them into the current function's 646 1.1 mrg statement tree. This must be done _before_ finish_stmt_tree is called. 647 1.1 mrg If there is no current function, we must be at file scope and no statements 648 1.1 mrg are involved. Pop the previous bindings. */ 649 1.1 mrg 650 1.1 mrg void 651 1.1 mrg finish_fname_decls (void) 652 1.1 mrg { 653 1.1 mrg unsigned ix; 654 1.1 mrg tree stmts = NULL_TREE; 655 1.1 mrg tree stack = saved_function_name_decls; 656 1.1 mrg 657 1.1 mrg for (; stack && TREE_VALUE (stack); stack = TREE_CHAIN (stack)) 658 1.1 mrg append_to_statement_list (TREE_VALUE (stack), &stmts); 659 1.1 mrg 660 1.1 mrg if (stmts) 661 1.1 mrg { 662 1.1 mrg tree *bodyp = &DECL_SAVED_TREE (current_function_decl); 663 1.1 mrg 664 1.1 mrg if (TREE_CODE (*bodyp) == BIND_EXPR) 665 1.1 mrg bodyp = &BIND_EXPR_BODY (*bodyp); 666 1.1 mrg 667 1.1 mrg append_to_statement_list_force (*bodyp, &stmts); 668 1.1 mrg *bodyp = stmts; 669 1.1 mrg } 670 1.1 mrg 671 1.1 mrg for (ix = 0; fname_vars[ix].decl; ix++) 672 1.1 mrg *fname_vars[ix].decl = NULL_TREE; 673 1.1 mrg 674 1.1 mrg if (stack) 675 1.1 mrg { 676 1.1 mrg /* We had saved values, restore them. */ 677 1.1 mrg tree saved; 678 1.1 mrg 679 1.1 mrg for (saved = TREE_PURPOSE (stack); saved; saved = TREE_CHAIN (saved)) 680 1.1 mrg { 681 1.1 mrg tree decl = TREE_PURPOSE (saved); 682 1.1 mrg unsigned ix = TREE_INT_CST_LOW (TREE_VALUE (saved)); 683 1.1 mrg 684 1.1 mrg *fname_vars[ix].decl = decl; 685 1.1 mrg } 686 1.1 mrg stack = TREE_CHAIN (stack); 687 1.1 mrg } 688 1.1 mrg saved_function_name_decls = stack; 689 1.1 mrg } 690 1.1 mrg 691 1.1 mrg /* Return the text name of the current function, suitably prettified 692 1.1 mrg by PRETTY_P. Return string must be freed by caller. */ 693 1.1 mrg 694 1.1 mrg const char * 695 1.1 mrg fname_as_string (int pretty_p) 696 1.1 mrg { 697 1.1 mrg const char *name = "top level"; 698 1.1 mrg char *namep; 699 1.1 mrg int vrb = 2, len; 700 1.1 mrg cpp_string cstr = { 0, 0 }, strname; 701 1.1 mrg 702 1.1 mrg if (!pretty_p) 703 1.1 mrg { 704 1.1 mrg name = ""; 705 1.1 mrg vrb = 0; 706 1.1 mrg } 707 1.1 mrg 708 1.1 mrg if (current_function_decl) 709 1.1 mrg name = lang_hooks.decl_printable_name (current_function_decl, vrb); 710 1.1 mrg 711 1.1 mrg len = strlen (name) + 3; /* Two for '"'s. One for NULL. */ 712 1.1 mrg 713 1.1 mrg namep = XNEWVEC (char, len); 714 1.1 mrg snprintf (namep, len, "\"%s\"", name); 715 1.1 mrg strname.text = (unsigned char *) namep; 716 1.1 mrg strname.len = len - 1; 717 1.1 mrg 718 1.1 mrg if (cpp_interpret_string (parse_in, &strname, 1, &cstr, CPP_STRING)) 719 1.1 mrg { 720 1.1 mrg XDELETEVEC (namep); 721 1.1 mrg return (const char *) cstr.text; 722 1.1 mrg } 723 1.1 mrg 724 1.1 mrg return namep; 725 1.1 mrg } 726 1.1 mrg 727 1.1 mrg /* Return the VAR_DECL for a const char array naming the current 728 1.1 mrg function. If the VAR_DECL has not yet been created, create it 729 1.1 mrg now. RID indicates how it should be formatted and IDENTIFIER_NODE 730 1.1 mrg ID is its name (unfortunately C and C++ hold the RID values of 731 1.1 mrg keywords in different places, so we can't derive RID from ID in 732 1.1 mrg this language independent code. LOC is the location of the 733 1.1 mrg function. */ 734 1.1 mrg 735 1.1 mrg tree 736 1.1 mrg fname_decl (location_t loc, unsigned int rid, tree id) 737 1.1 mrg { 738 1.1 mrg unsigned ix; 739 1.1 mrg tree decl = NULL_TREE; 740 1.1 mrg 741 1.1 mrg for (ix = 0; fname_vars[ix].decl; ix++) 742 1.1 mrg if (fname_vars[ix].rid == rid) 743 1.1 mrg break; 744 1.1 mrg 745 1.1 mrg decl = *fname_vars[ix].decl; 746 1.1 mrg if (!decl) 747 1.1 mrg { 748 1.1 mrg /* If a tree is built here, it would normally have the lineno of 749 1.1 mrg the current statement. Later this tree will be moved to the 750 1.1 mrg beginning of the function and this line number will be wrong. 751 1.1 mrg To avoid this problem set the lineno to 0 here; that prevents 752 1.1 mrg it from appearing in the RTL. */ 753 1.1 mrg tree stmts; 754 1.1 mrg location_t saved_location = input_location; 755 1.1 mrg input_location = UNKNOWN_LOCATION; 756 1.1 mrg 757 1.1 mrg stmts = push_stmt_list (); 758 1.1 mrg decl = (*make_fname_decl) (loc, id, fname_vars[ix].pretty); 759 1.1 mrg stmts = pop_stmt_list (stmts); 760 1.1 mrg if (!IS_EMPTY_STMT (stmts)) 761 1.1 mrg saved_function_name_decls 762 1.1 mrg = tree_cons (decl, stmts, saved_function_name_decls); 763 1.1 mrg *fname_vars[ix].decl = decl; 764 1.1 mrg input_location = saved_location; 765 1.1 mrg } 766 1.1 mrg if (!ix && !current_function_decl) 767 1.1 mrg pedwarn (loc, 0, "%qD is not defined outside of function scope", decl); 768 1.1 mrg 769 1.1 mrg return decl; 770 1.1 mrg } 771 1.1 mrg 772 1.1 mrg /* Given a STRING_CST, give it a suitable array-of-chars data type. */ 773 1.1 mrg 774 1.1 mrg tree 775 1.1 mrg fix_string_type (tree value) 776 1.1 mrg { 777 1.1 mrg int length = TREE_STRING_LENGTH (value); 778 1.1 mrg int nchars, charsz; 779 1.1 mrg tree e_type, i_type, a_type; 780 1.1 mrg 781 1.1 mrg /* Compute the number of elements, for the array type. */ 782 1.1 mrg if (TREE_TYPE (value) == char_array_type_node || !TREE_TYPE (value)) 783 1.1 mrg { 784 1.1 mrg charsz = 1; 785 1.1 mrg e_type = char_type_node; 786 1.1 mrg } 787 1.1 mrg else if (flag_char8_t && TREE_TYPE (value) == char8_array_type_node) 788 1.1 mrg { 789 1.1 mrg charsz = TYPE_PRECISION (char8_type_node) / BITS_PER_UNIT; 790 1.1 mrg e_type = char8_type_node; 791 1.1 mrg } 792 1.1 mrg else if (TREE_TYPE (value) == char16_array_type_node) 793 1.1 mrg { 794 1.1 mrg charsz = TYPE_PRECISION (char16_type_node) / BITS_PER_UNIT; 795 1.1 mrg e_type = char16_type_node; 796 1.1 mrg } 797 1.1 mrg else if (TREE_TYPE (value) == char32_array_type_node) 798 1.1 mrg { 799 1.1 mrg charsz = TYPE_PRECISION (char32_type_node) / BITS_PER_UNIT; 800 1.1 mrg e_type = char32_type_node; 801 1.1 mrg } 802 1.1 mrg else 803 1.1 mrg { 804 1.1 mrg charsz = TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT; 805 1.1 mrg e_type = wchar_type_node; 806 1.1 mrg } 807 1.1 mrg 808 1.1 mrg /* This matters only for targets where ssizetype has smaller precision 809 1.1 mrg than 32 bits. */ 810 1.1 mrg if (wi::lts_p (wi::to_wide (TYPE_MAX_VALUE (ssizetype)), length)) 811 1.1 mrg { 812 1.1 mrg error ("size of string literal is too large"); 813 1.1 mrg length = tree_to_shwi (TYPE_MAX_VALUE (ssizetype)) / charsz * charsz; 814 1.1 mrg char *str = CONST_CAST (char *, TREE_STRING_POINTER (value)); 815 1.1 mrg memset (str + length, '\0', 816 1.1 mrg MIN (TREE_STRING_LENGTH (value) - length, charsz)); 817 1.1 mrg TREE_STRING_LENGTH (value) = length; 818 1.1 mrg } 819 1.1 mrg nchars = length / charsz; 820 1.1 mrg 821 1.1 mrg /* C89 2.2.4.1, C99 5.2.4.1 (Translation limits). The analogous 822 1.1 mrg limit in C++98 Annex B is very large (65536) and is not normative, 823 1.1 mrg so we do not diagnose it (warn_overlength_strings is forced off 824 1.1 mrg in c_common_post_options). */ 825 1.1 mrg if (warn_overlength_strings) 826 1.1 mrg { 827 1.1 mrg const int nchars_max = flag_isoc99 ? 4095 : 509; 828 1.1 mrg const int relevant_std = flag_isoc99 ? 99 : 90; 829 1.1 mrg if (nchars - 1 > nchars_max) 830 1.1 mrg /* Translators: The %d after 'ISO C' will be 90 or 99. Do not 831 1.1 mrg separate the %d from the 'C'. 'ISO' should not be 832 1.1 mrg translated, but it may be moved after 'C%d' in languages 833 1.1 mrg where modifiers follow nouns. */ 834 1.1 mrg pedwarn (input_location, OPT_Woverlength_strings, 835 1.1 mrg "string length %qd is greater than the length %qd " 836 1.1 mrg "ISO C%d compilers are required to support", 837 1.1 mrg nchars - 1, nchars_max, relevant_std); 838 1.1 mrg } 839 1.1 mrg 840 1.1 mrg /* Create the array type for the string constant. The ISO C++ 841 1.1 mrg standard says that a string literal has type `const char[N]' or 842 1.1 mrg `const wchar_t[N]'. We use the same logic when invoked as a C 843 1.1 mrg front-end with -Wwrite-strings. 844 1.1 mrg ??? We should change the type of an expression depending on the 845 1.1 mrg state of a warning flag. We should just be warning -- see how 846 1.1 mrg this is handled in the C++ front-end for the deprecated implicit 847 1.1 mrg conversion from string literals to `char*' or `wchar_t*'. 848 1.1 mrg 849 1.1 mrg The C++ front end relies on TYPE_MAIN_VARIANT of a cv-qualified 850 1.1 mrg array type being the unqualified version of that type. 851 1.1 mrg Therefore, if we are constructing an array of const char, we must 852 1.1 mrg construct the matching unqualified array type first. The C front 853 1.1 mrg end does not require this, but it does no harm, so we do it 854 1.1 mrg unconditionally. */ 855 1.1 mrg i_type = build_index_type (size_int (nchars - 1)); 856 1.1 mrg a_type = build_array_type (e_type, i_type); 857 1.1 mrg if (c_dialect_cxx() || warn_write_strings) 858 1.1 mrg a_type = c_build_qualified_type (a_type, TYPE_QUAL_CONST); 859 1.1 mrg 860 1.1 mrg TREE_TYPE (value) = a_type; 861 1.1 mrg TREE_CONSTANT (value) = 1; 862 1.1 mrg TREE_READONLY (value) = 1; 863 1.1 mrg TREE_STATIC (value) = 1; 864 1.1 mrg return value; 865 1.1 mrg } 866 1.1 mrg 867 1.1 mrg /* Given a string of type STRING_TYPE, determine what kind of string 868 1.1 mrg token would give an equivalent execution encoding: CPP_STRING, 869 1.1 mrg CPP_STRING16, or CPP_STRING32. Return CPP_OTHER in case of error. 870 1.1 mrg This may not be exactly the string token type that initially created 871 1.1 mrg the string, since CPP_WSTRING is indistinguishable from the 16/32 bit 872 1.1 mrg string type, and CPP_UTF8STRING is indistinguishable from CPP_STRING 873 1.1 mrg at this point. 874 1.1 mrg 875 1.1 mrg This effectively reverses part of the logic in lex_string and 876 1.1 mrg fix_string_type. */ 877 1.1 mrg 878 1.1 mrg static enum cpp_ttype 879 1.1 mrg get_cpp_ttype_from_string_type (tree string_type) 880 1.1 mrg { 881 1.1 mrg gcc_assert (string_type); 882 1.1 mrg if (TREE_CODE (string_type) == POINTER_TYPE) 883 1.1 mrg string_type = TREE_TYPE (string_type); 884 1.1 mrg 885 1.1 mrg if (TREE_CODE (string_type) != ARRAY_TYPE) 886 1.1 mrg return CPP_OTHER; 887 1.1 mrg 888 1.1 mrg tree element_type = TREE_TYPE (string_type); 889 1.1 mrg if (TREE_CODE (element_type) != INTEGER_TYPE) 890 1.1 mrg return CPP_OTHER; 891 1.1 mrg 892 1.1 mrg int bits_per_character = TYPE_PRECISION (element_type); 893 1.1 mrg switch (bits_per_character) 894 1.1 mrg { 895 1.1 mrg case 8: 896 1.1 mrg return CPP_STRING; /* It could have also been CPP_UTF8STRING. */ 897 1.1 mrg case 16: 898 1.1 mrg return CPP_STRING16; 899 1.1 mrg case 32: 900 1.1 mrg return CPP_STRING32; 901 1.1 mrg } 902 1.1 mrg 903 1.1 mrg return CPP_OTHER; 904 1.1 mrg } 905 1.1 mrg 906 1.1 mrg /* The global record of string concatentations, for use in 907 1.1 mrg extracting locations within string literals. */ 908 1.1 mrg 909 1.1 mrg GTY(()) string_concat_db *g_string_concat_db; 910 1.1 mrg 911 1.1 mrg /* Implementation of LANG_HOOKS_GET_SUBSTRING_LOCATION. */ 912 1.1 mrg 913 1.1 mrg const char * 914 1.1 mrg c_get_substring_location (const substring_loc &substr_loc, 915 1.1 mrg location_t *out_loc) 916 1.1 mrg { 917 1.1 mrg enum cpp_ttype tok_type 918 1.1 mrg = get_cpp_ttype_from_string_type (substr_loc.get_string_type ()); 919 1.1 mrg if (tok_type == CPP_OTHER) 920 1.1 mrg return "unrecognized string type"; 921 1.1 mrg 922 1.1 mrg return get_location_within_string (parse_in, g_string_concat_db, 923 1.1 mrg substr_loc.get_fmt_string_loc (), 924 1.1 mrg tok_type, 925 1.1 mrg substr_loc.get_caret_idx (), 926 1.1 mrg substr_loc.get_start_idx (), 927 1.1 mrg substr_loc.get_end_idx (), 928 1.1 mrg out_loc); 929 1.1 mrg } 930 1.1 mrg 931 1.1 mrg 932 1.1 mrg /* Return true iff T is a boolean promoted to int. */ 934 1.1 mrg 935 1.1 mrg bool 936 1.1 mrg bool_promoted_to_int_p (tree t) 937 1.1 mrg { 938 1.1 mrg return (CONVERT_EXPR_P (t) 939 1.1 mrg && TREE_TYPE (t) == integer_type_node 940 1.1 mrg && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == BOOLEAN_TYPE); 941 1.1 mrg } 942 1.1 mrg 943 1.1 mrg /* vector_targets_convertible_p is used for vector pointer types. The 944 1.1 mrg callers perform various checks that the qualifiers are satisfactory, 945 1.1 mrg while OTOH vector_targets_convertible_p ignores the number of elements 946 1.1 mrg in the vectors. That's fine with vector pointers as we can consider, 947 1.1 mrg say, a vector of 8 elements as two consecutive vectors of 4 elements, 948 1.1 mrg and that does not require and conversion of the pointer values. 949 1.1 mrg In contrast, vector_types_convertible_p and 950 1.1 mrg vector_types_compatible_elements_p are used for vector value types. */ 951 1.1 mrg /* True if pointers to distinct types T1 and T2 can be converted to 952 1.1 mrg each other without an explicit cast. Only returns true for opaque 953 1.1 mrg vector types. */ 954 1.1 mrg bool 955 1.1 mrg vector_targets_convertible_p (const_tree t1, const_tree t2) 956 1.1 mrg { 957 1.1 mrg if (VECTOR_TYPE_P (t1) && VECTOR_TYPE_P (t2) 958 1.1 mrg && (TYPE_VECTOR_OPAQUE (t1) || TYPE_VECTOR_OPAQUE (t2)) 959 1.1 mrg && tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2))) 960 1.1 mrg return true; 961 1.1 mrg 962 1.1 mrg return false; 963 1.1 mrg } 964 1.1 mrg 965 1.1 mrg /* vector_types_convertible_p is used for vector value types. 966 1.1 mrg It could in principle call vector_targets_convertible_p as a subroutine, 967 1.1 mrg but then the check for vector type would be duplicated with its callers, 968 1.1 mrg and also the purpose of vector_targets_convertible_p would become 969 1.1 mrg muddled. 970 1.1 mrg Where vector_types_convertible_p returns true, a conversion might still be 971 1.1 mrg needed to make the types match. 972 1.1 mrg In contrast, vector_targets_convertible_p is used for vector pointer 973 1.1 mrg values, and vector_types_compatible_elements_p is used specifically 974 1.1 mrg in the context for binary operators, as a check if use is possible without 975 1.1 mrg conversion. */ 976 1.1 mrg /* True if vector types T1 and T2 can be converted to each other 977 1.1 mrg without an explicit cast. If EMIT_LAX_NOTE is true, and T1 and T2 978 1.1 mrg can only be converted with -flax-vector-conversions yet that is not 979 1.1 mrg in effect, emit a note telling the user about that option if such 980 1.1 mrg a note has not previously been emitted. */ 981 1.1 mrg bool 982 1.1 mrg vector_types_convertible_p (const_tree t1, const_tree t2, bool emit_lax_note) 983 1.1 mrg { 984 1.1 mrg static bool emitted_lax_note = false; 985 1.1 mrg bool convertible_lax; 986 1.1 mrg 987 1.1 mrg if ((TYPE_VECTOR_OPAQUE (t1) || TYPE_VECTOR_OPAQUE (t2)) 988 1.1 mrg && tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2))) 989 1.1 mrg return true; 990 1.1 mrg 991 1.1 mrg convertible_lax = 992 1.1 mrg (tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2)) 993 1.1 mrg && (TREE_CODE (TREE_TYPE (t1)) != REAL_TYPE 994 1.1 mrg || known_eq (TYPE_VECTOR_SUBPARTS (t1), 995 1.1 mrg TYPE_VECTOR_SUBPARTS (t2))) 996 1.1 mrg && (INTEGRAL_TYPE_P (TREE_TYPE (t1)) 997 1.1 mrg == INTEGRAL_TYPE_P (TREE_TYPE (t2)))); 998 1.1 mrg 999 1.1 mrg if (!convertible_lax || flag_lax_vector_conversions) 1000 1.1 mrg return convertible_lax; 1001 1.1 mrg 1002 1.1 mrg if (known_eq (TYPE_VECTOR_SUBPARTS (t1), TYPE_VECTOR_SUBPARTS (t2)) 1003 1.1 mrg && lang_hooks.types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2))) 1004 1.1 mrg return true; 1005 1.1 mrg 1006 1.1 mrg if (emit_lax_note && !emitted_lax_note) 1007 1.1 mrg { 1008 1.1 mrg emitted_lax_note = true; 1009 1.1 mrg inform (input_location, "use %<-flax-vector-conversions%> to permit " 1010 1.1 mrg "conversions between vectors with differing " 1011 1.1 mrg "element types or numbers of subparts"); 1012 1.1 mrg } 1013 1.1 mrg 1014 1.1 mrg return false; 1015 1.1 mrg } 1016 1.1 mrg 1017 1.1 mrg /* Build a VEC_PERM_EXPR if V0, V1 and MASK are not error_mark_nodes 1018 1.1 mrg and have vector types, V0 has the same type as V1, and the number of 1019 1.1 mrg elements of V0, V1, MASK is the same. 1020 1.1 mrg 1021 1.1 mrg In case V1 is a NULL_TREE it is assumed that __builtin_shuffle was 1022 1.1 mrg called with two arguments. In this case implementation passes the 1023 1.1 mrg first argument twice in order to share the same tree code. This fact 1024 1.1 mrg could enable the mask-values being twice the vector length. This is 1025 1.1 mrg an implementation accident and this semantics is not guaranteed to 1026 1.1 mrg the user. */ 1027 1.1 mrg tree 1028 1.1 mrg c_build_vec_perm_expr (location_t loc, tree v0, tree v1, tree mask, 1029 1.1 mrg bool complain) 1030 1.1 mrg { 1031 1.1 mrg tree ret; 1032 1.1 mrg bool wrap = true; 1033 1.1 mrg bool maybe_const = false; 1034 1.1 mrg bool two_arguments = false; 1035 1.1 mrg 1036 1.1 mrg if (v1 == NULL_TREE) 1037 1.1 mrg { 1038 1.1 mrg two_arguments = true; 1039 1.1 mrg v1 = v0; 1040 1.1 mrg } 1041 1.1 mrg 1042 1.1 mrg if (v0 == error_mark_node || v1 == error_mark_node 1043 1.1 mrg || mask == error_mark_node) 1044 1.1 mrg return error_mark_node; 1045 1.1 mrg 1046 1.1 mrg if (!gnu_vector_type_p (TREE_TYPE (mask)) 1047 1.1 mrg || !VECTOR_INTEGER_TYPE_P (TREE_TYPE (mask))) 1048 1.1 mrg { 1049 1.1 mrg if (complain) 1050 1.1 mrg error_at (loc, "%<__builtin_shuffle%> last argument must " 1051 1.1 mrg "be an integer vector"); 1052 1.1 mrg return error_mark_node; 1053 1.1 mrg } 1054 1.1 mrg 1055 1.1 mrg if (!gnu_vector_type_p (TREE_TYPE (v0)) 1056 1.1 mrg || !gnu_vector_type_p (TREE_TYPE (v1))) 1057 1.1 mrg { 1058 1.1 mrg if (complain) 1059 1.1 mrg error_at (loc, "%<__builtin_shuffle%> arguments must be vectors"); 1060 1.1 mrg return error_mark_node; 1061 1.1 mrg } 1062 1.1 mrg 1063 1.1 mrg if (TYPE_MAIN_VARIANT (TREE_TYPE (v0)) != TYPE_MAIN_VARIANT (TREE_TYPE (v1))) 1064 1.1 mrg { 1065 1.1 mrg if (complain) 1066 1.1 mrg error_at (loc, "%<__builtin_shuffle%> argument vectors must be of " 1067 1.1 mrg "the same type"); 1068 1.1 mrg return error_mark_node; 1069 1.1 mrg } 1070 1.1 mrg 1071 1.1 mrg if (maybe_ne (TYPE_VECTOR_SUBPARTS (TREE_TYPE (v0)), 1072 1.1 mrg TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask))) 1073 1.1 mrg && maybe_ne (TYPE_VECTOR_SUBPARTS (TREE_TYPE (v1)), 1074 1.1 mrg TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask)))) 1075 1.1 mrg { 1076 1.1 mrg if (complain) 1077 1.1 mrg error_at (loc, "%<__builtin_shuffle%> number of elements of the " 1078 1.1 mrg "argument vector(s) and the mask vector should " 1079 1.1 mrg "be the same"); 1080 1.1 mrg return error_mark_node; 1081 1.1 mrg } 1082 1.1 mrg 1083 1.1 mrg if (GET_MODE_BITSIZE (SCALAR_TYPE_MODE (TREE_TYPE (TREE_TYPE (v0)))) 1084 1.1 mrg != GET_MODE_BITSIZE (SCALAR_TYPE_MODE (TREE_TYPE (TREE_TYPE (mask))))) 1085 1.1 mrg { 1086 1.1 mrg if (complain) 1087 1.1 mrg error_at (loc, "%<__builtin_shuffle%> argument vector(s) inner type " 1088 1.1 mrg "must have the same size as inner type of the mask"); 1089 1.1 mrg return error_mark_node; 1090 1.1 mrg } 1091 1.1 mrg 1092 1.1 mrg if (!c_dialect_cxx ()) 1093 1.1 mrg { 1094 1.1 mrg /* Avoid C_MAYBE_CONST_EXPRs inside VEC_PERM_EXPR. */ 1095 1.1 mrg v0 = c_fully_fold (v0, false, &maybe_const); 1096 1.1 mrg wrap &= maybe_const; 1097 1.1 mrg 1098 1.1 mrg if (two_arguments) 1099 1.1 mrg v1 = v0 = save_expr (v0); 1100 1.1 mrg else 1101 1.1 mrg { 1102 1.1 mrg v1 = c_fully_fold (v1, false, &maybe_const); 1103 1.1 mrg wrap &= maybe_const; 1104 1.1 mrg } 1105 1.1 mrg 1106 1.1 mrg mask = c_fully_fold (mask, false, &maybe_const); 1107 1.1 mrg wrap &= maybe_const; 1108 1.1 mrg } 1109 1.1 mrg else if (two_arguments) 1110 1.1 mrg v1 = v0 = save_expr (v0); 1111 1.1 mrg 1112 1.1 mrg ret = build3_loc (loc, VEC_PERM_EXPR, TREE_TYPE (v0), v0, v1, mask); 1113 1.1 mrg 1114 1.1 mrg if (!c_dialect_cxx () && !wrap) 1115 1.1 mrg ret = c_wrap_maybe_const (ret, true); 1116 1.1 mrg 1117 1.1 mrg return ret; 1118 1.1 mrg } 1119 1.1 mrg 1120 1.1 mrg /* Build a VEC_PERM_EXPR if V0, V1 are not error_mark_nodes 1121 1.1 mrg and have vector types, V0 has the same element type as V1, and the 1122 1.1 mrg number of elements the result is that of MASK. */ 1123 1.1 mrg tree 1124 1.1 mrg c_build_shufflevector (location_t loc, tree v0, tree v1, 1125 1.1 mrg const vec<tree> &mask, bool complain) 1126 1.1 mrg { 1127 1.1 mrg tree ret; 1128 1.1 mrg bool wrap = true; 1129 1.1 mrg bool maybe_const = false; 1130 1.1 mrg 1131 1.1 mrg if (v0 == error_mark_node || v1 == error_mark_node) 1132 1.1 mrg return error_mark_node; 1133 1.1 mrg 1134 1.1 mrg if (!gnu_vector_type_p (TREE_TYPE (v0)) 1135 1.1 mrg || !gnu_vector_type_p (TREE_TYPE (v1))) 1136 1.1 mrg { 1137 1.1 mrg if (complain) 1138 1.1 mrg error_at (loc, "%<__builtin_shufflevector%> arguments must be vectors"); 1139 1.1 mrg return error_mark_node; 1140 1.1 mrg } 1141 1.1 mrg 1142 1.1 mrg /* ??? In principle one could select a constant part of a variable size 1143 1.1 mrg vector but things get a bit awkward with trying to support this here. */ 1144 1.1 mrg unsigned HOST_WIDE_INT v0n, v1n; 1145 1.1 mrg if (!TYPE_VECTOR_SUBPARTS (TREE_TYPE (v0)).is_constant (&v0n) 1146 1.1 mrg || !TYPE_VECTOR_SUBPARTS (TREE_TYPE (v1)).is_constant (&v1n)) 1147 1.1 mrg { 1148 1.1 mrg if (complain) 1149 1.1 mrg error_at (loc, "%<__builtin_shufflevector%> arguments must be constant" 1150 1.1 mrg " size vectors"); 1151 1.1 mrg return error_mark_node; 1152 1.1 mrg } 1153 1.1 mrg 1154 1.1 mrg if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (v0))) 1155 1.1 mrg != TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (v1)))) 1156 1.1 mrg { 1157 1.1 mrg if (complain) 1158 1.1 mrg error_at (loc, "%<__builtin_shufflevector%> argument vectors must " 1159 1.1 mrg "have the same element type"); 1160 1.1 mrg return error_mark_node; 1161 1.1 mrg } 1162 1.1 mrg 1163 1.1 mrg if (!pow2p_hwi (mask.length ())) 1164 1.1 mrg { 1165 1.1 mrg if (complain) 1166 1.1 mrg error_at (loc, "%<__builtin_shufflevector%> must specify a result " 1167 1.1 mrg "with a power of two number of elements"); 1168 1.1 mrg return error_mark_node; 1169 1.1 mrg } 1170 1.1 mrg 1171 1.1 mrg if (!c_dialect_cxx ()) 1172 1.1 mrg { 1173 1.1 mrg /* Avoid C_MAYBE_CONST_EXPRs inside VEC_PERM_EXPR. */ 1174 1.1 mrg v0 = c_fully_fold (v0, false, &maybe_const); 1175 1.1 mrg wrap &= maybe_const; 1176 1.1 mrg 1177 1.1 mrg v1 = c_fully_fold (v1, false, &maybe_const); 1178 1.1 mrg wrap &= maybe_const; 1179 1.1 mrg } 1180 1.1 mrg 1181 1.1 mrg unsigned HOST_WIDE_INT maskl = MAX (mask.length (), MAX (v0n, v1n)); 1182 1.1 mrg unsigned HOST_WIDE_INT pad = (v0n < maskl ? maskl - v0n : 0); 1183 1.1 mrg vec_perm_builder sel (maskl, maskl, 1); 1184 1.1 mrg unsigned i; 1185 1.1 mrg for (i = 0; i < mask.length (); ++i) 1186 1.1 mrg { 1187 1.1 mrg tree idx = mask[i]; 1188 1.1 mrg if (!tree_fits_shwi_p (idx)) 1189 1.1 mrg { 1190 1.1 mrg if (complain) 1191 1.1 mrg error_at (loc, "invalid element index %qE to " 1192 1.1 mrg "%<__builtin_shufflevector%>", idx); 1193 1.1 mrg return error_mark_node; 1194 1.1 mrg } 1195 1.1 mrg HOST_WIDE_INT iidx = tree_to_shwi (idx); 1196 1.1 mrg if (iidx < -1 1197 1.1 mrg || (iidx != -1 1198 1.1 mrg && (unsigned HOST_WIDE_INT) iidx >= v0n + v1n)) 1199 1.1 mrg { 1200 1.1 mrg if (complain) 1201 1.1 mrg error_at (loc, "invalid element index %qE to " 1202 1.1 mrg "%<__builtin_shufflevector%>", idx); 1203 1.1 mrg return error_mark_node; 1204 1.1 mrg } 1205 1.1 mrg /* ??? Our VEC_PERM_EXPR does not allow for -1 yet. */ 1206 1.1 mrg if (iidx == -1) 1207 1.1 mrg iidx = i; 1208 1.1 mrg /* ??? Our VEC_PERM_EXPR does not allow different sized inputs, 1209 1.1 mrg so pad out a smaller v0. */ 1210 1.1 mrg else if ((unsigned HOST_WIDE_INT) iidx >= v0n) 1211 1.1 mrg iidx += pad; 1212 1.1 mrg sel.quick_push (iidx); 1213 1.1 mrg } 1214 1.1 mrg /* ??? VEC_PERM_EXPR does not support a result that is smaller than 1215 1.1 mrg the inputs, so we have to pad id out. */ 1216 1.1 mrg for (; i < maskl; ++i) 1217 1.1 mrg sel.quick_push (i); 1218 1.1 mrg 1219 1.1 mrg vec_perm_indices indices (sel, 2, maskl); 1220 1.1 mrg 1221 1.1 mrg tree ret_type = build_vector_type (TREE_TYPE (TREE_TYPE (v0)), maskl); 1222 1.1 mrg tree mask_type = build_vector_type (build_nonstandard_integer_type 1223 1.1 mrg (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (ret_type))), 1), 1224 1.1 mrg maskl); 1225 1.1 mrg /* Pad out arguments to the common vector size. */ 1226 1.1 mrg if (v0n < maskl) 1227 1.1 mrg { 1228 1.1 mrg constructor_elt elt = { NULL_TREE, build_zero_cst (TREE_TYPE (v0)) }; 1229 1.1 mrg v0 = build_constructor_single (ret_type, NULL_TREE, v0); 1230 1.1 mrg for (i = 1; i < maskl / v0n; ++i) 1231 1.1 mrg vec_safe_push (CONSTRUCTOR_ELTS (v0), elt); 1232 1.1 mrg } 1233 1.1 mrg if (v1n < maskl) 1234 1.1 mrg { 1235 1.1 mrg constructor_elt elt = { NULL_TREE, build_zero_cst (TREE_TYPE (v1)) }; 1236 1.1 mrg v1 = build_constructor_single (ret_type, NULL_TREE, v1); 1237 1.1 mrg for (i = 1; i < maskl / v1n; ++i) 1238 1.1 mrg vec_safe_push (CONSTRUCTOR_ELTS (v1), elt); 1239 1.1 mrg } 1240 1.1 mrg ret = build3_loc (loc, VEC_PERM_EXPR, ret_type, v0, v1, 1241 1.1 mrg vec_perm_indices_to_tree (mask_type, indices)); 1242 1.1 mrg /* Get the lowpart we are interested in. */ 1243 1.1 mrg if (mask.length () < maskl) 1244 1.1 mrg { 1245 1.1 mrg tree lpartt = build_vector_type (TREE_TYPE (ret_type), mask.length ()); 1246 1.1 mrg ret = build3_loc (loc, BIT_FIELD_REF, 1247 1.1 mrg lpartt, ret, TYPE_SIZE (lpartt), bitsize_zero_node); 1248 1.1 mrg /* Wrap the lowpart operation in a TARGET_EXPR so it gets a separate 1249 1.1 mrg temporary during gimplification. See PR101530 for cases where 1250 1.1 mrg we'd otherwise end up with non-toplevel BIT_FIELD_REFs. */ 1251 1.1 mrg tree tem = create_tmp_var_raw (lpartt); 1252 1.1 mrg DECL_CONTEXT (tem) = current_function_decl; 1253 1.1 mrg ret = build4 (TARGET_EXPR, lpartt, tem, ret, NULL_TREE, NULL_TREE); 1254 1.1 mrg TREE_SIDE_EFFECTS (ret) = 1; 1255 1.1 mrg } 1256 1.1 mrg 1257 1.1 mrg if (!c_dialect_cxx () && !wrap) 1258 1.1 mrg ret = c_wrap_maybe_const (ret, true); 1259 1.1 mrg 1260 1.1 mrg return ret; 1261 1.1 mrg } 1262 1.1 mrg 1263 1.1 mrg /* Build a VEC_CONVERT ifn for __builtin_convertvector builtin. */ 1264 1.1 mrg 1265 1.1 mrg tree 1266 1.1 mrg c_build_vec_convert (location_t loc1, tree expr, location_t loc2, tree type, 1267 1.1 mrg bool complain) 1268 1.1 mrg { 1269 1.1 mrg if (error_operand_p (type)) 1270 1.1 mrg return error_mark_node; 1271 1.1 mrg if (error_operand_p (expr)) 1272 1.1 mrg return error_mark_node; 1273 1.1 mrg 1274 1.1 mrg if (!gnu_vector_type_p (TREE_TYPE (expr)) 1275 1.1 mrg || (!VECTOR_INTEGER_TYPE_P (TREE_TYPE (expr)) 1276 1.1 mrg && !VECTOR_FLOAT_TYPE_P (TREE_TYPE (expr)))) 1277 1.1 mrg { 1278 1.1 mrg if (complain) 1279 1.1 mrg error_at (loc1, "%<__builtin_convertvector%> first argument must " 1280 1.1 mrg "be an integer or floating vector"); 1281 1.1 mrg return error_mark_node; 1282 1.1 mrg } 1283 1.1 mrg 1284 1.1 mrg if (!gnu_vector_type_p (type) 1285 1.1 mrg || (!VECTOR_INTEGER_TYPE_P (type) && !VECTOR_FLOAT_TYPE_P (type))) 1286 1.1 mrg { 1287 1.1 mrg if (complain) 1288 1.1 mrg error_at (loc2, "%<__builtin_convertvector%> second argument must " 1289 1.1 mrg "be an integer or floating vector type"); 1290 1.1 mrg return error_mark_node; 1291 1.1 mrg } 1292 1.1 mrg 1293 1.1 mrg if (maybe_ne (TYPE_VECTOR_SUBPARTS (TREE_TYPE (expr)), 1294 1.1 mrg TYPE_VECTOR_SUBPARTS (type))) 1295 1.1 mrg { 1296 1.1 mrg if (complain) 1297 1.1 mrg error_at (loc1, "%<__builtin_convertvector%> number of elements " 1298 1.1 mrg "of the first argument vector and the second argument " 1299 1.1 mrg "vector type should be the same"); 1300 1.1 mrg return error_mark_node; 1301 1.1 mrg } 1302 1.1 mrg 1303 1.1 mrg if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (expr))) 1304 1.1 mrg == TYPE_MAIN_VARIANT (TREE_TYPE (type))) 1305 1.1 mrg || (VECTOR_INTEGER_TYPE_P (TREE_TYPE (expr)) 1306 1.1 mrg && VECTOR_INTEGER_TYPE_P (type) 1307 1.1 mrg && (TYPE_PRECISION (TREE_TYPE (TREE_TYPE (expr))) 1308 1.1 mrg == TYPE_PRECISION (TREE_TYPE (type))))) 1309 1.1 mrg return build1_loc (loc1, VIEW_CONVERT_EXPR, type, expr); 1310 1.1 mrg 1311 1.1 mrg bool wrap = true; 1312 1.1 mrg bool maybe_const = false; 1313 1.1 mrg tree ret; 1314 1.1 mrg if (!c_dialect_cxx ()) 1315 1.1 mrg { 1316 1.1 mrg /* Avoid C_MAYBE_CONST_EXPRs inside of VEC_CONVERT argument. */ 1317 1.1 mrg expr = c_fully_fold (expr, false, &maybe_const); 1318 1.1 mrg wrap &= maybe_const; 1319 1.1 mrg } 1320 1.1 mrg 1321 1.1 mrg ret = build_call_expr_internal_loc (loc1, IFN_VEC_CONVERT, type, 1, expr); 1322 1.1 mrg 1323 1.1 mrg if (!wrap) 1324 1.1 mrg ret = c_wrap_maybe_const (ret, true); 1325 1.1 mrg 1326 1.1 mrg return ret; 1327 1.1 mrg } 1328 1.1 mrg 1329 1.1 mrg /* Like tree.cc:get_narrower, but retain conversion from C++0x scoped enum 1330 1.1 mrg to integral type. */ 1331 1.1 mrg 1332 1.1 mrg tree 1333 1.1 mrg c_common_get_narrower (tree op, int *unsignedp_ptr) 1334 1.1 mrg { 1335 1.1 mrg op = get_narrower (op, unsignedp_ptr); 1336 1.1 mrg 1337 1.1 mrg if (TREE_CODE (TREE_TYPE (op)) == ENUMERAL_TYPE 1338 1.1 mrg && ENUM_IS_SCOPED (TREE_TYPE (op))) 1339 1.1 mrg { 1340 1.1 mrg /* C++0x scoped enumerations don't implicitly convert to integral 1341 1.1 mrg type; if we stripped an explicit conversion to a larger type we 1342 1.1 mrg need to replace it so common_type will still work. */ 1343 1.1 mrg tree type = c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op)), 1344 1.1 mrg TYPE_UNSIGNED (TREE_TYPE (op))); 1345 1.1 mrg op = fold_convert (type, op); 1346 1.1 mrg } 1347 1.1 mrg return op; 1348 1.1 mrg } 1349 1.1 mrg 1350 1.1 mrg /* This is a helper function of build_binary_op. 1351 1.1 mrg 1352 1.1 mrg For certain operations if both args were extended from the same 1353 1.1 mrg smaller type, do the arithmetic in that type and then extend. 1354 1.1 mrg 1355 1.1 mrg BITWISE indicates a bitwise operation. 1356 1.1 mrg For them, this optimization is safe only if 1357 1.1 mrg both args are zero-extended or both are sign-extended. 1358 1.1 mrg Otherwise, we might change the result. 1359 1.1 mrg Eg, (short)-1 | (unsigned short)-1 is (int)-1 1360 1.1 mrg but calculated in (unsigned short) it would be (unsigned short)-1. 1361 1.1 mrg */ 1362 1.1 mrg tree 1363 1.1 mrg shorten_binary_op (tree result_type, tree op0, tree op1, bool bitwise) 1364 1.1 mrg { 1365 1.1 mrg int unsigned0, unsigned1; 1366 1.1 mrg tree arg0, arg1; 1367 1.1 mrg int uns; 1368 1.1 mrg tree type; 1369 1.1 mrg 1370 1.1 mrg /* Cast OP0 and OP1 to RESULT_TYPE. Doing so prevents 1371 1.1 mrg excessive narrowing when we call get_narrower below. For 1372 1.1 mrg example, suppose that OP0 is of unsigned int extended 1373 1.1 mrg from signed char and that RESULT_TYPE is long long int. 1374 1.1 mrg If we explicitly cast OP0 to RESULT_TYPE, OP0 would look 1375 1.1 mrg like 1376 1.1 mrg 1377 1.1 mrg (long long int) (unsigned int) signed_char 1378 1.1 mrg 1379 1.1 mrg which get_narrower would narrow down to 1380 1.1 mrg 1381 1.1 mrg (unsigned int) signed char 1382 1.1 mrg 1383 1.1 mrg If we do not cast OP0 first, get_narrower would return 1384 1.1 mrg signed_char, which is inconsistent with the case of the 1385 1.1 mrg explicit cast. */ 1386 1.1 mrg op0 = convert (result_type, op0); 1387 1.1 mrg op1 = convert (result_type, op1); 1388 1.1 mrg 1389 1.1 mrg arg0 = c_common_get_narrower (op0, &unsigned0); 1390 1.1 mrg arg1 = c_common_get_narrower (op1, &unsigned1); 1391 1.1 mrg 1392 1.1 mrg /* UNS is 1 if the operation to be done is an unsigned one. */ 1393 1.1 mrg uns = TYPE_UNSIGNED (result_type); 1394 1.1 mrg 1395 1.1 mrg /* Handle the case that OP0 (or OP1) does not *contain* a conversion 1396 1.1 mrg but it *requires* conversion to FINAL_TYPE. */ 1397 1.1 mrg 1398 1.1 mrg if ((TYPE_PRECISION (TREE_TYPE (op0)) 1399 1.1 mrg == TYPE_PRECISION (TREE_TYPE (arg0))) 1400 1.1 mrg && TREE_TYPE (op0) != result_type) 1401 1.1 mrg unsigned0 = TYPE_UNSIGNED (TREE_TYPE (op0)); 1402 1.1 mrg if ((TYPE_PRECISION (TREE_TYPE (op1)) 1403 1.1 mrg == TYPE_PRECISION (TREE_TYPE (arg1))) 1404 1.1 mrg && TREE_TYPE (op1) != result_type) 1405 1.1 mrg unsigned1 = TYPE_UNSIGNED (TREE_TYPE (op1)); 1406 1.1 mrg 1407 1.1 mrg /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */ 1408 1.1 mrg 1409 1.1 mrg /* For bitwise operations, signedness of nominal type 1410 1.1 mrg does not matter. Consider only how operands were extended. */ 1411 1.1 mrg if (bitwise) 1412 1.1 mrg uns = unsigned0; 1413 1.1 mrg 1414 1.1 mrg /* Note that in all three cases below we refrain from optimizing 1415 1.1 mrg an unsigned operation on sign-extended args. 1416 1.1 mrg That would not be valid. */ 1417 1.1 mrg 1418 1.1 mrg /* Both args variable: if both extended in same way 1419 1.1 mrg from same width, do it in that width. 1420 1.1 mrg Do it unsigned if args were zero-extended. */ 1421 1.1 mrg if ((TYPE_PRECISION (TREE_TYPE (arg0)) 1422 1.1 mrg < TYPE_PRECISION (result_type)) 1423 1.1 mrg && (TYPE_PRECISION (TREE_TYPE (arg1)) 1424 1.1 mrg == TYPE_PRECISION (TREE_TYPE (arg0))) 1425 1.1 mrg && unsigned0 == unsigned1 1426 1.1 mrg && (unsigned0 || !uns)) 1427 1.1 mrg return c_common_signed_or_unsigned_type 1428 1.1 mrg (unsigned0, common_type (TREE_TYPE (arg0), TREE_TYPE (arg1))); 1429 1.1 mrg 1430 1.1 mrg else if (TREE_CODE (arg0) == INTEGER_CST 1431 1.1 mrg && (unsigned1 || !uns) 1432 1.1 mrg && (TYPE_PRECISION (TREE_TYPE (arg1)) 1433 1.1 mrg < TYPE_PRECISION (result_type)) 1434 1.1 mrg && (type 1435 1.1 mrg = c_common_signed_or_unsigned_type (unsigned1, 1436 1.1 mrg TREE_TYPE (arg1))) 1437 1.1 mrg && !POINTER_TYPE_P (type) 1438 1.1 mrg && int_fits_type_p (arg0, type)) 1439 1.1 mrg return type; 1440 1.1 mrg 1441 1.1 mrg else if (TREE_CODE (arg1) == INTEGER_CST 1442 1.1 mrg && (unsigned0 || !uns) 1443 1.1 mrg && (TYPE_PRECISION (TREE_TYPE (arg0)) 1444 1.1 mrg < TYPE_PRECISION (result_type)) 1445 1.1 mrg && (type 1446 1.1 mrg = c_common_signed_or_unsigned_type (unsigned0, 1447 1.1 mrg TREE_TYPE (arg0))) 1448 1.1 mrg && !POINTER_TYPE_P (type) 1449 1.1 mrg && int_fits_type_p (arg1, type)) 1450 1.1 mrg return type; 1451 1.1 mrg 1452 1.1 mrg return result_type; 1453 1.1 mrg } 1454 1.1 mrg 1455 1.1 mrg /* Returns true iff any integer value of type FROM_TYPE can be represented as 1456 1.1 mrg real of type TO_TYPE. This is a helper function for unsafe_conversion_p. */ 1457 1.1 mrg 1458 1.1 mrg static bool 1459 1.1 mrg int_safely_convertible_to_real_p (const_tree from_type, const_tree to_type) 1460 1.1 mrg { 1461 1.1 mrg tree type_low_bound = TYPE_MIN_VALUE (from_type); 1462 1.1 mrg tree type_high_bound = TYPE_MAX_VALUE (from_type); 1463 1.1 mrg REAL_VALUE_TYPE real_low_bound = 1464 1.1 mrg real_value_from_int_cst (0, type_low_bound); 1465 1.1 mrg REAL_VALUE_TYPE real_high_bound = 1466 1.1 mrg real_value_from_int_cst (0, type_high_bound); 1467 1.1 mrg 1468 1.1 mrg return exact_real_truncate (TYPE_MODE (to_type), &real_low_bound) 1469 1.1 mrg && exact_real_truncate (TYPE_MODE (to_type), &real_high_bound); 1470 1.1 mrg } 1471 1.1 mrg 1472 1.1 mrg /* Checks if expression EXPR of complex/real/integer type cannot be converted 1473 1.1 mrg to the complex/real/integer type TYPE. Function returns non-zero when: 1474 1.1 mrg * EXPR is a constant which cannot be exactly converted to TYPE. 1475 1.1 mrg * EXPR is not a constant and size of EXPR's type > than size of TYPE, 1476 1.1 mrg for EXPR type and TYPE being both integers or both real, or both 1477 1.1 mrg complex. 1478 1.1 mrg * EXPR is not a constant of complex type and TYPE is a real or 1479 1.1 mrg an integer. 1480 1.1 mrg * EXPR is not a constant of real type and TYPE is an integer. 1481 1.1 mrg * EXPR is not a constant of integer type which cannot be 1482 1.1 mrg exactly converted to real type. 1483 1.1 mrg 1484 1.1 mrg Function allows conversions between types of different signedness if 1485 1.1 mrg CHECK_SIGN is false and can return SAFE_CONVERSION (zero) in that 1486 1.1 mrg case. Function can return UNSAFE_SIGN if CHECK_SIGN is true. 1487 1.1 mrg 1488 1.1 mrg RESULT, when non-null is the result of the conversion. When constant 1489 1.1 mrg it is included in the text of diagnostics. 1490 1.1 mrg 1491 1.1 mrg Function allows conversions from complex constants to non-complex types, 1492 1.1 mrg provided that imaginary part is zero and real part can be safely converted 1493 1.1 mrg to TYPE. */ 1494 1.1 mrg 1495 1.1 mrg enum conversion_safety 1496 1.1 mrg unsafe_conversion_p (tree type, tree expr, tree result, bool check_sign) 1497 1.1 mrg { 1498 1.1 mrg enum conversion_safety give_warning = SAFE_CONVERSION; /* is 0 or false */ 1499 1.1 mrg tree expr_type = TREE_TYPE (expr); 1500 1.1 mrg 1501 1.1 mrg expr = fold_for_warn (expr); 1502 1.1 mrg 1503 1.1 mrg if (TREE_CODE (expr) == REAL_CST || TREE_CODE (expr) == INTEGER_CST) 1504 1.1 mrg { 1505 1.1 mrg /* If type is complex, we are interested in compatibility with 1506 1.1 mrg underlying type. */ 1507 1.1 mrg if (TREE_CODE (type) == COMPLEX_TYPE) 1508 1.1 mrg type = TREE_TYPE (type); 1509 1.1 mrg 1510 1.1 mrg /* Warn for real constant that is not an exact integer converted 1511 1.1 mrg to integer type. */ 1512 1.1 mrg if (TREE_CODE (expr_type) == REAL_TYPE 1513 1.1 mrg && TREE_CODE (type) == INTEGER_TYPE) 1514 1.1 mrg { 1515 1.1 mrg if (!real_isinteger (TREE_REAL_CST_PTR (expr), TYPE_MODE (expr_type))) 1516 1.1 mrg give_warning = UNSAFE_REAL; 1517 1.1 mrg } 1518 1.1 mrg /* Warn for an integer constant that does not fit into integer type. */ 1519 1.1 mrg else if (TREE_CODE (expr_type) == INTEGER_TYPE 1520 1.1 mrg && TREE_CODE (type) == INTEGER_TYPE 1521 1.1 mrg && !int_fits_type_p (expr, type)) 1522 1.1 mrg { 1523 1.1 mrg if (TYPE_UNSIGNED (type) && !TYPE_UNSIGNED (expr_type) 1524 1.1 mrg && tree_int_cst_sgn (expr) < 0) 1525 1.1 mrg { 1526 1.1 mrg if (check_sign) 1527 1.1 mrg give_warning = UNSAFE_SIGN; 1528 1.1 mrg } 1529 1.1 mrg else if (!TYPE_UNSIGNED (type) && TYPE_UNSIGNED (expr_type)) 1530 1.1 mrg { 1531 1.1 mrg if (check_sign) 1532 1.1 mrg give_warning = UNSAFE_SIGN; 1533 1.1 mrg } 1534 1.1 mrg else 1535 1.1 mrg give_warning = UNSAFE_OTHER; 1536 1.1 mrg } 1537 1.1 mrg else if (TREE_CODE (type) == REAL_TYPE) 1538 1.1 mrg { 1539 1.1 mrg /* Warn for an integer constant that does not fit into real type. */ 1540 1.1 mrg if (TREE_CODE (expr_type) == INTEGER_TYPE) 1541 1.1 mrg { 1542 1.1 mrg REAL_VALUE_TYPE a = real_value_from_int_cst (0, expr); 1543 1.1 mrg if (!exact_real_truncate (TYPE_MODE (type), &a)) 1544 1.1 mrg give_warning = UNSAFE_REAL; 1545 1.1 mrg } 1546 1.1 mrg /* Warn for a real constant that does not fit into a smaller 1547 1.1 mrg real type. */ 1548 1.1 mrg else if (TREE_CODE (expr_type) == REAL_TYPE 1549 1.1 mrg && TYPE_PRECISION (type) < TYPE_PRECISION (expr_type)) 1550 1.1 mrg { 1551 1.1 mrg REAL_VALUE_TYPE a = TREE_REAL_CST (expr); 1552 1.1 mrg if (!exact_real_truncate (TYPE_MODE (type), &a)) 1553 1.1 mrg give_warning = UNSAFE_REAL; 1554 1.1 mrg } 1555 1.1 mrg } 1556 1.1 mrg } 1557 1.1 mrg 1558 1.1 mrg else if (TREE_CODE (expr) == COMPLEX_CST) 1559 1.1 mrg { 1560 1.1 mrg tree imag_part = TREE_IMAGPART (expr); 1561 1.1 mrg /* Conversion from complex constant with zero imaginary part, 1562 1.1 mrg perform check for conversion of real part. */ 1563 1.1 mrg if ((TREE_CODE (imag_part) == REAL_CST 1564 1.1 mrg && real_zerop (imag_part)) 1565 1.1 mrg || (TREE_CODE (imag_part) == INTEGER_CST 1566 1.1 mrg && integer_zerop (imag_part))) 1567 1.1 mrg /* Note: in this branch we use recursive call to unsafe_conversion_p 1568 1.1 mrg with different type of EXPR, but it is still safe, because when EXPR 1569 1.1 mrg is a constant, it's type is not used in text of generated warnings 1570 1.1 mrg (otherwise they could sound misleading). */ 1571 1.1 mrg return unsafe_conversion_p (type, TREE_REALPART (expr), result, 1572 1.1 mrg check_sign); 1573 1.1 mrg /* Conversion from complex constant with non-zero imaginary part. */ 1574 1.1 mrg else 1575 1.1 mrg { 1576 1.1 mrg /* Conversion to complex type. 1577 1.1 mrg Perform checks for both real and imaginary parts. */ 1578 1.1 mrg if (TREE_CODE (type) == COMPLEX_TYPE) 1579 1.1 mrg { 1580 1.1 mrg enum conversion_safety re_safety = 1581 1.1 mrg unsafe_conversion_p (type, TREE_REALPART (expr), 1582 1.1 mrg result, check_sign); 1583 1.1 mrg enum conversion_safety im_safety = 1584 1.1 mrg unsafe_conversion_p (type, imag_part, result, check_sign); 1585 1.1 mrg 1586 1.1 mrg /* Merge the results into appropriate single warning. */ 1587 1.1 mrg 1588 1.1 mrg /* Note: this case includes SAFE_CONVERSION, i.e. success. */ 1589 1.1 mrg if (re_safety == im_safety) 1590 1.1 mrg give_warning = re_safety; 1591 1.1 mrg else if (!re_safety && im_safety) 1592 1.1 mrg give_warning = im_safety; 1593 1.1 mrg else if (re_safety && !im_safety) 1594 1.1 mrg give_warning = re_safety; 1595 1.1 mrg else 1596 1.1 mrg give_warning = UNSAFE_OTHER; 1597 1.1 mrg } 1598 1.1 mrg /* Warn about conversion from complex to real or integer type. */ 1599 1.1 mrg else 1600 1.1 mrg give_warning = UNSAFE_IMAGINARY; 1601 1.1 mrg } 1602 1.1 mrg } 1603 1.1 mrg 1604 1.1 mrg /* Checks for remaining case: EXPR is not constant. */ 1605 1.1 mrg else 1606 1.1 mrg { 1607 1.1 mrg /* Warn for real types converted to integer types. */ 1608 1.1 mrg if (TREE_CODE (expr_type) == REAL_TYPE 1609 1.1 mrg && TREE_CODE (type) == INTEGER_TYPE) 1610 1.1 mrg give_warning = UNSAFE_REAL; 1611 1.1 mrg 1612 1.1 mrg else if (TREE_CODE (expr_type) == INTEGER_TYPE 1613 1.1 mrg && TREE_CODE (type) == INTEGER_TYPE) 1614 1.1 mrg { 1615 1.1 mrg /* Don't warn about unsigned char y = 0xff, x = (int) y; */ 1616 1.1 mrg expr = get_unwidened (expr, 0); 1617 1.1 mrg expr_type = TREE_TYPE (expr); 1618 1.1 mrg 1619 1.1 mrg /* Don't warn for short y; short x = ((int)y & 0xff); */ 1620 1.1 mrg if (TREE_CODE (expr) == BIT_AND_EXPR 1621 1.1 mrg || TREE_CODE (expr) == BIT_IOR_EXPR 1622 1.1 mrg || TREE_CODE (expr) == BIT_XOR_EXPR) 1623 1.1 mrg { 1624 1.1 mrg /* If both args were extended from a shortest type, 1625 1.1 mrg use that type if that is safe. */ 1626 1.1 mrg expr_type = shorten_binary_op (expr_type, 1627 1.1 mrg TREE_OPERAND (expr, 0), 1628 1.1 mrg TREE_OPERAND (expr, 1), 1629 1.1 mrg /* bitwise */1); 1630 1.1 mrg 1631 1.1 mrg if (TREE_CODE (expr) == BIT_AND_EXPR) 1632 1.1 mrg { 1633 1.1 mrg tree op0 = TREE_OPERAND (expr, 0); 1634 1.1 mrg tree op1 = TREE_OPERAND (expr, 1); 1635 1.1 mrg bool unsigned0 = TYPE_UNSIGNED (TREE_TYPE (op0)); 1636 1.1 mrg bool unsigned1 = TYPE_UNSIGNED (TREE_TYPE (op1)); 1637 1.1 mrg 1638 1.1 mrg /* If one of the operands is a non-negative constant 1639 1.1 mrg that fits in the target type, then the type of the 1640 1.1 mrg other operand does not matter. */ 1641 1.1 mrg if ((TREE_CODE (op0) == INTEGER_CST 1642 1.1 mrg && int_fits_type_p (op0, c_common_signed_type (type)) 1643 1.1 mrg && int_fits_type_p (op0, c_common_unsigned_type (type))) 1644 1.1 mrg || (TREE_CODE (op1) == INTEGER_CST 1645 1.1 mrg && int_fits_type_p (op1, c_common_signed_type (type)) 1646 1.1 mrg && int_fits_type_p (op1, 1647 1.1 mrg c_common_unsigned_type (type)))) 1648 1.1 mrg return SAFE_CONVERSION; 1649 1.1 mrg /* If constant is unsigned and fits in the target 1650 1.1 mrg type, then the result will also fit. */ 1651 1.1 mrg else if ((TREE_CODE (op0) == INTEGER_CST 1652 1.1 mrg && unsigned0 1653 1.1 mrg && int_fits_type_p (op0, type)) 1654 1.1 mrg || (TREE_CODE (op1) == INTEGER_CST 1655 1.1 mrg && unsigned1 1656 1.1 mrg && int_fits_type_p (op1, type))) 1657 1.1 mrg return SAFE_CONVERSION; 1658 1.1 mrg } 1659 1.1 mrg } 1660 1.1 mrg /* Warn for integer types converted to smaller integer types. */ 1661 1.1 mrg if (TYPE_PRECISION (type) < TYPE_PRECISION (expr_type)) 1662 1.1 mrg give_warning = UNSAFE_OTHER; 1663 1.1 mrg 1664 1.1 mrg /* When they are the same width but different signedness, 1665 1.1 mrg then the value may change. */ 1666 1.1 mrg else if (((TYPE_PRECISION (type) == TYPE_PRECISION (expr_type) 1667 1.1 mrg && TYPE_UNSIGNED (expr_type) != TYPE_UNSIGNED (type)) 1668 1.1 mrg /* Even when converted to a bigger type, if the type is 1669 1.1 mrg unsigned but expr is signed, then negative values 1670 1.1 mrg will be changed. */ 1671 1.1 mrg || (TYPE_UNSIGNED (type) && !TYPE_UNSIGNED (expr_type))) 1672 1.1 mrg && check_sign) 1673 1.1 mrg give_warning = UNSAFE_SIGN; 1674 1.1 mrg } 1675 1.1 mrg 1676 1.1 mrg /* Warn for integer types converted to real types if and only if 1677 1.1 mrg all the range of values of the integer type cannot be 1678 1.1 mrg represented by the real type. */ 1679 1.1 mrg else if (TREE_CODE (expr_type) == INTEGER_TYPE 1680 1.1 mrg && TREE_CODE (type) == REAL_TYPE) 1681 1.1 mrg { 1682 1.1 mrg /* Don't warn about char y = 0xff; float x = (int) y; */ 1683 1.1 mrg expr = get_unwidened (expr, 0); 1684 1.1 mrg expr_type = TREE_TYPE (expr); 1685 1.1 mrg 1686 1.1 mrg if (!int_safely_convertible_to_real_p (expr_type, type)) 1687 1.1 mrg give_warning = UNSAFE_OTHER; 1688 1.1 mrg } 1689 1.1 mrg 1690 1.1 mrg /* Warn for real types converted to smaller real types. */ 1691 1.1 mrg else if (TREE_CODE (expr_type) == REAL_TYPE 1692 1.1 mrg && TREE_CODE (type) == REAL_TYPE 1693 1.1 mrg && TYPE_PRECISION (type) < TYPE_PRECISION (expr_type)) 1694 1.1 mrg give_warning = UNSAFE_REAL; 1695 1.1 mrg 1696 1.1 mrg /* Check conversion between two complex types. */ 1697 1.1 mrg else if (TREE_CODE (expr_type) == COMPLEX_TYPE 1698 1.1 mrg && TREE_CODE (type) == COMPLEX_TYPE) 1699 1.1 mrg { 1700 1.1 mrg /* Extract underlying types (i.e., type of real and imaginary 1701 1.1 mrg parts) of expr_type and type. */ 1702 1.1 mrg tree from_type = TREE_TYPE (expr_type); 1703 1.1 mrg tree to_type = TREE_TYPE (type); 1704 1.1 mrg 1705 1.1 mrg /* Warn for real types converted to integer types. */ 1706 1.1 mrg if (TREE_CODE (from_type) == REAL_TYPE 1707 1.1 mrg && TREE_CODE (to_type) == INTEGER_TYPE) 1708 1.1 mrg give_warning = UNSAFE_REAL; 1709 1.1 mrg 1710 1.1 mrg /* Warn for real types converted to smaller real types. */ 1711 1.1 mrg else if (TREE_CODE (from_type) == REAL_TYPE 1712 1.1 mrg && TREE_CODE (to_type) == REAL_TYPE 1713 1.1 mrg && TYPE_PRECISION (to_type) < TYPE_PRECISION (from_type)) 1714 1.1 mrg give_warning = UNSAFE_REAL; 1715 1.1 mrg 1716 1.1 mrg /* Check conversion for complex integer types. Here implementation 1717 1.1 mrg is simpler than for real-domain integers because it does not 1718 1.1 mrg involve sophisticated cases, such as bitmasks, casts, etc. */ 1719 1.1 mrg else if (TREE_CODE (from_type) == INTEGER_TYPE 1720 1.1 mrg && TREE_CODE (to_type) == INTEGER_TYPE) 1721 1.1 mrg { 1722 1.1 mrg /* Warn for integer types converted to smaller integer types. */ 1723 1.1 mrg if (TYPE_PRECISION (to_type) < TYPE_PRECISION (from_type)) 1724 1.1 mrg give_warning = UNSAFE_OTHER; 1725 1.1 mrg 1726 1.1 mrg /* Check for different signedness, see case for real-domain 1727 1.1 mrg integers (above) for a more detailed comment. */ 1728 1.1 mrg else if (((TYPE_PRECISION (to_type) == TYPE_PRECISION (from_type) 1729 1.1 mrg && TYPE_UNSIGNED (to_type) != TYPE_UNSIGNED (from_type)) 1730 1.1 mrg || (TYPE_UNSIGNED (to_type) && !TYPE_UNSIGNED (from_type))) 1731 1.1 mrg && check_sign) 1732 1.1 mrg give_warning = UNSAFE_SIGN; 1733 1.1 mrg } 1734 1.1 mrg else if (TREE_CODE (from_type) == INTEGER_TYPE 1735 1.1 mrg && TREE_CODE (to_type) == REAL_TYPE 1736 1.1 mrg && !int_safely_convertible_to_real_p (from_type, to_type)) 1737 1.1 mrg give_warning = UNSAFE_OTHER; 1738 1.1 mrg } 1739 1.1 mrg 1740 1.1 mrg /* Warn for complex types converted to real or integer types. */ 1741 1.1 mrg else if (TREE_CODE (expr_type) == COMPLEX_TYPE 1742 1.1 mrg && TREE_CODE (type) != COMPLEX_TYPE) 1743 1.1 mrg give_warning = UNSAFE_IMAGINARY; 1744 1.1 mrg } 1745 1.1 mrg 1746 1.1 mrg return give_warning; 1747 1.1 mrg } 1748 1.1 mrg 1749 1.1 mrg 1750 1.1 mrg /* Convert EXPR to TYPE, warning about conversion problems with constants. 1751 1.1 mrg Invoke this function on every expression that is converted implicitly, 1752 1.1 mrg i.e. because of language rules and not because of an explicit cast. 1753 1.1 mrg INIT_CONST is true if the conversion is for arithmetic types for a static 1754 1.1 mrg initializer and folding must apply accordingly (discarding floating-point 1755 1.1 mrg exceptions and assuming the default rounding mode is in effect). */ 1756 1.1 mrg 1757 1.1 mrg tree 1758 1.1 mrg convert_and_check (location_t loc, tree type, tree expr, bool init_const) 1759 1.1 mrg { 1760 1.1 mrg tree result; 1761 1.1 mrg tree expr_for_warning; 1762 1.1 mrg 1763 1.1 mrg /* Convert from a value with possible excess precision rather than 1764 1.1 mrg via the semantic type, but do not warn about values not fitting 1765 1.1 mrg exactly in the semantic type. */ 1766 1.1 mrg if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR) 1767 1.1 mrg { 1768 1.1 mrg tree orig_type = TREE_TYPE (expr); 1769 1.1 mrg expr = TREE_OPERAND (expr, 0); 1770 1.1 mrg expr_for_warning = (init_const 1771 1.1 mrg ? convert_init (orig_type, expr) 1772 1.1 mrg : convert (orig_type, expr)); 1773 1.1 mrg if (orig_type == type) 1774 1.1 mrg return expr_for_warning; 1775 1.1 mrg } 1776 1.1 mrg else 1777 1.1 mrg expr_for_warning = expr; 1778 1.1 mrg 1779 1.1 mrg if (TREE_TYPE (expr) == type) 1780 1.1 mrg return expr; 1781 1.1 mrg 1782 1.1 mrg result = init_const ? convert_init (type, expr) : convert (type, expr); 1783 1.1 mrg 1784 1.1 mrg if (c_inhibit_evaluation_warnings == 0 1785 1.1 mrg && !TREE_OVERFLOW_P (expr) 1786 1.1 mrg && result != error_mark_node) 1787 1.1 mrg warnings_for_convert_and_check (loc, type, expr_for_warning, result); 1788 1.1 mrg 1789 1.1 mrg return result; 1790 1.1 mrg } 1791 1.1 mrg 1792 1.1 mrg /* A node in a list that describes references to variables (EXPR), which are 1794 1.1 mrg either read accesses if WRITER is zero, or write accesses, in which case 1795 1.1 mrg WRITER is the parent of EXPR. */ 1796 1.1 mrg struct tlist 1797 1.1 mrg { 1798 1.1 mrg struct tlist *next; 1799 1.1 mrg tree expr, writer; 1800 1.1 mrg }; 1801 1.1 mrg 1802 1.1 mrg /* Used to implement a cache the results of a call to verify_tree. We only 1803 1.1 mrg use this for SAVE_EXPRs. */ 1804 1.1 mrg struct tlist_cache 1805 1.1 mrg { 1806 1.1 mrg struct tlist_cache *next; 1807 1.1 mrg struct tlist *cache_before_sp; 1808 1.1 mrg struct tlist *cache_after_sp; 1809 1.1 mrg tree expr; 1810 1.1 mrg }; 1811 1.1 mrg 1812 1.1 mrg /* Obstack to use when allocating tlist structures, and corresponding 1813 1.1 mrg firstobj. */ 1814 1.1 mrg static struct obstack tlist_obstack; 1815 1.1 mrg static char *tlist_firstobj = 0; 1816 1.1 mrg 1817 1.1 mrg /* Keep track of the identifiers we've warned about, so we can avoid duplicate 1818 1.1 mrg warnings. */ 1819 1.1 mrg static struct tlist *warned_ids; 1820 1.1 mrg /* SAVE_EXPRs need special treatment. We process them only once and then 1821 1.1 mrg cache the results. */ 1822 1.1 mrg static struct tlist_cache *save_expr_cache; 1823 1.1 mrg 1824 1.1 mrg static void add_tlist (struct tlist **, struct tlist *, tree, int); 1825 1.1 mrg static void merge_tlist (struct tlist **, struct tlist *, int); 1826 1.1 mrg static void verify_tree (tree, struct tlist **, struct tlist **, tree); 1827 1.1 mrg static bool warning_candidate_p (tree); 1828 1.1 mrg static bool candidate_equal_p (const_tree, const_tree); 1829 1.1 mrg static void warn_for_collisions (struct tlist *); 1830 1.1 mrg static void warn_for_collisions_1 (tree, tree, struct tlist *, int); 1831 1.1 mrg static struct tlist *new_tlist (struct tlist *, tree, tree); 1832 1.1 mrg 1833 1.1 mrg /* Create a new struct tlist and fill in its fields. */ 1834 1.1 mrg static struct tlist * 1835 1.1 mrg new_tlist (struct tlist *next, tree t, tree writer) 1836 1.1 mrg { 1837 1.1 mrg struct tlist *l; 1838 1.1 mrg l = XOBNEW (&tlist_obstack, struct tlist); 1839 1.1 mrg l->next = next; 1840 1.1 mrg l->expr = t; 1841 1.1 mrg l->writer = writer; 1842 1.1 mrg return l; 1843 1.1 mrg } 1844 1.1 mrg 1845 1.1 mrg /* Add duplicates of the nodes found in ADD to the list *TO. If EXCLUDE_WRITER 1846 1.1 mrg is nonnull, we ignore any node we find which has a writer equal to it. */ 1847 1.1 mrg 1848 1.1 mrg static void 1849 1.1 mrg add_tlist (struct tlist **to, struct tlist *add, tree exclude_writer, int copy) 1850 1.1 mrg { 1851 1.1 mrg while (add) 1852 1.1 mrg { 1853 1.1 mrg struct tlist *next = add->next; 1854 1.1 mrg if (!copy) 1855 1.1 mrg add->next = *to; 1856 1.1 mrg if (!exclude_writer || !candidate_equal_p (add->writer, exclude_writer)) 1857 1.1 mrg *to = copy ? new_tlist (*to, add->expr, add->writer) : add; 1858 1.1 mrg add = next; 1859 1.1 mrg } 1860 1.1 mrg } 1861 1.1 mrg 1862 1.1 mrg /* Merge the nodes of ADD into TO. This merging process is done so that for 1863 1.1 mrg each variable that already exists in TO, no new node is added; however if 1864 1.1 mrg there is a write access recorded in ADD, and an occurrence on TO is only 1865 1.1 mrg a read access, then the occurrence in TO will be modified to record the 1866 1.1 mrg write. */ 1867 1.1 mrg 1868 1.1 mrg static void 1869 1.1 mrg merge_tlist (struct tlist **to, struct tlist *add, int copy) 1870 1.1 mrg { 1871 1.1 mrg struct tlist **end = to; 1872 1.1 mrg 1873 1.1 mrg while (*end) 1874 1.1 mrg end = &(*end)->next; 1875 1.1 mrg 1876 1.1 mrg while (add) 1877 1.1 mrg { 1878 1.1 mrg int found = 0; 1879 1.1 mrg struct tlist *tmp2; 1880 1.1 mrg struct tlist *next = add->next; 1881 1.1 mrg 1882 1.1 mrg for (tmp2 = *to; tmp2; tmp2 = tmp2->next) 1883 1.1 mrg if (candidate_equal_p (tmp2->expr, add->expr)) 1884 1.1 mrg { 1885 1.1 mrg found = 1; 1886 1.1 mrg if (!tmp2->writer) 1887 1.1 mrg tmp2->writer = add->writer; 1888 1.1 mrg } 1889 1.1 mrg if (!found) 1890 1.1 mrg { 1891 1.1 mrg *end = copy ? new_tlist (NULL, add->expr, add->writer) : add; 1892 1.1 mrg end = &(*end)->next; 1893 1.1 mrg *end = 0; 1894 1.1 mrg } 1895 1.1 mrg add = next; 1896 1.1 mrg } 1897 1.1 mrg } 1898 1.1 mrg 1899 1.1 mrg /* WRITTEN is a variable, WRITER is its parent. Warn if any of the variable 1900 1.1 mrg references in list LIST conflict with it, excluding reads if ONLY writers 1901 1.1 mrg is nonzero. */ 1902 1.1 mrg 1903 1.1 mrg static void 1904 1.1 mrg warn_for_collisions_1 (tree written, tree writer, struct tlist *list, 1905 1.1 mrg int only_writes) 1906 1.1 mrg { 1907 1.1 mrg struct tlist *tmp; 1908 1.1 mrg 1909 1.1 mrg /* Avoid duplicate warnings. */ 1910 1.1 mrg for (tmp = warned_ids; tmp; tmp = tmp->next) 1911 1.1 mrg if (candidate_equal_p (tmp->expr, written)) 1912 1.1 mrg return; 1913 1.1 mrg 1914 1.1 mrg while (list) 1915 1.1 mrg { 1916 1.1 mrg if (candidate_equal_p (list->expr, written) 1917 1.1 mrg && !candidate_equal_p (list->writer, writer) 1918 1.1 mrg && (!only_writes || list->writer)) 1919 1.1 mrg { 1920 1.1 mrg warned_ids = new_tlist (warned_ids, written, NULL_TREE); 1921 1.1 mrg warning_at (EXPR_LOC_OR_LOC (writer, input_location), 1922 1.1 mrg OPT_Wsequence_point, "operation on %qE may be undefined", 1923 1.1 mrg list->expr); 1924 1.1 mrg } 1925 1.1 mrg list = list->next; 1926 1.1 mrg } 1927 1.1 mrg } 1928 1.1 mrg 1929 1.1 mrg /* Given a list LIST of references to variables, find whether any of these 1930 1.1 mrg can cause conflicts due to missing sequence points. */ 1931 1.1 mrg 1932 1.1 mrg static void 1933 1.1 mrg warn_for_collisions (struct tlist *list) 1934 1.1 mrg { 1935 1.1 mrg struct tlist *tmp; 1936 1.1 mrg 1937 1.1 mrg for (tmp = list; tmp; tmp = tmp->next) 1938 1.1 mrg { 1939 1.1 mrg if (tmp->writer) 1940 1.1 mrg warn_for_collisions_1 (tmp->expr, tmp->writer, list, 0); 1941 1.1 mrg } 1942 1.1 mrg } 1943 1.1 mrg 1944 1.1 mrg /* Return nonzero if X is a tree that can be verified by the sequence point 1945 1.1 mrg warnings. */ 1946 1.1 mrg 1947 1.1 mrg static bool 1948 1.1 mrg warning_candidate_p (tree x) 1949 1.1 mrg { 1950 1.1 mrg if (DECL_P (x) && DECL_ARTIFICIAL (x)) 1951 1.1 mrg return false; 1952 1.1 mrg 1953 1.1 mrg if (TREE_CODE (x) == BLOCK) 1954 1.1 mrg return false; 1955 1.1 mrg 1956 1.1 mrg /* VOID_TYPE_P (TREE_TYPE (x)) is workaround for cp/tree.cc 1957 1.1 mrg (lvalue_p) crash on TRY/CATCH. */ 1958 1.1 mrg if (TREE_TYPE (x) == NULL_TREE || VOID_TYPE_P (TREE_TYPE (x))) 1959 1.1 mrg return false; 1960 1.1 mrg 1961 1.1 mrg if (!lvalue_p (x)) 1962 1.1 mrg return false; 1963 1.1 mrg 1964 1.1 mrg /* No point to track non-const calls, they will never satisfy 1965 1.1 mrg operand_equal_p. */ 1966 1.1 mrg if (TREE_CODE (x) == CALL_EXPR && (call_expr_flags (x) & ECF_CONST) == 0) 1967 1.1 mrg return false; 1968 1.1 mrg 1969 1.1 mrg if (TREE_CODE (x) == STRING_CST) 1970 1.1 mrg return false; 1971 1.1 mrg 1972 1.1 mrg return true; 1973 1.1 mrg } 1974 1.1 mrg 1975 1.1 mrg /* Return nonzero if X and Y appear to be the same candidate (or NULL) */ 1976 1.1 mrg static bool 1977 1.1 mrg candidate_equal_p (const_tree x, const_tree y) 1978 1.1 mrg { 1979 1.1 mrg return (x == y) || (x && y && operand_equal_p (x, y, 0)); 1980 1.1 mrg } 1981 1.1 mrg 1982 1.1 mrg /* Walk the tree X, and record accesses to variables. If X is written by the 1983 1.1 mrg parent tree, WRITER is the parent. 1984 1.1 mrg We store accesses in one of the two lists: PBEFORE_SP, and PNO_SP. If this 1985 1.1 mrg expression or its only operand forces a sequence point, then everything up 1986 1.1 mrg to the sequence point is stored in PBEFORE_SP. Everything else gets stored 1987 1.1 mrg in PNO_SP. 1988 1.1 mrg Once we return, we will have emitted warnings if any subexpression before 1989 1.1 mrg such a sequence point could be undefined. On a higher level, however, the 1990 1.1 mrg sequence point may not be relevant, and we'll merge the two lists. 1991 1.1 mrg 1992 1.1 mrg Example: (b++, a) + b; 1993 1.1 mrg The call that processes the COMPOUND_EXPR will store the increment of B 1994 1.1 mrg in PBEFORE_SP, and the use of A in PNO_SP. The higher-level call that 1995 1.1 mrg processes the PLUS_EXPR will need to merge the two lists so that 1996 1.1 mrg eventually, all accesses end up on the same list (and we'll warn about the 1997 1.1 mrg unordered subexpressions b++ and b. 1998 1.1 mrg 1999 1.1 mrg A note on merging. If we modify the former example so that our expression 2000 1.1 mrg becomes 2001 1.1 mrg (b++, b) + a 2002 1.1 mrg care must be taken not simply to add all three expressions into the final 2003 1.1 mrg PNO_SP list. The function merge_tlist takes care of that by merging the 2004 1.1 mrg before-SP list of the COMPOUND_EXPR into its after-SP list in a special 2005 1.1 mrg way, so that no more than one access to B is recorded. */ 2006 1.1 mrg 2007 1.1 mrg static void 2008 1.1 mrg verify_tree (tree x, struct tlist **pbefore_sp, struct tlist **pno_sp, 2009 1.1 mrg tree writer) 2010 1.1 mrg { 2011 1.1 mrg struct tlist *tmp_before, *tmp_nosp, *tmp_list2, *tmp_list3; 2012 1.1 mrg enum tree_code code; 2013 1.1 mrg enum tree_code_class cl; 2014 1.1 mrg 2015 1.1 mrg restart: 2016 1.1 mrg /* X may be NULL if it is the operand of an empty statement expression 2017 1.1 mrg ({ }). */ 2018 1.1 mrg if (x == NULL) 2019 1.1 mrg return; 2020 1.1 mrg 2021 1.1 mrg code = TREE_CODE (x); 2022 1.1 mrg cl = TREE_CODE_CLASS (code); 2023 1.1 mrg 2024 1.1 mrg if (warning_candidate_p (x)) 2025 1.1 mrg *pno_sp = new_tlist (*pno_sp, x, writer); 2026 1.1 mrg 2027 1.1 mrg switch (code) 2028 1.1 mrg { 2029 1.1 mrg case CONSTRUCTOR: 2030 1.1 mrg case SIZEOF_EXPR: 2031 1.1 mrg case PAREN_SIZEOF_EXPR: 2032 1.1 mrg return; 2033 1.1 mrg 2034 1.1 mrg case COMPOUND_EXPR: 2035 1.1 mrg case TRUTH_ANDIF_EXPR: 2036 1.1 mrg case TRUTH_ORIF_EXPR: 2037 1.1 mrg sequenced_binary: 2038 1.1 mrg tmp_before = tmp_nosp = tmp_list2 = tmp_list3 = 0; 2039 1.1 mrg verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_nosp, NULL_TREE); 2040 1.1 mrg warn_for_collisions (tmp_nosp); 2041 1.1 mrg merge_tlist (pbefore_sp, tmp_before, 0); 2042 1.1 mrg merge_tlist (pbefore_sp, tmp_nosp, 0); 2043 1.1 mrg verify_tree (TREE_OPERAND (x, 1), &tmp_list3, &tmp_list2, NULL_TREE); 2044 1.1 mrg warn_for_collisions (tmp_list2); 2045 1.1 mrg merge_tlist (pbefore_sp, tmp_list3, 0); 2046 1.1 mrg merge_tlist (pno_sp, tmp_list2, 0); 2047 1.1 mrg return; 2048 1.1 mrg 2049 1.1 mrg case COND_EXPR: 2050 1.1 mrg tmp_before = tmp_list2 = 0; 2051 1.1 mrg verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_list2, NULL_TREE); 2052 1.1 mrg warn_for_collisions (tmp_list2); 2053 1.1 mrg merge_tlist (pbefore_sp, tmp_before, 0); 2054 1.1 mrg merge_tlist (pbefore_sp, tmp_list2, 0); 2055 1.1 mrg 2056 1.1 mrg tmp_list3 = tmp_nosp = 0; 2057 1.1 mrg verify_tree (TREE_OPERAND (x, 1), &tmp_list3, &tmp_nosp, NULL_TREE); 2058 1.1 mrg warn_for_collisions (tmp_nosp); 2059 1.1 mrg merge_tlist (pbefore_sp, tmp_list3, 0); 2060 1.1 mrg 2061 1.1 mrg tmp_list3 = tmp_list2 = 0; 2062 1.1 mrg verify_tree (TREE_OPERAND (x, 2), &tmp_list3, &tmp_list2, NULL_TREE); 2063 1.1 mrg warn_for_collisions (tmp_list2); 2064 1.1 mrg merge_tlist (pbefore_sp, tmp_list3, 0); 2065 1.1 mrg /* Rather than add both tmp_nosp and tmp_list2, we have to merge the 2066 1.1 mrg two first, to avoid warning for (a ? b++ : b++). */ 2067 1.1 mrg merge_tlist (&tmp_nosp, tmp_list2, 0); 2068 1.1 mrg add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0); 2069 1.1 mrg return; 2070 1.1 mrg 2071 1.1 mrg case PREDECREMENT_EXPR: 2072 1.1 mrg case PREINCREMENT_EXPR: 2073 1.1 mrg case POSTDECREMENT_EXPR: 2074 1.1 mrg case POSTINCREMENT_EXPR: 2075 1.1 mrg verify_tree (TREE_OPERAND (x, 0), pno_sp, pno_sp, x); 2076 1.1 mrg return; 2077 1.1 mrg 2078 1.1 mrg case MODIFY_EXPR: 2079 1.1 mrg tmp_before = tmp_nosp = tmp_list3 = 0; 2080 1.1 mrg verify_tree (TREE_OPERAND (x, 1), &tmp_before, &tmp_nosp, NULL_TREE); 2081 1.1 mrg verify_tree (TREE_OPERAND (x, 0), &tmp_list3, &tmp_list3, x); 2082 1.1 mrg /* Expressions inside the LHS are not ordered wrt. the sequence points 2083 1.1 mrg in the RHS. Example: 2084 1.1 mrg *a = (a++, 2) 2085 1.1 mrg Despite the fact that the modification of "a" is in the before_sp 2086 1.1 mrg list (tmp_before), it conflicts with the use of "a" in the LHS. 2087 1.1 mrg We can handle this by adding the contents of tmp_list3 2088 1.1 mrg to those of tmp_before, and redoing the collision warnings for that 2089 1.1 mrg list. */ 2090 1.1 mrg add_tlist (&tmp_before, tmp_list3, x, 1); 2091 1.1 mrg warn_for_collisions (tmp_before); 2092 1.1 mrg /* Exclude the LHS itself here; we first have to merge it into the 2093 1.1 mrg tmp_nosp list. This is done to avoid warning for "a = a"; if we 2094 1.1 mrg didn't exclude the LHS, we'd get it twice, once as a read and once 2095 1.1 mrg as a write. */ 2096 1.1 mrg add_tlist (pno_sp, tmp_list3, x, 0); 2097 1.1 mrg warn_for_collisions_1 (TREE_OPERAND (x, 0), x, tmp_nosp, 1); 2098 1.1 mrg 2099 1.1 mrg merge_tlist (pbefore_sp, tmp_before, 0); 2100 1.1 mrg if (warning_candidate_p (TREE_OPERAND (x, 0))) 2101 1.1 mrg merge_tlist (&tmp_nosp, new_tlist (NULL, TREE_OPERAND (x, 0), x), 0); 2102 1.1 mrg add_tlist (pno_sp, tmp_nosp, NULL_TREE, 1); 2103 1.1 mrg return; 2104 1.1 mrg 2105 1.1 mrg case CALL_EXPR: 2106 1.1 mrg /* We need to warn about conflicts among arguments and conflicts between 2107 1.1 mrg args and the function address. Side effects of the function address, 2108 1.1 mrg however, are not ordered by the sequence point of the call. */ 2109 1.1 mrg { 2110 1.1 mrg call_expr_arg_iterator iter; 2111 1.1 mrg tree arg; 2112 1.1 mrg tmp_before = tmp_nosp = 0; 2113 1.1 mrg verify_tree (CALL_EXPR_FN (x), &tmp_before, &tmp_nosp, NULL_TREE); 2114 1.1 mrg FOR_EACH_CALL_EXPR_ARG (arg, iter, x) 2115 1.1 mrg { 2116 1.1 mrg tmp_list2 = tmp_list3 = 0; 2117 1.1 mrg verify_tree (arg, &tmp_list2, &tmp_list3, NULL_TREE); 2118 1.1 mrg merge_tlist (&tmp_list3, tmp_list2, 0); 2119 1.1 mrg add_tlist (&tmp_before, tmp_list3, NULL_TREE, 0); 2120 1.1 mrg } 2121 1.1 mrg add_tlist (&tmp_before, tmp_nosp, NULL_TREE, 0); 2122 1.1 mrg warn_for_collisions (tmp_before); 2123 1.1 mrg add_tlist (pbefore_sp, tmp_before, NULL_TREE, 0); 2124 1.1 mrg return; 2125 1.1 mrg } 2126 1.1 mrg 2127 1.1 mrg case TREE_LIST: 2128 1.1 mrg /* Scan all the list, e.g. indices of multi dimensional array. */ 2129 1.1 mrg while (x) 2130 1.1 mrg { 2131 1.1 mrg tmp_before = tmp_nosp = 0; 2132 1.1 mrg verify_tree (TREE_VALUE (x), &tmp_before, &tmp_nosp, NULL_TREE); 2133 1.1 mrg merge_tlist (&tmp_nosp, tmp_before, 0); 2134 1.1 mrg add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0); 2135 1.1 mrg x = TREE_CHAIN (x); 2136 1.1 mrg } 2137 1.1 mrg return; 2138 1.1 mrg 2139 1.1 mrg case SAVE_EXPR: 2140 1.1 mrg { 2141 1.1 mrg struct tlist_cache *t; 2142 1.1 mrg for (t = save_expr_cache; t; t = t->next) 2143 1.1 mrg if (candidate_equal_p (t->expr, x)) 2144 1.1 mrg break; 2145 1.1 mrg 2146 1.1 mrg if (!t) 2147 1.1 mrg { 2148 1.1 mrg t = XOBNEW (&tlist_obstack, struct tlist_cache); 2149 1.1 mrg t->next = save_expr_cache; 2150 1.1 mrg t->expr = x; 2151 1.1 mrg save_expr_cache = t; 2152 1.1 mrg 2153 1.1 mrg tmp_before = tmp_nosp = 0; 2154 1.1 mrg verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_nosp, NULL_TREE); 2155 1.1 mrg warn_for_collisions (tmp_nosp); 2156 1.1 mrg 2157 1.1 mrg tmp_list3 = 0; 2158 1.1 mrg merge_tlist (&tmp_list3, tmp_nosp, 0); 2159 1.1 mrg t->cache_before_sp = tmp_before; 2160 1.1 mrg t->cache_after_sp = tmp_list3; 2161 1.1 mrg } 2162 1.1 mrg merge_tlist (pbefore_sp, t->cache_before_sp, 1); 2163 1.1 mrg add_tlist (pno_sp, t->cache_after_sp, NULL_TREE, 1); 2164 1.1 mrg return; 2165 1.1 mrg } 2166 1.1 mrg 2167 1.1 mrg case ADDR_EXPR: 2168 1.1 mrg x = TREE_OPERAND (x, 0); 2169 1.1 mrg if (DECL_P (x)) 2170 1.1 mrg return; 2171 1.1 mrg writer = 0; 2172 1.1 mrg goto restart; 2173 1.1 mrg 2174 1.1 mrg case VIEW_CONVERT_EXPR: 2175 1.1 mrg if (location_wrapper_p (x)) 2176 1.1 mrg { 2177 1.1 mrg x = TREE_OPERAND (x, 0); 2178 1.1 mrg goto restart; 2179 1.1 mrg } 2180 1.1 mrg goto do_default; 2181 1.1 mrg 2182 1.1 mrg case LSHIFT_EXPR: 2183 1.1 mrg case RSHIFT_EXPR: 2184 1.1 mrg case ARRAY_REF: 2185 1.1 mrg if (cxx_dialect >= cxx17) 2186 1.1 mrg goto sequenced_binary; 2187 1.1 mrg goto do_default; 2188 1.1 mrg 2189 1.1 mrg case COMPONENT_REF: 2190 1.1 mrg /* Treat as unary, the other operands aren't evaluated. */ 2191 1.1 mrg x = TREE_OPERAND (x, 0); 2192 1.1 mrg writer = 0; 2193 1.1 mrg goto restart; 2194 1.1 mrg 2195 1.1 mrg default: 2196 1.1 mrg do_default: 2197 1.1 mrg /* For other expressions, simply recurse on their operands. 2198 1.1 mrg Manual tail recursion for unary expressions. 2199 1.1 mrg Other non-expressions need not be processed. */ 2200 1.1 mrg if (cl == tcc_unary) 2201 1.1 mrg { 2202 1.1 mrg x = TREE_OPERAND (x, 0); 2203 1.1 mrg writer = 0; 2204 1.1 mrg goto restart; 2205 1.1 mrg } 2206 1.1 mrg else if (IS_EXPR_CODE_CLASS (cl)) 2207 1.1 mrg { 2208 1.1 mrg int lp; 2209 1.1 mrg int max = TREE_OPERAND_LENGTH (x); 2210 1.1 mrg for (lp = 0; lp < max; lp++) 2211 1.1 mrg { 2212 1.1 mrg tmp_before = tmp_nosp = 0; 2213 1.1 mrg verify_tree (TREE_OPERAND (x, lp), &tmp_before, &tmp_nosp, 0); 2214 1.1 mrg merge_tlist (&tmp_nosp, tmp_before, 0); 2215 1.1 mrg add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0); 2216 1.1 mrg } 2217 1.1 mrg } 2218 1.1 mrg return; 2219 1.1 mrg } 2220 1.1 mrg } 2221 1.1 mrg 2222 1.1 mrg static constexpr size_t verify_sequence_points_limit = 1024; 2223 1.1 mrg 2224 1.1 mrg /* Called from verify_sequence_points via walk_tree. */ 2225 1.1 mrg 2226 1.1 mrg static tree 2227 1.1 mrg verify_tree_lim_r (tree *tp, int *walk_subtrees, void *data) 2228 1.1 mrg { 2229 1.1 mrg if (++*((size_t *) data) > verify_sequence_points_limit) 2230 1.1 mrg return integer_zero_node; 2231 1.1 mrg 2232 1.1 mrg if (TYPE_P (*tp)) 2233 1.1 mrg *walk_subtrees = 0; 2234 1.1 mrg 2235 1.1 mrg return NULL_TREE; 2236 1.1 mrg } 2237 1.1 mrg 2238 1.1 mrg /* Try to warn for undefined behavior in EXPR due to missing sequence 2239 1.1 mrg points. */ 2240 1.1 mrg 2241 1.1 mrg void 2242 1.1 mrg verify_sequence_points (tree expr) 2243 1.1 mrg { 2244 1.1 mrg tlist *before_sp = nullptr, *after_sp = nullptr; 2245 1.1 mrg 2246 1.1 mrg /* verify_tree is highly recursive, and merge_tlist is O(n^2), 2247 1.1 mrg so we return early if the expression is too big. */ 2248 1.1 mrg size_t n = 0; 2249 1.1 mrg if (walk_tree (&expr, verify_tree_lim_r, &n, nullptr)) 2250 1.1 mrg return; 2251 1.1 mrg 2252 1.1 mrg warned_ids = nullptr; 2253 1.1 mrg save_expr_cache = nullptr; 2254 1.1 mrg if (!tlist_firstobj) 2255 1.1 mrg { 2256 1.1 mrg gcc_obstack_init (&tlist_obstack); 2257 1.1 mrg tlist_firstobj = (char *) obstack_alloc (&tlist_obstack, 0); 2258 1.1 mrg } 2259 1.1 mrg 2260 1.1 mrg verify_tree (expr, &before_sp, &after_sp, NULL_TREE); 2261 1.1 mrg warn_for_collisions (after_sp); 2262 1.1 mrg obstack_free (&tlist_obstack, tlist_firstobj); 2263 1.1 mrg } 2264 1.1 mrg 2265 1.1 mrg /* Validate the expression after `case' and apply default promotions. */ 2267 1.1 mrg 2268 1.1 mrg static tree 2269 1.1 mrg check_case_value (location_t loc, tree value) 2270 1.1 mrg { 2271 1.1 mrg if (value == NULL_TREE) 2272 1.1 mrg return value; 2273 1.1 mrg 2274 1.1 mrg if (TREE_CODE (value) == INTEGER_CST) 2275 1.1 mrg /* Promote char or short to int. */ 2276 1.1 mrg value = perform_integral_promotions (value); 2277 1.1 mrg else if (value != error_mark_node) 2278 1.1 mrg { 2279 1.1 mrg error_at (loc, "case label does not reduce to an integer constant"); 2280 1.1 mrg value = error_mark_node; 2281 1.1 mrg } 2282 1.1 mrg 2283 1.1 mrg constant_expression_warning (value); 2284 1.1 mrg 2285 1.1 mrg return value; 2286 1.1 mrg } 2287 1.1 mrg 2288 1.1 mrg /* Return an integer type with BITS bits of precision, 2290 1.1 mrg that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */ 2291 1.1 mrg 2292 1.1 mrg tree 2293 1.1 mrg c_common_type_for_size (unsigned int bits, int unsignedp) 2294 1.1 mrg { 2295 1.1 mrg int i; 2296 1.1 mrg 2297 1.1 mrg if (bits == TYPE_PRECISION (integer_type_node)) 2298 1.1 mrg return unsignedp ? unsigned_type_node : integer_type_node; 2299 1.1 mrg 2300 1.1 mrg if (bits == TYPE_PRECISION (signed_char_type_node)) 2301 1.1 mrg return unsignedp ? unsigned_char_type_node : signed_char_type_node; 2302 1.1 mrg 2303 1.1 mrg if (bits == TYPE_PRECISION (short_integer_type_node)) 2304 1.1 mrg return unsignedp ? short_unsigned_type_node : short_integer_type_node; 2305 1.1 mrg 2306 1.1 mrg if (bits == TYPE_PRECISION (long_integer_type_node)) 2307 1.1 mrg return unsignedp ? long_unsigned_type_node : long_integer_type_node; 2308 1.1 mrg 2309 1.1 mrg if (bits == TYPE_PRECISION (long_long_integer_type_node)) 2310 1.1 mrg return (unsignedp ? long_long_unsigned_type_node 2311 1.1 mrg : long_long_integer_type_node); 2312 1.1 mrg 2313 1.1 mrg for (i = 0; i < NUM_INT_N_ENTS; i ++) 2314 1.1 mrg if (int_n_enabled_p[i] 2315 1.1 mrg && bits == int_n_data[i].bitsize) 2316 1.1 mrg return (unsignedp ? int_n_trees[i].unsigned_type 2317 1.1 mrg : int_n_trees[i].signed_type); 2318 1.1 mrg 2319 1.1 mrg if (bits == TYPE_PRECISION (widest_integer_literal_type_node)) 2320 1.1 mrg return (unsignedp ? widest_unsigned_literal_type_node 2321 1.1 mrg : widest_integer_literal_type_node); 2322 1.1 mrg 2323 1.1 mrg if (bits <= TYPE_PRECISION (intQI_type_node)) 2324 1.1 mrg return unsignedp ? unsigned_intQI_type_node : intQI_type_node; 2325 1.1 mrg 2326 1.1 mrg if (bits <= TYPE_PRECISION (intHI_type_node)) 2327 1.1 mrg return unsignedp ? unsigned_intHI_type_node : intHI_type_node; 2328 1.1 mrg 2329 1.1 mrg if (bits <= TYPE_PRECISION (intSI_type_node)) 2330 1.1 mrg return unsignedp ? unsigned_intSI_type_node : intSI_type_node; 2331 1.1 mrg 2332 1.1 mrg if (bits <= TYPE_PRECISION (intDI_type_node)) 2333 1.1 mrg return unsignedp ? unsigned_intDI_type_node : intDI_type_node; 2334 1.1 mrg 2335 1.1 mrg return NULL_TREE; 2336 1.1 mrg } 2337 1.1 mrg 2338 1.1 mrg /* Return a fixed-point type that has at least IBIT ibits and FBIT fbits 2339 1.1 mrg that is unsigned if UNSIGNEDP is nonzero, otherwise signed; 2340 1.1 mrg and saturating if SATP is nonzero, otherwise not saturating. */ 2341 1.1 mrg 2342 1.1 mrg tree 2343 1.1 mrg c_common_fixed_point_type_for_size (unsigned int ibit, unsigned int fbit, 2344 1.1 mrg int unsignedp, int satp) 2345 1.1 mrg { 2346 1.1 mrg enum mode_class mclass; 2347 1.1 mrg if (ibit == 0) 2348 1.1 mrg mclass = unsignedp ? MODE_UFRACT : MODE_FRACT; 2349 1.1 mrg else 2350 1.1 mrg mclass = unsignedp ? MODE_UACCUM : MODE_ACCUM; 2351 1.1 mrg 2352 1.1 mrg opt_scalar_mode opt_mode; 2353 1.1 mrg scalar_mode mode; 2354 1.1 mrg FOR_EACH_MODE_IN_CLASS (opt_mode, mclass) 2355 1.1 mrg { 2356 1.1 mrg mode = opt_mode.require (); 2357 1.1 mrg if (GET_MODE_IBIT (mode) >= ibit && GET_MODE_FBIT (mode) >= fbit) 2358 1.1 mrg break; 2359 1.1 mrg } 2360 1.1 mrg 2361 1.1 mrg if (!opt_mode.exists (&mode) || !targetm.scalar_mode_supported_p (mode)) 2362 1.1 mrg { 2363 1.1 mrg sorry ("GCC cannot support operators with integer types and " 2364 1.1 mrg "fixed-point types that have too many integral and " 2365 1.1 mrg "fractional bits together"); 2366 1.1 mrg return NULL_TREE; 2367 1.1 mrg } 2368 1.1 mrg 2369 1.1 mrg return c_common_type_for_mode (mode, satp); 2370 1.1 mrg } 2371 1.1 mrg 2372 1.1 mrg /* Used for communication between c_common_type_for_mode and 2373 1.1 mrg c_register_builtin_type. */ 2374 1.1 mrg tree registered_builtin_types; 2375 1.1 mrg 2376 1.1 mrg /* Return a data type that has machine mode MODE. 2377 1.1 mrg If the mode is an integer, 2378 1.1 mrg then UNSIGNEDP selects between signed and unsigned types. 2379 1.1 mrg If the mode is a fixed-point mode, 2380 1.1 mrg then UNSIGNEDP selects between saturating and nonsaturating types. */ 2381 1.1 mrg 2382 1.1 mrg tree 2383 1.1 mrg c_common_type_for_mode (machine_mode mode, int unsignedp) 2384 1.1 mrg { 2385 1.1 mrg tree t; 2386 1.1 mrg int i; 2387 1.1 mrg 2388 1.1 mrg if (mode == TYPE_MODE (integer_type_node)) 2389 1.1 mrg return unsignedp ? unsigned_type_node : integer_type_node; 2390 1.1 mrg 2391 1.1 mrg if (mode == TYPE_MODE (signed_char_type_node)) 2392 1.1 mrg return unsignedp ? unsigned_char_type_node : signed_char_type_node; 2393 1.1 mrg 2394 1.1 mrg if (mode == TYPE_MODE (short_integer_type_node)) 2395 1.1 mrg return unsignedp ? short_unsigned_type_node : short_integer_type_node; 2396 1.1 mrg 2397 1.1 mrg if (mode == TYPE_MODE (long_integer_type_node)) 2398 1.1 mrg return unsignedp ? long_unsigned_type_node : long_integer_type_node; 2399 1.1 mrg 2400 1.1 mrg if (mode == TYPE_MODE (long_long_integer_type_node)) 2401 1.1 mrg return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node; 2402 1.1 mrg 2403 1.1 mrg for (i = 0; i < NUM_INT_N_ENTS; i ++) 2404 1.1 mrg if (int_n_enabled_p[i] 2405 1.1 mrg && mode == int_n_data[i].m) 2406 1.1 mrg return (unsignedp ? int_n_trees[i].unsigned_type 2407 1.1 mrg : int_n_trees[i].signed_type); 2408 1.1 mrg 2409 1.1 mrg if (mode == QImode) 2410 1.1 mrg return unsignedp ? unsigned_intQI_type_node : intQI_type_node; 2411 1.1 mrg 2412 1.1 mrg if (mode == HImode) 2413 1.1 mrg return unsignedp ? unsigned_intHI_type_node : intHI_type_node; 2414 1.1 mrg 2415 1.1 mrg if (mode == SImode) 2416 1.1 mrg return unsignedp ? unsigned_intSI_type_node : intSI_type_node; 2417 1.1 mrg 2418 1.1 mrg if (mode == DImode) 2419 1.1 mrg return unsignedp ? unsigned_intDI_type_node : intDI_type_node; 2420 1.1 mrg 2421 1.1 mrg #if HOST_BITS_PER_WIDE_INT >= 64 2422 1.1 mrg if (mode == TYPE_MODE (intTI_type_node)) 2423 1.1 mrg return unsignedp ? unsigned_intTI_type_node : intTI_type_node; 2424 1.1 mrg #endif 2425 1.1 mrg 2426 1.1 mrg if (mode == TYPE_MODE (float_type_node)) 2427 1.1 mrg return float_type_node; 2428 1.1 mrg 2429 1.1 mrg if (mode == TYPE_MODE (double_type_node)) 2430 1.1 mrg return double_type_node; 2431 1.1 mrg 2432 1.1 mrg if (mode == TYPE_MODE (long_double_type_node)) 2433 1.1 mrg return long_double_type_node; 2434 1.1 mrg 2435 1.1 mrg for (i = 0; i < NUM_FLOATN_NX_TYPES; i++) 2436 1.1 mrg if (FLOATN_NX_TYPE_NODE (i) != NULL_TREE 2437 1.1 mrg && mode == TYPE_MODE (FLOATN_NX_TYPE_NODE (i))) 2438 1.1 mrg return FLOATN_NX_TYPE_NODE (i); 2439 1.1 mrg 2440 1.1 mrg if (mode == TYPE_MODE (void_type_node)) 2441 1.1 mrg return void_type_node; 2442 1.1 mrg 2443 1.1 mrg if (mode == TYPE_MODE (build_pointer_type (char_type_node)) 2444 1.1 mrg || mode == TYPE_MODE (build_pointer_type (integer_type_node))) 2445 1.1 mrg { 2446 1.1 mrg unsigned int precision 2447 1.1 mrg = GET_MODE_PRECISION (as_a <scalar_int_mode> (mode)); 2448 1.1 mrg return (unsignedp 2449 1.1 mrg ? make_unsigned_type (precision) 2450 1.1 mrg : make_signed_type (precision)); 2451 1.1 mrg } 2452 1.1 mrg 2453 1.1 mrg if (COMPLEX_MODE_P (mode)) 2454 1.1 mrg { 2455 1.1 mrg machine_mode inner_mode; 2456 1.1 mrg tree inner_type; 2457 1.1 mrg 2458 1.1 mrg if (mode == TYPE_MODE (complex_float_type_node)) 2459 1.1 mrg return complex_float_type_node; 2460 1.1 mrg if (mode == TYPE_MODE (complex_double_type_node)) 2461 1.1 mrg return complex_double_type_node; 2462 1.1 mrg if (mode == TYPE_MODE (complex_long_double_type_node)) 2463 1.1 mrg return complex_long_double_type_node; 2464 1.1 mrg 2465 1.1 mrg for (i = 0; i < NUM_FLOATN_NX_TYPES; i++) 2466 1.1 mrg if (COMPLEX_FLOATN_NX_TYPE_NODE (i) != NULL_TREE 2467 1.1 mrg && mode == TYPE_MODE (COMPLEX_FLOATN_NX_TYPE_NODE (i))) 2468 1.1 mrg return COMPLEX_FLOATN_NX_TYPE_NODE (i); 2469 1.1 mrg 2470 1.1 mrg if (mode == TYPE_MODE (complex_integer_type_node) && !unsignedp) 2471 1.1 mrg return complex_integer_type_node; 2472 1.1 mrg 2473 1.1 mrg inner_mode = GET_MODE_INNER (mode); 2474 1.1 mrg inner_type = c_common_type_for_mode (inner_mode, unsignedp); 2475 1.1 mrg if (inner_type != NULL_TREE) 2476 1.1 mrg return build_complex_type (inner_type); 2477 1.1 mrg } 2478 1.1 mrg else if (GET_MODE_CLASS (mode) == MODE_VECTOR_BOOL 2479 1.1 mrg && valid_vector_subparts_p (GET_MODE_NUNITS (mode))) 2480 1.1 mrg { 2481 1.1 mrg unsigned int elem_bits = vector_element_size (GET_MODE_BITSIZE (mode), 2482 1.1 mrg GET_MODE_NUNITS (mode)); 2483 1.1 mrg tree bool_type = build_nonstandard_boolean_type (elem_bits); 2484 1.1 mrg return build_vector_type_for_mode (bool_type, mode); 2485 1.1 mrg } 2486 1.1 mrg else if (VECTOR_MODE_P (mode) 2487 1.1 mrg && valid_vector_subparts_p (GET_MODE_NUNITS (mode))) 2488 1.1 mrg { 2489 1.1 mrg machine_mode inner_mode = GET_MODE_INNER (mode); 2490 1.1 mrg tree inner_type = c_common_type_for_mode (inner_mode, unsignedp); 2491 1.1 mrg if (inner_type != NULL_TREE) 2492 1.1 mrg return build_vector_type_for_mode (inner_type, mode); 2493 1.1 mrg } 2494 1.1 mrg 2495 1.1 mrg if (dfloat32_type_node != NULL_TREE 2496 1.1 mrg && mode == TYPE_MODE (dfloat32_type_node)) 2497 1.1 mrg return dfloat32_type_node; 2498 1.1 mrg if (dfloat64_type_node != NULL_TREE 2499 1.1 mrg && mode == TYPE_MODE (dfloat64_type_node)) 2500 1.1 mrg return dfloat64_type_node; 2501 1.1 mrg if (dfloat128_type_node != NULL_TREE 2502 1.1 mrg && mode == TYPE_MODE (dfloat128_type_node)) 2503 1.1 mrg return dfloat128_type_node; 2504 1.1 mrg 2505 1.1 mrg if (ALL_SCALAR_FIXED_POINT_MODE_P (mode)) 2506 1.1 mrg { 2507 1.1 mrg if (mode == TYPE_MODE (short_fract_type_node)) 2508 1.1 mrg return unsignedp ? sat_short_fract_type_node : short_fract_type_node; 2509 1.1 mrg if (mode == TYPE_MODE (fract_type_node)) 2510 1.1 mrg return unsignedp ? sat_fract_type_node : fract_type_node; 2511 1.1 mrg if (mode == TYPE_MODE (long_fract_type_node)) 2512 1.1 mrg return unsignedp ? sat_long_fract_type_node : long_fract_type_node; 2513 1.1 mrg if (mode == TYPE_MODE (long_long_fract_type_node)) 2514 1.1 mrg return unsignedp ? sat_long_long_fract_type_node 2515 1.1 mrg : long_long_fract_type_node; 2516 1.1 mrg 2517 1.1 mrg if (mode == TYPE_MODE (unsigned_short_fract_type_node)) 2518 1.1 mrg return unsignedp ? sat_unsigned_short_fract_type_node 2519 1.1 mrg : unsigned_short_fract_type_node; 2520 1.1 mrg if (mode == TYPE_MODE (unsigned_fract_type_node)) 2521 1.1 mrg return unsignedp ? sat_unsigned_fract_type_node 2522 1.1 mrg : unsigned_fract_type_node; 2523 1.1 mrg if (mode == TYPE_MODE (unsigned_long_fract_type_node)) 2524 1.1 mrg return unsignedp ? sat_unsigned_long_fract_type_node 2525 1.1 mrg : unsigned_long_fract_type_node; 2526 1.1 mrg if (mode == TYPE_MODE (unsigned_long_long_fract_type_node)) 2527 1.1 mrg return unsignedp ? sat_unsigned_long_long_fract_type_node 2528 1.1 mrg : unsigned_long_long_fract_type_node; 2529 1.1 mrg 2530 1.1 mrg if (mode == TYPE_MODE (short_accum_type_node)) 2531 1.1 mrg return unsignedp ? sat_short_accum_type_node : short_accum_type_node; 2532 1.1 mrg if (mode == TYPE_MODE (accum_type_node)) 2533 1.1 mrg return unsignedp ? sat_accum_type_node : accum_type_node; 2534 1.1 mrg if (mode == TYPE_MODE (long_accum_type_node)) 2535 1.1 mrg return unsignedp ? sat_long_accum_type_node : long_accum_type_node; 2536 1.1 mrg if (mode == TYPE_MODE (long_long_accum_type_node)) 2537 1.1 mrg return unsignedp ? sat_long_long_accum_type_node 2538 1.1 mrg : long_long_accum_type_node; 2539 1.1 mrg 2540 1.1 mrg if (mode == TYPE_MODE (unsigned_short_accum_type_node)) 2541 1.1 mrg return unsignedp ? sat_unsigned_short_accum_type_node 2542 1.1 mrg : unsigned_short_accum_type_node; 2543 1.1 mrg if (mode == TYPE_MODE (unsigned_accum_type_node)) 2544 1.1 mrg return unsignedp ? sat_unsigned_accum_type_node 2545 1.1 mrg : unsigned_accum_type_node; 2546 1.1 mrg if (mode == TYPE_MODE (unsigned_long_accum_type_node)) 2547 1.1 mrg return unsignedp ? sat_unsigned_long_accum_type_node 2548 1.1 mrg : unsigned_long_accum_type_node; 2549 1.1 mrg if (mode == TYPE_MODE (unsigned_long_long_accum_type_node)) 2550 1.1 mrg return unsignedp ? sat_unsigned_long_long_accum_type_node 2551 1.1 mrg : unsigned_long_long_accum_type_node; 2552 1.1 mrg 2553 1.1 mrg if (mode == QQmode) 2554 1.1 mrg return unsignedp ? sat_qq_type_node : qq_type_node; 2555 1.1 mrg if (mode == HQmode) 2556 1.1 mrg return unsignedp ? sat_hq_type_node : hq_type_node; 2557 1.1 mrg if (mode == SQmode) 2558 1.1 mrg return unsignedp ? sat_sq_type_node : sq_type_node; 2559 1.1 mrg if (mode == DQmode) 2560 1.1 mrg return unsignedp ? sat_dq_type_node : dq_type_node; 2561 1.1 mrg if (mode == TQmode) 2562 1.1 mrg return unsignedp ? sat_tq_type_node : tq_type_node; 2563 1.1 mrg 2564 1.1 mrg if (mode == UQQmode) 2565 1.1 mrg return unsignedp ? sat_uqq_type_node : uqq_type_node; 2566 1.1 mrg if (mode == UHQmode) 2567 1.1 mrg return unsignedp ? sat_uhq_type_node : uhq_type_node; 2568 1.1 mrg if (mode == USQmode) 2569 1.1 mrg return unsignedp ? sat_usq_type_node : usq_type_node; 2570 1.1 mrg if (mode == UDQmode) 2571 1.1 mrg return unsignedp ? sat_udq_type_node : udq_type_node; 2572 1.1 mrg if (mode == UTQmode) 2573 1.1 mrg return unsignedp ? sat_utq_type_node : utq_type_node; 2574 1.1 mrg 2575 1.1 mrg if (mode == HAmode) 2576 1.1 mrg return unsignedp ? sat_ha_type_node : ha_type_node; 2577 1.1 mrg if (mode == SAmode) 2578 1.1 mrg return unsignedp ? sat_sa_type_node : sa_type_node; 2579 1.1 mrg if (mode == DAmode) 2580 1.1 mrg return unsignedp ? sat_da_type_node : da_type_node; 2581 1.1 mrg if (mode == TAmode) 2582 1.1 mrg return unsignedp ? sat_ta_type_node : ta_type_node; 2583 1.1 mrg 2584 1.1 mrg if (mode == UHAmode) 2585 1.1 mrg return unsignedp ? sat_uha_type_node : uha_type_node; 2586 1.1 mrg if (mode == USAmode) 2587 1.1 mrg return unsignedp ? sat_usa_type_node : usa_type_node; 2588 1.1 mrg if (mode == UDAmode) 2589 1.1 mrg return unsignedp ? sat_uda_type_node : uda_type_node; 2590 1.1 mrg if (mode == UTAmode) 2591 1.1 mrg return unsignedp ? sat_uta_type_node : uta_type_node; 2592 1.1 mrg } 2593 1.1 mrg 2594 1.1 mrg for (t = registered_builtin_types; t; t = TREE_CHAIN (t)) 2595 1.1 mrg { 2596 1.1 mrg tree type = TREE_VALUE (t); 2597 1.1 mrg if (TYPE_MODE (type) == mode 2598 1.1 mrg && VECTOR_TYPE_P (type) == VECTOR_MODE_P (mode) 2599 1.1 mrg && !!unsignedp == !!TYPE_UNSIGNED (type)) 2600 1.1 mrg return type; 2601 1.1 mrg } 2602 1.1 mrg return NULL_TREE; 2603 1.1 mrg } 2604 1.1 mrg 2605 1.1 mrg tree 2606 1.1 mrg c_common_unsigned_type (tree type) 2607 1.1 mrg { 2608 1.1 mrg return c_common_signed_or_unsigned_type (1, type); 2609 1.1 mrg } 2610 1.1 mrg 2611 1.1 mrg /* Return a signed type the same as TYPE in other respects. */ 2612 1.1 mrg 2613 1.1 mrg tree 2614 1.1 mrg c_common_signed_type (tree type) 2615 1.1 mrg { 2616 1.1 mrg return c_common_signed_or_unsigned_type (0, type); 2617 1.1 mrg } 2618 1.1 mrg 2619 1.1 mrg /* Return a type the same as TYPE except unsigned or 2620 1.1 mrg signed according to UNSIGNEDP. */ 2621 1.1 mrg 2622 1.1 mrg tree 2623 1.1 mrg c_common_signed_or_unsigned_type (int unsignedp, tree type) 2624 1.1 mrg { 2625 1.1 mrg tree type1; 2626 1.1 mrg int i; 2627 1.1 mrg 2628 1.1 mrg /* This block of code emulates the behavior of the old 2629 1.1 mrg c_common_unsigned_type. In particular, it returns 2630 1.1 mrg long_unsigned_type_node if passed a long, even when a int would 2631 1.1 mrg have the same size. This is necessary for warnings to work 2632 1.1 mrg correctly in archs where sizeof(int) == sizeof(long) */ 2633 1.1 mrg 2634 1.1 mrg type1 = TYPE_MAIN_VARIANT (type); 2635 1.1 mrg if (type1 == signed_char_type_node || type1 == char_type_node || type1 == unsigned_char_type_node) 2636 1.1 mrg return unsignedp ? unsigned_char_type_node : signed_char_type_node; 2637 1.1 mrg if (type1 == integer_type_node || type1 == unsigned_type_node) 2638 1.1 mrg return unsignedp ? unsigned_type_node : integer_type_node; 2639 1.1 mrg if (type1 == short_integer_type_node || type1 == short_unsigned_type_node) 2640 1.1 mrg return unsignedp ? short_unsigned_type_node : short_integer_type_node; 2641 1.1 mrg if (type1 == long_integer_type_node || type1 == long_unsigned_type_node) 2642 1.1 mrg return unsignedp ? long_unsigned_type_node : long_integer_type_node; 2643 1.1 mrg if (type1 == long_long_integer_type_node || type1 == long_long_unsigned_type_node) 2644 1.1 mrg return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node; 2645 1.1 mrg 2646 1.1 mrg for (i = 0; i < NUM_INT_N_ENTS; i ++) 2647 1.1 mrg if (int_n_enabled_p[i] 2648 1.1 mrg && (type1 == int_n_trees[i].unsigned_type 2649 1.1 mrg || type1 == int_n_trees[i].signed_type)) 2650 1.1 mrg return (unsignedp ? int_n_trees[i].unsigned_type 2651 1.1 mrg : int_n_trees[i].signed_type); 2652 1.1 mrg 2653 1.1 mrg #if HOST_BITS_PER_WIDE_INT >= 64 2654 1.1 mrg if (type1 == intTI_type_node || type1 == unsigned_intTI_type_node) 2655 1.1 mrg return unsignedp ? unsigned_intTI_type_node : intTI_type_node; 2656 1.1 mrg #endif 2657 1.1 mrg if (type1 == intDI_type_node || type1 == unsigned_intDI_type_node) 2658 1.1 mrg return unsignedp ? unsigned_intDI_type_node : intDI_type_node; 2659 1.1 mrg if (type1 == intSI_type_node || type1 == unsigned_intSI_type_node) 2660 1.1 mrg return unsignedp ? unsigned_intSI_type_node : intSI_type_node; 2661 1.1 mrg if (type1 == intHI_type_node || type1 == unsigned_intHI_type_node) 2662 1.1 mrg return unsignedp ? unsigned_intHI_type_node : intHI_type_node; 2663 1.1 mrg if (type1 == intQI_type_node || type1 == unsigned_intQI_type_node) 2664 1.1 mrg return unsignedp ? unsigned_intQI_type_node : intQI_type_node; 2665 1.1 mrg 2666 1.1 mrg #define C_COMMON_FIXED_TYPES(NAME) \ 2667 1.1 mrg if (type1 == short_ ## NAME ## _type_node \ 2668 1.1 mrg || type1 == unsigned_short_ ## NAME ## _type_node) \ 2669 1.1 mrg return unsignedp ? unsigned_short_ ## NAME ## _type_node \ 2670 1.1 mrg : short_ ## NAME ## _type_node; \ 2671 1.1 mrg if (type1 == NAME ## _type_node \ 2672 1.1 mrg || type1 == unsigned_ ## NAME ## _type_node) \ 2673 1.1 mrg return unsignedp ? unsigned_ ## NAME ## _type_node \ 2674 1.1 mrg : NAME ## _type_node; \ 2675 1.1 mrg if (type1 == long_ ## NAME ## _type_node \ 2676 1.1 mrg || type1 == unsigned_long_ ## NAME ## _type_node) \ 2677 1.1 mrg return unsignedp ? unsigned_long_ ## NAME ## _type_node \ 2678 1.1 mrg : long_ ## NAME ## _type_node; \ 2679 1.1 mrg if (type1 == long_long_ ## NAME ## _type_node \ 2680 1.1 mrg || type1 == unsigned_long_long_ ## NAME ## _type_node) \ 2681 1.1 mrg return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \ 2682 1.1 mrg : long_long_ ## NAME ## _type_node; 2683 1.1 mrg 2684 1.1 mrg #define C_COMMON_FIXED_MODE_TYPES(NAME) \ 2685 1.1 mrg if (type1 == NAME ## _type_node \ 2686 1.1 mrg || type1 == u ## NAME ## _type_node) \ 2687 1.1 mrg return unsignedp ? u ## NAME ## _type_node \ 2688 1.1 mrg : NAME ## _type_node; 2689 1.1 mrg 2690 1.1 mrg #define C_COMMON_FIXED_TYPES_SAT(NAME) \ 2691 1.1 mrg if (type1 == sat_ ## short_ ## NAME ## _type_node \ 2692 1.1 mrg || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \ 2693 1.1 mrg return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \ 2694 1.1 mrg : sat_ ## short_ ## NAME ## _type_node; \ 2695 1.1 mrg if (type1 == sat_ ## NAME ## _type_node \ 2696 1.1 mrg || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \ 2697 1.1 mrg return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \ 2698 1.1 mrg : sat_ ## NAME ## _type_node; \ 2699 1.1 mrg if (type1 == sat_ ## long_ ## NAME ## _type_node \ 2700 1.1 mrg || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \ 2701 1.1 mrg return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \ 2702 1.1 mrg : sat_ ## long_ ## NAME ## _type_node; \ 2703 1.1 mrg if (type1 == sat_ ## long_long_ ## NAME ## _type_node \ 2704 1.1 mrg || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \ 2705 1.1 mrg return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \ 2706 1.1 mrg : sat_ ## long_long_ ## NAME ## _type_node; 2707 1.1 mrg 2708 1.1 mrg #define C_COMMON_FIXED_MODE_TYPES_SAT(NAME) \ 2709 1.1 mrg if (type1 == sat_ ## NAME ## _type_node \ 2710 1.1 mrg || type1 == sat_ ## u ## NAME ## _type_node) \ 2711 1.1 mrg return unsignedp ? sat_ ## u ## NAME ## _type_node \ 2712 1.1 mrg : sat_ ## NAME ## _type_node; 2713 1.1 mrg 2714 1.1 mrg C_COMMON_FIXED_TYPES (fract); 2715 1.1 mrg C_COMMON_FIXED_TYPES_SAT (fract); 2716 1.1 mrg C_COMMON_FIXED_TYPES (accum); 2717 1.1 mrg C_COMMON_FIXED_TYPES_SAT (accum); 2718 1.1 mrg 2719 1.1 mrg C_COMMON_FIXED_MODE_TYPES (qq); 2720 1.1 mrg C_COMMON_FIXED_MODE_TYPES (hq); 2721 1.1 mrg C_COMMON_FIXED_MODE_TYPES (sq); 2722 1.1 mrg C_COMMON_FIXED_MODE_TYPES (dq); 2723 1.1 mrg C_COMMON_FIXED_MODE_TYPES (tq); 2724 1.1 mrg C_COMMON_FIXED_MODE_TYPES_SAT (qq); 2725 1.1 mrg C_COMMON_FIXED_MODE_TYPES_SAT (hq); 2726 1.1 mrg C_COMMON_FIXED_MODE_TYPES_SAT (sq); 2727 1.1 mrg C_COMMON_FIXED_MODE_TYPES_SAT (dq); 2728 1.1 mrg C_COMMON_FIXED_MODE_TYPES_SAT (tq); 2729 1.1 mrg C_COMMON_FIXED_MODE_TYPES (ha); 2730 1.1 mrg C_COMMON_FIXED_MODE_TYPES (sa); 2731 1.1 mrg C_COMMON_FIXED_MODE_TYPES (da); 2732 1.1 mrg C_COMMON_FIXED_MODE_TYPES (ta); 2733 1.1 mrg C_COMMON_FIXED_MODE_TYPES_SAT (ha); 2734 1.1 mrg C_COMMON_FIXED_MODE_TYPES_SAT (sa); 2735 1.1 mrg C_COMMON_FIXED_MODE_TYPES_SAT (da); 2736 1.1 mrg C_COMMON_FIXED_MODE_TYPES_SAT (ta); 2737 1.1 mrg 2738 1.1 mrg /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not 2739 1.1 mrg the precision; they have precision set to match their range, but 2740 1.1 mrg may use a wider mode to match an ABI. If we change modes, we may 2741 1.1 mrg wind up with bad conversions. For INTEGER_TYPEs in C, must check 2742 1.1 mrg the precision as well, so as to yield correct results for 2743 1.1 mrg bit-field types. C++ does not have these separate bit-field 2744 1.1 mrg types, and producing a signed or unsigned variant of an 2745 1.1 mrg ENUMERAL_TYPE may cause other problems as well. */ 2746 1.1 mrg 2747 1.1 mrg if (!INTEGRAL_TYPE_P (type) 2748 1.1 mrg || TYPE_UNSIGNED (type) == unsignedp) 2749 1.1 mrg return type; 2750 1.1 mrg 2751 1.1 mrg #define TYPE_OK(node) \ 2752 1.1 mrg (TYPE_MODE (type) == TYPE_MODE (node) \ 2753 1.1 mrg && TYPE_PRECISION (type) == TYPE_PRECISION (node)) 2754 1.1 mrg if (TYPE_OK (signed_char_type_node)) 2755 1.1 mrg return unsignedp ? unsigned_char_type_node : signed_char_type_node; 2756 1.1 mrg if (TYPE_OK (integer_type_node)) 2757 1.1 mrg return unsignedp ? unsigned_type_node : integer_type_node; 2758 1.1 mrg if (TYPE_OK (short_integer_type_node)) 2759 1.1 mrg return unsignedp ? short_unsigned_type_node : short_integer_type_node; 2760 1.1 mrg if (TYPE_OK (long_integer_type_node)) 2761 1.1 mrg return unsignedp ? long_unsigned_type_node : long_integer_type_node; 2762 1.1 mrg if (TYPE_OK (long_long_integer_type_node)) 2763 1.1 mrg return (unsignedp ? long_long_unsigned_type_node 2764 1.1 mrg : long_long_integer_type_node); 2765 1.1 mrg 2766 1.1 mrg for (i = 0; i < NUM_INT_N_ENTS; i ++) 2767 1.1 mrg if (int_n_enabled_p[i] 2768 1.1 mrg && TYPE_MODE (type) == int_n_data[i].m 2769 1.1 mrg && TYPE_PRECISION (type) == int_n_data[i].bitsize) 2770 1.1 mrg return (unsignedp ? int_n_trees[i].unsigned_type 2771 1.1 mrg : int_n_trees[i].signed_type); 2772 1.1 mrg 2773 1.1 mrg #if HOST_BITS_PER_WIDE_INT >= 64 2774 1.1 mrg if (TYPE_OK (intTI_type_node)) 2775 1.1 mrg return unsignedp ? unsigned_intTI_type_node : intTI_type_node; 2776 1.1 mrg #endif 2777 1.1 mrg if (TYPE_OK (intDI_type_node)) 2778 1.1 mrg return unsignedp ? unsigned_intDI_type_node : intDI_type_node; 2779 1.1 mrg if (TYPE_OK (intSI_type_node)) 2780 1.1 mrg return unsignedp ? unsigned_intSI_type_node : intSI_type_node; 2781 1.1 mrg if (TYPE_OK (intHI_type_node)) 2782 1.1 mrg return unsignedp ? unsigned_intHI_type_node : intHI_type_node; 2783 1.1 mrg if (TYPE_OK (intQI_type_node)) 2784 1.1 mrg return unsignedp ? unsigned_intQI_type_node : intQI_type_node; 2785 1.1 mrg #undef TYPE_OK 2786 1.1 mrg 2787 1.1 mrg return build_nonstandard_integer_type (TYPE_PRECISION (type), unsignedp); 2788 1.1 mrg } 2789 1.1 mrg 2790 1.1 mrg /* Build a bit-field integer type for the given WIDTH and UNSIGNEDP. */ 2791 1.1 mrg 2792 1.1 mrg tree 2793 1.1 mrg c_build_bitfield_integer_type (unsigned HOST_WIDE_INT width, int unsignedp) 2794 1.1 mrg { 2795 1.1 mrg int i; 2796 1.1 mrg 2797 1.1 mrg /* Extended integer types of the same width as a standard type have 2798 1.1 mrg lesser rank, so those of the same width as int promote to int or 2799 1.1 mrg unsigned int and are valid for printf formats expecting int or 2800 1.1 mrg unsigned int. To avoid such special cases, avoid creating 2801 1.1 mrg extended integer types for bit-fields if a standard integer type 2802 1.1 mrg is available. */ 2803 1.1 mrg if (width == TYPE_PRECISION (integer_type_node)) 2804 1.1 mrg return unsignedp ? unsigned_type_node : integer_type_node; 2805 1.1 mrg if (width == TYPE_PRECISION (signed_char_type_node)) 2806 1.1 mrg return unsignedp ? unsigned_char_type_node : signed_char_type_node; 2807 1.1 mrg if (width == TYPE_PRECISION (short_integer_type_node)) 2808 1.1 mrg return unsignedp ? short_unsigned_type_node : short_integer_type_node; 2809 1.1 mrg if (width == TYPE_PRECISION (long_integer_type_node)) 2810 1.1 mrg return unsignedp ? long_unsigned_type_node : long_integer_type_node; 2811 1.1 mrg if (width == TYPE_PRECISION (long_long_integer_type_node)) 2812 1.1 mrg return (unsignedp ? long_long_unsigned_type_node 2813 1.1 mrg : long_long_integer_type_node); 2814 1.1 mrg for (i = 0; i < NUM_INT_N_ENTS; i ++) 2815 1.1 mrg if (int_n_enabled_p[i] 2816 1.1 mrg && width == int_n_data[i].bitsize) 2817 1.1 mrg return (unsignedp ? int_n_trees[i].unsigned_type 2818 1.1 mrg : int_n_trees[i].signed_type); 2819 1.1 mrg return build_nonstandard_integer_type (width, unsignedp); 2820 1.1 mrg } 2821 1.1 mrg 2822 1.1 mrg /* The C version of the register_builtin_type langhook. */ 2823 1.1 mrg 2824 1.1 mrg void 2825 1.1 mrg c_register_builtin_type (tree type, const char* name) 2826 1.1 mrg { 2827 1.1 mrg tree decl; 2828 1.1 mrg 2829 1.1 mrg decl = build_decl (UNKNOWN_LOCATION, 2830 1.1 mrg TYPE_DECL, get_identifier (name), type); 2831 1.1 mrg DECL_ARTIFICIAL (decl) = 1; 2832 1.1 mrg if (!TYPE_NAME (type)) 2833 1.1 mrg TYPE_NAME (type) = decl; 2834 1.1 mrg lang_hooks.decls.pushdecl (decl); 2835 1.1 mrg 2836 1.1 mrg registered_builtin_types = tree_cons (0, type, registered_builtin_types); 2837 1.1 mrg } 2838 1.1 mrg 2839 1.1 mrg /* Print an error message for invalid operands to arith operation 2841 1.1 mrg CODE with TYPE0 for operand 0, and TYPE1 for operand 1. 2842 1.1 mrg RICHLOC is a rich location for the message, containing either 2843 1.1 mrg three separate locations for each of the operator and operands 2844 1.1 mrg 2845 1.1 mrg lhs op rhs 2846 1.1 mrg ~~~ ^~ ~~~ 2847 1.1 mrg 2848 1.1 mrg (C FE), or one location ranging over all over them 2849 1.1 mrg 2850 1.1 mrg lhs op rhs 2851 1.1 mrg ~~~~^~~~~~ 2852 1.1 mrg 2853 1.1 mrg (C++ FE). */ 2854 1.1 mrg 2855 1.1 mrg void 2856 1.1 mrg binary_op_error (rich_location *richloc, enum tree_code code, 2857 1.1 mrg tree type0, tree type1) 2858 1.1 mrg { 2859 1.1 mrg const char *opname; 2860 1.1 mrg 2861 1.1 mrg switch (code) 2862 1.1 mrg { 2863 1.1 mrg case PLUS_EXPR: 2864 1.1 mrg opname = "+"; break; 2865 1.1 mrg case MINUS_EXPR: 2866 1.1 mrg opname = "-"; break; 2867 1.1 mrg case MULT_EXPR: 2868 1.1 mrg opname = "*"; break; 2869 1.1 mrg case MAX_EXPR: 2870 1.1 mrg opname = "max"; break; 2871 1.1 mrg case MIN_EXPR: 2872 1.1 mrg opname = "min"; break; 2873 1.1 mrg case EQ_EXPR: 2874 1.1 mrg opname = "=="; break; 2875 1.1 mrg case NE_EXPR: 2876 1.1 mrg opname = "!="; break; 2877 1.1 mrg case LE_EXPR: 2878 1.1 mrg opname = "<="; break; 2879 1.1 mrg case GE_EXPR: 2880 1.1 mrg opname = ">="; break; 2881 1.1 mrg case LT_EXPR: 2882 1.1 mrg opname = "<"; break; 2883 1.1 mrg case GT_EXPR: 2884 1.1 mrg opname = ">"; break; 2885 1.1 mrg case LSHIFT_EXPR: 2886 1.1 mrg opname = "<<"; break; 2887 1.1 mrg case RSHIFT_EXPR: 2888 1.1 mrg opname = ">>"; break; 2889 1.1 mrg case TRUNC_MOD_EXPR: 2890 1.1 mrg case FLOOR_MOD_EXPR: 2891 1.1 mrg opname = "%"; break; 2892 1.1 mrg case TRUNC_DIV_EXPR: 2893 1.1 mrg case FLOOR_DIV_EXPR: 2894 1.1 mrg opname = "/"; break; 2895 1.1 mrg case BIT_AND_EXPR: 2896 1.1 mrg opname = "&"; break; 2897 1.1 mrg case BIT_IOR_EXPR: 2898 1.1 mrg opname = "|"; break; 2899 1.1 mrg case TRUTH_ANDIF_EXPR: 2900 1.1 mrg opname = "&&"; break; 2901 1.1 mrg case TRUTH_ORIF_EXPR: 2902 1.1 mrg opname = "||"; break; 2903 1.1 mrg case BIT_XOR_EXPR: 2904 1.1 mrg opname = "^"; break; 2905 1.1 mrg default: 2906 1.1 mrg gcc_unreachable (); 2907 1.1 mrg } 2908 1.1 mrg error_at (richloc, 2909 1.1 mrg "invalid operands to binary %s (have %qT and %qT)", 2910 1.1 mrg opname, type0, type1); 2911 1.1 mrg } 2912 1.1 mrg 2913 1.1 mrg /* Given an expression as a tree, return its original type. Do this 2915 1.1 mrg by stripping any conversion that preserves the sign and precision. */ 2916 1.1 mrg static tree 2917 1.1 mrg expr_original_type (tree expr) 2918 1.1 mrg { 2919 1.1 mrg STRIP_SIGN_NOPS (expr); 2920 1.1 mrg return TREE_TYPE (expr); 2921 1.1 mrg } 2922 1.1 mrg 2923 1.1 mrg /* Subroutine of build_binary_op, used for comparison operations. 2924 1.1 mrg See if the operands have both been converted from subword integer types 2925 1.1 mrg and, if so, perhaps change them both back to their original type. 2926 1.1 mrg This function is also responsible for converting the two operands 2927 1.1 mrg to the proper common type for comparison. 2928 1.1 mrg 2929 1.1 mrg The arguments of this function are all pointers to local variables 2930 1.1 mrg of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1, 2931 1.1 mrg RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE. 2932 1.1 mrg 2933 1.1 mrg LOC is the location of the comparison. 2934 1.1 mrg 2935 1.1 mrg If this function returns non-NULL_TREE, it means that the comparison has 2936 1.1 mrg a constant value. What this function returns is an expression for 2937 1.1 mrg that value. */ 2938 1.1 mrg 2939 1.1 mrg tree 2940 1.1 mrg shorten_compare (location_t loc, tree *op0_ptr, tree *op1_ptr, 2941 1.1 mrg tree *restype_ptr, enum tree_code *rescode_ptr) 2942 1.1 mrg { 2943 1.1 mrg tree type; 2944 1.1 mrg tree op0 = *op0_ptr; 2945 1.1 mrg tree op1 = *op1_ptr; 2946 1.1 mrg int unsignedp0, unsignedp1; 2947 1.1 mrg int real1, real2; 2948 1.1 mrg tree primop0, primop1; 2949 1.1 mrg enum tree_code code = *rescode_ptr; 2950 1.1 mrg 2951 1.1 mrg /* Throw away any conversions to wider types 2952 1.1 mrg already present in the operands. */ 2953 1.1 mrg 2954 1.1 mrg primop0 = c_common_get_narrower (op0, &unsignedp0); 2955 1.1 mrg primop1 = c_common_get_narrower (op1, &unsignedp1); 2956 1.1 mrg 2957 1.1 mrg /* If primopN is first sign-extended from primopN's precision to opN's 2958 1.1 mrg precision, then zero-extended from opN's precision to 2959 1.1 mrg *restype_ptr precision, shortenings might be invalid. */ 2960 1.1 mrg if (TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (TREE_TYPE (op0)) 2961 1.1 mrg && TYPE_PRECISION (TREE_TYPE (op0)) < TYPE_PRECISION (*restype_ptr) 2962 1.1 mrg && !unsignedp0 2963 1.1 mrg && TYPE_UNSIGNED (TREE_TYPE (op0))) 2964 1.1 mrg primop0 = op0; 2965 1.1 mrg if (TYPE_PRECISION (TREE_TYPE (primop1)) < TYPE_PRECISION (TREE_TYPE (op1)) 2966 1.1 mrg && TYPE_PRECISION (TREE_TYPE (op1)) < TYPE_PRECISION (*restype_ptr) 2967 1.1 mrg && !unsignedp1 2968 1.1 mrg && TYPE_UNSIGNED (TREE_TYPE (op1))) 2969 1.1 mrg primop1 = op1; 2970 1.1 mrg 2971 1.1 mrg /* Handle the case that OP0 does not *contain* a conversion 2972 1.1 mrg but it *requires* conversion to FINAL_TYPE. */ 2973 1.1 mrg 2974 1.1 mrg if (op0 == primop0 && TREE_TYPE (op0) != *restype_ptr) 2975 1.1 mrg unsignedp0 = TYPE_UNSIGNED (TREE_TYPE (op0)); 2976 1.1 mrg if (op1 == primop1 && TREE_TYPE (op1) != *restype_ptr) 2977 1.1 mrg unsignedp1 = TYPE_UNSIGNED (TREE_TYPE (op1)); 2978 1.1 mrg 2979 1.1 mrg /* If one of the operands must be floated, we cannot optimize. */ 2980 1.1 mrg real1 = TREE_CODE (TREE_TYPE (primop0)) == REAL_TYPE; 2981 1.1 mrg real2 = TREE_CODE (TREE_TYPE (primop1)) == REAL_TYPE; 2982 1.1 mrg 2983 1.1 mrg /* If first arg is constant, swap the args (changing operation 2984 1.1 mrg so value is preserved), for canonicalization. Don't do this if 2985 1.1 mrg the second arg is 0. */ 2986 1.1 mrg 2987 1.1 mrg if (TREE_CONSTANT (primop0) 2988 1.1 mrg && !integer_zerop (primop1) && !real_zerop (primop1) 2989 1.1 mrg && !fixed_zerop (primop1)) 2990 1.1 mrg { 2991 1.1 mrg std::swap (primop0, primop1); 2992 1.1 mrg std::swap (op0, op1); 2993 1.1 mrg *op0_ptr = op0; 2994 1.1 mrg *op1_ptr = op1; 2995 1.1 mrg std::swap (unsignedp0, unsignedp1); 2996 1.1 mrg std::swap (real1, real2); 2997 1.1 mrg 2998 1.1 mrg switch (code) 2999 1.1 mrg { 3000 1.1 mrg case LT_EXPR: 3001 1.1 mrg code = GT_EXPR; 3002 1.1 mrg break; 3003 1.1 mrg case GT_EXPR: 3004 1.1 mrg code = LT_EXPR; 3005 1.1 mrg break; 3006 1.1 mrg case LE_EXPR: 3007 1.1 mrg code = GE_EXPR; 3008 1.1 mrg break; 3009 1.1 mrg case GE_EXPR: 3010 1.1 mrg code = LE_EXPR; 3011 1.1 mrg break; 3012 1.1 mrg default: 3013 1.1 mrg break; 3014 1.1 mrg } 3015 1.1 mrg *rescode_ptr = code; 3016 1.1 mrg } 3017 1.1 mrg 3018 1.1 mrg /* If comparing an integer against a constant more bits wide, 3019 1.1 mrg maybe we can deduce a value of 1 or 0 independent of the data. 3020 1.1 mrg Or else truncate the constant now 3021 1.1 mrg rather than extend the variable at run time. 3022 1.1 mrg 3023 1.1 mrg This is only interesting if the constant is the wider arg. 3024 1.1 mrg Also, it is not safe if the constant is unsigned and the 3025 1.1 mrg variable arg is signed, since in this case the variable 3026 1.1 mrg would be sign-extended and then regarded as unsigned. 3027 1.1 mrg Our technique fails in this case because the lowest/highest 3028 1.1 mrg possible unsigned results don't follow naturally from the 3029 1.1 mrg lowest/highest possible values of the variable operand. 3030 1.1 mrg For just EQ_EXPR and NE_EXPR there is another technique that 3031 1.1 mrg could be used: see if the constant can be faithfully represented 3032 1.1 mrg in the other operand's type, by truncating it and reextending it 3033 1.1 mrg and see if that preserves the constant's value. */ 3034 1.1 mrg 3035 1.1 mrg if (!real1 && !real2 3036 1.1 mrg && TREE_CODE (TREE_TYPE (primop0)) != FIXED_POINT_TYPE 3037 1.1 mrg && TREE_CODE (primop1) == INTEGER_CST 3038 1.1 mrg && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr)) 3039 1.1 mrg { 3040 1.1 mrg int min_gt, max_gt, min_lt, max_lt; 3041 1.1 mrg tree maxval, minval; 3042 1.1 mrg /* 1 if comparison is nominally unsigned. */ 3043 1.1 mrg int unsignedp = TYPE_UNSIGNED (*restype_ptr); 3044 1.1 mrg tree val; 3045 1.1 mrg 3046 1.1 mrg type = c_common_signed_or_unsigned_type (unsignedp0, 3047 1.1 mrg TREE_TYPE (primop0)); 3048 1.1 mrg 3049 1.1 mrg maxval = TYPE_MAX_VALUE (type); 3050 1.1 mrg minval = TYPE_MIN_VALUE (type); 3051 1.1 mrg 3052 1.1 mrg if (unsignedp && !unsignedp0) 3053 1.1 mrg *restype_ptr = c_common_signed_type (*restype_ptr); 3054 1.1 mrg 3055 1.1 mrg if (TREE_TYPE (primop1) != *restype_ptr) 3056 1.1 mrg { 3057 1.1 mrg /* Convert primop1 to target type, but do not introduce 3058 1.1 mrg additional overflow. We know primop1 is an int_cst. */ 3059 1.1 mrg primop1 = force_fit_type (*restype_ptr, 3060 1.1 mrg wi::to_wide 3061 1.1 mrg (primop1, 3062 1.1 mrg TYPE_PRECISION (*restype_ptr)), 3063 1.1 mrg 0, TREE_OVERFLOW (primop1)); 3064 1.1 mrg } 3065 1.1 mrg if (type != *restype_ptr) 3066 1.1 mrg { 3067 1.1 mrg minval = convert (*restype_ptr, minval); 3068 1.1 mrg maxval = convert (*restype_ptr, maxval); 3069 1.1 mrg } 3070 1.1 mrg 3071 1.1 mrg min_gt = tree_int_cst_lt (primop1, minval); 3072 1.1 mrg max_gt = tree_int_cst_lt (primop1, maxval); 3073 1.1 mrg min_lt = tree_int_cst_lt (minval, primop1); 3074 1.1 mrg max_lt = tree_int_cst_lt (maxval, primop1); 3075 1.1 mrg 3076 1.1 mrg val = 0; 3077 1.1 mrg /* This used to be a switch, but Genix compiler can't handle that. */ 3078 1.1 mrg if (code == NE_EXPR) 3079 1.1 mrg { 3080 1.1 mrg if (max_lt || min_gt) 3081 1.1 mrg val = truthvalue_true_node; 3082 1.1 mrg } 3083 1.1 mrg else if (code == EQ_EXPR) 3084 1.1 mrg { 3085 1.1 mrg if (max_lt || min_gt) 3086 1.1 mrg val = truthvalue_false_node; 3087 1.1 mrg } 3088 1.1 mrg else if (code == LT_EXPR) 3089 1.1 mrg { 3090 1.1 mrg if (max_lt) 3091 1.1 mrg val = truthvalue_true_node; 3092 1.1 mrg if (!min_lt) 3093 1.1 mrg val = truthvalue_false_node; 3094 1.1 mrg } 3095 1.1 mrg else if (code == GT_EXPR) 3096 1.1 mrg { 3097 1.1 mrg if (min_gt) 3098 1.1 mrg val = truthvalue_true_node; 3099 1.1 mrg if (!max_gt) 3100 1.1 mrg val = truthvalue_false_node; 3101 1.1 mrg } 3102 1.1 mrg else if (code == LE_EXPR) 3103 1.1 mrg { 3104 1.1 mrg if (!max_gt) 3105 1.1 mrg val = truthvalue_true_node; 3106 1.1 mrg if (min_gt) 3107 1.1 mrg val = truthvalue_false_node; 3108 1.1 mrg } 3109 1.1 mrg else if (code == GE_EXPR) 3110 1.1 mrg { 3111 1.1 mrg if (!min_lt) 3112 1.1 mrg val = truthvalue_true_node; 3113 1.1 mrg if (max_lt) 3114 1.1 mrg val = truthvalue_false_node; 3115 1.1 mrg } 3116 1.1 mrg 3117 1.1 mrg /* If primop0 was sign-extended and unsigned comparison specd, 3118 1.1 mrg we did a signed comparison above using the signed type bounds. 3119 1.1 mrg But the comparison we output must be unsigned. 3120 1.1 mrg 3121 1.1 mrg Also, for inequalities, VAL is no good; but if the signed 3122 1.1 mrg comparison had *any* fixed result, it follows that the 3123 1.1 mrg unsigned comparison just tests the sign in reverse 3124 1.1 mrg (positive values are LE, negative ones GE). 3125 1.1 mrg So we can generate an unsigned comparison 3126 1.1 mrg against an extreme value of the signed type. */ 3127 1.1 mrg 3128 1.1 mrg if (unsignedp && !unsignedp0) 3129 1.1 mrg { 3130 1.1 mrg if (val != 0) 3131 1.1 mrg switch (code) 3132 1.1 mrg { 3133 1.1 mrg case LT_EXPR: 3134 1.1 mrg case GE_EXPR: 3135 1.1 mrg primop1 = TYPE_MIN_VALUE (type); 3136 1.1 mrg val = 0; 3137 1.1 mrg break; 3138 1.1 mrg 3139 1.1 mrg case LE_EXPR: 3140 1.1 mrg case GT_EXPR: 3141 1.1 mrg primop1 = TYPE_MAX_VALUE (type); 3142 1.1 mrg val = 0; 3143 1.1 mrg break; 3144 1.1 mrg 3145 1.1 mrg default: 3146 1.1 mrg break; 3147 1.1 mrg } 3148 1.1 mrg type = c_common_unsigned_type (type); 3149 1.1 mrg } 3150 1.1 mrg 3151 1.1 mrg if (TREE_CODE (primop0) != INTEGER_CST 3152 1.1 mrg /* Don't warn if it's from a (non-system) macro. */ 3153 1.1 mrg && !(from_macro_expansion_at 3154 1.1 mrg (expansion_point_location_if_in_system_header 3155 1.1 mrg (EXPR_LOCATION (primop0))))) 3156 1.1 mrg { 3157 1.1 mrg if (val == truthvalue_false_node) 3158 1.1 mrg warning_at (loc, OPT_Wtype_limits, 3159 1.1 mrg "comparison is always false due to limited range of data type"); 3160 1.1 mrg if (val == truthvalue_true_node) 3161 1.1 mrg warning_at (loc, OPT_Wtype_limits, 3162 1.1 mrg "comparison is always true due to limited range of data type"); 3163 1.1 mrg } 3164 1.1 mrg 3165 1.1 mrg if (val != 0) 3166 1.1 mrg { 3167 1.1 mrg /* Don't forget to evaluate PRIMOP0 if it has side effects. */ 3168 1.1 mrg if (TREE_SIDE_EFFECTS (primop0)) 3169 1.1 mrg return build2 (COMPOUND_EXPR, TREE_TYPE (val), primop0, val); 3170 1.1 mrg return val; 3171 1.1 mrg } 3172 1.1 mrg 3173 1.1 mrg /* Value is not predetermined, but do the comparison 3174 1.1 mrg in the type of the operand that is not constant. 3175 1.1 mrg TYPE is already properly set. */ 3176 1.1 mrg } 3177 1.1 mrg 3178 1.1 mrg /* If either arg is decimal float and the other is float, find the 3179 1.1 mrg proper common type to use for comparison. */ 3180 1.1 mrg else if (real1 && real2 3181 1.1 mrg && DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0))) 3182 1.1 mrg && DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1)))) 3183 1.1 mrg type = common_type (TREE_TYPE (primop0), TREE_TYPE (primop1)); 3184 1.1 mrg 3185 1.1 mrg /* If either arg is decimal float and the other is float, fail. */ 3186 1.1 mrg else if (real1 && real2 3187 1.1 mrg && (DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0))) 3188 1.1 mrg || DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1))))) 3189 1.1 mrg { 3190 1.1 mrg type = *restype_ptr; 3191 1.1 mrg primop0 = op0; 3192 1.1 mrg primop1 = op1; 3193 1.1 mrg } 3194 1.1 mrg 3195 1.1 mrg else if (real1 && real2 3196 1.1 mrg && (TYPE_PRECISION (TREE_TYPE (primop0)) 3197 1.1 mrg == TYPE_PRECISION (TREE_TYPE (primop1)))) 3198 1.1 mrg type = TREE_TYPE (primop0); 3199 1.1 mrg 3200 1.1 mrg /* If args' natural types are both narrower than nominal type 3201 1.1 mrg and both extend in the same manner, compare them 3202 1.1 mrg in the type of the wider arg. 3203 1.1 mrg Otherwise must actually extend both to the nominal 3204 1.1 mrg common type lest different ways of extending 3205 1.1 mrg alter the result. 3206 1.1 mrg (eg, (short)-1 == (unsigned short)-1 should be 0.) */ 3207 1.1 mrg 3208 1.1 mrg else if (unsignedp0 == unsignedp1 && real1 == real2 3209 1.1 mrg && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr) 3210 1.1 mrg && TYPE_PRECISION (TREE_TYPE (primop1)) < TYPE_PRECISION (*restype_ptr)) 3211 1.1 mrg { 3212 1.1 mrg type = common_type (TREE_TYPE (primop0), TREE_TYPE (primop1)); 3213 1.1 mrg type = c_common_signed_or_unsigned_type (unsignedp0 3214 1.1 mrg || TYPE_UNSIGNED (*restype_ptr), 3215 1.1 mrg type); 3216 1.1 mrg /* Make sure shorter operand is extended the right way 3217 1.1 mrg to match the longer operand. */ 3218 1.1 mrg primop0 3219 1.1 mrg = convert (c_common_signed_or_unsigned_type (unsignedp0, 3220 1.1 mrg TREE_TYPE (primop0)), 3221 1.1 mrg primop0); 3222 1.1 mrg primop1 3223 1.1 mrg = convert (c_common_signed_or_unsigned_type (unsignedp1, 3224 1.1 mrg TREE_TYPE (primop1)), 3225 1.1 mrg primop1); 3226 1.1 mrg } 3227 1.1 mrg else 3228 1.1 mrg { 3229 1.1 mrg /* Here we must do the comparison on the nominal type 3230 1.1 mrg using the args exactly as we received them. */ 3231 1.1 mrg type = *restype_ptr; 3232 1.1 mrg primop0 = op0; 3233 1.1 mrg primop1 = op1; 3234 1.1 mrg 3235 1.1 mrg /* We want to fold unsigned comparisons of >= and < against zero. 3236 1.1 mrg For these, we may also issue a warning if we have a non-constant 3237 1.1 mrg compared against zero, where the zero was spelled as "0" (rather 3238 1.1 mrg than merely folding to it). 3239 1.1 mrg If we have at least one constant, then op1 is constant 3240 1.1 mrg and we may have a non-constant expression as op0. */ 3241 1.1 mrg if (!real1 && !real2 && integer_zerop (primop1) 3242 1.1 mrg && TYPE_UNSIGNED (*restype_ptr)) 3243 1.1 mrg { 3244 1.1 mrg tree value = NULL_TREE; 3245 1.1 mrg /* All unsigned values are >= 0, so we warn. However, 3246 1.1 mrg if OP0 is a constant that is >= 0, the signedness of 3247 1.1 mrg the comparison isn't an issue, so suppress the 3248 1.1 mrg warning. */ 3249 1.1 mrg tree folded_op0 = fold_for_warn (op0); 3250 1.1 mrg bool warn = 3251 1.1 mrg warn_type_limits && !in_system_header_at (loc) 3252 1.1 mrg && !(TREE_CODE (folded_op0) == INTEGER_CST 3253 1.1 mrg && !TREE_OVERFLOW (convert (c_common_signed_type (type), 3254 1.1 mrg folded_op0))) 3255 1.1 mrg /* Do not warn for enumeration types. */ 3256 1.1 mrg && (TREE_CODE (expr_original_type (folded_op0)) != ENUMERAL_TYPE); 3257 1.1 mrg 3258 1.1 mrg switch (code) 3259 1.1 mrg { 3260 1.1 mrg case GE_EXPR: 3261 1.1 mrg if (warn) 3262 1.1 mrg warning_at (loc, OPT_Wtype_limits, 3263 1.1 mrg "comparison of unsigned expression in %<>= 0%> " 3264 1.1 mrg "is always true"); 3265 1.1 mrg value = truthvalue_true_node; 3266 1.1 mrg break; 3267 1.1 mrg 3268 1.1 mrg case LT_EXPR: 3269 1.1 mrg if (warn) 3270 1.1 mrg warning_at (loc, OPT_Wtype_limits, 3271 1.1 mrg "comparison of unsigned expression in %<< 0%> " 3272 1.1 mrg "is always false"); 3273 1.1 mrg value = truthvalue_false_node; 3274 1.1 mrg break; 3275 1.1 mrg 3276 1.1 mrg default: 3277 1.1 mrg break; 3278 1.1 mrg } 3279 1.1 mrg 3280 1.1 mrg if (value != NULL_TREE) 3281 1.1 mrg { 3282 1.1 mrg /* Don't forget to evaluate PRIMOP0 if it has side effects. */ 3283 1.1 mrg if (TREE_SIDE_EFFECTS (primop0)) 3284 1.1 mrg return build2 (COMPOUND_EXPR, TREE_TYPE (value), 3285 1.1 mrg primop0, value); 3286 1.1 mrg return value; 3287 1.1 mrg } 3288 1.1 mrg } 3289 1.1 mrg } 3290 1.1 mrg 3291 1.1 mrg *op0_ptr = convert (type, primop0); 3292 1.1 mrg *op1_ptr = convert (type, primop1); 3293 1.1 mrg 3294 1.1 mrg *restype_ptr = truthvalue_type_node; 3295 1.1 mrg 3296 1.1 mrg return NULL_TREE; 3297 1.1 mrg } 3298 1.1 mrg 3299 1.1 mrg /* Return a tree for the sum or difference (RESULTCODE says which) 3301 1.1 mrg of pointer PTROP and integer INTOP. */ 3302 1.1 mrg 3303 1.1 mrg tree 3304 1.1 mrg pointer_int_sum (location_t loc, enum tree_code resultcode, 3305 1.1 mrg tree ptrop, tree intop, bool complain) 3306 1.1 mrg { 3307 1.1 mrg tree size_exp, ret; 3308 1.1 mrg 3309 1.1 mrg /* The result is a pointer of the same type that is being added. */ 3310 1.1 mrg tree result_type = TREE_TYPE (ptrop); 3311 1.1 mrg 3312 1.1 mrg if (TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE) 3313 1.1 mrg { 3314 1.1 mrg if (complain && warn_pointer_arith) 3315 1.1 mrg pedwarn (loc, OPT_Wpointer_arith, 3316 1.1 mrg "pointer of type %<void *%> used in arithmetic"); 3317 1.1 mrg else if (!complain) 3318 1.1 mrg return error_mark_node; 3319 1.1 mrg size_exp = integer_one_node; 3320 1.1 mrg } 3321 1.1 mrg else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE) 3322 1.1 mrg { 3323 1.1 mrg if (complain && warn_pointer_arith) 3324 1.1 mrg pedwarn (loc, OPT_Wpointer_arith, 3325 1.1 mrg "pointer to a function used in arithmetic"); 3326 1.1 mrg else if (!complain) 3327 1.1 mrg return error_mark_node; 3328 1.1 mrg size_exp = integer_one_node; 3329 1.1 mrg } 3330 1.1 mrg else if (!verify_type_context (loc, TCTX_POINTER_ARITH, 3331 1.1 mrg TREE_TYPE (result_type))) 3332 1.1 mrg size_exp = integer_one_node; 3333 1.1 mrg else 3334 1.1 mrg { 3335 1.1 mrg if (!complain && !COMPLETE_TYPE_P (TREE_TYPE (result_type))) 3336 1.1 mrg return error_mark_node; 3337 1.1 mrg size_exp = size_in_bytes_loc (loc, TREE_TYPE (result_type)); 3338 1.1 mrg /* Wrap the pointer expression in a SAVE_EXPR to make sure it 3339 1.1 mrg is evaluated first when the size expression may depend 3340 1.1 mrg on it for VM types. */ 3341 1.1 mrg if (TREE_SIDE_EFFECTS (size_exp) 3342 1.1 mrg && TREE_SIDE_EFFECTS (ptrop) 3343 1.1 mrg && variably_modified_type_p (TREE_TYPE (ptrop), NULL)) 3344 1.1 mrg { 3345 1.1 mrg ptrop = save_expr (ptrop); 3346 1.1 mrg size_exp = build2 (COMPOUND_EXPR, TREE_TYPE (intop), ptrop, size_exp); 3347 1.1 mrg } 3348 1.1 mrg } 3349 1.1 mrg 3350 1.1 mrg /* We are manipulating pointer values, so we don't need to warn 3351 1.1 mrg about relying on undefined signed overflow. We disable the 3352 1.1 mrg warning here because we use integer types so fold won't know that 3353 1.1 mrg they are really pointers. */ 3354 1.1 mrg fold_defer_overflow_warnings (); 3355 1.1 mrg 3356 1.1 mrg /* If what we are about to multiply by the size of the elements 3357 1.1 mrg contains a constant term, apply distributive law 3358 1.1 mrg and multiply that constant term separately. 3359 1.1 mrg This helps produce common subexpressions. */ 3360 1.1 mrg if ((TREE_CODE (intop) == PLUS_EXPR || TREE_CODE (intop) == MINUS_EXPR) 3361 1.1 mrg && !TREE_CONSTANT (intop) 3362 1.1 mrg && TREE_CONSTANT (TREE_OPERAND (intop, 1)) 3363 1.1 mrg && TREE_CONSTANT (size_exp) 3364 1.1 mrg /* If the constant comes from pointer subtraction, 3365 1.1 mrg skip this optimization--it would cause an error. */ 3366 1.1 mrg && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop, 0))) == INTEGER_TYPE 3367 1.1 mrg /* If the constant is unsigned, and smaller than the pointer size, 3368 1.1 mrg then we must skip this optimization. This is because it could cause 3369 1.1 mrg an overflow error if the constant is negative but INTOP is not. */ 3370 1.1 mrg && (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (intop)) 3371 1.1 mrg || (TYPE_PRECISION (TREE_TYPE (intop)) 3372 1.1 mrg == TYPE_PRECISION (TREE_TYPE (ptrop))))) 3373 1.1 mrg { 3374 1.1 mrg enum tree_code subcode = resultcode; 3375 1.1 mrg tree int_type = TREE_TYPE (intop); 3376 1.1 mrg if (TREE_CODE (intop) == MINUS_EXPR) 3377 1.1 mrg subcode = (subcode == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR); 3378 1.1 mrg /* Convert both subexpression types to the type of intop, 3379 1.1 mrg because weird cases involving pointer arithmetic 3380 1.1 mrg can result in a sum or difference with different type args. */ 3381 1.1 mrg ptrop = build_binary_op (EXPR_LOCATION (TREE_OPERAND (intop, 1)), 3382 1.1 mrg subcode, ptrop, 3383 1.1 mrg convert (int_type, TREE_OPERAND (intop, 1)), 3384 1.1 mrg true); 3385 1.1 mrg intop = convert (int_type, TREE_OPERAND (intop, 0)); 3386 1.1 mrg } 3387 1.1 mrg 3388 1.1 mrg /* Convert the integer argument to a type the same size as sizetype 3389 1.1 mrg so the multiply won't overflow spuriously. */ 3390 1.1 mrg if (TYPE_PRECISION (TREE_TYPE (intop)) != TYPE_PRECISION (sizetype) 3391 1.1 mrg || TYPE_UNSIGNED (TREE_TYPE (intop)) != TYPE_UNSIGNED (sizetype)) 3392 1.1 mrg intop = convert (c_common_type_for_size (TYPE_PRECISION (sizetype), 3393 1.1 mrg TYPE_UNSIGNED (sizetype)), intop); 3394 1.1 mrg 3395 1.1 mrg /* Replace the integer argument with a suitable product by the object size. 3396 1.1 mrg Do this multiplication as signed, then convert to the appropriate type 3397 1.1 mrg for the pointer operation and disregard an overflow that occurred only 3398 1.1 mrg because of the sign-extension change in the latter conversion. */ 3399 1.1 mrg { 3400 1.1 mrg tree t = fold_build2_loc (loc, MULT_EXPR, TREE_TYPE (intop), intop, 3401 1.1 mrg convert (TREE_TYPE (intop), size_exp)); 3402 1.1 mrg intop = convert (sizetype, t); 3403 1.1 mrg if (TREE_OVERFLOW_P (intop) && !TREE_OVERFLOW (t)) 3404 1.1 mrg intop = wide_int_to_tree (TREE_TYPE (intop), wi::to_wide (intop)); 3405 1.1 mrg } 3406 1.1 mrg 3407 1.1 mrg /* Create the sum or difference. */ 3408 1.1 mrg if (resultcode == MINUS_EXPR) 3409 1.1 mrg intop = fold_build1_loc (loc, NEGATE_EXPR, sizetype, intop); 3410 1.1 mrg 3411 1.1 mrg ret = fold_build_pointer_plus_loc (loc, ptrop, intop); 3412 1.1 mrg 3413 1.1 mrg fold_undefer_and_ignore_overflow_warnings (); 3414 1.1 mrg 3415 1.1 mrg return ret; 3416 1.1 mrg } 3417 1.1 mrg 3418 1.1 mrg /* Wrap a C_MAYBE_CONST_EXPR around an expression that is fully folded 3420 1.1 mrg and if NON_CONST is known not to be permitted in an evaluated part 3421 1.1 mrg of a constant expression. */ 3422 1.1 mrg 3423 1.1 mrg tree 3424 1.1 mrg c_wrap_maybe_const (tree expr, bool non_const) 3425 1.1 mrg { 3426 1.1 mrg location_t loc = EXPR_LOCATION (expr); 3427 1.1 mrg 3428 1.1 mrg /* This should never be called for C++. */ 3429 1.1 mrg if (c_dialect_cxx ()) 3430 1.1 mrg gcc_unreachable (); 3431 1.1 mrg 3432 1.1 mrg /* The result of folding may have a NOP_EXPR to set TREE_NO_WARNING. */ 3433 1.1 mrg STRIP_TYPE_NOPS (expr); 3434 1.1 mrg expr = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (expr), NULL, expr); 3435 1.1 mrg C_MAYBE_CONST_EXPR_NON_CONST (expr) = non_const; 3436 1.1 mrg protected_set_expr_location (expr, loc); 3437 1.1 mrg 3438 1.1 mrg return expr; 3439 1.1 mrg } 3440 1.1 mrg 3441 1.1 mrg /* Return whether EXPR is a declaration whose address can never be NULL. 3442 1.1 mrg The address of the first struct member could be NULL only if it were 3443 1.1 mrg accessed through a NULL pointer, and such an access would be invalid. 3444 1.1 mrg The address of a weak symbol may be null unless it has a definition. */ 3445 1.1 mrg 3446 1.1 mrg bool 3447 1.1 mrg decl_with_nonnull_addr_p (const_tree expr) 3448 1.1 mrg { 3449 1.1 mrg if (!DECL_P (expr)) 3450 1.1 mrg return false; 3451 1.1 mrg 3452 1.1 mrg if (TREE_CODE (expr) == FIELD_DECL 3453 1.1 mrg || TREE_CODE (expr) == PARM_DECL 3454 1.1 mrg || TREE_CODE (expr) == LABEL_DECL) 3455 1.1 mrg return true; 3456 1.1 mrg 3457 1.1 mrg if (!VAR_OR_FUNCTION_DECL_P (expr)) 3458 1.1 mrg return false; 3459 1.1 mrg 3460 1.1 mrg if (!DECL_WEAK (expr)) 3461 1.1 mrg /* Ordinary (non-weak) symbols have nonnull addresses. */ 3462 1.1 mrg return true; 3463 1.1 mrg 3464 1.1 mrg if (DECL_INITIAL (expr) && DECL_INITIAL (expr) != error_mark_node) 3465 1.1 mrg /* Initialized weak symbols have nonnull addresses. */ 3466 1.1 mrg return true; 3467 1.1 mrg 3468 1.1 mrg if (DECL_EXTERNAL (expr) || !TREE_STATIC (expr)) 3469 1.1 mrg /* Uninitialized extern weak symbols and weak symbols with no 3470 1.1 mrg allocated storage might have a null address. */ 3471 1.1 mrg return false; 3472 1.1 mrg 3473 1.1 mrg tree attribs = DECL_ATTRIBUTES (expr); 3474 1.1 mrg if (lookup_attribute ("weakref", attribs)) 3475 1.1 mrg /* Weakref symbols might have a null address unless their referent 3476 1.1 mrg is known not to. Don't bother following weakref targets here. */ 3477 1.1 mrg return false; 3478 1.1 mrg 3479 1.1 mrg return true; 3480 1.1 mrg } 3481 1.1 mrg 3482 1.1 mrg /* Prepare expr to be an argument of a TRUTH_NOT_EXPR, 3483 1.1 mrg or for an `if' or `while' statement or ?..: exp. It should already 3484 1.1 mrg have been validated to be of suitable type; otherwise, a bad 3485 1.1 mrg diagnostic may result. 3486 1.1 mrg 3487 1.1 mrg The EXPR is located at LOCATION. 3488 1.1 mrg 3489 1.1 mrg This preparation consists of taking the ordinary 3490 1.1 mrg representation of an expression expr and producing a valid tree 3491 1.1 mrg boolean expression describing whether expr is nonzero. We could 3492 1.1 mrg simply always do build_binary_op (NE_EXPR, expr, truthvalue_false_node, 1), 3493 1.1 mrg but we optimize comparisons, &&, ||, and !. 3494 1.1 mrg 3495 1.1 mrg The resulting type should always be `truthvalue_type_node'. */ 3496 1.1 mrg 3497 1.1 mrg tree 3498 1.1 mrg c_common_truthvalue_conversion (location_t location, tree expr) 3499 1.1 mrg { 3500 1.1 mrg STRIP_ANY_LOCATION_WRAPPER (expr); 3501 1.1 mrg switch (TREE_CODE (expr)) 3502 1.1 mrg { 3503 1.1 mrg case EQ_EXPR: case NE_EXPR: case UNEQ_EXPR: case LTGT_EXPR: 3504 1.1 mrg case LE_EXPR: case GE_EXPR: case LT_EXPR: case GT_EXPR: 3505 1.1 mrg case UNLE_EXPR: case UNGE_EXPR: case UNLT_EXPR: case UNGT_EXPR: 3506 1.1 mrg case ORDERED_EXPR: case UNORDERED_EXPR: 3507 1.1 mrg if (TREE_TYPE (expr) == truthvalue_type_node) 3508 1.1 mrg return expr; 3509 1.1 mrg expr = build2 (TREE_CODE (expr), truthvalue_type_node, 3510 1.1 mrg TREE_OPERAND (expr, 0), TREE_OPERAND (expr, 1)); 3511 1.1 mrg goto ret; 3512 1.1 mrg 3513 1.1 mrg case TRUTH_ANDIF_EXPR: 3514 1.1 mrg case TRUTH_ORIF_EXPR: 3515 1.1 mrg case TRUTH_AND_EXPR: 3516 1.1 mrg case TRUTH_OR_EXPR: 3517 1.1 mrg case TRUTH_XOR_EXPR: 3518 1.1 mrg if (TREE_TYPE (expr) == truthvalue_type_node) 3519 1.1 mrg return expr; 3520 1.1 mrg expr = build2 (TREE_CODE (expr), truthvalue_type_node, 3521 1.1 mrg c_common_truthvalue_conversion (location, 3522 1.1 mrg TREE_OPERAND (expr, 0)), 3523 1.1 mrg c_common_truthvalue_conversion (location, 3524 1.1 mrg TREE_OPERAND (expr, 1))); 3525 1.1 mrg goto ret; 3526 1.1 mrg 3527 1.1 mrg case TRUTH_NOT_EXPR: 3528 1.1 mrg if (TREE_TYPE (expr) == truthvalue_type_node) 3529 1.1 mrg return expr; 3530 1.1 mrg expr = build1 (TREE_CODE (expr), truthvalue_type_node, 3531 1.1 mrg c_common_truthvalue_conversion (location, 3532 1.1 mrg TREE_OPERAND (expr, 0))); 3533 1.1 mrg goto ret; 3534 1.1 mrg 3535 1.1 mrg case ERROR_MARK: 3536 1.1 mrg return expr; 3537 1.1 mrg 3538 1.1 mrg case INTEGER_CST: 3539 1.1 mrg if (TREE_CODE (TREE_TYPE (expr)) == ENUMERAL_TYPE 3540 1.1 mrg && !integer_zerop (expr) 3541 1.1 mrg && !integer_onep (expr)) 3542 1.1 mrg warning_at (location, OPT_Wint_in_bool_context, 3543 1.1 mrg "enum constant in boolean context"); 3544 1.1 mrg return integer_zerop (expr) ? truthvalue_false_node 3545 1.1 mrg : truthvalue_true_node; 3546 1.1 mrg 3547 1.1 mrg case REAL_CST: 3548 1.1 mrg return real_compare (NE_EXPR, &TREE_REAL_CST (expr), &dconst0) 3549 1.1 mrg ? truthvalue_true_node 3550 1.1 mrg : truthvalue_false_node; 3551 1.1 mrg 3552 1.1 mrg case FIXED_CST: 3553 1.1 mrg return fixed_compare (NE_EXPR, &TREE_FIXED_CST (expr), 3554 1.1 mrg &FCONST0 (TYPE_MODE (TREE_TYPE (expr)))) 3555 1.1 mrg ? truthvalue_true_node 3556 1.1 mrg : truthvalue_false_node; 3557 1.1 mrg 3558 1.1 mrg case FUNCTION_DECL: 3559 1.1 mrg expr = build_unary_op (location, ADDR_EXPR, expr, false); 3560 1.1 mrg /* Fall through. */ 3561 1.1 mrg 3562 1.1 mrg case ADDR_EXPR: 3563 1.1 mrg { 3564 1.1 mrg tree inner = TREE_OPERAND (expr, 0); 3565 1.1 mrg if (decl_with_nonnull_addr_p (inner) 3566 1.1 mrg /* Check both EXPR and INNER for suppression. */ 3567 1.1 mrg && !warning_suppressed_p (expr, OPT_Waddress) 3568 1.1 mrg && !warning_suppressed_p (inner, OPT_Waddress)) 3569 1.1 mrg { 3570 1.1 mrg /* Common Ada programmer's mistake. */ 3571 1.1 mrg warning_at (location, 3572 1.1 mrg OPT_Waddress, 3573 1.1 mrg "the address of %qD will always evaluate as %<true%>", 3574 1.1 mrg inner); 3575 1.1 mrg suppress_warning (inner, OPT_Waddress); 3576 1.1 mrg return truthvalue_true_node; 3577 1.1 mrg } 3578 1.1 mrg break; 3579 1.1 mrg } 3580 1.1 mrg 3581 1.1 mrg case COMPLEX_EXPR: 3582 1.1 mrg expr = build_binary_op (EXPR_LOCATION (expr), 3583 1.1 mrg (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1)) 3584 1.1 mrg ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR), 3585 1.1 mrg c_common_truthvalue_conversion (location, 3586 1.1 mrg TREE_OPERAND (expr, 0)), 3587 1.1 mrg c_common_truthvalue_conversion (location, 3588 1.1 mrg TREE_OPERAND (expr, 1)), 3589 1.1 mrg false); 3590 1.1 mrg goto ret; 3591 1.1 mrg 3592 1.1 mrg case NEGATE_EXPR: 3593 1.1 mrg case ABS_EXPR: 3594 1.1 mrg case ABSU_EXPR: 3595 1.1 mrg case FLOAT_EXPR: 3596 1.1 mrg case EXCESS_PRECISION_EXPR: 3597 1.1 mrg /* These don't change whether an object is nonzero or zero. */ 3598 1.1 mrg return c_common_truthvalue_conversion (location, TREE_OPERAND (expr, 0)); 3599 1.1 mrg 3600 1.1 mrg case LROTATE_EXPR: 3601 1.1 mrg case RROTATE_EXPR: 3602 1.1 mrg /* These don't change whether an object is zero or nonzero, but 3603 1.1 mrg we can't ignore them if their second arg has side-effects. */ 3604 1.1 mrg if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1))) 3605 1.1 mrg { 3606 1.1 mrg expr = build2 (COMPOUND_EXPR, truthvalue_type_node, 3607 1.1 mrg TREE_OPERAND (expr, 1), 3608 1.1 mrg c_common_truthvalue_conversion 3609 1.1 mrg (location, TREE_OPERAND (expr, 0))); 3610 1.1 mrg goto ret; 3611 1.1 mrg } 3612 1.1 mrg else 3613 1.1 mrg return c_common_truthvalue_conversion (location, 3614 1.1 mrg TREE_OPERAND (expr, 0)); 3615 1.1 mrg 3616 1.1 mrg case MULT_EXPR: 3617 1.1 mrg warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context, 3618 1.1 mrg "%<*%> in boolean context, suggest %<&&%> instead"); 3619 1.1 mrg break; 3620 1.1 mrg 3621 1.1 mrg case LSHIFT_EXPR: 3622 1.1 mrg /* We will only warn on signed shifts here, because the majority of 3623 1.1 mrg false positive warnings happen in code where unsigned arithmetic 3624 1.1 mrg was used in anticipation of a possible overflow. 3625 1.1 mrg Furthermore, if we see an unsigned type here we know that the 3626 1.1 mrg result of the shift is not subject to integer promotion rules. */ 3627 1.1 mrg if (TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE 3628 1.1 mrg && !TYPE_UNSIGNED (TREE_TYPE (expr))) 3629 1.1 mrg warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context, 3630 1.1 mrg "%<<<%> in boolean context, did you mean %<<%>?"); 3631 1.1 mrg break; 3632 1.1 mrg 3633 1.1 mrg case COND_EXPR: 3634 1.1 mrg if (warn_int_in_bool_context 3635 1.1 mrg && !from_macro_definition_at (EXPR_LOCATION (expr))) 3636 1.1 mrg { 3637 1.1 mrg tree val1 = fold_for_warn (TREE_OPERAND (expr, 1)); 3638 1.1 mrg tree val2 = fold_for_warn (TREE_OPERAND (expr, 2)); 3639 1.1 mrg if (TREE_CODE (val1) == INTEGER_CST 3640 1.1 mrg && TREE_CODE (val2) == INTEGER_CST 3641 1.1 mrg && !integer_zerop (val1) 3642 1.1 mrg && !integer_zerop (val2) 3643 1.1 mrg && (!integer_onep (val1) 3644 1.1 mrg || !integer_onep (val2))) 3645 1.1 mrg warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context, 3646 1.1 mrg "%<?:%> using integer constants in boolean context, " 3647 1.1 mrg "the expression will always evaluate to %<true%>"); 3648 1.1 mrg else if ((TREE_CODE (val1) == INTEGER_CST 3649 1.1 mrg && !integer_zerop (val1) 3650 1.1 mrg && !integer_onep (val1)) 3651 1.1 mrg || (TREE_CODE (val2) == INTEGER_CST 3652 1.1 mrg && !integer_zerop (val2) 3653 1.1 mrg && !integer_onep (val2))) 3654 1.1 mrg warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context, 3655 1.1 mrg "%<?:%> using integer constants in boolean context"); 3656 1.1 mrg } 3657 1.1 mrg /* Distribute the conversion into the arms of a COND_EXPR. */ 3658 1.1 mrg if (c_dialect_cxx ()) 3659 1.1 mrg /* Avoid premature folding. */ 3660 1.1 mrg break; 3661 1.1 mrg else 3662 1.1 mrg { 3663 1.1 mrg int w = warn_int_in_bool_context; 3664 1.1 mrg warn_int_in_bool_context = 0; 3665 1.1 mrg /* Folding will happen later for C. */ 3666 1.1 mrg expr = build3 (COND_EXPR, truthvalue_type_node, 3667 1.1 mrg TREE_OPERAND (expr, 0), 3668 1.1 mrg c_common_truthvalue_conversion (location, 3669 1.1 mrg TREE_OPERAND (expr, 1)), 3670 1.1 mrg c_common_truthvalue_conversion (location, 3671 1.1 mrg TREE_OPERAND (expr, 2))); 3672 1.1 mrg warn_int_in_bool_context = w; 3673 1.1 mrg goto ret; 3674 1.1 mrg } 3675 1.1 mrg 3676 1.1 mrg CASE_CONVERT: 3677 1.1 mrg { 3678 1.1 mrg tree totype = TREE_TYPE (expr); 3679 1.1 mrg tree fromtype = TREE_TYPE (TREE_OPERAND (expr, 0)); 3680 1.1 mrg 3681 1.1 mrg if (POINTER_TYPE_P (totype) 3682 1.1 mrg && !c_inhibit_evaluation_warnings 3683 1.1 mrg && TREE_CODE (fromtype) == REFERENCE_TYPE) 3684 1.1 mrg { 3685 1.1 mrg tree inner = expr; 3686 1.1 mrg STRIP_NOPS (inner); 3687 1.1 mrg 3688 1.1 mrg if (DECL_P (inner)) 3689 1.1 mrg warning_at (location, 3690 1.1 mrg OPT_Waddress, 3691 1.1 mrg "the compiler can assume that the address of " 3692 1.1 mrg "%qD will always evaluate to %<true%>", 3693 1.1 mrg inner); 3694 1.1 mrg } 3695 1.1 mrg 3696 1.1 mrg /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE, 3697 1.1 mrg since that affects how `default_conversion' will behave. */ 3698 1.1 mrg if (TREE_CODE (totype) == REFERENCE_TYPE 3699 1.1 mrg || TREE_CODE (fromtype) == REFERENCE_TYPE) 3700 1.1 mrg break; 3701 1.1 mrg /* Don't strip a conversion from C++0x scoped enum, since they 3702 1.1 mrg don't implicitly convert to other types. */ 3703 1.1 mrg if (TREE_CODE (fromtype) == ENUMERAL_TYPE 3704 1.1 mrg && ENUM_IS_SCOPED (fromtype)) 3705 1.1 mrg break; 3706 1.1 mrg /* If this isn't narrowing the argument, we can ignore it. */ 3707 1.1 mrg if (TYPE_PRECISION (totype) >= TYPE_PRECISION (fromtype)) 3708 1.1 mrg { 3709 1.1 mrg tree op0 = TREE_OPERAND (expr, 0); 3710 1.1 mrg if ((TREE_CODE (fromtype) == POINTER_TYPE 3711 1.1 mrg && TREE_CODE (totype) == INTEGER_TYPE) 3712 1.1 mrg || warning_suppressed_p (expr, OPT_Waddress)) 3713 1.1 mrg /* Suppress -Waddress for casts to intptr_t, propagating 3714 1.1 mrg any suppression from the enclosing expression to its 3715 1.1 mrg operand. */ 3716 1.1 mrg suppress_warning (op0, OPT_Waddress); 3717 1.1 mrg return c_common_truthvalue_conversion (location, op0); 3718 1.1 mrg } 3719 1.1 mrg } 3720 1.1 mrg break; 3721 1.1 mrg 3722 1.1 mrg case MODIFY_EXPR: 3723 1.1 mrg if (!warning_suppressed_p (expr, OPT_Wparentheses) 3724 1.1 mrg && warn_parentheses 3725 1.1 mrg && warning_at (location, OPT_Wparentheses, 3726 1.1 mrg "suggest parentheses around assignment used as " 3727 1.1 mrg "truth value")) 3728 1.1 mrg suppress_warning (expr, OPT_Wparentheses); 3729 1.1 mrg break; 3730 1.1 mrg 3731 1.1 mrg case CONST_DECL: 3732 1.1 mrg { 3733 1.1 mrg tree folded_expr = fold_for_warn (expr); 3734 1.1 mrg if (folded_expr != expr) 3735 1.1 mrg return c_common_truthvalue_conversion (location, folded_expr); 3736 1.1 mrg } 3737 1.1 mrg break; 3738 1.1 mrg 3739 1.1 mrg default: 3740 1.1 mrg break; 3741 1.1 mrg } 3742 1.1 mrg 3743 1.1 mrg if (TREE_CODE (TREE_TYPE (expr)) == COMPLEX_TYPE) 3744 1.1 mrg { 3745 1.1 mrg tree t = save_expr (expr); 3746 1.1 mrg expr = (build_binary_op 3747 1.1 mrg (EXPR_LOCATION (expr), 3748 1.1 mrg (TREE_SIDE_EFFECTS (expr) 3749 1.1 mrg ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR), 3750 1.1 mrg c_common_truthvalue_conversion 3751 1.1 mrg (location, 3752 1.1 mrg build_unary_op (location, REALPART_EXPR, t, false)), 3753 1.1 mrg c_common_truthvalue_conversion 3754 1.1 mrg (location, 3755 1.1 mrg build_unary_op (location, IMAGPART_EXPR, t, false)), 3756 1.1 mrg false)); 3757 1.1 mrg goto ret; 3758 1.1 mrg } 3759 1.1 mrg 3760 1.1 mrg if (TREE_CODE (TREE_TYPE (expr)) == FIXED_POINT_TYPE) 3761 1.1 mrg { 3762 1.1 mrg tree fixed_zero_node = build_fixed (TREE_TYPE (expr), 3763 1.1 mrg FCONST0 (TYPE_MODE 3764 1.1 mrg (TREE_TYPE (expr)))); 3765 1.1 mrg return build_binary_op (location, NE_EXPR, expr, fixed_zero_node, true); 3766 1.1 mrg } 3767 1.1 mrg else 3768 1.1 mrg return build_binary_op (location, NE_EXPR, expr, integer_zero_node, true); 3769 1.1 mrg 3770 1.1 mrg ret: 3771 1.1 mrg protected_set_expr_location (expr, location); 3772 1.1 mrg return expr; 3773 1.1 mrg } 3774 1.1 mrg 3775 1.1 mrg static void def_builtin_1 (enum built_in_function fncode, 3777 1.1 mrg const char *name, 3778 1.1 mrg enum built_in_class fnclass, 3779 1.1 mrg tree fntype, tree libtype, 3780 1.1 mrg bool both_p, bool fallback_p, bool nonansi_p, 3781 1.1 mrg tree fnattrs, bool implicit_p); 3782 1.1 mrg 3783 1.1 mrg 3784 1.1 mrg /* Apply the TYPE_QUALS to the new DECL. */ 3785 1.1 mrg 3786 1.1 mrg void 3787 1.1 mrg c_apply_type_quals_to_decl (int type_quals, tree decl) 3788 1.1 mrg { 3789 1.1 mrg tree type = TREE_TYPE (decl); 3790 1.1 mrg 3791 1.1 mrg if (type == error_mark_node) 3792 1.1 mrg return; 3793 1.1 mrg 3794 1.1 mrg if ((type_quals & TYPE_QUAL_CONST) 3795 1.1 mrg || (type && TREE_CODE (type) == REFERENCE_TYPE)) 3796 1.1 mrg /* We used to check TYPE_NEEDS_CONSTRUCTING here, but now a constexpr 3797 1.1 mrg constructor can produce constant init, so rely on cp_finish_decl to 3798 1.1 mrg clear TREE_READONLY if the variable has non-constant init. */ 3799 1.1 mrg TREE_READONLY (decl) = 1; 3800 1.1 mrg if (type_quals & TYPE_QUAL_VOLATILE) 3801 1.1 mrg { 3802 1.1 mrg TREE_SIDE_EFFECTS (decl) = 1; 3803 1.1 mrg TREE_THIS_VOLATILE (decl) = 1; 3804 1.1 mrg } 3805 1.1 mrg if (type_quals & TYPE_QUAL_RESTRICT) 3806 1.1 mrg { 3807 1.1 mrg while (type && TREE_CODE (type) == ARRAY_TYPE) 3808 1.1 mrg /* Allow 'restrict' on arrays of pointers. 3809 1.1 mrg FIXME currently we just ignore it. */ 3810 1.1 mrg type = TREE_TYPE (type); 3811 1.1 mrg if (!type 3812 1.1 mrg || !POINTER_TYPE_P (type) 3813 1.1 mrg || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type))) 3814 1.1 mrg error ("invalid use of %<restrict%>"); 3815 1.1 mrg } 3816 1.1 mrg } 3817 1.1 mrg 3818 1.1 mrg /* Return the typed-based alias set for T, which may be an expression 3819 1.1 mrg or a type. Return -1 if we don't do anything special. */ 3820 1.1 mrg 3821 1.1 mrg alias_set_type 3822 1.1 mrg c_common_get_alias_set (tree t) 3823 1.1 mrg { 3824 1.1 mrg /* For VLAs, use the alias set of the element type rather than the 3825 1.1 mrg default of alias set 0 for types compared structurally. */ 3826 1.1 mrg if (TYPE_P (t) && TYPE_STRUCTURAL_EQUALITY_P (t)) 3827 1.1 mrg { 3828 1.1 mrg if (TREE_CODE (t) == ARRAY_TYPE) 3829 1.1 mrg return get_alias_set (TREE_TYPE (t)); 3830 1.1 mrg return -1; 3831 1.1 mrg } 3832 1.1 mrg 3833 1.1 mrg /* That's all the expressions we handle specially. */ 3834 1.1 mrg if (!TYPE_P (t)) 3835 1.1 mrg return -1; 3836 1.1 mrg 3837 1.1 mrg /* Unlike char, char8_t doesn't alias. */ 3838 1.1 mrg if (flag_char8_t && t == char8_type_node) 3839 1.1 mrg return -1; 3840 1.1 mrg 3841 1.1 mrg /* The C standard guarantees that any object may be accessed via an 3842 1.1 mrg lvalue that has narrow character type (except char8_t). */ 3843 1.1 mrg if (t == char_type_node 3844 1.1 mrg || t == signed_char_type_node 3845 1.1 mrg || t == unsigned_char_type_node) 3846 1.1 mrg return 0; 3847 1.1 mrg 3848 1.1 mrg /* The C standard specifically allows aliasing between signed and 3849 1.1 mrg unsigned variants of the same type. We treat the signed 3850 1.1 mrg variant as canonical. */ 3851 1.1 mrg if (TREE_CODE (t) == INTEGER_TYPE && TYPE_UNSIGNED (t)) 3852 1.1 mrg { 3853 1.1 mrg tree t1 = c_common_signed_type (t); 3854 1.1 mrg 3855 1.1 mrg /* t1 == t can happen for boolean nodes which are always unsigned. */ 3856 1.1 mrg if (t1 != t) 3857 1.1 mrg return get_alias_set (t1); 3858 1.1 mrg } 3859 1.1 mrg 3860 1.1 mrg return -1; 3861 1.1 mrg } 3862 1.1 mrg 3863 1.1 mrg /* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where 3865 1.1 mrg the IS_SIZEOF parameter indicates which operator is being applied. 3866 1.1 mrg The COMPLAIN flag controls whether we should diagnose possibly 3867 1.1 mrg ill-formed constructs or not. LOC is the location of the SIZEOF or 3868 1.1 mrg TYPEOF operator. If MIN_ALIGNOF, the least alignment required for 3869 1.1 mrg a type in any context should be returned, rather than the normal 3870 1.1 mrg alignment for that type. */ 3871 1.1 mrg 3872 1.1 mrg tree 3873 1.1 mrg c_sizeof_or_alignof_type (location_t loc, 3874 1.1 mrg tree type, bool is_sizeof, bool min_alignof, 3875 1.1 mrg int complain) 3876 1.1 mrg { 3877 1.1 mrg const char *op_name; 3878 1.1 mrg tree value = NULL; 3879 1.1 mrg enum tree_code type_code = TREE_CODE (type); 3880 1.1 mrg 3881 1.1 mrg op_name = is_sizeof ? "sizeof" : "__alignof__"; 3882 1.1 mrg 3883 1.1 mrg if (type_code == FUNCTION_TYPE) 3884 1.1 mrg { 3885 1.1 mrg if (is_sizeof) 3886 1.1 mrg { 3887 1.1 mrg if (complain && warn_pointer_arith) 3888 1.1 mrg pedwarn (loc, OPT_Wpointer_arith, 3889 1.1 mrg "invalid application of %<sizeof%> to a function type"); 3890 1.1 mrg else if (!complain) 3891 1.1 mrg return error_mark_node; 3892 1.1 mrg value = size_one_node; 3893 1.1 mrg } 3894 1.1 mrg else 3895 1.1 mrg { 3896 1.1 mrg if (complain) 3897 1.1 mrg { 3898 1.1 mrg if (c_dialect_cxx ()) 3899 1.1 mrg pedwarn (loc, OPT_Wpedantic, "ISO C++ does not permit " 3900 1.1 mrg "%<alignof%> applied to a function type"); 3901 1.1 mrg else 3902 1.1 mrg pedwarn (loc, OPT_Wpedantic, "ISO C does not permit " 3903 1.1 mrg "%<_Alignof%> applied to a function type"); 3904 1.1 mrg } 3905 1.1 mrg value = size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT); 3906 1.1 mrg } 3907 1.1 mrg } 3908 1.1 mrg else if (type_code == VOID_TYPE || type_code == ERROR_MARK) 3909 1.1 mrg { 3910 1.1 mrg if (type_code == VOID_TYPE 3911 1.1 mrg && complain && warn_pointer_arith) 3912 1.1 mrg pedwarn (loc, OPT_Wpointer_arith, 3913 1.1 mrg "invalid application of %qs to a void type", op_name); 3914 1.1 mrg else if (!complain) 3915 1.1 mrg return error_mark_node; 3916 1.1 mrg value = size_one_node; 3917 1.1 mrg } 3918 1.1 mrg else if (!COMPLETE_TYPE_P (type) 3919 1.1 mrg && (!c_dialect_cxx () || is_sizeof || type_code != ARRAY_TYPE)) 3920 1.1 mrg { 3921 1.1 mrg if (complain) 3922 1.1 mrg error_at (loc, "invalid application of %qs to incomplete type %qT", 3923 1.1 mrg op_name, type); 3924 1.1 mrg return error_mark_node; 3925 1.1 mrg } 3926 1.1 mrg else if (c_dialect_cxx () && type_code == ARRAY_TYPE 3927 1.1 mrg && !COMPLETE_TYPE_P (TREE_TYPE (type))) 3928 1.1 mrg { 3929 1.1 mrg if (complain) 3930 1.1 mrg error_at (loc, "invalid application of %qs to array type %qT of " 3931 1.1 mrg "incomplete element type", op_name, type); 3932 1.1 mrg return error_mark_node; 3933 1.1 mrg } 3934 1.1 mrg else if (!verify_type_context (loc, is_sizeof ? TCTX_SIZEOF : TCTX_ALIGNOF, 3935 1.1 mrg type, !complain)) 3936 1.1 mrg { 3937 1.1 mrg if (!complain) 3938 1.1 mrg return error_mark_node; 3939 1.1 mrg value = size_one_node; 3940 1.1 mrg } 3941 1.1 mrg else 3942 1.1 mrg { 3943 1.1 mrg if (is_sizeof) 3944 1.1 mrg /* Convert in case a char is more than one unit. */ 3945 1.1 mrg value = size_binop_loc (loc, CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type), 3946 1.1 mrg size_int (TYPE_PRECISION (char_type_node) 3947 1.1 mrg / BITS_PER_UNIT)); 3948 1.1 mrg else if (min_alignof) 3949 1.1 mrg value = size_int (min_align_of_type (type)); 3950 1.1 mrg else 3951 1.1 mrg value = size_int (TYPE_ALIGN_UNIT (type)); 3952 1.1 mrg } 3953 1.1 mrg 3954 1.1 mrg /* VALUE will have the middle-end integer type sizetype. 3955 1.1 mrg However, we should really return a value of type `size_t', 3956 1.1 mrg which is just a typedef for an ordinary integer type. */ 3957 1.1 mrg value = fold_convert_loc (loc, size_type_node, value); 3958 1.1 mrg 3959 1.1 mrg return value; 3960 1.1 mrg } 3961 1.1 mrg 3962 1.1 mrg /* Implement the __alignof keyword: Return the minimum required 3963 1.1 mrg alignment of EXPR, measured in bytes. For VAR_DECLs, 3964 1.1 mrg FUNCTION_DECLs and FIELD_DECLs return DECL_ALIGN (which can be set 3965 1.1 mrg from an "aligned" __attribute__ specification). LOC is the 3966 1.1 mrg location of the ALIGNOF operator. */ 3967 1.1 mrg 3968 1.1 mrg tree 3969 1.1 mrg c_alignof_expr (location_t loc, tree expr) 3970 1.1 mrg { 3971 1.1 mrg tree t; 3972 1.1 mrg 3973 1.1 mrg if (!verify_type_context (loc, TCTX_ALIGNOF, TREE_TYPE (expr))) 3974 1.1 mrg t = size_one_node; 3975 1.1 mrg 3976 1.1 mrg else if (VAR_OR_FUNCTION_DECL_P (expr)) 3977 1.1 mrg t = size_int (DECL_ALIGN_UNIT (expr)); 3978 1.1 mrg 3979 1.1 mrg else if (TREE_CODE (expr) == COMPONENT_REF 3980 1.1 mrg && DECL_C_BIT_FIELD (TREE_OPERAND (expr, 1))) 3981 1.1 mrg { 3982 1.1 mrg error_at (loc, "%<__alignof%> applied to a bit-field"); 3983 1.1 mrg t = size_one_node; 3984 1.1 mrg } 3985 1.1 mrg else if (TREE_CODE (expr) == COMPONENT_REF 3986 1.1 mrg && TREE_CODE (TREE_OPERAND (expr, 1)) == FIELD_DECL) 3987 1.1 mrg t = size_int (DECL_ALIGN_UNIT (TREE_OPERAND (expr, 1))); 3988 1.1 mrg 3989 1.1 mrg else if (INDIRECT_REF_P (expr)) 3990 1.1 mrg { 3991 1.1 mrg tree t = TREE_OPERAND (expr, 0); 3992 1.1 mrg tree best = t; 3993 1.1 mrg int bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t))); 3994 1.1 mrg 3995 1.1 mrg while (CONVERT_EXPR_P (t) 3996 1.1 mrg && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE) 3997 1.1 mrg { 3998 1.1 mrg int thisalign; 3999 1.1 mrg 4000 1.1 mrg t = TREE_OPERAND (t, 0); 4001 1.1 mrg thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t))); 4002 1.1 mrg if (thisalign > bestalign) 4003 1.1 mrg best = t, bestalign = thisalign; 4004 1.1 mrg } 4005 1.1 mrg return c_alignof (loc, TREE_TYPE (TREE_TYPE (best))); 4006 1.1 mrg } 4007 1.1 mrg else 4008 1.1 mrg return c_alignof (loc, TREE_TYPE (expr)); 4009 1.1 mrg 4010 1.1 mrg return fold_convert_loc (loc, size_type_node, t); 4011 1.1 mrg } 4012 1.1 mrg 4013 1.1 mrg /* Handle C and C++ default attributes. */ 4015 1.1 mrg 4016 1.1 mrg enum built_in_attribute 4017 1.1 mrg { 4018 1.1 mrg #define DEF_ATTR_NULL_TREE(ENUM) ENUM, 4019 1.1 mrg #define DEF_ATTR_INT(ENUM, VALUE) ENUM, 4020 1.1 mrg #define DEF_ATTR_STRING(ENUM, VALUE) ENUM, 4021 1.1 mrg #define DEF_ATTR_IDENT(ENUM, STRING) ENUM, 4022 1.1 mrg #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM, 4023 1.1 mrg #include "builtin-attrs.def" 4024 1.1 mrg #undef DEF_ATTR_NULL_TREE 4025 1.1 mrg #undef DEF_ATTR_INT 4026 1.1 mrg #undef DEF_ATTR_STRING 4027 1.1 mrg #undef DEF_ATTR_IDENT 4028 1.1 mrg #undef DEF_ATTR_TREE_LIST 4029 1.1 mrg ATTR_LAST 4030 1.1 mrg }; 4031 1.1 mrg 4032 1.1 mrg static GTY(()) tree built_in_attributes[(int) ATTR_LAST]; 4033 1.1 mrg 4034 1.1 mrg static void c_init_attributes (void); 4035 1.1 mrg 4036 1.1 mrg enum c_builtin_type 4037 1.1 mrg { 4038 1.1 mrg #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME, 4039 1.1 mrg #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME, 4040 1.1 mrg #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME, 4041 1.1 mrg #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME, 4042 1.1 mrg #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME, 4043 1.1 mrg #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME, 4044 1.1 mrg #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME, 4045 1.1 mrg #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ 4046 1.1 mrg ARG6) NAME, 4047 1.1 mrg #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ 4048 1.1 mrg ARG6, ARG7) NAME, 4049 1.1 mrg #define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ 4050 1.1 mrg ARG6, ARG7, ARG8) NAME, 4051 1.1 mrg #define DEF_FUNCTION_TYPE_9(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ 4052 1.1 mrg ARG6, ARG7, ARG8, ARG9) NAME, 4053 1.1 mrg #define DEF_FUNCTION_TYPE_10(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ 4054 1.1 mrg ARG6, ARG7, ARG8, ARG9, ARG10) NAME, 4055 1.1 mrg #define DEF_FUNCTION_TYPE_11(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ 4056 1.1 mrg ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) NAME, 4057 1.1 mrg #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME, 4058 1.1 mrg #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME, 4059 1.1 mrg #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME, 4060 1.1 mrg #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME, 4061 1.1 mrg #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME, 4062 1.1 mrg #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \ 4063 1.1 mrg NAME, 4064 1.1 mrg #define DEF_FUNCTION_TYPE_VAR_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ 4065 1.1 mrg ARG6) NAME, 4066 1.1 mrg #define DEF_FUNCTION_TYPE_VAR_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ 4067 1.1 mrg ARG6, ARG7) NAME, 4068 1.1 mrg #define DEF_POINTER_TYPE(NAME, TYPE) NAME, 4069 1.1 mrg #include "builtin-types.def" 4070 1.1 mrg #undef DEF_PRIMITIVE_TYPE 4071 1.1 mrg #undef DEF_FUNCTION_TYPE_0 4072 1.1 mrg #undef DEF_FUNCTION_TYPE_1 4073 1.1 mrg #undef DEF_FUNCTION_TYPE_2 4074 1.1 mrg #undef DEF_FUNCTION_TYPE_3 4075 1.1 mrg #undef DEF_FUNCTION_TYPE_4 4076 1.1 mrg #undef DEF_FUNCTION_TYPE_5 4077 1.1 mrg #undef DEF_FUNCTION_TYPE_6 4078 1.1 mrg #undef DEF_FUNCTION_TYPE_7 4079 1.1 mrg #undef DEF_FUNCTION_TYPE_8 4080 1.1 mrg #undef DEF_FUNCTION_TYPE_9 4081 1.1 mrg #undef DEF_FUNCTION_TYPE_10 4082 1.1 mrg #undef DEF_FUNCTION_TYPE_11 4083 1.1 mrg #undef DEF_FUNCTION_TYPE_VAR_0 4084 1.1 mrg #undef DEF_FUNCTION_TYPE_VAR_1 4085 1.1 mrg #undef DEF_FUNCTION_TYPE_VAR_2 4086 1.1 mrg #undef DEF_FUNCTION_TYPE_VAR_3 4087 1.1 mrg #undef DEF_FUNCTION_TYPE_VAR_4 4088 1.1 mrg #undef DEF_FUNCTION_TYPE_VAR_5 4089 1.1 mrg #undef DEF_FUNCTION_TYPE_VAR_6 4090 1.1 mrg #undef DEF_FUNCTION_TYPE_VAR_7 4091 1.1 mrg #undef DEF_POINTER_TYPE 4092 1.1 mrg BT_LAST 4093 1.1 mrg }; 4094 1.1 mrg 4095 1.1 mrg typedef enum c_builtin_type builtin_type; 4096 1.1 mrg 4097 1.1 mrg /* A temporary array for c_common_nodes_and_builtins. Used in 4098 1.1 mrg communication with def_fn_type. */ 4099 1.1 mrg static tree builtin_types[(int) BT_LAST + 1]; 4100 1.1 mrg 4101 1.1 mrg /* A helper function for c_common_nodes_and_builtins. Build function type 4102 1.1 mrg for DEF with return type RET and N arguments. If VAR is true, then the 4103 1.1 mrg function should be variadic after those N arguments. 4104 1.1 mrg 4105 1.1 mrg Takes special care not to ICE if any of the types involved are 4106 1.1 mrg error_mark_node, which indicates that said type is not in fact available 4107 1.1 mrg (see builtin_type_for_size). In which case the function type as a whole 4108 1.1 mrg should be error_mark_node. */ 4109 1.1 mrg 4110 1.1 mrg static void 4111 1.1 mrg def_fn_type (builtin_type def, builtin_type ret, bool var, int n, ...) 4112 1.1 mrg { 4113 1.1 mrg tree t; 4114 1.1 mrg tree *args = XALLOCAVEC (tree, n); 4115 1.1 mrg va_list list; 4116 1.1 mrg int i; 4117 1.1 mrg 4118 1.1 mrg va_start (list, n); 4119 1.1 mrg for (i = 0; i < n; ++i) 4120 1.1 mrg { 4121 1.1 mrg builtin_type a = (builtin_type) va_arg (list, int); 4122 1.1 mrg t = builtin_types[a]; 4123 1.1 mrg if (t == error_mark_node) 4124 1.1 mrg goto egress; 4125 1.1 mrg args[i] = t; 4126 1.1 mrg } 4127 1.1 mrg 4128 1.1 mrg t = builtin_types[ret]; 4129 1.1 mrg if (t == error_mark_node) 4130 1.1 mrg goto egress; 4131 1.1 mrg if (var) 4132 1.1 mrg t = build_varargs_function_type_array (t, n, args); 4133 1.1 mrg else 4134 1.1 mrg t = build_function_type_array (t, n, args); 4135 1.1 mrg 4136 1.1 mrg egress: 4137 1.1 mrg builtin_types[def] = t; 4138 1.1 mrg va_end (list); 4139 1.1 mrg } 4140 1.1 mrg 4141 1.1 mrg /* Build builtin functions common to both C and C++ language 4142 1.1 mrg frontends. */ 4143 1.1 mrg 4144 1.1 mrg static void 4145 1.1 mrg c_define_builtins (tree va_list_ref_type_node, tree va_list_arg_type_node) 4146 1.1 mrg { 4147 1.1 mrg #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \ 4148 1.1 mrg builtin_types[ENUM] = VALUE; 4149 1.1 mrg #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \ 4150 1.1 mrg def_fn_type (ENUM, RETURN, 0, 0); 4151 1.1 mrg #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \ 4152 1.1 mrg def_fn_type (ENUM, RETURN, 0, 1, ARG1); 4153 1.1 mrg #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \ 4154 1.1 mrg def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2); 4155 1.1 mrg #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \ 4156 1.1 mrg def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3); 4157 1.1 mrg #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \ 4158 1.1 mrg def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4); 4159 1.1 mrg #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \ 4160 1.1 mrg def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5); 4161 1.1 mrg #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ 4162 1.1 mrg ARG6) \ 4163 1.1 mrg def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6); 4164 1.1 mrg #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ 4165 1.1 mrg ARG6, ARG7) \ 4166 1.1 mrg def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7); 4167 1.1 mrg #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ 4168 1.1 mrg ARG6, ARG7, ARG8) \ 4169 1.1 mrg def_fn_type (ENUM, RETURN, 0, 8, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \ 4170 1.1 mrg ARG7, ARG8); 4171 1.1 mrg #define DEF_FUNCTION_TYPE_9(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ 4172 1.1 mrg ARG6, ARG7, ARG8, ARG9) \ 4173 1.1 mrg def_fn_type (ENUM, RETURN, 0, 9, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \ 4174 1.1 mrg ARG7, ARG8, ARG9); 4175 1.1 mrg #define DEF_FUNCTION_TYPE_10(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ 4176 1.1 mrg ARG6, ARG7, ARG8, ARG9, ARG10) \ 4177 1.1 mrg def_fn_type (ENUM, RETURN, 0, 10, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \ 4178 1.1 mrg ARG7, ARG8, ARG9, ARG10); 4179 1.1 mrg #define DEF_FUNCTION_TYPE_11(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ 4180 1.1 mrg ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) \ 4181 1.1 mrg def_fn_type (ENUM, RETURN, 0, 11, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \ 4182 1.1 mrg ARG7, ARG8, ARG9, ARG10, ARG11); 4183 1.1 mrg #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \ 4184 1.1 mrg def_fn_type (ENUM, RETURN, 1, 0); 4185 1.1 mrg #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \ 4186 1.1 mrg def_fn_type (ENUM, RETURN, 1, 1, ARG1); 4187 1.1 mrg #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \ 4188 1.1 mrg def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2); 4189 1.1 mrg #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \ 4190 1.1 mrg def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3); 4191 1.1 mrg #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \ 4192 1.1 mrg def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4); 4193 1.1 mrg #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \ 4194 1.1 mrg def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5); 4195 1.1 mrg #define DEF_FUNCTION_TYPE_VAR_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ 4196 1.1 mrg ARG6) \ 4197 1.1 mrg def_fn_type (ENUM, RETURN, 1, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6); 4198 1.1 mrg #define DEF_FUNCTION_TYPE_VAR_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ 4199 1.1 mrg ARG6, ARG7) \ 4200 1.1 mrg def_fn_type (ENUM, RETURN, 1, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7); 4201 1.1 mrg #define DEF_POINTER_TYPE(ENUM, TYPE) \ 4202 1.1 mrg builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]); 4203 1.1 mrg 4204 1.1 mrg #include "builtin-types.def" 4205 1.1 mrg 4206 1.1 mrg #undef DEF_PRIMITIVE_TYPE 4207 1.1 mrg #undef DEF_FUNCTION_TYPE_0 4208 1.1 mrg #undef DEF_FUNCTION_TYPE_1 4209 1.1 mrg #undef DEF_FUNCTION_TYPE_2 4210 1.1 mrg #undef DEF_FUNCTION_TYPE_3 4211 1.1 mrg #undef DEF_FUNCTION_TYPE_4 4212 1.1 mrg #undef DEF_FUNCTION_TYPE_5 4213 1.1 mrg #undef DEF_FUNCTION_TYPE_6 4214 1.1 mrg #undef DEF_FUNCTION_TYPE_7 4215 1.1 mrg #undef DEF_FUNCTION_TYPE_8 4216 1.1 mrg #undef DEF_FUNCTION_TYPE_9 4217 1.1 mrg #undef DEF_FUNCTION_TYPE_10 4218 1.1 mrg #undef DEF_FUNCTION_TYPE_11 4219 1.1 mrg #undef DEF_FUNCTION_TYPE_VAR_0 4220 1.1 mrg #undef DEF_FUNCTION_TYPE_VAR_1 4221 1.1 mrg #undef DEF_FUNCTION_TYPE_VAR_2 4222 1.1 mrg #undef DEF_FUNCTION_TYPE_VAR_3 4223 1.1 mrg #undef DEF_FUNCTION_TYPE_VAR_4 4224 1.1 mrg #undef DEF_FUNCTION_TYPE_VAR_5 4225 1.1 mrg #undef DEF_FUNCTION_TYPE_VAR_6 4226 1.1 mrg #undef DEF_FUNCTION_TYPE_VAR_7 4227 1.1 mrg #undef DEF_POINTER_TYPE 4228 1.1 mrg builtin_types[(int) BT_LAST] = NULL_TREE; 4229 1.1 mrg 4230 1.1 mrg c_init_attributes (); 4231 1.1 mrg 4232 1.1 mrg #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P, \ 4233 1.1 mrg NONANSI_P, ATTRS, IMPLICIT, COND) \ 4234 1.1 mrg if (NAME && COND) \ 4235 1.1 mrg def_builtin_1 (ENUM, NAME, CLASS, \ 4236 1.1 mrg builtin_types[(int) TYPE], \ 4237 1.1 mrg builtin_types[(int) LIBTYPE], \ 4238 1.1 mrg BOTH_P, FALLBACK_P, NONANSI_P, \ 4239 1.1 mrg built_in_attributes[(int) ATTRS], IMPLICIT); 4240 1.1 mrg #include "builtins.def" 4241 1.1 mrg 4242 1.1 mrg targetm.init_builtins (); 4243 1.1 mrg 4244 1.1 mrg build_common_builtin_nodes (); 4245 1.1 mrg } 4246 1.1 mrg 4247 1.1 mrg /* Like get_identifier, but avoid warnings about null arguments when 4248 1.1 mrg the argument may be NULL for targets where GCC lacks stdint.h type 4249 1.1 mrg information. */ 4250 1.1 mrg 4251 1.1 mrg static inline tree 4252 1.1 mrg c_get_ident (const char *id) 4253 1.1 mrg { 4254 1.1 mrg return get_identifier (id); 4255 1.1 mrg } 4256 1.1 mrg 4257 1.1 mrg /* Build tree nodes and builtin functions common to both C and C++ language 4258 1.1 mrg frontends. */ 4259 1.1 mrg 4260 1.1 mrg void 4261 1.1 mrg c_common_nodes_and_builtins (void) 4262 1.1 mrg { 4263 1.1 mrg int char8_type_size; 4264 1.1 mrg int char16_type_size; 4265 1.1 mrg int char32_type_size; 4266 1.1 mrg int wchar_type_size; 4267 1.1 mrg tree array_domain_type; 4268 1.1 mrg tree va_list_ref_type_node; 4269 1.1 mrg tree va_list_arg_type_node; 4270 1.1 mrg int i; 4271 1.1 mrg 4272 1.1 mrg build_common_tree_nodes (flag_signed_char); 4273 1.1 mrg 4274 1.1 mrg /* Define `int' and `char' first so that dbx will output them first. */ 4275 1.1 mrg record_builtin_type (RID_INT, NULL, integer_type_node); 4276 1.1 mrg record_builtin_type (RID_CHAR, "char", char_type_node); 4277 1.1 mrg 4278 1.1 mrg /* `signed' is the same as `int'. FIXME: the declarations of "signed", 4279 1.1 mrg "unsigned long", "long long unsigned" and "unsigned short" were in C++ 4280 1.1 mrg but not C. Are the conditionals here needed? */ 4281 1.1 mrg if (c_dialect_cxx ()) 4282 1.1 mrg record_builtin_type (RID_SIGNED, NULL, integer_type_node); 4283 1.1 mrg record_builtin_type (RID_LONG, "long int", long_integer_type_node); 4284 1.1 mrg record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node); 4285 1.1 mrg record_builtin_type (RID_MAX, "long unsigned int", 4286 1.1 mrg long_unsigned_type_node); 4287 1.1 mrg 4288 1.1 mrg for (i = 0; i < NUM_INT_N_ENTS; i ++) 4289 1.1 mrg { 4290 1.1 mrg char name[25]; 4291 1.1 mrg 4292 1.1 mrg sprintf (name, "__int%d", int_n_data[i].bitsize); 4293 1.1 mrg record_builtin_type ((enum rid)(RID_FIRST_INT_N + i), name, 4294 1.1 mrg int_n_trees[i].signed_type); 4295 1.1 mrg sprintf (name, "__int%d__", int_n_data[i].bitsize); 4296 1.1 mrg record_builtin_type ((enum rid)(RID_FIRST_INT_N + i), name, 4297 1.1 mrg int_n_trees[i].signed_type); 4298 1.1 mrg ridpointers[RID_FIRST_INT_N + i] 4299 1.1 mrg = DECL_NAME (TYPE_NAME (int_n_trees[i].signed_type)); 4300 1.1 mrg 4301 1.1 mrg sprintf (name, "__int%d unsigned", int_n_data[i].bitsize); 4302 1.1 mrg record_builtin_type (RID_MAX, name, int_n_trees[i].unsigned_type); 4303 1.1 mrg sprintf (name, "__int%d__ unsigned", int_n_data[i].bitsize); 4304 1.1 mrg record_builtin_type (RID_MAX, name, int_n_trees[i].unsigned_type); 4305 1.1 mrg } 4306 1.1 mrg 4307 1.1 mrg if (c_dialect_cxx ()) 4308 1.1 mrg record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node); 4309 1.1 mrg record_builtin_type (RID_MAX, "long long int", 4310 1.1 mrg long_long_integer_type_node); 4311 1.1 mrg record_builtin_type (RID_MAX, "long long unsigned int", 4312 1.1 mrg long_long_unsigned_type_node); 4313 1.1 mrg if (c_dialect_cxx ()) 4314 1.1 mrg record_builtin_type (RID_MAX, "long long unsigned", 4315 1.1 mrg long_long_unsigned_type_node); 4316 1.1 mrg record_builtin_type (RID_SHORT, "short int", short_integer_type_node); 4317 1.1 mrg record_builtin_type (RID_MAX, "short unsigned int", 4318 1.1 mrg short_unsigned_type_node); 4319 1.1 mrg if (c_dialect_cxx ()) 4320 1.1 mrg record_builtin_type (RID_MAX, "unsigned short", 4321 1.1 mrg short_unsigned_type_node); 4322 1.1 mrg 4323 1.1 mrg /* Define both `signed char' and `unsigned char'. */ 4324 1.1 mrg record_builtin_type (RID_MAX, "signed char", signed_char_type_node); 4325 1.1 mrg record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node); 4326 1.1 mrg 4327 1.1 mrg /* These are types that c_common_type_for_size and 4328 1.1 mrg c_common_type_for_mode use. */ 4329 1.1 mrg lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION, 4330 1.1 mrg TYPE_DECL, NULL_TREE, 4331 1.1 mrg intQI_type_node)); 4332 1.1 mrg lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION, 4333 1.1 mrg TYPE_DECL, NULL_TREE, 4334 1.1 mrg intHI_type_node)); 4335 1.1 mrg lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION, 4336 1.1 mrg TYPE_DECL, NULL_TREE, 4337 1.1 mrg intSI_type_node)); 4338 1.1 mrg lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION, 4339 1.1 mrg TYPE_DECL, NULL_TREE, 4340 1.1 mrg intDI_type_node)); 4341 1.1 mrg #if HOST_BITS_PER_WIDE_INT >= 64 4342 1.1 mrg /* Note that this is different than the __int128 type that's part of 4343 1.1 mrg the generic __intN support. */ 4344 1.1 mrg if (targetm.scalar_mode_supported_p (TImode)) 4345 1.1 mrg lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION, 4346 1.1 mrg TYPE_DECL, 4347 1.1 mrg get_identifier ("__int128_t"), 4348 1.1 mrg intTI_type_node)); 4349 1.1 mrg #endif 4350 1.1 mrg lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION, 4351 1.1 mrg TYPE_DECL, NULL_TREE, 4352 1.1 mrg unsigned_intQI_type_node)); 4353 1.1 mrg lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION, 4354 1.1 mrg TYPE_DECL, NULL_TREE, 4355 1.1 mrg unsigned_intHI_type_node)); 4356 1.1 mrg lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION, 4357 1.1 mrg TYPE_DECL, NULL_TREE, 4358 1.1 mrg unsigned_intSI_type_node)); 4359 1.1 mrg lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION, 4360 1.1 mrg TYPE_DECL, NULL_TREE, 4361 1.1 mrg unsigned_intDI_type_node)); 4362 1.1 mrg #if HOST_BITS_PER_WIDE_INT >= 64 4363 1.1 mrg if (targetm.scalar_mode_supported_p (TImode)) 4364 1.1 mrg lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION, 4365 1.1 mrg TYPE_DECL, 4366 1.1 mrg get_identifier ("__uint128_t"), 4367 1.1 mrg unsigned_intTI_type_node)); 4368 1.1 mrg #endif 4369 1.1 mrg 4370 1.1 mrg /* Create the widest literal types. */ 4371 1.1 mrg if (targetm.scalar_mode_supported_p (TImode)) 4372 1.1 mrg { 4373 1.1 mrg widest_integer_literal_type_node = intTI_type_node; 4374 1.1 mrg widest_unsigned_literal_type_node = unsigned_intTI_type_node; 4375 1.1 mrg } 4376 1.1 mrg else 4377 1.1 mrg { 4378 1.1 mrg widest_integer_literal_type_node = intDI_type_node; 4379 1.1 mrg widest_unsigned_literal_type_node = unsigned_intDI_type_node; 4380 1.1 mrg } 4381 1.1 mrg 4382 1.1 mrg signed_size_type_node = c_common_signed_type (size_type_node); 4383 1.1 mrg 4384 1.1 mrg pid_type_node = 4385 1.1 mrg TREE_TYPE (identifier_global_value (get_identifier (PID_TYPE))); 4386 1.1 mrg 4387 1.1 mrg record_builtin_type (RID_FLOAT, NULL, float_type_node); 4388 1.1 mrg record_builtin_type (RID_DOUBLE, NULL, double_type_node); 4389 1.1 mrg record_builtin_type (RID_MAX, "long double", long_double_type_node); 4390 1.1 mrg 4391 1.1 mrg if (!c_dialect_cxx ()) 4392 1.1 mrg for (i = 0; i < NUM_FLOATN_NX_TYPES; i++) 4393 1.1 mrg if (FLOATN_NX_TYPE_NODE (i) != NULL_TREE) 4394 1.1 mrg record_builtin_type ((enum rid) (RID_FLOATN_NX_FIRST + i), NULL, 4395 1.1 mrg FLOATN_NX_TYPE_NODE (i)); 4396 1.1 mrg 4397 1.1 mrg /* Only supported decimal floating point extension if the target 4398 1.1 mrg actually supports underlying modes. */ 4399 1.1 mrg if (targetm.scalar_mode_supported_p (SDmode) 4400 1.1 mrg && targetm.scalar_mode_supported_p (DDmode) 4401 1.1 mrg && targetm.scalar_mode_supported_p (TDmode)) 4402 1.1 mrg { 4403 1.1 mrg record_builtin_type (RID_DFLOAT32, NULL, dfloat32_type_node); 4404 1.1 mrg record_builtin_type (RID_DFLOAT64, NULL, dfloat64_type_node); 4405 1.1 mrg record_builtin_type (RID_DFLOAT128, NULL, dfloat128_type_node); 4406 1.1 mrg } 4407 1.1 mrg 4408 1.1 mrg if (targetm.fixed_point_supported_p ()) 4409 1.1 mrg { 4410 1.1 mrg record_builtin_type (RID_MAX, "short _Fract", short_fract_type_node); 4411 1.1 mrg record_builtin_type (RID_FRACT, NULL, fract_type_node); 4412 1.1 mrg record_builtin_type (RID_MAX, "long _Fract", long_fract_type_node); 4413 1.1 mrg record_builtin_type (RID_MAX, "long long _Fract", 4414 1.1 mrg long_long_fract_type_node); 4415 1.1 mrg record_builtin_type (RID_MAX, "unsigned short _Fract", 4416 1.1 mrg unsigned_short_fract_type_node); 4417 1.1 mrg record_builtin_type (RID_MAX, "unsigned _Fract", 4418 1.1 mrg unsigned_fract_type_node); 4419 1.1 mrg record_builtin_type (RID_MAX, "unsigned long _Fract", 4420 1.1 mrg unsigned_long_fract_type_node); 4421 1.1 mrg record_builtin_type (RID_MAX, "unsigned long long _Fract", 4422 1.1 mrg unsigned_long_long_fract_type_node); 4423 1.1 mrg record_builtin_type (RID_MAX, "_Sat short _Fract", 4424 1.1 mrg sat_short_fract_type_node); 4425 1.1 mrg record_builtin_type (RID_MAX, "_Sat _Fract", sat_fract_type_node); 4426 1.1 mrg record_builtin_type (RID_MAX, "_Sat long _Fract", 4427 1.1 mrg sat_long_fract_type_node); 4428 1.1 mrg record_builtin_type (RID_MAX, "_Sat long long _Fract", 4429 1.1 mrg sat_long_long_fract_type_node); 4430 1.1 mrg record_builtin_type (RID_MAX, "_Sat unsigned short _Fract", 4431 1.1 mrg sat_unsigned_short_fract_type_node); 4432 1.1 mrg record_builtin_type (RID_MAX, "_Sat unsigned _Fract", 4433 1.1 mrg sat_unsigned_fract_type_node); 4434 1.1 mrg record_builtin_type (RID_MAX, "_Sat unsigned long _Fract", 4435 1.1 mrg sat_unsigned_long_fract_type_node); 4436 1.1 mrg record_builtin_type (RID_MAX, "_Sat unsigned long long _Fract", 4437 1.1 mrg sat_unsigned_long_long_fract_type_node); 4438 1.1 mrg record_builtin_type (RID_MAX, "short _Accum", short_accum_type_node); 4439 1.1 mrg record_builtin_type (RID_ACCUM, NULL, accum_type_node); 4440 1.1 mrg record_builtin_type (RID_MAX, "long _Accum", long_accum_type_node); 4441 1.1 mrg record_builtin_type (RID_MAX, "long long _Accum", 4442 1.1 mrg long_long_accum_type_node); 4443 1.1 mrg record_builtin_type (RID_MAX, "unsigned short _Accum", 4444 1.1 mrg unsigned_short_accum_type_node); 4445 1.1 mrg record_builtin_type (RID_MAX, "unsigned _Accum", 4446 1.1 mrg unsigned_accum_type_node); 4447 1.1 mrg record_builtin_type (RID_MAX, "unsigned long _Accum", 4448 1.1 mrg unsigned_long_accum_type_node); 4449 1.1 mrg record_builtin_type (RID_MAX, "unsigned long long _Accum", 4450 1.1 mrg unsigned_long_long_accum_type_node); 4451 1.1 mrg record_builtin_type (RID_MAX, "_Sat short _Accum", 4452 1.1 mrg sat_short_accum_type_node); 4453 1.1 mrg record_builtin_type (RID_MAX, "_Sat _Accum", sat_accum_type_node); 4454 1.1 mrg record_builtin_type (RID_MAX, "_Sat long _Accum", 4455 1.1 mrg sat_long_accum_type_node); 4456 1.1 mrg record_builtin_type (RID_MAX, "_Sat long long _Accum", 4457 1.1 mrg sat_long_long_accum_type_node); 4458 1.1 mrg record_builtin_type (RID_MAX, "_Sat unsigned short _Accum", 4459 1.1 mrg sat_unsigned_short_accum_type_node); 4460 1.1 mrg record_builtin_type (RID_MAX, "_Sat unsigned _Accum", 4461 1.1 mrg sat_unsigned_accum_type_node); 4462 1.1 mrg record_builtin_type (RID_MAX, "_Sat unsigned long _Accum", 4463 1.1 mrg sat_unsigned_long_accum_type_node); 4464 1.1 mrg record_builtin_type (RID_MAX, "_Sat unsigned long long _Accum", 4465 1.1 mrg sat_unsigned_long_long_accum_type_node); 4466 1.1 mrg 4467 1.1 mrg } 4468 1.1 mrg 4469 1.1 mrg lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION, 4470 1.1 mrg TYPE_DECL, 4471 1.1 mrg get_identifier ("complex int"), 4472 1.1 mrg complex_integer_type_node)); 4473 1.1 mrg lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION, 4474 1.1 mrg TYPE_DECL, 4475 1.1 mrg get_identifier ("complex float"), 4476 1.1 mrg complex_float_type_node)); 4477 1.1 mrg lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION, 4478 1.1 mrg TYPE_DECL, 4479 1.1 mrg get_identifier ("complex double"), 4480 1.1 mrg complex_double_type_node)); 4481 1.1 mrg lang_hooks.decls.pushdecl 4482 1.1 mrg (build_decl (UNKNOWN_LOCATION, 4483 1.1 mrg TYPE_DECL, get_identifier ("complex long double"), 4484 1.1 mrg complex_long_double_type_node)); 4485 1.1 mrg 4486 1.1 mrg if (!c_dialect_cxx ()) 4487 1.1 mrg for (i = 0; i < NUM_FLOATN_NX_TYPES; i++) 4488 1.1 mrg if (COMPLEX_FLOATN_NX_TYPE_NODE (i) != NULL_TREE) 4489 1.1 mrg { 4490 1.1 mrg char buf[30]; 4491 1.1 mrg sprintf (buf, "complex _Float%d%s", floatn_nx_types[i].n, 4492 1.1 mrg floatn_nx_types[i].extended ? "x" : ""); 4493 1.1 mrg lang_hooks.decls.pushdecl 4494 1.1 mrg (build_decl (UNKNOWN_LOCATION, 4495 1.1 mrg TYPE_DECL, 4496 1.1 mrg get_identifier (buf), 4497 1.1 mrg COMPLEX_FLOATN_NX_TYPE_NODE (i))); 4498 1.1 mrg } 4499 1.1 mrg 4500 1.1 mrg /* Make fileptr_type_node a distinct void * type until 4501 1.1 mrg FILE type is defined. Likewise for const struct tm*. */ 4502 1.1 mrg for (unsigned i = 0; 4503 1.1 mrg i < sizeof (builtin_structptr_types) / sizeof (builtin_structptr_type); 4504 1.1 mrg ++i) 4505 1.1 mrg builtin_structptr_types[i].node 4506 1.1 mrg = build_variant_type_copy (builtin_structptr_types[i].base); 4507 1.1 mrg 4508 1.1 mrg record_builtin_type (RID_VOID, NULL, void_type_node); 4509 1.1 mrg 4510 1.1 mrg /* Set the TYPE_NAME for any variants that were built before 4511 1.1 mrg record_builtin_type gave names to the built-in types. */ 4512 1.1 mrg { 4513 1.1 mrg tree void_name = TYPE_NAME (void_type_node); 4514 1.1 mrg TYPE_NAME (void_type_node) = NULL_TREE; 4515 1.1 mrg TYPE_NAME (build_qualified_type (void_type_node, TYPE_QUAL_CONST)) 4516 1.1 mrg = void_name; 4517 1.1 mrg TYPE_NAME (void_type_node) = void_name; 4518 1.1 mrg } 4519 1.1 mrg 4520 1.1 mrg void_list_node = build_void_list_node (); 4521 1.1 mrg 4522 1.1 mrg /* Make a type to be the domain of a few array types 4523 1.1 mrg whose domains don't really matter. 4524 1.1 mrg 200 is small enough that it always fits in size_t 4525 1.1 mrg and large enough that it can hold most function names for the 4526 1.1 mrg initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */ 4527 1.1 mrg array_domain_type = build_index_type (size_int (200)); 4528 1.1 mrg 4529 1.1 mrg /* Make a type for arrays of characters. 4530 1.1 mrg With luck nothing will ever really depend on the length of this 4531 1.1 mrg array type. */ 4532 1.1 mrg char_array_type_node 4533 1.1 mrg = build_array_type (char_type_node, array_domain_type); 4534 1.1 mrg 4535 1.1 mrg string_type_node = build_pointer_type (char_type_node); 4536 1.1 mrg const_string_type_node 4537 1.1 mrg = build_pointer_type (build_qualified_type 4538 1.1 mrg (char_type_node, TYPE_QUAL_CONST)); 4539 1.1 mrg 4540 1.1 mrg /* This is special for C++ so functions can be overloaded. */ 4541 1.1 mrg wchar_type_node = get_identifier (MODIFIED_WCHAR_TYPE); 4542 1.1 mrg wchar_type_node = TREE_TYPE (identifier_global_value (wchar_type_node)); 4543 1.1 mrg wchar_type_size = TYPE_PRECISION (wchar_type_node); 4544 1.1 mrg underlying_wchar_type_node = wchar_type_node; 4545 1.1 mrg if (c_dialect_cxx ()) 4546 1.1 mrg { 4547 1.1 mrg if (TYPE_UNSIGNED (wchar_type_node)) 4548 1.1 mrg wchar_type_node = make_unsigned_type (wchar_type_size); 4549 1.1 mrg else 4550 1.1 mrg wchar_type_node = make_signed_type (wchar_type_size); 4551 1.1 mrg record_builtin_type (RID_WCHAR, "wchar_t", wchar_type_node); 4552 1.1 mrg } 4553 1.1 mrg 4554 1.1 mrg /* This is for wide string constants. */ 4555 1.1 mrg wchar_array_type_node 4556 1.1 mrg = build_array_type (wchar_type_node, array_domain_type); 4557 1.1 mrg 4558 1.1 mrg /* Define 'char8_t'. */ 4559 1.1 mrg char8_type_node = get_identifier (CHAR8_TYPE); 4560 1.1 mrg char8_type_node = TREE_TYPE (identifier_global_value (char8_type_node)); 4561 1.1 mrg char8_type_size = TYPE_PRECISION (char8_type_node); 4562 1.1 mrg if (c_dialect_cxx ()) 4563 1.1 mrg { 4564 1.1 mrg char8_type_node = make_unsigned_type (char8_type_size); 4565 1.1 mrg 4566 1.1 mrg if (flag_char8_t) 4567 1.1 mrg record_builtin_type (RID_CHAR8, "char8_t", char8_type_node); 4568 1.1 mrg } 4569 1.1 mrg 4570 1.1 mrg /* This is for UTF-8 string constants. */ 4571 1.1 mrg char8_array_type_node 4572 1.1 mrg = build_array_type (char8_type_node, array_domain_type); 4573 1.1 mrg 4574 1.1 mrg /* Define 'char16_t'. */ 4575 1.1 mrg char16_type_node = get_identifier (CHAR16_TYPE); 4576 1.1 mrg char16_type_node = TREE_TYPE (identifier_global_value (char16_type_node)); 4577 1.1 mrg char16_type_size = TYPE_PRECISION (char16_type_node); 4578 1.1 mrg if (c_dialect_cxx ()) 4579 1.1 mrg { 4580 1.1 mrg char16_type_node = make_unsigned_type (char16_type_size); 4581 1.1 mrg 4582 1.1 mrg if (cxx_dialect >= cxx11) 4583 1.1 mrg record_builtin_type (RID_CHAR16, "char16_t", char16_type_node); 4584 1.1 mrg } 4585 1.1 mrg 4586 1.1 mrg /* This is for UTF-16 string constants. */ 4587 1.1 mrg char16_array_type_node 4588 1.1 mrg = build_array_type (char16_type_node, array_domain_type); 4589 1.1 mrg 4590 1.1 mrg /* Define 'char32_t'. */ 4591 1.1 mrg char32_type_node = get_identifier (CHAR32_TYPE); 4592 1.1 mrg char32_type_node = TREE_TYPE (identifier_global_value (char32_type_node)); 4593 1.1 mrg char32_type_size = TYPE_PRECISION (char32_type_node); 4594 1.1 mrg if (c_dialect_cxx ()) 4595 1.1 mrg { 4596 1.1 mrg char32_type_node = make_unsigned_type (char32_type_size); 4597 1.1 mrg 4598 1.1 mrg if (cxx_dialect >= cxx11) 4599 1.1 mrg record_builtin_type (RID_CHAR32, "char32_t", char32_type_node); 4600 1.1 mrg } 4601 1.1 mrg 4602 1.1 mrg /* This is for UTF-32 string constants. */ 4603 1.1 mrg char32_array_type_node 4604 1.1 mrg = build_array_type (char32_type_node, array_domain_type); 4605 1.1 mrg 4606 1.1 mrg wint_type_node = 4607 1.1 mrg TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE))); 4608 1.1 mrg 4609 1.1 mrg intmax_type_node = 4610 1.1 mrg TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE))); 4611 1.1 mrg uintmax_type_node = 4612 1.1 mrg TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE))); 4613 1.1 mrg 4614 1.1 mrg if (SIG_ATOMIC_TYPE) 4615 1.1 mrg sig_atomic_type_node = 4616 1.1 mrg TREE_TYPE (identifier_global_value (c_get_ident (SIG_ATOMIC_TYPE))); 4617 1.1 mrg if (INT8_TYPE) 4618 1.1 mrg int8_type_node = 4619 1.1 mrg TREE_TYPE (identifier_global_value (c_get_ident (INT8_TYPE))); 4620 1.1 mrg if (INT16_TYPE) 4621 1.1 mrg int16_type_node = 4622 1.1 mrg TREE_TYPE (identifier_global_value (c_get_ident (INT16_TYPE))); 4623 1.1 mrg if (INT32_TYPE) 4624 1.1 mrg int32_type_node = 4625 1.1 mrg TREE_TYPE (identifier_global_value (c_get_ident (INT32_TYPE))); 4626 1.1 mrg if (INT64_TYPE) 4627 1.1 mrg int64_type_node = 4628 1.1 mrg TREE_TYPE (identifier_global_value (c_get_ident (INT64_TYPE))); 4629 1.1 mrg if (UINT8_TYPE) 4630 1.1 mrg uint8_type_node = 4631 1.1 mrg TREE_TYPE (identifier_global_value (c_get_ident (UINT8_TYPE))); 4632 1.1 mrg if (UINT16_TYPE) 4633 1.1 mrg c_uint16_type_node = uint16_type_node = 4634 1.1 mrg TREE_TYPE (identifier_global_value (c_get_ident (UINT16_TYPE))); 4635 1.1 mrg if (UINT32_TYPE) 4636 1.1 mrg c_uint32_type_node = uint32_type_node = 4637 1.1 mrg TREE_TYPE (identifier_global_value (c_get_ident (UINT32_TYPE))); 4638 1.1 mrg if (UINT64_TYPE) 4639 1.1 mrg c_uint64_type_node = uint64_type_node = 4640 1.1 mrg TREE_TYPE (identifier_global_value (c_get_ident (UINT64_TYPE))); 4641 1.1 mrg if (INT_LEAST8_TYPE) 4642 1.1 mrg int_least8_type_node = 4643 1.1 mrg TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST8_TYPE))); 4644 1.1 mrg if (INT_LEAST16_TYPE) 4645 1.1 mrg int_least16_type_node = 4646 1.1 mrg TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST16_TYPE))); 4647 1.1 mrg if (INT_LEAST32_TYPE) 4648 1.1 mrg int_least32_type_node = 4649 1.1 mrg TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST32_TYPE))); 4650 1.1 mrg if (INT_LEAST64_TYPE) 4651 1.1 mrg int_least64_type_node = 4652 1.1 mrg TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST64_TYPE))); 4653 1.1 mrg if (UINT_LEAST8_TYPE) 4654 1.1 mrg uint_least8_type_node = 4655 1.1 mrg TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST8_TYPE))); 4656 1.1 mrg if (UINT_LEAST16_TYPE) 4657 1.1 mrg uint_least16_type_node = 4658 1.1 mrg TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST16_TYPE))); 4659 1.1 mrg if (UINT_LEAST32_TYPE) 4660 1.1 mrg uint_least32_type_node = 4661 1.1 mrg TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST32_TYPE))); 4662 1.1 mrg if (UINT_LEAST64_TYPE) 4663 1.1 mrg uint_least64_type_node = 4664 1.1 mrg TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST64_TYPE))); 4665 1.1 mrg if (INT_FAST8_TYPE) 4666 1.1 mrg int_fast8_type_node = 4667 1.1 mrg TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST8_TYPE))); 4668 1.1 mrg if (INT_FAST16_TYPE) 4669 1.1 mrg int_fast16_type_node = 4670 1.1 mrg TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST16_TYPE))); 4671 1.1 mrg if (INT_FAST32_TYPE) 4672 1.1 mrg int_fast32_type_node = 4673 1.1 mrg TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST32_TYPE))); 4674 1.1 mrg if (INT_FAST64_TYPE) 4675 1.1 mrg int_fast64_type_node = 4676 1.1 mrg TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST64_TYPE))); 4677 1.1 mrg if (UINT_FAST8_TYPE) 4678 1.1 mrg uint_fast8_type_node = 4679 1.1 mrg TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST8_TYPE))); 4680 1.1 mrg if (UINT_FAST16_TYPE) 4681 1.1 mrg uint_fast16_type_node = 4682 1.1 mrg TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST16_TYPE))); 4683 1.1 mrg if (UINT_FAST32_TYPE) 4684 1.1 mrg uint_fast32_type_node = 4685 1.1 mrg TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST32_TYPE))); 4686 1.1 mrg if (UINT_FAST64_TYPE) 4687 1.1 mrg uint_fast64_type_node = 4688 1.1 mrg TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST64_TYPE))); 4689 1.1 mrg if (INTPTR_TYPE) 4690 1.1 mrg intptr_type_node = 4691 1.1 mrg TREE_TYPE (identifier_global_value (c_get_ident (INTPTR_TYPE))); 4692 1.1 mrg if (UINTPTR_TYPE) 4693 1.1 mrg uintptr_type_node = 4694 1.1 mrg TREE_TYPE (identifier_global_value (c_get_ident (UINTPTR_TYPE))); 4695 1.1 mrg 4696 1.1 mrg default_function_type 4697 1.1 mrg = build_varargs_function_type_list (integer_type_node, NULL_TREE); 4698 1.1 mrg unsigned_ptrdiff_type_node = c_common_unsigned_type (ptrdiff_type_node); 4699 1.1 mrg 4700 1.1 mrg lang_hooks.decls.pushdecl 4701 1.1 mrg (build_decl (UNKNOWN_LOCATION, 4702 1.1 mrg TYPE_DECL, get_identifier ("__builtin_va_list"), 4703 1.1 mrg va_list_type_node)); 4704 1.1 mrg if (targetm.enum_va_list_p) 4705 1.1 mrg { 4706 1.1 mrg int l; 4707 1.1 mrg const char *pname; 4708 1.1 mrg tree ptype; 4709 1.1 mrg 4710 1.1 mrg for (l = 0; targetm.enum_va_list_p (l, &pname, &ptype); ++l) 4711 1.1 mrg { 4712 1.1 mrg lang_hooks.decls.pushdecl 4713 1.1 mrg (build_decl (UNKNOWN_LOCATION, 4714 1.1 mrg TYPE_DECL, get_identifier (pname), 4715 1.1 mrg ptype)); 4716 1.1 mrg 4717 1.1 mrg } 4718 1.1 mrg } 4719 1.1 mrg 4720 1.1 mrg if (TREE_CODE (va_list_type_node) == ARRAY_TYPE) 4721 1.1 mrg { 4722 1.1 mrg va_list_arg_type_node = va_list_ref_type_node = 4723 1.1 mrg build_pointer_type (TREE_TYPE (va_list_type_node)); 4724 1.1 mrg } 4725 1.1 mrg else 4726 1.1 mrg { 4727 1.1 mrg va_list_arg_type_node = va_list_type_node; 4728 1.1 mrg va_list_ref_type_node = build_reference_type (va_list_type_node); 4729 1.1 mrg } 4730 1.1 mrg 4731 1.1 mrg c_define_builtins (va_list_ref_type_node, va_list_arg_type_node); 4732 1.1 mrg 4733 1.1 mrg main_identifier_node = get_identifier ("main"); 4734 1.1 mrg 4735 1.1 mrg /* Create the built-in __null node. It is important that this is 4736 1.1 mrg not shared. */ 4737 1.1 mrg null_node = make_int_cst (1, 1); 4738 1.1 mrg TREE_TYPE (null_node) = c_common_type_for_size (POINTER_SIZE, 0); 4739 1.1 mrg 4740 1.1 mrg /* Since builtin_types isn't gc'ed, don't export these nodes. */ 4741 1.1 mrg memset (builtin_types, 0, sizeof (builtin_types)); 4742 1.1 mrg } 4743 1.1 mrg 4744 1.1 mrg /* The number of named compound-literals generated thus far. */ 4745 1.1 mrg static GTY(()) int compound_literal_number; 4746 1.1 mrg 4747 1.1 mrg /* Set DECL_NAME for DECL, a VAR_DECL for a compound-literal. */ 4748 1.1 mrg 4749 1.1 mrg void 4750 1.1 mrg set_compound_literal_name (tree decl) 4751 1.1 mrg { 4752 1.1 mrg char *name; 4753 1.1 mrg ASM_FORMAT_PRIVATE_NAME (name, "__compound_literal", 4754 1.1 mrg compound_literal_number); 4755 1.1 mrg compound_literal_number++; 4756 1.1 mrg DECL_NAME (decl) = get_identifier (name); 4757 1.1 mrg } 4758 1.1 mrg 4759 1.1 mrg /* build_va_arg helper function. Return a VA_ARG_EXPR with location LOC, type 4760 1.1 mrg TYPE and operand OP. */ 4761 1.1 mrg 4762 1.1 mrg static tree 4763 1.1 mrg build_va_arg_1 (location_t loc, tree type, tree op) 4764 1.1 mrg { 4765 1.1 mrg tree expr = build1 (VA_ARG_EXPR, type, op); 4766 1.1 mrg SET_EXPR_LOCATION (expr, loc); 4767 1.1 mrg return expr; 4768 1.1 mrg } 4769 1.1 mrg 4770 1.1 mrg /* Return a VA_ARG_EXPR corresponding to a source-level expression 4771 1.1 mrg va_arg (EXPR, TYPE) at source location LOC. */ 4772 1.1 mrg 4773 1.1 mrg tree 4774 1.1 mrg build_va_arg (location_t loc, tree expr, tree type) 4775 1.1 mrg { 4776 1.1 mrg tree va_type = TREE_TYPE (expr); 4777 1.1 mrg tree canon_va_type = (va_type == error_mark_node 4778 1.1 mrg ? error_mark_node 4779 1.1 mrg : targetm.canonical_va_list_type (va_type)); 4780 1.1 mrg 4781 1.1 mrg if (va_type == error_mark_node 4782 1.1 mrg || canon_va_type == NULL_TREE) 4783 1.1 mrg { 4784 1.1 mrg if (canon_va_type == NULL_TREE) 4785 1.1 mrg error_at (loc, "first argument to %<va_arg%> not of type %<va_list%>"); 4786 1.1 mrg 4787 1.1 mrg /* Let's handle things neutrally, if expr: 4788 1.1 mrg - has undeclared type, or 4789 1.1 mrg - is not an va_list type. */ 4790 1.1 mrg return build_va_arg_1 (loc, type, error_mark_node); 4791 1.1 mrg } 4792 1.1 mrg 4793 1.1 mrg if (TREE_CODE (canon_va_type) != ARRAY_TYPE) 4794 1.1 mrg { 4795 1.1 mrg /* Case 1: Not an array type. */ 4796 1.1 mrg 4797 1.1 mrg /* Take the address, to get '&ap'. Note that &ap is not a va_list 4798 1.1 mrg type. */ 4799 1.1 mrg c_common_mark_addressable_vec (expr); 4800 1.1 mrg expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (expr)), expr); 4801 1.1 mrg 4802 1.1 mrg return build_va_arg_1 (loc, type, expr); 4803 1.1 mrg } 4804 1.1 mrg 4805 1.1 mrg /* Case 2: Array type. 4806 1.1 mrg 4807 1.1 mrg Background: 4808 1.1 mrg 4809 1.1 mrg For contrast, let's start with the simple case (case 1). If 4810 1.1 mrg canon_va_type is not an array type, but say a char *, then when 4811 1.1 mrg passing-by-value a va_list, the type of the va_list param decl is 4812 1.1 mrg the same as for another va_list decl (all ap's are char *): 4813 1.1 mrg 4814 1.1 mrg f2_1 (char * ap) 4815 1.1 mrg D.1815 = VA_ARG (&ap, 0B, 1); 4816 1.1 mrg return D.1815; 4817 1.1 mrg 4818 1.1 mrg f2 (int i) 4819 1.1 mrg char * ap.0; 4820 1.1 mrg char * ap; 4821 1.1 mrg __builtin_va_start (&ap, 0); 4822 1.1 mrg ap.0 = ap; 4823 1.1 mrg res = f2_1 (ap.0); 4824 1.1 mrg __builtin_va_end (&ap); 4825 1.1 mrg D.1812 = res; 4826 1.1 mrg return D.1812; 4827 1.1 mrg 4828 1.1 mrg However, if canon_va_type is ARRAY_TYPE, then when passing-by-value a 4829 1.1 mrg va_list the type of the va_list param decl (case 2b, struct * ap) is not 4830 1.1 mrg the same as for another va_list decl (case 2a, struct ap[1]). 4831 1.1 mrg 4832 1.1 mrg f2_1 (struct * ap) 4833 1.1 mrg D.1844 = VA_ARG (ap, 0B, 0); 4834 1.1 mrg return D.1844; 4835 1.1 mrg 4836 1.1 mrg f2 (int i) 4837 1.1 mrg struct ap[1]; 4838 1.1 mrg __builtin_va_start (&ap, 0); 4839 1.1 mrg res = f2_1 (&ap); 4840 1.1 mrg __builtin_va_end (&ap); 4841 1.1 mrg D.1841 = res; 4842 1.1 mrg return D.1841; 4843 1.1 mrg 4844 1.1 mrg Case 2b is different because: 4845 1.1 mrg - on the callee side, the parm decl has declared type va_list, but 4846 1.1 mrg grokdeclarator changes the type of the parm decl to a pointer to the 4847 1.1 mrg array elem type. 4848 1.1 mrg - on the caller side, the pass-by-value uses &ap. 4849 1.1 mrg 4850 1.1 mrg We unify these two cases (case 2a: va_list is array type, 4851 1.1 mrg case 2b: va_list is pointer to array elem type), by adding '&' for the 4852 1.1 mrg array type case, such that we have a pointer to array elem in both 4853 1.1 mrg cases. */ 4854 1.1 mrg 4855 1.1 mrg if (TREE_CODE (va_type) == ARRAY_TYPE) 4856 1.1 mrg { 4857 1.1 mrg /* Case 2a: va_list is array type. */ 4858 1.1 mrg 4859 1.1 mrg /* Take the address, to get '&ap'. Make sure it's a pointer to array 4860 1.1 mrg elem type. */ 4861 1.1 mrg c_common_mark_addressable_vec (expr); 4862 1.1 mrg expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (canon_va_type)), 4863 1.1 mrg expr); 4864 1.1 mrg 4865 1.1 mrg /* Verify that &ap is still recognized as having va_list type. */ 4866 1.1 mrg tree canon_expr_type 4867 1.1 mrg = targetm.canonical_va_list_type (TREE_TYPE (expr)); 4868 1.1 mrg gcc_assert (canon_expr_type != NULL_TREE); 4869 1.1 mrg } 4870 1.1 mrg else 4871 1.1 mrg { 4872 1.1 mrg /* Case 2b: va_list is pointer to array elem type. */ 4873 1.1 mrg gcc_assert (POINTER_TYPE_P (va_type)); 4874 1.1 mrg 4875 1.1 mrg /* Comparison as in std_canonical_va_list_type. */ 4876 1.1 mrg gcc_assert (TYPE_MAIN_VARIANT (TREE_TYPE (va_type)) 4877 1.1 mrg == TYPE_MAIN_VARIANT (TREE_TYPE (canon_va_type))); 4878 1.1 mrg 4879 1.1 mrg /* Don't take the address. We've already got '&ap'. */ 4880 1.1 mrg ; 4881 1.1 mrg } 4882 1.1 mrg 4883 1.1 mrg return build_va_arg_1 (loc, type, expr); 4884 1.1 mrg } 4885 1.1 mrg 4886 1.1 mrg 4887 1.1 mrg /* Linked list of disabled built-in functions. */ 4888 1.1 mrg 4889 1.1 mrg struct disabled_builtin 4890 1.1 mrg { 4891 1.1 mrg const char *name; 4892 1.1 mrg struct disabled_builtin *next; 4893 1.1 mrg }; 4894 1.1 mrg static disabled_builtin *disabled_builtins = NULL; 4895 1.1 mrg 4896 1.1 mrg static bool builtin_function_disabled_p (const char *); 4897 1.1 mrg 4898 1.1 mrg /* Disable a built-in function specified by -fno-builtin-NAME. If NAME 4899 1.1 mrg begins with "__builtin_", give an error. */ 4900 1.1 mrg 4901 1.1 mrg void 4902 1.1 mrg disable_builtin_function (const char *name) 4903 1.1 mrg { 4904 1.1 mrg if (startswith (name, "__builtin_")) 4905 1.1 mrg error ("cannot disable built-in function %qs", name); 4906 1.1 mrg else 4907 1.1 mrg { 4908 1.1 mrg disabled_builtin *new_disabled_builtin = XNEW (disabled_builtin); 4909 1.1 mrg new_disabled_builtin->name = name; 4910 1.1 mrg new_disabled_builtin->next = disabled_builtins; 4911 1.1 mrg disabled_builtins = new_disabled_builtin; 4912 1.1 mrg } 4913 1.1 mrg } 4914 1.1 mrg 4915 1.1 mrg 4916 1.1 mrg /* Return true if the built-in function NAME has been disabled, false 4917 1.1 mrg otherwise. */ 4918 1.1 mrg 4919 1.1 mrg static bool 4920 1.1 mrg builtin_function_disabled_p (const char *name) 4921 1.1 mrg { 4922 1.1 mrg disabled_builtin *p; 4923 1.1 mrg for (p = disabled_builtins; p != NULL; p = p->next) 4924 1.1 mrg { 4925 1.1 mrg if (strcmp (name, p->name) == 0) 4926 1.1 mrg return true; 4927 1.1 mrg } 4928 1.1 mrg return false; 4929 1.1 mrg } 4930 1.1 mrg 4931 1.1 mrg 4932 1.1 mrg /* Worker for DEF_BUILTIN. 4933 1.1 mrg Possibly define a builtin function with one or two names. 4934 1.1 mrg Does not declare a non-__builtin_ function if flag_no_builtin, or if 4935 1.1 mrg nonansi_p and flag_no_nonansi_builtin. */ 4936 1.1 mrg 4937 1.1 mrg static void 4938 1.1 mrg def_builtin_1 (enum built_in_function fncode, 4939 1.1 mrg const char *name, 4940 1.1 mrg enum built_in_class fnclass, 4941 1.1 mrg tree fntype, tree libtype, 4942 1.1 mrg bool both_p, bool fallback_p, bool nonansi_p, 4943 1.1 mrg tree fnattrs, bool implicit_p) 4944 1.1 mrg { 4945 1.1 mrg tree decl; 4946 1.1 mrg const char *libname; 4947 1.1 mrg 4948 1.1 mrg if (fntype == error_mark_node) 4949 1.1 mrg return; 4950 1.1 mrg 4951 1.1 mrg gcc_assert ((!both_p && !fallback_p) 4952 1.1 mrg || startswith (name, "__builtin_")); 4953 1.1 mrg 4954 1.1 mrg libname = name + strlen ("__builtin_"); 4955 1.1 mrg decl = add_builtin_function (name, fntype, fncode, fnclass, 4956 1.1 mrg (fallback_p ? libname : NULL), 4957 1.1 mrg fnattrs); 4958 1.1 mrg 4959 1.1 mrg set_builtin_decl (fncode, decl, implicit_p); 4960 1.1 mrg 4961 1.1 mrg if (both_p 4962 1.1 mrg && !flag_no_builtin && !builtin_function_disabled_p (libname) 4963 1.1 mrg && !(nonansi_p && flag_no_nonansi_builtin)) 4964 1.1 mrg add_builtin_function (libname, libtype, fncode, fnclass, 4965 1.1 mrg NULL, fnattrs); 4966 1.1 mrg } 4967 1.1 mrg 4968 1.1 mrg /* Nonzero if the type T promotes to int. This is (nearly) the 4970 1.1 mrg integral promotions defined in ISO C99 6.3.1.1/2. */ 4971 1.1 mrg 4972 1.1 mrg bool 4973 1.1 mrg c_promoting_integer_type_p (const_tree t) 4974 1.1 mrg { 4975 1.1 mrg switch (TREE_CODE (t)) 4976 1.1 mrg { 4977 1.1 mrg case INTEGER_TYPE: 4978 1.1 mrg return (TYPE_MAIN_VARIANT (t) == char_type_node 4979 1.1 mrg || TYPE_MAIN_VARIANT (t) == signed_char_type_node 4980 1.1 mrg || TYPE_MAIN_VARIANT (t) == unsigned_char_type_node 4981 1.1 mrg || TYPE_MAIN_VARIANT (t) == short_integer_type_node 4982 1.1 mrg || TYPE_MAIN_VARIANT (t) == short_unsigned_type_node 4983 1.1 mrg || TYPE_PRECISION (t) < TYPE_PRECISION (integer_type_node)); 4984 1.1 mrg 4985 1.1 mrg case ENUMERAL_TYPE: 4986 1.1 mrg /* ??? Technically all enumerations not larger than an int 4987 1.1 mrg promote to an int. But this is used along code paths 4988 1.1 mrg that only want to notice a size change. */ 4989 1.1 mrg return TYPE_PRECISION (t) < TYPE_PRECISION (integer_type_node); 4990 1.1 mrg 4991 1.1 mrg case BOOLEAN_TYPE: 4992 1.1 mrg return true; 4993 1.1 mrg 4994 1.1 mrg default: 4995 1.1 mrg return false; 4996 1.1 mrg } 4997 1.1 mrg } 4998 1.1 mrg 4999 1.1 mrg /* Return 1 if PARMS specifies a fixed number of parameters 5000 1.1 mrg and none of their types is affected by default promotions. */ 5001 1.1 mrg 5002 1.1 mrg bool 5003 1.1 mrg self_promoting_args_p (const_tree parms) 5004 1.1 mrg { 5005 1.1 mrg const_tree t; 5006 1.1 mrg for (t = parms; t; t = TREE_CHAIN (t)) 5007 1.1 mrg { 5008 1.1 mrg tree type = TREE_VALUE (t); 5009 1.1 mrg 5010 1.1 mrg if (type == error_mark_node) 5011 1.1 mrg continue; 5012 1.1 mrg 5013 1.1 mrg if (TREE_CHAIN (t) == NULL_TREE && type != void_type_node) 5014 1.1 mrg return false; 5015 1.1 mrg 5016 1.1 mrg if (type == NULL_TREE) 5017 1.1 mrg return false; 5018 1.1 mrg 5019 1.1 mrg if (TYPE_MAIN_VARIANT (type) == float_type_node) 5020 1.1 mrg return false; 5021 1.1 mrg 5022 1.1 mrg if (c_promoting_integer_type_p (type)) 5023 1.1 mrg return false; 5024 1.1 mrg } 5025 1.1 mrg return true; 5026 1.1 mrg } 5027 1.1 mrg 5028 1.1 mrg /* Recursively remove any '*' or '&' operator from TYPE. */ 5029 1.1 mrg tree 5030 1.1 mrg strip_pointer_operator (tree t) 5031 1.1 mrg { 5032 1.1 mrg while (POINTER_TYPE_P (t)) 5033 1.1 mrg t = TREE_TYPE (t); 5034 1.1 mrg return t; 5035 1.1 mrg } 5036 1.1 mrg 5037 1.1 mrg /* Recursively remove pointer or array type from TYPE. */ 5038 1.1 mrg tree 5039 1.1 mrg strip_pointer_or_array_types (tree t) 5040 1.1 mrg { 5041 1.1 mrg while (TREE_CODE (t) == ARRAY_TYPE || POINTER_TYPE_P (t)) 5042 1.1 mrg t = TREE_TYPE (t); 5043 1.1 mrg return t; 5044 1.1 mrg } 5045 1.1 mrg 5046 1.1 mrg /* Used to compare case labels. K1 and K2 are actually tree nodes 5047 1.1 mrg representing case labels, or NULL_TREE for a `default' label. 5048 1.1 mrg Returns -1 if K1 is ordered before K2, -1 if K1 is ordered after 5049 1.1 mrg K2, and 0 if K1 and K2 are equal. */ 5050 1.1 mrg 5051 1.1 mrg int 5052 1.1 mrg case_compare (splay_tree_key k1, splay_tree_key k2) 5053 1.1 mrg { 5054 1.1 mrg /* Consider a NULL key (such as arises with a `default' label) to be 5055 1.1 mrg smaller than anything else. */ 5056 1.1 mrg if (!k1) 5057 1.1 mrg return k2 ? -1 : 0; 5058 1.1 mrg else if (!k2) 5059 1.1 mrg return k1 ? 1 : 0; 5060 1.1 mrg 5061 1.1 mrg return tree_int_cst_compare ((tree) k1, (tree) k2); 5062 1.1 mrg } 5063 1.1 mrg 5064 1.1 mrg /* Process a case label, located at LOC, for the range LOW_VALUE 5065 1.1 mrg ... HIGH_VALUE. If LOW_VALUE and HIGH_VALUE are both NULL_TREE 5066 1.1 mrg then this case label is actually a `default' label. If only 5067 1.1 mrg HIGH_VALUE is NULL_TREE, then case label was declared using the 5068 1.1 mrg usual C/C++ syntax, rather than the GNU case range extension. 5069 1.1 mrg CASES is a tree containing all the case ranges processed so far; 5070 1.1 mrg COND is the condition for the switch-statement itself. 5071 1.1 mrg Returns the CASE_LABEL_EXPR created, or ERROR_MARK_NODE if no 5072 1.1 mrg CASE_LABEL_EXPR is created. */ 5073 1.1 mrg 5074 1.1 mrg tree 5075 1.1 mrg c_add_case_label (location_t loc, splay_tree cases, tree cond, 5076 1.1 mrg tree low_value, tree high_value) 5077 1.1 mrg { 5078 1.1 mrg tree type; 5079 1.1 mrg tree label; 5080 1.1 mrg tree case_label; 5081 1.1 mrg splay_tree_node node; 5082 1.1 mrg 5083 1.1 mrg /* Create the LABEL_DECL itself. */ 5084 1.1 mrg label = create_artificial_label (loc); 5085 1.1 mrg 5086 1.1 mrg /* If there was an error processing the switch condition, bail now 5087 1.1 mrg before we get more confused. */ 5088 1.1 mrg if (!cond || cond == error_mark_node) 5089 1.1 mrg goto error_out; 5090 1.1 mrg 5091 1.1 mrg if ((low_value && TREE_TYPE (low_value) 5092 1.1 mrg && POINTER_TYPE_P (TREE_TYPE (low_value))) 5093 1.1 mrg || (high_value && TREE_TYPE (high_value) 5094 1.1 mrg && POINTER_TYPE_P (TREE_TYPE (high_value)))) 5095 1.1 mrg { 5096 1.1 mrg error_at (loc, "pointers are not permitted as case values"); 5097 1.1 mrg goto error_out; 5098 1.1 mrg } 5099 1.1 mrg 5100 1.1 mrg /* Case ranges are a GNU extension. */ 5101 1.1 mrg if (high_value) 5102 1.1 mrg pedwarn (loc, OPT_Wpedantic, 5103 1.1 mrg "range expressions in switch statements are non-standard"); 5104 1.1 mrg 5105 1.1 mrg type = TREE_TYPE (cond); 5106 1.1 mrg if (low_value) 5107 1.1 mrg { 5108 1.1 mrg low_value = check_case_value (loc, low_value); 5109 1.1 mrg low_value = convert_and_check (loc, type, low_value); 5110 1.1 mrg low_value = fold (low_value); 5111 1.1 mrg if (low_value == error_mark_node) 5112 1.1 mrg goto error_out; 5113 1.1 mrg } 5114 1.1 mrg if (high_value) 5115 1.1 mrg { 5116 1.1 mrg high_value = check_case_value (loc, high_value); 5117 1.1 mrg high_value = convert_and_check (loc, type, high_value); 5118 1.1 mrg high_value = fold (high_value); 5119 1.1 mrg if (high_value == error_mark_node) 5120 1.1 mrg goto error_out; 5121 1.1 mrg } 5122 1.1 mrg 5123 1.1 mrg if (low_value && high_value) 5124 1.1 mrg { 5125 1.1 mrg /* If the LOW_VALUE and HIGH_VALUE are the same, then this isn't 5126 1.1 mrg really a case range, even though it was written that way. 5127 1.1 mrg Remove the HIGH_VALUE to simplify later processing. */ 5128 1.1 mrg if (tree_int_cst_equal (low_value, high_value)) 5129 1.1 mrg high_value = NULL_TREE; 5130 1.1 mrg else if (!tree_int_cst_lt (low_value, high_value)) 5131 1.1 mrg warning_at (loc, 0, "empty range specified"); 5132 1.1 mrg } 5133 1.1 mrg 5134 1.1 mrg /* Look up the LOW_VALUE in the table of case labels we already 5135 1.1 mrg have. */ 5136 1.1 mrg node = splay_tree_lookup (cases, (splay_tree_key) low_value); 5137 1.1 mrg /* If there was not an exact match, check for overlapping ranges. 5138 1.1 mrg There's no need to do this if there's no LOW_VALUE or HIGH_VALUE; 5139 1.1 mrg that's a `default' label and the only overlap is an exact match. */ 5140 1.1 mrg if (!node && (low_value || high_value)) 5141 1.1 mrg { 5142 1.1 mrg splay_tree_node low_bound; 5143 1.1 mrg splay_tree_node high_bound; 5144 1.1 mrg 5145 1.1 mrg /* Even though there wasn't an exact match, there might be an 5146 1.1 mrg overlap between this case range and another case range. 5147 1.1 mrg Since we've (inductively) not allowed any overlapping case 5148 1.1 mrg ranges, we simply need to find the greatest low case label 5149 1.1 mrg that is smaller that LOW_VALUE, and the smallest low case 5150 1.1 mrg label that is greater than LOW_VALUE. If there is an overlap 5151 1.1 mrg it will occur in one of these two ranges. */ 5152 1.1 mrg low_bound = splay_tree_predecessor (cases, 5153 1.1 mrg (splay_tree_key) low_value); 5154 1.1 mrg high_bound = splay_tree_successor (cases, 5155 1.1 mrg (splay_tree_key) low_value); 5156 1.1 mrg 5157 1.1 mrg /* Check to see if the LOW_BOUND overlaps. It is smaller than 5158 1.1 mrg the LOW_VALUE, so there is no need to check unless the 5159 1.1 mrg LOW_BOUND is in fact itself a case range. */ 5160 1.1 mrg if (low_bound 5161 1.1 mrg && CASE_HIGH ((tree) low_bound->value) 5162 1.1 mrg && tree_int_cst_compare (CASE_HIGH ((tree) low_bound->value), 5163 1.1 mrg low_value) >= 0) 5164 1.1 mrg node = low_bound; 5165 1.1 mrg /* Check to see if the HIGH_BOUND overlaps. The low end of that 5166 1.1 mrg range is bigger than the low end of the current range, so we 5167 1.1 mrg are only interested if the current range is a real range, and 5168 1.1 mrg not an ordinary case label. */ 5169 1.1 mrg else if (high_bound 5170 1.1 mrg && high_value 5171 1.1 mrg && (tree_int_cst_compare ((tree) high_bound->key, 5172 1.1 mrg high_value) 5173 1.1 mrg <= 0)) 5174 1.1 mrg node = high_bound; 5175 1.1 mrg } 5176 1.1 mrg /* If there was an overlap, issue an error. */ 5177 1.1 mrg if (node) 5178 1.1 mrg { 5179 1.1 mrg tree duplicate = CASE_LABEL ((tree) node->value); 5180 1.1 mrg 5181 1.1 mrg if (high_value) 5182 1.1 mrg { 5183 1.1 mrg error_at (loc, "duplicate (or overlapping) case value"); 5184 1.1 mrg inform (DECL_SOURCE_LOCATION (duplicate), 5185 1.1 mrg "this is the first entry overlapping that value"); 5186 1.1 mrg } 5187 1.1 mrg else if (low_value) 5188 1.1 mrg { 5189 1.1 mrg error_at (loc, "duplicate case value") ; 5190 1.1 mrg inform (DECL_SOURCE_LOCATION (duplicate), "previously used here"); 5191 1.1 mrg } 5192 1.1 mrg else 5193 1.1 mrg { 5194 1.1 mrg error_at (loc, "multiple default labels in one switch"); 5195 1.1 mrg inform (DECL_SOURCE_LOCATION (duplicate), 5196 1.1 mrg "this is the first default label"); 5197 1.1 mrg } 5198 1.1 mrg goto error_out; 5199 1.1 mrg } 5200 1.1 mrg 5201 1.1 mrg /* Add a CASE_LABEL to the statement-tree. */ 5202 1.1 mrg case_label = add_stmt (build_case_label (low_value, high_value, label)); 5203 1.1 mrg /* Register this case label in the splay tree. */ 5204 1.1 mrg splay_tree_insert (cases, 5205 1.1 mrg (splay_tree_key) low_value, 5206 1.1 mrg (splay_tree_value) case_label); 5207 1.1 mrg 5208 1.1 mrg return case_label; 5209 1.1 mrg 5210 1.1 mrg error_out: 5211 1.1 mrg /* Add a label so that the back-end doesn't think that the beginning of 5212 1.1 mrg the switch is unreachable. Note that we do not add a case label, as 5213 1.1 mrg that just leads to duplicates and thence to failure later on. */ 5214 1.1 mrg if (!cases->root) 5215 1.1 mrg { 5216 1.1 mrg tree t = create_artificial_label (loc); 5217 1.1 mrg add_stmt (build_stmt (loc, LABEL_EXPR, t)); 5218 1.1 mrg } 5219 1.1 mrg return error_mark_node; 5220 1.1 mrg } 5221 1.1 mrg 5222 1.1 mrg /* Subroutine of c_switch_covers_all_cases_p, called via 5223 1.1 mrg splay_tree_foreach. Return 1 if it doesn't cover all the cases. 5224 1.1 mrg ARGS[0] is initially NULL and after the first iteration is the 5225 1.1 mrg so far highest case label. ARGS[1] is the minimum of SWITCH_COND's 5226 1.1 mrg type. */ 5227 1.1 mrg 5228 1.1 mrg static int 5229 1.1 mrg c_switch_covers_all_cases_p_1 (splay_tree_node node, void *data) 5230 1.1 mrg { 5231 1.1 mrg tree label = (tree) node->value; 5232 1.1 mrg tree *args = (tree *) data; 5233 1.1 mrg 5234 1.1 mrg /* If there is a default case, we shouldn't have called this. */ 5235 1.1 mrg gcc_assert (CASE_LOW (label)); 5236 1.1 mrg 5237 1.1 mrg if (args[0] == NULL_TREE) 5238 1.1 mrg { 5239 1.1 mrg if (wi::to_widest (args[1]) < wi::to_widest (CASE_LOW (label))) 5240 1.1 mrg return 1; 5241 1.1 mrg } 5242 1.1 mrg else if (wi::add (wi::to_widest (args[0]), 1) 5243 1.1 mrg != wi::to_widest (CASE_LOW (label))) 5244 1.1 mrg return 1; 5245 1.1 mrg if (CASE_HIGH (label)) 5246 1.1 mrg args[0] = CASE_HIGH (label); 5247 1.1 mrg else 5248 1.1 mrg args[0] = CASE_LOW (label); 5249 1.1 mrg return 0; 5250 1.1 mrg } 5251 1.1 mrg 5252 1.1 mrg /* Return true if switch with CASES and switch condition with type 5253 1.1 mrg covers all possible values in the case labels. */ 5254 1.1 mrg 5255 1.1 mrg bool 5256 1.1 mrg c_switch_covers_all_cases_p (splay_tree cases, tree type) 5257 1.1 mrg { 5258 1.1 mrg /* If there is default:, this is always the case. */ 5259 1.1 mrg splay_tree_node default_node 5260 1.1 mrg = splay_tree_lookup (cases, (splay_tree_key) NULL); 5261 1.1 mrg if (default_node) 5262 1.1 mrg return true; 5263 1.1 mrg 5264 1.1 mrg if (!INTEGRAL_TYPE_P (type)) 5265 1.1 mrg return false; 5266 1.1 mrg 5267 1.1 mrg tree args[2] = { NULL_TREE, TYPE_MIN_VALUE (type) }; 5268 1.1 mrg if (splay_tree_foreach (cases, c_switch_covers_all_cases_p_1, args)) 5269 1.1 mrg return false; 5270 1.1 mrg 5271 1.1 mrg /* If there are no cases at all, or if the highest case label 5272 1.1 mrg is smaller than TYPE_MAX_VALUE, return false. */ 5273 1.1 mrg if (args[0] == NULL_TREE 5274 1.1 mrg || wi::to_widest (args[0]) < wi::to_widest (TYPE_MAX_VALUE (type))) 5275 1.1 mrg return false; 5276 1.1 mrg 5277 1.1 mrg return true; 5278 1.1 mrg } 5279 1.1 mrg 5280 1.1 mrg /* Return true if stmt can fall through. Used by block_may_fallthru 5281 1.1 mrg default case. */ 5282 1.1 mrg 5283 1.1 mrg bool 5284 1.1 mrg c_block_may_fallthru (const_tree stmt) 5285 1.1 mrg { 5286 1.1 mrg switch (TREE_CODE (stmt)) 5287 1.1 mrg { 5288 1.1 mrg case SWITCH_STMT: 5289 1.1 mrg return (!SWITCH_STMT_ALL_CASES_P (stmt) 5290 1.1 mrg || !SWITCH_STMT_NO_BREAK_P (stmt) 5291 1.1 mrg || block_may_fallthru (SWITCH_STMT_BODY (stmt))); 5292 1.1 mrg 5293 1.1 mrg default: 5294 1.1 mrg return true; 5295 1.1 mrg } 5296 1.1 mrg } 5297 1.1 mrg 5298 1.1 mrg /* Finish an expression taking the address of LABEL (an 5299 1.1 mrg IDENTIFIER_NODE). Returns an expression for the address. 5300 1.1 mrg 5301 1.1 mrg LOC is the location for the expression returned. */ 5302 1.1 mrg 5303 1.1 mrg tree 5304 1.1 mrg finish_label_address_expr (tree label, location_t loc) 5305 1.1 mrg { 5306 1.1 mrg tree result; 5307 1.1 mrg 5308 1.1 mrg pedwarn (input_location, OPT_Wpedantic, "taking the address of a label is non-standard"); 5309 1.1 mrg 5310 1.1 mrg if (label == error_mark_node) 5311 1.1 mrg return error_mark_node; 5312 1.1 mrg 5313 1.1 mrg label = lookup_label (label); 5314 1.1 mrg if (label == NULL_TREE) 5315 1.1 mrg result = null_pointer_node; 5316 1.1 mrg else 5317 1.1 mrg { 5318 1.1 mrg TREE_USED (label) = 1; 5319 1.1 mrg result = build1 (ADDR_EXPR, ptr_type_node, label); 5320 1.1 mrg /* The current function is not necessarily uninlinable. 5321 1.1 mrg Computed gotos are incompatible with inlining, but the value 5322 1.1 mrg here could be used only in a diagnostic, for example. */ 5323 1.1 mrg protected_set_expr_location (result, loc); 5324 1.1 mrg } 5325 1.1 mrg 5326 1.1 mrg return result; 5327 1.1 mrg } 5328 1.1 mrg 5329 1.1 mrg 5331 1.1 mrg /* Given a boolean expression ARG, return a tree representing an increment 5332 1.1 mrg or decrement (as indicated by CODE) of ARG. The front end must check for 5333 1.1 mrg invalid cases (e.g., decrement in C++). */ 5334 1.1 mrg tree 5335 1.1 mrg boolean_increment (enum tree_code code, tree arg) 5336 1.1 mrg { 5337 1.1 mrg tree val; 5338 1.1 mrg tree true_res = build_int_cst (TREE_TYPE (arg), 1); 5339 1.1 mrg 5340 1.1 mrg arg = stabilize_reference (arg); 5341 1.1 mrg switch (code) 5342 1.1 mrg { 5343 1.1 mrg case PREINCREMENT_EXPR: 5344 1.1 mrg val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg, true_res); 5345 1.1 mrg break; 5346 1.1 mrg case POSTINCREMENT_EXPR: 5347 1.1 mrg val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg, true_res); 5348 1.1 mrg arg = save_expr (arg); 5349 1.1 mrg val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), val, arg); 5350 1.1 mrg val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), arg, val); 5351 1.1 mrg break; 5352 1.1 mrg case PREDECREMENT_EXPR: 5353 1.1 mrg val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg, 5354 1.1 mrg invert_truthvalue_loc (input_location, arg)); 5355 1.1 mrg break; 5356 1.1 mrg case POSTDECREMENT_EXPR: 5357 1.1 mrg val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg, 5358 1.1 mrg invert_truthvalue_loc (input_location, arg)); 5359 1.1 mrg arg = save_expr (arg); 5360 1.1 mrg val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), val, arg); 5361 1.1 mrg val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), arg, val); 5362 1.1 mrg break; 5363 1.1 mrg default: 5364 1.1 mrg gcc_unreachable (); 5365 1.1 mrg } 5366 1.1 mrg TREE_SIDE_EFFECTS (val) = 1; 5367 1.1 mrg return val; 5368 1.1 mrg } 5369 1.1 mrg 5370 1.1 mrg /* Built-in macros for stddef.h and stdint.h, that require macros 5372 1.1 mrg defined in this file. */ 5373 1.1 mrg void 5374 1.1 mrg c_stddef_cpp_builtins(void) 5375 1.1 mrg { 5376 1.1 mrg builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE, 0); 5377 1.1 mrg builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE, 0); 5378 1.1 mrg builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE, 0); 5379 1.1 mrg builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE, 0); 5380 1.1 mrg builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE, 0); 5381 1.1 mrg builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE, 0); 5382 1.1 mrg if (flag_char8_t) 5383 1.1 mrg builtin_define_with_value ("__CHAR8_TYPE__", CHAR8_TYPE, 0); 5384 1.1 mrg builtin_define_with_value ("__CHAR16_TYPE__", CHAR16_TYPE, 0); 5385 1.1 mrg builtin_define_with_value ("__CHAR32_TYPE__", CHAR32_TYPE, 0); 5386 1.1 mrg if (SIG_ATOMIC_TYPE) 5387 1.1 mrg builtin_define_with_value ("__SIG_ATOMIC_TYPE__", SIG_ATOMIC_TYPE, 0); 5388 1.1 mrg if (INT8_TYPE) 5389 1.1 mrg builtin_define_with_value ("__INT8_TYPE__", INT8_TYPE, 0); 5390 1.1 mrg if (INT16_TYPE) 5391 1.1 mrg builtin_define_with_value ("__INT16_TYPE__", INT16_TYPE, 0); 5392 1.1 mrg if (INT32_TYPE) 5393 1.1 mrg builtin_define_with_value ("__INT32_TYPE__", INT32_TYPE, 0); 5394 1.1 mrg if (INT64_TYPE) 5395 1.1 mrg builtin_define_with_value ("__INT64_TYPE__", INT64_TYPE, 0); 5396 1.1 mrg if (UINT8_TYPE) 5397 1.1 mrg builtin_define_with_value ("__UINT8_TYPE__", UINT8_TYPE, 0); 5398 1.1 mrg if (UINT16_TYPE) 5399 1.1 mrg builtin_define_with_value ("__UINT16_TYPE__", UINT16_TYPE, 0); 5400 1.1 mrg if (UINT32_TYPE) 5401 1.1 mrg builtin_define_with_value ("__UINT32_TYPE__", UINT32_TYPE, 0); 5402 1.1 mrg if (UINT64_TYPE) 5403 1.1 mrg builtin_define_with_value ("__UINT64_TYPE__", UINT64_TYPE, 0); 5404 1.1 mrg if (INT_LEAST8_TYPE) 5405 1.1 mrg builtin_define_with_value ("__INT_LEAST8_TYPE__", INT_LEAST8_TYPE, 0); 5406 1.1 mrg if (INT_LEAST16_TYPE) 5407 1.1 mrg builtin_define_with_value ("__INT_LEAST16_TYPE__", INT_LEAST16_TYPE, 0); 5408 1.1 mrg if (INT_LEAST32_TYPE) 5409 1.1 mrg builtin_define_with_value ("__INT_LEAST32_TYPE__", INT_LEAST32_TYPE, 0); 5410 1.1 mrg if (INT_LEAST64_TYPE) 5411 1.1 mrg builtin_define_with_value ("__INT_LEAST64_TYPE__", INT_LEAST64_TYPE, 0); 5412 1.1 mrg if (UINT_LEAST8_TYPE) 5413 1.1 mrg builtin_define_with_value ("__UINT_LEAST8_TYPE__", UINT_LEAST8_TYPE, 0); 5414 1.1 mrg if (UINT_LEAST16_TYPE) 5415 1.1 mrg builtin_define_with_value ("__UINT_LEAST16_TYPE__", UINT_LEAST16_TYPE, 0); 5416 1.1 mrg if (UINT_LEAST32_TYPE) 5417 1.1 mrg builtin_define_with_value ("__UINT_LEAST32_TYPE__", UINT_LEAST32_TYPE, 0); 5418 1.1 mrg if (UINT_LEAST64_TYPE) 5419 1.1 mrg builtin_define_with_value ("__UINT_LEAST64_TYPE__", UINT_LEAST64_TYPE, 0); 5420 1.1 mrg if (INT_FAST8_TYPE) 5421 1.1 mrg builtin_define_with_value ("__INT_FAST8_TYPE__", INT_FAST8_TYPE, 0); 5422 1.1 mrg if (INT_FAST16_TYPE) 5423 1.1 mrg builtin_define_with_value ("__INT_FAST16_TYPE__", INT_FAST16_TYPE, 0); 5424 1.1 mrg if (INT_FAST32_TYPE) 5425 1.1 mrg builtin_define_with_value ("__INT_FAST32_TYPE__", INT_FAST32_TYPE, 0); 5426 1.1 mrg if (INT_FAST64_TYPE) 5427 1.1 mrg builtin_define_with_value ("__INT_FAST64_TYPE__", INT_FAST64_TYPE, 0); 5428 1.1 mrg if (UINT_FAST8_TYPE) 5429 1.1 mrg builtin_define_with_value ("__UINT_FAST8_TYPE__", UINT_FAST8_TYPE, 0); 5430 1.1 mrg if (UINT_FAST16_TYPE) 5431 1.1 mrg builtin_define_with_value ("__UINT_FAST16_TYPE__", UINT_FAST16_TYPE, 0); 5432 1.1 mrg if (UINT_FAST32_TYPE) 5433 1.1 mrg builtin_define_with_value ("__UINT_FAST32_TYPE__", UINT_FAST32_TYPE, 0); 5434 1.1 mrg if (UINT_FAST64_TYPE) 5435 1.1 mrg builtin_define_with_value ("__UINT_FAST64_TYPE__", UINT_FAST64_TYPE, 0); 5436 1.1 mrg if (INTPTR_TYPE) 5437 1.1 mrg builtin_define_with_value ("__INTPTR_TYPE__", INTPTR_TYPE, 0); 5438 1.1 mrg if (UINTPTR_TYPE) 5439 1.1 mrg builtin_define_with_value ("__UINTPTR_TYPE__", UINTPTR_TYPE, 0); 5440 1.1 mrg /* GIMPLE FE testcases need access to the GCC internal 'sizetype'. 5441 1.1 mrg Expose it as __SIZETYPE__. */ 5442 1.1 mrg if (flag_gimple) 5443 1.1 mrg builtin_define_with_value ("__SIZETYPE__", SIZETYPE, 0); 5444 1.1 mrg } 5445 1.1 mrg 5446 1.1 mrg static void 5447 1.1 mrg c_init_attributes (void) 5448 1.1 mrg { 5449 1.1 mrg /* Fill in the built_in_attributes array. */ 5450 1.1 mrg #define DEF_ATTR_NULL_TREE(ENUM) \ 5451 1.1 mrg built_in_attributes[(int) ENUM] = NULL_TREE; 5452 1.1 mrg #define DEF_ATTR_INT(ENUM, VALUE) \ 5453 1.1 mrg built_in_attributes[(int) ENUM] = build_int_cst (integer_type_node, VALUE); 5454 1.1 mrg #define DEF_ATTR_STRING(ENUM, VALUE) \ 5455 1.1 mrg built_in_attributes[(int) ENUM] = build_string (strlen (VALUE), VALUE); 5456 1.1 mrg #define DEF_ATTR_IDENT(ENUM, STRING) \ 5457 1.1 mrg built_in_attributes[(int) ENUM] = get_identifier (STRING); 5458 1.1 mrg #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \ 5459 1.1 mrg built_in_attributes[(int) ENUM] \ 5460 1.1 mrg = tree_cons (built_in_attributes[(int) PURPOSE], \ 5461 1.1 mrg built_in_attributes[(int) VALUE], \ 5462 1.1 mrg built_in_attributes[(int) CHAIN]); 5463 1.1 mrg #include "builtin-attrs.def" 5464 1.1 mrg #undef DEF_ATTR_NULL_TREE 5465 1.1 mrg #undef DEF_ATTR_INT 5466 1.1 mrg #undef DEF_ATTR_IDENT 5467 1.1 mrg #undef DEF_ATTR_TREE_LIST 5468 1.1 mrg } 5469 1.1 mrg 5470 1.1 mrg /* Check whether the byte alignment ALIGN is a valid user-specified 5471 1.1 mrg alignment less than the supported maximum. If so, return ALIGN's 5472 1.1 mrg base-2 log; if not, output an error and return -1. If OBJFILE 5473 1.1 mrg then reject alignments greater than MAX_OFILE_ALIGNMENT when 5474 1.1 mrg converted to bits. Otherwise, consider valid only alignments 5475 1.1 mrg that are less than HOST_BITS_PER_INT - LOG2_BITS_PER_UNIT. 5476 1.1 mrg Zero is not considered a valid argument (and results in -1 on 5477 1.1 mrg return) but it only triggers a warning when WARN_ZERO is set. */ 5478 1.1 mrg 5479 1.1 mrg int 5480 1.1 mrg check_user_alignment (const_tree align, bool objfile, bool warn_zero) 5481 1.1 mrg { 5482 1.1 mrg if (error_operand_p (align)) 5483 1.1 mrg return -1; 5484 1.1 mrg 5485 1.1 mrg if (TREE_CODE (align) != INTEGER_CST 5486 1.1 mrg || !INTEGRAL_TYPE_P (TREE_TYPE (align))) 5487 1.1 mrg { 5488 1.1 mrg error ("requested alignment is not an integer constant"); 5489 1.1 mrg return -1; 5490 1.1 mrg } 5491 1.1 mrg 5492 1.1 mrg if (integer_zerop (align)) 5493 1.1 mrg { 5494 1.1 mrg if (warn_zero) 5495 1.1 mrg warning (OPT_Wattributes, 5496 1.1 mrg "requested alignment %qE is not a positive power of 2", 5497 1.1 mrg align); 5498 1.1 mrg return -1; 5499 1.1 mrg } 5500 1.1 mrg 5501 1.1 mrg /* Log2 of the byte alignment ALIGN. */ 5502 1.1 mrg int log2align; 5503 1.1 mrg if (tree_int_cst_sgn (align) == -1 5504 1.1 mrg || (log2align = tree_log2 (align)) == -1) 5505 1.1 mrg { 5506 1.1 mrg error ("requested alignment %qE is not a positive power of 2", 5507 1.1 mrg align); 5508 1.1 mrg return -1; 5509 1.1 mrg } 5510 1.1 mrg 5511 1.1 mrg if (objfile) 5512 1.1 mrg { 5513 1.1 mrg unsigned maxalign = MAX_OFILE_ALIGNMENT / BITS_PER_UNIT; 5514 1.1 mrg if (!tree_fits_uhwi_p (align) || tree_to_uhwi (align) > maxalign) 5515 1.1 mrg { 5516 1.1 mrg error ("requested alignment %qE exceeds object file maximum %u", 5517 1.1 mrg align, maxalign); 5518 1.1 mrg return -1; 5519 1.1 mrg } 5520 1.1 mrg } 5521 1.1 mrg 5522 1.1 mrg if (log2align >= HOST_BITS_PER_INT - LOG2_BITS_PER_UNIT) 5523 1.1 mrg { 5524 1.1 mrg error ("requested alignment %qE exceeds maximum %u", 5525 1.1 mrg align, 1U << (HOST_BITS_PER_INT - LOG2_BITS_PER_UNIT - 1)); 5526 1.1 mrg return -1; 5527 1.1 mrg } 5528 1.1 mrg 5529 1.1 mrg return log2align; 5530 1.1 mrg } 5531 1.1 mrg 5532 1.1 mrg /* Determine the ELF symbol visibility for DECL, which is either a 5533 1.1 mrg variable or a function. It is an error to use this function if a 5534 1.1 mrg definition of DECL is not available in this translation unit. 5535 1.1 mrg Returns true if the final visibility has been determined by this 5536 1.1 mrg function; false if the caller is free to make additional 5537 1.1 mrg modifications. */ 5538 1.1 mrg 5539 1.1 mrg bool 5540 1.1 mrg c_determine_visibility (tree decl) 5541 1.1 mrg { 5542 1.1 mrg gcc_assert (VAR_OR_FUNCTION_DECL_P (decl)); 5543 1.1 mrg 5544 1.1 mrg /* If the user explicitly specified the visibility with an 5545 1.1 mrg attribute, honor that. DECL_VISIBILITY will have been set during 5546 1.1 mrg the processing of the attribute. We check for an explicit 5547 1.1 mrg attribute, rather than just checking DECL_VISIBILITY_SPECIFIED, 5548 1.1 mrg to distinguish the use of an attribute from the use of a "#pragma 5549 1.1 mrg GCC visibility push(...)"; in the latter case we still want other 5550 1.1 mrg considerations to be able to overrule the #pragma. */ 5551 1.1 mrg if (lookup_attribute ("visibility", DECL_ATTRIBUTES (decl)) 5552 1.1 mrg || (TARGET_DLLIMPORT_DECL_ATTRIBUTES 5553 1.1 mrg && (lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl)) 5554 1.1 mrg || lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl))))) 5555 1.1 mrg return true; 5556 1.1 mrg 5557 1.1 mrg /* Set default visibility to whatever the user supplied with 5558 1.1 mrg visibility_specified depending on #pragma GCC visibility. */ 5559 1.1 mrg if (!DECL_VISIBILITY_SPECIFIED (decl)) 5560 1.1 mrg { 5561 1.1 mrg if (visibility_options.inpragma 5562 1.1 mrg || DECL_VISIBILITY (decl) != default_visibility) 5563 1.1 mrg { 5564 1.1 mrg DECL_VISIBILITY (decl) = default_visibility; 5565 1.1 mrg DECL_VISIBILITY_SPECIFIED (decl) = visibility_options.inpragma; 5566 1.1 mrg /* If visibility changed and DECL already has DECL_RTL, ensure 5567 1.1 mrg symbol flags are updated. */ 5568 1.1 mrg if (((VAR_P (decl) && TREE_STATIC (decl)) 5569 1.1 mrg || TREE_CODE (decl) == FUNCTION_DECL) 5570 1.1 mrg && DECL_RTL_SET_P (decl)) 5571 1.1 mrg make_decl_rtl (decl); 5572 1.1 mrg } 5573 1.1 mrg } 5574 1.1 mrg return false; 5575 1.1 mrg } 5576 1.1 mrg 5577 1.1 mrg /* Data to communicate through check_function_arguments_recurse between 5578 1.1 mrg check_function_nonnull and check_nonnull_arg. */ 5579 1.1 mrg 5580 1.1 mrg struct nonnull_arg_ctx 5581 1.1 mrg { 5582 1.1 mrg /* Location of the call. */ 5583 1.1 mrg location_t loc; 5584 1.1 mrg /* The function whose arguments are being checked and its type (used 5585 1.1 mrg for calls through function pointers). */ 5586 1.1 mrg const_tree fndecl, fntype; 5587 1.1 mrg /* True if a warning has been issued. */ 5588 1.1 mrg bool warned_p; 5589 1.1 mrg }; 5590 1.1 mrg 5591 1.1 mrg /* Check the argument list of a function call to CTX.FNDECL of CTX.FNTYPE 5592 1.1 mrg for null in argument slots that are marked as requiring a non-null 5593 1.1 mrg pointer argument. The NARGS arguments are passed in the array ARGARRAY. 5594 1.1 mrg Return true if we have warned. */ 5595 1.1 mrg 5596 1.1 mrg static bool 5597 1.1 mrg check_function_nonnull (nonnull_arg_ctx &ctx, int nargs, tree *argarray) 5598 1.1 mrg { 5599 1.1 mrg int firstarg = 0; 5600 1.1 mrg if (TREE_CODE (ctx.fntype) == METHOD_TYPE) 5601 1.1 mrg { 5602 1.1 mrg bool closure = false; 5603 1.1 mrg if (ctx.fndecl) 5604 1.1 mrg { 5605 1.1 mrg /* For certain lambda expressions the C++ front end emits calls 5606 1.1 mrg that pass a null this pointer as an argument named __closure 5607 1.1 mrg to the member operator() of empty function. Detect those 5608 1.1 mrg and avoid checking them, but proceed to check the remaining 5609 1.1 mrg arguments. */ 5610 1.1 mrg tree arg0 = DECL_ARGUMENTS (ctx.fndecl); 5611 1.1 mrg if (tree arg0name = DECL_NAME (arg0)) 5612 1.1 mrg closure = id_equal (arg0name, "__closure"); 5613 1.1 mrg } 5614 1.1 mrg 5615 1.1 mrg /* In calls to C++ non-static member functions check the this 5616 1.1 mrg pointer regardless of whether the function is declared with 5617 1.1 mrg attribute nonnull. */ 5618 1.1 mrg firstarg = 1; 5619 1.1 mrg if (!closure) 5620 1.1 mrg check_function_arguments_recurse (check_nonnull_arg, &ctx, argarray[0], 5621 1.1 mrg firstarg, OPT_Wnonnull); 5622 1.1 mrg } 5623 1.1 mrg 5624 1.1 mrg tree attrs = lookup_attribute ("nonnull", TYPE_ATTRIBUTES (ctx.fntype)); 5625 1.1 mrg if (attrs == NULL_TREE) 5626 1.1 mrg return ctx.warned_p; 5627 1.1 mrg 5628 1.1 mrg tree a = attrs; 5629 1.1 mrg /* See if any of the nonnull attributes has no arguments. If so, 5630 1.1 mrg then every pointer argument is checked (in which case the check 5631 1.1 mrg for pointer type is done in check_nonnull_arg). */ 5632 1.1 mrg if (TREE_VALUE (a) != NULL_TREE) 5633 1.1 mrg do 5634 1.1 mrg a = lookup_attribute ("nonnull", TREE_CHAIN (a)); 5635 1.1 mrg while (a != NULL_TREE && TREE_VALUE (a) != NULL_TREE); 5636 1.1 mrg 5637 1.1 mrg if (a != NULL_TREE) 5638 1.1 mrg for (int i = firstarg; i < nargs; i++) 5639 1.1 mrg check_function_arguments_recurse (check_nonnull_arg, &ctx, argarray[i], 5640 1.1 mrg i + 1, OPT_Wnonnull); 5641 1.1 mrg else 5642 1.1 mrg { 5643 1.1 mrg /* Walk the argument list. If we encounter an argument number we 5644 1.1 mrg should check for non-null, do it. */ 5645 1.1 mrg for (int i = firstarg; i < nargs; i++) 5646 1.1 mrg { 5647 1.1 mrg for (a = attrs; ; a = TREE_CHAIN (a)) 5648 1.1 mrg { 5649 1.1 mrg a = lookup_attribute ("nonnull", a); 5650 1.1 mrg if (a == NULL_TREE || nonnull_check_p (TREE_VALUE (a), i + 1)) 5651 1.1 mrg break; 5652 1.1 mrg } 5653 1.1 mrg 5654 1.1 mrg if (a != NULL_TREE) 5655 1.1 mrg check_function_arguments_recurse (check_nonnull_arg, &ctx, 5656 1.1 mrg argarray[i], i + 1, 5657 1.1 mrg OPT_Wnonnull); 5658 1.1 mrg } 5659 1.1 mrg } 5660 1.1 mrg return ctx.warned_p; 5661 1.1 mrg } 5662 1.1 mrg 5663 1.1 mrg /* Check that the Nth argument of a function call (counting backwards 5664 1.1 mrg from the end) is a (pointer)0. The NARGS arguments are passed in the 5665 1.1 mrg array ARGARRAY. */ 5666 1.1 mrg 5667 1.1 mrg static void 5668 1.1 mrg check_function_sentinel (const_tree fntype, int nargs, tree *argarray) 5669 1.1 mrg { 5670 1.1 mrg tree attr = lookup_attribute ("sentinel", TYPE_ATTRIBUTES (fntype)); 5671 1.1 mrg 5672 1.1 mrg if (attr) 5673 1.1 mrg { 5674 1.1 mrg int len = 0; 5675 1.1 mrg int pos = 0; 5676 1.1 mrg tree sentinel; 5677 1.1 mrg function_args_iterator iter; 5678 1.1 mrg tree t; 5679 1.1 mrg 5680 1.1 mrg /* Skip over the named arguments. */ 5681 1.1 mrg FOREACH_FUNCTION_ARGS (fntype, t, iter) 5682 1.1 mrg { 5683 1.1 mrg if (len == nargs) 5684 1.1 mrg break; 5685 1.1 mrg len++; 5686 1.1 mrg } 5687 1.1 mrg 5688 1.1 mrg if (TREE_VALUE (attr)) 5689 1.1 mrg { 5690 1.1 mrg tree p = TREE_VALUE (TREE_VALUE (attr)); 5691 1.1 mrg pos = TREE_INT_CST_LOW (p); 5692 1.1 mrg } 5693 1.1 mrg 5694 1.1 mrg /* The sentinel must be one of the varargs, i.e. 5695 1.1 mrg in position >= the number of fixed arguments. */ 5696 1.1 mrg if ((nargs - 1 - pos) < len) 5697 1.1 mrg { 5698 1.1 mrg warning (OPT_Wformat_, 5699 1.1 mrg "not enough variable arguments to fit a sentinel"); 5700 1.1 mrg return; 5701 1.1 mrg } 5702 1.1 mrg 5703 1.1 mrg /* Validate the sentinel. */ 5704 1.1 mrg sentinel = fold_for_warn (argarray[nargs - 1 - pos]); 5705 1.1 mrg if ((!POINTER_TYPE_P (TREE_TYPE (sentinel)) 5706 1.1 mrg || !integer_zerop (sentinel)) 5707 1.1 mrg /* Although __null (in C++) is only an integer we allow it 5708 1.1 mrg nevertheless, as we are guaranteed that it's exactly 5709 1.1 mrg as wide as a pointer, and we don't want to force 5710 1.1 mrg users to cast the NULL they have written there. 5711 1.1 mrg We warn with -Wstrict-null-sentinel, though. */ 5712 1.1 mrg && (warn_strict_null_sentinel || null_node != sentinel)) 5713 1.1 mrg warning (OPT_Wformat_, "missing sentinel in function call"); 5714 1.1 mrg } 5715 1.1 mrg } 5716 1.1 mrg 5717 1.1 mrg /* Check that the same argument isn't passed to two or more 5718 1.1 mrg restrict-qualified formal and issue a -Wrestrict warning 5719 1.1 mrg if it is. Return true if a warning has been issued. */ 5720 1.1 mrg 5721 1.1 mrg static bool 5722 1.1 mrg check_function_restrict (const_tree fndecl, const_tree fntype, 5723 1.1 mrg int nargs, tree *unfolded_argarray) 5724 1.1 mrg { 5725 1.1 mrg int i; 5726 1.1 mrg tree parms = TYPE_ARG_TYPES (fntype); 5727 1.1 mrg 5728 1.1 mrg /* Call fold_for_warn on all of the arguments. */ 5729 1.1 mrg auto_vec<tree> argarray (nargs); 5730 1.1 mrg for (i = 0; i < nargs; i++) 5731 1.1 mrg argarray.quick_push (fold_for_warn (unfolded_argarray[i])); 5732 1.1 mrg 5733 1.1 mrg if (fndecl 5734 1.1 mrg && TREE_CODE (fndecl) == FUNCTION_DECL) 5735 1.1 mrg { 5736 1.1 mrg /* Avoid diagnosing calls built-ins with a zero size/bound 5737 1.1 mrg here. They are checked in more detail elsewhere. */ 5738 1.1 mrg if (fndecl_built_in_p (fndecl, BUILT_IN_NORMAL) 5739 1.1 mrg && nargs == 3 5740 1.1 mrg && TREE_CODE (argarray[2]) == INTEGER_CST 5741 1.1 mrg && integer_zerop (argarray[2])) 5742 1.1 mrg return false; 5743 1.1 mrg 5744 1.1 mrg if (DECL_ARGUMENTS (fndecl)) 5745 1.1 mrg parms = DECL_ARGUMENTS (fndecl); 5746 1.1 mrg } 5747 1.1 mrg 5748 1.1 mrg for (i = 0; i < nargs; i++) 5749 1.1 mrg TREE_VISITED (argarray[i]) = 0; 5750 1.1 mrg 5751 1.1 mrg bool warned = false; 5752 1.1 mrg 5753 1.1 mrg for (i = 0; i < nargs && parms && parms != void_list_node; i++) 5754 1.1 mrg { 5755 1.1 mrg tree type; 5756 1.1 mrg if (TREE_CODE (parms) == PARM_DECL) 5757 1.1 mrg { 5758 1.1 mrg type = TREE_TYPE (parms); 5759 1.1 mrg parms = DECL_CHAIN (parms); 5760 1.1 mrg } 5761 1.1 mrg else 5762 1.1 mrg { 5763 1.1 mrg type = TREE_VALUE (parms); 5764 1.1 mrg parms = TREE_CHAIN (parms); 5765 1.1 mrg } 5766 1.1 mrg if (POINTER_TYPE_P (type) 5767 1.1 mrg && TYPE_RESTRICT (type) 5768 1.1 mrg && !TYPE_READONLY (TREE_TYPE (type))) 5769 1.1 mrg warned |= warn_for_restrict (i, argarray.address (), nargs); 5770 1.1 mrg } 5771 1.1 mrg 5772 1.1 mrg for (i = 0; i < nargs; i++) 5773 1.1 mrg TREE_VISITED (argarray[i]) = 0; 5774 1.1 mrg 5775 1.1 mrg return warned; 5776 1.1 mrg } 5777 1.1 mrg 5778 1.1 mrg /* Helper for check_function_nonnull; given a list of operands which 5779 1.1 mrg must be non-null in ARGS, determine if operand PARAM_NUM should be 5780 1.1 mrg checked. */ 5781 1.1 mrg 5782 1.1 mrg static bool 5783 1.1 mrg nonnull_check_p (tree args, unsigned HOST_WIDE_INT param_num) 5784 1.1 mrg { 5785 1.1 mrg unsigned HOST_WIDE_INT arg_num = 0; 5786 1.1 mrg 5787 1.1 mrg for (; args; args = TREE_CHAIN (args)) 5788 1.1 mrg { 5789 1.1 mrg bool found = get_attribute_operand (TREE_VALUE (args), &arg_num); 5790 1.1 mrg 5791 1.1 mrg gcc_assert (found); 5792 1.1 mrg 5793 1.1 mrg if (arg_num == param_num) 5794 1.1 mrg return true; 5795 1.1 mrg } 5796 1.1 mrg return false; 5797 1.1 mrg } 5798 1.1 mrg 5799 1.1 mrg /* Check that the function argument PARAM (which is operand number 5800 1.1 mrg PARAM_NUM) is non-null. This is called by check_function_nonnull 5801 1.1 mrg via check_function_arguments_recurse. */ 5802 1.1 mrg 5803 1.1 mrg static void 5804 1.1 mrg check_nonnull_arg (void *ctx, tree param, unsigned HOST_WIDE_INT param_num) 5805 1.1 mrg { 5806 1.1 mrg struct nonnull_arg_ctx *pctx = (struct nonnull_arg_ctx *) ctx; 5807 1.1 mrg 5808 1.1 mrg /* Just skip checking the argument if it's not a pointer. This can 5809 1.1 mrg happen if the "nonnull" attribute was given without an operand 5810 1.1 mrg list (which means to check every pointer argument). */ 5811 1.1 mrg 5812 1.1 mrg tree paramtype = TREE_TYPE (param); 5813 1.1 mrg if (TREE_CODE (paramtype) != POINTER_TYPE 5814 1.1 mrg && TREE_CODE (paramtype) != NULLPTR_TYPE) 5815 1.1 mrg return; 5816 1.1 mrg 5817 1.1 mrg /* Diagnose the simple cases of null arguments. */ 5818 1.1 mrg if (!integer_zerop (fold_for_warn (param))) 5819 1.1 mrg return; 5820 1.1 mrg 5821 1.1 mrg auto_diagnostic_group adg; 5822 1.1 mrg 5823 1.1 mrg const location_t loc = EXPR_LOC_OR_LOC (param, pctx->loc); 5824 1.1 mrg 5825 1.1 mrg if (TREE_CODE (pctx->fntype) == METHOD_TYPE) 5826 1.1 mrg --param_num; 5827 1.1 mrg 5828 1.1 mrg bool warned; 5829 1.1 mrg if (param_num == 0) 5830 1.1 mrg { 5831 1.1 mrg warned = warning_at (loc, OPT_Wnonnull, 5832 1.1 mrg "%qs pointer is null", "this"); 5833 1.1 mrg if (warned && pctx->fndecl) 5834 1.1 mrg inform (DECL_SOURCE_LOCATION (pctx->fndecl), 5835 1.1 mrg "in a call to non-static member function %qD", 5836 1.1 mrg pctx->fndecl); 5837 1.1 mrg } 5838 1.1 mrg else 5839 1.1 mrg { 5840 1.1 mrg warned = warning_at (loc, OPT_Wnonnull, 5841 1.1 mrg "argument %u null where non-null expected", 5842 1.1 mrg (unsigned) param_num); 5843 1.1 mrg if (warned && pctx->fndecl) 5844 1.1 mrg inform (DECL_SOURCE_LOCATION (pctx->fndecl), 5845 1.1 mrg "in a call to function %qD declared %qs", 5846 1.1 mrg pctx->fndecl, "nonnull"); 5847 1.1 mrg } 5848 1.1 mrg 5849 1.1 mrg if (warned) 5850 1.1 mrg pctx->warned_p = true; 5851 1.1 mrg } 5852 1.1 mrg 5853 1.1 mrg /* Helper for attribute handling; fetch the operand number from 5854 1.1 mrg the attribute argument list. */ 5855 1.1 mrg 5856 1.1 mrg bool 5857 1.1 mrg get_attribute_operand (tree arg_num_expr, unsigned HOST_WIDE_INT *valp) 5858 1.1 mrg { 5859 1.1 mrg /* Verify the arg number is a small constant. */ 5860 1.1 mrg if (tree_fits_uhwi_p (arg_num_expr)) 5861 1.1 mrg { 5862 1.1 mrg *valp = tree_to_uhwi (arg_num_expr); 5863 1.1 mrg return true; 5864 1.1 mrg } 5865 1.1 mrg else 5866 1.1 mrg return false; 5867 1.1 mrg } 5868 1.1 mrg 5869 1.1 mrg /* Arguments being collected for optimization. */ 5870 1.1 mrg typedef const char *const_char_p; /* For DEF_VEC_P. */ 5871 1.1 mrg static GTY(()) vec<const_char_p, va_gc> *optimize_args; 5872 1.1 mrg 5873 1.1 mrg 5874 1.1 mrg /* Inner function to convert a TREE_LIST to argv string to parse the optimize 5875 1.1 mrg options in ARGS. ATTR_P is true if this is for attribute(optimize), and 5876 1.1 mrg false for #pragma GCC optimize. */ 5877 1.1 mrg 5878 1.1 mrg bool 5879 1.1 mrg parse_optimize_options (tree args, bool attr_p) 5880 1.1 mrg { 5881 1.1 mrg bool ret = true; 5882 1.1 mrg unsigned opt_argc; 5883 1.1 mrg unsigned i; 5884 1.1 mrg const char **opt_argv; 5885 1.1 mrg struct cl_decoded_option *decoded_options; 5886 1.1 mrg unsigned int decoded_options_count; 5887 1.1 mrg tree ap; 5888 1.1 mrg 5889 1.1 mrg /* Build up argv vector. Just in case the string is stored away, use garbage 5890 1.1 mrg collected strings. */ 5891 1.1 mrg vec_safe_truncate (optimize_args, 0); 5892 1.1 mrg vec_safe_push (optimize_args, (const char *) NULL); 5893 1.1 mrg 5894 1.1 mrg for (ap = args; ap != NULL_TREE; ap = TREE_CHAIN (ap)) 5895 1.1 mrg { 5896 1.1 mrg tree value = TREE_VALUE (ap); 5897 1.1 mrg 5898 1.1 mrg if (TREE_CODE (value) == INTEGER_CST) 5899 1.1 mrg { 5900 1.1 mrg char buffer[HOST_BITS_PER_LONG / 3 + 4]; 5901 1.1 mrg sprintf (buffer, "-O%ld", (long) TREE_INT_CST_LOW (value)); 5902 1.1 mrg vec_safe_push (optimize_args, ggc_strdup (buffer)); 5903 1.1 mrg } 5904 1.1 mrg 5905 1.1 mrg else if (TREE_CODE (value) == STRING_CST) 5906 1.1 mrg { 5907 1.1 mrg /* Split string into multiple substrings. */ 5908 1.1 mrg size_t len = TREE_STRING_LENGTH (value); 5909 1.1 mrg char *p = ASTRDUP (TREE_STRING_POINTER (value)); 5910 1.1 mrg char *end = p + len; 5911 1.1 mrg char *comma; 5912 1.1 mrg char *next_p = p; 5913 1.1 mrg 5914 1.1 mrg while (next_p != NULL) 5915 1.1 mrg { 5916 1.1 mrg size_t len2; 5917 1.1 mrg char *q, *r; 5918 1.1 mrg 5919 1.1 mrg p = next_p; 5920 1.1 mrg comma = strchr (p, ','); 5921 1.1 mrg if (comma) 5922 1.1 mrg { 5923 1.1 mrg len2 = comma - p; 5924 1.1 mrg *comma = '\0'; 5925 1.1 mrg next_p = comma+1; 5926 1.1 mrg } 5927 1.1 mrg else 5928 1.1 mrg { 5929 1.1 mrg len2 = end - p; 5930 1.1 mrg next_p = NULL; 5931 1.1 mrg } 5932 1.1 mrg 5933 1.1 mrg /* If the user supplied -Oxxx or -fxxx, only allow -Oxxx or -fxxx 5934 1.1 mrg options. */ 5935 1.1 mrg if (*p == '-' && p[1] != 'O' && p[1] != 'f') 5936 1.1 mrg { 5937 1.1 mrg ret = false; 5938 1.1 mrg if (attr_p) 5939 1.1 mrg warning (OPT_Wattributes, 5940 1.1 mrg "bad option %qs to attribute %<optimize%>", p); 5941 1.1 mrg else 5942 1.1 mrg warning (OPT_Wpragmas, 5943 1.1 mrg "bad option %qs to pragma %<optimize%>", p); 5944 1.1 mrg continue; 5945 1.1 mrg } 5946 1.1 mrg 5947 1.1 mrg /* Can't use GC memory here, see PR88007. */ 5948 1.1 mrg r = q = XOBNEWVEC (&opts_obstack, char, len2 + 3); 5949 1.1 mrg 5950 1.1 mrg if (*p != '-') 5951 1.1 mrg { 5952 1.1 mrg *r++ = '-'; 5953 1.1 mrg 5954 1.1 mrg /* Assume that Ox is -Ox, a numeric value is -Ox, a s by 5955 1.1 mrg itself is -Os, and any other switch begins with a -f. */ 5956 1.1 mrg if ((*p >= '0' && *p <= '9') 5957 1.1 mrg || (p[0] == 's' && p[1] == '\0')) 5958 1.1 mrg *r++ = 'O'; 5959 1.1 mrg else if (*p != 'O') 5960 1.1 mrg *r++ = 'f'; 5961 1.1 mrg } 5962 1.1 mrg 5963 1.1 mrg memcpy (r, p, len2); 5964 1.1 mrg r[len2] = '\0'; 5965 1.1 mrg vec_safe_push (optimize_args, (const char *) q); 5966 1.1 mrg } 5967 1.1 mrg 5968 1.1 mrg } 5969 1.1 mrg } 5970 1.1 mrg 5971 1.1 mrg opt_argc = optimize_args->length (); 5972 1.1 mrg opt_argv = (const char **) alloca (sizeof (char *) * (opt_argc + 1)); 5973 1.1 mrg 5974 1.1 mrg for (i = 1; i < opt_argc; i++) 5975 1.1 mrg opt_argv[i] = (*optimize_args)[i]; 5976 1.1 mrg 5977 1.1 mrg /* Now parse the options. */ 5978 1.1 mrg decode_cmdline_options_to_array_default_mask (opt_argc, opt_argv, 5979 1.1 mrg &decoded_options, 5980 1.1 mrg &decoded_options_count); 5981 1.1 mrg /* Drop non-Optimization options. */ 5982 1.1 mrg unsigned j = 1; 5983 1.1 mrg for (i = 1; i < decoded_options_count; ++i) 5984 1.1 mrg { 5985 1.1 mrg if (! (cl_options[decoded_options[i].opt_index].flags & CL_OPTIMIZATION)) 5986 1.1 mrg { 5987 1.1 mrg ret = false; 5988 1.1 mrg if (attr_p) 5989 1.1 mrg warning (OPT_Wattributes, 5990 1.1 mrg "bad option %qs to attribute %<optimize%>", 5991 1.1 mrg decoded_options[i].orig_option_with_args_text); 5992 1.1 mrg else 5993 1.1 mrg warning (OPT_Wpragmas, 5994 1.1 mrg "bad option %qs to pragma %<optimize%>", 5995 1.1 mrg decoded_options[i].orig_option_with_args_text); 5996 1.1 mrg continue; 5997 1.1 mrg } 5998 1.1 mrg if (i != j) 5999 1.1 mrg decoded_options[j] = decoded_options[i]; 6000 1.1 mrg j++; 6001 1.1 mrg } 6002 1.1 mrg decoded_options_count = j; 6003 1.1 mrg 6004 1.1 mrg /* Merge the decoded options with save_decoded_options. */ 6005 1.1 mrg unsigned save_opt_count = save_opt_decoded_options->length (); 6006 1.1 mrg unsigned merged_decoded_options_count 6007 1.1 mrg = save_opt_count + decoded_options_count; 6008 1.1 mrg cl_decoded_option *merged_decoded_options 6009 1.1 mrg = XNEWVEC (cl_decoded_option, merged_decoded_options_count); 6010 1.1 mrg 6011 1.1 mrg /* Note the first decoded_options is used for the program name. */ 6012 1.1 mrg for (unsigned i = 0; i < save_opt_count; ++i) 6013 1.1 mrg merged_decoded_options[i + 1] = (*save_opt_decoded_options)[i]; 6014 1.1 mrg for (unsigned i = 1; i < decoded_options_count; ++i) 6015 1.1 mrg merged_decoded_options[save_opt_count + i] = decoded_options[i]; 6016 1.1 mrg 6017 1.1 mrg /* And apply them. */ 6018 1.1 mrg decode_options (&global_options, &global_options_set, 6019 1.1 mrg merged_decoded_options, merged_decoded_options_count, 6020 1.1 mrg input_location, global_dc, NULL); 6021 1.1 mrg free (decoded_options); 6022 1.1 mrg 6023 1.1 mrg targetm.override_options_after_change(); 6024 1.1 mrg 6025 1.1 mrg optimize_args->truncate (0); 6026 1.1 mrg return ret; 6027 1.1 mrg } 6028 1.1 mrg 6029 1.1 mrg /* Check whether ATTR is a valid attribute fallthrough. */ 6030 1.1 mrg 6031 1.1 mrg bool 6032 1.1 mrg attribute_fallthrough_p (tree attr) 6033 1.1 mrg { 6034 1.1 mrg if (attr == error_mark_node) 6035 1.1 mrg return false; 6036 1.1 mrg tree t = lookup_attribute ("fallthrough", attr); 6037 1.1 mrg if (t == NULL_TREE) 6038 1.1 mrg return false; 6039 1.1 mrg /* It is no longer true that "this attribute shall appear at most once in 6040 1.1 mrg each attribute-list", but we still give a warning. */ 6041 1.1 mrg if (lookup_attribute ("fallthrough", TREE_CHAIN (t))) 6042 1.1 mrg warning (OPT_Wattributes, "attribute %<fallthrough%> specified multiple " 6043 1.1 mrg "times"); 6044 1.1 mrg /* No attribute-argument-clause shall be present. */ 6045 1.1 mrg else if (TREE_VALUE (t) != NULL_TREE) 6046 1.1 mrg warning (OPT_Wattributes, "%<fallthrough%> attribute specified with " 6047 1.1 mrg "a parameter"); 6048 1.1 mrg /* Warn if other attributes are found. */ 6049 1.1 mrg for (t = attr; t != NULL_TREE; t = TREE_CHAIN (t)) 6050 1.1 mrg { 6051 1.1 mrg tree name = get_attribute_name (t); 6052 1.1 mrg if (!is_attribute_p ("fallthrough", name)) 6053 1.1 mrg { 6054 1.1 mrg if (!c_dialect_cxx () && get_attribute_namespace (t) == NULL_TREE) 6055 1.1 mrg /* The specifications of standard attributes in C mean 6056 1.1 mrg this is a constraint violation. */ 6057 1.1 mrg pedwarn (input_location, OPT_Wattributes, "%qE attribute ignored", 6058 1.1 mrg get_attribute_name (t)); 6059 1.1 mrg else 6060 1.1 mrg warning (OPT_Wattributes, "%qE attribute ignored", name); 6061 1.1 mrg } 6062 1.1 mrg } 6063 1.1 mrg return true; 6064 1.1 mrg } 6065 1.1 mrg 6066 1.1 mrg 6067 1.1 mrg /* Check for valid arguments being passed to a function with FNTYPE. 6069 1.1 mrg There are NARGS arguments in the array ARGARRAY. LOC should be used 6070 1.1 mrg for diagnostics. Return true if either -Wnonnull or -Wrestrict has 6071 1.1 mrg been issued. 6072 1.1 mrg 6073 1.1 mrg The arguments in ARGARRAY may not have been folded yet (e.g. for C++, 6074 1.1 mrg to preserve location wrappers); checks that require folded arguments 6075 1.1 mrg should call fold_for_warn on them. */ 6076 1.1 mrg 6077 1.1 mrg bool 6078 1.1 mrg check_function_arguments (location_t loc, const_tree fndecl, const_tree fntype, 6079 1.1 mrg int nargs, tree *argarray, vec<location_t> *arglocs) 6080 1.1 mrg { 6081 1.1 mrg bool warned_p = false; 6082 1.1 mrg 6083 1.1 mrg /* Check for null being passed in a pointer argument that must be 6084 1.1 mrg non-null. In C++, this includes the this pointer. We also need 6085 1.1 mrg to do this if format checking is enabled. */ 6086 1.1 mrg if (warn_nonnull) 6087 1.1 mrg { 6088 1.1 mrg nonnull_arg_ctx ctx = { loc, fndecl, fntype, false }; 6089 1.1 mrg warned_p = check_function_nonnull (ctx, nargs, argarray); 6090 1.1 mrg } 6091 1.1 mrg 6092 1.1 mrg /* Check for errors in format strings. */ 6093 1.1 mrg 6094 1.1 mrg if (warn_format || warn_suggest_attribute_format) 6095 1.1 mrg check_function_format (fntype, TYPE_ATTRIBUTES (fntype), nargs, argarray, 6096 1.1 mrg arglocs); 6097 1.1 mrg 6098 1.1 mrg if (warn_format) 6099 1.1 mrg check_function_sentinel (fntype, nargs, argarray); 6100 1.1 mrg 6101 1.1 mrg if (fndecl && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)) 6102 1.1 mrg { 6103 1.1 mrg switch (DECL_FUNCTION_CODE (fndecl)) 6104 1.1 mrg { 6105 1.1 mrg case BUILT_IN_SPRINTF: 6106 1.1 mrg case BUILT_IN_SPRINTF_CHK: 6107 1.1 mrg case BUILT_IN_SNPRINTF: 6108 1.1 mrg case BUILT_IN_SNPRINTF_CHK: 6109 1.1 mrg /* Let the sprintf pass handle these. */ 6110 1.1 mrg return warned_p; 6111 1.1 mrg 6112 1.1 mrg default: 6113 1.1 mrg break; 6114 1.1 mrg } 6115 1.1 mrg } 6116 1.1 mrg 6117 1.1 mrg /* check_function_restrict sets the DECL_READ_P for arguments 6118 1.1 mrg so it must be called unconditionally. */ 6119 1.1 mrg warned_p |= check_function_restrict (fndecl, fntype, nargs, argarray); 6120 1.1 mrg 6121 1.1 mrg return warned_p; 6122 1.1 mrg } 6123 1.1 mrg 6124 1.1 mrg /* Generic argument checking recursion routine. PARAM is the argument to 6125 1.1 mrg be checked. PARAM_NUM is the number of the argument. CALLBACK is invoked 6126 1.1 mrg once the argument is resolved. CTX is context for the callback. 6127 1.1 mrg OPT is the warning for which this is done. */ 6128 1.1 mrg void 6129 1.1 mrg check_function_arguments_recurse (void (*callback) 6130 1.1 mrg (void *, tree, unsigned HOST_WIDE_INT), 6131 1.1 mrg void *ctx, tree param, 6132 1.1 mrg unsigned HOST_WIDE_INT param_num, 6133 1.1 mrg opt_code opt) 6134 1.1 mrg { 6135 1.1 mrg if (opt != OPT_Wformat_ && warning_suppressed_p (param)) 6136 1.1 mrg return; 6137 1.1 mrg 6138 1.1 mrg if (CONVERT_EXPR_P (param) 6139 1.1 mrg && (TYPE_PRECISION (TREE_TYPE (param)) 6140 1.1 mrg == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (param, 0))))) 6141 1.1 mrg { 6142 1.1 mrg /* Strip coercion. */ 6143 1.1 mrg check_function_arguments_recurse (callback, ctx, 6144 1.1 mrg TREE_OPERAND (param, 0), param_num, 6145 1.1 mrg opt); 6146 1.1 mrg return; 6147 1.1 mrg } 6148 1.1 mrg 6149 1.1 mrg if (TREE_CODE (param) == CALL_EXPR && CALL_EXPR_FN (param)) 6150 1.1 mrg { 6151 1.1 mrg tree type = TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (param))); 6152 1.1 mrg tree attrs; 6153 1.1 mrg bool found_format_arg = false; 6154 1.1 mrg 6155 1.1 mrg /* See if this is a call to a known internationalization function 6156 1.1 mrg that modifies a format arg. Such a function may have multiple 6157 1.1 mrg format_arg attributes (for example, ngettext). */ 6158 1.1 mrg 6159 1.1 mrg for (attrs = TYPE_ATTRIBUTES (type); 6160 1.1 mrg attrs; 6161 1.1 mrg attrs = TREE_CHAIN (attrs)) 6162 1.1 mrg if (is_attribute_p ("format_arg", get_attribute_name (attrs))) 6163 1.1 mrg { 6164 1.1 mrg tree inner_arg; 6165 1.1 mrg tree format_num_expr; 6166 1.1 mrg int format_num; 6167 1.1 mrg int i; 6168 1.1 mrg call_expr_arg_iterator iter; 6169 1.1 mrg 6170 1.1 mrg /* Extract the argument number, which was previously checked 6171 1.1 mrg to be valid. */ 6172 1.1 mrg format_num_expr = TREE_VALUE (TREE_VALUE (attrs)); 6173 1.1 mrg 6174 1.1 mrg format_num = tree_to_uhwi (format_num_expr); 6175 1.1 mrg 6176 1.1 mrg for (inner_arg = first_call_expr_arg (param, &iter), i = 1; 6177 1.1 mrg inner_arg != NULL_TREE; 6178 1.1 mrg inner_arg = next_call_expr_arg (&iter), i++) 6179 1.1 mrg if (i == format_num) 6180 1.1 mrg { 6181 1.1 mrg check_function_arguments_recurse (callback, ctx, 6182 1.1 mrg inner_arg, param_num, 6183 1.1 mrg opt); 6184 1.1 mrg found_format_arg = true; 6185 1.1 mrg break; 6186 1.1 mrg } 6187 1.1 mrg } 6188 1.1 mrg 6189 1.1 mrg /* If we found a format_arg attribute and did a recursive check, 6190 1.1 mrg we are done with checking this argument. Otherwise, we continue 6191 1.1 mrg and this will be considered a non-literal. */ 6192 1.1 mrg if (found_format_arg) 6193 1.1 mrg return; 6194 1.1 mrg } 6195 1.1 mrg 6196 1.1 mrg if (TREE_CODE (param) == COND_EXPR) 6197 1.1 mrg { 6198 1.1 mrg /* Simplify to avoid warning for an impossible case. */ 6199 1.1 mrg param = fold_for_warn (param); 6200 1.1 mrg if (TREE_CODE (param) == COND_EXPR) 6201 1.1 mrg { 6202 1.1 mrg /* Check both halves of the conditional expression. */ 6203 1.1 mrg check_function_arguments_recurse (callback, ctx, 6204 1.1 mrg TREE_OPERAND (param, 1), 6205 1.1 mrg param_num, opt); 6206 1.1 mrg check_function_arguments_recurse (callback, ctx, 6207 1.1 mrg TREE_OPERAND (param, 2), 6208 1.1 mrg param_num, opt); 6209 1.1 mrg return; 6210 1.1 mrg } 6211 1.1 mrg } 6212 1.1 mrg 6213 1.1 mrg (*callback) (ctx, param, param_num); 6214 1.1 mrg } 6215 1.1 mrg 6216 1.1 mrg /* Checks for a builtin function FNDECL that the number of arguments 6217 1.1 mrg NARGS against the required number REQUIRED and issues an error if 6218 1.1 mrg there is a mismatch. Returns true if the number of arguments is 6219 1.1 mrg correct, otherwise false. LOC is the location of FNDECL. */ 6220 1.1 mrg 6221 1.1 mrg static bool 6222 1.1 mrg builtin_function_validate_nargs (location_t loc, tree fndecl, int nargs, 6223 1.1 mrg int required) 6224 1.1 mrg { 6225 1.1 mrg if (nargs < required) 6226 1.1 mrg { 6227 1.1 mrg error_at (loc, "too few arguments to function %qE", fndecl); 6228 1.1 mrg return false; 6229 1.1 mrg } 6230 1.1 mrg else if (nargs > required) 6231 1.1 mrg { 6232 1.1 mrg error_at (loc, "too many arguments to function %qE", fndecl); 6233 1.1 mrg return false; 6234 1.1 mrg } 6235 1.1 mrg return true; 6236 1.1 mrg } 6237 1.1 mrg 6238 1.1 mrg /* Helper macro for check_builtin_function_arguments. */ 6239 1.1 mrg #define ARG_LOCATION(N) \ 6240 1.1 mrg (arg_loc.is_empty () \ 6241 1.1 mrg ? EXPR_LOC_OR_LOC (args[(N)], input_location) \ 6242 1.1 mrg : expansion_point_location (arg_loc[(N)])) 6243 1.1 mrg 6244 1.1 mrg /* Verifies the NARGS arguments ARGS to the builtin function FNDECL. 6245 1.1 mrg Returns false if there was an error, otherwise true. LOC is the 6246 1.1 mrg location of the function; ARG_LOC is a vector of locations of the 6247 1.1 mrg arguments. If FNDECL is the result of resolving an overloaded 6248 1.1 mrg target built-in, ORIG_FNDECL is the original function decl, 6249 1.1 mrg otherwise it is null. */ 6250 1.1 mrg 6251 1.1 mrg bool 6252 1.1 mrg check_builtin_function_arguments (location_t loc, vec<location_t> arg_loc, 6253 1.1 mrg tree fndecl, tree orig_fndecl, 6254 1.1 mrg int nargs, tree *args) 6255 1.1 mrg { 6256 1.1 mrg if (!fndecl_built_in_p (fndecl)) 6257 1.1 mrg return true; 6258 1.1 mrg 6259 1.1 mrg if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD) 6260 1.1 mrg return (!targetm.check_builtin_call 6261 1.1 mrg || targetm.check_builtin_call (loc, arg_loc, fndecl, 6262 1.1 mrg orig_fndecl, nargs, args)); 6263 1.1 mrg 6264 1.1 mrg if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_FRONTEND) 6265 1.1 mrg return true; 6266 1.1 mrg 6267 1.1 mrg gcc_assert (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL); 6268 1.1 mrg switch (DECL_FUNCTION_CODE (fndecl)) 6269 1.1 mrg { 6270 1.1 mrg case BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX: 6271 1.1 mrg if (!tree_fits_uhwi_p (args[2])) 6272 1.1 mrg { 6273 1.1 mrg error_at (ARG_LOCATION (2), 6274 1.1 mrg "third argument to function %qE must be a constant integer", 6275 1.1 mrg fndecl); 6276 1.1 mrg return false; 6277 1.1 mrg } 6278 1.1 mrg /* fall through */ 6279 1.1 mrg 6280 1.1 mrg case BUILT_IN_ALLOCA_WITH_ALIGN: 6281 1.1 mrg { 6282 1.1 mrg /* Get the requested alignment (in bits) if it's a constant 6283 1.1 mrg integer expression. */ 6284 1.1 mrg unsigned HOST_WIDE_INT align 6285 1.1 mrg = tree_fits_uhwi_p (args[1]) ? tree_to_uhwi (args[1]) : 0; 6286 1.1 mrg 6287 1.1 mrg /* Determine if the requested alignment is a power of 2. */ 6288 1.1 mrg if ((align & (align - 1))) 6289 1.1 mrg align = 0; 6290 1.1 mrg 6291 1.1 mrg /* The maximum alignment in bits corresponding to the same 6292 1.1 mrg maximum in bytes enforced in check_user_alignment(). */ 6293 1.1 mrg unsigned maxalign = (UINT_MAX >> 1) + 1; 6294 1.1 mrg 6295 1.1 mrg /* Reject invalid alignments. */ 6296 1.1 mrg if (align < BITS_PER_UNIT || maxalign < align) 6297 1.1 mrg { 6298 1.1 mrg error_at (ARG_LOCATION (1), 6299 1.1 mrg "second argument to function %qE must be a constant " 6300 1.1 mrg "integer power of 2 between %qi and %qu bits", 6301 1.1 mrg fndecl, BITS_PER_UNIT, maxalign); 6302 1.1 mrg return false; 6303 1.1 mrg } 6304 1.1 mrg return true; 6305 1.1 mrg } 6306 1.1 mrg 6307 1.1 mrg case BUILT_IN_CONSTANT_P: 6308 1.1 mrg return builtin_function_validate_nargs (loc, fndecl, nargs, 1); 6309 1.1 mrg 6310 1.1 mrg case BUILT_IN_ISFINITE: 6311 1.1 mrg case BUILT_IN_ISINF: 6312 1.1 mrg case BUILT_IN_ISINF_SIGN: 6313 1.1 mrg case BUILT_IN_ISNAN: 6314 1.1 mrg case BUILT_IN_ISNORMAL: 6315 1.1 mrg case BUILT_IN_SIGNBIT: 6316 1.1 mrg if (builtin_function_validate_nargs (loc, fndecl, nargs, 1)) 6317 1.1 mrg { 6318 1.1 mrg if (TREE_CODE (TREE_TYPE (args[0])) != REAL_TYPE) 6319 1.1 mrg { 6320 1.1 mrg error_at (ARG_LOCATION (0), "non-floating-point argument in " 6321 1.1 mrg "call to function %qE", fndecl); 6322 1.1 mrg return false; 6323 1.1 mrg } 6324 1.1 mrg return true; 6325 1.1 mrg } 6326 1.1 mrg return false; 6327 1.1 mrg 6328 1.1 mrg case BUILT_IN_ISGREATER: 6329 1.1 mrg case BUILT_IN_ISGREATEREQUAL: 6330 1.1 mrg case BUILT_IN_ISLESS: 6331 1.1 mrg case BUILT_IN_ISLESSEQUAL: 6332 1.1 mrg case BUILT_IN_ISLESSGREATER: 6333 1.1 mrg case BUILT_IN_ISUNORDERED: 6334 1.1 mrg if (builtin_function_validate_nargs (loc, fndecl, nargs, 2)) 6335 1.1 mrg { 6336 1.1 mrg enum tree_code code0, code1; 6337 1.1 mrg code0 = TREE_CODE (TREE_TYPE (args[0])); 6338 1.1 mrg code1 = TREE_CODE (TREE_TYPE (args[1])); 6339 1.1 mrg if (!((code0 == REAL_TYPE && code1 == REAL_TYPE) 6340 1.1 mrg || (code0 == REAL_TYPE && code1 == INTEGER_TYPE) 6341 1.1 mrg || (code0 == INTEGER_TYPE && code1 == REAL_TYPE))) 6342 1.1 mrg { 6343 1.1 mrg error_at (loc, "non-floating-point arguments in call to " 6344 1.1 mrg "function %qE", fndecl); 6345 1.1 mrg return false; 6346 1.1 mrg } 6347 1.1 mrg return true; 6348 1.1 mrg } 6349 1.1 mrg return false; 6350 1.1 mrg 6351 1.1 mrg case BUILT_IN_FPCLASSIFY: 6352 1.1 mrg if (builtin_function_validate_nargs (loc, fndecl, nargs, 6)) 6353 1.1 mrg { 6354 1.1 mrg for (unsigned int i = 0; i < 5; i++) 6355 1.1 mrg if (TREE_CODE (args[i]) != INTEGER_CST) 6356 1.1 mrg { 6357 1.1 mrg error_at (ARG_LOCATION (i), "non-const integer argument %u in " 6358 1.1 mrg "call to function %qE", i + 1, fndecl); 6359 1.1 mrg return false; 6360 1.1 mrg } 6361 1.1 mrg 6362 1.1 mrg if (TREE_CODE (TREE_TYPE (args[5])) != REAL_TYPE) 6363 1.1 mrg { 6364 1.1 mrg error_at (ARG_LOCATION (5), "non-floating-point argument in " 6365 1.1 mrg "call to function %qE", fndecl); 6366 1.1 mrg return false; 6367 1.1 mrg } 6368 1.1 mrg return true; 6369 1.1 mrg } 6370 1.1 mrg return false; 6371 1.1 mrg 6372 1.1 mrg case BUILT_IN_ASSUME_ALIGNED: 6373 1.1 mrg if (builtin_function_validate_nargs (loc, fndecl, nargs, 2 + (nargs > 2))) 6374 1.1 mrg { 6375 1.1 mrg if (nargs >= 3 && TREE_CODE (TREE_TYPE (args[2])) != INTEGER_TYPE) 6376 1.1 mrg { 6377 1.1 mrg error_at (ARG_LOCATION (2), "non-integer argument 3 in call to " 6378 1.1 mrg "function %qE", fndecl); 6379 1.1 mrg return false; 6380 1.1 mrg } 6381 1.1 mrg return true; 6382 1.1 mrg } 6383 1.1 mrg return false; 6384 1.1 mrg 6385 1.1 mrg case BUILT_IN_ADD_OVERFLOW: 6386 1.1 mrg case BUILT_IN_SUB_OVERFLOW: 6387 1.1 mrg case BUILT_IN_MUL_OVERFLOW: 6388 1.1 mrg if (builtin_function_validate_nargs (loc, fndecl, nargs, 3)) 6389 1.1 mrg { 6390 1.1 mrg unsigned i; 6391 1.1 mrg for (i = 0; i < 2; i++) 6392 1.1 mrg if (!INTEGRAL_TYPE_P (TREE_TYPE (args[i]))) 6393 1.1 mrg { 6394 1.1 mrg error_at (ARG_LOCATION (i), "argument %u in call to function " 6395 1.1 mrg "%qE does not have integral type", i + 1, fndecl); 6396 1.1 mrg return false; 6397 1.1 mrg } 6398 1.1 mrg if (TREE_CODE (TREE_TYPE (args[2])) != POINTER_TYPE 6399 1.1 mrg || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (args[2])))) 6400 1.1 mrg { 6401 1.1 mrg error_at (ARG_LOCATION (2), "argument 3 in call to function %qE " 6402 1.1 mrg "does not have pointer to integral type", fndecl); 6403 1.1 mrg return false; 6404 1.1 mrg } 6405 1.1 mrg else if (TREE_CODE (TREE_TYPE (TREE_TYPE (args[2]))) == ENUMERAL_TYPE) 6406 1.1 mrg { 6407 1.1 mrg error_at (ARG_LOCATION (2), "argument 3 in call to function %qE " 6408 1.1 mrg "has pointer to enumerated type", fndecl); 6409 1.1 mrg return false; 6410 1.1 mrg } 6411 1.1 mrg else if (TREE_CODE (TREE_TYPE (TREE_TYPE (args[2]))) == BOOLEAN_TYPE) 6412 1.1 mrg { 6413 1.1 mrg error_at (ARG_LOCATION (2), "argument 3 in call to function %qE " 6414 1.1 mrg "has pointer to boolean type", fndecl); 6415 1.1 mrg return false; 6416 1.1 mrg } 6417 1.1 mrg else if (TYPE_READONLY (TREE_TYPE (TREE_TYPE (args[2])))) 6418 1.1 mrg { 6419 1.1 mrg error_at (ARG_LOCATION (2), "argument %u in call to function %qE " 6420 1.1 mrg "has pointer to %qs type (%qT)", 3, fndecl, "const", 6421 1.1 mrg TREE_TYPE (args[2])); 6422 1.1 mrg return false; 6423 1.1 mrg } 6424 1.1 mrg else if (TYPE_ATOMIC (TREE_TYPE (TREE_TYPE (args[2])))) 6425 1.1 mrg { 6426 1.1 mrg error_at (ARG_LOCATION (2), "argument %u in call to function %qE " 6427 1.1 mrg "has pointer to %qs type (%qT)", 3, fndecl, 6428 1.1 mrg "_Atomic", TREE_TYPE (args[2])); 6429 1.1 mrg return false; 6430 1.1 mrg } 6431 1.1 mrg return true; 6432 1.1 mrg } 6433 1.1 mrg return false; 6434 1.1 mrg 6435 1.1 mrg case BUILT_IN_ADD_OVERFLOW_P: 6436 1.1 mrg case BUILT_IN_SUB_OVERFLOW_P: 6437 1.1 mrg case BUILT_IN_MUL_OVERFLOW_P: 6438 1.1 mrg if (builtin_function_validate_nargs (loc, fndecl, nargs, 3)) 6439 1.1 mrg { 6440 1.1 mrg unsigned i; 6441 1.1 mrg for (i = 0; i < 3; i++) 6442 1.1 mrg if (!INTEGRAL_TYPE_P (TREE_TYPE (args[i]))) 6443 1.1 mrg { 6444 1.1 mrg error_at (ARG_LOCATION (i), "argument %u in call to function " 6445 1.1 mrg "%qE does not have integral type", i + 1, fndecl); 6446 1.1 mrg return false; 6447 1.1 mrg } 6448 1.1 mrg if (TREE_CODE (TREE_TYPE (args[2])) == ENUMERAL_TYPE) 6449 1.1 mrg { 6450 1.1 mrg error_at (ARG_LOCATION (2), "argument 3 in call to function " 6451 1.1 mrg "%qE has enumerated type", fndecl); 6452 1.1 mrg return false; 6453 1.1 mrg } 6454 1.1 mrg else if (TREE_CODE (TREE_TYPE (args[2])) == BOOLEAN_TYPE) 6455 1.1 mrg { 6456 1.1 mrg error_at (ARG_LOCATION (2), "argument 3 in call to function " 6457 1.1 mrg "%qE has boolean type", fndecl); 6458 1.1 mrg return false; 6459 1.1 mrg } 6460 1.1 mrg return true; 6461 1.1 mrg } 6462 1.1 mrg return false; 6463 1.1 mrg 6464 1.1 mrg case BUILT_IN_CLEAR_PADDING: 6465 1.1 mrg if (builtin_function_validate_nargs (loc, fndecl, nargs, 1)) 6466 1.1 mrg { 6467 1.1 mrg if (!POINTER_TYPE_P (TREE_TYPE (args[0]))) 6468 1.1 mrg { 6469 1.1 mrg error_at (ARG_LOCATION (0), "argument %u in call to function " 6470 1.1 mrg "%qE does not have pointer type", 1, fndecl); 6471 1.1 mrg return false; 6472 1.1 mrg } 6473 1.1 mrg else if (!COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (args[0])))) 6474 1.1 mrg { 6475 1.1 mrg error_at (ARG_LOCATION (0), "argument %u in call to function " 6476 1.1 mrg "%qE points to incomplete type", 1, fndecl); 6477 1.1 mrg return false; 6478 1.1 mrg } 6479 1.1 mrg else if (TYPE_READONLY (TREE_TYPE (TREE_TYPE (args[0])))) 6480 1.1 mrg { 6481 1.1 mrg error_at (ARG_LOCATION (0), "argument %u in call to function %qE " 6482 1.1 mrg "has pointer to %qs type (%qT)", 1, fndecl, "const", 6483 1.1 mrg TREE_TYPE (args[0])); 6484 1.1 mrg return false; 6485 1.1 mrg } 6486 1.1 mrg else if (TYPE_ATOMIC (TREE_TYPE (TREE_TYPE (args[0])))) 6487 1.1 mrg { 6488 1.1 mrg error_at (ARG_LOCATION (0), "argument %u in call to function %qE " 6489 1.1 mrg "has pointer to %qs type (%qT)", 1, fndecl, 6490 1.1 mrg "_Atomic", TREE_TYPE (args[0])); 6491 1.1 mrg return false; 6492 1.1 mrg } 6493 1.1 mrg return true; 6494 1.1 mrg } 6495 1.1 mrg return false; 6496 1.1 mrg 6497 1.1 mrg default: 6498 1.1 mrg return true; 6499 1.1 mrg } 6500 1.1 mrg } 6501 1.1 mrg 6502 1.1 mrg /* Subroutine of c_parse_error. 6503 1.1 mrg Return the result of concatenating LHS and RHS. RHS is really 6504 1.1 mrg a string literal, its first character is indicated by RHS_START and 6505 1.1 mrg RHS_SIZE is its length (including the terminating NUL character). 6506 1.1 mrg 6507 1.1 mrg The caller is responsible for deleting the returned pointer. */ 6508 1.1 mrg 6509 1.1 mrg static char * 6510 1.1 mrg catenate_strings (const char *lhs, const char *rhs_start, int rhs_size) 6511 1.1 mrg { 6512 1.1 mrg const size_t lhs_size = strlen (lhs); 6513 1.1 mrg char *result = XNEWVEC (char, lhs_size + rhs_size); 6514 1.1 mrg memcpy (result, lhs, lhs_size); 6515 1.1 mrg memcpy (result + lhs_size, rhs_start, rhs_size); 6516 1.1 mrg return result; 6517 1.1 mrg } 6518 1.1 mrg 6519 1.1 mrg /* Issue the error given by GMSGID at RICHLOC, indicating that it occurred 6520 1.1 mrg before TOKEN, which had the associated VALUE. */ 6521 1.1 mrg 6522 1.1 mrg void 6523 1.1 mrg c_parse_error (const char *gmsgid, enum cpp_ttype token_type, 6524 1.1 mrg tree value, unsigned char token_flags, 6525 1.1 mrg rich_location *richloc) 6526 1.1 mrg { 6527 1.1 mrg #define catenate_messages(M1, M2) catenate_strings ((M1), (M2), sizeof (M2)) 6528 1.1 mrg 6529 1.1 mrg char *message = NULL; 6530 1.1 mrg 6531 1.1 mrg if (token_type == CPP_EOF) 6532 1.1 mrg message = catenate_messages (gmsgid, " at end of input"); 6533 1.1 mrg else if (token_type == CPP_CHAR 6534 1.1 mrg || token_type == CPP_WCHAR 6535 1.1 mrg || token_type == CPP_CHAR16 6536 1.1 mrg || token_type == CPP_CHAR32 6537 1.1 mrg || token_type == CPP_UTF8CHAR) 6538 1.1 mrg { 6539 1.1 mrg unsigned int val = TREE_INT_CST_LOW (value); 6540 1.1 mrg const char *prefix; 6541 1.1 mrg 6542 1.1 mrg switch (token_type) 6543 1.1 mrg { 6544 1.1 mrg default: 6545 1.1 mrg prefix = ""; 6546 1.1 mrg break; 6547 1.1 mrg case CPP_WCHAR: 6548 1.1 mrg prefix = "L"; 6549 1.1 mrg break; 6550 1.1 mrg case CPP_CHAR16: 6551 1.1 mrg prefix = "u"; 6552 1.1 mrg break; 6553 1.1 mrg case CPP_CHAR32: 6554 1.1 mrg prefix = "U"; 6555 1.1 mrg break; 6556 1.1 mrg case CPP_UTF8CHAR: 6557 1.1 mrg prefix = "u8"; 6558 1.1 mrg break; 6559 1.1 mrg } 6560 1.1 mrg 6561 1.1 mrg if (val <= UCHAR_MAX && ISGRAPH (val)) 6562 1.1 mrg message = catenate_messages (gmsgid, " before %s'%c'"); 6563 1.1 mrg else 6564 1.1 mrg message = catenate_messages (gmsgid, " before %s'\\x%x'"); 6565 1.1 mrg 6566 1.1 mrg error_at (richloc, message, prefix, val); 6567 1.1 mrg free (message); 6568 1.1 mrg message = NULL; 6569 1.1 mrg } 6570 1.1 mrg else if (token_type == CPP_CHAR_USERDEF 6571 1.1 mrg || token_type == CPP_WCHAR_USERDEF 6572 1.1 mrg || token_type == CPP_CHAR16_USERDEF 6573 1.1 mrg || token_type == CPP_CHAR32_USERDEF 6574 1.1 mrg || token_type == CPP_UTF8CHAR_USERDEF) 6575 1.1 mrg message = catenate_messages (gmsgid, 6576 1.1 mrg " before user-defined character literal"); 6577 1.1 mrg else if (token_type == CPP_STRING_USERDEF 6578 1.1 mrg || token_type == CPP_WSTRING_USERDEF 6579 1.1 mrg || token_type == CPP_STRING16_USERDEF 6580 1.1 mrg || token_type == CPP_STRING32_USERDEF 6581 1.1 mrg || token_type == CPP_UTF8STRING_USERDEF) 6582 1.1 mrg message = catenate_messages (gmsgid, " before user-defined string literal"); 6583 1.1 mrg else if (token_type == CPP_STRING 6584 1.1 mrg || token_type == CPP_WSTRING 6585 1.1 mrg || token_type == CPP_STRING16 6586 1.1 mrg || token_type == CPP_STRING32 6587 1.1 mrg || token_type == CPP_UTF8STRING) 6588 1.1 mrg message = catenate_messages (gmsgid, " before string constant"); 6589 1.1 mrg else if (token_type == CPP_NUMBER) 6590 1.1 mrg message = catenate_messages (gmsgid, " before numeric constant"); 6591 1.1 mrg else if (token_type == CPP_NAME) 6592 1.1 mrg { 6593 1.1 mrg message = catenate_messages (gmsgid, " before %qE"); 6594 1.1 mrg error_at (richloc, message, value); 6595 1.1 mrg free (message); 6596 1.1 mrg message = NULL; 6597 1.1 mrg } 6598 1.1 mrg else if (token_type == CPP_PRAGMA) 6599 1.1 mrg message = catenate_messages (gmsgid, " before %<#pragma%>"); 6600 1.1 mrg else if (token_type == CPP_PRAGMA_EOL) 6601 1.1 mrg message = catenate_messages (gmsgid, " before end of line"); 6602 1.1 mrg else if (token_type == CPP_DECLTYPE) 6603 1.1 mrg message = catenate_messages (gmsgid, " before %<decltype%>"); 6604 1.1 mrg else if (token_type < N_TTYPES) 6605 1.1 mrg { 6606 1.1 mrg message = catenate_messages (gmsgid, " before %qs token"); 6607 1.1 mrg error_at (richloc, message, cpp_type2name (token_type, token_flags)); 6608 1.1 mrg free (message); 6609 1.1 mrg message = NULL; 6610 1.1 mrg } 6611 1.1 mrg else 6612 1.1 mrg error_at (richloc, gmsgid); 6613 1.1 mrg 6614 1.1 mrg if (message) 6615 1.1 mrg { 6616 1.1 mrg error_at (richloc, message); 6617 1.1 mrg free (message); 6618 1.1 mrg } 6619 1.1 mrg #undef catenate_messages 6620 1.1 mrg } 6621 1.1 mrg 6622 1.1 mrg /* Return the gcc option code associated with the reason for a cpp 6623 1.1 mrg message, or 0 if none. */ 6624 1.1 mrg 6625 1.1 mrg static int 6626 1.1 mrg c_option_controlling_cpp_diagnostic (enum cpp_warning_reason reason) 6627 1.1 mrg { 6628 1.1 mrg const struct cpp_reason_option_codes_t *entry; 6629 1.1 mrg 6630 1.1 mrg for (entry = cpp_reason_option_codes; entry->reason != CPP_W_NONE; entry++) 6631 1.1 mrg { 6632 1.1 mrg if (entry->reason == reason) 6633 1.1 mrg return entry->option_code; 6634 1.1 mrg } 6635 1.1 mrg return 0; 6636 1.1 mrg } 6637 1.1 mrg 6638 1.1 mrg /* Callback from cpp_diagnostic for PFILE to print diagnostics from the 6639 1.1 mrg preprocessor. The diagnostic is of type LEVEL, with REASON set 6640 1.1 mrg to the reason code if LEVEL is represents a warning, at location 6641 1.1 mrg RICHLOC unless this is after lexing and the compiler's location 6642 1.1 mrg should be used instead; MSG is the translated message and AP 6643 1.1 mrg the arguments. Returns true if a diagnostic was emitted, false 6644 1.1 mrg otherwise. */ 6645 1.1 mrg 6646 1.1 mrg bool 6647 1.1 mrg c_cpp_diagnostic (cpp_reader *pfile ATTRIBUTE_UNUSED, 6648 1.1 mrg enum cpp_diagnostic_level level, 6649 1.1 mrg enum cpp_warning_reason reason, 6650 1.1 mrg rich_location *richloc, 6651 1.1 mrg const char *msg, va_list *ap) 6652 1.1 mrg { 6653 1.1 mrg diagnostic_info diagnostic; 6654 1.1 mrg diagnostic_t dlevel; 6655 1.1 mrg bool save_warn_system_headers = global_dc->dc_warn_system_headers; 6656 1.1 mrg bool ret; 6657 1.1 mrg 6658 1.1 mrg switch (level) 6659 1.1 mrg { 6660 1.1 mrg case CPP_DL_WARNING_SYSHDR: 6661 1.1 mrg if (flag_no_output) 6662 1.1 mrg return false; 6663 1.1 mrg global_dc->dc_warn_system_headers = 1; 6664 1.1 mrg /* Fall through. */ 6665 1.1 mrg case CPP_DL_WARNING: 6666 1.1 mrg if (flag_no_output) 6667 1.1 mrg return false; 6668 1.1 mrg dlevel = DK_WARNING; 6669 1.1 mrg break; 6670 1.1 mrg case CPP_DL_PEDWARN: 6671 1.1 mrg if (flag_no_output && !flag_pedantic_errors) 6672 1.1 mrg return false; 6673 1.1 mrg dlevel = DK_PEDWARN; 6674 1.1 mrg break; 6675 1.1 mrg case CPP_DL_ERROR: 6676 1.1 mrg dlevel = DK_ERROR; 6677 1.1 mrg break; 6678 1.1 mrg case CPP_DL_ICE: 6679 1.1 mrg dlevel = DK_ICE; 6680 1.1 mrg break; 6681 1.1 mrg case CPP_DL_NOTE: 6682 1.1 mrg dlevel = DK_NOTE; 6683 1.1 mrg break; 6684 1.1 mrg case CPP_DL_FATAL: 6685 1.1 mrg dlevel = DK_FATAL; 6686 1.1 mrg break; 6687 1.1 mrg default: 6688 1.1 mrg gcc_unreachable (); 6689 1.1 mrg } 6690 1.1 mrg if (done_lexing) 6691 1.1 mrg richloc->set_range (0, input_location, SHOW_RANGE_WITH_CARET); 6692 1.1 mrg diagnostic_set_info_translated (&diagnostic, msg, ap, 6693 1.1 mrg richloc, dlevel); 6694 1.1 mrg diagnostic_override_option_index 6695 1.1 mrg (&diagnostic, 6696 1.1 mrg c_option_controlling_cpp_diagnostic (reason)); 6697 1.1 mrg ret = diagnostic_report_diagnostic (global_dc, &diagnostic); 6698 1.1 mrg if (level == CPP_DL_WARNING_SYSHDR) 6699 1.1 mrg global_dc->dc_warn_system_headers = save_warn_system_headers; 6700 1.1 mrg return ret; 6701 1.1 mrg } 6702 1.1 mrg 6703 1.1 mrg /* Convert a character from the host to the target execution character 6704 1.1 mrg set. cpplib handles this, mostly. */ 6705 1.1 mrg 6706 1.1 mrg HOST_WIDE_INT 6707 1.1 mrg c_common_to_target_charset (HOST_WIDE_INT c) 6708 1.1 mrg { 6709 1.1 mrg /* Character constants in GCC proper are sign-extended under -fsigned-char, 6710 1.1 mrg zero-extended under -fno-signed-char. cpplib insists that characters 6711 1.1 mrg and character constants are always unsigned. Hence we must convert 6712 1.1 mrg back and forth. */ 6713 1.1 mrg cppchar_t uc = ((cppchar_t)c) & ((((cppchar_t)1) << CHAR_BIT)-1); 6714 1.1 mrg 6715 1.1 mrg uc = cpp_host_to_exec_charset (parse_in, uc); 6716 1.1 mrg 6717 1.1 mrg if (flag_signed_char) 6718 1.1 mrg return ((HOST_WIDE_INT)uc) << (HOST_BITS_PER_WIDE_INT - CHAR_TYPE_SIZE) 6719 1.1 mrg >> (HOST_BITS_PER_WIDE_INT - CHAR_TYPE_SIZE); 6720 1.1 mrg else 6721 1.1 mrg return uc; 6722 1.1 mrg } 6723 1.1 mrg 6724 1.1 mrg /* Fold an offsetof-like expression. EXPR is a nested sequence of component 6725 1.1 mrg references with an INDIRECT_REF of a constant at the bottom; much like the 6726 1.1 mrg traditional rendering of offsetof as a macro. TYPE is the desired type of 6727 1.1 mrg the whole expression. Return the folded result. */ 6728 1.1 mrg 6729 1.1 mrg tree 6730 1.1 mrg fold_offsetof (tree expr, tree type, enum tree_code ctx) 6731 1.1 mrg { 6732 1.1 mrg tree base, off, t; 6733 1.1 mrg tree_code code = TREE_CODE (expr); 6734 1.1 mrg switch (code) 6735 1.1 mrg { 6736 1.1 mrg case ERROR_MARK: 6737 1.1 mrg return expr; 6738 1.1 mrg 6739 1.1 mrg case VAR_DECL: 6740 1.1 mrg error ("cannot apply %<offsetof%> to static data member %qD", expr); 6741 1.1 mrg return error_mark_node; 6742 1.1 mrg 6743 1.1 mrg case CALL_EXPR: 6744 1.1 mrg case TARGET_EXPR: 6745 1.1 mrg error ("cannot apply %<offsetof%> when %<operator[]%> is overloaded"); 6746 1.1 mrg return error_mark_node; 6747 1.1 mrg 6748 1.1 mrg case NOP_EXPR: 6749 1.1 mrg case INDIRECT_REF: 6750 1.1 mrg if (!TREE_CONSTANT (TREE_OPERAND (expr, 0))) 6751 1.1 mrg { 6752 1.1 mrg error ("cannot apply %<offsetof%> to a non constant address"); 6753 1.1 mrg return error_mark_node; 6754 1.1 mrg } 6755 1.1 mrg return convert (type, TREE_OPERAND (expr, 0)); 6756 1.1 mrg 6757 1.1 mrg case COMPONENT_REF: 6758 1.1 mrg base = fold_offsetof (TREE_OPERAND (expr, 0), type, code); 6759 1.1 mrg if (base == error_mark_node) 6760 1.1 mrg return base; 6761 1.1 mrg 6762 1.1 mrg t = TREE_OPERAND (expr, 1); 6763 1.1 mrg if (DECL_C_BIT_FIELD (t)) 6764 1.1 mrg { 6765 1.1 mrg error ("attempt to take address of bit-field structure " 6766 1.1 mrg "member %qD", t); 6767 1.1 mrg return error_mark_node; 6768 1.1 mrg } 6769 1.1 mrg off = size_binop_loc (input_location, PLUS_EXPR, DECL_FIELD_OFFSET (t), 6770 1.1 mrg size_int (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (t)) 6771 1.1 mrg / BITS_PER_UNIT)); 6772 1.1 mrg break; 6773 1.1 mrg 6774 1.1 mrg case ARRAY_REF: 6775 1.1 mrg base = fold_offsetof (TREE_OPERAND (expr, 0), type, code); 6776 1.1 mrg if (base == error_mark_node) 6777 1.1 mrg return base; 6778 1.1 mrg 6779 1.1 mrg t = TREE_OPERAND (expr, 1); 6780 1.1 mrg STRIP_ANY_LOCATION_WRAPPER (t); 6781 1.1 mrg 6782 1.1 mrg /* Check if the offset goes beyond the upper bound of the array. */ 6783 1.1 mrg if (TREE_CODE (t) == INTEGER_CST && tree_int_cst_sgn (t) >= 0) 6784 1.1 mrg { 6785 1.1 mrg tree upbound = array_ref_up_bound (expr); 6786 1.1 mrg if (upbound != NULL_TREE 6787 1.1 mrg && TREE_CODE (upbound) == INTEGER_CST 6788 1.1 mrg && !tree_int_cst_equal (upbound, 6789 1.1 mrg TYPE_MAX_VALUE (TREE_TYPE (upbound)))) 6790 1.1 mrg { 6791 1.1 mrg if (ctx != ARRAY_REF && ctx != COMPONENT_REF) 6792 1.1 mrg upbound = size_binop (PLUS_EXPR, upbound, 6793 1.1 mrg build_int_cst (TREE_TYPE (upbound), 1)); 6794 1.1 mrg if (tree_int_cst_lt (upbound, t)) 6795 1.1 mrg { 6796 1.1 mrg tree v; 6797 1.1 mrg 6798 1.1 mrg for (v = TREE_OPERAND (expr, 0); 6799 1.1 mrg TREE_CODE (v) == COMPONENT_REF; 6800 1.1 mrg v = TREE_OPERAND (v, 0)) 6801 1.1 mrg if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0))) 6802 1.1 mrg == RECORD_TYPE) 6803 1.1 mrg { 6804 1.1 mrg tree fld_chain = DECL_CHAIN (TREE_OPERAND (v, 1)); 6805 1.1 mrg for (; fld_chain; fld_chain = DECL_CHAIN (fld_chain)) 6806 1.1 mrg if (TREE_CODE (fld_chain) == FIELD_DECL) 6807 1.1 mrg break; 6808 1.1 mrg 6809 1.1 mrg if (fld_chain) 6810 1.1 mrg break; 6811 1.1 mrg } 6812 1.1 mrg /* Don't warn if the array might be considered a poor 6813 1.1 mrg man's flexible array member with a very permissive 6814 1.1 mrg definition thereof. */ 6815 1.1 mrg if (TREE_CODE (v) == ARRAY_REF 6816 1.1 mrg || TREE_CODE (v) == COMPONENT_REF) 6817 1.1 mrg warning (OPT_Warray_bounds, 6818 1.1 mrg "index %E denotes an offset " 6819 1.1 mrg "greater than size of %qT", 6820 1.1 mrg t, TREE_TYPE (TREE_OPERAND (expr, 0))); 6821 1.1 mrg } 6822 1.1 mrg } 6823 1.1 mrg } 6824 1.1 mrg 6825 1.1 mrg t = convert (sizetype, t); 6826 1.1 mrg off = size_binop (MULT_EXPR, TYPE_SIZE_UNIT (TREE_TYPE (expr)), t); 6827 1.1 mrg break; 6828 1.1 mrg 6829 1.1 mrg case COMPOUND_EXPR: 6830 1.1 mrg /* Handle static members of volatile structs. */ 6831 1.1 mrg t = TREE_OPERAND (expr, 1); 6832 1.1 mrg gcc_checking_assert (VAR_P (get_base_address (t))); 6833 1.1 mrg return fold_offsetof (t, type); 6834 1.1 mrg 6835 1.1 mrg default: 6836 1.1 mrg gcc_unreachable (); 6837 1.1 mrg } 6838 1.1 mrg 6839 1.1 mrg if (!POINTER_TYPE_P (type)) 6840 1.1 mrg return size_binop (PLUS_EXPR, base, convert (type, off)); 6841 1.1 mrg return fold_build_pointer_plus (base, off); 6842 1.1 mrg } 6843 1.1 mrg 6844 1.1 mrg /* *PTYPE is an incomplete array. Complete it with a domain based on 6846 1.1 mrg INITIAL_VALUE. If INITIAL_VALUE is not present, use 1 if DO_DEFAULT 6847 1.1 mrg is true. Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered, 6848 1.1 mrg 2 if INITIAL_VALUE was NULL, and 3 if INITIAL_VALUE was empty. */ 6849 1.1 mrg 6850 1.1 mrg int 6851 1.1 mrg complete_array_type (tree *ptype, tree initial_value, bool do_default) 6852 1.1 mrg { 6853 1.1 mrg tree maxindex, type, main_type, elt, unqual_elt; 6854 1.1 mrg int failure = 0, quals; 6855 1.1 mrg bool overflow_p = false; 6856 1.1 mrg 6857 1.1 mrg maxindex = size_zero_node; 6858 1.1 mrg if (initial_value) 6859 1.1 mrg { 6860 1.1 mrg STRIP_ANY_LOCATION_WRAPPER (initial_value); 6861 1.1 mrg 6862 1.1 mrg if (TREE_CODE (initial_value) == STRING_CST) 6863 1.1 mrg { 6864 1.1 mrg int eltsize 6865 1.1 mrg = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value))); 6866 1.1 mrg maxindex = size_int (TREE_STRING_LENGTH (initial_value)/eltsize - 1); 6867 1.1 mrg } 6868 1.1 mrg else if (TREE_CODE (initial_value) == CONSTRUCTOR) 6869 1.1 mrg { 6870 1.1 mrg vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (initial_value); 6871 1.1 mrg 6872 1.1 mrg if (vec_safe_is_empty (v)) 6873 1.1 mrg { 6874 1.1 mrg if (pedantic) 6875 1.1 mrg failure = 3; 6876 1.1 mrg maxindex = ssize_int (-1); 6877 1.1 mrg } 6878 1.1 mrg else 6879 1.1 mrg { 6880 1.1 mrg tree curindex; 6881 1.1 mrg unsigned HOST_WIDE_INT cnt; 6882 1.1 mrg constructor_elt *ce; 6883 1.1 mrg bool fold_p = false; 6884 1.1 mrg 6885 1.1 mrg if ((*v)[0].index) 6886 1.1 mrg maxindex = (*v)[0].index, fold_p = true; 6887 1.1 mrg 6888 1.1 mrg curindex = maxindex; 6889 1.1 mrg 6890 1.1 mrg for (cnt = 1; vec_safe_iterate (v, cnt, &ce); cnt++) 6891 1.1 mrg { 6892 1.1 mrg bool curfold_p = false; 6893 1.1 mrg if (ce->index) 6894 1.1 mrg curindex = ce->index, curfold_p = true; 6895 1.1 mrg else 6896 1.1 mrg { 6897 1.1 mrg if (fold_p) 6898 1.1 mrg { 6899 1.1 mrg /* Since we treat size types now as ordinary 6900 1.1 mrg unsigned types, we need an explicit overflow 6901 1.1 mrg check. */ 6902 1.1 mrg tree orig = curindex; 6903 1.1 mrg curindex = fold_convert (sizetype, curindex); 6904 1.1 mrg overflow_p |= tree_int_cst_lt (curindex, orig); 6905 1.1 mrg } 6906 1.1 mrg curindex = size_binop (PLUS_EXPR, curindex, 6907 1.1 mrg size_one_node); 6908 1.1 mrg } 6909 1.1 mrg if (tree_int_cst_lt (maxindex, curindex)) 6910 1.1 mrg maxindex = curindex, fold_p = curfold_p; 6911 1.1 mrg } 6912 1.1 mrg if (fold_p) 6913 1.1 mrg { 6914 1.1 mrg tree orig = maxindex; 6915 1.1 mrg maxindex = fold_convert (sizetype, maxindex); 6916 1.1 mrg overflow_p |= tree_int_cst_lt (maxindex, orig); 6917 1.1 mrg } 6918 1.1 mrg } 6919 1.1 mrg } 6920 1.1 mrg else 6921 1.1 mrg { 6922 1.1 mrg /* Make an error message unless that happened already. */ 6923 1.1 mrg if (initial_value != error_mark_node) 6924 1.1 mrg failure = 1; 6925 1.1 mrg } 6926 1.1 mrg } 6927 1.1 mrg else 6928 1.1 mrg { 6929 1.1 mrg failure = 2; 6930 1.1 mrg if (!do_default) 6931 1.1 mrg return failure; 6932 1.1 mrg } 6933 1.1 mrg 6934 1.1 mrg type = *ptype; 6935 1.1 mrg elt = TREE_TYPE (type); 6936 1.1 mrg quals = TYPE_QUALS (strip_array_types (elt)); 6937 1.1 mrg if (quals == 0) 6938 1.1 mrg unqual_elt = elt; 6939 1.1 mrg else 6940 1.1 mrg unqual_elt = c_build_qualified_type (elt, KEEP_QUAL_ADDR_SPACE (quals)); 6941 1.1 mrg 6942 1.1 mrg /* Using build_distinct_type_copy and modifying things afterward instead 6943 1.1 mrg of using build_array_type to create a new type preserves all of the 6944 1.1 mrg TYPE_LANG_FLAG_? bits that the front end may have set. */ 6945 1.1 mrg main_type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type)); 6946 1.1 mrg TREE_TYPE (main_type) = unqual_elt; 6947 1.1 mrg TYPE_DOMAIN (main_type) 6948 1.1 mrg = build_range_type (TREE_TYPE (maxindex), 6949 1.1 mrg build_int_cst (TREE_TYPE (maxindex), 0), maxindex); 6950 1.1 mrg TYPE_TYPELESS_STORAGE (main_type) = TYPE_TYPELESS_STORAGE (type); 6951 1.1 mrg layout_type (main_type); 6952 1.1 mrg 6953 1.1 mrg /* Make sure we have the canonical MAIN_TYPE. */ 6954 1.1 mrg hashval_t hashcode = type_hash_canon_hash (main_type); 6955 1.1 mrg main_type = type_hash_canon (hashcode, main_type); 6956 1.1 mrg 6957 1.1 mrg /* Fix the canonical type. */ 6958 1.1 mrg if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type)) 6959 1.1 mrg || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type))) 6960 1.1 mrg SET_TYPE_STRUCTURAL_EQUALITY (main_type); 6961 1.1 mrg else if (TYPE_CANONICAL (TREE_TYPE (main_type)) != TREE_TYPE (main_type) 6962 1.1 mrg || (TYPE_CANONICAL (TYPE_DOMAIN (main_type)) 6963 1.1 mrg != TYPE_DOMAIN (main_type))) 6964 1.1 mrg TYPE_CANONICAL (main_type) 6965 1.1 mrg = build_array_type (TYPE_CANONICAL (TREE_TYPE (main_type)), 6966 1.1 mrg TYPE_CANONICAL (TYPE_DOMAIN (main_type)), 6967 1.1 mrg TYPE_TYPELESS_STORAGE (main_type)); 6968 1.1 mrg else 6969 1.1 mrg TYPE_CANONICAL (main_type) = main_type; 6970 1.1 mrg 6971 1.1 mrg if (quals == 0) 6972 1.1 mrg type = main_type; 6973 1.1 mrg else 6974 1.1 mrg type = c_build_qualified_type (main_type, quals); 6975 1.1 mrg 6976 1.1 mrg if (COMPLETE_TYPE_P (type) 6977 1.1 mrg && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST 6978 1.1 mrg && (overflow_p || TREE_OVERFLOW (TYPE_SIZE_UNIT (type)))) 6979 1.1 mrg { 6980 1.1 mrg error ("size of array is too large"); 6981 1.1 mrg /* If we proceed with the array type as it is, we'll eventually 6982 1.1 mrg crash in tree_to_[su]hwi(). */ 6983 1.1 mrg type = error_mark_node; 6984 1.1 mrg } 6985 1.1 mrg 6986 1.1 mrg *ptype = type; 6987 1.1 mrg return failure; 6988 1.1 mrg } 6989 1.1 mrg 6990 1.1 mrg /* INIT is an constructor of a structure with a flexible array member. 6991 1.1 mrg Complete the flexible array member with a domain based on it's value. */ 6992 1.1 mrg void 6993 1.1 mrg complete_flexible_array_elts (tree init) 6994 1.1 mrg { 6995 1.1 mrg tree elt, type; 6996 1.1 mrg 6997 1.1 mrg if (init == NULL_TREE || TREE_CODE (init) != CONSTRUCTOR) 6998 1.1 mrg return; 6999 1.1 mrg 7000 1.1 mrg if (vec_safe_is_empty (CONSTRUCTOR_ELTS (init))) 7001 1.1 mrg return; 7002 1.1 mrg 7003 1.1 mrg elt = CONSTRUCTOR_ELTS (init)->last ().value; 7004 1.1 mrg type = TREE_TYPE (elt); 7005 1.1 mrg if (TREE_CODE (type) == ARRAY_TYPE 7006 1.1 mrg && TYPE_SIZE (type) == NULL_TREE) 7007 1.1 mrg complete_array_type (&TREE_TYPE (elt), elt, false); 7008 1.1 mrg else 7009 1.1 mrg complete_flexible_array_elts (elt); 7010 1.1 mrg } 7011 1.1 mrg 7012 1.1 mrg /* Like c_mark_addressable but don't check register qualifier. */ 7013 1.1 mrg void 7014 1.1 mrg c_common_mark_addressable_vec (tree t) 7015 1.1 mrg { 7016 1.1 mrg while (handled_component_p (t) || TREE_CODE (t) == C_MAYBE_CONST_EXPR) 7017 1.1 mrg { 7018 1.1 mrg if (TREE_CODE (t) == C_MAYBE_CONST_EXPR) 7019 1.1 mrg t = C_MAYBE_CONST_EXPR_EXPR (t); 7020 1.1 mrg else 7021 1.1 mrg t = TREE_OPERAND (t, 0); 7022 1.1 mrg } 7023 1.1 mrg if (!VAR_P (t) 7024 1.1 mrg && TREE_CODE (t) != PARM_DECL 7025 1.1 mrg && TREE_CODE (t) != COMPOUND_LITERAL_EXPR 7026 1.1 mrg && TREE_CODE (t) != TARGET_EXPR) 7027 1.1 mrg return; 7028 1.1 mrg if (!VAR_P (t) || !DECL_HARD_REGISTER (t)) 7029 1.1 mrg TREE_ADDRESSABLE (t) = 1; 7030 1.1 mrg if (TREE_CODE (t) == COMPOUND_LITERAL_EXPR) 7031 1.1 mrg TREE_ADDRESSABLE (COMPOUND_LITERAL_EXPR_DECL (t)) = 1; 7032 1.1 mrg else if (TREE_CODE (t) == TARGET_EXPR) 7033 1.1 mrg TREE_ADDRESSABLE (TARGET_EXPR_SLOT (t)) = 1; 7034 1.1 mrg } 7035 1.1 mrg 7036 1.1 mrg 7037 1.1 mrg 7038 1.1 mrg /* Used to help initialize the builtin-types.def table. When a type of 7040 1.1 mrg the correct size doesn't exist, use error_mark_node instead of NULL. 7041 1.1 mrg The later results in segfaults even when a decl using the type doesn't 7042 1.1 mrg get invoked. */ 7043 1.1 mrg 7044 1.1 mrg tree 7045 1.1 mrg builtin_type_for_size (int size, bool unsignedp) 7046 1.1 mrg { 7047 1.1 mrg tree type = c_common_type_for_size (size, unsignedp); 7048 1.1 mrg return type ? type : error_mark_node; 7049 1.1 mrg } 7050 1.1 mrg 7051 1.1 mrg /* Work out the size of the first argument of a call to 7052 1.1 mrg __builtin_speculation_safe_value. Only pointers and integral types 7053 1.1 mrg are permitted. Return -1 if the argument type is not supported or 7054 1.1 mrg the size is too large; 0 if the argument type is a pointer or the 7055 1.1 mrg size if it is integral. */ 7056 1.1 mrg static enum built_in_function 7057 1.1 mrg speculation_safe_value_resolve_call (tree function, vec<tree, va_gc> *params) 7058 1.1 mrg { 7059 1.1 mrg /* Type of the argument. */ 7060 1.1 mrg tree type; 7061 1.1 mrg int size; 7062 1.1 mrg 7063 1.1 mrg if (vec_safe_is_empty (params)) 7064 1.1 mrg { 7065 1.1 mrg error ("too few arguments to function %qE", function); 7066 1.1 mrg return BUILT_IN_NONE; 7067 1.1 mrg } 7068 1.1 mrg 7069 1.1 mrg type = TREE_TYPE ((*params)[0]); 7070 1.1 mrg if (TREE_CODE (type) == ARRAY_TYPE && c_dialect_cxx ()) 7071 1.1 mrg { 7072 1.1 mrg /* Force array-to-pointer decay for C++. */ 7073 1.1 mrg (*params)[0] = default_conversion ((*params)[0]); 7074 1.1 mrg type = TREE_TYPE ((*params)[0]); 7075 1.1 mrg } 7076 1.1 mrg 7077 1.1 mrg if (POINTER_TYPE_P (type)) 7078 1.1 mrg return BUILT_IN_SPECULATION_SAFE_VALUE_PTR; 7079 1.1 mrg 7080 1.1 mrg if (!INTEGRAL_TYPE_P (type)) 7081 1.1 mrg goto incompatible; 7082 1.1 mrg 7083 1.1 mrg if (!COMPLETE_TYPE_P (type)) 7084 1.1 mrg goto incompatible; 7085 1.1 mrg 7086 1.1 mrg size = tree_to_uhwi (TYPE_SIZE_UNIT (type)); 7087 1.1 mrg if (size == 1 || size == 2 || size == 4 || size == 8 || size == 16) 7088 1.1 mrg return ((enum built_in_function) 7089 1.1 mrg ((int) BUILT_IN_SPECULATION_SAFE_VALUE_1 + exact_log2 (size))); 7090 1.1 mrg 7091 1.1 mrg incompatible: 7092 1.1 mrg /* Issue the diagnostic only if the argument is valid, otherwise 7093 1.1 mrg it would be redundant at best and could be misleading. */ 7094 1.1 mrg if (type != error_mark_node) 7095 1.1 mrg error ("operand type %qT is incompatible with argument %d of %qE", 7096 1.1 mrg type, 1, function); 7097 1.1 mrg 7098 1.1 mrg return BUILT_IN_NONE; 7099 1.1 mrg } 7100 1.1 mrg 7101 1.1 mrg /* Validate and coerce PARAMS, the arguments to ORIG_FUNCTION to fit 7102 1.1 mrg the prototype for FUNCTION. The first argument is mandatory, a second 7103 1.1 mrg argument, if present, must be type compatible with the first. */ 7104 1.1 mrg static bool 7105 1.1 mrg speculation_safe_value_resolve_params (location_t loc, tree orig_function, 7106 1.1 mrg vec<tree, va_gc> *params) 7107 1.1 mrg { 7108 1.1 mrg tree val; 7109 1.1 mrg 7110 1.1 mrg if (params->length () == 0) 7111 1.1 mrg { 7112 1.1 mrg error_at (loc, "too few arguments to function %qE", orig_function); 7113 1.1 mrg return false; 7114 1.1 mrg } 7115 1.1 mrg 7116 1.1 mrg else if (params->length () > 2) 7117 1.1 mrg { 7118 1.1 mrg error_at (loc, "too many arguments to function %qE", orig_function); 7119 1.1 mrg return false; 7120 1.1 mrg } 7121 1.1 mrg 7122 1.1 mrg val = (*params)[0]; 7123 1.1 mrg if (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE) 7124 1.1 mrg val = default_conversion (val); 7125 1.1 mrg if (!(TREE_CODE (TREE_TYPE (val)) == POINTER_TYPE 7126 1.1 mrg || TREE_CODE (TREE_TYPE (val)) == INTEGER_TYPE)) 7127 1.1 mrg { 7128 1.1 mrg error_at (loc, 7129 1.1 mrg "expecting argument of type pointer or of type integer " 7130 1.1 mrg "for argument 1"); 7131 1.1 mrg return false; 7132 1.1 mrg } 7133 1.1 mrg (*params)[0] = val; 7134 1.1 mrg 7135 1.1 mrg if (params->length () == 2) 7136 1.1 mrg { 7137 1.1 mrg tree val2 = (*params)[1]; 7138 1.1 mrg if (TREE_CODE (TREE_TYPE (val2)) == ARRAY_TYPE) 7139 1.1 mrg val2 = default_conversion (val2); 7140 1.1 mrg if (error_operand_p (val2)) 7141 1.1 mrg return false; 7142 1.1 mrg if (!(TREE_TYPE (val) == TREE_TYPE (val2) 7143 1.1 mrg || useless_type_conversion_p (TREE_TYPE (val), TREE_TYPE (val2)))) 7144 1.1 mrg { 7145 1.1 mrg error_at (loc, "both arguments must be compatible"); 7146 1.1 mrg return false; 7147 1.1 mrg } 7148 1.1 mrg (*params)[1] = val2; 7149 1.1 mrg } 7150 1.1 mrg 7151 1.1 mrg return true; 7152 1.1 mrg } 7153 1.1 mrg 7154 1.1 mrg /* Cast the result of the builtin back to the type of the first argument, 7155 1.1 mrg preserving any qualifiers that it might have. */ 7156 1.1 mrg static tree 7157 1.1 mrg speculation_safe_value_resolve_return (tree first_param, tree result) 7158 1.1 mrg { 7159 1.1 mrg tree ptype = TREE_TYPE (first_param); 7160 1.1 mrg tree rtype = TREE_TYPE (result); 7161 1.1 mrg ptype = TYPE_MAIN_VARIANT (ptype); 7162 1.1 mrg 7163 1.1 mrg if (tree_int_cst_equal (TYPE_SIZE (ptype), TYPE_SIZE (rtype))) 7164 1.1 mrg return convert (ptype, result); 7165 1.1 mrg 7166 1.1 mrg return result; 7167 1.1 mrg } 7168 1.1 mrg 7169 1.1 mrg /* A helper function for resolve_overloaded_builtin in resolving the 7170 1.1 mrg overloaded __sync_ builtins. Returns a positive power of 2 if the 7171 1.1 mrg first operand of PARAMS is a pointer to a supported data type. 7172 1.1 mrg Returns 0 if an error is encountered. 7173 1.1 mrg FETCH is true when FUNCTION is one of the _FETCH_OP_ or _OP_FETCH_ 7174 1.1 mrg built-ins. */ 7175 1.1 mrg 7176 1.1 mrg static int 7177 1.1 mrg sync_resolve_size (tree function, vec<tree, va_gc> *params, bool fetch) 7178 1.1 mrg { 7179 1.1 mrg /* Type of the argument. */ 7180 1.1 mrg tree argtype; 7181 1.1 mrg /* Type the argument points to. */ 7182 1.1 mrg tree type; 7183 1.1 mrg int size; 7184 1.1 mrg 7185 1.1 mrg if (vec_safe_is_empty (params)) 7186 1.1 mrg { 7187 1.1 mrg error ("too few arguments to function %qE", function); 7188 1.1 mrg return 0; 7189 1.1 mrg } 7190 1.1 mrg 7191 1.1 mrg argtype = type = TREE_TYPE ((*params)[0]); 7192 1.1 mrg if (TREE_CODE (type) == ARRAY_TYPE && c_dialect_cxx ()) 7193 1.1 mrg { 7194 1.1 mrg /* Force array-to-pointer decay for C++. */ 7195 1.1 mrg (*params)[0] = default_conversion ((*params)[0]); 7196 1.1 mrg type = TREE_TYPE ((*params)[0]); 7197 1.1 mrg } 7198 1.1 mrg if (TREE_CODE (type) != POINTER_TYPE) 7199 1.1 mrg goto incompatible; 7200 1.1 mrg 7201 1.1 mrg type = TREE_TYPE (type); 7202 1.1 mrg if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type)) 7203 1.1 mrg goto incompatible; 7204 1.1 mrg 7205 1.1 mrg if (!COMPLETE_TYPE_P (type)) 7206 1.1 mrg goto incompatible; 7207 1.1 mrg 7208 1.1 mrg if (fetch && TREE_CODE (type) == BOOLEAN_TYPE) 7209 1.1 mrg goto incompatible; 7210 1.1 mrg 7211 1.1 mrg size = tree_to_uhwi (TYPE_SIZE_UNIT (type)); 7212 1.1 mrg if (size == 1 || size == 2 || size == 4 || size == 8 || size == 16) 7213 1.1 mrg return size; 7214 1.1 mrg 7215 1.1 mrg incompatible: 7216 1.1 mrg /* Issue the diagnostic only if the argument is valid, otherwise 7217 1.1 mrg it would be redundant at best and could be misleading. */ 7218 1.1 mrg if (argtype != error_mark_node) 7219 1.1 mrg error ("operand type %qT is incompatible with argument %d of %qE", 7220 1.1 mrg argtype, 1, function); 7221 1.1 mrg return 0; 7222 1.1 mrg } 7223 1.1 mrg 7224 1.1 mrg /* A helper function for resolve_overloaded_builtin. Adds casts to 7225 1.1 mrg PARAMS to make arguments match up with those of FUNCTION. Drops 7226 1.1 mrg the variadic arguments at the end. Returns false if some error 7227 1.1 mrg was encountered; true on success. */ 7228 1.1 mrg 7229 1.1 mrg static bool 7230 1.1 mrg sync_resolve_params (location_t loc, tree orig_function, tree function, 7231 1.1 mrg vec<tree, va_gc> *params, bool orig_format) 7232 1.1 mrg { 7233 1.1 mrg function_args_iterator iter; 7234 1.1 mrg tree ptype; 7235 1.1 mrg unsigned int parmnum; 7236 1.1 mrg 7237 1.1 mrg function_args_iter_init (&iter, TREE_TYPE (function)); 7238 1.1 mrg /* We've declared the implementation functions to use "volatile void *" 7239 1.1 mrg as the pointer parameter, so we shouldn't get any complaints from the 7240 1.1 mrg call to check_function_arguments what ever type the user used. */ 7241 1.1 mrg function_args_iter_next (&iter); 7242 1.1 mrg ptype = TREE_TYPE (TREE_TYPE ((*params)[0])); 7243 1.1 mrg ptype = TYPE_MAIN_VARIANT (ptype); 7244 1.1 mrg 7245 1.1 mrg /* For the rest of the values, we need to cast these to FTYPE, so that we 7246 1.1 mrg don't get warnings for passing pointer types, etc. */ 7247 1.1 mrg parmnum = 0; 7248 1.1 mrg while (1) 7249 1.1 mrg { 7250 1.1 mrg tree val, arg_type; 7251 1.1 mrg 7252 1.1 mrg arg_type = function_args_iter_cond (&iter); 7253 1.1 mrg /* XXX void_type_node belies the abstraction. */ 7254 1.1 mrg if (arg_type == void_type_node) 7255 1.1 mrg break; 7256 1.1 mrg 7257 1.1 mrg ++parmnum; 7258 1.1 mrg if (params->length () <= parmnum) 7259 1.1 mrg { 7260 1.1 mrg error_at (loc, "too few arguments to function %qE", orig_function); 7261 1.1 mrg return false; 7262 1.1 mrg } 7263 1.1 mrg 7264 1.1 mrg /* Only convert parameters if arg_type is unsigned integer type with 7265 1.1 mrg new format sync routines, i.e. don't attempt to convert pointer 7266 1.1 mrg arguments (e.g. EXPECTED argument of __atomic_compare_exchange_n), 7267 1.1 mrg bool arguments (e.g. WEAK argument) or signed int arguments (memmodel 7268 1.1 mrg kinds). */ 7269 1.1 mrg if (TREE_CODE (arg_type) == INTEGER_TYPE && TYPE_UNSIGNED (arg_type)) 7270 1.1 mrg { 7271 1.1 mrg /* Ideally for the first conversion we'd use convert_for_assignment 7272 1.1 mrg so that we get warnings for anything that doesn't match the pointer 7273 1.1 mrg type. This isn't portable across the C and C++ front ends atm. */ 7274 1.1 mrg val = (*params)[parmnum]; 7275 1.1 mrg val = convert (ptype, val); 7276 1.1 mrg val = convert (arg_type, val); 7277 1.1 mrg (*params)[parmnum] = val; 7278 1.1 mrg } 7279 1.1 mrg 7280 1.1 mrg function_args_iter_next (&iter); 7281 1.1 mrg } 7282 1.1 mrg 7283 1.1 mrg /* __atomic routines are not variadic. */ 7284 1.1 mrg if (!orig_format && params->length () != parmnum + 1) 7285 1.1 mrg { 7286 1.1 mrg error_at (loc, "too many arguments to function %qE", orig_function); 7287 1.1 mrg return false; 7288 1.1 mrg } 7289 1.1 mrg 7290 1.1 mrg /* The definition of these primitives is variadic, with the remaining 7291 1.1 mrg being "an optional list of variables protected by the memory barrier". 7292 1.1 mrg No clue what that's supposed to mean, precisely, but we consider all 7293 1.1 mrg call-clobbered variables to be protected so we're safe. */ 7294 1.1 mrg params->truncate (parmnum + 1); 7295 1.1 mrg 7296 1.1 mrg return true; 7297 1.1 mrg } 7298 1.1 mrg 7299 1.1 mrg /* A helper function for resolve_overloaded_builtin. Adds a cast to 7300 1.1 mrg RESULT to make it match the type of the first pointer argument in 7301 1.1 mrg PARAMS. */ 7302 1.1 mrg 7303 1.1 mrg static tree 7304 1.1 mrg sync_resolve_return (tree first_param, tree result, bool orig_format) 7305 1.1 mrg { 7306 1.1 mrg tree ptype = TREE_TYPE (TREE_TYPE (first_param)); 7307 1.1 mrg tree rtype = TREE_TYPE (result); 7308 1.1 mrg ptype = TYPE_MAIN_VARIANT (ptype); 7309 1.1 mrg 7310 1.1 mrg /* New format doesn't require casting unless the types are the same size. */ 7311 1.1 mrg if (orig_format || tree_int_cst_equal (TYPE_SIZE (ptype), TYPE_SIZE (rtype))) 7312 1.1 mrg return convert (ptype, result); 7313 1.1 mrg else 7314 1.1 mrg return result; 7315 1.1 mrg } 7316 1.1 mrg 7317 1.1 mrg /* This function verifies the PARAMS to generic atomic FUNCTION. 7318 1.1 mrg It returns the size if all the parameters are the same size, otherwise 7319 1.1 mrg 0 is returned if the parameters are invalid. */ 7320 1.1 mrg 7321 1.1 mrg static int 7322 1.1 mrg get_atomic_generic_size (location_t loc, tree function, 7323 1.1 mrg vec<tree, va_gc> *params) 7324 1.1 mrg { 7325 1.1 mrg unsigned int n_param; 7326 1.1 mrg unsigned int n_model; 7327 1.1 mrg unsigned int outputs = 0; // bitset of output parameters 7328 1.1 mrg unsigned int x; 7329 1.1 mrg int size_0; 7330 1.1 mrg tree type_0; 7331 1.1 mrg 7332 1.1 mrg /* Determine the parameter makeup. */ 7333 1.1 mrg switch (DECL_FUNCTION_CODE (function)) 7334 1.1 mrg { 7335 1.1 mrg case BUILT_IN_ATOMIC_EXCHANGE: 7336 1.1 mrg n_param = 4; 7337 1.1 mrg n_model = 1; 7338 1.1 mrg outputs = 5; 7339 1.1 mrg break; 7340 1.1 mrg case BUILT_IN_ATOMIC_LOAD: 7341 1.1 mrg n_param = 3; 7342 1.1 mrg n_model = 1; 7343 1.1 mrg outputs = 2; 7344 1.1 mrg break; 7345 1.1 mrg case BUILT_IN_ATOMIC_STORE: 7346 1.1 mrg n_param = 3; 7347 1.1 mrg n_model = 1; 7348 1.1 mrg outputs = 1; 7349 1.1 mrg break; 7350 1.1 mrg case BUILT_IN_ATOMIC_COMPARE_EXCHANGE: 7351 1.1 mrg n_param = 6; 7352 1.1 mrg n_model = 2; 7353 1.1 mrg outputs = 3; 7354 1.1 mrg break; 7355 1.1 mrg default: 7356 1.1 mrg gcc_unreachable (); 7357 1.1 mrg } 7358 1.1 mrg 7359 1.1 mrg if (vec_safe_length (params) != n_param) 7360 1.1 mrg { 7361 1.1 mrg error_at (loc, "incorrect number of arguments to function %qE", function); 7362 1.1 mrg return 0; 7363 1.1 mrg } 7364 1.1 mrg 7365 1.1 mrg /* Get type of first parameter, and determine its size. */ 7366 1.1 mrg type_0 = TREE_TYPE ((*params)[0]); 7367 1.1 mrg if (TREE_CODE (type_0) == ARRAY_TYPE && c_dialect_cxx ()) 7368 1.1 mrg { 7369 1.1 mrg /* Force array-to-pointer decay for C++. */ 7370 1.1 mrg (*params)[0] = default_conversion ((*params)[0]); 7371 1.1 mrg type_0 = TREE_TYPE ((*params)[0]); 7372 1.1 mrg } 7373 1.1 mrg if (TREE_CODE (type_0) != POINTER_TYPE || VOID_TYPE_P (TREE_TYPE (type_0))) 7374 1.1 mrg { 7375 1.1 mrg error_at (loc, "argument 1 of %qE must be a non-void pointer type", 7376 1.1 mrg function); 7377 1.1 mrg return 0; 7378 1.1 mrg } 7379 1.1 mrg 7380 1.1 mrg if (!COMPLETE_TYPE_P (TREE_TYPE (type_0))) 7381 1.1 mrg { 7382 1.1 mrg error_at (loc, "argument 1 of %qE must be a pointer to a complete type", 7383 1.1 mrg function); 7384 1.1 mrg return 0; 7385 1.1 mrg } 7386 1.1 mrg 7387 1.1 mrg /* Types must be compile time constant sizes. */ 7388 1.1 mrg if (!tree_fits_uhwi_p ((TYPE_SIZE_UNIT (TREE_TYPE (type_0))))) 7389 1.1 mrg { 7390 1.1 mrg error_at (loc, 7391 1.1 mrg "argument 1 of %qE must be a pointer to a constant size type", 7392 1.1 mrg function); 7393 1.1 mrg return 0; 7394 1.1 mrg } 7395 1.1 mrg 7396 1.1 mrg size_0 = tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type_0))); 7397 1.1 mrg 7398 1.1 mrg /* Zero size objects are not allowed. */ 7399 1.1 mrg if (size_0 == 0) 7400 1.1 mrg { 7401 1.1 mrg error_at (loc, 7402 1.1 mrg "argument 1 of %qE must be a pointer to a nonzero size object", 7403 1.1 mrg function); 7404 1.1 mrg return 0; 7405 1.1 mrg } 7406 1.1 mrg 7407 1.1 mrg /* Check each other parameter is a pointer and the same size. */ 7408 1.1 mrg for (x = 0; x < n_param - n_model; x++) 7409 1.1 mrg { 7410 1.1 mrg int size; 7411 1.1 mrg tree type = TREE_TYPE ((*params)[x]); 7412 1.1 mrg /* __atomic_compare_exchange has a bool in the 4th position, skip it. */ 7413 1.1 mrg if (n_param == 6 && x == 3) 7414 1.1 mrg continue; 7415 1.1 mrg if (TREE_CODE (type) == ARRAY_TYPE && c_dialect_cxx ()) 7416 1.1 mrg { 7417 1.1 mrg /* Force array-to-pointer decay for C++. */ 7418 1.1 mrg (*params)[x] = default_conversion ((*params)[x]); 7419 1.1 mrg type = TREE_TYPE ((*params)[x]); 7420 1.1 mrg } 7421 1.1 mrg if (!POINTER_TYPE_P (type)) 7422 1.1 mrg { 7423 1.1 mrg error_at (loc, "argument %d of %qE must be a pointer type", x + 1, 7424 1.1 mrg function); 7425 1.1 mrg return 0; 7426 1.1 mrg } 7427 1.1 mrg else if (TYPE_SIZE_UNIT (TREE_TYPE (type)) 7428 1.1 mrg && TREE_CODE ((TYPE_SIZE_UNIT (TREE_TYPE (type)))) 7429 1.1 mrg != INTEGER_CST) 7430 1.1 mrg { 7431 1.1 mrg error_at (loc, "argument %d of %qE must be a pointer to a constant " 7432 1.1 mrg "size type", x + 1, function); 7433 1.1 mrg return 0; 7434 1.1 mrg } 7435 1.1 mrg else if (FUNCTION_POINTER_TYPE_P (type)) 7436 1.1 mrg { 7437 1.1 mrg error_at (loc, "argument %d of %qE must not be a pointer to a " 7438 1.1 mrg "function", x + 1, function); 7439 1.1 mrg return 0; 7440 1.1 mrg } 7441 1.1 mrg tree type_size = TYPE_SIZE_UNIT (TREE_TYPE (type)); 7442 1.1 mrg size = type_size ? tree_to_uhwi (type_size) : 0; 7443 1.1 mrg if (size != size_0) 7444 1.1 mrg { 7445 1.1 mrg error_at (loc, "size mismatch in argument %d of %qE", x + 1, 7446 1.1 mrg function); 7447 1.1 mrg return 0; 7448 1.1 mrg } 7449 1.1 mrg 7450 1.1 mrg { 7451 1.1 mrg auto_diagnostic_group d; 7452 1.1 mrg int quals = TYPE_QUALS (TREE_TYPE (type)); 7453 1.1 mrg /* Must not write to an argument of a const-qualified type. */ 7454 1.1 mrg if (outputs & (1 << x) && quals & TYPE_QUAL_CONST) 7455 1.1 mrg { 7456 1.1 mrg if (c_dialect_cxx ()) 7457 1.1 mrg { 7458 1.1 mrg error_at (loc, "argument %d of %qE must not be a pointer to " 7459 1.1 mrg "a %<const%> type", x + 1, function); 7460 1.1 mrg return 0; 7461 1.1 mrg } 7462 1.1 mrg else 7463 1.1 mrg pedwarn (loc, OPT_Wincompatible_pointer_types, "argument %d " 7464 1.1 mrg "of %qE discards %<const%> qualifier", x + 1, 7465 1.1 mrg function); 7466 1.1 mrg } 7467 1.1 mrg /* Only the first argument is allowed to be volatile. */ 7468 1.1 mrg if (x > 0 && quals & TYPE_QUAL_VOLATILE) 7469 1.1 mrg { 7470 1.1 mrg if (c_dialect_cxx ()) 7471 1.1 mrg { 7472 1.1 mrg error_at (loc, "argument %d of %qE must not be a pointer to " 7473 1.1 mrg "a %<volatile%> type", x + 1, function); 7474 1.1 mrg return 0; 7475 1.1 mrg } 7476 1.1 mrg else 7477 1.1 mrg pedwarn (loc, OPT_Wincompatible_pointer_types, "argument %d " 7478 1.1 mrg "of %qE discards %<volatile%> qualifier", x + 1, 7479 1.1 mrg function); 7480 1.1 mrg } 7481 1.1 mrg } 7482 1.1 mrg } 7483 1.1 mrg 7484 1.1 mrg /* Check memory model parameters for validity. */ 7485 1.1 mrg for (x = n_param - n_model ; x < n_param; x++) 7486 1.1 mrg { 7487 1.1 mrg tree p = (*params)[x]; 7488 1.1 mrg if (!INTEGRAL_TYPE_P (TREE_TYPE (p))) 7489 1.1 mrg { 7490 1.1 mrg error_at (loc, "non-integer memory model argument %d of %qE", x + 1, 7491 1.1 mrg function); 7492 1.1 mrg return 0; 7493 1.1 mrg } 7494 1.1 mrg p = fold_for_warn (p); 7495 1.1 mrg if (TREE_CODE (p) == INTEGER_CST) 7496 1.1 mrg { 7497 1.1 mrg /* memmodel_base masks the low 16 bits, thus ignore any bits above 7498 1.1 mrg it by using TREE_INT_CST_LOW instead of tree_to_*hwi. Those high 7499 1.1 mrg bits will be checked later during expansion in target specific 7500 1.1 mrg way. */ 7501 1.1 mrg if (memmodel_base (TREE_INT_CST_LOW (p)) >= MEMMODEL_LAST) 7502 1.1 mrg warning_at (loc, OPT_Winvalid_memory_model, 7503 1.1 mrg "invalid memory model argument %d of %qE", x + 1, 7504 1.1 mrg function); 7505 1.1 mrg } 7506 1.1 mrg } 7507 1.1 mrg 7508 1.1 mrg return size_0; 7509 1.1 mrg } 7510 1.1 mrg 7511 1.1 mrg 7512 1.1 mrg /* This will take an __atomic_ generic FUNCTION call, and add a size parameter N 7513 1.1 mrg at the beginning of the parameter list PARAMS representing the size of the 7514 1.1 mrg objects. This is to match the library ABI requirement. LOC is the location 7515 1.1 mrg of the function call. 7516 1.1 mrg The new function is returned if it needed rebuilding, otherwise NULL_TREE is 7517 1.1 mrg returned to allow the external call to be constructed. */ 7518 1.1 mrg 7519 1.1 mrg static tree 7520 1.1 mrg add_atomic_size_parameter (unsigned n, location_t loc, tree function, 7521 1.1 mrg vec<tree, va_gc> *params) 7522 1.1 mrg { 7523 1.1 mrg tree size_node; 7524 1.1 mrg 7525 1.1 mrg /* Insert a SIZE_T parameter as the first param. If there isn't 7526 1.1 mrg enough space, allocate a new vector and recursively re-build with that. */ 7527 1.1 mrg if (!params->space (1)) 7528 1.1 mrg { 7529 1.1 mrg unsigned int z, len; 7530 1.1 mrg vec<tree, va_gc> *v; 7531 1.1 mrg tree f; 7532 1.1 mrg 7533 1.1 mrg len = params->length (); 7534 1.1 mrg vec_alloc (v, len + 1); 7535 1.1 mrg v->quick_push (build_int_cst (size_type_node, n)); 7536 1.1 mrg for (z = 0; z < len; z++) 7537 1.1 mrg v->quick_push ((*params)[z]); 7538 1.1 mrg f = build_function_call_vec (loc, vNULL, function, v, NULL); 7539 1.1 mrg vec_free (v); 7540 1.1 mrg return f; 7541 1.1 mrg } 7542 1.1 mrg 7543 1.1 mrg /* Add the size parameter and leave as a function call for processing. */ 7544 1.1 mrg size_node = build_int_cst (size_type_node, n); 7545 1.1 mrg params->quick_insert (0, size_node); 7546 1.1 mrg return NULL_TREE; 7547 1.1 mrg } 7548 1.1 mrg 7549 1.1 mrg 7550 1.1 mrg /* Return whether atomic operations for naturally aligned N-byte 7551 1.1 mrg arguments are supported, whether inline or through libatomic. */ 7552 1.1 mrg static bool 7553 1.1 mrg atomic_size_supported_p (int n) 7554 1.1 mrg { 7555 1.1 mrg switch (n) 7556 1.1 mrg { 7557 1.1 mrg case 1: 7558 1.1 mrg case 2: 7559 1.1 mrg case 4: 7560 1.1 mrg case 8: 7561 1.1 mrg return true; 7562 1.1 mrg 7563 1.1 mrg case 16: 7564 1.1 mrg return targetm.scalar_mode_supported_p (TImode); 7565 1.1 mrg 7566 1.1 mrg default: 7567 1.1 mrg return false; 7568 1.1 mrg } 7569 1.1 mrg } 7570 1.1 mrg 7571 1.1 mrg /* This will process an __atomic_exchange function call, determine whether it 7572 1.1 mrg needs to be mapped to the _N variation, or turned into a library call. 7573 1.1 mrg LOC is the location of the builtin call. 7574 1.1 mrg FUNCTION is the DECL that has been invoked; 7575 1.1 mrg PARAMS is the argument list for the call. The return value is non-null 7576 1.1 mrg TRUE is returned if it is translated into the proper format for a call to the 7577 1.1 mrg external library, and NEW_RETURN is set the tree for that function. 7578 1.1 mrg FALSE is returned if processing for the _N variation is required, and 7579 1.1 mrg NEW_RETURN is set to the return value the result is copied into. */ 7580 1.1 mrg static bool 7581 1.1 mrg resolve_overloaded_atomic_exchange (location_t loc, tree function, 7582 1.1 mrg vec<tree, va_gc> *params, tree *new_return) 7583 1.1 mrg { 7584 1.1 mrg tree p0, p1, p2, p3; 7585 1.1 mrg tree I_type, I_type_ptr; 7586 1.1 mrg int n = get_atomic_generic_size (loc, function, params); 7587 1.1 mrg 7588 1.1 mrg /* Size of 0 is an error condition. */ 7589 1.1 mrg if (n == 0) 7590 1.1 mrg { 7591 1.1 mrg *new_return = error_mark_node; 7592 1.1 mrg return true; 7593 1.1 mrg } 7594 1.1 mrg 7595 1.1 mrg /* If not a lock-free size, change to the library generic format. */ 7596 1.1 mrg if (!atomic_size_supported_p (n)) 7597 1.1 mrg { 7598 1.1 mrg *new_return = add_atomic_size_parameter (n, loc, function, params); 7599 1.1 mrg return true; 7600 1.1 mrg } 7601 1.1 mrg 7602 1.1 mrg /* Otherwise there is a lockfree match, transform the call from: 7603 1.1 mrg void fn(T* mem, T* desired, T* return, model) 7604 1.1 mrg into 7605 1.1 mrg *return = (T) (fn (In* mem, (In) *desired, model)) */ 7606 1.1 mrg 7607 1.1 mrg p0 = (*params)[0]; 7608 1.1 mrg p1 = (*params)[1]; 7609 1.1 mrg p2 = (*params)[2]; 7610 1.1 mrg p3 = (*params)[3]; 7611 1.1 mrg 7612 1.1 mrg /* Create pointer to appropriate size. */ 7613 1.1 mrg I_type = builtin_type_for_size (BITS_PER_UNIT * n, 1); 7614 1.1 mrg I_type_ptr = build_pointer_type (I_type); 7615 1.1 mrg 7616 1.1 mrg /* Convert object pointer to required type. */ 7617 1.1 mrg p0 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p0); 7618 1.1 mrg (*params)[0] = p0; 7619 1.1 mrg /* Convert new value to required type, and dereference it. */ 7620 1.1 mrg p1 = build_indirect_ref (loc, p1, RO_UNARY_STAR); 7621 1.1 mrg p1 = build1 (VIEW_CONVERT_EXPR, I_type, p1); 7622 1.1 mrg (*params)[1] = p1; 7623 1.1 mrg 7624 1.1 mrg /* Move memory model to the 3rd position, and end param list. */ 7625 1.1 mrg (*params)[2] = p3; 7626 1.1 mrg params->truncate (3); 7627 1.1 mrg 7628 1.1 mrg /* Convert return pointer and dereference it for later assignment. */ 7629 1.1 mrg *new_return = build_indirect_ref (loc, p2, RO_UNARY_STAR); 7630 1.1 mrg 7631 1.1 mrg return false; 7632 1.1 mrg } 7633 1.1 mrg 7634 1.1 mrg 7635 1.1 mrg /* This will process an __atomic_compare_exchange function call, determine 7636 1.1 mrg whether it needs to be mapped to the _N variation, or turned into a lib call. 7637 1.1 mrg LOC is the location of the builtin call. 7638 1.1 mrg FUNCTION is the DECL that has been invoked; 7639 1.1 mrg PARAMS is the argument list for the call. The return value is non-null 7640 1.1 mrg TRUE is returned if it is translated into the proper format for a call to the 7641 1.1 mrg external library, and NEW_RETURN is set the tree for that function. 7642 1.1 mrg FALSE is returned if processing for the _N variation is required. */ 7643 1.1 mrg 7644 1.1 mrg static bool 7645 1.1 mrg resolve_overloaded_atomic_compare_exchange (location_t loc, tree function, 7646 1.1 mrg vec<tree, va_gc> *params, 7647 1.1 mrg tree *new_return) 7648 1.1 mrg { 7649 1.1 mrg tree p0, p1, p2; 7650 1.1 mrg tree I_type, I_type_ptr; 7651 1.1 mrg int n = get_atomic_generic_size (loc, function, params); 7652 1.1 mrg 7653 1.1 mrg /* Size of 0 is an error condition. */ 7654 1.1 mrg if (n == 0) 7655 1.1 mrg { 7656 1.1 mrg *new_return = error_mark_node; 7657 1.1 mrg return true; 7658 1.1 mrg } 7659 1.1 mrg 7660 1.1 mrg /* If not a lock-free size, change to the library generic format. */ 7661 1.1 mrg if (!atomic_size_supported_p (n)) 7662 1.1 mrg { 7663 1.1 mrg /* The library generic format does not have the weak parameter, so 7664 1.1 mrg remove it from the param list. Since a parameter has been removed, 7665 1.1 mrg we can be sure that there is room for the SIZE_T parameter, meaning 7666 1.1 mrg there will not be a recursive rebuilding of the parameter list, so 7667 1.1 mrg there is no danger this will be done twice. */ 7668 1.1 mrg if (n > 0) 7669 1.1 mrg { 7670 1.1 mrg (*params)[3] = (*params)[4]; 7671 1.1 mrg (*params)[4] = (*params)[5]; 7672 1.1 mrg params->truncate (5); 7673 1.1 mrg } 7674 1.1 mrg *new_return = add_atomic_size_parameter (n, loc, function, params); 7675 1.1 mrg return true; 7676 1.1 mrg } 7677 1.1 mrg 7678 1.1 mrg /* Otherwise, there is a match, so the call needs to be transformed from: 7679 1.1 mrg bool fn(T* mem, T* desired, T* return, weak, success, failure) 7680 1.1 mrg into 7681 1.1 mrg bool fn ((In *)mem, (In *)expected, (In) *desired, weak, succ, fail) */ 7682 1.1 mrg 7683 1.1 mrg p0 = (*params)[0]; 7684 1.1 mrg p1 = (*params)[1]; 7685 1.1 mrg p2 = (*params)[2]; 7686 1.1 mrg 7687 1.1 mrg /* Create pointer to appropriate size. */ 7688 1.1 mrg I_type = builtin_type_for_size (BITS_PER_UNIT * n, 1); 7689 1.1 mrg I_type_ptr = build_pointer_type (I_type); 7690 1.1 mrg 7691 1.1 mrg /* Convert object pointer to required type. */ 7692 1.1 mrg p0 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p0); 7693 1.1 mrg (*params)[0] = p0; 7694 1.1 mrg 7695 1.1 mrg /* Convert expected pointer to required type. */ 7696 1.1 mrg p1 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p1); 7697 1.1 mrg (*params)[1] = p1; 7698 1.1 mrg 7699 1.1 mrg /* Convert desired value to required type, and dereference it. */ 7700 1.1 mrg p2 = build_indirect_ref (loc, p2, RO_UNARY_STAR); 7701 1.1 mrg p2 = build1 (VIEW_CONVERT_EXPR, I_type, p2); 7702 1.1 mrg (*params)[2] = p2; 7703 1.1 mrg 7704 1.1 mrg /* The rest of the parameters are fine. NULL means no special return value 7705 1.1 mrg processing.*/ 7706 1.1 mrg *new_return = NULL; 7707 1.1 mrg return false; 7708 1.1 mrg } 7709 1.1 mrg 7710 1.1 mrg 7711 1.1 mrg /* This will process an __atomic_load function call, determine whether it 7712 1.1 mrg needs to be mapped to the _N variation, or turned into a library call. 7713 1.1 mrg LOC is the location of the builtin call. 7714 1.1 mrg FUNCTION is the DECL that has been invoked; 7715 1.1 mrg PARAMS is the argument list for the call. The return value is non-null 7716 1.1 mrg TRUE is returned if it is translated into the proper format for a call to the 7717 1.1 mrg external library, and NEW_RETURN is set the tree for that function. 7718 1.1 mrg FALSE is returned if processing for the _N variation is required, and 7719 1.1 mrg NEW_RETURN is set to the return value the result is copied into. */ 7720 1.1 mrg 7721 1.1 mrg static bool 7722 1.1 mrg resolve_overloaded_atomic_load (location_t loc, tree function, 7723 1.1 mrg vec<tree, va_gc> *params, tree *new_return) 7724 1.1 mrg { 7725 1.1 mrg tree p0, p1, p2; 7726 1.1 mrg tree I_type, I_type_ptr; 7727 1.1 mrg int n = get_atomic_generic_size (loc, function, params); 7728 1.1 mrg 7729 1.1 mrg /* Size of 0 is an error condition. */ 7730 1.1 mrg if (n == 0) 7731 1.1 mrg { 7732 1.1 mrg *new_return = error_mark_node; 7733 1.1 mrg return true; 7734 1.1 mrg } 7735 1.1 mrg 7736 1.1 mrg /* If not a lock-free size, change to the library generic format. */ 7737 1.1 mrg if (!atomic_size_supported_p (n)) 7738 1.1 mrg { 7739 1.1 mrg *new_return = add_atomic_size_parameter (n, loc, function, params); 7740 1.1 mrg return true; 7741 1.1 mrg } 7742 1.1 mrg 7743 1.1 mrg /* Otherwise, there is a match, so the call needs to be transformed from: 7744 1.1 mrg void fn(T* mem, T* return, model) 7745 1.1 mrg into 7746 1.1 mrg *return = (T) (fn ((In *) mem, model)) */ 7747 1.1 mrg 7748 1.1 mrg p0 = (*params)[0]; 7749 1.1 mrg p1 = (*params)[1]; 7750 1.1 mrg p2 = (*params)[2]; 7751 1.1 mrg 7752 1.1 mrg /* Create pointer to appropriate size. */ 7753 1.1 mrg I_type = builtin_type_for_size (BITS_PER_UNIT * n, 1); 7754 1.1 mrg I_type_ptr = build_pointer_type (I_type); 7755 1.1 mrg 7756 1.1 mrg /* Convert object pointer to required type. */ 7757 1.1 mrg p0 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p0); 7758 1.1 mrg (*params)[0] = p0; 7759 1.1 mrg 7760 1.1 mrg /* Move memory model to the 2nd position, and end param list. */ 7761 1.1 mrg (*params)[1] = p2; 7762 1.1 mrg params->truncate (2); 7763 1.1 mrg 7764 1.1 mrg /* Convert return pointer and dereference it for later assignment. */ 7765 1.1 mrg *new_return = build_indirect_ref (loc, p1, RO_UNARY_STAR); 7766 1.1 mrg 7767 1.1 mrg return false; 7768 1.1 mrg } 7769 1.1 mrg 7770 1.1 mrg 7771 1.1 mrg /* This will process an __atomic_store function call, determine whether it 7772 1.1 mrg needs to be mapped to the _N variation, or turned into a library call. 7773 1.1 mrg LOC is the location of the builtin call. 7774 1.1 mrg FUNCTION is the DECL that has been invoked; 7775 1.1 mrg PARAMS is the argument list for the call. The return value is non-null 7776 1.1 mrg TRUE is returned if it is translated into the proper format for a call to the 7777 1.1 mrg external library, and NEW_RETURN is set the tree for that function. 7778 1.1 mrg FALSE is returned if processing for the _N variation is required, and 7779 1.1 mrg NEW_RETURN is set to the return value the result is copied into. */ 7780 1.1 mrg 7781 1.1 mrg static bool 7782 1.1 mrg resolve_overloaded_atomic_store (location_t loc, tree function, 7783 1.1 mrg vec<tree, va_gc> *params, tree *new_return) 7784 1.1 mrg { 7785 1.1 mrg tree p0, p1; 7786 1.1 mrg tree I_type, I_type_ptr; 7787 1.1 mrg int n = get_atomic_generic_size (loc, function, params); 7788 1.1 mrg 7789 1.1 mrg /* Size of 0 is an error condition. */ 7790 1.1 mrg if (n == 0) 7791 1.1 mrg { 7792 1.1 mrg *new_return = error_mark_node; 7793 1.1 mrg return true; 7794 1.1 mrg } 7795 1.1 mrg 7796 1.1 mrg /* If not a lock-free size, change to the library generic format. */ 7797 1.1 mrg if (!atomic_size_supported_p (n)) 7798 1.1 mrg { 7799 1.1 mrg *new_return = add_atomic_size_parameter (n, loc, function, params); 7800 1.1 mrg return true; 7801 1.1 mrg } 7802 1.1 mrg 7803 1.1 mrg /* Otherwise, there is a match, so the call needs to be transformed from: 7804 1.1 mrg void fn(T* mem, T* value, model) 7805 1.1 mrg into 7806 1.1 mrg fn ((In *) mem, (In) *value, model) */ 7807 1.1 mrg 7808 1.1 mrg p0 = (*params)[0]; 7809 1.1 mrg p1 = (*params)[1]; 7810 1.1 mrg 7811 1.1 mrg /* Create pointer to appropriate size. */ 7812 1.1 mrg I_type = builtin_type_for_size (BITS_PER_UNIT * n, 1); 7813 1.1 mrg I_type_ptr = build_pointer_type (I_type); 7814 1.1 mrg 7815 1.1 mrg /* Convert object pointer to required type. */ 7816 1.1 mrg p0 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p0); 7817 1.1 mrg (*params)[0] = p0; 7818 1.1 mrg 7819 1.1 mrg /* Convert new value to required type, and dereference it. */ 7820 1.1 mrg p1 = build_indirect_ref (loc, p1, RO_UNARY_STAR); 7821 1.1 mrg p1 = build1 (VIEW_CONVERT_EXPR, I_type, p1); 7822 1.1 mrg (*params)[1] = p1; 7823 1.1 mrg 7824 1.1 mrg /* The memory model is in the right spot already. Return is void. */ 7825 1.1 mrg *new_return = NULL_TREE; 7826 1.1 mrg 7827 1.1 mrg return false; 7828 1.1 mrg } 7829 1.1 mrg 7830 1.1 mrg 7831 1.1 mrg /* Some builtin functions are placeholders for other expressions. This 7832 1.1 mrg function should be called immediately after parsing the call expression 7833 1.1 mrg before surrounding code has committed to the type of the expression. 7834 1.1 mrg 7835 1.1 mrg LOC is the location of the builtin call. 7836 1.1 mrg 7837 1.1 mrg FUNCTION is the DECL that has been invoked; it is known to be a builtin. 7838 1.1 mrg PARAMS is the argument list for the call. The return value is non-null 7839 1.1 mrg when expansion is complete, and null if normal processing should 7840 1.1 mrg continue. */ 7841 1.1 mrg 7842 1.1 mrg tree 7843 1.1 mrg resolve_overloaded_builtin (location_t loc, tree function, 7844 1.1 mrg vec<tree, va_gc> *params) 7845 1.1 mrg { 7846 1.1 mrg /* Is function one of the _FETCH_OP_ or _OP_FETCH_ built-ins? 7847 1.1 mrg Those are not valid to call with a pointer to _Bool (or C++ bool) 7848 1.1 mrg and so must be rejected. */ 7849 1.1 mrg bool fetch_op = true; 7850 1.1 mrg bool orig_format = true; 7851 1.1 mrg tree new_return = NULL_TREE; 7852 1.1 mrg 7853 1.1 mrg switch (DECL_BUILT_IN_CLASS (function)) 7854 1.1 mrg { 7855 1.1 mrg case BUILT_IN_NORMAL: 7856 1.1 mrg break; 7857 1.1 mrg case BUILT_IN_MD: 7858 1.1 mrg if (targetm.resolve_overloaded_builtin) 7859 1.1 mrg return targetm.resolve_overloaded_builtin (loc, function, params); 7860 1.1 mrg else 7861 1.1 mrg return NULL_TREE; 7862 1.1 mrg default: 7863 1.1 mrg return NULL_TREE; 7864 1.1 mrg } 7865 1.1 mrg 7866 1.1 mrg /* Handle BUILT_IN_NORMAL here. */ 7867 1.1 mrg enum built_in_function orig_code = DECL_FUNCTION_CODE (function); 7868 1.1 mrg switch (orig_code) 7869 1.1 mrg { 7870 1.1 mrg case BUILT_IN_SPECULATION_SAFE_VALUE_N: 7871 1.1 mrg { 7872 1.1 mrg tree new_function, first_param, result; 7873 1.1 mrg enum built_in_function fncode 7874 1.1 mrg = speculation_safe_value_resolve_call (function, params); 7875 1.1 mrg 7876 1.1 mrg if (fncode == BUILT_IN_NONE) 7877 1.1 mrg return error_mark_node; 7878 1.1 mrg 7879 1.1 mrg first_param = (*params)[0]; 7880 1.1 mrg if (!speculation_safe_value_resolve_params (loc, function, params)) 7881 1.1 mrg return error_mark_node; 7882 1.1 mrg 7883 1.1 mrg if (targetm.have_speculation_safe_value (true)) 7884 1.1 mrg { 7885 1.1 mrg new_function = builtin_decl_explicit (fncode); 7886 1.1 mrg result = build_function_call_vec (loc, vNULL, new_function, params, 7887 1.1 mrg NULL); 7888 1.1 mrg 7889 1.1 mrg if (result == error_mark_node) 7890 1.1 mrg return result; 7891 1.1 mrg 7892 1.1 mrg return speculation_safe_value_resolve_return (first_param, result); 7893 1.1 mrg } 7894 1.1 mrg else 7895 1.1 mrg { 7896 1.1 mrg /* This target doesn't have, or doesn't need, active mitigation 7897 1.1 mrg against incorrect speculative execution. Simply return the 7898 1.1 mrg first parameter to the builtin. */ 7899 1.1 mrg if (!targetm.have_speculation_safe_value (false)) 7900 1.1 mrg /* The user has invoked __builtin_speculation_safe_value 7901 1.1 mrg even though __HAVE_SPECULATION_SAFE_VALUE is not 7902 1.1 mrg defined: emit a warning. */ 7903 1.1 mrg warning_at (input_location, 0, 7904 1.1 mrg "this target does not define a speculation barrier; " 7905 1.1 mrg "your program will still execute correctly, " 7906 1.1 mrg "but incorrect speculation may not be " 7907 1.1 mrg "restricted"); 7908 1.1 mrg 7909 1.1 mrg /* If the optional second argument is present, handle any side 7910 1.1 mrg effects now. */ 7911 1.1 mrg if (params->length () == 2 7912 1.1 mrg && TREE_SIDE_EFFECTS ((*params)[1])) 7913 1.1 mrg return build2 (COMPOUND_EXPR, TREE_TYPE (first_param), 7914 1.1 mrg (*params)[1], first_param); 7915 1.1 mrg 7916 1.1 mrg return first_param; 7917 1.1 mrg } 7918 1.1 mrg } 7919 1.1 mrg 7920 1.1 mrg case BUILT_IN_ATOMIC_EXCHANGE: 7921 1.1 mrg case BUILT_IN_ATOMIC_COMPARE_EXCHANGE: 7922 1.1 mrg case BUILT_IN_ATOMIC_LOAD: 7923 1.1 mrg case BUILT_IN_ATOMIC_STORE: 7924 1.1 mrg { 7925 1.1 mrg /* Handle these 4 together so that they can fall through to the next 7926 1.1 mrg case if the call is transformed to an _N variant. */ 7927 1.1 mrg switch (orig_code) 7928 1.1 mrg { 7929 1.1 mrg case BUILT_IN_ATOMIC_EXCHANGE: 7930 1.1 mrg { 7931 1.1 mrg if (resolve_overloaded_atomic_exchange (loc, function, params, 7932 1.1 mrg &new_return)) 7933 1.1 mrg return new_return; 7934 1.1 mrg /* Change to the _N variant. */ 7935 1.1 mrg orig_code = BUILT_IN_ATOMIC_EXCHANGE_N; 7936 1.1 mrg break; 7937 1.1 mrg } 7938 1.1 mrg 7939 1.1 mrg case BUILT_IN_ATOMIC_COMPARE_EXCHANGE: 7940 1.1 mrg { 7941 1.1 mrg if (resolve_overloaded_atomic_compare_exchange (loc, function, 7942 1.1 mrg params, 7943 1.1 mrg &new_return)) 7944 1.1 mrg return new_return; 7945 1.1 mrg /* Change to the _N variant. */ 7946 1.1 mrg orig_code = BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N; 7947 1.1 mrg break; 7948 1.1 mrg } 7949 1.1 mrg case BUILT_IN_ATOMIC_LOAD: 7950 1.1 mrg { 7951 1.1 mrg if (resolve_overloaded_atomic_load (loc, function, params, 7952 1.1 mrg &new_return)) 7953 1.1 mrg return new_return; 7954 1.1 mrg /* Change to the _N variant. */ 7955 1.1 mrg orig_code = BUILT_IN_ATOMIC_LOAD_N; 7956 1.1 mrg break; 7957 1.1 mrg } 7958 1.1 mrg case BUILT_IN_ATOMIC_STORE: 7959 1.1 mrg { 7960 1.1 mrg if (resolve_overloaded_atomic_store (loc, function, params, 7961 1.1 mrg &new_return)) 7962 1.1 mrg return new_return; 7963 1.1 mrg /* Change to the _N variant. */ 7964 1.1 mrg orig_code = BUILT_IN_ATOMIC_STORE_N; 7965 1.1 mrg break; 7966 1.1 mrg } 7967 1.1 mrg default: 7968 1.1 mrg gcc_unreachable (); 7969 1.1 mrg } 7970 1.1 mrg } 7971 1.1 mrg /* FALLTHRU */ 7972 1.1 mrg case BUILT_IN_ATOMIC_EXCHANGE_N: 7973 1.1 mrg case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N: 7974 1.1 mrg case BUILT_IN_ATOMIC_LOAD_N: 7975 1.1 mrg case BUILT_IN_ATOMIC_STORE_N: 7976 1.1 mrg fetch_op = false; 7977 1.1 mrg /* FALLTHRU */ 7978 1.1 mrg case BUILT_IN_ATOMIC_ADD_FETCH_N: 7979 1.1 mrg case BUILT_IN_ATOMIC_SUB_FETCH_N: 7980 1.1 mrg case BUILT_IN_ATOMIC_AND_FETCH_N: 7981 1.1 mrg case BUILT_IN_ATOMIC_NAND_FETCH_N: 7982 1.1 mrg case BUILT_IN_ATOMIC_XOR_FETCH_N: 7983 1.1 mrg case BUILT_IN_ATOMIC_OR_FETCH_N: 7984 1.1 mrg case BUILT_IN_ATOMIC_FETCH_ADD_N: 7985 1.1 mrg case BUILT_IN_ATOMIC_FETCH_SUB_N: 7986 1.1 mrg case BUILT_IN_ATOMIC_FETCH_AND_N: 7987 1.1 mrg case BUILT_IN_ATOMIC_FETCH_NAND_N: 7988 1.1 mrg case BUILT_IN_ATOMIC_FETCH_XOR_N: 7989 1.1 mrg case BUILT_IN_ATOMIC_FETCH_OR_N: 7990 1.1 mrg orig_format = false; 7991 1.1 mrg /* FALLTHRU */ 7992 1.1 mrg case BUILT_IN_SYNC_FETCH_AND_ADD_N: 7993 1.1 mrg case BUILT_IN_SYNC_FETCH_AND_SUB_N: 7994 1.1 mrg case BUILT_IN_SYNC_FETCH_AND_OR_N: 7995 1.1 mrg case BUILT_IN_SYNC_FETCH_AND_AND_N: 7996 1.1 mrg case BUILT_IN_SYNC_FETCH_AND_XOR_N: 7997 1.1 mrg case BUILT_IN_SYNC_FETCH_AND_NAND_N: 7998 1.1 mrg case BUILT_IN_SYNC_ADD_AND_FETCH_N: 7999 1.1 mrg case BUILT_IN_SYNC_SUB_AND_FETCH_N: 8000 1.1 mrg case BUILT_IN_SYNC_OR_AND_FETCH_N: 8001 1.1 mrg case BUILT_IN_SYNC_AND_AND_FETCH_N: 8002 1.1 mrg case BUILT_IN_SYNC_XOR_AND_FETCH_N: 8003 1.1 mrg case BUILT_IN_SYNC_NAND_AND_FETCH_N: 8004 1.1 mrg case BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N: 8005 1.1 mrg case BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N: 8006 1.1 mrg case BUILT_IN_SYNC_LOCK_TEST_AND_SET_N: 8007 1.1 mrg case BUILT_IN_SYNC_LOCK_RELEASE_N: 8008 1.1 mrg { 8009 1.1 mrg /* The following are not _FETCH_OPs and must be accepted with 8010 1.1 mrg pointers to _Bool (or C++ bool). */ 8011 1.1 mrg if (fetch_op) 8012 1.1 mrg fetch_op = 8013 1.1 mrg (orig_code != BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N 8014 1.1 mrg && orig_code != BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N 8015 1.1 mrg && orig_code != BUILT_IN_SYNC_LOCK_TEST_AND_SET_N 8016 1.1 mrg && orig_code != BUILT_IN_SYNC_LOCK_RELEASE_N); 8017 1.1 mrg 8018 1.1 mrg int n = sync_resolve_size (function, params, fetch_op); 8019 1.1 mrg tree new_function, first_param, result; 8020 1.1 mrg enum built_in_function fncode; 8021 1.1 mrg 8022 1.1 mrg if (n == 0) 8023 1.1 mrg return error_mark_node; 8024 1.1 mrg 8025 1.1 mrg fncode = (enum built_in_function)((int)orig_code + exact_log2 (n) + 1); 8026 1.1 mrg new_function = builtin_decl_explicit (fncode); 8027 1.1 mrg if (!sync_resolve_params (loc, function, new_function, params, 8028 1.1 mrg orig_format)) 8029 1.1 mrg return error_mark_node; 8030 1.1 mrg 8031 1.1 mrg first_param = (*params)[0]; 8032 1.1 mrg result = build_function_call_vec (loc, vNULL, new_function, params, 8033 1.1 mrg NULL); 8034 1.1 mrg if (result == error_mark_node) 8035 1.1 mrg return result; 8036 1.1 mrg if (orig_code != BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N 8037 1.1 mrg && orig_code != BUILT_IN_SYNC_LOCK_RELEASE_N 8038 1.1 mrg && orig_code != BUILT_IN_ATOMIC_STORE_N 8039 1.1 mrg && orig_code != BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N) 8040 1.1 mrg result = sync_resolve_return (first_param, result, orig_format); 8041 1.1 mrg 8042 1.1 mrg if (fetch_op) 8043 1.1 mrg /* Prevent -Wunused-value warning. */ 8044 1.1 mrg TREE_USED (result) = true; 8045 1.1 mrg 8046 1.1 mrg /* If new_return is set, assign function to that expr and cast the 8047 1.1 mrg result to void since the generic interface returned void. */ 8048 1.1 mrg if (new_return) 8049 1.1 mrg { 8050 1.1 mrg /* Cast function result from I{1,2,4,8,16} to the required type. */ 8051 1.1 mrg result = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (new_return), result); 8052 1.1 mrg result = build2 (MODIFY_EXPR, TREE_TYPE (new_return), new_return, 8053 1.1 mrg result); 8054 1.1 mrg TREE_SIDE_EFFECTS (result) = 1; 8055 1.1 mrg protected_set_expr_location (result, loc); 8056 1.1 mrg result = convert (void_type_node, result); 8057 1.1 mrg } 8058 1.1 mrg return result; 8059 1.1 mrg } 8060 1.1 mrg 8061 1.1 mrg default: 8062 1.1 mrg return NULL_TREE; 8063 1.1 mrg } 8064 1.1 mrg } 8065 1.1 mrg 8066 1.1 mrg /* vector_types_compatible_elements_p is used in type checks of vectors 8067 1.1 mrg values used as operands of binary operators. Where it returns true, and 8068 1.1 mrg the other checks of the caller succeed (being vector types in he first 8069 1.1 mrg place, and matching number of elements), we can just treat the types 8070 1.1 mrg as essentially the same. 8071 1.1 mrg Contrast with vector_targets_convertible_p, which is used for vector 8072 1.1 mrg pointer types, and vector_types_convertible_p, which will allow 8073 1.1 mrg language-specific matches under the control of flag_lax_vector_conversions, 8074 1.1 mrg and might still require a conversion. */ 8075 1.1 mrg /* True if vector types T1 and T2 can be inputs to the same binary 8076 1.1 mrg operator without conversion. 8077 1.1 mrg We don't check the overall vector size here because some of our callers 8078 1.1 mrg want to give different error messages when the vectors are compatible 8079 1.1 mrg except for the element count. */ 8080 1.1 mrg 8081 1.1 mrg bool 8082 1.1 mrg vector_types_compatible_elements_p (tree t1, tree t2) 8083 1.1 mrg { 8084 1.1 mrg bool opaque = TYPE_VECTOR_OPAQUE (t1) || TYPE_VECTOR_OPAQUE (t2); 8085 1.1 mrg t1 = TREE_TYPE (t1); 8086 1.1 mrg t2 = TREE_TYPE (t2); 8087 1.1 mrg 8088 1.1 mrg enum tree_code c1 = TREE_CODE (t1), c2 = TREE_CODE (t2); 8089 1.1 mrg 8090 1.1 mrg gcc_assert ((INTEGRAL_TYPE_P (t1) 8091 1.1 mrg || c1 == REAL_TYPE 8092 1.1 mrg || c1 == FIXED_POINT_TYPE) 8093 1.1 mrg && (INTEGRAL_TYPE_P (t2) 8094 1.1 mrg || c2 == REAL_TYPE 8095 1.1 mrg || c2 == FIXED_POINT_TYPE)); 8096 1.1 mrg 8097 1.1 mrg t1 = c_common_signed_type (t1); 8098 1.1 mrg t2 = c_common_signed_type (t2); 8099 1.1 mrg /* Equality works here because c_common_signed_type uses 8100 1.1 mrg TYPE_MAIN_VARIANT. */ 8101 1.1 mrg if (t1 == t2) 8102 1.1 mrg return true; 8103 1.1 mrg if (opaque && c1 == c2 8104 1.1 mrg && (INTEGRAL_TYPE_P (t1) || c1 == REAL_TYPE) 8105 1.1 mrg && TYPE_PRECISION (t1) == TYPE_PRECISION (t2)) 8106 1.1 mrg return true; 8107 1.1 mrg return false; 8108 1.1 mrg } 8109 1.1 mrg 8110 1.1 mrg /* Check for missing format attributes on function pointers. LTYPE is 8111 1.1 mrg the new type or left-hand side type. RTYPE is the old type or 8112 1.1 mrg right-hand side type. Returns TRUE if LTYPE is missing the desired 8113 1.1 mrg attribute. */ 8114 1.1 mrg 8115 1.1 mrg bool 8116 1.1 mrg check_missing_format_attribute (tree ltype, tree rtype) 8117 1.1 mrg { 8118 1.1 mrg tree const ttr = TREE_TYPE (rtype), ttl = TREE_TYPE (ltype); 8119 1.1 mrg tree ra; 8120 1.1 mrg 8121 1.1 mrg for (ra = TYPE_ATTRIBUTES (ttr); ra; ra = TREE_CHAIN (ra)) 8122 1.1 mrg if (is_attribute_p ("format", get_attribute_name (ra))) 8123 1.1 mrg break; 8124 1.1 mrg if (ra) 8125 1.1 mrg { 8126 1.1 mrg tree la; 8127 1.1 mrg for (la = TYPE_ATTRIBUTES (ttl); la; la = TREE_CHAIN (la)) 8128 1.1 mrg if (is_attribute_p ("format", get_attribute_name (la))) 8129 1.1 mrg break; 8130 1.1 mrg return !la; 8131 1.1 mrg } 8132 1.1 mrg else 8133 1.1 mrg return false; 8134 1.1 mrg } 8135 1.1 mrg 8136 1.1 mrg /* Setup a TYPE_DECL node as a typedef representation. 8137 1.1 mrg 8138 1.1 mrg X is a TYPE_DECL for a typedef statement. Create a brand new 8139 1.1 mrg ..._TYPE node (which will be just a variant of the existing 8140 1.1 mrg ..._TYPE node with identical properties) and then install X 8141 1.1 mrg as the TYPE_NAME of this brand new (duplicate) ..._TYPE node. 8142 1.1 mrg 8143 1.1 mrg The whole point here is to end up with a situation where each 8144 1.1 mrg and every ..._TYPE node the compiler creates will be uniquely 8145 1.1 mrg associated with AT MOST one node representing a typedef name. 8146 1.1 mrg This way, even though the compiler substitutes corresponding 8147 1.1 mrg ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very 8148 1.1 mrg early on, later parts of the compiler can always do the reverse 8149 1.1 mrg translation and get back the corresponding typedef name. For 8150 1.1 mrg example, given: 8151 1.1 mrg 8152 1.1 mrg typedef struct S MY_TYPE; 8153 1.1 mrg MY_TYPE object; 8154 1.1 mrg 8155 1.1 mrg Later parts of the compiler might only know that `object' was of 8156 1.1 mrg type `struct S' if it were not for code just below. With this 8157 1.1 mrg code however, later parts of the compiler see something like: 8158 1.1 mrg 8159 1.1 mrg struct S' == struct S 8160 1.1 mrg typedef struct S' MY_TYPE; 8161 1.1 mrg struct S' object; 8162 1.1 mrg 8163 1.1 mrg And they can then deduce (from the node for type struct S') that 8164 1.1 mrg the original object declaration was: 8165 1.1 mrg 8166 1.1 mrg MY_TYPE object; 8167 1.1 mrg 8168 1.1 mrg Being able to do this is important for proper support of protoize, 8169 1.1 mrg and also for generating precise symbolic debugging information 8170 1.1 mrg which takes full account of the programmer's (typedef) vocabulary. 8171 1.1 mrg 8172 1.1 mrg Obviously, we don't want to generate a duplicate ..._TYPE node if 8173 1.1 mrg the TYPE_DECL node that we are now processing really represents a 8174 1.1 mrg standard built-in type. */ 8175 1.1 mrg 8176 1.1 mrg void 8177 1.1 mrg set_underlying_type (tree x) 8178 1.1 mrg { 8179 1.1 mrg if (x == error_mark_node) 8180 1.1 mrg return; 8181 1.1 mrg if (DECL_IS_UNDECLARED_BUILTIN (x) && TREE_CODE (TREE_TYPE (x)) != ARRAY_TYPE) 8182 1.1 mrg { 8183 1.1 mrg if (TYPE_NAME (TREE_TYPE (x)) == 0) 8184 1.1 mrg TYPE_NAME (TREE_TYPE (x)) = x; 8185 1.1 mrg } 8186 1.1 mrg else if (TREE_TYPE (x) != error_mark_node 8187 1.1 mrg && DECL_ORIGINAL_TYPE (x) == NULL_TREE) 8188 1.1 mrg { 8189 1.1 mrg tree tt = TREE_TYPE (x); 8190 1.1 mrg DECL_ORIGINAL_TYPE (x) = tt; 8191 1.1 mrg tt = build_variant_type_copy (tt); 8192 1.1 mrg TYPE_STUB_DECL (tt) = TYPE_STUB_DECL (DECL_ORIGINAL_TYPE (x)); 8193 1.1 mrg TYPE_NAME (tt) = x; 8194 1.1 mrg 8195 1.1 mrg /* Mark the type as used only when its type decl is decorated 8196 1.1 mrg with attribute unused. */ 8197 1.1 mrg if (lookup_attribute ("unused", DECL_ATTRIBUTES (x))) 8198 1.1 mrg TREE_USED (tt) = 1; 8199 1.1 mrg 8200 1.1 mrg TREE_TYPE (x) = tt; 8201 1.1 mrg } 8202 1.1 mrg } 8203 1.1 mrg 8204 1.1 mrg /* Return true if it is worth exposing the DECL_ORIGINAL_TYPE of TYPE to 8205 1.1 mrg the user in diagnostics, false if it would be better to use TYPE itself. 8206 1.1 mrg TYPE is known to satisfy typedef_variant_p. */ 8207 1.1 mrg 8208 1.1 mrg bool 8209 1.1 mrg user_facing_original_type_p (const_tree type) 8210 1.1 mrg { 8211 1.1 mrg gcc_assert (typedef_variant_p (type)); 8212 1.1 mrg tree decl = TYPE_NAME (type); 8213 1.1 mrg 8214 1.1 mrg /* Look through any typedef in "user" code. */ 8215 1.1 mrg if (!DECL_IN_SYSTEM_HEADER (decl) && !DECL_IS_UNDECLARED_BUILTIN (decl)) 8216 1.1 mrg return true; 8217 1.1 mrg 8218 1.1 mrg /* If the original type is also named and is in the user namespace, 8219 1.1 mrg assume it too is a user-facing type. */ 8220 1.1 mrg tree orig_type = DECL_ORIGINAL_TYPE (decl); 8221 1.1 mrg if (tree orig_id = TYPE_IDENTIFIER (orig_type)) 8222 1.1 mrg if (!name_reserved_for_implementation_p (IDENTIFIER_POINTER (orig_id))) 8223 1.1 mrg return true; 8224 1.1 mrg 8225 1.1 mrg switch (TREE_CODE (orig_type)) 8226 1.1 mrg { 8227 1.1 mrg /* Don't look through to an anonymous vector type, since the syntax 8228 1.1 mrg we use for them in diagnostics isn't real C or C++ syntax. 8229 1.1 mrg And if ORIG_TYPE is named but in the implementation namespace, 8230 1.1 mrg TYPE is likely to be more meaningful to the user. */ 8231 1.1 mrg case VECTOR_TYPE: 8232 1.1 mrg return false; 8233 1.1 mrg 8234 1.1 mrg /* Don't expose anonymous tag types that are presumably meant to be 8235 1.1 mrg known by their typedef name. Also don't expose tags that are in 8236 1.1 mrg the implementation namespace, such as: 8237 1.1 mrg 8238 1.1 mrg typedef struct __foo foo; */ 8239 1.1 mrg case RECORD_TYPE: 8240 1.1 mrg case UNION_TYPE: 8241 1.1 mrg case ENUMERAL_TYPE: 8242 1.1 mrg return false; 8243 1.1 mrg 8244 1.1 mrg /* Look through to anything else. */ 8245 1.1 mrg default: 8246 1.1 mrg return true; 8247 1.1 mrg } 8248 1.1 mrg } 8249 1.1 mrg 8250 1.1 mrg /* Record the types used by the current global variable declaration 8251 1.1 mrg being parsed, so that we can decide later to emit their debug info. 8252 1.1 mrg Those types are in types_used_by_cur_var_decl, and we are going to 8253 1.1 mrg store them in the types_used_by_vars_hash hash table. 8254 1.1 mrg DECL is the declaration of the global variable that has been parsed. */ 8255 1.1 mrg 8256 1.1 mrg void 8257 1.1 mrg record_types_used_by_current_var_decl (tree decl) 8258 1.1 mrg { 8259 1.1 mrg gcc_assert (decl && DECL_P (decl) && TREE_STATIC (decl)); 8260 1.1 mrg 8261 1.1 mrg while (types_used_by_cur_var_decl && !types_used_by_cur_var_decl->is_empty ()) 8262 1.1 mrg { 8263 1.1 mrg tree type = types_used_by_cur_var_decl->pop (); 8264 1.1 mrg types_used_by_var_decl_insert (type, decl); 8265 1.1 mrg } 8266 1.1 mrg } 8267 1.1 mrg 8268 1.1 mrg /* The C and C++ parsers both use vectors to hold function arguments. 8269 1.1 mrg For efficiency, we keep a cache of unused vectors. This is the 8270 1.1 mrg cache. */ 8271 1.1 mrg 8272 1.1 mrg typedef vec<tree, va_gc> *tree_gc_vec; 8273 1.1 mrg static GTY((deletable)) vec<tree_gc_vec, va_gc> *tree_vector_cache; 8274 1.1 mrg 8275 1.1 mrg /* Return a new vector from the cache. If the cache is empty, 8276 1.1 mrg allocate a new vector. These vectors are GC'ed, so it is OK if the 8277 1.1 mrg pointer is not released.. */ 8278 1.1 mrg 8279 1.1 mrg vec<tree, va_gc> * 8280 1.1 mrg make_tree_vector (void) 8281 1.1 mrg { 8282 1.1 mrg if (tree_vector_cache && !tree_vector_cache->is_empty ()) 8283 1.1 mrg return tree_vector_cache->pop (); 8284 1.1 mrg else 8285 1.1 mrg { 8286 1.1 mrg /* Passing 0 to vec::alloc returns NULL, and our callers require 8287 1.1 mrg that we always return a non-NULL value. The vector code uses 8288 1.1 mrg 4 when growing a NULL vector, so we do too. */ 8289 1.1 mrg vec<tree, va_gc> *v; 8290 1.1 mrg vec_alloc (v, 4); 8291 1.1 mrg return v; 8292 1.1 mrg } 8293 1.1 mrg } 8294 1.1 mrg 8295 1.1 mrg /* Release a vector of trees back to the cache. */ 8296 1.1 mrg 8297 1.1 mrg void 8298 1.1 mrg release_tree_vector (vec<tree, va_gc> *vec) 8299 1.1 mrg { 8300 1.1 mrg if (vec != NULL) 8301 1.1 mrg { 8302 1.1 mrg if (vec->allocated () >= 16) 8303 1.1 mrg /* Don't cache vecs that have expanded more than once. On a p64 8304 1.1 mrg target, vecs double in alloc size with each power of 2 elements, e.g 8305 1.1 mrg at 16 elements the alloc increases from 128 to 256 bytes. */ 8306 1.1 mrg vec_free (vec); 8307 1.1 mrg else 8308 1.1 mrg { 8309 1.1 mrg vec->truncate (0); 8310 1.1 mrg vec_safe_push (tree_vector_cache, vec); 8311 1.1 mrg } 8312 1.1 mrg } 8313 1.1 mrg } 8314 1.1 mrg 8315 1.1 mrg /* Get a new tree vector holding a single tree. */ 8316 1.1 mrg 8317 1.1 mrg vec<tree, va_gc> * 8318 1.1 mrg make_tree_vector_single (tree t) 8319 1.1 mrg { 8320 1.1 mrg vec<tree, va_gc> *ret = make_tree_vector (); 8321 1.1 mrg ret->quick_push (t); 8322 1.1 mrg return ret; 8323 1.1 mrg } 8324 1.1 mrg 8325 1.1 mrg /* Get a new tree vector of the TREE_VALUEs of a TREE_LIST chain. */ 8326 1.1 mrg 8327 1.1 mrg vec<tree, va_gc> * 8328 1.1 mrg make_tree_vector_from_list (tree list) 8329 1.1 mrg { 8330 1.1 mrg vec<tree, va_gc> *ret = make_tree_vector (); 8331 1.1 mrg for (; list; list = TREE_CHAIN (list)) 8332 1.1 mrg vec_safe_push (ret, TREE_VALUE (list)); 8333 1.1 mrg return ret; 8334 1.1 mrg } 8335 1.1 mrg 8336 1.1 mrg /* Get a new tree vector of the values of a CONSTRUCTOR. */ 8337 1.1 mrg 8338 1.1 mrg vec<tree, va_gc> * 8339 1.1 mrg make_tree_vector_from_ctor (tree ctor) 8340 1.1 mrg { 8341 1.1 mrg vec<tree,va_gc> *ret = make_tree_vector (); 8342 1.1 mrg vec_safe_reserve (ret, CONSTRUCTOR_NELTS (ctor)); 8343 1.1 mrg for (unsigned i = 0; i < CONSTRUCTOR_NELTS (ctor); ++i) 8344 1.1 mrg ret->quick_push (CONSTRUCTOR_ELT (ctor, i)->value); 8345 1.1 mrg return ret; 8346 1.1 mrg } 8347 1.1 mrg 8348 1.1 mrg /* Get a new tree vector which is a copy of an existing one. */ 8349 1.1 mrg 8350 1.1 mrg vec<tree, va_gc> * 8351 1.1 mrg make_tree_vector_copy (const vec<tree, va_gc> *orig) 8352 1.1 mrg { 8353 1.1 mrg vec<tree, va_gc> *ret; 8354 1.1 mrg unsigned int ix; 8355 1.1 mrg tree t; 8356 1.1 mrg 8357 1.1 mrg ret = make_tree_vector (); 8358 1.1 mrg vec_safe_reserve (ret, vec_safe_length (orig)); 8359 1.1 mrg FOR_EACH_VEC_SAFE_ELT (orig, ix, t) 8360 1.1 mrg ret->quick_push (t); 8361 1.1 mrg return ret; 8362 1.1 mrg } 8363 1.1 mrg 8364 1.1 mrg /* Return true if KEYWORD starts a type specifier. */ 8365 1.1 mrg 8366 1.1 mrg bool 8367 1.1 mrg keyword_begins_type_specifier (enum rid keyword) 8368 1.1 mrg { 8369 1.1 mrg switch (keyword) 8370 1.1 mrg { 8371 1.1 mrg case RID_AUTO_TYPE: 8372 1.1 mrg case RID_INT: 8373 1.1 mrg case RID_CHAR: 8374 1.1 mrg case RID_FLOAT: 8375 1.1 mrg case RID_DOUBLE: 8376 1.1 mrg case RID_VOID: 8377 1.1 mrg case RID_UNSIGNED: 8378 1.1 mrg case RID_LONG: 8379 1.1 mrg case RID_SHORT: 8380 1.1 mrg case RID_SIGNED: 8381 1.1 mrg CASE_RID_FLOATN_NX: 8382 1.1 mrg case RID_DFLOAT32: 8383 1.1 mrg case RID_DFLOAT64: 8384 1.1 mrg case RID_DFLOAT128: 8385 1.1 mrg case RID_FRACT: 8386 1.1 mrg case RID_ACCUM: 8387 1.1 mrg case RID_BOOL: 8388 1.1 mrg case RID_WCHAR: 8389 1.1 mrg case RID_CHAR8: 8390 1.1 mrg case RID_CHAR16: 8391 1.1 mrg case RID_CHAR32: 8392 1.1 mrg case RID_SAT: 8393 1.1 mrg case RID_COMPLEX: 8394 1.1 mrg case RID_TYPEOF: 8395 1.1 mrg case RID_STRUCT: 8396 1.1 mrg case RID_CLASS: 8397 1.1 mrg case RID_UNION: 8398 1.1 mrg case RID_ENUM: 8399 1.1 mrg return true; 8400 1.1 mrg default: 8401 1.1 mrg if (keyword >= RID_FIRST_INT_N 8402 1.1 mrg && keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS 8403 1.1 mrg && int_n_enabled_p[keyword-RID_FIRST_INT_N]) 8404 1.1 mrg return true; 8405 1.1 mrg return false; 8406 1.1 mrg } 8407 1.1 mrg } 8408 1.1 mrg 8409 1.1 mrg /* Return true if KEYWORD names a type qualifier. */ 8410 1.1 mrg 8411 1.1 mrg bool 8412 1.1 mrg keyword_is_type_qualifier (enum rid keyword) 8413 1.1 mrg { 8414 1.1 mrg switch (keyword) 8415 1.1 mrg { 8416 1.1 mrg case RID_CONST: 8417 1.1 mrg case RID_VOLATILE: 8418 1.1 mrg case RID_RESTRICT: 8419 1.1 mrg case RID_ATOMIC: 8420 1.1 mrg return true; 8421 1.1 mrg default: 8422 1.1 mrg return false; 8423 1.1 mrg } 8424 1.1 mrg } 8425 1.1 mrg 8426 1.1 mrg /* Return true if KEYWORD names a storage class specifier. 8427 1.1 mrg 8428 1.1 mrg RID_TYPEDEF is not included in this list despite `typedef' being 8429 1.1 mrg listed in C99 6.7.1.1. 6.7.1.3 indicates that `typedef' is listed as 8430 1.1 mrg such for syntactic convenience only. */ 8431 1.1 mrg 8432 1.1 mrg bool 8433 1.1 mrg keyword_is_storage_class_specifier (enum rid keyword) 8434 1.1 mrg { 8435 1.1 mrg switch (keyword) 8436 1.1 mrg { 8437 1.1 mrg case RID_STATIC: 8438 1.1 mrg case RID_EXTERN: 8439 1.1 mrg case RID_REGISTER: 8440 1.1 mrg case RID_AUTO: 8441 1.1 mrg case RID_MUTABLE: 8442 1.1 mrg case RID_THREAD: 8443 1.1 mrg return true; 8444 1.1 mrg default: 8445 1.1 mrg return false; 8446 1.1 mrg } 8447 1.1 mrg } 8448 1.1 mrg 8449 1.1 mrg /* Return true if KEYWORD names a function-specifier [dcl.fct.spec]. */ 8450 1.1 mrg 8451 1.1 mrg static bool 8452 1.1 mrg keyword_is_function_specifier (enum rid keyword) 8453 1.1 mrg { 8454 1.1 mrg switch (keyword) 8455 1.1 mrg { 8456 1.1 mrg case RID_INLINE: 8457 1.1 mrg case RID_NORETURN: 8458 1.1 mrg case RID_VIRTUAL: 8459 1.1 mrg case RID_EXPLICIT: 8460 1.1 mrg return true; 8461 1.1 mrg default: 8462 1.1 mrg return false; 8463 1.1 mrg } 8464 1.1 mrg } 8465 1.1 mrg 8466 1.1 mrg /* Return true if KEYWORD names a decl-specifier [dcl.spec] or a 8467 1.1 mrg declaration-specifier (C99 6.7). */ 8468 1.1 mrg 8469 1.1 mrg bool 8470 1.1 mrg keyword_is_decl_specifier (enum rid keyword) 8471 1.1 mrg { 8472 1.1 mrg if (keyword_is_storage_class_specifier (keyword) 8473 1.1 mrg || keyword_is_type_qualifier (keyword) 8474 1.1 mrg || keyword_is_function_specifier (keyword)) 8475 1.1 mrg return true; 8476 1.1 mrg 8477 1.1 mrg switch (keyword) 8478 1.1 mrg { 8479 1.1 mrg case RID_TYPEDEF: 8480 1.1 mrg case RID_FRIEND: 8481 1.1 mrg case RID_CONSTEXPR: 8482 1.1 mrg case RID_CONSTINIT: 8483 1.1 mrg return true; 8484 1.1 mrg default: 8485 1.1 mrg return false; 8486 1.1 mrg } 8487 1.1 mrg } 8488 1.1 mrg 8489 1.1 mrg /* Initialize language-specific-bits of tree_contains_struct. */ 8490 1.1 mrg 8491 1.1 mrg void 8492 1.1 mrg c_common_init_ts (void) 8493 1.1 mrg { 8494 1.1 mrg MARK_TS_EXP (SIZEOF_EXPR); 8495 1.1 mrg MARK_TS_EXP (PAREN_SIZEOF_EXPR); 8496 1.1 mrg MARK_TS_EXP (C_MAYBE_CONST_EXPR); 8497 1.1 mrg MARK_TS_EXP (EXCESS_PRECISION_EXPR); 8498 1.1 mrg MARK_TS_EXP (BREAK_STMT); 8499 1.1 mrg MARK_TS_EXP (CONTINUE_STMT); 8500 1.1 mrg MARK_TS_EXP (DO_STMT); 8501 1.1 mrg MARK_TS_EXP (FOR_STMT); 8502 1.1 mrg MARK_TS_EXP (SWITCH_STMT); 8503 1.1 mrg MARK_TS_EXP (WHILE_STMT); 8504 1.1 mrg } 8505 1.1 mrg 8506 1.1 mrg /* Build a user-defined numeric literal out of an integer constant type VALUE 8507 1.1 mrg with identifier SUFFIX. */ 8508 1.1 mrg 8509 1.1 mrg tree 8510 1.1 mrg build_userdef_literal (tree suffix_id, tree value, 8511 1.1 mrg enum overflow_type overflow, tree num_string) 8512 1.1 mrg { 8513 1.1 mrg tree literal = make_node (USERDEF_LITERAL); 8514 1.1 mrg USERDEF_LITERAL_SUFFIX_ID (literal) = suffix_id; 8515 1.1 mrg USERDEF_LITERAL_VALUE (literal) = value; 8516 1.1 mrg USERDEF_LITERAL_OVERFLOW (literal) = overflow; 8517 1.1 mrg USERDEF_LITERAL_NUM_STRING (literal) = num_string; 8518 1.1 mrg return literal; 8519 1.1 mrg } 8520 1.1 mrg 8521 1.1 mrg /* For vector[index], convert the vector to an array of the underlying type. 8522 1.1 mrg Return true if the resulting ARRAY_REF should not be an lvalue. */ 8523 1.1 mrg 8524 1.1 mrg bool 8525 1.1 mrg convert_vector_to_array_for_subscript (location_t loc, 8526 1.1 mrg tree *vecp, tree index) 8527 1.1 mrg { 8528 1.1 mrg bool ret = false; 8529 1.1 mrg if (gnu_vector_type_p (TREE_TYPE (*vecp))) 8530 1.1 mrg { 8531 1.1 mrg tree type = TREE_TYPE (*vecp); 8532 1.1 mrg tree newitype; 8533 1.1 mrg 8534 1.1 mrg ret = !lvalue_p (*vecp); 8535 1.1 mrg 8536 1.1 mrg index = fold_for_warn (index); 8537 1.1 mrg if (TREE_CODE (index) == INTEGER_CST) 8538 1.1 mrg if (!tree_fits_uhwi_p (index) 8539 1.1 mrg || maybe_ge (tree_to_uhwi (index), TYPE_VECTOR_SUBPARTS (type))) 8540 1.1 mrg warning_at (loc, OPT_Warray_bounds, "index value is out of bound"); 8541 1.1 mrg 8542 1.1 mrg /* We are building an ARRAY_REF so mark the vector as addressable 8543 1.1 mrg to not run into the gimplifiers premature setting of DECL_GIMPLE_REG_P 8544 1.1 mrg for function parameters. */ 8545 1.1 mrg c_common_mark_addressable_vec (*vecp); 8546 1.1 mrg 8547 1.1 mrg /* Make sure qualifiers are copied from the vector type to the new element 8548 1.1 mrg of the array type. */ 8549 1.1 mrg newitype = build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type)); 8550 1.1 mrg 8551 1.1 mrg *vecp = build1 (VIEW_CONVERT_EXPR, 8552 1.1 mrg build_array_type_nelts (newitype, 8553 1.1 mrg TYPE_VECTOR_SUBPARTS (type)), 8554 1.1 mrg *vecp); 8555 1.1 mrg } 8556 1.1 mrg return ret; 8557 1.1 mrg } 8558 1.1 mrg 8559 1.1 mrg /* Determine which of the operands, if any, is a scalar that needs to be 8560 1.1 mrg converted to a vector, for the range of operations. */ 8561 1.1 mrg enum stv_conv 8562 1.1 mrg scalar_to_vector (location_t loc, enum tree_code code, tree op0, tree op1, 8563 1.1 mrg bool complain) 8564 1.1 mrg { 8565 1.1 mrg tree type0 = TREE_TYPE (op0); 8566 1.1 mrg tree type1 = TREE_TYPE (op1); 8567 1.1 mrg bool integer_only_op = false; 8568 1.1 mrg enum stv_conv ret = stv_firstarg; 8569 1.1 mrg 8570 1.1 mrg gcc_assert (gnu_vector_type_p (type0) || gnu_vector_type_p (type1)); 8571 1.1 mrg switch (code) 8572 1.1 mrg { 8573 1.1 mrg /* Most GENERIC binary expressions require homogeneous arguments. 8574 1.1 mrg LSHIFT_EXPR and RSHIFT_EXPR are exceptions and accept a first 8575 1.1 mrg argument that is a vector and a second one that is a scalar, so 8576 1.1 mrg we never return stv_secondarg for them. */ 8577 1.1 mrg case RSHIFT_EXPR: 8578 1.1 mrg case LSHIFT_EXPR: 8579 1.1 mrg if (TREE_CODE (type0) == INTEGER_TYPE 8580 1.1 mrg && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE) 8581 1.1 mrg { 8582 1.1 mrg if (unsafe_conversion_p (TREE_TYPE (type1), op0, 8583 1.1 mrg NULL_TREE, false)) 8584 1.1 mrg { 8585 1.1 mrg if (complain) 8586 1.1 mrg error_at (loc, "conversion of scalar %qT to vector %qT " 8587 1.1 mrg "involves truncation", type0, type1); 8588 1.1 mrg return stv_error; 8589 1.1 mrg } 8590 1.1 mrg else 8591 1.1 mrg return stv_firstarg; 8592 1.1 mrg } 8593 1.1 mrg break; 8594 1.1 mrg 8595 1.1 mrg case BIT_IOR_EXPR: 8596 1.1 mrg case BIT_XOR_EXPR: 8597 1.1 mrg case BIT_AND_EXPR: 8598 1.1 mrg integer_only_op = true; 8599 1.1 mrg /* fall through */ 8600 1.1 mrg 8601 1.1 mrg case VEC_COND_EXPR: 8602 1.1 mrg 8603 1.1 mrg case PLUS_EXPR: 8604 1.1 mrg case MINUS_EXPR: 8605 1.1 mrg case MULT_EXPR: 8606 1.1 mrg case TRUNC_DIV_EXPR: 8607 1.1 mrg case CEIL_DIV_EXPR: 8608 1.1 mrg case FLOOR_DIV_EXPR: 8609 1.1 mrg case ROUND_DIV_EXPR: 8610 1.1 mrg case EXACT_DIV_EXPR: 8611 1.1 mrg case TRUNC_MOD_EXPR: 8612 1.1 mrg case FLOOR_MOD_EXPR: 8613 1.1 mrg case RDIV_EXPR: 8614 1.1 mrg case EQ_EXPR: 8615 1.1 mrg case NE_EXPR: 8616 1.1 mrg case LE_EXPR: 8617 1.1 mrg case GE_EXPR: 8618 1.1 mrg case LT_EXPR: 8619 1.1 mrg case GT_EXPR: 8620 1.1 mrg /* What about UNLT_EXPR? */ 8621 1.1 mrg if (gnu_vector_type_p (type0)) 8622 1.1 mrg { 8623 1.1 mrg ret = stv_secondarg; 8624 1.1 mrg std::swap (type0, type1); 8625 1.1 mrg std::swap (op0, op1); 8626 1.1 mrg } 8627 1.1 mrg 8628 1.1 mrg if (TREE_CODE (type0) == INTEGER_TYPE 8629 1.1 mrg && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE) 8630 1.1 mrg { 8631 1.1 mrg if (unsafe_conversion_p (TREE_TYPE (type1), op0, 8632 1.1 mrg NULL_TREE, false)) 8633 1.1 mrg { 8634 1.1 mrg if (complain) 8635 1.1 mrg error_at (loc, "conversion of scalar %qT to vector %qT " 8636 1.1 mrg "involves truncation", type0, type1); 8637 1.1 mrg return stv_error; 8638 1.1 mrg } 8639 1.1 mrg return ret; 8640 1.1 mrg } 8641 1.1 mrg else if (!integer_only_op 8642 1.1 mrg /* Allow integer --> real conversion if safe. */ 8643 1.1 mrg && (TREE_CODE (type0) == REAL_TYPE 8644 1.1 mrg || TREE_CODE (type0) == INTEGER_TYPE) 8645 1.1 mrg && SCALAR_FLOAT_TYPE_P (TREE_TYPE (type1))) 8646 1.1 mrg { 8647 1.1 mrg if (unsafe_conversion_p (TREE_TYPE (type1), op0, 8648 1.1 mrg NULL_TREE, false)) 8649 1.1 mrg { 8650 1.1 mrg if (complain) 8651 1.1 mrg error_at (loc, "conversion of scalar %qT to vector %qT " 8652 1.1 mrg "involves truncation", type0, type1); 8653 1.1 mrg return stv_error; 8654 1.1 mrg } 8655 1.1 mrg return ret; 8656 1.1 mrg } 8657 1.1 mrg default: 8658 1.1 mrg break; 8659 1.1 mrg } 8660 1.1 mrg 8661 1.1 mrg return stv_nothing; 8662 1.1 mrg } 8663 1.1 mrg 8664 1.1 mrg /* Return the alignment of std::max_align_t. 8665 1.1 mrg 8666 1.1 mrg [support.types.layout] The type max_align_t is a POD type whose alignment 8667 1.1 mrg requirement is at least as great as that of every scalar type, and whose 8668 1.1 mrg alignment requirement is supported in every context. */ 8669 1.1 mrg 8670 1.1 mrg unsigned 8671 1.1 mrg max_align_t_align () 8672 1.1 mrg { 8673 1.1 mrg unsigned int max_align = MAX (TYPE_ALIGN (long_long_integer_type_node), 8674 1.1 mrg TYPE_ALIGN (long_double_type_node)); 8675 1.1 mrg if (float128_type_node != NULL_TREE) 8676 1.1 mrg max_align = MAX (max_align, TYPE_ALIGN (float128_type_node)); 8677 1.1 mrg return max_align; 8678 1.1 mrg } 8679 1.1 mrg 8680 1.1 mrg /* Return true iff ALIGN is an integral constant that is a fundamental 8681 1.1 mrg alignment, as defined by [basic.align] in the c++-11 8682 1.1 mrg specifications. 8683 1.1 mrg 8684 1.1 mrg That is: 8685 1.1 mrg 8686 1.1 mrg [A fundamental alignment is represented by an alignment less than or 8687 1.1 mrg equal to the greatest alignment supported by the implementation 8688 1.1 mrg in all contexts, which is equal to alignof(max_align_t)]. */ 8689 1.1 mrg 8690 1.1 mrg bool 8691 1.1 mrg cxx_fundamental_alignment_p (unsigned align) 8692 1.1 mrg { 8693 1.1 mrg return (align <= max_align_t_align ()); 8694 1.1 mrg } 8695 1.1 mrg 8696 1.1 mrg /* Return true if T is a pointer to a zero-sized aggregate. */ 8697 1.1 mrg 8698 1.1 mrg bool 8699 1.1 mrg pointer_to_zero_sized_aggr_p (tree t) 8700 1.1 mrg { 8701 1.1 mrg if (!POINTER_TYPE_P (t)) 8702 1.1 mrg return false; 8703 1.1 mrg t = TREE_TYPE (t); 8704 1.1 mrg return (TYPE_SIZE (t) && integer_zerop (TYPE_SIZE (t))); 8705 1.1 mrg } 8706 1.1 mrg 8707 1.1 mrg /* For an EXPR of a FUNCTION_TYPE that references a GCC built-in function 8708 1.1 mrg with no library fallback or for an ADDR_EXPR whose operand is such type 8709 1.1 mrg issues an error pointing to the location LOC. 8710 1.1 mrg Returns true when the expression has been diagnosed and false 8711 1.1 mrg otherwise. */ 8712 1.1 mrg 8713 1.1 mrg bool 8714 1.1 mrg reject_gcc_builtin (const_tree expr, location_t loc /* = UNKNOWN_LOCATION */) 8715 1.1 mrg { 8716 1.1 mrg if (TREE_CODE (expr) == ADDR_EXPR) 8717 1.1 mrg expr = TREE_OPERAND (expr, 0); 8718 1.1 mrg 8719 1.1 mrg STRIP_ANY_LOCATION_WRAPPER (expr); 8720 1.1 mrg 8721 1.1 mrg if (TREE_TYPE (expr) 8722 1.1 mrg && TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE 8723 1.1 mrg && TREE_CODE (expr) == FUNCTION_DECL 8724 1.1 mrg /* The intersection of DECL_BUILT_IN and DECL_IS_UNDECLARED_BUILTIN avoids 8725 1.1 mrg false positives for user-declared built-ins such as abs or 8726 1.1 mrg strlen, and for C++ operators new and delete. 8727 1.1 mrg The c_decl_implicit() test avoids false positives for implicitly 8728 1.1 mrg declared built-ins with library fallbacks (such as abs). */ 8729 1.1 mrg && fndecl_built_in_p (expr) 8730 1.1 mrg && DECL_IS_UNDECLARED_BUILTIN (expr) 8731 1.1 mrg && !c_decl_implicit (expr) 8732 1.1 mrg && !DECL_ASSEMBLER_NAME_SET_P (expr)) 8733 1.1 mrg { 8734 1.1 mrg if (loc == UNKNOWN_LOCATION) 8735 1.1 mrg loc = EXPR_LOC_OR_LOC (expr, input_location); 8736 1.1 mrg 8737 1.1 mrg /* Reject arguments that are built-in functions with 8738 1.1 mrg no library fallback. */ 8739 1.1 mrg error_at (loc, "built-in function %qE must be directly called", expr); 8740 1.1 mrg 8741 1.1 mrg return true; 8742 1.1 mrg } 8743 1.1 mrg 8744 1.1 mrg return false; 8745 1.1 mrg } 8746 1.1 mrg 8747 1.1 mrg /* Issue an ERROR for an invalid SIZE of array NAME which is null 8748 1.1 mrg for unnamed arrays. */ 8749 1.1 mrg 8750 1.1 mrg void 8751 1.1 mrg invalid_array_size_error (location_t loc, cst_size_error error, 8752 1.1 mrg const_tree size, const_tree name) 8753 1.1 mrg { 8754 1.1 mrg tree maxsize = max_object_size (); 8755 1.1 mrg switch (error) 8756 1.1 mrg { 8757 1.1 mrg case cst_size_not_constant: 8758 1.1 mrg if (name) 8759 1.1 mrg error_at (loc, "size of array %qE is not a constant expression", 8760 1.1 mrg name); 8761 1.1 mrg else 8762 1.1 mrg error_at (loc, "size of array is not a constant expression"); 8763 1.1 mrg break; 8764 1.1 mrg case cst_size_negative: 8765 1.1 mrg if (name) 8766 1.1 mrg error_at (loc, "size %qE of array %qE is negative", 8767 1.1 mrg size, name); 8768 1.1 mrg else 8769 1.1 mrg error_at (loc, "size %qE of array is negative", 8770 1.1 mrg size); 8771 1.1 mrg break; 8772 1.1 mrg case cst_size_too_big: 8773 1.1 mrg if (name) 8774 1.1 mrg error_at (loc, "size %qE of array %qE exceeds maximum " 8775 1.1 mrg "object size %qE", size, name, maxsize); 8776 1.1 mrg else 8777 1.1 mrg error_at (loc, "size %qE of array exceeds maximum " 8778 1.1 mrg "object size %qE", size, maxsize); 8779 1.1 mrg break; 8780 1.1 mrg case cst_size_overflow: 8781 1.1 mrg if (name) 8782 1.1 mrg error_at (loc, "size of array %qE exceeds maximum " 8783 1.1 mrg "object size %qE", name, maxsize); 8784 1.1 mrg else 8785 1.1 mrg error_at (loc, "size of array exceeds maximum " 8786 1.1 mrg "object size %qE", maxsize); 8787 1.1 mrg break; 8788 1.1 mrg default: 8789 1.1 mrg gcc_unreachable (); 8790 1.1 mrg } 8791 1.1 mrg } 8792 1.1 mrg 8793 1.1 mrg /* Check if array size calculations overflow or if the array covers more 8794 1.1 mrg than half of the address space. Return true if the size of the array 8795 1.1 mrg is valid, false otherwise. T is either the type of the array or its 8796 1.1 mrg size, and NAME is the name of the array, or null for unnamed arrays. */ 8797 1.1 mrg 8798 1.1 mrg bool 8799 1.1 mrg valid_array_size_p (location_t loc, const_tree t, tree name, bool complain) 8800 1.1 mrg { 8801 1.1 mrg if (t == error_mark_node) 8802 1.1 mrg return true; 8803 1.1 mrg 8804 1.1 mrg const_tree size; 8805 1.1 mrg if (TYPE_P (t)) 8806 1.1 mrg { 8807 1.1 mrg if (!COMPLETE_TYPE_P (t)) 8808 1.1 mrg return true; 8809 1.1 mrg size = TYPE_SIZE_UNIT (t); 8810 1.1 mrg } 8811 1.1 mrg else 8812 1.1 mrg size = t; 8813 1.1 mrg 8814 1.1 mrg if (TREE_CODE (size) != INTEGER_CST) 8815 1.1 mrg return true; 8816 1.1 mrg 8817 1.1 mrg cst_size_error error; 8818 1.1 mrg if (valid_constant_size_p (size, &error)) 8819 1.1 mrg return true; 8820 1.1 mrg 8821 1.1 mrg if (!complain) 8822 1.1 mrg return false; 8823 1.1 mrg 8824 1.1 mrg if (TREE_CODE (TREE_TYPE (size)) == ENUMERAL_TYPE) 8825 1.1 mrg /* Show the value of the enumerator rather than its name. */ 8826 1.1 mrg size = convert (ssizetype, const_cast<tree> (size)); 8827 1.1 mrg 8828 1.1 mrg invalid_array_size_error (loc, error, size, name); 8829 1.1 mrg return false; 8830 1.1 mrg } 8831 1.1 mrg 8832 1.1 mrg /* Read SOURCE_DATE_EPOCH from environment to have a deterministic 8833 1.1 mrg timestamp to replace embedded current dates to get reproducible 8834 1.1 mrg results. Returns -1 if SOURCE_DATE_EPOCH is not defined. */ 8835 1.1 mrg 8836 1.1 mrg time_t 8837 1.1 mrg cb_get_source_date_epoch (cpp_reader *pfile ATTRIBUTE_UNUSED) 8838 1.1 mrg { 8839 1.1 mrg char *source_date_epoch; 8840 1.1 mrg int64_t epoch; 8841 1.1 mrg char *endptr; 8842 1.1 mrg 8843 1.1 mrg source_date_epoch = getenv ("SOURCE_DATE_EPOCH"); 8844 1.1 mrg if (!source_date_epoch) 8845 1.1 mrg return (time_t) -1; 8846 1.1 mrg 8847 1.1 mrg errno = 0; 8848 1.1 mrg #if defined(INT64_T_IS_LONG) 8849 1.1 mrg epoch = strtol (source_date_epoch, &endptr, 10); 8850 1.1 mrg #else 8851 1.1 mrg epoch = strtoll (source_date_epoch, &endptr, 10); 8852 1.1 mrg #endif 8853 1.1 mrg if (errno != 0 || endptr == source_date_epoch || *endptr != '\0' 8854 1.1 mrg || epoch < 0 || epoch > MAX_SOURCE_DATE_EPOCH) 8855 1.1 mrg { 8856 1.1 mrg error_at (input_location, "environment variable %qs must " 8857 1.1 mrg "expand to a non-negative integer less than or equal to %wd", 8858 1.1 mrg "SOURCE_DATE_EPOCH", MAX_SOURCE_DATE_EPOCH); 8859 1.1 mrg return (time_t) -1; 8860 1.1 mrg } 8861 1.1 mrg 8862 1.1 mrg return (time_t) epoch; 8863 1.1 mrg } 8864 1.1 mrg 8865 1.1 mrg /* Callback for libcpp for offering spelling suggestions for misspelled 8866 1.1 mrg directives. GOAL is an unrecognized string; CANDIDATES is a 8867 1.1 mrg NULL-terminated array of candidate strings. Return the closest 8868 1.1 mrg match to GOAL within CANDIDATES, or NULL if none are good 8869 1.1 mrg suggestions. */ 8870 1.1 mrg 8871 1.1 mrg const char * 8872 1.1 mrg cb_get_suggestion (cpp_reader *, const char *goal, 8873 1.1 mrg const char *const *candidates) 8874 1.1 mrg { 8875 1.1 mrg best_match<const char *, const char *> bm (goal); 8876 1.1 mrg while (*candidates) 8877 1.1 mrg bm.consider (*candidates++); 8878 1.1 mrg return bm.get_best_meaningful_candidate (); 8879 1.1 mrg } 8880 1.1 mrg 8881 1.1 mrg /* Return the latice point which is the wider of the two FLT_EVAL_METHOD 8882 1.1 mrg modes X, Y. This isn't just >, as the FLT_EVAL_METHOD values added 8883 1.1 mrg by C TS 18661-3 for interchange types that are computed in their 8884 1.1 mrg native precision are larger than the C11 values for evaluating in the 8885 1.1 mrg precision of float/double/long double. If either mode is 8886 1.1 mrg FLT_EVAL_METHOD_UNPREDICTABLE, return that. */ 8887 1.1 mrg 8888 1.1 mrg enum flt_eval_method 8889 1.1 mrg excess_precision_mode_join (enum flt_eval_method x, 8890 1.1 mrg enum flt_eval_method y) 8891 1.1 mrg { 8892 1.1 mrg if (x == FLT_EVAL_METHOD_UNPREDICTABLE 8893 1.1 mrg || y == FLT_EVAL_METHOD_UNPREDICTABLE) 8894 1.1 mrg return FLT_EVAL_METHOD_UNPREDICTABLE; 8895 1.1 mrg 8896 1.1 mrg /* GCC only supports one interchange type right now, _Float16. If 8897 1.1 mrg we're evaluating _Float16 in 16-bit precision, then flt_eval_method 8898 1.1 mrg will be FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16. */ 8899 1.1 mrg if (x == FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16) 8900 1.1 mrg return y; 8901 1.1 mrg if (y == FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16) 8902 1.1 mrg return x; 8903 1.1 mrg 8904 1.1 mrg /* Other values for flt_eval_method are directly comparable, and we want 8905 1.1 mrg the maximum. */ 8906 1.1 mrg return MAX (x, y); 8907 1.1 mrg } 8908 1.1 mrg 8909 1.1 mrg /* Return the value that should be set for FLT_EVAL_METHOD in the 8910 1.1 mrg context of ISO/IEC TS 18861-3. 8911 1.1 mrg 8912 1.1 mrg This relates to the effective excess precision seen by the user, 8913 1.1 mrg which is the join point of the precision the target requests for 8914 1.1 mrg -fexcess-precision={standard,fast,16} and the implicit excess precision 8915 1.1 mrg the target uses. */ 8916 1.1 mrg 8917 1.1 mrg static enum flt_eval_method 8918 1.1 mrg c_ts18661_flt_eval_method (void) 8919 1.1 mrg { 8920 1.1 mrg enum flt_eval_method implicit 8921 1.1 mrg = targetm.c.excess_precision (EXCESS_PRECISION_TYPE_IMPLICIT); 8922 1.1 mrg 8923 1.1 mrg enum excess_precision_type flag_type 8924 1.1 mrg = (flag_excess_precision == EXCESS_PRECISION_STANDARD 8925 1.1 mrg ? EXCESS_PRECISION_TYPE_STANDARD 8926 1.1 mrg : (flag_excess_precision == EXCESS_PRECISION_FLOAT16 8927 1.1 mrg ? EXCESS_PRECISION_TYPE_FLOAT16 8928 1.1 mrg : EXCESS_PRECISION_TYPE_FAST)); 8929 1.1 mrg 8930 1.1 mrg enum flt_eval_method requested 8931 1.1 mrg = targetm.c.excess_precision (flag_type); 8932 1.1 mrg 8933 1.1 mrg return excess_precision_mode_join (implicit, requested); 8934 1.1 mrg } 8935 1.1 mrg 8936 1.1 mrg /* As c_cpp_ts18661_flt_eval_method, but clamps the expected values to 8937 1.1 mrg those that were permitted by C11. That is to say, eliminates 8938 1.1 mrg FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16. */ 8939 1.1 mrg 8940 1.1 mrg static enum flt_eval_method 8941 1.1 mrg c_c11_flt_eval_method (void) 8942 1.1 mrg { 8943 1.1 mrg return excess_precision_mode_join (c_ts18661_flt_eval_method (), 8944 1.1 mrg FLT_EVAL_METHOD_PROMOTE_TO_FLOAT); 8945 1.1 mrg } 8946 1.1 mrg 8947 1.1 mrg /* Return the value that should be set for FLT_EVAL_METHOD. 8948 1.1 mrg MAYBE_C11_ONLY_P is TRUE if we should check 8949 1.1 mrg FLAG_PERMITTED_EVAL_METHODS as to whether we should limit the possible 8950 1.1 mrg values we can return to those from C99/C11, and FALSE otherwise. 8951 1.1 mrg See the comments on c_ts18661_flt_eval_method for what value we choose 8952 1.1 mrg to set here. */ 8953 1.1 mrg 8954 1.1 mrg int 8955 1.1 mrg c_flt_eval_method (bool maybe_c11_only_p) 8956 1.1 mrg { 8957 1.1 mrg if (maybe_c11_only_p 8958 1.1 mrg && flag_permitted_flt_eval_methods 8959 1.1 mrg == PERMITTED_FLT_EVAL_METHODS_C11) 8960 1.1 mrg return c_c11_flt_eval_method (); 8961 1.1 mrg else 8962 1.1 mrg return c_ts18661_flt_eval_method (); 8963 1.1 mrg } 8964 1.1 mrg 8965 1.1 mrg /* An enum for get_missing_token_insertion_kind for describing the best 8966 1.1 mrg place to insert a missing token, if there is one. */ 8967 1.1 mrg 8968 1.1 mrg enum missing_token_insertion_kind 8969 1.1 mrg { 8970 1.1 mrg MTIK_IMPOSSIBLE, 8971 1.1 mrg MTIK_INSERT_BEFORE_NEXT, 8972 1.1 mrg MTIK_INSERT_AFTER_PREV 8973 1.1 mrg }; 8974 1.1 mrg 8975 1.1 mrg /* Given a missing token of TYPE, determine if it is reasonable to 8976 1.1 mrg emit a fix-it hint suggesting the insertion of the token, and, 8977 1.1 mrg if so, where the token should be inserted relative to other tokens. 8978 1.1 mrg 8979 1.1 mrg It only makes sense to do this for values of TYPE that are symbols. 8980 1.1 mrg 8981 1.1 mrg Some symbols should go before the next token, e.g. in: 8982 1.1 mrg if flag) 8983 1.1 mrg we want to insert the missing '(' immediately before "flag", 8984 1.1 mrg giving: 8985 1.1 mrg if (flag) 8986 1.1 mrg rather than: 8987 1.1 mrg if( flag) 8988 1.1 mrg These use MTIK_INSERT_BEFORE_NEXT. 8989 1.1 mrg 8990 1.1 mrg Other symbols should go after the previous token, e.g. in: 8991 1.1 mrg if (flag 8992 1.1 mrg do_something (); 8993 1.1 mrg we want to insert the missing ')' immediately after the "flag", 8994 1.1 mrg giving: 8995 1.1 mrg if (flag) 8996 1.1 mrg do_something (); 8997 1.1 mrg rather than: 8998 1.1 mrg if (flag 8999 1.1 mrg )do_something (); 9000 1.1 mrg These use MTIK_INSERT_AFTER_PREV. */ 9001 1.1 mrg 9002 1.1 mrg static enum missing_token_insertion_kind 9003 1.1 mrg get_missing_token_insertion_kind (enum cpp_ttype type) 9004 1.1 mrg { 9005 1.1 mrg switch (type) 9006 1.1 mrg { 9007 1.1 mrg /* Insert missing "opening" brackets immediately 9008 1.1 mrg before the next token. */ 9009 1.1 mrg case CPP_OPEN_SQUARE: 9010 1.1 mrg case CPP_OPEN_PAREN: 9011 1.1 mrg return MTIK_INSERT_BEFORE_NEXT; 9012 1.1 mrg 9013 1.1 mrg /* Insert other missing symbols immediately after 9014 1.1 mrg the previous token. */ 9015 1.1 mrg case CPP_CLOSE_PAREN: 9016 1.1 mrg case CPP_CLOSE_SQUARE: 9017 1.1 mrg case CPP_SEMICOLON: 9018 1.1 mrg case CPP_COMMA: 9019 1.1 mrg case CPP_COLON: 9020 1.1 mrg return MTIK_INSERT_AFTER_PREV; 9021 1.1 mrg 9022 1.1 mrg /* Other kinds of token don't get fix-it hints. */ 9023 1.1 mrg default: 9024 1.1 mrg return MTIK_IMPOSSIBLE; 9025 1.1 mrg } 9026 1.1 mrg } 9027 1.1 mrg 9028 1.1 mrg /* Given RICHLOC, a location for a diagnostic describing a missing token 9029 1.1 mrg of kind TOKEN_TYPE, potentially add a fix-it hint suggesting the 9030 1.1 mrg insertion of the token. 9031 1.1 mrg 9032 1.1 mrg The location of the attempted fix-it hint depends on TOKEN_TYPE: 9033 1.1 mrg it will either be: 9034 1.1 mrg (a) immediately after PREV_TOKEN_LOC, or 9035 1.1 mrg 9036 1.1 mrg (b) immediately before the primary location within RICHLOC (taken to 9037 1.1 mrg be that of the token following where the token was expected). 9038 1.1 mrg 9039 1.1 mrg If we manage to add a fix-it hint, then the location of the 9040 1.1 mrg fix-it hint is likely to be more useful as the primary location 9041 1.1 mrg of the diagnostic than that of the following token, so we swap 9042 1.1 mrg these locations. 9043 1.1 mrg 9044 1.1 mrg For example, given this bogus code: 9045 1.1 mrg 123456789012345678901234567890 9046 1.1 mrg 1 | int missing_semicolon (void) 9047 1.1 mrg 2 | { 9048 1.1 mrg 3 | return 42 9049 1.1 mrg 4 | } 9050 1.1 mrg 9051 1.1 mrg we will emit: 9052 1.1 mrg 9053 1.1 mrg "expected ';' before '}'" 9054 1.1 mrg 9055 1.1 mrg RICHLOC's primary location is at the closing brace, so before "swapping" 9056 1.1 mrg we would emit the error at line 4 column 1: 9057 1.1 mrg 9058 1.1 mrg 123456789012345678901234567890 9059 1.1 mrg 3 | return 42 |< fix-it hint emitted for this line 9060 1.1 mrg | ; | 9061 1.1 mrg 4 | } |< "expected ';' before '}'" emitted at this line 9062 1.1 mrg | ^ | 9063 1.1 mrg 9064 1.1 mrg It's more useful for the location of the diagnostic to be at the 9065 1.1 mrg fix-it hint, so we swap the locations, so the primary location 9066 1.1 mrg is at the fix-it hint, with the old primary location inserted 9067 1.1 mrg as a secondary location, giving this, with the error at line 3 9068 1.1 mrg column 12: 9069 1.1 mrg 9070 1.1 mrg 123456789012345678901234567890 9071 1.1 mrg 3 | return 42 |< "expected ';' before '}'" emitted at this line, 9072 1.1 mrg | ^ | with fix-it hint 9073 1.1 mrg 4 | ; | 9074 1.1 mrg | } |< secondary range emitted here 9075 1.1 mrg | ~ |. */ 9076 1.1 mrg 9077 1.1 mrg void 9078 1.1 mrg maybe_suggest_missing_token_insertion (rich_location *richloc, 9079 1.1 mrg enum cpp_ttype token_type, 9080 1.1 mrg location_t prev_token_loc) 9081 1.1 mrg { 9082 1.1 mrg gcc_assert (richloc); 9083 1.1 mrg 9084 1.1 mrg enum missing_token_insertion_kind mtik 9085 1.1 mrg = get_missing_token_insertion_kind (token_type); 9086 1.1 mrg 9087 1.1 mrg switch (mtik) 9088 1.1 mrg { 9089 1.1 mrg default: 9090 1.1 mrg gcc_unreachable (); 9091 1.1 mrg break; 9092 1.1 mrg 9093 1.1 mrg case MTIK_IMPOSSIBLE: 9094 1.1 mrg return; 9095 1.1 mrg 9096 1.1 mrg case MTIK_INSERT_BEFORE_NEXT: 9097 1.1 mrg /* Attempt to add the fix-it hint before the primary location 9098 1.1 mrg of RICHLOC. */ 9099 1.1 mrg richloc->add_fixit_insert_before (cpp_type2name (token_type, 0)); 9100 1.1 mrg break; 9101 1.1 mrg 9102 1.1 mrg case MTIK_INSERT_AFTER_PREV: 9103 1.1 mrg /* Attempt to add the fix-it hint after PREV_TOKEN_LOC. */ 9104 1.1 mrg richloc->add_fixit_insert_after (prev_token_loc, 9105 1.1 mrg cpp_type2name (token_type, 0)); 9106 1.1 mrg break; 9107 1.1 mrg } 9108 1.1 mrg 9109 1.1 mrg /* If we were successful, use the fix-it hint's location as the 9110 1.1 mrg primary location within RICHLOC, adding the old primary location 9111 1.1 mrg back as a secondary location. */ 9112 1.1 mrg if (!richloc->seen_impossible_fixit_p ()) 9113 1.1 mrg { 9114 1.1 mrg fixit_hint *hint = richloc->get_last_fixit_hint (); 9115 1.1 mrg location_t hint_loc = hint->get_start_loc (); 9116 1.1 mrg location_t old_loc = richloc->get_loc (); 9117 1.1 mrg 9118 1.1 mrg richloc->set_range (0, hint_loc, SHOW_RANGE_WITH_CARET); 9119 1.1 mrg richloc->add_range (old_loc); 9120 1.1 mrg } 9121 1.1 mrg } 9122 1.1 mrg 9123 1.1 mrg #if CHECKING_P 9124 1.1 mrg 9125 1.1 mrg namespace selftest { 9126 1.1 mrg 9127 1.1 mrg /* Verify that fold_for_warn on error_mark_node is safe. */ 9128 1.1 mrg 9129 1.1 mrg static void 9130 1.1 mrg test_fold_for_warn () 9131 1.1 mrg { 9132 1.1 mrg ASSERT_EQ (error_mark_node, fold_for_warn (error_mark_node)); 9133 1.1 mrg } 9134 1.1 mrg 9135 1.1 mrg /* Run all of the selftests within this file. */ 9136 1.1 mrg 9137 1.1 mrg static void 9138 1.1 mrg c_common_cc_tests () 9139 1.1 mrg { 9140 1.1 mrg test_fold_for_warn (); 9141 1.1 mrg } 9142 1.1 mrg 9143 1.1 mrg /* Run all of the tests within c-family. */ 9144 1.1 mrg 9145 1.1 mrg void 9146 1.1 mrg c_family_tests (void) 9147 1.1 mrg { 9148 1.1 mrg c_common_cc_tests (); 9149 1.1 mrg c_format_cc_tests (); 9150 1.1 mrg c_indentation_cc_tests (); 9151 1.1 mrg c_pretty_print_cc_tests (); 9152 1.1 mrg c_spellcheck_cc_tests (); 9153 1.1 mrg c_diagnostic_cc_tests (); 9154 1.1 mrg c_opt_problem_cc_tests (); 9155 1.1 mrg } 9156 1.1 mrg 9157 1.1 mrg } // namespace selftest 9158 1.1 mrg 9159 1.1 mrg #endif /* #if CHECKING_P */ 9160 1.1 mrg 9161 1.1 mrg /* Attempt to locate a suitable location within FILE for a 9162 1.1 mrg #include directive to be inserted before. 9163 1.1 mrg LOC is the location of the relevant diagnostic. 9164 1.1 mrg 9165 1.1 mrg Attempt to return the location within FILE immediately 9166 1.1 mrg after the last #include within that file, or the start of 9167 1.1 mrg that file if it has no #include directives. 9168 1.1 mrg 9169 1.1 mrg Return UNKNOWN_LOCATION if no suitable location is found, 9170 1.1 mrg or if an error occurs. */ 9171 1.1 mrg 9172 1.1 mrg static location_t 9173 1.1 mrg try_to_locate_new_include_insertion_point (const char *file, location_t loc) 9174 1.1 mrg { 9175 1.1 mrg /* Locate the last ordinary map within FILE that ended with a #include. */ 9176 1.1 mrg const line_map_ordinary *last_include_ord_map = NULL; 9177 1.1 mrg 9178 1.1 mrg /* ...and the next ordinary map within FILE after that one. */ 9179 1.1 mrg const line_map_ordinary *last_ord_map_after_include = NULL; 9180 1.1 mrg 9181 1.1 mrg /* ...and the first ordinary map within FILE. */ 9182 1.1 mrg const line_map_ordinary *first_ord_map_in_file = NULL; 9183 1.1 mrg 9184 1.1 mrg /* Get ordinary map containing LOC (or its expansion). */ 9185 1.1 mrg const line_map_ordinary *ord_map_for_loc = NULL; 9186 1.1 mrg linemap_resolve_location (line_table, loc, LRK_MACRO_EXPANSION_POINT, 9187 1.1 mrg &ord_map_for_loc); 9188 1.1 mrg gcc_assert (ord_map_for_loc); 9189 1.1 mrg 9190 1.1 mrg for (unsigned int i = 0; i < LINEMAPS_ORDINARY_USED (line_table); i++) 9191 1.1 mrg { 9192 1.1 mrg const line_map_ordinary *ord_map 9193 1.1 mrg = LINEMAPS_ORDINARY_MAP_AT (line_table, i); 9194 1.1 mrg 9195 1.1 mrg if (const line_map_ordinary *from 9196 1.1 mrg = linemap_included_from_linemap (line_table, ord_map)) 9197 1.1 mrg /* We cannot use pointer equality, because with preprocessed 9198 1.1 mrg input all filename strings are unique. */ 9199 1.1 mrg if (0 == strcmp (from->to_file, file)) 9200 1.1 mrg { 9201 1.1 mrg last_include_ord_map = from; 9202 1.1 mrg last_ord_map_after_include = NULL; 9203 1.1 mrg } 9204 1.1 mrg 9205 1.1 mrg /* Likewise, use strcmp, and reject any line-zero introductory 9206 1.1 mrg map. */ 9207 1.1 mrg if (ord_map->to_line && 0 == strcmp (ord_map->to_file, file)) 9208 1.1 mrg { 9209 1.1 mrg if (!first_ord_map_in_file) 9210 1.1 mrg first_ord_map_in_file = ord_map; 9211 1.1 mrg if (last_include_ord_map && !last_ord_map_after_include) 9212 1.1 mrg last_ord_map_after_include = ord_map; 9213 1.1 mrg } 9214 1.1 mrg 9215 1.1 mrg /* Stop searching when reaching the ord_map containing LOC, 9216 1.1 mrg as it makes no sense to provide fix-it hints that appear 9217 1.1 mrg after the diagnostic in question. */ 9218 1.1 mrg if (ord_map == ord_map_for_loc) 9219 1.1 mrg break; 9220 1.1 mrg } 9221 1.1 mrg 9222 1.1 mrg /* Determine where to insert the #include. */ 9223 1.1 mrg const line_map_ordinary *ord_map_for_insertion; 9224 1.1 mrg 9225 1.1 mrg /* We want the next ordmap in the file after the last one that's a 9226 1.1 mrg #include, but failing that, the start of the file. */ 9227 1.1 mrg if (last_ord_map_after_include) 9228 1.1 mrg ord_map_for_insertion = last_ord_map_after_include; 9229 1.1 mrg else 9230 1.1 mrg ord_map_for_insertion = first_ord_map_in_file; 9231 1.1 mrg 9232 1.1 mrg if (!ord_map_for_insertion) 9233 1.1 mrg return UNKNOWN_LOCATION; 9234 1.1 mrg 9235 1.1 mrg /* The "start_location" is column 0, meaning "the whole line". 9236 1.1 mrg rich_location and edit_context can't cope with this, so use 9237 1.1 mrg column 1 instead. */ 9238 1.1 mrg location_t col_0 = ord_map_for_insertion->start_location; 9239 1.1 mrg return linemap_position_for_loc_and_offset (line_table, col_0, 1); 9240 1.1 mrg } 9241 1.1 mrg 9242 1.1 mrg /* A map from filenames to sets of headers added to them, for 9243 1.1 mrg ensuring idempotency within maybe_add_include_fixit. */ 9244 1.1 mrg 9245 1.1 mrg /* The values within the map. We need string comparison as there's 9246 1.1 mrg no guarantee that two different diagnostics that are recommending 9247 1.1 mrg adding e.g. "<stdio.h>" are using the same buffer. */ 9248 1.1 mrg 9249 1.1 mrg typedef hash_set <const char *, false, nofree_string_hash> per_file_includes_t; 9250 1.1 mrg 9251 1.1 mrg /* The map itself. We don't need string comparison for the filename keys, 9252 1.1 mrg as they come from libcpp. */ 9253 1.1 mrg 9254 1.1 mrg typedef hash_map <const char *, per_file_includes_t *> added_includes_t; 9255 1.1 mrg static added_includes_t *added_includes; 9256 1.1 mrg 9257 1.1 mrg /* Attempt to add a fix-it hint to RICHLOC, adding "#include HEADER\n" 9258 1.1 mrg in a suitable location within the file of RICHLOC's primary 9259 1.1 mrg location. 9260 1.1 mrg 9261 1.1 mrg This function is idempotent: a header will be added at most once to 9262 1.1 mrg any given file. 9263 1.1 mrg 9264 1.1 mrg If OVERRIDE_LOCATION is true, then if a fix-it is added and will be 9265 1.1 mrg printed, then RICHLOC's primary location will be replaced by that of 9266 1.1 mrg the fix-it hint (for use by "inform" notes where the location of the 9267 1.1 mrg issue has already been reported). */ 9268 1.1 mrg 9269 1.1 mrg void 9270 1.1 mrg maybe_add_include_fixit (rich_location *richloc, const char *header, 9271 1.1 mrg bool override_location) 9272 1.1 mrg { 9273 1.1 mrg location_t loc = richloc->get_loc (); 9274 1.1 mrg const char *file = LOCATION_FILE (loc); 9275 1.1 mrg if (!file) 9276 1.1 mrg return; 9277 1.1 mrg 9278 1.1 mrg /* Idempotency: don't add the same header more than once to a given file. */ 9279 1.1 mrg if (!added_includes) 9280 1.1 mrg added_includes = new added_includes_t (); 9281 1.1 mrg per_file_includes_t *&set = added_includes->get_or_insert (file); 9282 1.1 mrg if (set) 9283 1.1 mrg if (set->contains (header)) 9284 1.1 mrg /* ...then we've already added HEADER to that file. */ 9285 1.1 mrg return; 9286 1.1 mrg if (!set) 9287 1.1 mrg set = new per_file_includes_t (); 9288 1.1 mrg set->add (header); 9289 1.1 mrg 9290 1.1 mrg /* Attempt to locate a suitable place for the new directive. */ 9291 1.1 mrg location_t include_insert_loc 9292 1.1 mrg = try_to_locate_new_include_insertion_point (file, loc); 9293 1.1 mrg if (include_insert_loc == UNKNOWN_LOCATION) 9294 1.1 mrg return; 9295 1.1 mrg 9296 1.1 mrg char *text = xasprintf ("#include %s\n", header); 9297 1.1 mrg richloc->add_fixit_insert_before (include_insert_loc, text); 9298 1.1 mrg free (text); 9299 1.1 mrg 9300 1.1 mrg if (override_location && global_dc->show_caret) 9301 1.1 mrg { 9302 1.1 mrg /* Replace the primary location with that of the insertion point for the 9303 1.1 mrg fix-it hint. 9304 1.1 mrg 9305 1.1 mrg We use SHOW_LINES_WITHOUT_RANGE so that we don't meaningless print a 9306 1.1 mrg caret for the insertion point (or colorize it). 9307 1.1 mrg 9308 1.1 mrg Hence we print e.g.: 9309 1.1 mrg 9310 1.1 mrg ../x86_64-pc-linux-gnu/libstdc++-v3/include/vector:74:1: note: msg 2 9311 1.1 mrg 73 | # include <debug/vector> 9312 1.1 mrg +++ |+#include <vector> 9313 1.1 mrg 74 | #endif 9314 1.1 mrg 9315 1.1 mrg rather than: 9316 1.1 mrg 9317 1.1 mrg ../x86_64-pc-linux-gnu/libstdc++-v3/include/vector:74:1: note: msg 2 9318 1.1 mrg 73 | # include <debug/vector> 9319 1.1 mrg +++ |+#include <vector> 9320 1.1 mrg 74 | #endif 9321 1.1 mrg | ^ 9322 1.1 mrg 9323 1.1 mrg avoiding the caret on the first column of line 74. */ 9324 1.1 mrg richloc->set_range (0, include_insert_loc, SHOW_LINES_WITHOUT_RANGE); 9325 1.1 mrg } 9326 1.1 mrg } 9327 1.1 mrg 9328 1.1 mrg /* Attempt to convert a braced array initializer list CTOR for array 9329 1.1 mrg TYPE into a STRING_CST for convenience and efficiency. Return 9330 1.1 mrg the converted string on success or the original ctor on failure. */ 9331 1.1 mrg 9332 1.1 mrg static tree 9333 1.1 mrg braced_list_to_string (tree type, tree ctor, bool member) 9334 1.1 mrg { 9335 1.1 mrg /* Ignore non-members with unknown size like arrays with unspecified 9336 1.1 mrg bound. */ 9337 1.1 mrg tree typesize = TYPE_SIZE_UNIT (type); 9338 1.1 mrg if (!member && !tree_fits_uhwi_p (typesize)) 9339 1.1 mrg return ctor; 9340 1.1 mrg 9341 1.1 mrg /* If the target char size differes from the host char size, we'd risk 9342 1.1 mrg loosing data and getting object sizes wrong by converting to 9343 1.1 mrg host chars. */ 9344 1.1 mrg if (TYPE_PRECISION (char_type_node) != CHAR_BIT) 9345 1.1 mrg return ctor; 9346 1.1 mrg 9347 1.1 mrg /* If the array has an explicit bound, use it to constrain the size 9348 1.1 mrg of the string. If it doesn't, be sure to create a string that's 9349 1.1 mrg as long as implied by the index of the last zero specified via 9350 1.1 mrg a designator, as in: 9351 1.1 mrg const char a[] = { [7] = 0 }; */ 9352 1.1 mrg unsigned HOST_WIDE_INT maxelts; 9353 1.1 mrg if (typesize) 9354 1.1 mrg { 9355 1.1 mrg maxelts = tree_to_uhwi (typesize); 9356 1.1 mrg maxelts /= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type))); 9357 1.1 mrg } 9358 1.1 mrg else 9359 1.1 mrg maxelts = HOST_WIDE_INT_M1U; 9360 1.1 mrg 9361 1.1 mrg /* Avoid converting initializers for zero-length arrays (but do 9362 1.1 mrg create them for flexible array members). */ 9363 1.1 mrg if (!maxelts) 9364 1.1 mrg return ctor; 9365 1.1 mrg 9366 1.1 mrg unsigned HOST_WIDE_INT nelts = CONSTRUCTOR_NELTS (ctor); 9367 1.1 mrg 9368 1.1 mrg auto_vec<char> str; 9369 1.1 mrg str.reserve (nelts + 1); 9370 1.1 mrg 9371 1.1 mrg unsigned HOST_WIDE_INT i; 9372 1.1 mrg tree index, value; 9373 1.1 mrg 9374 1.1 mrg FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), i, index, value) 9375 1.1 mrg { 9376 1.1 mrg unsigned HOST_WIDE_INT idx = i; 9377 1.1 mrg if (index) 9378 1.1 mrg { 9379 1.1 mrg if (!tree_fits_uhwi_p (index)) 9380 1.1 mrg return ctor; 9381 1.1 mrg idx = tree_to_uhwi (index); 9382 1.1 mrg } 9383 1.1 mrg 9384 1.1 mrg /* auto_vec is limited to UINT_MAX elements. */ 9385 1.1 mrg if (idx > UINT_MAX) 9386 1.1 mrg return ctor; 9387 1.1 mrg 9388 1.1 mrg /* Avoid non-constant initializers. */ 9389 1.1 mrg if (!tree_fits_shwi_p (value)) 9390 1.1 mrg return ctor; 9391 1.1 mrg 9392 1.1 mrg /* Skip over embedded nuls except the last one (initializer 9393 1.1 mrg elements are in ascending order of indices). */ 9394 1.1 mrg HOST_WIDE_INT val = tree_to_shwi (value); 9395 1.1 mrg if (!val && i + 1 < nelts) 9396 1.1 mrg continue; 9397 1.1 mrg 9398 1.1 mrg if (idx < str.length()) 9399 1.1 mrg return ctor; 9400 1.1 mrg 9401 1.1 mrg /* Bail if the CTOR has a block of more than 256 embedded nuls 9402 1.1 mrg due to implicitly initialized elements. */ 9403 1.1 mrg unsigned nchars = (idx - str.length ()) + 1; 9404 1.1 mrg if (nchars > 256) 9405 1.1 mrg return ctor; 9406 1.1 mrg 9407 1.1 mrg if (nchars > 1) 9408 1.1 mrg { 9409 1.1 mrg str.reserve (idx); 9410 1.1 mrg str.quick_grow_cleared (idx); 9411 1.1 mrg } 9412 1.1 mrg 9413 1.1 mrg if (idx >= maxelts) 9414 1.1 mrg return ctor; 9415 1.1 mrg 9416 1.1 mrg str.safe_insert (idx, val); 9417 1.1 mrg } 9418 1.1 mrg 9419 1.1 mrg /* Append a nul string termination. */ 9420 1.1 mrg if (maxelts != HOST_WIDE_INT_M1U && str.length () < maxelts) 9421 1.1 mrg str.safe_push (0); 9422 1.1 mrg 9423 1.1 mrg /* Build a STRING_CST with the same type as the array. */ 9424 1.1 mrg tree res = build_string (str.length (), str.begin ()); 9425 1.1 mrg TREE_TYPE (res) = type; 9426 1.1 mrg return res; 9427 1.1 mrg } 9428 1.1 mrg 9429 1.1 mrg /* Implementation of the two-argument braced_lists_to_string withe 9430 1.1 mrg the same arguments plus MEMBER which is set for struct members 9431 1.1 mrg to allow initializers for flexible member arrays. */ 9432 1.1 mrg 9433 1.1 mrg static tree 9434 1.1 mrg braced_lists_to_strings (tree type, tree ctor, bool member) 9435 1.1 mrg { 9436 1.1 mrg if (TREE_CODE (ctor) != CONSTRUCTOR) 9437 1.1 mrg return ctor; 9438 1.1 mrg 9439 1.1 mrg tree_code code = TREE_CODE (type); 9440 1.1 mrg 9441 1.1 mrg tree ttp; 9442 1.1 mrg if (code == ARRAY_TYPE) 9443 1.1 mrg ttp = TREE_TYPE (type); 9444 1.1 mrg else if (code == RECORD_TYPE) 9445 1.1 mrg { 9446 1.1 mrg ttp = TREE_TYPE (ctor); 9447 1.1 mrg if (TREE_CODE (ttp) == ARRAY_TYPE) 9448 1.1 mrg { 9449 1.1 mrg type = ttp; 9450 1.1 mrg ttp = TREE_TYPE (ttp); 9451 1.1 mrg } 9452 1.1 mrg } 9453 1.1 mrg else 9454 1.1 mrg return ctor; 9455 1.1 mrg 9456 1.1 mrg if ((TREE_CODE (ttp) == ARRAY_TYPE || TREE_CODE (ttp) == INTEGER_TYPE) 9457 1.1 mrg && TYPE_STRING_FLAG (ttp)) 9458 1.1 mrg return braced_list_to_string (type, ctor, member); 9459 1.1 mrg 9460 1.1 mrg code = TREE_CODE (ttp); 9461 1.1 mrg if (code == ARRAY_TYPE || RECORD_OR_UNION_TYPE_P (ttp)) 9462 1.1 mrg { 9463 1.1 mrg bool rec = RECORD_OR_UNION_TYPE_P (ttp); 9464 1.1 mrg 9465 1.1 mrg /* Handle array of arrays or struct member initializers. */ 9466 1.1 mrg tree val; 9467 1.1 mrg unsigned HOST_WIDE_INT idx; 9468 1.1 mrg FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), idx, val) 9469 1.1 mrg { 9470 1.1 mrg val = braced_lists_to_strings (ttp, val, rec); 9471 1.1 mrg CONSTRUCTOR_ELT (ctor, idx)->value = val; 9472 1.1 mrg } 9473 1.1 mrg } 9474 1.1 mrg 9475 1.1 mrg return ctor; 9476 1.1 mrg } 9477 1.1 mrg 9478 1.1 mrg /* Attempt to convert a CTOR containing braced array initializer lists 9479 1.1 mrg for array TYPE into one containing STRING_CSTs, for convenience and 9480 1.1 mrg efficiency. Recurse for arrays of arrays and member initializers. 9481 1.1 mrg Return the converted CTOR or STRING_CST on success or the original 9482 1.1 mrg CTOR otherwise. */ 9483 1.1 mrg 9484 1.1 mrg tree 9485 1.1 mrg braced_lists_to_strings (tree type, tree ctor) 9486 1.1 mrg { 9487 1.1 mrg return braced_lists_to_strings (type, ctor, false); 9488 1.1 mrg } 9489 1.1 mrg 9490 9491 /* Emit debug for functions before finalizing early debug. */ 9492 9493 void 9494 c_common_finalize_early_debug (void) 9495 { 9496 /* Emit early debug for reachable functions, and by consequence, 9497 locally scoped symbols. Also emit debug for extern declared 9498 functions that are still reachable at this point. */ 9499 struct cgraph_node *cnode; 9500 FOR_EACH_FUNCTION (cnode) 9501 if (!cnode->alias && !cnode->thunk 9502 && (cnode->has_gimple_body_p () 9503 || !DECL_IS_UNDECLARED_BUILTIN (cnode->decl))) 9504 (*debug_hooks->early_global_decl) (cnode->decl); 9505 } 9506 9507 #include "gt-c-family-c-common.h" 9508