Deleted Added
full compact
c-common.c (110621) c-common.c (117404)
1/* Subroutines shared by all languages that are variants of C.
2 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002 Free Software Foundation, Inc.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free

--- 8 unchanged lines hidden (view full) ---

17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING. If not, write to the Free
19Software Foundation, 59 Temple Place - Suite 330, Boston, MA
2002111-1307, USA. */
21
22#include "config.h"
23#include "system.h"
24#include "tree.h"
1/* Subroutines shared by all languages that are variants of C.
2 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002 Free Software Foundation, Inc.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free

--- 8 unchanged lines hidden (view full) ---

17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING. If not, write to the Free
19Software Foundation, 59 Temple Place - Suite 330, Boston, MA
2002111-1307, USA. */
21
22#include "config.h"
23#include "system.h"
24#include "tree.h"
25#include "real.h"
25#include "flags.h"
26#include "toplev.h"
27#include "output.h"
28#include "c-pragma.h"
29#include "rtl.h"
30#include "ggc.h"
31#include "expr.h"
32#include "c-common.h"
26#include "flags.h"
27#include "toplev.h"
28#include "output.h"
29#include "c-pragma.h"
30#include "rtl.h"
31#include "ggc.h"
32#include "expr.h"
33#include "c-common.h"
33#include "tree-inline.h"
34#include "diagnostic.h"
35#include "tm_p.h"
36#include "obstack.h"
34#include "diagnostic.h"
35#include "tm_p.h"
36#include "obstack.h"
37#include "c-lex.h"
38#include "cpplib.h"
39#include "target.h"
37#include "cpplib.h"
38#include "target.h"
40cpp_reader *parse_in; /* Declared in c-lex.h. */
39#include "langhooks.h"
40#include "except.h" /* For USING_SJLJ_EXCEPTIONS. */
41#include "tree-inline.h"
42#include "c-tree.h"
41
43
42#undef WCHAR_TYPE_SIZE
43#define WCHAR_TYPE_SIZE TYPE_PRECISION (wchar_type_node)
44cpp_reader *parse_in; /* Declared in c-pragma.h. */
44
45/* We let tm.h override the types used here, to handle trivial differences
46 such as the choice of unsigned int or long unsigned int for size_t.
47 When machines start needing nontrivial differences in the size type,
48 it would be best to do something here to figure out automatically
49 from other information what type to use. */
50
51#ifndef SIZE_TYPE
52#define SIZE_TYPE "long unsigned int"
53#endif
54
55#ifndef WCHAR_TYPE
56#define WCHAR_TYPE "int"
57#endif
58
45
46/* We let tm.h override the types used here, to handle trivial differences
47 such as the choice of unsigned int or long unsigned int for size_t.
48 When machines start needing nontrivial differences in the size type,
49 it would be best to do something here to figure out automatically
50 from other information what type to use. */
51
52#ifndef SIZE_TYPE
53#define SIZE_TYPE "long unsigned int"
54#endif
55
56#ifndef WCHAR_TYPE
57#define WCHAR_TYPE "int"
58#endif
59
60/* WCHAR_TYPE gets overridden by -fshort-wchar. */
61#define MODIFIED_WCHAR_TYPE \
62 (flag_short_wchar ? "short unsigned int" : WCHAR_TYPE)
63
59#ifndef PTRDIFF_TYPE
60#define PTRDIFF_TYPE "long int"
61#endif
62
63#ifndef WINT_TYPE
64#define WINT_TYPE "unsigned int"
65#endif
66

--- 8 unchanged lines hidden (view full) ---

75#ifndef UINTMAX_TYPE
76#define UINTMAX_TYPE ((INT_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
77 ? "unsigned int" \
78 : ((LONG_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
79 ? "long unsigned int" \
80 : "long long unsigned int"))
81#endif
82
64#ifndef PTRDIFF_TYPE
65#define PTRDIFF_TYPE "long int"
66#endif
67
68#ifndef WINT_TYPE
69#define WINT_TYPE "unsigned int"
70#endif
71

--- 8 unchanged lines hidden (view full) ---

80#ifndef UINTMAX_TYPE
81#define UINTMAX_TYPE ((INT_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
82 ? "unsigned int" \
83 : ((LONG_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
84 ? "long unsigned int" \
85 : "long long unsigned int"))
86#endif
87
88#ifndef REGISTER_PREFIX
89#define REGISTER_PREFIX ""
90#endif
91
83/* The variant of the C language being processed. */
84
85enum c_language_kind c_language;
86
87/* The following symbols are subsumed in the c_global_trees array, and
88 listed here individually for documentation purposes.
89
90 INTEGER_TYPE and REAL_TYPE nodes for the standard data types.

--- 84 unchanged lines hidden (view full) ---

175 Stack of nested function name VAR_DECLs.
176
177 tree saved_function_name_decls;
178
179*/
180
181tree c_global_trees[CTI_MAX];
182
92/* The variant of the C language being processed. */
93
94enum c_language_kind c_language;
95
96/* The following symbols are subsumed in the c_global_trees array, and
97 listed here individually for documentation purposes.
98
99 INTEGER_TYPE and REAL_TYPE nodes for the standard data types.

--- 84 unchanged lines hidden (view full) ---

184 Stack of nested function name VAR_DECLs.
185
186 tree saved_function_name_decls;
187
188*/
189
190tree c_global_trees[CTI_MAX];
191
192/* Switches common to the C front ends. */
193
194/* Nonzero if prepreprocessing only. */
195int flag_preprocess_only;
196
197/* Nonzero if an ISO standard was selected. It rejects macros in the
198 user's namespace. */
199int flag_iso;
200
201/* Nonzero whenever Objective-C functionality is being used. */
202int flag_objc;
203
204/* Nonzero if -undef was given. It suppresses target built-in macros
205 and assertions. */
206int flag_undef;
207
183/* Nonzero means don't recognize the non-ANSI builtin functions. */
184
185int flag_no_builtin;
186
187/* Nonzero means don't recognize the non-ANSI builtin functions.
188 -ansi sets this. */
189
190int flag_no_nonansi_builtin;
191
192/* Nonzero means give `double' the same size as `float'. */
193
194int flag_short_double;
195
196/* Nonzero means give `wchar_t' the same size as `short'. */
197
198int flag_short_wchar;
199
208/* Nonzero means don't recognize the non-ANSI builtin functions. */
209
210int flag_no_builtin;
211
212/* Nonzero means don't recognize the non-ANSI builtin functions.
213 -ansi sets this. */
214
215int flag_no_nonansi_builtin;
216
217/* Nonzero means give `double' the same size as `float'. */
218
219int flag_short_double;
220
221/* Nonzero means give `wchar_t' the same size as `short'. */
222
223int flag_short_wchar;
224
225/* Nonzero means allow Microsoft extensions without warnings or errors. */
226int flag_ms_extensions;
227
228/* Nonzero means don't recognize the keyword `asm'. */
229
230int flag_no_asm;
231
232/* Nonzero means give string constants the type `const char *', as mandated
233 by the standard. */
234
235int flag_const_strings;
236
237/* Nonzero means `$' can be in an identifier. */
238
239#ifndef DOLLARS_IN_IDENTIFIERS
240#define DOLLARS_IN_IDENTIFIERS 1
241#endif
242int dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
243
244/* Nonzero means to treat bitfields as signed unless they say `unsigned'. */
245
246int flag_signed_bitfields = 1;
247int explicit_flag_signed_bitfields;
248
249/* Nonzero means warn about pointer casts that can drop a type qualifier
250 from the pointer target type. */
251
252int warn_cast_qual;
253
254/* Warn about functions which might be candidates for format attributes. */
255
256int warn_missing_format_attribute;
257
258/* Nonzero means warn about sizeof(function) or addition/subtraction
259 of function pointers. */
260
261int warn_pointer_arith;
262
263/* Nonzero means warn for any global function def
264 without separate previous prototype decl. */
265
266int warn_missing_prototypes;
267
268/* Warn if adding () is suggested. */
269
270int warn_parentheses;
271
272/* Warn if initializer is not completely bracketed. */
273
274int warn_missing_braces;
275
276/* Warn about comparison of signed and unsigned values.
277 If -1, neither -Wsign-compare nor -Wno-sign-compare has been specified. */
278
279int warn_sign_compare;
280
281/* Nonzero means warn about usage of long long when `-pedantic'. */
282
283int warn_long_long = 1;
284
285/* Nonzero means warn about deprecated conversion from string constant to
286 `char *'. */
287
288int warn_write_strings;
289
290/* Nonzero means warn about multiple (redundant) decls for the same single
291 variable or function. */
292
293int warn_redundant_decls;
294
295/* Warn about testing equality of floating point numbers. */
296
297int warn_float_equal;
298
299/* Warn about a subscript that has type char. */
300
301int warn_char_subscripts;
302
303/* Warn if a type conversion is done that might have confusing results. */
304
305int warn_conversion;
306
307/* Warn about #pragma directives that are not recognized. */
308
309int warn_unknown_pragmas; /* Tri state variable. */
310
311/* Warn about format/argument anomalies in calls to formatted I/O functions
312 (*printf, *scanf, strftime, strfmon, etc.). */
313
314int warn_format;
315
316/* Warn about Y2K problems with strftime formats. */
317
318int warn_format_y2k;
319
320/* Warn about excess arguments to formats. */
321
322int warn_format_extra_args;
323
324/* Warn about zero-length formats. */
325
326int warn_format_zero_length;
327
328/* Warn about non-literal format arguments. */
329
330int warn_format_nonliteral;
331
332/* Warn about possible security problems with calls to format functions. */
333
334int warn_format_security;
335
336
337/* C/ObjC language option variables. */
338
339
340/* Nonzero means message about use of implicit function declarations;
341 1 means warning; 2 means error. */
342
343int mesg_implicit_function_declaration = -1;
344
345/* Nonzero means allow type mismatches in conditional expressions;
346 just make their values `void'. */
347
348int flag_cond_mismatch;
349
350/* Nonzero means enable C89 Amendment 1 features. */
351
352int flag_isoc94;
353
354/* Nonzero means use the ISO C99 dialect of C. */
355
356int flag_isoc99;
357
358/* Nonzero means that we have builtin functions, and main is an int */
359
360int flag_hosted = 1;
361
362/* Nonzero means add default format_arg attributes for functions not
363 in ISO C. */
364
365int flag_noniso_default_format_attributes = 1;
366
367/* Nonzero means warn when casting a function call to a type that does
368 not match the return type (e.g. (float)sqrt() or (anything*)malloc()
369 when there is no previous declaration of sqrt or malloc. */
370
371int warn_bad_function_cast;
372
373/* Warn about traditional constructs whose meanings changed in ANSI C. */
374
375int warn_traditional;
376
377/* Nonzero means warn for non-prototype function decls
378 or non-prototyped defs without previous prototype. */
379
380int warn_strict_prototypes;
381
382/* Nonzero means warn for any global function def
383 without separate previous decl. */
384
385int warn_missing_declarations;
386
387/* Nonzero means warn about declarations of objects not at
388 file-scope level and about *all* declarations of functions (whether
389 or static) not at file-scope level. Note that we exclude
390 implicit function declarations. To get warnings about those, use
391 -Wimplicit. */
392
393int warn_nested_externs;
394
395/* Warn if main is suspicious. */
396
397int warn_main;
398
200/* Nonzero means warn about possible violations of sequence point rules. */
201
202int warn_sequence_point;
203
204/* Nonzero means to warn about compile-time division by zero. */
205int warn_div_by_zero = 1;
206
399/* Nonzero means warn about possible violations of sequence point rules. */
400
401int warn_sequence_point;
402
403/* Nonzero means to warn about compile-time division by zero. */
404int warn_div_by_zero = 1;
405
406/* Nonzero means warn about use of implicit int. */
407
408int warn_implicit_int;
409
410/* Warn about NULL being passed to argument slots marked as requiring
411 non-NULL. */
412
413int warn_nonnull;
414
415
416/* ObjC language option variables. */
417
418
419/* Open and close the file for outputting class declarations, if
420 requested (ObjC). */
421
422int flag_gen_declaration;
423
424/* Generate code for GNU or NeXT runtime environment. */
425
426#ifdef NEXT_OBJC_RUNTIME
427int flag_next_runtime = 1;
428#else
429int flag_next_runtime = 0;
430#endif
431
432/* Tells the compiler that this is a special run. Do not perform any
433 compiling, instead we are to test some platform dependent features
434 and output a C header file with appropriate definitions. */
435
436int print_struct_values;
437
438/* ???. Undocumented. */
439
440const char *constant_string_class_name;
441
442/* Warn if multiple methods are seen for the same selector, but with
443 different argument types. Performs the check on the whole selector
444 table at the end of compilation. */
445
446int warn_selector;
447
448/* Warn if a @selector() is found, and no method with that selector
449 has been previously declared. The check is done on each
450 @selector() as soon as it is found - so it warns about forward
451 declarations. */
452
453int warn_undeclared_selector;
454
455/* Warn if methods required by a protocol are not implemented in the
456 class adopting it. When turned off, methods inherited to that
457 class are also considered implemented. */
458
459int warn_protocol = 1;
460
461
462/* C++ language option variables. */
463
464
465/* Nonzero means don't recognize any extension keywords. */
466
467int flag_no_gnu_keywords;
468
469/* Nonzero means do emit exported implementations of functions even if
470 they can be inlined. */
471
472int flag_implement_inlines = 1;
473
474/* Nonzero means do emit exported implementations of templates, instead of
475 multiple static copies in each file that needs a definition. */
476
477int flag_external_templates;
478
479/* Nonzero means that the decision to emit or not emit the implementation of a
480 template depends on where the template is instantiated, rather than where
481 it is defined. */
482
483int flag_alt_external_templates;
484
485/* Nonzero means that implicit instantiations will be emitted if needed. */
486
487int flag_implicit_templates = 1;
488
489/* Nonzero means that implicit instantiations of inline templates will be
490 emitted if needed, even if instantiations of non-inline templates
491 aren't. */
492
493int flag_implicit_inline_templates = 1;
494
495/* Nonzero means generate separate instantiation control files and
496 juggle them at link time. */
497
498int flag_use_repository;
499
500/* Nonzero if we want to issue diagnostics that the standard says are not
501 required. */
502
503int flag_optional_diags = 1;
504
505/* Nonzero means we should attempt to elide constructors when possible. */
506
507int flag_elide_constructors = 1;
508
509/* Nonzero means that member functions defined in class scope are
510 inline by default. */
511
512int flag_default_inline = 1;
513
514/* Controls whether compiler generates 'type descriptor' that give
515 run-time type information. */
516
517int flag_rtti = 1;
518
519/* Nonzero if we want to conserve space in the .o files. We do this
520 by putting uninitialized data and runtime initialized data into
521 .common instead of .data at the expense of not flagging multiple
522 definitions. */
523
524int flag_conserve_space;
525
526/* Nonzero if we want to obey access control semantics. */
527
528int flag_access_control = 1;
529
530/* Nonzero if we want to check the return value of new and avoid calling
531 constructors if it is a null pointer. */
532
533int flag_check_new;
534
535/* Nonzero if we want the new ISO rules for pushing a new scope for `for'
536 initialization variables.
537 0: Old rules, set by -fno-for-scope.
538 2: New ISO rules, set by -ffor-scope.
539 1: Try to implement new ISO rules, but with backup compatibility
540 (and warnings). This is the default, for now. */
541
542int flag_new_for_scope = 1;
543
544/* Nonzero if we want to emit defined symbols with common-like linkage as
545 weak symbols where possible, in order to conform to C++ semantics.
546 Otherwise, emit them as local symbols. */
547
548int flag_weak = 1;
549
550/* Nonzero to use __cxa_atexit, rather than atexit, to register
551 destructors for local statics and global objects. */
552
553int flag_use_cxa_atexit = DEFAULT_USE_CXA_ATEXIT;
554
555/* Nonzero means output .vtable_{entry,inherit} for use in doing vtable gc. */
556
557int flag_vtable_gc;
558
559/* Nonzero means make the default pedwarns warnings instead of errors.
560 The value of this flag is ignored if -pedantic is specified. */
561
562int flag_permissive;
563
564/* Nonzero means to implement standard semantics for exception
565 specifications, calling unexpected if an exception is thrown that
566 doesn't match the specification. Zero means to treat them as
567 assertions and optimize accordingly, but not check them. */
568
569int flag_enforce_eh_specs = 1;
570
571/* The version of the C++ ABI in use. The following values are
572 allowed:
573
574 0: The version of the ABI believed most conformant with the
575 C++ ABI specification. This ABI may change as bugs are
576 discovered and fixed. Therefore, 0 will not necessarily
577 indicate the same ABI in different versions of G++.
578
579 1: The version of the ABI first used in G++ 3.2.
580
581 Additional positive integers will be assigned as new versions of
582 the ABI become the default version of the ABI. */
583
584int flag_abi_version = 1;
585
586/* Nonzero means warn about things that will change when compiling
587 with an ABI-compliant compiler. */
588
589int warn_abi = 0;
590
591/* Nonzero means warn about implicit declarations. */
592
593int warn_implicit = 1;
594
595/* Nonzero means warn when all ctors or dtors are private, and the class
596 has no friends. */
597
598int warn_ctor_dtor_privacy = 1;
599
600/* Nonzero means warn in function declared in derived class has the
601 same name as a virtual in the base class, but fails to match the
602 type signature of any virtual function in the base class. */
603
604int warn_overloaded_virtual;
605
606/* Nonzero means warn when declaring a class that has a non virtual
607 destructor, when it really ought to have a virtual one. */
608
609int warn_nonvdtor;
610
611/* Nonzero means warn when the compiler will reorder code. */
612
613int warn_reorder;
614
615/* Nonzero means warn when synthesis behavior differs from Cfront's. */
616
617int warn_synth;
618
619/* Nonzero means warn when we convert a pointer to member function
620 into a pointer to (void or function). */
621
622int warn_pmf2ptr = 1;
623
624/* Nonzero means warn about violation of some Effective C++ style rules. */
625
626int warn_ecpp;
627
628/* Nonzero means warn where overload resolution chooses a promotion from
629 unsigned to signed over a conversion to an unsigned of the same size. */
630
631int warn_sign_promo;
632
633/* Nonzero means warn when an old-style cast is used. */
634
635int warn_old_style_cast;
636
637/* Nonzero means warn when non-templatized friend functions are
638 declared within a template */
639
640int warn_nontemplate_friend = 1;
641
642/* Nonzero means complain about deprecated features. */
643
644int warn_deprecated = 1;
645
646/* Maximum template instantiation depth. This limit is rather
647 arbitrary, but it exists to limit the time it takes to notice
648 infinite template instantiations. */
649
650int max_tinst_depth = 500;
651
652
653
207/* The elements of `ridpointers' are identifier nodes for the reserved
208 type names and storage classes. It is indexed by a RID_... value. */
209tree *ridpointers;
210
211tree (*make_fname_decl) PARAMS ((tree, int));
212
213/* If non-NULL, the address of a language-specific function that
214 returns 1 for language-specific statement codes. */

--- 47 unchanged lines hidden (view full) ---

262static if_elt *if_stack;
263
264/* Amount of space in the if statement stack. */
265static int if_stack_space = 0;
266
267/* Stack pointer. */
268static int if_stack_pointer = 0;
269
654/* The elements of `ridpointers' are identifier nodes for the reserved
655 type names and storage classes. It is indexed by a RID_... value. */
656tree *ridpointers;
657
658tree (*make_fname_decl) PARAMS ((tree, int));
659
660/* If non-NULL, the address of a language-specific function that
661 returns 1 for language-specific statement codes. */

--- 47 unchanged lines hidden (view full) ---

709static if_elt *if_stack;
710
711/* Amount of space in the if statement stack. */
712static int if_stack_space = 0;
713
714/* Stack pointer. */
715static int if_stack_pointer = 0;
716
717static tree handle_packed_attribute PARAMS ((tree *, tree, tree, int,
718 bool *));
719static tree handle_nocommon_attribute PARAMS ((tree *, tree, tree, int,
720 bool *));
721static tree handle_common_attribute PARAMS ((tree *, tree, tree, int,
722 bool *));
723static tree handle_noreturn_attribute PARAMS ((tree *, tree, tree, int,
724 bool *));
725static tree handle_noinline_attribute PARAMS ((tree *, tree, tree, int,
726 bool *));
727static tree handle_always_inline_attribute PARAMS ((tree *, tree, tree, int,
728 bool *));
729static tree handle_used_attribute PARAMS ((tree *, tree, tree, int,
730 bool *));
731static tree handle_unused_attribute PARAMS ((tree *, tree, tree, int,
732 bool *));
733static tree handle_const_attribute PARAMS ((tree *, tree, tree, int,
734 bool *));
735static tree handle_transparent_union_attribute PARAMS ((tree *, tree, tree,
736 int, bool *));
737static tree handle_constructor_attribute PARAMS ((tree *, tree, tree, int,
738 bool *));
739static tree handle_destructor_attribute PARAMS ((tree *, tree, tree, int,
740 bool *));
741static tree handle_mode_attribute PARAMS ((tree *, tree, tree, int,
742 bool *));
743static tree handle_section_attribute PARAMS ((tree *, tree, tree, int,
744 bool *));
745static tree handle_aligned_attribute PARAMS ((tree *, tree, tree, int,
746 bool *));
747static tree handle_weak_attribute PARAMS ((tree *, tree, tree, int,
748 bool *));
749static tree handle_alias_attribute PARAMS ((tree *, tree, tree, int,
750 bool *));
751static tree handle_visibility_attribute PARAMS ((tree *, tree, tree, int,
752 bool *));
753static tree handle_tls_model_attribute PARAMS ((tree *, tree, tree, int,
754 bool *));
755static tree handle_no_instrument_function_attribute PARAMS ((tree *, tree,
756 tree, int,
757 bool *));
758static tree handle_malloc_attribute PARAMS ((tree *, tree, tree, int,
759 bool *));
760static tree handle_no_limit_stack_attribute PARAMS ((tree *, tree, tree, int,
761 bool *));
762static tree handle_pure_attribute PARAMS ((tree *, tree, tree, int,
763 bool *));
764static tree handle_deprecated_attribute PARAMS ((tree *, tree, tree, int,
765 bool *));
766static tree handle_vector_size_attribute PARAMS ((tree *, tree, tree, int,
767 bool *));
768static tree handle_nonnull_attribute PARAMS ((tree *, tree, tree, int,
769 bool *));
770static tree handle_nothrow_attribute PARAMS ((tree *, tree, tree, int,
771 bool *));
772static tree handle_cleanup_attribute PARAMS ((tree *, tree, tree, int,
773 bool *));
774static tree vector_size_helper PARAMS ((tree, tree));
775
776static void check_function_nonnull PARAMS ((tree, tree));
777static void check_nonnull_arg PARAMS ((void *, tree,
778 unsigned HOST_WIDE_INT));
779static bool nonnull_check_p PARAMS ((tree, unsigned HOST_WIDE_INT));
780static bool get_nonnull_operand PARAMS ((tree,
781 unsigned HOST_WIDE_INT *));
782void builtin_define_std PARAMS ((const char *));
783static void builtin_define_with_value PARAMS ((const char *, const char *,
784 int));
785static void builtin_define_with_int_value PARAMS ((const char *,
786 HOST_WIDE_INT));
787static void builtin_define_with_hex_fp_value PARAMS ((const char *, tree,
788 int, const char *,
789 const char *));
790static void builtin_define_type_max PARAMS ((const char *, tree, int));
791static void builtin_define_type_precision PARAMS ((const char *, tree));
792static void builtin_define_float_constants PARAMS ((const char *,
793 const char *, tree));
794
795/* Table of machine-independent attributes common to all C-like languages. */
796const struct attribute_spec c_common_attribute_table[] =
797{
798 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
799 { "packed", 0, 0, false, false, false,
800 handle_packed_attribute },
801 { "nocommon", 0, 0, true, false, false,
802 handle_nocommon_attribute },
803 { "common", 0, 0, true, false, false,
804 handle_common_attribute },
805 /* FIXME: logically, noreturn attributes should be listed as
806 "false, true, true" and apply to function types. But implementing this
807 would require all the places in the compiler that use TREE_THIS_VOLATILE
808 on a decl to identify non-returning functions to be located and fixed
809 to check the function type instead. */
810 { "noreturn", 0, 0, true, false, false,
811 handle_noreturn_attribute },
812 { "volatile", 0, 0, true, false, false,
813 handle_noreturn_attribute },
814 { "noinline", 0, 0, true, false, false,
815 handle_noinline_attribute },
816 { "always_inline", 0, 0, true, false, false,
817 handle_always_inline_attribute },
818 { "used", 0, 0, true, false, false,
819 handle_used_attribute },
820 { "unused", 0, 0, false, false, false,
821 handle_unused_attribute },
822 /* The same comments as for noreturn attributes apply to const ones. */
823 { "const", 0, 0, true, false, false,
824 handle_const_attribute },
825 { "transparent_union", 0, 0, false, false, false,
826 handle_transparent_union_attribute },
827 { "constructor", 0, 0, true, false, false,
828 handle_constructor_attribute },
829 { "destructor", 0, 0, true, false, false,
830 handle_destructor_attribute },
831 { "mode", 1, 1, false, true, false,
832 handle_mode_attribute },
833 { "section", 1, 1, true, false, false,
834 handle_section_attribute },
835 { "aligned", 0, 1, false, false, false,
836 handle_aligned_attribute },
837 { "weak", 0, 0, true, false, false,
838 handle_weak_attribute },
839 { "alias", 1, 1, true, false, false,
840 handle_alias_attribute },
841 { "no_instrument_function", 0, 0, true, false, false,
842 handle_no_instrument_function_attribute },
843 { "malloc", 0, 0, true, false, false,
844 handle_malloc_attribute },
845 { "no_stack_limit", 0, 0, true, false, false,
846 handle_no_limit_stack_attribute },
847 { "pure", 0, 0, true, false, false,
848 handle_pure_attribute },
849 { "deprecated", 0, 0, false, false, false,
850 handle_deprecated_attribute },
851 { "vector_size", 1, 1, false, true, false,
852 handle_vector_size_attribute },
853 { "visibility", 1, 1, true, false, false,
854 handle_visibility_attribute },
855 { "tls_model", 1, 1, true, false, false,
856 handle_tls_model_attribute },
857 { "nonnull", 0, -1, false, true, true,
858 handle_nonnull_attribute },
859 { "nothrow", 0, 0, true, false, false,
860 handle_nothrow_attribute },
861 { "may_alias", 0, 0, false, true, false, NULL },
862 { "cleanup", 1, 1, true, false, false,
863 handle_cleanup_attribute },
864 { NULL, 0, 0, false, false, false, NULL }
865};
866
867/* Give the specifications for the format attributes, used by C and all
868 descendents. */
869
870const struct attribute_spec c_common_format_attribute_table[] =
871{
872 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
873 { "format", 3, 3, false, true, true,
874 handle_format_attribute },
875 { "format_arg", 1, 1, false, true, true,
876 handle_format_arg_attribute },
877 { NULL, 0, 0, false, false, false, NULL }
878};
879
270/* Record the start of an if-then, and record the start of it
271 for ambiguous else detection.
272
273 COND is the condition for the if-then statement.
274
275 IF_STMT is the statement node that has already been created for
276 this if-then statement. It is created before parsing the
277 condition to keep line number information accurate. */

