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