00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "config.h"
00023 #include "system.h"
00024 #include "coretypes.h"
00025 #include "tm.h"
00026 #include "intl.h"
00027 #include "tree.h"
00028 #include "flags.h"
00029 #include "output.h"
00030 #include "c-pragma.h"
00031 #include "rtl.h"
00032 #include "ggc.h"
00033 #include "varray.h"
00034 #include "expr.h"
00035 #include "c-common.h"
00036 #include "diagnostic.h"
00037 #include "tm_p.h"
00038 #include "obstack.h"
00039 #include "cpplib.h"
00040 #include "target.h"
00041 #include "langhooks.h"
00042 #include "tree-inline.h"
00043 #include "c-tree.h"
00044 #include "toplev.h"
00045 #include "tree-iterator.h"
00046 #include "hashtab.h"
00047 #include "tree-mudflap.h"
00048 #include "opts.h"
00049 #include "real.h"
00050
00051 cpp_reader *parse_in;
00052
00053
00054
00055
00056
00057
00058
00059 #ifndef SIZE_TYPE
00060 #define SIZE_TYPE "long unsigned int"
00061 #endif
00062
00063 #ifndef PID_TYPE
00064 #define PID_TYPE "int"
00065 #endif
00066
00067 #ifndef WCHAR_TYPE
00068 #define WCHAR_TYPE "int"
00069 #endif
00070
00071
00072 #define MODIFIED_WCHAR_TYPE \
00073 (flag_short_wchar ? "short unsigned int" : WCHAR_TYPE)
00074
00075 #ifndef PTRDIFF_TYPE
00076 #define PTRDIFF_TYPE "long int"
00077 #endif
00078
00079 #ifndef WINT_TYPE
00080 #define WINT_TYPE "unsigned int"
00081 #endif
00082
00083 #ifndef INTMAX_TYPE
00084 #define INTMAX_TYPE ((INT_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
00085 ? "int" \
00086 : ((LONG_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
00087 ? "long int" \
00088 : "long long int"))
00089 #endif
00090
00091 #ifndef UINTMAX_TYPE
00092 #define UINTMAX_TYPE ((INT_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
00093 ? "unsigned int" \
00094 : ((LONG_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
00095 ? "long unsigned int" \
00096 : "long long unsigned int"))
00097 #endif
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193 tree c_global_trees[CTI_MAX];
00194
00195
00196
00197
00198 bool statement_code_p[MAX_TREE_CODES];
00199
00200
00201
00202
00203
00204 int flag_preprocess_only;
00205
00206
00207
00208 char flag_no_line_commands;
00209
00210
00211
00212
00213 char flag_no_output;
00214
00215
00216
00217 char flag_dump_macros;
00218
00219
00220
00221 char flag_dump_includes;
00222
00223
00224
00225 bool flag_pch_preprocess;
00226
00227
00228
00229
00230 const char *pch_file;
00231
00232
00233
00234 int flag_iso;
00235
00236
00237
00238 int flag_undef;
00239
00240
00241
00242 int flag_no_builtin;
00243
00244
00245
00246
00247 int flag_no_nonansi_builtin;
00248
00249
00250
00251 int flag_short_double;
00252
00253
00254
00255 int flag_short_wchar;
00256
00257
00258 int flag_ms_extensions;
00259
00260
00261
00262 int flag_no_asm;
00263
00264
00265
00266
00267 int flag_const_strings;
00268
00269
00270
00271 int flag_signed_bitfields = 1;
00272
00273
00274
00275
00276 int warn_write_strings;
00277
00278
00279
00280 int warn_unknown_pragmas;
00281
00282
00283
00284
00285 int warn_format;
00286
00287
00288
00289
00290
00291 int warn_strict_null_sentinel;
00292
00293
00294
00295
00296 int flag_nil_receivers = 1;
00297
00298
00299
00300 int flag_objc_exceptions = 0;
00301
00302
00303 int flag_objc_sjlj_exceptions = -1;
00304
00305
00306
00307
00308 int flag_zero_link = 0;
00309
00310
00311
00312
00313 int flag_replace_objc_classes = 0;
00314
00315
00316
00317
00318
00319
00320
00321 int flag_cond_mismatch;
00322
00323
00324
00325 int flag_isoc94;
00326
00327
00328
00329 int flag_isoc99;
00330
00331
00332
00333 int flag_hosted = 1;
00334
00335
00336
00337 int warn_main;
00338
00339
00340
00341
00342
00343
00344
00345
00346 int flag_gen_declaration;
00347
00348
00349
00350 #ifdef NEXT_OBJC_RUNTIME
00351 int flag_next_runtime = 1;
00352 #else
00353 int flag_next_runtime = 0;
00354 #endif
00355
00356
00357
00358
00359
00360 int print_struct_values;
00361
00362
00363
00364 const char *constant_string_class_name;
00365
00366
00367
00368
00369
00370
00371
00372 int flag_no_gnu_keywords;
00373
00374
00375
00376
00377 int flag_implement_inlines = 1;
00378
00379
00380
00381 int flag_implicit_templates = 1;
00382
00383
00384
00385
00386
00387 int flag_implicit_inline_templates = 1;
00388
00389
00390
00391
00392 int flag_use_repository;
00393
00394
00395
00396
00397 int flag_optional_diags = 1;
00398
00399
00400
00401 int flag_elide_constructors = 1;
00402
00403
00404
00405
00406 int flag_default_inline = 1;
00407
00408
00409
00410
00411 int flag_rtti = 1;
00412
00413
00414
00415
00416
00417
00418 int flag_conserve_space;
00419
00420
00421
00422 int flag_access_control = 1;
00423
00424
00425
00426
00427 int flag_check_new;
00428
00429
00430
00431
00432
00433
00434
00435
00436 int flag_new_for_scope = 1;
00437
00438
00439
00440
00441
00442 int flag_weak = 1;
00443
00444
00445
00446
00447
00448
00449 int flag_working_directory = -1;
00450
00451
00452
00453
00454 int flag_use_cxa_atexit = DEFAULT_USE_CXA_ATEXIT;
00455
00456
00457
00458
00459 int flag_permissive;
00460
00461
00462
00463
00464
00465
00466 int flag_enforce_eh_specs = 1;
00467
00468
00469
00470
00471 int flag_threadsafe_statics = 1;
00472
00473
00474
00475 int warn_implicit = 1;
00476
00477
00478
00479
00480
00481 int max_tinst_depth = 500;
00482
00483
00484
00485
00486
00487 tree *ridpointers;
00488
00489 tree (*make_fname_decl) (tree, int);
00490
00491
00492
00493 int skip_evaluation;
00494
00495
00496 struct fname_var_t
00497 {
00498 tree *const decl;
00499 const unsigned rid;
00500 const int pretty;
00501 };
00502
00503
00504
00505 const struct fname_var_t fname_vars[] =
00506 {
00507
00508 {&c99_function_name_decl_node, RID_C99_FUNCTION_NAME, 0},
00509
00510 {&function_name_decl_node, RID_FUNCTION_NAME, 0},
00511
00512 {&pretty_function_name_decl_node, RID_PRETTY_FUNCTION_NAME, 1},
00513 {NULL, 0, 0},
00514 };
00515
00516 static int constant_fits_type_p (tree, tree);
00517 static tree check_case_value (tree);
00518 static bool check_case_bounds (tree, tree, tree *, tree *);
00519
00520 static tree handle_packed_attribute (tree *, tree, tree, int, bool *);
00521 static tree handle_nocommon_attribute (tree *, tree, tree, int, bool *);
00522 static tree handle_common_attribute (tree *, tree, tree, int, bool *);
00523 static tree handle_noreturn_attribute (tree *, tree, tree, int, bool *);
00524 static tree handle_noinline_attribute (tree *, tree, tree, int, bool *);
00525 static tree handle_always_inline_attribute (tree *, tree, tree, int,
00526 bool *);
00527 static tree handle_used_attribute (tree *, tree, tree, int, bool *);
00528 static tree handle_unused_attribute (tree *, tree, tree, int, bool *);
00529 static tree handle_const_attribute (tree *, tree, tree, int, bool *);
00530 static tree handle_transparent_union_attribute (tree *, tree, tree,
00531 int, bool *);
00532 static tree handle_constructor_attribute (tree *, tree, tree, int, bool *);
00533 static tree handle_destructor_attribute (tree *, tree, tree, int, bool *);
00534 static tree handle_mode_attribute (tree *, tree, tree, int, bool *);
00535 static tree handle_section_attribute (tree *, tree, tree, int, bool *);
00536 static tree handle_aligned_attribute (tree *, tree, tree, int, bool *);
00537 static tree handle_weak_attribute (tree *, tree, tree, int, bool *) ;
00538 static tree handle_alias_attribute (tree *, tree, tree, int, bool *);
00539 static tree handle_visibility_attribute (tree *, tree, tree, int,
00540 bool *);
00541 static tree handle_tls_model_attribute (tree *, tree, tree, int,
00542 bool *);
00543 static tree handle_no_instrument_function_attribute (tree *, tree,
00544 tree, int, bool *);
00545 static tree handle_malloc_attribute (tree *, tree, tree, int, bool *);
00546 static tree handle_no_limit_stack_attribute (tree *, tree, tree, int,
00547 bool *);
00548 static tree handle_pure_attribute (tree *, tree, tree, int, bool *);
00549 static tree handle_deprecated_attribute (tree *, tree, tree, int,
00550 bool *);
00551 static tree handle_vector_size_attribute (tree *, tree, tree, int,
00552 bool *);
00553 static tree handle_nonnull_attribute (tree *, tree, tree, int, bool *);
00554 static tree handle_nothrow_attribute (tree *, tree, tree, int, bool *);
00555 static tree handle_cleanup_attribute (tree *, tree, tree, int, bool *);
00556 static tree handle_warn_unused_result_attribute (tree *, tree, tree, int,
00557 bool *);
00558 static tree handle_sentinel_attribute (tree *, tree, tree, int, bool *);
00559
00560 static void check_function_nonnull (tree, tree);
00561 static void check_nonnull_arg (void *, tree, unsigned HOST_WIDE_INT);
00562 static bool nonnull_check_p (tree, unsigned HOST_WIDE_INT);
00563 static bool get_nonnull_operand (tree, unsigned HOST_WIDE_INT *);
00564 static int resort_field_decl_cmp (const void *, const void *);
00565
00566
00567 const struct attribute_spec c_common_attribute_table[] =
00568 {
00569
00570 { "packed", 0, 0, false, false, false,
00571 handle_packed_attribute },
00572 { "nocommon", 0, 0, true, false, false,
00573 handle_nocommon_attribute },
00574 { "common", 0, 0, true, false, false,
00575 handle_common_attribute },
00576
00577
00578
00579
00580
00581 { "noreturn", 0, 0, true, false, false,
00582 handle_noreturn_attribute },
00583 { "volatile", 0, 0, true, false, false,
00584 handle_noreturn_attribute },
00585 { "noinline", 0, 0, true, false, false,
00586 handle_noinline_attribute },
00587 { "always_inline", 0, 0, true, false, false,
00588 handle_always_inline_attribute },
00589 { "used", 0, 0, true, false, false,
00590 handle_used_attribute },
00591 { "unused", 0, 0, false, false, false,
00592 handle_unused_attribute },
00593
00594 { "const", 0, 0, true, false, false,
00595 handle_const_attribute },
00596 { "transparent_union", 0, 0, false, false, false,
00597 handle_transparent_union_attribute },
00598 { "constructor", 0, 0, true, false, false,
00599 handle_constructor_attribute },
00600 { "destructor", 0, 0, true, false, false,
00601 handle_destructor_attribute },
00602 { "mode", 1, 1, false, true, false,
00603 handle_mode_attribute },
00604 { "section", 1, 1, true, false, false,
00605 handle_section_attribute },
00606 { "aligned", 0, 1, false, false, false,
00607 handle_aligned_attribute },
00608 { "weak", 0, 0, true, false, false,
00609 handle_weak_attribute },
00610 { "alias", 1, 1, true, false, false,
00611 handle_alias_attribute },
00612 { "no_instrument_function", 0, 0, true, false, false,
00613 handle_no_instrument_function_attribute },
00614 { "malloc", 0, 0, true, false, false,
00615 handle_malloc_attribute },
00616 { "no_stack_limit", 0, 0, true, false, false,
00617 handle_no_limit_stack_attribute },
00618 { "pure", 0, 0, true, false, false,
00619 handle_pure_attribute },
00620 { "deprecated", 0, 0, false, false, false,
00621 handle_deprecated_attribute },
00622 { "vector_size", 1, 1, false, true, false,
00623 handle_vector_size_attribute },
00624 { "visibility", 1, 1, false, false, false,
00625 handle_visibility_attribute },
00626 { "tls_model", 1, 1, true, false, false,
00627 handle_tls_model_attribute },
00628 { "nonnull", 0, -1, false, true, true,
00629 handle_nonnull_attribute },
00630 { "nothrow", 0, 0, true, false, false,
00631 handle_nothrow_attribute },
00632 { "may_alias", 0, 0, false, true, false, NULL },
00633 { "cleanup", 1, 1, true, false, false,
00634 handle_cleanup_attribute },
00635 { "warn_unused_result", 0, 0, false, true, true,
00636 handle_warn_unused_result_attribute },
00637 { "sentinel", 0, 1, false, true, true,
00638 handle_sentinel_attribute },
00639 { NULL, 0, 0, false, false, false, NULL }
00640 };
00641
00642
00643
00644
00645 const struct attribute_spec c_common_format_attribute_table[] =
00646 {
00647
00648 { "format", 3, 3, false, true, true,
00649 handle_format_attribute },
00650 { "format_arg", 1, 1, false, true, true,
00651 handle_format_arg_attribute },
00652 { NULL, 0, 0, false, false, false, NULL }
00653 };
00654
00655
00656
00657 void
00658 start_fname_decls (void)
00659 {
00660 unsigned ix;
00661 tree saved = NULL_TREE;
00662
00663 for (ix = 0; fname_vars[ix].decl; ix++)
00664 {
00665 tree decl = *fname_vars[ix].decl;
00666
00667 if (decl)
00668 {
00669 saved = tree_cons (decl, build_int_cst (NULL_TREE, ix), saved);
00670 *fname_vars[ix].decl = NULL_TREE;
00671 }
00672 }
00673 if (saved || saved_function_name_decls)
00674
00675
00676 saved_function_name_decls = tree_cons (saved, NULL_TREE,
00677 saved_function_name_decls);
00678 }
00679
00680
00681
00682
00683
00684
00685 void
00686 finish_fname_decls (void)
00687 {
00688 unsigned ix;
00689 tree stmts = NULL_TREE;
00690 tree stack = saved_function_name_decls;
00691
00692 for (; stack && TREE_VALUE (stack); stack = TREE_CHAIN (stack))
00693 append_to_statement_list (TREE_VALUE (stack), &stmts);
00694
00695 if (stmts)
00696 {
00697 tree *bodyp = &DECL_SAVED_TREE (current_function_decl);
00698
00699 if (TREE_CODE (*bodyp) == BIND_EXPR)
00700 bodyp = &BIND_EXPR_BODY (*bodyp);
00701
00702 append_to_statement_list (*bodyp, &stmts);
00703 *bodyp = stmts;
00704 }
00705
00706 for (ix = 0; fname_vars[ix].decl; ix++)
00707 *fname_vars[ix].decl = NULL_TREE;
00708
00709 if (stack)
00710 {
00711
00712 tree saved;
00713
00714 for (saved = TREE_PURPOSE (stack); saved; saved = TREE_CHAIN (saved))
00715 {
00716 tree decl = TREE_PURPOSE (saved);
00717 unsigned ix = TREE_INT_CST_LOW (TREE_VALUE (saved));
00718
00719 *fname_vars[ix].decl = decl;
00720 }
00721 stack = TREE_CHAIN (stack);
00722 }
00723 saved_function_name_decls = stack;
00724 }
00725
00726
00727
00728
00729 const char *
00730 fname_as_string (int pretty_p)
00731 {
00732 const char *name = "top level";
00733 char *namep;
00734 int vrb = 2;
00735
00736 if (!pretty_p)
00737 {
00738 name = "";
00739 vrb = 0;
00740 }
00741
00742 if (current_function_decl)
00743 name = lang_hooks.decl_printable_name (current_function_decl, vrb);
00744
00745 if (c_lex_string_translate)
00746 {
00747 int len = strlen (name) + 3;
00748 cpp_string cstr = { 0, 0 }, strname;
00749
00750 namep = XNEWVEC (char, len);
00751 snprintf (namep, len, "\"%s\"", name);
00752 strname.text = (unsigned char *) namep;
00753 strname.len = len - 1;
00754
00755 if (cpp_interpret_string (parse_in, &strname, 1, &cstr, false))
00756 {
00757 XDELETEVEC (namep);
00758 return (char *) cstr.text;
00759 }
00760 }
00761 else
00762 namep = xstrdup (name);
00763
00764 return namep;
00765 }
00766
00767
00768
00769
00770 int
00771 c_expand_decl (tree decl)
00772 {
00773 if (TREE_CODE (decl) == VAR_DECL && !TREE_STATIC (decl))
00774 {
00775
00776 if (!anon_aggr_type_p (TREE_TYPE (decl)))
00777 emit_local_var (decl);
00778 else
00779 expand_anon_union_decl (decl, NULL_TREE,
00780 DECL_ANON_UNION_ELEMS (decl));
00781 }
00782 else
00783 return 0;
00784
00785 return 1;
00786 }
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796 tree
00797 fname_decl (unsigned int rid, tree id)
00798 {
00799 unsigned ix;
00800 tree decl = NULL_TREE;
00801
00802 for (ix = 0; fname_vars[ix].decl; ix++)
00803 if (fname_vars[ix].rid == rid)
00804 break;
00805
00806 decl = *fname_vars[ix].decl;
00807 if (!decl)
00808 {
00809
00810
00811
00812
00813
00814 tree stmts;
00815 location_t saved_location = input_location;
00816 #ifdef USE_MAPPED_LOCATION
00817 input_location = UNKNOWN_LOCATION;
00818 #else
00819 input_line = 0;
00820 #endif
00821
00822 stmts = push_stmt_list ();
00823 decl = (*make_fname_decl) (id, fname_vars[ix].pretty);
00824 stmts = pop_stmt_list (stmts);
00825 if (!IS_EMPTY_STMT (stmts))
00826 saved_function_name_decls
00827 = tree_cons (decl, stmts, saved_function_name_decls);
00828 *fname_vars[ix].decl = decl;
00829 input_location = saved_location;
00830 }
00831 if (!ix && !current_function_decl)
00832 pedwarn ("%qD is not defined outside of function scope", decl);
00833
00834 return decl;
00835 }
00836
00837
00838
00839 tree
00840 fix_string_type (tree value)
00841 {
00842 const int wchar_bytes = TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT;
00843 const int wide_flag = TREE_TYPE (value) == wchar_array_type_node;
00844 const int nchars_max = flag_isoc99 ? 4095 : 509;
00845 int length = TREE_STRING_LENGTH (value);
00846 int nchars;
00847 tree e_type, i_type, a_type;
00848
00849
00850 nchars = wide_flag ? length / wchar_bytes : length;
00851
00852 if (pedantic && nchars - 1 > nchars_max && !c_dialect_cxx ())
00853 pedwarn ("string length %qd is greater than the length %qd ISO C%d compilers are required to support",
00854 nchars - 1, nchars_max, flag_isoc99 ? 99 : 89);
00855
00856 e_type = wide_flag ? wchar_type_node : char_type_node;
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868 i_type = build_index_type (build_int_cst (NULL_TREE, nchars - 1));
00869 a_type = build_array_type (e_type, i_type);
00870 if (flag_const_strings)
00871 a_type = c_build_qualified_type (a_type, TYPE_QUAL_CONST);
00872
00873 TREE_TYPE (value) = a_type;
00874 TREE_CONSTANT (value) = 1;
00875 TREE_INVARIANT (value) = 1;
00876 TREE_READONLY (value) = 1;
00877 TREE_STATIC (value) = 1;
00878 return value;
00879 }
00880
00881
00882
00883
00884
00885
00886
00887 void
00888 constant_expression_warning (tree value)
00889 {
00890 if ((TREE_CODE (value) == INTEGER_CST || TREE_CODE (value) == REAL_CST
00891 || TREE_CODE (value) == VECTOR_CST
00892 || TREE_CODE (value) == COMPLEX_CST)
00893 && TREE_CONSTANT_OVERFLOW (value) && pedantic)
00894 pedwarn ("overflow in constant expression");
00895 }
00896
00897
00898
00899
00900
00901
00902
00903
00904 void
00905 overflow_warning (tree value)
00906 {
00907 if ((TREE_CODE (value) == INTEGER_CST
00908 || (TREE_CODE (value) == COMPLEX_CST
00909 && TREE_CODE (TREE_REALPART (value)) == INTEGER_CST))
00910 && TREE_OVERFLOW (value))
00911 {
00912 TREE_OVERFLOW (value) = 0;
00913 if (skip_evaluation == 0)
00914 warning ("integer overflow in expression");
00915 }
00916 else if ((TREE_CODE (value) == REAL_CST
00917 || (TREE_CODE (value) == COMPLEX_CST
00918 && TREE_CODE (TREE_REALPART (value)) == REAL_CST))
00919 && TREE_OVERFLOW (value))
00920 {
00921 TREE_OVERFLOW (value) = 0;
00922 if (skip_evaluation == 0)
00923 warning ("floating point overflow in expression");
00924 }
00925 else if (TREE_CODE (value) == VECTOR_CST && TREE_OVERFLOW (value))
00926 {
00927 TREE_OVERFLOW (value) = 0;
00928 if (skip_evaluation == 0)
00929 warning ("vector overflow in expression");
00930 }
00931 }
00932
00933
00934
00935
00936
00937
00938 void
00939 unsigned_conversion_warning (tree result, tree operand)
00940 {
00941 tree type = TREE_TYPE (result);
00942
00943 if (TREE_CODE (operand) == INTEGER_CST
00944 && TREE_CODE (type) == INTEGER_TYPE
00945 && TYPE_UNSIGNED (type)
00946 && skip_evaluation == 0
00947 && !int_fits_type_p (operand, type))
00948 {
00949 if (!int_fits_type_p (operand, c_common_signed_type (type)))
00950
00951 warning ("large integer implicitly truncated to unsigned type");
00952 else if (warn_conversion)
00953 warning ("negative integer implicitly converted to unsigned type");
00954 }
00955 }
00956
00957
00958
00959
00960 static int
00961 constant_fits_type_p (tree c, tree type)
00962 {
00963 if (TREE_CODE (c) == INTEGER_CST)
00964 return int_fits_type_p (c, type);
00965
00966 c = convert (type, c);
00967 return !TREE_OVERFLOW (c);
00968 }
00969
00970
00971
00972 int
00973 vector_types_convertible_p (tree t1, tree t2)
00974 {
00975 return targetm.vector_opaque_p (t1)
00976 || targetm.vector_opaque_p (t2)
00977 || (tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2))
00978 && INTEGRAL_TYPE_P (TREE_TYPE (t1))
00979 == INTEGRAL_TYPE_P (TREE_TYPE (t2)));
00980 }
00981
00982
00983
00984
00985
00986 tree
00987 convert_and_check (tree type, tree expr)
00988 {
00989 tree t = convert (type, expr);
00990 if (TREE_CODE (t) == INTEGER_CST)
00991 {
00992 if (TREE_OVERFLOW (t))
00993 {
00994 TREE_OVERFLOW (t) = 0;
00995
00996
00997
00998 TREE_CONSTANT_OVERFLOW (t) = TREE_CONSTANT_OVERFLOW (expr);
00999
01000
01001 if (!(TYPE_UNSIGNED (type) < TYPE_UNSIGNED (TREE_TYPE (expr))
01002 && TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
01003 && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (expr))))
01004
01005
01006 if ((pedantic
01007 || TYPE_UNSIGNED (type)
01008 || !constant_fits_type_p (expr,
01009 c_common_unsigned_type (type)))
01010 && skip_evaluation == 0)
01011 warning ("overflow in implicit constant conversion");
01012 }
01013 else
01014 unsigned_conversion_warning (t, expr);
01015 }
01016 return t;
01017 }
01018
01019
01020
01021
01022 struct tlist
01023 {
01024 struct tlist *next;
01025 tree expr, writer;
01026 };
01027
01028
01029
01030 struct tlist_cache
01031 {
01032 struct tlist_cache *next;
01033 struct tlist *cache_before_sp;
01034 struct tlist *cache_after_sp;
01035 tree expr;
01036 };
01037
01038
01039
01040 static struct obstack tlist_obstack;
01041 static char *tlist_firstobj = 0;
01042
01043
01044
01045 static struct tlist *warned_ids;
01046
01047
01048 static struct tlist_cache *save_expr_cache;
01049
01050 static void add_tlist (struct tlist **, struct tlist *, tree, int);
01051 static void merge_tlist (struct tlist **, struct tlist *, int);
01052 static void verify_tree (tree, struct tlist **, struct tlist **, tree);
01053 static int warning_candidate_p (tree);
01054 static void warn_for_collisions (struct tlist *);
01055 static void warn_for_collisions_1 (tree, tree, struct tlist *, int);
01056 static struct tlist *new_tlist (struct tlist *, tree, tree);
01057
01058
01059 static struct tlist *
01060 new_tlist (struct tlist *next, tree t, tree writer)
01061 {
01062 struct tlist *l;
01063 l = XOBNEW (&tlist_obstack, struct tlist);
01064 l->next = next;
01065 l->expr = t;
01066 l->writer = writer;
01067 return l;
01068 }
01069
01070
01071
01072
01073 static void
01074 add_tlist (struct tlist **to, struct tlist *add, tree exclude_writer, int copy)
01075 {
01076 while (add)
01077 {
01078 struct tlist *next = add->next;
01079 if (!copy)
01080 add->next = *to;
01081 if (!exclude_writer || add->writer != exclude_writer)
01082 *to = copy ? new_tlist (*to, add->expr, add->writer) : add;
01083 add = next;
01084 }
01085 }
01086
01087
01088
01089
01090
01091
01092
01093 static void
01094 merge_tlist (struct tlist **to, struct tlist *add, int copy)
01095 {
01096 struct tlist **end = to;
01097
01098 while (*end)
01099 end = &(*end)->next;
01100
01101 while (add)
01102 {
01103 int found = 0;
01104 struct tlist *tmp2;
01105 struct tlist *next = add->next;
01106
01107 for (tmp2 = *to; tmp2; tmp2 = tmp2->next)
01108 if (tmp2->expr == add->expr)
01109 {
01110 found = 1;
01111 if (!tmp2->writer)
01112 tmp2->writer = add->writer;
01113 }
01114 if (!found)
01115 {
01116 *end = copy ? add : new_tlist (NULL, add->expr, add->writer);
01117 end = &(*end)->next;
01118 *end = 0;
01119 }
01120 add = next;
01121 }
01122 }
01123
01124
01125
01126
01127
01128 static void
01129 warn_for_collisions_1 (tree written, tree writer, struct tlist *list,
01130 int only_writes)
01131 {
01132 struct tlist *tmp;
01133
01134
01135 for (tmp = warned_ids; tmp; tmp = tmp->next)
01136 if (tmp->expr == written)
01137 return;
01138
01139 while (list)
01140 {
01141 if (list->expr == written
01142 && list->writer != writer
01143 && (!only_writes || list->writer)
01144 && DECL_NAME (list->expr))
01145 {
01146 warned_ids = new_tlist (warned_ids, written, NULL_TREE);
01147 warning ("operation on %qs may be undefined",
01148 IDENTIFIER_POINTER (DECL_NAME (list->expr)));
01149 }
01150 list = list->next;
01151 }
01152 }
01153
01154
01155
01156
01157 static void
01158 warn_for_collisions (struct tlist *list)
01159 {
01160 struct tlist *tmp;
01161
01162 for (tmp = list; tmp; tmp = tmp->next)
01163 {
01164 if (tmp->writer)
01165 warn_for_collisions_1 (tmp->expr, tmp->writer, list, 0);
01166 }
01167 }
01168
01169
01170
01171 static int
01172 warning_candidate_p (tree x)
01173 {
01174 return TREE_CODE (x) == VAR_DECL || TREE_CODE (x) == PARM_DECL;
01175 }
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196
01197
01198
01199
01200
01201
01202 static void
01203 verify_tree (tree x, struct tlist **pbefore_sp, struct tlist **pno_sp,
01204 tree writer)
01205 {
01206 struct tlist *tmp_before, *tmp_nosp, *tmp_list2, *tmp_list3;
01207 enum tree_code code;
01208 enum tree_code_class cl;
01209
01210
01211
01212 if (x == NULL)
01213 return;
01214
01215 restart:
01216 code = TREE_CODE (x);
01217 cl = TREE_CODE_CLASS (code);
01218
01219 if (warning_candidate_p (x))
01220 {
01221 *pno_sp = new_tlist (*pno_sp, x, writer);
01222 return;
01223 }
01224
01225 switch (code)
01226 {
01227 case CONSTRUCTOR:
01228 return;
01229
01230 case COMPOUND_EXPR:
01231 case TRUTH_ANDIF_EXPR:
01232 case TRUTH_ORIF_EXPR:
01233 tmp_before = tmp_nosp = tmp_list3 = 0;
01234 verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_nosp, NULL_TREE);
01235 warn_for_collisions (tmp_nosp);
01236 merge_tlist (pbefore_sp, tmp_before, 0);
01237 merge_tlist (pbefore_sp, tmp_nosp, 0);
01238 verify_tree (TREE_OPERAND (x, 1), &tmp_list3, pno_sp, NULL_TREE);
01239 merge_tlist (pbefore_sp, tmp_list3, 0);
01240 return;
01241
01242 case COND_EXPR:
01243 tmp_before = tmp_list2 = 0;
01244 verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_list2, NULL_TREE);
01245 warn_for_collisions (tmp_list2);
01246 merge_tlist (pbefore_sp, tmp_before, 0);
01247 merge_tlist (pbefore_sp, tmp_list2, 1);
01248
01249 tmp_list3 = tmp_nosp = 0;
01250 verify_tree (TREE_OPERAND (x, 1), &tmp_list3, &tmp_nosp, NULL_TREE);
01251 warn_for_collisions (tmp_nosp);
01252 merge_tlist (pbefore_sp, tmp_list3, 0);
01253
01254 tmp_list3 = tmp_list2 = 0;
01255 verify_tree (TREE_OPERAND (x, 2), &tmp_list3, &tmp_list2, NULL_TREE);
01256 warn_for_collisions (tmp_list2);
01257 merge_tlist (pbefore_sp, tmp_list3, 0);
01258
01259
01260 merge_tlist (&tmp_nosp, tmp_list2, 0);
01261 add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
01262 return;
01263
01264 case PREDECREMENT_EXPR:
01265 case PREINCREMENT_EXPR:
01266 case POSTDECREMENT_EXPR:
01267 case POSTINCREMENT_EXPR:
01268 verify_tree (TREE_OPERAND (x, 0), pno_sp, pno_sp, x);
01269 return;
01270
01271 case MODIFY_EXPR:
01272 tmp_before = tmp_nosp = tmp_list3 = 0;
01273 verify_tree (TREE_OPERAND (x, 1), &tmp_before, &tmp_nosp, NULL_TREE);
01274 verify_tree (TREE_OPERAND (x, 0), &tmp_list3, &tmp_list3, x);
01275
01276
01277
01278
01279
01280
01281
01282
01283 add_tlist (&tmp_before, tmp_list3, x, 1);
01284 warn_for_collisions (tmp_before);
01285
01286
01287
01288
01289 add_tlist (pno_sp, tmp_list3, x, 0);
01290 warn_for_collisions_1 (TREE_OPERAND (x, 0), x, tmp_nosp, 1);
01291
01292 merge_tlist (pbefore_sp, tmp_before, 0);
01293 if (warning_candidate_p (TREE_OPERAND (x, 0)))
01294 merge_tlist (&tmp_nosp, new_tlist (NULL, TREE_OPERAND (x, 0), x), 0);
01295 add_tlist (pno_sp, tmp_nosp, NULL_TREE, 1);
01296 return;
01297
01298 case CALL_EXPR:
01299
01300
01301
01302 tmp_before = tmp_nosp = tmp_list2 = tmp_list3 = 0;
01303 verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_nosp, NULL_TREE);
01304 if (TREE_OPERAND (x, 1))
01305 verify_tree (TREE_OPERAND (x, 1), &tmp_list2, &tmp_list3, NULL_TREE);
01306 merge_tlist (&tmp_list3, tmp_list2, 0);
01307 add_tlist (&tmp_before, tmp_list3, NULL_TREE, 0);
01308 add_tlist (&tmp_before, tmp_nosp, NULL_TREE, 0);
01309 warn_for_collisions (tmp_before);
01310 add_tlist (pbefore_sp, tmp_before, NULL_TREE, 0);
01311 return;
01312
01313 case TREE_LIST:
01314
01315 while (x)
01316 {
01317 tmp_before = tmp_nosp = 0;
01318 verify_tree (TREE_VALUE (x), &tmp_before, &tmp_nosp, NULL_TREE);
01319 merge_tlist (&tmp_nosp, tmp_before, 0);
01320 add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
01321 x = TREE_CHAIN (x);
01322 }
01323 return;
01324
01325 case SAVE_EXPR:
01326 {
01327 struct tlist_cache *t;
01328 for (t = save_expr_cache; t; t = t->next)
01329 if (t->expr == x)
01330 break;
01331
01332 if (!t)
01333 {
01334 t = XOBNEW (&tlist_obstack, struct tlist_cache);
01335 t->next = save_expr_cache;
01336 t->expr = x;
01337 save_expr_cache = t;
01338
01339 tmp_before = tmp_nosp = 0;
01340 verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_nosp, NULL_TREE);
01341 warn_for_collisions (tmp_nosp);
01342
01343 tmp_list3 = 0;
01344 while (tmp_nosp)
01345 {
01346 struct tlist *t = tmp_nosp;
01347 tmp_nosp = t->next;
01348 merge_tlist (&tmp_list3, t, 0);
01349 }
01350 t->cache_before_sp = tmp_before;
01351 t->cache_after_sp = tmp_list3;
01352 }
01353 merge_tlist (pbefore_sp, t->cache_before_sp, 1);
01354 add_tlist (pno_sp, t->cache_after_sp, NULL_TREE, 1);
01355 return;
01356 }
01357
01358 default:
01359
01360
01361
01362 if (cl == tcc_unary)
01363 {
01364 x = TREE_OPERAND (x, 0);
01365 writer = 0;
01366 goto restart;
01367 }
01368 else if (IS_EXPR_CODE_CLASS (cl))
01369 {
01370 int lp;
01371 int max = TREE_CODE_LENGTH (TREE_CODE (x));
01372 for (lp = 0; lp < max; lp++)
01373 {
01374 tmp_before = tmp_nosp = 0;
01375 verify_tree (TREE_OPERAND (x, lp), &tmp_before, &tmp_nosp, 0);
01376 merge_tlist (&tmp_nosp, tmp_before, 0);
01377 add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
01378 }
01379 }
01380 return;
01381 }
01382 }
01383
01384
01385
01386
01387 void
01388 verify_sequence_points (tree expr)
01389 {
01390 struct tlist *before_sp = 0, *after_sp = 0;
01391
01392 warned_ids = 0;
01393 save_expr_cache = 0;
01394 if (tlist_firstobj == 0)
01395 {
01396 gcc_obstack_init (&tlist_obstack);
01397 tlist_firstobj = (char *) obstack_alloc (&tlist_obstack, 0);
01398 }
01399
01400 verify_tree (expr, &before_sp, &after_sp, 0);
01401 warn_for_collisions (after_sp);
01402 obstack_free (&tlist_obstack, tlist_firstobj);
01403 }
01404
01405
01406
01407 static tree
01408 check_case_value (tree value)
01409 {
01410 if (value == NULL_TREE)
01411 return value;
01412
01413
01414 STRIP_TYPE_NOPS (value);
01415
01416
01417
01418
01419
01420
01421 if (c_dialect_cxx ())
01422 {
01423 value = decl_constant_value (value);
01424 STRIP_TYPE_NOPS (value);
01425 value = fold (value);
01426 }
01427
01428 if (TREE_CODE (value) != INTEGER_CST
01429 && value != error_mark_node)
01430 {
01431 error ("case label does not reduce to an integer constant");
01432 value = error_mark_node;
01433 }
01434 else
01435
01436 value = default_conversion (value);
01437
01438 constant_expression_warning (value);
01439
01440 return value;
01441 }
01442
01443
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453
01454
01455 static bool
01456 check_case_bounds (tree type, tree orig_type,
01457 tree *case_low_p, tree *case_high_p)
01458 {
01459 tree min_value, max_value;
01460 tree case_low = *case_low_p;
01461 tree case_high = case_high_p ? *case_high_p : case_low;
01462
01463
01464 if (orig_type == error_mark_node)
01465 return true;
01466
01467 min_value = TYPE_MIN_VALUE (orig_type);
01468 max_value = TYPE_MAX_VALUE (orig_type);
01469
01470
01471 if (tree_int_cst_compare (case_low, min_value) < 0
01472 && tree_int_cst_compare (case_high, min_value) < 0)
01473 {
01474 warning ("case label value is less than minimum value for type");
01475 return false;
01476 }
01477
01478
01479 if (tree_int_cst_compare (case_low, max_value) > 0
01480 && tree_int_cst_compare (case_high, max_value) > 0)
01481 {
01482 warning ("case label value exceeds maximum value for type");
01483 return false;
01484 }
01485
01486
01487 if (tree_int_cst_compare (case_high, min_value) >= 0
01488 && tree_int_cst_compare (case_low, min_value) < 0)
01489 {
01490 warning ("lower value in case label range"
01491 " less than minimum value for type");
01492 case_low = min_value;
01493 }
01494
01495
01496 if (tree_int_cst_compare (case_low, max_value) <= 0
01497 && tree_int_cst_compare (case_high, max_value) > 0)
01498 {
01499 warning ("upper value in case label range"
01500 " exceeds maximum value for type");
01501 case_high = max_value;
01502 }
01503
01504 if (*case_low_p != case_low)
01505 *case_low_p = convert (type, case_low);
01506 if (case_high_p && *case_high_p != case_high)
01507 *case_high_p = convert (type, case_high);
01508
01509 return true;
01510 }
01511
01512
01513
01514
01515 tree
01516 c_common_type_for_size (unsigned int bits, int unsignedp)
01517 {
01518 if (bits == TYPE_PRECISION (integer_type_node))
01519 return unsignedp ? unsigned_type_node : integer_type_node;
01520
01521 if (bits == TYPE_PRECISION (signed_char_type_node))
01522 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
01523
01524 if (bits == TYPE_PRECISION (short_integer_type_node))
01525 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
01526
01527 if (bits == TYPE_PRECISION (long_integer_type_node))
01528 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
01529
01530 if (bits == TYPE_PRECISION (long_long_integer_type_node))
01531 return (unsignedp ? long_long_unsigned_type_node
01532 : long_long_integer_type_node);
01533
01534 if (bits == TYPE_PRECISION (widest_integer_literal_type_node))
01535 return (unsignedp ? widest_unsigned_literal_type_node
01536 : widest_integer_literal_type_node);
01537
01538 if (bits <= TYPE_PRECISION (intQI_type_node))
01539 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
01540
01541 if (bits <= TYPE_PRECISION (intHI_type_node))
01542 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
01543
01544 if (bits <= TYPE_PRECISION (intSI_type_node))
01545 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
01546
01547 if (bits <= TYPE_PRECISION (intDI_type_node))
01548 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
01549
01550 return 0;
01551 }
01552
01553
01554
01555 static GTY(()) tree registered_builtin_types;
01556
01557
01558
01559
01560
01561 tree
01562 c_common_type_for_mode (enum machine_mode mode, int unsignedp)
01563 {
01564 tree t;
01565
01566 if (mode == TYPE_MODE (integer_type_node))
01567 return unsignedp ? unsigned_type_node : integer_type_node;
01568
01569 if (mode == TYPE_MODE (signed_char_type_node))
01570 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
01571
01572 if (mode == TYPE_MODE (short_integer_type_node))
01573 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
01574
01575 if (mode == TYPE_MODE (long_integer_type_node))
01576 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
01577
01578 if (mode == TYPE_MODE (long_long_integer_type_node))
01579 return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node;
01580
01581 if (mode == TYPE_MODE (widest_integer_literal_type_node))
01582 return unsignedp ? widest_unsigned_literal_type_node
01583 : widest_integer_literal_type_node;
01584
01585 if (mode == QImode)
01586 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
01587
01588 if (mode == HImode)
01589 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
01590
01591 if (mode == SImode)
01592 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
01593
01594 if (mode == DImode)
01595 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
01596
01597 #if HOST_BITS_PER_WIDE_INT >= 64
01598 if (mode == TYPE_MODE (intTI_type_node))
01599 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
01600 #endif
01601
01602 if (mode == TYPE_MODE (float_type_node))
01603 return float_type_node;
01604
01605 if (mode == TYPE_MODE (double_type_node))
01606 return double_type_node;
01607
01608 if (mode == TYPE_MODE (long_double_type_node))
01609 return long_double_type_node;
01610
01611 if (mode == TYPE_MODE (void_type_node))
01612 return void_type_node;
01613
01614 if (mode == TYPE_MODE (build_pointer_type (char_type_node)))
01615 return (unsignedp
01616 ? make_unsigned_type (GET_MODE_PRECISION (mode))
01617 : make_signed_type (GET_MODE_PRECISION (mode)));
01618
01619 if (mode == TYPE_MODE (build_pointer_type (integer_type_node)))
01620 return (unsignedp
01621 ? make_unsigned_type (GET_MODE_PRECISION (mode))
01622 : make_signed_type (GET_MODE_PRECISION (mode)));
01623
01624 if (COMPLEX_MODE_P (mode))
01625 {
01626 enum machine_mode inner_mode;
01627 tree inner_type;
01628
01629 if (mode == TYPE_MODE (complex_float_type_node))
01630 return complex_float_type_node;
01631 if (mode == TYPE_MODE (complex_double_type_node))
01632 return complex_double_type_node;
01633 if (mode == TYPE_MODE (complex_long_double_type_node))
01634 return complex_long_double_type_node;
01635
01636 if (mode == TYPE_MODE (complex_integer_type_node) && !unsignedp)
01637 return complex_integer_type_node;
01638
01639 inner_mode = GET_MODE_INNER (mode);
01640 inner_type = c_common_type_for_mode (inner_mode, unsignedp);
01641 if (inner_type != NULL_TREE)
01642 return build_complex_type (inner_type);
01643 }
01644 else if (VECTOR_MODE_P (mode))
01645 {
01646 enum machine_mode inner_mode = GET_MODE_INNER (mode);
01647 tree inner_type = c_common_type_for_mode (inner_mode, unsignedp);
01648 if (inner_type != NULL_TREE)
01649 return build_vector_type_for_mode (inner_type, mode);
01650 }
01651
01652 for (t = registered_builtin_types; t; t = TREE_CHAIN (t))
01653 if (TYPE_MODE (TREE_VALUE (t)) == mode)
01654 return TREE_VALUE (t);
01655
01656 return 0;
01657 }
01658
01659
01660 tree
01661 c_common_unsigned_type (tree type)
01662 {
01663 tree type1 = TYPE_MAIN_VARIANT (type);
01664 if (type1 == signed_char_type_node || type1 == char_type_node)
01665 return unsigned_char_type_node;
01666 if (type1 == integer_type_node)
01667 return unsigned_type_node;
01668 if (type1 == short_integer_type_node)
01669 return short_unsigned_type_node;
01670 if (type1 == long_integer_type_node)
01671 return long_unsigned_type_node;
01672 if (type1 == long_long_integer_type_node)
01673 return long_long_unsigned_type_node;
01674 if (type1 == widest_integer_literal_type_node)
01675 return widest_unsigned_literal_type_node;
01676 #if HOST_BITS_PER_WIDE_INT >= 64
01677 if (type1 == intTI_type_node)
01678 return unsigned_intTI_type_node;
01679 #endif
01680 if (type1 == intDI_type_node)
01681 return unsigned_intDI_type_node;
01682 if (type1 == intSI_type_node)
01683 return unsigned_intSI_type_node;
01684 if (type1 == intHI_type_node)
01685 return unsigned_intHI_type_node;
01686 if (type1 == intQI_type_node)
01687 return unsigned_intQI_type_node;
01688
01689 return c_common_signed_or_unsigned_type (1, type);
01690 }
01691
01692
01693
01694 tree
01695 c_common_signed_type (tree type)
01696 {
01697 tree type1 = TYPE_MAIN_VARIANT (type);
01698 if (type1 == unsigned_char_type_node || type1 == char_type_node)
01699 return signed_char_type_node;
01700 if (type1 == unsigned_type_node)
01701 return integer_type_node;
01702 if (type1 == short_unsigned_type_node)
01703 return short_integer_type_node;
01704 if (type1 == long_unsigned_type_node)
01705 return long_integer_type_node;
01706 if (type1 == long_long_unsigned_type_node)
01707 return long_long_integer_type_node;
01708 if (type1 == widest_unsigned_literal_type_node)
01709 return widest_integer_literal_type_node;
01710 #if HOST_BITS_PER_WIDE_INT >= 64
01711 if (type1 == unsigned_intTI_type_node)
01712 return intTI_type_node;
01713 #endif
01714 if (type1 == unsigned_intDI_type_node)
01715 return intDI_type_node;
01716 if (type1 == unsigned_intSI_type_node)
01717 return intSI_type_node;
01718 if (type1 == unsigned_intHI_type_node)
01719 return intHI_type_node;
01720 if (type1 == unsigned_intQI_type_node)
01721 return intQI_type_node;
01722
01723 return c_common_signed_or_unsigned_type (0, type);
01724 }
01725
01726
01727
01728
01729 tree
01730 c_common_signed_or_unsigned_type (int unsignedp, tree type)
01731 {
01732 if (!INTEGRAL_TYPE_P (type)
01733 || TYPE_UNSIGNED (type) == unsignedp)
01734 return type;
01735
01736
01737
01738
01739
01740
01741
01742
01743
01744
01745 #define TYPE_OK(node) \
01746 (TYPE_MODE (type) == TYPE_MODE (node) \
01747 && (c_dialect_cxx () || TYPE_PRECISION (type) == TYPE_PRECISION (node)))
01748 if (TYPE_OK (signed_char_type_node))
01749 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
01750 if (TYPE_OK (integer_type_node))
01751 return unsignedp ? unsigned_type_node : integer_type_node;
01752 if (TYPE_OK (short_integer_type_node))
01753 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
01754 if (TYPE_OK (long_integer_type_node))
01755 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
01756 if (TYPE_OK (long_long_integer_type_node))
01757 return (unsignedp ? long_long_unsigned_type_node
01758 : long_long_integer_type_node);
01759 if (TYPE_OK (widest_integer_literal_type_node))
01760 return (unsignedp ? widest_unsigned_literal_type_node
01761 : widest_integer_literal_type_node);
01762
01763 #if HOST_BITS_PER_WIDE_INT >= 64
01764 if (TYPE_OK (intTI_type_node))
01765 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
01766 #endif
01767 if (TYPE_OK (intDI_type_node))
01768 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
01769 if (TYPE_OK (intSI_type_node))
01770 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
01771 if (TYPE_OK (intHI_type_node))
01772 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
01773 if (TYPE_OK (intQI_type_node))
01774 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
01775 #undef TYPE_OK
01776
01777 if (c_dialect_cxx ())
01778 return type;
01779 else
01780 return build_nonstandard_integer_type (TYPE_PRECISION (type), unsignedp);
01781 }
01782
01783
01784
01785 void
01786 c_register_builtin_type (tree type, const char* name)
01787 {
01788 tree decl;
01789
01790 decl = build_decl (TYPE_DECL, get_identifier (name), type);
01791 DECL_ARTIFICIAL (decl) = 1;
01792 if (!TYPE_NAME (type))
01793 TYPE_NAME (type) = decl;
01794 pushdecl (decl);
01795
01796 registered_builtin_types = tree_cons (0, type, registered_builtin_types);
01797 }
01798
01799
01800
01801
01802
01803 unsigned int
01804 min_precision (tree value, int unsignedp)
01805 {
01806 int log;
01807
01808
01809
01810
01811
01812
01813 if (tree_int_cst_sgn (value) < 0)
01814 value = fold (build1 (BIT_NOT_EXPR, TREE_TYPE (value), value));
01815
01816
01817
01818
01819 if (integer_zerop (value))
01820 log = 0;
01821 else
01822 log = tree_floor_log2 (value);
01823
01824 return log + 1 + !unsignedp;
01825 }
01826
01827
01828
01829
01830
01831 void
01832 binary_op_error (enum tree_code code)
01833 {
01834 const char *opname;
01835
01836 switch (code)
01837 {
01838 case NOP_EXPR:
01839 error ("invalid truth-value expression");
01840 return;
01841
01842 case PLUS_EXPR:
01843 opname = "+"; break;
01844 case MINUS_EXPR:
01845 opname = "-"; break;
01846 case MULT_EXPR:
01847 opname = "*"; break;
01848 case MAX_EXPR:
01849 opname = "max"; break;
01850 case MIN_EXPR:
01851 opname = "min"; break;
01852 case EQ_EXPR:
01853 opname = "=="; break;
01854 case NE_EXPR:
01855 opname = "!="; break;
01856 case LE_EXPR:
01857 opname = "<="; break;
01858 case GE_EXPR:
01859 opname = ">="; break;
01860 case LT_EXPR:
01861 opname = "<"; break;
01862 case GT_EXPR:
01863 opname = ">"; break;
01864 case LSHIFT_EXPR:
01865 opname = "<<"; break;
01866 case RSHIFT_EXPR:
01867 opname = ">>"; break;
01868 case TRUNC_MOD_EXPR:
01869 case FLOOR_MOD_EXPR:
01870 opname = "%"; break;
01871 case TRUNC_DIV_EXPR:
01872 case FLOOR_DIV_EXPR:
01873 opname = "/"; break;
01874 case BIT_AND_EXPR:
01875 opname = "&"; break;
01876 case BIT_IOR_EXPR:
01877 opname = "|"; break;
01878 case TRUTH_ANDIF_EXPR:
01879 opname = "&&"; break;
01880 case TRUTH_ORIF_EXPR:
01881 opname = "||"; break;
01882 case BIT_XOR_EXPR:
01883 opname = "^"; break;
01884 default:
01885 gcc_unreachable ();
01886 }
01887 error ("invalid operands to binary %s", opname);
01888 }
01889
01890
01891
01892
01893
01894
01895
01896
01897
01898
01899
01900
01901
01902
01903
01904 tree
01905 shorten_compare (tree *op0_ptr, tree *op1_ptr, tree *restype_ptr,
01906 enum tree_code *rescode_ptr)
01907 {
01908 tree type;
01909 tree op0 = *op0_ptr;
01910 tree op1 = *op1_ptr;
01911 int unsignedp0, unsignedp1;
01912 int real1, real2;
01913 tree primop0, primop1;
01914 enum tree_code code = *rescode_ptr;
01915
01916
01917
01918
01919 primop0 = get_narrower (op0, &unsignedp0);
01920 primop1 = get_narrower (op1, &unsignedp1);
01921
01922
01923
01924
01925 if (op0 == primop0 && TREE_TYPE (op0) != *restype_ptr)
01926 unsignedp0 = TYPE_UNSIGNED (TREE_TYPE (op0));
01927 if (op1 == primop1 && TREE_TYPE (op1) != *restype_ptr)
01928 unsignedp1 = TYPE_UNSIGNED (TREE_TYPE (op1));
01929
01930
01931 real1 = TREE_CODE (TREE_TYPE (primop0)) == REAL_TYPE;
01932 real2 = TREE_CODE (TREE_TYPE (primop1)) == REAL_TYPE;
01933
01934
01935
01936
01937
01938 if (TREE_CONSTANT (primop0)
01939 && !integer_zerop (primop1) && !real_zerop (primop1))
01940 {
01941 tree tem = primop0;
01942 int temi = unsignedp0;
01943 primop0 = primop1;
01944 primop1 = tem;
01945 tem = op0;
01946 op0 = op1;
01947 op1 = tem;
01948 *op0_ptr = op0;
01949 *op1_ptr = op1;
01950 unsignedp0 = unsignedp1;
01951 unsignedp1 = temi;
01952 temi = real1;
01953 real1 = real2;
01954 real2 = temi;
01955
01956 switch (code)
01957 {
01958 case LT_EXPR:
01959 code = GT_EXPR;
01960 break;
01961 case GT_EXPR:
01962 code = LT_EXPR;
01963 break;
01964 case LE_EXPR:
01965 code = GE_EXPR;
01966 break;
01967 case GE_EXPR:
01968 code = LE_EXPR;
01969 break;
01970 default:
01971 break;
01972 }
01973 *rescode_ptr = code;
01974 }
01975
01976
01977
01978
01979
01980
01981
01982
01983
01984
01985
01986
01987
01988
01989
01990
01991
01992
01993 if (!real1 && !real2
01994 && TREE_CODE (primop1) == INTEGER_CST
01995 && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr))
01996 {
01997 int min_gt, max_gt, min_lt, max_lt;
01998 tree maxval, minval;
01999
02000 int unsignedp = TYPE_UNSIGNED (*restype_ptr);
02001 tree val;
02002
02003 type = c_common_signed_or_unsigned_type (unsignedp0,
02004 TREE_TYPE (primop0));
02005
02006 maxval = TYPE_MAX_VALUE (type);
02007 minval = TYPE_MIN_VALUE (type);
02008
02009 if (unsignedp && !unsignedp0)
02010 *restype_ptr = c_common_signed_type (*restype_ptr);
02011
02012 if (TREE_TYPE (primop1) != *restype_ptr)
02013 {
02014
02015
02016 tree tmp = build_int_cst_wide (*restype_ptr,
02017 TREE_INT_CST_LOW (primop1),
02018 TREE_INT_CST_HIGH (primop1));
02019
02020 primop1 = force_fit_type (tmp, 0, TREE_OVERFLOW (primop1),
02021 TREE_CONSTANT_OVERFLOW (primop1));
02022 }
02023 if (type != *restype_ptr)
02024 {
02025 minval = convert (*restype_ptr, minval);
02026 maxval = convert (*restype_ptr, maxval);
02027 }
02028
02029 if (unsignedp && unsignedp0)
02030 {
02031 min_gt = INT_CST_LT_UNSIGNED (primop1, minval);
02032 max_gt = INT_CST_LT_UNSIGNED (primop1, maxval);
02033 min_lt = INT_CST_LT_UNSIGNED (minval, primop1);
02034 max_lt = INT_CST_LT_UNSIGNED (maxval, primop1);
02035 }
02036 else
02037 {
02038 min_gt = INT_CST_LT (primop1, minval);
02039 max_gt = INT_CST_LT (primop1, maxval);
02040 min_lt = INT_CST_LT (minval, primop1);
02041 max_lt = INT_CST_LT (maxval, primop1);
02042 }
02043
02044 val = 0;
02045
02046 if (code == NE_EXPR)
02047 {
02048 if (max_lt || min_gt)
02049 val = truthvalue_true_node;
02050 }
02051 else if (code == EQ_EXPR)
02052 {
02053 if (max_lt || min_gt)
02054 val = truthvalue_false_node;
02055 }
02056 else if (code == LT_EXPR)
02057 {
02058 if (max_lt)
02059 val = truthvalue_true_node;
02060 if (!min_lt)
02061 val = truthvalue_false_node;
02062 }
02063 else if (code == GT_EXPR)
02064 {
02065 if (min_gt)
02066 val = truthvalue_true_node;
02067 if (!max_gt)
02068 val = truthvalue_false_node;
02069 }
02070 else if (code == LE_EXPR)
02071 {
02072 if (!max_gt)
02073 val = truthvalue_true_node;
02074 if (min_gt)
02075 val = truthvalue_false_node;
02076 }
02077 else if (code == GE_EXPR)
02078 {
02079 if (!min_lt)
02080 val = truthvalue_true_node;
02081 if (max_lt)
02082 val = truthvalue_false_node;
02083 }
02084
02085
02086
02087
02088
02089
02090
02091
02092
02093
02094
02095
02096 if (unsignedp && !unsignedp0)
02097 {
02098 if (val != 0)
02099 switch (code)
02100 {
02101 case LT_EXPR:
02102 case GE_EXPR:
02103 primop1 = TYPE_MIN_VALUE (type);
02104 val = 0;
02105 break;
02106
02107 case LE_EXPR:
02108 case GT_EXPR:
02109 primop1 = TYPE_MAX_VALUE (type);
02110 val = 0;
02111 break;
02112
02113 default:
02114 break;
02115 }
02116 type = c_common_unsigned_type (type);
02117 }
02118
02119 if (TREE_CODE (primop0) != INTEGER_CST)
02120 {
02121 if (val == truthvalue_false_node)
02122 warning ("comparison is always false due to limited range of data type");
02123 if (val == truthvalue_true_node)
02124 warning ("comparison is always true due to limited range of data type");
02125 }
02126
02127 if (val != 0)
02128 {
02129
02130 if (TREE_SIDE_EFFECTS (primop0))
02131 return build2 (COMPOUND_EXPR, TREE_TYPE (val), primop0, val);
02132 return val;
02133 }
02134
02135
02136
02137
02138 }
02139 else if (real1 && real2
02140 && (TYPE_PRECISION (TREE_TYPE (primop0))
02141 == TYPE_PRECISION (TREE_TYPE (primop1))))
02142 type = TREE_TYPE (primop0);
02143
02144
02145
02146
02147
02148
02149
02150
02151
02152 else if (unsignedp0 == unsignedp1 && real1 == real2
02153 && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr)
02154 && TYPE_PRECISION (TREE_TYPE (primop1)) < TYPE_PRECISION (*restype_ptr))
02155 {
02156 type = common_type (TREE_TYPE (primop0), TREE_TYPE (primop1));
02157 type = c_common_signed_or_unsigned_type (unsignedp0
02158 || TYPE_UNSIGNED (*restype_ptr),
02159 type);
02160
02161
02162 primop0
02163 = convert (c_common_signed_or_unsigned_type (unsignedp0,
02164 TREE_TYPE (primop0)),
02165 primop0);
02166 primop1
02167 = convert (c_common_signed_or_unsigned_type (unsignedp1,
02168 TREE_TYPE (primop1)),
02169 primop1);
02170 }
02171 else
02172 {
02173
02174
02175 type = *restype_ptr;
02176 primop0 = op0;
02177 primop1 = op1;
02178
02179 if (!real1 && !real2 && integer_zerop (primop1)
02180 && TYPE_UNSIGNED (*restype_ptr))
02181 {
02182 tree value = 0;
02183 switch (code)
02184 {
02185 case GE_EXPR:
02186
02187
02188
02189
02190 if (extra_warnings && !in_system_header
02191 && !(TREE_CODE (primop0) == INTEGER_CST
02192 && !TREE_OVERFLOW (convert (c_common_signed_type (type),
02193 primop0))))
02194 warning ("comparison of unsigned expression >= 0 is always true");
02195 value = truthvalue_true_node;
02196 break;
02197
02198 case LT_EXPR:
02199 if (extra_warnings && !in_system_header
02200 && !(TREE_CODE (primop0) == INTEGER_CST
02201 && !TREE_OVERFLOW (convert (c_common_signed_type (type),
02202 primop0))))
02203 warning ("comparison of unsigned expression < 0 is always false");
02204 value = truthvalue_false_node;
02205 break;
02206
02207 default:
02208 break;
02209 }
02210
02211 if (value != 0)
02212 {
02213
02214 if (TREE_SIDE_EFFECTS (primop0))
02215 return build2 (COMPOUND_EXPR, TREE_TYPE (value),
02216 primop0, value);
02217 return value;
02218 }
02219 }
02220 }
02221
02222 *op0_ptr = convert (type, primop0);
02223 *op1_ptr = convert (type, primop1);
02224
02225 *restype_ptr = truthvalue_type_node;
02226
02227 return 0;
02228 }
02229
02230
02231
02232
02233 tree
02234 pointer_int_sum (enum tree_code resultcode, tree ptrop, tree intop)
02235 {
02236 tree size_exp;
02237
02238
02239
02240 tree result_type = TREE_TYPE (ptrop);
02241
02242 if (TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE)
02243 {
02244 if (pedantic || warn_pointer_arith)
02245 pedwarn ("pointer of type %<void *%> used in arithmetic");
02246 size_exp = integer_one_node;
02247 }
02248 else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE)
02249 {
02250 if (pedantic || warn_pointer_arith)
02251 pedwarn ("pointer to a function used in arithmetic");
02252 size_exp = integer_one_node;
02253 }
02254 else if (TREE_CODE (TREE_TYPE (result_type)) == METHOD_TYPE)
02255 {
02256 if (pedantic || warn_pointer_arith)
02257 pedwarn ("pointer to member function used in arithmetic");
02258 size_exp = integer_one_node;
02259 }
02260 else
02261 size_exp = size_in_bytes (TREE_TYPE (result_type));
02262
02263
02264
02265
02266
02267
02268 if ((TREE_CODE (intop) == PLUS_EXPR || TREE_CODE (intop) == MINUS_EXPR)
02269 && !TREE_CONSTANT (intop)
02270 && TREE_CONSTANT (TREE_OPERAND (intop, 1))
02271 && TREE_CONSTANT (size_exp)
02272
02273
02274 && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop, 0))) == INTEGER_TYPE
02275
02276
02277
02278 && (!TYPE_UNSIGNED (TREE_TYPE (intop))
02279 || (TYPE_PRECISION (TREE_TYPE (intop))
02280 == TYPE_PRECISION (TREE_TYPE (ptrop)))))
02281 {
02282 enum tree_code subcode = resultcode;
02283 tree int_type = TREE_TYPE (intop);
02284 if (TREE_CODE (intop) == MINUS_EXPR)
02285 subcode = (subcode == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR);
02286
02287
02288
02289 ptrop = build_binary_op (subcode, ptrop,
02290 convert (int_type, TREE_OPERAND (intop, 1)), 1);
02291 intop = convert (int_type, TREE_OPERAND (intop, 0));
02292 }
02293
02294
02295
02296
02297 if (TYPE_PRECISION (TREE_TYPE (intop)) != TYPE_PRECISION (sizetype)
02298 || TYPE_UNSIGNED (TREE_TYPE (intop)) != TYPE_UNSIGNED (sizetype))
02299 intop = convert (c_common_type_for_size (TYPE_PRECISION (sizetype),
02300 TYPE_UNSIGNED (sizetype)), intop);
02301
02302
02303
02304
02305
02306 intop = convert (result_type,
02307 build_binary_op (MULT_EXPR, intop,
02308 convert (TREE_TYPE (intop), size_exp), 1));
02309
02310
02311 return fold (build2 (resultcode, result_type, ptrop, intop));
02312 }
02313
02314
02315
02316
02317
02318
02319
02320
02321
02322
02323
02324
02325 tree
02326 c_common_truthvalue_conversion (tree expr)
02327 {
02328 switch (TREE_CODE (expr))
02329 {
02330 case EQ_EXPR: case NE_EXPR: case UNEQ_EXPR: case LTGT_EXPR:
02331 case LE_EXPR: case GE_EXPR: case LT_EXPR: case GT_EXPR:
02332 case UNLE_EXPR: case UNGE_EXPR: case UNLT_EXPR: case UNGT_EXPR:
02333 case ORDERED_EXPR: case UNORDERED_EXPR:
02334 if (TREE_TYPE (expr) == truthvalue_type_node)
02335 return expr;
02336 return build2 (TREE_CODE (expr), truthvalue_type_node,
02337 TREE_OPERAND (expr, 0), TREE_OPERAND (expr, 1));
02338
02339 case TRUTH_ANDIF_EXPR:
02340 case TRUTH_ORIF_EXPR:
02341 case TRUTH_AND_EXPR:
02342 case TRUTH_OR_EXPR:
02343 case TRUTH_XOR_EXPR:
02344 if (TREE_TYPE (expr) == truthvalue_type_node)
02345 return expr;
02346 return build2 (TREE_CODE (expr), truthvalue_type_node,
02347 lang_hooks.truthvalue_conversion (TREE_OPERAND (expr, 0)),
02348 lang_hooks.truthvalue_conversion (TREE_OPERAND (expr, 1)));
02349
02350 case TRUTH_NOT_EXPR:
02351 if (TREE_TYPE (expr) == truthvalue_type_node)
02352 return expr;
02353 return build1 (TREE_CODE (expr), truthvalue_type_node,
02354 lang_hooks.truthvalue_conversion (TREE_OPERAND (expr, 0)));
02355
02356 case ERROR_MARK:
02357 return expr;
02358
02359 case INTEGER_CST:
02360
02361 return (TREE_INT_CST_LOW (expr) != 0 || TREE_INT_CST_HIGH (expr) != 0)
02362 ? truthvalue_true_node
02363 : truthvalue_false_node;
02364
02365 case REAL_CST:
02366 return real_compare (NE_EXPR, &TREE_REAL_CST (expr), &dconst0)
02367 ? truthvalue_true_node
02368 : truthvalue_false_node;
02369
02370 case FUNCTION_DECL:
02371 expr = build_unary_op (ADDR_EXPR, expr, 0);
02372
02373
02374 case ADDR_EXPR:
02375 {
02376 if (TREE_CODE (TREE_OPERAND (expr, 0)) == FUNCTION_DECL
02377 && !DECL_WEAK (TREE_OPERAND (expr, 0)))
02378 {
02379
02380
02381 warning ("the address of %qD, will always evaluate as %<true%>",
02382 TREE_OPERAND (expr, 0));
02383 return truthvalue_true_node;
02384 }
02385
02386
02387
02388 if (DECL_P (TREE_OPERAND (expr, 0))
02389 && DECL_EXTERNAL (TREE_OPERAND (expr, 0)))
02390 break;
02391
02392 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 0)))
02393 return build2 (COMPOUND_EXPR, truthvalue_type_node,
02394 TREE_OPERAND (expr, 0), truthvalue_true_node);
02395 else
02396 return truthvalue_true_node;
02397 }
02398
02399 case COMPLEX_EXPR:
02400 return build_binary_op ((TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1))
02401 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
02402 lang_hooks.truthvalue_conversion (TREE_OPERAND (expr, 0)),
02403 lang_hooks.truthvalue_conversion (TREE_OPERAND (expr, 1)),
02404 0);
02405
02406 case NEGATE_EXPR:
02407 case ABS_EXPR:
02408 case FLOAT_EXPR:
02409
02410 return lang_hooks.truthvalue_conversion (TREE_OPERAND (expr, 0));
02411
02412 case LROTATE_EXPR:
02413 case RROTATE_EXPR:
02414
02415
02416 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1)))
02417 return build2 (COMPOUND_EXPR, truthvalue_type_node,
02418 TREE_OPERAND (expr, 1),
02419 lang_hooks.truthvalue_conversion (TREE_OPERAND (expr, 0)));
02420 else
02421 return lang_hooks.truthvalue_conversion (TREE_OPERAND (expr, 0));
02422
02423 case COND_EXPR:
02424
02425 return fold (build3 (COND_EXPR, truthvalue_type_node,
02426 TREE_OPERAND (expr, 0),
02427 lang_hooks.truthvalue_conversion (TREE_OPERAND (expr, 1)),
02428 lang_hooks.truthvalue_conversion (TREE_OPERAND (expr, 2))));
02429
02430 case CONVERT_EXPR:
02431
02432
02433 if (TREE_CODE (TREE_TYPE (expr)) == REFERENCE_TYPE
02434 || TREE_CODE (TREE_TYPE (TREE_OPERAND (expr, 0))) == REFERENCE_TYPE)
02435 break;
02436
02437 case NOP_EXPR:
02438
02439 if (TYPE_PRECISION (TREE_TYPE (expr))
02440 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0))))
02441 return lang_hooks.truthvalue_conversion (TREE_OPERAND (expr, 0));
02442 break;
02443
02444 case MINUS_EXPR:
02445
02446
02447
02448
02449
02450
02451
02452
02453 if (HONOR_INFINITIES (TYPE_MODE (TREE_TYPE (TREE_OPERAND (expr, 0)))))
02454 break;
02455
02456 case BIT_XOR_EXPR:
02457
02458
02459 if (TREE_TYPE (TREE_OPERAND (expr, 0))
02460 == TREE_TYPE (TREE_OPERAND (expr, 1)))
02461 return build_binary_op (NE_EXPR, TREE_OPERAND (expr, 0),
02462 TREE_OPERAND (expr, 1), 1);
02463 return build_binary_op (NE_EXPR, TREE_OPERAND (expr, 0),
02464 fold (build1 (NOP_EXPR,
02465 TREE_TYPE (TREE_OPERAND (expr, 0)),
02466 TREE_OPERAND (expr, 1))), 1);
02467
02468 case BIT_AND_EXPR:
02469 if (integer_onep (TREE_OPERAND (expr, 1))
02470 && TREE_TYPE (expr) != truthvalue_type_node)
02471
02472 return build1 (NOP_EXPR, truthvalue_type_node, expr);
02473 break;
02474
02475 case MODIFY_EXPR:
02476 if (warn_parentheses && !TREE_NO_WARNING (expr))
02477 warning ("suggest parentheses around assignment used as truth value");
02478 break;
02479
02480 default:
02481 break;
02482 }
02483
02484 if (TREE_CODE (TREE_TYPE (expr)) == COMPLEX_TYPE)
02485 {
02486 tree t = save_expr (expr);
02487 return (build_binary_op
02488 ((TREE_SIDE_EFFECTS (expr)
02489 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
02490 lang_hooks.truthvalue_conversion (build_unary_op (REALPART_EXPR, t, 0)),
02491 lang_hooks.truthvalue_conversion (build_unary_op (IMAGPART_EXPR, t, 0)),
02492 0));
02493 }
02494
02495 return build_binary_op (NE_EXPR, expr, integer_zero_node, 1);
02496 }
02497
02498 static tree builtin_function_2 (const char *builtin_name, const char *name,
02499 tree builtin_type, tree type,
02500 enum built_in_function function_code,
02501 enum built_in_class cl, int library_name_p,
02502 bool nonansi_p,
02503 tree attrs);
02504
02505
02506
02507
02508 tree
02509 c_build_qualified_type (tree type, int type_quals)
02510 {
02511 if (type == error_mark_node)
02512 return type;
02513
02514 if (TREE_CODE (type) == ARRAY_TYPE)
02515 {
02516 tree t;
02517 tree element_type = c_build_qualified_type (TREE_TYPE (type),
02518 type_quals);
02519
02520
02521 for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
02522 {
02523 if (TYPE_QUALS (strip_array_types (t)) == type_quals
02524 && TYPE_NAME (t) == TYPE_NAME (type)
02525 && TYPE_CONTEXT (t) == TYPE_CONTEXT (type)
02526 && attribute_list_equal (TYPE_ATTRIBUTES (t),
02527 TYPE_ATTRIBUTES (type)))
02528 break;
02529 }
02530 if (!t)
02531 {
02532 t = build_variant_type_copy (type);
02533 TREE_TYPE (t) = element_type;
02534 }
02535 return t;
02536 }
02537
02538
02539
02540
02541 if ((type_quals & TYPE_QUAL_RESTRICT)
02542 && (!POINTER_TYPE_P (type)
02543 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type))))
02544 {
02545 error ("invalid use of %<restrict%>");
02546 type_quals &= ~TYPE_QUAL_RESTRICT;
02547 }
02548
02549 return build_qualified_type (type, type_quals);
02550 }
02551
02552
02553
02554 void
02555 c_apply_type_quals_to_decl (int type_quals, tree decl)
02556 {
02557 tree type = TREE_TYPE (decl);
02558
02559 if (type == error_mark_node)
02560 return;
02561
02562 if (((type_quals & TYPE_QUAL_CONST)
02563 || (type && TREE_CODE (type) == REFERENCE_TYPE))
02564
02565
02566
02567
02568
02569 && !(type && TYPE_NEEDS_CONSTRUCTING (type)))
02570 TREE_READONLY (decl) = 1;
02571 if (type_quals & TYPE_QUAL_VOLATILE)
02572 {
02573 TREE_SIDE_EFFECTS (decl) = 1;
02574 TREE_THIS_VOLATILE (decl) = 1;
02575 }
02576 if (type_quals & TYPE_QUAL_RESTRICT)
02577 {
02578 while (type && TREE_CODE (type) == ARRAY_TYPE)
02579
02580
02581 type = TREE_TYPE (type);
02582 if (!type
02583 || !POINTER_TYPE_P (type)
02584 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type)))
02585 error ("invalid use of %<restrict%>");
02586 else if (flag_strict_aliasing && type == TREE_TYPE (decl))
02587
02588
02589
02590 DECL_POINTER_ALIAS_SET (decl) = -2;
02591 }
02592 }
02593
02594
02595
02596
02597
02598
02599 static hashval_t
02600 c_type_hash (const void *p)
02601 {
02602 int i = 0;
02603 int shift, size;
02604 tree t = (tree) p;
02605 tree t2;
02606 switch (TREE_CODE (t))
02607 {
02608
02609 case POINTER_TYPE:
02610 return c_type_hash (TREE_TYPE (t)) ^ 0x3003003;
02611
02612 case ENUMERAL_TYPE:
02613 shift = 3;
02614 t2 = TYPE_VALUES (t);
02615 break;
02616 case RECORD_TYPE:
02617 shift = 0;
02618 t2 = TYPE_FIELDS (t);
02619 break;
02620 case QUAL_UNION_TYPE:
02621 shift = 1;
02622 t2 = TYPE_FIELDS (t);
02623 break;
02624 case UNION_TYPE:
02625 shift = 2;
02626 t2 = TYPE_FIELDS (t);
02627 break;
02628 default:
02629 gcc_unreachable ();
02630 }
02631 for (; t2; t2 = TREE_CHAIN (t2))
02632 i++;
02633 size = TREE_INT_CST_LOW (TYPE_SIZE (t));
02634 return ((size << 24) | (i << shift));
02635 }
02636
02637 static GTY((param_is (union tree_node))) htab_t type_hash_table;
02638
02639
02640
02641
02642 HOST_WIDE_INT
02643 c_common_get_alias_set (tree t)
02644 {
02645 tree u;
02646 PTR *slot;
02647
02648
02649
02650
02651
02652
02653
02654 for (u = t;
02655 TREE_CODE (u) == COMPONENT_REF || TREE_CODE (u) == ARRAY_REF;
02656 u = TREE_OPERAND (u, 0))
02657 if (TREE_CODE (u) == COMPONENT_REF
02658 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u, 0))) == UNION_TYPE)
02659 return 0;
02660
02661
02662 if (!TYPE_P (t))
02663 return -1;
02664
02665
02666
02667 if (t == char_type_node
02668 || t == signed_char_type_node
02669 || t == unsigned_char_type_node)
02670 return 0;
02671
02672
02673 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (t)))
02674 return 0;
02675
02676
02677
02678
02679 if (TREE_CODE (t) == INTEGER_TYPE && TYPE_UNSIGNED (t))
02680 {
02681 tree t1 = c_common_signed_type (t);
02682
02683
02684 if (t1 != t)
02685 return get_alias_set (t1);
02686 }
02687 else if (POINTER_TYPE_P (t))
02688 {
02689 tree t1;
02690
02691
02692
02693
02694
02695
02696
02697
02698
02699
02700
02701
02702
02703
02704
02705
02706
02707
02708
02709
02710
02711
02712
02713
02714 t1 = build_type_no_quals (t);
02715 if (t1 != t)
02716 return get_alias_set (t1);
02717 }
02718
02719
02720
02721
02722
02723
02724
02725
02726 if (c_language != clk_c || flag_isoc99)
02727 return -1;
02728
02729
02730 if (num_in_fnames == 1)
02731 return -1;
02732
02733
02734
02735 if (TREE_CODE (t) == POINTER_TYPE)
02736 {
02737 tree t2;
02738
02739 for (t2 = TREE_TYPE (t);
02740 TREE_CODE (t2) == POINTER_TYPE;
02741 t2 = TREE_TYPE (t2))
02742 ;
02743 if (TREE_CODE (t2) != RECORD_TYPE
02744 && TREE_CODE (t2) != ENUMERAL_TYPE
02745 && TREE_CODE (t2) != QUAL_UNION_TYPE
02746 && TREE_CODE (t2) != UNION_TYPE)
02747 return -1;
02748 if (TYPE_SIZE (t2) == 0)
02749 return -1;
02750 }
02751
02752 if (TREE_CODE (t) != RECORD_TYPE
02753 && TREE_CODE (t) != ENUMERAL_TYPE
02754 && TREE_CODE (t) != QUAL_UNION_TYPE
02755 && TREE_CODE (t) != UNION_TYPE
02756 && TREE_CODE (t) != POINTER_TYPE)
02757 return -1;
02758
02759 if (TYPE_SIZE (t) == 0)
02760 return -1;
02761
02762
02763
02764 if (!type_hash_table)
02765 type_hash_table = htab_create_ggc (1021, c_type_hash,
02766 (htab_eq) lang_hooks.types_compatible_p,
02767 NULL);
02768 slot = htab_find_slot (type_hash_table, t, INSERT);
02769 if (*slot != NULL)
02770 {
02771 TYPE_ALIAS_SET (t) = TYPE_ALIAS_SET ((tree)*slot);
02772 return TYPE_ALIAS_SET ((tree)*slot);
02773 }
02774 else
02775
02776
02777 *slot = t;
02778
02779 return -1;
02780 }
02781
02782
02783
02784
02785
02786 tree
02787 c_sizeof_or_alignof_type (tree type, enum tree_code op, int complain)
02788 {
02789 const char *op_name;
02790 tree value = NULL;
02791 enum tree_code type_code = TREE_CODE (type);
02792
02793 gcc_assert (op == SIZEOF_EXPR || op == ALIGNOF_EXPR);
02794 op_name = op == SIZEOF_EXPR ? "sizeof" : "__alignof__";
02795
02796 if (type_code == FUNCTION_TYPE)
02797 {
02798 if (op == SIZEOF_EXPR)
02799 {
02800 if (complain && (pedantic || warn_pointer_arith))
02801 pedwarn ("invalid application of %<sizeof%> to a function type");
02802 value = size_one_node;
02803 }
02804 else
02805 value = size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
02806 }
02807 else if (type_code == VOID_TYPE || type_code == ERROR_MARK)
02808 {
02809 if (type_code == VOID_TYPE
02810 && complain && (pedantic || warn_pointer_arith))
02811 pedwarn ("invalid application of %qs to a void type", op_name);
02812 value = size_one_node;
02813 }
02814 else if (!COMPLETE_TYPE_P (type))
02815 {
02816 if (complain)
02817 error ("invalid application of %qs to incomplete type %qT ",
02818 op_name, type);
02819 value = size_zero_node;
02820 }
02821 else
02822 {
02823 if (op == (enum tree_code) SIZEOF_EXPR)
02824
02825 value = size_binop (CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
02826 size_int (TYPE_PRECISION (char_type_node)
02827 / BITS_PER_UNIT));
02828 else
02829 value = size_int (TYPE_ALIGN_UNIT (type));
02830 }
02831
02832
02833
02834
02835
02836 value = fold (build1 (NOP_EXPR, size_type_node, value));
02837 gcc_assert (!TYPE_IS_SIZETYPE (TREE_TYPE (value)));
02838
02839 return value;
02840 }
02841
02842
02843
02844
02845
02846
02847 tree
02848 c_alignof_expr (tree expr)
02849 {
02850 tree t;
02851
02852 if (TREE_CODE (expr) == VAR_DECL)
02853 t = size_int (DECL_ALIGN_UNIT (expr));
02854
02855 else if (TREE_CODE (expr) == COMPONENT_REF
02856 && DECL_C_BIT_FIELD (TREE_OPERAND (expr, 1)))
02857 {
02858 error ("%<__alignof%> applied to a bit-field");
02859 t = size_one_node;
02860 }
02861 else if (TREE_CODE (expr) == COMPONENT_REF
02862 && TREE_CODE (TREE_OPERAND (expr, 1)) == FIELD_DECL)
02863 t = size_int (DECL_ALIGN_UNIT (TREE_OPERAND (expr, 1)));
02864
02865 else if (TREE_CODE (expr) == INDIRECT_REF)
02866 {
02867 tree t = TREE_OPERAND (expr, 0);
02868 tree best = t;
02869 int bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
02870
02871 while (TREE_CODE (t) == NOP_EXPR
02872 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
02873 {
02874 int thisalign;
02875
02876 t = TREE_OPERAND (t, 0);
02877 thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
02878 if (thisalign > bestalign)
02879 best = t, bestalign = thisalign;
02880 }
02881 return c_alignof (TREE_TYPE (TREE_TYPE (best)));
02882 }
02883 else
02884 return c_alignof (TREE_TYPE (expr));
02885
02886 return fold (build1 (NOP_EXPR, size_type_node, t));
02887 }
02888
02889
02890
02891 enum built_in_attribute
02892 {
02893 #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
02894 #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
02895 #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
02896 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
02897 #include "builtin-attrs.def"
02898 #undef DEF_ATTR_NULL_TREE
02899 #undef DEF_ATTR_INT
02900 #undef DEF_ATTR_IDENT
02901 #undef DEF_ATTR_TREE_LIST
02902 ATTR_LAST
02903 };
02904
02905 static GTY(()) tree built_in_attributes[(int) ATTR_LAST];
02906
02907 static void c_init_attributes (void);
02908
02909
02910
02911
02912 void
02913 c_common_nodes_and_builtins (void)
02914 {
02915 enum builtin_type
02916 {
02917 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
02918 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
02919 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
02920 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
02921 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
02922 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
02923 #ifdef TARG_SL
02924 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
02925 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) NAME,
02926 #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) NAME,
02927 #define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8) NAME,
02928 #define DEF_FUNCTION_TYPE_9(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8, ARG9) NAME,
02929 #endif
02930 #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
02931 #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
02932 #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
02933 #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
02934 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
02935 #include "builtin-types.def"
02936 #undef DEF_PRIMITIVE_TYPE
02937 #undef DEF_FUNCTION_TYPE_0
02938 #undef DEF_FUNCTION_TYPE_1
02939 #undef DEF_FUNCTION_TYPE_2
02940 #undef DEF_FUNCTION_TYPE_3
02941 #undef DEF_FUNCTION_TYPE_4
02942 #ifdef TARG_SL
02943 #undef DEF_FUNCTION_TYPE_5
02944 #undef DEF_FUNCTION_TYPE_6
02945 #undef DEF_FUNCTION_TYPE_7
02946 #undef DEF_FUNCTION_TYPE_8
02947 #undef DEF_FUNCTION_TYPE_9
02948 #endif
02949 #undef DEF_FUNCTION_TYPE_VAR_0
02950 #undef DEF_FUNCTION_TYPE_VAR_1
02951 #undef DEF_FUNCTION_TYPE_VAR_2
02952 #undef DEF_FUNCTION_TYPE_VAR_3
02953 #undef DEF_POINTER_TYPE
02954 BT_LAST
02955 };
02956
02957 typedef enum builtin_type builtin_type;
02958
02959 tree builtin_types[(int) BT_LAST + 1];
02960 int wchar_type_size;
02961 tree array_domain_type;
02962 tree va_list_ref_type_node;
02963 tree va_list_arg_type_node;
02964
02965
02966 record_builtin_type (RID_INT, NULL, integer_type_node);
02967 record_builtin_type (RID_CHAR, "char", char_type_node);
02968
02969
02970
02971
02972 if (c_dialect_cxx ())
02973 record_builtin_type (RID_SIGNED, NULL, integer_type_node);
02974 record_builtin_type (RID_LONG, "long int", long_integer_type_node);
02975 record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node);
02976 record_builtin_type (RID_MAX, "long unsigned int",
02977 long_unsigned_type_node);
02978 if (c_dialect_cxx ())
02979 record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node);
02980 record_builtin_type (RID_MAX, "long long int",
02981 long_long_integer_type_node);
02982 record_builtin_type (RID_MAX, "long long unsigned int",
02983 long_long_unsigned_type_node);
02984 if (c_dialect_cxx ())
02985 record_builtin_type (RID_MAX, "long long unsigned",
02986 long_long_unsigned_type_node);
02987 record_builtin_type (RID_SHORT, "short int", short_integer_type_node);
02988 record_builtin_type (RID_MAX, "short unsigned int",
02989 short_unsigned_type_node);
02990 if (c_dialect_cxx ())
02991 record_builtin_type (RID_MAX, "unsigned short",
02992 short_unsigned_type_node);
02993
02994
02995 record_builtin_type (RID_MAX, "signed char", signed_char_type_node);
02996 record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node);
02997
02998
02999
03000 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, NULL_TREE,
03001 intQI_type_node));
03002 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, NULL_TREE,
03003 intHI_type_node));
03004 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, NULL_TREE,
03005 intSI_type_node));
03006 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, NULL_TREE,
03007 intDI_type_node));
03008 #if HOST_BITS_PER_WIDE_INT >= 64
03009 if (targetm.scalar_mode_supported_p (TImode))
03010 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL,
03011 get_identifier ("__int128_t"),
03012 intTI_type_node));
03013 #endif
03014 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, NULL_TREE,
03015 unsigned_intQI_type_node));
03016 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, NULL_TREE,
03017 unsigned_intHI_type_node));
03018 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, NULL_TREE,
03019 unsigned_intSI_type_node));
03020 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, NULL_TREE,
03021 unsigned_intDI_type_node));
03022 #if HOST_BITS_PER_WIDE_INT >= 64
03023 if (targetm.scalar_mode_supported_p (TImode))
03024 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL,
03025 get_identifier ("__uint128_t"),
03026 unsigned_intTI_type_node));
03027 #endif
03028
03029
03030 widest_integer_literal_type_node
03031 = make_signed_type (HOST_BITS_PER_WIDE_INT * 2);
03032 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, NULL_TREE,
03033 widest_integer_literal_type_node));
03034
03035 widest_unsigned_literal_type_node
03036 = make_unsigned_type (HOST_BITS_PER_WIDE_INT * 2);
03037 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, NULL_TREE,
03038 widest_unsigned_literal_type_node));
03039
03040
03041
03042
03043 size_type_node =
03044 TREE_TYPE (identifier_global_value (get_identifier (SIZE_TYPE)));
03045 signed_size_type_node = c_common_signed_type (size_type_node);
03046 set_sizetype (size_type_node);
03047
03048 pid_type_node =
03049 TREE_TYPE (identifier_global_value (get_identifier (PID_TYPE)));
03050
03051 build_common_tree_nodes_2 (flag_short_double);
03052
03053 record_builtin_type (RID_FLOAT, NULL, float_type_node);
03054 record_builtin_type (RID_DOUBLE, NULL, double_type_node);
03055 record_builtin_type (RID_MAX, "long double", long_double_type_node);
03056
03057 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL,
03058 get_identifier ("complex int"),
03059 complex_integer_type_node));
03060 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL,
03061 get_identifier ("complex float"),
03062 complex_float_type_node));
03063 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL,
03064 get_identifier ("complex double"),
03065 complex_double_type_node));
03066 lang_hooks.decls.pushdecl
03067 (build_decl (TYPE_DECL, get_identifier ("complex long double"),
03068 complex_long_double_type_node));
03069
03070 if (c_dialect_cxx ())
03071
03072
03073 fileptr_type_node = build_variant_type_copy (ptr_type_node);
03074
03075 record_builtin_type (RID_VOID, NULL, void_type_node);
03076
03077
03078 void_zero_node = make_node (INTEGER_CST);
03079 TREE_TYPE (void_zero_node) = void_type_node;
03080
03081 void_list_node = build_void_list_node ();
03082
03083
03084
03085
03086
03087
03088 array_domain_type = build_index_type (size_int (200));
03089
03090
03091
03092
03093 char_array_type_node
03094 = build_array_type (char_type_node, array_domain_type);
03095
03096
03097 int_array_type_node
03098 = build_array_type (integer_type_node, array_domain_type);
03099
03100 string_type_node = build_pointer_type (char_type_node);
03101 const_string_type_node
03102 = build_pointer_type (build_qualified_type
03103 (char_type_node, TYPE_QUAL_CONST));
03104
03105
03106 wchar_type_node = get_identifier (MODIFIED_WCHAR_TYPE);
03107 wchar_type_node = TREE_TYPE (identifier_global_value (wchar_type_node));
03108 wchar_type_size = TYPE_PRECISION (wchar_type_node);
03109 if (c_dialect_cxx ())
03110 {
03111 if (TYPE_UNSIGNED (wchar_type_node))
03112 wchar_type_node = make_unsigned_type (wchar_type_size);
03113 else
03114 wchar_type_node = make_signed_type (wchar_type_size);
03115 record_builtin_type (RID_WCHAR, "wchar_t", wchar_type_node);
03116 }
03117 else
03118 {
03119 signed_wchar_type_node = c_common_signed_type (wchar_type_node);
03120 unsigned_wchar_type_node = c_common_unsigned_type (wchar_type_node);
03121 }
03122
03123
03124 wchar_array_type_node
03125 = build_array_type (wchar_type_node, array_domain_type);
03126
03127 wint_type_node =
03128 TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE)));
03129
03130 intmax_type_node =
03131 TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE)));
03132 uintmax_type_node =
03133 TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE)));
03134
03135 default_function_type = build_function_type (integer_type_node, NULL_TREE);
03136 ptrdiff_type_node
03137 = TREE_TYPE (identifier_global_value (get_identifier (PTRDIFF_TYPE)));
03138 unsigned_ptrdiff_type_node = c_common_unsigned_type (ptrdiff_type_node);
03139
03140 lang_hooks.decls.pushdecl
03141 (build_decl (TYPE_DECL, get_identifier ("__builtin_va_list"),
03142 va_list_type_node));
03143
03144 if (TREE_CODE (va_list_type_node) == ARRAY_TYPE)
03145 {
03146 va_list_arg_type_node = va_list_ref_type_node =
03147 build_pointer_type (TREE_TYPE (va_list_type_node));
03148 }
03149 else
03150 {
03151 va_list_arg_type_node = va_list_type_node;
03152 va_list_ref_type_node = build_reference_type (va_list_type_node);
03153 }
03154
03155 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
03156 builtin_types[(int) ENUM] = VALUE;
03157 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
03158 builtin_types[(int) ENUM] \
03159 = build_function_type (builtin_types[(int) RETURN], \
03160 void_list_node);
03161 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
03162 builtin_types[(int) ENUM] \
03163 = build_function_type (builtin_types[(int) RETURN], \
03164 tree_cons (NULL_TREE, \
03165 builtin_types[(int) ARG1], \
03166 void_list_node));
03167 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
03168 builtin_types[(int) ENUM] \
03169 = build_function_type \
03170 (builtin_types[(int) RETURN], \
03171 tree_cons (NULL_TREE, \
03172 builtin_types[(int) ARG1], \
03173 tree_cons (NULL_TREE, \
03174 builtin_types[(int) ARG2], \
03175 void_list_node)));
03176 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
03177 builtin_types[(int) ENUM] \
03178 = build_function_type \
03179 (builtin_types[(int) RETURN], \
03180 tree_cons (NULL_TREE, \
03181 builtin_types[(int) ARG1], \
03182 tree_cons (NULL_TREE, \
03183 builtin_types[(int) ARG2], \
03184 tree_cons (NULL_TREE, \
03185 builtin_types[(int) ARG3], \
03186 void_list_node))));
03187 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
03188 builtin_types[(int) ENUM] \
03189 = build_function_type \
03190 (builtin_types[(int) RETURN], \
03191 tree_cons (NULL_TREE, \
03192 builtin_types[(int) ARG1], \
03193 tree_cons (NULL_TREE, \
03194 builtin_types[(int) ARG2], \
03195 tree_cons \
03196 (NULL_TREE, \
03197 builtin_types[(int) ARG3], \
03198 tree_cons (NULL_TREE, \
03199 builtin_types[(int) ARG4], \
03200 void_list_node)))));
03201 #if defined(TARG_SL)
03202 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
03203 builtin_types[(int) ENUM] \
03204 = build_function_type \
03205 (builtin_types[(int) RETURN], \
03206 tree_cons (NULL_TREE, \
03207 builtin_types[(int) ARG1], \
03208 tree_cons (NULL_TREE, \
03209 builtin_types[(int) ARG2], \
03210 tree_cons \
03211 (NULL_TREE, \
03212 builtin_types[(int) ARG3], \
03213 tree_cons (NULL_TREE, \
03214 builtin_types[(int) ARG4], \
03215 tree_cons(NULL_TREE, \
03216 builtin_types[(int) ARG5], \
03217 void_list_node))))));
03218
03219 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6)\
03220 builtin_types[(int) ENUM] \
03221 = build_function_type \
03222 (builtin_types[(int) RETURN], \
03223 tree_cons (NULL_TREE, \
03224 builtin_types[(int) ARG1], \
03225 tree_cons (NULL_TREE, \
03226 builtin_types[(int) ARG2], \
03227 tree_cons(NULL_TREE, \
03228 builtin_types[(int) ARG3], \
03229 tree_cons (NULL_TREE, \
03230 builtin_types[(int) ARG4], \
03231 tree_cons (NULL_TREE, \
03232 builtin_types[(int) ARG5], \
03233 tree_cons (NULL_TREE, \
03234 builtin_types[(int) ARG6], \
03235 void_list_node)))))));
03236
03237 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7)\
03238 builtin_types[(int) ENUM] \
03239 = build_function_type \
03240 (builtin_types[(int) RETURN], \
03241 tree_cons (NULL_TREE, \
03242 builtin_types[(int) ARG1], \
03243 tree_cons (NULL_TREE, \
03244 builtin_types[(int) ARG2], \
03245 tree_cons(NULL_TREE, \
03246 builtin_types[(int) ARG3], \
03247 tree_cons (NULL_TREE, \
03248 builtin_types[(int) ARG4], \
03249 tree_cons (NULL_TREE, \
03250 builtin_types[(int) ARG5], \
03251 tree_cons (NULL_TREE, \
03252 builtin_types[(int) ARG6], \
03253 tree_cons (NULL_TREE, \
03254 builtin_types[(int) ARG7], \
03255 void_list_node))))))));
03256
03257 #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8)\
03258 builtin_types[(int) ENUM] \
03259 = build_function_type \
03260 (builtin_types[(int) RETURN], \
03261 tree_cons (NULL_TREE, \
03262 builtin_types[(int) ARG1], \
03263 tree_cons (NULL_TREE, \
03264 builtin_types[(int) ARG2], \
03265 tree_cons(NULL_TREE, \
03266 builtin_types[(int) ARG3], \
03267 tree_cons (NULL_TREE, \
03268 builtin_types[(int) ARG4], \
03269 tree_cons (NULL_TREE, \
03270 builtin_types[(int) ARG5], \
03271 tree_cons (NULL_TREE, \
03272 builtin_types[(int) ARG6], \
03273 tree_cons (NULL_TREE, \
03274 builtin_types[(int) ARG7], \
03275 tree_cons (NULL_TREE, \
03276 builtin_types[(int) ARG8], \
03277 void_list_node)))))))));
03278
03279 #define DEF_FUNCTION_TYPE_9(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8, ARG9) \
03280 builtin_types[(int) ENUM] \
03281 = build_function_type \
03282 (builtin_types[(int) RETURN], \
03283 tree_cons (NULL_TREE, \
03284 builtin_types[(int) ARG1], \
03285 tree_cons (NULL_TREE, \
03286 builtin_types[(int) ARG2], \
03287 tree_cons(NULL_TREE, \
03288 builtin_types[(int) ARG3], \
03289 tree_cons (NULL_TREE, \
03290 builtin_types[(int) ARG4], \
03291 tree_cons (NULL_TREE, \
03292 builtin_types[(int) ARG5], \
03293 tree_cons (NULL_TREE, \
03294 builtin_types[(int) ARG6], \
03295 tree_cons (NULL_TREE, \
03296 builtin_types[(int) ARG7], \
03297 tree_cons (NULL_TREE, \
03298 builtin_types[(int) ARG8], \
03299 tree_cons (NULL_TREE, \
03300 builtin_types[(int) ARG9], \
03301 void_list_node))))))))));
03302
03303 #endif
03304
03305 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
03306 builtin_types[(int) ENUM] \
03307 = build_function_type (builtin_types[(int) RETURN], NULL_TREE);
03308 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
03309 builtin_types[(int) ENUM] \
03310 = build_function_type (builtin_types[(int) RETURN], \
03311 tree_cons (NULL_TREE, \
03312 builtin_types[(int) ARG1], \
03313 NULL_TREE));
03314
03315 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
03316 builtin_types[(int) ENUM] \
03317 = build_function_type \
03318 (builtin_types[(int) RETURN], \
03319 tree_cons (NULL_TREE, \
03320 builtin_types[(int) ARG1], \
03321 tree_cons (NULL_TREE, \
03322 builtin_types[(int) ARG2], \
03323 NULL_TREE)));
03324
03325 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
03326 builtin_types[(int) ENUM] \
03327 = build_function_type \
03328 (builtin_types[(int) RETURN], \
03329 tree_cons (NULL_TREE, \
03330 builtin_types[(int) ARG1], \
03331 tree_cons (NULL_TREE, \
03332 builtin_types[(int) ARG2], \
03333 tree_cons (NULL_TREE, \
03334 builtin_types[(int) ARG3], \
03335 NULL_TREE))));
03336
03337 #define DEF_POINTER_TYPE(ENUM, TYPE) \
03338 builtin_types[(int) ENUM] \
03339 = build_pointer_type (builtin_types[(int) TYPE]);
03340 #include "builtin-types.def"
03341 #undef DEF_PRIMITIVE_TYPE
03342 #undef DEF_FUNCTION_TYPE_1
03343 #undef DEF_FUNCTION_TYPE_2
03344 #undef DEF_FUNCTION_TYPE_3
03345 #undef DEF_FUNCTION_TYPE_4
03346 #ifdef TARG_SL
03347 #undef DEF_FUNCTION_TYPE_5
03348 #undef DEF_FUNCTION_TYPE_6
03349 #undef DEF_FUNCTION_TYPE_7
03350 #undef DEF_FUNCTION_TYPE_8
03351 #undef DEF_FUNCTION_TYPE_9
03352 #endif
03353 #undef DEF_FUNCTION_TYPE_VAR_0
03354 #undef DEF_FUNCTION_TYPE_VAR_1
03355 #undef DEF_FUNCTION_TYPE_VAR_2
03356 #undef DEF_FUNCTION_TYPE_VAR_3
03357 #undef DEF_POINTER_TYPE
03358 builtin_types[(int) BT_LAST] = NULL_TREE;
03359
03360 c_init_attributes ();
03361
03362 #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P, \
03363 NONANSI_P, ATTRS, IMPLICIT, COND) \
03364 if (NAME && COND) \
03365 { \
03366 tree decl; \
03367 \
03368 gcc_assert (!strncmp (NAME, "__builtin_", \
03369 strlen ("__builtin_"))); \
03370 \
03371 if (!BOTH_P) \
03372 decl = lang_hooks.builtin_function (NAME, builtin_types[TYPE], \
03373 ENUM, \
03374 CLASS, \
03375 (FALLBACK_P \
03376 ? (NAME + strlen ("__builtin_")) \
03377 : NULL), \
03378 built_in_attributes[(int) ATTRS]); \
03379 else \
03380 decl = builtin_function_2 (NAME, \
03381 NAME + strlen ("__builtin_"), \
03382 builtin_types[TYPE], \
03383 builtin_types[LIBTYPE], \
03384 ENUM, \
03385 CLASS, \
03386 FALLBACK_P, \
03387 NONANSI_P, \
03388 built_in_attributes[(int) ATTRS]); \
03389 \
03390 built_in_decls[(int) ENUM] = decl; \
03391 if (IMPLICIT) \
03392 implicit_built_in_decls[(int) ENUM] = decl; \
03393 }
03394 #include "builtins.def"
03395 #undef DEF_BUILTIN
03396
03397 build_common_builtin_nodes ();
03398
03399 targetm.init_builtins ();
03400 if (flag_mudflap)
03401 mudflap_init ();
03402
03403 main_identifier_node = get_identifier ("main");
03404
03405
03406
03407 null_node = make_node (INTEGER_CST);
03408 TREE_TYPE (null_node) = c_common_type_for_size (POINTER_SIZE, 0);
03409 }
03410
03411
03412
03413
03414
03415 void
03416 set_builtin_user_assembler_name (tree decl, const char *asmspec)
03417 {
03418 tree builtin;
03419 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL
03420 && DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
03421 && asmspec != 0);
03422
03423 builtin = built_in_decls [DECL_FUNCTION_CODE (decl)];
03424 set_user_assembler_name (builtin, asmspec);
03425 if (DECL_FUNCTION_CODE (decl) == BUILT_IN_MEMCPY)
03426 init_block_move_fn (asmspec);
03427 else if (DECL_FUNCTION_CODE (decl) == BUILT_IN_MEMSET)
03428 init_block_clear_fn (asmspec);
03429 }
03430
03431 tree
03432 build_va_arg (tree expr, tree type)
03433 {
03434 return build1 (VA_ARG_EXPR, type, expr);
03435 }
03436
03437
03438
03439
03440 typedef struct disabled_builtin
03441 {
03442 const char *name;
03443 struct disabled_builtin *next;
03444 } disabled_builtin;
03445 static disabled_builtin *disabled_builtins = NULL;
03446
03447 static bool builtin_function_disabled_p (const char *);
03448
03449
03450
03451
03452 void
03453 disable_builtin_function (const char *name)
03454 {
03455 if (strncmp (name, "__builtin_", strlen ("__builtin_")) == 0)
03456 error ("cannot disable built-in function %qs", name);
03457 else
03458 {
03459 disabled_builtin *new_disabled_builtin = XNEW (disabled_builtin);
03460 new_disabled_builtin->name = name;
03461 new_disabled_builtin->next = disabled_builtins;
03462 disabled_builtins = new_disabled_builtin;
03463 }
03464 }
03465
03466
03467
03468
03469
03470 static bool
03471 builtin_function_disabled_p (const char *name)
03472 {
03473 disabled_builtin *p;
03474 for (p = disabled_builtins; p != NULL; p = p->next)
03475 {
03476 if (strcmp (name, p->name) == 0)
03477 return true;
03478 }
03479 return false;
03480 }
03481
03482
03483
03484
03485
03486
03487
03488
03489
03490
03491
03492
03493
03494
03495
03496
03497
03498 static tree
03499 builtin_function_2 (const char *builtin_name, const char *name,
03500 tree builtin_type, tree type,
03501 enum built_in_function function_code,
03502 enum built_in_class cl, int library_name_p,
03503 bool nonansi_p, tree attrs)
03504 {
03505 tree bdecl = NULL_TREE;
03506 tree decl = NULL_TREE;
03507
03508 if (builtin_name != 0)
03509 bdecl = lang_hooks.builtin_function (builtin_name, builtin_type,
03510 function_code, cl,
03511 library_name_p ? name : NULL, attrs);
03512
03513 if (name != 0 && !flag_no_builtin && !builtin_function_disabled_p (name)
03514 && !(nonansi_p && flag_no_nonansi_builtin))
03515 decl = lang_hooks.builtin_function (name, type, function_code, cl,
03516 NULL, attrs);
03517
03518 return (bdecl != 0 ? bdecl : decl);
03519 }
03520
03521
03522
03523
03524 bool
03525 c_promoting_integer_type_p (tree t)
03526 {
03527 switch (TREE_CODE (t))
03528 {
03529 case INTEGER_TYPE:
03530 return (TYPE_MAIN_VARIANT (t) == char_type_node
03531 || TYPE_MAIN_VARIANT (t) == signed_char_type_node
03532 || TYPE_MAIN_VARIANT (t) == unsigned_char_type_node
03533 || TYPE_MAIN_VARIANT (t) == short_integer_type_node
03534 || TYPE_MAIN_VARIANT (t) == short_unsigned_type_node
03535 || TYPE_PRECISION (t) < TYPE_PRECISION (integer_type_node));
03536
03537 case ENUMERAL_TYPE:
03538
03539
03540
03541 return TYPE_PRECISION (t) < TYPE_PRECISION (integer_type_node);
03542
03543 case BOOLEAN_TYPE:
03544 return 1;
03545
03546 default:
03547 return 0;
03548 }
03549 }
03550
03551
03552
03553
03554 int
03555 self_promoting_args_p (tree parms)
03556 {
03557 tree t;
03558 for (t = parms; t; t = TREE_CHAIN (t))
03559 {
03560 tree type = TREE_VALUE (t);
03561
03562 if (TREE_CHAIN (t) == 0 && type != void_type_node)
03563 return 0;
03564
03565 if (type == 0)
03566 return 0;
03567
03568 if (TYPE_MAIN_VARIANT (type) == float_type_node)
03569 return 0;
03570
03571 if (c_promoting_integer_type_p (type))
03572 return 0;
03573 }
03574 return 1;
03575 }
03576
03577
03578
03579
03580 tree
03581 strip_array_types (tree type)
03582 {
03583 while (TREE_CODE (type) == ARRAY_TYPE)
03584 type = TREE_TYPE (type);
03585
03586 return type;
03587 }
03588
03589
03590 tree
03591 strip_pointer_operator (tree t)
03592 {
03593 while (POINTER_TYPE_P (t))
03594 t = TREE_TYPE (t);
03595 return t;
03596 }
03597
03598
03599
03600
03601
03602
03603 int
03604 case_compare (splay_tree_key k1, splay_tree_key k2)
03605 {
03606
03607
03608 if (!k1)
03609 return k2 ? -1 : 0;
03610 else if (!k2)
03611 return k1 ? 1 : 0;
03612
03613 return tree_int_cst_compare ((tree) k1, (tree) k2);
03614 }
03615
03616
03617
03618
03619
03620
03621
03622
03623
03624
03625 tree
03626 c_add_case_label (splay_tree cases, tree cond, tree orig_type,
03627 tree low_value, tree high_value)
03628 {
03629 tree type;
03630 tree label;
03631 tree case_label;
03632 splay_tree_node node;
03633
03634
03635 label = create_artificial_label ();
03636
03637
03638
03639 if (!cond || cond == error_mark_node)
03640 goto error_out;
03641
03642 if ((low_value && TREE_TYPE (low_value)
03643 && POINTER_TYPE_P (TREE_TYPE (low_value)))
03644 || (high_value && TREE_TYPE (high_value)
03645 && POINTER_TYPE_P (TREE_TYPE (high_value))))
03646 error ("pointers are not permitted as case values");
03647
03648
03649 if (high_value && pedantic)
03650 pedwarn ("range expressions in switch statements are non-standard");
03651
03652 type = TREE_TYPE (cond);
03653 if (low_value)
03654 {
03655 low_value = check_case_value (low_value);
03656 low_value = convert_and_check (type, low_value);
03657 }
03658 if (high_value)
03659 {
03660 high_value = check_case_value (high_value);
03661 high_value = convert_and_check (type, high_value);
03662 }
03663
03664
03665 if (low_value == error_mark_node || high_value == error_mark_node)
03666 goto error_out;
03667
03668
03669
03670
03671 if (tree_int_cst_equal (low_value, high_value))
03672 high_value = NULL_TREE;
03673 if (low_value && high_value
03674 && !tree_int_cst_lt (low_value, high_value))
03675 warning ("empty range specified");
03676
03677
03678
03679
03680 if (low_value
03681 && !check_case_bounds (type, orig_type,
03682 &low_value, high_value ? &high_value : NULL))
03683 return NULL_TREE;
03684
03685
03686
03687 node = splay_tree_lookup (cases, (splay_tree_key) low_value);
03688
03689
03690
03691 if (!node && (low_value || high_value))
03692 {
03693 splay_tree_node low_bound;
03694 splay_tree_node high_bound;
03695
03696
03697
03698
03699
03700
03701
03702
03703 low_bound = splay_tree_predecessor (cases,
03704 (splay_tree_key) low_value);
03705 high_bound = splay_tree_successor (cases,
03706 (splay_tree_key) low_value);
03707
03708
03709
03710
03711 if (low_bound
03712 && CASE_HIGH ((tree) low_bound->value)
03713 && tree_int_cst_compare (CASE_HIGH ((tree) low_bound->value),
03714 low_value) >= 0)
03715 node = low_bound;
03716
03717
03718
03719
03720 else if (high_bound
03721 && high_value
03722 && (tree_int_cst_compare ((tree) high_bound->key,
03723 high_value)
03724 <= 0))
03725 node = high_bound;
03726 }
03727
03728 if (node)
03729 {
03730 tree duplicate = CASE_LABEL ((tree) node->value);
03731
03732 if (high_value)
03733 {
03734 error ("duplicate (or overlapping) case value");
03735 error ("%Jthis is the first entry overlapping that value", duplicate);
03736 }
03737 else if (low_value)
03738 {
03739 error ("duplicate case value") ;
03740 error ("%Jpreviously used here", duplicate);
03741 }
03742 else
03743 {
03744 error ("multiple default labels in one switch");
03745 error ("%Jthis is the first default label", duplicate);
03746 }
03747 goto error_out;
03748 }
03749
03750
03751 case_label = add_stmt (build_case_label (low_value, high_value, label));
03752
03753 splay_tree_insert (cases,
03754 (splay_tree_key) low_value,
03755 (splay_tree_value) case_label);
03756
03757 return case_label;
03758
03759 error_out:
03760
03761
03762
03763 if (!cases->root)
03764 {
03765 tree t = create_artificial_label ();
03766 add_stmt (build_stmt (LABEL_EXPR, t));
03767 }
03768 return error_mark_node;
03769 }
03770
03771
03772
03773
03774 static void
03775 match_case_to_enum_1 (tree key, tree type, tree label)
03776 {
03777 char buf[2 + 2*HOST_BITS_PER_WIDE_INT/4 + 1];
03778
03779
03780
03781 if (TREE_INT_CST_HIGH (key) == 0)
03782 snprintf (buf, sizeof (buf), HOST_WIDE_INT_PRINT_UNSIGNED,
03783 TREE_INT_CST_LOW (key));
03784 else if (!TYPE_UNSIGNED (type)
03785 && TREE_INT_CST_HIGH (key) == -1
03786 && TREE_INT_CST_LOW (key) != 0)
03787 snprintf (buf, sizeof (buf), "-" HOST_WIDE_INT_PRINT_UNSIGNED,
03788 -TREE_INT_CST_LOW (key));
03789 else
03790 snprintf (buf, sizeof (buf), HOST_WIDE_INT_PRINT_DOUBLE_HEX,
03791 TREE_INT_CST_HIGH (key), TREE_INT_CST_LOW (key));
03792
03793 if (TYPE_NAME (type) == 0)
03794 warning ("%Jcase value %qs not in enumerated type",
03795 CASE_LABEL (label), buf);
03796 else
03797 warning ("%Jcase value %qs not in enumerated type %qT",
03798 CASE_LABEL (label), buf, type);
03799 }
03800
03801 static int
03802 match_case_to_enum (splay_tree_node node, void *data)
03803 {
03804 tree label = (tree) node->value;
03805 tree type = (tree) data;
03806
03807
03808 if (!CASE_LOW (label))
03809 return 0;
03810
03811
03812
03813 if (!TREE_ADDRESSABLE (label))
03814 match_case_to_enum_1 (CASE_LOW (label), type, label);
03815 else
03816 TREE_ADDRESSABLE (label) = 0;
03817
03818
03819
03820
03821 if (CASE_HIGH (label))
03822 {
03823 tree chain, key = CASE_HIGH (label);
03824
03825 for (chain = TYPE_VALUES (type);
03826 chain && !tree_int_cst_equal (key, TREE_VALUE (chain));
03827 chain = TREE_CHAIN (chain))
03828 continue;
03829 if (!chain)
03830 match_case_to_enum_1 (key, type, label);
03831 }
03832
03833 return 0;
03834 }
03835
03836
03837
03838
03839
03840
03841
03842
03843
03844
03845 void
03846 c_do_switch_warnings (splay_tree cases, tree switch_stmt)
03847 {
03848 splay_tree_node default_node;
03849 location_t switch_location;
03850 tree type;
03851
03852 if (!warn_switch && !warn_switch_enum && !warn_switch_default)
03853 return;
03854
03855 if (EXPR_HAS_LOCATION (switch_stmt))
03856 switch_location = EXPR_LOCATION (switch_stmt);
03857 else
03858 switch_location = input_location;
03859
03860 type = SWITCH_STMT_TYPE (switch_stmt);
03861
03862 default_node = splay_tree_lookup (cases, (splay_tree_key) NULL);
03863 if (warn_switch_default && !default_node)
03864 warning ("%Hswitch missing default case", &switch_location);
03865
03866
03867
03868
03869
03870 if (((warn_switch && !default_node) || warn_switch_enum)
03871 && type && TREE_CODE (type) == ENUMERAL_TYPE
03872 && TREE_CODE (SWITCH_STMT_COND (switch_stmt)) != INTEGER_CST)
03873 {
03874 tree chain;
03875
03876
03877
03878
03879
03880
03881 for (chain = TYPE_VALUES (type); chain; chain = TREE_CHAIN (chain))
03882 {
03883 splay_tree_node node
03884 = splay_tree_lookup (cases, (splay_tree_key) TREE_VALUE (chain));
03885 if (!node)
03886 {
03887 tree low_value = TREE_VALUE (chain);
03888 splay_tree_node low_bound;
03889 splay_tree_node high_bound;
03890
03891
03892 low_bound = splay_tree_predecessor (cases,
03893 (splay_tree_key) low_value);
03894 high_bound = splay_tree_successor (cases,
03895 (splay_tree_key) low_value);
03896
03897
03898
03899 if (low_bound
03900 && CASE_HIGH ((tree) low_bound->value)
03901 && tree_int_cst_compare (CASE_HIGH ((tree) low_bound->value),
03902 low_value) >= 0)
03903 node = low_bound;
03904
03905 else if (high_bound
03906 && (tree_int_cst_compare ((tree) high_bound->key,
03907 low_value)
03908 <= 0))
03909 node = high_bound;
03910 }
03911 if (node)
03912 {
03913
03914
03915
03916 tree label = (tree) node->value;
03917 TREE_ADDRESSABLE (label) = 1;
03918 }
03919 else
03920 {
03921
03922
03923 warning ("%Henumeration value %qE not handled in switch",
03924 &switch_location, TREE_PURPOSE (chain));
03925 }
03926 }
03927
03928
03929
03930
03931
03932
03933
03934
03935
03936
03937 splay_tree_foreach (cases, match_case_to_enum, type);
03938 }
03939 }
03940
03941
03942
03943
03944 tree
03945 finish_label_address_expr (tree label)
03946 {
03947 tree result;
03948
03949 if (pedantic)
03950 pedwarn ("taking the address of a label is non-standard");
03951
03952 if (label == error_mark_node)
03953 return error_mark_node;
03954
03955 label = lookup_label (label);
03956 if (label == NULL_TREE)
03957 result = null_pointer_node;
03958 else
03959 {
03960 TREE_USED (label) = 1;
03961 result = build1 (ADDR_EXPR, ptr_type_node, label);
03962
03963
03964
03965 }
03966
03967 return result;
03968 }
03969
03970
03971
03972
03973
03974
03975 rtx
03976 c_expand_expr (tree exp, rtx target, enum machine_mode tmode,
03977 int modifier ,
03978 rtx *alt_rtl)
03979 {
03980 switch (TREE_CODE (exp))
03981 {
03982 case COMPOUND_LITERAL_EXPR:
03983 {
03984
03985
03986 tree decl = COMPOUND_LITERAL_EXPR_DECL (exp);
03987 emit_local_var (decl);
03988 return expand_expr_real (decl, target, tmode, modifier, alt_rtl);
03989 }
03990
03991 default:
03992 gcc_unreachable ();
03993 }
03994 }
03995
03996
03997
03998 tree
03999 c_staticp (tree exp)
04000 {
04001 return (TREE_CODE (exp) == COMPOUND_LITERAL_EXPR
04002 && TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (exp))
04003 ? exp : NULL);
04004 }
04005
04006
04007
04008
04009
04010 tree
04011 boolean_increment (enum tree_code code, tree arg)
04012 {
04013 tree val;
04014 tree true_res = boolean_true_node;
04015
04016 arg = stabilize_reference (arg);
04017 switch (code)
04018 {
04019 case PREINCREMENT_EXPR:
04020 val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg, true_res);
04021 break;
04022 case POSTINCREMENT_EXPR:
04023 val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg, true_res);
04024 arg = save_expr (arg);
04025 val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), val, arg);
04026 val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), arg, val);
04027 break;
04028 case PREDECREMENT_EXPR:
04029 val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg,
04030 invert_truthvalue (arg));
04031 break;
04032 case POSTDECREMENT_EXPR:
04033 val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg,
04034 invert_truthvalue (arg));
04035 arg = save_expr (arg);
04036 val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), val, arg);
04037 val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), arg, val);
04038 break;
04039 default:
04040 gcc_unreachable ();
04041 }
04042 TREE_SIDE_EFFECTS (val) = 1;
04043 return val;
04044 }
04045
04046
04047
04048 void
04049 c_stddef_cpp_builtins(void)
04050 {
04051 builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE, 0);
04052 builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE, 0);
04053 builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE, 0);
04054 builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE, 0);
04055 builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE, 0);
04056 builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE, 0);
04057 }
04058
04059 static void
04060 c_init_attributes (void)
04061 {
04062
04063 #define DEF_ATTR_NULL_TREE(ENUM) \
04064 built_in_attributes[(int) ENUM] = NULL_TREE;
04065 #define DEF_ATTR_INT(ENUM, VALUE) \
04066 built_in_attributes[(int) ENUM] = build_int_cst (NULL_TREE, VALUE);
04067 #define DEF_ATTR_IDENT(ENUM, STRING) \
04068 built_in_attributes[(int) ENUM] = get_identifier (STRING);
04069 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
04070 built_in_attributes[(int) ENUM] \
04071 = tree_cons (built_in_attributes[(int) PURPOSE], \
04072 built_in_attributes[(int) VALUE], \
04073 built_in_attributes[(int) CHAIN]);
04074 #include "builtin-attrs.def"
04075 #undef DEF_ATTR_NULL_TREE
04076 #undef DEF_ATTR_INT
04077 #undef DEF_ATTR_IDENT
04078 #undef DEF_ATTR_TREE_LIST
04079 }
04080
04081
04082
04083
04084
04085
04086 static tree
04087 handle_packed_attribute (tree *node, tree name, tree ARG_UNUSED (args),
04088 int flags, bool *no_add_attrs)
04089 {
04090 if (TYPE_P (*node))
04091 {
04092 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
04093 *node = build_variant_type_copy (*node);
04094 TYPE_PACKED (*node) = 1;
04095 if (TYPE_MAIN_VARIANT (*node) == *node)
04096 {
04097
04098
04099
04100
04101
04102
04103
04104 tree probe;
04105
04106 for (probe = *node; probe; probe = TYPE_NEXT_VARIANT (probe))
04107 TYPE_PACKED (probe) = 1;
04108 }
04109
04110 }
04111 else if (TREE_CODE (*node) == FIELD_DECL)
04112 DECL_PACKED (*node) = 1;
04113
04114
04115
04116
04117 else
04118 {
04119 warning ("%qs attribute ignored", IDENTIFIER_POINTER (name));
04120 *no_add_attrs = true;
04121 }
04122
04123 return NULL_TREE;
04124 }
04125
04126
04127
04128
04129 static tree
04130 handle_nocommon_attribute (tree *node, tree name,
04131 tree ARG_UNUSED (args),
04132 int ARG_UNUSED (flags), bool *no_add_attrs)
04133 {
04134 if (TREE_CODE (*node) == VAR_DECL)
04135 DECL_COMMON (*node) = 0;
04136 else
04137 {
04138 warning ("%qs attribute ignored", IDENTIFIER_POINTER (name));
04139 *no_add_attrs = true;
04140 }
04141
04142 return NULL_TREE;
04143 }
04144
04145
04146
04147
04148 static tree
04149 handle_common_attribute (tree *node, tree name, tree ARG_UNUSED (args),
04150 int ARG_UNUSED (flags), bool *no_add_attrs)
04151 {
04152 if (TREE_CODE (*node) == VAR_DECL)
04153 DECL_COMMON (*node) = 1;
04154 else
04155 {
04156 warning ("%qs attribute ignored", IDENTIFIER_POINTER (name));
04157 *no_add_attrs = true;
04158 }
04159
04160 return NULL_TREE;
04161 }
04162
04163
04164
04165
04166 static tree
04167 handle_noreturn_attribute (tree *node, tree name, tree ARG_UNUSED (args),
04168 int ARG_UNUSED (flags), bool *no_add_attrs)
04169 {
04170 tree type = TREE_TYPE (*node);
04171
04172
04173 if (TREE_CODE (*node) == FUNCTION_DECL)
04174 TREE_THIS_VOLATILE (*node) = 1;
04175 else if (TREE_CODE (type) == POINTER_TYPE
04176 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
04177 TREE_TYPE (*node)
04178 = build_pointer_type
04179 (build_type_variant (TREE_TYPE (type),
04180 TYPE_READONLY (TREE_TYPE (type)), 1));
04181 else
04182 {
04183 warning ("%qs attribute ignored", IDENTIFIER_POINTER (name));
04184 *no_add_attrs = true;
04185 }
04186
04187 return NULL_TREE;
04188 }
04189
04190
04191
04192
04193 static tree
04194 handle_noinline_attribute (tree *node, tree name,
04195 tree ARG_UNUSED (args),
04196 int ARG_UNUSED (flags), bool *no_add_attrs)
04197 {
04198 if (TREE_CODE (*node) == FUNCTION_DECL)
04199 DECL_UNINLINABLE (*node) = 1;
04200 else
04201 {
04202 warning ("%qs attribute ignored", IDENTIFIER_POINTER (name));
04203 *no_add_attrs = true;
04204 }
04205
04206 return NULL_TREE;
04207 }
04208
04209
04210
04211
04212 static tree
04213 handle_always_inline_attribute (tree *node, tree name,
04214 tree ARG_UNUSED (args),
04215 int ARG_UNUSED (flags),
04216 bool *no_add_attrs)
04217 {
04218 if (TREE_CODE (*node) == FUNCTION_DECL)
04219 {
04220
04221
04222 }
04223 else
04224 {
04225 warning ("%qs attribute ignored", IDENTIFIER_POINTER (name));
04226 *no_add_attrs = true;
04227 }
04228
04229 return NULL_TREE;
04230 }
04231
04232
04233
04234
04235 static tree
04236 handle_used_attribute (tree *pnode, tree name, tree ARG_UNUSED (args),
04237 int ARG_UNUSED (flags), bool *no_add_attrs)
04238 {
04239 tree node = *pnode;
04240
04241 if (TREE_CODE (node) == FUNCTION_DECL
04242 || (TREE_CODE (node) == VAR_DECL && TREE_STATIC (node)))
04243 {
04244 TREE_USED (node) = 1;
04245 DECL_PRESERVE_P (node) = 1;
04246 }
04247 else
04248 {
04249 warning ("%qs attribute ignored", IDENTIFIER_POINTER (name));
04250 *no_add_attrs = true;
04251 }
04252
04253 return NULL_TREE;
04254 }
04255
04256
04257
04258
04259 static tree
04260 handle_unused_attribute (tree *node, tree name, tree ARG_UNUSED (args),
04261 int flags, bool *no_add_attrs)
04262 {
04263 if (DECL_P (*node))
04264 {
04265 tree decl = *node;
04266
04267 if (TREE_CODE (decl) == PARM_DECL
04268 || TREE_CODE (decl) == VAR_DECL
04269 || TREE_CODE (decl) == FUNCTION_DECL
04270 || TREE_CODE (decl) == LABEL_DECL
04271 || TREE_CODE (decl) == TYPE_DECL)
04272 TREE_USED (decl) = 1;
04273 else
04274 {
04275 warning ("%qs attribute ignored", IDENTIFIER_POINTER (name));
04276 *no_add_attrs = true;
04277 }
04278 }
04279 else
04280 {
04281 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
04282 *node = build_variant_type_copy (*node);
04283 TREE_USED (*node) = 1;
04284 }
04285
04286 return NULL_TREE;
04287 }
04288
04289
04290
04291
04292 static tree
04293 handle_const_attribute (tree *node, tree name, tree ARG_UNUSED (args),
04294 int ARG_UNUSED (flags), bool *no_add_attrs)
04295 {
04296 tree type = TREE_TYPE (*node);
04297
04298
04299 if (TREE_CODE (*node) == FUNCTION_DECL)
04300 TREE_READONLY (*node) = 1;
04301 else if (TREE_CODE (type) == POINTER_TYPE
04302 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
04303 TREE_TYPE (*node)
04304 = build_pointer_type
04305 (build_type_variant (TREE_TYPE (type), 1,
04306 TREE_THIS_VOLATILE (TREE_TYPE (type))));
04307 else
04308 {
04309 warning ("%qs attribute ignored", IDENTIFIER_POINTER (name));
04310 *no_add_attrs = true;
04311 }
04312
04313 return NULL_TREE;
04314 }
04315
04316
04317
04318
04319 static tree
04320 handle_transparent_union_attribute (tree *node, tree name,
04321 tree ARG_UNUSED (args), int flags,
04322 bool *no_add_attrs)
04323 {
04324 tree decl = NULL_TREE;
04325 tree *type = NULL;
04326 int is_type = 0;
04327
04328 if (DECL_P (*node))
04329 {
04330 decl = *node;
04331 type = &TREE_TYPE (decl);
04332 is_type = TREE_CODE (*node) == TYPE_DECL;
04333 }
04334 else if (TYPE_P (*node))
04335 type = node, is_type = 1;
04336
04337 if (is_type
04338 && TREE_CODE (*type) == UNION_TYPE
04339 && (decl == 0
04340 || (TYPE_FIELDS (*type) != 0
04341 && TYPE_MODE (*type) == DECL_MODE (TYPE_FIELDS (*type)))))
04342 {
04343 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
04344 *type = build_variant_type_copy (*type);
04345 TYPE_TRANSPARENT_UNION (*type) = 1;
04346 }
04347 else if (decl != 0 && TREE_CODE (decl) == PARM_DECL
04348 && TREE_CODE (*type) == UNION_TYPE
04349 && TYPE_MODE (*type) == DECL_MODE (TYPE_FIELDS (*type)))
04350 DECL_TRANSPARENT_UNION (decl) = 1;
04351 else
04352 {
04353 warning ("%qs attribute ignored", IDENTIFIER_POINTER (name));
04354 *no_add_attrs = true;
04355 }
04356
04357 return NULL_TREE;
04358 }
04359
04360
04361
04362
04363 static tree
04364 handle_constructor_attribute (tree *node, tree name,
04365 tree ARG_UNUSED (args),
04366 int ARG_UNUSED (flags),
04367 bool *no_add_attrs)
04368 {
04369 tree decl = *node;
04370 tree type = TREE_TYPE (decl);
04371
04372 if (TREE_CODE (decl) == FUNCTION_DECL
04373 && TREE_CODE (type) == FUNCTION_TYPE
04374 && decl_function_context (decl) == 0)
04375 {
04376 DECL_STATIC_CONSTRUCTOR (decl) = 1;
04377 TREE_USED (decl) = 1;
04378 }
04379 else
04380 {
04381 warning ("%qs attribute ignored", IDENTIFIER_POINTER (name));
04382 *no_add_attrs = true;
04383 }
04384
04385 return NULL_TREE;
04386 }
04387
04388
04389
04390
04391 static tree
04392 handle_destructor_attribute (tree *node, tree name,
04393 tree ARG_UNUSED (args),
04394 int ARG_UNUSED (flags),
04395 bool *no_add_attrs)
04396 {
04397 tree decl = *node;
04398 tree type = TREE_TYPE (decl);
04399
04400 if (TREE_CODE (decl) == FUNCTION_DECL
04401 && TREE_CODE (type) == FUNCTION_TYPE
04402 && decl_function_context (decl) == 0)
04403 {
04404 DECL_STATIC_DESTRUCTOR (decl) = 1;
04405 TREE_USED (decl) = 1;
04406 }
04407 else
04408 {
04409 warning ("%qs attribute ignored", IDENTIFIER_POINTER (name));
04410 *no_add_attrs = true;
04411 }
04412
04413 return NULL_TREE;
04414 }
04415
04416
04417
04418
04419 static tree
04420 handle_mode_attribute (tree *node, tree name, tree args,
04421 int ARG_UNUSED (flags), bool *no_add_attrs)
04422 {
04423 tree type = *node;
04424
04425 *no_add_attrs = true;
04426
04427 if (TREE_CODE (TREE_VALUE (args)) != IDENTIFIER_NODE)
04428 warning ("%qs attribute ignored", IDENTIFIER_POINTER (name));
04429 else
04430 {
04431 int j;
04432 const char *p = IDENTIFIER_POINTER (TREE_VALUE (args));
04433 int len = strlen (p);
04434 enum machine_mode mode = VOIDmode;
04435 tree typefm;
04436 bool valid_mode;
04437
04438 if (len > 4 && p[0] == '_' && p[1] == '_'
04439 && p[len - 1] == '_' && p[len - 2] == '_')
04440 {
04441 char *newp = (char *) alloca (len - 1);
04442
04443 strcpy (newp, &p[2]);
04444 newp[len - 4] = '\0';
04445 p = newp;
04446 }
04447
04448
04449
04450 if (!strcmp (p, "byte"))
04451 mode = byte_mode;
04452 else if (!strcmp (p, "word"))
04453 mode = word_mode;
04454 else if (!strcmp (p, "pointer"))
04455 mode = ptr_mode;
04456 else
04457 for (j = 0; j < NUM_MACHINE_MODES; j++)
04458 if (!strcmp (p, GET_MODE_NAME (j)))
04459 {
04460 mode = (enum machine_mode) j;
04461 break;
04462 }
04463
04464 if (mode == VOIDmode)
04465 {
04466 error ("unknown machine mode %qs", p);
04467 return NULL_TREE;
04468 }
04469
04470 valid_mode = false;
04471 switch (GET_MODE_CLASS (mode))
04472 {
04473 case MODE_INT:
04474 case MODE_PARTIAL_INT:
04475 case MODE_FLOAT:
04476 valid_mode = targetm.scalar_mode_supported_p (mode);
04477 break;
04478
04479 case MODE_COMPLEX_INT:
04480 case MODE_COMPLEX_FLOAT:
04481 valid_mode = targetm.scalar_mode_supported_p (GET_MODE_INNER (mode));
04482 break;
04483
04484 case MODE_VECTOR_INT:
04485 case MODE_VECTOR_FLOAT:
04486 warning ("specifying vector types with __attribute__ ((mode)) "
04487 "is deprecated");
04488 warning ("use __attribute__ ((vector_size)) instead");
04489 valid_mode = vector_mode_valid_p (mode);
04490 break;
04491
04492 default:
04493 break;
04494 }
04495 if (!valid_mode)
04496 {
04497 error ("unable to emulate %qs", p);
04498 return NULL_TREE;
04499 }
04500
04501 if (POINTER_TYPE_P (type))
04502 {
04503 tree (*fn)(tree, enum machine_mode, bool);
04504
04505 if (!targetm.valid_pointer_mode (mode))
04506 {
04507 error ("invalid pointer mode %qs", p);
04508 return NULL_TREE;
04509 }
04510
04511 if (TREE_CODE (type) == POINTER_TYPE)
04512 fn = build_pointer_type_for_mode;
04513 else
04514 fn = build_reference_type_for_mode;
04515 typefm = fn (TREE_TYPE (type), mode, false);
04516 }
04517 else
04518 typefm = lang_hooks.types.type_for_mode (mode, TYPE_UNSIGNED (type));
04519
04520 if (typefm == NULL_TREE)
04521 {
04522 error ("no data type for mode %qs", p);
04523 return NULL_TREE;
04524 }
04525 else if (TREE_CODE (type) == ENUMERAL_TYPE)
04526 {
04527
04528
04529
04530 if (TREE_CODE (typefm) != INTEGER_TYPE)
04531 {
04532 error ("cannot use mode %qs for enumeral types", p);
04533 return NULL_TREE;
04534 }
04535
04536 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
04537 type = build_variant_type_copy (type);
04538
04539
04540
04541 TYPE_PRECISION (type) = TYPE_PRECISION (typefm);
04542 TYPE_MIN_VALUE (type) = TYPE_MIN_VALUE (typefm);
04543 TYPE_MAX_VALUE (type) = TYPE_MAX_VALUE (typefm);
04544 TYPE_SIZE (type) = TYPE_SIZE (typefm);
04545 TYPE_SIZE_UNIT (type) = TYPE_SIZE_UNIT (typefm);
04546 TYPE_MODE (type) = TYPE_MODE (typefm);
04547 if (!TYPE_USER_ALIGN (type))
04548 TYPE_ALIGN (type) = TYPE_ALIGN (typefm);
04549
04550 typefm = type;
04551 }
04552 else if (VECTOR_MODE_P (mode)
04553 ? TREE_CODE (type) != TREE_CODE (TREE_TYPE (typefm))
04554 : TREE_CODE (type) != TREE_CODE (typefm))
04555 {
04556 error ("mode %qs applied to inappropriate type", p);
04557 return NULL_TREE;
04558 }
04559
04560 *node = typefm;
04561 }
04562
04563 return NULL_TREE;
04564 }
04565
04566
04567
04568
04569 static tree
04570 handle_section_attribute (tree *node, tree ARG_UNUSED (name), tree args,
04571 int ARG_UNUSED (flags), bool *no_add_attrs)
04572 {
04573 tree decl = *node;
04574
04575 if (targetm.have_named_sections)
04576 {
04577 user_defined_section_attribute = true;
04578
04579 if ((TREE_CODE (decl) == FUNCTION_DECL
04580 || TREE_CODE (decl) == VAR_DECL)
04581 && TREE_CODE (TREE_VALUE (args)) == STRING_CST)
04582 {
04583 if (TREE_CODE (decl) == VAR_DECL
04584 && current_function_decl != NULL_TREE
04585 && !TREE_STATIC (decl))
04586 {
04587 error ("%Jsection attribute cannot be specified for "
04588 "local variables", decl);
04589 *no_add_attrs = true;
04590 }
04591
04592
04593
04594 else if (DECL_SECTION_NAME (decl) != NULL_TREE
04595 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)),
04596 TREE_STRING_POINTER (TREE_VALUE (args))) != 0)
04597 {
04598 error ("%Jsection of %qD conflicts with previous declaration",
04599 *node, *node);
04600 *no_add_attrs = true;
04601 }
04602 else
04603 DECL_SECTION_NAME (decl) = TREE_VALUE (args);
04604 }
04605 else
04606 {
04607 error ("%Jsection attribute not allowed for %qD", *node, *node);
04608 *no_add_attrs = true;
04609 }
04610 }
04611 else
04612 {
04613 error ("%Jsection attributes are not supported for this target", *node);
04614 *no_add_attrs = true;
04615 }
04616
04617 return NULL_TREE;
04618 }
04619
04620
04621
04622
04623 static tree
04624 handle_aligned_attribute (tree *node, tree ARG_UNUSED (name), tree args,
04625 int flags, bool *no_add_attrs)
04626 {
04627 tree decl = NULL_TREE;
04628 tree *type = NULL;
04629 int is_type = 0;
04630 tree align_expr = (args ? TREE_VALUE (args)
04631 : size_int (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
04632 int i;
04633
04634 if (DECL_P (*node))
04635 {
04636 decl = *node;
04637 type = &TREE_TYPE (decl);
04638 is_type = TREE_CODE (*node) == TYPE_DECL;
04639 }
04640 else if (TYPE_P (*node))
04641 type = node, is_type = 1;
04642
04643
04644 while (TREE_CODE (align_expr) == NOP_EXPR
04645 || TREE_CODE (align_expr) == CONVERT_EXPR
04646 || TREE_CODE (align_expr) == NON_LVALUE_EXPR)
04647 align_expr = TREE_OPERAND (align_expr, 0);
04648
04649 if (TREE_CODE (align_expr) != INTEGER_CST)
04650 {
04651 error ("requested alignment is not a constant");
04652 *no_add_attrs = true;
04653 }
04654 else if ((i = tree_log2 (align_expr)) == -1)
04655 {
04656 error ("requested alignment is not a power of 2");
04657 *no_add_attrs = true;
04658 }
04659 else if (i > HOST_BITS_PER_INT - 2)
04660 {
04661 error ("requested alignment is too large");
04662 *no_add_attrs = true;
04663 }
04664 else if (is_type)
04665 {
04666
04667
04668 if (decl && TREE_TYPE (decl) != error_mark_node
04669 && DECL_ORIGINAL_TYPE (decl) == NULL_TREE)
04670 {
04671 tree tt = TREE_TYPE (decl);
04672 *type = build_variant_type_copy (*type);
04673 DECL_ORIGINAL_TYPE (decl) = tt;
04674 TYPE_NAME (*type) = decl;
04675 TREE_USED (*type) = TREE_USED (decl);
04676 TREE_TYPE (decl) = *type;
04677 }
04678 else if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
04679 *type = build_variant_type_copy (*type);
04680
04681 TYPE_ALIGN (*type) = (1 << i) * BITS_PER_UNIT;
04682 TYPE_USER_ALIGN (*type) = 1;
04683 }
04684 else if (TREE_CODE (decl) != VAR_DECL
04685 && TREE_CODE (decl) != FIELD_DECL)
04686 {
04687 error ("%Jalignment may not be specified for %qD", decl, decl);
04688 *no_add_attrs = true;
04689 }
04690 else
04691 {
04692 DECL_ALIGN (decl) = (1 << i) * BITS_PER_UNIT;
04693 DECL_USER_ALIGN (decl) = 1;
04694 }
04695
04696 return NULL_TREE;
04697 }
04698
04699
04700
04701
04702 static tree
04703 handle_weak_attribute (tree *node, tree ARG_UNUSED (name),
04704 tree ARG_UNUSED (args),
04705 int ARG_UNUSED (flags),
04706 bool * ARG_UNUSED (no_add_attrs))
04707 {
04708 declare_weak (*node);
04709
04710 return NULL_TREE;
04711 }
04712
04713
04714
04715
04716 static tree
04717 handle_alias_attribute (tree *node, tree name, tree args,
04718 int ARG_UNUSED (flags), bool *no_add_attrs)
04719 {
04720 tree decl = *node;
04721
04722 if ((TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
04723 || (TREE_CODE (decl) != FUNCTION_DECL && !DECL_EXTERNAL (decl)))
04724 {
04725 error ("%J%qD defined both normally and as an alias", decl, decl);
04726 *no_add_attrs = true;
04727 }
04728
04729
04730
04731
04732
04733
04734 else if (decl_function_context (decl) == 0 && current_function_decl == NULL)
04735 {
04736 tree id;
04737
04738 id = TREE_VALUE (args);
04739 if (TREE_CODE (id) != STRING_CST)
04740 {
04741 error ("alias argument not a string");
04742 *no_add_attrs = true;
04743 return NULL_TREE;
04744 }
04745 id = get_identifier (TREE_STRING_POINTER (id));
04746
04747 TREE_USED (id) = 1;
04748
04749 if (TREE_CODE (decl) == FUNCTION_DECL)
04750 DECL_INITIAL (decl) = error_mark_node;
04751 else
04752 {
04753 DECL_EXTERNAL (decl) = 0;
04754 TREE_STATIC (decl) = 1;
04755 }
04756 }
04757 else
04758 {
04759 warning ("%qs attribute ignored", IDENTIFIER_POINTER (name));
04760 *no_add_attrs = true;
04761 }
04762
04763 return NULL_TREE;
04764 }
04765
04766
04767
04768
04769 static tree
04770 handle_visibility_attribute (tree *node, tree name, tree args,
04771 int ARG_UNUSED (flags),
04772 bool *no_add_attrs)
04773 {
04774 tree decl = *node;
04775 tree id = TREE_VALUE (args);
04776
04777 *no_add_attrs = true;
04778
04779 if (TYPE_P (*node))
04780 {
04781 if (TREE_CODE (*node) != RECORD_TYPE && TREE_CODE (*node) != UNION_TYPE)
04782 {
04783 warning ("%qs attribute ignored on non-class types",
04784 IDENTIFIER_POINTER (name));
04785 return NULL_TREE;
04786 }
04787 }
04788 else if (decl_function_context (decl) != 0 || !TREE_PUBLIC (decl))
04789 {
04790 warning ("%qs attribute ignored", IDENTIFIER_POINTER (name));
04791 return NULL_TREE;
04792 }
04793
04794 if (TREE_CODE (id) != STRING_CST)
04795 {
04796 error ("visibility argument not a string");
04797 return NULL_TREE;
04798 }
04799
04800
04801 if (TYPE_P (decl))
04802 {
04803 decl = TYPE_NAME (decl);
04804 if (!decl)
04805 return NULL_TREE;
04806 if (TREE_CODE (decl) == IDENTIFIER_NODE)
04807 {
04808 warning ("%qE attribute ignored on types",
04809 name);
04810 return NULL_TREE;
04811 }
04812 }
04813
04814 if (strcmp (TREE_STRING_POINTER (id), "default") == 0)
04815 DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
04816 else if (strcmp (TREE_STRING_POINTER (id), "internal") == 0)
04817 DECL_VISIBILITY (decl) = VISIBILITY_INTERNAL;
04818 else if (strcmp (TREE_STRING_POINTER (id), "hidden") == 0)
04819 DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
04820 else if (strcmp (TREE_STRING_POINTER (id), "protected") == 0)
04821 DECL_VISIBILITY (decl) = VISIBILITY_PROTECTED;
04822 else
04823 error ("visibility argument must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
04824 DECL_VISIBILITY_SPECIFIED (decl) = 1;
04825
04826
04827
04828
04829
04830 if (DECL_P (*node))
04831 *no_add_attrs = false;
04832
04833 return NULL_TREE;
04834 }
04835
04836
04837
04838
04839
04840
04841
04842
04843 bool
04844 c_determine_visibility (tree decl)
04845 {
04846 gcc_assert (TREE_CODE (decl) == VAR_DECL
04847 || TREE_CODE (decl) == FUNCTION_DECL);
04848
04849
04850
04851
04852
04853
04854
04855
04856 if (lookup_attribute ("visibility", DECL_ATTRIBUTES (decl)))
04857 return true;
04858
04859
04860 if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
04861 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl)))
04862 {
04863 DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
04864 DECL_VISIBILITY_SPECIFIED (decl) = 1;
04865 return true;
04866 }
04867
04868 return false;
04869 }
04870
04871
04872
04873
04874 static tree
04875 handle_tls_model_attribute (tree *node, tree name, tree args,
04876 int ARG_UNUSED (flags), bool *no_add_attrs)
04877 {
04878 tree decl = *node;
04879
04880 if (!DECL_THREAD_LOCAL (decl))
04881 {
04882 warning ("%qs attribute ignored", IDENTIFIER_POINTER (name));
04883 *no_add_attrs = true;
04884 }
04885 else
04886 {
04887 tree id;
04888
04889 id = TREE_VALUE (args);
04890 if (TREE_CODE (id) != STRING_CST)
04891 {
04892 error ("tls_model argument not a string");
04893 *no_add_attrs = true;
04894 return NULL_TREE;
04895 }
04896 if (strcmp (TREE_STRING_POINTER (id), "local-exec")
04897 && strcmp (TREE_STRING_POINTER (id), "initial-exec")
04898 && strcmp (TREE_STRING_POINTER (id), "local-dynamic")
04899 && strcmp (TREE_STRING_POINTER (id), "global-dynamic"))
04900 {
04901 error ("tls_model argument must be one of \"local-exec\", \"initial-exec\", \"local-dynamic\" or \"global-dynamic\"");
04902 *no_add_attrs = true;
04903 return NULL_TREE;
04904 }
04905 }
04906
04907 return NULL_TREE;
04908 }
04909
04910
04911
04912
04913 static tree
04914 handle_no_instrument_function_attribute (tree *node, tree name,
04915 tree ARG_UNUSED (args),
04916 int ARG_UNUSED (flags),
04917 bool *no_add_attrs)
04918 {
04919 tree decl = *node;
04920
04921 if (TREE_CODE (decl) != FUNCTION_DECL)
04922 {
04923 error ("%J%qE attribute applies only to functions", decl, name);
04924 *no_add_attrs = true;
04925 }
04926 else if (DECL_INITIAL (decl))
04927 {
04928 error ("%Jcan%'t set %qE attribute after definition", decl, name);
04929 *no_add_attrs = true;
04930 }
04931 else
04932 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl) = 1;
04933
04934 return NULL_TREE;
04935 }
04936
04937
04938
04939
04940 static tree
04941 handle_malloc_attribute (tree *node, tree name, tree ARG_UNUSED (args),
04942 int ARG_UNUSED (flags), bool *no_add_attrs)
04943 {
04944 if (TREE_CODE (*node) == FUNCTION_DECL)
04945 DECL_IS_MALLOC (*node) = 1;
04946
04947 else
04948 {
04949 warning ("%qs attribute ignored", IDENTIFIER_POINTER (name));
04950 *no_add_attrs = true;
04951 }
04952
04953 return NULL_TREE;
04954 }
04955
04956
04957
04958
04959 static tree
04960 handle_no_limit_stack_attribute (tree *node, tree name,
04961 tree ARG_UNUSED (args),
04962 int ARG_UNUSED (flags),
04963 bool *no_add_attrs)
04964 {
04965 tree decl = *node;
04966
04967 if (TREE_CODE (decl) != FUNCTION_DECL)
04968 {
04969 error ("%J%qE attribute applies only to functions", decl, name);
04970 *no_add_attrs = true;
04971 }
04972 else if (DECL_INITIAL (decl))
04973 {
04974 error ("%Jcan%'t set %qE attribute after definition", decl, name);
04975 *no_add_attrs = true;
04976 }
04977 else
04978 DECL_NO_LIMIT_STACK (decl) = 1;
04979
04980 return NULL_TREE;
04981 }
04982
04983
04984
04985
04986 static tree
04987 handle_pure_attribute (tree *node, tree name, tree ARG_UNUSED (args),
04988 int ARG_UNUSED (flags), bool *no_add_attrs)
04989 {
04990 if (TREE_CODE (*node) == FUNCTION_DECL)
04991 DECL_IS_PURE (*node) = 1;
04992
04993 else
04994 {
04995 warning ("%qs attribute ignored", IDENTIFIER_POINTER (name));
04996 *no_add_attrs = true;
04997 }
04998
04999 return NULL_TREE;
05000 }
05001
05002
05003
05004
05005 static tree
05006 handle_deprecated_attribute (tree *node, tree name,
05007 tree ARG_UNUSED (args), int flags,
05008 bool *no_add_attrs)
05009 {
05010 tree type = NULL_TREE;
05011 int warn = 0;
05012 const char *what = NULL;
05013
05014 if (DECL_P (*node))
05015 {
05016 tree decl = *node;
05017 type = TREE_TYPE (decl);
05018
05019 if (TREE_CODE (decl) == TYPE_DECL
05020 || TREE_CODE (decl) == PARM_DECL
05021 || TREE_CODE (decl) == VAR_DECL
05022 || TREE_CODE (decl) == FUNCTION_DECL
05023 || TREE_CODE (decl) == FIELD_DECL)
05024 TREE_DEPRECATED (decl) = 1;
05025 else
05026 warn = 1;
05027 }
05028 else if (TYPE_P (*node))
05029 {
05030 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
05031 *node = build_variant_type_copy (*node);
05032 TREE_DEPRECATED (*node) = 1;
05033 type = *node;
05034 }
05035 else
05036 warn = 1;
05037
05038 if (warn)
05039 {
05040 *no_add_attrs = true;
05041 if (type && TYPE_NAME (type))
05042 {
05043 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
05044 what = IDENTIFIER_POINTER (TYPE_NAME (*node));
05045 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
05046 && DECL_NAME (TYPE_NAME (type)))
05047 what = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
05048 }
05049 if (what)
05050 warning ("%qs attribute ignored for %qs",
05051 IDENTIFIER_POINTER (name), what);
05052 else
05053 warning ("%qs attribute ignored",
05054 IDENTIFIER_POINTER (name));
05055 }
05056
05057 return NULL_TREE;
05058 }
05059
05060
05061
05062
05063 static tree
05064 handle_vector_size_attribute (tree *node, tree name, tree args,
05065 int ARG_UNUSED (flags),
05066 bool *no_add_attrs)
05067 {
05068 unsigned HOST_WIDE_INT vecsize, nunits;
05069 enum machine_mode orig_mode;
05070 tree type = *node, new_type, size;
05071
05072 *no_add_attrs = true;
05073
05074
05075
05076 size = TREE_VALUE (args);
05077 if (TREE_CODE (size) == NON_LVALUE_EXPR)
05078 size = TREE_OPERAND (size, 0);
05079
05080 if (!host_integerp (size, 1))
05081 {
05082 warning ("%qs attribute ignored", IDENTIFIER_POINTER (name));
05083 return NULL_TREE;
05084 }
05085
05086
05087 vecsize = tree_low_cst (size, 1);
05088
05089
05090
05091
05092
05093
05094
05095
05096
05097 while (POINTER_TYPE_P (type)
05098 || TREE_CODE (type) == FUNCTION_TYPE
05099 || TREE_CODE (type) == METHOD_TYPE
05100 || TREE_CODE (type) == ARRAY_TYPE)
05101 type = TREE_TYPE (type);
05102
05103
05104 orig_mode = TYPE_MODE (type);
05105
05106 if (TREE_CODE (type) == RECORD_TYPE
05107 || (GET_MODE_CLASS (orig_mode) != MODE_FLOAT
05108 && GET_MODE_CLASS (orig_mode) != MODE_INT)
05109 || !host_integerp (TYPE_SIZE_UNIT (type), 1))
05110 {
05111 error ("invalid vector type for attribute %qs",
05112 IDENTIFIER_POINTER (name));
05113 return NULL_TREE;
05114 }
05115
05116
05117 nunits = vecsize / tree_low_cst (TYPE_SIZE_UNIT (type), 1);
05118 if (nunits & (nunits - 1))
05119 {
05120 error ("number of components of the vector not a power of two");
05121 return NULL_TREE;
05122 }
05123
05124 new_type = build_vector_type (type, nunits);
05125
05126
05127 *node = reconstruct_complex_type (*node, new_type);
05128
05129 return NULL_TREE;
05130 }
05131
05132
05133 static tree
05134 handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name),
05135 tree args, int ARG_UNUSED (flags),
05136 bool *no_add_attrs)
05137 {
05138 tree type = *node;
05139 unsigned HOST_WIDE_INT attr_arg_num;
05140
05141
05142
05143
05144 if (!args)
05145 {
05146 if (!TYPE_ARG_TYPES (type))
05147 {
05148 error ("nonnull attribute without arguments on a non-prototype");
05149 *no_add_attrs = true;
05150 }
05151 return NULL_TREE;
05152 }
05153
05154
05155
05156 for (attr_arg_num = 1; args; args = TREE_CHAIN (args))
05157 {
05158 tree argument;
05159 unsigned HOST_WIDE_INT arg_num = 0, ck_num;
05160
05161 if (!get_nonnull_operand (TREE_VALUE (args), &arg_num))
05162 {
05163 error ("nonnull argument has invalid operand number (argument %lu)",
05164 (unsigned long) attr_arg_num);
05165 *no_add_attrs = true;
05166 return NULL_TREE;
05167 }
05168
05169 argument = TYPE_ARG_TYPES (type);
05170 if (argument)
05171 {
05172 for (ck_num = 1; ; ck_num++)
05173 {
05174 if (!argument || ck_num == arg_num)
05175 break;
05176 argument = TREE_CHAIN (argument);
05177 }
05178
05179 if (!argument
05180 || TREE_CODE (TREE_VALUE (argument)) == VOID_TYPE)
05181 {
05182 error ("nonnull argument with out-of-range operand number (argument %lu, operand %lu)",
05183 (unsigned long) attr_arg_num, (unsigned long) arg_num);
05184 *no_add_attrs = true;
05185 return NULL_TREE;
05186 }
05187
05188 if (TREE_CODE (TREE_VALUE (argument)) != POINTER_TYPE)
05189 {
05190 error ("nonnull argument references non-pointer operand (argument %lu, operand %lu)",
05191 (unsigned long) attr_arg_num, (unsigned long) arg_num);
05192 *no_add_attrs = true;
05193 return NULL_TREE;
05194 }
05195 }
05196 }
05197
05198 return NULL_TREE;
05199 }
05200
05201
05202
05203
05204 static void
05205 check_function_nonnull (tree attrs, tree params)
05206 {
05207 tree a, args, param;
05208 int param_num;
05209
05210 for (a = attrs; a; a = TREE_CHAIN (a))
05211 {
05212 if (is_attribute_p ("nonnull", TREE_PURPOSE (a)))
05213 {
05214 args = TREE_VALUE (a);
05215
05216
05217
05218
05219
05220 for (param = params, param_num = 1; ;
05221 param_num++, param = TREE_CHAIN (param))
05222 {
05223 if (!param)
05224 break;
05225 if (!args || nonnull_check_p (args, param_num))
05226 check_function_arguments_recurse (check_nonnull_arg, NULL,
05227 TREE_VALUE (param),
05228 param_num);
05229 }
05230 }
05231 }
05232 }
05233
05234
05235
05236
05237 static void
05238 check_function_sentinel (tree attrs, tree params, tree typelist)
05239 {
05240 tree attr = lookup_attribute ("sentinel", attrs);
05241
05242 if (attr)
05243 {
05244
05245 while (typelist && params)
05246 {
05247 typelist = TREE_CHAIN (typelist);
05248 params = TREE_CHAIN (params);
05249 }
05250
05251 if (typelist || !params)
05252 warning ("not enough variable arguments to fit a sentinel");
05253 else
05254 {
05255 tree sentinel, end;
05256 unsigned pos = 0;
05257
05258 if (TREE_VALUE (attr))
05259 {
05260 tree p = TREE_VALUE (TREE_VALUE (attr));
05261 STRIP_NOPS (p);
05262 pos = TREE_INT_CST_LOW (p);
05263 }
05264
05265 sentinel = end = params;
05266
05267
05268 while (pos > 0 && TREE_CHAIN (end))
05269 {
05270 pos--;
05271 end = TREE_CHAIN (end);
05272 }
05273 if (pos > 0)
05274 {
05275 warning ("not enough variable arguments to fit a sentinel");
05276 return;
05277 }
05278
05279
05280 while (TREE_CHAIN (end))
05281 {
05282 end = TREE_CHAIN (end);
05283 sentinel = TREE_CHAIN (sentinel);
05284 }
05285
05286
05287 if ((!POINTER_TYPE_P (TREE_TYPE (TREE_VALUE (sentinel)))
05288 || !integer_zerop (TREE_VALUE (sentinel)))
05289
05290
05291
05292
05293
05294 && (warn_strict_null_sentinel
05295 || null_node != TREE_VALUE (sentinel)))
05296 warning ("missing sentinel in function call");
05297 }
05298 }
05299 }
05300
05301
05302
05303
05304
05305 static bool
05306 nonnull_check_p (tree args, unsigned HOST_WIDE_INT param_num)
05307 {
05308 unsigned HOST_WIDE_INT arg_num = 0;
05309
05310 for (; args; args = TREE_CHAIN (args))
05311 {
05312 bool found = get_nonnull_operand (TREE_VALUE (args), &arg_num);
05313
05314 gcc_assert (found);
05315
05316 if (arg_num == param_num)
05317 return true;
05318 }
05319 return false;
05320 }
05321
05322
05323
05324
05325
05326 static void
05327 check_nonnull_arg (void * ARG_UNUSED (ctx), tree param,
05328 unsigned HOST_WIDE_INT param_num)
05329 {
05330
05331
05332
05333
05334 if (TREE_CODE (TREE_TYPE (param)) != POINTER_TYPE)
05335 return;
05336
05337 if (integer_zerop (param))
05338 warning ("null argument where non-null required (argument %lu)",
05339 (unsigned long) param_num);
05340 }
05341
05342
05343
05344
05345 static bool
05346 get_nonnull_operand (tree arg_num_expr, unsigned HOST_WIDE_INT *valp)
05347 {
05348
05349
05350 while (TREE_CODE (arg_num_expr) == NOP_EXPR
05351 || TREE_CODE (arg_num_expr) == CONVERT_EXPR
05352 || TREE_CODE (arg_num_expr) == NON_LVALUE_EXPR)
05353 arg_num_expr = TREE_OPERAND (arg_num_expr, 0);
05354
05355 if (TREE_CODE (arg_num_expr) != INTEGER_CST
05356 || TREE_INT_CST_HIGH (arg_num_expr) != 0)
05357 return false;
05358
05359 *valp = TREE_INT_CST_LOW (arg_num_expr);
05360 return true;
05361 }
05362
05363
05364
05365
05366 static tree
05367 handle_nothrow_attribute (tree *node, tree name, tree ARG_UNUSED (args),
05368 int ARG_UNUSED (flags), bool *no_add_attrs)
05369 {
05370 if (TREE_CODE (*node) == FUNCTION_DECL)
05371 TREE_NOTHROW (*node) = 1;
05372
05373 else
05374 {
05375 warning ("%qs attribute ignored", IDENTIFIER_POINTER (name));
05376 *no_add_attrs = true;
05377 }
05378
05379 return NULL_TREE;
05380 }
05381
05382
05383
05384
05385 static tree
05386 handle_cleanup_attribute (tree *node, tree name, tree args,
05387 int ARG_UNUSED (flags), bool *no_add_attrs)
05388 {
05389 tree decl = *node;
05390 tree cleanup_id, cleanup_decl;
05391
05392
05393
05394
05395
05396 if (TREE_CODE (decl) != VAR_DECL || TREE_STATIC (decl))
05397 {
05398 warning ("%qs attribute ignored", IDENTIFIER_POINTER (name));
05399 *no_add_attrs = true;
05400 return NULL_TREE;
05401 }
05402
05403
05404
05405
05406 cleanup_id = TREE_VALUE (args);
05407 if (TREE_CODE (cleanup_id) != IDENTIFIER_NODE)
05408 {
05409 error ("cleanup argument not an identifier");
05410 *no_add_attrs = true;
05411 return NULL_TREE;
05412 }
05413 cleanup_decl = lookup_name (cleanup_id);
05414 if (!cleanup_decl || TREE_CODE (cleanup_decl) != FUNCTION_DECL)
05415 {
05416 error ("cleanup argument not a function");
05417 *no_add_attrs = true;
05418 return NULL_TREE;
05419 }
05420
05421
05422
05423
05424 return NULL_TREE;
05425 }
05426
05427
05428
05429 static tree
05430 handle_warn_unused_result_attribute (tree *node, tree name,
05431 tree ARG_UNUSED (args),
05432 int ARG_UNUSED (flags), bool *no_add_attrs)
05433 {
05434
05435 if (VOID_TYPE_P (TREE_TYPE (*node)))
05436 {
05437 warning ("%qs attribute ignored", IDENTIFIER_POINTER (name));
05438 *no_add_attrs = true;
05439 }
05440
05441 return NULL_TREE;
05442 }
05443
05444
05445
05446 static tree
05447 handle_sentinel_attribute (tree *node, tree name, tree args,
05448 int ARG_UNUSED (flags), bool *no_add_attrs)
05449 {
05450 tree params = TYPE_ARG_TYPES (*node);
05451
05452 if (!params)
05453 {
05454 warning ("%qs attribute requires prototypes with named arguments",
05455 IDENTIFIER_POINTER (name));
05456 *no_add_attrs = true;
05457 }
05458 else
05459 {
05460 while (TREE_CHAIN (params))
05461 params = TREE_CHAIN (params);
05462
05463 if (VOID_TYPE_P (TREE_VALUE (params)))
05464 {
05465 warning ("%qs attribute only applies to variadic functions",
05466 IDENTIFIER_POINTER (name));
05467 *no_add_attrs = true;
05468 }
05469 }
05470
05471 if (args)
05472 {
05473 tree position = TREE_VALUE (args);
05474
05475 STRIP_NOPS (position);
05476 if (TREE_CODE (position) != INTEGER_CST)
05477 {
05478 warning ("requested position is not an integer constant");
05479 *no_add_attrs = true;
05480 }
05481 else
05482 {
05483 if (tree_int_cst_lt (position, integer_zero_node))
05484 {
05485 warning ("requested position is less than zero");
05486 *no_add_attrs = true;
05487 }
05488 }
05489 }
05490
05491 return NULL_TREE;
05492 }
05493
05494
05495 void
05496 check_function_arguments (tree attrs, tree params, tree typelist)
05497 {
05498
05499
05500
05501 if (warn_nonnull)
05502 check_function_nonnull (attrs, params);
05503
05504
05505
05506 if (warn_format)
05507 {
05508 check_function_format (attrs, params);
05509 check_function_sentinel (attrs, params, typelist);
05510 }
05511 }
05512
05513
05514
05515
05516 void
05517 check_function_arguments_recurse (void (*callback)
05518 (void *, tree, unsigned HOST_WIDE_INT),
05519 void *ctx, tree param,
05520 unsigned HOST_WIDE_INT param_num)
05521 {
05522 if (TREE_CODE (param) == NOP_EXPR)
05523 {
05524
05525 check_function_arguments_recurse (callback, ctx,
05526 TREE_OPERAND (param, 0), param_num);
05527 return;
05528 }
05529
05530 if (TREE_CODE (param) == CALL_EXPR)
05531 {
05532 tree type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (param, 0)));
05533 tree attrs;
05534 bool found_format_arg = false;
05535
05536
05537
05538
05539
05540 for (attrs = TYPE_ATTRIBUTES (type);
05541 attrs;
05542 attrs = TREE_CHAIN (attrs))
05543 if (is_attribute_p ("format_arg", TREE_PURPOSE (attrs)))
05544 {
05545 tree inner_args;
05546 tree format_num_expr;
05547 int format_num;
05548 int i;
05549
05550
05551
05552 format_num_expr = TREE_VALUE (TREE_VALUE (attrs));
05553 while (TREE_CODE (format_num_expr) == NOP_EXPR
05554 || TREE_CODE (format_num_expr) == CONVERT_EXPR
05555 || TREE_CODE (format_num_expr) == NON_LVALUE_EXPR)
05556 format_num_expr = TREE_OPERAND (format_num_expr, 0);
05557
05558 gcc_assert (TREE_CODE (format_num_expr) == INTEGER_CST
05559 && !TREE_INT_CST_HIGH (format_num_expr));
05560
05561 format_num = TREE_INT_CST_LOW (format_num_expr);
05562
05563 for (inner_args = TREE_OPERAND (param, 1), i = 1;
05564 inner_args != 0;
05565 inner_args = TREE_CHAIN (inner_args), i++)
05566 if (i == format_num)
05567 {
05568 check_function_arguments_recurse (callback, ctx,
05569 TREE_VALUE (inner_args),
05570 param_num);
05571 found_format_arg = true;
05572 break;
05573 }
05574 }
05575
05576
05577
05578
05579 if (found_format_arg)
05580 return;
05581 }
05582
05583 if (TREE_CODE (param) == COND_EXPR)
05584 {
05585
05586 check_function_arguments_recurse (callback, ctx,
05587 TREE_OPERAND (param, 1), param_num);
05588 check_function_arguments_recurse (callback, ctx,
05589 TREE_OPERAND (param, 2), param_num);
05590 return;
05591 }
05592
05593 (*callback) (ctx, param, param_num);
05594 }
05595
05596
05597
05598 int
05599 field_decl_cmp (const void *x_p, const void *y_p)
05600 {
05601 const tree *const x = (const tree *const) x_p;
05602 const tree *const y = (const tree *const) y_p;
05603
05604 if (DECL_NAME (*x) == DECL_NAME (*y))
05605
05606 return (TREE_CODE (*y) == TYPE_DECL) - (TREE_CODE (*x) == TYPE_DECL);
05607 if (DECL_NAME (*x) == NULL_TREE)
05608 return -1;
05609 if (DECL_NAME (*y) == NULL_TREE)
05610 return 1;
05611 if (DECL_NAME (*x) < DECL_NAME (*y))
05612 return -1;
05613 return 1;
05614 }
05615
05616 static struct {
05617 gt_pointer_operator new_value;
05618 void *cookie;
05619 } resort_data;
05620
05621
05622
05623
05624 static int
05625 resort_field_decl_cmp (const void *x_p, const void *y_p)
05626 {
05627 const tree *const x = (const tree *const) x_p;
05628 const tree *const y = (const tree *const) y_p;
05629
05630 if (DECL_NAME (*x) == DECL_NAME (*y))
05631
05632 return (TREE_CODE (*y) == TYPE_DECL) - (TREE_CODE (*x) == TYPE_DECL);
05633 if (DECL_NAME (*x) == NULL_TREE)
05634 return -1;
05635 if (DECL_NAME (*y) == NULL_TREE)
05636 return 1;
05637 {
05638 tree d1 = DECL_NAME (*x);
05639 tree d2 = DECL_NAME (*y);
05640 resort_data.new_value (&d1, resort_data.cookie);
05641 resort_data.new_value (&d2, resort_data.cookie);
05642 if (d1 < d2)
05643 return -1;
05644 }
05645 return 1;
05646 }
05647
05648
05649
05650 void
05651 resort_sorted_fields (void *obj,
05652 void * ARG_UNUSED (orig_obj),
05653 gt_pointer_operator new_value,
05654 void *cookie)
05655 {
05656 struct sorted_fields_type *sf = (struct sorted_fields_type *) obj;
05657 resort_data.new_value = new_value;
05658 resort_data.cookie = cookie;
05659 qsort (&sf->elts[0], sf->len, sizeof (tree),
05660 resort_field_decl_cmp);
05661 }
05662
05663
05664
05665
05666
05667
05668
05669
05670 static char *
05671 catenate_strings (const char *lhs, const char *rhs_start, int rhs_size)
05672 {
05673 const int lhs_size = strlen (lhs);
05674 char *result = XNEWVEC (char, lhs_size + rhs_size);
05675 strncpy (result, lhs, lhs_size);
05676 strncpy (result + lhs_size, rhs_start, rhs_size);
05677 return result;
05678 }
05679
05680
05681
05682
05683 void
05684 c_parse_error (const char *gmsgid, enum cpp_ttype token, tree value)
05685 {
05686 #define catenate_messages(M1, M2) catenate_strings ((M1), (M2), sizeof (M2))
05687
05688 char *message = NULL;
05689
05690 if (token == CPP_EOF)
05691 message = catenate_messages (gmsgid, " at end of input");
05692 else if (token == CPP_CHAR || token == CPP_WCHAR)
05693 {
05694 unsigned int val = TREE_INT_CST_LOW (value);
05695 const char *const ell = (token == CPP_CHAR) ? "" : "L";
05696 if (val <= UCHAR_MAX && ISGRAPH (val))
05697 message = catenate_messages (gmsgid, " before %s'%c'");
05698 else
05699 message = catenate_messages (gmsgid, " before %s'\\x%x'");
05700
05701 error (message, ell, val);
05702 free (message);
05703 message = NULL;
05704 }
05705 else if (token == CPP_STRING || token == CPP_WSTRING)
05706 message = catenate_messages (gmsgid, " before string constant");
05707 else if (token == CPP_NUMBER)
05708 message = catenate_messages (gmsgid, " before numeric constant");
05709 else if (token == CPP_NAME)
05710 {
05711 message = catenate_messages (gmsgid, " before %qs");
05712 error (message, IDENTIFIER_POINTER (value));
05713 free (message);
05714 message = NULL;
05715 }
05716 else if (token < N_TTYPES)
05717 {
05718 message = catenate_messages (gmsgid, " before %qs token");
05719 error (message, cpp_type2name (token));
05720 free (message);
05721 message = NULL;
05722 }
05723 else
05724 error (gmsgid);
05725
05726 if (message)
05727 {
05728 error (message);
05729 free (message);
05730 }
05731 #undef catenate_messages
05732 }
05733
05734
05735
05736
05737
05738 void
05739 c_warn_unused_result (tree *top_p)
05740 {
05741 tree t = *top_p;
05742 tree_stmt_iterator i;
05743 tree fdecl, ftype;
05744
05745 switch (TREE_CODE (t))
05746 {
05747 case STATEMENT_LIST:
05748 for (i = tsi_start (*top_p); !tsi_end_p (i); tsi_next (&i))
05749 c_warn_unused_result (tsi_stmt_ptr (i));
05750 break;
05751
05752 case COND_EXPR:
05753 c_warn_unused_result (&COND_EXPR_THEN (t));
05754 c_warn_unused_result (&COND_EXPR_ELSE (t));
05755 break;
05756 case BIND_EXPR:
05757 c_warn_unused_result (&BIND_EXPR_BODY (t));
05758 break;
05759 case TRY_FINALLY_EXPR:
05760 case TRY_CATCH_EXPR:
05761 c_warn_unused_result (&TREE_OPERAND (t, 0));
05762 c_warn_unused_result (&TREE_OPERAND (t, 1));
05763 break;
05764 case CATCH_EXPR:
05765 c_warn_unused_result (&CATCH_BODY (t));
05766 break;
05767 case EH_FILTER_EXPR:
05768 c_warn_unused_result (&EH_FILTER_FAILURE (t));
05769 break;
05770
05771 case CALL_EXPR:
05772 if (TREE_USED (t))
05773 break;
05774
05775
05776
05777
05778 fdecl = get_callee_fndecl (t);
05779 if (fdecl)
05780 ftype = TREE_TYPE (fdecl);
05781 else
05782 {
05783 ftype = TREE_TYPE (TREE_OPERAND (t, 0));
05784
05785 ftype = TREE_TYPE (ftype);
05786 }
05787
05788 if (lookup_attribute ("warn_unused_result", TYPE_ATTRIBUTES (ftype)))
05789 {
05790 if (fdecl)
05791 warning ("%Hignoring return value of %qD, "
05792 "declared with attribute warn_unused_result",
05793 EXPR_LOCUS (t), fdecl);
05794 else
05795 warning ("%Hignoring return value of function "
05796 "declared with attribute warn_unused_result",
05797 EXPR_LOCUS (t));
05798 }
05799 break;
05800
05801 default:
05802
05803 break;
05804 }
05805 }
05806
05807
05808
05809
05810 HOST_WIDE_INT
05811 c_common_to_target_charset (HOST_WIDE_INT c)
05812 {
05813
05814
05815
05816
05817 cppchar_t uc = ((cppchar_t)c) & ((((cppchar_t)1) << CHAR_BIT)-1);
05818
05819 uc = cpp_host_to_exec_charset (parse_in, uc);
05820
05821 if (flag_signed_char)
05822 return ((HOST_WIDE_INT)uc) << (HOST_BITS_PER_WIDE_INT - CHAR_TYPE_SIZE)
05823 >> (HOST_BITS_PER_WIDE_INT - CHAR_TYPE_SIZE);
05824 else
05825 return uc;
05826 }
05827
05828
05829
05830
05831
05832
05833 static tree
05834 fold_offsetof_1 (tree expr)
05835 {
05836 enum tree_code code = PLUS_EXPR;
05837 tree base, off, t;
05838
05839 switch (TREE_CODE (expr))
05840 {
05841 case ERROR_MARK:
05842 return expr;
05843
05844 case INDIRECT_REF:
05845 return size_zero_node;
05846
05847 case COMPONENT_REF:
05848 base = fold_offsetof_1 (TREE_OPERAND (expr, 0));
05849 if (base == error_mark_node)
05850 return base;
05851
05852 t = TREE_OPERAND (expr, 1);
05853 if (DECL_C_BIT_FIELD (t))
05854 {
05855 error ("attempt to take address of bit-field structure "
05856 "member %qs", IDENTIFIER_POINTER (DECL_NAME (t)));
05857 return error_mark_node;
05858 }
05859 off = size_binop (PLUS_EXPR, DECL_FIELD_OFFSET (t),
05860 size_int (tree_low_cst (DECL_FIELD_BIT_OFFSET (t), 1)
05861 / BITS_PER_UNIT));
05862 break;
05863
05864 case ARRAY_REF:
05865 base = fold_offsetof_1 (TREE_OPERAND (expr, 0));
05866 if (base == error_mark_node)
05867 return base;
05868
05869 t = TREE_OPERAND (expr, 1);
05870 if (TREE_CODE (t) == INTEGER_CST && tree_int_cst_sgn (t) < 0)
05871 {
05872 code = MINUS_EXPR;
05873 t = fold (build1 (NEGATE_EXPR, TREE_TYPE (t), t));
05874 }
05875 t = convert (sizetype, t);
05876 off = size_binop (MULT_EXPR, TYPE_SIZE_UNIT (TREE_TYPE (expr)), t);
05877 break;
05878
05879 default:
05880 gcc_unreachable ();
05881 }
05882
05883 return size_binop (code, base, off);
05884 }
05885
05886 tree
05887 fold_offsetof (tree expr)
05888 {
05889
05890 return convert (size_type_node, fold_offsetof_1 (expr));
05891 }
05892
05893
05894
05895
05896
05897 int
05898 lvalue_or_else (tree ref, enum lvalue_use use)
05899 {
05900 int win = lvalue_p (ref);
05901
05902 if (!win)
05903 {
05904 switch (use)
05905 {
05906 case lv_assign:
05907 error ("invalid lvalue in assignment");
05908 break;
05909 case lv_increment:
05910 error ("invalid lvalue in increment");
05911 break;
05912 case lv_decrement:
05913 error ("invalid lvalue in decrement");
05914 break;
05915 case lv_addressof:
05916 error ("invalid lvalue in unary %<&%>");
05917 break;
05918 case lv_asm:
05919 error ("invalid lvalue in asm statement");
05920 break;
05921 default:
05922 gcc_unreachable ();
05923 }
05924 }
05925
05926 return win;
05927 }
05928
05929
05930
05931
05932
05933
05934 int
05935 complete_array_type (tree *ptype, tree initial_value, bool do_default)
05936 {
05937 tree maxindex, type, main_type, elt, unqual_elt;
05938 int failure = 0, quals;
05939
05940 maxindex = size_zero_node;
05941 if (initial_value)
05942 {
05943 if (TREE_CODE (initial_value) == STRING_CST)
05944 {
05945 int eltsize
05946 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value)));
05947 maxindex = size_int (TREE_STRING_LENGTH (initial_value)/eltsize - 1);
05948 }
05949 else if (TREE_CODE (initial_value) == CONSTRUCTOR)
05950 {
05951 tree elts = CONSTRUCTOR_ELTS (initial_value);
05952
05953 if (elts == NULL)
05954 {
05955 if (pedantic)
05956 failure = 3;
05957 maxindex = integer_minus_one_node;
05958 }
05959 else
05960 {
05961 tree curindex;
05962
05963 if (TREE_PURPOSE (elts))
05964 maxindex = fold_convert (sizetype, TREE_PURPOSE (elts));
05965 curindex = maxindex;
05966
05967 for (elts = TREE_CHAIN (elts); elts; elts = TREE_CHAIN (elts))
05968 {
05969 if (TREE_PURPOSE (elts))
05970 curindex = fold_convert (sizetype, TREE_PURPOSE (elts));
05971 else
05972 curindex = size_binop (PLUS_EXPR, curindex, size_one_node);
05973
05974 if (tree_int_cst_lt (maxindex, curindex))
05975 maxindex = curindex;
05976 }
05977 }
05978 }
05979 else
05980 {
05981
05982 if (initial_value != error_mark_node)
05983 failure = 1;
05984 }
05985 }
05986 else
05987 {
05988 failure = 2;
05989 if (!do_default)
05990 return failure;
05991 }
05992
05993 type = *ptype;
05994 elt = TREE_TYPE (type);
05995 quals = TYPE_QUALS (strip_array_types (elt));
05996 if (quals == 0)
05997 unqual_elt = elt;
05998 else
05999 unqual_elt = c_build_qualified_type (elt, TYPE_UNQUALIFIED);
06000
06001
06002
06003
06004 main_type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
06005 TREE_TYPE (main_type) = unqual_elt;
06006 TYPE_DOMAIN (main_type) = build_index_type (maxindex);
06007 layout_type (main_type);
06008
06009 if (quals == 0)
06010 type = main_type;
06011 else
06012 type = c_build_qualified_type (main_type, quals);
06013
06014 *ptype = type;
06015 return failure;
06016 }
06017
06018
06019 bool
06020 same_scalar_type_ignoring_signedness (tree t1, tree t2)
06021 {
06022 enum tree_code c1 = TREE_CODE (t1), c2 = TREE_CODE (t2);
06023
06024 gcc_assert ((c1 == INTEGER_TYPE || c1 == REAL_TYPE)
06025 && (c2 == INTEGER_TYPE || c2 == REAL_TYPE));
06026
06027
06028
06029 return lang_hooks.types.signed_type (t1)
06030 == lang_hooks.types.signed_type (t2);
06031 }
06032
06033 #include "gt-c-common.h"