--- 200 unchanged lines hidden (view full) ---

478const char *
479fname_as_string (pretty_p)
480 int pretty_p;
481{
482 const char *name = NULL;
483
484 if (pretty_p)
485 name = (current_function_decl
880/* Record the start of an if-then, and record the start of it
881 for ambiguous else detection.
882
883 COND is the condition for the if-then statement.
884
885 IF_STMT is the statement node that has already been created for
886 this if-then statement. It is created before parsing the
887 condition to keep line number information accurate. */

--- 200 unchanged lines hidden (view full) ---

1088const char *
1089fname_as_string (pretty_p)
1090 int pretty_p;
1091{
1092 const char *name = NULL;
1093
1094 if (pretty_p)
1095 name = (current_function_decl
486 ? (*decl_printable_name) (current_function_decl, 2)
1096 ? (*lang_hooks.decl_printable_name) (current_function_decl, 2)
487 : "top level");
488 else if (current_function_decl && DECL_NAME (current_function_decl))
489 name = IDENTIFIER_POINTER (DECL_NAME (current_function_decl));
490 else
491 name = "";
492 return name;
493}
494

--- 30 unchanged lines hidden (view full) ---

525 for (ix = 0; fname_vars[ix].decl; ix++)
526 if (fname_vars[ix].rid == rid)
527 break;
528
529 decl = *fname_vars[ix].decl;
530 if (!decl)
531 {
532 tree saved_last_tree = last_tree;
1097 : "top level");
1098 else if (current_function_decl && DECL_NAME (current_function_decl))
1099 name = IDENTIFIER_POINTER (DECL_NAME (current_function_decl));
1100 else
1101 name = "";
1102 return name;
1103}
1104

--- 30 unchanged lines hidden (view full) ---

1135 for (ix = 0; fname_vars[ix].decl; ix++)
1136 if (fname_vars[ix].rid == rid)
1137 break;
1138
1139 decl = *fname_vars[ix].decl;
1140 if (!decl)
1141 {
1142 tree saved_last_tree = last_tree;
1143 /* If a tree is built here, it would normally have the lineno of
1144 the current statement. Later this tree will be moved to the
1145 beginning of the function and this line number will be wrong.
1146 To avoid this problem set the lineno to 0 here; that prevents
1147 it from appearing in the RTL. */
1148 int saved_lineno = lineno;
1149 lineno = 0;
533
534 decl = (*make_fname_decl) (id, fname_vars[ix].pretty);
535 if (last_tree != saved_last_tree)
536 {
537 /* We created some statement tree for the decl. This belongs
538 at the start of the function, so remove it now and reinsert
539 it after the function is complete. */
540 tree stmts = TREE_CHAIN (saved_last_tree);
541
542 TREE_CHAIN (saved_last_tree) = NULL_TREE;
543 last_tree = saved_last_tree;
544 saved_function_name_decls = tree_cons (decl, stmts,
545 saved_function_name_decls);
546 }
547 *fname_vars[ix].decl = decl;
1150
1151 decl = (*make_fname_decl) (id, fname_vars[ix].pretty);
1152 if (last_tree != saved_last_tree)
1153 {
1154 /* We created some statement tree for the decl. This belongs
1155 at the start of the function, so remove it now and reinsert
1156 it after the function is complete. */
1157 tree stmts = TREE_CHAIN (saved_last_tree);
1158
1159 TREE_CHAIN (saved_last_tree) = NULL_TREE;
1160 last_tree = saved_last_tree;
1161 saved_function_name_decls = tree_cons (decl, stmts,
1162 saved_function_name_decls);
1163 }
1164 *fname_vars[ix].decl = decl;
1165 lineno = saved_lineno;
548 }
549 if (!ix && !current_function_decl)
550 pedwarn_with_decl (decl, "`%s' is not defined outside of function scope");
551
552 return decl;
553}
554
1166 }
1167 if (!ix && !current_function_decl)
1168 pedwarn_with_decl (decl, "`%s' is not defined outside of function scope");
1169
1170 return decl;
1171}
1172
555/* Given a chain of STRING_CST nodes,
556 concatenate them into one STRING_CST
557 and give it a suitable array-of-chars data type. */
1173/* Given a STRING_CST, give it a suitable array-of-chars data type. */
558
559tree
1174
1175tree
1176fix_string_type (value)
1177 tree value;
1178{
1179 const int wchar_bytes = TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT;
1180 const int wide_flag = TREE_TYPE (value) == wchar_array_type_node;
1181 const int nchars_max = flag_isoc99 ? 4095 : 509;
1182 int length = TREE_STRING_LENGTH (value);
1183 int nchars;
1184
1185 /* Compute the number of elements, for the array type. */
1186 nchars = wide_flag ? length / wchar_bytes : length;
1187
1188 if (pedantic && nchars - 1 > nchars_max && c_language == clk_c)
1189 pedwarn ("string length `%d' is greater than the length `%d' ISO C%d compilers are required to support",
1190 nchars - 1, nchars_max, flag_isoc99 ? 99 : 89);
1191
1192 /* Create the array type for the string constant.
1193 -Wwrite-strings says make the string constant an array of const char
1194 so that copying it to a non-const pointer will get a warning.
1195 For C++, this is the standard behavior. */
1196 if (flag_const_strings && ! flag_writable_strings)
1197 {
1198 tree elements
1199 = build_type_variant (wide_flag ? wchar_type_node : char_type_node,
1200 1, 0);
1201 TREE_TYPE (value)
1202 = build_array_type (elements,
1203 build_index_type (build_int_2 (nchars - 1, 0)));
1204 }
1205 else
1206 TREE_TYPE (value)
1207 = build_array_type (wide_flag ? wchar_type_node : char_type_node,
1208 build_index_type (build_int_2 (nchars - 1, 0)));
1209
1210 TREE_CONSTANT (value) = 1;
1211 TREE_READONLY (value) = ! flag_writable_strings;
1212 TREE_STATIC (value) = 1;
1213 return value;
1214}
1215
1216/* Given a VARRAY of STRING_CST nodes, concatenate them into one
1217 STRING_CST. */
1218
1219tree
560combine_strings (strings)
1220combine_strings (strings)
561 tree strings;
1221 varray_type strings;
562{
1222{
1223 const int wchar_bytes = TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT;
1224 const int nstrings = VARRAY_ACTIVE_SIZE (strings);
563 tree value, t;
564 int length = 1;
565 int wide_length = 0;
566 int wide_flag = 0;
1225 tree value, t;
1226 int length = 1;
1227 int wide_length = 0;
1228 int wide_flag = 0;
567 int wchar_bytes = TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT;
568 int nchars;
569 const int nchars_max = flag_isoc99 ? 4095 : 509;
1229 int i;
1230 char *p, *q;
570
1231
571 if (TREE_CHAIN (strings))
1232 /* Don't include the \0 at the end of each substring. Count wide
1233 strings and ordinary strings separately. */
1234 for (i = 0; i < nstrings; ++i)
572 {
1235 {
573 /* More than one in the chain, so concatenate. */
574 char *p, *q;
1236 t = VARRAY_TREE (strings, i);
575
1237
576 /* Don't include the \0 at the end of each substring,
577 except for the last one.
578 Count wide strings and ordinary strings separately. */
579 for (t = strings; t; t = TREE_CHAIN (t))
1238 if (TREE_TYPE (t) == wchar_array_type_node)
580 {
1239 {
581 if (TREE_TYPE (t) == wchar_array_type_node)
582 {
583 wide_length += (TREE_STRING_LENGTH (t) - wchar_bytes);
584 wide_flag = 1;
585 }
586 else
587 {
588 length += (TREE_STRING_LENGTH (t) - 1);
589 if (C_ARTIFICIAL_STRING_P (t) && !in_system_header)
590 warning ("concatenation of string literals with __FUNCTION__ is deprecated");
591 }
1240 wide_length += TREE_STRING_LENGTH (t) - wchar_bytes;
1241 wide_flag = 1;
592 }
1242 }
1243 else
1244 {
1245 length += (TREE_STRING_LENGTH (t) - 1);
1246 if (C_ARTIFICIAL_STRING_P (t) && !in_system_header)
1247 warning ("concatenation of string literals with __FUNCTION__ is deprecated");
1248 }
1249 }
593
1250
594 /* If anything is wide, the non-wides will be converted,
595 which makes them take more space. */
596 if (wide_flag)
597 length = length * wchar_bytes + wide_length;
1251 /* If anything is wide, the non-wides will be converted,
1252 which makes them take more space. */
1253 if (wide_flag)
1254 length = length * wchar_bytes + wide_length;
598
1255
599 p = xmalloc (length);
1256 p = xmalloc (length);
600
1257
601 /* Copy the individual strings into the new combined string.
602 If the combined string is wide, convert the chars to ints
603 for any individual strings that are not wide. */
1258 /* Copy the individual strings into the new combined string.
1259 If the combined string is wide, convert the chars to ints
1260 for any individual strings that are not wide. */
604
1261
605 q = p;
606 for (t = strings; t; t = TREE_CHAIN (t))
1262 q = p;
1263 for (i = 0; i < nstrings; ++i)
1264 {
1265 int len, this_wide;
1266
1267 t = VARRAY_TREE (strings, i);
1268 this_wide = TREE_TYPE (t) == wchar_array_type_node;
1269 len = TREE_STRING_LENGTH (t) - (this_wide ? wchar_bytes : 1);
1270 if (this_wide == wide_flag)
607 {
1271 {
608 int len = (TREE_STRING_LENGTH (t)
609 - ((TREE_TYPE (t) == wchar_array_type_node)
610 ? wchar_bytes : 1));
611 if ((TREE_TYPE (t) == wchar_array_type_node) == wide_flag)
1272 memcpy (q, TREE_STRING_POINTER (t), len);
1273 q += len;
1274 }
1275 else
1276 {
1277 const int nzeros = (TYPE_PRECISION (wchar_type_node)
1278 / BITS_PER_UNIT) - 1;
1279 int j, k;
1280
1281 if (BYTES_BIG_ENDIAN)
612 {
1282 {
613 memcpy (q, TREE_STRING_POINTER (t), len);
614 q += len;
1283 for (k = 0; k < len; k++)
1284 {
1285 for (j = 0; j < nzeros; j++)
1286 *q++ = 0;
1287 *q++ = TREE_STRING_POINTER (t)[k];
1288 }
615 }
616 else
617 {
1289 }
1290 else
1291 {
618 int i, j;
619 for (i = 0; i < len; i++)
1292 for (k = 0; k < len; k++)
620 {
1293 {
621 if (BYTES_BIG_ENDIAN)
622 {
623 for (j=0; j<(WCHAR_TYPE_SIZE / BITS_PER_UNIT)-1; j++)
624 *q++ = 0;
625 *q++ = TREE_STRING_POINTER (t)[i];
626 }
627 else
628 {
629 *q++ = TREE_STRING_POINTER (t)[i];
630 for (j=0; j<(WCHAR_TYPE_SIZE / BITS_PER_UNIT)-1; j++)
631 *q++ = 0;
632 }
1294 *q++ = TREE_STRING_POINTER (t)[k];
1295 for (j = 0; j < nzeros; j++)
1296 *q++ = 0;
633 }
634 }
635 }
1297 }
1298 }
1299 }
636 if (wide_flag)
637 {
638 int i;
639 for (i = 0; i < wchar_bytes; i++)
640 *q++ = 0;
641 }
642 else
643 *q = 0;
644
645 value = build_string (length, p);
646 free (p);
647 }
1300 }
648 else
1301
1302 /* Nul terminate the string. */
1303 if (wide_flag)
649 {
1304 {
650 value = strings;
651 length = TREE_STRING_LENGTH (value);
652 if (TREE_TYPE (value) == wchar_array_type_node)
653 wide_flag = 1;
1305 for (i = 0; i < wchar_bytes; i++)
1306 *q++ = 0;
654 }
1307 }
1308 else
1309 *q = 0;
655
1310
656 /* Compute the number of elements, for the array type. */
657 nchars = wide_flag ? length / wchar_bytes : length;
1311 value = build_string (length, p);
1312 free (p);
658
1313
659 if (pedantic && nchars - 1 > nchars_max && c_language == clk_c)
660 pedwarn ("string length `%d' is greater than the length `%d' ISO C%d compilers are required to support",
661 nchars - 1, nchars_max, flag_isoc99 ? 99 : 89);
662
663 /* Create the array type for the string constant.
664 -Wwrite-strings says make the string constant an array of const char
665 so that copying it to a non-const pointer will get a warning.
666 For C++, this is the standard behavior. */
667 if (flag_const_strings
668 && (! flag_traditional && ! flag_writable_strings))
669 {
670 tree elements
671 = build_type_variant (wide_flag ? wchar_type_node : char_type_node,
672 1, 0);
673 TREE_TYPE (value)
674 = build_array_type (elements,
675 build_index_type (build_int_2 (nchars - 1, 0)));
676 }
1314 if (wide_flag)
1315 TREE_TYPE (value) = wchar_array_type_node;
677 else
1316 else
678 TREE_TYPE (value)
679 = build_array_type (wide_flag ? wchar_type_node : char_type_node,
680 build_index_type (build_int_2 (nchars - 1, 0)));
1317 TREE_TYPE (value) = char_array_type_node;
681
1318
682 TREE_CONSTANT (value) = 1;
683 TREE_READONLY (value) = ! flag_writable_strings;
684 TREE_STATIC (value) = 1;
685 return value;
686}
687
688static int is_valid_printf_arglist PARAMS ((tree));
689static rtx c_expand_builtin PARAMS ((tree, rtx, enum machine_mode, enum expand_modifier));
690static rtx c_expand_builtin_printf PARAMS ((tree, rtx, enum machine_mode,
691 enum expand_modifier, int, int));
692static rtx c_expand_builtin_fprintf PARAMS ((tree, rtx, enum machine_mode,

--- 57 unchanged lines hidden (view full) ---

750 or if -Wconversion is used and a constant < 0 is converted to unsigned.
751 Invoke this function on every expression that might be implicitly
752 converted to an unsigned type. */
753
754void
755unsigned_conversion_warning (result, operand)
756 tree result, operand;
757{
1319 return value;
1320}
1321
1322static int is_valid_printf_arglist PARAMS ((tree));
1323static rtx c_expand_builtin PARAMS ((tree, rtx, enum machine_mode, enum expand_modifier));
1324static rtx c_expand_builtin_printf PARAMS ((tree, rtx, enum machine_mode,
1325 enum expand_modifier, int, int));
1326static rtx c_expand_builtin_fprintf PARAMS ((tree, rtx, enum machine_mode,

--- 57 unchanged lines hidden (view full) ---

1384 or if -Wconversion is used and a constant < 0 is converted to unsigned.
1385 Invoke this function on every expression that might be implicitly
1386 converted to an unsigned type. */
1387
1388void
1389unsigned_conversion_warning (result, operand)
1390 tree result, operand;
1391{
1392 tree type = TREE_TYPE (result);
1393
758 if (TREE_CODE (operand) == INTEGER_CST
1394 if (TREE_CODE (operand) == INTEGER_CST
759 && TREE_CODE (TREE_TYPE (result)) == INTEGER_TYPE
760 && TREE_UNSIGNED (TREE_TYPE (result))
1395 && TREE_CODE (type) == INTEGER_TYPE
1396 && TREE_UNSIGNED (type)
761 && skip_evaluation == 0
1397 && skip_evaluation == 0
762 && !int_fits_type_p (operand, TREE_TYPE (result)))
1398 && !int_fits_type_p (operand, type))
763 {
1399 {
764 if (!int_fits_type_p (operand, signed_type (TREE_TYPE (result))))
1400 if (!int_fits_type_p (operand, c_common_signed_type (type)))
765 /* This detects cases like converting -129 or 256 to unsigned char. */
766 warning ("large integer implicitly truncated to unsigned type");
767 else if (warn_conversion)
768 warning ("negative integer implicitly converted to unsigned type");
769 }
770}
771
772/* Nonzero if constant C has a value that is permissible

--- 32 unchanged lines hidden (view full) ---

805 /* No warning for converting 0x80000000 to int. */
806 if (!(TREE_UNSIGNED (type) < TREE_UNSIGNED (TREE_TYPE (expr))
807 && TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
808 && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (expr))))
809 /* If EXPR fits in the unsigned version of TYPE,
810 don't warn unless pedantic. */
811 if ((pedantic
812 || TREE_UNSIGNED (type)
1401 /* This detects cases like converting -129 or 256 to unsigned char. */
1402 warning ("large integer implicitly truncated to unsigned type");
1403 else if (warn_conversion)
1404 warning ("negative integer implicitly converted to unsigned type");
1405 }
1406}
1407
1408/* Nonzero if constant C has a value that is permissible

--- 32 unchanged lines hidden (view full) ---

1441 /* No warning for converting 0x80000000 to int. */
1442 if (!(TREE_UNSIGNED (type) < TREE_UNSIGNED (TREE_TYPE (expr))
1443 && TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
1444 && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (expr))))
1445 /* If EXPR fits in the unsigned version of TYPE,
1446 don't warn unless pedantic. */
1447 if ((pedantic
1448 || TREE_UNSIGNED (type)
813 || ! constant_fits_type_p (expr, unsigned_type (type)))
1449 || ! constant_fits_type_p (expr,
1450 c_common_unsigned_type (type)))
814 && skip_evaluation == 0)
815 warning ("overflow in implicit constant conversion");
816 }
817 else
818 unsigned_conversion_warning (t, expr);
819 }
820 return t;
821}

--- 385 unchanged lines hidden (view full) ---

1207 merge_tlist (&tmp_nosp, tmp_before, 0);
1208 add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
1209 }
1210 break;
1211 }
1212 }
1213}
1214
1451 && skip_evaluation == 0)
1452 warning ("overflow in implicit constant conversion");
1453 }
1454 else
1455 unsigned_conversion_warning (t, expr);
1456 }
1457 return t;
1458}

--- 385 unchanged lines hidden (view full) ---

1844 merge_tlist (&tmp_nosp, tmp_before, 0);
1845 add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
1846 }
1847 break;
1848 }
1849 }
1850}
1851
1215/* Try to warn for undefined behaviour in EXPR due to missing sequence
1852/* Try to warn for undefined behavior in EXPR due to missing sequence
1216 points. */
1217
1218static void
1219verify_sequence_points (expr)
1220 tree expr;
1221{
1222 struct tlist *before_sp = 0, *after_sp = 0;
1223

--- 71 unchanged lines hidden (view full) ---

1295
1296 return value;
1297}
1298
1299/* Return an integer type with BITS bits of precision,
1300 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
1301
1302tree
1853 points. */
1854
1855static void
1856verify_sequence_points (expr)
1857 tree expr;
1858{
1859 struct tlist *before_sp = 0, *after_sp = 0;
1860

--- 71 unchanged lines hidden (view full) ---

1932
1933 return value;
1934}
1935
1936/* Return an integer type with BITS bits of precision,
1937 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
1938
1939tree
1303type_for_size (bits, unsignedp)
1940c_common_type_for_size (bits, unsignedp)
1304 unsigned bits;
1305 int unsignedp;
1306{
1307 if (bits == TYPE_PRECISION (integer_type_node))
1308 return unsignedp ? unsigned_type_node : integer_type_node;
1309
1310 if (bits == TYPE_PRECISION (signed_char_type_node))
1311 return unsignedp ? unsigned_char_type_node : signed_char_type_node;

--- 27 unchanged lines hidden (view full) ---

1339 return 0;
1340}
1341
1342/* Return a data type that has machine mode MODE.
1343 If the mode is an integer,
1344 then UNSIGNEDP selects between signed and unsigned types. */
1345
1346tree
1941 unsigned bits;
1942 int unsignedp;
1943{
1944 if (bits == TYPE_PRECISION (integer_type_node))
1945 return unsignedp ? unsigned_type_node : integer_type_node;
1946
1947 if (bits == TYPE_PRECISION (signed_char_type_node))
1948 return unsignedp ? unsigned_char_type_node : signed_char_type_node;

--- 27 unchanged lines hidden (view full) ---

1976 return 0;
1977}
1978
1979/* Return a data type that has machine mode MODE.
1980 If the mode is an integer,
1981 then UNSIGNEDP selects between signed and unsigned types. */
1982
1983tree
1347type_for_mode (mode, unsignedp)
1984c_common_type_for_mode (mode, unsignedp)
1348 enum machine_mode mode;
1349 int unsignedp;
1350{
1351 if (mode == TYPE_MODE (integer_type_node))
1352 return unsignedp ? unsigned_type_node : integer_type_node;
1353
1354 if (mode == TYPE_MODE (signed_char_type_node))
1355 return unsignedp ? unsigned_char_type_node : signed_char_type_node;

--- 38 unchanged lines hidden (view full) ---

1394 return long_double_type_node;
1395
1396 if (mode == TYPE_MODE (build_pointer_type (char_type_node)))
1397 return build_pointer_type (char_type_node);
1398
1399 if (mode == TYPE_MODE (build_pointer_type (integer_type_node)))
1400 return build_pointer_type (integer_type_node);
1401
1985 enum machine_mode mode;
1986 int unsignedp;
1987{
1988 if (mode == TYPE_MODE (integer_type_node))
1989 return unsignedp ? unsigned_type_node : integer_type_node;
1990
1991 if (mode == TYPE_MODE (signed_char_type_node))
1992 return unsignedp ? unsigned_char_type_node : signed_char_type_node;

--- 38 unchanged lines hidden (view full) ---

2031 return long_double_type_node;
2032
2033 if (mode == TYPE_MODE (build_pointer_type (char_type_node)))
2034 return build_pointer_type (char_type_node);
2035
2036 if (mode == TYPE_MODE (build_pointer_type (integer_type_node)))
2037 return build_pointer_type (integer_type_node);
2038
1402#ifdef VECTOR_MODE_SUPPORTED_P
1403 if (VECTOR_MODE_SUPPORTED_P (mode))
2039 switch (mode)
1404 {
2040 {
1405 switch (mode)
1406 {
1407 case V16QImode:
1408 return unsignedp ? unsigned_V16QI_type_node : V16QI_type_node;
1409 case V8HImode:
1410 return unsignedp ? unsigned_V8HI_type_node : V8HI_type_node;
1411 case V4SImode:
1412 return unsignedp ? unsigned_V4SI_type_node : V4SI_type_node;
1413 case V2SImode:
1414 return unsignedp ? unsigned_V2SI_type_node : V2SI_type_node;
1415 case V4HImode:
1416 return unsignedp ? unsigned_V4HI_type_node : V4HI_type_node;
1417 case V8QImode:
1418 return unsignedp ? unsigned_V8QI_type_node : V8QI_type_node;
1419 case V16SFmode:
1420 return V16SF_type_node;
1421 case V4SFmode:
1422 return V4SF_type_node;
1423 case V2SFmode:
1424 return V2SF_type_node;
1425 default:
1426 break;
1427 }
2041 case V16QImode:
2042 return unsignedp ? unsigned_V16QI_type_node : V16QI_type_node;
2043 case V8HImode:
2044 return unsignedp ? unsigned_V8HI_type_node : V8HI_type_node;
2045 case V4SImode:
2046 return unsignedp ? unsigned_V4SI_type_node : V4SI_type_node;
2047 case V2DImode:
2048 return unsignedp ? unsigned_V2DI_type_node : V2DI_type_node;
2049 case V2SImode:
2050 return unsignedp ? unsigned_V2SI_type_node : V2SI_type_node;
2051 case V2HImode:
2052 return unsignedp ? unsigned_V2HI_type_node : V2HI_type_node;
2053 case V4HImode:
2054 return unsignedp ? unsigned_V4HI_type_node : V4HI_type_node;
2055 case V8QImode:
2056 return unsignedp ? unsigned_V8QI_type_node : V8QI_type_node;
2057 case V1DImode:
2058 return unsignedp ? unsigned_V1DI_type_node : V1DI_type_node;
2059 case V16SFmode:
2060 return V16SF_type_node;
2061 case V4SFmode:
2062 return V4SF_type_node;
2063 case V2SFmode:
2064 return V2SF_type_node;
2065 case V2DFmode:
2066 return V2DF_type_node;
2067 default:
2068 break;
1428 }
2069 }
1429#endif
1430
1431 return 0;
1432}
1433
1434/* Return an unsigned type the same as TYPE in other respects. */
1435tree
2070
2071 return 0;
2072}
2073
2074/* Return an unsigned type the same as TYPE in other respects. */
2075tree
1436unsigned_type (type)
2076c_common_unsigned_type (type)
1437 tree type;
1438{
1439 tree type1 = TYPE_MAIN_VARIANT (type);
1440 if (type1 == signed_char_type_node || type1 == char_type_node)
1441 return unsigned_char_type_node;
1442 if (type1 == integer_type_node)
1443 return unsigned_type_node;
1444 if (type1 == short_integer_type_node)

--- 12 unchanged lines hidden (view full) ---

1457 return unsigned_intDI_type_node;
1458 if (type1 == intSI_type_node)
1459 return unsigned_intSI_type_node;
1460 if (type1 == intHI_type_node)
1461 return unsigned_intHI_type_node;
1462 if (type1 == intQI_type_node)
1463 return unsigned_intQI_type_node;
1464
2077 tree type;
2078{
2079 tree type1 = TYPE_MAIN_VARIANT (type);
2080 if (type1 == signed_char_type_node || type1 == char_type_node)
2081 return unsigned_char_type_node;
2082 if (type1 == integer_type_node)
2083 return unsigned_type_node;
2084 if (type1 == short_integer_type_node)

--- 12 unchanged lines hidden (view full) ---

2097 return unsigned_intDI_type_node;
2098 if (type1 == intSI_type_node)
2099 return unsigned_intSI_type_node;
2100 if (type1 == intHI_type_node)
2101 return unsigned_intHI_type_node;
2102 if (type1 == intQI_type_node)
2103 return unsigned_intQI_type_node;
2104
1465 return signed_or_unsigned_type (1, type);
2105 return c_common_signed_or_unsigned_type (1, type);
1466}
1467
1468/* Return a signed type the same as TYPE in other respects. */
1469
1470tree
2106}
2107
2108/* Return a signed type the same as TYPE in other respects. */
2109
2110tree
1471signed_type (type)
2111c_common_signed_type (type)
1472 tree type;
1473{
1474 tree type1 = TYPE_MAIN_VARIANT (type);
1475 if (type1 == unsigned_char_type_node || type1 == char_type_node)
1476 return signed_char_type_node;
1477 if (type1 == unsigned_type_node)
1478 return integer_type_node;
1479 if (type1 == short_unsigned_type_node)

--- 12 unchanged lines hidden (view full) ---

1492 return intDI_type_node;
1493 if (type1 == unsigned_intSI_type_node)
1494 return intSI_type_node;
1495 if (type1 == unsigned_intHI_type_node)
1496 return intHI_type_node;
1497 if (type1 == unsigned_intQI_type_node)
1498 return intQI_type_node;
1499
2112 tree type;
2113{
2114 tree type1 = TYPE_MAIN_VARIANT (type);
2115 if (type1 == unsigned_char_type_node || type1 == char_type_node)
2116 return signed_char_type_node;
2117 if (type1 == unsigned_type_node)
2118 return integer_type_node;
2119 if (type1 == short_unsigned_type_node)

--- 12 unchanged lines hidden (view full) ---

2132 return intDI_type_node;
2133 if (type1 == unsigned_intSI_type_node)
2134 return intSI_type_node;
2135 if (type1 == unsigned_intHI_type_node)
2136 return intHI_type_node;
2137 if (type1 == unsigned_intQI_type_node)
2138 return intQI_type_node;
2139
1500 return signed_or_unsigned_type (0, type);
2140 return c_common_signed_or_unsigned_type (0, type);
1501}
1502
1503/* Return a type the same as TYPE except unsigned or
1504 signed according to UNSIGNEDP. */
1505
1506tree
2141}
2142
2143/* Return a type the same as TYPE except unsigned or
2144 signed according to UNSIGNEDP. */
2145
2146tree
1507signed_or_unsigned_type (unsignedp, type)
2147c_common_signed_or_unsigned_type (unsignedp, type)
1508 int unsignedp;
1509 tree type;
1510{
1511 if (! INTEGRAL_TYPE_P (type)
1512 || TREE_UNSIGNED (type) == unsignedp)
1513 return type;
1514
1515 if (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node))

