00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "config.h"
00027 #include "system.h"
00028 #ifdef SGI_MONGOOSE
00029
00030 #include "rtl.h"
00031 #endif
00032 #include "tree.h"
00033 #include "real.h"
00034 #include "flags.h"
00035 #include "toplev.h"
00036 #include "output.h"
00037 #include "c-pragma.h"
00038 #ifndef SGI_MONGOOSE
00039 #include "rtl.h"
00040 #endif
00041 #include "ggc.h"
00042 #include "expr.h"
00043 #include "c-common.h"
00044 #include "diagnostic.h"
00045 #include "tm_p.h"
00046 #include "obstack.h"
00047 #include "cpplib.h"
00048 #include "target.h"
00049 #include "langhooks.h"
00050 #include "except.h"
00051 #include "tree-inline.h"
00052 #include "c-tree.h"
00053
00054 cpp_reader *parse_in;
00055
00056
00057
00058
00059
00060
00061
00062 #ifndef SIZE_TYPE
00063 #define SIZE_TYPE "long unsigned int"
00064 #endif
00065
00066 #ifndef WCHAR_TYPE
00067 #define WCHAR_TYPE "int"
00068 #endif
00069
00070
00071 #define MODIFIED_WCHAR_TYPE \
00072 (flag_short_wchar ? "short unsigned int" : WCHAR_TYPE)
00073
00074 #ifndef PTRDIFF_TYPE
00075 #define PTRDIFF_TYPE "long int"
00076 #endif
00077
00078 #ifndef WINT_TYPE
00079 #define WINT_TYPE "unsigned int"
00080 #endif
00081
00082 #ifndef INTMAX_TYPE
00083 #define INTMAX_TYPE ((INT_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
00084 ? "int" \
00085 : ((LONG_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
00086 ? "long int" \
00087 : "long long int"))
00088 #endif
00089
00090 #ifndef UINTMAX_TYPE
00091 #define UINTMAX_TYPE ((INT_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
00092 ? "unsigned int" \
00093 : ((LONG_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
00094 ? "long unsigned int" \
00095 : "long long unsigned int"))
00096 #endif
00097
00098 #ifndef REGISTER_PREFIX
00099 #define REGISTER_PREFIX ""
00100 #endif
00101
00102
00103
00104 enum c_language_kind c_language;
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
00194
00195
00196
00197
00198
00199
00200 tree c_global_trees[CTI_MAX];
00201
00202
00203
00204
00205 int flag_preprocess_only;
00206
00207
00208
00209 int flag_iso;
00210
00211
00212 int flag_objc;
00213
00214
00215
00216 int flag_undef;
00217
00218
00219
00220 int flag_no_builtin;
00221
00222
00223
00224
00225 int flag_no_nonansi_builtin;
00226
00227
00228
00229 int flag_short_double;
00230
00231
00232
00233 int flag_short_wchar;
00234
00235
00236 int flag_ms_extensions;
00237
00238
00239
00240 int flag_no_asm;
00241
00242
00243
00244
00245 int flag_const_strings;
00246
00247
00248
00249 #ifndef DOLLARS_IN_IDENTIFIERS
00250 #define DOLLARS_IN_IDENTIFIERS 1
00251 #endif
00252 int dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
00253
00254
00255
00256 int flag_signed_bitfields = 1;
00257 int explicit_flag_signed_bitfields;
00258
00259
00260
00261
00262 int warn_cast_qual;
00263
00264
00265
00266 int warn_missing_format_attribute;
00267
00268
00269
00270
00271 int warn_pointer_arith;
00272
00273
00274
00275
00276 int warn_missing_prototypes;
00277
00278
00279
00280 int warn_parentheses;
00281
00282
00283
00284 int warn_missing_braces;
00285
00286
00287
00288
00289 int warn_sign_compare;
00290
00291
00292
00293 int warn_long_long = 1;
00294
00295
00296
00297
00298 int warn_write_strings;
00299
00300
00301
00302
00303 int warn_redundant_decls;
00304
00305
00306
00307 int warn_float_equal;
00308
00309
00310
00311 int warn_char_subscripts;
00312
00313
00314
00315 int warn_conversion;
00316
00317
00318
00319 int warn_unknown_pragmas;
00320
00321
00322
00323
00324 int warn_format;
00325
00326
00327
00328 int warn_format_y2k;
00329
00330
00331
00332 int warn_format_extra_args;
00333
00334
00335
00336 int warn_format_zero_length;
00337
00338
00339
00340 int warn_format_nonliteral;
00341
00342
00343
00344 int warn_format_security;
00345
00346
00347
00348
00349
00350
00351
00352
00353 int mesg_implicit_function_declaration = -1;
00354
00355
00356
00357
00358 int flag_cond_mismatch;
00359
00360
00361
00362 int flag_isoc94;
00363
00364
00365
00366 int flag_isoc99;
00367
00368
00369
00370 int flag_hosted = 1;
00371
00372
00373
00374
00375 int flag_noniso_default_format_attributes = 1;
00376
00377
00378
00379
00380
00381 int warn_bad_function_cast;
00382
00383
00384
00385 int warn_traditional;
00386
00387
00388
00389 int warn_declaration_after_statement;
00390
00391
00392
00393
00394 int warn_strict_prototypes;
00395
00396
00397
00398
00399 int warn_missing_declarations;
00400
00401
00402
00403
00404
00405
00406
00407 int warn_nested_externs;
00408
00409
00410
00411 int warn_main;
00412
00413
00414
00415 int warn_sequence_point;
00416
00417
00418 int warn_div_by_zero = 1;
00419
00420
00421
00422 int warn_implicit_int;
00423
00424
00425
00426
00427 int warn_nonnull;
00428
00429
00430
00431
00432
00433
00434
00435
00436 int flag_gen_declaration;
00437
00438
00439
00440 #ifdef NEXT_OBJC_RUNTIME
00441 int flag_next_runtime = 1;
00442 #else
00443 int flag_next_runtime = 0;
00444 #endif
00445
00446
00447
00448
00449
00450 int print_struct_values;
00451
00452
00453
00454 const char *constant_string_class_name;
00455
00456
00457
00458
00459
00460 int warn_selector;
00461
00462
00463
00464
00465
00466
00467 int warn_undeclared_selector;
00468
00469
00470
00471
00472
00473 int warn_protocol = 1;
00474
00475
00476
00477
00478
00479
00480
00481 int flag_no_gnu_keywords;
00482
00483
00484
00485
00486 int flag_implement_inlines = 1;
00487
00488
00489
00490
00491 int flag_external_templates;
00492
00493
00494
00495
00496
00497 int flag_alt_external_templates;
00498
00499
00500
00501 int flag_implicit_templates = 1;
00502
00503
00504
00505
00506
00507 int flag_implicit_inline_templates = 1;
00508
00509
00510
00511
00512 int flag_use_repository;
00513
00514
00515
00516
00517 int flag_optional_diags = 1;
00518
00519
00520
00521 int flag_elide_constructors = 1;
00522
00523
00524
00525
00526 int flag_default_inline = 1;
00527
00528
00529
00530
00531 int flag_rtti = 1;
00532
00533
00534
00535
00536
00537
00538 int flag_conserve_space;
00539
00540
00541
00542 int flag_access_control = 1;
00543
00544
00545
00546
00547 int flag_check_new;
00548
00549
00550
00551
00552
00553
00554
00555
00556 int flag_new_for_scope = 1;
00557
00558
00559
00560
00561
00562 int flag_weak = 1;
00563
00564
00565
00566
00567 int flag_use_cxa_atexit = DEFAULT_USE_CXA_ATEXIT;
00568
00569
00570
00571 int flag_vtable_gc;
00572
00573
00574
00575
00576 int flag_permissive;
00577
00578
00579
00580
00581
00582
00583 int flag_enforce_eh_specs = 1;
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598 int flag_abi_version = 1;
00599
00600
00601
00602
00603 int warn_abi = 0;
00604
00605
00606
00607 int warn_implicit = 1;
00608
00609
00610
00611
00612 int warn_ctor_dtor_privacy = 1;
00613
00614
00615
00616
00617
00618 int warn_overloaded_virtual;
00619
00620
00621
00622
00623 int warn_nonvdtor;
00624
00625
00626
00627 int warn_reorder;
00628
00629
00630
00631 int warn_synth;
00632
00633
00634
00635
00636 int warn_pmf2ptr = 1;
00637
00638
00639
00640 int warn_ecpp;
00641
00642
00643
00644
00645 int warn_sign_promo;
00646
00647
00648
00649 int warn_old_style_cast;
00650
00651
00652
00653
00654 int warn_nontemplate_friend = 1;
00655
00656
00657
00658 int warn_deprecated = 1;
00659
00660
00661
00662
00663
00664 int max_tinst_depth = 500;
00665
00666
00667
00668
00669
00670 tree *ridpointers;
00671
00672 tree (*make_fname_decl) PARAMS ((tree, int));
00673
00674
00675
00676 int (*lang_statement_code_p) PARAMS ((enum tree_code));
00677
00678
00679
00680 void (*lang_expand_function_end) PARAMS ((void));
00681
00682
00683
00684 int skip_evaluation;
00685
00686
00687 struct fname_var_t
00688 {
00689 tree *const decl;
00690 const unsigned rid;
00691 const int pretty;
00692 };
00693
00694
00695
00696 const struct fname_var_t fname_vars[] =
00697 {
00698
00699 {&c99_function_name_decl_node, RID_C99_FUNCTION_NAME, 0},
00700
00701 {&function_name_decl_node, RID_FUNCTION_NAME, 0},
00702
00703 {&pretty_function_name_decl_node, RID_PRETTY_FUNCTION_NAME, 1},
00704 {NULL, 0, 0},
00705 };
00706
00707 static int constant_fits_type_p PARAMS ((tree, tree));
00708
00709
00710
00711
00712
00713
00714 typedef struct
00715 {
00716 int compstmt_count;
00717 int line;
00718 const char *file;
00719 int needs_warning;
00720 tree if_stmt;
00721 } if_elt;
00722
00723 static if_elt *if_stack;
00724
00725
00726 static int if_stack_space = 0;
00727
00728
00729 static int if_stack_pointer = 0;
00730
00731 static tree handle_packed_attribute PARAMS ((tree *, tree, tree, int,
00732 bool *));
00733 static tree handle_nocommon_attribute PARAMS ((tree *, tree, tree, int,
00734 bool *));
00735 static tree handle_common_attribute PARAMS ((tree *, tree, tree, int,
00736 bool *));
00737 static tree handle_noreturn_attribute PARAMS ((tree *, tree, tree, int,
00738 bool *));
00739 static tree handle_noinline_attribute PARAMS ((tree *, tree, tree, int,
00740 bool *));
00741 static tree handle_always_inline_attribute PARAMS ((tree *, tree, tree, int,
00742 bool *));
00743 static tree handle_used_attribute PARAMS ((tree *, tree, tree, int,
00744 bool *));
00745 static tree handle_unused_attribute PARAMS ((tree *, tree, tree, int,
00746 bool *));
00747 static tree handle_const_attribute PARAMS ((tree *, tree, tree, int,
00748 bool *));
00749 static tree handle_transparent_union_attribute PARAMS ((tree *, tree, tree,
00750 int, bool *));
00751 static tree handle_constructor_attribute PARAMS ((tree *, tree, tree, int,
00752 bool *));
00753 static tree handle_destructor_attribute PARAMS ((tree *, tree, tree, int,
00754 bool *));
00755 static tree handle_mode_attribute PARAMS ((tree *, tree, tree, int,
00756 bool *));
00757 static tree handle_section_attribute PARAMS ((tree *, tree, tree, int,
00758 bool *));
00759 static tree handle_aligned_attribute PARAMS ((tree *, tree, tree, int,
00760 bool *));
00761 static tree handle_weak_attribute PARAMS ((tree *, tree, tree, int,
00762 bool *));
00763 static tree handle_alias_attribute PARAMS ((tree *, tree, tree, int,
00764 bool *));
00765 static tree handle_visibility_attribute PARAMS ((tree *, tree, tree, int,
00766 bool *));
00767 static tree handle_tls_model_attribute PARAMS ((tree *, tree, tree, int,
00768 bool *));
00769 static tree handle_no_instrument_function_attribute PARAMS ((tree *, tree,
00770 tree, int,
00771 bool *));
00772 static tree handle_malloc_attribute PARAMS ((tree *, tree, tree, int,
00773 bool *));
00774 static tree handle_no_limit_stack_attribute PARAMS ((tree *, tree, tree, int,
00775 bool *));
00776 static tree handle_pure_attribute PARAMS ((tree *, tree, tree, int,
00777 bool *));
00778 static tree handle_deprecated_attribute PARAMS ((tree *, tree, tree, int,
00779 bool *));
00780 static tree handle_vector_size_attribute PARAMS ((tree *, tree, tree, int,
00781 bool *));
00782 static tree handle_nonnull_attribute PARAMS ((tree *, tree, tree, int,
00783 bool *));
00784 static tree handle_nothrow_attribute PARAMS ((tree *, tree, tree, int,
00785 bool *));
00786 static tree handle_cleanup_attribute PARAMS ((tree *, tree, tree, int,
00787 bool *));
00788 #ifdef SGI_MONGOOSE
00789 static tree handle_syscall_linkage_attribute PARAMS ((tree *, tree, tree, int,
00790 bool *));
00791 static tree handle_widenretval_attribute PARAMS ((tree *, tree, tree, int,
00792 bool *));
00793 #endif
00794
00795 #if defined(TARG_SL)
00796 static tree handle_sl_model_attribute PARAMS ((tree *, tree, tree, int,
00797 bool *));
00798 #endif
00799 static tree vector_size_helper PARAMS ((tree, tree));
00800
00801 static void check_function_nonnull PARAMS ((tree, tree));
00802 static void check_nonnull_arg PARAMS ((void *, tree,
00803 unsigned HOST_WIDE_INT));
00804 static bool nonnull_check_p PARAMS ((tree, unsigned HOST_WIDE_INT));
00805 static bool get_nonnull_operand PARAMS ((tree,
00806 unsigned HOST_WIDE_INT *));
00807 void builtin_define_std PARAMS ((const char *));
00808 static void builtin_define_with_value PARAMS ((const char *, const char *,
00809 int));
00810 static void builtin_define_with_int_value PARAMS ((const char *,
00811 HOST_WIDE_INT));
00812 static void builtin_define_with_hex_fp_value PARAMS ((const char *, tree,
00813 int, const char *,
00814 const char *));
00815 static void builtin_define_type_max PARAMS ((const char *, tree, int));
00816 static void builtin_define_type_precision PARAMS ((const char *, tree));
00817 static void builtin_define_float_constants PARAMS ((const char *,
00818 const char *, tree));
00819
00820
00821 const struct attribute_spec c_common_attribute_table[] =
00822 {
00823
00824 { "packed", 0, 0, false, false, false,
00825 handle_packed_attribute },
00826 { "nocommon", 0, 0, true, false, false,
00827 handle_nocommon_attribute },
00828 { "common", 0, 0, true, false, false,
00829 handle_common_attribute },
00830
00831
00832
00833
00834
00835 { "noreturn", 0, 0, true, false, false,
00836 handle_noreturn_attribute },
00837 { "volatile", 0, 0, true, false, false,
00838 handle_noreturn_attribute },
00839 { "noinline", 0, 0, true, false, false,
00840 handle_noinline_attribute },
00841 { "always_inline", 0, 0, true, false, false,
00842 handle_always_inline_attribute },
00843 { "used", 0, 0, true, false, false,
00844 handle_used_attribute },
00845 { "unused", 0, 0, false, false, false,
00846 handle_unused_attribute },
00847
00848 { "const", 0, 0, true, false, false,
00849 handle_const_attribute },
00850 { "transparent_union", 0, 0, false, false, false,
00851 handle_transparent_union_attribute },
00852 { "constructor", 0, 0, true, false, false,
00853 handle_constructor_attribute },
00854 { "destructor", 0, 0, true, false, false,
00855 handle_destructor_attribute },
00856 { "mode", 1, 1, false, true, false,
00857 handle_mode_attribute },
00858 { "section", 1, 1, true, false, false,
00859 handle_section_attribute },
00860 { "aligned", 0, 1, false, false, false,
00861 handle_aligned_attribute },
00862 { "weak", 0, 0, true, false, false,
00863 handle_weak_attribute },
00864 { "alias", 1, 1, true, false, false,
00865 handle_alias_attribute },
00866 { "no_instrument_function", 0, 0, true, false, false,
00867 handle_no_instrument_function_attribute },
00868 { "malloc", 0, 0, true, false, false,
00869 handle_malloc_attribute },
00870 { "no_stack_limit", 0, 0, true, false, false,
00871 handle_no_limit_stack_attribute },
00872 { "pure", 0, 0, true, false, false,
00873 handle_pure_attribute },
00874 { "deprecated", 0, 0, false, false, false,
00875 handle_deprecated_attribute },
00876 { "vector_size", 1, 1, false, true, false,
00877 handle_vector_size_attribute },
00878 { "visibility", 1, 1, true, false, false,
00879 handle_visibility_attribute },
00880 { "tls_model", 1, 1, true, false, false,
00881 handle_tls_model_attribute },
00882 { "nonnull", 0, -1, false, true, true,
00883 handle_nonnull_attribute },
00884 { "nothrow", 0, 0, true, false, false,
00885 handle_nothrow_attribute },
00886 { "may_alias", 0, 0, false, true, false, NULL },
00887 { "cleanup", 1, 1, true, false, false,
00888 handle_cleanup_attribute },
00889 #ifdef SGI_MONGOOSE
00890 { "syscall_linkage", 0, 0, true, false, false,
00891 handle_syscall_linkage_attribute },
00892 { "readonlyargs", 0, 0, true, false, false,
00893 handle_syscall_linkage_attribute },
00894 { "widenretval", 0, 0, true, false, false,
00895 handle_widenretval_attribute },
00896 #endif
00897 #if defined(TARG_SL)
00898 {"sl_model", 1, 1, true, false, false,
00899 handle_sl_model_attribute },
00900 #endif
00901 { NULL, 0, 0, false, false, false, NULL }
00902 };
00903
00904
00905
00906
00907 const struct attribute_spec c_common_format_attribute_table[] =
00908 {
00909
00910 { "format", 3, 3, false, true, true,
00911 handle_format_attribute },
00912 { "format_arg", 1, 1, false, true, true,
00913 handle_format_arg_attribute },
00914 { NULL, 0, 0, false, false, false, NULL }
00915 };
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926 void
00927 c_expand_start_cond (cond, compstmt_count, if_stmt)
00928 tree cond;
00929 int compstmt_count;
00930 tree if_stmt;
00931 {
00932
00933 if (if_stack_space == 0)
00934 {
00935 if_stack_space = 10;
00936 if_stack = (if_elt *) xmalloc (10 * sizeof (if_elt));
00937 }
00938 else if (if_stack_space == if_stack_pointer)
00939 {
00940 if_stack_space += 10;
00941 if_stack = (if_elt *) xrealloc (if_stack, if_stack_space * sizeof (if_elt));
00942 }
00943
00944 IF_COND (if_stmt) = cond;
00945 add_stmt (if_stmt);
00946
00947
00948 if_stack[if_stack_pointer].compstmt_count = compstmt_count;
00949 if_stack[if_stack_pointer].file = input_filename;
00950 if_stack[if_stack_pointer].line = lineno;
00951 if_stack[if_stack_pointer].needs_warning = 0;
00952 if_stack[if_stack_pointer].if_stmt = if_stmt;
00953 if_stack_pointer++;
00954 }
00955
00956
00957
00958 void
00959 c_finish_then ()
00960 {
00961 tree if_stmt = if_stack[if_stack_pointer - 1].if_stmt;
00962 RECHAIN_STMTS (if_stmt, THEN_CLAUSE (if_stmt));
00963 }
00964
00965
00966
00967
00968 void
00969 c_expand_end_cond ()
00970 {
00971 if_stack_pointer--;
00972 if (if_stack[if_stack_pointer].needs_warning)
00973 warning_with_file_and_line (if_stack[if_stack_pointer].file,
00974 if_stack[if_stack_pointer].line,
00975 "suggest explicit braces to avoid ambiguous `else'");
00976 last_expr_type = NULL_TREE;
00977 }
00978
00979
00980
00981
00982 void
00983 c_expand_start_else ()
00984 {
00985
00986
00987 if (warn_parentheses
00988 && if_stack_pointer > 1
00989 && (if_stack[if_stack_pointer - 1].compstmt_count
00990 == if_stack[if_stack_pointer - 2].compstmt_count))
00991 if_stack[if_stack_pointer - 2].needs_warning = 1;
00992
00993
00994
00995
00996 if_stack[if_stack_pointer - 1].needs_warning = 0;
00997 if_stack[if_stack_pointer - 1].compstmt_count--;
00998 }
00999
01000
01001
01002 void
01003 c_finish_else ()
01004 {
01005 tree if_stmt = if_stack[if_stack_pointer - 1].if_stmt;
01006 RECHAIN_STMTS (if_stmt, ELSE_CLAUSE (if_stmt));
01007 }
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017 tree
01018 c_begin_if_stmt ()
01019 {
01020 tree r;
01021 r = build_stmt (IF_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
01022 return r;
01023 }
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033 tree
01034 c_begin_while_stmt ()
01035 {
01036 tree r;
01037 r = build_stmt (WHILE_STMT, NULL_TREE, NULL_TREE);
01038 return r;
01039 }
01040
01041 void
01042 c_finish_while_stmt_cond (cond, while_stmt)
01043 tree while_stmt;
01044 tree cond;
01045 {
01046 WHILE_COND (while_stmt) = cond;
01047 }
01048
01049
01050
01051 void
01052 start_fname_decls ()
01053 {
01054 unsigned ix;
01055 tree saved = NULL_TREE;
01056
01057 for (ix = 0; fname_vars[ix].decl; ix++)
01058 {
01059 tree decl = *fname_vars[ix].decl;
01060
01061 if (decl)
01062 {
01063 saved = tree_cons (decl, build_int_2 (ix, 0), saved);
01064 *fname_vars[ix].decl = NULL_TREE;
01065 }
01066 }
01067 if (saved || saved_function_name_decls)
01068
01069
01070 saved_function_name_decls = tree_cons (saved, NULL_TREE,
01071 saved_function_name_decls);
01072 }
01073
01074
01075
01076
01077
01078
01079
01080
01081 void
01082 finish_fname_decls ()
01083 {
01084 unsigned ix;
01085 tree body = NULL_TREE;
01086 tree stack = saved_function_name_decls;
01087
01088 for (; stack && TREE_VALUE (stack); stack = TREE_CHAIN (stack))
01089 body = chainon (TREE_VALUE (stack), body);
01090
01091 if (body)
01092 {
01093
01094 body = chainon (body,
01095 TREE_CHAIN (DECL_SAVED_TREE (current_function_decl)));
01096 body = build_stmt (COMPOUND_STMT, body);
01097
01098 COMPOUND_STMT_NO_SCOPE (body) = 1;
01099 TREE_CHAIN (DECL_SAVED_TREE (current_function_decl)) = body;
01100 }
01101
01102 for (ix = 0; fname_vars[ix].decl; ix++)
01103 *fname_vars[ix].decl = NULL_TREE;
01104
01105 if (stack)
01106 {
01107
01108 tree saved;
01109
01110 for (saved = TREE_PURPOSE (stack); saved; saved = TREE_CHAIN (saved))
01111 {
01112 tree decl = TREE_PURPOSE (saved);
01113 unsigned ix = TREE_INT_CST_LOW (TREE_VALUE (saved));
01114
01115 *fname_vars[ix].decl = decl;
01116 }
01117 stack = TREE_CHAIN (stack);
01118 }
01119 saved_function_name_decls = stack;
01120 }
01121
01122
01123
01124
01125 const char *
01126 fname_as_string (pretty_p)
01127 int pretty_p;
01128 {
01129 const char *name = NULL;
01130
01131 if (pretty_p)
01132 name = (current_function_decl
01133 ? (*lang_hooks.decl_printable_name) (current_function_decl, 2)
01134 : "top level");
01135 else if (current_function_decl && DECL_NAME (current_function_decl))
01136 name = IDENTIFIER_POINTER (DECL_NAME (current_function_decl));
01137 else
01138 name = "";
01139 return name;
01140 }
01141
01142
01143
01144
01145 const char *
01146 fname_string (rid)
01147 unsigned rid;
01148 {
01149 unsigned ix;
01150
01151 for (ix = 0; fname_vars[ix].decl; ix++)
01152 if (fname_vars[ix].rid == rid)
01153 break;
01154 return fname_as_string (fname_vars[ix].pretty);
01155 }
01156
01157
01158
01159
01160
01161
01162
01163
01164 tree
01165 fname_decl (rid, id)
01166 unsigned rid;
01167 tree id;
01168 {
01169 unsigned ix;
01170 tree decl = NULL_TREE;
01171
01172 for (ix = 0; fname_vars[ix].decl; ix++)
01173 if (fname_vars[ix].rid == rid)
01174 break;
01175
01176 decl = *fname_vars[ix].decl;
01177 if (!decl)
01178 {
01179 tree saved_last_tree = last_tree;
01180
01181
01182
01183
01184
01185 int saved_lineno = lineno;
01186 lineno = 0;
01187
01188 decl = (*make_fname_decl) (id, fname_vars[ix].pretty);
01189 if (last_tree != saved_last_tree)
01190 {
01191
01192
01193
01194 tree stmts = TREE_CHAIN (saved_last_tree);
01195
01196 TREE_CHAIN (saved_last_tree) = NULL_TREE;
01197 last_tree = saved_last_tree;
01198 saved_function_name_decls = tree_cons (decl, stmts,
01199 saved_function_name_decls);
01200 }
01201 *fname_vars[ix].decl = decl;
01202 lineno = saved_lineno;
01203 }
01204 if (!ix && !current_function_decl)
01205 pedwarn_with_decl (decl, "`%s' is not defined outside of function scope");
01206
01207 return decl;
01208 }
01209
01210
01211
01212 tree
01213 fix_string_type (value)
01214 tree value;
01215 {
01216 const int wchar_bytes = TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT;
01217 const int wide_flag = TREE_TYPE (value) == wchar_array_type_node;
01218 const int nchars_max = flag_isoc99 ? 4095 : 509;
01219 int length = TREE_STRING_LENGTH (value);
01220 int nchars;
01221
01222
01223 nchars = wide_flag ? length / wchar_bytes : length;
01224
01225 if (pedantic && nchars - 1 > nchars_max && c_language == clk_c)
01226 pedwarn ("string length `%d' is greater than the length `%d' ISO C%d compilers are required to support",
01227 nchars - 1, nchars_max, flag_isoc99 ? 99 : 89);
01228
01229
01230
01231
01232
01233 if (flag_const_strings && ! flag_writable_strings)
01234 {
01235 tree elements
01236 = build_type_variant (wide_flag ? wchar_type_node : char_type_node,
01237 1, 0);
01238 TREE_TYPE (value)
01239 = build_array_type (elements,
01240 build_index_type (build_int_2 (nchars - 1, 0)));
01241 }
01242 else
01243 TREE_TYPE (value)
01244 = build_array_type (wide_flag ? wchar_type_node : char_type_node,
01245 build_index_type (build_int_2 (nchars - 1, 0)));
01246
01247 TREE_CONSTANT (value) = 1;
01248 TREE_READONLY (value) = ! flag_writable_strings;
01249 TREE_STATIC (value) = 1;
01250 return value;
01251 }
01252
01253
01254
01255
01256 tree
01257 combine_strings (strings)
01258 varray_type strings;
01259 {
01260 const int wchar_bytes = TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT;
01261 const int nstrings = VARRAY_ACTIVE_SIZE (strings);
01262 tree value, t;
01263 int length = 1;
01264 int wide_length = 0;
01265 int wide_flag = 0;
01266 int i;
01267 char *p, *q;
01268
01269
01270
01271 for (i = 0; i < nstrings; ++i)
01272 {
01273 t = VARRAY_TREE (strings, i);
01274
01275 if (TREE_TYPE (t) == wchar_array_type_node)
01276 {
01277 wide_length += TREE_STRING_LENGTH (t) - wchar_bytes;
01278 wide_flag = 1;
01279 }
01280 else
01281 {
01282 length += (TREE_STRING_LENGTH (t) - 1);
01283 if (C_ARTIFICIAL_STRING_P (t) && !in_system_header)
01284 warning ("concatenation of string literals with __FUNCTION__ is deprecated");
01285 }
01286 }
01287
01288
01289
01290 if (wide_flag)
01291 length = length * wchar_bytes + wide_length;
01292
01293 p = xmalloc (length);
01294
01295
01296
01297
01298
01299 q = p;
01300 for (i = 0; i < nstrings; ++i)
01301 {
01302 int len, this_wide;
01303
01304 t = VARRAY_TREE (strings, i);
01305 this_wide = TREE_TYPE (t) == wchar_array_type_node;
01306 len = TREE_STRING_LENGTH (t) - (this_wide ? wchar_bytes : 1);
01307 if (this_wide == wide_flag)
01308 {
01309 memcpy (q, TREE_STRING_POINTER (t), len);
01310 q += len;
01311 }
01312 else
01313 {
01314 const int nzeros = (TYPE_PRECISION (wchar_type_node)
01315 / BITS_PER_UNIT) - 1;
01316 int j, k;
01317
01318 if (BYTES_BIG_ENDIAN)
01319 {
01320 for (k = 0; k < len; k++)
01321 {
01322 for (j = 0; j < nzeros; j++)
01323 *q++ = 0;
01324 *q++ = TREE_STRING_POINTER (t)[k];
01325 }
01326 }
01327 else
01328 {
01329 for (k = 0; k < len; k++)
01330 {
01331 *q++ = TREE_STRING_POINTER (t)[k];
01332 for (j = 0; j < nzeros; j++)
01333 *q++ = 0;
01334 }
01335 }
01336 }
01337 }
01338
01339
01340 if (wide_flag)
01341 {
01342 for (i = 0; i < wchar_bytes; i++)
01343 *q++ = 0;
01344 }
01345 else
01346 *q = 0;
01347
01348 value = build_string (length, p);
01349 free (p);
01350
01351 if (wide_flag)
01352 TREE_TYPE (value) = wchar_array_type_node;
01353 else
01354 TREE_TYPE (value) = char_array_type_node;
01355
01356 return value;
01357 }
01358
01359 static int is_valid_printf_arglist PARAMS ((tree));
01360 static rtx c_expand_builtin PARAMS ((tree, rtx, enum machine_mode, enum expand_modifier));
01361 static rtx c_expand_builtin_printf PARAMS ((tree, rtx, enum machine_mode,
01362 enum expand_modifier, int, int));
01363 static rtx c_expand_builtin_fprintf PARAMS ((tree, rtx, enum machine_mode,
01364 enum expand_modifier, int, int));
01365
01366
01367
01368
01369
01370
01371
01372 void
01373 constant_expression_warning (value)
01374 tree value;
01375 {
01376 if ((TREE_CODE (value) == INTEGER_CST || TREE_CODE (value) == REAL_CST
01377 || TREE_CODE (value) == VECTOR_CST
01378 || TREE_CODE (value) == COMPLEX_CST)
01379 && TREE_CONSTANT_OVERFLOW (value) && pedantic)
01380 pedwarn ("overflow in constant expression");
01381 }
01382
01383
01384
01385
01386
01387
01388
01389
01390 void
01391 overflow_warning (value)
01392 tree value;
01393 {
01394 if ((TREE_CODE (value) == INTEGER_CST
01395 || (TREE_CODE (value) == COMPLEX_CST
01396 && TREE_CODE (TREE_REALPART (value)) == INTEGER_CST))
01397 && TREE_OVERFLOW (value))
01398 {
01399 TREE_OVERFLOW (value) = 0;
01400 if (skip_evaluation == 0)
01401 warning ("integer overflow in expression");
01402 }
01403 else if ((TREE_CODE (value) == REAL_CST
01404 || (TREE_CODE (value) == COMPLEX_CST
01405 && TREE_CODE (TREE_REALPART (value)) == REAL_CST))
01406 && TREE_OVERFLOW (value))
01407 {
01408 TREE_OVERFLOW (value) = 0;
01409 if (skip_evaluation == 0)
01410 warning ("floating point overflow in expression");
01411 }
01412 else if (TREE_CODE (value) == VECTOR_CST && TREE_OVERFLOW (value))
01413 {
01414 TREE_OVERFLOW (value) = 0;
01415 if (skip_evaluation == 0)
01416 warning ("vector overflow in expression");
01417 }
01418 }
01419
01420
01421
01422
01423
01424
01425 void
01426 unsigned_conversion_warning (result, operand)
01427 tree result, operand;
01428 {
01429 tree type = TREE_TYPE (result);
01430
01431 if (TREE_CODE (operand) == INTEGER_CST
01432 && TREE_CODE (type) == INTEGER_TYPE
01433 && TREE_UNSIGNED (type)
01434 && skip_evaluation == 0
01435 && !int_fits_type_p (operand, type))
01436 {
01437 if (!int_fits_type_p (operand, c_common_signed_type (type)))
01438
01439 warning ("large integer implicitly truncated to unsigned type");
01440 else if (warn_conversion)
01441 warning ("negative integer implicitly converted to unsigned type");
01442 }
01443 }
01444
01445
01446
01447
01448 static int
01449 constant_fits_type_p (c, type)
01450 tree c, type;
01451 {
01452 if (TREE_CODE (c) == INTEGER_CST)
01453 return int_fits_type_p (c, type);
01454
01455 c = convert (type, c);
01456 return !TREE_OVERFLOW (c);
01457 }
01458
01459
01460
01461
01462
01463 tree
01464 convert_and_check (type, expr)
01465 tree type, expr;
01466 {
01467 tree t = convert (type, expr);
01468 if (TREE_CODE (t) == INTEGER_CST)
01469 {
01470 if (TREE_OVERFLOW (t))
01471 {
01472 TREE_OVERFLOW (t) = 0;
01473
01474
01475
01476 TREE_CONSTANT_OVERFLOW (t) = TREE_CONSTANT_OVERFLOW (expr);
01477
01478
01479 if (!(TREE_UNSIGNED (type) < TREE_UNSIGNED (TREE_TYPE (expr))
01480 && TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
01481 && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (expr))))
01482
01483
01484 if ((pedantic
01485 || TREE_UNSIGNED (type)
01486 || ! constant_fits_type_p (expr,
01487 c_common_unsigned_type (type)))
01488 && skip_evaluation == 0)
01489 warning ("overflow in implicit constant conversion");
01490 }
01491 else
01492 unsigned_conversion_warning (t, expr);
01493 }
01494 return t;
01495 }
01496
01497
01498
01499
01500 struct tlist
01501 {
01502 struct tlist *next;
01503 tree expr, writer;
01504 };
01505
01506
01507
01508 struct tlist_cache
01509 {
01510 struct tlist_cache *next;
01511 struct tlist *cache_before_sp;
01512 struct tlist *cache_after_sp;
01513 tree expr;
01514 };
01515
01516
01517
01518 static struct obstack tlist_obstack;
01519 static char *tlist_firstobj = 0;
01520
01521
01522
01523 static struct tlist *warned_ids;
01524
01525
01526 static struct tlist_cache *save_expr_cache;
01527
01528 static void add_tlist PARAMS ((struct tlist **, struct tlist *, tree, int));
01529 static void merge_tlist PARAMS ((struct tlist **, struct tlist *, int));
01530 static void verify_tree PARAMS ((tree, struct tlist **, struct tlist **, tree));
01531 static int warning_candidate_p PARAMS ((tree));
01532 static void warn_for_collisions PARAMS ((struct tlist *));
01533 static void warn_for_collisions_1 PARAMS ((tree, tree, struct tlist *, int));
01534 static struct tlist *new_tlist PARAMS ((struct tlist *, tree, tree));
01535 static void verify_sequence_points PARAMS ((tree));
01536
01537
01538 static struct tlist *
01539 new_tlist (next, t, writer)
01540 struct tlist *next;
01541 tree t;
01542 tree writer;
01543 {
01544 struct tlist *l;
01545 l = (struct tlist *) obstack_alloc (&tlist_obstack, sizeof *l);
01546 l->next = next;
01547 l->expr = t;
01548 l->writer = writer;
01549 return l;
01550 }
01551
01552
01553
01554
01555 static void
01556 add_tlist (to, add, exclude_writer, copy)
01557 struct tlist **to;
01558 struct tlist *add;
01559 tree exclude_writer;
01560 int copy;
01561 {
01562 while (add)
01563 {
01564 struct tlist *next = add->next;
01565 if (! copy)
01566 add->next = *to;
01567 if (! exclude_writer || add->writer != exclude_writer)
01568 *to = copy ? new_tlist (*to, add->expr, add->writer) : add;
01569 add = next;
01570 }
01571 }
01572
01573
01574
01575
01576
01577
01578
01579 static void
01580 merge_tlist (to, add, copy)
01581 struct tlist **to;
01582 struct tlist *add;
01583 int copy;
01584 {
01585 struct tlist **end = to;
01586
01587 while (*end)
01588 end = &(*end)->next;
01589
01590 while (add)
01591 {
01592 int found = 0;
01593 struct tlist *tmp2;
01594 struct tlist *next = add->next;
01595
01596 for (tmp2 = *to; tmp2; tmp2 = tmp2->next)
01597 if (tmp2->expr == add->expr)
01598 {
01599 found = 1;
01600 if (! tmp2->writer)
01601 tmp2->writer = add->writer;
01602 }
01603 if (! found)
01604 {
01605 *end = copy ? add : new_tlist (NULL, add->expr, add->writer);
01606 end = &(*end)->next;
01607 *end = 0;
01608 }
01609 add = next;
01610 }
01611 }
01612
01613
01614
01615
01616
01617 static void
01618 warn_for_collisions_1 (written, writer, list, only_writes)
01619 tree written, writer;
01620 struct tlist *list;
01621 int only_writes;
01622 {
01623 struct tlist *tmp;
01624
01625
01626 for (tmp = warned_ids; tmp; tmp = tmp->next)
01627 if (tmp->expr == written)
01628 return;
01629
01630 while (list)
01631 {
01632 if (list->expr == written
01633 && list->writer != writer
01634 && (! only_writes || list->writer))
01635 {
01636 warned_ids = new_tlist (warned_ids, written, NULL_TREE);
01637 warning ("operation on `%s' may be undefined",
01638 IDENTIFIER_POINTER (DECL_NAME (list->expr)));
01639 }
01640 list = list->next;
01641 }
01642 }
01643
01644
01645
01646
01647 static void
01648 warn_for_collisions (list)
01649 struct tlist *list;
01650 {
01651 struct tlist *tmp;
01652
01653 for (tmp = list; tmp; tmp = tmp->next)
01654 {
01655 if (tmp->writer)
01656 warn_for_collisions_1 (tmp->expr, tmp->writer, list, 0);
01657 }
01658 }
01659
01660
01661
01662 static int
01663 warning_candidate_p (x)
01664 tree x;
01665 {
01666 return TREE_CODE (x) == VAR_DECL || TREE_CODE (x) == PARM_DECL;
01667 }
01668
01669
01670
01671
01672
01673
01674
01675
01676
01677
01678
01679
01680
01681
01682
01683
01684
01685
01686
01687
01688
01689
01690
01691
01692
01693
01694 static void
01695 verify_tree (x, pbefore_sp, pno_sp, writer)
01696 tree x;
01697 struct tlist **pbefore_sp, **pno_sp;
01698 tree writer;
01699 {
01700 struct tlist *tmp_before, *tmp_nosp, *tmp_list2, *tmp_list3;
01701 enum tree_code code;
01702 char class;
01703
01704
01705
01706 if (x == NULL)
01707 return;
01708
01709 restart:
01710 code = TREE_CODE (x);
01711 class = TREE_CODE_CLASS (code);
01712
01713 if (warning_candidate_p (x))
01714 {
01715 *pno_sp = new_tlist (*pno_sp, x, writer);
01716 return;
01717 }
01718
01719 switch (code)
01720 {
01721 case CONSTRUCTOR:
01722 return;
01723
01724 case COMPOUND_EXPR:
01725 case TRUTH_ANDIF_EXPR:
01726 case TRUTH_ORIF_EXPR:
01727 tmp_before = tmp_nosp = tmp_list3 = 0;
01728 verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_nosp, NULL_TREE);
01729 warn_for_collisions (tmp_nosp);
01730 merge_tlist (pbefore_sp, tmp_before, 0);
01731 merge_tlist (pbefore_sp, tmp_nosp, 0);
01732 verify_tree (TREE_OPERAND (x, 1), &tmp_list3, pno_sp, NULL_TREE);
01733 merge_tlist (pbefore_sp, tmp_list3, 0);
01734 return;
01735
01736 case COND_EXPR:
01737 tmp_before = tmp_list2 = 0;
01738 verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_list2, NULL_TREE);
01739 warn_for_collisions (tmp_list2);
01740 merge_tlist (pbefore_sp, tmp_before, 0);
01741 merge_tlist (pbefore_sp, tmp_list2, 1);
01742
01743 tmp_list3 = tmp_nosp = 0;
01744 verify_tree (TREE_OPERAND (x, 1), &tmp_list3, &tmp_nosp, NULL_TREE);
01745 warn_for_collisions (tmp_nosp);
01746 merge_tlist (pbefore_sp, tmp_list3, 0);
01747
01748 tmp_list3 = tmp_list2 = 0;
01749 verify_tree (TREE_OPERAND (x, 2), &tmp_list3, &tmp_list2, NULL_TREE);
01750 warn_for_collisions (tmp_list2);
01751 merge_tlist (pbefore_sp, tmp_list3, 0);
01752
01753
01754 merge_tlist (&tmp_nosp, tmp_list2, 0);
01755 add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
01756 return;
01757
01758 case PREDECREMENT_EXPR:
01759 case PREINCREMENT_EXPR:
01760 case POSTDECREMENT_EXPR:
01761 case POSTINCREMENT_EXPR:
01762 verify_tree (TREE_OPERAND (x, 0), pno_sp, pno_sp, x);
01763 return;
01764
01765 case MODIFY_EXPR:
01766 tmp_before = tmp_nosp = tmp_list3 = 0;
01767 verify_tree (TREE_OPERAND (x, 1), &tmp_before, &tmp_nosp, NULL_TREE);
01768 verify_tree (TREE_OPERAND (x, 0), &tmp_list3, &tmp_list3, x);
01769
01770
01771
01772
01773
01774
01775
01776
01777 add_tlist (&tmp_before, tmp_list3, x, 1);
01778 warn_for_collisions (tmp_before);
01779
01780
01781
01782
01783 add_tlist (pno_sp, tmp_list3, x, 0);
01784 warn_for_collisions_1 (TREE_OPERAND (x, 0), x, tmp_nosp, 1);
01785
01786 merge_tlist (pbefore_sp, tmp_before, 0);
01787 if (warning_candidate_p (TREE_OPERAND (x, 0)))
01788 merge_tlist (&tmp_nosp, new_tlist (NULL, TREE_OPERAND (x, 0), x), 0);
01789 add_tlist (pno_sp, tmp_nosp, NULL_TREE, 1);
01790 return;
01791
01792 case CALL_EXPR:
01793
01794
01795
01796 tmp_before = tmp_nosp = tmp_list2 = tmp_list3 = 0;
01797 verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_nosp, NULL_TREE);
01798 if (TREE_OPERAND (x, 1))
01799 verify_tree (TREE_OPERAND (x, 1), &tmp_list2, &tmp_list3, NULL_TREE);
01800 merge_tlist (&tmp_list3, tmp_list2, 0);
01801 add_tlist (&tmp_before, tmp_list3, NULL_TREE, 0);
01802 add_tlist (&tmp_before, tmp_nosp, NULL_TREE, 0);
01803 warn_for_collisions (tmp_before);
01804 add_tlist (pbefore_sp, tmp_before, NULL_TREE, 0);
01805 return;
01806
01807 case TREE_LIST:
01808
01809 while (x)
01810 {
01811 tmp_before = tmp_nosp = 0;
01812 verify_tree (TREE_VALUE (x), &tmp_before, &tmp_nosp, NULL_TREE);
01813 merge_tlist (&tmp_nosp, tmp_before, 0);
01814 add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
01815 x = TREE_CHAIN (x);
01816 }
01817 return;
01818
01819 case SAVE_EXPR:
01820 {
01821 struct tlist_cache *t;
01822 for (t = save_expr_cache; t; t = t->next)
01823 if (t->expr == x)
01824 break;
01825
01826 if (! t)
01827 {
01828 t = (struct tlist_cache *) obstack_alloc (&tlist_obstack,
01829 sizeof *t);
01830 t->next = save_expr_cache;
01831 t->expr = x;
01832 save_expr_cache = t;
01833
01834 tmp_before = tmp_nosp = 0;
01835 verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_nosp, NULL_TREE);
01836 warn_for_collisions (tmp_nosp);
01837
01838 tmp_list3 = 0;
01839 while (tmp_nosp)
01840 {
01841 struct tlist *t = tmp_nosp;
01842 tmp_nosp = t->next;
01843 merge_tlist (&tmp_list3, t, 0);
01844 }
01845 t->cache_before_sp = tmp_before;
01846 t->cache_after_sp = tmp_list3;
01847 }
01848 merge_tlist (pbefore_sp, t->cache_before_sp, 1);
01849 add_tlist (pno_sp, t->cache_after_sp, NULL_TREE, 1);
01850 return;
01851 }
01852 default:
01853 break;
01854 }
01855
01856 if (class == '1')
01857 {
01858 if (first_rtl_op (code) == 0)
01859 return;
01860 x = TREE_OPERAND (x, 0);
01861 writer = 0;
01862 goto restart;
01863 }
01864
01865 switch (class)
01866 {
01867 case 'r':
01868 case '<':
01869 case '2':
01870 case 'b':
01871 case 'e':
01872 case 's':
01873 case 'x':
01874 {
01875 int lp;
01876 int max = first_rtl_op (TREE_CODE (x));
01877 for (lp = 0; lp < max; lp++)
01878 {
01879 tmp_before = tmp_nosp = 0;
01880 verify_tree (TREE_OPERAND (x, lp), &tmp_before, &tmp_nosp, NULL_TREE);
01881 merge_tlist (&tmp_nosp, tmp_before, 0);
01882 add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
01883 }
01884 break;
01885 }
01886 }
01887 }
01888
01889
01890
01891
01892 static void
01893 verify_sequence_points (expr)
01894 tree expr;
01895 {
01896 struct tlist *before_sp = 0, *after_sp = 0;
01897
01898 warned_ids = 0;
01899 save_expr_cache = 0;
01900 if (tlist_firstobj == 0)
01901 {
01902 gcc_obstack_init (&tlist_obstack);
01903 tlist_firstobj = obstack_alloc (&tlist_obstack, 0);
01904 }
01905
01906 verify_tree (expr, &before_sp, &after_sp, 0);
01907 warn_for_collisions (after_sp);
01908 obstack_free (&tlist_obstack, tlist_firstobj);
01909 }
01910
01911 tree
01912 c_expand_expr_stmt (expr)
01913 tree expr;
01914 {
01915
01916
01917 if ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
01918 && (flag_isoc99 || lvalue_p (expr)))
01919 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE)
01920 expr = default_conversion (expr);
01921
01922 if (warn_sequence_point)
01923 verify_sequence_points (expr);
01924
01925 if (TREE_TYPE (expr) != error_mark_node
01926 && !COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (expr))
01927 && TREE_CODE (TREE_TYPE (expr)) != ARRAY_TYPE)
01928 error ("expression statement has incomplete type");
01929
01930 last_expr_type = TREE_TYPE (expr);
01931 return add_stmt (build_stmt (EXPR_STMT, expr));
01932 }
01933
01934
01935
01936 tree
01937 check_case_value (value)
01938 tree value;
01939 {
01940 if (value == NULL_TREE)
01941 return value;
01942
01943
01944 STRIP_TYPE_NOPS (value);
01945
01946
01947
01948
01949
01950
01951 if (c_language == clk_cplusplus)
01952 {
01953 value = decl_constant_value (value);
01954 STRIP_TYPE_NOPS (value);
01955 value = fold (value);
01956 }
01957
01958 if (TREE_CODE (value) != INTEGER_CST
01959 && value != error_mark_node)
01960 {
01961 error ("case label does not reduce to an integer constant");
01962 value = error_mark_node;
01963 }
01964 else
01965
01966 value = default_conversion (value);
01967
01968 constant_expression_warning (value);
01969
01970 return value;
01971 }
01972
01973
01974
01975
01976 tree
01977 c_common_type_for_size (bits, unsignedp)
01978 unsigned bits;
01979 int unsignedp;
01980 {
01981 if (bits == TYPE_PRECISION (integer_type_node))
01982 return unsignedp ? unsigned_type_node : integer_type_node;
01983
01984 if (bits == TYPE_PRECISION (signed_char_type_node))
01985 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
01986
01987 if (bits == TYPE_PRECISION (short_integer_type_node))
01988 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
01989
01990 if (bits == TYPE_PRECISION (long_integer_type_node))
01991 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
01992
01993 if (bits == TYPE_PRECISION (long_long_integer_type_node))
01994 return (unsignedp ? long_long_unsigned_type_node
01995 : long_long_integer_type_node);
01996
01997 if (bits == TYPE_PRECISION (widest_integer_literal_type_node))
01998 return (unsignedp ? widest_unsigned_literal_type_node
01999 : widest_integer_literal_type_node);
02000
02001 if (bits <= TYPE_PRECISION (intQI_type_node))
02002 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
02003
02004 if (bits <= TYPE_PRECISION (intHI_type_node))
02005 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
02006
02007 if (bits <= TYPE_PRECISION (intSI_type_node))
02008 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
02009
02010 if (bits <= TYPE_PRECISION (intDI_type_node))
02011 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
02012
02013 return 0;
02014 }
02015
02016
02017
02018
02019
02020 tree
02021 c_common_type_for_mode (mode, unsignedp)
02022 enum machine_mode mode;
02023 int unsignedp;
02024 {
02025 if (mode == TYPE_MODE (integer_type_node))
02026 return unsignedp ? unsigned_type_node : integer_type_node;
02027
02028 if (mode == TYPE_MODE (signed_char_type_node))
02029 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
02030
02031 if (mode == TYPE_MODE (short_integer_type_node))
02032 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
02033
02034 if (mode == TYPE_MODE (long_integer_type_node))
02035 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
02036
02037 if (mode == TYPE_MODE (long_long_integer_type_node))
02038 return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node;
02039
02040 if (mode == TYPE_MODE (widest_integer_literal_type_node))
02041 return unsignedp ? widest_unsigned_literal_type_node
02042 : widest_integer_literal_type_node;
02043
02044 if (mode == QImode)
02045 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
02046
02047 if (mode == HImode)
02048 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
02049
02050 if (mode == SImode)
02051 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
02052
02053 if (mode == DImode)
02054 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
02055
02056 #if HOST_BITS_PER_WIDE_INT >= 64
02057 if (mode == TYPE_MODE (intTI_type_node))
02058 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
02059 #endif
02060
02061 if (mode == TYPE_MODE (float_type_node))
02062 return float_type_node;
02063
02064 if (mode == TYPE_MODE (double_type_node))
02065 return double_type_node;
02066
02067 if (mode == TYPE_MODE (long_double_type_node))
02068 return long_double_type_node;
02069
02070 if (mode == TYPE_MODE (build_pointer_type (char_type_node)))
02071 return build_pointer_type (char_type_node);
02072
02073 if (mode == TYPE_MODE (build_pointer_type (integer_type_node)))
02074 return build_pointer_type (integer_type_node);
02075
02076 switch (mode)
02077 {
02078 case V16QImode:
02079 return unsignedp ? unsigned_V16QI_type_node : V16QI_type_node;
02080 case V8HImode:
02081 return unsignedp ? unsigned_V8HI_type_node : V8HI_type_node;
02082 case V4SImode:
02083 return unsignedp ? unsigned_V4SI_type_node : V4SI_type_node;
02084 case V2DImode:
02085 return unsignedp ? unsigned_V2DI_type_node : V2DI_type_node;
02086 case V2SImode:
02087 return unsignedp ? unsigned_V2SI_type_node : V2SI_type_node;
02088 case V2HImode:
02089 return unsignedp ? unsigned_V2HI_type_node : V2HI_type_node;
02090 case V4HImode:
02091 return unsignedp ? unsigned_V4HI_type_node : V4HI_type_node;
02092 case V8QImode:
02093 return unsignedp ? unsigned_V8QI_type_node : V8QI_type_node;
02094 case V1DImode:
02095 return unsignedp ? unsigned_V1DI_type_node : V1DI_type_node;
02096 case V16SFmode:
02097 return V16SF_type_node;
02098 case V4SFmode:
02099 return V4SF_type_node;
02100 case V2SFmode:
02101 return V2SF_type_node;
02102 case V2DFmode:
02103 return V2DF_type_node;
02104 default:
02105 break;
02106 }
02107
02108 return 0;
02109 }
02110
02111
02112 tree
02113 c_common_unsigned_type (type)
02114 tree type;
02115 {
02116 tree type1 = TYPE_MAIN_VARIANT (type);
02117 if (type1 == signed_char_type_node || type1 == char_type_node)
02118 return unsigned_char_type_node;
02119 if (type1 == integer_type_node)
02120 return unsigned_type_node;
02121 if (type1 == short_integer_type_node)
02122 return short_unsigned_type_node;
02123 if (type1 == long_integer_type_node)
02124 return long_unsigned_type_node;
02125 if (type1 == long_long_integer_type_node)
02126 return long_long_unsigned_type_node;
02127 if (type1 == widest_integer_literal_type_node)
02128 return widest_unsigned_literal_type_node;
02129 #if HOST_BITS_PER_WIDE_INT >= 64
02130 if (type1 == intTI_type_node)
02131 return unsigned_intTI_type_node;
02132 #endif
02133 if (type1 == intDI_type_node)
02134 return unsigned_intDI_type_node;
02135 if (type1 == intSI_type_node)
02136 return unsigned_intSI_type_node;
02137 if (type1 == intHI_type_node)
02138 return unsigned_intHI_type_node;
02139 if (type1 == intQI_type_node)
02140 return unsigned_intQI_type_node;
02141
02142 return c_common_signed_or_unsigned_type (1, type);
02143 }
02144
02145
02146
02147 tree
02148 c_common_signed_type (type)
02149 tree type;
02150 {
02151 tree type1 = TYPE_MAIN_VARIANT (type);
02152 if (type1 == unsigned_char_type_node || type1 == char_type_node)
02153 return signed_char_type_node;
02154 if (type1 == unsigned_type_node)
02155 return integer_type_node;
02156 if (type1 == short_unsigned_type_node)
02157 return short_integer_type_node;
02158 if (type1 == long_unsigned_type_node)
02159 return long_integer_type_node;
02160 if (type1 == long_long_unsigned_type_node)
02161 return long_long_integer_type_node;
02162 if (type1 == widest_unsigned_literal_type_node)
02163 return widest_integer_literal_type_node;
02164 #if HOST_BITS_PER_WIDE_INT >= 64
02165 if (type1 == unsigned_intTI_type_node)
02166 return intTI_type_node;
02167 #endif
02168 if (type1 == unsigned_intDI_type_node)
02169 return intDI_type_node;
02170 if (type1 == unsigned_intSI_type_node)
02171 return intSI_type_node;
02172 if (type1 == unsigned_intHI_type_node)
02173 return intHI_type_node;
02174 if (type1 == unsigned_intQI_type_node)
02175 return intQI_type_node;
02176
02177 return c_common_signed_or_unsigned_type (0, type);
02178 }
02179
02180
02181
02182
02183 tree
02184 c_common_signed_or_unsigned_type (unsignedp, type)
02185 int unsignedp;
02186 tree type;
02187 {
02188 if (! INTEGRAL_TYPE_P (type)
02189 || TREE_UNSIGNED (type) == unsignedp)
02190 return type;
02191
02192 if (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node))
02193 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
02194 if (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
02195 return unsignedp ? unsigned_type_node : integer_type_node;
02196 if (TYPE_PRECISION (type) == TYPE_PRECISION (short_integer_type_node))
02197 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
02198 if (TYPE_PRECISION (type) == TYPE_PRECISION (long_integer_type_node))
02199 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
02200 if (TYPE_PRECISION (type) == TYPE_PRECISION (long_long_integer_type_node))
02201 return (unsignedp ? long_long_unsigned_type_node
02202 : long_long_integer_type_node);
02203 if (TYPE_PRECISION (type) == TYPE_PRECISION (widest_integer_literal_type_node))
02204 return (unsignedp ? widest_unsigned_literal_type_node
02205 : widest_integer_literal_type_node);
02206
02207 #if HOST_BITS_PER_WIDE_INT >= 64
02208 if (TYPE_PRECISION (type) == TYPE_PRECISION (intTI_type_node))
02209 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
02210 #endif
02211 if (TYPE_PRECISION (type) == TYPE_PRECISION (intDI_type_node))
02212 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
02213 if (TYPE_PRECISION (type) == TYPE_PRECISION (intSI_type_node))
02214 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
02215 if (TYPE_PRECISION (type) == TYPE_PRECISION (intHI_type_node))
02216 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
02217 if (TYPE_PRECISION (type) == TYPE_PRECISION (intQI_type_node))
02218 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
02219
02220 return type;
02221 }
02222
02223
02224
02225
02226 unsigned int
02227 min_precision (value, unsignedp)
02228 tree value;
02229 int unsignedp;
02230 {
02231 int log;
02232
02233
02234
02235
02236
02237
02238 if (tree_int_cst_sgn (value) < 0)
02239 value = fold (build1 (BIT_NOT_EXPR, TREE_TYPE (value), value));
02240
02241
02242
02243
02244 if (integer_zerop (value))
02245 log = 0;
02246 else
02247 log = tree_floor_log2 (value);
02248
02249 return log + 1 + ! unsignedp;
02250 }
02251
02252
02253
02254
02255
02256 void
02257 binary_op_error (code)
02258 enum tree_code code;
02259 {
02260 const char *opname;
02261
02262 switch (code)
02263 {
02264 case NOP_EXPR:
02265 error ("invalid truth-value expression");
02266 return;
02267
02268 case PLUS_EXPR:
02269 opname = "+"; break;
02270 case MINUS_EXPR:
02271 opname = "-"; break;
02272 case MULT_EXPR:
02273 opname = "*"; break;
02274 case MAX_EXPR:
02275 opname = "max"; break;
02276 case MIN_EXPR:
02277 opname = "min"; break;
02278 case EQ_EXPR:
02279 opname = "=="; break;
02280 case NE_EXPR:
02281 opname = "!="; break;
02282 case LE_EXPR:
02283 opname = "<="; break;
02284 case GE_EXPR:
02285 opname = ">="; break;
02286 case LT_EXPR:
02287 opname = "<"; break;
02288 case GT_EXPR:
02289 opname = ">"; break;
02290 case LSHIFT_EXPR:
02291 opname = "<<"; break;
02292 case RSHIFT_EXPR:
02293 opname = ">>"; break;
02294 case TRUNC_MOD_EXPR:
02295 case FLOOR_MOD_EXPR:
02296 opname = "%"; break;
02297 case TRUNC_DIV_EXPR:
02298 case FLOOR_DIV_EXPR:
02299 opname = "/"; break;
02300 case BIT_AND_EXPR:
02301 opname = "&"; break;
02302 case BIT_IOR_EXPR:
02303 opname = "|"; break;
02304 case TRUTH_ANDIF_EXPR:
02305 opname = "&&"; break;
02306 case TRUTH_ORIF_EXPR:
02307 opname = "||"; break;
02308 case BIT_XOR_EXPR:
02309 opname = "^"; break;
02310 case LROTATE_EXPR:
02311 case RROTATE_EXPR:
02312 opname = "rotate"; break;
02313 default:
02314 opname = "unknown"; break;
02315 }
02316 error ("invalid operands to binary %s", opname);
02317 }
02318
02319
02320
02321
02322
02323
02324
02325
02326
02327
02328
02329
02330
02331
02332
02333 tree
02334 shorten_compare (op0_ptr, op1_ptr, restype_ptr, rescode_ptr)
02335 tree *op0_ptr, *op1_ptr;
02336 tree *restype_ptr;
02337 enum tree_code *rescode_ptr;
02338 {
02339 tree type;
02340 tree op0 = *op0_ptr;
02341 tree op1 = *op1_ptr;
02342 int unsignedp0, unsignedp1;
02343 int real1, real2;
02344 tree primop0, primop1;
02345 enum tree_code code = *rescode_ptr;
02346
02347
02348
02349
02350 primop0 = get_narrower (op0, &unsignedp0);
02351 primop1 = get_narrower (op1, &unsignedp1);
02352
02353
02354
02355
02356 if (op0 == primop0 && TREE_TYPE (op0) != *restype_ptr)
02357 unsignedp0 = TREE_UNSIGNED (TREE_TYPE (op0));
02358 if (op1 == primop1 && TREE_TYPE (op1) != *restype_ptr)
02359 unsignedp1 = TREE_UNSIGNED (TREE_TYPE (op1));
02360
02361
02362 real1 = TREE_CODE (TREE_TYPE (primop0)) == REAL_TYPE;
02363 real2 = TREE_CODE (TREE_TYPE (primop1)) == REAL_TYPE;
02364
02365
02366
02367
02368
02369 if (TREE_CONSTANT (primop0)
02370 && ! integer_zerop (primop1) && ! real_zerop (primop1))
02371 {
02372 tree tem = primop0;
02373 int temi = unsignedp0;
02374 primop0 = primop1;
02375 primop1 = tem;
02376 tem = op0;
02377 op0 = op1;
02378 op1 = tem;
02379 *op0_ptr = op0;
02380 *op1_ptr = op1;
02381 unsignedp0 = unsignedp1;
02382 unsignedp1 = temi;
02383 temi = real1;
02384 real1 = real2;
02385 real2 = temi;
02386
02387 switch (code)
02388 {
02389 case LT_EXPR:
02390 code = GT_EXPR;
02391 break;
02392 case GT_EXPR:
02393 code = LT_EXPR;
02394 break;
02395 case LE_EXPR:
02396 code = GE_EXPR;
02397 break;
02398 case GE_EXPR:
02399 code = LE_EXPR;
02400 break;
02401 default:
02402 break;
02403 }
02404 *rescode_ptr = code;
02405 }
02406
02407
02408
02409
02410
02411
02412
02413
02414
02415
02416
02417
02418
02419
02420
02421
02422
02423
02424 if (!real1 && !real2
02425 && TREE_CODE (primop1) == INTEGER_CST
02426 && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr))
02427 {
02428 int min_gt, max_gt, min_lt, max_lt;
02429 tree maxval, minval;
02430
02431 int unsignedp = TREE_UNSIGNED (*restype_ptr);
02432 tree val;
02433
02434 type = c_common_signed_or_unsigned_type (unsignedp0,
02435 TREE_TYPE (primop0));
02436
02437
02438
02439
02440 if (TREE_CODE (type) == ENUMERAL_TYPE)
02441 type = c_common_type_for_size (TYPE_PRECISION (type), unsignedp0);
02442
02443 maxval = TYPE_MAX_VALUE (type);
02444 minval = TYPE_MIN_VALUE (type);
02445
02446 if (unsignedp && !unsignedp0)
02447 *restype_ptr = c_common_signed_type (*restype_ptr);
02448
02449 if (TREE_TYPE (primop1) != *restype_ptr)
02450 primop1 = convert (*restype_ptr, primop1);
02451 if (type != *restype_ptr)
02452 {
02453 minval = convert (*restype_ptr, minval);
02454 maxval = convert (*restype_ptr, maxval);
02455 }
02456
02457 if (unsignedp && unsignedp0)
02458 {
02459 min_gt = INT_CST_LT_UNSIGNED (primop1, minval);
02460 max_gt = INT_CST_LT_UNSIGNED (primop1, maxval);
02461 min_lt = INT_CST_LT_UNSIGNED (minval, primop1);
02462 max_lt = INT_CST_LT_UNSIGNED (maxval, primop1);
02463 }
02464 else
02465 {
02466 min_gt = INT_CST_LT (primop1, minval);
02467 max_gt = INT_CST_LT (primop1, maxval);
02468 min_lt = INT_CST_LT (minval, primop1);
02469 max_lt = INT_CST_LT (maxval, primop1);
02470 }
02471
02472 val = 0;
02473
02474 if (code == NE_EXPR)
02475 {
02476 if (max_lt || min_gt)
02477 val = boolean_true_node;
02478 }
02479 else if (code == EQ_EXPR)
02480 {
02481 if (max_lt || min_gt)
02482 val = boolean_false_node;
02483 }
02484 else if (code == LT_EXPR)
02485 {
02486 if (max_lt)
02487 val = boolean_true_node;
02488 if (!min_lt)
02489 val = boolean_false_node;
02490 }
02491 else if (code == GT_EXPR)
02492 {
02493 if (min_gt)
02494 val = boolean_true_node;
02495 if (!max_gt)
02496 val = boolean_false_node;
02497 }
02498 else if (code == LE_EXPR)
02499 {
02500 if (!max_gt)
02501 val = boolean_true_node;
02502 if (min_gt)
02503 val = boolean_false_node;
02504 }
02505 else if (code == GE_EXPR)
02506 {
02507 if (!min_lt)
02508 val = boolean_true_node;
02509 if (max_lt)
02510 val = boolean_false_node;
02511 }
02512
02513
02514
02515
02516
02517
02518
02519
02520
02521
02522
02523
02524 if (unsignedp && !unsignedp0)
02525 {
02526 if (val != 0)
02527 switch (code)
02528 {
02529 case LT_EXPR:
02530 case GE_EXPR:
02531 primop1 = TYPE_MIN_VALUE (type);
02532 val = 0;
02533 break;
02534
02535 case LE_EXPR:
02536 case GT_EXPR:
02537 primop1 = TYPE_MAX_VALUE (type);
02538 val = 0;
02539 break;
02540
02541 default:
02542 break;
02543 }
02544 type = c_common_unsigned_type (type);
02545 }
02546
02547 if (TREE_CODE (primop0) != INTEGER_CST)
02548 {
02549 if (val == boolean_false_node)
02550 warning ("comparison is always false due to limited range of data type");
02551 if (val == boolean_true_node)
02552 warning ("comparison is always true due to limited range of data type");
02553 }
02554
02555 if (val != 0)
02556 {
02557
02558 if (TREE_SIDE_EFFECTS (primop0))
02559 return build (COMPOUND_EXPR, TREE_TYPE (val), primop0, val);
02560 return val;
02561 }
02562
02563
02564
02565
02566 }
02567 else if (real1 && real2
02568 && (TYPE_PRECISION (TREE_TYPE (primop0))
02569 == TYPE_PRECISION (TREE_TYPE (primop1))))
02570 type = TREE_TYPE (primop0);
02571
02572
02573
02574
02575
02576
02577
02578
02579
02580 else if (unsignedp0 == unsignedp1 && real1 == real2
02581 && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr)
02582 && TYPE_PRECISION (TREE_TYPE (primop1)) < TYPE_PRECISION (*restype_ptr))
02583 {
02584 type = common_type (TREE_TYPE (primop0), TREE_TYPE (primop1));
02585 type = c_common_signed_or_unsigned_type (unsignedp0
02586 || TREE_UNSIGNED (*restype_ptr),
02587 type);
02588
02589
02590 primop0
02591 = convert (c_common_signed_or_unsigned_type (unsignedp0,
02592 TREE_TYPE (primop0)),
02593 primop0);
02594 primop1
02595 = convert (c_common_signed_or_unsigned_type (unsignedp1,
02596 TREE_TYPE (primop1)),
02597 primop1);
02598 }
02599 else
02600 {
02601
02602
02603 type = *restype_ptr;
02604 primop0 = op0;
02605 primop1 = op1;
02606
02607 if (!real1 && !real2 && integer_zerop (primop1)
02608 && TREE_UNSIGNED (*restype_ptr))
02609 {
02610 tree value = 0;
02611 switch (code)
02612 {
02613 case GE_EXPR:
02614
02615
02616
02617
02618 if (extra_warnings && !in_system_header
02619 && ! (TREE_CODE (primop0) == INTEGER_CST
02620 && ! TREE_OVERFLOW (convert (c_common_signed_type (type),
02621 primop0))))
02622 warning ("comparison of unsigned expression >= 0 is always true");
02623 value = boolean_true_node;
02624 break;
02625
02626 case LT_EXPR:
02627 if (extra_warnings && !in_system_header
02628 && ! (TREE_CODE (primop0) == INTEGER_CST
02629 && ! TREE_OVERFLOW (convert (c_common_signed_type (type),
02630 primop0))))
02631 warning ("comparison of unsigned expression < 0 is always false");
02632 value = boolean_false_node;
02633 break;
02634
02635 default:
02636 break;
02637 }
02638
02639 if (value != 0)
02640 {
02641
02642 if (TREE_SIDE_EFFECTS (primop0))
02643 return build (COMPOUND_EXPR, TREE_TYPE (value),
02644 primop0, value);
02645 return value;
02646 }
02647 }
02648 }
02649
02650 *op0_ptr = convert (type, primop0);
02651 *op1_ptr = convert (type, primop1);
02652
02653 *restype_ptr = boolean_type_node;
02654
02655 return 0;
02656 }
02657
02658
02659
02660
02661 tree
02662 pointer_int_sum (resultcode, ptrop, intop)
02663 enum tree_code resultcode;
02664 tree ptrop, intop;
02665 {
02666 tree size_exp;
02667
02668 tree result;
02669 tree folded;
02670
02671
02672
02673 tree result_type = TREE_TYPE (ptrop);
02674
02675 if (TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE)
02676 {
02677 if (pedantic || warn_pointer_arith)
02678 pedwarn ("pointer of type `void *' used in arithmetic");
02679 size_exp = integer_one_node;
02680 }
02681 else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE)
02682 {
02683 if (pedantic || warn_pointer_arith)
02684 pedwarn ("pointer to a function used in arithmetic");
02685 size_exp = integer_one_node;
02686 }
02687 else if (TREE_CODE (TREE_TYPE (result_type)) == METHOD_TYPE)
02688 {
02689 if (pedantic || warn_pointer_arith)
02690 pedwarn ("pointer to member function used in arithmetic");
02691 size_exp = integer_one_node;
02692 }
02693 else if (TREE_CODE (TREE_TYPE (result_type)) == OFFSET_TYPE)
02694 {
02695 if (pedantic || warn_pointer_arith)
02696 pedwarn ("pointer to a member used in arithmetic");
02697 size_exp = integer_one_node;
02698 }
02699 else
02700 size_exp = size_in_bytes (TREE_TYPE (result_type));
02701
02702
02703
02704
02705
02706
02707 if ((TREE_CODE (intop) == PLUS_EXPR || TREE_CODE (intop) == MINUS_EXPR)
02708 && ! TREE_CONSTANT (intop)
02709 && TREE_CONSTANT (TREE_OPERAND (intop, 1))
02710 && TREE_CONSTANT (size_exp)
02711
02712
02713 && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop, 0))) == INTEGER_TYPE
02714
02715
02716
02717 && (! TREE_UNSIGNED (TREE_TYPE (intop))
02718 || (TYPE_PRECISION (TREE_TYPE (intop))
02719 == TYPE_PRECISION (TREE_TYPE (ptrop)))))
02720 {
02721 enum tree_code subcode = resultcode;
02722 tree int_type = TREE_TYPE (intop);
02723 if (TREE_CODE (intop) == MINUS_EXPR)
02724 subcode = (subcode == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR);
02725
02726
02727
02728 ptrop = build_binary_op (subcode, ptrop,
02729 convert (int_type, TREE_OPERAND (intop, 1)), 1);
02730 intop = convert (int_type, TREE_OPERAND (intop, 0));
02731 }
02732
02733
02734
02735
02736 if (TYPE_PRECISION (TREE_TYPE (intop)) != TYPE_PRECISION (sizetype)
02737 || TREE_UNSIGNED (TREE_TYPE (intop)) != TREE_UNSIGNED (sizetype))
02738 intop = convert (c_common_type_for_size (TYPE_PRECISION (sizetype),
02739 TREE_UNSIGNED (sizetype)), intop);
02740
02741
02742
02743
02744
02745 intop = convert (result_type,
02746 build_binary_op (MULT_EXPR, intop,
02747 convert (TREE_TYPE (intop), size_exp), 1));
02748
02749
02750
02751 result = build (resultcode, result_type, ptrop, intop);
02752
02753 folded = fold (result);
02754 if (folded == result)
02755 TREE_CONSTANT (folded) = TREE_CONSTANT (ptrop) & TREE_CONSTANT (intop);
02756 return folded;
02757 }
02758
02759
02760
02761
02762
02763
02764
02765
02766
02767
02768
02769
02770 tree
02771 c_common_truthvalue_conversion (expr)
02772 tree expr;
02773 {
02774 if (TREE_CODE (expr) == ERROR_MARK)
02775 return expr;
02776
02777 #if 0
02778
02779
02780 switch (TREE_CODE (TREE_TYPE (expr)))
02781 {
02782 case RECORD_TYPE:
02783 error ("struct type value used where scalar is required");
02784 return boolean_false_node;
02785
02786 case UNION_TYPE:
02787 error ("union type value used where scalar is required");
02788 return boolean_false_node;
02789
02790 case ARRAY_TYPE:
02791 error ("array type value used where scalar is required");
02792 return boolean_false_node;
02793
02794 default:
02795 break;
02796 }
02797 #endif
02798
02799 switch (TREE_CODE (expr))
02800 {
02801 case EQ_EXPR:
02802 case NE_EXPR: case LE_EXPR: case GE_EXPR: case LT_EXPR: case GT_EXPR:
02803 case TRUTH_ANDIF_EXPR:
02804 case TRUTH_ORIF_EXPR:
02805 case TRUTH_AND_EXPR:
02806 case TRUTH_OR_EXPR:
02807 case TRUTH_XOR_EXPR:
02808 case TRUTH_NOT_EXPR:
02809 TREE_TYPE (expr) = boolean_type_node;
02810 return expr;
02811
02812 case ERROR_MARK:
02813 return expr;
02814
02815 case INTEGER_CST:
02816 #ifdef KEY // bug 2684
02817 if (TREE_CONSTANT_OVERFLOW (expr))
02818 break;
02819 #endif
02820 return integer_zerop (expr) ? boolean_false_node : boolean_true_node;
02821
02822 case REAL_CST:
02823 #ifdef KEY // bug 2684
02824 if (TREE_CONSTANT_OVERFLOW (expr))
02825 break;
02826 #endif
02827 return real_zerop (expr) ? boolean_false_node : boolean_true_node;
02828
02829 case ADDR_EXPR:
02830
02831
02832 if (DECL_P (TREE_OPERAND (expr, 0))
02833 && DECL_EXTERNAL (TREE_OPERAND (expr, 0)))
02834 break;
02835
02836 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 0)))
02837 return build (COMPOUND_EXPR, boolean_type_node,
02838 TREE_OPERAND (expr, 0), boolean_true_node);
02839 else
02840 return boolean_true_node;
02841
02842 case COMPLEX_EXPR:
02843 return build_binary_op ((TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1))
02844 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
02845 c_common_truthvalue_conversion (TREE_OPERAND (expr, 0)),
02846 c_common_truthvalue_conversion (TREE_OPERAND (expr, 1)),
02847 0);
02848
02849 case NEGATE_EXPR:
02850 case ABS_EXPR:
02851 case FLOAT_EXPR:
02852 case FFS_EXPR:
02853
02854 return c_common_truthvalue_conversion (TREE_OPERAND (expr, 0));
02855
02856 case LROTATE_EXPR:
02857 case RROTATE_EXPR:
02858
02859
02860 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1)))
02861 return build (COMPOUND_EXPR, boolean_type_node, TREE_OPERAND (expr, 1),
02862 c_common_truthvalue_conversion (TREE_OPERAND (expr, 0)));
02863 else
02864 return c_common_truthvalue_conversion (TREE_OPERAND (expr, 0));
02865
02866 case COND_EXPR:
02867
02868 return fold (build (COND_EXPR, boolean_type_node, TREE_OPERAND (expr, 0),
02869 c_common_truthvalue_conversion (TREE_OPERAND (expr, 1)),
02870 c_common_truthvalue_conversion (TREE_OPERAND (expr, 2))));
02871
02872 case CONVERT_EXPR:
02873
02874
02875 if (TREE_CODE (TREE_TYPE (expr)) == REFERENCE_TYPE
02876 || TREE_CODE (TREE_TYPE (TREE_OPERAND (expr, 0))) == REFERENCE_TYPE)
02877 break;
02878
02879 case NOP_EXPR:
02880
02881 if (TYPE_PRECISION (TREE_TYPE (expr))
02882 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0))))
02883 return c_common_truthvalue_conversion (TREE_OPERAND (expr, 0));
02884 break;
02885
02886 case MINUS_EXPR:
02887
02888
02889
02890
02891
02892
02893
02894
02895 if (HONOR_INFINITIES (TYPE_MODE (TREE_TYPE (TREE_OPERAND (expr, 0)))))
02896 break;
02897
02898 case BIT_XOR_EXPR:
02899
02900
02901 if (TREE_TYPE (TREE_OPERAND (expr, 0))
02902 == TREE_TYPE (TREE_OPERAND (expr, 1)))
02903 return build_binary_op (NE_EXPR, TREE_OPERAND (expr, 0),
02904 TREE_OPERAND (expr, 1), 1);
02905 return build_binary_op (NE_EXPR, TREE_OPERAND (expr, 0),
02906 fold (build1 (NOP_EXPR,
02907 TREE_TYPE (TREE_OPERAND (expr, 0)),
02908 TREE_OPERAND (expr, 1))), 1);
02909
02910 case BIT_AND_EXPR:
02911 if (integer_onep (TREE_OPERAND (expr, 1))
02912 && TREE_TYPE (expr) != boolean_type_node)
02913
02914 return build1 (NOP_EXPR, boolean_type_node, expr);
02915 break;
02916
02917 case MODIFY_EXPR:
02918 if (warn_parentheses && C_EXP_ORIGINAL_CODE (expr) == MODIFY_EXPR)
02919 warning ("suggest parentheses around assignment used as truth value");
02920 break;
02921
02922 default:
02923 break;
02924 }
02925
02926 if (TREE_CODE (TREE_TYPE (expr)) == COMPLEX_TYPE)
02927 {
02928 tree t = save_expr (expr);
02929 return (build_binary_op
02930 ((TREE_SIDE_EFFECTS (expr)
02931 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
02932 c_common_truthvalue_conversion (build_unary_op (REALPART_EXPR, t, 0)),
02933 c_common_truthvalue_conversion (build_unary_op (IMAGPART_EXPR, t, 0)),
02934 0));
02935 }
02936
02937 return build_binary_op (NE_EXPR, expr, integer_zero_node, 1);
02938 }
02939
02940 static tree builtin_function_2 PARAMS ((const char *, const char *, tree, tree,
02941 int, enum built_in_class, int, int,
02942 tree));
02943
02944
02945
02946
02947 tree
02948 c_build_qualified_type (type, type_quals)
02949 tree type;
02950 int type_quals;
02951 {
02952
02953
02954
02955
02956
02957
02958
02959 if ((type_quals & TYPE_QUAL_RESTRICT)
02960 && (!POINTER_TYPE_P (type)
02961 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type))))
02962 {
02963 error ("invalid use of `restrict'");
02964 type_quals &= ~TYPE_QUAL_RESTRICT;
02965 }
02966
02967 if (TREE_CODE (type) == ARRAY_TYPE)
02968 return build_array_type (c_build_qualified_type (TREE_TYPE (type),
02969 type_quals),
02970 TYPE_DOMAIN (type));
02971 return build_qualified_type (type, type_quals);
02972 }
02973
02974
02975
02976 void
02977 c_apply_type_quals_to_decl (type_quals, decl)
02978 int type_quals;
02979 tree decl;
02980 {
02981 if ((type_quals & TYPE_QUAL_CONST)
02982 || (TREE_TYPE (decl)
02983 && TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE))
02984 TREE_READONLY (decl) = 1;
02985 if (type_quals & TYPE_QUAL_VOLATILE)
02986 {
02987 TREE_SIDE_EFFECTS (decl) = 1;
02988 TREE_THIS_VOLATILE (decl) = 1;
02989 }
02990 if (type_quals & TYPE_QUAL_RESTRICT)
02991 {
02992 if (!TREE_TYPE (decl)
02993 || !POINTER_TYPE_P (TREE_TYPE (decl))
02994 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (TREE_TYPE (decl))))
02995 error ("invalid use of `restrict'");
02996 else if (flag_strict_aliasing)
02997
02998
02999
03000 DECL_POINTER_ALIAS_SET (decl) = -2;
03001 }
03002 }
03003
03004
03005
03006
03007 HOST_WIDE_INT
03008 c_common_get_alias_set (t)
03009 tree t;
03010 {
03011 tree u;
03012
03013
03014
03015
03016
03017
03018
03019 for (u = t;
03020 TREE_CODE (u) == COMPONENT_REF || TREE_CODE (u) == ARRAY_REF;
03021 u = TREE_OPERAND (u, 0))
03022 if (TREE_CODE (u) == COMPONENT_REF
03023 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u, 0))) == UNION_TYPE)
03024 return 0;
03025
03026
03027 if (! TYPE_P (t))
03028 return -1;
03029
03030
03031
03032 if (t == char_type_node
03033 || t == signed_char_type_node
03034 || t == unsigned_char_type_node)
03035 return 0;
03036
03037
03038 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (t)))
03039 return 0;
03040
03041
03042
03043
03044 if (TREE_CODE (t) == INTEGER_TYPE && TREE_UNSIGNED (t))
03045 {
03046 tree t1 = c_common_signed_type (t);
03047
03048
03049 if (t1 != t)
03050 return get_alias_set (t1);
03051 }
03052 else if (POINTER_TYPE_P (t))
03053 {
03054 tree t1;
03055
03056
03057
03058
03059
03060
03061
03062
03063
03064
03065
03066
03067
03068
03069
03070
03071
03072
03073
03074
03075
03076
03077
03078
03079 t1 = build_type_no_quals (t);
03080 if (t1 != t)
03081 return get_alias_set (t1);
03082 }
03083
03084 return -1;
03085 }
03086
03087
03088
03089
03090
03091 tree
03092 c_sizeof_or_alignof_type (type, op, complain)
03093 tree type;
03094 enum tree_code op;
03095 int complain;
03096 {
03097 const char *op_name;
03098 tree value = NULL;
03099 enum tree_code type_code = TREE_CODE (type);
03100
03101 my_friendly_assert (op == SIZEOF_EXPR || op == ALIGNOF_EXPR, 20020720);
03102 op_name = op == SIZEOF_EXPR ? "sizeof" : "__alignof__";
03103
03104 if (type_code == FUNCTION_TYPE)
03105 {
03106 if (op == SIZEOF_EXPR)
03107 {
03108 if (complain && (pedantic || warn_pointer_arith))
03109 pedwarn ("invalid application of `sizeof' to a function type");
03110 value = size_one_node;
03111 }
03112 else
03113 value = size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
03114 }
03115 else if (type_code == VOID_TYPE || type_code == ERROR_MARK)
03116 {
03117 if (type_code == VOID_TYPE
03118 && complain && (pedantic || warn_pointer_arith))
03119 pedwarn ("invalid application of `%s' to a void type", op_name);
03120 value = size_one_node;
03121 }
03122 else if (!COMPLETE_TYPE_P (type))
03123 {
03124 if (complain)
03125 error ("invalid application of `%s' to an incomplete type", op_name);
03126 value = size_zero_node;
03127 }
03128 else
03129 {
03130 if (op == SIZEOF_EXPR)
03131
03132 value = size_binop (CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
03133 size_int (TYPE_PRECISION (char_type_node)
03134 / BITS_PER_UNIT));
03135 else
03136 value = size_int (TYPE_ALIGN (type) / BITS_PER_UNIT);
03137 }
03138
03139
03140
03141
03142
03143 value = fold (build1 (NOP_EXPR, size_type_node, value));
03144 my_friendly_assert (!TYPE_IS_SIZETYPE (TREE_TYPE (value)), 20001021);
03145
03146 return value;
03147 }
03148
03149
03150
03151
03152
03153
03154 tree
03155 c_alignof_expr (expr)
03156 tree expr;
03157 {
03158 tree t;
03159
03160 if (TREE_CODE (expr) == VAR_DECL)
03161 t = size_int (DECL_ALIGN (expr) / BITS_PER_UNIT);
03162
03163 else if (TREE_CODE (expr) == COMPONENT_REF
03164 && DECL_C_BIT_FIELD (TREE_OPERAND (expr, 1)))
03165 {
03166 error ("`__alignof' applied to a bit-field");
03167 t = size_one_node;
03168 }
03169 else if (TREE_CODE (expr) == COMPONENT_REF
03170 && TREE_CODE (TREE_OPERAND (expr, 1)) == FIELD_DECL)
03171 t = size_int (DECL_ALIGN (TREE_OPERAND (expr, 1)) / BITS_PER_UNIT);
03172
03173 else if (TREE_CODE (expr) == INDIRECT_REF)
03174 {
03175 tree t = TREE_OPERAND (expr, 0);
03176 tree best = t;
03177 int bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
03178
03179 while (TREE_CODE (t) == NOP_EXPR
03180 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
03181 {
03182 int thisalign;
03183
03184 t = TREE_OPERAND (t, 0);
03185 thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
03186 if (thisalign > bestalign)
03187 best = t, bestalign = thisalign;
03188 }
03189 return c_alignof (TREE_TYPE (TREE_TYPE (best)));
03190 }
03191 else
03192 return c_alignof (TREE_TYPE (expr));
03193
03194 return fold (build1 (NOP_EXPR, size_type_node, t));
03195 }
03196
03197
03198
03199 enum built_in_attribute
03200 {
03201 #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
03202 #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
03203 #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
03204 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
03205 #define DEF_FN_ATTR(NAME, ATTRS, PREDICATE)
03206 #include "builtin-attrs.def"
03207 #undef DEF_ATTR_NULL_TREE
03208 #undef DEF_ATTR_INT
03209 #undef DEF_ATTR_IDENT
03210 #undef DEF_ATTR_TREE_LIST
03211 #undef DEF_FN_ATTR
03212 ATTR_LAST
03213 };
03214
03215 static GTY(()) tree built_in_attributes[(int) ATTR_LAST];
03216
03217 static bool c_attrs_initialized = false;
03218
03219 static void c_init_attributes PARAMS ((void));
03220
03221
03222
03223
03224 void
03225 c_common_nodes_and_builtins ()
03226 {
03227 enum builtin_type
03228 {
03229 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
03230 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
03231 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
03232 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
03233 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
03234 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
03235 #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
03236 #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
03237 #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
03238 #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
03239 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
03240 #if defined(TARG_SL)
03241 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
03242 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) NAME,
03243 #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) NAME,
03244 #define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8) NAME,
03245 #define DEF_FUNCTION_TYPE_9(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8, ARG9) NAME,
03246 #endif // TARG_SL
03247 #include "builtin-types.def"
03248 #undef DEF_PRIMITIVE_TYPE
03249 #undef DEF_FUNCTION_TYPE_0
03250 #undef DEF_FUNCTION_TYPE_1
03251 #undef DEF_FUNCTION_TYPE_2
03252 #undef DEF_FUNCTION_TYPE_3
03253 #undef DEF_FUNCTION_TYPE_4
03254 #undef DEF_FUNCTION_TYPE_VAR_0
03255 #undef DEF_FUNCTION_TYPE_VAR_1
03256 #undef DEF_FUNCTION_TYPE_VAR_2
03257 #undef DEF_FUNCTION_TYPE_VAR_3
03258 #undef DEF_POINTER_TYPE
03259 #ifdef TARG_SL
03260 #undef DEF_FUNCTION_TYPE_5
03261 #undef DEF_FUNCTION_TYPE_6
03262 #undef DEF_FUNCTION_TYPE_7
03263 #undef DEF_FUNCTION_TYPE_8
03264 #undef DEF_FUNCTION_TYPE_9
03265 #endif
03266 BT_LAST
03267 };
03268
03269 typedef enum builtin_type builtin_type;
03270
03271 tree builtin_types[(int) BT_LAST];
03272 int wchar_type_size;
03273 tree array_domain_type;
03274 tree va_list_ref_type_node;
03275 tree va_list_arg_type_node;
03276
03277
03278 record_builtin_type (RID_INT, NULL, integer_type_node);
03279 record_builtin_type (RID_CHAR, "char", char_type_node);
03280
03281
03282
03283
03284 if (c_language == clk_cplusplus)
03285 record_builtin_type (RID_SIGNED, NULL, integer_type_node);
03286 record_builtin_type (RID_LONG, "long int", long_integer_type_node);
03287 record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node);
03288 record_builtin_type (RID_MAX, "long unsigned int",
03289 long_unsigned_type_node);
03290 if (c_language == clk_cplusplus)
03291 record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node);
03292 record_builtin_type (RID_MAX, "long long int",
03293 long_long_integer_type_node);
03294 record_builtin_type (RID_MAX, "long long unsigned int",
03295 long_long_unsigned_type_node);
03296 if (c_language == clk_cplusplus)
03297 record_builtin_type (RID_MAX, "long long unsigned",
03298 long_long_unsigned_type_node);
03299 record_builtin_type (RID_SHORT, "short int", short_integer_type_node);
03300 record_builtin_type (RID_MAX, "short unsigned int",
03301 short_unsigned_type_node);
03302 if (c_language == clk_cplusplus)
03303 record_builtin_type (RID_MAX, "unsigned short",
03304 short_unsigned_type_node);
03305
03306
03307 record_builtin_type (RID_MAX, "signed char", signed_char_type_node);
03308 record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node);
03309
03310
03311
03312 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, NULL_TREE,
03313 intQI_type_node));
03314 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, NULL_TREE,
03315 intHI_type_node));
03316 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, NULL_TREE,
03317 intSI_type_node));
03318 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, NULL_TREE,
03319 intDI_type_node));
03320 #if HOST_BITS_PER_WIDE_INT >= 64
03321 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
03322 get_identifier ("__int128_t"),
03323 intTI_type_node));
03324 #endif
03325 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, NULL_TREE,
03326 unsigned_intQI_type_node));
03327 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, NULL_TREE,
03328 unsigned_intHI_type_node));
03329 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, NULL_TREE,
03330 unsigned_intSI_type_node));
03331 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, NULL_TREE,
03332 unsigned_intDI_type_node));
03333 #if HOST_BITS_PER_WIDE_INT >= 64
03334 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
03335 get_identifier ("__uint128_t"),
03336 unsigned_intTI_type_node));
03337 #endif
03338
03339
03340 widest_integer_literal_type_node
03341 = make_signed_type (HOST_BITS_PER_WIDE_INT * 2);
03342 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, NULL_TREE,
03343 widest_integer_literal_type_node));
03344
03345 widest_unsigned_literal_type_node
03346 = make_unsigned_type (HOST_BITS_PER_WIDE_INT * 2);
03347 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, NULL_TREE,
03348 widest_unsigned_literal_type_node));
03349
03350
03351
03352
03353 size_type_node =
03354 TREE_TYPE (identifier_global_value (get_identifier (SIZE_TYPE)));
03355 signed_size_type_node = c_common_signed_type (size_type_node);
03356 set_sizetype (size_type_node);
03357
03358 build_common_tree_nodes_2 (flag_short_double);
03359
03360 record_builtin_type (RID_FLOAT, NULL, float_type_node);
03361 record_builtin_type (RID_DOUBLE, NULL, double_type_node);
03362 record_builtin_type (RID_MAX, "long double", long_double_type_node);
03363
03364 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
03365 get_identifier ("complex int"),
03366 complex_integer_type_node));
03367 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
03368 get_identifier ("complex float"),
03369 complex_float_type_node));
03370 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
03371 get_identifier ("complex double"),
03372 complex_double_type_node));
03373 (*lang_hooks.decls.pushdecl)
03374 (build_decl (TYPE_DECL, get_identifier ("complex long double"),
03375 complex_long_double_type_node));
03376
03377
03378
03379
03380 if (TYPE_PRECISION (float_type_node)
03381 == TYPE_PRECISION (long_integer_type_node))
03382 {
03383 g77_integer_type_node = long_integer_type_node;
03384 g77_uinteger_type_node = long_unsigned_type_node;
03385 }
03386 else if (TYPE_PRECISION (float_type_node)
03387 == TYPE_PRECISION (integer_type_node))
03388 {
03389 g77_integer_type_node = integer_type_node;
03390 g77_uinteger_type_node = unsigned_type_node;
03391 }
03392 else
03393 g77_integer_type_node = g77_uinteger_type_node = NULL_TREE;
03394
03395 if (g77_integer_type_node != NULL_TREE)
03396 {
03397 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
03398 get_identifier ("__g77_integer"),
03399 g77_integer_type_node));
03400 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
03401 get_identifier ("__g77_uinteger"),
03402 g77_uinteger_type_node));
03403 }
03404
03405 if (TYPE_PRECISION (float_type_node) * 2
03406 == TYPE_PRECISION (long_integer_type_node))
03407 {
03408 g77_longint_type_node = long_integer_type_node;
03409 g77_ulongint_type_node = long_unsigned_type_node;
03410 }
03411 else if (TYPE_PRECISION (float_type_node) * 2
03412 == TYPE_PRECISION (long_long_integer_type_node))
03413 {
03414 g77_longint_type_node = long_long_integer_type_node;
03415 g77_ulongint_type_node = long_long_unsigned_type_node;
03416 }
03417 else
03418 g77_longint_type_node = g77_ulongint_type_node = NULL_TREE;
03419
03420 if (g77_longint_type_node != NULL_TREE)
03421 {
03422 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
03423 get_identifier ("__g77_longint"),
03424 g77_longint_type_node));
03425 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
03426 get_identifier ("__g77_ulongint"),
03427 g77_ulongint_type_node));
03428 }
03429
03430 record_builtin_type (RID_VOID, NULL, void_type_node);
03431
03432 void_zero_node = build_int_2 (0, 0);
03433 TREE_TYPE (void_zero_node) = void_type_node;
03434
03435 void_list_node = build_void_list_node ();
03436
03437
03438
03439
03440
03441
03442 array_domain_type = build_index_type (size_int (200));
03443
03444
03445
03446
03447 char_array_type_node
03448 = build_array_type (char_type_node, array_domain_type);
03449
03450
03451 int_array_type_node
03452 = build_array_type (integer_type_node, array_domain_type);
03453
03454 string_type_node = build_pointer_type (char_type_node);
03455 const_string_type_node
03456 = build_pointer_type (build_qualified_type
03457 (char_type_node, TYPE_QUAL_CONST));
03458
03459
03460 wchar_type_node = get_identifier (MODIFIED_WCHAR_TYPE);
03461 wchar_type_node = TREE_TYPE (identifier_global_value (wchar_type_node));
03462 wchar_type_size = TYPE_PRECISION (wchar_type_node);
03463 if (c_language == clk_cplusplus)
03464 {
03465 if (TREE_UNSIGNED (wchar_type_node))
03466 wchar_type_node = make_unsigned_type (wchar_type_size);
03467 else
03468 wchar_type_node = make_signed_type (wchar_type_size);
03469 record_builtin_type (RID_WCHAR, "wchar_t", wchar_type_node);
03470 }
03471 else
03472 {
03473 signed_wchar_type_node = c_common_signed_type (wchar_type_node);
03474 unsigned_wchar_type_node = c_common_unsigned_type (wchar_type_node);
03475 }
03476
03477
03478 wchar_array_type_node
03479 = build_array_type (wchar_type_node, array_domain_type);
03480
03481 wint_type_node =
03482 TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE)));
03483
03484 intmax_type_node =
03485 TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE)));
03486 uintmax_type_node =
03487 TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE)));
03488
03489 default_function_type = build_function_type (integer_type_node, NULL_TREE);
03490 ptrdiff_type_node
03491 = TREE_TYPE (identifier_global_value (get_identifier (PTRDIFF_TYPE)));
03492 unsigned_ptrdiff_type_node = c_common_unsigned_type (ptrdiff_type_node);
03493
03494 (*lang_hooks.decls.pushdecl)
03495 (build_decl (TYPE_DECL, get_identifier ("__builtin_va_list"),
03496 va_list_type_node));
03497
03498 (*lang_hooks.decls.pushdecl)
03499 (build_decl (TYPE_DECL, get_identifier ("__builtin_ptrdiff_t"),
03500 ptrdiff_type_node));
03501
03502 (*lang_hooks.decls.pushdecl)
03503 (build_decl (TYPE_DECL, get_identifier ("__builtin_size_t"),
03504 sizetype));
03505
03506 if (TREE_CODE (va_list_type_node) == ARRAY_TYPE)
03507 {
03508 va_list_arg_type_node = va_list_ref_type_node =
03509 build_pointer_type (TREE_TYPE (va_list_type_node));
03510 }
03511 else
03512 {
03513 va_list_arg_type_node = va_list_type_node;
03514 va_list_ref_type_node = build_reference_type (va_list_type_node);
03515 }
03516
03517 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
03518 builtin_types[(int) ENUM] = VALUE;
03519 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
03520 builtin_types[(int) ENUM] \
03521 = build_function_type (builtin_types[(int) RETURN], \
03522 void_list_node);
03523 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
03524 builtin_types[(int) ENUM] \
03525 = build_function_type (builtin_types[(int) RETURN], \
03526 tree_cons (NULL_TREE, \
03527 builtin_types[(int) ARG1], \
03528 void_list_node));
03529 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
03530 builtin_types[(int) ENUM] \
03531 = build_function_type \
03532 (builtin_types[(int) RETURN], \
03533 tree_cons (NULL_TREE, \
03534 builtin_types[(int) ARG1], \
03535 tree_cons (NULL_TREE, \
03536 builtin_types[(int) ARG2], \
03537 void_list_node)));
03538 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
03539 builtin_types[(int) ENUM] \
03540 = build_function_type \
03541 (builtin_types[(int) RETURN], \
03542 tree_cons (NULL_TREE, \
03543 builtin_types[(int) ARG1], \
03544 tree_cons (NULL_TREE, \
03545 builtin_types[(int) ARG2], \
03546 tree_cons (NULL_TREE, \
03547 builtin_types[(int) ARG3], \
03548 void_list_node))));
03549 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
03550 builtin_types[(int) ENUM] \
03551 = build_function_type \
03552 (builtin_types[(int) RETURN], \
03553 tree_cons (NULL_TREE, \
03554 builtin_types[(int) ARG1], \
03555 tree_cons (NULL_TREE, \
03556 builtin_types[(int) ARG2], \
03557 tree_cons \
03558 (NULL_TREE, \
03559 builtin_types[(int) ARG3], \
03560 tree_cons (NULL_TREE, \
03561 builtin_types[(int) ARG4], \
03562 void_list_node)))));
03563 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
03564 builtin_types[(int) ENUM] \
03565 = build_function_type (builtin_types[(int) RETURN], NULL_TREE);
03566 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
03567 builtin_types[(int) ENUM] \
03568 = build_function_type (builtin_types[(int) RETURN], \
03569 tree_cons (NULL_TREE, \
03570 builtin_types[(int) ARG1], \
03571 NULL_TREE));
03572
03573 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
03574 builtin_types[(int) ENUM] \
03575 = build_function_type \
03576 (builtin_types[(int) RETURN], \
03577 tree_cons (NULL_TREE, \
03578 builtin_types[(int) ARG1], \
03579 tree_cons (NULL_TREE, \
03580 builtin_types[(int) ARG2], \
03581 NULL_TREE)));
03582
03583 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
03584 builtin_types[(int) ENUM] \
03585 = build_function_type \
03586 (builtin_types[(int) RETURN], \
03587 tree_cons (NULL_TREE, \
03588 builtin_types[(int) ARG1], \
03589 tree_cons (NULL_TREE, \
03590 builtin_types[(int) ARG2], \
03591 tree_cons (NULL_TREE, \
03592 builtin_types[(int) ARG3], \
03593 NULL_TREE))));
03594
03595 #define DEF_POINTER_TYPE(ENUM, TYPE) \
03596 builtin_types[(int) ENUM] \
03597 = build_pointer_type (builtin_types[(int) TYPE]);
03598
03599 #ifdef TARG_SL
03600 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5)\
03601 builtin_types[(int) ENUM] \
03602 = build_function_type \
03603 (builtin_types[(int) RETURN], \
03604 tree_cons (NULL_TREE, \
03605 builtin_types[(int) ARG1], \
03606 tree_cons (NULL_TREE, \
03607 builtin_types[(int) ARG2], \
03608 tree_cons(NULL_TREE, \
03609 builtin_types[(int) ARG3], \
03610 tree_cons (NULL_TREE, \
03611 builtin_types[(int) ARG4], \
03612 tree_cons (NULL_TREE, \
03613 builtin_types[(int) ARG5], \
03614 void_list_node))))));
03615 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6)\
03616 builtin_types[(int) ENUM] \
03617 = build_function_type \
03618 (builtin_types[(int) RETURN], \
03619 tree_cons (NULL_TREE, \
03620 builtin_types[(int) ARG1], \
03621 tree_cons (NULL_TREE, \
03622 builtin_types[(int) ARG2], \
03623 tree_cons(NULL_TREE, \
03624 builtin_types[(int) ARG3], \
03625 tree_cons (NULL_TREE, \
03626 builtin_types[(int) ARG4], \
03627 tree_cons (NULL_TREE, \
03628 builtin_types[(int) ARG5], \
03629 tree_cons (NULL_TREE, \
03630 builtin_types[(int) ARG6], \
03631 void_list_node)))))));
03632 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7)\
03633 builtin_types[(int) ENUM] \
03634 = build_function_type \
03635 (builtin_types[(int) RETURN], \
03636 tree_cons (NULL_TREE, \
03637 builtin_types[(int) ARG1], \
03638 tree_cons (NULL_TREE, \
03639 builtin_types[(int) ARG2], \
03640 tree_cons(NULL_TREE, \
03641 builtin_types[(int) ARG3], \
03642 tree_cons (NULL_TREE, \
03643 builtin_types[(int) ARG4], \
03644 tree_cons (NULL_TREE, \
03645 builtin_types[(int) ARG5], \
03646 tree_cons (NULL_TREE, \
03647 builtin_types[(int) ARG6], \
03648 tree_cons (NULL_TREE, \
03649 builtin_types[(int) ARG7], \
03650 void_list_node))))))));
03651
03652 #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8)\
03653 builtin_types[(int) ENUM] \
03654 = build_function_type \
03655 (builtin_types[(int) RETURN], \
03656 tree_cons (NULL_TREE, \
03657 builtin_types[(int) ARG1], \
03658 tree_cons (NULL_TREE, \
03659 builtin_types[(int) ARG2], \
03660 tree_cons(NULL_TREE, \
03661 builtin_types[(int) ARG3], \
03662 tree_cons (NULL_TREE, \
03663 builtin_types[(int) ARG4], \
03664 tree_cons (NULL_TREE, \
03665 builtin_types[(int) ARG5], \
03666 tree_cons (NULL_TREE, \
03667 builtin_types[(int) ARG6], \
03668 tree_cons (NULL_TREE, \
03669 builtin_types[(int) ARG7], \
03670 tree_cons (NULL_TREE, \
03671 builtin_types[(int) ARG8], \
03672 void_list_node)))))))));
03673
03674 #define DEF_FUNCTION_TYPE_9(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8, ARG9)\
03675 builtin_types[(int) ENUM] \
03676 = build_function_type \
03677 (builtin_types[(int) RETURN], \
03678 tree_cons (NULL_TREE, \
03679 builtin_types[(int) ARG1], \
03680 tree_cons (NULL_TREE, \
03681 builtin_types[(int) ARG2], \
03682 tree_cons(NULL_TREE, \
03683 builtin_types[(int) ARG3], \
03684 tree_cons (NULL_TREE, \
03685 builtin_types[(int) ARG4], \
03686 tree_cons (NULL_TREE, \
03687 builtin_types[(int) ARG5], \
03688 tree_cons (NULL_TREE, \
03689 builtin_types[(int) ARG6], \
03690 tree_cons (NULL_TREE, \
03691 builtin_types[(int) ARG7], \
03692 tree_cons (NULL_TREE, \
03693 builtin_types[(int) ARG8], \
03694 tree_cons (NULL_TREE, \
03695 builtin_types[(int) ARG9], \
03696 void_list_node))))))))));
03697 #endif
03698
03699 #include "builtin-types.def"
03700 #undef DEF_PRIMITIVE_TYPE
03701 #undef DEF_FUNCTION_TYPE_1
03702 #undef DEF_FUNCTION_TYPE_2
03703 #undef DEF_FUNCTION_TYPE_3
03704 #undef DEF_FUNCTION_TYPE_4
03705 #undef DEF_FUNCTION_TYPE_VAR_0
03706 #undef DEF_FUNCTION_TYPE_VAR_1
03707 #undef DEF_FUNCTION_TYPE_VAR_2
03708 #undef DEF_FUNCTION_TYPE_VAR_3
03709 #undef DEF_POINTER_TYPE
03710 #if defined(TARG_SL)
03711 #undef DEF_FUNCTION_TYPE_5
03712 #undef DEF_FUNCTION_TYPE_6
03713 #undef DEF_FUNCTION_TYPE_7
03714 #undef DEF_FUNCTION_TYPE_8
03715 #undef DEF_FUNCTION_TYPE_9
03716 #endif // TARG_SL
03717
03718 if (!c_attrs_initialized)
03719 c_init_attributes ();
03720
03721 #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, \
03722 BOTH_P, FALLBACK_P, NONANSI_P, ATTRS) \
03723 if (NAME) \
03724 { \
03725 const char *__name__ = NAME; \
03726 tree decl; \
03727 \
03728 if (strncmp (__name__, "__builtin_", strlen ("__builtin_")) != 0) \
03729 abort (); \
03730 \
03731 if (!BOTH_P) \
03732 decl = builtin_function (__name__, builtin_types[TYPE], ENUM, \
03733 CLASS, \
03734 (FALLBACK_P \
03735 ? (__name__ + strlen ("__builtin_")) \
03736 : NULL), \
03737 built_in_attributes[(int) ATTRS]); \
03738 else \
03739 decl = builtin_function_2 (__name__, \
03740 __name__ + strlen ("__builtin_"), \
03741 builtin_types[TYPE], \
03742 builtin_types[LIBTYPE], \
03743 ENUM, \
03744 CLASS, \
03745 FALLBACK_P, \
03746 NONANSI_P, \
03747 built_in_attributes[(int) ATTRS]); \
03748 \
03749 built_in_decls[(int) ENUM] = decl; \
03750 }
03751 #include "builtins.def"
03752 #undef DEF_BUILTIN
03753
03754 (*targetm.init_builtins) ();
03755
03756 main_identifier_node = get_identifier ("main");
03757 }
03758
03759 tree
03760 build_va_arg (expr, type)
03761 tree expr, type;
03762 {
03763 return build1 (VA_ARG_EXPR, type, expr);
03764 }
03765
03766
03767
03768
03769 typedef struct disabled_builtin
03770 {
03771 const char *name;
03772 struct disabled_builtin *next;
03773 } disabled_builtin;
03774 static disabled_builtin *disabled_builtins = NULL;
03775
03776 static bool builtin_function_disabled_p PARAMS ((const char *));
03777
03778
03779
03780
03781 void
03782 disable_builtin_function (name)
03783 const char *name;
03784 {
03785 if (strncmp (name, "__builtin_", strlen ("__builtin_")) == 0)
03786 error ("cannot disable built-in function `%s'", name);
03787 else
03788 {
03789 disabled_builtin *new = xmalloc (sizeof (disabled_builtin));
03790 new->name = name;
03791 new->next = disabled_builtins;
03792 disabled_builtins = new;
03793 }
03794 }
03795
03796
03797
03798
03799
03800 static bool
03801 builtin_function_disabled_p (name)
03802 const char *name;
03803 {
03804 disabled_builtin *p;
03805 for (p = disabled_builtins; p != NULL; p = p->next)
03806 {
03807 if (strcmp (name, p->name) == 0)
03808 return true;
03809 }
03810 return false;
03811 }
03812
03813
03814
03815
03816
03817
03818
03819
03820
03821
03822
03823
03824
03825
03826
03827
03828
03829 static tree
03830 builtin_function_2 (builtin_name, name, builtin_type, type, function_code,
03831 class, library_name_p, nonansi_p, attrs)
03832 const char *builtin_name;
03833 const char *name;
03834 tree builtin_type;
03835 tree type;
03836 int function_code;
03837 enum built_in_class class;
03838 int library_name_p;
03839 int nonansi_p;
03840 tree attrs;
03841 {
03842 tree bdecl = NULL_TREE;
03843 tree decl = NULL_TREE;
03844 if (builtin_name != 0)
03845 {
03846 bdecl = builtin_function (builtin_name, builtin_type, function_code,
03847 class, library_name_p ? name : NULL,
03848 attrs);
03849 }
03850 if (name != 0 && !flag_no_builtin && !builtin_function_disabled_p (name)
03851 && !(nonansi_p && flag_no_nonansi_builtin))
03852 {
03853 decl = builtin_function (name, type, function_code, class, NULL,
03854 attrs);
03855 if (nonansi_p)
03856 DECL_BUILT_IN_NONANSI (decl) = 1;
03857 }
03858 return (bdecl != 0 ? bdecl : decl);
03859 }
03860
03861
03862
03863
03864 bool
03865 c_promoting_integer_type_p (t)
03866 tree t;
03867 {
03868 switch (TREE_CODE (t))
03869 {
03870 case INTEGER_TYPE:
03871 return (TYPE_MAIN_VARIANT (t) == char_type_node
03872 || TYPE_MAIN_VARIANT (t) == signed_char_type_node
03873 || TYPE_MAIN_VARIANT (t) == unsigned_char_type_node
03874 || TYPE_MAIN_VARIANT (t) == short_integer_type_node
03875 || TYPE_MAIN_VARIANT (t) == short_unsigned_type_node
03876 || TYPE_PRECISION (t) < TYPE_PRECISION (integer_type_node));
03877
03878 case ENUMERAL_TYPE:
03879
03880
03881
03882 return TYPE_PRECISION (t) < TYPE_PRECISION (integer_type_node);
03883
03884 case BOOLEAN_TYPE:
03885 return 1;
03886
03887 default:
03888 return 0;
03889 }
03890 }
03891
03892
03893
03894
03895 int
03896 self_promoting_args_p (parms)
03897 tree parms;
03898 {
03899 tree t;
03900 for (t = parms; t; t = TREE_CHAIN (t))
03901 {
03902 tree type = TREE_VALUE (t);
03903
03904 if (TREE_CHAIN (t) == 0 && type != void_type_node)
03905 return 0;
03906
03907 if (type == 0)
03908 return 0;
03909
03910 if (TYPE_MAIN_VARIANT (type) == float_type_node)
03911 return 0;
03912
03913 if (c_promoting_integer_type_p (type))
03914 return 0;
03915 }
03916 return 1;
03917 }
03918
03919
03920
03921
03922 tree
03923 strip_array_types (type)
03924 tree type;
03925 {
03926 while (TREE_CODE (type) == ARRAY_TYPE)
03927 type = TREE_TYPE (type);
03928
03929 return type;
03930 }
03931
03932 static tree expand_unordered_cmp PARAMS ((tree, tree, enum tree_code,
03933 enum tree_code));
03934
03935
03936
03937
03938
03939
03940
03941
03942
03943
03944 static tree
03945 expand_unordered_cmp (function, params, unordered_code, ordered_code)
03946 tree function, params;
03947 enum tree_code unordered_code, ordered_code;
03948 {
03949 tree arg0, arg1, type;
03950 enum tree_code code0, code1;
03951
03952
03953 if (params == 0 || TREE_CHAIN (params) == 0)
03954 {
03955 error ("too few arguments to function `%s'",
03956 IDENTIFIER_POINTER (DECL_NAME (function)));
03957 return error_mark_node;
03958 }
03959 else if (TREE_CHAIN (TREE_CHAIN (params)) != 0)
03960 {
03961 error ("too many arguments to function `%s'",
03962 IDENTIFIER_POINTER (DECL_NAME (function)));
03963 return error_mark_node;
03964 }
03965
03966 arg0 = TREE_VALUE (params);
03967 arg1 = TREE_VALUE (TREE_CHAIN (params));
03968
03969 code0 = TREE_CODE (TREE_TYPE (arg0));
03970 code1 = TREE_CODE (TREE_TYPE (arg1));
03971
03972
03973 type = 0;
03974 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
03975 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
03976 type = common_type (TREE_TYPE (arg0), TREE_TYPE (arg1));
03977
03978 if (type == 0 || TREE_CODE (type) != REAL_TYPE)
03979 {
03980 error ("non-floating-point argument to function `%s'",
03981 IDENTIFIER_POINTER (DECL_NAME (function)));
03982 return error_mark_node;
03983 }
03984
03985 #ifdef KEY
03986
03987
03988 if (MODE_HAS_NANS (TYPE_MODE (type))) return NULL_TREE;
03989 #endif
03990
03991 if (unordered_code == UNORDERED_EXPR)
03992 {
03993 if (MODE_HAS_NANS (TYPE_MODE (type)))
03994 return build_binary_op (unordered_code,
03995 convert (type, arg0),
03996 convert (type, arg1),
03997 0);
03998 else
03999 return integer_zero_node;
04000 }
04001
04002 return build_unary_op (TRUTH_NOT_EXPR,
04003 build_binary_op (MODE_HAS_NANS (TYPE_MODE (type))
04004 ? unordered_code
04005 : ordered_code,
04006 convert (type, arg0),
04007 convert (type, arg1),
04008 0),
04009 0);
04010 }
04011
04012
04013
04014
04015
04016
04017
04018
04019
04020
04021 tree
04022 expand_tree_builtin (function, params, coerced_params)
04023 tree function, params, coerced_params;
04024 {
04025 if (DECL_BUILT_IN_CLASS (function) != BUILT_IN_NORMAL)
04026 return NULL_TREE;
04027
04028 switch (DECL_FUNCTION_CODE (function))
04029 {
04030 case BUILT_IN_ABS:
04031 case BUILT_IN_LABS:
04032 case BUILT_IN_LLABS:
04033 case BUILT_IN_IMAXABS:
04034 case BUILT_IN_FABS:
04035 case BUILT_IN_FABSL:
04036 case BUILT_IN_FABSF:
04037 if (coerced_params == 0)
04038 return integer_zero_node;
04039 return build_unary_op (ABS_EXPR, TREE_VALUE (coerced_params), 0);
04040
04041 case BUILT_IN_CONJ:
04042 case BUILT_IN_CONJF:
04043 case BUILT_IN_CONJL:
04044 if (coerced_params == 0)
04045 return integer_zero_node;
04046 return build_unary_op (CONJ_EXPR, TREE_VALUE (coerced_params), 0);
04047
04048 case BUILT_IN_CREAL:
04049 case BUILT_IN_CREALF:
04050 case BUILT_IN_CREALL:
04051 if (coerced_params == 0)
04052 return integer_zero_node;
04053 return build_unary_op (REALPART_EXPR, TREE_VALUE (coerced_params), 0);
04054
04055 case BUILT_IN_CIMAG:
04056 case BUILT_IN_CIMAGF:
04057 case BUILT_IN_CIMAGL:
04058 if (coerced_params == 0)
04059 return integer_zero_node;
04060 return build_unary_op (IMAGPART_EXPR, TREE_VALUE (coerced_params), 0);
04061
04062 case BUILT_IN_ISGREATER:
04063 return expand_unordered_cmp (function, params, UNLE_EXPR, LE_EXPR);
04064
04065 case BUILT_IN_ISGREATEREQUAL:
04066 return expand_unordered_cmp (function, params, UNLT_EXPR, LT_EXPR);
04067
04068 case BUILT_IN_ISLESS:
04069 return expand_unordered_cmp (function, params, UNGE_EXPR, GE_EXPR);
04070
04071 case BUILT_IN_ISLESSEQUAL:
04072 return expand_unordered_cmp (function, params, UNGT_EXPR, GT_EXPR);
04073
04074 case BUILT_IN_ISLESSGREATER:
04075 return expand_unordered_cmp (function, params, UNEQ_EXPR, EQ_EXPR);
04076
04077 case BUILT_IN_ISUNORDERED:
04078 return expand_unordered_cmp (function, params, UNORDERED_EXPR, NOP_EXPR);
04079
04080 default:
04081 break;
04082 }
04083
04084 return NULL_TREE;
04085 }
04086
04087
04088
04089 int
04090 statement_code_p (code)
04091 enum tree_code code;
04092 {
04093 switch (code)
04094 {
04095 case CLEANUP_STMT:
04096 case EXPR_STMT:
04097 case COMPOUND_STMT:
04098 case DECL_STMT:
04099 case IF_STMT:
04100 case FOR_STMT:
04101 case WHILE_STMT:
04102 case DO_STMT:
04103 case RETURN_STMT:
04104 case BREAK_STMT:
04105 case CONTINUE_STMT:
04106 case SCOPE_STMT:
04107 case SWITCH_STMT:
04108 case GOTO_STMT:
04109 case LABEL_STMT:
04110 case ASM_STMT:
04111 case FILE_STMT:
04112 case CASE_LABEL:
04113 #ifdef KEY
04114 case OMP_MARKER_STMT:
04115 #endif
04116 return 1;
04117
04118 default:
04119 if (lang_statement_code_p)
04120 return (*lang_statement_code_p) (code);
04121 return 0;
04122 }
04123 }
04124
04125
04126
04127
04128
04129
04130
04131
04132
04133
04134
04135 tree
04136 walk_stmt_tree (tp, func, data)
04137 tree *tp;
04138 walk_tree_fn func;
04139 void *data;
04140 {
04141 enum tree_code code;
04142 int walk_subtrees;
04143 tree result;
04144 int i, len;
04145
04146 #define WALK_SUBTREE(NODE) \
04147 do \
04148 { \
04149 result = walk_stmt_tree (&(NODE), func, data); \
04150 if (result) \
04151 return result; \
04152 } \
04153 while (0)
04154
04155
04156 if (!*tp)
04157 return NULL_TREE;
04158
04159
04160 if (!statement_code_p (TREE_CODE (*tp)))
04161 return NULL_TREE;
04162
04163
04164 walk_subtrees = 1;
04165 result = (*func) (tp, &walk_subtrees, data);
04166
04167
04168 if (result)
04169 return result;
04170
04171
04172
04173 code = TREE_CODE (*tp);
04174 if (!statement_code_p (code))
04175 return NULL_TREE;
04176
04177
04178
04179 if (walk_subtrees)
04180 {
04181
04182
04183 len = TREE_CODE_LENGTH (code);
04184
04185
04186
04187 for (i = 0; i < len; ++i)
04188 WALK_SUBTREE (TREE_OPERAND (*tp, i));
04189 }
04190
04191
04192
04193 return walk_stmt_tree (&TREE_CHAIN (*tp), func, data);
04194
04195 #undef WALK_SUBTREE
04196 }
04197
04198
04199
04200
04201
04202
04203 int
04204 case_compare (k1, k2)
04205 splay_tree_key k1;
04206 splay_tree_key k2;
04207 {
04208
04209
04210 if (!k1)
04211 return k2 ? -1 : 0;
04212 else if (!k2)
04213 return k1 ? 1 : 0;
04214
04215 return tree_int_cst_compare ((tree) k1, (tree) k2);
04216 }
04217
04218
04219
04220
04221
04222
04223
04224
04225
04226
04227 tree
04228 c_add_case_label (cases, cond, low_value, high_value)
04229 splay_tree cases;
04230 tree cond;
04231 tree low_value;
04232 tree high_value;
04233 {
04234 tree type;
04235 tree label;
04236 tree case_label;
04237 splay_tree_node node;
04238
04239
04240 label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
04241 DECL_CONTEXT (label) = current_function_decl;
04242
04243
04244
04245 if (!cond || cond == error_mark_node)
04246 {
04247
04248
04249 if (!cases->root)
04250 add_stmt (build_case_label (NULL_TREE, NULL_TREE, label));
04251 return error_mark_node;
04252 }
04253
04254 if ((low_value && TREE_TYPE (low_value)
04255 && POINTER_TYPE_P (TREE_TYPE (low_value)))
04256 || (high_value && TREE_TYPE (high_value)
04257 && POINTER_TYPE_P (TREE_TYPE (high_value))))
04258 error ("pointers are not permitted as case values");
04259
04260
04261 if (high_value && pedantic)
04262 {
04263 if (c_language == clk_cplusplus)
04264 pedwarn ("ISO C++ forbids range expressions in switch statements");
04265 else
04266 pedwarn ("ISO C forbids range expressions in switch statements");
04267 }
04268
04269 type = TREE_TYPE (cond);
04270 if (low_value)
04271 {
04272 low_value = check_case_value (low_value);
04273 low_value = convert_and_check (type, low_value);
04274 }
04275 if (high_value)
04276 {
04277 high_value = check_case_value (high_value);
04278 high_value = convert_and_check (type, high_value);
04279 }
04280
04281
04282 if (low_value == error_mark_node || high_value == error_mark_node)
04283 {
04284 if (!cases->root)
04285 add_stmt (build_case_label (NULL_TREE, NULL_TREE, label));
04286 return error_mark_node;
04287 }
04288
04289
04290
04291
04292 if (tree_int_cst_equal (low_value, high_value))
04293 high_value = NULL_TREE;
04294 if (low_value && high_value
04295 && !tree_int_cst_lt (low_value, high_value))
04296 warning ("empty range specified");
04297
04298
04299
04300 node = splay_tree_lookup (cases, (splay_tree_key) low_value);
04301
04302
04303
04304 if (!node && (low_value || high_value))
04305 {
04306 splay_tree_node low_bound;
04307 splay_tree_node high_bound;
04308
04309
04310
04311
04312
04313
04314
04315
04316 low_bound = splay_tree_predecessor (cases,
04317 (splay_tree_key) low_value);
04318 high_bound = splay_tree_successor (cases,
04319 (splay_tree_key) low_value);
04320
04321
04322
04323
04324 if (low_bound
04325 && CASE_HIGH ((tree) low_bound->value)
04326 && tree_int_cst_compare (CASE_HIGH ((tree) low_bound->value),
04327 low_value) >= 0)
04328 node = low_bound;
04329
04330
04331
04332
04333 else if (high_bound
04334 && high_value
04335 && (tree_int_cst_compare ((tree) high_bound->key,
04336 high_value)
04337 <= 0))
04338 node = high_bound;
04339 }
04340
04341 if (node)
04342 {
04343 tree duplicate = CASE_LABEL_DECL ((tree) node->value);
04344
04345 if (high_value)
04346 {
04347 error ("duplicate (or overlapping) case value");
04348 error_with_decl (duplicate,
04349 "this is the first entry overlapping that value");
04350 }
04351 else if (low_value)
04352 {
04353 error ("duplicate case value") ;
04354 error_with_decl (duplicate, "previously used here");
04355 }
04356 else
04357 {
04358 error ("multiple default labels in one switch");
04359 error_with_decl (duplicate, "this is the first default label");
04360 }
04361 if (!cases->root)
04362 add_stmt (build_case_label (NULL_TREE, NULL_TREE, label));
04363 }
04364
04365
04366 case_label = add_stmt (build_case_label (low_value, high_value, label));
04367
04368 splay_tree_insert (cases,
04369 (splay_tree_key) low_value,
04370 (splay_tree_value) case_label);
04371
04372 return case_label;
04373 }
04374
04375
04376
04377
04378 tree
04379 finish_label_address_expr (label)
04380 tree label;
04381 {
04382 tree result;
04383
04384 if (pedantic)
04385 {
04386 if (c_language == clk_cplusplus)
04387 pedwarn ("ISO C++ forbids taking the address of a label");
04388 else
04389 pedwarn ("ISO C forbids taking the address of a label");
04390 }
04391
04392 label = lookup_label (label);
04393 if (label == NULL_TREE)
04394 result = null_pointer_node;
04395 else
04396 {
04397 TREE_USED (label) = 1;
04398 result = build1 (ADDR_EXPR, ptr_type_node, label);
04399 TREE_CONSTANT (result) = 1;
04400
04401
04402
04403 }
04404
04405 return result;
04406 }
04407
04408
04409
04410 rtx
04411 c_expand_expr (exp, target, tmode, modifier)
04412 tree exp;
04413 rtx target;
04414 enum machine_mode tmode;
04415 int modifier;
04416 {
04417 switch (TREE_CODE (exp))
04418 {
04419 case STMT_EXPR:
04420 {
04421 tree rtl_expr;
04422 rtx result;
04423 bool preserve_result = false;
04424 bool return_target = false;
04425
04426
04427
04428
04429
04430
04431 push_temp_slots ();
04432 rtl_expr = expand_start_stmt_expr (!STMT_EXPR_NO_SCOPE (exp));
04433
04434
04435
04436 if (target != const0_rtx
04437 && TREE_CODE (STMT_EXPR_STMT (exp)) == COMPOUND_STMT
04438 && TREE_CODE (COMPOUND_BODY (STMT_EXPR_STMT (exp))) == SCOPE_STMT)
04439 {
04440 tree expr = COMPOUND_BODY (STMT_EXPR_STMT (exp));
04441 tree last = TREE_CHAIN (expr);
04442
04443 while (TREE_CHAIN (last))
04444 {
04445 expr = last;
04446 last = TREE_CHAIN (last);
04447 }
04448
04449 if (TREE_CODE (last) == SCOPE_STMT
04450 && TREE_CODE (expr) == EXPR_STMT)
04451 {
04452 if (target && TREE_CODE (EXPR_STMT_EXPR (expr)) == VAR_DECL
04453 && DECL_RTL_IF_SET (EXPR_STMT_EXPR (expr)) == target)
04454
04455
04456
04457
04458 return_target = true;
04459 else
04460 {
04461
04462
04463 TREE_ADDRESSABLE (expr) = 1;
04464 preserve_result = true;
04465 }
04466 }
04467 }
04468
04469 expand_stmt (STMT_EXPR_STMT (exp));
04470 expand_end_stmt_expr (rtl_expr);
04471
04472 result = expand_expr (rtl_expr, target, tmode, modifier);
04473 if (return_target)
04474 result = target;
04475 else if (preserve_result && GET_CODE (result) == MEM)
04476 {
04477 if (GET_MODE (result) != BLKmode)
04478 result = copy_to_reg (result);
04479 else
04480 preserve_temp_slots (result);
04481 }
04482
04483
04484
04485
04486 if (STMT_EXPR_NO_SCOPE (exp))
04487 preserve_temp_slots (NULL_RTX);
04488
04489 pop_temp_slots ();
04490 return result;
04491 }
04492 break;
04493
04494 case CALL_EXPR:
04495 {
04496 if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
04497 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
04498 == FUNCTION_DECL)
04499 && DECL_BUILT_IN (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
04500 && (DECL_BUILT_IN_CLASS (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
04501 == BUILT_IN_FRONTEND))
04502 return c_expand_builtin (exp, target, tmode, modifier);
04503 else
04504 abort ();
04505 }
04506 break;
04507
04508 case COMPOUND_LITERAL_EXPR:
04509 {
04510
04511
04512 tree decl = COMPOUND_LITERAL_EXPR_DECL (exp);
04513 emit_local_var (decl);
04514 return expand_expr (decl, target, tmode, modifier);
04515 }
04516
04517 default:
04518 abort ();
04519 }
04520
04521 abort ();
04522 return NULL;
04523 }
04524
04525
04526
04527 int
04528 c_safe_from_p (target, exp)
04529 rtx target;
04530 tree exp;
04531 {
04532
04533
04534
04535 if (TREE_CODE (exp) == DECL_STMT)
04536 {
04537 tree decl = DECL_STMT_DECL (exp);
04538
04539 if (TREE_CODE (decl) == VAR_DECL
04540 && DECL_INITIAL (decl)
04541 && !safe_from_p (target, DECL_INITIAL (decl), 0))
04542 return 0;
04543 }
04544
04545
04546 if (statement_code_p (TREE_CODE (exp)) && TREE_CHAIN (exp))
04547 return safe_from_p (target, TREE_CHAIN (exp), 0);
04548
04549
04550 return 1;
04551 }
04552
04553
04554
04555 int
04556 c_common_unsafe_for_reeval (exp)
04557 tree exp;
04558 {
04559
04560
04561 if (TREE_CODE (exp) == STMT_EXPR
04562 || TREE_CODE (exp) == COMPOUND_LITERAL_EXPR)
04563 return 2;
04564
04565
04566 return -1;
04567 }
04568
04569
04570
04571 int
04572 c_staticp (exp)
04573 tree exp;
04574 {
04575 if (TREE_CODE (exp) == COMPOUND_LITERAL_EXPR
04576 && TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (exp)))
04577 return 1;
04578 return 0;
04579 }
04580
04581 #define CALLED_AS_BUILT_IN(NODE) \
04582 (!strncmp (IDENTIFIER_POINTER (DECL_NAME (NODE)), "__builtin_", 10))
04583
04584 static rtx
04585 c_expand_builtin (exp, target, tmode, modifier)
04586 tree exp;
04587 rtx target;
04588 enum machine_mode tmode;
04589 enum expand_modifier modifier;
04590 {
04591 tree type = TREE_TYPE (exp);
04592 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
04593 tree arglist = TREE_OPERAND (exp, 1);
04594 enum built_in_function fcode = DECL_FUNCTION_CODE (fndecl);
04595 enum tree_code code = TREE_CODE (exp);
04596 const int ignore = (target == const0_rtx
04597 || ((code == NON_LVALUE_EXPR || code == NOP_EXPR
04598 || code == CONVERT_EXPR || code == REFERENCE_EXPR
04599 || code == COND_EXPR)
04600 && TREE_CODE (type) == VOID_TYPE));
04601
04602 if (! optimize && ! CALLED_AS_BUILT_IN (fndecl))
04603 return expand_call (exp, target, ignore);
04604
04605 switch (fcode)
04606 {
04607 #ifndef SGI_MONGOOSE
04608 case BUILT_IN_PRINTF:
04609 target = c_expand_builtin_printf (arglist, target, tmode,
04610 modifier, ignore, 0);
04611 if (target)
04612 return target;
04613 break;
04614
04615 case BUILT_IN_PRINTF_UNLOCKED:
04616 target = c_expand_builtin_printf (arglist, target, tmode,
04617 modifier, ignore, 1);
04618 if (target)
04619 return target;
04620 break;
04621
04622 case BUILT_IN_FPRINTF:
04623 target = c_expand_builtin_fprintf (arglist, target, tmode,
04624 modifier, ignore, 0);
04625 if (target)
04626 return target;
04627 break;
04628
04629 case BUILT_IN_FPRINTF_UNLOCKED:
04630 target = c_expand_builtin_fprintf (arglist, target, tmode,
04631 modifier, ignore, 1);
04632 if (target)
04633 return target;
04634 break;
04635 #endif
04636
04637 default:
04638 error ("built-in function `%s' not currently supported",
04639 IDENTIFIER_POINTER (DECL_NAME (fndecl)));
04640 }
04641
04642
04643
04644 return expand_call (exp, target, ignore);
04645 }
04646
04647
04648
04649
04650 static int
04651 is_valid_printf_arglist (arglist)
04652 tree arglist;
04653 {
04654
04655 const int SAVE_pedantic = pedantic;
04656 int diagnostic_occurred = 0;
04657 tree attrs;
04658
04659
04660
04661 pedantic = 1;
04662
04663 attrs = tree_cons (get_identifier ("format"),
04664 tree_cons (NULL_TREE,
04665 get_identifier ("printf"),
04666 tree_cons (NULL_TREE,
04667 integer_one_node,
04668 tree_cons (NULL_TREE,
04669 build_int_2 (2, 0),
04670 NULL_TREE))),
04671 NULL_TREE);
04672 check_function_format (&diagnostic_occurred, attrs, arglist);
04673
04674
04675 pedantic = SAVE_pedantic;
04676
04677
04678
04679 return ! diagnostic_occurred;
04680 }
04681
04682 #ifndef SGI_MONGOOSE
04683
04684
04685 static rtx
04686 c_expand_builtin_printf (arglist, target, tmode, modifier, ignore, unlocked)
04687 tree arglist;
04688 rtx target;
04689 enum machine_mode tmode;
04690 enum expand_modifier modifier;
04691 int ignore;
04692 int unlocked;
04693 {
04694 tree fn_putchar = unlocked ?
04695 built_in_decls[BUILT_IN_PUTCHAR_UNLOCKED] : built_in_decls[BUILT_IN_PUTCHAR];
04696 tree fn_puts = unlocked ?
04697 built_in_decls[BUILT_IN_PUTS_UNLOCKED] : built_in_decls[BUILT_IN_PUTS];
04698 tree fn, format_arg, stripped_string;
04699
04700
04701
04702 if (!ignore || !fn_putchar || !fn_puts)
04703 return 0;
04704
04705
04706 if (arglist == 0
04707 || (TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE))
04708 return 0;
04709
04710
04711 if (!is_valid_printf_arglist (arglist))
04712 return 0;
04713
04714 format_arg = TREE_VALUE (arglist);
04715 stripped_string = format_arg;
04716 STRIP_NOPS (stripped_string);
04717 if (stripped_string && TREE_CODE (stripped_string) == ADDR_EXPR)
04718 stripped_string = TREE_OPERAND (stripped_string, 0);
04719
04720
04721 if (TREE_CODE (stripped_string) != STRING_CST)
04722 return 0;
04723
04724
04725
04726
04727 if (strcmp (TREE_STRING_POINTER (stripped_string), "%s\n") == 0)
04728 {
04729 arglist = TREE_CHAIN (arglist);
04730 fn = fn_puts;
04731 }
04732
04733 else if (strcmp (TREE_STRING_POINTER (stripped_string), "%c") == 0)
04734 {
04735 arglist = TREE_CHAIN (arglist);
04736 fn = fn_putchar;
04737 }
04738 else
04739 {
04740
04741 if (strchr (TREE_STRING_POINTER (stripped_string), '%'))
04742 return 0;
04743
04744
04745
04746
04747 if (TREE_STRING_LENGTH (stripped_string) == 2)
04748 {
04749
04750
04751
04752 arglist = build_int_2 (TREE_STRING_POINTER (stripped_string)[0], 0);
04753 arglist = build_tree_list (NULL_TREE, arglist);
04754
04755 fn = fn_putchar;
04756 }
04757
04758
04759
04760
04761 else if (TREE_STRING_LENGTH (stripped_string) > 2
04762 && TREE_STRING_POINTER (stripped_string)
04763 [TREE_STRING_LENGTH (stripped_string) - 2] == '\n')
04764 {
04765
04766
04767 const int newlen = TREE_STRING_LENGTH (stripped_string) - 1;
04768 char *newstr = (char *) alloca (newlen);
04769 memcpy (newstr, TREE_STRING_POINTER (stripped_string), newlen - 1);
04770 newstr[newlen - 1] = 0;
04771
04772 arglist = fix_string_type (build_string (newlen, newstr));
04773 arglist = build_tree_list (NULL_TREE, arglist);
04774 fn = fn_puts;
04775 }
04776 else
04777
04778
04779 return 0;
04780 }
04781
04782 return expand_expr (build_function_call (fn, arglist),
04783 (ignore ? const0_rtx : target),
04784 tmode, modifier);
04785 }
04786
04787
04788
04789 static rtx
04790 c_expand_builtin_fprintf (arglist, target, tmode, modifier, ignore, unlocked)
04791 tree arglist;
04792 rtx target;
04793 enum machine_mode tmode;
04794 enum expand_modifier modifier;
04795 int ignore;
04796 int unlocked;
04797 {
04798 tree fn_fputc = unlocked ?
04799 built_in_decls[BUILT_IN_FPUTC_UNLOCKED] : built_in_decls[BUILT_IN_FPUTC];
04800 tree fn_fputs = unlocked ?
04801 built_in_decls[BUILT_IN_FPUTS_UNLOCKED] : built_in_decls[BUILT_IN_FPUTS];
04802 tree fn, format_arg, stripped_string;
04803
04804
04805
04806 if (!ignore || !fn_fputc || !fn_fputs)
04807 return 0;
04808
04809
04810 if (arglist == 0
04811 || (TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE)
04812 || (TREE_CHAIN (arglist) == 0)
04813 || (TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (arglist)))) !=
04814 POINTER_TYPE))
04815 return 0;
04816
04817
04818 if (!is_valid_printf_arglist (TREE_CHAIN (arglist)))
04819 return 0;
04820
04821 format_arg = TREE_VALUE (TREE_CHAIN (arglist));
04822 stripped_string = format_arg;
04823 STRIP_NOPS (stripped_string);
04824 if (stripped_string && TREE_CODE (stripped_string) == ADDR_EXPR)
04825 stripped_string = TREE_OPERAND (stripped_string, 0);
04826
04827
04828 if (TREE_CODE (stripped_string) != STRING_CST)
04829 return 0;
04830
04831
04832
04833
04834 if (strcmp (TREE_STRING_POINTER (stripped_string), "%s") == 0)
04835 {
04836 tree newarglist = build_tree_list (NULL_TREE, TREE_VALUE (arglist));
04837 arglist = tree_cons (NULL_TREE,
04838 TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))),
04839 newarglist);
04840 fn = fn_fputs;
04841 }
04842
04843 else if (strcmp (TREE_STRING_POINTER (stripped_string), "%c") == 0)
04844 {
04845 tree newarglist = build_tree_list (NULL_TREE, TREE_VALUE (arglist));
04846 arglist = tree_cons (NULL_TREE,
04847 TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))),
04848 newarglist);
04849 fn = fn_fputc;
04850 }
04851 else
04852 {
04853
04854 if (strchr (TREE_STRING_POINTER (stripped_string), '%'))
04855 return 0;
04856
04857
04858
04859
04860 arglist = tree_cons (NULL_TREE, TREE_VALUE (TREE_CHAIN (arglist)),
04861 build_tree_list (NULL_TREE, TREE_VALUE (arglist)));
04862 fn = fn_fputs;
04863 }
04864
04865 return expand_expr (build_function_call (fn, arglist),
04866 (ignore ? const0_rtx : target),
04867 tmode, modifier);
04868 }
04869 #endif
04870
04871
04872
04873
04874
04875 tree
04876 boolean_increment (code, arg)
04877 enum tree_code code;
04878 tree arg;
04879 {
04880 tree val;
04881 tree true_res = (c_language == clk_cplusplus
04882 ? boolean_true_node
04883 : c_bool_true_node);
04884 arg = stabilize_reference (arg);
04885 switch (code)
04886 {
04887 case PREINCREMENT_EXPR:
04888 val = build (MODIFY_EXPR, TREE_TYPE (arg), arg, true_res);
04889 break;
04890 case POSTINCREMENT_EXPR:
04891 val = build (MODIFY_EXPR, TREE_TYPE (arg), arg, true_res);
04892 arg = save_expr (arg);
04893 val = build (COMPOUND_EXPR, TREE_TYPE (arg), val, arg);
04894 val = build (COMPOUND_EXPR, TREE_TYPE (arg), arg, val);
04895 break;
04896 case PREDECREMENT_EXPR:
04897 val = build (MODIFY_EXPR, TREE_TYPE (arg), arg, invert_truthvalue (arg));
04898 break;
04899 case POSTDECREMENT_EXPR:
04900 val = build (MODIFY_EXPR, TREE_TYPE (arg), arg, invert_truthvalue (arg));
04901 arg = save_expr (arg);
04902 val = build (COMPOUND_EXPR, TREE_TYPE (arg), val, arg);
04903 val = build (COMPOUND_EXPR, TREE_TYPE (arg), arg, val);
04904 break;
04905 default:
04906 abort ();
04907 }
04908 TREE_SIDE_EFFECTS (val) = 1;
04909 return val;
04910 }
04911
04912
04913 static void
04914 builtin_define_type_precision (name, type)
04915 const char *name;
04916 tree type;
04917 {
04918 builtin_define_with_int_value (name, TYPE_PRECISION (type));
04919 }
04920
04921
04922 static void
04923 builtin_define_float_constants (name_prefix, fp_suffix, type)
04924 const char *name_prefix;
04925 const char *fp_suffix;
04926 tree type;
04927 {
04928
04929
04930
04931
04932
04933
04934
04935
04936 const double log10_2 = .30102999566398119521;
04937 double log10_b;
04938 const struct real_format *fmt;
04939
04940 char name[64], buf[128];
04941 int dig, min_10_exp, max_10_exp;
04942 int decimal_dig;
04943
04944 fmt = real_format_for_mode[TYPE_MODE (type) - QFmode];
04945
04946
04947 if (type == float_type_node)
04948 builtin_define_with_int_value ("__FLT_RADIX__", fmt->b);
04949 log10_b = log10_2 * fmt->log2_b;
04950
04951
04952 sprintf (name, "__%s_MANT_DIG__", name_prefix);
04953 builtin_define_with_int_value (name, fmt->p);
04954
04955
04956
04957
04958
04959
04960
04961
04962 dig = (fmt->p - 1) * log10_b;
04963 sprintf (name, "__%s_DIG__", name_prefix);
04964 builtin_define_with_int_value (name, dig);
04965
04966
04967 sprintf (name, "__%s_MIN_EXP__", name_prefix);
04968 sprintf (buf, "(%d)", fmt->emin);
04969 builtin_define_with_value (name, buf, 0);
04970
04971
04972
04973
04974
04975
04976
04977
04978 min_10_exp = (fmt->emin - 1) * log10_b;
04979 sprintf (name, "__%s_MIN_10_EXP__", name_prefix);
04980 sprintf (buf, "(%d)", min_10_exp);
04981 builtin_define_with_value (name, buf, 0);
04982
04983
04984 sprintf (name, "__%s_MAX_EXP__", name_prefix);
04985 builtin_define_with_int_value (name, fmt->emax);
04986
04987
04988
04989
04990
04991
04992
04993
04994
04995
04996
04997
04998
04999
05000
05001
05002
05003
05004
05005
05006
05007
05008
05009
05010
05011
05012
05013 max_10_exp = fmt->emax * log10_b;
05014 sprintf (name, "__%s_MAX_10_EXP__", name_prefix);
05015 builtin_define_with_int_value (name, max_10_exp);
05016
05017
05018
05019
05020
05021
05022
05023
05024
05025
05026 {
05027 double d_decimal_dig = 1 + fmt->p * log10_b;
05028 decimal_dig = d_decimal_dig;
05029 if (decimal_dig < d_decimal_dig)
05030 decimal_dig++;
05031 }
05032 if (type == long_double_type_node)
05033 builtin_define_with_int_value ("__DECIMAL_DIG__", decimal_dig);
05034
05035
05036
05037
05038
05039
05040
05041 {
05042 int i, n;
05043 char *p;
05044
05045 strcpy (buf, "0x0.");
05046 n = fmt->p * fmt->log2_b;
05047 for (i = 0, p = buf + 4; i + 3 < n; i += 4)
05048 *p++ = 'f';
05049 if (i < n)
05050 *p++ = "08ce"[n - i];
05051 sprintf (p, "p%d", fmt->emax * fmt->log2_b);
05052 }
05053 sprintf (name, "__%s_MAX__", name_prefix);
05054 builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix);
05055
05056
05057
05058 sprintf (name, "__%s_MIN__", name_prefix);
05059 sprintf (buf, "0x1p%d", (fmt->emin - 1) * fmt->log2_b);
05060 builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix);
05061
05062
05063
05064 sprintf (name, "__%s_EPSILON__", name_prefix);
05065 sprintf (buf, "0x1p%d", (1 - fmt->p) * fmt->log2_b);
05066 builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix);
05067
05068
05069
05070
05071 sprintf (name, "__%s_DENORM_MIN__", name_prefix);
05072 if (fmt->has_denorm)
05073 {
05074 sprintf (buf, "0x1p%d", (fmt->emin - fmt->p) * fmt->log2_b);
05075 builtin_define_with_hex_fp_value (name, type, decimal_dig,
05076 buf, fp_suffix);
05077 }
05078 else
05079 {
05080 sprintf (buf, "0.0%s", fp_suffix);
05081 builtin_define_with_value (name, buf, 0);
05082 }
05083 }
05084
05085
05086 void
05087 cb_register_builtins (pfile)
05088 cpp_reader *pfile;
05089 {
05090
05091 if (flag_undef)
05092 return;
05093
05094 if (c_language == clk_cplusplus)
05095 {
05096 if (SUPPORTS_ONE_ONLY)
05097 cpp_define (pfile, "__GXX_WEAK__=1");
05098 else
05099 cpp_define (pfile, "__GXX_WEAK__=0");
05100 if (warn_deprecated)
05101 cpp_define (pfile, "__DEPRECATED");
05102 }
05103 if (flag_exceptions)
05104 cpp_define (pfile, "__EXCEPTIONS");
05105
05106
05107
05108 cpp_define (pfile, "__GXX_ABI_VERSION=102");
05109
05110
05111 if (USING_SJLJ_EXCEPTIONS)
05112 cpp_define (pfile, "__USING_SJLJ_EXCEPTIONS__");
05113
05114
05115 builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE, 0);
05116 builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE, 0);
05117 builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE, 0);
05118 builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE, 0);
05119
05120
05121 builtin_define_type_max ("__SCHAR_MAX__", signed_char_type_node, 0);
05122 builtin_define_type_max ("__SHRT_MAX__", short_integer_type_node, 0);
05123 builtin_define_type_max ("__INT_MAX__", integer_type_node, 0);
05124 builtin_define_type_max ("__LONG_MAX__", long_integer_type_node, 1);
05125 builtin_define_type_max ("__LONG_LONG_MAX__", long_long_integer_type_node, 2);
05126 builtin_define_type_max ("__WCHAR_MAX__", wchar_type_node, 0);
05127
05128 builtin_define_type_precision ("__CHAR_BIT__", char_type_node);
05129
05130
05131
05132 builtin_define_with_int_value ("__FLT_EVAL_METHOD__",
05133 TARGET_FLT_EVAL_METHOD);
05134
05135 builtin_define_float_constants ("FLT", "F", float_type_node);
05136 builtin_define_float_constants ("DBL", "", double_type_node);
05137 builtin_define_float_constants ("LDBL", "L", long_double_type_node);
05138
05139
05140 builtin_define_with_value ("__REGISTER_PREFIX__", REGISTER_PREFIX, 0);
05141 builtin_define_with_value ("__USER_LABEL_PREFIX__", user_label_prefix, 0);
05142
05143
05144 builtin_define_with_value ("__VERSION__", version_string, 1);
05145
05146
05147
05148 if (optimize_size)
05149 cpp_define (pfile, "__OPTIMIZE_SIZE__");
05150 if (optimize)
05151 cpp_define (pfile, "__OPTIMIZE__");
05152
05153 if (flag_hosted)
05154 cpp_define (pfile, "__STDC_HOSTED__=1");
05155 else
05156 cpp_define (pfile, "__STDC_HOSTED__=0");
05157
05158 if (fast_math_flags_set_p ())
05159 cpp_define (pfile, "__FAST_MATH__");
05160 if (flag_really_no_inline)
05161 cpp_define (pfile, "__NO_INLINE__");
05162 if (flag_signaling_nans)
05163 cpp_define (pfile, "__SUPPORT_SNAN__");
05164 if (flag_finite_math_only)
05165 cpp_define (pfile, "__FINITE_MATH_ONLY__=1");
05166 else
05167 cpp_define (pfile, "__FINITE_MATH_ONLY__=0");
05168
05169 if (flag_iso)
05170 cpp_define (pfile, "__STRICT_ANSI__");
05171
05172 if (!flag_signed_char)
05173 cpp_define (pfile, "__CHAR_UNSIGNED__");
05174
05175 if (c_language == clk_cplusplus && TREE_UNSIGNED (wchar_type_node))
05176 cpp_define (pfile, "__WCHAR_UNSIGNED__");
05177
05178
05179 if (flag_objc && flag_next_runtime)
05180 cpp_define (pfile, "__NEXT_RUNTIME__");
05181
05182
05183
05184 # define preprocessing_asm_p() (cpp_get_options (pfile)->lang == CLK_ASM)
05185 # define preprocessing_trad_p() (cpp_get_options (pfile)->traditional)
05186 # define builtin_define(TXT) cpp_define (pfile, TXT)
05187 # define builtin_assert(TXT) cpp_assert (pfile, TXT)
05188 TARGET_CPU_CPP_BUILTINS ();
05189 TARGET_OS_CPP_BUILTINS ();
05190 }
05191
05192
05193
05194
05195
05196
05197
05198
05199
05200
05201 void
05202 builtin_define_std (macro)
05203 const char *macro;
05204 {
05205 size_t len = strlen (macro);
05206 char *buff = alloca (len + 5);
05207 char *p = buff + 2;
05208 char *q = p + len;
05209
05210
05211 memcpy (p, macro, len + 1);
05212 if (!( *p == '_' && (p[1] == '_' || ISUPPER (p[1]))))
05213 {
05214 if (*p != '_')
05215 *--p = '_';
05216 if (p[1] != '_')
05217 *--p = '_';
05218 }
05219 cpp_define (parse_in, p);
05220
05221
05222 if (p != buff + 2)
05223 {
05224
05225 if (q[-1] != '_')
05226 *q++ = '_';
05227 if (q[-2] != '_')
05228 *q++ = '_';
05229 *q = '\0';
05230 cpp_define (parse_in, p);
05231
05232
05233 if (!flag_iso)
05234 cpp_define (parse_in, macro);
05235 }
05236 }
05237
05238
05239
05240
05241 static void
05242 builtin_define_with_value (macro, expansion, is_str)
05243 const char *macro;
05244 const char *expansion;
05245 int is_str;
05246 {
05247 char *buf;
05248 size_t mlen = strlen (macro);
05249 size_t elen = strlen (expansion);
05250 size_t extra = 2;
05251
05252 if (is_str)
05253 extra += 2;
05254
05255 buf = alloca (mlen + elen + extra);
05256 if (is_str)
05257 sprintf (buf, "%s=\"%s\"", macro, expansion);
05258 else
05259 sprintf (buf, "%s=%s", macro, expansion);
05260
05261 cpp_define (parse_in, buf);
05262 }
05263
05264
05265 static void
05266 builtin_define_with_int_value (macro, value)
05267 const char *macro;
05268 HOST_WIDE_INT value;
05269 {
05270 char *buf;
05271 size_t mlen = strlen (macro);
05272 size_t vlen = 18;
05273 size_t extra = 2;
05274
05275 buf = alloca (mlen + vlen + extra);
05276 memcpy (buf, macro, mlen);
05277 buf[mlen] = '=';
05278 sprintf (buf + mlen + 1, HOST_WIDE_INT_PRINT_DEC, value);
05279
05280 cpp_define (parse_in, buf);
05281 }
05282
05283
05284 static void
05285 builtin_define_with_hex_fp_value (macro, type, digits, hex_str, fp_suffix)
05286 const char *macro;
05287 tree type ATTRIBUTE_UNUSED;
05288 int digits;
05289 const char *hex_str;
05290 const char *fp_suffix;
05291 {
05292 REAL_VALUE_TYPE real;
05293 char dec_str[64], buf[256];
05294
05295
05296
05297
05298
05299
05300
05301
05302
05303
05304
05305 real_from_string (&real, hex_str);
05306 real_to_decimal (dec_str, &real, sizeof (dec_str), digits, 0);
05307
05308 sprintf (buf, "%s=%s%s", macro, dec_str, fp_suffix);
05309 cpp_define (parse_in, buf);
05310 }
05311
05312
05313
05314
05315
05316 static void
05317 builtin_define_type_max (macro, type, is_long)
05318 const char *macro;
05319 tree type;
05320 int is_long;
05321 {
05322 static const char *const values[]
05323 = { "127", "255",
05324 "32767", "65535",
05325 "2147483647", "4294967295",
05326 "9223372036854775807", "18446744073709551615",
05327 "170141183460469231731687303715884105727",
05328 "340282366920938463463374607431768211455" };
05329 static const char *const suffixes[] = { "", "U", "L", "UL", "LL", "ULL" };
05330
05331 const char *value, *suffix;
05332 char *buf;
05333 size_t idx;
05334
05335
05336
05337
05338 switch (TYPE_PRECISION (type))
05339 {
05340 case 8: idx = 0; break;
05341 case 16: idx = 2; break;
05342 case 32: idx = 4; break;
05343 case 64: idx = 6; break;
05344 case 128: idx = 8; break;
05345 default: abort ();
05346 }
05347
05348 value = values[idx + TREE_UNSIGNED (type)];
05349 suffix = suffixes[is_long * 2 + TREE_UNSIGNED (type)];
05350
05351 buf = alloca (strlen (macro) + 1 + strlen (value) + strlen (suffix) + 1);
05352 sprintf (buf, "%s=%s%s", macro, value, suffix);
05353
05354 cpp_define (parse_in, buf);
05355 }
05356
05357 static void
05358 c_init_attributes ()
05359 {
05360
05361 #define DEF_ATTR_NULL_TREE(ENUM) \
05362 built_in_attributes[(int) ENUM] = NULL_TREE;
05363 #define DEF_ATTR_INT(ENUM, VALUE) \
05364 built_in_attributes[(int) ENUM] = build_int_2 (VALUE, VALUE < 0 ? -1 : 0);
05365 #define DEF_ATTR_IDENT(ENUM, STRING) \
05366 built_in_attributes[(int) ENUM] = get_identifier (STRING);
05367 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
05368 built_in_attributes[(int) ENUM] \
05369 = tree_cons (built_in_attributes[(int) PURPOSE], \
05370 built_in_attributes[(int) VALUE], \
05371 built_in_attributes[(int) CHAIN]);
05372 #define DEF_FN_ATTR(NAME, ATTRS, PREDICATE)
05373 #include "builtin-attrs.def"
05374 #undef DEF_ATTR_NULL_TREE
05375 #undef DEF_ATTR_INT
05376 #undef DEF_ATTR_IDENT
05377 #undef DEF_ATTR_TREE_LIST
05378 #undef DEF_FN_ATTR
05379 c_attrs_initialized = true;
05380 }
05381
05382
05383
05384 void
05385 c_common_insert_default_attributes (decl)
05386 tree decl;
05387 {
05388 tree name = DECL_NAME (decl);
05389
05390 if (!c_attrs_initialized)
05391 c_init_attributes ();
05392
05393 #define DEF_ATTR_NULL_TREE(ENUM)
05394 #define DEF_ATTR_INT(ENUM, VALUE)
05395 #define DEF_ATTR_IDENT(ENUM, STRING)
05396 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN)
05397 #define DEF_FN_ATTR(NAME, ATTRS, PREDICATE) \
05398 if ((PREDICATE) && name == built_in_attributes[(int) NAME]) \
05399 decl_attributes (&decl, built_in_attributes[(int) ATTRS], \
05400 ATTR_FLAG_BUILT_IN);
05401 #include "builtin-attrs.def"
05402 #undef DEF_ATTR_NULL_TREE
05403 #undef DEF_ATTR_INT
05404 #undef DEF_ATTR_IDENT
05405 #undef DEF_ATTR_TREE_LIST
05406 #undef DEF_FN_ATTR
05407 }
05408
05409
05410
05411 void
05412 shadow_warning (msgid, name, decl)
05413 const char *msgid;
05414 tree name, decl;
05415 {
05416 warning ("declaration of `%s' shadows %s", IDENTIFIER_POINTER (name), msgid);
05417 warning_with_file_and_line (DECL_SOURCE_FILE (decl),
05418 DECL_SOURCE_LINE (decl),
05419 "shadowed declaration is here");
05420 }
05421
05422
05423
05424
05425
05426
05427 static tree
05428 handle_packed_attribute (node, name, args, flags, no_add_attrs)
05429 tree *node;
05430 tree name;
05431 tree args ATTRIBUTE_UNUSED;
05432 int flags;
05433 bool *no_add_attrs;
05434 {
05435 tree *type = NULL;
05436 if (DECL_P (*node))
05437 {
05438 if (TREE_CODE (*node) == TYPE_DECL)
05439 type = &TREE_TYPE (*node);
05440 }
05441 else
05442 type = node;
05443
05444 if (type)
05445 {
05446 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
05447 *type = build_type_copy (*type);
05448 TYPE_PACKED (*type) = 1;
05449 }
05450 else if (TREE_CODE (*node) == FIELD_DECL)
05451 DECL_PACKED (*node) = 1;
05452
05453
05454 else
05455 {
05456 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
05457 *no_add_attrs = true;
05458 }
05459
05460 return NULL_TREE;
05461 }
05462
05463
05464
05465
05466 static tree
05467 handle_nocommon_attribute (node, name, args, flags, no_add_attrs)
05468 tree *node;
05469 tree name;
05470 tree args ATTRIBUTE_UNUSED;
05471 int flags ATTRIBUTE_UNUSED;
05472 bool *no_add_attrs;
05473 {
05474 if (TREE_CODE (*node) == VAR_DECL)
05475 DECL_COMMON (*node) = 0;
05476 else
05477 {
05478 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
05479 *no_add_attrs = true;
05480 }
05481
05482 return NULL_TREE;
05483 }
05484
05485
05486
05487
05488 static tree
05489 handle_common_attribute (node, name, args, flags, no_add_attrs)
05490 tree *node;
05491 tree name;
05492 tree args ATTRIBUTE_UNUSED;
05493 int flags ATTRIBUTE_UNUSED;
05494 bool *no_add_attrs;
05495 {
05496 if (TREE_CODE (*node) == VAR_DECL)
05497 DECL_COMMON (*node) = 1;
05498 else
05499 {
05500 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
05501 *no_add_attrs = true;
05502 }
05503
05504 return NULL_TREE;
05505 }
05506
05507
05508
05509
05510 static tree
05511 handle_noreturn_attribute (node, name, args, flags, no_add_attrs)
05512 tree *node;
05513 tree name;
05514 tree args ATTRIBUTE_UNUSED;
05515 int flags ATTRIBUTE_UNUSED;
05516 bool *no_add_attrs;
05517 {
05518 tree type = TREE_TYPE (*node);
05519
05520
05521 if (TREE_CODE (*node) == FUNCTION_DECL)
05522 TREE_THIS_VOLATILE (*node) = 1;
05523 else if (TREE_CODE (type) == POINTER_TYPE
05524 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
05525 TREE_TYPE (*node)
05526 = build_pointer_type
05527 (build_type_variant (TREE_TYPE (type),
05528 TREE_READONLY (TREE_TYPE (type)), 1));
05529 else
05530 {
05531 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
05532 *no_add_attrs = true;
05533 }
05534
05535 return NULL_TREE;
05536 }
05537
05538
05539
05540
05541 static tree
05542 handle_noinline_attribute (node, name, args, flags, no_add_attrs)
05543 tree *node;
05544 tree name;
05545 tree args ATTRIBUTE_UNUSED;
05546 int flags ATTRIBUTE_UNUSED;
05547 bool *no_add_attrs;
05548 {
05549 if (TREE_CODE (*node) == FUNCTION_DECL)
05550 DECL_UNINLINABLE (*node) = 1;
05551 else
05552 {
05553 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
05554 *no_add_attrs = true;
05555 }
05556
05557 return NULL_TREE;
05558 }
05559
05560
05561
05562
05563 static tree
05564 handle_always_inline_attribute (node, name, args, flags, no_add_attrs)
05565 tree *node;
05566 tree name;
05567 tree args ATTRIBUTE_UNUSED;
05568 int flags ATTRIBUTE_UNUSED;
05569 bool *no_add_attrs;
05570 {
05571 if (TREE_CODE (*node) == FUNCTION_DECL)
05572 {
05573
05574
05575 }
05576 else
05577 {
05578 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
05579 *no_add_attrs = true;
05580 }
05581
05582 return NULL_TREE;
05583 }
05584
05585
05586
05587
05588 static tree
05589 handle_used_attribute (pnode, name, args, flags, no_add_attrs)
05590 tree *pnode;
05591 tree name;
05592 tree args ATTRIBUTE_UNUSED;
05593 int flags ATTRIBUTE_UNUSED;
05594 bool *no_add_attrs;
05595 {
05596 tree node = *pnode;
05597
05598 if (TREE_CODE (node) == FUNCTION_DECL
05599 || (TREE_CODE (node) == VAR_DECL && TREE_STATIC (node)))
05600 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (node))
05601 = TREE_USED (node) = 1;
05602 else
05603 {
05604 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
05605 *no_add_attrs = true;
05606 }
05607
05608 return NULL_TREE;
05609 }
05610
05611
05612
05613
05614 static tree
05615 handle_unused_attribute (node, name, args, flags, no_add_attrs)
05616 tree *node;
05617 tree name;
05618 tree args ATTRIBUTE_UNUSED;
05619 int flags;
05620 bool *no_add_attrs;
05621 {
05622 if (DECL_P (*node))
05623 {
05624 tree decl = *node;
05625
05626 if (TREE_CODE (decl) == PARM_DECL
05627 || TREE_CODE (decl) == VAR_DECL
05628 || TREE_CODE (decl) == FUNCTION_DECL
05629 || TREE_CODE (decl) == LABEL_DECL
05630 || TREE_CODE (decl) == TYPE_DECL)
05631 TREE_USED (decl) = 1;
05632 else
05633 {
05634 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
05635 *no_add_attrs = true;
05636 }
05637 }
05638 else
05639 {
05640 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
05641 *node = build_type_copy (*node);
05642 TREE_USED (*node) = 1;
05643 }
05644
05645 return NULL_TREE;
05646 }
05647
05648
05649
05650
05651 static tree
05652 handle_const_attribute (node, name, args, flags, no_add_attrs)
05653 tree *node;
05654 tree name;
05655 tree args ATTRIBUTE_UNUSED;
05656 int flags ATTRIBUTE_UNUSED;
05657 bool *no_add_attrs;
05658 {
05659 tree type = TREE_TYPE (*node);
05660
05661
05662 if (TREE_CODE (*node) == FUNCTION_DECL)
05663 TREE_READONLY (*node) = 1;
05664 else if (TREE_CODE (type) == POINTER_TYPE
05665 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
05666 TREE_TYPE (*node)
05667 = build_pointer_type
05668 (build_type_variant (TREE_TYPE (type), 1,
05669 TREE_THIS_VOLATILE (TREE_TYPE (type))));
05670 else
05671 {
05672 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
05673 *no_add_attrs = true;
05674 }
05675
05676 return NULL_TREE;
05677 }
05678
05679
05680
05681
05682 static tree
05683 handle_transparent_union_attribute (node, name, args, flags, no_add_attrs)
05684 tree *node;
05685 tree name;
05686 tree args ATTRIBUTE_UNUSED;
05687 int flags;
05688 bool *no_add_attrs;
05689 {
05690 tree decl = NULL_TREE;
05691 tree *type = NULL;
05692 int is_type = 0;
05693
05694 if (DECL_P (*node))
05695 {
05696 decl = *node;
05697 type = &TREE_TYPE (decl);
05698 is_type = TREE_CODE (*node) == TYPE_DECL;
05699 }
05700 else if (TYPE_P (*node))
05701 type = node, is_type = 1;
05702
05703 if (is_type
05704 && TREE_CODE (*type) == UNION_TYPE
05705 && (decl == 0
05706 || (TYPE_FIELDS (*type) != 0
05707 && TYPE_MODE (*type) == DECL_MODE (TYPE_FIELDS (*type)))))
05708 {
05709 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
05710 *type = build_type_copy (*type);
05711 TYPE_TRANSPARENT_UNION (*type) = 1;
05712 }
05713 else if (decl != 0 && TREE_CODE (decl) == PARM_DECL
05714 && TREE_CODE (*type) == UNION_TYPE
05715 && TYPE_MODE (*type) == DECL_MODE (TYPE_FIELDS (*type)))
05716 DECL_TRANSPARENT_UNION (decl) = 1;
05717 else
05718 {
05719 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
05720 *no_add_attrs = true;
05721 }
05722
05723 return NULL_TREE;
05724 }
05725
05726
05727
05728
05729 static tree
05730 handle_constructor_attribute (node, name, args, flags, no_add_attrs)
05731 tree *node;
05732 tree name;
05733 tree args ATTRIBUTE_UNUSED;
05734 int flags ATTRIBUTE_UNUSED;
05735 bool *no_add_attrs;
05736 {
05737 tree decl = *node;
05738 tree type = TREE_TYPE (decl);
05739
05740 if (TREE_CODE (decl) == FUNCTION_DECL
05741 && TREE_CODE (type) == FUNCTION_TYPE
05742 && decl_function_context (decl) == 0)
05743 {
05744 DECL_STATIC_CONSTRUCTOR (decl) = 1;
05745 TREE_USED (decl) = 1;
05746 }
05747 else
05748 {
05749 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
05750 *no_add_attrs = true;
05751 }
05752
05753 return NULL_TREE;
05754 }
05755
05756
05757
05758
05759 static tree
05760 handle_destructor_attribute (node, name, args, flags, no_add_attrs)
05761 tree *node;
05762 tree name;
05763 tree args ATTRIBUTE_UNUSED;
05764 int flags ATTRIBUTE_UNUSED;
05765 bool *no_add_attrs;
05766 {
05767 tree decl = *node;
05768 tree type = TREE_TYPE (decl);
05769
05770 if (TREE_CODE (decl) == FUNCTION_DECL
05771 && TREE_CODE (type) == FUNCTION_TYPE
05772 && decl_function_context (decl) == 0)
05773 {
05774 DECL_STATIC_DESTRUCTOR (decl) = 1;
05775 TREE_USED (decl) = 1;
05776 }
05777 else
05778 {
05779 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
05780 *no_add_attrs = true;
05781 }
05782
05783 return NULL_TREE;
05784 }
05785
05786
05787
05788
05789 static tree
05790 handle_mode_attribute (node, name, args, flags, no_add_attrs)
05791 tree *node;
05792 tree name;
05793 tree args;
05794 int flags ATTRIBUTE_UNUSED;
05795 bool *no_add_attrs;
05796 {
05797 tree type = *node;
05798
05799 *no_add_attrs = true;
05800
05801 if (TREE_CODE (TREE_VALUE (args)) != IDENTIFIER_NODE)
05802 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
05803 else
05804 {
05805 int j;
05806 const char *p = IDENTIFIER_POINTER (TREE_VALUE (args));
05807 int len = strlen (p);
05808 enum machine_mode mode = VOIDmode;
05809 tree typefm;
05810
05811 if (len > 4 && p[0] == '_' && p[1] == '_'
05812 && p[len - 1] == '_' && p[len - 2] == '_')
05813 {
05814 char *newp = (char *) alloca (len - 1);
05815
05816 strcpy (newp, &p[2]);
05817 newp[len - 4] = '\0';
05818 p = newp;
05819 }
05820
05821
05822
05823 if (! strcmp (p, "byte"))
05824 mode = byte_mode;
05825 else if (!strcmp (p, "word"))
05826 mode = word_mode;
05827 else if (! strcmp (p, "pointer"))
05828 mode = ptr_mode;
05829 else
05830 for (j = 0; j < NUM_MACHINE_MODES; j++)
05831 if (!strcmp (p, GET_MODE_NAME (j)))
05832 mode = (enum machine_mode) j;
05833
05834 if (mode == VOIDmode)
05835 error ("unknown machine mode `%s'", p);
05836 else if (0 == (typefm = (*lang_hooks.types.type_for_mode)
05837 (mode, TREE_UNSIGNED (type))))
05838 error ("no data type for mode `%s'", p);
05839 else
05840 {
05841
05842
05843 if ((GET_MODE_CLASS (mode) == MODE_VECTOR_INT
05844 || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT)
05845 && !vector_mode_valid_p (mode))
05846 {
05847 error ("unable to emulate '%s'", GET_MODE_NAME (mode));
05848 return NULL_TREE;
05849 }
05850
05851 *node = typefm;
05852
05853 }
05854 }
05855
05856 return NULL_TREE;
05857 }
05858
05859
05860
05861
05862 static tree
05863 handle_section_attribute (node, name, args, flags, no_add_attrs)
05864 tree *node;
05865 tree name ATTRIBUTE_UNUSED;
05866 tree args;
05867 int flags ATTRIBUTE_UNUSED;
05868 bool *no_add_attrs;
05869 {
05870 tree decl = *node;
05871
05872 if (targetm.have_named_sections)
05873 {
05874 if ((TREE_CODE (decl) == FUNCTION_DECL
05875 || TREE_CODE (decl) == VAR_DECL)
05876 && TREE_CODE (TREE_VALUE (args)) == STRING_CST)
05877 {
05878 if (TREE_CODE (decl) == VAR_DECL
05879 && current_function_decl != NULL_TREE
05880 && ! TREE_STATIC (decl))
05881 {
05882 error_with_decl (decl,
05883 "section attribute cannot be specified for local variables");
05884 *no_add_attrs = true;
05885 }
05886
05887
05888
05889 else if (DECL_SECTION_NAME (decl) != NULL_TREE
05890 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)),
05891 TREE_STRING_POINTER (TREE_VALUE (args))) != 0)
05892 {
05893 error_with_decl (*node,
05894 "section of `%s' conflicts with previous declaration");
05895 *no_add_attrs = true;
05896 }
05897 else
05898 DECL_SECTION_NAME (decl) = TREE_VALUE (args);
05899 }
05900 else
05901 {
05902 error_with_decl (*node,
05903 "section attribute not allowed for `%s'");
05904 *no_add_attrs = true;
05905 }
05906 }
05907 else
05908 {
05909 error_with_decl (*node,
05910 "section attributes are not supported for this target");
05911 *no_add_attrs = true;
05912 }
05913
05914 return NULL_TREE;
05915 }
05916
05917
05918
05919
05920 static tree
05921 handle_aligned_attribute (node, name, args, flags, no_add_attrs)
05922 tree *node;
05923 tree name ATTRIBUTE_UNUSED;
05924 tree args;
05925 int flags;
05926 bool *no_add_attrs;
05927 {
05928 tree decl = NULL_TREE;
05929 tree *type = NULL;
05930 int is_type = 0;
05931 tree align_expr = (args ? TREE_VALUE (args)
05932 : size_int (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
05933 int i;
05934
05935 if (DECL_P (*node))
05936 {
05937 decl = *node;
05938 type = &TREE_TYPE (decl);
05939 is_type = TREE_CODE (*node) == TYPE_DECL;
05940 }
05941 else if (TYPE_P (*node))
05942 type = node, is_type = 1;
05943
05944
05945 while (TREE_CODE (align_expr) == NOP_EXPR
05946 || TREE_CODE (align_expr) == CONVERT_EXPR
05947 || TREE_CODE (align_expr) == NON_LVALUE_EXPR)
05948 align_expr = TREE_OPERAND (align_expr, 0);
05949
05950 if (TREE_CODE (align_expr) != INTEGER_CST)
05951 {
05952 error ("requested alignment is not a constant");
05953 *no_add_attrs = true;
05954 }
05955 else if ((i = tree_log2 (align_expr)) == -1)
05956 {
05957 error ("requested alignment is not a power of 2");
05958 *no_add_attrs = true;
05959 }
05960 else if (i > HOST_BITS_PER_INT - 2)
05961 {
05962 error ("requested alignment is too large");
05963 *no_add_attrs = true;
05964 }
05965 else if (is_type)
05966 {
05967
05968
05969 if (decl && TREE_TYPE (decl) != error_mark_node
05970 && DECL_ORIGINAL_TYPE (decl) == NULL_TREE)
05971 {
05972 tree tt = TREE_TYPE (decl);
05973 *type = build_type_copy (*type);
05974 DECL_ORIGINAL_TYPE (decl) = tt;
05975 TYPE_NAME (*type) = decl;
05976 TREE_USED (*type) = TREE_USED (decl);
05977 TREE_TYPE (decl) = *type;
05978 }
05979 else if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
05980 *type = build_type_copy (*type);
05981
05982 TYPE_ALIGN (*type) = (1 << i) * BITS_PER_UNIT;
05983 TYPE_USER_ALIGN (*type) = 1;
05984 }
05985 else if (TREE_CODE (decl) != VAR_DECL
05986 && TREE_CODE (decl) != FIELD_DECL)
05987 {
05988 error_with_decl (decl,
05989 "alignment may not be specified for `%s'");
05990 *no_add_attrs = true;
05991 }
05992 else
05993 {
05994 DECL_ALIGN (decl) = (1 << i) * BITS_PER_UNIT;
05995 DECL_USER_ALIGN (decl) = 1;
05996 }
05997
05998 return NULL_TREE;
05999 }
06000
06001
06002
06003
06004 static tree
06005 handle_weak_attribute (node, name, args, flags, no_add_attrs)
06006 tree *node;
06007 tree name ATTRIBUTE_UNUSED;
06008 tree args ATTRIBUTE_UNUSED;
06009 int flags ATTRIBUTE_UNUSED;
06010 bool *no_add_attrs ATTRIBUTE_UNUSED;
06011 {
06012 declare_weak (*node);
06013
06014 return NULL_TREE;
06015 }
06016
06017
06018
06019
06020 static tree
06021 handle_alias_attribute (node, name, args, flags, no_add_attrs)
06022 tree *node;
06023 tree name;
06024 tree args;
06025 int flags ATTRIBUTE_UNUSED;
06026 bool *no_add_attrs;
06027 {
06028 tree decl = *node;
06029
06030 if ((TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
06031 || (TREE_CODE (decl) != FUNCTION_DECL && ! DECL_EXTERNAL (decl)))
06032 {
06033 error_with_decl (decl,
06034 "`%s' defined both normally and as an alias");
06035 *no_add_attrs = true;
06036 }
06037 else if (decl_function_context (decl) == 0)
06038 {
06039 tree id;
06040
06041 id = TREE_VALUE (args);
06042 if (TREE_CODE (id) != STRING_CST)
06043 {
06044 error ("alias arg not a string");
06045 *no_add_attrs = true;
06046 return NULL_TREE;
06047 }
06048 id = get_identifier (TREE_STRING_POINTER (id));
06049
06050 TREE_USED (id) = 1;
06051
06052 if (TREE_CODE (decl) == FUNCTION_DECL)
06053 DECL_INITIAL (decl) = error_mark_node;
06054 else
06055 DECL_EXTERNAL (decl) = 0;
06056 }
06057 else
06058 {
06059 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
06060 *no_add_attrs = true;
06061 }
06062
06063 return NULL_TREE;
06064 }
06065
06066
06067
06068
06069 static tree
06070 handle_visibility_attribute (node, name, args, flags, no_add_attrs)
06071 tree *node;
06072 tree name;
06073 tree args;
06074 int flags ATTRIBUTE_UNUSED;
06075 bool *no_add_attrs;
06076 {
06077 tree decl = *node;
06078
06079 if (decl_function_context (decl) != 0 || ! TREE_PUBLIC (decl))
06080 {
06081 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
06082 *no_add_attrs = true;
06083 }
06084 else
06085 {
06086 tree id;
06087
06088 id = TREE_VALUE (args);
06089 if (TREE_CODE (id) != STRING_CST)
06090 {
06091 error ("visibility arg not a string");
06092 *no_add_attrs = true;
06093 return NULL_TREE;
06094 }
06095 if (strcmp (TREE_STRING_POINTER (id), "hidden")
06096 && strcmp (TREE_STRING_POINTER (id), "protected")
06097 && strcmp (TREE_STRING_POINTER (id), "internal")
06098 && strcmp (TREE_STRING_POINTER (id), "default"))
06099 {
06100 error ("visibility arg must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
06101 *no_add_attrs = true;
06102 return NULL_TREE;
06103 }
06104 }
06105
06106 return NULL_TREE;
06107 }
06108
06109
06110
06111
06112 static tree
06113 handle_tls_model_attribute (node, name, args, flags, no_add_attrs)
06114 tree *node;
06115 tree name;
06116 tree args;
06117 int flags ATTRIBUTE_UNUSED;
06118 bool *no_add_attrs;
06119 {
06120 tree decl = *node;
06121
06122 if (! DECL_THREAD_LOCAL (decl))
06123 {
06124 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
06125 *no_add_attrs = true;
06126 }
06127 else
06128 {
06129 tree id;
06130
06131 id = TREE_VALUE (args);
06132 if (TREE_CODE (id) != STRING_CST)
06133 {
06134 error ("tls_model arg not a string");
06135 *no_add_attrs = true;
06136 return NULL_TREE;
06137 }
06138 if (strcmp (TREE_STRING_POINTER (id), "local-exec")
06139 && strcmp (TREE_STRING_POINTER (id), "initial-exec")
06140 && strcmp (TREE_STRING_POINTER (id), "local-dynamic")
06141 && strcmp (TREE_STRING_POINTER (id), "global-dynamic"))
06142 {
06143 error ("tls_model arg must be one of \"local-exec\", \"initial-exec\", \"local-dynamic\" or \"global-dynamic\"");
06144 *no_add_attrs = true;
06145 return NULL_TREE;
06146 }
06147 }
06148
06149 return NULL_TREE;
06150 }
06151
06152
06153
06154
06155 static tree
06156 handle_no_instrument_function_attribute (node, name, args, flags, no_add_attrs)
06157 tree *node;
06158 tree name;
06159 tree args ATTRIBUTE_UNUSED;
06160 int flags ATTRIBUTE_UNUSED;
06161 bool *no_add_attrs;
06162 {
06163 tree decl = *node;
06164
06165 if (TREE_CODE (decl) != FUNCTION_DECL)
06166 {
06167 error_with_decl (decl,
06168 "`%s' attribute applies only to functions",
06169 IDENTIFIER_POINTER (name));
06170 *no_add_attrs = true;
06171 }
06172 else if (DECL_INITIAL (decl))
06173 {
06174 error_with_decl (decl,
06175 "can't set `%s' attribute after definition",
06176 IDENTIFIER_POINTER (name));
06177 *no_add_attrs = true;
06178 }
06179 else
06180 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl) = 1;
06181
06182 return NULL_TREE;
06183 }
06184
06185
06186
06187
06188 static tree
06189 handle_malloc_attribute (node, name, args, flags, no_add_attrs)
06190 tree *node;
06191 tree name;
06192 tree args ATTRIBUTE_UNUSED;
06193 int flags ATTRIBUTE_UNUSED;
06194 bool *no_add_attrs;
06195 {
06196 if (TREE_CODE (*node) == FUNCTION_DECL)
06197 DECL_IS_MALLOC (*node) = 1;
06198
06199 else
06200 {
06201 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
06202 *no_add_attrs = true;
06203 }
06204
06205 return NULL_TREE;
06206 }
06207
06208
06209
06210
06211 static tree
06212 handle_no_limit_stack_attribute (node, name, args, flags, no_add_attrs)
06213 tree *node;
06214 tree name;
06215 tree args ATTRIBUTE_UNUSED;
06216 int flags ATTRIBUTE_UNUSED;
06217 bool *no_add_attrs;
06218 {
06219 tree decl = *node;
06220
06221 if (TREE_CODE (decl) != FUNCTION_DECL)
06222 {
06223 error_with_decl (decl,
06224 "`%s' attribute applies only to functions",
06225 IDENTIFIER_POINTER (name));
06226 *no_add_attrs = true;
06227 }
06228 else if (DECL_INITIAL (decl))
06229 {
06230 error_with_decl (decl,
06231 "can't set `%s' attribute after definition",
06232 IDENTIFIER_POINTER (name));
06233 *no_add_attrs = true;
06234 }
06235 else
06236 DECL_NO_LIMIT_STACK (decl) = 1;
06237
06238 return NULL_TREE;
06239 }
06240
06241
06242
06243
06244 static tree
06245 handle_pure_attribute (node, name, args, flags, no_add_attrs)
06246 tree *node;
06247 tree name;
06248 tree args ATTRIBUTE_UNUSED;
06249 int flags ATTRIBUTE_UNUSED;
06250 bool *no_add_attrs;
06251 {
06252 if (TREE_CODE (*node) == FUNCTION_DECL)
06253 DECL_IS_PURE (*node) = 1;
06254
06255 else
06256 {
06257 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
06258 *no_add_attrs = true;
06259 }
06260
06261 return NULL_TREE;
06262 }
06263
06264
06265
06266
06267 static tree
06268 handle_cleanup_attribute (node, name, args, flags, no_add_attrs)
06269 tree *node;
06270 tree name;
06271 tree args;
06272 int flags ATTRIBUTE_UNUSED;
06273 bool *no_add_attrs;
06274 {
06275 tree decl = *node;
06276 tree cleanup_id, cleanup_decl;
06277
06278
06279
06280
06281
06282 if (TREE_CODE (decl) != VAR_DECL || TREE_STATIC (decl))
06283 {
06284 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
06285 *no_add_attrs = true;
06286 return NULL_TREE;
06287 }
06288
06289
06290
06291
06292 cleanup_id = TREE_VALUE (args);
06293 if (TREE_CODE (cleanup_id) != IDENTIFIER_NODE)
06294 {
06295 error ("cleanup arg not an identifier");
06296 *no_add_attrs = true;
06297 return NULL_TREE;
06298 }
06299 cleanup_decl = lookup_name (cleanup_id);
06300 if (!cleanup_decl || TREE_CODE (cleanup_decl) != FUNCTION_DECL)
06301 {
06302 error ("cleanup arg not a function");
06303 *no_add_attrs = true;
06304 return NULL_TREE;
06305 }
06306
06307
06308
06309
06310 return NULL_TREE;
06311 }
06312
06313
06314
06315
06316 static tree
06317 handle_deprecated_attribute (node, name, args, flags, no_add_attrs)
06318 tree *node;
06319 tree name;
06320 tree args ATTRIBUTE_UNUSED;
06321 int flags;
06322 bool *no_add_attrs;
06323 {
06324 tree type = NULL_TREE;
06325 int warn = 0;
06326 const char *what = NULL;
06327
06328 if (DECL_P (*node))
06329 {
06330 tree decl = *node;
06331 type = TREE_TYPE (decl);
06332
06333 if (TREE_CODE (decl) == TYPE_DECL
06334 || TREE_CODE (decl) == PARM_DECL
06335 || TREE_CODE (decl) == VAR_DECL
06336 || TREE_CODE (decl) == FUNCTION_DECL
06337 || TREE_CODE (decl) == FIELD_DECL)
06338 TREE_DEPRECATED (decl) = 1;
06339 else
06340 warn = 1;
06341 }
06342 else if (TYPE_P (*node))
06343 {
06344 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
06345 *node = build_type_copy (*node);
06346 TREE_DEPRECATED (*node) = 1;
06347 type = *node;
06348 }
06349 else
06350 warn = 1;
06351
06352 if (warn)
06353 {
06354 *no_add_attrs = true;
06355 if (type && TYPE_NAME (type))
06356 {
06357 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
06358 what = IDENTIFIER_POINTER (TYPE_NAME (*node));
06359 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
06360 && DECL_NAME (TYPE_NAME (type)))
06361 what = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
06362 }
06363 if (what)
06364 warning ("`%s' attribute ignored for `%s'",
06365 IDENTIFIER_POINTER (name), what);
06366 else
06367 warning ("`%s' attribute ignored",
06368 IDENTIFIER_POINTER (name));
06369 }
06370
06371 return NULL_TREE;
06372 }
06373
06374
06375
06376
06377
06378
06379 static GTY(()) tree vector_type_node_list = 0;
06380
06381
06382
06383
06384 static tree
06385 handle_vector_size_attribute (node, name, args, flags, no_add_attrs)
06386 tree *node;
06387 tree name;
06388 tree args;
06389 int flags ATTRIBUTE_UNUSED;
06390 bool *no_add_attrs;
06391 {
06392 unsigned HOST_WIDE_INT vecsize, nunits;
06393 enum machine_mode mode, orig_mode, new_mode;
06394 tree type = *node, new_type = NULL_TREE;
06395 tree type_list_node;
06396
06397 *no_add_attrs = true;
06398
06399 if (! host_integerp (TREE_VALUE (args), 1))
06400 {
06401 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
06402 return NULL_TREE;
06403 }
06404
06405
06406 vecsize = tree_low_cst (TREE_VALUE (args), 1);
06407
06408
06409
06410
06411
06412
06413
06414
06415
06416 while (POINTER_TYPE_P (type)
06417 || TREE_CODE (type) == FUNCTION_TYPE
06418 || TREE_CODE (type) == ARRAY_TYPE)
06419 type = TREE_TYPE (type);
06420
06421
06422 orig_mode = TYPE_MODE (type);
06423
06424 if (TREE_CODE (type) == RECORD_TYPE
06425 || (GET_MODE_CLASS (orig_mode) != MODE_FLOAT
06426 && GET_MODE_CLASS (orig_mode) != MODE_INT)
06427 || ! host_integerp (TYPE_SIZE_UNIT (type), 1))
06428 {
06429 error ("invalid vector type for attribute `%s'",
06430 IDENTIFIER_POINTER (name));
06431 return NULL_TREE;
06432 }
06433
06434
06435 nunits = vecsize / tree_low_cst (TYPE_SIZE_UNIT (type), 1);
06436
06437
06438 new_mode = VOIDmode;
06439 for (mode = GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_mode) == MODE_INT
06440 ? MODE_VECTOR_INT
06441 : MODE_VECTOR_FLOAT);
06442 mode != VOIDmode;
06443 mode = GET_MODE_WIDER_MODE (mode))
06444 if (vecsize == GET_MODE_SIZE (mode)
06445 && nunits == (unsigned HOST_WIDE_INT) GET_MODE_NUNITS (mode))
06446 {
06447 new_mode = mode;
06448 break;
06449 }
06450
06451 if (new_mode == VOIDmode)
06452 {
06453 error ("no vector mode with the size and type specified could be found");
06454 return NULL_TREE;
06455 }
06456
06457 for (type_list_node = vector_type_node_list; type_list_node;
06458 type_list_node = TREE_CHAIN (type_list_node))
06459 {
06460 tree other_type = TREE_VALUE (type_list_node);
06461 tree record = TYPE_DEBUG_REPRESENTATION_TYPE (other_type);
06462 tree fields = TYPE_FIELDS (record);
06463 tree field_type = TREE_TYPE (fields);
06464 tree array_type = TREE_TYPE (field_type);
06465 if (TREE_CODE (fields) != FIELD_DECL
06466 || TREE_CODE (field_type) != ARRAY_TYPE)
06467 abort ();
06468
06469 if (TYPE_MODE (other_type) == mode && type == array_type)
06470 {
06471 new_type = other_type;
06472 break;
06473 }
06474 }
06475
06476 if (new_type == NULL_TREE)
06477 {
06478 tree index, array, rt, list_node;
06479
06480 new_type = (*lang_hooks.types.type_for_mode) (new_mode,
06481 TREE_UNSIGNED (type));
06482
06483 if (!new_type)
06484 {
06485 error ("no vector mode with the size and type specified could be found");
06486 return NULL_TREE;
06487 }
06488
06489 new_type = build_type_copy (new_type);
06490
06491
06492
06493 if ((GET_MODE_CLASS (mode) == MODE_VECTOR_INT
06494 || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT)
06495 && !vector_mode_valid_p (mode))
06496 {
06497 error ("unable to emulate '%s'", GET_MODE_NAME (mode));
06498 return NULL_TREE;
06499 }
06500
06501
06502
06503
06504
06505 index = build_int_2 (TYPE_VECTOR_SUBPARTS (new_type) - 1, 0);
06506 array = build_array_type (type, build_index_type (index));
06507 rt = make_node (RECORD_TYPE);
06508
06509 TYPE_FIELDS (rt) = build_decl (FIELD_DECL, get_identifier ("f"), array);
06510 DECL_CONTEXT (TYPE_FIELDS (rt)) = rt;
06511 layout_type (rt);
06512 TYPE_DEBUG_REPRESENTATION_TYPE (new_type) = rt;
06513
06514 list_node = build_tree_list (NULL, new_type);
06515 TREE_CHAIN (list_node) = vector_type_node_list;
06516 vector_type_node_list = list_node;
06517 }
06518
06519
06520 *node = vector_size_helper (*node, new_type);
06521
06522 return NULL_TREE;
06523 }
06524
06525 #ifdef SGI_MONGOOSE
06526
06527
06528
06529 static tree
06530 handle_syscall_linkage_attribute (node, name, args, flags, no_add_attrs)
06531 tree *node;
06532 tree name;
06533 tree args;
06534 int flags ATTRIBUTE_UNUSED;
06535 bool *no_add_attrs;
06536 {
06537 int arg_num;
06538 tree argument;
06539 tree decl = *node;
06540 tree type = TREE_TYPE (decl);
06541
06542 if (TREE_CODE (decl) != FUNCTION_DECL)
06543 {
06544 error_with_decl (decl,
06545 "argument format specified for non-function `%s'");
06546 return NULL_TREE;
06547 }
06548 argument = TYPE_ARG_TYPES (type);
06549
06550
06551 for (argument = TYPE_ARG_TYPES(type); argument;
06552 argument = TREE_CHAIN(argument))
06553 {
06554 if (FLOAT_TYPE_P (TREE_VALUE (argument)))
06555 {
06556 warning ("readonlyargs/syscall_linkage won't work when floating point args");
06557 continue;
06558 }
06559 }
06560 DECL_SYSCALL_LINKAGE (decl) = 1;
06561
06562 return NULL_TREE;
06563 }
06564
06565
06566
06567
06568 static tree
06569 handle_widenretval_attribute (node, name, args, flags, no_add_attrs)
06570 tree *node;
06571 tree name;
06572 tree args;
06573 int flags ATTRIBUTE_UNUSED;
06574 bool *no_add_attrs;
06575 {
06576 int arg_num;
06577 tree argument;
06578 tree decl = *node;
06579 tree type = TREE_TYPE (decl);
06580
06581 if (TREE_CODE (decl) != FUNCTION_DECL)
06582 {
06583 error_with_decl (decl,
06584 "argument format specified for non-function `%s'");
06585 return NULL_TREE;
06586 }
06587
06588
06589 if ((TREE_CODE (TREE_TYPE (type)) == VOID_TYPE) ||
06590 POINTER_TYPE_P (TREE_TYPE (type)))
06591 {
06592 return NULL_TREE;
06593 }
06594
06595
06596 if (!INTEGRAL_TYPE_P (TREE_TYPE (type)))
06597 {
06598 warning ("widenretval won't work for non integral returns");
06599 return NULL_TREE;
06600 }
06601
06602
06603 if (!(TYPE_PRECISION(TREE_TYPE (type)) < TYPE_PRECISION(long_long_integer_type_node)))
06604 {
06605 return NULL_TREE;
06606 }
06607 DECL_WIDEN_RETVAL (decl) = 1;
06608 }
06609 #endif
06610
06611
06612 #if defined(TARG_SL)
06613 static tree
06614 handle_sl_model_attribute (node, name, args, flags, no_add_attrs)
06615 tree *node;
06616 tree name;
06617 tree args;
06618 int flags ATTRIBUTE_UNUSED;
06619 bool *no_add_attrs;
06620 {
06621
06622 tree decl = *node;
06623
06624 if ((TREE_CODE (decl) == VAR_DECL)
06625 && TREE_CODE (TREE_VALUE (args)) == STRING_CST)
06626 {
06627 DECL_SL_MODEL_NAME (decl) = TREE_VALUE (args);
06628 }
06629 else
06630 {
06631 error_with_decl (*node,
06632 "sl model attribute not allowed for `%s'");
06633 *no_add_attrs = true;
06634 }
06635
06636 return NULL_TREE;
06637 }
06638 #endif
06639
06640
06641
06642
06643
06644
06645
06646
06647
06648
06649
06650
06651 static tree
06652 vector_size_helper (type, bottom)
06653 tree type, bottom;
06654 {
06655 tree inner, outer;
06656
06657 if (POINTER_TYPE_P (type))
06658 {
06659 inner = vector_size_helper (TREE_TYPE (type), bottom);
06660 outer = build_pointer_type (inner);
06661 }
06662 else if (TREE_CODE (type) == ARRAY_TYPE)
06663 {
06664 inner = vector_size_helper (TREE_TYPE (type), bottom);
06665 outer = build_array_type (inner, TYPE_VALUES (type));
06666 }
06667 else if (TREE_CODE (type) == FUNCTION_TYPE)
06668 {
06669 inner = vector_size_helper (TREE_TYPE (type), bottom);
06670 outer = build_function_type (inner, TYPE_VALUES (type));
06671 }
06672 else
06673 return bottom;
06674
06675 TREE_READONLY (outer) = TREE_READONLY (type);
06676 TREE_THIS_VOLATILE (outer) = TREE_THIS_VOLATILE (type);
06677
06678 return outer;
06679 }
06680
06681
06682 static tree
06683 handle_nonnull_attribute (node, name, args, flags, no_add_attrs)
06684 tree *node;
06685 tree name ATTRIBUTE_UNUSED;
06686 tree args;
06687 int flags ATTRIBUTE_UNUSED;
06688 bool *no_add_attrs;
06689 {
06690 tree type = *node;
06691 unsigned HOST_WIDE_INT attr_arg_num;
06692
06693
06694
06695
06696 if (! args)
06697 {
06698 if (! TYPE_ARG_TYPES (type))
06699 {
06700 error ("nonnull attribute without arguments on a non-prototype");
06701 *no_add_attrs = true;
06702 }
06703 return NULL_TREE;
06704 }
06705
06706
06707
06708 for (attr_arg_num = 1; args; args = TREE_CHAIN (args))
06709 {
06710 tree argument;
06711 unsigned HOST_WIDE_INT arg_num, ck_num;
06712
06713 if (! get_nonnull_operand (TREE_VALUE (args), &arg_num))
06714 {
06715 error ("nonnull argument has invalid operand number (arg %lu)",
06716 (unsigned long) attr_arg_num);
06717 *no_add_attrs = true;
06718 return NULL_TREE;
06719 }
06720
06721 argument = TYPE_ARG_TYPES (type);
06722 if (argument)
06723 {
06724 for (ck_num = 1; ; ck_num++)
06725 {
06726 if (! argument || ck_num == arg_num)
06727 break;
06728 argument = TREE_CHAIN (argument);
06729 }
06730
06731 if (! argument
06732 || TREE_CODE (TREE_VALUE (argument)) == VOID_TYPE)
06733 {
06734 error ("nonnull argument with out-of-range operand number (arg %lu, operand %lu)",
06735 (unsigned long) attr_arg_num, (unsigned long) arg_num);
06736 *no_add_attrs = true;
06737 return NULL_TREE;
06738 }
06739
06740 if (TREE_CODE (TREE_VALUE (argument)) != POINTER_TYPE)
06741 {
06742 error ("nonnull argument references non-pointer operand (arg %lu, operand %lu)",
06743 (unsigned long) attr_arg_num, (unsigned long) arg_num);
06744 *no_add_attrs = true;
06745 return NULL_TREE;
06746 }
06747 }
06748 }
06749
06750 return NULL_TREE;
06751 }
06752
06753
06754
06755
06756 static void
06757 check_function_nonnull (attrs, params)
06758 tree attrs;
06759 tree params;
06760 {
06761 tree a, args, param;
06762 int param_num;
06763
06764 for (a = attrs; a; a = TREE_CHAIN (a))
06765 {
06766 if (is_attribute_p ("nonnull", TREE_PURPOSE (a)))
06767 {
06768 args = TREE_VALUE (a);
06769
06770
06771
06772
06773
06774 for (param = params, param_num = 1; ;
06775 param_num++, param = TREE_CHAIN (param))
06776 {
06777 if (! param)
06778 break;
06779 if (! args || nonnull_check_p (args, param_num))
06780 check_function_arguments_recurse (check_nonnull_arg, NULL,
06781 TREE_VALUE (param),
06782 param_num);
06783 }
06784 }
06785 }
06786 }
06787
06788
06789
06790
06791
06792 static bool
06793 nonnull_check_p (args, param_num)
06794 tree args;
06795 unsigned HOST_WIDE_INT param_num;
06796 {
06797 unsigned HOST_WIDE_INT arg_num;
06798
06799 for (; args; args = TREE_CHAIN (args))
06800 {
06801 if (! get_nonnull_operand (TREE_VALUE (args), &arg_num))
06802 abort ();
06803
06804 if (arg_num == param_num)
06805 return true;
06806 }
06807 return false;
06808 }
06809
06810
06811
06812
06813
06814 static void
06815 check_nonnull_arg (ctx, param, param_num)
06816 void *ctx ATTRIBUTE_UNUSED;
06817 tree param;
06818 unsigned HOST_WIDE_INT param_num;
06819 {
06820
06821
06822
06823
06824 if (TREE_CODE (TREE_TYPE (param)) != POINTER_TYPE)
06825 return;
06826
06827 if (integer_zerop (param))
06828 warning ("null argument where non-null required (arg %lu)",
06829 (unsigned long) param_num);
06830 }
06831
06832
06833
06834
06835 static bool
06836 get_nonnull_operand (arg_num_expr, valp)
06837 tree arg_num_expr;
06838 unsigned HOST_WIDE_INT *valp;
06839 {
06840
06841
06842 while (TREE_CODE (arg_num_expr) == NOP_EXPR
06843 || TREE_CODE (arg_num_expr) == CONVERT_EXPR
06844 || TREE_CODE (arg_num_expr) == NON_LVALUE_EXPR)
06845 arg_num_expr = TREE_OPERAND (arg_num_expr, 0);
06846
06847 if (TREE_CODE (arg_num_expr) != INTEGER_CST
06848 || TREE_INT_CST_HIGH (arg_num_expr) != 0)
06849 return false;
06850
06851 *valp = TREE_INT_CST_LOW (arg_num_expr);
06852 return true;
06853 }
06854
06855
06856
06857
06858 static tree
06859 handle_nothrow_attribute (node, name, args, flags, no_add_attrs)
06860 tree *node;
06861 tree name;
06862 tree args ATTRIBUTE_UNUSED;
06863 int flags ATTRIBUTE_UNUSED;
06864 bool *no_add_attrs;
06865 {
06866 if (TREE_CODE (*node) == FUNCTION_DECL)
06867 TREE_NOTHROW (*node) = 1;
06868
06869 else
06870 {
06871 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
06872 *no_add_attrs = true;
06873 }
06874
06875 return NULL_TREE;
06876 }
06877
06878
06879 void
06880 check_function_arguments (attrs, params)
06881 tree attrs;
06882 tree params;
06883 {
06884
06885
06886
06887 if (warn_nonnull)
06888 check_function_nonnull (attrs, params);
06889
06890
06891
06892 if (warn_format)
06893 check_function_format (NULL, attrs, params);
06894 }
06895
06896
06897
06898
06899 void
06900 check_function_arguments_recurse (callback, ctx, param, param_num)
06901 void (*callback) PARAMS ((void *, tree, unsigned HOST_WIDE_INT));
06902 void *ctx;
06903 tree param;
06904 unsigned HOST_WIDE_INT param_num;
06905 {
06906 if (TREE_CODE (param) == NOP_EXPR)
06907 {
06908
06909 check_function_arguments_recurse (callback, ctx,
06910 TREE_OPERAND (param, 0), param_num);
06911 return;
06912 }
06913
06914 if (TREE_CODE (param) == CALL_EXPR)
06915 {
06916 tree type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (param, 0)));
06917 tree attrs;
06918 bool found_format_arg = false;
06919
06920
06921
06922
06923
06924 for (attrs = TYPE_ATTRIBUTES (type);
06925 attrs;
06926 attrs = TREE_CHAIN (attrs))
06927 if (is_attribute_p ("format_arg", TREE_PURPOSE (attrs)))
06928 {
06929 tree inner_args;
06930 tree format_num_expr;
06931 int format_num;
06932 int i;
06933
06934
06935
06936 format_num_expr = TREE_VALUE (TREE_VALUE (attrs));
06937 while (TREE_CODE (format_num_expr) == NOP_EXPR
06938 || TREE_CODE (format_num_expr) == CONVERT_EXPR
06939 || TREE_CODE (format_num_expr) == NON_LVALUE_EXPR)
06940 format_num_expr = TREE_OPERAND (format_num_expr, 0);
06941
06942 if (TREE_CODE (format_num_expr) != INTEGER_CST
06943 || TREE_INT_CST_HIGH (format_num_expr) != 0)
06944 abort ();
06945
06946 format_num = TREE_INT_CST_LOW (format_num_expr);
06947
06948 for (inner_args = TREE_OPERAND (param, 1), i = 1;
06949 inner_args != 0;
06950 inner_args = TREE_CHAIN (inner_args), i++)
06951 if (i == format_num)
06952 {
06953 check_function_arguments_recurse (callback, ctx,
06954 TREE_VALUE (inner_args),
06955 param_num);
06956 found_format_arg = true;
06957 break;
06958 }
06959 }
06960
06961
06962
06963
06964 if (found_format_arg)
06965 return;
06966 }
06967
06968 if (TREE_CODE (param) == COND_EXPR)
06969 {
06970
06971 check_function_arguments_recurse (callback, ctx,
06972 TREE_OPERAND (param, 1), param_num);
06973 check_function_arguments_recurse (callback, ctx,
06974 TREE_OPERAND (param, 2), param_num);
06975 return;
06976 }
06977
06978 (*callback) (ctx, param, param_num);
06979 }
06980
06981 #include "gt-c-common.h"