--- 51 unchanged lines hidden (view full) ---

1567 if (integer_zerop (value))
1568 log = 0;
1569 else
1570 log = tree_floor_log2 (value);
1571
1572 return log + 1 + ! unsignedp;
1573}
1574
2148 int unsignedp;
2149 tree type;
2150{
2151 if (! INTEGRAL_TYPE_P (type)
2152 || TREE_UNSIGNED (type) == unsignedp)
2153 return type;
2154
2155 if (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node))

--- 51 unchanged lines hidden (view full) ---

2207 if (integer_zerop (value))
2208 log = 0;
2209 else
2210 log = tree_floor_log2 (value);
2211
2212 return log + 1 + ! unsignedp;
2213}
2214
1575/* Print an error message for invalid operands to arith operation CODE.
1576 NOP_EXPR is used as a special case (see truthvalue_conversion). */
2215/* Print an error message for invalid operands to arith operation
2216 CODE. NOP_EXPR is used as a special case (see
2217 c_common_truthvalue_conversion). */
1577
1578void
1579binary_op_error (code)
1580 enum tree_code code;
1581{
1582 const char *opname;
1583
1584 switch (code)

--- 163 unchanged lines hidden (view full) ---

1748 && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr))
1749 {
1750 int min_gt, max_gt, min_lt, max_lt;
1751 tree maxval, minval;
1752 /* 1 if comparison is nominally unsigned. */
1753 int unsignedp = TREE_UNSIGNED (*restype_ptr);
1754 tree val;
1755
2218
2219void
2220binary_op_error (code)
2221 enum tree_code code;
2222{
2223 const char *opname;
2224
2225 switch (code)

--- 163 unchanged lines hidden (view full) ---

2389 && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr))
2390 {
2391 int min_gt, max_gt, min_lt, max_lt;
2392 tree maxval, minval;
2393 /* 1 if comparison is nominally unsigned. */
2394 int unsignedp = TREE_UNSIGNED (*restype_ptr);
2395 tree val;
2396
1756 type = signed_or_unsigned_type (unsignedp0, TREE_TYPE (primop0));
2397 type = c_common_signed_or_unsigned_type (unsignedp0,
2398 TREE_TYPE (primop0));
1757
1758 /* If TYPE is an enumeration, then we need to get its min/max
1759 values from it's underlying integral type, not the enumerated
1760 type itself. */
1761 if (TREE_CODE (type) == ENUMERAL_TYPE)
2399
2400 /* If TYPE is an enumeration, then we need to get its min/max
2401 values from it's underlying integral type, not the enumerated
2402 type itself. */
2403 if (TREE_CODE (type) == ENUMERAL_TYPE)
1762 type = type_for_size (TYPE_PRECISION (type), unsignedp0);
2404 type = c_common_type_for_size (TYPE_PRECISION (type), unsignedp0);
1763
1764 maxval = TYPE_MAX_VALUE (type);
1765 minval = TYPE_MIN_VALUE (type);
1766
1767 if (unsignedp && !unsignedp0)
2405
2406 maxval = TYPE_MAX_VALUE (type);
2407 minval = TYPE_MIN_VALUE (type);
2408
2409 if (unsignedp && !unsignedp0)
1768 *restype_ptr = signed_type (*restype_ptr);
2410 *restype_ptr = c_common_signed_type (*restype_ptr);
1769
1770 if (TREE_TYPE (primop1) != *restype_ptr)
1771 primop1 = convert (*restype_ptr, primop1);
1772 if (type != *restype_ptr)
1773 {
1774 minval = convert (*restype_ptr, minval);
1775 maxval = convert (*restype_ptr, maxval);
1776 }

--- 80 unchanged lines hidden (view full) ---

1857 case GT_EXPR:
1858 primop1 = TYPE_MAX_VALUE (type);
1859 val = 0;
1860 break;
1861
1862 default:
1863 break;
1864 }
2411
2412 if (TREE_TYPE (primop1) != *restype_ptr)
2413 primop1 = convert (*restype_ptr, primop1);
2414 if (type != *restype_ptr)
2415 {
2416 minval = convert (*restype_ptr, minval);
2417 maxval = convert (*restype_ptr, maxval);
2418 }

--- 80 unchanged lines hidden (view full) ---

2499 case GT_EXPR:
2500 primop1 = TYPE_MAX_VALUE (type);
2501 val = 0;
2502 break;
2503
2504 default:
2505 break;
2506 }
1865 type = unsigned_type (type);
2507 type = c_common_unsigned_type (type);
1866 }
1867
2508 }
2509
1868 if (!max_gt && !unsignedp0 && TREE_CODE (primop0) != INTEGER_CST)
2510 if (TREE_CODE (primop0) != INTEGER_CST)
1869 {
2511 {
1870 /* This is the case of (char)x >?< 0x80, which people used to use
1871 expecting old C compilers to change the 0x80 into -0x80. */
1872 if (val == boolean_false_node)
1873 warning ("comparison is always false due to limited range of data type");
1874 if (val == boolean_true_node)
1875 warning ("comparison is always true due to limited range of data type");
1876 }
1877
2512 if (val == boolean_false_node)
2513 warning ("comparison is always false due to limited range of data type");
2514 if (val == boolean_true_node)
2515 warning ("comparison is always true due to limited range of data type");
2516 }
2517
1878 if (!min_lt && unsignedp0 && TREE_CODE (primop0) != INTEGER_CST)
1879 {
1880 /* This is the case of (unsigned char)x >?< -1 or < 0. */
1881 if (val == boolean_false_node)
1882 warning ("comparison is always false due to limited range of data type");
1883 if (val == boolean_true_node)
1884 warning ("comparison is always true due to limited range of data type");
1885 }
1886
1887 if (val != 0)
1888 {
1889 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
1890 if (TREE_SIDE_EFFECTS (primop0))
1891 return build (COMPOUND_EXPR, TREE_TYPE (val), primop0, val);
1892 return val;
1893 }
1894

--- 14 unchanged lines hidden (view full) ---

1909 alter the result.
1910 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
1911
1912 else if (unsignedp0 == unsignedp1 && real1 == real2
1913 && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr)
1914 && TYPE_PRECISION (TREE_TYPE (primop1)) < TYPE_PRECISION (*restype_ptr))
1915 {
1916 type = common_type (TREE_TYPE (primop0), TREE_TYPE (primop1));
2518 if (val != 0)
2519 {
2520 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
2521 if (TREE_SIDE_EFFECTS (primop0))
2522 return build (COMPOUND_EXPR, TREE_TYPE (val), primop0, val);
2523 return val;
2524 }
2525

--- 14 unchanged lines hidden (view full) ---

2540 alter the result.
2541 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
2542
2543 else if (unsignedp0 == unsignedp1 && real1 == real2
2544 && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr)
2545 && TYPE_PRECISION (TREE_TYPE (primop1)) < TYPE_PRECISION (*restype_ptr))
2546 {
2547 type = common_type (TREE_TYPE (primop0), TREE_TYPE (primop1));
1917 type = signed_or_unsigned_type (unsignedp0
1918 || TREE_UNSIGNED (*restype_ptr),
1919 type);
2548 type = c_common_signed_or_unsigned_type (unsignedp0
2549 || TREE_UNSIGNED (*restype_ptr),
2550 type);
1920 /* Make sure shorter operand is extended the right way
1921 to match the longer operand. */
2551 /* Make sure shorter operand is extended the right way
2552 to match the longer operand. */
1922 primop0 = convert (signed_or_unsigned_type (unsignedp0, TREE_TYPE (primop0)),
1923 primop0);
1924 primop1 = convert (signed_or_unsigned_type (unsignedp1, TREE_TYPE (primop1)),
1925 primop1);
2553 primop0
2554 = convert (c_common_signed_or_unsigned_type (unsignedp0,
2555 TREE_TYPE (primop0)),
2556 primop0);
2557 primop1
2558 = convert (c_common_signed_or_unsigned_type (unsignedp1,
2559 TREE_TYPE (primop1)),
2560 primop1);
1926 }
1927 else
1928 {
1929 /* Here we must do the comparison on the nominal type
1930 using the args exactly as we received them. */
1931 type = *restype_ptr;
1932 primop0 = op0;
1933 primop1 = op1;

--- 6 unchanged lines hidden (view full) ---

1940 {
1941 case GE_EXPR:
1942 /* All unsigned values are >= 0, so we warn if extra warnings
1943 are requested. However, if OP0 is a constant that is
1944 >= 0, the signedness of the comparison isn't an issue,
1945 so suppress the warning. */
1946 if (extra_warnings && !in_system_header
1947 && ! (TREE_CODE (primop0) == INTEGER_CST
2561 }
2562 else
2563 {
2564 /* Here we must do the comparison on the nominal type
2565 using the args exactly as we received them. */
2566 type = *restype_ptr;
2567 primop0 = op0;
2568 primop1 = op1;

--- 6 unchanged lines hidden (view full) ---

2575 {
2576 case GE_EXPR:
2577 /* All unsigned values are >= 0, so we warn if extra warnings
2578 are requested. However, if OP0 is a constant that is
2579 >= 0, the signedness of the comparison isn't an issue,
2580 so suppress the warning. */
2581 if (extra_warnings && !in_system_header
2582 && ! (TREE_CODE (primop0) == INTEGER_CST
1948 && ! TREE_OVERFLOW (convert (signed_type (type),
2583 && ! TREE_OVERFLOW (convert (c_common_signed_type (type),
1949 primop0))))
1950 warning ("comparison of unsigned expression >= 0 is always true");
1951 value = boolean_true_node;
1952 break;
1953
1954 case LT_EXPR:
1955 if (extra_warnings && !in_system_header
1956 && ! (TREE_CODE (primop0) == INTEGER_CST
2584 primop0))))
2585 warning ("comparison of unsigned expression >= 0 is always true");
2586 value = boolean_true_node;
2587 break;
2588
2589 case LT_EXPR:
2590 if (extra_warnings && !in_system_header
2591 && ! (TREE_CODE (primop0) == INTEGER_CST
1957 && ! TREE_OVERFLOW (convert (signed_type (type),
2592 && ! TREE_OVERFLOW (convert (c_common_signed_type (type),
1958 primop0))))
1959 warning ("comparison of unsigned expression < 0 is always false");
1960 value = boolean_false_node;
1961 break;
1962
1963 default:
1964 break;
1965 }

--- 92 unchanged lines hidden (view full) ---

2058 intop = convert (int_type, TREE_OPERAND (intop, 0));
2059 }
2060
2061 /* Convert the integer argument to a type the same size as sizetype
2062 so the multiply won't overflow spuriously. */
2063
2064 if (TYPE_PRECISION (TREE_TYPE (intop)) != TYPE_PRECISION (sizetype)
2065 || TREE_UNSIGNED (TREE_TYPE (intop)) != TREE_UNSIGNED (sizetype))
2593 primop0))))
2594 warning ("comparison of unsigned expression < 0 is always false");
2595 value = boolean_false_node;
2596 break;
2597
2598 default:
2599 break;
2600 }

--- 92 unchanged lines hidden (view full) ---

2693 intop = convert (int_type, TREE_OPERAND (intop, 0));
2694 }
2695
2696 /* Convert the integer argument to a type the same size as sizetype
2697 so the multiply won't overflow spuriously. */
2698
2699 if (TYPE_PRECISION (TREE_TYPE (intop)) != TYPE_PRECISION (sizetype)
2700 || TREE_UNSIGNED (TREE_TYPE (intop)) != TREE_UNSIGNED (sizetype))
2066 intop = convert (type_for_size (TYPE_PRECISION (sizetype),
2067 TREE_UNSIGNED (sizetype)), intop);
2701 intop = convert (c_common_type_for_size (TYPE_PRECISION (sizetype),
2702 TREE_UNSIGNED (sizetype)), intop);
2068
2069 /* Replace the integer argument with a suitable product by the object size.
2070 Do this multiplication as signed, then convert to the appropriate
2071 pointer type (actually unsigned integral). */
2072
2073 intop = convert (result_type,
2074 build_binary_op (MULT_EXPR, intop,
2075 convert (TREE_TYPE (intop), size_exp), 1));

--- 15 unchanged lines hidden (view full) ---

2091 representation of an expression expr and producing a valid tree
2092 boolean expression describing whether expr is nonzero. We could
2093 simply always do build_binary_op (NE_EXPR, expr, boolean_false_node, 1),
2094 but we optimize comparisons, &&, ||, and !.
2095
2096 The resulting type should always be `boolean_type_node'. */
2097
2098tree
2703
2704 /* Replace the integer argument with a suitable product by the object size.
2705 Do this multiplication as signed, then convert to the appropriate
2706 pointer type (actually unsigned integral). */
2707
2708 intop = convert (result_type,
2709 build_binary_op (MULT_EXPR, intop,
2710 convert (TREE_TYPE (intop), size_exp), 1));

--- 15 unchanged lines hidden (view full) ---

2726 representation of an expression expr and producing a valid tree
2727 boolean expression describing whether expr is nonzero. We could
2728 simply always do build_binary_op (NE_EXPR, expr, boolean_false_node, 1),
2729 but we optimize comparisons, &&, ||, and !.
2730
2731 The resulting type should always be `boolean_type_node'. */
2732
2733tree
2099truthvalue_conversion (expr)
2734c_common_truthvalue_conversion (expr)
2100 tree expr;
2101{
2102 if (TREE_CODE (expr) == ERROR_MARK)
2103 return expr;
2104
2105#if 0 /* This appears to be wrong for C++. */
2106 /* These really should return error_mark_node after 2.4 is stable.
2107 But not all callers handle ERROR_MARK properly. */

--- 49 unchanged lines hidden (view full) ---

2157 return build (COMPOUND_EXPR, boolean_type_node,
2158 TREE_OPERAND (expr, 0), boolean_true_node);
2159 else
2160 return boolean_true_node;
2161
2162 case COMPLEX_EXPR:
2163 return build_binary_op ((TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1))
2164 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
2735 tree expr;
2736{
2737 if (TREE_CODE (expr) == ERROR_MARK)
2738 return expr;
2739
2740#if 0 /* This appears to be wrong for C++. */
2741 /* These really should return error_mark_node after 2.4 is stable.
2742 But not all callers handle ERROR_MARK properly. */

--- 49 unchanged lines hidden (view full) ---

2792 return build (COMPOUND_EXPR, boolean_type_node,
2793 TREE_OPERAND (expr, 0), boolean_true_node);
2794 else
2795 return boolean_true_node;
2796
2797 case COMPLEX_EXPR:
2798 return build_binary_op ((TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1))
2799 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
2165 truthvalue_conversion (TREE_OPERAND (expr, 0)),
2166 truthvalue_conversion (TREE_OPERAND (expr, 1)),
2800 c_common_truthvalue_conversion (TREE_OPERAND (expr, 0)),
2801 c_common_truthvalue_conversion (TREE_OPERAND (expr, 1)),
2167 0);
2168
2169 case NEGATE_EXPR:
2170 case ABS_EXPR:
2171 case FLOAT_EXPR:
2172 case FFS_EXPR:
2802 0);
2803
2804 case NEGATE_EXPR:
2805 case ABS_EXPR:
2806 case FLOAT_EXPR:
2807 case FFS_EXPR:
2173 /* These don't change whether an object is non-zero or zero. */
2174 return truthvalue_conversion (TREE_OPERAND (expr, 0));
2808 /* These don't change whether an object is nonzero or zero. */
2809 return c_common_truthvalue_conversion (TREE_OPERAND (expr, 0));
2175
2176 case LROTATE_EXPR:
2177 case RROTATE_EXPR:
2810
2811 case LROTATE_EXPR:
2812 case RROTATE_EXPR:
2178 /* These don't change whether an object is zero or non-zero, but
2813 /* These don't change whether an object is zero or nonzero, but
2179 we can't ignore them if their second arg has side-effects. */
2180 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1)))
2181 return build (COMPOUND_EXPR, boolean_type_node, TREE_OPERAND (expr, 1),
2814 we can't ignore them if their second arg has side-effects. */
2815 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1)))
2816 return build (COMPOUND_EXPR, boolean_type_node, TREE_OPERAND (expr, 1),
2182 truthvalue_conversion (TREE_OPERAND (expr, 0)));
2817 c_common_truthvalue_conversion (TREE_OPERAND (expr, 0)));
2183 else
2818 else
2184 return truthvalue_conversion (TREE_OPERAND (expr, 0));
2819 return c_common_truthvalue_conversion (TREE_OPERAND (expr, 0));
2185
2186 case COND_EXPR:
2187 /* Distribute the conversion into the arms of a COND_EXPR. */
2188 return fold (build (COND_EXPR, boolean_type_node, TREE_OPERAND (expr, 0),
2820
2821 case COND_EXPR:
2822 /* Distribute the conversion into the arms of a COND_EXPR. */
2823 return fold (build (COND_EXPR, boolean_type_node, TREE_OPERAND (expr, 0),
2189 truthvalue_conversion (TREE_OPERAND (expr, 1)),
2190 truthvalue_conversion (TREE_OPERAND (expr, 2))));
2824 c_common_truthvalue_conversion (TREE_OPERAND (expr, 1)),
2825 c_common_truthvalue_conversion (TREE_OPERAND (expr, 2))));
2191
2192 case CONVERT_EXPR:
2193 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
2194 since that affects how `default_conversion' will behave. */
2195 if (TREE_CODE (TREE_TYPE (expr)) == REFERENCE_TYPE
2196 || TREE_CODE (TREE_TYPE (TREE_OPERAND (expr, 0))) == REFERENCE_TYPE)
2197 break;
2198 /* fall through... */
2199 case NOP_EXPR:
2200 /* If this is widening the argument, we can ignore it. */
2201 if (TYPE_PRECISION (TREE_TYPE (expr))
2202 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0))))
2826
2827 case CONVERT_EXPR:
2828 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
2829 since that affects how `default_conversion' will behave. */
2830 if (TREE_CODE (TREE_TYPE (expr)) == REFERENCE_TYPE
2831 || TREE_CODE (TREE_TYPE (TREE_OPERAND (expr, 0))) == REFERENCE_TYPE)
2832 break;
2833 /* fall through... */
2834 case NOP_EXPR:
2835 /* If this is widening the argument, we can ignore it. */
2836 if (TYPE_PRECISION (TREE_TYPE (expr))
2837 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0))))
2203 return truthvalue_conversion (TREE_OPERAND (expr, 0));
2838 return c_common_truthvalue_conversion (TREE_OPERAND (expr, 0));
2204 break;
2205
2206 case MINUS_EXPR:
2839 break;
2840
2841 case MINUS_EXPR:
2207 /* With IEEE arithmetic, x - x may not equal 0, so we can't optimize
2208 this case. */
2209 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
2210 && TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE)
2842 /* Perhaps reduce (x - y) != 0 to (x != y). The expressions
2843 aren't guaranteed to the be same for modes that can represent
2844 infinity, since if x and y are both +infinity, or both
2845 -infinity, then x - y is not a number.
2846
2847 Note that this transformation is safe when x or y is NaN.
2848 (x - y) is then NaN, and both (x - y) != 0 and x != y will
2849 be false. */
2850 if (HONOR_INFINITIES (TYPE_MODE (TREE_TYPE (TREE_OPERAND (expr, 0)))))
2211 break;
2212 /* fall through... */
2213 case BIT_XOR_EXPR:
2214 /* This and MINUS_EXPR can be changed into a comparison of the
2215 two objects. */
2216 if (TREE_TYPE (TREE_OPERAND (expr, 0))
2217 == TREE_TYPE (TREE_OPERAND (expr, 1)))
2218 return build_binary_op (NE_EXPR, TREE_OPERAND (expr, 0),

--- 16 unchanged lines hidden (view full) ---

2235 break;
2236
2237 default:
2238 break;
2239 }
2240
2241 if (TREE_CODE (TREE_TYPE (expr)) == COMPLEX_TYPE)
2242 {
2851 break;
2852 /* fall through... */
2853 case BIT_XOR_EXPR:
2854 /* This and MINUS_EXPR can be changed into a comparison of the
2855 two objects. */
2856 if (TREE_TYPE (TREE_OPERAND (expr, 0))
2857 == TREE_TYPE (TREE_OPERAND (expr, 1)))
2858 return build_binary_op (NE_EXPR, TREE_OPERAND (expr, 0),

--- 16 unchanged lines hidden (view full) ---

2875 break;
2876
2877 default:
2878 break;
2879 }
2880
2881 if (TREE_CODE (TREE_TYPE (expr)) == COMPLEX_TYPE)
2882 {
2243 tree tem = save_expr (expr);
2883 tree t = save_expr (expr);
2244 return (build_binary_op
2245 ((TREE_SIDE_EFFECTS (expr)
2246 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
2884 return (build_binary_op
2885 ((TREE_SIDE_EFFECTS (expr)
2886 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
2247 truthvalue_conversion (build_unary_op (REALPART_EXPR, tem, 0)),
2248 truthvalue_conversion (build_unary_op (IMAGPART_EXPR, tem, 0)),
2887 c_common_truthvalue_conversion (build_unary_op (REALPART_EXPR, t, 0)),
2888 c_common_truthvalue_conversion (build_unary_op (IMAGPART_EXPR, t, 0)),
2249 0));
2250 }
2251
2252 return build_binary_op (NE_EXPR, expr, integer_zero_node, 1);
2253}
2254
2255static tree builtin_function_2 PARAMS ((const char *, const char *, tree, tree,
2256 int, enum built_in_class, int, int,
2889 0));
2890 }
2891
2892 return build_binary_op (NE_EXPR, expr, integer_zero_node, 1);
2893}
2894
2895static tree builtin_function_2 PARAMS ((const char *, const char *, tree, tree,
2896 int, enum built_in_class, int, int,
2257 int));
2897 tree));
2258
2259/* Make a variant type in the proper way for C/C++, propagating qualifiers
2260 down to the element type of an array. */
2261
2262tree
2263c_build_qualified_type (type, type_quals)
2264 tree type;
2265 int type_quals;

--- 45 unchanged lines hidden (view full) ---

2311 else if (flag_strict_aliasing)
2312 /* Indicate we need to make a unique alias set for this pointer.
2313 We can't do it here because it might be pointing to an
2314 incomplete type. */
2315 DECL_POINTER_ALIAS_SET (decl) = -2;
2316 }
2317}
2318
2898
2899/* Make a variant type in the proper way for C/C++, propagating qualifiers
2900 down to the element type of an array. */
2901
2902tree
2903c_build_qualified_type (type, type_quals)
2904 tree type;
2905 int type_quals;

--- 45 unchanged lines hidden (view full) ---

2951 else if (flag_strict_aliasing)
2952 /* Indicate we need to make a unique alias set for this pointer.
2953 We can't do it here because it might be pointing to an
2954 incomplete type. */
2955 DECL_POINTER_ALIAS_SET (decl) = -2;
2956 }
2957}
2958
2319
2320/* Return the typed-based alias set for T, which may be an expression
2321 or a type. Return -1 if we don't do anything special. */
2322
2323HOST_WIDE_INT
2324c_common_get_alias_set (t)
2325 tree t;
2326{
2327 tree u;

--- 16 unchanged lines hidden (view full) ---

2344 return -1;
2345
2346 /* The C standard guarantess that any object may be accessed via an
2347 lvalue that has character type. */
2348 if (t == char_type_node
2349 || t == signed_char_type_node
2350 || t == unsigned_char_type_node)
2351 return 0;
2959/* Return the typed-based alias set for T, which may be an expression
2960 or a type. Return -1 if we don't do anything special. */
2961
2962HOST_WIDE_INT
2963c_common_get_alias_set (t)
2964 tree t;
2965{
2966 tree u;

--- 16 unchanged lines hidden (view full) ---

2983 return -1;
2984
2985 /* The C standard guarantess that any object may be accessed via an
2986 lvalue that has character type. */
2987 if (t == char_type_node
2988 || t == signed_char_type_node
2989 || t == unsigned_char_type_node)
2990 return 0;
2352
2991
2992 /* If it has the may_alias attribute, it can alias anything. */
2993 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (t)))
2994 return 0;
2995
2353 /* The C standard specifically allows aliasing between signed and
2354 unsigned variants of the same type. We treat the signed
2355 variant as canonical. */
2356 if (TREE_CODE (t) == INTEGER_TYPE && TREE_UNSIGNED (t))
2357 {
2996 /* The C standard specifically allows aliasing between signed and
2997 unsigned variants of the same type. We treat the signed
2998 variant as canonical. */
2999 if (TREE_CODE (t) == INTEGER_TYPE && TREE_UNSIGNED (t))
3000 {
2358 tree t1 = signed_type (t);
3001 tree t1 = c_common_signed_type (t);
2359
2360 /* t1 == t can happen for boolean nodes which are always unsigned. */
2361 if (t1 != t)
2362 return get_alias_set (t1);
2363 }
2364 else if (POINTER_TYPE_P (t))
2365 {
2366 tree t1;

--- 24 unchanged lines hidden (view full) ---

2391 t1 = build_type_no_quals (t);
2392 if (t1 != t)
2393 return get_alias_set (t1);
2394 }
2395
2396 return -1;
2397}
2398
3002
3003 /* t1 == t can happen for boolean nodes which are always unsigned. */
3004 if (t1 != t)
3005 return get_alias_set (t1);
3006 }
3007 else if (POINTER_TYPE_P (t))
3008 {
3009 tree t1;

--- 24 unchanged lines hidden (view full) ---

3034 t1 = build_type_no_quals (t);
3035 if (t1 != t)
3036 return get_alias_set (t1);
3037 }
3038
3039 return -1;
3040}
3041
2399/* Implement the __alignof keyword: Return the minimum required
2400 alignment of TYPE, measured in bytes. */
2401
3042/* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where the
3043 second parameter indicates which OPERATOR is being applied. The COMPLAIN
3044 flag controls whether we should diagnose possibly ill-formed
3045 constructs or not. */
2402tree
3046tree
2403c_alignof (type)
3047c_sizeof_or_alignof_type (type, op, complain)
2404 tree type;
3048 tree type;
3049 enum tree_code op;
3050 int complain;
2405{
3051{
2406 enum tree_code code = TREE_CODE (type);
2407 tree t;
2408
2409 /* In C++, sizeof applies to the referent. Handle alignof the same way. */
2410 if (code == REFERENCE_TYPE)
3052 const char *op_name;
3053 tree value = NULL;
3054 enum tree_code type_code = TREE_CODE (type);
3055
3056 my_friendly_assert (op == SIZEOF_EXPR || op == ALIGNOF_EXPR, 20020720);
3057 op_name = op == SIZEOF_EXPR ? "sizeof" : "__alignof__";
3058
3059 if (type_code == FUNCTION_TYPE)
2411 {
3060 {
2412 type = TREE_TYPE (type);
2413 code = TREE_CODE (type);
3061 if (op == SIZEOF_EXPR)
3062 {
3063 if (complain && (pedantic || warn_pointer_arith))
3064 pedwarn ("invalid application of `sizeof' to a function type");
3065 value = size_one_node;
3066 }
3067 else
3068 value = size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
2414 }
3069 }
2415
2416 if (code == FUNCTION_TYPE)
2417 t = size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
2418 else if (code == VOID_TYPE || code == ERROR_MARK)
2419 t = size_one_node;
3070 else if (type_code == VOID_TYPE || type_code == ERROR_MARK)
3071 {
3072 if (type_code == VOID_TYPE
3073 && complain && (pedantic || warn_pointer_arith))
3074 pedwarn ("invalid application of `%s' to a void type", op_name);
3075 value = size_one_node;
3076 }
2420 else if (!COMPLETE_TYPE_P (type))
2421 {
3077 else if (!COMPLETE_TYPE_P (type))
3078 {
2422 error ("__alignof__ applied to an incomplete type");
2423 t = size_zero_node;
3079 if (complain)
3080 error ("invalid application of `%s' to an incomplete type", op_name);
3081 value = size_zero_node;
2424 }
2425 else
3082 }
3083 else
2426 t = size_int (TYPE_ALIGN (type) / BITS_PER_UNIT);
3084 {
3085 if (op == SIZEOF_EXPR)
3086 /* Convert in case a char is more than one unit. */
3087 value = size_binop (CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
3088 size_int (TYPE_PRECISION (char_type_node)
3089 / BITS_PER_UNIT));
3090 else
3091 value = size_int (TYPE_ALIGN (type) / BITS_PER_UNIT);
3092 }
2427
3093
2428 return fold (build1 (NOP_EXPR, size_type_node, t));
3094 /* VALUE will have an integer type with TYPE_IS_SIZETYPE set.
3095 TYPE_IS_SIZETYPE means that certain things (like overflow) will
3096 never happen. However, this node should really have type
3097 `size_t', which is just a typedef for an ordinary integer type. */
3098 value = fold (build1 (NOP_EXPR, size_type_node, value));
3099 my_friendly_assert (!TYPE_IS_SIZETYPE (TREE_TYPE (value)), 20001021);
3100
3101 return value;
2429}
2430
2431/* Implement the __alignof keyword: Return the minimum required
2432 alignment of EXPR, measured in bytes. For VAR_DECL's and
2433 FIELD_DECL's return DECL_ALIGN (which can be set from an
2434 "aligned" __attribute__ specification). */
2435
2436tree

--- 34 unchanged lines hidden (view full) ---

2471 return c_alignof (TREE_TYPE (TREE_TYPE (best)));
2472 }
2473 else
2474 return c_alignof (TREE_TYPE (expr));
2475
2476 return fold (build1 (NOP_EXPR, size_type_node, t));
2477}
2478
3102}
3103
3104/* Implement the __alignof keyword: Return the minimum required
3105 alignment of EXPR, measured in bytes. For VAR_DECL's and
3106 FIELD_DECL's return DECL_ALIGN (which can be set from an
3107 "aligned" __attribute__ specification). */
3108
3109tree

--- 34 unchanged lines hidden (view full) ---

3144 return c_alignof (TREE_TYPE (TREE_TYPE (best)));
3145 }
3146 else
3147 return c_alignof (TREE_TYPE (expr));
3148
3149 return fold (build1 (NOP_EXPR, size_type_node, t));
3150}
3151
2479/* Give the specifications for the format attributes, used by C and all
2480 descendents. */
3152/* Handle C and C++ default attributes. */
2481
3153
2482static const struct attribute_spec c_format_attribute_table[] =
3154enum built_in_attribute
2483{
3155{
2484 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
2485 { "format", 3, 3, false, true, true,
2486 handle_format_attribute },
2487 { "format_arg", 1, 1, false, true, true,
2488 handle_format_arg_attribute },
2489 { NULL, 0, 0, false, false, false, NULL }
3156#define DEF_ATTR_NULL_TREE(ENUM) ENUM,
3157#define DEF_ATTR_INT(ENUM, VALUE) ENUM,
3158#define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
3159#define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
3160#define DEF_FN_ATTR(NAME, ATTRS, PREDICATE) /* No entry needed in enum. */
3161#include "builtin-attrs.def"
3162#undef DEF_ATTR_NULL_TREE
3163#undef DEF_ATTR_INT
3164#undef DEF_ATTR_IDENT
3165#undef DEF_ATTR_TREE_LIST
3166#undef DEF_FN_ATTR
3167 ATTR_LAST
2490};
2491
3168};
3169
3170static GTY(()) tree built_in_attributes[(int) ATTR_LAST];
3171
3172static bool c_attrs_initialized = false;
3173
3174static void c_init_attributes PARAMS ((void));
3175
2492/* Build tree nodes and builtin functions common to both C and C++ language
2493 frontends. */
2494
2495void
2496c_common_nodes_and_builtins ()
2497{
2498 enum builtin_type
2499 {
2500#define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
2501#define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
2502#define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
2503#define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
2504#define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
2505#define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
2506#define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
2507#define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
2508#define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
3176/* Build tree nodes and builtin functions common to both C and C++ language
3177 frontends. */
3178
3179void
3180c_common_nodes_and_builtins ()
3181{
3182 enum builtin_type
3183 {
3184#define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
3185#define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
3186#define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
3187#define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
3188#define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
3189#define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
3190#define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
3191#define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
3192#define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
3193#define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
2509#define DEF_POINTER_TYPE(NAME, TYPE) NAME,
2510#include "builtin-types.def"
2511#undef DEF_PRIMITIVE_TYPE
2512#undef DEF_FUNCTION_TYPE_0
2513#undef DEF_FUNCTION_TYPE_1
2514#undef DEF_FUNCTION_TYPE_2
2515#undef DEF_FUNCTION_TYPE_3
2516#undef DEF_FUNCTION_TYPE_4
2517#undef DEF_FUNCTION_TYPE_VAR_0
2518#undef DEF_FUNCTION_TYPE_VAR_1
2519#undef DEF_FUNCTION_TYPE_VAR_2
3194#define DEF_POINTER_TYPE(NAME, TYPE) NAME,
3195#include "builtin-types.def"
3196#undef DEF_PRIMITIVE_TYPE
3197#undef DEF_FUNCTION_TYPE_0
3198#undef DEF_FUNCTION_TYPE_1
3199#undef DEF_FUNCTION_TYPE_2
3200#undef DEF_FUNCTION_TYPE_3
3201#undef DEF_FUNCTION_TYPE_4
3202#undef DEF_FUNCTION_TYPE_VAR_0
3203#undef DEF_FUNCTION_TYPE_VAR_1
3204#undef DEF_FUNCTION_TYPE_VAR_2
3205#undef DEF_FUNCTION_TYPE_VAR_3
2520#undef DEF_POINTER_TYPE
2521 BT_LAST
2522 };
2523
2524 typedef enum builtin_type builtin_type;
2525
2526 tree builtin_types[(int) BT_LAST];
2527 int wchar_type_size;
2528 tree array_domain_type;
3206#undef DEF_POINTER_TYPE
3207 BT_LAST
3208 };
3209
3210 typedef enum builtin_type builtin_type;
3211
3212 tree builtin_types[(int) BT_LAST];
3213 int wchar_type_size;
3214 tree array_domain_type;
2529 /* Either char* or void*. */
2530 tree traditional_ptr_type_node;
2531 /* Either const char* or const void*. */
2532 tree traditional_cptr_type_node;
2533 tree traditional_len_type_node;
2534 tree va_list_ref_type_node;
2535 tree va_list_arg_type_node;
2536
3215 tree va_list_ref_type_node;
3216 tree va_list_arg_type_node;
3217
2537 /* We must initialize this before any builtin functions (which might have
2538 attributes) are declared. (c_common_init is too late.) */
2539 format_attribute_table = c_format_attribute_table;
2540
2541 /* Define `int' and `char' first so that dbx will output them first. */
2542 record_builtin_type (RID_INT, NULL, integer_type_node);
2543 record_builtin_type (RID_CHAR, "char", char_type_node);
2544
2545 /* `signed' is the same as `int'. FIXME: the declarations of "signed",
2546 "unsigned long", "long long unsigned" and "unsigned short" were in C++
2547 but not C. Are the conditionals here needed? */
2548 if (c_language == clk_cplusplus)

--- 17 unchanged lines hidden (view full) ---

2566 if (c_language == clk_cplusplus)
2567 record_builtin_type (RID_MAX, "unsigned short",
2568 short_unsigned_type_node);
2569
2570 /* Define both `signed char' and `unsigned char'. */
2571 record_builtin_type (RID_MAX, "signed char", signed_char_type_node);
2572 record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node);
2573
3218 /* Define `int' and `char' first so that dbx will output them first. */
3219 record_builtin_type (RID_INT, NULL, integer_type_node);
3220 record_builtin_type (RID_CHAR, "char", char_type_node);
3221
3222 /* `signed' is the same as `int'. FIXME: the declarations of "signed",
3223 "unsigned long", "long long unsigned" and "unsigned short" were in C++
3224 but not C. Are the conditionals here needed? */
3225 if (c_language == clk_cplusplus)

--- 17 unchanged lines hidden (view full) ---

3243 if (c_language == clk_cplusplus)
3244 record_builtin_type (RID_MAX, "unsigned short",
3245 short_unsigned_type_node);
3246
3247 /* Define both `signed char' and `unsigned char'. */
3248 record_builtin_type (RID_MAX, "signed char", signed_char_type_node);
3249 record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node);
3250
2574 /* These are types that type_for_size and type_for_mode use. */
2575 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intQI_type_node));
2576 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intHI_type_node));
2577 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node));
2578 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node));
3251 /* These are types that c_common_type_for_size and
3252 c_common_type_for_mode use. */
3253 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, NULL_TREE,
3254 intQI_type_node));
3255 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, NULL_TREE,
3256 intHI_type_node));
3257 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, NULL_TREE,
3258 intSI_type_node));
3259 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, NULL_TREE,
3260 intDI_type_node));
2579#if HOST_BITS_PER_WIDE_INT >= 64
3261#if HOST_BITS_PER_WIDE_INT >= 64
2580 pushdecl (build_decl (TYPE_DECL, get_identifier ("__int128_t"), intTI_type_node));
3262 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
3263 get_identifier ("__int128_t"),
3264 intTI_type_node));
2581#endif
3265#endif
2582 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node));
2583 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intHI_type_node));
2584 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node));
2585 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node));
3266 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, NULL_TREE,
3267 unsigned_intQI_type_node));
3268 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, NULL_TREE,
3269 unsigned_intHI_type_node));
3270 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, NULL_TREE,
3271 unsigned_intSI_type_node));
3272 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, NULL_TREE,
3273 unsigned_intDI_type_node));
2586#if HOST_BITS_PER_WIDE_INT >= 64
3274#if HOST_BITS_PER_WIDE_INT >= 64
2587 pushdecl (build_decl (TYPE_DECL, get_identifier ("__uint128_t"), unsigned_intTI_type_node));
3275 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
3276 get_identifier ("__uint128_t"),
3277 unsigned_intTI_type_node));
2588#endif
2589
2590 /* Create the widest literal types. */
2591 widest_integer_literal_type_node
2592 = make_signed_type (HOST_BITS_PER_WIDE_INT * 2);
3278#endif
3279
3280 /* Create the widest literal types. */
3281 widest_integer_literal_type_node
3282 = make_signed_type (HOST_BITS_PER_WIDE_INT * 2);
2593 pushdecl (build_decl (TYPE_DECL, NULL_TREE,
2594 widest_integer_literal_type_node));
3283 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, NULL_TREE,
3284 widest_integer_literal_type_node));
2595
2596 widest_unsigned_literal_type_node
2597 = make_unsigned_type (HOST_BITS_PER_WIDE_INT * 2);
3285
3286 widest_unsigned_literal_type_node
3287 = make_unsigned_type (HOST_BITS_PER_WIDE_INT * 2);
2598 pushdecl (build_decl (TYPE_DECL, NULL_TREE,
2599 widest_unsigned_literal_type_node));
3288 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, NULL_TREE,
3289 widest_unsigned_literal_type_node));
2600
2601 /* `unsigned long' is the standard type for sizeof.
2602 Note that stddef.h uses `unsigned long',
2603 and this must agree, even if long and int are the same size. */
2604 size_type_node =
2605 TREE_TYPE (identifier_global_value (get_identifier (SIZE_TYPE)));
3290
3291 /* `unsigned long' is the standard type for sizeof.
3292 Note that stddef.h uses `unsigned long',
3293 and this must agree, even if long and int are the same size. */
3294 size_type_node =
3295 TREE_TYPE (identifier_global_value (get_identifier (SIZE_TYPE)));
2606 signed_size_type_node = signed_type (size_type_node);
2607 if (flag_traditional)
2608 size_type_node = signed_size_type_node;
3296 signed_size_type_node = c_common_signed_type (size_type_node);
2609 set_sizetype (size_type_node);
2610
2611 build_common_tree_nodes_2 (flag_short_double);
2612
2613 record_builtin_type (RID_FLOAT, NULL, float_type_node);
2614 record_builtin_type (RID_DOUBLE, NULL, double_type_node);
2615 record_builtin_type (RID_MAX, "long double", long_double_type_node);
2616
3297 set_sizetype (size_type_node);
3298
3299 build_common_tree_nodes_2 (flag_short_double);
3300
3301 record_builtin_type (RID_FLOAT, NULL, float_type_node);
3302 record_builtin_type (RID_DOUBLE, NULL, double_type_node);
3303 record_builtin_type (RID_MAX, "long double", long_double_type_node);
3304
2617 pushdecl (build_decl (TYPE_DECL, get_identifier ("complex int"),
2618 complex_integer_type_node));
2619 pushdecl (build_decl (TYPE_DECL, get_identifier ("complex float"),
2620 complex_float_type_node));
2621 pushdecl (build_decl (TYPE_DECL, get_identifier ("complex double"),
2622 complex_double_type_node));
2623 pushdecl (build_decl (TYPE_DECL, get_identifier ("complex long double"),
2624 complex_long_double_type_node));
3305 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
3306 get_identifier ("complex int"),
3307 complex_integer_type_node));
3308 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
3309 get_identifier ("complex float"),
3310 complex_float_type_node));
3311 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
3312 get_identifier ("complex double"),
3313 complex_double_type_node));
3314 (*lang_hooks.decls.pushdecl)
3315 (build_decl (TYPE_DECL, get_identifier ("complex long double"),
3316 complex_long_double_type_node));
2625
2626 /* Types which are common to the fortran compiler and libf2c. When
2627 changing these, you also need to be concerned with f/com.h. */
2628
2629 if (TYPE_PRECISION (float_type_node)
2630 == TYPE_PRECISION (long_integer_type_node))
2631 {
2632 g77_integer_type_node = long_integer_type_node;

--- 5 unchanged lines hidden (view full) ---

2638 g77_integer_type_node = integer_type_node;
2639 g77_uinteger_type_node = unsigned_type_node;
2640 }
2641 else
2642 g77_integer_type_node = g77_uinteger_type_node = NULL_TREE;
2643
2644 if (g77_integer_type_node != NULL_TREE)
2645 {
3317
3318 /* Types which are common to the fortran compiler and libf2c. When
3319 changing these, you also need to be concerned with f/com.h. */
3320
3321 if (TYPE_PRECISION (float_type_node)
3322 == TYPE_PRECISION (long_integer_type_node))
3323 {
3324 g77_integer_type_node = long_integer_type_node;

--- 5 unchanged lines hidden (view full) ---

3330 g77_integer_type_node = integer_type_node;
3331 g77_uinteger_type_node = unsigned_type_node;
3332 }
3333 else
3334 g77_integer_type_node = g77_uinteger_type_node = NULL_TREE;
3335
3336 if (g77_integer_type_node != NULL_TREE)
3337 {
2646 pushdecl (build_decl (TYPE_DECL,
2647 get_identifier ("__g77_integer"),
2648 g77_integer_type_node));
2649 pushdecl (build_decl (TYPE_DECL,
2650 get_identifier ("__g77_uinteger"),
2651 g77_uinteger_type_node));
3338 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
3339 get_identifier ("__g77_integer"),
3340 g77_integer_type_node));
3341 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
3342 get_identifier ("__g77_uinteger"),
3343 g77_uinteger_type_node));
2652 }
2653
2654 if (TYPE_PRECISION (float_type_node) * 2
2655 == TYPE_PRECISION (long_integer_type_node))
2656 {
2657 g77_longint_type_node = long_integer_type_node;
2658 g77_ulongint_type_node = long_unsigned_type_node;
2659 }
2660 else if (TYPE_PRECISION (float_type_node) * 2
2661 == TYPE_PRECISION (long_long_integer_type_node))
2662 {
2663 g77_longint_type_node = long_long_integer_type_node;
2664 g77_ulongint_type_node = long_long_unsigned_type_node;
2665 }
2666 else
2667 g77_longint_type_node = g77_ulongint_type_node = NULL_TREE;
2668
2669 if (g77_longint_type_node != NULL_TREE)
2670 {
3344 }
3345
3346 if (TYPE_PRECISION (float_type_node) * 2
3347 == TYPE_PRECISION (long_integer_type_node))
3348 {
3349 g77_longint_type_node = long_integer_type_node;
3350 g77_ulongint_type_node = long_unsigned_type_node;
3351 }
3352 else if (TYPE_PRECISION (float_type_node) * 2
3353 == TYPE_PRECISION (long_long_integer_type_node))
3354 {
3355 g77_longint_type_node = long_long_integer_type_node;
3356 g77_ulongint_type_node = long_long_unsigned_type_node;
3357 }
3358 else
3359 g77_longint_type_node = g77_ulongint_type_node = NULL_TREE;
3360
3361 if (g77_longint_type_node != NULL_TREE)
3362 {
2671 pushdecl (build_decl (TYPE_DECL,
2672 get_identifier ("__g77_longint"),
2673 g77_longint_type_node));
2674 pushdecl (build_decl (TYPE_DECL,
2675 get_identifier ("__g77_ulongint"),
2676 g77_ulongint_type_node));
3363 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
3364 get_identifier ("__g77_longint"),
3365 g77_longint_type_node));
3366 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
3367 get_identifier ("__g77_ulongint"),
3368 g77_ulongint_type_node));
2677 }
2678
2679 record_builtin_type (RID_VOID, NULL, void_type_node);
2680
2681 void_zero_node = build_int_2 (0, 0);
2682 TREE_TYPE (void_zero_node) = void_type_node;
2683
2684 void_list_node = build_void_list_node ();

--- 15 unchanged lines hidden (view full) ---

2700 int_array_type_node
2701 = build_array_type (integer_type_node, array_domain_type);
2702
2703 string_type_node = build_pointer_type (char_type_node);
2704 const_string_type_node
2705 = build_pointer_type (build_qualified_type
2706 (char_type_node, TYPE_QUAL_CONST));
2707
3369 }
3370
3371 record_builtin_type (RID_VOID, NULL, void_type_node);
3372
3373 void_zero_node = build_int_2 (0, 0);
3374 TREE_TYPE (void_zero_node) = void_type_node;
3375
3376 void_list_node = build_void_list_node ();

--- 15 unchanged lines hidden (view full) ---

3392 int_array_type_node
3393 = build_array_type (integer_type_node, array_domain_type);
3394
3395 string_type_node = build_pointer_type (char_type_node);
3396 const_string_type_node
3397 = build_pointer_type (build_qualified_type
3398 (char_type_node, TYPE_QUAL_CONST));
3399
2708 traditional_ptr_type_node = ((flag_traditional &&
2709 c_language != clk_cplusplus)
2710 ? string_type_node : ptr_type_node);
2711 traditional_cptr_type_node = ((flag_traditional &&
2712 c_language != clk_cplusplus)
2713 ? const_string_type_node : const_ptr_type_node);
2714
2715 (*targetm.init_builtins) ();
2716
2717 /* This is special for C++ so functions can be overloaded. */
3400 /* This is special for C++ so functions can be overloaded. */
2718 wchar_type_node = get_identifier (flag_short_wchar
2719 ? "short unsigned int"
2720 : WCHAR_TYPE);
3401 wchar_type_node = get_identifier (MODIFIED_WCHAR_TYPE);
2721 wchar_type_node = TREE_TYPE (identifier_global_value (wchar_type_node));
2722 wchar_type_size = TYPE_PRECISION (wchar_type_node);
2723 if (c_language == clk_cplusplus)
2724 {
2725 if (TREE_UNSIGNED (wchar_type_node))
2726 wchar_type_node = make_unsigned_type (wchar_type_size);
2727 else
2728 wchar_type_node = make_signed_type (wchar_type_size);
2729 record_builtin_type (RID_WCHAR, "wchar_t", wchar_type_node);
2730 }
2731 else
2732 {
3402 wchar_type_node = TREE_TYPE (identifier_global_value (wchar_type_node));
3403 wchar_type_size = TYPE_PRECISION (wchar_type_node);
3404 if (c_language == clk_cplusplus)
3405 {
3406 if (TREE_UNSIGNED (wchar_type_node))
3407 wchar_type_node = make_unsigned_type (wchar_type_size);
3408 else
3409 wchar_type_node = make_signed_type (wchar_type_size);
3410 record_builtin_type (RID_WCHAR, "wchar_t", wchar_type_node);
3411 }
3412 else
3413 {
2733 signed_wchar_type_node = signed_type (wchar_type_node);
2734 unsigned_wchar_type_node = unsigned_type (wchar_type_node);
3414 signed_wchar_type_node = c_common_signed_type (wchar_type_node);
3415 unsigned_wchar_type_node = c_common_unsigned_type (wchar_type_node);
2735 }
2736
2737 /* This is for wide string constants. */
2738 wchar_array_type_node
2739 = build_array_type (wchar_type_node, array_domain_type);
2740
2741 wint_type_node =
2742 TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE)));
2743
2744 intmax_type_node =
2745 TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE)));
2746 uintmax_type_node =
2747 TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE)));
2748
2749 default_function_type = build_function_type (integer_type_node, NULL_TREE);
2750 ptrdiff_type_node
2751 = TREE_TYPE (identifier_global_value (get_identifier (PTRDIFF_TYPE)));
3416 }
3417
3418 /* This is for wide string constants. */
3419 wchar_array_type_node
3420 = build_array_type (wchar_type_node, array_domain_type);
3421
3422 wint_type_node =
3423 TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE)));
3424
3425 intmax_type_node =
3426 TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE)));
3427 uintmax_type_node =
3428 TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE)));
3429
3430 default_function_type = build_function_type (integer_type_node, NULL_TREE);
3431 ptrdiff_type_node
3432 = TREE_TYPE (identifier_global_value (get_identifier (PTRDIFF_TYPE)));
2752 unsigned_ptrdiff_type_node = unsigned_type (ptrdiff_type_node);
3433 unsigned_ptrdiff_type_node = c_common_unsigned_type (ptrdiff_type_node);
2753
3434
2754 pushdecl (build_decl (TYPE_DECL, get_identifier ("__builtin_va_list"),
2755 va_list_type_node));
3435 (*lang_hooks.decls.pushdecl)
3436 (build_decl (TYPE_DECL, get_identifier ("__builtin_va_list"),
3437 va_list_type_node));
2756
3438
2757 pushdecl (build_decl (TYPE_DECL, get_identifier ("__builtin_ptrdiff_t"),
2758 ptrdiff_type_node));
3439 (*lang_hooks.decls.pushdecl)
3440 (build_decl (TYPE_DECL, get_identifier ("__builtin_ptrdiff_t"),
3441 ptrdiff_type_node));
2759
3442
2760 pushdecl (build_decl (TYPE_DECL, get_identifier ("__builtin_size_t"),
2761 sizetype));
3443 (*lang_hooks.decls.pushdecl)
3444 (build_decl (TYPE_DECL, get_identifier ("__builtin_size_t"),
3445 sizetype));
2762
2763 if (TREE_CODE (va_list_type_node) == ARRAY_TYPE)
2764 {
2765 va_list_arg_type_node = va_list_ref_type_node =
2766 build_pointer_type (TREE_TYPE (va_list_type_node));
2767 }
2768 else
2769 {
2770 va_list_arg_type_node = va_list_type_node;
2771 va_list_ref_type_node = build_reference_type (va_list_type_node);
2772 }
2773
3446
3447 if (TREE_CODE (va_list_type_node) == ARRAY_TYPE)
3448 {
3449 va_list_arg_type_node = va_list_ref_type_node =
3450 build_pointer_type (TREE_TYPE (va_list_type_node));
3451 }
3452 else
3453 {
3454 va_list_arg_type_node = va_list_type_node;
3455 va_list_ref_type_node = build_reference_type (va_list_type_node);
3456 }
3457
2774 traditional_len_type_node = ((flag_traditional &&
2775 c_language != clk_cplusplus)
2776 ? integer_type_node : sizetype);
2777
2778#define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
2779 builtin_types[(int) ENUM] = VALUE;
2780#define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
2781 builtin_types[(int) ENUM] \
2782 = build_function_type (builtin_types[(int) RETURN], \
2783 void_list_node);
2784#define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
2785 builtin_types[(int) ENUM] \

--- 49 unchanged lines hidden (view full) ---

2835 builtin_types[(int) ENUM] \
2836 = build_function_type \
2837 (builtin_types[(int) RETURN], \
2838 tree_cons (NULL_TREE, \
2839 builtin_types[(int) ARG1], \
2840 tree_cons (NULL_TREE, \
2841 builtin_types[(int) ARG2], \
2842 NULL_TREE)));
3458#define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
3459 builtin_types[(int) ENUM] = VALUE;
3460#define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
3461 builtin_types[(int) ENUM] \
3462 = build_function_type (builtin_types[(int) RETURN], \
3463 void_list_node);
3464#define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
3465 builtin_types[(int) ENUM] \

--- 49 unchanged lines hidden (view full) ---

3515 builtin_types[(int) ENUM] \
3516 = build_function_type \
3517 (builtin_types[(int) RETURN], \
3518 tree_cons (NULL_TREE, \
3519 builtin_types[(int) ARG1], \
3520 tree_cons (NULL_TREE, \
3521 builtin_types[(int) ARG2], \
3522 NULL_TREE)));
3523
3524#define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
3525 builtin_types[(int) ENUM] \
3526 = build_function_type \
3527 (builtin_types[(int) RETURN], \
3528 tree_cons (NULL_TREE, \
3529 builtin_types[(int) ARG1], \
3530 tree_cons (NULL_TREE, \
3531 builtin_types[(int) ARG2], \
3532 tree_cons (NULL_TREE, \
3533 builtin_types[(int) ARG3], \
3534 NULL_TREE))));
3535
2843#define DEF_POINTER_TYPE(ENUM, TYPE) \
2844 builtin_types[(int) ENUM] \
2845 = build_pointer_type (builtin_types[(int) TYPE]);
2846#include "builtin-types.def"
2847#undef DEF_PRIMITIVE_TYPE
2848#undef DEF_FUNCTION_TYPE_1
2849#undef DEF_FUNCTION_TYPE_2
2850#undef DEF_FUNCTION_TYPE_3
2851#undef DEF_FUNCTION_TYPE_4
2852#undef DEF_FUNCTION_TYPE_VAR_0
2853#undef DEF_FUNCTION_TYPE_VAR_1
3536#define DEF_POINTER_TYPE(ENUM, TYPE) \
3537 builtin_types[(int) ENUM] \
3538 = build_pointer_type (builtin_types[(int) TYPE]);
3539#include "builtin-types.def"
3540#undef DEF_PRIMITIVE_TYPE
3541#undef DEF_FUNCTION_TYPE_1
3542#undef DEF_FUNCTION_TYPE_2
3543#undef DEF_FUNCTION_TYPE_3
3544#undef DEF_FUNCTION_TYPE_4
3545#undef DEF_FUNCTION_TYPE_VAR_0
3546#undef DEF_FUNCTION_TYPE_VAR_1
3547#undef DEF_FUNCTION_TYPE_VAR_2
3548#undef DEF_FUNCTION_TYPE_VAR_3
2854#undef DEF_POINTER_TYPE
2855
3549#undef DEF_POINTER_TYPE
3550
2856#define DEF_BUILTIN(ENUM, NAME, CLASS, \
2857 TYPE, LIBTYPE, BOTH_P, FALLBACK_P, NONANSI_P) \
3551 if (!c_attrs_initialized)
3552 c_init_attributes ();
3553
3554#define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, \
3555 BOTH_P, FALLBACK_P, NONANSI_P, ATTRS) \
2858 if (NAME) \
2859 { \
2860 tree decl; \
2861 \
2862 if (strncmp (NAME, "__builtin_", strlen ("__builtin_")) != 0) \
2863 abort (); \
2864 \
2865 if (!BOTH_P) \
2866 decl = builtin_function (NAME, builtin_types[TYPE], ENUM, \
2867 CLASS, \
2868 (FALLBACK_P \
2869 ? (NAME + strlen ("__builtin_")) \
3556 if (NAME) \
3557 { \
3558 tree decl; \
3559 \
3560 if (strncmp (NAME, "__builtin_", strlen ("__builtin_")) != 0) \
3561 abort (); \
3562 \
3563 if (!BOTH_P) \
3564 decl = builtin_function (NAME, builtin_types[TYPE], ENUM, \
3565 CLASS, \
3566 (FALLBACK_P \
3567 ? (NAME + strlen ("__builtin_")) \
2870 : NULL)); \
3568 : NULL), \
3569 built_in_attributes[(int) ATTRS]); \
2871 else \
2872 decl = builtin_function_2 (NAME, \
2873 NAME + strlen ("__builtin_"), \
2874 builtin_types[TYPE], \
2875 builtin_types[LIBTYPE], \
2876 ENUM, \
2877 CLASS, \
2878 FALLBACK_P, \
2879 NONANSI_P, \
3570 else \
3571 decl = builtin_function_2 (NAME, \
3572 NAME + strlen ("__builtin_"), \
3573 builtin_types[TYPE], \
3574 builtin_types[LIBTYPE], \
3575 ENUM, \
3576 CLASS, \
3577 FALLBACK_P, \
3578 NONANSI_P, \
2880 /*noreturn_p=*/0); \
3579 built_in_attributes[(int) ATTRS]); \
2881 \
2882 built_in_decls[(int) ENUM] = decl; \
2883 }
2884#include "builtins.def"
2885#undef DEF_BUILTIN
2886
3580 \
3581 built_in_decls[(int) ENUM] = decl; \
3582 }
3583#include "builtins.def"
3584#undef DEF_BUILTIN
3585
2887 /* Declare _exit and _Exit just to mark them as non-returning. */
2888 builtin_function_2 (NULL, "_exit", NULL_TREE,
2889 builtin_types[BT_FN_VOID_INT],
2890 0, NOT_BUILT_IN, 0, 1, 1);
2891 builtin_function_2 (NULL, "_Exit", NULL_TREE,
2892 builtin_types[BT_FN_VOID_INT],
2893 0, NOT_BUILT_IN, 0, !flag_isoc99, 1);
3586 (*targetm.init_builtins) ();
2894
3587
2895 /* Declare these functions non-returning
2896 to avoid spurious "control drops through" warnings. */
2897 builtin_function_2 (NULL, "abort",
2898 NULL_TREE, ((c_language == clk_cplusplus)
2899 ? builtin_types[BT_FN_VOID]
2900 : builtin_types[BT_FN_VOID_VAR]),
2901 0, NOT_BUILT_IN, 0, 0, 1);
2902
2903 builtin_function_2 (NULL, "exit",
2904 NULL_TREE, ((c_language == clk_cplusplus)
2905 ? builtin_types[BT_FN_VOID_INT]
2906 : builtin_types[BT_FN_VOID_VAR]),
2907 0, NOT_BUILT_IN, 0, 0, 1);
2908
2909 main_identifier_node = get_identifier ("main");
3588 main_identifier_node = get_identifier ("main");
2910
2911 /* ??? Perhaps there's a better place to do this. But it is related
2912 to __builtin_va_arg, so it isn't that off-the-wall. */
2913 lang_type_promotes_to = simple_type_promotes_to;
2914}
2915
2916tree
2917build_va_arg (expr, type)
2918 tree expr, type;
2919{
2920 return build1 (VA_ARG_EXPR, type, expr);
2921}

--- 50 unchanged lines hidden (view full) ---

2972 is an __builtin_-prefixed name; NAME is the ordinary name; one or both
2973 of these may be NULL (though both being NULL is useless).
2974 BUILTIN_TYPE is the type of the __builtin_-prefixed function;
2975 TYPE is the type of the function with the ordinary name. These
2976 may differ if the ordinary name is declared with a looser type to avoid
2977 conflicts with headers. FUNCTION_CODE and CLASS are as for
2978 builtin_function. If LIBRARY_NAME_P is nonzero, NAME is passed as
2979 the LIBRARY_NAME parameter to builtin_function when declaring BUILTIN_NAME.
3589}
3590
3591tree
3592build_va_arg (expr, type)
3593 tree expr, type;
3594{
3595 return build1 (VA_ARG_EXPR, type, expr);
3596}

--- 50 unchanged lines hidden (view full) ---

3647 is an __builtin_-prefixed name; NAME is the ordinary name; one or both
3648 of these may be NULL (though both being NULL is useless).
3649 BUILTIN_TYPE is the type of the __builtin_-prefixed function;
3650 TYPE is the type of the function with the ordinary name. These
3651 may differ if the ordinary name is declared with a looser type to avoid
3652 conflicts with headers. FUNCTION_CODE and CLASS are as for
3653 builtin_function. If LIBRARY_NAME_P is nonzero, NAME is passed as
3654 the LIBRARY_NAME parameter to builtin_function when declaring BUILTIN_NAME.
2980 If NONANSI_P is nonzero, the name NAME is treated as a non-ANSI name; if
2981 NORETURN_P is nonzero, the function is marked as non-returning.
3655 If NONANSI_P is nonzero, the name NAME is treated as a non-ANSI name;
3656 ATTRS is the tree list representing the builtin's function attributes.
2982 Returns the declaration of BUILTIN_NAME, if any, otherwise
2983 the declaration of NAME. Does not declare NAME if flag_no_builtin,
2984 or if NONANSI_P and flag_no_nonansi_builtin. */
2985
2986static tree
2987builtin_function_2 (builtin_name, name, builtin_type, type, function_code,
3657 Returns the declaration of BUILTIN_NAME, if any, otherwise
3658 the declaration of NAME. Does not declare NAME if flag_no_builtin,
3659 or if NONANSI_P and flag_no_nonansi_builtin. */
3660
3661static tree
3662builtin_function_2 (builtin_name, name, builtin_type, type, function_code,
2988 class, library_name_p, nonansi_p, noreturn_p)
3663 class, library_name_p, nonansi_p, attrs)
2989 const char *builtin_name;
2990 const char *name;
2991 tree builtin_type;
2992 tree type;
2993 int function_code;
2994 enum built_in_class class;
2995 int library_name_p;
2996 int nonansi_p;
3664 const char *builtin_name;
3665 const char *name;
3666 tree builtin_type;
3667 tree type;
3668 int function_code;
3669 enum built_in_class class;
3670 int library_name_p;
3671 int nonansi_p;
2997 int noreturn_p;
3672 tree attrs;
2998{
2999 tree bdecl = NULL_TREE;
3000 tree decl = NULL_TREE;
3001 if (builtin_name != 0)
3002 {
3003 bdecl = builtin_function (builtin_name, builtin_type, function_code,
3673{
3674 tree bdecl = NULL_TREE;
3675 tree decl = NULL_TREE;
3676 if (builtin_name != 0)
3677 {
3678 bdecl = builtin_function (builtin_name, builtin_type, function_code,
3004 class, library_name_p ? name : NULL);
3005 if (noreturn_p)
3006 {
3007 TREE_THIS_VOLATILE (bdecl) = 1;
3008 TREE_SIDE_EFFECTS (bdecl) = 1;
3009 }
3679 class, library_name_p ? name : NULL,
3680 attrs);
3010 }
3011 if (name != 0 && !flag_no_builtin && !builtin_function_disabled_p (name)
3012 && !(nonansi_p && flag_no_nonansi_builtin))
3013 {
3681 }
3682 if (name != 0 && !flag_no_builtin && !builtin_function_disabled_p (name)
3683 && !(nonansi_p && flag_no_nonansi_builtin))
3684 {
3014 decl = builtin_function (name, type, function_code, class, NULL);
3685 decl = builtin_function (name, type, function_code, class, NULL,
3686 attrs);
3015 if (nonansi_p)
3016 DECL_BUILT_IN_NONANSI (decl) = 1;
3687 if (nonansi_p)
3688 DECL_BUILT_IN_NONANSI (decl) = 1;
3017 if (noreturn_p)
3018 {
3019 TREE_THIS_VOLATILE (decl) = 1;
3020 TREE_SIDE_EFFECTS (decl) = 1;
3021 }
3022 }
3023 return (bdecl != 0 ? bdecl : decl);
3024}
3025
3026/* Nonzero if the type T promotes to int. This is (nearly) the
3027 integral promotions defined in ISO C99 6.3.1.1/2. */
3028
3029bool

--- 19 unchanged lines hidden (view full) ---

3049 case BOOLEAN_TYPE:
3050 return 1;
3051
3052 default:
3053 return 0;
3054 }
3055}
3056
3689 }
3690 return (bdecl != 0 ? bdecl : decl);
3691}
3692
3693/* Nonzero if the type T promotes to int. This is (nearly) the
3694 integral promotions defined in ISO C99 6.3.1.1/2. */
3695
3696bool

--- 19 unchanged lines hidden (view full) ---

3716 case BOOLEAN_TYPE:
3717 return 1;
3718
3719 default:
3720 return 0;
3721 }
3722}
3723
3057/* Given a type, apply default promotions wrt unnamed function arguments
3058 and return the new type. Return NULL_TREE if no change. */
3059/* ??? There is a function of the same name in the C++ front end that
3060 does something similar, but is more thorough and does not return NULL
3061 if no change. We could perhaps share code, but it would make the
3062 self_promoting_type property harder to identify. */
3063
3064tree
3065simple_type_promotes_to (type)
3066 tree type;
3067{
3068 if (TYPE_MAIN_VARIANT (type) == float_type_node)
3069 return double_type_node;
3070
3071 if (c_promoting_integer_type_p (type))
3072 {
3073 /* Traditionally, unsignedness is preserved in default promotions.
3074 Also preserve unsignedness if not really getting any wider. */
3075 if (TREE_UNSIGNED (type)
3076 && (flag_traditional
3077 || TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)))
3078 return unsigned_type_node;
3079 return integer_type_node;
3080 }
3081
3082 return NULL_TREE;
3083}
3084
3085/* Return 1 if PARMS specifies a fixed number of parameters
3086 and none of their types is affected by default promotions. */
3087
3088int
3089self_promoting_args_p (parms)
3090 tree parms;
3091{
3092 tree t;

--- 24 unchanged lines hidden (view full) ---

3117 tree type;
3118{
3119 while (TREE_CODE (type) == ARRAY_TYPE)
3120 type = TREE_TYPE (type);
3121
3122 return type;
3123}
3124
3724/* Return 1 if PARMS specifies a fixed number of parameters
3725 and none of their types is affected by default promotions. */
3726
3727int
3728self_promoting_args_p (parms)
3729 tree parms;
3730{
3731 tree t;

--- 24 unchanged lines hidden (view full) ---

3756 tree type;
3757{
3758 while (TREE_CODE (type) == ARRAY_TYPE)
3759 type = TREE_TYPE (type);
3760
3761 return type;
3762}
3763
3764static tree expand_unordered_cmp PARAMS ((tree, tree, enum tree_code,
3765 enum tree_code));
3766
3767/* Expand a call to an unordered comparison function such as
3768 __builtin_isgreater(). FUNCTION is the function's declaration and
3769 PARAMS a list of the values passed. For __builtin_isunordered(),
3770 UNORDERED_CODE is UNORDERED_EXPR and ORDERED_CODE is NOP_EXPR. In
3771 other cases, UNORDERED_CODE and ORDERED_CODE are comparison codes
3772 that give the opposite of the desired result. UNORDERED_CODE is
3773 used for modes that can hold NaNs and ORDERED_CODE is used for the
3774 rest. */
3775
3776static tree
3777expand_unordered_cmp (function, params, unordered_code, ordered_code)
3778 tree function, params;
3779 enum tree_code unordered_code, ordered_code;
3780{
3781 tree arg0, arg1, type;
3782 enum tree_code code0, code1;
3783
3784 /* Check that we have exactly two arguments. */
3785 if (params == 0 || TREE_CHAIN (params) == 0)
3786 {
3787 error ("too few arguments to function `%s'",
3788 IDENTIFIER_POINTER (DECL_NAME (function)));
3789 return error_mark_node;
3790 }
3791 else if (TREE_CHAIN (TREE_CHAIN (params)) != 0)
3792 {
3793 error ("too many arguments to function `%s'",
3794 IDENTIFIER_POINTER (DECL_NAME (function)));
3795 return error_mark_node;
3796 }
3797
3798 arg0 = TREE_VALUE (params);
3799 arg1 = TREE_VALUE (TREE_CHAIN (params));
3800
3801 code0 = TREE_CODE (TREE_TYPE (arg0));
3802 code1 = TREE_CODE (TREE_TYPE (arg1));
3803
3804 /* Make sure that the arguments have a common type of REAL. */
3805 type = 0;
3806 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
3807 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
3808 type = common_type (TREE_TYPE (arg0), TREE_TYPE (arg1));
3809
3810 if (type == 0 || TREE_CODE (type) != REAL_TYPE)
3811 {
3812 error ("non-floating-point argument to function `%s'",
3813 IDENTIFIER_POINTER (DECL_NAME (function)));
3814 return error_mark_node;
3815 }
3816
3817 if (unordered_code == UNORDERED_EXPR)
3818 {
3819 if (MODE_HAS_NANS (TYPE_MODE (type)))
3820 return build_binary_op (unordered_code,
3821 convert (type, arg0),
3822 convert (type, arg1),
3823 0);
3824 else
3825 return integer_zero_node;
3826 }
3827
3828 return build_unary_op (TRUTH_NOT_EXPR,
3829 build_binary_op (MODE_HAS_NANS (TYPE_MODE (type))
3830 ? unordered_code
3831 : ordered_code,
3832 convert (type, arg0),
3833 convert (type, arg1),
3834 0),
3835 0);
3836}
3837
3838
3125/* Recognize certain built-in functions so we can make tree-codes
3126 other than CALL_EXPR. We do this when it enables fold-const.c
3127 to do something useful. */
3128/* ??? By rights this should go in builtins.c, but only C and C++
3129 implement build_{binary,unary}_op. Not exactly sure what bits
3130 of functionality are actually needed from those functions, or
3131 where the similar functionality exists in the other front ends. */
3132
3133tree
3134expand_tree_builtin (function, params, coerced_params)
3135 tree function, params, coerced_params;
3136{
3839/* Recognize certain built-in functions so we can make tree-codes
3840 other than CALL_EXPR. We do this when it enables fold-const.c
3841 to do something useful. */
3842/* ??? By rights this should go in builtins.c, but only C and C++
3843 implement build_{binary,unary}_op. Not exactly sure what bits
3844 of functionality are actually needed from those functions, or
3845 where the similar functionality exists in the other front ends. */
3846
3847tree
3848expand_tree_builtin (function, params, coerced_params)
3849 tree function, params, coerced_params;
3850{
3137 enum tree_code code;
3138
3139 if (DECL_BUILT_IN_CLASS (function) != BUILT_IN_NORMAL)
3140 return NULL_TREE;
3141
3142 switch (DECL_FUNCTION_CODE (function))
3143 {
3144 case BUILT_IN_ABS:
3145 case BUILT_IN_LABS:
3146 case BUILT_IN_LLABS:

--- 22 unchanged lines hidden (view full) ---

3169 case BUILT_IN_CIMAG:
3170 case BUILT_IN_CIMAGF:
3171 case BUILT_IN_CIMAGL:
3172 if (coerced_params == 0)
3173 return integer_zero_node;
3174 return build_unary_op (IMAGPART_EXPR, TREE_VALUE (coerced_params), 0);
3175
3176 case BUILT_IN_ISGREATER:
3851 if (DECL_BUILT_IN_CLASS (function) != BUILT_IN_NORMAL)
3852 return NULL_TREE;
3853
3854 switch (DECL_FUNCTION_CODE (function))
3855 {
3856 case BUILT_IN_ABS:
3857 case BUILT_IN_LABS:
3858 case BUILT_IN_LLABS:

--- 22 unchanged lines hidden (view full) ---

3881 case BUILT_IN_CIMAG:
3882 case BUILT_IN_CIMAGF:
3883 case BUILT_IN_CIMAGL:
3884 if (coerced_params == 0)
3885 return integer_zero_node;
3886 return build_unary_op (IMAGPART_EXPR, TREE_VALUE (coerced_params), 0);
3887
3888 case BUILT_IN_ISGREATER:
3177 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT)
3178 code = UNLE_EXPR;
3179 else
3180 code = LE_EXPR;
3181 goto unordered_cmp;
3889 return expand_unordered_cmp (function, params, UNLE_EXPR, LE_EXPR);
3182
3183 case BUILT_IN_ISGREATEREQUAL:
3890
3891 case BUILT_IN_ISGREATEREQUAL:
3184 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT)
3185 code = UNLT_EXPR;
3186 else
3187 code = LT_EXPR;
3188 goto unordered_cmp;
3892 return expand_unordered_cmp (function, params, UNLT_EXPR, LT_EXPR);
3189
3190 case BUILT_IN_ISLESS:
3893
3894 case BUILT_IN_ISLESS:
3191 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT)
3192 code = UNGE_EXPR;
3193 else
3194 code = GE_EXPR;
3195 goto unordered_cmp;
3895 return expand_unordered_cmp (function, params, UNGE_EXPR, GE_EXPR);
3196
3197 case BUILT_IN_ISLESSEQUAL:
3896
3897 case BUILT_IN_ISLESSEQUAL:
3198 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT)
3199 code = UNGT_EXPR;
3200 else
3201 code = GT_EXPR;
3202 goto unordered_cmp;
3898 return expand_unordered_cmp (function, params, UNGT_EXPR, GT_EXPR);
3203
3204 case BUILT_IN_ISLESSGREATER:
3899
3900 case BUILT_IN_ISLESSGREATER:
3205 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT)
3206 code = UNEQ_EXPR;
3207 else
3208 code = EQ_EXPR;
3209 goto unordered_cmp;
3901 return expand_unordered_cmp (function, params, UNEQ_EXPR, EQ_EXPR);
3210
3211 case BUILT_IN_ISUNORDERED:
3902
3903 case BUILT_IN_ISUNORDERED:
3212 if (TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT)
3213 return integer_zero_node;
3214 code = UNORDERED_EXPR;
3215 goto unordered_cmp;
3904 return expand_unordered_cmp (function, params, UNORDERED_EXPR, NOP_EXPR);
3216
3905
3217 unordered_cmp:
3218 {
3219 tree arg0, arg1;
3220
3221 if (params == 0
3222 || TREE_CHAIN (params) == 0)
3223 {
3224 error ("too few arguments to function `%s'",
3225 IDENTIFIER_POINTER (DECL_NAME (function)));
3226 return error_mark_node;
3227 }
3228 else if (TREE_CHAIN (TREE_CHAIN (params)) != 0)
3229 {
3230 error ("too many arguments to function `%s'",
3231 IDENTIFIER_POINTER (DECL_NAME (function)));
3232 return error_mark_node;
3233 }
3234
3235 arg0 = TREE_VALUE (params);
3236 arg1 = TREE_VALUE (TREE_CHAIN (params));
3237 arg0 = build_binary_op (code, arg0, arg1, 0);
3238 if (code != UNORDERED_EXPR)
3239 arg0 = build_unary_op (TRUTH_NOT_EXPR, arg0, 0);
3240 return arg0;
3241 }
3242 break;
3243
3244 default:
3245 break;
3246 }
3247
3248 return NULL_TREE;
3249}
3250
3906 default:
3907 break;
3908 }
3909
3910 return NULL_TREE;
3911}
3912
3251/* Returns non-zero if CODE is the code for a statement. */
3913/* Returns nonzero if CODE is the code for a statement. */
3252
3253int
3254statement_code_p (code)
3255 enum tree_code code;
3256{
3257 switch (code)
3258 {
3259 case CLEANUP_STMT:

--- 301 unchanged lines hidden (view full) ---

3561 /* The current function in not necessarily uninlinable.
3562 Computed gotos are incompatible with inlining, but the value
3563 here could be used only in a diagnostic, for example. */
3564 }
3565
3566 return result;
3567}
3568
3914
3915int
3916statement_code_p (code)
3917 enum tree_code code;
3918{
3919 switch (code)
3920 {
3921 case CLEANUP_STMT:

--- 301 unchanged lines hidden (view full) ---

4223 /* The current function in not necessarily uninlinable.
4224 Computed gotos are incompatible with inlining, but the value
4225 here could be used only in a diagnostic, for example. */
4226 }
4227
4228 return result;
4229}
4230
3569/* Mark P (a stmt_tree) for GC. The use of a `void *' for the
3570 parameter allows this function to be used as a GC-marking
3571 function. */
3572
3573void
3574mark_stmt_tree (p)
3575 void *p;
3576{
3577 stmt_tree st = (stmt_tree) p;
3578
3579 ggc_mark_tree (st->x_last_stmt);
3580 ggc_mark_tree (st->x_last_expr_type);
3581}
3582
3583/* Mark LD for GC. */
3584
3585void
3586c_mark_lang_decl (c)
3587 struct c_lang_decl *c ATTRIBUTE_UNUSED;
3588{
3589}
3590
3591/* Mark F for GC. */
3592
3593void
3594mark_c_language_function (f)
3595 struct language_function *f;
3596{
3597 if (!f)
3598 return;
3599
3600 mark_stmt_tree (&f->x_stmt_tree);
3601 ggc_mark_tree (f->x_scope_stmt_stack);
3602}
3603
3604/* Hook used by expand_expr to expand language-specific tree codes. */
3605
3606rtx
3607c_expand_expr (exp, target, tmode, modifier)
3608 tree exp;
3609 rtx target;
3610 enum machine_mode tmode;
4231/* Hook used by expand_expr to expand language-specific tree codes. */
4232
4233rtx
4234c_expand_expr (exp, target, tmode, modifier)
4235 tree exp;
4236 rtx target;
4237 enum machine_mode tmode;
3611 enum expand_modifier modifier;
4238 int modifier; /* Actually enum_modifier. */
3612{
3613 switch (TREE_CODE (exp))
3614 {
3615 case STMT_EXPR:
3616 {
3617 tree rtl_expr;
3618 rtx result;
3619 bool preserve_result = false;

--- 124 unchanged lines hidden (view full) ---

3744
3745 /* Assume everything else is safe. */
3746 return 1;
3747}
3748
3749/* Hook used by unsafe_for_reeval to handle language-specific tree codes. */
3750
3751int
4239{
4240 switch (TREE_CODE (exp))
4241 {
4242 case STMT_EXPR:
4243 {
4244 tree rtl_expr;
4245 rtx result;
4246 bool preserve_result = false;

--- 124 unchanged lines hidden (view full) ---

4371
4372 /* Assume everything else is safe. */
4373 return 1;
4374}
4375
4376/* Hook used by unsafe_for_reeval to handle language-specific tree codes. */
4377
4378int
3752c_unsafe_for_reeval (exp)
4379c_common_unsafe_for_reeval (exp)
3753 tree exp;
3754{
3755 /* Statement expressions may not be reevaluated, likewise compound
3756 literals. */
3757 if (TREE_CODE (exp) == STMT_EXPR
3758 || TREE_CODE (exp) == COMPOUND_LITERAL_EXPR)
3759 return 2;
3760

--- 8 unchanged lines hidden (view full) ---

3769 tree exp;
3770{
3771 if (TREE_CODE (exp) == COMPOUND_LITERAL_EXPR
3772 && TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (exp)))
3773 return 1;
3774 return 0;
3775}
3776
4380 tree exp;
4381{
4382 /* Statement expressions may not be reevaluated, likewise compound
4383 literals. */
4384 if (TREE_CODE (exp) == STMT_EXPR
4385 || TREE_CODE (exp) == COMPOUND_LITERAL_EXPR)
4386 return 2;
4387

--- 8 unchanged lines hidden (view full) ---

4396 tree exp;
4397{
4398 if (TREE_CODE (exp) == COMPOUND_LITERAL_EXPR
4399 && TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (exp)))
4400 return 1;
4401 return 0;
4402}
4403
3777/* Tree code classes. */
3778
3779#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
3780
3781static const char c_tree_code_type[] = {
3782 'x',
3783#include "c-common.def"
3784};
3785#undef DEFTREECODE
3786
3787/* Table indexed by tree code giving number of expression
3788 operands beyond the fixed part of the node structure.
3789 Not used for types or decls. */
3790
3791#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
3792
3793static const int c_tree_code_length[] = {
3794 0,
3795#include "c-common.def"
3796};
3797#undef DEFTREECODE
3798
3799/* Names of tree components.
3800 Used for printing out the tree and error messages. */
3801#define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
3802
3803static const char *const c_tree_code_name[] = {
3804 "@@dummy",
3805#include "c-common.def"
3806};
3807#undef DEFTREECODE
3808
3809/* Adds the tree codes specific to the C front end to the list of all
3810 tree codes. */
3811
3812void
3813add_c_tree_codes ()
3814{
3815 memcpy (tree_code_type + (int) LAST_AND_UNUSED_TREE_CODE,
3816 c_tree_code_type,
3817 (int) LAST_C_TREE_CODE - (int) LAST_AND_UNUSED_TREE_CODE);
3818 memcpy (tree_code_length + (int) LAST_AND_UNUSED_TREE_CODE,
3819 c_tree_code_length,
3820 (LAST_C_TREE_CODE - (int) LAST_AND_UNUSED_TREE_CODE) * sizeof (int));
3821 memcpy (tree_code_name + (int) LAST_AND_UNUSED_TREE_CODE,
3822 c_tree_code_name,
3823 (LAST_C_TREE_CODE - (int) LAST_AND_UNUSED_TREE_CODE) * sizeof (char *));
3824 lang_unsafe_for_reeval = c_unsafe_for_reeval;
3825}
3826
3827#define CALLED_AS_BUILT_IN(NODE) \
3828 (!strncmp (IDENTIFIER_POINTER (DECL_NAME (NODE)), "__builtin_", 10))
3829
3830static rtx
3831c_expand_builtin (exp, target, tmode, modifier)
3832 tree exp;
3833 rtx target;
3834 enum machine_mode tmode;

--- 172 unchanged lines hidden (view full) ---

4007 {
4008 /* Create a NULL-terminated string that's one char shorter
4009 than the original, stripping off the trailing '\n'. */
4010 const int newlen = TREE_STRING_LENGTH (stripped_string) - 1;
4011 char *newstr = (char *) alloca (newlen);
4012 memcpy (newstr, TREE_STRING_POINTER (stripped_string), newlen - 1);
4013 newstr[newlen - 1] = 0;
4014
4404#define CALLED_AS_BUILT_IN(NODE) \
4405 (!strncmp (IDENTIFIER_POINTER (DECL_NAME (NODE)), "__builtin_", 10))
4406
4407static rtx
4408c_expand_builtin (exp, target, tmode, modifier)
4409 tree exp;
4410 rtx target;
4411 enum machine_mode tmode;

--- 172 unchanged lines hidden (view full) ---

4584 {
4585 /* Create a NULL-terminated string that's one char shorter
4586 than the original, stripping off the trailing '\n'. */
4587 const int newlen = TREE_STRING_LENGTH (stripped_string) - 1;
4588 char *newstr = (char *) alloca (newlen);
4589 memcpy (newstr, TREE_STRING_POINTER (stripped_string), newlen - 1);
4590 newstr[newlen - 1] = 0;
4591
4015 arglist = combine_strings (build_string (newlen, newstr));
4592 arglist = fix_string_type (build_string (newlen, newstr));
4016 arglist = build_tree_list (NULL_TREE, arglist);
4017 fn = fn_puts;
4018 }
4019 else
4020 /* We'd like to arrange to call fputs(string) here, but we
4021 need stdout and don't have a way to get it ... yet. */
4022 return 0;
4023 }

--- 122 unchanged lines hidden (view full) ---

4146 break;
4147 default:
4148 abort ();
4149 }
4150 TREE_SIDE_EFFECTS (val) = 1;
4151 return val;
4152}
4153
4593 arglist = build_tree_list (NULL_TREE, arglist);
4594 fn = fn_puts;
4595 }
4596 else
4597 /* We'd like to arrange to call fputs(string) here, but we
4598 need stdout and don't have a way to get it ... yet. */
4599 return 0;
4600 }

--- 122 unchanged lines hidden (view full) ---

4723 break;
4724 default:
4725 abort ();
4726 }
4727 TREE_SIDE_EFFECTS (val) = 1;
4728 return val;
4729}
4730
4154/* Handle C and C++ default attributes. */
4731/* Define NAME with value TYPE precision. */
4732static void
4733builtin_define_type_precision (name, type)
4734 const char *name;
4735 tree type;
4736{
4737 builtin_define_with_int_value (name, TYPE_PRECISION (type));
4738}
4155
4739
4156enum built_in_attribute
4740/* Define the float.h constants for TYPE using NAME_PREFIX and FP_SUFFIX. */
4741static void
4742builtin_define_float_constants (name_prefix, fp_suffix, type)
4743 const char *name_prefix;
4744 const char *fp_suffix;
4745 tree type;
4157{
4746{
4158#define DEF_ATTR_NULL_TREE(ENUM) ENUM,
4159#define DEF_ATTR_INT(ENUM, VALUE) ENUM,
4160#define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
4161#define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
4162#define DEF_FN_ATTR(NAME, ATTRS, PREDICATE) /* No entry needed in enum. */
4163#include "builtin-attrs.def"
4164#undef DEF_ATTR_NULL_TREE
4165#undef DEF_ATTR_INT
4166#undef DEF_ATTR_IDENT
4167#undef DEF_ATTR_TREE_LIST
4168#undef DEF_FN_ATTR
4169 ATTR_LAST
4170};
4747 /* Used to convert radix-based values to base 10 values in several cases.
4171
4748
4172static tree built_in_attributes[(int) ATTR_LAST];
4749 In the max_exp -> max_10_exp conversion for 128-bit IEEE, we need at
4750 least 6 significant digits for correct results. Using the fraction
4751 formed by (log(2)*1e6)/(log(10)*1e6) overflows a 32-bit integer as an
4752 intermediate; perhaps someone can find a better approximation, in the
4753 mean time, I suspect using doubles won't harm the bootstrap here. */
4173
4754
4174static bool c_attrs_initialized = false;
4755 const double log10_2 = .30102999566398119521;
4756 double log10_b;
4757 const struct real_format *fmt;
4175
4758
4176static void c_init_attributes PARAMS ((void));
4759 char name[64], buf[128];
4760 int dig, min_10_exp, max_10_exp;
4761 int decimal_dig;
4177
4762
4178/* Common initialization before parsing options. */
4763 fmt = real_format_for_mode[TYPE_MODE (type) - QFmode];
4764
4765 /* The radix of the exponent representation. */
4766 if (type == float_type_node)
4767 builtin_define_with_int_value ("__FLT_RADIX__", fmt->b);
4768 log10_b = log10_2 * fmt->log2_b;
4769
4770 /* The number of radix digits, p, in the floating-point significand. */
4771 sprintf (name, "__%s_MANT_DIG__", name_prefix);
4772 builtin_define_with_int_value (name, fmt->p);
4773
4774 /* The number of decimal digits, q, such that any floating-point number
4775 with q decimal digits can be rounded into a floating-point number with
4776 p radix b digits and back again without change to the q decimal digits,
4777
4778 p log10 b if b is a power of 10
4779 floor((p - 1) log10 b) otherwise
4780 */
4781 dig = (fmt->p - 1) * log10_b;
4782 sprintf (name, "__%s_DIG__", name_prefix);
4783 builtin_define_with_int_value (name, dig);
4784
4785 /* The minimum negative int x such that b**(x-1) is a normalized float. */
4786 sprintf (name, "__%s_MIN_EXP__", name_prefix);
4787 sprintf (buf, "(%d)", fmt->emin);
4788 builtin_define_with_value (name, buf, 0);
4789
4790 /* The minimum negative int x such that 10**x is a normalized float,
4791
4792 ceil (log10 (b ** (emin - 1)))
4793 = ceil (log10 (b) * (emin - 1))
4794
4795 Recall that emin is negative, so the integer truncation calculates
4796 the ceiling, not the floor, in this case. */
4797 min_10_exp = (fmt->emin - 1) * log10_b;
4798 sprintf (name, "__%s_MIN_10_EXP__", name_prefix);
4799 sprintf (buf, "(%d)", min_10_exp);
4800 builtin_define_with_value (name, buf, 0);
4801
4802 /* The maximum int x such that b**(x-1) is a representable float. */
4803 sprintf (name, "__%s_MAX_EXP__", name_prefix);
4804 builtin_define_with_int_value (name, fmt->emax);
4805
4806 /* The maximum int x such that 10**x is in the range of representable
4807 finite floating-point numbers,
4808
4809 floor (log10((1 - b**-p) * b**emax))
4810 = floor (log10(1 - b**-p) + log10(b**emax))
4811 = floor (log10(1 - b**-p) + log10(b)*emax)
4812
4813 The safest thing to do here is to just compute this number. But since
4814 we don't link cc1 with libm, we cannot. We could implement log10 here
4815 a series expansion, but that seems too much effort because:
4816
4817 Note that the first term, for all extant p, is a number exceedingly close
4818 to zero, but slightly negative. Note that the second term is an integer
4819 scaling an irrational number, and that because of the floor we are only
4820 interested in its integral portion.
4821
4822 In order for the first term to have any effect on the integral portion
4823 of the second term, the second term has to be exceedingly close to an
4824 integer itself (e.g. 123.000000000001 or something). Getting a result
4825 that close to an integer requires that the irrational multiplicand have
4826 a long series of zeros in its expansion, which doesn't occur in the
4827 first 20 digits or so of log10(b).
4828
4829 Hand-waving aside, crunching all of the sets of constants above by hand
4830 does not yield a case for which the first term is significant, which
4831 in the end is all that matters. */
4832 max_10_exp = fmt->emax * log10_b;
4833 sprintf (name, "__%s_MAX_10_EXP__", name_prefix);
4834 builtin_define_with_int_value (name, max_10_exp);
4835
4836 /* The number of decimal digits, n, such that any floating-point number
4837 can be rounded to n decimal digits and back again without change to
4838 the value.
4839
4840 p * log10(b) if b is a power of 10
4841 ceil(1 + p * log10(b)) otherwise
4842
4843 The only macro we care about is this number for the widest supported
4844 floating type, but we want this value for rendering constants below. */
4845 {
4846 double d_decimal_dig = 1 + fmt->p * log10_b;
4847 decimal_dig = d_decimal_dig;
4848 if (decimal_dig < d_decimal_dig)
4849 decimal_dig++;
4850 }
4851 if (type == long_double_type_node)
4852 builtin_define_with_int_value ("__DECIMAL_DIG__", decimal_dig);
4853
4854 /* Since, for the supported formats, B is always a power of 2, we
4855 construct the following numbers directly as a hexadecimal
4856 constants. */
4857
4858 /* The maximum representable finite floating-point number,
4859 (1 - b**-p) * b**emax */
4860 {
4861 int i, n;
4862 char *p;
4863
4864 strcpy (buf, "0x0.");
4865 n = fmt->p * fmt->log2_b;
4866 for (i = 0, p = buf + 4; i + 3 < n; i += 4)
4867 *p++ = 'f';
4868 if (i < n)
4869 *p++ = "08ce"[n - i];
4870 sprintf (p, "p%d", fmt->emax * fmt->log2_b);
4871 }
4872 sprintf (name, "__%s_MAX__", name_prefix);
4873 builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix);
4874
4875 /* The minimum normalized positive floating-point number,
4876 b**(emin-1). */
4877 sprintf (name, "__%s_MIN__", name_prefix);
4878 sprintf (buf, "0x1p%d", (fmt->emin - 1) * fmt->log2_b);
4879 builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix);
4880
4881 /* The difference between 1 and the least value greater than 1 that is
4882 representable in the given floating point type, b**(1-p). */
4883 sprintf (name, "__%s_EPSILON__", name_prefix);
4884 sprintf (buf, "0x1p%d", (1 - fmt->p) * fmt->log2_b);
4885 builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix);
4886
4887 /* For C++ std::numeric_limits<T>::denorm_min. The minimum denormalized
4888 positive floating-point number, b**(emin-p). Zero for formats that
4889 don't support denormals. */
4890 sprintf (name, "__%s_DENORM_MIN__", name_prefix);
4891 if (fmt->has_denorm)
4892 {
4893 sprintf (buf, "0x1p%d", (fmt->emin - fmt->p) * fmt->log2_b);
4894 builtin_define_with_hex_fp_value (name, type, decimal_dig,
4895 buf, fp_suffix);
4896 }
4897 else
4898 {
4899 sprintf (buf, "0.0%s", fp_suffix);
4900 builtin_define_with_value (name, buf, 0);
4901 }
4902}
4903
4904/* Hook that registers front end and target-specific built-ins. */
4179void
4905void
4180c_common_init_options (lang)
4181 enum c_language_kind lang;
4906cb_register_builtins (pfile)
4907 cpp_reader *pfile;
4182{
4908{
4183 c_language = lang;
4184 parse_in = cpp_create_reader (lang == clk_c ? CLK_GNUC89:
4185 lang == clk_cplusplus ? CLK_GNUCXX: CLK_OBJC);
4909 /* -undef turns off target-specific built-ins. */
4910 if (flag_undef)
4911 return;
4186
4912
4187 /* Mark as "unspecified" (see c_common_post_options). */
4188 flag_bounds_check = -1;
4913 if (c_language == clk_cplusplus)
4914 {
4915 if (SUPPORTS_ONE_ONLY)
4916 cpp_define (pfile, "__GXX_WEAK__=1");
4917 else
4918 cpp_define (pfile, "__GXX_WEAK__=0");
4919 if (warn_deprecated)
4920 cpp_define (pfile, "__DEPRECATED");
4921 }
4922 if (flag_exceptions)
4923 cpp_define (pfile, "__EXCEPTIONS");
4924
4925 /* represents the C++ ABI version, always defined so it can be used while
4926 preprocessing C and assembler. */
4927 cpp_define (pfile, "__GXX_ABI_VERSION=102");
4928
4929 /* libgcc needs to know this. */
4930 if (USING_SJLJ_EXCEPTIONS)
4931 cpp_define (pfile, "__USING_SJLJ_EXCEPTIONS__");
4932
4933 /* stddef.h needs to know these. */
4934 builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE, 0);
4935 builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE, 0);
4936 builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE, 0);
4937 builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE, 0);
4938
4939 /* limits.h needs to know these. */
4940 builtin_define_type_max ("__SCHAR_MAX__", signed_char_type_node, 0);
4941 builtin_define_type_max ("__SHRT_MAX__", short_integer_type_node, 0);
4942 builtin_define_type_max ("__INT_MAX__", integer_type_node, 0);
4943 builtin_define_type_max ("__LONG_MAX__", long_integer_type_node, 1);
4944 builtin_define_type_max ("__LONG_LONG_MAX__", long_long_integer_type_node, 2);
4945 builtin_define_type_max ("__WCHAR_MAX__", wchar_type_node, 0);
4946
4947 builtin_define_type_precision ("__CHAR_BIT__", char_type_node);
4948
4949 /* float.h needs to know these. */
4950
4951 builtin_define_with_int_value ("__FLT_EVAL_METHOD__",
4952 TARGET_FLT_EVAL_METHOD);
4953
4954 builtin_define_float_constants ("FLT", "F", float_type_node);
4955 builtin_define_float_constants ("DBL", "", double_type_node);
4956 builtin_define_float_constants ("LDBL", "L", long_double_type_node);
4957
4958 /* For use in assembly language. */
4959 builtin_define_with_value ("__REGISTER_PREFIX__", REGISTER_PREFIX, 0);
4960 builtin_define_with_value ("__USER_LABEL_PREFIX__", user_label_prefix, 0);
4961
4962 /* Misc. */
4963 builtin_define_with_value ("__VERSION__", version_string, 1);
4964
4965 /* Other target-independent built-ins determined by command-line
4966 options. */
4967 if (optimize_size)
4968 cpp_define (pfile, "__OPTIMIZE_SIZE__");
4969 if (optimize)
4970 cpp_define (pfile, "__OPTIMIZE__");
4971
4972 if (flag_hosted)
4973 cpp_define (pfile, "__STDC_HOSTED__=1");
4974 else
4975 cpp_define (pfile, "__STDC_HOSTED__=0");
4976
4977 if (fast_math_flags_set_p ())
4978 cpp_define (pfile, "__FAST_MATH__");
4979 if (flag_really_no_inline)
4980 cpp_define (pfile, "__NO_INLINE__");
4981 if (flag_signaling_nans)
4982 cpp_define (pfile, "__SUPPORT_SNAN__");
4983 if (flag_finite_math_only)
4984 cpp_define (pfile, "__FINITE_MATH_ONLY__=1");
4985 else
4986 cpp_define (pfile, "__FINITE_MATH_ONLY__=0");
4987
4988 if (flag_iso)
4989 cpp_define (pfile, "__STRICT_ANSI__");
4990
4991 if (!flag_signed_char)
4992 cpp_define (pfile, "__CHAR_UNSIGNED__");
4993
4994 if (c_language == clk_cplusplus && TREE_UNSIGNED (wchar_type_node))
4995 cpp_define (pfile, "__WCHAR_UNSIGNED__");
4996
4997 /* Make the choice of ObjC runtime visible to source code. */
4998 if (flag_objc && flag_next_runtime)
4999 cpp_define (pfile, "__NEXT_RUNTIME__");
5000
5001 /* A straightforward target hook doesn't work, because of problems
5002 linking that hook's body when part of non-C front ends. */
5003# define preprocessing_asm_p() (cpp_get_options (pfile)->lang == CLK_ASM)
5004# define preprocessing_trad_p() (cpp_get_options (pfile)->traditional)
5005# define builtin_define(TXT) cpp_define (pfile, TXT)
5006# define builtin_assert(TXT) cpp_assert (pfile, TXT)
5007 TARGET_CPU_CPP_BUILTINS ();
5008 TARGET_OS_CPP_BUILTINS ();
4189}
4190
5009}
5010
4191/* Post-switch processing. */
5011/* Pass an object-like macro. If it doesn't lie in the user's
5012 namespace, defines it unconditionally. Otherwise define a version
5013 with two leading underscores, and another version with two leading
5014 and trailing underscores, and define the original only if an ISO
5015 standard was not nominated.
5016
5017 e.g. passing "unix" defines "__unix", "__unix__" and possibly
5018 "unix". Passing "_mips" defines "__mips", "__mips__" and possibly
5019 "_mips". */
4192void
5020void
4193c_common_post_options ()
5021builtin_define_std (macro)
5022 const char *macro;
4194{
5023{
4195 cpp_post_options (parse_in);
5024 size_t len = strlen (macro);
5025 char *buff = alloca (len + 5);
5026 char *p = buff + 2;
5027 char *q = p + len;
4196
5028
4197 flag_inline_trees = 1;
5029 /* prepend __ (or maybe just _) if in user's namespace. */
5030 memcpy (p, macro, len + 1);
5031 if (!( *p == '_' && (p[1] == '_' || ISUPPER (p[1]))))
5032 {
5033 if (*p != '_')
5034 *--p = '_';
5035 if (p[1] != '_')
5036 *--p = '_';
5037 }
5038 cpp_define (parse_in, p);
4198
5039
4199 /* Use tree inlining if possible. Function instrumentation is only
4200 done in the RTL level, so we disable tree inlining. */
4201 if (! flag_instrument_function_entry_exit)
5040 /* If it was in user's namespace... */
5041 if (p != buff + 2)
4202 {
5042 {
4203 if (!flag_no_inline)
4204 flag_no_inline = 1;
4205 if (flag_inline_functions)
4206 {
4207 flag_inline_trees = 2;
4208 flag_inline_functions = 0;
4209 }
5043 /* Define the macro with leading and following __. */
5044 if (q[-1] != '_')
5045 *q++ = '_';
5046 if (q[-2] != '_')
5047 *q++ = '_';
5048 *q = '\0';
5049 cpp_define (parse_in, p);
5050
5051 /* Finally, define the original macro if permitted. */
5052 if (!flag_iso)
5053 cpp_define (parse_in, macro);
4210 }
5054 }
5055}
4211
5056
4212 /* If still "unspecified", make it match -fbounded-pointers. */
4213 if (flag_bounds_check == -1)
4214 flag_bounds_check = flag_bounded_pointers;
5057/* Pass an object-like macro and a value to define it to. The third
5058 parameter says whether or not to turn the value into a string
5059 constant. */
5060static void
5061builtin_define_with_value (macro, expansion, is_str)
5062 const char *macro;
5063 const char *expansion;
5064 int is_str;
5065{
5066 char *buf;
5067 size_t mlen = strlen (macro);
5068 size_t elen = strlen (expansion);
5069 size_t extra = 2; /* space for an = and a NUL */
4215
5070
4216 /* Special format checking options don't work without -Wformat; warn if
4217 they are used. */
4218 if (warn_format_y2k && !warn_format)
4219 warning ("-Wformat-y2k ignored without -Wformat");
4220 if (warn_format_extra_args && !warn_format)
4221 warning ("-Wformat-extra-args ignored without -Wformat");
4222 if (warn_format_nonliteral && !warn_format)
4223 warning ("-Wformat-nonliteral ignored without -Wformat");
4224 if (warn_format_security && !warn_format)
4225 warning ("-Wformat-security ignored without -Wformat");
4226 if (warn_missing_format_attribute && !warn_format)
4227 warning ("-Wmissing-format-attribute ignored without -Wformat");
5071 if (is_str)
5072 extra += 2; /* space for two quote marks */
4228
5073
4229 /* If an error has occurred in cpplib, note it so we fail
4230 immediately. */
4231 errorcount += cpp_errors (parse_in);
5074 buf = alloca (mlen + elen + extra);
5075 if (is_str)
5076 sprintf (buf, "%s=\"%s\"", macro, expansion);
5077 else
5078 sprintf (buf, "%s=%s", macro, expansion);
5079
5080 cpp_define (parse_in, buf);
4232}
4233
5081}
5082
4234/* Front end initialization common to C, ObjC and C++. */
4235const char *
4236c_common_init (filename)
4237 const char *filename;
5083/* Pass an object-like macro and an integer value to define it to. */
5084static void
5085builtin_define_with_int_value (macro, value)
5086 const char *macro;
5087 HOST_WIDE_INT value;
4238{
5088{
4239 /* Do this before initializing pragmas, as then cpplib's hash table
4240 has been set up. */
4241 filename = init_c_lex (filename);
5089 char *buf;
5090 size_t mlen = strlen (macro);
5091 size_t vlen = 18;
5092 size_t extra = 2; /* space for = and NUL. */
4242
5093
4243 init_pragma ();
5094 buf = alloca (mlen + vlen + extra);
5095 memcpy (buf, macro, mlen);
5096 buf[mlen] = '=';
5097 sprintf (buf + mlen + 1, HOST_WIDE_INT_PRINT_DEC, value);
4244
5098
4245 if (!c_attrs_initialized)
4246 c_init_attributes ();
5099 cpp_define (parse_in, buf);
5100}
4247
5101
4248 return filename;
5102/* Pass an object-like macro a hexadecimal floating-point value. */
5103static void
5104builtin_define_with_hex_fp_value (macro, type, digits, hex_str, fp_suffix)
5105 const char *macro;
5106 tree type ATTRIBUTE_UNUSED;
5107 int digits;
5108 const char *hex_str;
5109 const char *fp_suffix;
5110{
5111 REAL_VALUE_TYPE real;
5112 char dec_str[64], buf[256];
5113
5114 /* Hex values are really cool and convenient, except that they're
5115 not supported in strict ISO C90 mode. First, the "p-" sequence
5116 is not valid as part of a preprocessor number. Second, we get a
5117 pedwarn from the preprocessor, which has no context, so we can't
5118 suppress the warning with __extension__.
5119
5120 So instead what we do is construct the number in hex (because
5121 it's easy to get the exact correct value), parse it as a real,
5122 then print it back out as decimal. */
5123
5124 real_from_string (&real, hex_str);
5125 real_to_decimal (dec_str, &real, sizeof (dec_str), digits, 0);
5126
5127 sprintf (buf, "%s=%s%s", macro, dec_str, fp_suffix);
5128 cpp_define (parse_in, buf);
4249}
4250
5129}
5130
4251/* Common finish hook for the C, ObjC and C++ front ends. */
4252void
4253c_common_finish ()
5131/* Define MAX for TYPE based on the precision of the type. IS_LONG is
5132 1 for type "long" and 2 for "long long". We have to handle
5133 unsigned types, since wchar_t might be unsigned. */
5134
5135static void
5136builtin_define_type_max (macro, type, is_long)
5137 const char *macro;
5138 tree type;
5139 int is_long;
4254{
5140{
4255 cpp_finish (parse_in);
5141 static const char *const values[]
5142 = { "127", "255",
5143 "32767", "65535",
5144 "2147483647", "4294967295",
5145 "9223372036854775807", "18446744073709551615",
5146 "170141183460469231731687303715884105727",
5147 "340282366920938463463374607431768211455" };
5148 static const char *const suffixes[] = { "", "U", "L", "UL", "LL", "ULL" };
4256
5149
4257 /* For performance, avoid tearing down cpplib's internal structures.
4258 Call cpp_errors () instead of cpp_destroy (). */
4259 errorcount += cpp_errors (parse_in);
5150 const char *value, *suffix;
5151 char *buf;
5152 size_t idx;
5153
5154 /* Pre-rendering the values mean we don't have to futz with printing a
5155 multi-word decimal value. There are also a very limited number of
5156 precisions that we support, so it's really a waste of time. */
5157 switch (TYPE_PRECISION (type))
5158 {
5159 case 8: idx = 0; break;
5160 case 16: idx = 2; break;
5161 case 32: idx = 4; break;
5162 case 64: idx = 6; break;
5163 case 128: idx = 8; break;
5164 default: abort ();
5165 }
5166
5167 value = values[idx + TREE_UNSIGNED (type)];
5168 suffix = suffixes[is_long * 2 + TREE_UNSIGNED (type)];
5169
5170 buf = alloca (strlen (macro) + 1 + strlen (value) + strlen (suffix) + 1);
5171 sprintf (buf, "%s=%s%s", macro, value, suffix);
5172
5173 cpp_define (parse_in, buf);
4260}
4261
4262static void
4263c_init_attributes ()
4264{
4265 /* Fill in the built_in_attributes array. */
4266#define DEF_ATTR_NULL_TREE(ENUM) \
4267 built_in_attributes[(int) ENUM] = NULL_TREE;

--- 8 unchanged lines hidden (view full) ---

4276 built_in_attributes[(int) CHAIN]);
4277#define DEF_FN_ATTR(NAME, ATTRS, PREDICATE) /* No initialization needed. */
4278#include "builtin-attrs.def"
4279#undef DEF_ATTR_NULL_TREE
4280#undef DEF_ATTR_INT
4281#undef DEF_ATTR_IDENT
4282#undef DEF_ATTR_TREE_LIST
4283#undef DEF_FN_ATTR
5174}
5175
5176static void
5177c_init_attributes ()
5178{
5179 /* Fill in the built_in_attributes array. */
5180#define DEF_ATTR_NULL_TREE(ENUM) \
5181 built_in_attributes[(int) ENUM] = NULL_TREE;

--- 8 unchanged lines hidden (view full) ---

5190 built_in_attributes[(int) CHAIN]);
5191#define DEF_FN_ATTR(NAME, ATTRS, PREDICATE) /* No initialization needed. */
5192#include "builtin-attrs.def"
5193#undef DEF_ATTR_NULL_TREE
5194#undef DEF_ATTR_INT
5195#undef DEF_ATTR_IDENT
5196#undef DEF_ATTR_TREE_LIST
5197#undef DEF_FN_ATTR
4284 ggc_add_tree_root (built_in_attributes, (int) ATTR_LAST);
4285 c_attrs_initialized = true;
4286}
4287
4288/* Depending on the name of DECL, apply default attributes to it. */
4289
4290void
4291c_common_insert_default_attributes (decl)
4292 tree decl;

--- 27 unchanged lines hidden (view full) ---

4320 tree name, decl;
4321{
4322 warning ("declaration of `%s' shadows %s", IDENTIFIER_POINTER (name), msgid);
4323 warning_with_file_and_line (DECL_SOURCE_FILE (decl),
4324 DECL_SOURCE_LINE (decl),
4325 "shadowed declaration is here");
4326}
4327
5198 c_attrs_initialized = true;
5199}
5200
5201/* Depending on the name of DECL, apply default attributes to it. */
5202
5203void
5204c_common_insert_default_attributes (decl)
5205 tree decl;

--- 27 unchanged lines hidden (view full) ---

5233 tree name, decl;
5234{
5235 warning ("declaration of `%s' shadows %s", IDENTIFIER_POINTER (name), msgid);
5236 warning_with_file_and_line (DECL_SOURCE_FILE (decl),
5237 DECL_SOURCE_LINE (decl),
5238 "shadowed declaration is here");
5239}
5240
5241/* Attribute handlers common to C front ends. */
5242
5243/* Handle a "packed" attribute; arguments as in
5244 struct attribute_spec.handler. */
5245
5246static tree
5247handle_packed_attribute (node, name, args, flags, no_add_attrs)
5248 tree *node;
5249 tree name;
5250 tree args ATTRIBUTE_UNUSED;
5251 int flags;
5252 bool *no_add_attrs;
5253{
5254 tree *type = NULL;
5255 if (DECL_P (*node))
5256 {
5257 if (TREE_CODE (*node) == TYPE_DECL)
5258 type = &TREE_TYPE (*node);
5259 }
5260 else
5261 type = node;
5262
5263 if (type)
5264 {
5265 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
5266 *type = build_type_copy (*type);
5267 TYPE_PACKED (*type) = 1;
5268 }
5269 else if (TREE_CODE (*node) == FIELD_DECL)
5270 DECL_PACKED (*node) = 1;
5271 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
5272 used for DECL_REGISTER. It wouldn't mean anything anyway. */
5273 else
5274 {
5275 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
5276 *no_add_attrs = true;
5277 }
5278
5279 return NULL_TREE;
5280}
5281
5282/* Handle a "nocommon" attribute; arguments as in
5283 struct attribute_spec.handler. */
5284
5285static tree
5286handle_nocommon_attribute (node, name, args, flags, no_add_attrs)
5287 tree *node;
5288 tree name;
5289 tree args ATTRIBUTE_UNUSED;
5290 int flags ATTRIBUTE_UNUSED;
5291 bool *no_add_attrs;
5292{
5293 if (TREE_CODE (*node) == VAR_DECL)
5294 DECL_COMMON (*node) = 0;
5295 else
5296 {
5297 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
5298 *no_add_attrs = true;
5299 }
5300
5301 return NULL_TREE;
5302}
5303
5304/* Handle a "common" attribute; arguments as in
5305 struct attribute_spec.handler. */
5306
5307static tree
5308handle_common_attribute (node, name, args, flags, no_add_attrs)
5309 tree *node;
5310 tree name;
5311 tree args ATTRIBUTE_UNUSED;
5312 int flags ATTRIBUTE_UNUSED;
5313 bool *no_add_attrs;
5314{
5315 if (TREE_CODE (*node) == VAR_DECL)
5316 DECL_COMMON (*node) = 1;
5317 else
5318 {
5319 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
5320 *no_add_attrs = true;
5321 }
5322
5323 return NULL_TREE;
5324}
5325
5326/* Handle a "noreturn" attribute; arguments as in
5327 struct attribute_spec.handler. */
5328
5329static tree
5330handle_noreturn_attribute (node, name, args, flags, no_add_attrs)
5331 tree *node;
5332 tree name;
5333 tree args ATTRIBUTE_UNUSED;
5334 int flags ATTRIBUTE_UNUSED;
5335 bool *no_add_attrs;
5336{
5337 tree type = TREE_TYPE (*node);
5338
5339 /* See FIXME comment in c_common_attribute_table. */
5340 if (TREE_CODE (*node) == FUNCTION_DECL)
5341 TREE_THIS_VOLATILE (*node) = 1;
5342 else if (TREE_CODE (type) == POINTER_TYPE
5343 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
5344 TREE_TYPE (*node)
5345 = build_pointer_type
5346 (build_type_variant (TREE_TYPE (type),
5347 TREE_READONLY (TREE_TYPE (type)), 1));
5348 else
5349 {
5350 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
5351 *no_add_attrs = true;
5352 }
5353
5354 return NULL_TREE;
5355}
5356
5357/* Handle a "noinline" attribute; arguments as in
5358 struct attribute_spec.handler. */
5359
5360static tree
5361handle_noinline_attribute (node, name, args, flags, no_add_attrs)
5362 tree *node;
5363 tree name;
5364 tree args ATTRIBUTE_UNUSED;
5365 int flags ATTRIBUTE_UNUSED;
5366 bool *no_add_attrs;
5367{
5368 if (TREE_CODE (*node) == FUNCTION_DECL)
5369 DECL_UNINLINABLE (*node) = 1;
5370 else
5371 {
5372 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
5373 *no_add_attrs = true;
5374 }
5375
5376 return NULL_TREE;
5377}
5378
5379/* Handle a "always_inline" attribute; arguments as in
5380 struct attribute_spec.handler. */
5381
5382static tree
5383handle_always_inline_attribute (node, name, args, flags, no_add_attrs)
5384 tree *node;
5385 tree name;
5386 tree args ATTRIBUTE_UNUSED;
5387 int flags ATTRIBUTE_UNUSED;
5388 bool *no_add_attrs;
5389{
5390 if (TREE_CODE (*node) == FUNCTION_DECL)
5391 {
5392 /* Do nothing else, just set the attribute. We'll get at
5393 it later with lookup_attribute. */
5394 }
5395 else
5396 {
5397 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
5398 *no_add_attrs = true;
5399 }
5400
5401 return NULL_TREE;
5402}
5403
5404/* Handle a "used" attribute; arguments as in
5405 struct attribute_spec.handler. */
5406
5407static tree
5408handle_used_attribute (pnode, name, args, flags, no_add_attrs)
5409 tree *pnode;
5410 tree name;
5411 tree args ATTRIBUTE_UNUSED;
5412 int flags ATTRIBUTE_UNUSED;
5413 bool *no_add_attrs;
5414{
5415 tree node = *pnode;
5416
5417 if (TREE_CODE (node) == FUNCTION_DECL
5418 || (TREE_CODE (node) == VAR_DECL && TREE_STATIC (node)))
5419 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (node))
5420 = TREE_USED (node) = 1;
5421 else
5422 {
5423 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
5424 *no_add_attrs = true;
5425 }
5426
5427 return NULL_TREE;
5428}
5429
5430/* Handle a "unused" attribute; arguments as in
5431 struct attribute_spec.handler. */
5432
5433static tree
5434handle_unused_attribute (node, name, args, flags, no_add_attrs)
5435 tree *node;
5436 tree name;
5437 tree args ATTRIBUTE_UNUSED;
5438 int flags;
5439 bool *no_add_attrs;
5440{
5441 if (DECL_P (*node))
5442 {
5443 tree decl = *node;
5444
5445 if (TREE_CODE (decl) == PARM_DECL
5446 || TREE_CODE (decl) == VAR_DECL
5447 || TREE_CODE (decl) == FUNCTION_DECL
5448 || TREE_CODE (decl) == LABEL_DECL
5449 || TREE_CODE (decl) == TYPE_DECL)
5450 TREE_USED (decl) = 1;
5451 else
5452 {
5453 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
5454 *no_add_attrs = true;
5455 }
5456 }
5457 else
5458 {
5459 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
5460 *node = build_type_copy (*node);
5461 TREE_USED (*node) = 1;
5462 }
5463
5464 return NULL_TREE;
5465}
5466
5467/* Handle a "const" attribute; arguments as in
5468 struct attribute_spec.handler. */
5469
5470static tree
5471handle_const_attribute (node, name, args, flags, no_add_attrs)
5472 tree *node;
5473 tree name;
5474 tree args ATTRIBUTE_UNUSED;
5475 int flags ATTRIBUTE_UNUSED;
5476 bool *no_add_attrs;
5477{
5478 tree type = TREE_TYPE (*node);
5479
5480 /* See FIXME comment on noreturn in c_common_attribute_table. */
5481 if (TREE_CODE (*node) == FUNCTION_DECL)
5482 TREE_READONLY (*node) = 1;
5483 else if (TREE_CODE (type) == POINTER_TYPE
5484 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
5485 TREE_TYPE (*node)
5486 = build_pointer_type
5487 (build_type_variant (TREE_TYPE (type), 1,
5488 TREE_THIS_VOLATILE (TREE_TYPE (type))));
5489 else
5490 {
5491 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
5492 *no_add_attrs = true;
5493 }
5494
5495 return NULL_TREE;
5496}
5497
5498/* Handle a "transparent_union" attribute; arguments as in
5499 struct attribute_spec.handler. */
5500
5501static tree
5502handle_transparent_union_attribute (node, name, args, flags, no_add_attrs)
5503 tree *node;
5504 tree name;
5505 tree args ATTRIBUTE_UNUSED;
5506 int flags;
5507 bool *no_add_attrs;
5508{
5509 tree decl = NULL_TREE;
5510 tree *type = NULL;
5511 int is_type = 0;
5512
5513 if (DECL_P (*node))
5514 {
5515 decl = *node;
5516 type = &TREE_TYPE (decl);
5517 is_type = TREE_CODE (*node) == TYPE_DECL;
5518 }
5519 else if (TYPE_P (*node))
5520 type = node, is_type = 1;
5521
5522 if (is_type
5523 && TREE_CODE (*type) == UNION_TYPE
5524 && (decl == 0
5525 || (TYPE_FIELDS (*type) != 0
5526 && TYPE_MODE (*type) == DECL_MODE (TYPE_FIELDS (*type)))))
5527 {
5528 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
5529 *type = build_type_copy (*type);
5530 TYPE_TRANSPARENT_UNION (*type) = 1;
5531 }
5532 else if (decl != 0 && TREE_CODE (decl) == PARM_DECL
5533 && TREE_CODE (*type) == UNION_TYPE
5534 && TYPE_MODE (*type) == DECL_MODE (TYPE_FIELDS (*type)))
5535 DECL_TRANSPARENT_UNION (decl) = 1;
5536 else
5537 {
5538 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
5539 *no_add_attrs = true;
5540 }
5541
5542 return NULL_TREE;
5543}
5544
5545/* Handle a "constructor" attribute; arguments as in
5546 struct attribute_spec.handler. */
5547
5548static tree
5549handle_constructor_attribute (node, name, args, flags, no_add_attrs)
5550 tree *node;
5551 tree name;
5552 tree args ATTRIBUTE_UNUSED;
5553 int flags ATTRIBUTE_UNUSED;
5554 bool *no_add_attrs;
5555{
5556 tree decl = *node;
5557 tree type = TREE_TYPE (decl);
5558
5559 if (TREE_CODE (decl) == FUNCTION_DECL
5560 && TREE_CODE (type) == FUNCTION_TYPE
5561 && decl_function_context (decl) == 0)
5562 {
5563 DECL_STATIC_CONSTRUCTOR (decl) = 1;
5564 TREE_USED (decl) = 1;
5565 }
5566 else
5567 {
5568 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
5569 *no_add_attrs = true;
5570 }
5571
5572 return NULL_TREE;
5573}
5574
5575/* Handle a "destructor" attribute; arguments as in
5576 struct attribute_spec.handler. */
5577
5578static tree
5579handle_destructor_attribute (node, name, args, flags, no_add_attrs)
5580 tree *node;
5581 tree name;
5582 tree args ATTRIBUTE_UNUSED;
5583 int flags ATTRIBUTE_UNUSED;
5584 bool *no_add_attrs;
5585{
5586 tree decl = *node;
5587 tree type = TREE_TYPE (decl);
5588
5589 if (TREE_CODE (decl) == FUNCTION_DECL
5590 && TREE_CODE (type) == FUNCTION_TYPE
5591 && decl_function_context (decl) == 0)
5592 {
5593 DECL_STATIC_DESTRUCTOR (decl) = 1;
5594 TREE_USED (decl) = 1;
5595 }
5596 else
5597 {
5598 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
5599 *no_add_attrs = true;
5600 }
5601
5602 return NULL_TREE;
5603}
5604
5605/* Handle a "mode" attribute; arguments as in
5606 struct attribute_spec.handler. */
5607
5608static tree
5609handle_mode_attribute (node, name, args, flags, no_add_attrs)
5610 tree *node;
5611 tree name;
5612 tree args;
5613 int flags ATTRIBUTE_UNUSED;
5614 bool *no_add_attrs;
5615{
5616 tree type = *node;
5617
5618 *no_add_attrs = true;
5619
5620 if (TREE_CODE (TREE_VALUE (args)) != IDENTIFIER_NODE)
5621 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
5622 else
5623 {
5624 int j;
5625 const char *p = IDENTIFIER_POINTER (TREE_VALUE (args));
5626 int len = strlen (p);
5627 enum machine_mode mode = VOIDmode;
5628 tree typefm;
5629
5630 if (len > 4 && p[0] == '_' && p[1] == '_'
5631 && p[len - 1] == '_' && p[len - 2] == '_')
5632 {
5633 char *newp = (char *) alloca (len - 1);
5634
5635 strcpy (newp, &p[2]);
5636 newp[len - 4] = '\0';
5637 p = newp;
5638 }
5639
5640 /* Change this type to have a type with the specified mode.
5641 First check for the special modes. */
5642 if (! strcmp (p, "byte"))
5643 mode = byte_mode;
5644 else if (!strcmp (p, "word"))
5645 mode = word_mode;
5646 else if (! strcmp (p, "pointer"))
5647 mode = ptr_mode;
5648 else
5649 for (j = 0; j < NUM_MACHINE_MODES; j++)
5650 if (!strcmp (p, GET_MODE_NAME (j)))
5651 mode = (enum machine_mode) j;
5652
5653 if (mode == VOIDmode)
5654 error ("unknown machine mode `%s'", p);
5655 else if (0 == (typefm = (*lang_hooks.types.type_for_mode)
5656 (mode, TREE_UNSIGNED (type))))
5657 error ("no data type for mode `%s'", p);
5658 else
5659 {
5660 /* If this is a vector, make sure we either have hardware
5661 support, or we can emulate it. */
5662 if ((GET_MODE_CLASS (mode) == MODE_VECTOR_INT
5663 || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT)
5664 && !vector_mode_valid_p (mode))
5665 {
5666 error ("unable to emulate '%s'", GET_MODE_NAME (mode));
5667 return NULL_TREE;
5668 }
5669
5670 *node = typefm;
5671 /* No need to layout the type here. The caller should do this. */
5672 }
5673 }
5674
5675 return NULL_TREE;
5676}
5677
5678/* Handle a "section" attribute; arguments as in
5679 struct attribute_spec.handler. */
5680
5681static tree
5682handle_section_attribute (node, name, args, flags, no_add_attrs)
5683 tree *node;
5684 tree name ATTRIBUTE_UNUSED;
5685 tree args;
5686 int flags ATTRIBUTE_UNUSED;
5687 bool *no_add_attrs;
5688{
5689 tree decl = *node;
5690
5691 if (targetm.have_named_sections)
5692 {
5693 if ((TREE_CODE (decl) == FUNCTION_DECL
5694 || TREE_CODE (decl) == VAR_DECL)
5695 && TREE_CODE (TREE_VALUE (args)) == STRING_CST)
5696 {
5697 if (TREE_CODE (decl) == VAR_DECL
5698 && current_function_decl != NULL_TREE
5699 && ! TREE_STATIC (decl))
5700 {
5701 error_with_decl (decl,
5702 "section attribute cannot be specified for local variables");
5703 *no_add_attrs = true;
5704 }
5705
5706 /* The decl may have already been given a section attribute
5707 from a previous declaration. Ensure they match. */
5708 else if (DECL_SECTION_NAME (decl) != NULL_TREE
5709 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)),
5710 TREE_STRING_POINTER (TREE_VALUE (args))) != 0)
5711 {
5712 error_with_decl (*node,
5713 "section of `%s' conflicts with previous declaration");
5714 *no_add_attrs = true;
5715 }
5716 else
5717 DECL_SECTION_NAME (decl) = TREE_VALUE (args);
5718 }
5719 else
5720 {
5721 error_with_decl (*node,
5722 "section attribute not allowed for `%s'");
5723 *no_add_attrs = true;
5724 }
5725 }
5726 else
5727 {
5728 error_with_decl (*node,
5729 "section attributes are not supported for this target");
5730 *no_add_attrs = true;
5731 }
5732
5733 return NULL_TREE;
5734}
5735
5736/* Handle a "aligned" attribute; arguments as in
5737 struct attribute_spec.handler. */
5738
5739static tree
5740handle_aligned_attribute (node, name, args, flags, no_add_attrs)
5741 tree *node;
5742 tree name ATTRIBUTE_UNUSED;
5743 tree args;
5744 int flags;
5745 bool *no_add_attrs;
5746{
5747 tree decl = NULL_TREE;
5748 tree *type = NULL;
5749 int is_type = 0;
5750 tree align_expr = (args ? TREE_VALUE (args)
5751 : size_int (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
5752 int i;
5753
5754 if (DECL_P (*node))
5755 {
5756 decl = *node;
5757 type = &TREE_TYPE (decl);
5758 is_type = TREE_CODE (*node) == TYPE_DECL;
5759 }
5760 else if (TYPE_P (*node))
5761 type = node, is_type = 1;
5762
5763 /* Strip any NOPs of any kind. */
5764 while (TREE_CODE (align_expr) == NOP_EXPR
5765 || TREE_CODE (align_expr) == CONVERT_EXPR
5766 || TREE_CODE (align_expr) == NON_LVALUE_EXPR)
5767 align_expr = TREE_OPERAND (align_expr, 0);
5768
5769 if (TREE_CODE (align_expr) != INTEGER_CST)
5770 {
5771 error ("requested alignment is not a constant");
5772 *no_add_attrs = true;
5773 }
5774 else if ((i = tree_log2 (align_expr)) == -1)
5775 {
5776 error ("requested alignment is not a power of 2");
5777 *no_add_attrs = true;
5778 }
5779 else if (i > HOST_BITS_PER_INT - 2)
5780 {
5781 error ("requested alignment is too large");
5782 *no_add_attrs = true;
5783 }
5784 else if (is_type)
5785 {
5786 /* If we have a TYPE_DECL, then copy the type, so that we
5787 don't accidentally modify a builtin type. See pushdecl. */
5788 if (decl && TREE_TYPE (decl) != error_mark_node
5789 && DECL_ORIGINAL_TYPE (decl) == NULL_TREE)
5790 {
5791 tree tt = TREE_TYPE (decl);
5792 *type = build_type_copy (*type);
5793 DECL_ORIGINAL_TYPE (decl) = tt;
5794 TYPE_NAME (*type) = decl;
5795 TREE_USED (*type) = TREE_USED (decl);
5796 TREE_TYPE (decl) = *type;
5797 }
5798 else if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
5799 *type = build_type_copy (*type);
5800
5801 TYPE_ALIGN (*type) = (1 << i) * BITS_PER_UNIT;
5802 TYPE_USER_ALIGN (*type) = 1;
5803 }
5804 else if (TREE_CODE (decl) != VAR_DECL
5805 && TREE_CODE (decl) != FIELD_DECL)
5806 {
5807 error_with_decl (decl,
5808 "alignment may not be specified for `%s'");
5809 *no_add_attrs = true;
5810 }
5811 else
5812 {
5813 DECL_ALIGN (decl) = (1 << i) * BITS_PER_UNIT;
5814 DECL_USER_ALIGN (decl) = 1;
5815 }
5816
5817 return NULL_TREE;
5818}
5819
5820/* Handle a "weak" attribute; arguments as in
5821 struct attribute_spec.handler. */
5822
5823static tree
5824handle_weak_attribute (node, name, args, flags, no_add_attrs)
5825 tree *node;
5826 tree name ATTRIBUTE_UNUSED;
5827 tree args ATTRIBUTE_UNUSED;
5828 int flags ATTRIBUTE_UNUSED;
5829 bool *no_add_attrs ATTRIBUTE_UNUSED;
5830{
5831 declare_weak (*node);
5832
5833 return NULL_TREE;
5834}
5835
5836/* Handle an "alias" attribute; arguments as in
5837 struct attribute_spec.handler. */
5838
5839static tree
5840handle_alias_attribute (node, name, args, flags, no_add_attrs)
5841 tree *node;
5842 tree name;
5843 tree args;
5844 int flags ATTRIBUTE_UNUSED;
5845 bool *no_add_attrs;
5846{
5847 tree decl = *node;
5848
5849 if ((TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
5850 || (TREE_CODE (decl) != FUNCTION_DECL && ! DECL_EXTERNAL (decl)))
5851 {
5852 error_with_decl (decl,
5853 "`%s' defined both normally and as an alias");
5854 *no_add_attrs = true;
5855 }
5856 else if (decl_function_context (decl) == 0)
5857 {
5858 tree id;
5859
5860 id = TREE_VALUE (args);
5861 if (TREE_CODE (id) != STRING_CST)
5862 {
5863 error ("alias arg not a string");
5864 *no_add_attrs = true;
5865 return NULL_TREE;
5866 }
5867 id = get_identifier (TREE_STRING_POINTER (id));
5868 /* This counts as a use of the object pointed to. */
5869 TREE_USED (id) = 1;
5870
5871 if (TREE_CODE (decl) == FUNCTION_DECL)
5872 DECL_INITIAL (decl) = error_mark_node;
5873 else
5874 DECL_EXTERNAL (decl) = 0;
5875 }
5876 else
5877 {
5878 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
5879 *no_add_attrs = true;
5880 }
5881
5882 return NULL_TREE;
5883}
5884
5885/* Handle an "visibility" attribute; arguments as in
5886 struct attribute_spec.handler. */
5887
5888static tree
5889handle_visibility_attribute (node, name, args, flags, no_add_attrs)
5890 tree *node;
5891 tree name;
5892 tree args;
5893 int flags ATTRIBUTE_UNUSED;
5894 bool *no_add_attrs;
5895{
5896 tree decl = *node;
5897
5898 if (decl_function_context (decl) != 0 || ! TREE_PUBLIC (decl))
5899 {
5900 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
5901 *no_add_attrs = true;
5902 }
5903 else
5904 {
5905 tree id;
5906
5907 id = TREE_VALUE (args);
5908 if (TREE_CODE (id) != STRING_CST)
5909 {
5910 error ("visibility arg not a string");
5911 *no_add_attrs = true;
5912 return NULL_TREE;
5913 }
5914 if (strcmp (TREE_STRING_POINTER (id), "hidden")
5915 && strcmp (TREE_STRING_POINTER (id), "protected")
5916 && strcmp (TREE_STRING_POINTER (id), "internal")
5917 && strcmp (TREE_STRING_POINTER (id), "default"))
5918 {
5919 error ("visibility arg must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
5920 *no_add_attrs = true;
5921 return NULL_TREE;
5922 }
5923 }
5924
5925 return NULL_TREE;
5926}
5927
5928/* Handle an "tls_model" attribute; arguments as in
5929 struct attribute_spec.handler. */
5930
5931static tree
5932handle_tls_model_attribute (node, name, args, flags, no_add_attrs)
5933 tree *node;
5934 tree name;
5935 tree args;
5936 int flags ATTRIBUTE_UNUSED;
5937 bool *no_add_attrs;
5938{
5939 tree decl = *node;
5940
5941 if (! DECL_THREAD_LOCAL (decl))
5942 {
5943 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
5944 *no_add_attrs = true;
5945 }
5946 else
5947 {
5948 tree id;
5949
5950 id = TREE_VALUE (args);
5951 if (TREE_CODE (id) != STRING_CST)
5952 {
5953 error ("tls_model arg not a string");
5954 *no_add_attrs = true;
5955 return NULL_TREE;
5956 }
5957 if (strcmp (TREE_STRING_POINTER (id), "local-exec")
5958 && strcmp (TREE_STRING_POINTER (id), "initial-exec")
5959 && strcmp (TREE_STRING_POINTER (id), "local-dynamic")
5960 && strcmp (TREE_STRING_POINTER (id), "global-dynamic"))
5961 {
5962 error ("tls_model arg must be one of \"local-exec\", \"initial-exec\", \"local-dynamic\" or \"global-dynamic\"");
5963 *no_add_attrs = true;
5964 return NULL_TREE;
5965 }
5966 }
5967
5968 return NULL_TREE;
5969}
5970
5971/* Handle a "no_instrument_function" attribute; arguments as in
5972 struct attribute_spec.handler. */
5973
5974static tree
5975handle_no_instrument_function_attribute (node, name, args, flags, no_add_attrs)
5976 tree *node;
5977 tree name;
5978 tree args ATTRIBUTE_UNUSED;
5979 int flags ATTRIBUTE_UNUSED;
5980 bool *no_add_attrs;
5981{
5982 tree decl = *node;
5983
5984 if (TREE_CODE (decl) != FUNCTION_DECL)
5985 {
5986 error_with_decl (decl,
5987 "`%s' attribute applies only to functions",
5988 IDENTIFIER_POINTER (name));
5989 *no_add_attrs = true;
5990 }
5991 else if (DECL_INITIAL (decl))
5992 {
5993 error_with_decl (decl,
5994 "can't set `%s' attribute after definition",
5995 IDENTIFIER_POINTER (name));
5996 *no_add_attrs = true;
5997 }
5998 else
5999 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl) = 1;
6000
6001 return NULL_TREE;
6002}
6003
6004/* Handle a "malloc" attribute; arguments as in
6005 struct attribute_spec.handler. */
6006
6007static tree
6008handle_malloc_attribute (node, name, args, flags, no_add_attrs)
6009 tree *node;
6010 tree name;
6011 tree args ATTRIBUTE_UNUSED;
6012 int flags ATTRIBUTE_UNUSED;
6013 bool *no_add_attrs;
6014{
6015 if (TREE_CODE (*node) == FUNCTION_DECL)
6016 DECL_IS_MALLOC (*node) = 1;
6017 /* ??? TODO: Support types. */
6018 else
6019 {
6020 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
6021 *no_add_attrs = true;
6022 }
6023
6024 return NULL_TREE;
6025}
6026
6027/* Handle a "no_limit_stack" attribute; arguments as in
6028 struct attribute_spec.handler. */
6029
6030static tree
6031handle_no_limit_stack_attribute (node, name, args, flags, no_add_attrs)
6032 tree *node;
6033 tree name;
6034 tree args ATTRIBUTE_UNUSED;
6035 int flags ATTRIBUTE_UNUSED;
6036 bool *no_add_attrs;
6037{
6038 tree decl = *node;
6039
6040 if (TREE_CODE (decl) != FUNCTION_DECL)
6041 {
6042 error_with_decl (decl,
6043 "`%s' attribute applies only to functions",
6044 IDENTIFIER_POINTER (name));
6045 *no_add_attrs = true;
6046 }
6047 else if (DECL_INITIAL (decl))
6048 {
6049 error_with_decl (decl,
6050 "can't set `%s' attribute after definition",
6051 IDENTIFIER_POINTER (name));
6052 *no_add_attrs = true;
6053 }
6054 else
6055 DECL_NO_LIMIT_STACK (decl) = 1;
6056
6057 return NULL_TREE;
6058}
6059
6060/* Handle a "pure" attribute; arguments as in
6061 struct attribute_spec.handler. */
6062
6063static tree
6064handle_pure_attribute (node, name, args, flags, no_add_attrs)
6065 tree *node;
6066 tree name;
6067 tree args ATTRIBUTE_UNUSED;
6068 int flags ATTRIBUTE_UNUSED;
6069 bool *no_add_attrs;
6070{
6071 if (TREE_CODE (*node) == FUNCTION_DECL)
6072 DECL_IS_PURE (*node) = 1;
6073 /* ??? TODO: Support types. */
6074 else
6075 {
6076 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
6077 *no_add_attrs = true;
6078 }
6079
6080 return NULL_TREE;
6081}
6082
6083/* Handle a "cleanup" attribute; arguments as in
6084 struct attribute_spec.handler. */
6085
6086static tree
6087handle_cleanup_attribute (node, name, args, flags, no_add_attrs)
6088 tree *node;
6089 tree name;
6090 tree args;
6091 int flags ATTRIBUTE_UNUSED;
6092 bool *no_add_attrs;
6093{
6094 tree decl = *node;
6095 tree cleanup_id, cleanup_decl;
6096
6097 /* ??? Could perhaps support cleanups on TREE_STATIC, much like we do
6098 for global destructors in C++. This requires infrastructure that
6099 we don't have generically at the moment. It's also not a feature
6100 we'd be missing too much, since we do have attribute constructor. */
6101 if (TREE_CODE (decl) != VAR_DECL || TREE_STATIC (decl))
6102 {
6103 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
6104 *no_add_attrs = true;
6105 return NULL_TREE;
6106 }
6107
6108 /* Verify that the argument is a function in scope. */
6109 /* ??? We could support pointers to functions here as well, if
6110 that was considered desirable. */
6111 cleanup_id = TREE_VALUE (args);
6112 if (TREE_CODE (cleanup_id) != IDENTIFIER_NODE)
6113 {
6114 error ("cleanup arg not an identifier");
6115 *no_add_attrs = true;
6116 return NULL_TREE;
6117 }
6118 cleanup_decl = lookup_name (cleanup_id);
6119 if (!cleanup_decl || TREE_CODE (cleanup_decl) != FUNCTION_DECL)
6120 {
6121 error ("cleanup arg not a function");
6122 *no_add_attrs = true;
6123 return NULL_TREE;
6124 }
6125
6126 /* That the function has proper type is checked with the
6127 eventual call to build_function_call. */
6128
6129 return NULL_TREE;
6130}
6131
6132/* Handle a "deprecated" attribute; arguments as in
6133 struct attribute_spec.handler. */
6134
6135static tree
6136handle_deprecated_attribute (node, name, args, flags, no_add_attrs)
6137 tree *node;
6138 tree name;
6139 tree args ATTRIBUTE_UNUSED;
6140 int flags;
6141 bool *no_add_attrs;
6142{
6143 tree type = NULL_TREE;
6144 int warn = 0;
6145 const char *what = NULL;
6146
6147 if (DECL_P (*node))
6148 {
6149 tree decl = *node;
6150 type = TREE_TYPE (decl);
6151
6152 if (TREE_CODE (decl) == TYPE_DECL
6153 || TREE_CODE (decl) == PARM_DECL
6154 || TREE_CODE (decl) == VAR_DECL
6155 || TREE_CODE (decl) == FUNCTION_DECL
6156 || TREE_CODE (decl) == FIELD_DECL)
6157 TREE_DEPRECATED (decl) = 1;
6158 else
6159 warn = 1;
6160 }
6161 else if (TYPE_P (*node))
6162 {
6163 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
6164 *node = build_type_copy (*node);
6165 TREE_DEPRECATED (*node) = 1;
6166 type = *node;
6167 }
6168 else
6169 warn = 1;
6170
6171 if (warn)
6172 {
6173 *no_add_attrs = true;
6174 if (type && TYPE_NAME (type))
6175 {
6176 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
6177 what = IDENTIFIER_POINTER (TYPE_NAME (*node));
6178 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
6179 && DECL_NAME (TYPE_NAME (type)))
6180 what = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
6181 }
6182 if (what)
6183 warning ("`%s' attribute ignored for `%s'",
6184 IDENTIFIER_POINTER (name), what);
6185 else
6186 warning ("`%s' attribute ignored",
6187 IDENTIFIER_POINTER (name));
6188 }
6189
6190 return NULL_TREE;
6191}
6192
6193/* Keep a list of vector type nodes we created in handle_vector_size_attribute,
6194 to prevent us from duplicating type nodes unnecessarily.
6195 The normal mechanism to prevent duplicates is to use type_hash_canon, but
6196 since we want to distinguish types that are essentially identical (except
6197 for their debug representation), we use a local list here. */
6198static GTY(()) tree vector_type_node_list = 0;
6199
6200/* Handle a "vector_size" attribute; arguments as in
6201 struct attribute_spec.handler. */
6202
6203static tree
6204handle_vector_size_attribute (node, name, args, flags, no_add_attrs)
6205 tree *node;
6206 tree name;
6207 tree args;
6208 int flags ATTRIBUTE_UNUSED;
6209 bool *no_add_attrs;
6210{
6211 unsigned HOST_WIDE_INT vecsize, nunits;
6212 enum machine_mode mode, orig_mode, new_mode;
6213 tree type = *node, new_type = NULL_TREE;
6214 tree type_list_node;
6215
6216 *no_add_attrs = true;
6217
6218 if (! host_integerp (TREE_VALUE (args), 1))
6219 {
6220 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
6221 return NULL_TREE;
6222 }
6223
6224 /* Get the vector size (in bytes). */
6225 vecsize = tree_low_cst (TREE_VALUE (args), 1);
6226
6227 /* We need to provide for vector pointers, vector arrays, and
6228 functions returning vectors. For example:
6229
6230 __attribute__((vector_size(16))) short *foo;
6231
6232 In this case, the mode is SI, but the type being modified is
6233 HI, so we need to look further. */
6234
6235 while (POINTER_TYPE_P (type)
6236 || TREE_CODE (type) == FUNCTION_TYPE
6237 || TREE_CODE (type) == ARRAY_TYPE)
6238 type = TREE_TYPE (type);
6239
6240 /* Get the mode of the type being modified. */
6241 orig_mode = TYPE_MODE (type);
6242
6243 if (TREE_CODE (type) == RECORD_TYPE
6244 || (GET_MODE_CLASS (orig_mode) != MODE_FLOAT
6245 && GET_MODE_CLASS (orig_mode) != MODE_INT)
6246 || ! host_integerp (TYPE_SIZE_UNIT (type), 1))
6247 {
6248 error ("invalid vector type for attribute `%s'",
6249 IDENTIFIER_POINTER (name));
6250 return NULL_TREE;
6251 }
6252
6253 /* Calculate how many units fit in the vector. */
6254 nunits = vecsize / tree_low_cst (TYPE_SIZE_UNIT (type), 1);
6255
6256 /* Find a suitably sized vector. */
6257 new_mode = VOIDmode;
6258 for (mode = GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_mode) == MODE_INT
6259 ? MODE_VECTOR_INT
6260 : MODE_VECTOR_FLOAT);
6261 mode != VOIDmode;
6262 mode = GET_MODE_WIDER_MODE (mode))
6263 if (vecsize == GET_MODE_SIZE (mode)
6264 && nunits == (unsigned HOST_WIDE_INT) GET_MODE_NUNITS (mode))
6265 {
6266 new_mode = mode;
6267 break;
6268 }
6269
6270 if (new_mode == VOIDmode)
6271 {
6272 error ("no vector mode with the size and type specified could be found");
6273 return NULL_TREE;
6274 }
6275
6276 for (type_list_node = vector_type_node_list; type_list_node;
6277 type_list_node = TREE_CHAIN (type_list_node))
6278 {
6279 tree other_type = TREE_VALUE (type_list_node);
6280 tree record = TYPE_DEBUG_REPRESENTATION_TYPE (other_type);
6281 tree fields = TYPE_FIELDS (record);
6282 tree field_type = TREE_TYPE (fields);
6283 tree array_type = TREE_TYPE (field_type);
6284 if (TREE_CODE (fields) != FIELD_DECL
6285 || TREE_CODE (field_type) != ARRAY_TYPE)
6286 abort ();
6287
6288 if (TYPE_MODE (other_type) == mode && type == array_type)
6289 {
6290 new_type = other_type;
6291 break;
6292 }
6293 }
6294
6295 if (new_type == NULL_TREE)
6296 {
6297 tree index, array, rt, list_node;
6298
6299 new_type = (*lang_hooks.types.type_for_mode) (new_mode,
6300 TREE_UNSIGNED (type));
6301
6302 if (!new_type)
6303 {
6304 error ("no vector mode with the size and type specified could be found");
6305 return NULL_TREE;
6306 }
6307
6308 new_type = build_type_copy (new_type);
6309
6310 /* If this is a vector, make sure we either have hardware
6311 support, or we can emulate it. */
6312 if ((GET_MODE_CLASS (mode) == MODE_VECTOR_INT
6313 || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT)
6314 && !vector_mode_valid_p (mode))
6315 {
6316 error ("unable to emulate '%s'", GET_MODE_NAME (mode));
6317 return NULL_TREE;
6318 }
6319
6320 /* Set the debug information here, because this is the only
6321 place where we know the underlying type for a vector made
6322 with vector_size. For debugging purposes we pretend a vector
6323 is an array within a structure. */
6324 index = build_int_2 (TYPE_VECTOR_SUBPARTS (new_type) - 1, 0);
6325 array = build_array_type (type, build_index_type (index));
6326 rt = make_node (RECORD_TYPE);
6327
6328 TYPE_FIELDS (rt) = build_decl (FIELD_DECL, get_identifier ("f"), array);
6329 DECL_CONTEXT (TYPE_FIELDS (rt)) = rt;
6330 layout_type (rt);
6331 TYPE_DEBUG_REPRESENTATION_TYPE (new_type) = rt;
6332
6333 list_node = build_tree_list (NULL, new_type);
6334 TREE_CHAIN (list_node) = vector_type_node_list;
6335 vector_type_node_list = list_node;
6336 }
6337
6338 /* Build back pointers if needed. */
6339 *node = vector_size_helper (*node, new_type);
6340
6341 return NULL_TREE;
6342}
6343
6344/* HACK. GROSS. This is absolutely disgusting. I wish there was a
6345 better way.
6346
6347 If we requested a pointer to a vector, build up the pointers that
6348 we stripped off while looking for the inner type. Similarly for
6349 return values from functions.
6350
6351 The argument "type" is the top of the chain, and "bottom" is the
6352 new type which we will point to. */
6353
6354static tree
6355vector_size_helper (type, bottom)
6356 tree type, bottom;
6357{
6358 tree inner, outer;
6359
6360 if (POINTER_TYPE_P (type))
6361 {
6362 inner = vector_size_helper (TREE_TYPE (type), bottom);
6363 outer = build_pointer_type (inner);
6364 }
6365 else if (TREE_CODE (type) == ARRAY_TYPE)
6366 {
6367 inner = vector_size_helper (TREE_TYPE (type), bottom);
6368 outer = build_array_type (inner, TYPE_VALUES (type));
6369 }
6370 else if (TREE_CODE (type) == FUNCTION_TYPE)
6371 {
6372 inner = vector_size_helper (TREE_TYPE (type), bottom);
6373 outer = build_function_type (inner, TYPE_VALUES (type));
6374 }
6375 else
6376 return bottom;
6377
6378 TREE_READONLY (outer) = TREE_READONLY (type);
6379 TREE_THIS_VOLATILE (outer) = TREE_THIS_VOLATILE (type);
6380
6381 return outer;
6382}
6383
6384/* Handle the "nonnull" attribute. */
6385static tree
6386handle_nonnull_attribute (node, name, args, flags, no_add_attrs)
6387 tree *node;
6388 tree name ATTRIBUTE_UNUSED;
6389 tree args;
6390 int flags ATTRIBUTE_UNUSED;
6391 bool *no_add_attrs;
6392{
6393 tree type = *node;
6394 unsigned HOST_WIDE_INT attr_arg_num;
6395
6396 /* If no arguments are specified, all pointer arguments should be
6397 non-null. Veryify a full prototype is given so that the arguments
6398 will have the correct types when we actually check them later. */
6399 if (! args)
6400 {
6401 if (! TYPE_ARG_TYPES (type))
6402 {
6403 error ("nonnull attribute without arguments on a non-prototype");
6404 *no_add_attrs = true;
6405 }
6406 return NULL_TREE;
6407 }
6408
6409 /* Argument list specified. Verify that each argument number references
6410 a pointer argument. */
6411 for (attr_arg_num = 1; args; args = TREE_CHAIN (args))
6412 {
6413 tree argument;
6414 unsigned HOST_WIDE_INT arg_num, ck_num;
6415
6416 if (! get_nonnull_operand (TREE_VALUE (args), &arg_num))
6417 {
6418 error ("nonnull argument has invalid operand number (arg %lu)",
6419 (unsigned long) attr_arg_num);
6420 *no_add_attrs = true;
6421 return NULL_TREE;
6422 }
6423
6424 argument = TYPE_ARG_TYPES (type);
6425 if (argument)
6426 {
6427 for (ck_num = 1; ; ck_num++)
6428 {
6429 if (! argument || ck_num == arg_num)
6430 break;
6431 argument = TREE_CHAIN (argument);
6432 }
6433
6434 if (! argument
6435 || TREE_CODE (TREE_VALUE (argument)) == VOID_TYPE)
6436 {
6437 error ("nonnull argument with out-of-range operand number (arg %lu, operand %lu)",
6438 (unsigned long) attr_arg_num, (unsigned long) arg_num);
6439 *no_add_attrs = true;
6440 return NULL_TREE;
6441 }
6442
6443 if (TREE_CODE (TREE_VALUE (argument)) != POINTER_TYPE)
6444 {
6445 error ("nonnull argument references non-pointer operand (arg %lu, operand %lu)",
6446 (unsigned long) attr_arg_num, (unsigned long) arg_num);
6447 *no_add_attrs = true;
6448 return NULL_TREE;
6449 }
6450 }
6451 }
6452
6453 return NULL_TREE;
6454}
6455
6456/* Check the argument list of a function call for null in argument slots
6457 that are marked as requiring a non-null pointer argument. */
6458
6459static void
6460check_function_nonnull (attrs, params)
6461 tree attrs;
6462 tree params;
6463{
6464 tree a, args, param;
6465 int param_num;
6466
6467 for (a = attrs; a; a = TREE_CHAIN (a))
6468 {
6469 if (is_attribute_p ("nonnull", TREE_PURPOSE (a)))
6470 {
6471 args = TREE_VALUE (a);
6472
6473 /* Walk the argument list. If we encounter an argument number we
6474 should check for non-null, do it. If the attribute has no args,
6475 then every pointer argument is checked (in which case the check
6476 for pointer type is done in check_nonnull_arg). */
6477 for (param = params, param_num = 1; ;
6478 param_num++, param = TREE_CHAIN (param))
6479 {
6480 if (! param)
6481 break;
6482 if (! args || nonnull_check_p (args, param_num))
6483 check_function_arguments_recurse (check_nonnull_arg, NULL,
6484 TREE_VALUE (param),
6485 param_num);
6486 }
6487 }
6488 }
6489}
6490
6491/* Helper for check_function_nonnull; given a list of operands which
6492 must be non-null in ARGS, determine if operand PARAM_NUM should be
6493 checked. */
6494
6495static bool
6496nonnull_check_p (args, param_num)
6497 tree args;
6498 unsigned HOST_WIDE_INT param_num;
6499{
6500 unsigned HOST_WIDE_INT arg_num;
6501
6502 for (; args; args = TREE_CHAIN (args))
6503 {
6504 if (! get_nonnull_operand (TREE_VALUE (args), &arg_num))
6505 abort ();
6506
6507 if (arg_num == param_num)
6508 return true;
6509 }
6510 return false;
6511}
6512
6513/* Check that the function argument PARAM (which is operand number
6514 PARAM_NUM) is non-null. This is called by check_function_nonnull
6515 via check_function_arguments_recurse. */
6516
6517static void
6518check_nonnull_arg (ctx, param, param_num)
6519 void *ctx ATTRIBUTE_UNUSED;
6520 tree param;
6521 unsigned HOST_WIDE_INT param_num;
6522{
6523 /* Just skip checking the argument if it's not a pointer. This can
6524 happen if the "nonnull" attribute was given without an operand
6525 list (which means to check every pointer argument). */
6526
6527 if (TREE_CODE (TREE_TYPE (param)) != POINTER_TYPE)
6528 return;
6529
6530 if (integer_zerop (param))
6531 warning ("null argument where non-null required (arg %lu)",
6532 (unsigned long) param_num);
6533}
6534
6535/* Helper for nonnull attribute handling; fetch the operand number
6536 from the attribute argument list. */
6537
6538static bool
6539get_nonnull_operand (arg_num_expr, valp)
6540 tree arg_num_expr;
6541 unsigned HOST_WIDE_INT *valp;
6542{
6543 /* Strip any conversions from the arg number and verify they
6544 are constants. */
6545 while (TREE_CODE (arg_num_expr) == NOP_EXPR
6546 || TREE_CODE (arg_num_expr) == CONVERT_EXPR
6547 || TREE_CODE (arg_num_expr) == NON_LVALUE_EXPR)
6548 arg_num_expr = TREE_OPERAND (arg_num_expr, 0);
6549
6550 if (TREE_CODE (arg_num_expr) != INTEGER_CST
6551 || TREE_INT_CST_HIGH (arg_num_expr) != 0)
6552 return false;
6553
6554 *valp = TREE_INT_CST_LOW (arg_num_expr);
6555 return true;
6556}
6557
6558/* Handle a "nothrow" attribute; arguments as in
6559 struct attribute_spec.handler. */
6560
6561static tree
6562handle_nothrow_attribute (node, name, args, flags, no_add_attrs)
6563 tree *node;
6564 tree name;
6565 tree args ATTRIBUTE_UNUSED;
6566 int flags ATTRIBUTE_UNUSED;
6567 bool *no_add_attrs;
6568{
6569 if (TREE_CODE (*node) == FUNCTION_DECL)
6570 TREE_NOTHROW (*node) = 1;
6571 /* ??? TODO: Support types. */
6572 else
6573 {
6574 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
6575 *no_add_attrs = true;
6576 }
6577
6578 return NULL_TREE;
6579}
6580
6581/* Check for valid arguments being passed to a function. */
6582void
6583check_function_arguments (attrs, params)
6584 tree attrs;
6585 tree params;
6586{
6587 /* Check for null being passed in a pointer argument that must be
6588 non-null. We also need to do this if format checking is enabled. */
6589
6590 if (warn_nonnull)
6591 check_function_nonnull (attrs, params);
6592
6593 /* Check for errors in format strings. */
6594
6595 if (warn_format)
6596 check_function_format (NULL, attrs, params);
6597}
6598
6599/* Generic argument checking recursion routine. PARAM is the argument to
6600 be checked. PARAM_NUM is the number of the argument. CALLBACK is invoked
6601 once the argument is resolved. CTX is context for the callback. */
6602void
6603check_function_arguments_recurse (callback, ctx, param, param_num)
6604 void (*callback) PARAMS ((void *, tree, unsigned HOST_WIDE_INT));
6605 void *ctx;
6606 tree param;
6607 unsigned HOST_WIDE_INT param_num;
6608{
6609 if (TREE_CODE (param) == NOP_EXPR)
6610 {
6611 /* Strip coercion. */
6612 check_function_arguments_recurse (callback, ctx,
6613 TREE_OPERAND (param, 0), param_num);
6614 return;
6615 }
6616
6617 if (TREE_CODE (param) == CALL_EXPR)
6618 {
6619 tree type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (param, 0)));
6620 tree attrs;
6621 bool found_format_arg = false;
6622
6623 /* See if this is a call to a known internationalization function
6624 that modifies a format arg. Such a function may have multiple
6625 format_arg attributes (for example, ngettext). */
6626
6627 for (attrs = TYPE_ATTRIBUTES (type);
6628 attrs;
6629 attrs = TREE_CHAIN (attrs))
6630 if (is_attribute_p ("format_arg", TREE_PURPOSE (attrs)))
6631 {
6632 tree inner_args;
6633 tree format_num_expr;
6634 int format_num;
6635 int i;
6636
6637 /* Extract the argument number, which was previously checked
6638 to be valid. */
6639 format_num_expr = TREE_VALUE (TREE_VALUE (attrs));
6640 while (TREE_CODE (format_num_expr) == NOP_EXPR
6641 || TREE_CODE (format_num_expr) == CONVERT_EXPR
6642 || TREE_CODE (format_num_expr) == NON_LVALUE_EXPR)
6643 format_num_expr = TREE_OPERAND (format_num_expr, 0);
6644
6645 if (TREE_CODE (format_num_expr) != INTEGER_CST
6646 || TREE_INT_CST_HIGH (format_num_expr) != 0)
6647 abort ();
6648
6649 format_num = TREE_INT_CST_LOW (format_num_expr);
6650
6651 for (inner_args = TREE_OPERAND (param, 1), i = 1;
6652 inner_args != 0;
6653 inner_args = TREE_CHAIN (inner_args), i++)
6654 if (i == format_num)
6655 {
6656 check_function_arguments_recurse (callback, ctx,
6657 TREE_VALUE (inner_args),
6658 param_num);
6659 found_format_arg = true;
6660 break;
6661 }
6662 }
6663
6664 /* If we found a format_arg attribute and did a recursive check,
6665 we are done with checking this argument. Otherwise, we continue
6666 and this will be considered a non-literal. */
6667 if (found_format_arg)
6668 return;
6669 }
6670
6671 if (TREE_CODE (param) == COND_EXPR)
6672 {
6673 /* Check both halves of the conditional expression. */
6674 check_function_arguments_recurse (callback, ctx,
6675 TREE_OPERAND (param, 1), param_num);
6676 check_function_arguments_recurse (callback, ctx,
6677 TREE_OPERAND (param, 2), param_num);
6678 return;
6679 }
6680
6681 (*callback) (ctx, param, param_num);
6682}
6683
6684#include "gt-c-common.h"