gcc/libcpp/expr.c

2243 lines
61 KiB
C
Raw Permalink Normal View History

/* Parse C expressions for cpplib.
Copyright (C) 1987-2017 Free Software Foundation, Inc.
Contributed by Per Bothner, 1994.
1995-03-16 22:59:07 +01:00
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any
1995-03-16 22:59:07 +01:00
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
1995-03-16 22:59:07 +01:00
#include "config.h"
#include "system.h"
Warning Fixes: * Makefile.in (print-rtl.o): Depend on bitmap.h. (dbxout.o): Depend on toplev.h. ($(SCHED_PREFIX)sched.o): Likewise. ($(out_object_file)): Likewise for system.h and toplev.h. (cppmain.o): Depend on gansidecl.h. (cpplib.o): Likewise. (cpperror.o): Likewise. (cppexp.o): Likewise. (cpphash.o): Likewise. (cppalloc.o): Likewise. (fix-header.o): Depend on cpplib.h and cpphash.h. (scan-decls.o): Depend on gansidecl.h. * basic-block.h (free_regset_vector): Add prototype. * cccp.c (check_precompiled): Mark parameter `fname' with ATTRIBUTE_UNUSED. (do_assert): Likewise for `op' and `keyword'. (do_unassert): Likewise. (do_line): Likewise for `keyword'. (do_error): Likewise for `op' and `keyword'. (do_warning): Likewise. (do_ident): Likewise for `keyword'. (do_pragma): Likewise for `limit', `op' and `keyword'. (do_sccs): Likewise. (do_if): Likewise for `keyword'. (do_elif): Likewise. (do_else): Likewise. (do_endif): Likewise. * collect2.c (getenv): Remove redundant prototype. (collect_exit, collect_execute, dump_file): Likewise. (dump_list): Wrap prototype and definition in COLLECT_EXPORT_LIST. (dump_prefix_list): Hide prototype and definition. * sparc.c: Include toplev.h. (intreg_operand): Mark parameter `mode' with ATTRIBUTE_UNUSED. (symbolic_memory_operand): Likewise. (sp64_medium_pic_operand): Likewise. (data_segment_operand): Likewise. (text_segment_operand): Likewise. (splittable_symbolic_memory_operand): Likewise. (splittable_immediate_memory_operand): Likewise. (eq_or_neq): Likewise. (normal_comp_operator): Likewise. (noov_compare_op): Likewise. (v9_regcmp_op): Likewise. (v8plus_regcmp_op): Likewise. (extend_op): Likewise. (cc_arithop): Likewise. (cc_arithopn): Likewise. (small_int): Likewise. (uns_small_int): Likewise. (clobbered_register): Likewise. (legitimize_pic_address): Likewise. (delay_operand): Likewise. (sparc_builtin_saveregs): Remove unused variable `stdarg'. * sparc.h (order_regs_for_local_alloc, eligible_for_return_delay, sparc_issue_rate, v8plus_regcmp_p): Add prototypes. * sparc.md (cmpdi_v8plus): Add abort for default case in switch. * cppalloc.c: Include gansidecl.h. * cpperror.c: Include stdarg.h/varargs.h and gansidecl.h. (cpp_file_line_for_message): Mark parameter `pfile' with ATTRIBUTE_UNUSED. (v_cpp_message): New function. (cpp_message): Use it. Also convert to variable arguments. (cpp_fatal): Likewise. (cpp_pfatal_with_name): Constify parameter `name'. * cppexp.c: Move gansidecl.h before cpplib.h. * cpphash.c: Likewise. * cpphash.h (hashf, delete_macro): Add prototypes. * cpplib.c: Include stdarg.h/varargs.h and move gansidecl.h before cpplib.h. Don't include errno.h. (update_path): Add arguments to prototype. (cpp_fatal, cpp_file_line_for_message, cpp_message, delete_macro, cpp_print_containing_files): Remove redundant prototypes. (cpp_hash_cleanup, add_import, append_include_chain, make_assertion, path_include, initialize_builtins, initialize_char_syntax, finclude, validate_else, comp_def_part, lookup_import, redundant_include_p, is_system_include, read_name_map, read_filename_string, open_include_file, check_macro_name, compare_defs, compare_token_lists, eval_if_expression, change_newlines): Add prototype arguments. (hashf): Remove redundant prototype. (read_token_list, free_token_list, safe_read, xcalloc, savestring, conditional_skip, skip_if_group): Add prototype arguments. (fdopen): Remove redundant prototype. (do_define, do_line, do_include, do_undef, do_error, do_pragma, do_ident, do_if, do_xifdef, do_else, do_elif, do_endif, do_sccs, do_once, do_assert, do_unassert, do_warning): Add prototype arguments. (struct directive): Add prototype arguments to function pointer member `func'. (handle_directive): Add missing arguments to call to `do_line'. (do_include): Mark parameters `unused1' and `unused2' with ATTRIBUTE_UNUSED. (do_line): Likewise for `keyword' and new parameters `unused1' and `unused2'. (do_error): Likewise for `keyword'. (do_warning): Likewise. Also add missing argument `pfile' in call to cpp_pedwarn. (do_once): Mark parameter `keyword', `unused1' and `unused2' with ATTRIBUTE_UNUSED. (do_ident): Likewise for `keyword', `buf' and `limit'. (do_pragma): Likewise. Also add missing arguments in call to do_once. (do_sccs): Mark parameter `keyword', `buf' and `limit' with ATTRIBUTE_UNUSED. (do_if): Likewise for `keyword'. (do_elif): Likewise. (eval_if_expression): Likewise for `buf' and `length'. (do_xifdef): Likewise for `unused1' and `unused2'. (do_else): Likewise for `keyword', `buf' and `limit'. (do_endif): Likewise. (parse_name): Add missing argument `pfile' in call to cpp_pedwarn. (cpp_handle_options): Remove superfluous NULL argument in call to cpp_fatal. (cpp_handle_options): Likewise. (do_assert): Mark parameter `keyword', `buf' and `limit' with ATTRIBUTE_UNUSED. (do_unassert): Likewise. (cpp_print_file_and_line): Add missing argument `pfile' in call to cpp_file_line_for_message. (v_cpp_error): New function. (cpp_error): Use it. Also accept variable arguments. (v_cpp_warning): New function. (cpp_warning): Use it. Also accept variable arguments. (cpp_pedwarn): Accept variable arguments. (v_cpp_error_with_line): New function (cpp_error_with_line): Use it. Accept variable arguments. (v_cpp_warning_with_line): New function. (cpp_warning_with_line): Use it. Accept variable arguments. Hide definition. (cpp_pedwarn_with_line): Accept variable arguments. (cpp_pedwarn_with_file_and_line): Likewise. (cpp_error_from_errno): Constify parameter `name'. Add missing argument `pfile' in call to cpp_file_line_for_message. (cpp_perror_with_name): Constify parameter `name'. * cpplib.h: Define PARAMS() in terms of PROTO(). (fatal): Remove redundant prototype. (cpp_error, cpp_warning, cpp_pedwarn, cpp_error_with_line, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line, cpp_error_from_errno, cpp_perror_with_name, cpp_pfatal_with_name, cpp_fatal, cpp_message, cpp_pfatal_with_name, cpp_file_line_for_message, cpp_print_containing_files): Add arguments to prototypes. (scan_decls, cpp_finish): Add prototypes. * cppmain.c: Include gansidecl.h. (main): Remove unused variable `i'. * dbxout.c: Include toplev.h. * demangle.h (do_tlink, collect_execute, collect_exit, collect_wait, dump_file, file_exists): Add prototype. * dwarf2out.c (dwarf_type_encoding_name, decl_start_label): Hide prototype and definition. (gen_unspecified_parameters_die): Don't assign results of call to function new_die() to unused variable `parm_die'. (dwarf2out_line): Mark parameter `filename' with ATTRIBUTE_UNUSED. (dwarf2out_define): Likewise for `lineno' and `buffer'. * dwarfout.c (output_unsigned_leb128, output_signed_leb128): Hide prototype and definition. (output_die): Add prototype arguments to function pointer arg. (output_unspecified_parameters_die): Mark parameter `arg' with ATTRIBUTE_UNUSED. * except.c (output_exception_table_entry): Remove unused variable `eh_entry'. * except.h (expand_fixup_region_start, expand_fixup_region_end): Add prototypes. * expr.c (do_jump_by_parts_equality_rtx): Remove prototype. * expr.h (do_jump_by_parts_equality_rtx): Add prototype. * fix-header.c: Include stdarg.h/varargs.h, move gansidecl.h before cpplib.h, include cpphash.h, remove redundant prototype of cpp_fatal, don't define `const', add a prototype for `fatal'. (cpp_file_line_for_message): Add missing arguments `pfile'. (v_cpp_message): New function. (cpp_message): Use it. (v_fatal): New function. (fatal, cpp_fatal): Use it. (cpp_pfatal_with_name): Constify parameter `name'. * flow.c (free_regset_vector): Remove redundant prototype. * function.c (round_down): Wrap prototype and definition with macro ARGS_GROW_DOWNWARD. (record_insns): Wrap prototype and definition with defined (HAVE_prologue) || defined (HAVE_epilogue). * gansidecl.h (ATTRIBUTE_PRINTF_4, ATTRIBUTE_PRINTF_5): New macros. * gen-protos.c: Include gansidecl.h. (hashf): Don't make it static, constify parameter `name'. * genattrtab.c (check_attr_test): Change XEXP() to XSTR() to match specifier %s in calls to function `fatal'. * haifa-sched.c: Include toplev.h. (find_rgns): Remove unused variable `j'. * integrate.c (note_modified_parmregs): Mark parameter `x' with ATTRIBUTE_UNUSED. (mark_stores): Likewise. * jump.c (mark_modified_reg): Likewise. * output.h (insn_current_reference_address): Add prototype. (eh_frame_section): Likewise. * print-rtl.c: Include bitmap.h. * reload1.c (reload): Wrap variables `note' and `next' in macro PRESERVE_DEATH_INFO_REGNO_P. (forget_old_reloads_1): Mark parameter `ignored' with ATTRIBUTE_UNUSED. (choose_reload_regs): Remove unused variable `in'. (reload_cse_invalidate_mem): Mark parameter `ignore' with ATTRIBUTE_UNUSED. (reload_cse_check_clobber): Likewise. * rtl.h (expand_null_return, reg_classes_intersect_p): Add prototype. (mark_elimination): Fix typo in prototype. * scan-decls.c: Include gansidecl.h. * tree.h (using_eh_for_cleanups, supports_one_only): Add prototype. From-SVN: r19867
1998-05-19 10:42:48 +02:00
#include "cpplib.h"
Makefile.def (host_modules): add libcpp. ChangeLog: 2004-05-23 Paolo Bonzini <bonzini@gnu.org> * Makefile.def (host_modules): add libcpp. * Makefile.tpl: Add dependencies on and for libcpp. * Makefile.in: Regenerate. * configure.in: Add libcpp host module. * configure: Regenerate. config/ChangeLog: 2004-05-23 Paolo Bonzini <bonzini@gnu.org> * acx.m4 (ACX_HEADER_STDBOOL, ACX_HEADER_STRING): From gcc. gcc/ChangeLog: 2004-05-23 Paolo Bonzini <bonzini@gnu.org> Move libcpp to the toplevel. * Makefile.in: Remove references to libcpp files, use CPPLIBS instead of libcpp.a. Define SYMTAB_H and change hashtable.h to that. * aclocal.m4 (gcc_AC_HEADER_STDBOOL, gcc_AC_HEADER_STRING, gcc_AC_C__BOOL): Remove. * configure.ac (gcc_AC_C__BOOL, HAVE_UCHAR): Remove tests. * configure: Regenerate. * config.in: Regenerate. * c-ppoutput.c: Include ../libcpp/internal.h instead of cpphash.h. * cppcharset.c: Removed. * cpperror.c: Removed. * cppexp.c: Removed. * cppfiles.c: Removed. * cpphash.c: Removed. * cpphash.h: Removed. * cppinit.c: Removed. * cpplex.c: Removed. * cpplib.c: Removed. * cpplib.h: Removed. * cppmacro.c: Removed. * cpppch.c: Removed. * cpptrad.c: Removed. * cppucnid.h: Removed. * cppucnid.pl: Removed. * cppucnid.tab: Removed. * hashtable.c: Removed. * hashtable.h: Removed. * line-map.c: Removed. * line-map.h: Removed. * mkdeps.c: Removed. * mkdeps.h: Removed. * stringpool.h: Include symtab.h instead of hashtable.h. * tree.h: Include symtab.h instead of hashtable.h. * system.h (O_NONBLOCK, O_NOCTTY): Do not define. gcc/cp/ChangeLog: 2004-05-23 Paolo Bonzini <bonzini@gnu.org> * Make-lang.in: No need to specify $(LIBCPP). gcc/java/ChangeLog: 2004-05-23 Paolo Bonzini <bonzini@gnu.org> * Make-lang.in: Link in $(LIBCPP) instead of mkdeps.o. libcpp/ChangeLog: 2004-05-23 Paolo Bonzini <bonzini@gnu.org> Moved libcpp from the gcc subdirectory to the toplevel. * Makefile.am: New file. * Makefile.in: Regenerate. * configure.ac: New file. * configure: Regenerate. * config.in: Regenerate. * charset.c: Moved from gcc/cppcharset.c. Add note about brokenness of input charset detection. Adjust for change in name of cppucnid.h. * errors.c: Moved from gcc/cpperror.c. Do not include intl.h. * expr.c: Moved from gcc/cppexp.c. * files.c: Moved from gcc/cppfiles.c. Do not include intl.h. Remove #define of O_BINARY, it is in system.h. * identifiers.c: Moved from gcc/cpphash.c. * internal.h: Moved from gcc/cpphash.h. Change header guard name. All other files adjusted to match name change. * init.c: Moved from gcc/cppinit.c. (init_library) [ENABLE_NLS]: Call bindtextdomain. * lex.c: Moved from gcc/cpplex.c. * directives.c: Moved from gcc/cpplib.c. * macro.c: Moved from gcc/cppmacro.c. * pch.c: Moved from gcc/cpppch.c. Do not include intl.h. * traditional.c: Moved from gcc/cpptrad.c. * ucnid.h: Moved from gcc/cppucnid.h. Change header guard name. * ucnid.pl: Moved from gcc/cppucnid.pl. * ucnid.tab: Moved from gcc/cppucnid.tab. Change header guard name. * symtab.c: Moved from gcc/hashtable.c. * line-map.c: Moved from gcc. Do not include intl.h. * mkdeps.c: Moved from gcc. * system.h: New file. libcpp/include/ChangeLog: 2004-05-23 Paolo Bonzini <bonzini@gnu.org> * cpplib.h: Moved from gcc. Change header guard name. * line-map.h: Moved from gcc. Change header guard name. * mkdeps.h: Moved from gcc. Change header guard name. * symtab.h: Moved from gcc/hashtable.h. Change header guard name. libcpp/po/ChangeLog: 2004-05-23 Paolo Bonzini <bonzini@gnu.org> * be.po: Extracted from gcc/po/be.po. * ca.po: Extracted from gcc/po/ca.po. * da.po: Extracted from gcc/po/da.po. * de.po: Extracted from gcc/po/de.po. * el.po: Extracted from gcc/po/el.po. * es.po: Extracted from gcc/po/es.po. * fr.po: Extracted from gcc/po/fr.po. * ja.po: Extracted from gcc/po/ja.po. * nl.po: Extracted from gcc/po/nl.po. * sv.po: Extracted from gcc/po/sv.po. * tr.po: Extracted from gcc/po/tr.po. From-SVN: r82199
2004-05-24 12:50:45 +02:00
#include "internal.h"
1995-03-16 22:59:07 +01:00
#define PART_PRECISION (sizeof (cpp_num_part) * CHAR_BIT)
#define HALF_MASK (~(cpp_num_part) 0 >> (PART_PRECISION / 2))
#define LOW_PART(num_part) (num_part & HALF_MASK)
#define HIGH_PART(num_part) (num_part >> (PART_PRECISION / 2))
struct op
{
const cpp_token *token; /* The token forming op (for diagnostics). */
cpp_num value; /* The value logically "right" of op. */
source_location loc; /* The location of this value. */
enum cpp_ttype op;
1995-03-16 22:59:07 +01:00
};
/* Some simple utility routines on double integers. */
#define num_zerop(num) ((num.low | num.high) == 0)
#define num_eq(num1, num2) (num1.low == num2.low && num1.high == num2.high)
static bool num_positive (cpp_num, size_t);
static bool num_greater_eq (cpp_num, cpp_num, size_t);
static cpp_num num_trim (cpp_num, size_t);
static cpp_num num_part_mul (cpp_num_part, cpp_num_part);
static cpp_num num_unary_op (cpp_reader *, cpp_num, enum cpp_ttype);
static cpp_num num_binary_op (cpp_reader *, cpp_num, cpp_num, enum cpp_ttype);
static cpp_num num_negate (cpp_num, size_t);
static cpp_num num_bitwise_op (cpp_reader *, cpp_num, cpp_num, enum cpp_ttype);
static cpp_num num_inequality_op (cpp_reader *, cpp_num, cpp_num,
enum cpp_ttype);
static cpp_num num_equality_op (cpp_reader *, cpp_num, cpp_num,
enum cpp_ttype);
static cpp_num num_mul (cpp_reader *, cpp_num, cpp_num);
static cpp_num num_div_op (cpp_reader *, cpp_num, cpp_num, enum cpp_ttype,
source_location);
static cpp_num num_lshift (cpp_num, size_t, size_t);
static cpp_num num_rshift (cpp_num, size_t, size_t);
static cpp_num append_digit (cpp_num, int, int, size_t);
static cpp_num parse_defined (cpp_reader *);
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
static cpp_num eval_token (cpp_reader *, const cpp_token *, source_location);
static struct op *reduce (cpp_reader *, struct op *, enum cpp_ttype);
static unsigned int interpret_float_suffix (cpp_reader *, const uchar *, size_t);
static unsigned int interpret_int_suffix (cpp_reader *, const uchar *, size_t);
static void check_promotion (cpp_reader *, const struct op *);
Implement SD-6: SG10 Feature Test Recommendations 2014-10-01 Edward Smith-Rowland <3dw4rd@verizon.net> Implement SD-6: SG10 Feature Test Recommendations * internal.h (lexer_state, spec_nodes): Add in__has_include__. * directives.c: Support __has_include__ builtin. * expr.c (parse_has_include): New function to parse __has_include__ builtin; (eval_token()): Use it. * files.c (_cpp_has_header()): New funtion to look for header; (open_file_failed()): Not an error to not find a header file for __has_include__. * identifiers.c (_cpp_init_hashtable()): Add entry for __has_include__. * pch.c (cpp_read_state): Lookup __has_include__. * traditional.c (enum ls, _cpp_scan_out_logical_line()): Walk through __has_include__ statements. 2014-10-01 Edward Smith-Rowland <3dw4rd@verizon.net> Implement SD-6: SG10 Feature Test Recommendations * c-cppbuiltin.c (c_cpp_builtins()): Define language feature macros and the __has_header macro. 2014-10-01 Edward Smith-Rowland <3dw4rd@verizon.net> Implement SD-6: SG10 Feature Test Recommendations * include/bits/basic_string.h: Add __cpp_lib feature test macro. * include/bits/stl_algobase.h: Ditto. * include/bits/stl_function.h: Ditto. * include/bits/unique_ptr.h: Ditto. * include/std/chrono: Ditto. * include/std/complex: Ditto. * include/std/iomanip: Ditto. * include/std/shared_mutex: Ditto. * include/std/tuple: Ditto. * include/std/type_traits: Ditto. * include/std/utility: Ditto. * testsuite/experimental/feat-cxx14.cc: New. * testsuite/experimental/feat-lib-fund.cc: New. * testsuite/20_util/declval/requirements/1_neg.cc: Adjust. * testsuite/20_util/duration/literals/range.cc: Adjust. * testsuite/20_util/duration/requirements/typedefs_neg1.cc: Adjust. * testsuite/20_util/duration/requirements/typedefs_neg2.cc: Adjust. * testsuite/20_util/duration/requirements/typedefs_neg3.cc: Adjust. * testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Adjust. * testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: Adjust. * testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust. * testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc: Adjust. 2014-10-01 Edward Smith-Rowland <3dw4rd@verizon.net> Implement SD-6: SG10 Feature Test Recommendations * g++.dg/cpp1y/feat-cxx11-neg.C: New. * g++.dg/cpp1y/feat-cxx11.C: New. * g++.dg/cpp1y/feat-cxx14.C: New. * g++.dg/cpp1y/feat-cxx98.C: New. * g++.dg/cpp1y/feat-cxx98-neg.C: New. * g++.dg/cpp1y/phoobhar.h: New. * g++.dg/cpp1y/testinc/phoobhar.h: New. From-SVN: r215752
2014-10-01 13:49:23 +02:00
static cpp_num parse_has_include (cpp_reader *, enum include_type);
/* Token type abuse to create unary plus and minus operators. */
configure.ac: Check declarations for asprintf and vasprintf. * configure.ac: Check declarations for asprintf and vasprintf. * config.in: Regenerate. * configure: Likewise. * charset.c (conversion_loop): Use XRESIZEVEC. (convert_no_conversion): Likewise. (convert_using_iconv): Likewise. (init_iconv_desc): Cast return value of alloca. (cpp_host_to_exec_charset): Use XNEWVEC. (emit_numeric_escape): Use XRESIZEVEC. (cpp_interpret_string): Use XNEWVEC. (cpp_interpret_string): Use XRESIZEVEC. (_cpp_interpret_identifier): Cast return value of alloca. (_cpp_convert_input): Use XNEWVEC and XRESIZEVEC. * directives.c (glue_header_name): Use XNEWVEC and XRESIZEVEC. (parse_include): Use XNEWVEC. (insert_pragma_entry): Rename local variable "new" to "new_entry". (save_registered_pragmas): Cast return value of xmemdup. (destringize_and_run): Same for alloca. (parse_assertion): Likewise. (do_assert): Cast allocated storage to proper type. (cpp_define): Likewise. (_cpp_define_builtin): Likewise. (cpp_undef): Likewise. (handle_assertion): Likewise. (cpp_push_buffer): Rename local variable "new" to "new_buffer". * expr.c (CPP_UPLUS): Cast value to type cpp_ttype. (CPP_UMINUS): Likewise. (struct cpp_operator): Rename from struct operator. (_cpp_expand_op_stack): Use XRESIZEVEC. * files.c (pch_open_file): Use XNEWVEC. (pch_open_file): Use XRESIZEVEC. (read_file_guts): Use XNEWVEC and XRESIZEVEC. (dir_name_of_file): Use XNEWVEC. (make_cpp_file): Use XCNEW. (make_cpp_dir): Likewise. (allocate_file_hash_entries): USE XNEWVEC. (cpp_included): Cast return value of htab_find_with_hash. (append_file_to_dir): Use XNEWVEC. (read_filename_string): Likewise. Use XRESIZEVEC too. (read_name_map): Cast return value of alloca. Use XRESIZEVEC. (remap_filename): Use XNEWVEC. (struct pchf_entry): Move definition out of struct pchf_data. (_cpp_save_file_entries): Use XCNEWVAR. (_cpp_read_file_entries): Use XNEWVAR. * identifiers.c (alloc_node): Use XOBNEW. * init.c (cpp_create_reader): Use XCNEW. (cpp_init_builtins): Cast of b->value to enum builtin_type. (read_original_directory): Cast return value of alloca. * lex.c (add_line_note): Use XRESIZEVEC. (warn_about_normalization): Use XNEWVEC. (_cpp_lex_direct): Cast node->directive_index to (enum cpp_ttype). (new_buff): Use XNEWVEC. * line-map.c (linemap_add): Use XRESIZEVEC. * macro.c (builtin_macro): Cast return value of alloca. (paste_tokens): Likewise. (expand_arg): Use XNEWVEC and XRESIZEVEC. (_cpp_save_parameter): Use XRESIZEVEC. (create_iso_definition): Cast allocated storage to proper type. (_cpp_create_definition): Likewise. (cpp_macro_definition): Use XRESIZEVEC. * makedepend.c (add_clm): Use XNEW. (add_dir): Likewise. * mkdeps.c (munge): Use XNEWVEC. (deps_init): Use XCNEW. (deps_add_target): Use XRESIZEVEC. (deps_add_default_target): Cast return value of alloca. (deps_add_dep): Use XRESIZEVEC. (deps_add_vpath): Likewise. Use XNEWVEC too. (deps_restore): Likewise. * pch.c (save_idents): Use XNEW and XNEWVEC. (cpp_save_state): Use XNEW. (count_defs): Cast return value of htab_find. (write_defs): Likewise. (cpp_write_pch_deps): Use XNEWVEC. (collect_ht_nodes): Use XRESIZEVEC. (cpp_valid_state): Use XNEWVEC. (save_macros): Use XRESIZEVEC. Cast return value of xmemdup. * symtab.c (ht_create): Use XCNEW. (ht_lookup_with_hash): Cast return value of obstack_copy0. (ht_expand): Use XCNEWVEC. * system.h (HAVE_DESIGNATED_INITIALIZERS): False if __cplusplus. (bool): Do not define if __cplusplus. From-SVN: r100295
2005-05-28 17:52:48 +02:00
#define CPP_UPLUS ((enum cpp_ttype) (CPP_LAST_CPP_OP + 1))
#define CPP_UMINUS ((enum cpp_ttype) (CPP_LAST_CPP_OP + 2))
cppexp.c (parse_assertion): New. * cppexp.c (parse_assertion): New. (lex): Call it for CPP_HASH. Remove CPP_ASSERTION case. (_cpp_parse_expr): Remove case '#'. Don't set parsing_if_directive. * cpphash.c (collect_objlike_expansion, collect_funlike_expansion, collect_params, _cpp_create_definition): The list no longer has a trailing VSPACE token. * cpphash.h (enum node_type): Add T_ASSERTION. (struct hashnode): Remove aschain, add pred. (struct predicate): New. Update prototypes. * cpplex.c (expand_token_space): Handle both offset and nonoffset lists. (init_token_list, _cpp_free_token_list, _cpp_parse_assertion): Delete. (_cpp_init_toklist, _cpp_clear_toklist, _cpp_free_toklist, _cpp_slice_toklist, _cpp_squeeze_toklist, _cpp_equiv_tokens, _cpp_equiv_toklists): New. (_cpp_scan_line): Rename to _cpp_scan_until; add ability to stop at any single-character token, not just newline. (_cpp_lex_token): Remove special cases for #define and #if. (cpp_get_token): Expect # as a separate token type. Remove DIRECTIVE case. (_cpp_get_directive_token): Remove DIRECTIVE case. (_cpp_lex_line, _cpp_lex_file, _cpp_init_input_buffer): Update. * cpplib.c (_cpp_check_directive): Set dirno and SYNTAX_INCLUDE bit of flags, not dir_handler and dir_flags. (_cpp_handle_directive): Run # <number> through the same logic as normal directives. (do_define): Don't set parsing_define_directive. Use _cpp_scan_until. The list does not have a VSPACE at the end. (do_if): Save, clear, and restore only_seen_white around _cpp_parse_expr. (skip_if_group): s/CPP_DIRECTIVE/CPP_HASH/ (do_assert, do_unassert): Rewrite. * cpplib.h (TTYPE_TABLE): Remove CPP_ASSERTION. (LIST_OFFSET): New flag. (struct cpp_toklist): Replace dir_handler and dir_flags with dirno and flags. (struct cpp_reader): Remove parsing_if_directive and parsing_define_directive. From-SVN: r33984
2000-05-18 17:55:46 +02:00
/* With -O2, gcc appears to produce nice code, moving the error
message load and subsequent jump completely out of the main path. */
#define SYNTAX_ERROR(msgid) \
do { cpp_error (pfile, CPP_DL_ERROR, msgid); goto syntax_error; } while(0)
cppexp.c (parse_assertion): New. * cppexp.c (parse_assertion): New. (lex): Call it for CPP_HASH. Remove CPP_ASSERTION case. (_cpp_parse_expr): Remove case '#'. Don't set parsing_if_directive. * cpphash.c (collect_objlike_expansion, collect_funlike_expansion, collect_params, _cpp_create_definition): The list no longer has a trailing VSPACE token. * cpphash.h (enum node_type): Add T_ASSERTION. (struct hashnode): Remove aschain, add pred. (struct predicate): New. Update prototypes. * cpplex.c (expand_token_space): Handle both offset and nonoffset lists. (init_token_list, _cpp_free_token_list, _cpp_parse_assertion): Delete. (_cpp_init_toklist, _cpp_clear_toklist, _cpp_free_toklist, _cpp_slice_toklist, _cpp_squeeze_toklist, _cpp_equiv_tokens, _cpp_equiv_toklists): New. (_cpp_scan_line): Rename to _cpp_scan_until; add ability to stop at any single-character token, not just newline. (_cpp_lex_token): Remove special cases for #define and #if. (cpp_get_token): Expect # as a separate token type. Remove DIRECTIVE case. (_cpp_get_directive_token): Remove DIRECTIVE case. (_cpp_lex_line, _cpp_lex_file, _cpp_init_input_buffer): Update. * cpplib.c (_cpp_check_directive): Set dirno and SYNTAX_INCLUDE bit of flags, not dir_handler and dir_flags. (_cpp_handle_directive): Run # <number> through the same logic as normal directives. (do_define): Don't set parsing_define_directive. Use _cpp_scan_until. The list does not have a VSPACE at the end. (do_if): Save, clear, and restore only_seen_white around _cpp_parse_expr. (skip_if_group): s/CPP_DIRECTIVE/CPP_HASH/ (do_assert, do_unassert): Rewrite. * cpplib.h (TTYPE_TABLE): Remove CPP_ASSERTION. (LIST_OFFSET): New flag. (struct cpp_toklist): Replace dir_handler and dir_flags with dirno and flags. (struct cpp_reader): Remove parsing_if_directive and parsing_define_directive. From-SVN: r33984
2000-05-18 17:55:46 +02:00
#define SYNTAX_ERROR2(msgid, arg) \
do { cpp_error (pfile, CPP_DL_ERROR, msgid, arg); goto syntax_error; } \
while(0)
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
#define SYNTAX_ERROR_AT(loc, msgid) \
do { cpp_error_with_line (pfile, CPP_DL_ERROR, (loc), 0, msgid); goto syntax_error; } \
while(0)
#define SYNTAX_ERROR2_AT(loc, msgid, arg) \
do { cpp_error_with_line (pfile, CPP_DL_ERROR, (loc), 0, msgid, arg); goto syntax_error; } \
while(0)
cppexp.c (parse_assertion): New. * cppexp.c (parse_assertion): New. (lex): Call it for CPP_HASH. Remove CPP_ASSERTION case. (_cpp_parse_expr): Remove case '#'. Don't set parsing_if_directive. * cpphash.c (collect_objlike_expansion, collect_funlike_expansion, collect_params, _cpp_create_definition): The list no longer has a trailing VSPACE token. * cpphash.h (enum node_type): Add T_ASSERTION. (struct hashnode): Remove aschain, add pred. (struct predicate): New. Update prototypes. * cpplex.c (expand_token_space): Handle both offset and nonoffset lists. (init_token_list, _cpp_free_token_list, _cpp_parse_assertion): Delete. (_cpp_init_toklist, _cpp_clear_toklist, _cpp_free_toklist, _cpp_slice_toklist, _cpp_squeeze_toklist, _cpp_equiv_tokens, _cpp_equiv_toklists): New. (_cpp_scan_line): Rename to _cpp_scan_until; add ability to stop at any single-character token, not just newline. (_cpp_lex_token): Remove special cases for #define and #if. (cpp_get_token): Expect # as a separate token type. Remove DIRECTIVE case. (_cpp_get_directive_token): Remove DIRECTIVE case. (_cpp_lex_line, _cpp_lex_file, _cpp_init_input_buffer): Update. * cpplib.c (_cpp_check_directive): Set dirno and SYNTAX_INCLUDE bit of flags, not dir_handler and dir_flags. (_cpp_handle_directive): Run # <number> through the same logic as normal directives. (do_define): Don't set parsing_define_directive. Use _cpp_scan_until. The list does not have a VSPACE at the end. (do_if): Save, clear, and restore only_seen_white around _cpp_parse_expr. (skip_if_group): s/CPP_DIRECTIVE/CPP_HASH/ (do_assert, do_unassert): Rewrite. * cpplib.h (TTYPE_TABLE): Remove CPP_ASSERTION. (LIST_OFFSET): New flag. (struct cpp_toklist): Replace dir_handler and dir_flags with dirno and flags. (struct cpp_reader): Remove parsing_if_directive and parsing_define_directive. From-SVN: r33984
2000-05-18 17:55:46 +02:00
/* Subroutine of cpp_classify_number. S points to a float suffix of
length LEN, possibly zero. Returns 0 for an invalid suffix, or a
Implement C _FloatN, _FloatNx types. ISO/IEC TS 18661-3:2015 defines C bindings to IEEE interchange and extended types, in the form of _FloatN and _FloatNx type names with corresponding fN/FN and fNx/FNx constant suffixes and FLTN_* / FLTNX_* <float.h> macros. This patch implements support for this feature in GCC. The _FloatN types, for N = 16, 32, 64 or >= 128 and a multiple of 32, are types encoded according to the corresponding IEEE interchange format (endianness unspecified; may use either the NaN conventions recommended in IEEE 754-2008, or the MIPS NaN conventions, since the choice of convention is only an IEEE recommendation, not a requirement). The _FloatNx types, for N = 32, 64 and 128, are IEEE "extended" types: types extending a narrower format with range and precision at least as big as those specified in IEEE 754 for each extended type (and with unspecified representation, but still following IEEE semantics for their values and operations - and with the set of values being determined by the precision and the maximum exponent, which means that while Intel "extended" is suitable for _Float64x, m68k "extended" is not). These types are always distinct from and not compatible with each other and the standard floating types float, double, long double; thus, double, _Float64 and _Float32x may all have the same ABI, but they are three still distinct types. The type names may be used with _Complex to construct corresponding complex types (unlike __float128, which acts more like a typedef name than a keyword - thus, this patch may be considered to fix PR c/32187). The new suffixes can be combined with GNU "i" and "j" suffixes for constants of complex types (e.g. 1.0if128, 2.0f64i). The set of types supported is implementation-defined. In this GCC patch, _Float32 is SFmode if that is suitable; _Float32x and _Float64 are DFmode if that is suitable; _Float128 is TFmode if that is suitable; _Float64x is XFmode if that is suitable, and otherwise TFmode if that is suitable. There is a target hook to override the choices if necessary. "Suitable" means both conforming to the requirements of that type, and supported as a scalar type including in libgcc. The ABI is whatever the back end does for scalars of that mode (but note that _Float32 is passed without promotion in variable arguments, unlike float). All the existing issues with exceptions and rounding modes for existing types apply equally to the new type names. No GCC port supports a floating-point format suitable for _Float128x. Although there is HFmode support for ARM and AArch64, use of that for _Float16 is not enabled. Supporting _Float16 would require additional work on the excess precision aspects of TS 18661-3: there are new values of FLT_EVAL_METHOD, which are not currently supported in GCC, and FLT_EVAL_METHOD == 0 now means that operations and constants on types narrower than float are evaluated to the range and precision of float. Implementing that, so that _Float16 gets evaluated with excess range and precision, would involve changes to the excess precision infrastructure so that the _Float16 case is enabled by default, unlike the x87 case which is only enabled for -fexcess-precision=standard. Other differences between _Float16 and __fp16 would also need to be disentangled. GCC has some prior support for nonstandard floating-point types in the form of __float80 and __float128. Where these were previously types distinct from long double, they are made by this patch into aliases for _Float64x / _Float128 if those types have the required properties. In principle the set of possible _FloatN types is infinite. This patch hardcodes the four such types for N <= 128, but with as much code as possible using loops over types to minimize the number of places with such hardcoding. I don't think it's likely any further such types will be of use in future (or indeed that formats suitable for _Float128x will actually be implemented). There is a corner case that all _FloatN, for N >= 128 and a multiple of 32, should be treated as keywords even when the corresponding type is not supported; I intend to deal with that in a followup patch. Tests are added for various functionality of the new types, mostly using type-generic headers. The tests use dg-add-options to pass any extra options needed to enable the types; this is wired up to use the same options as for __float128 on powerpc to enable _Float128 and _Float64x, and effective-target keywords for runtime support do the same hardware test as for __float128 to make sure the VSX instructions generated by those options are supported. (Corresponding additions would be needed for _Float16 on ARM as well if that were enabled with -mfp16-format=ieee required to use it rather than unconditionally available. Of course, -mfp16-format=alternative enables use of a format which is not compatible with the requirements of the _Float16 type.) C++ note: no support for the new types or constant suffixes is added for C++. C++ decimal floating-point support was very different from the C support, using class types, and the same may well apply to any future C++ bindings for IEEE interchange and extended types. There is a case, however, for supporting at least *f128 constants in C++, so that code using __float128 can use the newer style for constants throughout rather than needing to use the older *q constants in C++. Also, if built-in functions are added that may provide a way in which the types could leak into C++ code. Fortran note: the float128_type_node used in the Fortran front end is renamed to gfc_float128_type_node, since the semantics are different: in particular, if long double has binary128 format, then the new language-independent float128_type_node is a distinct type that also has binary128 format, but the Fortran node is expected to be NULL in that case. Likewise, Fortran's complex_float128_type_node is renamed to gfc_complex_float128_type_node. PowerPC note: the back end had an inconsistency that if TFmode was binary128, *q constants were TFmode instead of KFmode but __float128 was KFmode. This patch follows the same logic as for *q constants, so that _Float128 prefers TFmode (and __float128 becomes an alias for _Float128). ARM note: __fp16 is promoted to double (by convert_arguments) when passed without a prototype / in variable arguments. But this is only about the argument promotion; it is not handled as promoting in c-common.c:self_promoting_args_p / c-typeck.c:c_type_promotes_to, meaning that a K&R function definition for an argument of type __fp16 corresponds to a prototype with an argument of that type, not to one with an argument of type double, whereas a float argument in a K&R function definition corresponds to a double prototype argument - and the same functions are also what's involved in making va_arg give a warning and generate a call to abort when called with type float. This is preserved by this patch, while arranging for _Float16 not to be promoted when passed without a prototype / in variable arguments (the promotion of float being considered a legacy feature, not applied to any new types in C99 or later). TS 18661-3 extends the set of decimal floating-point types similarly, and adds new constant suffixes for the existing types, but this patch does not do anything regarding that extension. This patch does nothing regarding built-in functions, although type-generic functions such as __builtin_isinf work for the new types and associated tests are included. There are at least two levels of built-in function support possible for these types. The minimal level, implemented in <https://gcc.gnu.org/ml/gcc-patches/2016-06/msg01702.html> (which needs updating to use dg-add-options), adds built-in functions similar to those x86 has for __float128: __builtin_inf* __builtin_huge_val*, __builtin_nan*, __builtin_nans*, __builtin_fabs*, __builtin_copysign*. That would be sufficient for glibc to use the *f128 names for built-in functions by default with *q used only for backwards compatibility when using older GCC versions. That would also allow c_cpp_builtins's flag_building_libgcc code, defining __LIBGCC_%s_FUNC_EXT__, to use such suffixes rather than the present code hardcoding logic about target-specific constant suffixes and how those relate to function suffixes. Full built-in function support would cover the full range of built-in functions for existing floating-point types, adding variants for all the new types, except for a few obsolescent functions and non-type-generic variants of type-generic functions. Some but not all references to such functions in GCC use macros such as CASE_FLT_FN to be type-generic; a fair amount of work would be needed to identify all places to update. Adding all those functions would enable optimizations (for constant arguments and otherwise) for TS 18661-3 functions, but it would also substantially expand the enum listing built-in functions (and we've had problems with the size of that enum in the past), and increase the amount of built-in function initialization to do - I don't know what the startup cost involved in built-in function initialization is, but it would be something to consider when adding such a large set of functions. There are also a range of optimizations, in match.pd and elsewhere, that only operate on the three standard floating-point types. Ideally those would be made generic to all floating-point types, but this patch does nothing in that regard. Special care would be needed regarding making sure library functions to which calls are generated actually exist. For example, if sqrt is called on an argument of type _Float32, and the result converted to _Float32, this is equivalent to doing a square root operation directly on _Float32. But if the user's libm does not have the sqrtf32 function, or the name is not reserved because __STDC_WANT_IEC_60559_TYPES_EXT__ was not defined before including <math.h>, you can only do that optimization if you convert to a call to sqrtf instead. DECIMAL_DIG now relates to all supported floating-point formats, not just float, double and long double; I've raised the question with WG14 of how this relates to the formula for DECIMAL_DIG in C11 not considering this. TS 18661-3 says it also covers non-arithmetic formats only supported by library conversion functions; this patch does not add any target hooks to allow for the case where there are such formats wider than any supported for arithmetic types (where e.g. libc supports conversions involving the binary128 representation, but the _Float128 type is not supported). GCC provides its own <tgmath.h> for some targets. No attempt is made to adapt this to handle the new types. Nothing is done regarding debug info for the new types (see the "Debugger support for __float128 type?" thread on gcc@, Sep/Oct 2015). No __SIZEOF_*__ macros are added for the new types. Nothing is done with do_warn_double_promotion. Nothing is done to include the new types in those determining max_align_t, although properly it should be sufficiently aligned for any of those types. The logic for usual arithmetic conversions in c_common_type relies on TYPE_PRECISION for floating-point types, which is less than ideal (doesn't necessarily correspond to whether one type's values are subset of another); looking in more detail at the formats might be better. But since I included code in build_common_tree_nodes to work around rs6000 KFmode having precision 113 not 128, I think it should work. Ideally one might have errors in generic code for the case where the two types do not have one type's values a subset of the other (which is undefined behavior). But the only case where this can actually occur is mixing IBM long double with binary128 on powerpc, and rs6000_invalid_binary_op deals with that at present. TS 18661-3 does not fully specify the type resulting from the usual arithmetic conversions in the case where two _FloatNx types have the same set of values; I arranged the code to prefer the greater value of N in that case. The __FP_FAST_FMA* macros are not extended to cover the new types, since there are no corresponding built-in functions (if built-in fmafN, fmafNx are added, the macros should be extended, and the new macros documented). Also, only a limited set of modes is handled in mode_has_fma. Diagnostics relating to the use of the new types with -pedantic do not try to distinguish them from purely nonstandard types such as __int128 and constant suffixes such as *q. If you use an unsupported _FloatN / _FloatNx type you get a warning about the type defaulting to int after the warning about the type not being supported. That's less than ideal, but it's also a pre-existing condition if you use __int128 on a 32-bit system where it's unsupported. Bootstrapped with no regressions on x86_64-pc-linux-gnu. Other back-end changes minimally tested by building cc1 for ia64-linux-gnu, powerpc64le-linux-gnu, pdp11-none (the last failed for unrelated reasons). PR c/32187 gcc: * tree-core.h (TI_COMPLEX_FLOAT16_TYPE) (TI_COMPLEX_FLOATN_NX_TYPE_FIRST, TI_COMPLEX_FLOAT32_TYPE) (TI_COMPLEX_FLOAT64_TYPE, TI_COMPLEX_FLOAT128_TYPE) (TI_COMPLEX_FLOAT32X_TYPE, TI_COMPLEX_FLOAT64X_TYPE) (TI_COMPLEX_FLOAT128X_TYPE, TI_FLOAT16_TYPE, TI_FLOATN_TYPE_FIRST) (TI_FLOATN_NX_TYPE_FIRST, TI_FLOAT32_TYPE, TI_FLOAT64_TYPE) (TI_FLOAT128_TYPE, TI_FLOATN_TYPE_LAST, TI_FLOAT32X_TYPE) (TI_FLOATNX_TYPE_FIRST, TI_FLOAT64X_TYPE, TI_FLOAT128X_TYPE) (TI_FLOATNX_TYPE_LAST, TI_FLOATN_NX_TYPE_LAST): New enum tree_index values. (NUM_FLOATN_TYPES, NUM_FLOATNX_TYPES, NUM_FLOATN_NX_TYPES): New macros. (struct floatn_type_info): New structure type. (floatn_nx_types): New variable declaration. * tree.h (FLOATN_TYPE_NODE, FLOATN_NX_TYPE_NODE) (FLOATNX_TYPE_NODE, float128_type_node, float64x_type_node) (COMPLEX_FLOATN_NX_TYPE_NODE): New macros. * tree.c (floatn_nx_types): New variable. (build_common_tree_nodes): Initialize _FloatN, _FloatNx and corresponding complex types. * target.def (floatn_mode): New hook. * targhooks.c: Include "real.h". (default_floatn_mode): New function. * targhooks.h (default_floatn_mode): New prototype. * doc/extend.texi (Floating Types): Document _FloatN and _FloatNx types. * doc/sourcebuild.texi (float@var{n}, float@var{n}x): Document new effective-target and dg-add-options keywords. (float@var{n}_runtime, float@var{n}x_runtime, floatn_nx_runtime): Document new effective-target keywords. * doc/tm.texi.in (TARGET_FLOATN_MODE): New @hook. * doc/tm.texi: Regenerate. * ginclude/float.h (LDBL_DECIMAL_DIG): Define to __LDBL_DECIMAL_DIG__, not __DECIMAL_DIG__. [__STDC_WANT_IEC_60559_TYPES_EXT__]: Define macros from TS 18661-3. * real.h (struct real_format): Add field ieee_bits. * real.c (ieee_single_format, mips_single_format) (motorola_single_format, spu_single_format, ieee_double_format) (mips_double_format, motorola_double_format) (ieee_extended_motorola_format, ieee_extended_intel_96_format) (ieee_extended_intel_128_format) (ieee_extended_intel_96_round_53_format, ibm_extended_format) (mips_extended_format, ieee_quad_format, mips_quad_format) (vax_f_format, vax_d_format, vax_g_format, decimal_single_format) (decimal_double_format, decimal_quad_format, ieee_half_format) (arm_half_format, real_internal_format: Initialize ieee_bits field. * config/i386/i386.c (ix86_init_builtin_types): Do not initialize float128_type_node. Set float80_type_node to float64x_type_node if appropriate and long_double_type_node not appropriate. * config/ia64/ia64.c (ia64_init_builtins): Likewise. * config/pdp11/pdp11.c (pdp11_f_format, pdp11_d_format): Initialize ieee_bits field. * config/rs6000/rs6000.c (TARGET_FLOATN_MODE): New macro. (rs6000_init_builtins): Set ieee128_float_type_node to float128_type_node. (rs6000_floatn_mode): New function. gcc/c: * c-tree.h (cts_floatn_nx): New enum c_typespec_keyword value. (struct c_declspecs): Add field floatn_nx_idx. * c-decl.c (declspecs_add_type, finish_declspecs): Handle _FloatN and _FloatNx type specifiers. * c-parser.c (c_keyword_starts_typename, c_token_starts_declspecs) (c_parser_declspecs, c_parser_attribute_any_word) (c_parser_objc_selector): Use CASE_RID_FLOATN_NX. * c-typeck.c (c_common_type): Handle _FloatN and _FloatNx types. (convert_arguments): Avoid promoting _FloatN and _FloatNx types narrower than double. gcc/c-family: * c-common.h (RID_FLOAT16, RID_FLOATN_NX_FIRST, RID_FLOAT32) (RID_FLOAT64, RID_FLOAT128, RID_FLOAT32X, RID_FLOAT64X) (RID_FLOAT128X): New enum rid values. (CASE_RID_FLOATN_NX): New macro. * c-common.c (c_common_reswords): Add _FloatN and _FloatNx keywords. (c_common_type_for_mode): Check for _FloatN and _FloatNx and corresponding complex types. (c_common_nodes_and_builtins): For non-C++, register _FloatN and _FloatNx and corresponding complex types. (keyword_begins_type_specifier): Use CASE_RID_FLOATN_NX. * c-cppbuiltin.c (builtin_define_float_constants): Check _FloatN and _FloatNx types for the widest type for determining DECIMAL_DIG. Define __LDBL_DECIMAL_DIG__ as well as __DECIMAL_DIG__ for long double. Handle FMA_SUFFIX being NULL. (c_cpp_builtins): Call builtin_define_float_constants for _FloatN and _FloatNx types. * c-lex.c (interpret_float): Handle _FloatN and _FloatNx constants. * c-pretty-print.c (pp_c_floating_constant): Handle _FloatN and _FloatNx types. gcc/fortran: * trans-types.h (float128_type_node): Rename to gfc_float128_type_node. (complex_float128_type_node): Rename to gfc_complex_float128_type_node. * iso-c-binding.def, trans-intrinsic.c, trans-types.c: All users changed. gcc/testsuite: * lib/target-supports.exp (check_effective_target_float16) (check_effective_target_float32, check_effective_target_float64) (check_effective_target_float128, check_effective_target_float32x) (check_effective_target_float64x) (check_effective_target_float128x) (check_effective_target_float16_runtime) (check_effective_target_float32_runtime) (check_effective_target_float64_runtime) (check_effective_target_float128_runtime) (check_effective_target_float32x_runtime) (check_effective_target_float64x_runtime) (check_effective_target_float128x_runtime) (check_effective_target_floatn_nx_runtime) (add_options_for_float16, add_options_for_float32) (add_options_for_float64, add_options_for_float128) (add_options_for_float32x, add_options_for_float64x) (add_options_for_float128x): New procedures. * gcc.dg/dfp/floatn.c, gcc.dg/float128-typeof.c, gcc.dg/float128x-typeof.c, gcc.dg/float16-typeof.c, gcc.dg/float32-typeof.c, gcc.dg/float32x-typeof.c, gcc.dg/float64-typeof.c, gcc.dg/float64x-typeof.c, gcc.dg/floatn-arithconv.c, gcc.dg/floatn-errs.c, gcc.dg/floatn-typeof.h, gcc.dg/torture/float128-basic.c, gcc.dg/torture/float128-complex.c, gcc.dg/torture/float128-floath.c, gcc.dg/torture/float128-tg.c, gcc.dg/torture/float128x-basic.c, gcc.dg/torture/float128x-complex.c, gcc.dg/torture/float128x-floath.c, gcc.dg/torture/float128x-tg.c, gcc.dg/torture/float16-basic.c, gcc.dg/torture/float16-complex.c, gcc.dg/torture/float16-floath.c, gcc.dg/torture/float16-tg.c, gcc.dg/torture/float32-basic.c, gcc.dg/torture/float32-complex.c, gcc.dg/torture/float32-floath.c, gcc.dg/torture/float32-tg.c, gcc.dg/torture/float32x-basic.c, gcc.dg/torture/float32x-complex.c, gcc.dg/torture/float32x-floath.c, gcc.dg/torture/float32x-tg.c, gcc.dg/torture/float64-basic.c, gcc.dg/torture/float64-complex.c, gcc.dg/torture/float64-floath.c, gcc.dg/torture/float64-tg.c, gcc.dg/torture/float64x-basic.c, gcc.dg/torture/float64x-complex.c, gcc.dg/torture/float64x-floath.c, gcc.dg/torture/float64x-tg.c, gcc.dg/torture/floatn-basic.h, gcc.dg/torture/floatn-complex.h, gcc.dg/torture/floatn-convert.c, gcc.dg/torture/floatn-floath.h, gcc.dg/torture/floatn-tg.h, gcc.dg/torture/fp-int-convert-float128-ieee-timode.c, gcc.dg/torture/fp-int-convert-float128-ieee.c, gcc.dg/torture/fp-int-convert-float128x-timode.c, gcc.dg/torture/fp-int-convert-float128x.c, gcc.dg/torture/fp-int-convert-float16-timode.c, gcc.dg/torture/fp-int-convert-float16.c, gcc.dg/torture/fp-int-convert-float32-timode.c, gcc.dg/torture/fp-int-convert-float32.c, gcc.dg/torture/fp-int-convert-float32x-timode.c, gcc.dg/torture/fp-int-convert-float32x.c, gcc.dg/torture/fp-int-convert-float64-timode.c, gcc.dg/torture/fp-int-convert-float64.c, gcc.dg/torture/fp-int-convert-float64x-timode.c, gcc.dg/torture/fp-int-convert-float64x.c: New tests. * gcc.dg/torture/fp-int-convert.h (TEST_I_F): Add argument for maximum exponent of floating-point type. Use it in testing whether 0x8...0 fits in the floating-point type. Always treat -1 (signed 0xf...f) as fitting in the floating-point type. (M_OK1): New macro. * gcc.dg/torture/fp-int-convert-double.c, gcc.dg/torture/fp-int-convert-float.c, gcc.dg/torture/fp-int-convert-float128-timode.c, gcc.dg/torture/fp-int-convert-float128.c, gcc.dg/torture/fp-int-convert-float80-timode.c, gcc.dg/torture/fp-int-convert-float80.c, gcc.dg/torture/fp-int-convert-long-double.c, gcc.dg/torture/fp-int-convert-timode.c: Update calls to TEST_I_F. libcpp: * include/cpplib.h (CPP_N_FLOATN, CPP_N_FLOATNX) (CPP_N_WIDTH_FLOATN_NX, CPP_FLOATN_SHIFT, CPP_FLOATN_MAX): New macros. * expr.c (interpret_float_suffix): Handle fN, fNx, FN and FNx suffixes. From-SVN: r239625
2016-08-19 19:43:26 +02:00
flag vector (of CPP_N_* bits) describing the suffix. */
static unsigned int
interpret_float_suffix (cpp_reader *pfile, const uchar *s, size_t len)
{
size_t flags;
Implement C _FloatN, _FloatNx types. ISO/IEC TS 18661-3:2015 defines C bindings to IEEE interchange and extended types, in the form of _FloatN and _FloatNx type names with corresponding fN/FN and fNx/FNx constant suffixes and FLTN_* / FLTNX_* <float.h> macros. This patch implements support for this feature in GCC. The _FloatN types, for N = 16, 32, 64 or >= 128 and a multiple of 32, are types encoded according to the corresponding IEEE interchange format (endianness unspecified; may use either the NaN conventions recommended in IEEE 754-2008, or the MIPS NaN conventions, since the choice of convention is only an IEEE recommendation, not a requirement). The _FloatNx types, for N = 32, 64 and 128, are IEEE "extended" types: types extending a narrower format with range and precision at least as big as those specified in IEEE 754 for each extended type (and with unspecified representation, but still following IEEE semantics for their values and operations - and with the set of values being determined by the precision and the maximum exponent, which means that while Intel "extended" is suitable for _Float64x, m68k "extended" is not). These types are always distinct from and not compatible with each other and the standard floating types float, double, long double; thus, double, _Float64 and _Float32x may all have the same ABI, but they are three still distinct types. The type names may be used with _Complex to construct corresponding complex types (unlike __float128, which acts more like a typedef name than a keyword - thus, this patch may be considered to fix PR c/32187). The new suffixes can be combined with GNU "i" and "j" suffixes for constants of complex types (e.g. 1.0if128, 2.0f64i). The set of types supported is implementation-defined. In this GCC patch, _Float32 is SFmode if that is suitable; _Float32x and _Float64 are DFmode if that is suitable; _Float128 is TFmode if that is suitable; _Float64x is XFmode if that is suitable, and otherwise TFmode if that is suitable. There is a target hook to override the choices if necessary. "Suitable" means both conforming to the requirements of that type, and supported as a scalar type including in libgcc. The ABI is whatever the back end does for scalars of that mode (but note that _Float32 is passed without promotion in variable arguments, unlike float). All the existing issues with exceptions and rounding modes for existing types apply equally to the new type names. No GCC port supports a floating-point format suitable for _Float128x. Although there is HFmode support for ARM and AArch64, use of that for _Float16 is not enabled. Supporting _Float16 would require additional work on the excess precision aspects of TS 18661-3: there are new values of FLT_EVAL_METHOD, which are not currently supported in GCC, and FLT_EVAL_METHOD == 0 now means that operations and constants on types narrower than float are evaluated to the range and precision of float. Implementing that, so that _Float16 gets evaluated with excess range and precision, would involve changes to the excess precision infrastructure so that the _Float16 case is enabled by default, unlike the x87 case which is only enabled for -fexcess-precision=standard. Other differences between _Float16 and __fp16 would also need to be disentangled. GCC has some prior support for nonstandard floating-point types in the form of __float80 and __float128. Where these were previously types distinct from long double, they are made by this patch into aliases for _Float64x / _Float128 if those types have the required properties. In principle the set of possible _FloatN types is infinite. This patch hardcodes the four such types for N <= 128, but with as much code as possible using loops over types to minimize the number of places with such hardcoding. I don't think it's likely any further such types will be of use in future (or indeed that formats suitable for _Float128x will actually be implemented). There is a corner case that all _FloatN, for N >= 128 and a multiple of 32, should be treated as keywords even when the corresponding type is not supported; I intend to deal with that in a followup patch. Tests are added for various functionality of the new types, mostly using type-generic headers. The tests use dg-add-options to pass any extra options needed to enable the types; this is wired up to use the same options as for __float128 on powerpc to enable _Float128 and _Float64x, and effective-target keywords for runtime support do the same hardware test as for __float128 to make sure the VSX instructions generated by those options are supported. (Corresponding additions would be needed for _Float16 on ARM as well if that were enabled with -mfp16-format=ieee required to use it rather than unconditionally available. Of course, -mfp16-format=alternative enables use of a format which is not compatible with the requirements of the _Float16 type.) C++ note: no support for the new types or constant suffixes is added for C++. C++ decimal floating-point support was very different from the C support, using class types, and the same may well apply to any future C++ bindings for IEEE interchange and extended types. There is a case, however, for supporting at least *f128 constants in C++, so that code using __float128 can use the newer style for constants throughout rather than needing to use the older *q constants in C++. Also, if built-in functions are added that may provide a way in which the types could leak into C++ code. Fortran note: the float128_type_node used in the Fortran front end is renamed to gfc_float128_type_node, since the semantics are different: in particular, if long double has binary128 format, then the new language-independent float128_type_node is a distinct type that also has binary128 format, but the Fortran node is expected to be NULL in that case. Likewise, Fortran's complex_float128_type_node is renamed to gfc_complex_float128_type_node. PowerPC note: the back end had an inconsistency that if TFmode was binary128, *q constants were TFmode instead of KFmode but __float128 was KFmode. This patch follows the same logic as for *q constants, so that _Float128 prefers TFmode (and __float128 becomes an alias for _Float128). ARM note: __fp16 is promoted to double (by convert_arguments) when passed without a prototype / in variable arguments. But this is only about the argument promotion; it is not handled as promoting in c-common.c:self_promoting_args_p / c-typeck.c:c_type_promotes_to, meaning that a K&R function definition for an argument of type __fp16 corresponds to a prototype with an argument of that type, not to one with an argument of type double, whereas a float argument in a K&R function definition corresponds to a double prototype argument - and the same functions are also what's involved in making va_arg give a warning and generate a call to abort when called with type float. This is preserved by this patch, while arranging for _Float16 not to be promoted when passed without a prototype / in variable arguments (the promotion of float being considered a legacy feature, not applied to any new types in C99 or later). TS 18661-3 extends the set of decimal floating-point types similarly, and adds new constant suffixes for the existing types, but this patch does not do anything regarding that extension. This patch does nothing regarding built-in functions, although type-generic functions such as __builtin_isinf work for the new types and associated tests are included. There are at least two levels of built-in function support possible for these types. The minimal level, implemented in <https://gcc.gnu.org/ml/gcc-patches/2016-06/msg01702.html> (which needs updating to use dg-add-options), adds built-in functions similar to those x86 has for __float128: __builtin_inf* __builtin_huge_val*, __builtin_nan*, __builtin_nans*, __builtin_fabs*, __builtin_copysign*. That would be sufficient for glibc to use the *f128 names for built-in functions by default with *q used only for backwards compatibility when using older GCC versions. That would also allow c_cpp_builtins's flag_building_libgcc code, defining __LIBGCC_%s_FUNC_EXT__, to use such suffixes rather than the present code hardcoding logic about target-specific constant suffixes and how those relate to function suffixes. Full built-in function support would cover the full range of built-in functions for existing floating-point types, adding variants for all the new types, except for a few obsolescent functions and non-type-generic variants of type-generic functions. Some but not all references to such functions in GCC use macros such as CASE_FLT_FN to be type-generic; a fair amount of work would be needed to identify all places to update. Adding all those functions would enable optimizations (for constant arguments and otherwise) for TS 18661-3 functions, but it would also substantially expand the enum listing built-in functions (and we've had problems with the size of that enum in the past), and increase the amount of built-in function initialization to do - I don't know what the startup cost involved in built-in function initialization is, but it would be something to consider when adding such a large set of functions. There are also a range of optimizations, in match.pd and elsewhere, that only operate on the three standard floating-point types. Ideally those would be made generic to all floating-point types, but this patch does nothing in that regard. Special care would be needed regarding making sure library functions to which calls are generated actually exist. For example, if sqrt is called on an argument of type _Float32, and the result converted to _Float32, this is equivalent to doing a square root operation directly on _Float32. But if the user's libm does not have the sqrtf32 function, or the name is not reserved because __STDC_WANT_IEC_60559_TYPES_EXT__ was not defined before including <math.h>, you can only do that optimization if you convert to a call to sqrtf instead. DECIMAL_DIG now relates to all supported floating-point formats, not just float, double and long double; I've raised the question with WG14 of how this relates to the formula for DECIMAL_DIG in C11 not considering this. TS 18661-3 says it also covers non-arithmetic formats only supported by library conversion functions; this patch does not add any target hooks to allow for the case where there are such formats wider than any supported for arithmetic types (where e.g. libc supports conversions involving the binary128 representation, but the _Float128 type is not supported). GCC provides its own <tgmath.h> for some targets. No attempt is made to adapt this to handle the new types. Nothing is done regarding debug info for the new types (see the "Debugger support for __float128 type?" thread on gcc@, Sep/Oct 2015). No __SIZEOF_*__ macros are added for the new types. Nothing is done with do_warn_double_promotion. Nothing is done to include the new types in those determining max_align_t, although properly it should be sufficiently aligned for any of those types. The logic for usual arithmetic conversions in c_common_type relies on TYPE_PRECISION for floating-point types, which is less than ideal (doesn't necessarily correspond to whether one type's values are subset of another); looking in more detail at the formats might be better. But since I included code in build_common_tree_nodes to work around rs6000 KFmode having precision 113 not 128, I think it should work. Ideally one might have errors in generic code for the case where the two types do not have one type's values a subset of the other (which is undefined behavior). But the only case where this can actually occur is mixing IBM long double with binary128 on powerpc, and rs6000_invalid_binary_op deals with that at present. TS 18661-3 does not fully specify the type resulting from the usual arithmetic conversions in the case where two _FloatNx types have the same set of values; I arranged the code to prefer the greater value of N in that case. The __FP_FAST_FMA* macros are not extended to cover the new types, since there are no corresponding built-in functions (if built-in fmafN, fmafNx are added, the macros should be extended, and the new macros documented). Also, only a limited set of modes is handled in mode_has_fma. Diagnostics relating to the use of the new types with -pedantic do not try to distinguish them from purely nonstandard types such as __int128 and constant suffixes such as *q. If you use an unsupported _FloatN / _FloatNx type you get a warning about the type defaulting to int after the warning about the type not being supported. That's less than ideal, but it's also a pre-existing condition if you use __int128 on a 32-bit system where it's unsupported. Bootstrapped with no regressions on x86_64-pc-linux-gnu. Other back-end changes minimally tested by building cc1 for ia64-linux-gnu, powerpc64le-linux-gnu, pdp11-none (the last failed for unrelated reasons). PR c/32187 gcc: * tree-core.h (TI_COMPLEX_FLOAT16_TYPE) (TI_COMPLEX_FLOATN_NX_TYPE_FIRST, TI_COMPLEX_FLOAT32_TYPE) (TI_COMPLEX_FLOAT64_TYPE, TI_COMPLEX_FLOAT128_TYPE) (TI_COMPLEX_FLOAT32X_TYPE, TI_COMPLEX_FLOAT64X_TYPE) (TI_COMPLEX_FLOAT128X_TYPE, TI_FLOAT16_TYPE, TI_FLOATN_TYPE_FIRST) (TI_FLOATN_NX_TYPE_FIRST, TI_FLOAT32_TYPE, TI_FLOAT64_TYPE) (TI_FLOAT128_TYPE, TI_FLOATN_TYPE_LAST, TI_FLOAT32X_TYPE) (TI_FLOATNX_TYPE_FIRST, TI_FLOAT64X_TYPE, TI_FLOAT128X_TYPE) (TI_FLOATNX_TYPE_LAST, TI_FLOATN_NX_TYPE_LAST): New enum tree_index values. (NUM_FLOATN_TYPES, NUM_FLOATNX_TYPES, NUM_FLOATN_NX_TYPES): New macros. (struct floatn_type_info): New structure type. (floatn_nx_types): New variable declaration. * tree.h (FLOATN_TYPE_NODE, FLOATN_NX_TYPE_NODE) (FLOATNX_TYPE_NODE, float128_type_node, float64x_type_node) (COMPLEX_FLOATN_NX_TYPE_NODE): New macros. * tree.c (floatn_nx_types): New variable. (build_common_tree_nodes): Initialize _FloatN, _FloatNx and corresponding complex types. * target.def (floatn_mode): New hook. * targhooks.c: Include "real.h". (default_floatn_mode): New function. * targhooks.h (default_floatn_mode): New prototype. * doc/extend.texi (Floating Types): Document _FloatN and _FloatNx types. * doc/sourcebuild.texi (float@var{n}, float@var{n}x): Document new effective-target and dg-add-options keywords. (float@var{n}_runtime, float@var{n}x_runtime, floatn_nx_runtime): Document new effective-target keywords. * doc/tm.texi.in (TARGET_FLOATN_MODE): New @hook. * doc/tm.texi: Regenerate. * ginclude/float.h (LDBL_DECIMAL_DIG): Define to __LDBL_DECIMAL_DIG__, not __DECIMAL_DIG__. [__STDC_WANT_IEC_60559_TYPES_EXT__]: Define macros from TS 18661-3. * real.h (struct real_format): Add field ieee_bits. * real.c (ieee_single_format, mips_single_format) (motorola_single_format, spu_single_format, ieee_double_format) (mips_double_format, motorola_double_format) (ieee_extended_motorola_format, ieee_extended_intel_96_format) (ieee_extended_intel_128_format) (ieee_extended_intel_96_round_53_format, ibm_extended_format) (mips_extended_format, ieee_quad_format, mips_quad_format) (vax_f_format, vax_d_format, vax_g_format, decimal_single_format) (decimal_double_format, decimal_quad_format, ieee_half_format) (arm_half_format, real_internal_format: Initialize ieee_bits field. * config/i386/i386.c (ix86_init_builtin_types): Do not initialize float128_type_node. Set float80_type_node to float64x_type_node if appropriate and long_double_type_node not appropriate. * config/ia64/ia64.c (ia64_init_builtins): Likewise. * config/pdp11/pdp11.c (pdp11_f_format, pdp11_d_format): Initialize ieee_bits field. * config/rs6000/rs6000.c (TARGET_FLOATN_MODE): New macro. (rs6000_init_builtins): Set ieee128_float_type_node to float128_type_node. (rs6000_floatn_mode): New function. gcc/c: * c-tree.h (cts_floatn_nx): New enum c_typespec_keyword value. (struct c_declspecs): Add field floatn_nx_idx. * c-decl.c (declspecs_add_type, finish_declspecs): Handle _FloatN and _FloatNx type specifiers. * c-parser.c (c_keyword_starts_typename, c_token_starts_declspecs) (c_parser_declspecs, c_parser_attribute_any_word) (c_parser_objc_selector): Use CASE_RID_FLOATN_NX. * c-typeck.c (c_common_type): Handle _FloatN and _FloatNx types. (convert_arguments): Avoid promoting _FloatN and _FloatNx types narrower than double. gcc/c-family: * c-common.h (RID_FLOAT16, RID_FLOATN_NX_FIRST, RID_FLOAT32) (RID_FLOAT64, RID_FLOAT128, RID_FLOAT32X, RID_FLOAT64X) (RID_FLOAT128X): New enum rid values. (CASE_RID_FLOATN_NX): New macro. * c-common.c (c_common_reswords): Add _FloatN and _FloatNx keywords. (c_common_type_for_mode): Check for _FloatN and _FloatNx and corresponding complex types. (c_common_nodes_and_builtins): For non-C++, register _FloatN and _FloatNx and corresponding complex types. (keyword_begins_type_specifier): Use CASE_RID_FLOATN_NX. * c-cppbuiltin.c (builtin_define_float_constants): Check _FloatN and _FloatNx types for the widest type for determining DECIMAL_DIG. Define __LDBL_DECIMAL_DIG__ as well as __DECIMAL_DIG__ for long double. Handle FMA_SUFFIX being NULL. (c_cpp_builtins): Call builtin_define_float_constants for _FloatN and _FloatNx types. * c-lex.c (interpret_float): Handle _FloatN and _FloatNx constants. * c-pretty-print.c (pp_c_floating_constant): Handle _FloatN and _FloatNx types. gcc/fortran: * trans-types.h (float128_type_node): Rename to gfc_float128_type_node. (complex_float128_type_node): Rename to gfc_complex_float128_type_node. * iso-c-binding.def, trans-intrinsic.c, trans-types.c: All users changed. gcc/testsuite: * lib/target-supports.exp (check_effective_target_float16) (check_effective_target_float32, check_effective_target_float64) (check_effective_target_float128, check_effective_target_float32x) (check_effective_target_float64x) (check_effective_target_float128x) (check_effective_target_float16_runtime) (check_effective_target_float32_runtime) (check_effective_target_float64_runtime) (check_effective_target_float128_runtime) (check_effective_target_float32x_runtime) (check_effective_target_float64x_runtime) (check_effective_target_float128x_runtime) (check_effective_target_floatn_nx_runtime) (add_options_for_float16, add_options_for_float32) (add_options_for_float64, add_options_for_float128) (add_options_for_float32x, add_options_for_float64x) (add_options_for_float128x): New procedures. * gcc.dg/dfp/floatn.c, gcc.dg/float128-typeof.c, gcc.dg/float128x-typeof.c, gcc.dg/float16-typeof.c, gcc.dg/float32-typeof.c, gcc.dg/float32x-typeof.c, gcc.dg/float64-typeof.c, gcc.dg/float64x-typeof.c, gcc.dg/floatn-arithconv.c, gcc.dg/floatn-errs.c, gcc.dg/floatn-typeof.h, gcc.dg/torture/float128-basic.c, gcc.dg/torture/float128-complex.c, gcc.dg/torture/float128-floath.c, gcc.dg/torture/float128-tg.c, gcc.dg/torture/float128x-basic.c, gcc.dg/torture/float128x-complex.c, gcc.dg/torture/float128x-floath.c, gcc.dg/torture/float128x-tg.c, gcc.dg/torture/float16-basic.c, gcc.dg/torture/float16-complex.c, gcc.dg/torture/float16-floath.c, gcc.dg/torture/float16-tg.c, gcc.dg/torture/float32-basic.c, gcc.dg/torture/float32-complex.c, gcc.dg/torture/float32-floath.c, gcc.dg/torture/float32-tg.c, gcc.dg/torture/float32x-basic.c, gcc.dg/torture/float32x-complex.c, gcc.dg/torture/float32x-floath.c, gcc.dg/torture/float32x-tg.c, gcc.dg/torture/float64-basic.c, gcc.dg/torture/float64-complex.c, gcc.dg/torture/float64-floath.c, gcc.dg/torture/float64-tg.c, gcc.dg/torture/float64x-basic.c, gcc.dg/torture/float64x-complex.c, gcc.dg/torture/float64x-floath.c, gcc.dg/torture/float64x-tg.c, gcc.dg/torture/floatn-basic.h, gcc.dg/torture/floatn-complex.h, gcc.dg/torture/floatn-convert.c, gcc.dg/torture/floatn-floath.h, gcc.dg/torture/floatn-tg.h, gcc.dg/torture/fp-int-convert-float128-ieee-timode.c, gcc.dg/torture/fp-int-convert-float128-ieee.c, gcc.dg/torture/fp-int-convert-float128x-timode.c, gcc.dg/torture/fp-int-convert-float128x.c, gcc.dg/torture/fp-int-convert-float16-timode.c, gcc.dg/torture/fp-int-convert-float16.c, gcc.dg/torture/fp-int-convert-float32-timode.c, gcc.dg/torture/fp-int-convert-float32.c, gcc.dg/torture/fp-int-convert-float32x-timode.c, gcc.dg/torture/fp-int-convert-float32x.c, gcc.dg/torture/fp-int-convert-float64-timode.c, gcc.dg/torture/fp-int-convert-float64.c, gcc.dg/torture/fp-int-convert-float64x-timode.c, gcc.dg/torture/fp-int-convert-float64x.c: New tests. * gcc.dg/torture/fp-int-convert.h (TEST_I_F): Add argument for maximum exponent of floating-point type. Use it in testing whether 0x8...0 fits in the floating-point type. Always treat -1 (signed 0xf...f) as fitting in the floating-point type. (M_OK1): New macro. * gcc.dg/torture/fp-int-convert-double.c, gcc.dg/torture/fp-int-convert-float.c, gcc.dg/torture/fp-int-convert-float128-timode.c, gcc.dg/torture/fp-int-convert-float128.c, gcc.dg/torture/fp-int-convert-float80-timode.c, gcc.dg/torture/fp-int-convert-float80.c, gcc.dg/torture/fp-int-convert-long-double.c, gcc.dg/torture/fp-int-convert-timode.c: Update calls to TEST_I_F. libcpp: * include/cpplib.h (CPP_N_FLOATN, CPP_N_FLOATNX) (CPP_N_WIDTH_FLOATN_NX, CPP_FLOATN_SHIFT, CPP_FLOATN_MAX): New macros. * expr.c (interpret_float_suffix): Handle fN, fNx, FN and FNx suffixes. From-SVN: r239625
2016-08-19 19:43:26 +02:00
size_t f, d, l, w, q, i, fn, fnx, fn_bits;
flags = 0;
Implement C _FloatN, _FloatNx types. ISO/IEC TS 18661-3:2015 defines C bindings to IEEE interchange and extended types, in the form of _FloatN and _FloatNx type names with corresponding fN/FN and fNx/FNx constant suffixes and FLTN_* / FLTNX_* <float.h> macros. This patch implements support for this feature in GCC. The _FloatN types, for N = 16, 32, 64 or >= 128 and a multiple of 32, are types encoded according to the corresponding IEEE interchange format (endianness unspecified; may use either the NaN conventions recommended in IEEE 754-2008, or the MIPS NaN conventions, since the choice of convention is only an IEEE recommendation, not a requirement). The _FloatNx types, for N = 32, 64 and 128, are IEEE "extended" types: types extending a narrower format with range and precision at least as big as those specified in IEEE 754 for each extended type (and with unspecified representation, but still following IEEE semantics for their values and operations - and with the set of values being determined by the precision and the maximum exponent, which means that while Intel "extended" is suitable for _Float64x, m68k "extended" is not). These types are always distinct from and not compatible with each other and the standard floating types float, double, long double; thus, double, _Float64 and _Float32x may all have the same ABI, but they are three still distinct types. The type names may be used with _Complex to construct corresponding complex types (unlike __float128, which acts more like a typedef name than a keyword - thus, this patch may be considered to fix PR c/32187). The new suffixes can be combined with GNU "i" and "j" suffixes for constants of complex types (e.g. 1.0if128, 2.0f64i). The set of types supported is implementation-defined. In this GCC patch, _Float32 is SFmode if that is suitable; _Float32x and _Float64 are DFmode if that is suitable; _Float128 is TFmode if that is suitable; _Float64x is XFmode if that is suitable, and otherwise TFmode if that is suitable. There is a target hook to override the choices if necessary. "Suitable" means both conforming to the requirements of that type, and supported as a scalar type including in libgcc. The ABI is whatever the back end does for scalars of that mode (but note that _Float32 is passed without promotion in variable arguments, unlike float). All the existing issues with exceptions and rounding modes for existing types apply equally to the new type names. No GCC port supports a floating-point format suitable for _Float128x. Although there is HFmode support for ARM and AArch64, use of that for _Float16 is not enabled. Supporting _Float16 would require additional work on the excess precision aspects of TS 18661-3: there are new values of FLT_EVAL_METHOD, which are not currently supported in GCC, and FLT_EVAL_METHOD == 0 now means that operations and constants on types narrower than float are evaluated to the range and precision of float. Implementing that, so that _Float16 gets evaluated with excess range and precision, would involve changes to the excess precision infrastructure so that the _Float16 case is enabled by default, unlike the x87 case which is only enabled for -fexcess-precision=standard. Other differences between _Float16 and __fp16 would also need to be disentangled. GCC has some prior support for nonstandard floating-point types in the form of __float80 and __float128. Where these were previously types distinct from long double, they are made by this patch into aliases for _Float64x / _Float128 if those types have the required properties. In principle the set of possible _FloatN types is infinite. This patch hardcodes the four such types for N <= 128, but with as much code as possible using loops over types to minimize the number of places with such hardcoding. I don't think it's likely any further such types will be of use in future (or indeed that formats suitable for _Float128x will actually be implemented). There is a corner case that all _FloatN, for N >= 128 and a multiple of 32, should be treated as keywords even when the corresponding type is not supported; I intend to deal with that in a followup patch. Tests are added for various functionality of the new types, mostly using type-generic headers. The tests use dg-add-options to pass any extra options needed to enable the types; this is wired up to use the same options as for __float128 on powerpc to enable _Float128 and _Float64x, and effective-target keywords for runtime support do the same hardware test as for __float128 to make sure the VSX instructions generated by those options are supported. (Corresponding additions would be needed for _Float16 on ARM as well if that were enabled with -mfp16-format=ieee required to use it rather than unconditionally available. Of course, -mfp16-format=alternative enables use of a format which is not compatible with the requirements of the _Float16 type.) C++ note: no support for the new types or constant suffixes is added for C++. C++ decimal floating-point support was very different from the C support, using class types, and the same may well apply to any future C++ bindings for IEEE interchange and extended types. There is a case, however, for supporting at least *f128 constants in C++, so that code using __float128 can use the newer style for constants throughout rather than needing to use the older *q constants in C++. Also, if built-in functions are added that may provide a way in which the types could leak into C++ code. Fortran note: the float128_type_node used in the Fortran front end is renamed to gfc_float128_type_node, since the semantics are different: in particular, if long double has binary128 format, then the new language-independent float128_type_node is a distinct type that also has binary128 format, but the Fortran node is expected to be NULL in that case. Likewise, Fortran's complex_float128_type_node is renamed to gfc_complex_float128_type_node. PowerPC note: the back end had an inconsistency that if TFmode was binary128, *q constants were TFmode instead of KFmode but __float128 was KFmode. This patch follows the same logic as for *q constants, so that _Float128 prefers TFmode (and __float128 becomes an alias for _Float128). ARM note: __fp16 is promoted to double (by convert_arguments) when passed without a prototype / in variable arguments. But this is only about the argument promotion; it is not handled as promoting in c-common.c:self_promoting_args_p / c-typeck.c:c_type_promotes_to, meaning that a K&R function definition for an argument of type __fp16 corresponds to a prototype with an argument of that type, not to one with an argument of type double, whereas a float argument in a K&R function definition corresponds to a double prototype argument - and the same functions are also what's involved in making va_arg give a warning and generate a call to abort when called with type float. This is preserved by this patch, while arranging for _Float16 not to be promoted when passed without a prototype / in variable arguments (the promotion of float being considered a legacy feature, not applied to any new types in C99 or later). TS 18661-3 extends the set of decimal floating-point types similarly, and adds new constant suffixes for the existing types, but this patch does not do anything regarding that extension. This patch does nothing regarding built-in functions, although type-generic functions such as __builtin_isinf work for the new types and associated tests are included. There are at least two levels of built-in function support possible for these types. The minimal level, implemented in <https://gcc.gnu.org/ml/gcc-patches/2016-06/msg01702.html> (which needs updating to use dg-add-options), adds built-in functions similar to those x86 has for __float128: __builtin_inf* __builtin_huge_val*, __builtin_nan*, __builtin_nans*, __builtin_fabs*, __builtin_copysign*. That would be sufficient for glibc to use the *f128 names for built-in functions by default with *q used only for backwards compatibility when using older GCC versions. That would also allow c_cpp_builtins's flag_building_libgcc code, defining __LIBGCC_%s_FUNC_EXT__, to use such suffixes rather than the present code hardcoding logic about target-specific constant suffixes and how those relate to function suffixes. Full built-in function support would cover the full range of built-in functions for existing floating-point types, adding variants for all the new types, except for a few obsolescent functions and non-type-generic variants of type-generic functions. Some but not all references to such functions in GCC use macros such as CASE_FLT_FN to be type-generic; a fair amount of work would be needed to identify all places to update. Adding all those functions would enable optimizations (for constant arguments and otherwise) for TS 18661-3 functions, but it would also substantially expand the enum listing built-in functions (and we've had problems with the size of that enum in the past), and increase the amount of built-in function initialization to do - I don't know what the startup cost involved in built-in function initialization is, but it would be something to consider when adding such a large set of functions. There are also a range of optimizations, in match.pd and elsewhere, that only operate on the three standard floating-point types. Ideally those would be made generic to all floating-point types, but this patch does nothing in that regard. Special care would be needed regarding making sure library functions to which calls are generated actually exist. For example, if sqrt is called on an argument of type _Float32, and the result converted to _Float32, this is equivalent to doing a square root operation directly on _Float32. But if the user's libm does not have the sqrtf32 function, or the name is not reserved because __STDC_WANT_IEC_60559_TYPES_EXT__ was not defined before including <math.h>, you can only do that optimization if you convert to a call to sqrtf instead. DECIMAL_DIG now relates to all supported floating-point formats, not just float, double and long double; I've raised the question with WG14 of how this relates to the formula for DECIMAL_DIG in C11 not considering this. TS 18661-3 says it also covers non-arithmetic formats only supported by library conversion functions; this patch does not add any target hooks to allow for the case where there are such formats wider than any supported for arithmetic types (where e.g. libc supports conversions involving the binary128 representation, but the _Float128 type is not supported). GCC provides its own <tgmath.h> for some targets. No attempt is made to adapt this to handle the new types. Nothing is done regarding debug info for the new types (see the "Debugger support for __float128 type?" thread on gcc@, Sep/Oct 2015). No __SIZEOF_*__ macros are added for the new types. Nothing is done with do_warn_double_promotion. Nothing is done to include the new types in those determining max_align_t, although properly it should be sufficiently aligned for any of those types. The logic for usual arithmetic conversions in c_common_type relies on TYPE_PRECISION for floating-point types, which is less than ideal (doesn't necessarily correspond to whether one type's values are subset of another); looking in more detail at the formats might be better. But since I included code in build_common_tree_nodes to work around rs6000 KFmode having precision 113 not 128, I think it should work. Ideally one might have errors in generic code for the case where the two types do not have one type's values a subset of the other (which is undefined behavior). But the only case where this can actually occur is mixing IBM long double with binary128 on powerpc, and rs6000_invalid_binary_op deals with that at present. TS 18661-3 does not fully specify the type resulting from the usual arithmetic conversions in the case where two _FloatNx types have the same set of values; I arranged the code to prefer the greater value of N in that case. The __FP_FAST_FMA* macros are not extended to cover the new types, since there are no corresponding built-in functions (if built-in fmafN, fmafNx are added, the macros should be extended, and the new macros documented). Also, only a limited set of modes is handled in mode_has_fma. Diagnostics relating to the use of the new types with -pedantic do not try to distinguish them from purely nonstandard types such as __int128 and constant suffixes such as *q. If you use an unsupported _FloatN / _FloatNx type you get a warning about the type defaulting to int after the warning about the type not being supported. That's less than ideal, but it's also a pre-existing condition if you use __int128 on a 32-bit system where it's unsupported. Bootstrapped with no regressions on x86_64-pc-linux-gnu. Other back-end changes minimally tested by building cc1 for ia64-linux-gnu, powerpc64le-linux-gnu, pdp11-none (the last failed for unrelated reasons). PR c/32187 gcc: * tree-core.h (TI_COMPLEX_FLOAT16_TYPE) (TI_COMPLEX_FLOATN_NX_TYPE_FIRST, TI_COMPLEX_FLOAT32_TYPE) (TI_COMPLEX_FLOAT64_TYPE, TI_COMPLEX_FLOAT128_TYPE) (TI_COMPLEX_FLOAT32X_TYPE, TI_COMPLEX_FLOAT64X_TYPE) (TI_COMPLEX_FLOAT128X_TYPE, TI_FLOAT16_TYPE, TI_FLOATN_TYPE_FIRST) (TI_FLOATN_NX_TYPE_FIRST, TI_FLOAT32_TYPE, TI_FLOAT64_TYPE) (TI_FLOAT128_TYPE, TI_FLOATN_TYPE_LAST, TI_FLOAT32X_TYPE) (TI_FLOATNX_TYPE_FIRST, TI_FLOAT64X_TYPE, TI_FLOAT128X_TYPE) (TI_FLOATNX_TYPE_LAST, TI_FLOATN_NX_TYPE_LAST): New enum tree_index values. (NUM_FLOATN_TYPES, NUM_FLOATNX_TYPES, NUM_FLOATN_NX_TYPES): New macros. (struct floatn_type_info): New structure type. (floatn_nx_types): New variable declaration. * tree.h (FLOATN_TYPE_NODE, FLOATN_NX_TYPE_NODE) (FLOATNX_TYPE_NODE, float128_type_node, float64x_type_node) (COMPLEX_FLOATN_NX_TYPE_NODE): New macros. * tree.c (floatn_nx_types): New variable. (build_common_tree_nodes): Initialize _FloatN, _FloatNx and corresponding complex types. * target.def (floatn_mode): New hook. * targhooks.c: Include "real.h". (default_floatn_mode): New function. * targhooks.h (default_floatn_mode): New prototype. * doc/extend.texi (Floating Types): Document _FloatN and _FloatNx types. * doc/sourcebuild.texi (float@var{n}, float@var{n}x): Document new effective-target and dg-add-options keywords. (float@var{n}_runtime, float@var{n}x_runtime, floatn_nx_runtime): Document new effective-target keywords. * doc/tm.texi.in (TARGET_FLOATN_MODE): New @hook. * doc/tm.texi: Regenerate. * ginclude/float.h (LDBL_DECIMAL_DIG): Define to __LDBL_DECIMAL_DIG__, not __DECIMAL_DIG__. [__STDC_WANT_IEC_60559_TYPES_EXT__]: Define macros from TS 18661-3. * real.h (struct real_format): Add field ieee_bits. * real.c (ieee_single_format, mips_single_format) (motorola_single_format, spu_single_format, ieee_double_format) (mips_double_format, motorola_double_format) (ieee_extended_motorola_format, ieee_extended_intel_96_format) (ieee_extended_intel_128_format) (ieee_extended_intel_96_round_53_format, ibm_extended_format) (mips_extended_format, ieee_quad_format, mips_quad_format) (vax_f_format, vax_d_format, vax_g_format, decimal_single_format) (decimal_double_format, decimal_quad_format, ieee_half_format) (arm_half_format, real_internal_format: Initialize ieee_bits field. * config/i386/i386.c (ix86_init_builtin_types): Do not initialize float128_type_node. Set float80_type_node to float64x_type_node if appropriate and long_double_type_node not appropriate. * config/ia64/ia64.c (ia64_init_builtins): Likewise. * config/pdp11/pdp11.c (pdp11_f_format, pdp11_d_format): Initialize ieee_bits field. * config/rs6000/rs6000.c (TARGET_FLOATN_MODE): New macro. (rs6000_init_builtins): Set ieee128_float_type_node to float128_type_node. (rs6000_floatn_mode): New function. gcc/c: * c-tree.h (cts_floatn_nx): New enum c_typespec_keyword value. (struct c_declspecs): Add field floatn_nx_idx. * c-decl.c (declspecs_add_type, finish_declspecs): Handle _FloatN and _FloatNx type specifiers. * c-parser.c (c_keyword_starts_typename, c_token_starts_declspecs) (c_parser_declspecs, c_parser_attribute_any_word) (c_parser_objc_selector): Use CASE_RID_FLOATN_NX. * c-typeck.c (c_common_type): Handle _FloatN and _FloatNx types. (convert_arguments): Avoid promoting _FloatN and _FloatNx types narrower than double. gcc/c-family: * c-common.h (RID_FLOAT16, RID_FLOATN_NX_FIRST, RID_FLOAT32) (RID_FLOAT64, RID_FLOAT128, RID_FLOAT32X, RID_FLOAT64X) (RID_FLOAT128X): New enum rid values. (CASE_RID_FLOATN_NX): New macro. * c-common.c (c_common_reswords): Add _FloatN and _FloatNx keywords. (c_common_type_for_mode): Check for _FloatN and _FloatNx and corresponding complex types. (c_common_nodes_and_builtins): For non-C++, register _FloatN and _FloatNx and corresponding complex types. (keyword_begins_type_specifier): Use CASE_RID_FLOATN_NX. * c-cppbuiltin.c (builtin_define_float_constants): Check _FloatN and _FloatNx types for the widest type for determining DECIMAL_DIG. Define __LDBL_DECIMAL_DIG__ as well as __DECIMAL_DIG__ for long double. Handle FMA_SUFFIX being NULL. (c_cpp_builtins): Call builtin_define_float_constants for _FloatN and _FloatNx types. * c-lex.c (interpret_float): Handle _FloatN and _FloatNx constants. * c-pretty-print.c (pp_c_floating_constant): Handle _FloatN and _FloatNx types. gcc/fortran: * trans-types.h (float128_type_node): Rename to gfc_float128_type_node. (complex_float128_type_node): Rename to gfc_complex_float128_type_node. * iso-c-binding.def, trans-intrinsic.c, trans-types.c: All users changed. gcc/testsuite: * lib/target-supports.exp (check_effective_target_float16) (check_effective_target_float32, check_effective_target_float64) (check_effective_target_float128, check_effective_target_float32x) (check_effective_target_float64x) (check_effective_target_float128x) (check_effective_target_float16_runtime) (check_effective_target_float32_runtime) (check_effective_target_float64_runtime) (check_effective_target_float128_runtime) (check_effective_target_float32x_runtime) (check_effective_target_float64x_runtime) (check_effective_target_float128x_runtime) (check_effective_target_floatn_nx_runtime) (add_options_for_float16, add_options_for_float32) (add_options_for_float64, add_options_for_float128) (add_options_for_float32x, add_options_for_float64x) (add_options_for_float128x): New procedures. * gcc.dg/dfp/floatn.c, gcc.dg/float128-typeof.c, gcc.dg/float128x-typeof.c, gcc.dg/float16-typeof.c, gcc.dg/float32-typeof.c, gcc.dg/float32x-typeof.c, gcc.dg/float64-typeof.c, gcc.dg/float64x-typeof.c, gcc.dg/floatn-arithconv.c, gcc.dg/floatn-errs.c, gcc.dg/floatn-typeof.h, gcc.dg/torture/float128-basic.c, gcc.dg/torture/float128-complex.c, gcc.dg/torture/float128-floath.c, gcc.dg/torture/float128-tg.c, gcc.dg/torture/float128x-basic.c, gcc.dg/torture/float128x-complex.c, gcc.dg/torture/float128x-floath.c, gcc.dg/torture/float128x-tg.c, gcc.dg/torture/float16-basic.c, gcc.dg/torture/float16-complex.c, gcc.dg/torture/float16-floath.c, gcc.dg/torture/float16-tg.c, gcc.dg/torture/float32-basic.c, gcc.dg/torture/float32-complex.c, gcc.dg/torture/float32-floath.c, gcc.dg/torture/float32-tg.c, gcc.dg/torture/float32x-basic.c, gcc.dg/torture/float32x-complex.c, gcc.dg/torture/float32x-floath.c, gcc.dg/torture/float32x-tg.c, gcc.dg/torture/float64-basic.c, gcc.dg/torture/float64-complex.c, gcc.dg/torture/float64-floath.c, gcc.dg/torture/float64-tg.c, gcc.dg/torture/float64x-basic.c, gcc.dg/torture/float64x-complex.c, gcc.dg/torture/float64x-floath.c, gcc.dg/torture/float64x-tg.c, gcc.dg/torture/floatn-basic.h, gcc.dg/torture/floatn-complex.h, gcc.dg/torture/floatn-convert.c, gcc.dg/torture/floatn-floath.h, gcc.dg/torture/floatn-tg.h, gcc.dg/torture/fp-int-convert-float128-ieee-timode.c, gcc.dg/torture/fp-int-convert-float128-ieee.c, gcc.dg/torture/fp-int-convert-float128x-timode.c, gcc.dg/torture/fp-int-convert-float128x.c, gcc.dg/torture/fp-int-convert-float16-timode.c, gcc.dg/torture/fp-int-convert-float16.c, gcc.dg/torture/fp-int-convert-float32-timode.c, gcc.dg/torture/fp-int-convert-float32.c, gcc.dg/torture/fp-int-convert-float32x-timode.c, gcc.dg/torture/fp-int-convert-float32x.c, gcc.dg/torture/fp-int-convert-float64-timode.c, gcc.dg/torture/fp-int-convert-float64.c, gcc.dg/torture/fp-int-convert-float64x-timode.c, gcc.dg/torture/fp-int-convert-float64x.c: New tests. * gcc.dg/torture/fp-int-convert.h (TEST_I_F): Add argument for maximum exponent of floating-point type. Use it in testing whether 0x8...0 fits in the floating-point type. Always treat -1 (signed 0xf...f) as fitting in the floating-point type. (M_OK1): New macro. * gcc.dg/torture/fp-int-convert-double.c, gcc.dg/torture/fp-int-convert-float.c, gcc.dg/torture/fp-int-convert-float128-timode.c, gcc.dg/torture/fp-int-convert-float128.c, gcc.dg/torture/fp-int-convert-float80-timode.c, gcc.dg/torture/fp-int-convert-float80.c, gcc.dg/torture/fp-int-convert-long-double.c, gcc.dg/torture/fp-int-convert-timode.c: Update calls to TEST_I_F. libcpp: * include/cpplib.h (CPP_N_FLOATN, CPP_N_FLOATNX) (CPP_N_WIDTH_FLOATN_NX, CPP_FLOATN_SHIFT, CPP_FLOATN_MAX): New macros. * expr.c (interpret_float_suffix): Handle fN, fNx, FN and FNx suffixes. From-SVN: r239625
2016-08-19 19:43:26 +02:00
f = d = l = w = q = i = fn = fnx = fn_bits = 0;
/* The following decimal float suffixes, from TR 24732:2009 and TS
18661-2:2015, are supported:
df, DF - _Decimal32.
dd, DD - _Decimal64.
dl, DL - _Decimal128.
The dN and DN suffixes for _DecimalN, and dNx and DNx for
_DecimalNx, defined in TS 18661-3:2015, are not supported.
Fixed-point suffixes, from TR 18037:2008, are supported. They
consist of three parts, in order:
(i) An optional u or U, for unsigned types.
(ii) An optional h or H, for short types, or l or L, for long
types, or ll or LL, for long long types. Use of ll or LL is a
GNU extension.
(iii) r or R, for _Fract types, or k or K, for _Accum types.
Otherwise the suffix is for a binary or standard floating-point
type. Such a suffix, or the absence of a suffix, may be preceded
or followed by i, I, j or J, to indicate an imaginary number with
the corresponding complex type. The following suffixes for
binary or standard floating-point types are supported:
f, F - float (ISO C and C++).
l, L - long double (ISO C and C++).
d, D - double, even with the FLOAT_CONST_DECIMAL64 pragma in
operation (from TR 24732:2009; the pragma and the suffix
are not included in TS 18661-2:2015).
w, W - machine-specific type such as __float80 (GNU extension).
q, Q - machine-specific type such as __float128 (GNU extension).
fN, FN - _FloatN (TS 18661-3:2015).
fNx, FNx - _FloatNx (TS 18661-3:2015). */
/* Process decimal float suffixes, which are two letters starting
with d or D. Order and case are significant. */
if (len == 2 && (*s == 'd' || *s == 'D'))
{
bool uppercase = (*s == 'D');
switch (s[1])
{
case 'f': return (!uppercase ? (CPP_N_DFLOAT | CPP_N_SMALL): 0); break;
case 'F': return (uppercase ? (CPP_N_DFLOAT | CPP_N_SMALL) : 0); break;
case 'd': return (!uppercase ? (CPP_N_DFLOAT | CPP_N_MEDIUM): 0); break;
case 'D': return (uppercase ? (CPP_N_DFLOAT | CPP_N_MEDIUM) : 0); break;
case 'l': return (!uppercase ? (CPP_N_DFLOAT | CPP_N_LARGE) : 0); break;
case 'L': return (uppercase ? (CPP_N_DFLOAT | CPP_N_LARGE) : 0); break;
default:
/* Additional two-character suffixes beginning with D are not
for decimal float constants. */
break;
}
}
if (CPP_OPTION (pfile, ext_numeric_literals))
{
/* Recognize a fixed-point suffix. */
if (len != 0)
switch (s[len-1])
{
case 'k': case 'K': flags = CPP_N_ACCUM; break;
case 'r': case 'R': flags = CPP_N_FRACT; break;
default: break;
}
/* Continue processing a fixed-point suffix. The suffix is case
insensitive except for ll or LL. Order is significant. */
if (flags)
{
if (len == 1)
return flags;
len--;
if (*s == 'u' || *s == 'U')
{
flags |= CPP_N_UNSIGNED;
if (len == 1)
return flags;
len--;
s++;
}
switch (*s)
{
case 'h': case 'H':
if (len == 1)
return flags |= CPP_N_SMALL;
break;
case 'l':
if (len == 1)
return flags |= CPP_N_MEDIUM;
if (len == 2 && s[1] == 'l')
return flags |= CPP_N_LARGE;
break;
case 'L':
if (len == 1)
return flags |= CPP_N_MEDIUM;
if (len == 2 && s[1] == 'L')
return flags |= CPP_N_LARGE;
break;
default:
break;
}
/* Anything left at this point is invalid. */
return 0;
}
}
/* In any remaining valid suffix, the case and order don't matter. */
while (len--)
Implement C _FloatN, _FloatNx types. ISO/IEC TS 18661-3:2015 defines C bindings to IEEE interchange and extended types, in the form of _FloatN and _FloatNx type names with corresponding fN/FN and fNx/FNx constant suffixes and FLTN_* / FLTNX_* <float.h> macros. This patch implements support for this feature in GCC. The _FloatN types, for N = 16, 32, 64 or >= 128 and a multiple of 32, are types encoded according to the corresponding IEEE interchange format (endianness unspecified; may use either the NaN conventions recommended in IEEE 754-2008, or the MIPS NaN conventions, since the choice of convention is only an IEEE recommendation, not a requirement). The _FloatNx types, for N = 32, 64 and 128, are IEEE "extended" types: types extending a narrower format with range and precision at least as big as those specified in IEEE 754 for each extended type (and with unspecified representation, but still following IEEE semantics for their values and operations - and with the set of values being determined by the precision and the maximum exponent, which means that while Intel "extended" is suitable for _Float64x, m68k "extended" is not). These types are always distinct from and not compatible with each other and the standard floating types float, double, long double; thus, double, _Float64 and _Float32x may all have the same ABI, but they are three still distinct types. The type names may be used with _Complex to construct corresponding complex types (unlike __float128, which acts more like a typedef name than a keyword - thus, this patch may be considered to fix PR c/32187). The new suffixes can be combined with GNU "i" and "j" suffixes for constants of complex types (e.g. 1.0if128, 2.0f64i). The set of types supported is implementation-defined. In this GCC patch, _Float32 is SFmode if that is suitable; _Float32x and _Float64 are DFmode if that is suitable; _Float128 is TFmode if that is suitable; _Float64x is XFmode if that is suitable, and otherwise TFmode if that is suitable. There is a target hook to override the choices if necessary. "Suitable" means both conforming to the requirements of that type, and supported as a scalar type including in libgcc. The ABI is whatever the back end does for scalars of that mode (but note that _Float32 is passed without promotion in variable arguments, unlike float). All the existing issues with exceptions and rounding modes for existing types apply equally to the new type names. No GCC port supports a floating-point format suitable for _Float128x. Although there is HFmode support for ARM and AArch64, use of that for _Float16 is not enabled. Supporting _Float16 would require additional work on the excess precision aspects of TS 18661-3: there are new values of FLT_EVAL_METHOD, which are not currently supported in GCC, and FLT_EVAL_METHOD == 0 now means that operations and constants on types narrower than float are evaluated to the range and precision of float. Implementing that, so that _Float16 gets evaluated with excess range and precision, would involve changes to the excess precision infrastructure so that the _Float16 case is enabled by default, unlike the x87 case which is only enabled for -fexcess-precision=standard. Other differences between _Float16 and __fp16 would also need to be disentangled. GCC has some prior support for nonstandard floating-point types in the form of __float80 and __float128. Where these were previously types distinct from long double, they are made by this patch into aliases for _Float64x / _Float128 if those types have the required properties. In principle the set of possible _FloatN types is infinite. This patch hardcodes the four such types for N <= 128, but with as much code as possible using loops over types to minimize the number of places with such hardcoding. I don't think it's likely any further such types will be of use in future (or indeed that formats suitable for _Float128x will actually be implemented). There is a corner case that all _FloatN, for N >= 128 and a multiple of 32, should be treated as keywords even when the corresponding type is not supported; I intend to deal with that in a followup patch. Tests are added for various functionality of the new types, mostly using type-generic headers. The tests use dg-add-options to pass any extra options needed to enable the types; this is wired up to use the same options as for __float128 on powerpc to enable _Float128 and _Float64x, and effective-target keywords for runtime support do the same hardware test as for __float128 to make sure the VSX instructions generated by those options are supported. (Corresponding additions would be needed for _Float16 on ARM as well if that were enabled with -mfp16-format=ieee required to use it rather than unconditionally available. Of course, -mfp16-format=alternative enables use of a format which is not compatible with the requirements of the _Float16 type.) C++ note: no support for the new types or constant suffixes is added for C++. C++ decimal floating-point support was very different from the C support, using class types, and the same may well apply to any future C++ bindings for IEEE interchange and extended types. There is a case, however, for supporting at least *f128 constants in C++, so that code using __float128 can use the newer style for constants throughout rather than needing to use the older *q constants in C++. Also, if built-in functions are added that may provide a way in which the types could leak into C++ code. Fortran note: the float128_type_node used in the Fortran front end is renamed to gfc_float128_type_node, since the semantics are different: in particular, if long double has binary128 format, then the new language-independent float128_type_node is a distinct type that also has binary128 format, but the Fortran node is expected to be NULL in that case. Likewise, Fortran's complex_float128_type_node is renamed to gfc_complex_float128_type_node. PowerPC note: the back end had an inconsistency that if TFmode was binary128, *q constants were TFmode instead of KFmode but __float128 was KFmode. This patch follows the same logic as for *q constants, so that _Float128 prefers TFmode (and __float128 becomes an alias for _Float128). ARM note: __fp16 is promoted to double (by convert_arguments) when passed without a prototype / in variable arguments. But this is only about the argument promotion; it is not handled as promoting in c-common.c:self_promoting_args_p / c-typeck.c:c_type_promotes_to, meaning that a K&R function definition for an argument of type __fp16 corresponds to a prototype with an argument of that type, not to one with an argument of type double, whereas a float argument in a K&R function definition corresponds to a double prototype argument - and the same functions are also what's involved in making va_arg give a warning and generate a call to abort when called with type float. This is preserved by this patch, while arranging for _Float16 not to be promoted when passed without a prototype / in variable arguments (the promotion of float being considered a legacy feature, not applied to any new types in C99 or later). TS 18661-3 extends the set of decimal floating-point types similarly, and adds new constant suffixes for the existing types, but this patch does not do anything regarding that extension. This patch does nothing regarding built-in functions, although type-generic functions such as __builtin_isinf work for the new types and associated tests are included. There are at least two levels of built-in function support possible for these types. The minimal level, implemented in <https://gcc.gnu.org/ml/gcc-patches/2016-06/msg01702.html> (which needs updating to use dg-add-options), adds built-in functions similar to those x86 has for __float128: __builtin_inf* __builtin_huge_val*, __builtin_nan*, __builtin_nans*, __builtin_fabs*, __builtin_copysign*. That would be sufficient for glibc to use the *f128 names for built-in functions by default with *q used only for backwards compatibility when using older GCC versions. That would also allow c_cpp_builtins's flag_building_libgcc code, defining __LIBGCC_%s_FUNC_EXT__, to use such suffixes rather than the present code hardcoding logic about target-specific constant suffixes and how those relate to function suffixes. Full built-in function support would cover the full range of built-in functions for existing floating-point types, adding variants for all the new types, except for a few obsolescent functions and non-type-generic variants of type-generic functions. Some but not all references to such functions in GCC use macros such as CASE_FLT_FN to be type-generic; a fair amount of work would be needed to identify all places to update. Adding all those functions would enable optimizations (for constant arguments and otherwise) for TS 18661-3 functions, but it would also substantially expand the enum listing built-in functions (and we've had problems with the size of that enum in the past), and increase the amount of built-in function initialization to do - I don't know what the startup cost involved in built-in function initialization is, but it would be something to consider when adding such a large set of functions. There are also a range of optimizations, in match.pd and elsewhere, that only operate on the three standard floating-point types. Ideally those would be made generic to all floating-point types, but this patch does nothing in that regard. Special care would be needed regarding making sure library functions to which calls are generated actually exist. For example, if sqrt is called on an argument of type _Float32, and the result converted to _Float32, this is equivalent to doing a square root operation directly on _Float32. But if the user's libm does not have the sqrtf32 function, or the name is not reserved because __STDC_WANT_IEC_60559_TYPES_EXT__ was not defined before including <math.h>, you can only do that optimization if you convert to a call to sqrtf instead. DECIMAL_DIG now relates to all supported floating-point formats, not just float, double and long double; I've raised the question with WG14 of how this relates to the formula for DECIMAL_DIG in C11 not considering this. TS 18661-3 says it also covers non-arithmetic formats only supported by library conversion functions; this patch does not add any target hooks to allow for the case where there are such formats wider than any supported for arithmetic types (where e.g. libc supports conversions involving the binary128 representation, but the _Float128 type is not supported). GCC provides its own <tgmath.h> for some targets. No attempt is made to adapt this to handle the new types. Nothing is done regarding debug info for the new types (see the "Debugger support for __float128 type?" thread on gcc@, Sep/Oct 2015). No __SIZEOF_*__ macros are added for the new types. Nothing is done with do_warn_double_promotion. Nothing is done to include the new types in those determining max_align_t, although properly it should be sufficiently aligned for any of those types. The logic for usual arithmetic conversions in c_common_type relies on TYPE_PRECISION for floating-point types, which is less than ideal (doesn't necessarily correspond to whether one type's values are subset of another); looking in more detail at the formats might be better. But since I included code in build_common_tree_nodes to work around rs6000 KFmode having precision 113 not 128, I think it should work. Ideally one might have errors in generic code for the case where the two types do not have one type's values a subset of the other (which is undefined behavior). But the only case where this can actually occur is mixing IBM long double with binary128 on powerpc, and rs6000_invalid_binary_op deals with that at present. TS 18661-3 does not fully specify the type resulting from the usual arithmetic conversions in the case where two _FloatNx types have the same set of values; I arranged the code to prefer the greater value of N in that case. The __FP_FAST_FMA* macros are not extended to cover the new types, since there are no corresponding built-in functions (if built-in fmafN, fmafNx are added, the macros should be extended, and the new macros documented). Also, only a limited set of modes is handled in mode_has_fma. Diagnostics relating to the use of the new types with -pedantic do not try to distinguish them from purely nonstandard types such as __int128 and constant suffixes such as *q. If you use an unsupported _FloatN / _FloatNx type you get a warning about the type defaulting to int after the warning about the type not being supported. That's less than ideal, but it's also a pre-existing condition if you use __int128 on a 32-bit system where it's unsupported. Bootstrapped with no regressions on x86_64-pc-linux-gnu. Other back-end changes minimally tested by building cc1 for ia64-linux-gnu, powerpc64le-linux-gnu, pdp11-none (the last failed for unrelated reasons). PR c/32187 gcc: * tree-core.h (TI_COMPLEX_FLOAT16_TYPE) (TI_COMPLEX_FLOATN_NX_TYPE_FIRST, TI_COMPLEX_FLOAT32_TYPE) (TI_COMPLEX_FLOAT64_TYPE, TI_COMPLEX_FLOAT128_TYPE) (TI_COMPLEX_FLOAT32X_TYPE, TI_COMPLEX_FLOAT64X_TYPE) (TI_COMPLEX_FLOAT128X_TYPE, TI_FLOAT16_TYPE, TI_FLOATN_TYPE_FIRST) (TI_FLOATN_NX_TYPE_FIRST, TI_FLOAT32_TYPE, TI_FLOAT64_TYPE) (TI_FLOAT128_TYPE, TI_FLOATN_TYPE_LAST, TI_FLOAT32X_TYPE) (TI_FLOATNX_TYPE_FIRST, TI_FLOAT64X_TYPE, TI_FLOAT128X_TYPE) (TI_FLOATNX_TYPE_LAST, TI_FLOATN_NX_TYPE_LAST): New enum tree_index values. (NUM_FLOATN_TYPES, NUM_FLOATNX_TYPES, NUM_FLOATN_NX_TYPES): New macros. (struct floatn_type_info): New structure type. (floatn_nx_types): New variable declaration. * tree.h (FLOATN_TYPE_NODE, FLOATN_NX_TYPE_NODE) (FLOATNX_TYPE_NODE, float128_type_node, float64x_type_node) (COMPLEX_FLOATN_NX_TYPE_NODE): New macros. * tree.c (floatn_nx_types): New variable. (build_common_tree_nodes): Initialize _FloatN, _FloatNx and corresponding complex types. * target.def (floatn_mode): New hook. * targhooks.c: Include "real.h". (default_floatn_mode): New function. * targhooks.h (default_floatn_mode): New prototype. * doc/extend.texi (Floating Types): Document _FloatN and _FloatNx types. * doc/sourcebuild.texi (float@var{n}, float@var{n}x): Document new effective-target and dg-add-options keywords. (float@var{n}_runtime, float@var{n}x_runtime, floatn_nx_runtime): Document new effective-target keywords. * doc/tm.texi.in (TARGET_FLOATN_MODE): New @hook. * doc/tm.texi: Regenerate. * ginclude/float.h (LDBL_DECIMAL_DIG): Define to __LDBL_DECIMAL_DIG__, not __DECIMAL_DIG__. [__STDC_WANT_IEC_60559_TYPES_EXT__]: Define macros from TS 18661-3. * real.h (struct real_format): Add field ieee_bits. * real.c (ieee_single_format, mips_single_format) (motorola_single_format, spu_single_format, ieee_double_format) (mips_double_format, motorola_double_format) (ieee_extended_motorola_format, ieee_extended_intel_96_format) (ieee_extended_intel_128_format) (ieee_extended_intel_96_round_53_format, ibm_extended_format) (mips_extended_format, ieee_quad_format, mips_quad_format) (vax_f_format, vax_d_format, vax_g_format, decimal_single_format) (decimal_double_format, decimal_quad_format, ieee_half_format) (arm_half_format, real_internal_format: Initialize ieee_bits field. * config/i386/i386.c (ix86_init_builtin_types): Do not initialize float128_type_node. Set float80_type_node to float64x_type_node if appropriate and long_double_type_node not appropriate. * config/ia64/ia64.c (ia64_init_builtins): Likewise. * config/pdp11/pdp11.c (pdp11_f_format, pdp11_d_format): Initialize ieee_bits field. * config/rs6000/rs6000.c (TARGET_FLOATN_MODE): New macro. (rs6000_init_builtins): Set ieee128_float_type_node to float128_type_node. (rs6000_floatn_mode): New function. gcc/c: * c-tree.h (cts_floatn_nx): New enum c_typespec_keyword value. (struct c_declspecs): Add field floatn_nx_idx. * c-decl.c (declspecs_add_type, finish_declspecs): Handle _FloatN and _FloatNx type specifiers. * c-parser.c (c_keyword_starts_typename, c_token_starts_declspecs) (c_parser_declspecs, c_parser_attribute_any_word) (c_parser_objc_selector): Use CASE_RID_FLOATN_NX. * c-typeck.c (c_common_type): Handle _FloatN and _FloatNx types. (convert_arguments): Avoid promoting _FloatN and _FloatNx types narrower than double. gcc/c-family: * c-common.h (RID_FLOAT16, RID_FLOATN_NX_FIRST, RID_FLOAT32) (RID_FLOAT64, RID_FLOAT128, RID_FLOAT32X, RID_FLOAT64X) (RID_FLOAT128X): New enum rid values. (CASE_RID_FLOATN_NX): New macro. * c-common.c (c_common_reswords): Add _FloatN and _FloatNx keywords. (c_common_type_for_mode): Check for _FloatN and _FloatNx and corresponding complex types. (c_common_nodes_and_builtins): For non-C++, register _FloatN and _FloatNx and corresponding complex types. (keyword_begins_type_specifier): Use CASE_RID_FLOATN_NX. * c-cppbuiltin.c (builtin_define_float_constants): Check _FloatN and _FloatNx types for the widest type for determining DECIMAL_DIG. Define __LDBL_DECIMAL_DIG__ as well as __DECIMAL_DIG__ for long double. Handle FMA_SUFFIX being NULL. (c_cpp_builtins): Call builtin_define_float_constants for _FloatN and _FloatNx types. * c-lex.c (interpret_float): Handle _FloatN and _FloatNx constants. * c-pretty-print.c (pp_c_floating_constant): Handle _FloatN and _FloatNx types. gcc/fortran: * trans-types.h (float128_type_node): Rename to gfc_float128_type_node. (complex_float128_type_node): Rename to gfc_complex_float128_type_node. * iso-c-binding.def, trans-intrinsic.c, trans-types.c: All users changed. gcc/testsuite: * lib/target-supports.exp (check_effective_target_float16) (check_effective_target_float32, check_effective_target_float64) (check_effective_target_float128, check_effective_target_float32x) (check_effective_target_float64x) (check_effective_target_float128x) (check_effective_target_float16_runtime) (check_effective_target_float32_runtime) (check_effective_target_float64_runtime) (check_effective_target_float128_runtime) (check_effective_target_float32x_runtime) (check_effective_target_float64x_runtime) (check_effective_target_float128x_runtime) (check_effective_target_floatn_nx_runtime) (add_options_for_float16, add_options_for_float32) (add_options_for_float64, add_options_for_float128) (add_options_for_float32x, add_options_for_float64x) (add_options_for_float128x): New procedures. * gcc.dg/dfp/floatn.c, gcc.dg/float128-typeof.c, gcc.dg/float128x-typeof.c, gcc.dg/float16-typeof.c, gcc.dg/float32-typeof.c, gcc.dg/float32x-typeof.c, gcc.dg/float64-typeof.c, gcc.dg/float64x-typeof.c, gcc.dg/floatn-arithconv.c, gcc.dg/floatn-errs.c, gcc.dg/floatn-typeof.h, gcc.dg/torture/float128-basic.c, gcc.dg/torture/float128-complex.c, gcc.dg/torture/float128-floath.c, gcc.dg/torture/float128-tg.c, gcc.dg/torture/float128x-basic.c, gcc.dg/torture/float128x-complex.c, gcc.dg/torture/float128x-floath.c, gcc.dg/torture/float128x-tg.c, gcc.dg/torture/float16-basic.c, gcc.dg/torture/float16-complex.c, gcc.dg/torture/float16-floath.c, gcc.dg/torture/float16-tg.c, gcc.dg/torture/float32-basic.c, gcc.dg/torture/float32-complex.c, gcc.dg/torture/float32-floath.c, gcc.dg/torture/float32-tg.c, gcc.dg/torture/float32x-basic.c, gcc.dg/torture/float32x-complex.c, gcc.dg/torture/float32x-floath.c, gcc.dg/torture/float32x-tg.c, gcc.dg/torture/float64-basic.c, gcc.dg/torture/float64-complex.c, gcc.dg/torture/float64-floath.c, gcc.dg/torture/float64-tg.c, gcc.dg/torture/float64x-basic.c, gcc.dg/torture/float64x-complex.c, gcc.dg/torture/float64x-floath.c, gcc.dg/torture/float64x-tg.c, gcc.dg/torture/floatn-basic.h, gcc.dg/torture/floatn-complex.h, gcc.dg/torture/floatn-convert.c, gcc.dg/torture/floatn-floath.h, gcc.dg/torture/floatn-tg.h, gcc.dg/torture/fp-int-convert-float128-ieee-timode.c, gcc.dg/torture/fp-int-convert-float128-ieee.c, gcc.dg/torture/fp-int-convert-float128x-timode.c, gcc.dg/torture/fp-int-convert-float128x.c, gcc.dg/torture/fp-int-convert-float16-timode.c, gcc.dg/torture/fp-int-convert-float16.c, gcc.dg/torture/fp-int-convert-float32-timode.c, gcc.dg/torture/fp-int-convert-float32.c, gcc.dg/torture/fp-int-convert-float32x-timode.c, gcc.dg/torture/fp-int-convert-float32x.c, gcc.dg/torture/fp-int-convert-float64-timode.c, gcc.dg/torture/fp-int-convert-float64.c, gcc.dg/torture/fp-int-convert-float64x-timode.c, gcc.dg/torture/fp-int-convert-float64x.c: New tests. * gcc.dg/torture/fp-int-convert.h (TEST_I_F): Add argument for maximum exponent of floating-point type. Use it in testing whether 0x8...0 fits in the floating-point type. Always treat -1 (signed 0xf...f) as fitting in the floating-point type. (M_OK1): New macro. * gcc.dg/torture/fp-int-convert-double.c, gcc.dg/torture/fp-int-convert-float.c, gcc.dg/torture/fp-int-convert-float128-timode.c, gcc.dg/torture/fp-int-convert-float128.c, gcc.dg/torture/fp-int-convert-float80-timode.c, gcc.dg/torture/fp-int-convert-float80.c, gcc.dg/torture/fp-int-convert-long-double.c, gcc.dg/torture/fp-int-convert-timode.c: Update calls to TEST_I_F. libcpp: * include/cpplib.h (CPP_N_FLOATN, CPP_N_FLOATNX) (CPP_N_WIDTH_FLOATN_NX, CPP_FLOATN_SHIFT, CPP_FLOATN_MAX): New macros. * expr.c (interpret_float_suffix): Handle fN, fNx, FN and FNx suffixes. From-SVN: r239625
2016-08-19 19:43:26 +02:00
{
switch (s[0])
{
case 'f': case 'F':
f++;
if (len > 0
&& !CPP_OPTION (pfile, cplusplus)
&& s[1] >= '1'
&& s[1] <= '9'
&& fn_bits == 0)
{
f--;
while (len > 0
&& s[1] >= '0'
&& s[1] <= '9'
&& fn_bits < CPP_FLOATN_MAX)
{
fn_bits = fn_bits * 10 + (s[1] - '0');
len--;
s++;
}
if (len > 0 && s[1] == 'x')
{
fnx++;
len--;
s++;
}
else
fn++;
}
break;
case 'd': case 'D': d++; break;
case 'l': case 'L': l++; break;
case 'w': case 'W': w++; break;
case 'q': case 'Q': q++; break;
case 'i': case 'I':
case 'j': case 'J': i++; break;
default:
return 0;
}
s++;
}
1995-03-16 22:59:07 +01:00
Implement C _FloatN, _FloatNx types. ISO/IEC TS 18661-3:2015 defines C bindings to IEEE interchange and extended types, in the form of _FloatN and _FloatNx type names with corresponding fN/FN and fNx/FNx constant suffixes and FLTN_* / FLTNX_* <float.h> macros. This patch implements support for this feature in GCC. The _FloatN types, for N = 16, 32, 64 or >= 128 and a multiple of 32, are types encoded according to the corresponding IEEE interchange format (endianness unspecified; may use either the NaN conventions recommended in IEEE 754-2008, or the MIPS NaN conventions, since the choice of convention is only an IEEE recommendation, not a requirement). The _FloatNx types, for N = 32, 64 and 128, are IEEE "extended" types: types extending a narrower format with range and precision at least as big as those specified in IEEE 754 for each extended type (and with unspecified representation, but still following IEEE semantics for their values and operations - and with the set of values being determined by the precision and the maximum exponent, which means that while Intel "extended" is suitable for _Float64x, m68k "extended" is not). These types are always distinct from and not compatible with each other and the standard floating types float, double, long double; thus, double, _Float64 and _Float32x may all have the same ABI, but they are three still distinct types. The type names may be used with _Complex to construct corresponding complex types (unlike __float128, which acts more like a typedef name than a keyword - thus, this patch may be considered to fix PR c/32187). The new suffixes can be combined with GNU "i" and "j" suffixes for constants of complex types (e.g. 1.0if128, 2.0f64i). The set of types supported is implementation-defined. In this GCC patch, _Float32 is SFmode if that is suitable; _Float32x and _Float64 are DFmode if that is suitable; _Float128 is TFmode if that is suitable; _Float64x is XFmode if that is suitable, and otherwise TFmode if that is suitable. There is a target hook to override the choices if necessary. "Suitable" means both conforming to the requirements of that type, and supported as a scalar type including in libgcc. The ABI is whatever the back end does for scalars of that mode (but note that _Float32 is passed without promotion in variable arguments, unlike float). All the existing issues with exceptions and rounding modes for existing types apply equally to the new type names. No GCC port supports a floating-point format suitable for _Float128x. Although there is HFmode support for ARM and AArch64, use of that for _Float16 is not enabled. Supporting _Float16 would require additional work on the excess precision aspects of TS 18661-3: there are new values of FLT_EVAL_METHOD, which are not currently supported in GCC, and FLT_EVAL_METHOD == 0 now means that operations and constants on types narrower than float are evaluated to the range and precision of float. Implementing that, so that _Float16 gets evaluated with excess range and precision, would involve changes to the excess precision infrastructure so that the _Float16 case is enabled by default, unlike the x87 case which is only enabled for -fexcess-precision=standard. Other differences between _Float16 and __fp16 would also need to be disentangled. GCC has some prior support for nonstandard floating-point types in the form of __float80 and __float128. Where these were previously types distinct from long double, they are made by this patch into aliases for _Float64x / _Float128 if those types have the required properties. In principle the set of possible _FloatN types is infinite. This patch hardcodes the four such types for N <= 128, but with as much code as possible using loops over types to minimize the number of places with such hardcoding. I don't think it's likely any further such types will be of use in future (or indeed that formats suitable for _Float128x will actually be implemented). There is a corner case that all _FloatN, for N >= 128 and a multiple of 32, should be treated as keywords even when the corresponding type is not supported; I intend to deal with that in a followup patch. Tests are added for various functionality of the new types, mostly using type-generic headers. The tests use dg-add-options to pass any extra options needed to enable the types; this is wired up to use the same options as for __float128 on powerpc to enable _Float128 and _Float64x, and effective-target keywords for runtime support do the same hardware test as for __float128 to make sure the VSX instructions generated by those options are supported. (Corresponding additions would be needed for _Float16 on ARM as well if that were enabled with -mfp16-format=ieee required to use it rather than unconditionally available. Of course, -mfp16-format=alternative enables use of a format which is not compatible with the requirements of the _Float16 type.) C++ note: no support for the new types or constant suffixes is added for C++. C++ decimal floating-point support was very different from the C support, using class types, and the same may well apply to any future C++ bindings for IEEE interchange and extended types. There is a case, however, for supporting at least *f128 constants in C++, so that code using __float128 can use the newer style for constants throughout rather than needing to use the older *q constants in C++. Also, if built-in functions are added that may provide a way in which the types could leak into C++ code. Fortran note: the float128_type_node used in the Fortran front end is renamed to gfc_float128_type_node, since the semantics are different: in particular, if long double has binary128 format, then the new language-independent float128_type_node is a distinct type that also has binary128 format, but the Fortran node is expected to be NULL in that case. Likewise, Fortran's complex_float128_type_node is renamed to gfc_complex_float128_type_node. PowerPC note: the back end had an inconsistency that if TFmode was binary128, *q constants were TFmode instead of KFmode but __float128 was KFmode. This patch follows the same logic as for *q constants, so that _Float128 prefers TFmode (and __float128 becomes an alias for _Float128). ARM note: __fp16 is promoted to double (by convert_arguments) when passed without a prototype / in variable arguments. But this is only about the argument promotion; it is not handled as promoting in c-common.c:self_promoting_args_p / c-typeck.c:c_type_promotes_to, meaning that a K&R function definition for an argument of type __fp16 corresponds to a prototype with an argument of that type, not to one with an argument of type double, whereas a float argument in a K&R function definition corresponds to a double prototype argument - and the same functions are also what's involved in making va_arg give a warning and generate a call to abort when called with type float. This is preserved by this patch, while arranging for _Float16 not to be promoted when passed without a prototype / in variable arguments (the promotion of float being considered a legacy feature, not applied to any new types in C99 or later). TS 18661-3 extends the set of decimal floating-point types similarly, and adds new constant suffixes for the existing types, but this patch does not do anything regarding that extension. This patch does nothing regarding built-in functions, although type-generic functions such as __builtin_isinf work for the new types and associated tests are included. There are at least two levels of built-in function support possible for these types. The minimal level, implemented in <https://gcc.gnu.org/ml/gcc-patches/2016-06/msg01702.html> (which needs updating to use dg-add-options), adds built-in functions similar to those x86 has for __float128: __builtin_inf* __builtin_huge_val*, __builtin_nan*, __builtin_nans*, __builtin_fabs*, __builtin_copysign*. That would be sufficient for glibc to use the *f128 names for built-in functions by default with *q used only for backwards compatibility when using older GCC versions. That would also allow c_cpp_builtins's flag_building_libgcc code, defining __LIBGCC_%s_FUNC_EXT__, to use such suffixes rather than the present code hardcoding logic about target-specific constant suffixes and how those relate to function suffixes. Full built-in function support would cover the full range of built-in functions for existing floating-point types, adding variants for all the new types, except for a few obsolescent functions and non-type-generic variants of type-generic functions. Some but not all references to such functions in GCC use macros such as CASE_FLT_FN to be type-generic; a fair amount of work would be needed to identify all places to update. Adding all those functions would enable optimizations (for constant arguments and otherwise) for TS 18661-3 functions, but it would also substantially expand the enum listing built-in functions (and we've had problems with the size of that enum in the past), and increase the amount of built-in function initialization to do - I don't know what the startup cost involved in built-in function initialization is, but it would be something to consider when adding such a large set of functions. There are also a range of optimizations, in match.pd and elsewhere, that only operate on the three standard floating-point types. Ideally those would be made generic to all floating-point types, but this patch does nothing in that regard. Special care would be needed regarding making sure library functions to which calls are generated actually exist. For example, if sqrt is called on an argument of type _Float32, and the result converted to _Float32, this is equivalent to doing a square root operation directly on _Float32. But if the user's libm does not have the sqrtf32 function, or the name is not reserved because __STDC_WANT_IEC_60559_TYPES_EXT__ was not defined before including <math.h>, you can only do that optimization if you convert to a call to sqrtf instead. DECIMAL_DIG now relates to all supported floating-point formats, not just float, double and long double; I've raised the question with WG14 of how this relates to the formula for DECIMAL_DIG in C11 not considering this. TS 18661-3 says it also covers non-arithmetic formats only supported by library conversion functions; this patch does not add any target hooks to allow for the case where there are such formats wider than any supported for arithmetic types (where e.g. libc supports conversions involving the binary128 representation, but the _Float128 type is not supported). GCC provides its own <tgmath.h> for some targets. No attempt is made to adapt this to handle the new types. Nothing is done regarding debug info for the new types (see the "Debugger support for __float128 type?" thread on gcc@, Sep/Oct 2015). No __SIZEOF_*__ macros are added for the new types. Nothing is done with do_warn_double_promotion. Nothing is done to include the new types in those determining max_align_t, although properly it should be sufficiently aligned for any of those types. The logic for usual arithmetic conversions in c_common_type relies on TYPE_PRECISION for floating-point types, which is less than ideal (doesn't necessarily correspond to whether one type's values are subset of another); looking in more detail at the formats might be better. But since I included code in build_common_tree_nodes to work around rs6000 KFmode having precision 113 not 128, I think it should work. Ideally one might have errors in generic code for the case where the two types do not have one type's values a subset of the other (which is undefined behavior). But the only case where this can actually occur is mixing IBM long double with binary128 on powerpc, and rs6000_invalid_binary_op deals with that at present. TS 18661-3 does not fully specify the type resulting from the usual arithmetic conversions in the case where two _FloatNx types have the same set of values; I arranged the code to prefer the greater value of N in that case. The __FP_FAST_FMA* macros are not extended to cover the new types, since there are no corresponding built-in functions (if built-in fmafN, fmafNx are added, the macros should be extended, and the new macros documented). Also, only a limited set of modes is handled in mode_has_fma. Diagnostics relating to the use of the new types with -pedantic do not try to distinguish them from purely nonstandard types such as __int128 and constant suffixes such as *q. If you use an unsupported _FloatN / _FloatNx type you get a warning about the type defaulting to int after the warning about the type not being supported. That's less than ideal, but it's also a pre-existing condition if you use __int128 on a 32-bit system where it's unsupported. Bootstrapped with no regressions on x86_64-pc-linux-gnu. Other back-end changes minimally tested by building cc1 for ia64-linux-gnu, powerpc64le-linux-gnu, pdp11-none (the last failed for unrelated reasons). PR c/32187 gcc: * tree-core.h (TI_COMPLEX_FLOAT16_TYPE) (TI_COMPLEX_FLOATN_NX_TYPE_FIRST, TI_COMPLEX_FLOAT32_TYPE) (TI_COMPLEX_FLOAT64_TYPE, TI_COMPLEX_FLOAT128_TYPE) (TI_COMPLEX_FLOAT32X_TYPE, TI_COMPLEX_FLOAT64X_TYPE) (TI_COMPLEX_FLOAT128X_TYPE, TI_FLOAT16_TYPE, TI_FLOATN_TYPE_FIRST) (TI_FLOATN_NX_TYPE_FIRST, TI_FLOAT32_TYPE, TI_FLOAT64_TYPE) (TI_FLOAT128_TYPE, TI_FLOATN_TYPE_LAST, TI_FLOAT32X_TYPE) (TI_FLOATNX_TYPE_FIRST, TI_FLOAT64X_TYPE, TI_FLOAT128X_TYPE) (TI_FLOATNX_TYPE_LAST, TI_FLOATN_NX_TYPE_LAST): New enum tree_index values. (NUM_FLOATN_TYPES, NUM_FLOATNX_TYPES, NUM_FLOATN_NX_TYPES): New macros. (struct floatn_type_info): New structure type. (floatn_nx_types): New variable declaration. * tree.h (FLOATN_TYPE_NODE, FLOATN_NX_TYPE_NODE) (FLOATNX_TYPE_NODE, float128_type_node, float64x_type_node) (COMPLEX_FLOATN_NX_TYPE_NODE): New macros. * tree.c (floatn_nx_types): New variable. (build_common_tree_nodes): Initialize _FloatN, _FloatNx and corresponding complex types. * target.def (floatn_mode): New hook. * targhooks.c: Include "real.h". (default_floatn_mode): New function. * targhooks.h (default_floatn_mode): New prototype. * doc/extend.texi (Floating Types): Document _FloatN and _FloatNx types. * doc/sourcebuild.texi (float@var{n}, float@var{n}x): Document new effective-target and dg-add-options keywords. (float@var{n}_runtime, float@var{n}x_runtime, floatn_nx_runtime): Document new effective-target keywords. * doc/tm.texi.in (TARGET_FLOATN_MODE): New @hook. * doc/tm.texi: Regenerate. * ginclude/float.h (LDBL_DECIMAL_DIG): Define to __LDBL_DECIMAL_DIG__, not __DECIMAL_DIG__. [__STDC_WANT_IEC_60559_TYPES_EXT__]: Define macros from TS 18661-3. * real.h (struct real_format): Add field ieee_bits. * real.c (ieee_single_format, mips_single_format) (motorola_single_format, spu_single_format, ieee_double_format) (mips_double_format, motorola_double_format) (ieee_extended_motorola_format, ieee_extended_intel_96_format) (ieee_extended_intel_128_format) (ieee_extended_intel_96_round_53_format, ibm_extended_format) (mips_extended_format, ieee_quad_format, mips_quad_format) (vax_f_format, vax_d_format, vax_g_format, decimal_single_format) (decimal_double_format, decimal_quad_format, ieee_half_format) (arm_half_format, real_internal_format: Initialize ieee_bits field. * config/i386/i386.c (ix86_init_builtin_types): Do not initialize float128_type_node. Set float80_type_node to float64x_type_node if appropriate and long_double_type_node not appropriate. * config/ia64/ia64.c (ia64_init_builtins): Likewise. * config/pdp11/pdp11.c (pdp11_f_format, pdp11_d_format): Initialize ieee_bits field. * config/rs6000/rs6000.c (TARGET_FLOATN_MODE): New macro. (rs6000_init_builtins): Set ieee128_float_type_node to float128_type_node. (rs6000_floatn_mode): New function. gcc/c: * c-tree.h (cts_floatn_nx): New enum c_typespec_keyword value. (struct c_declspecs): Add field floatn_nx_idx. * c-decl.c (declspecs_add_type, finish_declspecs): Handle _FloatN and _FloatNx type specifiers. * c-parser.c (c_keyword_starts_typename, c_token_starts_declspecs) (c_parser_declspecs, c_parser_attribute_any_word) (c_parser_objc_selector): Use CASE_RID_FLOATN_NX. * c-typeck.c (c_common_type): Handle _FloatN and _FloatNx types. (convert_arguments): Avoid promoting _FloatN and _FloatNx types narrower than double. gcc/c-family: * c-common.h (RID_FLOAT16, RID_FLOATN_NX_FIRST, RID_FLOAT32) (RID_FLOAT64, RID_FLOAT128, RID_FLOAT32X, RID_FLOAT64X) (RID_FLOAT128X): New enum rid values. (CASE_RID_FLOATN_NX): New macro. * c-common.c (c_common_reswords): Add _FloatN and _FloatNx keywords. (c_common_type_for_mode): Check for _FloatN and _FloatNx and corresponding complex types. (c_common_nodes_and_builtins): For non-C++, register _FloatN and _FloatNx and corresponding complex types. (keyword_begins_type_specifier): Use CASE_RID_FLOATN_NX. * c-cppbuiltin.c (builtin_define_float_constants): Check _FloatN and _FloatNx types for the widest type for determining DECIMAL_DIG. Define __LDBL_DECIMAL_DIG__ as well as __DECIMAL_DIG__ for long double. Handle FMA_SUFFIX being NULL. (c_cpp_builtins): Call builtin_define_float_constants for _FloatN and _FloatNx types. * c-lex.c (interpret_float): Handle _FloatN and _FloatNx constants. * c-pretty-print.c (pp_c_floating_constant): Handle _FloatN and _FloatNx types. gcc/fortran: * trans-types.h (float128_type_node): Rename to gfc_float128_type_node. (complex_float128_type_node): Rename to gfc_complex_float128_type_node. * iso-c-binding.def, trans-intrinsic.c, trans-types.c: All users changed. gcc/testsuite: * lib/target-supports.exp (check_effective_target_float16) (check_effective_target_float32, check_effective_target_float64) (check_effective_target_float128, check_effective_target_float32x) (check_effective_target_float64x) (check_effective_target_float128x) (check_effective_target_float16_runtime) (check_effective_target_float32_runtime) (check_effective_target_float64_runtime) (check_effective_target_float128_runtime) (check_effective_target_float32x_runtime) (check_effective_target_float64x_runtime) (check_effective_target_float128x_runtime) (check_effective_target_floatn_nx_runtime) (add_options_for_float16, add_options_for_float32) (add_options_for_float64, add_options_for_float128) (add_options_for_float32x, add_options_for_float64x) (add_options_for_float128x): New procedures. * gcc.dg/dfp/floatn.c, gcc.dg/float128-typeof.c, gcc.dg/float128x-typeof.c, gcc.dg/float16-typeof.c, gcc.dg/float32-typeof.c, gcc.dg/float32x-typeof.c, gcc.dg/float64-typeof.c, gcc.dg/float64x-typeof.c, gcc.dg/floatn-arithconv.c, gcc.dg/floatn-errs.c, gcc.dg/floatn-typeof.h, gcc.dg/torture/float128-basic.c, gcc.dg/torture/float128-complex.c, gcc.dg/torture/float128-floath.c, gcc.dg/torture/float128-tg.c, gcc.dg/torture/float128x-basic.c, gcc.dg/torture/float128x-complex.c, gcc.dg/torture/float128x-floath.c, gcc.dg/torture/float128x-tg.c, gcc.dg/torture/float16-basic.c, gcc.dg/torture/float16-complex.c, gcc.dg/torture/float16-floath.c, gcc.dg/torture/float16-tg.c, gcc.dg/torture/float32-basic.c, gcc.dg/torture/float32-complex.c, gcc.dg/torture/float32-floath.c, gcc.dg/torture/float32-tg.c, gcc.dg/torture/float32x-basic.c, gcc.dg/torture/float32x-complex.c, gcc.dg/torture/float32x-floath.c, gcc.dg/torture/float32x-tg.c, gcc.dg/torture/float64-basic.c, gcc.dg/torture/float64-complex.c, gcc.dg/torture/float64-floath.c, gcc.dg/torture/float64-tg.c, gcc.dg/torture/float64x-basic.c, gcc.dg/torture/float64x-complex.c, gcc.dg/torture/float64x-floath.c, gcc.dg/torture/float64x-tg.c, gcc.dg/torture/floatn-basic.h, gcc.dg/torture/floatn-complex.h, gcc.dg/torture/floatn-convert.c, gcc.dg/torture/floatn-floath.h, gcc.dg/torture/floatn-tg.h, gcc.dg/torture/fp-int-convert-float128-ieee-timode.c, gcc.dg/torture/fp-int-convert-float128-ieee.c, gcc.dg/torture/fp-int-convert-float128x-timode.c, gcc.dg/torture/fp-int-convert-float128x.c, gcc.dg/torture/fp-int-convert-float16-timode.c, gcc.dg/torture/fp-int-convert-float16.c, gcc.dg/torture/fp-int-convert-float32-timode.c, gcc.dg/torture/fp-int-convert-float32.c, gcc.dg/torture/fp-int-convert-float32x-timode.c, gcc.dg/torture/fp-int-convert-float32x.c, gcc.dg/torture/fp-int-convert-float64-timode.c, gcc.dg/torture/fp-int-convert-float64.c, gcc.dg/torture/fp-int-convert-float64x-timode.c, gcc.dg/torture/fp-int-convert-float64x.c: New tests. * gcc.dg/torture/fp-int-convert.h (TEST_I_F): Add argument for maximum exponent of floating-point type. Use it in testing whether 0x8...0 fits in the floating-point type. Always treat -1 (signed 0xf...f) as fitting in the floating-point type. (M_OK1): New macro. * gcc.dg/torture/fp-int-convert-double.c, gcc.dg/torture/fp-int-convert-float.c, gcc.dg/torture/fp-int-convert-float128-timode.c, gcc.dg/torture/fp-int-convert-float128.c, gcc.dg/torture/fp-int-convert-float80-timode.c, gcc.dg/torture/fp-int-convert-float80.c, gcc.dg/torture/fp-int-convert-long-double.c, gcc.dg/torture/fp-int-convert-timode.c: Update calls to TEST_I_F. libcpp: * include/cpplib.h (CPP_N_FLOATN, CPP_N_FLOATNX) (CPP_N_WIDTH_FLOATN_NX, CPP_FLOATN_SHIFT, CPP_FLOATN_MAX): New macros. * expr.c (interpret_float_suffix): Handle fN, fNx, FN and FNx suffixes. From-SVN: r239625
2016-08-19 19:43:26 +02:00
/* Reject any case of multiple suffixes specifying types, multiple
suffixes specifying an imaginary constant, _FloatN or _FloatNx
suffixes for invalid values of N, and _FloatN suffixes for values
of N larger than can be represented in the return value. The
caller is responsible for rejecting _FloatN suffixes where
_FloatN is not supported on the chosen target. */
if (f + d + l + w + q + fn + fnx > 1 || i > 1)
return 0;
if (fn_bits > CPP_FLOATN_MAX)
return 0;
if (fnx && fn_bits != 32 && fn_bits != 64 && fn_bits != 128)
return 0;
if (fn && fn_bits != 16 && fn_bits % 32 != 0)
return 0;
if (fn && fn_bits == 96)
return 0;
if (i && !CPP_OPTION (pfile, ext_numeric_literals))
return 0;
if ((w || q) && !CPP_OPTION (pfile, ext_numeric_literals))
return 0;
return ((i ? CPP_N_IMAGINARY : 0)
| (f ? CPP_N_SMALL :
d ? CPP_N_MEDIUM :
l ? CPP_N_LARGE :
w ? CPP_N_MD_W :
Implement C _FloatN, _FloatNx types. ISO/IEC TS 18661-3:2015 defines C bindings to IEEE interchange and extended types, in the form of _FloatN and _FloatNx type names with corresponding fN/FN and fNx/FNx constant suffixes and FLTN_* / FLTNX_* <float.h> macros. This patch implements support for this feature in GCC. The _FloatN types, for N = 16, 32, 64 or >= 128 and a multiple of 32, are types encoded according to the corresponding IEEE interchange format (endianness unspecified; may use either the NaN conventions recommended in IEEE 754-2008, or the MIPS NaN conventions, since the choice of convention is only an IEEE recommendation, not a requirement). The _FloatNx types, for N = 32, 64 and 128, are IEEE "extended" types: types extending a narrower format with range and precision at least as big as those specified in IEEE 754 for each extended type (and with unspecified representation, but still following IEEE semantics for their values and operations - and with the set of values being determined by the precision and the maximum exponent, which means that while Intel "extended" is suitable for _Float64x, m68k "extended" is not). These types are always distinct from and not compatible with each other and the standard floating types float, double, long double; thus, double, _Float64 and _Float32x may all have the same ABI, but they are three still distinct types. The type names may be used with _Complex to construct corresponding complex types (unlike __float128, which acts more like a typedef name than a keyword - thus, this patch may be considered to fix PR c/32187). The new suffixes can be combined with GNU "i" and "j" suffixes for constants of complex types (e.g. 1.0if128, 2.0f64i). The set of types supported is implementation-defined. In this GCC patch, _Float32 is SFmode if that is suitable; _Float32x and _Float64 are DFmode if that is suitable; _Float128 is TFmode if that is suitable; _Float64x is XFmode if that is suitable, and otherwise TFmode if that is suitable. There is a target hook to override the choices if necessary. "Suitable" means both conforming to the requirements of that type, and supported as a scalar type including in libgcc. The ABI is whatever the back end does for scalars of that mode (but note that _Float32 is passed without promotion in variable arguments, unlike float). All the existing issues with exceptions and rounding modes for existing types apply equally to the new type names. No GCC port supports a floating-point format suitable for _Float128x. Although there is HFmode support for ARM and AArch64, use of that for _Float16 is not enabled. Supporting _Float16 would require additional work on the excess precision aspects of TS 18661-3: there are new values of FLT_EVAL_METHOD, which are not currently supported in GCC, and FLT_EVAL_METHOD == 0 now means that operations and constants on types narrower than float are evaluated to the range and precision of float. Implementing that, so that _Float16 gets evaluated with excess range and precision, would involve changes to the excess precision infrastructure so that the _Float16 case is enabled by default, unlike the x87 case which is only enabled for -fexcess-precision=standard. Other differences between _Float16 and __fp16 would also need to be disentangled. GCC has some prior support for nonstandard floating-point types in the form of __float80 and __float128. Where these were previously types distinct from long double, they are made by this patch into aliases for _Float64x / _Float128 if those types have the required properties. In principle the set of possible _FloatN types is infinite. This patch hardcodes the four such types for N <= 128, but with as much code as possible using loops over types to minimize the number of places with such hardcoding. I don't think it's likely any further such types will be of use in future (or indeed that formats suitable for _Float128x will actually be implemented). There is a corner case that all _FloatN, for N >= 128 and a multiple of 32, should be treated as keywords even when the corresponding type is not supported; I intend to deal with that in a followup patch. Tests are added for various functionality of the new types, mostly using type-generic headers. The tests use dg-add-options to pass any extra options needed to enable the types; this is wired up to use the same options as for __float128 on powerpc to enable _Float128 and _Float64x, and effective-target keywords for runtime support do the same hardware test as for __float128 to make sure the VSX instructions generated by those options are supported. (Corresponding additions would be needed for _Float16 on ARM as well if that were enabled with -mfp16-format=ieee required to use it rather than unconditionally available. Of course, -mfp16-format=alternative enables use of a format which is not compatible with the requirements of the _Float16 type.) C++ note: no support for the new types or constant suffixes is added for C++. C++ decimal floating-point support was very different from the C support, using class types, and the same may well apply to any future C++ bindings for IEEE interchange and extended types. There is a case, however, for supporting at least *f128 constants in C++, so that code using __float128 can use the newer style for constants throughout rather than needing to use the older *q constants in C++. Also, if built-in functions are added that may provide a way in which the types could leak into C++ code. Fortran note: the float128_type_node used in the Fortran front end is renamed to gfc_float128_type_node, since the semantics are different: in particular, if long double has binary128 format, then the new language-independent float128_type_node is a distinct type that also has binary128 format, but the Fortran node is expected to be NULL in that case. Likewise, Fortran's complex_float128_type_node is renamed to gfc_complex_float128_type_node. PowerPC note: the back end had an inconsistency that if TFmode was binary128, *q constants were TFmode instead of KFmode but __float128 was KFmode. This patch follows the same logic as for *q constants, so that _Float128 prefers TFmode (and __float128 becomes an alias for _Float128). ARM note: __fp16 is promoted to double (by convert_arguments) when passed without a prototype / in variable arguments. But this is only about the argument promotion; it is not handled as promoting in c-common.c:self_promoting_args_p / c-typeck.c:c_type_promotes_to, meaning that a K&R function definition for an argument of type __fp16 corresponds to a prototype with an argument of that type, not to one with an argument of type double, whereas a float argument in a K&R function definition corresponds to a double prototype argument - and the same functions are also what's involved in making va_arg give a warning and generate a call to abort when called with type float. This is preserved by this patch, while arranging for _Float16 not to be promoted when passed without a prototype / in variable arguments (the promotion of float being considered a legacy feature, not applied to any new types in C99 or later). TS 18661-3 extends the set of decimal floating-point types similarly, and adds new constant suffixes for the existing types, but this patch does not do anything regarding that extension. This patch does nothing regarding built-in functions, although type-generic functions such as __builtin_isinf work for the new types and associated tests are included. There are at least two levels of built-in function support possible for these types. The minimal level, implemented in <https://gcc.gnu.org/ml/gcc-patches/2016-06/msg01702.html> (which needs updating to use dg-add-options), adds built-in functions similar to those x86 has for __float128: __builtin_inf* __builtin_huge_val*, __builtin_nan*, __builtin_nans*, __builtin_fabs*, __builtin_copysign*. That would be sufficient for glibc to use the *f128 names for built-in functions by default with *q used only for backwards compatibility when using older GCC versions. That would also allow c_cpp_builtins's flag_building_libgcc code, defining __LIBGCC_%s_FUNC_EXT__, to use such suffixes rather than the present code hardcoding logic about target-specific constant suffixes and how those relate to function suffixes. Full built-in function support would cover the full range of built-in functions for existing floating-point types, adding variants for all the new types, except for a few obsolescent functions and non-type-generic variants of type-generic functions. Some but not all references to such functions in GCC use macros such as CASE_FLT_FN to be type-generic; a fair amount of work would be needed to identify all places to update. Adding all those functions would enable optimizations (for constant arguments and otherwise) for TS 18661-3 functions, but it would also substantially expand the enum listing built-in functions (and we've had problems with the size of that enum in the past), and increase the amount of built-in function initialization to do - I don't know what the startup cost involved in built-in function initialization is, but it would be something to consider when adding such a large set of functions. There are also a range of optimizations, in match.pd and elsewhere, that only operate on the three standard floating-point types. Ideally those would be made generic to all floating-point types, but this patch does nothing in that regard. Special care would be needed regarding making sure library functions to which calls are generated actually exist. For example, if sqrt is called on an argument of type _Float32, and the result converted to _Float32, this is equivalent to doing a square root operation directly on _Float32. But if the user's libm does not have the sqrtf32 function, or the name is not reserved because __STDC_WANT_IEC_60559_TYPES_EXT__ was not defined before including <math.h>, you can only do that optimization if you convert to a call to sqrtf instead. DECIMAL_DIG now relates to all supported floating-point formats, not just float, double and long double; I've raised the question with WG14 of how this relates to the formula for DECIMAL_DIG in C11 not considering this. TS 18661-3 says it also covers non-arithmetic formats only supported by library conversion functions; this patch does not add any target hooks to allow for the case where there are such formats wider than any supported for arithmetic types (where e.g. libc supports conversions involving the binary128 representation, but the _Float128 type is not supported). GCC provides its own <tgmath.h> for some targets. No attempt is made to adapt this to handle the new types. Nothing is done regarding debug info for the new types (see the "Debugger support for __float128 type?" thread on gcc@, Sep/Oct 2015). No __SIZEOF_*__ macros are added for the new types. Nothing is done with do_warn_double_promotion. Nothing is done to include the new types in those determining max_align_t, although properly it should be sufficiently aligned for any of those types. The logic for usual arithmetic conversions in c_common_type relies on TYPE_PRECISION for floating-point types, which is less than ideal (doesn't necessarily correspond to whether one type's values are subset of another); looking in more detail at the formats might be better. But since I included code in build_common_tree_nodes to work around rs6000 KFmode having precision 113 not 128, I think it should work. Ideally one might have errors in generic code for the case where the two types do not have one type's values a subset of the other (which is undefined behavior). But the only case where this can actually occur is mixing IBM long double with binary128 on powerpc, and rs6000_invalid_binary_op deals with that at present. TS 18661-3 does not fully specify the type resulting from the usual arithmetic conversions in the case where two _FloatNx types have the same set of values; I arranged the code to prefer the greater value of N in that case. The __FP_FAST_FMA* macros are not extended to cover the new types, since there are no corresponding built-in functions (if built-in fmafN, fmafNx are added, the macros should be extended, and the new macros documented). Also, only a limited set of modes is handled in mode_has_fma. Diagnostics relating to the use of the new types with -pedantic do not try to distinguish them from purely nonstandard types such as __int128 and constant suffixes such as *q. If you use an unsupported _FloatN / _FloatNx type you get a warning about the type defaulting to int after the warning about the type not being supported. That's less than ideal, but it's also a pre-existing condition if you use __int128 on a 32-bit system where it's unsupported. Bootstrapped with no regressions on x86_64-pc-linux-gnu. Other back-end changes minimally tested by building cc1 for ia64-linux-gnu, powerpc64le-linux-gnu, pdp11-none (the last failed for unrelated reasons). PR c/32187 gcc: * tree-core.h (TI_COMPLEX_FLOAT16_TYPE) (TI_COMPLEX_FLOATN_NX_TYPE_FIRST, TI_COMPLEX_FLOAT32_TYPE) (TI_COMPLEX_FLOAT64_TYPE, TI_COMPLEX_FLOAT128_TYPE) (TI_COMPLEX_FLOAT32X_TYPE, TI_COMPLEX_FLOAT64X_TYPE) (TI_COMPLEX_FLOAT128X_TYPE, TI_FLOAT16_TYPE, TI_FLOATN_TYPE_FIRST) (TI_FLOATN_NX_TYPE_FIRST, TI_FLOAT32_TYPE, TI_FLOAT64_TYPE) (TI_FLOAT128_TYPE, TI_FLOATN_TYPE_LAST, TI_FLOAT32X_TYPE) (TI_FLOATNX_TYPE_FIRST, TI_FLOAT64X_TYPE, TI_FLOAT128X_TYPE) (TI_FLOATNX_TYPE_LAST, TI_FLOATN_NX_TYPE_LAST): New enum tree_index values. (NUM_FLOATN_TYPES, NUM_FLOATNX_TYPES, NUM_FLOATN_NX_TYPES): New macros. (struct floatn_type_info): New structure type. (floatn_nx_types): New variable declaration. * tree.h (FLOATN_TYPE_NODE, FLOATN_NX_TYPE_NODE) (FLOATNX_TYPE_NODE, float128_type_node, float64x_type_node) (COMPLEX_FLOATN_NX_TYPE_NODE): New macros. * tree.c (floatn_nx_types): New variable. (build_common_tree_nodes): Initialize _FloatN, _FloatNx and corresponding complex types. * target.def (floatn_mode): New hook. * targhooks.c: Include "real.h". (default_floatn_mode): New function. * targhooks.h (default_floatn_mode): New prototype. * doc/extend.texi (Floating Types): Document _FloatN and _FloatNx types. * doc/sourcebuild.texi (float@var{n}, float@var{n}x): Document new effective-target and dg-add-options keywords. (float@var{n}_runtime, float@var{n}x_runtime, floatn_nx_runtime): Document new effective-target keywords. * doc/tm.texi.in (TARGET_FLOATN_MODE): New @hook. * doc/tm.texi: Regenerate. * ginclude/float.h (LDBL_DECIMAL_DIG): Define to __LDBL_DECIMAL_DIG__, not __DECIMAL_DIG__. [__STDC_WANT_IEC_60559_TYPES_EXT__]: Define macros from TS 18661-3. * real.h (struct real_format): Add field ieee_bits. * real.c (ieee_single_format, mips_single_format) (motorola_single_format, spu_single_format, ieee_double_format) (mips_double_format, motorola_double_format) (ieee_extended_motorola_format, ieee_extended_intel_96_format) (ieee_extended_intel_128_format) (ieee_extended_intel_96_round_53_format, ibm_extended_format) (mips_extended_format, ieee_quad_format, mips_quad_format) (vax_f_format, vax_d_format, vax_g_format, decimal_single_format) (decimal_double_format, decimal_quad_format, ieee_half_format) (arm_half_format, real_internal_format: Initialize ieee_bits field. * config/i386/i386.c (ix86_init_builtin_types): Do not initialize float128_type_node. Set float80_type_node to float64x_type_node if appropriate and long_double_type_node not appropriate. * config/ia64/ia64.c (ia64_init_builtins): Likewise. * config/pdp11/pdp11.c (pdp11_f_format, pdp11_d_format): Initialize ieee_bits field. * config/rs6000/rs6000.c (TARGET_FLOATN_MODE): New macro. (rs6000_init_builtins): Set ieee128_float_type_node to float128_type_node. (rs6000_floatn_mode): New function. gcc/c: * c-tree.h (cts_floatn_nx): New enum c_typespec_keyword value. (struct c_declspecs): Add field floatn_nx_idx. * c-decl.c (declspecs_add_type, finish_declspecs): Handle _FloatN and _FloatNx type specifiers. * c-parser.c (c_keyword_starts_typename, c_token_starts_declspecs) (c_parser_declspecs, c_parser_attribute_any_word) (c_parser_objc_selector): Use CASE_RID_FLOATN_NX. * c-typeck.c (c_common_type): Handle _FloatN and _FloatNx types. (convert_arguments): Avoid promoting _FloatN and _FloatNx types narrower than double. gcc/c-family: * c-common.h (RID_FLOAT16, RID_FLOATN_NX_FIRST, RID_FLOAT32) (RID_FLOAT64, RID_FLOAT128, RID_FLOAT32X, RID_FLOAT64X) (RID_FLOAT128X): New enum rid values. (CASE_RID_FLOATN_NX): New macro. * c-common.c (c_common_reswords): Add _FloatN and _FloatNx keywords. (c_common_type_for_mode): Check for _FloatN and _FloatNx and corresponding complex types. (c_common_nodes_and_builtins): For non-C++, register _FloatN and _FloatNx and corresponding complex types. (keyword_begins_type_specifier): Use CASE_RID_FLOATN_NX. * c-cppbuiltin.c (builtin_define_float_constants): Check _FloatN and _FloatNx types for the widest type for determining DECIMAL_DIG. Define __LDBL_DECIMAL_DIG__ as well as __DECIMAL_DIG__ for long double. Handle FMA_SUFFIX being NULL. (c_cpp_builtins): Call builtin_define_float_constants for _FloatN and _FloatNx types. * c-lex.c (interpret_float): Handle _FloatN and _FloatNx constants. * c-pretty-print.c (pp_c_floating_constant): Handle _FloatN and _FloatNx types. gcc/fortran: * trans-types.h (float128_type_node): Rename to gfc_float128_type_node. (complex_float128_type_node): Rename to gfc_complex_float128_type_node. * iso-c-binding.def, trans-intrinsic.c, trans-types.c: All users changed. gcc/testsuite: * lib/target-supports.exp (check_effective_target_float16) (check_effective_target_float32, check_effective_target_float64) (check_effective_target_float128, check_effective_target_float32x) (check_effective_target_float64x) (check_effective_target_float128x) (check_effective_target_float16_runtime) (check_effective_target_float32_runtime) (check_effective_target_float64_runtime) (check_effective_target_float128_runtime) (check_effective_target_float32x_runtime) (check_effective_target_float64x_runtime) (check_effective_target_float128x_runtime) (check_effective_target_floatn_nx_runtime) (add_options_for_float16, add_options_for_float32) (add_options_for_float64, add_options_for_float128) (add_options_for_float32x, add_options_for_float64x) (add_options_for_float128x): New procedures. * gcc.dg/dfp/floatn.c, gcc.dg/float128-typeof.c, gcc.dg/float128x-typeof.c, gcc.dg/float16-typeof.c, gcc.dg/float32-typeof.c, gcc.dg/float32x-typeof.c, gcc.dg/float64-typeof.c, gcc.dg/float64x-typeof.c, gcc.dg/floatn-arithconv.c, gcc.dg/floatn-errs.c, gcc.dg/floatn-typeof.h, gcc.dg/torture/float128-basic.c, gcc.dg/torture/float128-complex.c, gcc.dg/torture/float128-floath.c, gcc.dg/torture/float128-tg.c, gcc.dg/torture/float128x-basic.c, gcc.dg/torture/float128x-complex.c, gcc.dg/torture/float128x-floath.c, gcc.dg/torture/float128x-tg.c, gcc.dg/torture/float16-basic.c, gcc.dg/torture/float16-complex.c, gcc.dg/torture/float16-floath.c, gcc.dg/torture/float16-tg.c, gcc.dg/torture/float32-basic.c, gcc.dg/torture/float32-complex.c, gcc.dg/torture/float32-floath.c, gcc.dg/torture/float32-tg.c, gcc.dg/torture/float32x-basic.c, gcc.dg/torture/float32x-complex.c, gcc.dg/torture/float32x-floath.c, gcc.dg/torture/float32x-tg.c, gcc.dg/torture/float64-basic.c, gcc.dg/torture/float64-complex.c, gcc.dg/torture/float64-floath.c, gcc.dg/torture/float64-tg.c, gcc.dg/torture/float64x-basic.c, gcc.dg/torture/float64x-complex.c, gcc.dg/torture/float64x-floath.c, gcc.dg/torture/float64x-tg.c, gcc.dg/torture/floatn-basic.h, gcc.dg/torture/floatn-complex.h, gcc.dg/torture/floatn-convert.c, gcc.dg/torture/floatn-floath.h, gcc.dg/torture/floatn-tg.h, gcc.dg/torture/fp-int-convert-float128-ieee-timode.c, gcc.dg/torture/fp-int-convert-float128-ieee.c, gcc.dg/torture/fp-int-convert-float128x-timode.c, gcc.dg/torture/fp-int-convert-float128x.c, gcc.dg/torture/fp-int-convert-float16-timode.c, gcc.dg/torture/fp-int-convert-float16.c, gcc.dg/torture/fp-int-convert-float32-timode.c, gcc.dg/torture/fp-int-convert-float32.c, gcc.dg/torture/fp-int-convert-float32x-timode.c, gcc.dg/torture/fp-int-convert-float32x.c, gcc.dg/torture/fp-int-convert-float64-timode.c, gcc.dg/torture/fp-int-convert-float64.c, gcc.dg/torture/fp-int-convert-float64x-timode.c, gcc.dg/torture/fp-int-convert-float64x.c: New tests. * gcc.dg/torture/fp-int-convert.h (TEST_I_F): Add argument for maximum exponent of floating-point type. Use it in testing whether 0x8...0 fits in the floating-point type. Always treat -1 (signed 0xf...f) as fitting in the floating-point type. (M_OK1): New macro. * gcc.dg/torture/fp-int-convert-double.c, gcc.dg/torture/fp-int-convert-float.c, gcc.dg/torture/fp-int-convert-float128-timode.c, gcc.dg/torture/fp-int-convert-float128.c, gcc.dg/torture/fp-int-convert-float80-timode.c, gcc.dg/torture/fp-int-convert-float80.c, gcc.dg/torture/fp-int-convert-long-double.c, gcc.dg/torture/fp-int-convert-timode.c: Update calls to TEST_I_F. libcpp: * include/cpplib.h (CPP_N_FLOATN, CPP_N_FLOATNX) (CPP_N_WIDTH_FLOATN_NX, CPP_FLOATN_SHIFT, CPP_FLOATN_MAX): New macros. * expr.c (interpret_float_suffix): Handle fN, fNx, FN and FNx suffixes. From-SVN: r239625
2016-08-19 19:43:26 +02:00
q ? CPP_N_MD_Q :
fn ? CPP_N_FLOATN | (fn_bits << CPP_FLOATN_SHIFT) :
fnx ? CPP_N_FLOATNX | (fn_bits << CPP_FLOATN_SHIFT) :
CPP_N_DEFAULT));
}
Implement C++11 user-defined literals. libcpp/ * expr.c: (cpp_interpret_float_suffix, cpp_interpret_int_suffix, cpp_userdef_string_remove_type, cpp_userdef_string_add_type, cpp_userdef_char_remove_type, cpp_userdef_char_add_type, cpp_userdef_string_p, cpp_userdef_char_p, cpp_get_userdef_suffix): New. (cpp_classify_number): Classify unrecognized tokens as user-defined literals. * include/cpplib.h: Add new tokens for user-defined literals. * init.c: Add new preprocessor flag (cxx11). * lex.c: (lex_string, lex_raw_string): Handle user-defined literals including concatenation and promotion with suffixes. c-family/ * c-common.c (build_userdef_literal): New. * c-common.def: New tree code. * c-common.h (tree_userdef_literal): New tree struct and accessors. * c-lex.c (interpret_float): Add suffix parm. (c_lex_with_flags): Build literal tokens. cp/ * cp-objcp-common.c: (cp_tree_size) Return size of USERDEF_LITERAL tree. * cp-tree.h: (UDLIT_OP_*, UDLIT_OPER_P): Literal operator name tools. New tree code for user-defined literals. * cxx-pretty-print.h: (pp_cxx_userdef_literal) New. * cxx-pretty-print.c: (pp_cxx_userdef_literal) New. (pp_cxx_primary_expression, pp_cxx_expression): Use it. * decl.c: (cp_tree_node_structure): Return new tree code. (duplicate_decls): Check for raw vs. template operator conflicts. (grokfndecl, grokdeclarator): New checks for literal operators. * error.c: (dump_expr): Warn about user-defined literals in C++98 mode. (dump_function_name): Pretty printing. * mangle.c: (write_literal_operator_name): New. (write_unqualified_id, write_unqualified_name): Use it. * parser.c: (cp_parser_operator): Handle operator"". (cp_parser_userdef_char_literal, cp_parser_userdef_numeric_literal, cp_parser_userdef_string_literal): New. (cp_parser_primary_expression): Handle new user-defined literal tokens with new functions. * semantics.c: (potential_constant_expression_1): Add user-defined literals. * typeck.c (check_raw_literal_operator, check_literal_operator_args): New. From-SVN: r180536
2011-10-26 21:30:59 +02:00
/* Return the classification flags for a float suffix. */
unsigned int
cpp_interpret_float_suffix (cpp_reader *pfile, const char *s, size_t len)
Implement C++11 user-defined literals. libcpp/ * expr.c: (cpp_interpret_float_suffix, cpp_interpret_int_suffix, cpp_userdef_string_remove_type, cpp_userdef_string_add_type, cpp_userdef_char_remove_type, cpp_userdef_char_add_type, cpp_userdef_string_p, cpp_userdef_char_p, cpp_get_userdef_suffix): New. (cpp_classify_number): Classify unrecognized tokens as user-defined literals. * include/cpplib.h: Add new tokens for user-defined literals. * init.c: Add new preprocessor flag (cxx11). * lex.c: (lex_string, lex_raw_string): Handle user-defined literals including concatenation and promotion with suffixes. c-family/ * c-common.c (build_userdef_literal): New. * c-common.def: New tree code. * c-common.h (tree_userdef_literal): New tree struct and accessors. * c-lex.c (interpret_float): Add suffix parm. (c_lex_with_flags): Build literal tokens. cp/ * cp-objcp-common.c: (cp_tree_size) Return size of USERDEF_LITERAL tree. * cp-tree.h: (UDLIT_OP_*, UDLIT_OPER_P): Literal operator name tools. New tree code for user-defined literals. * cxx-pretty-print.h: (pp_cxx_userdef_literal) New. * cxx-pretty-print.c: (pp_cxx_userdef_literal) New. (pp_cxx_primary_expression, pp_cxx_expression): Use it. * decl.c: (cp_tree_node_structure): Return new tree code. (duplicate_decls): Check for raw vs. template operator conflicts. (grokfndecl, grokdeclarator): New checks for literal operators. * error.c: (dump_expr): Warn about user-defined literals in C++98 mode. (dump_function_name): Pretty printing. * mangle.c: (write_literal_operator_name): New. (write_unqualified_id, write_unqualified_name): Use it. * parser.c: (cp_parser_operator): Handle operator"". (cp_parser_userdef_char_literal, cp_parser_userdef_numeric_literal, cp_parser_userdef_string_literal): New. (cp_parser_primary_expression): Handle new user-defined literal tokens with new functions. * semantics.c: (potential_constant_expression_1): Add user-defined literals. * typeck.c (check_raw_literal_operator, check_literal_operator_args): New. From-SVN: r180536
2011-10-26 21:30:59 +02:00
{
return interpret_float_suffix (pfile, (const unsigned char *)s, len);
Implement C++11 user-defined literals. libcpp/ * expr.c: (cpp_interpret_float_suffix, cpp_interpret_int_suffix, cpp_userdef_string_remove_type, cpp_userdef_string_add_type, cpp_userdef_char_remove_type, cpp_userdef_char_add_type, cpp_userdef_string_p, cpp_userdef_char_p, cpp_get_userdef_suffix): New. (cpp_classify_number): Classify unrecognized tokens as user-defined literals. * include/cpplib.h: Add new tokens for user-defined literals. * init.c: Add new preprocessor flag (cxx11). * lex.c: (lex_string, lex_raw_string): Handle user-defined literals including concatenation and promotion with suffixes. c-family/ * c-common.c (build_userdef_literal): New. * c-common.def: New tree code. * c-common.h (tree_userdef_literal): New tree struct and accessors. * c-lex.c (interpret_float): Add suffix parm. (c_lex_with_flags): Build literal tokens. cp/ * cp-objcp-common.c: (cp_tree_size) Return size of USERDEF_LITERAL tree. * cp-tree.h: (UDLIT_OP_*, UDLIT_OPER_P): Literal operator name tools. New tree code for user-defined literals. * cxx-pretty-print.h: (pp_cxx_userdef_literal) New. * cxx-pretty-print.c: (pp_cxx_userdef_literal) New. (pp_cxx_primary_expression, pp_cxx_expression): Use it. * decl.c: (cp_tree_node_structure): Return new tree code. (duplicate_decls): Check for raw vs. template operator conflicts. (grokfndecl, grokdeclarator): New checks for literal operators. * error.c: (dump_expr): Warn about user-defined literals in C++98 mode. (dump_function_name): Pretty printing. * mangle.c: (write_literal_operator_name): New. (write_unqualified_id, write_unqualified_name): Use it. * parser.c: (cp_parser_operator): Handle operator"". (cp_parser_userdef_char_literal, cp_parser_userdef_numeric_literal, cp_parser_userdef_string_literal): New. (cp_parser_primary_expression): Handle new user-defined literal tokens with new functions. * semantics.c: (potential_constant_expression_1): Add user-defined literals. * typeck.c (check_raw_literal_operator, check_literal_operator_args): New. From-SVN: r180536
2011-10-26 21:30:59 +02:00
}
/* Subroutine of cpp_classify_number. S points to an integer suffix
of length LEN, possibly zero. Returns 0 for an invalid suffix, or a
flag vector describing the suffix. */
static unsigned int
interpret_int_suffix (cpp_reader *pfile, const uchar *s, size_t len)
{
size_t u, l, i;
u = l = i = 0;
while (len--)
switch (s[len])
{
case 'u': case 'U': u++; break;
case 'i': case 'I':
case 'j': case 'J': i++; break;
case 'l': case 'L': l++;
/* If there are two Ls, they must be adjacent and the same case. */
if (l == 2 && s[len] != s[len + 1])
return 0;
break;
default:
return 0;
}
if (l > 2 || u > 1 || i > 1)
return 0;
if (i && !CPP_OPTION (pfile, ext_numeric_literals))
return 0;
return ((i ? CPP_N_IMAGINARY : 0)
| (u ? CPP_N_UNSIGNED : 0)
| ((l == 0) ? CPP_N_SMALL
: (l == 1) ? CPP_N_MEDIUM : CPP_N_LARGE));
}
Implement C++11 user-defined literals. libcpp/ * expr.c: (cpp_interpret_float_suffix, cpp_interpret_int_suffix, cpp_userdef_string_remove_type, cpp_userdef_string_add_type, cpp_userdef_char_remove_type, cpp_userdef_char_add_type, cpp_userdef_string_p, cpp_userdef_char_p, cpp_get_userdef_suffix): New. (cpp_classify_number): Classify unrecognized tokens as user-defined literals. * include/cpplib.h: Add new tokens for user-defined literals. * init.c: Add new preprocessor flag (cxx11). * lex.c: (lex_string, lex_raw_string): Handle user-defined literals including concatenation and promotion with suffixes. c-family/ * c-common.c (build_userdef_literal): New. * c-common.def: New tree code. * c-common.h (tree_userdef_literal): New tree struct and accessors. * c-lex.c (interpret_float): Add suffix parm. (c_lex_with_flags): Build literal tokens. cp/ * cp-objcp-common.c: (cp_tree_size) Return size of USERDEF_LITERAL tree. * cp-tree.h: (UDLIT_OP_*, UDLIT_OPER_P): Literal operator name tools. New tree code for user-defined literals. * cxx-pretty-print.h: (pp_cxx_userdef_literal) New. * cxx-pretty-print.c: (pp_cxx_userdef_literal) New. (pp_cxx_primary_expression, pp_cxx_expression): Use it. * decl.c: (cp_tree_node_structure): Return new tree code. (duplicate_decls): Check for raw vs. template operator conflicts. (grokfndecl, grokdeclarator): New checks for literal operators. * error.c: (dump_expr): Warn about user-defined literals in C++98 mode. (dump_function_name): Pretty printing. * mangle.c: (write_literal_operator_name): New. (write_unqualified_id, write_unqualified_name): Use it. * parser.c: (cp_parser_operator): Handle operator"". (cp_parser_userdef_char_literal, cp_parser_userdef_numeric_literal, cp_parser_userdef_string_literal): New. (cp_parser_primary_expression): Handle new user-defined literal tokens with new functions. * semantics.c: (potential_constant_expression_1): Add user-defined literals. * typeck.c (check_raw_literal_operator, check_literal_operator_args): New. From-SVN: r180536
2011-10-26 21:30:59 +02:00
/* Return the classification flags for an int suffix. */
unsigned int
cpp_interpret_int_suffix (cpp_reader *pfile, const char *s, size_t len)
Implement C++11 user-defined literals. libcpp/ * expr.c: (cpp_interpret_float_suffix, cpp_interpret_int_suffix, cpp_userdef_string_remove_type, cpp_userdef_string_add_type, cpp_userdef_char_remove_type, cpp_userdef_char_add_type, cpp_userdef_string_p, cpp_userdef_char_p, cpp_get_userdef_suffix): New. (cpp_classify_number): Classify unrecognized tokens as user-defined literals. * include/cpplib.h: Add new tokens for user-defined literals. * init.c: Add new preprocessor flag (cxx11). * lex.c: (lex_string, lex_raw_string): Handle user-defined literals including concatenation and promotion with suffixes. c-family/ * c-common.c (build_userdef_literal): New. * c-common.def: New tree code. * c-common.h (tree_userdef_literal): New tree struct and accessors. * c-lex.c (interpret_float): Add suffix parm. (c_lex_with_flags): Build literal tokens. cp/ * cp-objcp-common.c: (cp_tree_size) Return size of USERDEF_LITERAL tree. * cp-tree.h: (UDLIT_OP_*, UDLIT_OPER_P): Literal operator name tools. New tree code for user-defined literals. * cxx-pretty-print.h: (pp_cxx_userdef_literal) New. * cxx-pretty-print.c: (pp_cxx_userdef_literal) New. (pp_cxx_primary_expression, pp_cxx_expression): Use it. * decl.c: (cp_tree_node_structure): Return new tree code. (duplicate_decls): Check for raw vs. template operator conflicts. (grokfndecl, grokdeclarator): New checks for literal operators. * error.c: (dump_expr): Warn about user-defined literals in C++98 mode. (dump_function_name): Pretty printing. * mangle.c: (write_literal_operator_name): New. (write_unqualified_id, write_unqualified_name): Use it. * parser.c: (cp_parser_operator): Handle operator"". (cp_parser_userdef_char_literal, cp_parser_userdef_numeric_literal, cp_parser_userdef_string_literal): New. (cp_parser_primary_expression): Handle new user-defined literal tokens with new functions. * semantics.c: (potential_constant_expression_1): Add user-defined literals. * typeck.c (check_raw_literal_operator, check_literal_operator_args): New. From-SVN: r180536
2011-10-26 21:30:59 +02:00
{
return interpret_int_suffix (pfile, (const unsigned char *)s, len);
Implement C++11 user-defined literals. libcpp/ * expr.c: (cpp_interpret_float_suffix, cpp_interpret_int_suffix, cpp_userdef_string_remove_type, cpp_userdef_string_add_type, cpp_userdef_char_remove_type, cpp_userdef_char_add_type, cpp_userdef_string_p, cpp_userdef_char_p, cpp_get_userdef_suffix): New. (cpp_classify_number): Classify unrecognized tokens as user-defined literals. * include/cpplib.h: Add new tokens for user-defined literals. * init.c: Add new preprocessor flag (cxx11). * lex.c: (lex_string, lex_raw_string): Handle user-defined literals including concatenation and promotion with suffixes. c-family/ * c-common.c (build_userdef_literal): New. * c-common.def: New tree code. * c-common.h (tree_userdef_literal): New tree struct and accessors. * c-lex.c (interpret_float): Add suffix parm. (c_lex_with_flags): Build literal tokens. cp/ * cp-objcp-common.c: (cp_tree_size) Return size of USERDEF_LITERAL tree. * cp-tree.h: (UDLIT_OP_*, UDLIT_OPER_P): Literal operator name tools. New tree code for user-defined literals. * cxx-pretty-print.h: (pp_cxx_userdef_literal) New. * cxx-pretty-print.c: (pp_cxx_userdef_literal) New. (pp_cxx_primary_expression, pp_cxx_expression): Use it. * decl.c: (cp_tree_node_structure): Return new tree code. (duplicate_decls): Check for raw vs. template operator conflicts. (grokfndecl, grokdeclarator): New checks for literal operators. * error.c: (dump_expr): Warn about user-defined literals in C++98 mode. (dump_function_name): Pretty printing. * mangle.c: (write_literal_operator_name): New. (write_unqualified_id, write_unqualified_name): Use it. * parser.c: (cp_parser_operator): Handle operator"". (cp_parser_userdef_char_literal, cp_parser_userdef_numeric_literal, cp_parser_userdef_string_literal): New. (cp_parser_primary_expression): Handle new user-defined literal tokens with new functions. * semantics.c: (potential_constant_expression_1): Add user-defined literals. * typeck.c (check_raw_literal_operator, check_literal_operator_args): New. From-SVN: r180536
2011-10-26 21:30:59 +02:00
}
/* Return the string type corresponding to the the input user-defined string
literal type. If the input type is not a user-defined string literal
type return the input type. */
enum cpp_ttype
cpp_userdef_string_remove_type (enum cpp_ttype type)
{
if (type == CPP_STRING_USERDEF)
return CPP_STRING;
else if (type == CPP_WSTRING_USERDEF)
return CPP_WSTRING;
else if (type == CPP_STRING16_USERDEF)
return CPP_STRING16;
else if (type == CPP_STRING32_USERDEF)
return CPP_STRING32;
else if (type == CPP_UTF8STRING_USERDEF)
return CPP_UTF8STRING;
else
return type;
}
/* Return the user-defined string literal type corresponding to the input
string type. If the input type is not a string type return the input
type. */
enum cpp_ttype
cpp_userdef_string_add_type (enum cpp_ttype type)
{
if (type == CPP_STRING)
return CPP_STRING_USERDEF;
else if (type == CPP_WSTRING)
return CPP_WSTRING_USERDEF;
else if (type == CPP_STRING16)
return CPP_STRING16_USERDEF;
else if (type == CPP_STRING32)
return CPP_STRING32_USERDEF;
else if (type == CPP_UTF8STRING)
return CPP_UTF8STRING_USERDEF;
else
return type;
}
/* Return the char type corresponding to the the input user-defined char
literal type. If the input type is not a user-defined char literal
type return the input type. */
enum cpp_ttype
cpp_userdef_char_remove_type (enum cpp_ttype type)
{
if (type == CPP_CHAR_USERDEF)
return CPP_CHAR;
else if (type == CPP_WCHAR_USERDEF)
return CPP_WCHAR;
else if (type == CPP_CHAR16_USERDEF)
return CPP_CHAR16;
Implement C++11 user-defined literals. libcpp/ * expr.c: (cpp_interpret_float_suffix, cpp_interpret_int_suffix, cpp_userdef_string_remove_type, cpp_userdef_string_add_type, cpp_userdef_char_remove_type, cpp_userdef_char_add_type, cpp_userdef_string_p, cpp_userdef_char_p, cpp_get_userdef_suffix): New. (cpp_classify_number): Classify unrecognized tokens as user-defined literals. * include/cpplib.h: Add new tokens for user-defined literals. * init.c: Add new preprocessor flag (cxx11). * lex.c: (lex_string, lex_raw_string): Handle user-defined literals including concatenation and promotion with suffixes. c-family/ * c-common.c (build_userdef_literal): New. * c-common.def: New tree code. * c-common.h (tree_userdef_literal): New tree struct and accessors. * c-lex.c (interpret_float): Add suffix parm. (c_lex_with_flags): Build literal tokens. cp/ * cp-objcp-common.c: (cp_tree_size) Return size of USERDEF_LITERAL tree. * cp-tree.h: (UDLIT_OP_*, UDLIT_OPER_P): Literal operator name tools. New tree code for user-defined literals. * cxx-pretty-print.h: (pp_cxx_userdef_literal) New. * cxx-pretty-print.c: (pp_cxx_userdef_literal) New. (pp_cxx_primary_expression, pp_cxx_expression): Use it. * decl.c: (cp_tree_node_structure): Return new tree code. (duplicate_decls): Check for raw vs. template operator conflicts. (grokfndecl, grokdeclarator): New checks for literal operators. * error.c: (dump_expr): Warn about user-defined literals in C++98 mode. (dump_function_name): Pretty printing. * mangle.c: (write_literal_operator_name): New. (write_unqualified_id, write_unqualified_name): Use it. * parser.c: (cp_parser_operator): Handle operator"". (cp_parser_userdef_char_literal, cp_parser_userdef_numeric_literal, cp_parser_userdef_string_literal): New. (cp_parser_primary_expression): Handle new user-defined literal tokens with new functions. * semantics.c: (potential_constant_expression_1): Add user-defined literals. * typeck.c (check_raw_literal_operator, check_literal_operator_args): New. From-SVN: r180536
2011-10-26 21:30:59 +02:00
else if (type == CPP_CHAR32_USERDEF)
return CPP_CHAR32;
Implement N4197 - Adding u8 character literals libcpp: 2015-06-30 Edward Smith-Rowland <3dw4rd@verizon.net> Implement N4197 - Adding u8 character literals * include/cpplib.h (UTF8CHAR, UTF8CHAR_USERDEF): New cpp tokens; (struct cpp_options): Add utf8_char_literals. * init.c (struct lang_flags): Add utf8_char_literals; (struct lang_flags lang_defaults): Add column for utf8_char_literals. * macro.c (stringify_arg()): Treat CPP_UTF8CHAR token; * expr.c (cpp_userdef_char_remove_type(), cpp_userdef_char_add_type()): Treat CPP_UTF8CHAR_USERDEF, CPP_UTF8CHAR tokens; (cpp_userdef_char_p()): Treat CPP_UTF8CHAR_USERDEF token; (eval_token(), _cpp_parse_expr()): Treat CPP_UTF8CHAR token. * lex.c (lex_string(), _cpp_lex_direct()): Include CPP_UTF8CHAR tokens. * charset.c (converter_for_type(), cpp_interpret_charconst()): Treat CPP_UTF8CHAR token. gcc/c-family: 2015-06-30 Edward Smith-Rowland <3dw4rd@verizon.net> Implement N4197 - Adding u8 character literals * c-family/c-ada-spec.c (print_ada_macros()): Treat CPP_UTF8CHAR like CPP_CHAR. * c-family/c-common.c (c_parse_error()): print CPP_UTF8CHAR and CPP_UTF8CHAR_USERDEF tokens. * c-family/c-lex.c (c_lex_with_flags()): Treat CPP_UTF8CHAR_USERDEF and CPP_UTF8CHAR tokens; (lex_charconst()): Treat CPP_UTF8CHAR token. gcc/cp: 2015-06-30 Edward Smith-Rowland <3dw4rd@verizon.net> Implement N4197 - Adding u8 character literals * parser.c (cp_parser_primary_expression()): Treat CPP_UTF8CHAR and CPP_UTF8CHAR_USERDEF tokens; (cp_parser_parenthesized_expression_list()): Treat CPP_UTF8CHAR token. gcc/testsuite: 2015-06-30 Edward Smith-Rowland <3dw4rd@verizon.net> Implement N4197 - Adding u8 character literals * g++.dg/cpp1z/utf8.C: New. * g++.dg/cpp1z/utf8-neg.C: New. * g++.dg/cpp1z/udlit-utf8char.C: New. From-SVN: r225185
2015-06-30 14:58:48 +02:00
else if (type == CPP_UTF8CHAR_USERDEF)
return CPP_UTF8CHAR;
Implement C++11 user-defined literals. libcpp/ * expr.c: (cpp_interpret_float_suffix, cpp_interpret_int_suffix, cpp_userdef_string_remove_type, cpp_userdef_string_add_type, cpp_userdef_char_remove_type, cpp_userdef_char_add_type, cpp_userdef_string_p, cpp_userdef_char_p, cpp_get_userdef_suffix): New. (cpp_classify_number): Classify unrecognized tokens as user-defined literals. * include/cpplib.h: Add new tokens for user-defined literals. * init.c: Add new preprocessor flag (cxx11). * lex.c: (lex_string, lex_raw_string): Handle user-defined literals including concatenation and promotion with suffixes. c-family/ * c-common.c (build_userdef_literal): New. * c-common.def: New tree code. * c-common.h (tree_userdef_literal): New tree struct and accessors. * c-lex.c (interpret_float): Add suffix parm. (c_lex_with_flags): Build literal tokens. cp/ * cp-objcp-common.c: (cp_tree_size) Return size of USERDEF_LITERAL tree. * cp-tree.h: (UDLIT_OP_*, UDLIT_OPER_P): Literal operator name tools. New tree code for user-defined literals. * cxx-pretty-print.h: (pp_cxx_userdef_literal) New. * cxx-pretty-print.c: (pp_cxx_userdef_literal) New. (pp_cxx_primary_expression, pp_cxx_expression): Use it. * decl.c: (cp_tree_node_structure): Return new tree code. (duplicate_decls): Check for raw vs. template operator conflicts. (grokfndecl, grokdeclarator): New checks for literal operators. * error.c: (dump_expr): Warn about user-defined literals in C++98 mode. (dump_function_name): Pretty printing. * mangle.c: (write_literal_operator_name): New. (write_unqualified_id, write_unqualified_name): Use it. * parser.c: (cp_parser_operator): Handle operator"". (cp_parser_userdef_char_literal, cp_parser_userdef_numeric_literal, cp_parser_userdef_string_literal): New. (cp_parser_primary_expression): Handle new user-defined literal tokens with new functions. * semantics.c: (potential_constant_expression_1): Add user-defined literals. * typeck.c (check_raw_literal_operator, check_literal_operator_args): New. From-SVN: r180536
2011-10-26 21:30:59 +02:00
else
return type;
}
/* Return the user-defined char literal type corresponding to the input
char type. If the input type is not a char type return the input
type. */
enum cpp_ttype
cpp_userdef_char_add_type (enum cpp_ttype type)
{
if (type == CPP_CHAR)
return CPP_CHAR_USERDEF;
else if (type == CPP_WCHAR)
return CPP_WCHAR_USERDEF;
else if (type == CPP_CHAR16)
return CPP_CHAR16_USERDEF;
else if (type == CPP_CHAR32)
return CPP_CHAR32_USERDEF;
Implement N4197 - Adding u8 character literals libcpp: 2015-06-30 Edward Smith-Rowland <3dw4rd@verizon.net> Implement N4197 - Adding u8 character literals * include/cpplib.h (UTF8CHAR, UTF8CHAR_USERDEF): New cpp tokens; (struct cpp_options): Add utf8_char_literals. * init.c (struct lang_flags): Add utf8_char_literals; (struct lang_flags lang_defaults): Add column for utf8_char_literals. * macro.c (stringify_arg()): Treat CPP_UTF8CHAR token; * expr.c (cpp_userdef_char_remove_type(), cpp_userdef_char_add_type()): Treat CPP_UTF8CHAR_USERDEF, CPP_UTF8CHAR tokens; (cpp_userdef_char_p()): Treat CPP_UTF8CHAR_USERDEF token; (eval_token(), _cpp_parse_expr()): Treat CPP_UTF8CHAR token. * lex.c (lex_string(), _cpp_lex_direct()): Include CPP_UTF8CHAR tokens. * charset.c (converter_for_type(), cpp_interpret_charconst()): Treat CPP_UTF8CHAR token. gcc/c-family: 2015-06-30 Edward Smith-Rowland <3dw4rd@verizon.net> Implement N4197 - Adding u8 character literals * c-family/c-ada-spec.c (print_ada_macros()): Treat CPP_UTF8CHAR like CPP_CHAR. * c-family/c-common.c (c_parse_error()): print CPP_UTF8CHAR and CPP_UTF8CHAR_USERDEF tokens. * c-family/c-lex.c (c_lex_with_flags()): Treat CPP_UTF8CHAR_USERDEF and CPP_UTF8CHAR tokens; (lex_charconst()): Treat CPP_UTF8CHAR token. gcc/cp: 2015-06-30 Edward Smith-Rowland <3dw4rd@verizon.net> Implement N4197 - Adding u8 character literals * parser.c (cp_parser_primary_expression()): Treat CPP_UTF8CHAR and CPP_UTF8CHAR_USERDEF tokens; (cp_parser_parenthesized_expression_list()): Treat CPP_UTF8CHAR token. gcc/testsuite: 2015-06-30 Edward Smith-Rowland <3dw4rd@verizon.net> Implement N4197 - Adding u8 character literals * g++.dg/cpp1z/utf8.C: New. * g++.dg/cpp1z/utf8-neg.C: New. * g++.dg/cpp1z/udlit-utf8char.C: New. From-SVN: r225185
2015-06-30 14:58:48 +02:00
else if (type == CPP_UTF8CHAR)
return CPP_UTF8CHAR_USERDEF;
Implement C++11 user-defined literals. libcpp/ * expr.c: (cpp_interpret_float_suffix, cpp_interpret_int_suffix, cpp_userdef_string_remove_type, cpp_userdef_string_add_type, cpp_userdef_char_remove_type, cpp_userdef_char_add_type, cpp_userdef_string_p, cpp_userdef_char_p, cpp_get_userdef_suffix): New. (cpp_classify_number): Classify unrecognized tokens as user-defined literals. * include/cpplib.h: Add new tokens for user-defined literals. * init.c: Add new preprocessor flag (cxx11). * lex.c: (lex_string, lex_raw_string): Handle user-defined literals including concatenation and promotion with suffixes. c-family/ * c-common.c (build_userdef_literal): New. * c-common.def: New tree code. * c-common.h (tree_userdef_literal): New tree struct and accessors. * c-lex.c (interpret_float): Add suffix parm. (c_lex_with_flags): Build literal tokens. cp/ * cp-objcp-common.c: (cp_tree_size) Return size of USERDEF_LITERAL tree. * cp-tree.h: (UDLIT_OP_*, UDLIT_OPER_P): Literal operator name tools. New tree code for user-defined literals. * cxx-pretty-print.h: (pp_cxx_userdef_literal) New. * cxx-pretty-print.c: (pp_cxx_userdef_literal) New. (pp_cxx_primary_expression, pp_cxx_expression): Use it. * decl.c: (cp_tree_node_structure): Return new tree code. (duplicate_decls): Check for raw vs. template operator conflicts. (grokfndecl, grokdeclarator): New checks for literal operators. * error.c: (dump_expr): Warn about user-defined literals in C++98 mode. (dump_function_name): Pretty printing. * mangle.c: (write_literal_operator_name): New. (write_unqualified_id, write_unqualified_name): Use it. * parser.c: (cp_parser_operator): Handle operator"". (cp_parser_userdef_char_literal, cp_parser_userdef_numeric_literal, cp_parser_userdef_string_literal): New. (cp_parser_primary_expression): Handle new user-defined literal tokens with new functions. * semantics.c: (potential_constant_expression_1): Add user-defined literals. * typeck.c (check_raw_literal_operator, check_literal_operator_args): New. From-SVN: r180536
2011-10-26 21:30:59 +02:00
else
return type;
}
/* Return true if the token type is a user-defined string literal. */
bool
cpp_userdef_string_p (enum cpp_ttype type)
{
if (type == CPP_STRING_USERDEF
|| type == CPP_WSTRING_USERDEF
|| type == CPP_STRING16_USERDEF
|| type == CPP_STRING32_USERDEF
|| type == CPP_UTF8STRING_USERDEF)
return true;
else
return false;
}
/* Return true if the token type is a user-defined char literal. */
bool
cpp_userdef_char_p (enum cpp_ttype type)
{
if (type == CPP_CHAR_USERDEF
|| type == CPP_WCHAR_USERDEF
|| type == CPP_CHAR16_USERDEF
Implement N4197 - Adding u8 character literals libcpp: 2015-06-30 Edward Smith-Rowland <3dw4rd@verizon.net> Implement N4197 - Adding u8 character literals * include/cpplib.h (UTF8CHAR, UTF8CHAR_USERDEF): New cpp tokens; (struct cpp_options): Add utf8_char_literals. * init.c (struct lang_flags): Add utf8_char_literals; (struct lang_flags lang_defaults): Add column for utf8_char_literals. * macro.c (stringify_arg()): Treat CPP_UTF8CHAR token; * expr.c (cpp_userdef_char_remove_type(), cpp_userdef_char_add_type()): Treat CPP_UTF8CHAR_USERDEF, CPP_UTF8CHAR tokens; (cpp_userdef_char_p()): Treat CPP_UTF8CHAR_USERDEF token; (eval_token(), _cpp_parse_expr()): Treat CPP_UTF8CHAR token. * lex.c (lex_string(), _cpp_lex_direct()): Include CPP_UTF8CHAR tokens. * charset.c (converter_for_type(), cpp_interpret_charconst()): Treat CPP_UTF8CHAR token. gcc/c-family: 2015-06-30 Edward Smith-Rowland <3dw4rd@verizon.net> Implement N4197 - Adding u8 character literals * c-family/c-ada-spec.c (print_ada_macros()): Treat CPP_UTF8CHAR like CPP_CHAR. * c-family/c-common.c (c_parse_error()): print CPP_UTF8CHAR and CPP_UTF8CHAR_USERDEF tokens. * c-family/c-lex.c (c_lex_with_flags()): Treat CPP_UTF8CHAR_USERDEF and CPP_UTF8CHAR tokens; (lex_charconst()): Treat CPP_UTF8CHAR token. gcc/cp: 2015-06-30 Edward Smith-Rowland <3dw4rd@verizon.net> Implement N4197 - Adding u8 character literals * parser.c (cp_parser_primary_expression()): Treat CPP_UTF8CHAR and CPP_UTF8CHAR_USERDEF tokens; (cp_parser_parenthesized_expression_list()): Treat CPP_UTF8CHAR token. gcc/testsuite: 2015-06-30 Edward Smith-Rowland <3dw4rd@verizon.net> Implement N4197 - Adding u8 character literals * g++.dg/cpp1z/utf8.C: New. * g++.dg/cpp1z/utf8-neg.C: New. * g++.dg/cpp1z/udlit-utf8char.C: New. From-SVN: r225185
2015-06-30 14:58:48 +02:00
|| type == CPP_CHAR32_USERDEF
|| type == CPP_UTF8CHAR_USERDEF)
Implement C++11 user-defined literals. libcpp/ * expr.c: (cpp_interpret_float_suffix, cpp_interpret_int_suffix, cpp_userdef_string_remove_type, cpp_userdef_string_add_type, cpp_userdef_char_remove_type, cpp_userdef_char_add_type, cpp_userdef_string_p, cpp_userdef_char_p, cpp_get_userdef_suffix): New. (cpp_classify_number): Classify unrecognized tokens as user-defined literals. * include/cpplib.h: Add new tokens for user-defined literals. * init.c: Add new preprocessor flag (cxx11). * lex.c: (lex_string, lex_raw_string): Handle user-defined literals including concatenation and promotion with suffixes. c-family/ * c-common.c (build_userdef_literal): New. * c-common.def: New tree code. * c-common.h (tree_userdef_literal): New tree struct and accessors. * c-lex.c (interpret_float): Add suffix parm. (c_lex_with_flags): Build literal tokens. cp/ * cp-objcp-common.c: (cp_tree_size) Return size of USERDEF_LITERAL tree. * cp-tree.h: (UDLIT_OP_*, UDLIT_OPER_P): Literal operator name tools. New tree code for user-defined literals. * cxx-pretty-print.h: (pp_cxx_userdef_literal) New. * cxx-pretty-print.c: (pp_cxx_userdef_literal) New. (pp_cxx_primary_expression, pp_cxx_expression): Use it. * decl.c: (cp_tree_node_structure): Return new tree code. (duplicate_decls): Check for raw vs. template operator conflicts. (grokfndecl, grokdeclarator): New checks for literal operators. * error.c: (dump_expr): Warn about user-defined literals in C++98 mode. (dump_function_name): Pretty printing. * mangle.c: (write_literal_operator_name): New. (write_unqualified_id, write_unqualified_name): Use it. * parser.c: (cp_parser_operator): Handle operator"". (cp_parser_userdef_char_literal, cp_parser_userdef_numeric_literal, cp_parser_userdef_string_literal): New. (cp_parser_primary_expression): Handle new user-defined literal tokens with new functions. * semantics.c: (potential_constant_expression_1): Add user-defined literals. * typeck.c (check_raw_literal_operator, check_literal_operator_args): New. From-SVN: r180536
2011-10-26 21:30:59 +02:00
return true;
else
return false;
}
/* Extract the suffix from a user-defined literal string or char. */
const char *
cpp_get_userdef_suffix (const cpp_token *tok)
{
unsigned int len = tok->val.str.len;
const char *text = (const char *)tok->val.str.text;
char delim;
unsigned int i;
for (i = 0; i < len; ++i)
if (text[i] == '\'' || text[i] == '"')
break;
if (i == len)
return text + len;
delim = text[i];
for (i = len; i > 0; --i)
if (text[i - 1] == delim)
break;
return text + i;
}
/* Categorize numeric constants according to their field (integer,
floating point, or invalid), radix (decimal, octal, hexadecimal),
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
and type suffixes.
TOKEN is the token that represents the numeric constant to
classify.
In C++0X if UD_SUFFIX is non null it will be assigned
any unrecognized suffix for a user-defined literal.
VIRTUAL_LOCATION is the virtual location for TOKEN. */
unsigned int
Implement C++11 user-defined literals. libcpp/ * expr.c: (cpp_interpret_float_suffix, cpp_interpret_int_suffix, cpp_userdef_string_remove_type, cpp_userdef_string_add_type, cpp_userdef_char_remove_type, cpp_userdef_char_add_type, cpp_userdef_string_p, cpp_userdef_char_p, cpp_get_userdef_suffix): New. (cpp_classify_number): Classify unrecognized tokens as user-defined literals. * include/cpplib.h: Add new tokens for user-defined literals. * init.c: Add new preprocessor flag (cxx11). * lex.c: (lex_string, lex_raw_string): Handle user-defined literals including concatenation and promotion with suffixes. c-family/ * c-common.c (build_userdef_literal): New. * c-common.def: New tree code. * c-common.h (tree_userdef_literal): New tree struct and accessors. * c-lex.c (interpret_float): Add suffix parm. (c_lex_with_flags): Build literal tokens. cp/ * cp-objcp-common.c: (cp_tree_size) Return size of USERDEF_LITERAL tree. * cp-tree.h: (UDLIT_OP_*, UDLIT_OPER_P): Literal operator name tools. New tree code for user-defined literals. * cxx-pretty-print.h: (pp_cxx_userdef_literal) New. * cxx-pretty-print.c: (pp_cxx_userdef_literal) New. (pp_cxx_primary_expression, pp_cxx_expression): Use it. * decl.c: (cp_tree_node_structure): Return new tree code. (duplicate_decls): Check for raw vs. template operator conflicts. (grokfndecl, grokdeclarator): New checks for literal operators. * error.c: (dump_expr): Warn about user-defined literals in C++98 mode. (dump_function_name): Pretty printing. * mangle.c: (write_literal_operator_name): New. (write_unqualified_id, write_unqualified_name): Use it. * parser.c: (cp_parser_operator): Handle operator"". (cp_parser_userdef_char_literal, cp_parser_userdef_numeric_literal, cp_parser_userdef_string_literal): New. (cp_parser_primary_expression): Handle new user-defined literal tokens with new functions. * semantics.c: (potential_constant_expression_1): Add user-defined literals. * typeck.c (check_raw_literal_operator, check_literal_operator_args): New. From-SVN: r180536
2011-10-26 21:30:59 +02:00
cpp_classify_number (cpp_reader *pfile, const cpp_token *token,
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
const char **ud_suffix, source_location virtual_location)
{
const uchar *str = token->val.str.text;
const uchar *limit;
unsigned int max_digit, result, radix;
enum {NOT_FLOAT = 0, AFTER_POINT, AFTER_EXPON} float_flag;
bool seen_digit;
bool seen_digit_sep;
Implement C++11 user-defined literals. libcpp/ * expr.c: (cpp_interpret_float_suffix, cpp_interpret_int_suffix, cpp_userdef_string_remove_type, cpp_userdef_string_add_type, cpp_userdef_char_remove_type, cpp_userdef_char_add_type, cpp_userdef_string_p, cpp_userdef_char_p, cpp_get_userdef_suffix): New. (cpp_classify_number): Classify unrecognized tokens as user-defined literals. * include/cpplib.h: Add new tokens for user-defined literals. * init.c: Add new preprocessor flag (cxx11). * lex.c: (lex_string, lex_raw_string): Handle user-defined literals including concatenation and promotion with suffixes. c-family/ * c-common.c (build_userdef_literal): New. * c-common.def: New tree code. * c-common.h (tree_userdef_literal): New tree struct and accessors. * c-lex.c (interpret_float): Add suffix parm. (c_lex_with_flags): Build literal tokens. cp/ * cp-objcp-common.c: (cp_tree_size) Return size of USERDEF_LITERAL tree. * cp-tree.h: (UDLIT_OP_*, UDLIT_OPER_P): Literal operator name tools. New tree code for user-defined literals. * cxx-pretty-print.h: (pp_cxx_userdef_literal) New. * cxx-pretty-print.c: (pp_cxx_userdef_literal) New. (pp_cxx_primary_expression, pp_cxx_expression): Use it. * decl.c: (cp_tree_node_structure): Return new tree code. (duplicate_decls): Check for raw vs. template operator conflicts. (grokfndecl, grokdeclarator): New checks for literal operators. * error.c: (dump_expr): Warn about user-defined literals in C++98 mode. (dump_function_name): Pretty printing. * mangle.c: (write_literal_operator_name): New. (write_unqualified_id, write_unqualified_name): Use it. * parser.c: (cp_parser_operator): Handle operator"". (cp_parser_userdef_char_literal, cp_parser_userdef_numeric_literal, cp_parser_userdef_string_literal): New. (cp_parser_primary_expression): Handle new user-defined literal tokens with new functions. * semantics.c: (potential_constant_expression_1): Add user-defined literals. * typeck.c (check_raw_literal_operator, check_literal_operator_args): New. From-SVN: r180536
2011-10-26 21:30:59 +02:00
if (ud_suffix)
*ud_suffix = NULL;
/* If the lexer has done its job, length one can only be a single
digit. Fast-path this very common case. */
if (token->val.str.len == 1)
return CPP_N_INTEGER | CPP_N_SMALL | CPP_N_DECIMAL;
limit = str + token->val.str.len;
float_flag = NOT_FLOAT;
max_digit = 0;
radix = 10;
seen_digit = false;
seen_digit_sep = false;
/* First, interpret the radix. */
if (*str == '0')
{
radix = 8;
str++;
/* Require at least one hex digit to classify it as hex. */
if (*str == 'x' || *str == 'X')
{
if (str[1] == '.' || ISXDIGIT (str[1]))
{
radix = 16;
str++;
}
else if (DIGIT_SEP (str[1]))
SYNTAX_ERROR_AT (virtual_location,
"digit separator after base indicator");
}
else if (*str == 'b' || *str == 'B')
{
if (str[1] == '0' || str[1] == '1')
{
radix = 2;
str++;
}
else if (DIGIT_SEP (str[1]))
SYNTAX_ERROR_AT (virtual_location,
"digit separator after base indicator");
}
}
/* Now scan for a well-formed integer or float. */
for (;;)
{
unsigned int c = *str++;
if (ISDIGIT (c) || (ISXDIGIT (c) && radix == 16))
{
seen_digit_sep = false;
seen_digit = true;
c = hex_value (c);
if (c > max_digit)
max_digit = c;
}
else if (DIGIT_SEP (c))
{
if (seen_digit_sep)
SYNTAX_ERROR_AT (virtual_location, "adjacent digit separators");
seen_digit_sep = true;
}
else if (c == '.')
{
if (seen_digit_sep || DIGIT_SEP (*str))
SYNTAX_ERROR_AT (virtual_location,
"digit separator adjacent to decimal point");
seen_digit_sep = false;
if (float_flag == NOT_FLOAT)
float_flag = AFTER_POINT;
else
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
SYNTAX_ERROR_AT (virtual_location,
"too many decimal points in number");
}
else if ((radix <= 10 && (c == 'e' || c == 'E'))
|| (radix == 16 && (c == 'p' || c == 'P')))
{
if (seen_digit_sep || DIGIT_SEP (*str))
SYNTAX_ERROR_AT (virtual_location,
"digit separator adjacent to exponent");
float_flag = AFTER_EXPON;
break;
}
else
{
/* Start of suffix. */
str--;
break;
}
}
if (seen_digit_sep && float_flag != AFTER_EXPON)
SYNTAX_ERROR_AT (virtual_location,
"digit separator outside digit sequence");
/* The suffix may be for decimal fixed-point constants without exponent. */
if (radix != 16 && float_flag == NOT_FLOAT)
{
result = interpret_float_suffix (pfile, str, limit - str);
if ((result & CPP_N_FRACT) || (result & CPP_N_ACCUM))
{
result |= CPP_N_FLOATING;
/* We need to restore the radix to 10, if the radix is 8. */
if (radix == 8)
radix = 10;
if (CPP_PEDANTIC (pfile))
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
"fixed-point constants are a GCC extension");
goto syntax_ok;
}
else
result = 0;
}
if (float_flag != NOT_FLOAT && radix == 8)
radix = 10;
if (max_digit >= radix)
{
if (radix == 2)
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
SYNTAX_ERROR2_AT (virtual_location,
"invalid digit \"%c\" in binary constant", '0' + max_digit);
else
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
SYNTAX_ERROR2_AT (virtual_location,
"invalid digit \"%c\" in octal constant", '0' + max_digit);
}
if (float_flag != NOT_FLOAT)
{
if (radix == 2)
{
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
cpp_error_with_line (pfile, CPP_DL_ERROR, virtual_location, 0,
"invalid prefix \"0b\" for floating constant");
return CPP_N_INVALID;
}
if (radix == 16 && !seen_digit)
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
SYNTAX_ERROR_AT (virtual_location,
"no digits in hexadecimal floating constant");
if (radix == 16 && CPP_PEDANTIC (pfile)
&& !CPP_OPTION (pfile, extended_numbers))
{
if (CPP_OPTION (pfile, cplusplus))
cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
"use of C++1z hexadecimal floating constant");
else
cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
"use of C99 hexadecimal floating constant");
}
if (float_flag == AFTER_EXPON)
{
if (*str == '+' || *str == '-')
str++;
/* Exponent is decimal, even if string is a hex float. */
if (!ISDIGIT (*str))
{
if (DIGIT_SEP (*str))
SYNTAX_ERROR_AT (virtual_location,
"digit separator adjacent to exponent");
else
SYNTAX_ERROR_AT (virtual_location, "exponent has no digits");
}
do
{
seen_digit_sep = DIGIT_SEP (*str);
str++;
}
while (ISDIGIT (*str) || DIGIT_SEP (*str));
}
else if (radix == 16)
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
SYNTAX_ERROR_AT (virtual_location,
"hexadecimal floating constants require an exponent");
if (seen_digit_sep)
SYNTAX_ERROR_AT (virtual_location,
"digit separator outside digit sequence");
result = interpret_float_suffix (pfile, str, limit - str);
if (result == 0)
{
Implement C++11 user-defined literals. libcpp/ * expr.c: (cpp_interpret_float_suffix, cpp_interpret_int_suffix, cpp_userdef_string_remove_type, cpp_userdef_string_add_type, cpp_userdef_char_remove_type, cpp_userdef_char_add_type, cpp_userdef_string_p, cpp_userdef_char_p, cpp_get_userdef_suffix): New. (cpp_classify_number): Classify unrecognized tokens as user-defined literals. * include/cpplib.h: Add new tokens for user-defined literals. * init.c: Add new preprocessor flag (cxx11). * lex.c: (lex_string, lex_raw_string): Handle user-defined literals including concatenation and promotion with suffixes. c-family/ * c-common.c (build_userdef_literal): New. * c-common.def: New tree code. * c-common.h (tree_userdef_literal): New tree struct and accessors. * c-lex.c (interpret_float): Add suffix parm. (c_lex_with_flags): Build literal tokens. cp/ * cp-objcp-common.c: (cp_tree_size) Return size of USERDEF_LITERAL tree. * cp-tree.h: (UDLIT_OP_*, UDLIT_OPER_P): Literal operator name tools. New tree code for user-defined literals. * cxx-pretty-print.h: (pp_cxx_userdef_literal) New. * cxx-pretty-print.c: (pp_cxx_userdef_literal) New. (pp_cxx_primary_expression, pp_cxx_expression): Use it. * decl.c: (cp_tree_node_structure): Return new tree code. (duplicate_decls): Check for raw vs. template operator conflicts. (grokfndecl, grokdeclarator): New checks for literal operators. * error.c: (dump_expr): Warn about user-defined literals in C++98 mode. (dump_function_name): Pretty printing. * mangle.c: (write_literal_operator_name): New. (write_unqualified_id, write_unqualified_name): Use it. * parser.c: (cp_parser_operator): Handle operator"". (cp_parser_userdef_char_literal, cp_parser_userdef_numeric_literal, cp_parser_userdef_string_literal): New. (cp_parser_primary_expression): Handle new user-defined literal tokens with new functions. * semantics.c: (potential_constant_expression_1): Add user-defined literals. * typeck.c (check_raw_literal_operator, check_literal_operator_args): New. From-SVN: r180536
2011-10-26 21:30:59 +02:00
if (CPP_OPTION (pfile, user_literals))
{
if (ud_suffix)
*ud_suffix = (const char *) str;
result = CPP_N_LARGE | CPP_N_USERDEF;
}
else
{
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
cpp_error_with_line (pfile, CPP_DL_ERROR, virtual_location, 0,
"invalid suffix \"%.*s\" on floating constant",
(int) (limit - str), str);
Implement C++11 user-defined literals. libcpp/ * expr.c: (cpp_interpret_float_suffix, cpp_interpret_int_suffix, cpp_userdef_string_remove_type, cpp_userdef_string_add_type, cpp_userdef_char_remove_type, cpp_userdef_char_add_type, cpp_userdef_string_p, cpp_userdef_char_p, cpp_get_userdef_suffix): New. (cpp_classify_number): Classify unrecognized tokens as user-defined literals. * include/cpplib.h: Add new tokens for user-defined literals. * init.c: Add new preprocessor flag (cxx11). * lex.c: (lex_string, lex_raw_string): Handle user-defined literals including concatenation and promotion with suffixes. c-family/ * c-common.c (build_userdef_literal): New. * c-common.def: New tree code. * c-common.h (tree_userdef_literal): New tree struct and accessors. * c-lex.c (interpret_float): Add suffix parm. (c_lex_with_flags): Build literal tokens. cp/ * cp-objcp-common.c: (cp_tree_size) Return size of USERDEF_LITERAL tree. * cp-tree.h: (UDLIT_OP_*, UDLIT_OPER_P): Literal operator name tools. New tree code for user-defined literals. * cxx-pretty-print.h: (pp_cxx_userdef_literal) New. * cxx-pretty-print.c: (pp_cxx_userdef_literal) New. (pp_cxx_primary_expression, pp_cxx_expression): Use it. * decl.c: (cp_tree_node_structure): Return new tree code. (duplicate_decls): Check for raw vs. template operator conflicts. (grokfndecl, grokdeclarator): New checks for literal operators. * error.c: (dump_expr): Warn about user-defined literals in C++98 mode. (dump_function_name): Pretty printing. * mangle.c: (write_literal_operator_name): New. (write_unqualified_id, write_unqualified_name): Use it. * parser.c: (cp_parser_operator): Handle operator"". (cp_parser_userdef_char_literal, cp_parser_userdef_numeric_literal, cp_parser_userdef_string_literal): New. (cp_parser_primary_expression): Handle new user-defined literal tokens with new functions. * semantics.c: (potential_constant_expression_1): Add user-defined literals. * typeck.c (check_raw_literal_operator, check_literal_operator_args): New. From-SVN: r180536
2011-10-26 21:30:59 +02:00
return CPP_N_INVALID;
}
}
/* Traditional C didn't accept any floating suffixes. */
if (limit != str
&& CPP_WTRADITIONAL (pfile)
&& ! cpp_sys_macro_p (pfile))
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
cpp_warning_with_line (pfile, CPP_W_TRADITIONAL, virtual_location, 0,
"traditional C rejects the \"%.*s\" suffix",
(int) (limit - str), str);
/* A suffix for double is a GCC extension via decimal float support.
If the suffix also specifies an imaginary value we'll catch that
later. */
if ((result == CPP_N_MEDIUM) && CPP_PEDANTIC (pfile))
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
"suffix for double constant is a GCC extension");
/* Radix must be 10 for decimal floats. */
if ((result & CPP_N_DFLOAT) && radix != 10)
{
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
cpp_error_with_line (pfile, CPP_DL_ERROR, virtual_location, 0,
"invalid suffix \"%.*s\" with hexadecimal floating constant",
(int) (limit - str), str);
return CPP_N_INVALID;
}
if ((result & (CPP_N_FRACT | CPP_N_ACCUM)) && CPP_PEDANTIC (pfile))
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
"fixed-point constants are a GCC extension");
if ((result & CPP_N_DFLOAT) && CPP_PEDANTIC (pfile))
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
"decimal float constants are a GCC extension");
result |= CPP_N_FLOATING;
}
else
{
result = interpret_int_suffix (pfile, str, limit - str);
if (result == 0)
{
Implement C++11 user-defined literals. libcpp/ * expr.c: (cpp_interpret_float_suffix, cpp_interpret_int_suffix, cpp_userdef_string_remove_type, cpp_userdef_string_add_type, cpp_userdef_char_remove_type, cpp_userdef_char_add_type, cpp_userdef_string_p, cpp_userdef_char_p, cpp_get_userdef_suffix): New. (cpp_classify_number): Classify unrecognized tokens as user-defined literals. * include/cpplib.h: Add new tokens for user-defined literals. * init.c: Add new preprocessor flag (cxx11). * lex.c: (lex_string, lex_raw_string): Handle user-defined literals including concatenation and promotion with suffixes. c-family/ * c-common.c (build_userdef_literal): New. * c-common.def: New tree code. * c-common.h (tree_userdef_literal): New tree struct and accessors. * c-lex.c (interpret_float): Add suffix parm. (c_lex_with_flags): Build literal tokens. cp/ * cp-objcp-common.c: (cp_tree_size) Return size of USERDEF_LITERAL tree. * cp-tree.h: (UDLIT_OP_*, UDLIT_OPER_P): Literal operator name tools. New tree code for user-defined literals. * cxx-pretty-print.h: (pp_cxx_userdef_literal) New. * cxx-pretty-print.c: (pp_cxx_userdef_literal) New. (pp_cxx_primary_expression, pp_cxx_expression): Use it. * decl.c: (cp_tree_node_structure): Return new tree code. (duplicate_decls): Check for raw vs. template operator conflicts. (grokfndecl, grokdeclarator): New checks for literal operators. * error.c: (dump_expr): Warn about user-defined literals in C++98 mode. (dump_function_name): Pretty printing. * mangle.c: (write_literal_operator_name): New. (write_unqualified_id, write_unqualified_name): Use it. * parser.c: (cp_parser_operator): Handle operator"". (cp_parser_userdef_char_literal, cp_parser_userdef_numeric_literal, cp_parser_userdef_string_literal): New. (cp_parser_primary_expression): Handle new user-defined literal tokens with new functions. * semantics.c: (potential_constant_expression_1): Add user-defined literals. * typeck.c (check_raw_literal_operator, check_literal_operator_args): New. From-SVN: r180536
2011-10-26 21:30:59 +02:00
if (CPP_OPTION (pfile, user_literals))
{
if (ud_suffix)
*ud_suffix = (const char *) str;
result = CPP_N_UNSIGNED | CPP_N_LARGE | CPP_N_USERDEF;
}
else
{
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
cpp_error_with_line (pfile, CPP_DL_ERROR, virtual_location, 0,
"invalid suffix \"%.*s\" on integer constant",
(int) (limit - str), str);
Implement C++11 user-defined literals. libcpp/ * expr.c: (cpp_interpret_float_suffix, cpp_interpret_int_suffix, cpp_userdef_string_remove_type, cpp_userdef_string_add_type, cpp_userdef_char_remove_type, cpp_userdef_char_add_type, cpp_userdef_string_p, cpp_userdef_char_p, cpp_get_userdef_suffix): New. (cpp_classify_number): Classify unrecognized tokens as user-defined literals. * include/cpplib.h: Add new tokens for user-defined literals. * init.c: Add new preprocessor flag (cxx11). * lex.c: (lex_string, lex_raw_string): Handle user-defined literals including concatenation and promotion with suffixes. c-family/ * c-common.c (build_userdef_literal): New. * c-common.def: New tree code. * c-common.h (tree_userdef_literal): New tree struct and accessors. * c-lex.c (interpret_float): Add suffix parm. (c_lex_with_flags): Build literal tokens. cp/ * cp-objcp-common.c: (cp_tree_size) Return size of USERDEF_LITERAL tree. * cp-tree.h: (UDLIT_OP_*, UDLIT_OPER_P): Literal operator name tools. New tree code for user-defined literals. * cxx-pretty-print.h: (pp_cxx_userdef_literal) New. * cxx-pretty-print.c: (pp_cxx_userdef_literal) New. (pp_cxx_primary_expression, pp_cxx_expression): Use it. * decl.c: (cp_tree_node_structure): Return new tree code. (duplicate_decls): Check for raw vs. template operator conflicts. (grokfndecl, grokdeclarator): New checks for literal operators. * error.c: (dump_expr): Warn about user-defined literals in C++98 mode. (dump_function_name): Pretty printing. * mangle.c: (write_literal_operator_name): New. (write_unqualified_id, write_unqualified_name): Use it. * parser.c: (cp_parser_operator): Handle operator"". (cp_parser_userdef_char_literal, cp_parser_userdef_numeric_literal, cp_parser_userdef_string_literal): New. (cp_parser_primary_expression): Handle new user-defined literal tokens with new functions. * semantics.c: (potential_constant_expression_1): Add user-defined literals. * typeck.c (check_raw_literal_operator, check_literal_operator_args): New. From-SVN: r180536
2011-10-26 21:30:59 +02:00
return CPP_N_INVALID;
}
}
/* Traditional C only accepted the 'L' suffix.
Suppress warning about 'LL' with -Wno-long-long. */
if (CPP_WTRADITIONAL (pfile) && ! cpp_sys_macro_p (pfile))
{
int u_or_i = (result & (CPP_N_UNSIGNED|CPP_N_IMAGINARY));
diagnostic.h (diagnostic_override_option_index): New macro to set a diagnostic's option_index. * diagnostic.h (diagnostic_override_option_index): New macro to set a diagnostic's option_index. * c-tree.h (c_cpp_error): Add warning reason argument. * opts.c (_warning_as_error_callback): New. (register_warning_as_error_callback): Store callback for warnings enabled via enable_warning_as_error. (enable_warning_as_error): Call callback, minor code tidy. * opts.h (register_warning_as_error_callback): Declare. * c-opts.c (warning_as_error_callback): New, set cpp_opts flag in response to -Werror=. (c_common_init_options): Register warning_as_error_callback in opts.c. * common.opt: Add -Wno-cpp option. * c-common.c (struct reason_option_codes_t): Map cpp warning reason codes to gcc option indexes. * (c_option_controlling_cpp_error): New function, lookup the gcc option index for a cpp warning reason code. * (c_cpp_error): Add warning reason argument, call c_option_controlling_cpp_error for diagnostic_override_option_index. * doc/invoke.texi: Document -Wno-cpp. * cpp.c (cb_cpp_error): Add warning reason argument, set a value for diagnostic_override_option_index if CPP_W_WARNING_DIRECTIVE. * directives.c (do_diagnostic): Add warning reason argument, call appropriate error reporting function for code. (directive_diagnostics): Call specific warning functions with warning reason where appropriate. (do_error, do_warning, do_pragma_dependency): Add warning reason argument to do_diagnostic calls. * macro.c (_cpp_warn_if_unused_macro, enter_macro_context, _cpp_create_definition): Call specific warning functions with warning reason where appropriate. * Makefile.in: Add new diagnostic functions to gettext translations. * include/cpplib.h (struct cpp_callbacks): Add warning reason code to error callback. (CPP_DL_WARNING, CPP_DL_WARNING_SYSHDR, CPP_DL_PEDWARN, CPP_DL_ERROR, CPP_DL_ICE, CPP_DL_NOTE, CPP_DL_FATAL): Replace macros with enums. (CPP_W_NONE, CPP_W_DEPRECATED, CPP_W_COMMENTS, CPP_W_MISSING_INCLUDE_DIRS, CPP_W_TRIGRAPHS, CPP_W_MULTICHAR, CPP_W_TRADITIONAL, CPP_W_LONG_LONG, CPP_W_ENDIF_LABELS, CPP_W_NUM_SIGN_CHANGE, CPP_W_VARIADIC_MACROS, CPP_W_BUILTIN_MACRO_REDEFINED, CPP_W_DOLLARS, CPP_W_UNDEF, CPP_W_UNUSED_MACROS, CPP_W_CXX_OPERATOR_NAMES, CPP_W_NORMALIZE, CPP_W_INVALID_PCH, CPP_W_WARNING_DIRECTIVE): New enums for cpp warning reason codes. (cpp_warning, cpp_pedwarning, cpp_warning_syshdr, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): New specific error reporting functions. * pch.c (cpp_valid_state): Call specific warning functions with warning reason where appropriate. * errors.c (cpp_diagnostic, cpp_diagnostic_with_line): New central diagnostic handlers. (cpp_warning, cpp_pedwarning, cpp_warning_syshdr, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): New specific error reporting functions. * expr.c (cpp_classify_number, eval_token, num_unary_op): Call specific warning functions with warning reason where appropriate. * lex.c (_cpp_process_line_notes, _cpp_skip_block_comment, warn_about_normalization, lex_identifier_intern, lex_identifier, _cpp_lex_direct): Ditto. * charset.c (_cpp_valid_ucn, convert_hex, convert_escape, narrow_str_to_charconst): Ditto. * gcc.dg/cpp/warn-undef-2.c: New. * gcc.dg/cpp/warn-traditional-2.c: New. * gcc.dg/cpp/warn-comments-2.c: New. * gcc.dg/cpp/warning-directive-1.c: New. * gcc.dg/cpp/warn-long-long.c: New. * gcc.dg/cpp/warn-traditional.c: New. * gcc.dg/cpp/warn-variadic-2.c: New. * gcc.dg/cpp/warn-undef.c: New. * gcc.dg/cpp/warn-normalized-1.c: New. * gcc.dg/cpp/warning-directive-2.c: New. * gcc.dg/cpp/warn-long-long-2.c: New. * gcc.dg/cpp/warn-variadic.c: New. * gcc.dg/cpp/warn-normalized-2.c: New. * gcc.dg/cpp/warning-directive-3.c: New. * gcc.dg/cpp/warn-deprecated-2.c: New. * gcc.dg/cpp/warn-trigraphs-1.c: New. * gcc.dg/cpp/warn-multichar-2.c: New. * gcc.dg/cpp/warn-normalized-3.c: New. * gcc.dg/cpp/warning-directive-4.c: New. * gcc.dg/cpp/warn-unused-macros.c: New. * gcc.dg/cpp/warn-trigraphs-2.c: New. * gcc.dg/cpp/warn-cxx-compat-2.c: New. * gcc.dg/cpp/warn-cxx-compat.c: New. * gcc.dg/cpp/warn-redefined.c: New. * gcc.dg/cpp/warn-trigraphs-3.c: New. * gcc.dg/cpp/warn-unused-macros-2.c: New. * gcc.dg/cpp/warn-deprecated.c: New. * gcc.dg/cpp/warn-trigraphs-4.c: New. * gcc.dg/cpp/warn-redefined-2.c: New. * gcc.dg/cpp/warn-comments.c: New. * gcc.dg/cpp/warn-multichar.c: New. * g++.dg/cpp/warning-directive-1.C: New. * g++.dg/cpp/warning-directive-2.C: New. * g++.dg/cpp/warning-directive-3.C: New. * g++.dg/cpp/warning-directive-4.C: New. * gfortran.dg/warning-directive-1.F90: New. * gfortran.dg/warning-directive-3.F90: New. * gfortran.dg/warning-directive-2.F90: New. * gfortran.dg/warning-directive-4.F90: New. From-SVN: r158079
2010-04-07 19:18:10 +02:00
int large = (result & CPP_N_WIDTH) == CPP_N_LARGE
optc-gen.awk: Generate global_options initializer instead of individual variables. gcc: * optc-gen.awk: Generate global_options initializer instead of individual variables. Add x_ prefix to names of structure members. * opth-gen.awk: Generate gcc_options structure. Add x_ prefix to names of structure members. * doc/tm.texi.in (HARD_FRAME_POINTER_IS_FRAME_POINTER, HARD_FRAME_POINTER_IS_ARG_POINTER): Document. * doc/tm.texi: Regenerate. * alias.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER * builtins.c: Use HARD_FRAME_POINTER_IS_ARG_POINTER. * c-parser.c (disable_extension_diagnostics, restore_extension_diagnostics): Update names of cpp_options members. * combine.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER * common.opt (fcompare-debug-second): Don't use Var. * config/alpha/alpha.h (target_flags): Remove. * config/arm/arm.h (HARD_FRAME_POINTER_IS_FRAME_POINTER, HARD_FRAME_POINTER_IS_ARG_POINTER): Define. * config/bfin/bfin.h (target_flags): Remove. * config/cris/cris.h (target_flags): Remove. * config/i386/i386-c.c (ix86_pragma_target_parse): Update names of cl_target_option members. * config/i386/i386.c (ix86_force_align_arg_pointer): Remove. (ix86_function_specific_print, ix86_valid_target_attribute_tree, ix86_can_inline_p): Update names of cl_target_option members. * config/i386/i386.h (ix86_isa_flags): Remove. * config/lm32/lm32.h (target_flags): Remove. * config/mcore/mcore.h (mcore_stack_increment): Remove. * config/mcore/mcore.md (addsi3): Remove extern declaration of flag_omit_frame_pointer. * config/mep/mep.h (target_flags): Remove. * config/mips/mips.h (HARD_FRAME_POINTER_IS_FRAME_POINTER, HARD_FRAME_POINTER_IS_ARG_POINTER): Define. * config/mmix/mmix.h (target_flags): Remove. * config/rs6000/rs6000.h (rs6000_xilinx_fpu, flag_pic, flag_expensive_optimizations): Remove. * config/s390/s390.h (flag_pic): Remove. * config/score/score-conv.h (target_flags): Remove. * config/sh/sh.h (sh_fixed_range_str): Remove. * config/spu/spu.h (target_flags, spu_fixed_range_string): Remove. * dbxout.c: Use HARD_FRAME_POINTER_IS_ARG_POINTER * df-scan.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * diagnostic.c (diagnostic_initialize): Update names of diagnostic_context members. * diagnostic.h (diagnostic_context): Rename inhibit_warnings and warn_system_headers. (diagnostic_report_warnings_p): Update for new names. * dwarf2out.c: Use HARD_FRAME_POINTER_IS_ARG_POINTER * emit-rtl.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER and HARD_FRAME_POINTER_IS_ARG_POINTER. * flags.h (flag_compare_debug): Declare. * ira.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER * opts.c (flag_compare_debug): Define. (common_handle_option): Update names of diagnostic_context members. Handle -fcompare-debug-second. (fast_math_flags_struct_set_p): Update names of cl_optimization members. * reginfo.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * regrename.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * reload.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * reload1.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * resource.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * rtl.h (HARD_FRAME_POINTER_IS_FRAME_POINTER, HARD_FRAME_POINTER_IS_ARG_POINTER): Define and use. * sel-sched.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER * stmt.c: Use HARD_FRAME_POINTER_IS_ARG_POINTER. gcc/c-family: * c-common.c (c_cpp_error): Update names of diagnostic_context members. * c-cppbuiltin.c (c_cpp_builtins_optimize_pragma): Update names of cl_optimization members. * c-opts.c (warning_as_error_callback, c_common_handle_option, sanitize_cpp_opts, finish_options): Update names of cpp_options members. gcc/fortran: * cpp.c (cpp_define_builtins): Update names of gfc_option_t members. (gfc_cpp_post_options): Update names of cpp_options members. (cb_cpp_error): Update names of diagnostic_context members. * f95-lang.c (gfc_init_builtin_functions): Update names of gfc_option_t members. * gfortran.h (gfc_option_t): Rename warn_conversion and flag_openmp. * intrinsic.c (gfc_convert_type_warn): Update names of gfc_option_t members. * options.c (gfc_init_options, gfc_post_options, set_Wall, gfc_handle_option): Update names of gfc_option_t members. * parse.c (next_free, next_fixed): Update names of gfc_option_t members. * scanner.c (pedantic): Remove extern declaration. (skip_free_comments, skip_fixed_comments, include_line): Update names of gfc_option_t members. * trans-decl.c (gfc_generate_function_code): Update names of gfc_option_t members. gcc/java: * java-tree.h (flag_filelist_file, flag_assert, flag_jni, flag_force_classes_archive_check, flag_redundant, flag_newer, flag_use_divide_subroutine, flag_use_atomic_builtins, flag_use_boehm_gc, flag_hash_synchronization, flag_check_references, flag_optimize_sci, flag_indirect_classes, flag_indirect_dispatch, flag_store_check, flag_reduced_reflection): Remove. * jcf-dump.c (flag_newer): Remove. * jcf.h (quiet_flag): Remove. * parse.h (quiet_flag): Remove. libcpp: * include/cpplib.h (cpp_options): Rename warn_deprecated, warn_traditional, warn_long_long and pedantic. * directives.c (directive_diagnostics, _cpp_handle_directive): Update names of cpp_options members. * expr.c (cpp_classify_number, eval_token): Update names of cpp_options members. * init.c (cpp_create_reader, post_options): Update names of cpp_options members. * internal.h (CPP_PEDANTIC, CPP_WTRADITIONAL): Update names of cpp_options members. * macro.c (parse_params): Update names of cpp_options members. From-SVN: r164723
2010-09-29 16:49:14 +02:00
&& CPP_OPTION (pfile, cpp_warn_long_long);
diagnostic.h (diagnostic_override_option_index): New macro to set a diagnostic's option_index. * diagnostic.h (diagnostic_override_option_index): New macro to set a diagnostic's option_index. * c-tree.h (c_cpp_error): Add warning reason argument. * opts.c (_warning_as_error_callback): New. (register_warning_as_error_callback): Store callback for warnings enabled via enable_warning_as_error. (enable_warning_as_error): Call callback, minor code tidy. * opts.h (register_warning_as_error_callback): Declare. * c-opts.c (warning_as_error_callback): New, set cpp_opts flag in response to -Werror=. (c_common_init_options): Register warning_as_error_callback in opts.c. * common.opt: Add -Wno-cpp option. * c-common.c (struct reason_option_codes_t): Map cpp warning reason codes to gcc option indexes. * (c_option_controlling_cpp_error): New function, lookup the gcc option index for a cpp warning reason code. * (c_cpp_error): Add warning reason argument, call c_option_controlling_cpp_error for diagnostic_override_option_index. * doc/invoke.texi: Document -Wno-cpp. * cpp.c (cb_cpp_error): Add warning reason argument, set a value for diagnostic_override_option_index if CPP_W_WARNING_DIRECTIVE. * directives.c (do_diagnostic): Add warning reason argument, call appropriate error reporting function for code. (directive_diagnostics): Call specific warning functions with warning reason where appropriate. (do_error, do_warning, do_pragma_dependency): Add warning reason argument to do_diagnostic calls. * macro.c (_cpp_warn_if_unused_macro, enter_macro_context, _cpp_create_definition): Call specific warning functions with warning reason where appropriate. * Makefile.in: Add new diagnostic functions to gettext translations. * include/cpplib.h (struct cpp_callbacks): Add warning reason code to error callback. (CPP_DL_WARNING, CPP_DL_WARNING_SYSHDR, CPP_DL_PEDWARN, CPP_DL_ERROR, CPP_DL_ICE, CPP_DL_NOTE, CPP_DL_FATAL): Replace macros with enums. (CPP_W_NONE, CPP_W_DEPRECATED, CPP_W_COMMENTS, CPP_W_MISSING_INCLUDE_DIRS, CPP_W_TRIGRAPHS, CPP_W_MULTICHAR, CPP_W_TRADITIONAL, CPP_W_LONG_LONG, CPP_W_ENDIF_LABELS, CPP_W_NUM_SIGN_CHANGE, CPP_W_VARIADIC_MACROS, CPP_W_BUILTIN_MACRO_REDEFINED, CPP_W_DOLLARS, CPP_W_UNDEF, CPP_W_UNUSED_MACROS, CPP_W_CXX_OPERATOR_NAMES, CPP_W_NORMALIZE, CPP_W_INVALID_PCH, CPP_W_WARNING_DIRECTIVE): New enums for cpp warning reason codes. (cpp_warning, cpp_pedwarning, cpp_warning_syshdr, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): New specific error reporting functions. * pch.c (cpp_valid_state): Call specific warning functions with warning reason where appropriate. * errors.c (cpp_diagnostic, cpp_diagnostic_with_line): New central diagnostic handlers. (cpp_warning, cpp_pedwarning, cpp_warning_syshdr, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): New specific error reporting functions. * expr.c (cpp_classify_number, eval_token, num_unary_op): Call specific warning functions with warning reason where appropriate. * lex.c (_cpp_process_line_notes, _cpp_skip_block_comment, warn_about_normalization, lex_identifier_intern, lex_identifier, _cpp_lex_direct): Ditto. * charset.c (_cpp_valid_ucn, convert_hex, convert_escape, narrow_str_to_charconst): Ditto. * gcc.dg/cpp/warn-undef-2.c: New. * gcc.dg/cpp/warn-traditional-2.c: New. * gcc.dg/cpp/warn-comments-2.c: New. * gcc.dg/cpp/warning-directive-1.c: New. * gcc.dg/cpp/warn-long-long.c: New. * gcc.dg/cpp/warn-traditional.c: New. * gcc.dg/cpp/warn-variadic-2.c: New. * gcc.dg/cpp/warn-undef.c: New. * gcc.dg/cpp/warn-normalized-1.c: New. * gcc.dg/cpp/warning-directive-2.c: New. * gcc.dg/cpp/warn-long-long-2.c: New. * gcc.dg/cpp/warn-variadic.c: New. * gcc.dg/cpp/warn-normalized-2.c: New. * gcc.dg/cpp/warning-directive-3.c: New. * gcc.dg/cpp/warn-deprecated-2.c: New. * gcc.dg/cpp/warn-trigraphs-1.c: New. * gcc.dg/cpp/warn-multichar-2.c: New. * gcc.dg/cpp/warn-normalized-3.c: New. * gcc.dg/cpp/warning-directive-4.c: New. * gcc.dg/cpp/warn-unused-macros.c: New. * gcc.dg/cpp/warn-trigraphs-2.c: New. * gcc.dg/cpp/warn-cxx-compat-2.c: New. * gcc.dg/cpp/warn-cxx-compat.c: New. * gcc.dg/cpp/warn-redefined.c: New. * gcc.dg/cpp/warn-trigraphs-3.c: New. * gcc.dg/cpp/warn-unused-macros-2.c: New. * gcc.dg/cpp/warn-deprecated.c: New. * gcc.dg/cpp/warn-trigraphs-4.c: New. * gcc.dg/cpp/warn-redefined-2.c: New. * gcc.dg/cpp/warn-comments.c: New. * gcc.dg/cpp/warn-multichar.c: New. * g++.dg/cpp/warning-directive-1.C: New. * g++.dg/cpp/warning-directive-2.C: New. * g++.dg/cpp/warning-directive-3.C: New. * g++.dg/cpp/warning-directive-4.C: New. * gfortran.dg/warning-directive-1.F90: New. * gfortran.dg/warning-directive-3.F90: New. * gfortran.dg/warning-directive-2.F90: New. * gfortran.dg/warning-directive-4.F90: New. From-SVN: r158079
2010-04-07 19:18:10 +02:00
if (u_or_i || large)
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
cpp_warning_with_line (pfile, large ? CPP_W_LONG_LONG : CPP_W_TRADITIONAL,
virtual_location, 0,
"traditional C rejects the \"%.*s\" suffix",
(int) (limit - str), str);
}
if ((result & CPP_N_WIDTH) == CPP_N_LARGE
optc-gen.awk: Generate global_options initializer instead of individual variables. gcc: * optc-gen.awk: Generate global_options initializer instead of individual variables. Add x_ prefix to names of structure members. * opth-gen.awk: Generate gcc_options structure. Add x_ prefix to names of structure members. * doc/tm.texi.in (HARD_FRAME_POINTER_IS_FRAME_POINTER, HARD_FRAME_POINTER_IS_ARG_POINTER): Document. * doc/tm.texi: Regenerate. * alias.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER * builtins.c: Use HARD_FRAME_POINTER_IS_ARG_POINTER. * c-parser.c (disable_extension_diagnostics, restore_extension_diagnostics): Update names of cpp_options members. * combine.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER * common.opt (fcompare-debug-second): Don't use Var. * config/alpha/alpha.h (target_flags): Remove. * config/arm/arm.h (HARD_FRAME_POINTER_IS_FRAME_POINTER, HARD_FRAME_POINTER_IS_ARG_POINTER): Define. * config/bfin/bfin.h (target_flags): Remove. * config/cris/cris.h (target_flags): Remove. * config/i386/i386-c.c (ix86_pragma_target_parse): Update names of cl_target_option members. * config/i386/i386.c (ix86_force_align_arg_pointer): Remove. (ix86_function_specific_print, ix86_valid_target_attribute_tree, ix86_can_inline_p): Update names of cl_target_option members. * config/i386/i386.h (ix86_isa_flags): Remove. * config/lm32/lm32.h (target_flags): Remove. * config/mcore/mcore.h (mcore_stack_increment): Remove. * config/mcore/mcore.md (addsi3): Remove extern declaration of flag_omit_frame_pointer. * config/mep/mep.h (target_flags): Remove. * config/mips/mips.h (HARD_FRAME_POINTER_IS_FRAME_POINTER, HARD_FRAME_POINTER_IS_ARG_POINTER): Define. * config/mmix/mmix.h (target_flags): Remove. * config/rs6000/rs6000.h (rs6000_xilinx_fpu, flag_pic, flag_expensive_optimizations): Remove. * config/s390/s390.h (flag_pic): Remove. * config/score/score-conv.h (target_flags): Remove. * config/sh/sh.h (sh_fixed_range_str): Remove. * config/spu/spu.h (target_flags, spu_fixed_range_string): Remove. * dbxout.c: Use HARD_FRAME_POINTER_IS_ARG_POINTER * df-scan.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * diagnostic.c (diagnostic_initialize): Update names of diagnostic_context members. * diagnostic.h (diagnostic_context): Rename inhibit_warnings and warn_system_headers. (diagnostic_report_warnings_p): Update for new names. * dwarf2out.c: Use HARD_FRAME_POINTER_IS_ARG_POINTER * emit-rtl.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER and HARD_FRAME_POINTER_IS_ARG_POINTER. * flags.h (flag_compare_debug): Declare. * ira.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER * opts.c (flag_compare_debug): Define. (common_handle_option): Update names of diagnostic_context members. Handle -fcompare-debug-second. (fast_math_flags_struct_set_p): Update names of cl_optimization members. * reginfo.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * regrename.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * reload.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * reload1.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * resource.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * rtl.h (HARD_FRAME_POINTER_IS_FRAME_POINTER, HARD_FRAME_POINTER_IS_ARG_POINTER): Define and use. * sel-sched.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER * stmt.c: Use HARD_FRAME_POINTER_IS_ARG_POINTER. gcc/c-family: * c-common.c (c_cpp_error): Update names of diagnostic_context members. * c-cppbuiltin.c (c_cpp_builtins_optimize_pragma): Update names of cl_optimization members. * c-opts.c (warning_as_error_callback, c_common_handle_option, sanitize_cpp_opts, finish_options): Update names of cpp_options members. gcc/fortran: * cpp.c (cpp_define_builtins): Update names of gfc_option_t members. (gfc_cpp_post_options): Update names of cpp_options members. (cb_cpp_error): Update names of diagnostic_context members. * f95-lang.c (gfc_init_builtin_functions): Update names of gfc_option_t members. * gfortran.h (gfc_option_t): Rename warn_conversion and flag_openmp. * intrinsic.c (gfc_convert_type_warn): Update names of gfc_option_t members. * options.c (gfc_init_options, gfc_post_options, set_Wall, gfc_handle_option): Update names of gfc_option_t members. * parse.c (next_free, next_fixed): Update names of gfc_option_t members. * scanner.c (pedantic): Remove extern declaration. (skip_free_comments, skip_fixed_comments, include_line): Update names of gfc_option_t members. * trans-decl.c (gfc_generate_function_code): Update names of gfc_option_t members. gcc/java: * java-tree.h (flag_filelist_file, flag_assert, flag_jni, flag_force_classes_archive_check, flag_redundant, flag_newer, flag_use_divide_subroutine, flag_use_atomic_builtins, flag_use_boehm_gc, flag_hash_synchronization, flag_check_references, flag_optimize_sci, flag_indirect_classes, flag_indirect_dispatch, flag_store_check, flag_reduced_reflection): Remove. * jcf-dump.c (flag_newer): Remove. * jcf.h (quiet_flag): Remove. * parse.h (quiet_flag): Remove. libcpp: * include/cpplib.h (cpp_options): Rename warn_deprecated, warn_traditional, warn_long_long and pedantic. * directives.c (directive_diagnostics, _cpp_handle_directive): Update names of cpp_options members. * expr.c (cpp_classify_number, eval_token): Update names of cpp_options members. * init.c (cpp_create_reader, post_options): Update names of cpp_options members. * internal.h (CPP_PEDANTIC, CPP_WTRADITIONAL): Update names of cpp_options members. * macro.c (parse_params): Update names of cpp_options members. From-SVN: r164723
2010-09-29 16:49:14 +02:00
&& CPP_OPTION (pfile, cpp_warn_long_long))
diagnostic.h (diagnostic_override_option_index): New macro to set a diagnostic's option_index. * diagnostic.h (diagnostic_override_option_index): New macro to set a diagnostic's option_index. * c-tree.h (c_cpp_error): Add warning reason argument. * opts.c (_warning_as_error_callback): New. (register_warning_as_error_callback): Store callback for warnings enabled via enable_warning_as_error. (enable_warning_as_error): Call callback, minor code tidy. * opts.h (register_warning_as_error_callback): Declare. * c-opts.c (warning_as_error_callback): New, set cpp_opts flag in response to -Werror=. (c_common_init_options): Register warning_as_error_callback in opts.c. * common.opt: Add -Wno-cpp option. * c-common.c (struct reason_option_codes_t): Map cpp warning reason codes to gcc option indexes. * (c_option_controlling_cpp_error): New function, lookup the gcc option index for a cpp warning reason code. * (c_cpp_error): Add warning reason argument, call c_option_controlling_cpp_error for diagnostic_override_option_index. * doc/invoke.texi: Document -Wno-cpp. * cpp.c (cb_cpp_error): Add warning reason argument, set a value for diagnostic_override_option_index if CPP_W_WARNING_DIRECTIVE. * directives.c (do_diagnostic): Add warning reason argument, call appropriate error reporting function for code. (directive_diagnostics): Call specific warning functions with warning reason where appropriate. (do_error, do_warning, do_pragma_dependency): Add warning reason argument to do_diagnostic calls. * macro.c (_cpp_warn_if_unused_macro, enter_macro_context, _cpp_create_definition): Call specific warning functions with warning reason where appropriate. * Makefile.in: Add new diagnostic functions to gettext translations. * include/cpplib.h (struct cpp_callbacks): Add warning reason code to error callback. (CPP_DL_WARNING, CPP_DL_WARNING_SYSHDR, CPP_DL_PEDWARN, CPP_DL_ERROR, CPP_DL_ICE, CPP_DL_NOTE, CPP_DL_FATAL): Replace macros with enums. (CPP_W_NONE, CPP_W_DEPRECATED, CPP_W_COMMENTS, CPP_W_MISSING_INCLUDE_DIRS, CPP_W_TRIGRAPHS, CPP_W_MULTICHAR, CPP_W_TRADITIONAL, CPP_W_LONG_LONG, CPP_W_ENDIF_LABELS, CPP_W_NUM_SIGN_CHANGE, CPP_W_VARIADIC_MACROS, CPP_W_BUILTIN_MACRO_REDEFINED, CPP_W_DOLLARS, CPP_W_UNDEF, CPP_W_UNUSED_MACROS, CPP_W_CXX_OPERATOR_NAMES, CPP_W_NORMALIZE, CPP_W_INVALID_PCH, CPP_W_WARNING_DIRECTIVE): New enums for cpp warning reason codes. (cpp_warning, cpp_pedwarning, cpp_warning_syshdr, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): New specific error reporting functions. * pch.c (cpp_valid_state): Call specific warning functions with warning reason where appropriate. * errors.c (cpp_diagnostic, cpp_diagnostic_with_line): New central diagnostic handlers. (cpp_warning, cpp_pedwarning, cpp_warning_syshdr, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): New specific error reporting functions. * expr.c (cpp_classify_number, eval_token, num_unary_op): Call specific warning functions with warning reason where appropriate. * lex.c (_cpp_process_line_notes, _cpp_skip_block_comment, warn_about_normalization, lex_identifier_intern, lex_identifier, _cpp_lex_direct): Ditto. * charset.c (_cpp_valid_ucn, convert_hex, convert_escape, narrow_str_to_charconst): Ditto. * gcc.dg/cpp/warn-undef-2.c: New. * gcc.dg/cpp/warn-traditional-2.c: New. * gcc.dg/cpp/warn-comments-2.c: New. * gcc.dg/cpp/warning-directive-1.c: New. * gcc.dg/cpp/warn-long-long.c: New. * gcc.dg/cpp/warn-traditional.c: New. * gcc.dg/cpp/warn-variadic-2.c: New. * gcc.dg/cpp/warn-undef.c: New. * gcc.dg/cpp/warn-normalized-1.c: New. * gcc.dg/cpp/warning-directive-2.c: New. * gcc.dg/cpp/warn-long-long-2.c: New. * gcc.dg/cpp/warn-variadic.c: New. * gcc.dg/cpp/warn-normalized-2.c: New. * gcc.dg/cpp/warning-directive-3.c: New. * gcc.dg/cpp/warn-deprecated-2.c: New. * gcc.dg/cpp/warn-trigraphs-1.c: New. * gcc.dg/cpp/warn-multichar-2.c: New. * gcc.dg/cpp/warn-normalized-3.c: New. * gcc.dg/cpp/warning-directive-4.c: New. * gcc.dg/cpp/warn-unused-macros.c: New. * gcc.dg/cpp/warn-trigraphs-2.c: New. * gcc.dg/cpp/warn-cxx-compat-2.c: New. * gcc.dg/cpp/warn-cxx-compat.c: New. * gcc.dg/cpp/warn-redefined.c: New. * gcc.dg/cpp/warn-trigraphs-3.c: New. * gcc.dg/cpp/warn-unused-macros-2.c: New. * gcc.dg/cpp/warn-deprecated.c: New. * gcc.dg/cpp/warn-trigraphs-4.c: New. * gcc.dg/cpp/warn-redefined-2.c: New. * gcc.dg/cpp/warn-comments.c: New. * gcc.dg/cpp/warn-multichar.c: New. * g++.dg/cpp/warning-directive-1.C: New. * g++.dg/cpp/warning-directive-2.C: New. * g++.dg/cpp/warning-directive-3.C: New. * g++.dg/cpp/warning-directive-4.C: New. * gfortran.dg/warning-directive-1.F90: New. * gfortran.dg/warning-directive-3.F90: New. * gfortran.dg/warning-directive-2.F90: New. * gfortran.dg/warning-directive-4.F90: New. From-SVN: r158079
2010-04-07 19:18:10 +02:00
{
const char *message = CPP_OPTION (pfile, cplusplus)
? N_("use of C++11 long long integer constant")
diagnostic.h (diagnostic_override_option_index): New macro to set a diagnostic's option_index. * diagnostic.h (diagnostic_override_option_index): New macro to set a diagnostic's option_index. * c-tree.h (c_cpp_error): Add warning reason argument. * opts.c (_warning_as_error_callback): New. (register_warning_as_error_callback): Store callback for warnings enabled via enable_warning_as_error. (enable_warning_as_error): Call callback, minor code tidy. * opts.h (register_warning_as_error_callback): Declare. * c-opts.c (warning_as_error_callback): New, set cpp_opts flag in response to -Werror=. (c_common_init_options): Register warning_as_error_callback in opts.c. * common.opt: Add -Wno-cpp option. * c-common.c (struct reason_option_codes_t): Map cpp warning reason codes to gcc option indexes. * (c_option_controlling_cpp_error): New function, lookup the gcc option index for a cpp warning reason code. * (c_cpp_error): Add warning reason argument, call c_option_controlling_cpp_error for diagnostic_override_option_index. * doc/invoke.texi: Document -Wno-cpp. * cpp.c (cb_cpp_error): Add warning reason argument, set a value for diagnostic_override_option_index if CPP_W_WARNING_DIRECTIVE. * directives.c (do_diagnostic): Add warning reason argument, call appropriate error reporting function for code. (directive_diagnostics): Call specific warning functions with warning reason where appropriate. (do_error, do_warning, do_pragma_dependency): Add warning reason argument to do_diagnostic calls. * macro.c (_cpp_warn_if_unused_macro, enter_macro_context, _cpp_create_definition): Call specific warning functions with warning reason where appropriate. * Makefile.in: Add new diagnostic functions to gettext translations. * include/cpplib.h (struct cpp_callbacks): Add warning reason code to error callback. (CPP_DL_WARNING, CPP_DL_WARNING_SYSHDR, CPP_DL_PEDWARN, CPP_DL_ERROR, CPP_DL_ICE, CPP_DL_NOTE, CPP_DL_FATAL): Replace macros with enums. (CPP_W_NONE, CPP_W_DEPRECATED, CPP_W_COMMENTS, CPP_W_MISSING_INCLUDE_DIRS, CPP_W_TRIGRAPHS, CPP_W_MULTICHAR, CPP_W_TRADITIONAL, CPP_W_LONG_LONG, CPP_W_ENDIF_LABELS, CPP_W_NUM_SIGN_CHANGE, CPP_W_VARIADIC_MACROS, CPP_W_BUILTIN_MACRO_REDEFINED, CPP_W_DOLLARS, CPP_W_UNDEF, CPP_W_UNUSED_MACROS, CPP_W_CXX_OPERATOR_NAMES, CPP_W_NORMALIZE, CPP_W_INVALID_PCH, CPP_W_WARNING_DIRECTIVE): New enums for cpp warning reason codes. (cpp_warning, cpp_pedwarning, cpp_warning_syshdr, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): New specific error reporting functions. * pch.c (cpp_valid_state): Call specific warning functions with warning reason where appropriate. * errors.c (cpp_diagnostic, cpp_diagnostic_with_line): New central diagnostic handlers. (cpp_warning, cpp_pedwarning, cpp_warning_syshdr, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): New specific error reporting functions. * expr.c (cpp_classify_number, eval_token, num_unary_op): Call specific warning functions with warning reason where appropriate. * lex.c (_cpp_process_line_notes, _cpp_skip_block_comment, warn_about_normalization, lex_identifier_intern, lex_identifier, _cpp_lex_direct): Ditto. * charset.c (_cpp_valid_ucn, convert_hex, convert_escape, narrow_str_to_charconst): Ditto. * gcc.dg/cpp/warn-undef-2.c: New. * gcc.dg/cpp/warn-traditional-2.c: New. * gcc.dg/cpp/warn-comments-2.c: New. * gcc.dg/cpp/warning-directive-1.c: New. * gcc.dg/cpp/warn-long-long.c: New. * gcc.dg/cpp/warn-traditional.c: New. * gcc.dg/cpp/warn-variadic-2.c: New. * gcc.dg/cpp/warn-undef.c: New. * gcc.dg/cpp/warn-normalized-1.c: New. * gcc.dg/cpp/warning-directive-2.c: New. * gcc.dg/cpp/warn-long-long-2.c: New. * gcc.dg/cpp/warn-variadic.c: New. * gcc.dg/cpp/warn-normalized-2.c: New. * gcc.dg/cpp/warning-directive-3.c: New. * gcc.dg/cpp/warn-deprecated-2.c: New. * gcc.dg/cpp/warn-trigraphs-1.c: New. * gcc.dg/cpp/warn-multichar-2.c: New. * gcc.dg/cpp/warn-normalized-3.c: New. * gcc.dg/cpp/warning-directive-4.c: New. * gcc.dg/cpp/warn-unused-macros.c: New. * gcc.dg/cpp/warn-trigraphs-2.c: New. * gcc.dg/cpp/warn-cxx-compat-2.c: New. * gcc.dg/cpp/warn-cxx-compat.c: New. * gcc.dg/cpp/warn-redefined.c: New. * gcc.dg/cpp/warn-trigraphs-3.c: New. * gcc.dg/cpp/warn-unused-macros-2.c: New. * gcc.dg/cpp/warn-deprecated.c: New. * gcc.dg/cpp/warn-trigraphs-4.c: New. * gcc.dg/cpp/warn-redefined-2.c: New. * gcc.dg/cpp/warn-comments.c: New. * gcc.dg/cpp/warn-multichar.c: New. * g++.dg/cpp/warning-directive-1.C: New. * g++.dg/cpp/warning-directive-2.C: New. * g++.dg/cpp/warning-directive-3.C: New. * g++.dg/cpp/warning-directive-4.C: New. * gfortran.dg/warning-directive-1.F90: New. * gfortran.dg/warning-directive-3.F90: New. * gfortran.dg/warning-directive-2.F90: New. * gfortran.dg/warning-directive-4.F90: New. From-SVN: r158079
2010-04-07 19:18:10 +02:00
: N_("use of C99 long long integer constant");
if (CPP_OPTION (pfile, c99))
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
cpp_warning_with_line (pfile, CPP_W_LONG_LONG, virtual_location,
0, message);
diagnostic.h (diagnostic_override_option_index): New macro to set a diagnostic's option_index. * diagnostic.h (diagnostic_override_option_index): New macro to set a diagnostic's option_index. * c-tree.h (c_cpp_error): Add warning reason argument. * opts.c (_warning_as_error_callback): New. (register_warning_as_error_callback): Store callback for warnings enabled via enable_warning_as_error. (enable_warning_as_error): Call callback, minor code tidy. * opts.h (register_warning_as_error_callback): Declare. * c-opts.c (warning_as_error_callback): New, set cpp_opts flag in response to -Werror=. (c_common_init_options): Register warning_as_error_callback in opts.c. * common.opt: Add -Wno-cpp option. * c-common.c (struct reason_option_codes_t): Map cpp warning reason codes to gcc option indexes. * (c_option_controlling_cpp_error): New function, lookup the gcc option index for a cpp warning reason code. * (c_cpp_error): Add warning reason argument, call c_option_controlling_cpp_error for diagnostic_override_option_index. * doc/invoke.texi: Document -Wno-cpp. * cpp.c (cb_cpp_error): Add warning reason argument, set a value for diagnostic_override_option_index if CPP_W_WARNING_DIRECTIVE. * directives.c (do_diagnostic): Add warning reason argument, call appropriate error reporting function for code. (directive_diagnostics): Call specific warning functions with warning reason where appropriate. (do_error, do_warning, do_pragma_dependency): Add warning reason argument to do_diagnostic calls. * macro.c (_cpp_warn_if_unused_macro, enter_macro_context, _cpp_create_definition): Call specific warning functions with warning reason where appropriate. * Makefile.in: Add new diagnostic functions to gettext translations. * include/cpplib.h (struct cpp_callbacks): Add warning reason code to error callback. (CPP_DL_WARNING, CPP_DL_WARNING_SYSHDR, CPP_DL_PEDWARN, CPP_DL_ERROR, CPP_DL_ICE, CPP_DL_NOTE, CPP_DL_FATAL): Replace macros with enums. (CPP_W_NONE, CPP_W_DEPRECATED, CPP_W_COMMENTS, CPP_W_MISSING_INCLUDE_DIRS, CPP_W_TRIGRAPHS, CPP_W_MULTICHAR, CPP_W_TRADITIONAL, CPP_W_LONG_LONG, CPP_W_ENDIF_LABELS, CPP_W_NUM_SIGN_CHANGE, CPP_W_VARIADIC_MACROS, CPP_W_BUILTIN_MACRO_REDEFINED, CPP_W_DOLLARS, CPP_W_UNDEF, CPP_W_UNUSED_MACROS, CPP_W_CXX_OPERATOR_NAMES, CPP_W_NORMALIZE, CPP_W_INVALID_PCH, CPP_W_WARNING_DIRECTIVE): New enums for cpp warning reason codes. (cpp_warning, cpp_pedwarning, cpp_warning_syshdr, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): New specific error reporting functions. * pch.c (cpp_valid_state): Call specific warning functions with warning reason where appropriate. * errors.c (cpp_diagnostic, cpp_diagnostic_with_line): New central diagnostic handlers. (cpp_warning, cpp_pedwarning, cpp_warning_syshdr, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): New specific error reporting functions. * expr.c (cpp_classify_number, eval_token, num_unary_op): Call specific warning functions with warning reason where appropriate. * lex.c (_cpp_process_line_notes, _cpp_skip_block_comment, warn_about_normalization, lex_identifier_intern, lex_identifier, _cpp_lex_direct): Ditto. * charset.c (_cpp_valid_ucn, convert_hex, convert_escape, narrow_str_to_charconst): Ditto. * gcc.dg/cpp/warn-undef-2.c: New. * gcc.dg/cpp/warn-traditional-2.c: New. * gcc.dg/cpp/warn-comments-2.c: New. * gcc.dg/cpp/warning-directive-1.c: New. * gcc.dg/cpp/warn-long-long.c: New. * gcc.dg/cpp/warn-traditional.c: New. * gcc.dg/cpp/warn-variadic-2.c: New. * gcc.dg/cpp/warn-undef.c: New. * gcc.dg/cpp/warn-normalized-1.c: New. * gcc.dg/cpp/warning-directive-2.c: New. * gcc.dg/cpp/warn-long-long-2.c: New. * gcc.dg/cpp/warn-variadic.c: New. * gcc.dg/cpp/warn-normalized-2.c: New. * gcc.dg/cpp/warning-directive-3.c: New. * gcc.dg/cpp/warn-deprecated-2.c: New. * gcc.dg/cpp/warn-trigraphs-1.c: New. * gcc.dg/cpp/warn-multichar-2.c: New. * gcc.dg/cpp/warn-normalized-3.c: New. * gcc.dg/cpp/warning-directive-4.c: New. * gcc.dg/cpp/warn-unused-macros.c: New. * gcc.dg/cpp/warn-trigraphs-2.c: New. * gcc.dg/cpp/warn-cxx-compat-2.c: New. * gcc.dg/cpp/warn-cxx-compat.c: New. * gcc.dg/cpp/warn-redefined.c: New. * gcc.dg/cpp/warn-trigraphs-3.c: New. * gcc.dg/cpp/warn-unused-macros-2.c: New. * gcc.dg/cpp/warn-deprecated.c: New. * gcc.dg/cpp/warn-trigraphs-4.c: New. * gcc.dg/cpp/warn-redefined-2.c: New. * gcc.dg/cpp/warn-comments.c: New. * gcc.dg/cpp/warn-multichar.c: New. * g++.dg/cpp/warning-directive-1.C: New. * g++.dg/cpp/warning-directive-2.C: New. * g++.dg/cpp/warning-directive-3.C: New. * g++.dg/cpp/warning-directive-4.C: New. * gfortran.dg/warning-directive-1.F90: New. * gfortran.dg/warning-directive-3.F90: New. * gfortran.dg/warning-directive-2.F90: New. * gfortran.dg/warning-directive-4.F90: New. From-SVN: r158079
2010-04-07 19:18:10 +02:00
else
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
cpp_pedwarning_with_line (pfile, CPP_W_LONG_LONG,
virtual_location, 0, message);
diagnostic.h (diagnostic_override_option_index): New macro to set a diagnostic's option_index. * diagnostic.h (diagnostic_override_option_index): New macro to set a diagnostic's option_index. * c-tree.h (c_cpp_error): Add warning reason argument. * opts.c (_warning_as_error_callback): New. (register_warning_as_error_callback): Store callback for warnings enabled via enable_warning_as_error. (enable_warning_as_error): Call callback, minor code tidy. * opts.h (register_warning_as_error_callback): Declare. * c-opts.c (warning_as_error_callback): New, set cpp_opts flag in response to -Werror=. (c_common_init_options): Register warning_as_error_callback in opts.c. * common.opt: Add -Wno-cpp option. * c-common.c (struct reason_option_codes_t): Map cpp warning reason codes to gcc option indexes. * (c_option_controlling_cpp_error): New function, lookup the gcc option index for a cpp warning reason code. * (c_cpp_error): Add warning reason argument, call c_option_controlling_cpp_error for diagnostic_override_option_index. * doc/invoke.texi: Document -Wno-cpp. * cpp.c (cb_cpp_error): Add warning reason argument, set a value for diagnostic_override_option_index if CPP_W_WARNING_DIRECTIVE. * directives.c (do_diagnostic): Add warning reason argument, call appropriate error reporting function for code. (directive_diagnostics): Call specific warning functions with warning reason where appropriate. (do_error, do_warning, do_pragma_dependency): Add warning reason argument to do_diagnostic calls. * macro.c (_cpp_warn_if_unused_macro, enter_macro_context, _cpp_create_definition): Call specific warning functions with warning reason where appropriate. * Makefile.in: Add new diagnostic functions to gettext translations. * include/cpplib.h (struct cpp_callbacks): Add warning reason code to error callback. (CPP_DL_WARNING, CPP_DL_WARNING_SYSHDR, CPP_DL_PEDWARN, CPP_DL_ERROR, CPP_DL_ICE, CPP_DL_NOTE, CPP_DL_FATAL): Replace macros with enums. (CPP_W_NONE, CPP_W_DEPRECATED, CPP_W_COMMENTS, CPP_W_MISSING_INCLUDE_DIRS, CPP_W_TRIGRAPHS, CPP_W_MULTICHAR, CPP_W_TRADITIONAL, CPP_W_LONG_LONG, CPP_W_ENDIF_LABELS, CPP_W_NUM_SIGN_CHANGE, CPP_W_VARIADIC_MACROS, CPP_W_BUILTIN_MACRO_REDEFINED, CPP_W_DOLLARS, CPP_W_UNDEF, CPP_W_UNUSED_MACROS, CPP_W_CXX_OPERATOR_NAMES, CPP_W_NORMALIZE, CPP_W_INVALID_PCH, CPP_W_WARNING_DIRECTIVE): New enums for cpp warning reason codes. (cpp_warning, cpp_pedwarning, cpp_warning_syshdr, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): New specific error reporting functions. * pch.c (cpp_valid_state): Call specific warning functions with warning reason where appropriate. * errors.c (cpp_diagnostic, cpp_diagnostic_with_line): New central diagnostic handlers. (cpp_warning, cpp_pedwarning, cpp_warning_syshdr, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): New specific error reporting functions. * expr.c (cpp_classify_number, eval_token, num_unary_op): Call specific warning functions with warning reason where appropriate. * lex.c (_cpp_process_line_notes, _cpp_skip_block_comment, warn_about_normalization, lex_identifier_intern, lex_identifier, _cpp_lex_direct): Ditto. * charset.c (_cpp_valid_ucn, convert_hex, convert_escape, narrow_str_to_charconst): Ditto. * gcc.dg/cpp/warn-undef-2.c: New. * gcc.dg/cpp/warn-traditional-2.c: New. * gcc.dg/cpp/warn-comments-2.c: New. * gcc.dg/cpp/warning-directive-1.c: New. * gcc.dg/cpp/warn-long-long.c: New. * gcc.dg/cpp/warn-traditional.c: New. * gcc.dg/cpp/warn-variadic-2.c: New. * gcc.dg/cpp/warn-undef.c: New. * gcc.dg/cpp/warn-normalized-1.c: New. * gcc.dg/cpp/warning-directive-2.c: New. * gcc.dg/cpp/warn-long-long-2.c: New. * gcc.dg/cpp/warn-variadic.c: New. * gcc.dg/cpp/warn-normalized-2.c: New. * gcc.dg/cpp/warning-directive-3.c: New. * gcc.dg/cpp/warn-deprecated-2.c: New. * gcc.dg/cpp/warn-trigraphs-1.c: New. * gcc.dg/cpp/warn-multichar-2.c: New. * gcc.dg/cpp/warn-normalized-3.c: New. * gcc.dg/cpp/warning-directive-4.c: New. * gcc.dg/cpp/warn-unused-macros.c: New. * gcc.dg/cpp/warn-trigraphs-2.c: New. * gcc.dg/cpp/warn-cxx-compat-2.c: New. * gcc.dg/cpp/warn-cxx-compat.c: New. * gcc.dg/cpp/warn-redefined.c: New. * gcc.dg/cpp/warn-trigraphs-3.c: New. * gcc.dg/cpp/warn-unused-macros-2.c: New. * gcc.dg/cpp/warn-deprecated.c: New. * gcc.dg/cpp/warn-trigraphs-4.c: New. * gcc.dg/cpp/warn-redefined-2.c: New. * gcc.dg/cpp/warn-comments.c: New. * gcc.dg/cpp/warn-multichar.c: New. * g++.dg/cpp/warning-directive-1.C: New. * g++.dg/cpp/warning-directive-2.C: New. * g++.dg/cpp/warning-directive-3.C: New. * g++.dg/cpp/warning-directive-4.C: New. * gfortran.dg/warning-directive-1.F90: New. * gfortran.dg/warning-directive-3.F90: New. * gfortran.dg/warning-directive-2.F90: New. * gfortran.dg/warning-directive-4.F90: New. From-SVN: r158079
2010-04-07 19:18:10 +02:00
}
result |= CPP_N_INTEGER;
}
syntax_ok:
if ((result & CPP_N_IMAGINARY) && CPP_PEDANTIC (pfile))
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
"imaginary constants are a GCC extension");
if (radix == 2
&& !CPP_OPTION (pfile, binary_constants)
&& CPP_PEDANTIC (pfile))
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
CPP_OPTION (pfile, cplusplus)
? N_("binary constants are a C++14 feature "
"or GCC extension")
: N_("binary constants are a GCC extension"));
if (radix == 10)
result |= CPP_N_DECIMAL;
else if (radix == 16)
result |= CPP_N_HEX;
else if (radix == 2)
result |= CPP_N_BINARY;
else
result |= CPP_N_OCTAL;
return result;
syntax_error:
return CPP_N_INVALID;
}
/* cpp_interpret_integer converts an integer constant into a cpp_num,
of precision options->precision.
We do not provide any interface for decimal->float conversion,
because the preprocessor doesn't need it and we don't want to
drag in GCC's floating point emulator. */
cpp_num
cpp_interpret_integer (cpp_reader *pfile, const cpp_token *token,
unsigned int type)
{
const uchar *p, *end;
cpp_num result;
result.low = 0;
result.high = 0;
result.unsignedp = !!(type & CPP_N_UNSIGNED);
result.overflow = false;
p = token->val.str.text;
end = p + token->val.str.len;
/* Common case of a single digit. */
if (token->val.str.len == 1)
result.low = p[0] - '0';
else
{
cpp_num_part max;
size_t precision = CPP_OPTION (pfile, precision);
unsigned int base = 10, c = 0;
bool overflow = false;
if ((type & CPP_N_RADIX) == CPP_N_OCTAL)
{
base = 8;
p++;
}
else if ((type & CPP_N_RADIX) == CPP_N_HEX)
{
base = 16;
p += 2;
}
else if ((type & CPP_N_RADIX) == CPP_N_BINARY)
{
base = 2;
p += 2;
}
/* We can add a digit to numbers strictly less than this without
needing the precision and slowness of double integers. */
max = ~(cpp_num_part) 0;
if (precision < PART_PRECISION)
max >>= PART_PRECISION - precision;
max = (max - base + 1) / base + 1;
for (; p < end; p++)
{
c = *p;
if (ISDIGIT (c) || (base == 16 && ISXDIGIT (c)))
c = hex_value (c);
else if (DIGIT_SEP (c))
continue;
else
break;
/* Strict inequality for when max is set to zero. */
if (result.low < max)
result.low = result.low * base + c;
else
{
result = append_digit (result, c, base, precision);
overflow |= result.overflow;
max = 0;
}
}
Implement C++11 user-defined literals. libcpp/ * expr.c: (cpp_interpret_float_suffix, cpp_interpret_int_suffix, cpp_userdef_string_remove_type, cpp_userdef_string_add_type, cpp_userdef_char_remove_type, cpp_userdef_char_add_type, cpp_userdef_string_p, cpp_userdef_char_p, cpp_get_userdef_suffix): New. (cpp_classify_number): Classify unrecognized tokens as user-defined literals. * include/cpplib.h: Add new tokens for user-defined literals. * init.c: Add new preprocessor flag (cxx11). * lex.c: (lex_string, lex_raw_string): Handle user-defined literals including concatenation and promotion with suffixes. c-family/ * c-common.c (build_userdef_literal): New. * c-common.def: New tree code. * c-common.h (tree_userdef_literal): New tree struct and accessors. * c-lex.c (interpret_float): Add suffix parm. (c_lex_with_flags): Build literal tokens. cp/ * cp-objcp-common.c: (cp_tree_size) Return size of USERDEF_LITERAL tree. * cp-tree.h: (UDLIT_OP_*, UDLIT_OPER_P): Literal operator name tools. New tree code for user-defined literals. * cxx-pretty-print.h: (pp_cxx_userdef_literal) New. * cxx-pretty-print.c: (pp_cxx_userdef_literal) New. (pp_cxx_primary_expression, pp_cxx_expression): Use it. * decl.c: (cp_tree_node_structure): Return new tree code. (duplicate_decls): Check for raw vs. template operator conflicts. (grokfndecl, grokdeclarator): New checks for literal operators. * error.c: (dump_expr): Warn about user-defined literals in C++98 mode. (dump_function_name): Pretty printing. * mangle.c: (write_literal_operator_name): New. (write_unqualified_id, write_unqualified_name): Use it. * parser.c: (cp_parser_operator): Handle operator"". (cp_parser_userdef_char_literal, cp_parser_userdef_numeric_literal, cp_parser_userdef_string_literal): New. (cp_parser_primary_expression): Handle new user-defined literal tokens with new functions. * semantics.c: (potential_constant_expression_1): Add user-defined literals. * typeck.c (check_raw_literal_operator, check_literal_operator_args): New. From-SVN: r180536
2011-10-26 21:30:59 +02:00
if (overflow && !(type & CPP_N_USERDEF))
cpp_error (pfile, CPP_DL_PEDWARN,
"integer constant is too large for its type");
/* If too big to be signed, consider it unsigned. Only warn for
decimal numbers. Traditional numbers were always signed (but
we still honor an explicit U suffix); but we only have
traditional semantics in directives. */
else if (!result.unsignedp
&& !(CPP_OPTION (pfile, traditional)
&& pfile->state.in_directive)
&& !num_positive (result, precision))
{
/* This is for constants within the range of uintmax_t but
not that of intmax_t. For such decimal constants, a
diagnostic is required for C99 as the selected type must
be signed and not having a type is a constraint violation
(DR#298, TC3), so this must be a pedwarn. For C90,
unsigned long is specified to be used for a constant that
does not fit in signed long; if uintmax_t has the same
range as unsigned long this means only a warning is
appropriate here. C90 permits the preprocessor to use a
wider range than unsigned long in the compiler, so if
uintmax_t is wider than unsigned long no diagnostic is
required for such constants in preprocessor #if
expressions and the compiler will pedwarn for such
constants outside the range of unsigned long that reach
the compiler so a diagnostic is not required there
either; thus, pedwarn for C99 but use a plain warning for
C90. */
if (base == 10)
cpp_error (pfile, (CPP_OPTION (pfile, c99)
? CPP_DL_PEDWARN
: CPP_DL_WARNING),
"integer constant is so large that it is unsigned");
result.unsignedp = true;
}
}
return result;
}
/* Append DIGIT to NUM, a number of PRECISION bits being read in base BASE. */
static cpp_num
append_digit (cpp_num num, int digit, int base, size_t precision)
{
cpp_num result;
unsigned int shift;
bool overflow;
cpp_num_part add_high, add_low;
/* Multiply by 2, 8 or 16. Catching this overflow here means we don't
need to worry about add_high overflowing. */
switch (base)
{
case 2:
shift = 1;
break;
case 16:
shift = 4;
break;
default:
shift = 3;
}
overflow = !!(num.high >> (PART_PRECISION - shift));
result.high = num.high << shift;
result.low = num.low << shift;
result.high |= num.low >> (PART_PRECISION - shift);
result.unsignedp = num.unsignedp;
if (base == 10)
{
add_low = num.low << 1;
add_high = (num.high << 1) + (num.low >> (PART_PRECISION - 1));
}
else
add_high = add_low = 0;
if (add_low + digit < add_low)
add_high++;
add_low += digit;
if (result.low + add_low < result.low)
add_high++;
if (result.high + add_high < result.high)
overflow = true;
result.low += add_low;
result.high += add_high;
result.overflow = overflow;
/* The above code catches overflow of a cpp_num type. This catches
overflow of the (possibly shorter) target precision. */
num.low = result.low;
num.high = result.high;
result = num_trim (result, precision);
if (!num_eq (result, num))
result.overflow = true;
return result;
}
/* Handle meeting "defined" in a preprocessor expression. */
static cpp_num
parse_defined (cpp_reader *pfile)
cpplib.h (CPP_ASSERTION, [...]): New token types. * cpplib.h (CPP_ASSERTION, CPP_STRINGIZE, CPP_TOKPASTE): New token types. (struct cpp_reader): Add parsing_if_directive and parsing_define_directive flags. (struct cpp_options): Remove output_conditionals flag. (check_macro_name): Delete prototype. * cpphash.h (struct macrodef): Delete. (struct reflist): Separate from struct definition. (struct definition): Remove unused fields. Add column number. (create_definition): Returns a DEFINITION *. Takes a cpp_reader * and an int. * cpphash.c (SKIP_WHITE_SPACE): Delete. (PEEKC): Copy defn from cpplib.c. (rest_extension, REST_EXTENSION_LENGTH): Delete. (struct arg): New. (struct arglist): Simplify. (collect_expansion): Rewrite. Get tokens by calling cpp_get_token. Add more error checking. (collect_formal_parameters): New function, broken out of create_definition and reworked to use get_directive_token. (create_definition): All real work is now in collect_expansion and collect_formal_parameters. do_define handles finding the macro name. Return a DEFINITION, not a MACRODEF. (macroexpand): Replace bcopy with memcpy throughout. Replace character-at-a-time copy loop with memcpy and pointer increments. (compare-defs): d1->argnames / d2->argnames might be null. * cpplib.c (copy_rest_of_line): Delete function. (skip_rest_of_line): Do all the work ourselves. (skip_string): New function. (parse_string): Use skip_string. (get_macro_name): New function. (check_macro_name): Delete. (copy_comment): Use CPP_RESERVE and CPP_PUTC_Q. (cpp_skip_hspace): Use CPP_BUMP_LINE. (handle_directive): ICE if we're called on a macro buffer. (do_define): Determine macro name and type (funlike/objlike) here. Expunge all uses of MACRODEF. (cpp_push_buffer): Set line_base to NULL. (do_undef, read_line_number): Don't worry about getting a POP token. (eval_if_expression): Set/reset parsing_if_directive around cpp_parse_expr. Don't clear only_seen_white. (skip_if_group): Remove output_conditionals logic. Use skip_rest_of_line. (cpp_get_token): Return ASSERTION, STRINGIZE, and TOKPASTE tokens under appropriate conditions. (cpp_unassert): Call do_unassert not do_assert. Oops. * cppexp.c (parse_defined): New function, break out of cpp_lex. (cpp_lex): We now get CPP_ASSERTION tokens and can check them ourselves, with cpp_defined. * cppinit.c (cpp_handle_option, print_help): Delete -ifoutput. * gcc.dg/20000209-2.c: Turn off -pedantic-errors. * gcc.dg/strpaste-2.c: New. From-SVN: r32274
2000-03-01 01:57:09 +01:00
{
cpp_num result;
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
int paren = 0;
cpp_hashnode *node = 0;
c-lex.c (cb_def_pragma): Update. * c-lex.c (cb_def_pragma): Update. (c_lex): Update, and skip padding. * cppexp.c (lex, parse_defined): Update, remove unused variable. * cpphash.h (struct toklist): Delete. (union utoken): New. (struct cpp_context): Update. (struct cpp_reader): New members eof, avoid_paste. (_cpp_temp_token): New. * cppinit.c (cpp_create_reader): Update. * cpplex.c (_cpp_temp_token): New. (_cpp_lex_direct): Add PREV_WHITE when parsing args. (cpp_output_token): Don't print leading whitespace. (cpp_output_line): Update. * cpplib.c (glue_header_name, parse_include, get__Pragma_string, do_include_common, do_line, do_ident, do_pragma, do_pragma_dependency, _cpp_do__Pragma, parse_answer, parse_assertion): Update. (get_token_no_padding): New. * cpplib.h (CPP_PADDING): New. (AVOID_LPASTE): Delete. (struct cpp_token): New union member source. (cpp_get_token): Update. * cppmacro.c (macro_arg): Convert to use pointers to const tokens. (builtin_macro, paste_all_tokens, paste_tokens, funlike_invocation_p, replace_args, quote_string, stringify_arg, parse_arg, next_context, enter_macro_context, expand_arg, _cpp_pop_context, cpp_scan_nooutput, _cpp_backup_tokens, _cpp_create_definition): Update. (push_arg_context): Delete. (padding_token, push_token_context, push_ptoken_context): New. (make_string_token, make_number_token): Update, rename. (cpp_get_token): Update to handle tokens as pointers to const, and insert padding appropriately. * cppmain.c (struct printer): New member prev. (check_multiline_token): Constify. (do_preprocessing, cb_line_change): Update. (scan_translation_unit): Update to handle spacing. * scan-decls.c (get_a_token): New. (skip_to_closing_brace, scan_decls): Update. * fix-header.c (read_scan_file): Update. * doc/cpp.texi: Update. * gcc.dg/cpp/macro10.c: New test. * gcc.dg/cpp/strify3.c: New test. * gcc.dg/cpp/spacing1.c: Add tests. * gcc.dg/cpp/19990703-1.c: Remove bogus test. * gcc.dg/cpp/20000625-2.c: Fudge to pass. From-SVN: r45793
2001-09-25 00:53:12 +02:00
const cpp_token *token;
cpp_context *initial_context = pfile->context;
cpplib.h (CPP_ASSERTION, [...]): New token types. * cpplib.h (CPP_ASSERTION, CPP_STRINGIZE, CPP_TOKPASTE): New token types. (struct cpp_reader): Add parsing_if_directive and parsing_define_directive flags. (struct cpp_options): Remove output_conditionals flag. (check_macro_name): Delete prototype. * cpphash.h (struct macrodef): Delete. (struct reflist): Separate from struct definition. (struct definition): Remove unused fields. Add column number. (create_definition): Returns a DEFINITION *. Takes a cpp_reader * and an int. * cpphash.c (SKIP_WHITE_SPACE): Delete. (PEEKC): Copy defn from cpplib.c. (rest_extension, REST_EXTENSION_LENGTH): Delete. (struct arg): New. (struct arglist): Simplify. (collect_expansion): Rewrite. Get tokens by calling cpp_get_token. Add more error checking. (collect_formal_parameters): New function, broken out of create_definition and reworked to use get_directive_token. (create_definition): All real work is now in collect_expansion and collect_formal_parameters. do_define handles finding the macro name. Return a DEFINITION, not a MACRODEF. (macroexpand): Replace bcopy with memcpy throughout. Replace character-at-a-time copy loop with memcpy and pointer increments. (compare-defs): d1->argnames / d2->argnames might be null. * cpplib.c (copy_rest_of_line): Delete function. (skip_rest_of_line): Do all the work ourselves. (skip_string): New function. (parse_string): Use skip_string. (get_macro_name): New function. (check_macro_name): Delete. (copy_comment): Use CPP_RESERVE and CPP_PUTC_Q. (cpp_skip_hspace): Use CPP_BUMP_LINE. (handle_directive): ICE if we're called on a macro buffer. (do_define): Determine macro name and type (funlike/objlike) here. Expunge all uses of MACRODEF. (cpp_push_buffer): Set line_base to NULL. (do_undef, read_line_number): Don't worry about getting a POP token. (eval_if_expression): Set/reset parsing_if_directive around cpp_parse_expr. Don't clear only_seen_white. (skip_if_group): Remove output_conditionals logic. Use skip_rest_of_line. (cpp_get_token): Return ASSERTION, STRINGIZE, and TOKPASTE tokens under appropriate conditions. (cpp_unassert): Call do_unassert not do_assert. Oops. * cppexp.c (parse_defined): New function, break out of cpp_lex. (cpp_lex): We now get CPP_ASSERTION tokens and can check them ourselves, with cpp_defined. * cppinit.c (cpp_handle_option, print_help): Delete -ifoutput. * gcc.dg/20000209-2.c: Turn off -pedantic-errors. * gcc.dg/strpaste-2.c: New. From-SVN: r32274
2000-03-01 01:57:09 +01:00
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
/* Don't expand macros. */
pfile->state.prevent_expansion++;
c-lex.c (cb_def_pragma): Update. * c-lex.c (cb_def_pragma): Update. (c_lex): Update, and skip padding. * cppexp.c (lex, parse_defined): Update, remove unused variable. * cpphash.h (struct toklist): Delete. (union utoken): New. (struct cpp_context): Update. (struct cpp_reader): New members eof, avoid_paste. (_cpp_temp_token): New. * cppinit.c (cpp_create_reader): Update. * cpplex.c (_cpp_temp_token): New. (_cpp_lex_direct): Add PREV_WHITE when parsing args. (cpp_output_token): Don't print leading whitespace. (cpp_output_line): Update. * cpplib.c (glue_header_name, parse_include, get__Pragma_string, do_include_common, do_line, do_ident, do_pragma, do_pragma_dependency, _cpp_do__Pragma, parse_answer, parse_assertion): Update. (get_token_no_padding): New. * cpplib.h (CPP_PADDING): New. (AVOID_LPASTE): Delete. (struct cpp_token): New union member source. (cpp_get_token): Update. * cppmacro.c (macro_arg): Convert to use pointers to const tokens. (builtin_macro, paste_all_tokens, paste_tokens, funlike_invocation_p, replace_args, quote_string, stringify_arg, parse_arg, next_context, enter_macro_context, expand_arg, _cpp_pop_context, cpp_scan_nooutput, _cpp_backup_tokens, _cpp_create_definition): Update. (push_arg_context): Delete. (padding_token, push_token_context, push_ptoken_context): New. (make_string_token, make_number_token): Update, rename. (cpp_get_token): Update to handle tokens as pointers to const, and insert padding appropriately. * cppmain.c (struct printer): New member prev. (check_multiline_token): Constify. (do_preprocessing, cb_line_change): Update. (scan_translation_unit): Update to handle spacing. * scan-decls.c (get_a_token): New. (skip_to_closing_brace, scan_decls): Update. * fix-header.c (read_scan_file): Update. * doc/cpp.texi: Update. * gcc.dg/cpp/macro10.c: New test. * gcc.dg/cpp/strify3.c: New test. * gcc.dg/cpp/spacing1.c: Add tests. * gcc.dg/cpp/19990703-1.c: Remove bogus test. * gcc.dg/cpp/20000625-2.c: Fudge to pass. From-SVN: r45793
2001-09-25 00:53:12 +02:00
token = cpp_get_token (pfile);
if (token->type == CPP_OPEN_PAREN)
cpplib.h (CPP_ASSERTION, [...]): New token types. * cpplib.h (CPP_ASSERTION, CPP_STRINGIZE, CPP_TOKPASTE): New token types. (struct cpp_reader): Add parsing_if_directive and parsing_define_directive flags. (struct cpp_options): Remove output_conditionals flag. (check_macro_name): Delete prototype. * cpphash.h (struct macrodef): Delete. (struct reflist): Separate from struct definition. (struct definition): Remove unused fields. Add column number. (create_definition): Returns a DEFINITION *. Takes a cpp_reader * and an int. * cpphash.c (SKIP_WHITE_SPACE): Delete. (PEEKC): Copy defn from cpplib.c. (rest_extension, REST_EXTENSION_LENGTH): Delete. (struct arg): New. (struct arglist): Simplify. (collect_expansion): Rewrite. Get tokens by calling cpp_get_token. Add more error checking. (collect_formal_parameters): New function, broken out of create_definition and reworked to use get_directive_token. (create_definition): All real work is now in collect_expansion and collect_formal_parameters. do_define handles finding the macro name. Return a DEFINITION, not a MACRODEF. (macroexpand): Replace bcopy with memcpy throughout. Replace character-at-a-time copy loop with memcpy and pointer increments. (compare-defs): d1->argnames / d2->argnames might be null. * cpplib.c (copy_rest_of_line): Delete function. (skip_rest_of_line): Do all the work ourselves. (skip_string): New function. (parse_string): Use skip_string. (get_macro_name): New function. (check_macro_name): Delete. (copy_comment): Use CPP_RESERVE and CPP_PUTC_Q. (cpp_skip_hspace): Use CPP_BUMP_LINE. (handle_directive): ICE if we're called on a macro buffer. (do_define): Determine macro name and type (funlike/objlike) here. Expunge all uses of MACRODEF. (cpp_push_buffer): Set line_base to NULL. (do_undef, read_line_number): Don't worry about getting a POP token. (eval_if_expression): Set/reset parsing_if_directive around cpp_parse_expr. Don't clear only_seen_white. (skip_if_group): Remove output_conditionals logic. Use skip_rest_of_line. (cpp_get_token): Return ASSERTION, STRINGIZE, and TOKPASTE tokens under appropriate conditions. (cpp_unassert): Call do_unassert not do_assert. Oops. * cppexp.c (parse_defined): New function, break out of cpp_lex. (cpp_lex): We now get CPP_ASSERTION tokens and can check them ourselves, with cpp_defined. * cppinit.c (cpp_handle_option, print_help): Delete -ifoutput. * gcc.dg/20000209-2.c: Turn off -pedantic-errors. * gcc.dg/strpaste-2.c: New. From-SVN: r32274
2000-03-01 01:57:09 +01:00
{
paren = 1;
c-lex.c (cb_def_pragma): Update. * c-lex.c (cb_def_pragma): Update. (c_lex): Update, and skip padding. * cppexp.c (lex, parse_defined): Update, remove unused variable. * cpphash.h (struct toklist): Delete. (union utoken): New. (struct cpp_context): Update. (struct cpp_reader): New members eof, avoid_paste. (_cpp_temp_token): New. * cppinit.c (cpp_create_reader): Update. * cpplex.c (_cpp_temp_token): New. (_cpp_lex_direct): Add PREV_WHITE when parsing args. (cpp_output_token): Don't print leading whitespace. (cpp_output_line): Update. * cpplib.c (glue_header_name, parse_include, get__Pragma_string, do_include_common, do_line, do_ident, do_pragma, do_pragma_dependency, _cpp_do__Pragma, parse_answer, parse_assertion): Update. (get_token_no_padding): New. * cpplib.h (CPP_PADDING): New. (AVOID_LPASTE): Delete. (struct cpp_token): New union member source. (cpp_get_token): Update. * cppmacro.c (macro_arg): Convert to use pointers to const tokens. (builtin_macro, paste_all_tokens, paste_tokens, funlike_invocation_p, replace_args, quote_string, stringify_arg, parse_arg, next_context, enter_macro_context, expand_arg, _cpp_pop_context, cpp_scan_nooutput, _cpp_backup_tokens, _cpp_create_definition): Update. (push_arg_context): Delete. (padding_token, push_token_context, push_ptoken_context): New. (make_string_token, make_number_token): Update, rename. (cpp_get_token): Update to handle tokens as pointers to const, and insert padding appropriately. * cppmain.c (struct printer): New member prev. (check_multiline_token): Constify. (do_preprocessing, cb_line_change): Update. (scan_translation_unit): Update to handle spacing. * scan-decls.c (get_a_token): New. (skip_to_closing_brace, scan_decls): Update. * fix-header.c (read_scan_file): Update. * doc/cpp.texi: Update. * gcc.dg/cpp/macro10.c: New test. * gcc.dg/cpp/strify3.c: New test. * gcc.dg/cpp/spacing1.c: Add tests. * gcc.dg/cpp/19990703-1.c: Remove bogus test. * gcc.dg/cpp/20000625-2.c: Fudge to pass. From-SVN: r45793
2001-09-25 00:53:12 +02:00
token = cpp_get_token (pfile);
cpplib.h (CPP_ASSERTION, [...]): New token types. * cpplib.h (CPP_ASSERTION, CPP_STRINGIZE, CPP_TOKPASTE): New token types. (struct cpp_reader): Add parsing_if_directive and parsing_define_directive flags. (struct cpp_options): Remove output_conditionals flag. (check_macro_name): Delete prototype. * cpphash.h (struct macrodef): Delete. (struct reflist): Separate from struct definition. (struct definition): Remove unused fields. Add column number. (create_definition): Returns a DEFINITION *. Takes a cpp_reader * and an int. * cpphash.c (SKIP_WHITE_SPACE): Delete. (PEEKC): Copy defn from cpplib.c. (rest_extension, REST_EXTENSION_LENGTH): Delete. (struct arg): New. (struct arglist): Simplify. (collect_expansion): Rewrite. Get tokens by calling cpp_get_token. Add more error checking. (collect_formal_parameters): New function, broken out of create_definition and reworked to use get_directive_token. (create_definition): All real work is now in collect_expansion and collect_formal_parameters. do_define handles finding the macro name. Return a DEFINITION, not a MACRODEF. (macroexpand): Replace bcopy with memcpy throughout. Replace character-at-a-time copy loop with memcpy and pointer increments. (compare-defs): d1->argnames / d2->argnames might be null. * cpplib.c (copy_rest_of_line): Delete function. (skip_rest_of_line): Do all the work ourselves. (skip_string): New function. (parse_string): Use skip_string. (get_macro_name): New function. (check_macro_name): Delete. (copy_comment): Use CPP_RESERVE and CPP_PUTC_Q. (cpp_skip_hspace): Use CPP_BUMP_LINE. (handle_directive): ICE if we're called on a macro buffer. (do_define): Determine macro name and type (funlike/objlike) here. Expunge all uses of MACRODEF. (cpp_push_buffer): Set line_base to NULL. (do_undef, read_line_number): Don't worry about getting a POP token. (eval_if_expression): Set/reset parsing_if_directive around cpp_parse_expr. Don't clear only_seen_white. (skip_if_group): Remove output_conditionals logic. Use skip_rest_of_line. (cpp_get_token): Return ASSERTION, STRINGIZE, and TOKPASTE tokens under appropriate conditions. (cpp_unassert): Call do_unassert not do_assert. Oops. * cppexp.c (parse_defined): New function, break out of cpp_lex. (cpp_lex): We now get CPP_ASSERTION tokens and can check them ourselves, with cpp_defined. * cppinit.c (cpp_handle_option, print_help): Delete -ifoutput. * gcc.dg/20000209-2.c: Turn off -pedantic-errors. * gcc.dg/strpaste-2.c: New. From-SVN: r32274
2000-03-01 01:57:09 +01:00
}
c-lex.c (cb_def_pragma): Update. * c-lex.c (cb_def_pragma): Update. (c_lex): Update, and skip padding. * cppexp.c (lex, parse_defined): Update, remove unused variable. * cpphash.h (struct toklist): Delete. (union utoken): New. (struct cpp_context): Update. (struct cpp_reader): New members eof, avoid_paste. (_cpp_temp_token): New. * cppinit.c (cpp_create_reader): Update. * cpplex.c (_cpp_temp_token): New. (_cpp_lex_direct): Add PREV_WHITE when parsing args. (cpp_output_token): Don't print leading whitespace. (cpp_output_line): Update. * cpplib.c (glue_header_name, parse_include, get__Pragma_string, do_include_common, do_line, do_ident, do_pragma, do_pragma_dependency, _cpp_do__Pragma, parse_answer, parse_assertion): Update. (get_token_no_padding): New. * cpplib.h (CPP_PADDING): New. (AVOID_LPASTE): Delete. (struct cpp_token): New union member source. (cpp_get_token): Update. * cppmacro.c (macro_arg): Convert to use pointers to const tokens. (builtin_macro, paste_all_tokens, paste_tokens, funlike_invocation_p, replace_args, quote_string, stringify_arg, parse_arg, next_context, enter_macro_context, expand_arg, _cpp_pop_context, cpp_scan_nooutput, _cpp_backup_tokens, _cpp_create_definition): Update. (push_arg_context): Delete. (padding_token, push_token_context, push_ptoken_context): New. (make_string_token, make_number_token): Update, rename. (cpp_get_token): Update to handle tokens as pointers to const, and insert padding appropriately. * cppmain.c (struct printer): New member prev. (check_multiline_token): Constify. (do_preprocessing, cb_line_change): Update. (scan_translation_unit): Update to handle spacing. * scan-decls.c (get_a_token): New. (skip_to_closing_brace, scan_decls): Update. * fix-header.c (read_scan_file): Update. * doc/cpp.texi: Update. * gcc.dg/cpp/macro10.c: New test. * gcc.dg/cpp/strify3.c: New test. * gcc.dg/cpp/spacing1.c: Add tests. * gcc.dg/cpp/19990703-1.c: Remove bogus test. * gcc.dg/cpp/20000625-2.c: Fudge to pass. From-SVN: r45793
2001-09-25 00:53:12 +02:00
if (token->type == CPP_NAME)
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
{
node = token->val.node.node;
c-lex.c (cb_def_pragma): Update. * c-lex.c (cb_def_pragma): Update. (c_lex): Update, and skip padding. * cppexp.c (lex, parse_defined): Update, remove unused variable. * cpphash.h (struct toklist): Delete. (union utoken): New. (struct cpp_context): Update. (struct cpp_reader): New members eof, avoid_paste. (_cpp_temp_token): New. * cppinit.c (cpp_create_reader): Update. * cpplex.c (_cpp_temp_token): New. (_cpp_lex_direct): Add PREV_WHITE when parsing args. (cpp_output_token): Don't print leading whitespace. (cpp_output_line): Update. * cpplib.c (glue_header_name, parse_include, get__Pragma_string, do_include_common, do_line, do_ident, do_pragma, do_pragma_dependency, _cpp_do__Pragma, parse_answer, parse_assertion): Update. (get_token_no_padding): New. * cpplib.h (CPP_PADDING): New. (AVOID_LPASTE): Delete. (struct cpp_token): New union member source. (cpp_get_token): Update. * cppmacro.c (macro_arg): Convert to use pointers to const tokens. (builtin_macro, paste_all_tokens, paste_tokens, funlike_invocation_p, replace_args, quote_string, stringify_arg, parse_arg, next_context, enter_macro_context, expand_arg, _cpp_pop_context, cpp_scan_nooutput, _cpp_backup_tokens, _cpp_create_definition): Update. (push_arg_context): Delete. (padding_token, push_token_context, push_ptoken_context): New. (make_string_token, make_number_token): Update, rename. (cpp_get_token): Update to handle tokens as pointers to const, and insert padding appropriately. * cppmain.c (struct printer): New member prev. (check_multiline_token): Constify. (do_preprocessing, cb_line_change): Update. (scan_translation_unit): Update to handle spacing. * scan-decls.c (get_a_token): New. (skip_to_closing_brace, scan_decls): Update. * fix-header.c (read_scan_file): Update. * doc/cpp.texi: Update. * gcc.dg/cpp/macro10.c: New test. * gcc.dg/cpp/strify3.c: New test. * gcc.dg/cpp/spacing1.c: Add tests. * gcc.dg/cpp/19990703-1.c: Remove bogus test. * gcc.dg/cpp/20000625-2.c: Fudge to pass. From-SVN: r45793
2001-09-25 00:53:12 +02:00
if (paren && cpp_get_token (pfile)->type != CPP_CLOSE_PAREN)
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
{
cpp_error (pfile, CPP_DL_ERROR, "missing ')' after \"defined\"");
c-lex.c (cb_def_pragma): Update. * c-lex.c (cb_def_pragma): Update. (c_lex): Update, and skip padding. * cppexp.c (lex, parse_defined): Update, remove unused variable. * cpphash.h (struct toklist): Delete. (union utoken): New. (struct cpp_context): Update. (struct cpp_reader): New members eof, avoid_paste. (_cpp_temp_token): New. * cppinit.c (cpp_create_reader): Update. * cpplex.c (_cpp_temp_token): New. (_cpp_lex_direct): Add PREV_WHITE when parsing args. (cpp_output_token): Don't print leading whitespace. (cpp_output_line): Update. * cpplib.c (glue_header_name, parse_include, get__Pragma_string, do_include_common, do_line, do_ident, do_pragma, do_pragma_dependency, _cpp_do__Pragma, parse_answer, parse_assertion): Update. (get_token_no_padding): New. * cpplib.h (CPP_PADDING): New. (AVOID_LPASTE): Delete. (struct cpp_token): New union member source. (cpp_get_token): Update. * cppmacro.c (macro_arg): Convert to use pointers to const tokens. (builtin_macro, paste_all_tokens, paste_tokens, funlike_invocation_p, replace_args, quote_string, stringify_arg, parse_arg, next_context, enter_macro_context, expand_arg, _cpp_pop_context, cpp_scan_nooutput, _cpp_backup_tokens, _cpp_create_definition): Update. (push_arg_context): Delete. (padding_token, push_token_context, push_ptoken_context): New. (make_string_token, make_number_token): Update, rename. (cpp_get_token): Update to handle tokens as pointers to const, and insert padding appropriately. * cppmain.c (struct printer): New member prev. (check_multiline_token): Constify. (do_preprocessing, cb_line_change): Update. (scan_translation_unit): Update to handle spacing. * scan-decls.c (get_a_token): New. (skip_to_closing_brace, scan_decls): Update. * fix-header.c (read_scan_file): Update. * doc/cpp.texi: Update. * gcc.dg/cpp/macro10.c: New test. * gcc.dg/cpp/strify3.c: New test. * gcc.dg/cpp/spacing1.c: Add tests. * gcc.dg/cpp/19990703-1.c: Remove bogus test. * gcc.dg/cpp/20000625-2.c: Fudge to pass. From-SVN: r45793
2001-09-25 00:53:12 +02:00
node = 0;
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
}
}
else
{
cpp_error (pfile, CPP_DL_ERROR,
cpperror.c (print_location): Don't print include chain if line == 0. * cpperror.c (print_location): Don't print include chain if line == 0. (cpp_begin_message): Update to use DL_ macros. (cpp_ice, cpp_fatal, cpp_error_from_errno, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_notice, cpp_notice_from_errno): Remove. (cpp_error, cpp_error_with_line): Update to take a diagnostic level. (cpp_errno): New. * cppexp.c (CPP_ICE): Remove. (SYNTAX_ERROR, SYNTAX_ERROR2, parse_number, parse_defined, lex, integer_overflow, _cpp_parse_expr): Update. * cppfiles.c (read_include_file, find_include_file, handle_missing_header, _cpp_read_file, remap_filename): Update. * cpphash.h (enum error_type): Remove. (_cpp_begin_message): Update. * cppinit.c (append_include_chain, remove_dup_dirs, output_deps, cpp_handle_option, cpp_post_options): Update. * cpplex.c (trigraph_p, skip_escaped_newlines, skip_block_comment, skip_whitespace, parse_identifier, parse_slow, parse_string, _cpp_lex_direct, cpp_spell_token, maybe_read_ucs, cpp_parse_escape, cpp_interpret_charconst): Update. * cpplib.c (check_eol, directive_diagnostics, _cpp_handle_directive, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, read_flag, do_line, do_linemarker, do_ident, cpp_register_pragma, do_pragma_once, do_pragma_system_header, do_pragma_poison, do_pragma_dependency, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, parse_assertion, do_assert, _cpp_pop_buffer, do_diagnostic): Update. * cpplib.h (DL_WARNING, DL_WARNING_SYSHDR, DL_PEDWARN, DL_ERROR, DL_FATAL, DL_ICE, DL_EXTRACT, DL_WARNING_P): New. (cpp_ice, cpp_fatal, cpp_error_from_errno, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_notice, cpp_notice_from_errno): Remove. (cpp_error, cpp_error_with_line): Update to take a diagnostic level. (cpp_errno): New. * cppmacro.c (builtin_macro, stringify_arg, paste_all_tokens, collect_args, enter_macro_context, save_parameter, parse_params, _cpp_create_definition, check_trad_stringification, cpp_macro_definition): Update. * cppmain.c (cpp_preprocess_file): Update. * fix-header.c (read_scan_file): Update. From-SVN: r52302
2002-04-14 20:42:47 +02:00
"operator \"defined\" requires an identifier");
c-lex.c (cb_def_pragma): Update. * c-lex.c (cb_def_pragma): Update. (c_lex): Update, and skip padding. * cppexp.c (lex, parse_defined): Update, remove unused variable. * cpphash.h (struct toklist): Delete. (union utoken): New. (struct cpp_context): Update. (struct cpp_reader): New members eof, avoid_paste. (_cpp_temp_token): New. * cppinit.c (cpp_create_reader): Update. * cpplex.c (_cpp_temp_token): New. (_cpp_lex_direct): Add PREV_WHITE when parsing args. (cpp_output_token): Don't print leading whitespace. (cpp_output_line): Update. * cpplib.c (glue_header_name, parse_include, get__Pragma_string, do_include_common, do_line, do_ident, do_pragma, do_pragma_dependency, _cpp_do__Pragma, parse_answer, parse_assertion): Update. (get_token_no_padding): New. * cpplib.h (CPP_PADDING): New. (AVOID_LPASTE): Delete. (struct cpp_token): New union member source. (cpp_get_token): Update. * cppmacro.c (macro_arg): Convert to use pointers to const tokens. (builtin_macro, paste_all_tokens, paste_tokens, funlike_invocation_p, replace_args, quote_string, stringify_arg, parse_arg, next_context, enter_macro_context, expand_arg, _cpp_pop_context, cpp_scan_nooutput, _cpp_backup_tokens, _cpp_create_definition): Update. (push_arg_context): Delete. (padding_token, push_token_context, push_ptoken_context): New. (make_string_token, make_number_token): Update, rename. (cpp_get_token): Update to handle tokens as pointers to const, and insert padding appropriately. * cppmain.c (struct printer): New member prev. (check_multiline_token): Constify. (do_preprocessing, cb_line_change): Update. (scan_translation_unit): Update to handle spacing. * scan-decls.c (get_a_token): New. (skip_to_closing_brace, scan_decls): Update. * fix-header.c (read_scan_file): Update. * doc/cpp.texi: Update. * gcc.dg/cpp/macro10.c: New test. * gcc.dg/cpp/strify3.c: New test. * gcc.dg/cpp/spacing1.c: Add tests. * gcc.dg/cpp/19990703-1.c: Remove bogus test. * gcc.dg/cpp/20000625-2.c: Fudge to pass. From-SVN: r45793
2001-09-25 00:53:12 +02:00
if (token->flags & NAMED_OP)
{
cpp_token op;
op.flags = 0;
c-lex.c (cb_def_pragma): Update. * c-lex.c (cb_def_pragma): Update. (c_lex): Update, and skip padding. * cppexp.c (lex, parse_defined): Update, remove unused variable. * cpphash.h (struct toklist): Delete. (union utoken): New. (struct cpp_context): Update. (struct cpp_reader): New members eof, avoid_paste. (_cpp_temp_token): New. * cppinit.c (cpp_create_reader): Update. * cpplex.c (_cpp_temp_token): New. (_cpp_lex_direct): Add PREV_WHITE when parsing args. (cpp_output_token): Don't print leading whitespace. (cpp_output_line): Update. * cpplib.c (glue_header_name, parse_include, get__Pragma_string, do_include_common, do_line, do_ident, do_pragma, do_pragma_dependency, _cpp_do__Pragma, parse_answer, parse_assertion): Update. (get_token_no_padding): New. * cpplib.h (CPP_PADDING): New. (AVOID_LPASTE): Delete. (struct cpp_token): New union member source. (cpp_get_token): Update. * cppmacro.c (macro_arg): Convert to use pointers to const tokens. (builtin_macro, paste_all_tokens, paste_tokens, funlike_invocation_p, replace_args, quote_string, stringify_arg, parse_arg, next_context, enter_macro_context, expand_arg, _cpp_pop_context, cpp_scan_nooutput, _cpp_backup_tokens, _cpp_create_definition): Update. (push_arg_context): Delete. (padding_token, push_token_context, push_ptoken_context): New. (make_string_token, make_number_token): Update, rename. (cpp_get_token): Update to handle tokens as pointers to const, and insert padding appropriately. * cppmain.c (struct printer): New member prev. (check_multiline_token): Constify. (do_preprocessing, cb_line_change): Update. (scan_translation_unit): Update to handle spacing. * scan-decls.c (get_a_token): New. (skip_to_closing_brace, scan_decls): Update. * fix-header.c (read_scan_file): Update. * doc/cpp.texi: Update. * gcc.dg/cpp/macro10.c: New test. * gcc.dg/cpp/strify3.c: New test. * gcc.dg/cpp/spacing1.c: Add tests. * gcc.dg/cpp/19990703-1.c: Remove bogus test. * gcc.dg/cpp/20000625-2.c: Fudge to pass. From-SVN: r45793
2001-09-25 00:53:12 +02:00
op.type = token->type;
cpp_error (pfile, CPP_DL_ERROR,
"(\"%s\" is an alternative token for \"%s\" in C++)",
c-lex.c (cb_def_pragma): Update. * c-lex.c (cb_def_pragma): Update. (c_lex): Update, and skip padding. * cppexp.c (lex, parse_defined): Update, remove unused variable. * cpphash.h (struct toklist): Delete. (union utoken): New. (struct cpp_context): Update. (struct cpp_reader): New members eof, avoid_paste. (_cpp_temp_token): New. * cppinit.c (cpp_create_reader): Update. * cpplex.c (_cpp_temp_token): New. (_cpp_lex_direct): Add PREV_WHITE when parsing args. (cpp_output_token): Don't print leading whitespace. (cpp_output_line): Update. * cpplib.c (glue_header_name, parse_include, get__Pragma_string, do_include_common, do_line, do_ident, do_pragma, do_pragma_dependency, _cpp_do__Pragma, parse_answer, parse_assertion): Update. (get_token_no_padding): New. * cpplib.h (CPP_PADDING): New. (AVOID_LPASTE): Delete. (struct cpp_token): New union member source. (cpp_get_token): Update. * cppmacro.c (macro_arg): Convert to use pointers to const tokens. (builtin_macro, paste_all_tokens, paste_tokens, funlike_invocation_p, replace_args, quote_string, stringify_arg, parse_arg, next_context, enter_macro_context, expand_arg, _cpp_pop_context, cpp_scan_nooutput, _cpp_backup_tokens, _cpp_create_definition): Update. (push_arg_context): Delete. (padding_token, push_token_context, push_ptoken_context): New. (make_string_token, make_number_token): Update, rename. (cpp_get_token): Update to handle tokens as pointers to const, and insert padding appropriately. * cppmain.c (struct printer): New member prev. (check_multiline_token): Constify. (do_preprocessing, cb_line_change): Update. (scan_translation_unit): Update to handle spacing. * scan-decls.c (get_a_token): New. (skip_to_closing_brace, scan_decls): Update. * fix-header.c (read_scan_file): Update. * doc/cpp.texi: Update. * gcc.dg/cpp/macro10.c: New test. * gcc.dg/cpp/strify3.c: New test. * gcc.dg/cpp/spacing1.c: Add tests. * gcc.dg/cpp/19990703-1.c: Remove bogus test. * gcc.dg/cpp/20000625-2.c: Fudge to pass. From-SVN: r45793
2001-09-25 00:53:12 +02:00
cpp_token_as_text (pfile, token),
cpp_token_as_text (pfile, &op));
}
}
cppexp.c (parse_assertion): New. * cppexp.c (parse_assertion): New. (lex): Call it for CPP_HASH. Remove CPP_ASSERTION case. (_cpp_parse_expr): Remove case '#'. Don't set parsing_if_directive. * cpphash.c (collect_objlike_expansion, collect_funlike_expansion, collect_params, _cpp_create_definition): The list no longer has a trailing VSPACE token. * cpphash.h (enum node_type): Add T_ASSERTION. (struct hashnode): Remove aschain, add pred. (struct predicate): New. Update prototypes. * cpplex.c (expand_token_space): Handle both offset and nonoffset lists. (init_token_list, _cpp_free_token_list, _cpp_parse_assertion): Delete. (_cpp_init_toklist, _cpp_clear_toklist, _cpp_free_toklist, _cpp_slice_toklist, _cpp_squeeze_toklist, _cpp_equiv_tokens, _cpp_equiv_toklists): New. (_cpp_scan_line): Rename to _cpp_scan_until; add ability to stop at any single-character token, not just newline. (_cpp_lex_token): Remove special cases for #define and #if. (cpp_get_token): Expect # as a separate token type. Remove DIRECTIVE case. (_cpp_get_directive_token): Remove DIRECTIVE case. (_cpp_lex_line, _cpp_lex_file, _cpp_init_input_buffer): Update. * cpplib.c (_cpp_check_directive): Set dirno and SYNTAX_INCLUDE bit of flags, not dir_handler and dir_flags. (_cpp_handle_directive): Run # <number> through the same logic as normal directives. (do_define): Don't set parsing_define_directive. Use _cpp_scan_until. The list does not have a VSPACE at the end. (do_if): Save, clear, and restore only_seen_white around _cpp_parse_expr. (skip_if_group): s/CPP_DIRECTIVE/CPP_HASH/ (do_assert, do_unassert): Rewrite. * cpplib.h (TTYPE_TABLE): Remove CPP_ASSERTION. (LIST_OFFSET): New flag. (struct cpp_toklist): Replace dir_handler and dir_flags with dirno and flags. (struct cpp_reader): Remove parsing_if_directive and parsing_define_directive. From-SVN: r33984
2000-05-18 17:55:46 +02:00
if (node)
cppexp.c (parse_assertion): New. * cppexp.c (parse_assertion): New. (lex): Call it for CPP_HASH. Remove CPP_ASSERTION case. (_cpp_parse_expr): Remove case '#'. Don't set parsing_if_directive. * cpphash.c (collect_objlike_expansion, collect_funlike_expansion, collect_params, _cpp_create_definition): The list no longer has a trailing VSPACE token. * cpphash.h (enum node_type): Add T_ASSERTION. (struct hashnode): Remove aschain, add pred. (struct predicate): New. Update prototypes. * cpplex.c (expand_token_space): Handle both offset and nonoffset lists. (init_token_list, _cpp_free_token_list, _cpp_parse_assertion): Delete. (_cpp_init_toklist, _cpp_clear_toklist, _cpp_free_toklist, _cpp_slice_toklist, _cpp_squeeze_toklist, _cpp_equiv_tokens, _cpp_equiv_toklists): New. (_cpp_scan_line): Rename to _cpp_scan_until; add ability to stop at any single-character token, not just newline. (_cpp_lex_token): Remove special cases for #define and #if. (cpp_get_token): Expect # as a separate token type. Remove DIRECTIVE case. (_cpp_get_directive_token): Remove DIRECTIVE case. (_cpp_lex_line, _cpp_lex_file, _cpp_init_input_buffer): Update. * cpplib.c (_cpp_check_directive): Set dirno and SYNTAX_INCLUDE bit of flags, not dir_handler and dir_flags. (_cpp_handle_directive): Run # <number> through the same logic as normal directives. (do_define): Don't set parsing_define_directive. Use _cpp_scan_until. The list does not have a VSPACE at the end. (do_if): Save, clear, and restore only_seen_white around _cpp_parse_expr. (skip_if_group): s/CPP_DIRECTIVE/CPP_HASH/ (do_assert, do_unassert): Rewrite. * cpplib.h (TTYPE_TABLE): Remove CPP_ASSERTION. (LIST_OFFSET): New flag. (struct cpp_toklist): Replace dir_handler and dir_flags with dirno and flags. (struct cpp_reader): Remove parsing_if_directive and parsing_define_directive. From-SVN: r33984
2000-05-18 17:55:46 +02:00
{
if ((pfile->context != initial_context
|| initial_context != &pfile->base_context)
&& CPP_OPTION (pfile, warn_expansion_to_defined))
cpp_pedwarning (pfile, CPP_W_EXPANSION_TO_DEFINED,
"this use of \"defined\" may not be portable");
_cpp_mark_macro_used (node);
if (!(node->flags & NODE_USED))
{
node->flags |= NODE_USED;
if (node->type == NT_MACRO)
{
if ((node->flags & NODE_BUILTIN)
&& pfile->cb.user_builtin_macro)
pfile->cb.user_builtin_macro (pfile, node);
if (pfile->cb.used_define)
pfile->cb.used_define (pfile, pfile->directive_line, node);
}
else
{
if (pfile->cb.used_undef)
pfile->cb.used_undef (pfile, pfile->directive_line, node);
}
}
/* A possible controlling macro of the form #if !defined ().
_cpp_parse_expr checks there was no other junk on the line. */
pfile->mi_ind_cmacro = node;
cppexp.c (parse_assertion): New. * cppexp.c (parse_assertion): New. (lex): Call it for CPP_HASH. Remove CPP_ASSERTION case. (_cpp_parse_expr): Remove case '#'. Don't set parsing_if_directive. * cpphash.c (collect_objlike_expansion, collect_funlike_expansion, collect_params, _cpp_create_definition): The list no longer has a trailing VSPACE token. * cpphash.h (enum node_type): Add T_ASSERTION. (struct hashnode): Remove aschain, add pred. (struct predicate): New. Update prototypes. * cpplex.c (expand_token_space): Handle both offset and nonoffset lists. (init_token_list, _cpp_free_token_list, _cpp_parse_assertion): Delete. (_cpp_init_toklist, _cpp_clear_toklist, _cpp_free_toklist, _cpp_slice_toklist, _cpp_squeeze_toklist, _cpp_equiv_tokens, _cpp_equiv_toklists): New. (_cpp_scan_line): Rename to _cpp_scan_until; add ability to stop at any single-character token, not just newline. (_cpp_lex_token): Remove special cases for #define and #if. (cpp_get_token): Expect # as a separate token type. Remove DIRECTIVE case. (_cpp_get_directive_token): Remove DIRECTIVE case. (_cpp_lex_line, _cpp_lex_file, _cpp_init_input_buffer): Update. * cpplib.c (_cpp_check_directive): Set dirno and SYNTAX_INCLUDE bit of flags, not dir_handler and dir_flags. (_cpp_handle_directive): Run # <number> through the same logic as normal directives. (do_define): Don't set parsing_define_directive. Use _cpp_scan_until. The list does not have a VSPACE at the end. (do_if): Save, clear, and restore only_seen_white around _cpp_parse_expr. (skip_if_group): s/CPP_DIRECTIVE/CPP_HASH/ (do_assert, do_unassert): Rewrite. * cpplib.h (TTYPE_TABLE): Remove CPP_ASSERTION. (LIST_OFFSET): New flag. (struct cpp_toklist): Replace dir_handler and dir_flags with dirno and flags. (struct cpp_reader): Remove parsing_if_directive and parsing_define_directive. From-SVN: r33984
2000-05-18 17:55:46 +02:00
}
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
pfile->state.prevent_expansion--;
/* Do not treat conditional macros as being defined. This is due to the
powerpc and spu ports using conditional macros for 'vector', 'bool', and
'pixel' to act as conditional keywords. This messes up tests like #ifndef
bool. */
result.unsignedp = false;
result.high = 0;
result.overflow = false;
result.low = (node && node->type == NT_MACRO
&& (node->flags & NODE_CONDITIONAL) == 0);
return result;
cppexp.c (parse_assertion): New. * cppexp.c (parse_assertion): New. (lex): Call it for CPP_HASH. Remove CPP_ASSERTION case. (_cpp_parse_expr): Remove case '#'. Don't set parsing_if_directive. * cpphash.c (collect_objlike_expansion, collect_funlike_expansion, collect_params, _cpp_create_definition): The list no longer has a trailing VSPACE token. * cpphash.h (enum node_type): Add T_ASSERTION. (struct hashnode): Remove aschain, add pred. (struct predicate): New. Update prototypes. * cpplex.c (expand_token_space): Handle both offset and nonoffset lists. (init_token_list, _cpp_free_token_list, _cpp_parse_assertion): Delete. (_cpp_init_toklist, _cpp_clear_toklist, _cpp_free_toklist, _cpp_slice_toklist, _cpp_squeeze_toklist, _cpp_equiv_tokens, _cpp_equiv_toklists): New. (_cpp_scan_line): Rename to _cpp_scan_until; add ability to stop at any single-character token, not just newline. (_cpp_lex_token): Remove special cases for #define and #if. (cpp_get_token): Expect # as a separate token type. Remove DIRECTIVE case. (_cpp_get_directive_token): Remove DIRECTIVE case. (_cpp_lex_line, _cpp_lex_file, _cpp_init_input_buffer): Update. * cpplib.c (_cpp_check_directive): Set dirno and SYNTAX_INCLUDE bit of flags, not dir_handler and dir_flags. (_cpp_handle_directive): Run # <number> through the same logic as normal directives. (do_define): Don't set parsing_define_directive. Use _cpp_scan_until. The list does not have a VSPACE at the end. (do_if): Save, clear, and restore only_seen_white around _cpp_parse_expr. (skip_if_group): s/CPP_DIRECTIVE/CPP_HASH/ (do_assert, do_unassert): Rewrite. * cpplib.h (TTYPE_TABLE): Remove CPP_ASSERTION. (LIST_OFFSET): New flag. (struct cpp_toklist): Replace dir_handler and dir_flags with dirno and flags. (struct cpp_reader): Remove parsing_if_directive and parsing_define_directive. From-SVN: r33984
2000-05-18 17:55:46 +02:00
}
/* Convert a token into a CPP_NUMBER (an interpreted preprocessing
number or character constant, or the result of the "defined" or "#"
operators). */
static cpp_num
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
eval_token (cpp_reader *pfile, const cpp_token *token,
source_location virtual_location)
1995-03-16 22:59:07 +01:00
{
cpp_num result;
unsigned int temp;
int unsignedp = 0;
top level: 2000-07-03 Zack Weinberg <zack@wolery.cumb.org> * fix-header.c (struct partial_proto): Remove unnecessary fields. (recognized_extern, recognized_function, read_scan_file): Update for new scheme. (check_protection): It's still a multiple include guard even if it doesn't always trigger. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new scheme. * scan.h: Declare struct cpp_token. Update prototypes. 2000-07-03 Neil Booth <neilb@earthling.net> Zack Weinberg <zack@wolery.cumb.org> Complete overhaul of the lexer and macro expander. * cpphash.c (object_defn, funct_defn, push_macro_expansion, arg, arglist, argdata, reflist, collect_objlike_expansion, collect_funlike_expansion, collect_params, warn_trad_stringify, trad_stringify, duplicate_arg_p, add_pat, unsafe_chars, macarg, compare_defs, special_symbol, scan_arguments, stringify, funlike_macroexpand, _cpp_quote_string, monthnames): Delete. (cpp_lookup, _cpp_free_definition, dump_funlike_macro, _cpp_create_definition, _cpp_dump_definition, dump_hash_helper): Adjust. (find_param, count_params, parse_define, var_args_str, check_macro_redefinition, save_expansion): New. * cpplex.c (skip_block_comment, skip_line_comment, parse_name, parse_string, output_line_command, trigraph_replace, lex_line, cpp_push_buffer, cpp_pop_buffer, cpp_output_tokens, cpp_scan_buffer_nooutput, cpp_scan_buffer, cpp_free_toklist, cpp_idcmp, _cpp_get_directive_token, _cpp_init_input_buffer, _cpp_skip_rest_of_line): Modify. (maybe_macroexpand, skip_comment, copy_comment, skip_string, find_position, null_warning, bump_column, expand_name_space, pedantic_whitespace, _cpp_output_list, _cpp_slice_toklist, _cpp_squeeze_toklist, _cpp_scan_until, _cpp_skip_hspace, _cpp_parse_name, _cpp_lex_token, cpp_get_non_space_token, _cpp_prescan): Delete. (dump_param_spelling, process_directive, lex_next, is_macro_disabled, stringify_arg, expand_context_stack, output_token, make_string_token, alloc_number_token, special_symbol, duplicate_token, maybe_paste_with_next, can_paste, prevent_macro_expansion, restore_macro_expansion, get_temp_token, release_temp_tokens, quote_string, token_names, token_spellings, _cpp_expand_name_space, _cpp_glue_header_name, _cpp_reserve_name_space, digraph_spellings, trigraph_ok, skip_whitespace, save_comment, placemarker_token, eof_token, cpp_context, macro_args, get_raw_token, parse_arg, parse_args, save_token, push_arg_context, push_macro_context, pop_context, do_pop_context, free_macro_args, _cpp_get_line, _cpp_run_directive): New. * cpplib.c (validate_else, parse_include, push_conditional, pass_thru_directive, read_line_number, parse_ifdef, detect_if_not_defined, _cpp_check_directive, do_define, do_undef, do_include, do_import, do_include_next, do_error, do_warning, do_ident, do_pragma, pragma_dispatch, gcc_pragmas, top_pragmas, do_pragma_gcc, do_pragma_implementation, do_pragma_poison, do_pragma_system_header, do_pragma_dependency, do_sccs, do_ifdef, do_ifndef, do_else, dl_elif, do_endif, _cpp_unwind_if_stack, do_assert, do_unassert, cpp_define, cpp_undef, cpp_assert, cpp_unassert, cpp_defined): Update for new scheme. (strtoul_for_line, get_define_node, dump_macro_name, _cpp_check_linemarker, _cpp_parse_assertion): New. (_cpp_handle_directive, do_pragma_default): Delete. * cpphash.h (struct predicate): Now struct answer. (enum spell_type, struct token_spelling, struct directive, directive_handler): New. Update prototypes. Remove unused macros. * cpplib.h: Update prototypes. Remove unused macros, structure definitions, and fields. * cpperror.c (print_containing_files, v_message): Adjust. * cppexp.c (parse_assertion, lex, parse_escape, _cpp_parse_expr): Adjust. * cppfiles.c (open_include_file, _cpp_execute_include, _cpp_compare_file_date, cpp_read_file, read_include_file): Adjust. * cppinit.c (dump_special_to_buffer): Delete. (append_include_chain, merge_include_chains, cpp_reader_init, cpp_cleanup, initialize_builtins, builtin_array, cpp_start_read, cpp_finish, handle_option, print_help): Adjust. * cppmain.c (main): Adjust. testsuite: 2000-07-03 Zack Weinberg <zack@wolery.cumb.org> * testsuite/gcc.dg/cpp/19951025-1.c: Adjust regexps. * testsuite/gcc.dg/cpp/19990703-1.c: Likewise. * testsuite/gcc.dg/cpp/20000625-1.c: Likewise. * testsuite/gcc.dg/cpp/20000625-2.c: Likewise. * testsuite/gcc.dg/cpp/macro1.c, testsuite/gcc.dg/cpp/paste1.c, testsuite/gcc.dg/cpp/paste2.c, testsuite/gcc.dg/cpp/paste3.c, testsuite/gcc.dg/cpp/paste4.c, testsuite/gcc.dg/cpp/strify1.c, testsuite/gcc.dg/cpp/strify2.c: New tests. From-SVN: r34859
2000-07-04 03:58:21 +02:00
result.unsignedp = false;
result.overflow = false;
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
switch (token->type)
cpplib.h (CPP_ASSERTION, [...]): New token types. * cpplib.h (CPP_ASSERTION, CPP_STRINGIZE, CPP_TOKPASTE): New token types. (struct cpp_reader): Add parsing_if_directive and parsing_define_directive flags. (struct cpp_options): Remove output_conditionals flag. (check_macro_name): Delete prototype. * cpphash.h (struct macrodef): Delete. (struct reflist): Separate from struct definition. (struct definition): Remove unused fields. Add column number. (create_definition): Returns a DEFINITION *. Takes a cpp_reader * and an int. * cpphash.c (SKIP_WHITE_SPACE): Delete. (PEEKC): Copy defn from cpplib.c. (rest_extension, REST_EXTENSION_LENGTH): Delete. (struct arg): New. (struct arglist): Simplify. (collect_expansion): Rewrite. Get tokens by calling cpp_get_token. Add more error checking. (collect_formal_parameters): New function, broken out of create_definition and reworked to use get_directive_token. (create_definition): All real work is now in collect_expansion and collect_formal_parameters. do_define handles finding the macro name. Return a DEFINITION, not a MACRODEF. (macroexpand): Replace bcopy with memcpy throughout. Replace character-at-a-time copy loop with memcpy and pointer increments. (compare-defs): d1->argnames / d2->argnames might be null. * cpplib.c (copy_rest_of_line): Delete function. (skip_rest_of_line): Do all the work ourselves. (skip_string): New function. (parse_string): Use skip_string. (get_macro_name): New function. (check_macro_name): Delete. (copy_comment): Use CPP_RESERVE and CPP_PUTC_Q. (cpp_skip_hspace): Use CPP_BUMP_LINE. (handle_directive): ICE if we're called on a macro buffer. (do_define): Determine macro name and type (funlike/objlike) here. Expunge all uses of MACRODEF. (cpp_push_buffer): Set line_base to NULL. (do_undef, read_line_number): Don't worry about getting a POP token. (eval_if_expression): Set/reset parsing_if_directive around cpp_parse_expr. Don't clear only_seen_white. (skip_if_group): Remove output_conditionals logic. Use skip_rest_of_line. (cpp_get_token): Return ASSERTION, STRINGIZE, and TOKPASTE tokens under appropriate conditions. (cpp_unassert): Call do_unassert not do_assert. Oops. * cppexp.c (parse_defined): New function, break out of cpp_lex. (cpp_lex): We now get CPP_ASSERTION tokens and can check them ourselves, with cpp_defined. * cppinit.c (cpp_handle_option, print_help): Delete -ifoutput. * gcc.dg/20000209-2.c: Turn off -pedantic-errors. * gcc.dg/strpaste-2.c: New. From-SVN: r32274
2000-03-01 01:57:09 +01:00
{
1995-03-16 22:59:07 +01:00
case CPP_NUMBER:
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
temp = cpp_classify_number (pfile, token, NULL, virtual_location);
Implement C++11 user-defined literals. libcpp/ * expr.c: (cpp_interpret_float_suffix, cpp_interpret_int_suffix, cpp_userdef_string_remove_type, cpp_userdef_string_add_type, cpp_userdef_char_remove_type, cpp_userdef_char_add_type, cpp_userdef_string_p, cpp_userdef_char_p, cpp_get_userdef_suffix): New. (cpp_classify_number): Classify unrecognized tokens as user-defined literals. * include/cpplib.h: Add new tokens for user-defined literals. * init.c: Add new preprocessor flag (cxx11). * lex.c: (lex_string, lex_raw_string): Handle user-defined literals including concatenation and promotion with suffixes. c-family/ * c-common.c (build_userdef_literal): New. * c-common.def: New tree code. * c-common.h (tree_userdef_literal): New tree struct and accessors. * c-lex.c (interpret_float): Add suffix parm. (c_lex_with_flags): Build literal tokens. cp/ * cp-objcp-common.c: (cp_tree_size) Return size of USERDEF_LITERAL tree. * cp-tree.h: (UDLIT_OP_*, UDLIT_OPER_P): Literal operator name tools. New tree code for user-defined literals. * cxx-pretty-print.h: (pp_cxx_userdef_literal) New. * cxx-pretty-print.c: (pp_cxx_userdef_literal) New. (pp_cxx_primary_expression, pp_cxx_expression): Use it. * decl.c: (cp_tree_node_structure): Return new tree code. (duplicate_decls): Check for raw vs. template operator conflicts. (grokfndecl, grokdeclarator): New checks for literal operators. * error.c: (dump_expr): Warn about user-defined literals in C++98 mode. (dump_function_name): Pretty printing. * mangle.c: (write_literal_operator_name): New. (write_unqualified_id, write_unqualified_name): Use it. * parser.c: (cp_parser_operator): Handle operator"". (cp_parser_userdef_char_literal, cp_parser_userdef_numeric_literal, cp_parser_userdef_string_literal): New. (cp_parser_primary_expression): Handle new user-defined literal tokens with new functions. * semantics.c: (potential_constant_expression_1): Add user-defined literals. * typeck.c (check_raw_literal_operator, check_literal_operator_args): New. From-SVN: r180536
2011-10-26 21:30:59 +02:00
if (temp & CPP_N_USERDEF)
cpp_error (pfile, CPP_DL_ERROR,
"user-defined literal in preprocessor expression");
switch (temp & CPP_N_CATEGORY)
{
case CPP_N_FLOATING:
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
cpp_error_with_line (pfile, CPP_DL_ERROR, virtual_location, 0,
"floating constant in preprocessor expression");
break;
case CPP_N_INTEGER:
if (!(temp & CPP_N_IMAGINARY))
return cpp_interpret_integer (pfile, token, temp);
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
cpp_error_with_line (pfile, CPP_DL_ERROR, virtual_location, 0,
"imaginary number in preprocessor expression");
break;
case CPP_N_INVALID:
/* Error already issued. */
break;
}
result.high = result.low = 0;
break;
case CPP_WCHAR:
case CPP_CHAR:
cpp-id-data.h (UC): Was U, conflicts with U... libcpp/ChangeLog: 2008-04-14 Kris Van Hees <kris.van.hees@oracle.com> * include/cpp-id-data.h (UC): Was U, conflicts with U... literal. * include/cpplib.h (CHAR16, CHAR32, STRING16, STRING32): New tokens. (struct cpp_options): Added uliterals. (cpp_interpret_string): Update prototype. (cpp_interpret_string_notranslate): Idem. * charset.c (init_iconv_desc): New width member in cset_converter. (cpp_init_iconv): Add support for char{16,32}_cset_desc. (convert_ucn): Idem. (emit_numeric_escape): Idem. (convert_hex): Idem. (convert_oct): Idem. (convert_escape): Idem. (converter_for_type): New function. (cpp_interpret_string): Use converter_for_type, support u and U prefix. (cpp_interpret_string_notranslate): Match changed prototype. (wide_str_to_charconst): Use converter_for_type. (cpp_interpret_charconst): Add support for CPP_CHAR{16,32}. * directives.c (linemarker_dir): Macro U changed to UC. (parse_include): Idem. (register_pragma_1): Idem. (restore_registered_pragmas): Idem. (get__Pragma_string): Support CPP_STRING{16,32}. * expr.c (eval_token): Support CPP_CHAR{16,32}. * init.c (struct lang_flags): Added uliterals. (lang_defaults): Idem. * internal.h (struct cset_converter) <width>: New field. (struct cpp_reader) <char16_cset_desc>: Idem. (struct cpp_reader) <char32_cset_desc>: Idem. * lex.c (digraph_spellings): Macro U changed to UC. (OP, TK): Idem. (lex_string): Add support for u'...', U'...', u... and U.... (_cpp_lex_direct): Idem. * macro.c (_cpp_builtin_macro_text): Macro U changed to UC. (stringify_arg): Support CPP_CHAR{16,32} and CPP_STRING{16,32}. gcc/ChangeLog: 2008-04-14 Kris Van Hees <kris.van.hees@oracle.com> * c-common.c (CHAR16_TYPE, CHAR32_TYPE): New macros. (fname_as_string): Match updated cpp_interpret_string prototype. (fix_string_type): Support char16_t* and char32_t*. (c_common_nodes_and_builtins): Add char16_t and char32_t (and derivative) nodes. Register as builtin if C++0x. (c_parse_error): Support CPP_CHAR{16,32}. * c-common.h (RID_CHAR16, RID_CHAR32): New elements. (enum c_tree_index) <CTI_CHAR16_TYPE, CTI_SIGNED_CHAR16_TYPE, CTI_UNSIGNED_CHAR16_TYPE, CTI_CHAR32_TYPE, CTI_SIGNED_CHAR32_TYPE, CTI_UNSIGNED_CHAR32_TYPE, CTI_CHAR16_ARRAY_TYPE, CTI_CHAR32_ARRAY_TYPE>: New elements. (char16_type_node, signed_char16_type_node, unsigned_char16_type_node, char32_type_node, signed_char32_type_node, char16_array_type_node, char32_array_type_node): New defines. * c-lex.c (cb_ident): Match updated cpp_interpret_string prototype. (c_lex_with_flags): Support CPP_CHAR{16,32} and CPP_STRING{16,32}. (lex_string): Support CPP_STRING{16,32}, match updated cpp_interpret_string and cpp_interpret_string_notranslate prototypes. (lex_charconst): Support CPP_CHAR{16,32}. * c-parser.c (c_parser_postfix_expression): Support CPP_CHAR{16,32} and CPP_STRING{16,32}. gcc/cp/ChangeLog: 2008-04-14 Kris Van Hees <kris.van.hees@oracle.com> * cvt.c (type_promotes_to): Support char16_t and char32_t. * decl.c (grokdeclarator): Disallow signed/unsigned/short/long on char16_t and char32_t. * lex.c (reswords): Add char16_t and char32_t (for c++0x). * mangle.c (write_builtin_type): Mangle char16_t/char32_t as vendor extended builtin type u8char32_t. * parser.c (cp_lexer_next_token_is_decl_specifier_keyword): Support RID_CHAR{16,32}. (cp_lexer_print_token): Support CPP_STRING{16,32}. (cp_parser_is_string_literal): Idem. (cp_parser_string_literal): Idem. (cp_parser_primary_expression): Support CPP_CHAR{16,32} and CPP_STRING{16,32}. (cp_parser_simple_type_specifier): Support RID_CHAR{16,32}. * tree.c (char_type_p): Support char16_t and char32_t as char types. * typeck.c (string_conv_p): Support char16_t and char32_t. gcc/testsuite/ChangeLog: 2008-04-14 Kris Van Hees <kris.van.hees@oracle.com> Tests for char16_t and char32_t support. * g++.dg/ext/utf-cvt.C: New * g++.dg/ext/utf-cxx0x.C: New * g++.dg/ext/utf-cxx98.C: New * g++.dg/ext/utf-dflt.C: New * g++.dg/ext/utf-gnuxx0x.C: New * g++.dg/ext/utf-gnuxx98.C: New * g++.dg/ext/utf-mangle.C: New * g++.dg/ext/utf-typedef-cxx0x.C: New * g++.dg/ext/utf-typedef- * g++.dg/ext/utf-typespec.C: New * g++.dg/ext/utf16-1.C: New * g++.dg/ext/utf16-2.C: New * g++.dg/ext/utf16-3.C: New * g++.dg/ext/utf16-4.C: New * g++.dg/ext/utf32-1.C: New * g++.dg/ext/utf32-2.C: New * g++.dg/ext/utf32-3.C: New * g++.dg/ext/utf32-4.C: New * gcc.dg/utf-cvt.c: New * gcc.dg/utf-dflt.c: New * gcc.dg/utf16-1.c: New * gcc.dg/utf16-2.c: New * gcc.dg/utf16-3.c: New * gcc.dg/utf16-4.c: New * gcc.dg/utf32-1.c: New * gcc.dg/utf32-2.c: New * gcc.dg/utf32-3.c: New * gcc.dg/utf32-4.c: New libiberty/ChangeLog: 2008-04-14 Kris Van Hees <kris.van.hees@oracle.com> * testsuite/demangle-expected: Added tests for char16_t and char32_t. From-SVN: r134438
2008-04-18 15:58:08 +02:00
case CPP_CHAR16:
case CPP_CHAR32:
Implement N4197 - Adding u8 character literals libcpp: 2015-06-30 Edward Smith-Rowland <3dw4rd@verizon.net> Implement N4197 - Adding u8 character literals * include/cpplib.h (UTF8CHAR, UTF8CHAR_USERDEF): New cpp tokens; (struct cpp_options): Add utf8_char_literals. * init.c (struct lang_flags): Add utf8_char_literals; (struct lang_flags lang_defaults): Add column for utf8_char_literals. * macro.c (stringify_arg()): Treat CPP_UTF8CHAR token; * expr.c (cpp_userdef_char_remove_type(), cpp_userdef_char_add_type()): Treat CPP_UTF8CHAR_USERDEF, CPP_UTF8CHAR tokens; (cpp_userdef_char_p()): Treat CPP_UTF8CHAR_USERDEF token; (eval_token(), _cpp_parse_expr()): Treat CPP_UTF8CHAR token. * lex.c (lex_string(), _cpp_lex_direct()): Include CPP_UTF8CHAR tokens. * charset.c (converter_for_type(), cpp_interpret_charconst()): Treat CPP_UTF8CHAR token. gcc/c-family: 2015-06-30 Edward Smith-Rowland <3dw4rd@verizon.net> Implement N4197 - Adding u8 character literals * c-family/c-ada-spec.c (print_ada_macros()): Treat CPP_UTF8CHAR like CPP_CHAR. * c-family/c-common.c (c_parse_error()): print CPP_UTF8CHAR and CPP_UTF8CHAR_USERDEF tokens. * c-family/c-lex.c (c_lex_with_flags()): Treat CPP_UTF8CHAR_USERDEF and CPP_UTF8CHAR tokens; (lex_charconst()): Treat CPP_UTF8CHAR token. gcc/cp: 2015-06-30 Edward Smith-Rowland <3dw4rd@verizon.net> Implement N4197 - Adding u8 character literals * parser.c (cp_parser_primary_expression()): Treat CPP_UTF8CHAR and CPP_UTF8CHAR_USERDEF tokens; (cp_parser_parenthesized_expression_list()): Treat CPP_UTF8CHAR token. gcc/testsuite: 2015-06-30 Edward Smith-Rowland <3dw4rd@verizon.net> Implement N4197 - Adding u8 character literals * g++.dg/cpp1z/utf8.C: New. * g++.dg/cpp1z/utf8-neg.C: New. * g++.dg/cpp1z/udlit-utf8char.C: New. From-SVN: r225185
2015-06-30 14:58:48 +02:00
case CPP_UTF8CHAR:
{
cppchar_t cc = cpp_interpret_charconst (pfile, token,
&temp, &unsignedp);
result.high = 0;
result.low = cc;
/* Sign-extend the result if necessary. */
if (!unsignedp && (cppchar_signed_t) cc < 0)
{
if (PART_PRECISION > BITS_PER_CPPCHAR_T)
result.low |= ~(~(cpp_num_part) 0
>> (PART_PRECISION - BITS_PER_CPPCHAR_T));
result.high = ~(cpp_num_part) 0;
result = num_trim (result, CPP_OPTION (pfile, precision));
}
}
break;
cpplib.h (CPP_ASSERTION, [...]): New token types. * cpplib.h (CPP_ASSERTION, CPP_STRINGIZE, CPP_TOKPASTE): New token types. (struct cpp_reader): Add parsing_if_directive and parsing_define_directive flags. (struct cpp_options): Remove output_conditionals flag. (check_macro_name): Delete prototype. * cpphash.h (struct macrodef): Delete. (struct reflist): Separate from struct definition. (struct definition): Remove unused fields. Add column number. (create_definition): Returns a DEFINITION *. Takes a cpp_reader * and an int. * cpphash.c (SKIP_WHITE_SPACE): Delete. (PEEKC): Copy defn from cpplib.c. (rest_extension, REST_EXTENSION_LENGTH): Delete. (struct arg): New. (struct arglist): Simplify. (collect_expansion): Rewrite. Get tokens by calling cpp_get_token. Add more error checking. (collect_formal_parameters): New function, broken out of create_definition and reworked to use get_directive_token. (create_definition): All real work is now in collect_expansion and collect_formal_parameters. do_define handles finding the macro name. Return a DEFINITION, not a MACRODEF. (macroexpand): Replace bcopy with memcpy throughout. Replace character-at-a-time copy loop with memcpy and pointer increments. (compare-defs): d1->argnames / d2->argnames might be null. * cpplib.c (copy_rest_of_line): Delete function. (skip_rest_of_line): Do all the work ourselves. (skip_string): New function. (parse_string): Use skip_string. (get_macro_name): New function. (check_macro_name): Delete. (copy_comment): Use CPP_RESERVE and CPP_PUTC_Q. (cpp_skip_hspace): Use CPP_BUMP_LINE. (handle_directive): ICE if we're called on a macro buffer. (do_define): Determine macro name and type (funlike/objlike) here. Expunge all uses of MACRODEF. (cpp_push_buffer): Set line_base to NULL. (do_undef, read_line_number): Don't worry about getting a POP token. (eval_if_expression): Set/reset parsing_if_directive around cpp_parse_expr. Don't clear only_seen_white. (skip_if_group): Remove output_conditionals logic. Use skip_rest_of_line. (cpp_get_token): Return ASSERTION, STRINGIZE, and TOKPASTE tokens under appropriate conditions. (cpp_unassert): Call do_unassert not do_assert. Oops. * cppexp.c (parse_defined): New function, break out of cpp_lex. (cpp_lex): We now get CPP_ASSERTION tokens and can check them ourselves, with cpp_defined. * cppinit.c (cpp_handle_option, print_help): Delete -ifoutput. * gcc.dg/20000209-2.c: Turn off -pedantic-errors. * gcc.dg/strpaste-2.c: New. From-SVN: r32274
2000-03-01 01:57:09 +01:00
case CPP_NAME:
if (token->val.node.node == pfile->spec_nodes.n_defined)
return parse_defined (pfile);
Implement SD-6: SG10 Feature Test Recommendations 2014-10-01 Edward Smith-Rowland <3dw4rd@verizon.net> Implement SD-6: SG10 Feature Test Recommendations * internal.h (lexer_state, spec_nodes): Add in__has_include__. * directives.c: Support __has_include__ builtin. * expr.c (parse_has_include): New function to parse __has_include__ builtin; (eval_token()): Use it. * files.c (_cpp_has_header()): New funtion to look for header; (open_file_failed()): Not an error to not find a header file for __has_include__. * identifiers.c (_cpp_init_hashtable()): Add entry for __has_include__. * pch.c (cpp_read_state): Lookup __has_include__. * traditional.c (enum ls, _cpp_scan_out_logical_line()): Walk through __has_include__ statements. 2014-10-01 Edward Smith-Rowland <3dw4rd@verizon.net> Implement SD-6: SG10 Feature Test Recommendations * c-cppbuiltin.c (c_cpp_builtins()): Define language feature macros and the __has_header macro. 2014-10-01 Edward Smith-Rowland <3dw4rd@verizon.net> Implement SD-6: SG10 Feature Test Recommendations * include/bits/basic_string.h: Add __cpp_lib feature test macro. * include/bits/stl_algobase.h: Ditto. * include/bits/stl_function.h: Ditto. * include/bits/unique_ptr.h: Ditto. * include/std/chrono: Ditto. * include/std/complex: Ditto. * include/std/iomanip: Ditto. * include/std/shared_mutex: Ditto. * include/std/tuple: Ditto. * include/std/type_traits: Ditto. * include/std/utility: Ditto. * testsuite/experimental/feat-cxx14.cc: New. * testsuite/experimental/feat-lib-fund.cc: New. * testsuite/20_util/declval/requirements/1_neg.cc: Adjust. * testsuite/20_util/duration/literals/range.cc: Adjust. * testsuite/20_util/duration/requirements/typedefs_neg1.cc: Adjust. * testsuite/20_util/duration/requirements/typedefs_neg2.cc: Adjust. * testsuite/20_util/duration/requirements/typedefs_neg3.cc: Adjust. * testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Adjust. * testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: Adjust. * testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust. * testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc: Adjust. 2014-10-01 Edward Smith-Rowland <3dw4rd@verizon.net> Implement SD-6: SG10 Feature Test Recommendations * g++.dg/cpp1y/feat-cxx11-neg.C: New. * g++.dg/cpp1y/feat-cxx11.C: New. * g++.dg/cpp1y/feat-cxx14.C: New. * g++.dg/cpp1y/feat-cxx98.C: New. * g++.dg/cpp1y/feat-cxx98-neg.C: New. * g++.dg/cpp1y/phoobhar.h: New. * g++.dg/cpp1y/testinc/phoobhar.h: New. From-SVN: r215752
2014-10-01 13:49:23 +02:00
else if (token->val.node.node == pfile->spec_nodes.n__has_include__)
return parse_has_include (pfile, IT_INCLUDE);
else if (token->val.node.node == pfile->spec_nodes.n__has_include_next__)
return parse_has_include (pfile, IT_INCLUDE_NEXT);
else if (CPP_OPTION (pfile, cplusplus)
&& (token->val.node.node == pfile->spec_nodes.n_true
|| token->val.node.node == pfile->spec_nodes.n_false))
{
result.high = 0;
result.low = (token->val.node.node == pfile->spec_nodes.n_true);
}
else
{
result.high = 0;
result.low = 0;
if (CPP_OPTION (pfile, warn_undef) && !pfile->state.skip_eval)
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
cpp_warning_with_line (pfile, CPP_W_UNDEF, virtual_location, 0,
"\"%s\" is not defined, evaluates to 0",
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
NODE_NAME (token->val.node.node));
1995-03-16 22:59:07 +01:00
}
break;
1995-03-16 22:59:07 +01:00
re PR preprocessor/22168 (#if #A == #B should have a diagnostic in ISO C mode) libcpp PR preprocessor/22168: * include/cpplib.h (struct cpp_options) <objc>: Update documentation. * expr.c (eval_token): Warn for use of assertions. * directives.c (directive_diagnostics): Warn about extensions. (DEPRECATED): New define. (DIRECTIVE_TABLE): Use it. gcc PR preprocessor/22168: * doc/cpp.texi (Top): Update menu. (Alternatives to Wrapper #ifndef): New node. (Other Directives): Document deprecation. (Obsolete Features): Remove menu. (Assertions): Merge node into Obsolete Features. (Obsolete once-only headers): Move earlier; rename to Alternatives to Wrapper #ifndef. * doc/cppopts.texi: Update. * c.opt (Wdeprecated): Enable for C and ObjC. * doc/invoke.texi (Option Summary): Move -Wno-deprecated. (C++ Dialect Options): Move -Wno-deprecated from here to... (Warning Options): ... here. gcc/testsuite PR preprocessor/22168: * gcc.dg/pch/import-2.hs: Add -Wno-deprecated. * gcc.dg/pch/import-1.hs: Add -Wno-deprecated. * gcc.dg/pch/import-2.c: Add -Wno-deprecated. * gcc.dg/pch/import-1.c: Add -Wno-deprecated. * gcc.dg/cpp/import2.c: Add -Wno-deprecated. * gcc.dg/cpp/import1.c: Add -Wno-deprecated. * gcc.dg/cpp/trad/assert3.c: Add -Wno-deprecated. * gcc.dg/cpp/trad/assert2.c: Add -Wno-deprecated. * gcc.dg/cpp/trad/assert1.c: Add -Wno-deprecated. * gcc.dg/cpp/ident.c: Add -Wno-deprecated. * gcc.dg/cpp/ident-1.c: Add -Wno-deprecated. * gcc.dg/cpp/extratokens.c: Add -Wno-deprecated. * gcc.dg/cpp/assert3.c: Add -Wno-deprecated. * gcc.dg/cpp/assert2.c: Add -Wno-deprecated. * gcc.dg/cpp/assert1.c: Add -Wno-deprecated. * gcc.dg/cpp/assert4.c: Compile with -ansi and not -pedantic. Add -Wno-deprecated. * gcc.dg/cpp/pr22168.c: New file. * gcc.dg/cpp/pr22168-2.c: New file. From-SVN: r135264
2008-05-13 16:50:27 +02:00
case CPP_HASH:
if (!pfile->state.skipping)
{
/* A pedantic warning takes precedence over a deprecated
warning here. */
if (CPP_PEDANTIC (pfile))
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
cpp_error_with_line (pfile, CPP_DL_PEDWARN,
virtual_location, 0,
"assertions are a GCC extension");
optc-gen.awk: Generate global_options initializer instead of individual variables. gcc: * optc-gen.awk: Generate global_options initializer instead of individual variables. Add x_ prefix to names of structure members. * opth-gen.awk: Generate gcc_options structure. Add x_ prefix to names of structure members. * doc/tm.texi.in (HARD_FRAME_POINTER_IS_FRAME_POINTER, HARD_FRAME_POINTER_IS_ARG_POINTER): Document. * doc/tm.texi: Regenerate. * alias.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER * builtins.c: Use HARD_FRAME_POINTER_IS_ARG_POINTER. * c-parser.c (disable_extension_diagnostics, restore_extension_diagnostics): Update names of cpp_options members. * combine.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER * common.opt (fcompare-debug-second): Don't use Var. * config/alpha/alpha.h (target_flags): Remove. * config/arm/arm.h (HARD_FRAME_POINTER_IS_FRAME_POINTER, HARD_FRAME_POINTER_IS_ARG_POINTER): Define. * config/bfin/bfin.h (target_flags): Remove. * config/cris/cris.h (target_flags): Remove. * config/i386/i386-c.c (ix86_pragma_target_parse): Update names of cl_target_option members. * config/i386/i386.c (ix86_force_align_arg_pointer): Remove. (ix86_function_specific_print, ix86_valid_target_attribute_tree, ix86_can_inline_p): Update names of cl_target_option members. * config/i386/i386.h (ix86_isa_flags): Remove. * config/lm32/lm32.h (target_flags): Remove. * config/mcore/mcore.h (mcore_stack_increment): Remove. * config/mcore/mcore.md (addsi3): Remove extern declaration of flag_omit_frame_pointer. * config/mep/mep.h (target_flags): Remove. * config/mips/mips.h (HARD_FRAME_POINTER_IS_FRAME_POINTER, HARD_FRAME_POINTER_IS_ARG_POINTER): Define. * config/mmix/mmix.h (target_flags): Remove. * config/rs6000/rs6000.h (rs6000_xilinx_fpu, flag_pic, flag_expensive_optimizations): Remove. * config/s390/s390.h (flag_pic): Remove. * config/score/score-conv.h (target_flags): Remove. * config/sh/sh.h (sh_fixed_range_str): Remove. * config/spu/spu.h (target_flags, spu_fixed_range_string): Remove. * dbxout.c: Use HARD_FRAME_POINTER_IS_ARG_POINTER * df-scan.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * diagnostic.c (diagnostic_initialize): Update names of diagnostic_context members. * diagnostic.h (diagnostic_context): Rename inhibit_warnings and warn_system_headers. (diagnostic_report_warnings_p): Update for new names. * dwarf2out.c: Use HARD_FRAME_POINTER_IS_ARG_POINTER * emit-rtl.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER and HARD_FRAME_POINTER_IS_ARG_POINTER. * flags.h (flag_compare_debug): Declare. * ira.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER * opts.c (flag_compare_debug): Define. (common_handle_option): Update names of diagnostic_context members. Handle -fcompare-debug-second. (fast_math_flags_struct_set_p): Update names of cl_optimization members. * reginfo.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * regrename.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * reload.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * reload1.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * resource.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER. * rtl.h (HARD_FRAME_POINTER_IS_FRAME_POINTER, HARD_FRAME_POINTER_IS_ARG_POINTER): Define and use. * sel-sched.c: Use HARD_FRAME_POINTER_IS_FRAME_POINTER * stmt.c: Use HARD_FRAME_POINTER_IS_ARG_POINTER. gcc/c-family: * c-common.c (c_cpp_error): Update names of diagnostic_context members. * c-cppbuiltin.c (c_cpp_builtins_optimize_pragma): Update names of cl_optimization members. * c-opts.c (warning_as_error_callback, c_common_handle_option, sanitize_cpp_opts, finish_options): Update names of cpp_options members. gcc/fortran: * cpp.c (cpp_define_builtins): Update names of gfc_option_t members. (gfc_cpp_post_options): Update names of cpp_options members. (cb_cpp_error): Update names of diagnostic_context members. * f95-lang.c (gfc_init_builtin_functions): Update names of gfc_option_t members. * gfortran.h (gfc_option_t): Rename warn_conversion and flag_openmp. * intrinsic.c (gfc_convert_type_warn): Update names of gfc_option_t members. * options.c (gfc_init_options, gfc_post_options, set_Wall, gfc_handle_option): Update names of gfc_option_t members. * parse.c (next_free, next_fixed): Update names of gfc_option_t members. * scanner.c (pedantic): Remove extern declaration. (skip_free_comments, skip_fixed_comments, include_line): Update names of gfc_option_t members. * trans-decl.c (gfc_generate_function_code): Update names of gfc_option_t members. gcc/java: * java-tree.h (flag_filelist_file, flag_assert, flag_jni, flag_force_classes_archive_check, flag_redundant, flag_newer, flag_use_divide_subroutine, flag_use_atomic_builtins, flag_use_boehm_gc, flag_hash_synchronization, flag_check_references, flag_optimize_sci, flag_indirect_classes, flag_indirect_dispatch, flag_store_check, flag_reduced_reflection): Remove. * jcf-dump.c (flag_newer): Remove. * jcf.h (quiet_flag): Remove. * parse.h (quiet_flag): Remove. libcpp: * include/cpplib.h (cpp_options): Rename warn_deprecated, warn_traditional, warn_long_long and pedantic. * directives.c (directive_diagnostics, _cpp_handle_directive): Update names of cpp_options members. * expr.c (cpp_classify_number, eval_token): Update names of cpp_options members. * init.c (cpp_create_reader, post_options): Update names of cpp_options members. * internal.h (CPP_PEDANTIC, CPP_WTRADITIONAL): Update names of cpp_options members. * macro.c (parse_params): Update names of cpp_options members. From-SVN: r164723
2010-09-29 16:49:14 +02:00
else if (CPP_OPTION (pfile, cpp_warn_deprecated))
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
cpp_warning_with_line (pfile, CPP_W_DEPRECATED, virtual_location, 0,
"assertions are a deprecated extension");
re PR preprocessor/22168 (#if #A == #B should have a diagnostic in ISO C mode) libcpp PR preprocessor/22168: * include/cpplib.h (struct cpp_options) <objc>: Update documentation. * expr.c (eval_token): Warn for use of assertions. * directives.c (directive_diagnostics): Warn about extensions. (DEPRECATED): New define. (DIRECTIVE_TABLE): Use it. gcc PR preprocessor/22168: * doc/cpp.texi (Top): Update menu. (Alternatives to Wrapper #ifndef): New node. (Other Directives): Document deprecation. (Obsolete Features): Remove menu. (Assertions): Merge node into Obsolete Features. (Obsolete once-only headers): Move earlier; rename to Alternatives to Wrapper #ifndef. * doc/cppopts.texi: Update. * c.opt (Wdeprecated): Enable for C and ObjC. * doc/invoke.texi (Option Summary): Move -Wno-deprecated. (C++ Dialect Options): Move -Wno-deprecated from here to... (Warning Options): ... here. gcc/testsuite PR preprocessor/22168: * gcc.dg/pch/import-2.hs: Add -Wno-deprecated. * gcc.dg/pch/import-1.hs: Add -Wno-deprecated. * gcc.dg/pch/import-2.c: Add -Wno-deprecated. * gcc.dg/pch/import-1.c: Add -Wno-deprecated. * gcc.dg/cpp/import2.c: Add -Wno-deprecated. * gcc.dg/cpp/import1.c: Add -Wno-deprecated. * gcc.dg/cpp/trad/assert3.c: Add -Wno-deprecated. * gcc.dg/cpp/trad/assert2.c: Add -Wno-deprecated. * gcc.dg/cpp/trad/assert1.c: Add -Wno-deprecated. * gcc.dg/cpp/ident.c: Add -Wno-deprecated. * gcc.dg/cpp/ident-1.c: Add -Wno-deprecated. * gcc.dg/cpp/extratokens.c: Add -Wno-deprecated. * gcc.dg/cpp/assert3.c: Add -Wno-deprecated. * gcc.dg/cpp/assert2.c: Add -Wno-deprecated. * gcc.dg/cpp/assert1.c: Add -Wno-deprecated. * gcc.dg/cpp/assert4.c: Compile with -ansi and not -pedantic. Add -Wno-deprecated. * gcc.dg/cpp/pr22168.c: New file. * gcc.dg/cpp/pr22168-2.c: New file. From-SVN: r135264
2008-05-13 16:50:27 +02:00
}
_cpp_test_assertion (pfile, &temp);
result.high = 0;
result.low = temp;
re PR preprocessor/22168 (#if #A == #B should have a diagnostic in ISO C mode) libcpp PR preprocessor/22168: * include/cpplib.h (struct cpp_options) <objc>: Update documentation. * expr.c (eval_token): Warn for use of assertions. * directives.c (directive_diagnostics): Warn about extensions. (DEPRECATED): New define. (DIRECTIVE_TABLE): Use it. gcc PR preprocessor/22168: * doc/cpp.texi (Top): Update menu. (Alternatives to Wrapper #ifndef): New node. (Other Directives): Document deprecation. (Obsolete Features): Remove menu. (Assertions): Merge node into Obsolete Features. (Obsolete once-only headers): Move earlier; rename to Alternatives to Wrapper #ifndef. * doc/cppopts.texi: Update. * c.opt (Wdeprecated): Enable for C and ObjC. * doc/invoke.texi (Option Summary): Move -Wno-deprecated. (C++ Dialect Options): Move -Wno-deprecated from here to... (Warning Options): ... here. gcc/testsuite PR preprocessor/22168: * gcc.dg/pch/import-2.hs: Add -Wno-deprecated. * gcc.dg/pch/import-1.hs: Add -Wno-deprecated. * gcc.dg/pch/import-2.c: Add -Wno-deprecated. * gcc.dg/pch/import-1.c: Add -Wno-deprecated. * gcc.dg/cpp/import2.c: Add -Wno-deprecated. * gcc.dg/cpp/import1.c: Add -Wno-deprecated. * gcc.dg/cpp/trad/assert3.c: Add -Wno-deprecated. * gcc.dg/cpp/trad/assert2.c: Add -Wno-deprecated. * gcc.dg/cpp/trad/assert1.c: Add -Wno-deprecated. * gcc.dg/cpp/ident.c: Add -Wno-deprecated. * gcc.dg/cpp/ident-1.c: Add -Wno-deprecated. * gcc.dg/cpp/extratokens.c: Add -Wno-deprecated. * gcc.dg/cpp/assert3.c: Add -Wno-deprecated. * gcc.dg/cpp/assert2.c: Add -Wno-deprecated. * gcc.dg/cpp/assert1.c: Add -Wno-deprecated. * gcc.dg/cpp/assert4.c: Compile with -ansi and not -pedantic. Add -Wno-deprecated. * gcc.dg/cpp/pr22168.c: New file. * gcc.dg/cpp/pr22168-2.c: New file. From-SVN: r135264
2008-05-13 16:50:27 +02:00
break;
default:
abort ();
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
}
result.unsignedp = !!unsignedp;
return result;
1995-03-16 22:59:07 +01:00
}
/* Operator precedence and flags table.
After an operator is returned from the lexer, if it has priority less
than the operator on the top of the stack, we reduce the stack by one
operator and repeat the test. Since equal priorities do not reduce,
this is naturally right-associative.
We handle left-associative operators by decrementing the priority of
just-lexed operators by one, but retaining the priority of operators
already on the stack.
The remaining cases are '(' and ')'. We handle '(' by skipping the
reduction phase completely. ')' is given lower priority than
everything else, including '(', effectively forcing a reduction of the
parenthesized expression. If there is a matching '(', the routine
reduce() exits immediately. If the normal exit route sees a ')', then
there cannot have been a matching '(' and an error message is output.
The parser assumes all shifted operators require a left operand unless
the flag NO_L_OPERAND is set. These semantics are automatic; any
extra semantics need to be handled with operator-specific code. */
/* Flags. If CHECK_PROMOTION, we warn if the effective sign of an
operand changes because of integer promotions. */
#define NO_L_OPERAND (1 << 0)
#define LEFT_ASSOC (1 << 1)
#define CHECK_PROMOTION (1 << 2)
/* Operator to priority map. Must be in the same order as the first
N entries of enum cpp_ttype. */
configure.ac: Check declarations for asprintf and vasprintf. * configure.ac: Check declarations for asprintf and vasprintf. * config.in: Regenerate. * configure: Likewise. * charset.c (conversion_loop): Use XRESIZEVEC. (convert_no_conversion): Likewise. (convert_using_iconv): Likewise. (init_iconv_desc): Cast return value of alloca. (cpp_host_to_exec_charset): Use XNEWVEC. (emit_numeric_escape): Use XRESIZEVEC. (cpp_interpret_string): Use XNEWVEC. (cpp_interpret_string): Use XRESIZEVEC. (_cpp_interpret_identifier): Cast return value of alloca. (_cpp_convert_input): Use XNEWVEC and XRESIZEVEC. * directives.c (glue_header_name): Use XNEWVEC and XRESIZEVEC. (parse_include): Use XNEWVEC. (insert_pragma_entry): Rename local variable "new" to "new_entry". (save_registered_pragmas): Cast return value of xmemdup. (destringize_and_run): Same for alloca. (parse_assertion): Likewise. (do_assert): Cast allocated storage to proper type. (cpp_define): Likewise. (_cpp_define_builtin): Likewise. (cpp_undef): Likewise. (handle_assertion): Likewise. (cpp_push_buffer): Rename local variable "new" to "new_buffer". * expr.c (CPP_UPLUS): Cast value to type cpp_ttype. (CPP_UMINUS): Likewise. (struct cpp_operator): Rename from struct operator. (_cpp_expand_op_stack): Use XRESIZEVEC. * files.c (pch_open_file): Use XNEWVEC. (pch_open_file): Use XRESIZEVEC. (read_file_guts): Use XNEWVEC and XRESIZEVEC. (dir_name_of_file): Use XNEWVEC. (make_cpp_file): Use XCNEW. (make_cpp_dir): Likewise. (allocate_file_hash_entries): USE XNEWVEC. (cpp_included): Cast return value of htab_find_with_hash. (append_file_to_dir): Use XNEWVEC. (read_filename_string): Likewise. Use XRESIZEVEC too. (read_name_map): Cast return value of alloca. Use XRESIZEVEC. (remap_filename): Use XNEWVEC. (struct pchf_entry): Move definition out of struct pchf_data. (_cpp_save_file_entries): Use XCNEWVAR. (_cpp_read_file_entries): Use XNEWVAR. * identifiers.c (alloc_node): Use XOBNEW. * init.c (cpp_create_reader): Use XCNEW. (cpp_init_builtins): Cast of b->value to enum builtin_type. (read_original_directory): Cast return value of alloca. * lex.c (add_line_note): Use XRESIZEVEC. (warn_about_normalization): Use XNEWVEC. (_cpp_lex_direct): Cast node->directive_index to (enum cpp_ttype). (new_buff): Use XNEWVEC. * line-map.c (linemap_add): Use XRESIZEVEC. * macro.c (builtin_macro): Cast return value of alloca. (paste_tokens): Likewise. (expand_arg): Use XNEWVEC and XRESIZEVEC. (_cpp_save_parameter): Use XRESIZEVEC. (create_iso_definition): Cast allocated storage to proper type. (_cpp_create_definition): Likewise. (cpp_macro_definition): Use XRESIZEVEC. * makedepend.c (add_clm): Use XNEW. (add_dir): Likewise. * mkdeps.c (munge): Use XNEWVEC. (deps_init): Use XCNEW. (deps_add_target): Use XRESIZEVEC. (deps_add_default_target): Cast return value of alloca. (deps_add_dep): Use XRESIZEVEC. (deps_add_vpath): Likewise. Use XNEWVEC too. (deps_restore): Likewise. * pch.c (save_idents): Use XNEW and XNEWVEC. (cpp_save_state): Use XNEW. (count_defs): Cast return value of htab_find. (write_defs): Likewise. (cpp_write_pch_deps): Use XNEWVEC. (collect_ht_nodes): Use XRESIZEVEC. (cpp_valid_state): Use XNEWVEC. (save_macros): Use XRESIZEVEC. Cast return value of xmemdup. * symtab.c (ht_create): Use XCNEW. (ht_lookup_with_hash): Cast return value of obstack_copy0. (ht_expand): Use XCNEWVEC. * system.h (HAVE_DESIGNATED_INITIALIZERS): False if __cplusplus. (bool): Do not define if __cplusplus. From-SVN: r100295
2005-05-28 17:52:48 +02:00
static const struct cpp_operator
{
uchar prio;
uchar flags;
} optab[] =
{
/* EQ */ {0, 0}, /* Shouldn't happen. */
/* NOT */ {16, NO_L_OPERAND},
/* GREATER */ {12, LEFT_ASSOC | CHECK_PROMOTION},
/* LESS */ {12, LEFT_ASSOC | CHECK_PROMOTION},
/* PLUS */ {14, LEFT_ASSOC | CHECK_PROMOTION},
/* MINUS */ {14, LEFT_ASSOC | CHECK_PROMOTION},
/* MULT */ {15, LEFT_ASSOC | CHECK_PROMOTION},
/* DIV */ {15, LEFT_ASSOC | CHECK_PROMOTION},
/* MOD */ {15, LEFT_ASSOC | CHECK_PROMOTION},
/* AND */ {9, LEFT_ASSOC | CHECK_PROMOTION},
/* OR */ {7, LEFT_ASSOC | CHECK_PROMOTION},
/* XOR */ {8, LEFT_ASSOC | CHECK_PROMOTION},
/* RSHIFT */ {13, LEFT_ASSOC},
/* LSHIFT */ {13, LEFT_ASSOC},
/* COMPL */ {16, NO_L_OPERAND},
/* AND_AND */ {6, LEFT_ASSOC},
/* OR_OR */ {5, LEFT_ASSOC},
/* Note that QUERY, COLON, and COMMA must have the same precedence.
However, there are some special cases for these in reduce(). */
/* QUERY */ {4, 0},
/* COLON */ {4, LEFT_ASSOC | CHECK_PROMOTION},
/* COMMA */ {4, LEFT_ASSOC},
/* OPEN_PAREN */ {1, NO_L_OPERAND},
/* CLOSE_PAREN */ {0, 0},
/* EOF */ {0, 0},
/* EQ_EQ */ {11, LEFT_ASSOC},
/* NOT_EQ */ {11, LEFT_ASSOC},
/* GREATER_EQ */ {12, LEFT_ASSOC | CHECK_PROMOTION},
/* LESS_EQ */ {12, LEFT_ASSOC | CHECK_PROMOTION},
/* UPLUS */ {16, NO_L_OPERAND},
/* UMINUS */ {16, NO_L_OPERAND}
};
1995-03-16 22:59:07 +01:00
/* Parse and evaluate a C expression, reading from PFILE.
Returns the truth value of the expression.
The implementation is an operator precedence parser, i.e. a
bottom-up parser, using a stack for not-yet-reduced tokens.
The stack base is op_stack, and the current stack pointer is 'top'.
There is a stack element for each operator (only), and the most
recently pushed operator is 'top->op'. An operand (value) is
stored in the 'value' field of the stack element of the operator
that precedes it. */
bool
_cpp_parse_expr (cpp_reader *pfile, bool is_if)
1995-03-16 22:59:07 +01:00
{
struct op *top = pfile->op_stack;
unsigned int lex_count;
bool saw_leading_not, want_value = true;
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
source_location virtual_location = 0;
pfile->state.skip_eval = 0;
1995-03-16 22:59:07 +01:00
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
/* Set up detection of #if ! defined(). */
pfile->mi_ind_cmacro = 0;
saw_leading_not = false;
lex_count = 0;
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
/* Lowest priority operator prevents further reductions. */
top->op = CPP_EOF;
1995-03-16 22:59:07 +01:00
for (;;)
{
struct op op;
1995-03-16 22:59:07 +01:00
lex_count++;
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
op.token = cpp_get_token_with_location (pfile, &virtual_location);
op.op = op.token->type;
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
op.loc = virtual_location;
1995-03-16 22:59:07 +01:00
switch (op.op)
{
/* These tokens convert into values. */
case CPP_NUMBER:
case CPP_CHAR:
case CPP_WCHAR:
cpp-id-data.h (UC): Was U, conflicts with U... libcpp/ChangeLog: 2008-04-14 Kris Van Hees <kris.van.hees@oracle.com> * include/cpp-id-data.h (UC): Was U, conflicts with U... literal. * include/cpplib.h (CHAR16, CHAR32, STRING16, STRING32): New tokens. (struct cpp_options): Added uliterals. (cpp_interpret_string): Update prototype. (cpp_interpret_string_notranslate): Idem. * charset.c (init_iconv_desc): New width member in cset_converter. (cpp_init_iconv): Add support for char{16,32}_cset_desc. (convert_ucn): Idem. (emit_numeric_escape): Idem. (convert_hex): Idem. (convert_oct): Idem. (convert_escape): Idem. (converter_for_type): New function. (cpp_interpret_string): Use converter_for_type, support u and U prefix. (cpp_interpret_string_notranslate): Match changed prototype. (wide_str_to_charconst): Use converter_for_type. (cpp_interpret_charconst): Add support for CPP_CHAR{16,32}. * directives.c (linemarker_dir): Macro U changed to UC. (parse_include): Idem. (register_pragma_1): Idem. (restore_registered_pragmas): Idem. (get__Pragma_string): Support CPP_STRING{16,32}. * expr.c (eval_token): Support CPP_CHAR{16,32}. * init.c (struct lang_flags): Added uliterals. (lang_defaults): Idem. * internal.h (struct cset_converter) <width>: New field. (struct cpp_reader) <char16_cset_desc>: Idem. (struct cpp_reader) <char32_cset_desc>: Idem. * lex.c (digraph_spellings): Macro U changed to UC. (OP, TK): Idem. (lex_string): Add support for u'...', U'...', u... and U.... (_cpp_lex_direct): Idem. * macro.c (_cpp_builtin_macro_text): Macro U changed to UC. (stringify_arg): Support CPP_CHAR{16,32} and CPP_STRING{16,32}. gcc/ChangeLog: 2008-04-14 Kris Van Hees <kris.van.hees@oracle.com> * c-common.c (CHAR16_TYPE, CHAR32_TYPE): New macros. (fname_as_string): Match updated cpp_interpret_string prototype. (fix_string_type): Support char16_t* and char32_t*. (c_common_nodes_and_builtins): Add char16_t and char32_t (and derivative) nodes. Register as builtin if C++0x. (c_parse_error): Support CPP_CHAR{16,32}. * c-common.h (RID_CHAR16, RID_CHAR32): New elements. (enum c_tree_index) <CTI_CHAR16_TYPE, CTI_SIGNED_CHAR16_TYPE, CTI_UNSIGNED_CHAR16_TYPE, CTI_CHAR32_TYPE, CTI_SIGNED_CHAR32_TYPE, CTI_UNSIGNED_CHAR32_TYPE, CTI_CHAR16_ARRAY_TYPE, CTI_CHAR32_ARRAY_TYPE>: New elements. (char16_type_node, signed_char16_type_node, unsigned_char16_type_node, char32_type_node, signed_char32_type_node, char16_array_type_node, char32_array_type_node): New defines. * c-lex.c (cb_ident): Match updated cpp_interpret_string prototype. (c_lex_with_flags): Support CPP_CHAR{16,32} and CPP_STRING{16,32}. (lex_string): Support CPP_STRING{16,32}, match updated cpp_interpret_string and cpp_interpret_string_notranslate prototypes. (lex_charconst): Support CPP_CHAR{16,32}. * c-parser.c (c_parser_postfix_expression): Support CPP_CHAR{16,32} and CPP_STRING{16,32}. gcc/cp/ChangeLog: 2008-04-14 Kris Van Hees <kris.van.hees@oracle.com> * cvt.c (type_promotes_to): Support char16_t and char32_t. * decl.c (grokdeclarator): Disallow signed/unsigned/short/long on char16_t and char32_t. * lex.c (reswords): Add char16_t and char32_t (for c++0x). * mangle.c (write_builtin_type): Mangle char16_t/char32_t as vendor extended builtin type u8char32_t. * parser.c (cp_lexer_next_token_is_decl_specifier_keyword): Support RID_CHAR{16,32}. (cp_lexer_print_token): Support CPP_STRING{16,32}. (cp_parser_is_string_literal): Idem. (cp_parser_string_literal): Idem. (cp_parser_primary_expression): Support CPP_CHAR{16,32} and CPP_STRING{16,32}. (cp_parser_simple_type_specifier): Support RID_CHAR{16,32}. * tree.c (char_type_p): Support char16_t and char32_t as char types. * typeck.c (string_conv_p): Support char16_t and char32_t. gcc/testsuite/ChangeLog: 2008-04-14 Kris Van Hees <kris.van.hees@oracle.com> Tests for char16_t and char32_t support. * g++.dg/ext/utf-cvt.C: New * g++.dg/ext/utf-cxx0x.C: New * g++.dg/ext/utf-cxx98.C: New * g++.dg/ext/utf-dflt.C: New * g++.dg/ext/utf-gnuxx0x.C: New * g++.dg/ext/utf-gnuxx98.C: New * g++.dg/ext/utf-mangle.C: New * g++.dg/ext/utf-typedef-cxx0x.C: New * g++.dg/ext/utf-typedef- * g++.dg/ext/utf-typespec.C: New * g++.dg/ext/utf16-1.C: New * g++.dg/ext/utf16-2.C: New * g++.dg/ext/utf16-3.C: New * g++.dg/ext/utf16-4.C: New * g++.dg/ext/utf32-1.C: New * g++.dg/ext/utf32-2.C: New * g++.dg/ext/utf32-3.C: New * g++.dg/ext/utf32-4.C: New * gcc.dg/utf-cvt.c: New * gcc.dg/utf-dflt.c: New * gcc.dg/utf16-1.c: New * gcc.dg/utf16-2.c: New * gcc.dg/utf16-3.c: New * gcc.dg/utf16-4.c: New * gcc.dg/utf32-1.c: New * gcc.dg/utf32-2.c: New * gcc.dg/utf32-3.c: New * gcc.dg/utf32-4.c: New libiberty/ChangeLog: 2008-04-14 Kris Van Hees <kris.van.hees@oracle.com> * testsuite/demangle-expected: Added tests for char16_t and char32_t. From-SVN: r134438
2008-04-18 15:58:08 +02:00
case CPP_CHAR16:
case CPP_CHAR32:
Implement N4197 - Adding u8 character literals libcpp: 2015-06-30 Edward Smith-Rowland <3dw4rd@verizon.net> Implement N4197 - Adding u8 character literals * include/cpplib.h (UTF8CHAR, UTF8CHAR_USERDEF): New cpp tokens; (struct cpp_options): Add utf8_char_literals. * init.c (struct lang_flags): Add utf8_char_literals; (struct lang_flags lang_defaults): Add column for utf8_char_literals. * macro.c (stringify_arg()): Treat CPP_UTF8CHAR token; * expr.c (cpp_userdef_char_remove_type(), cpp_userdef_char_add_type()): Treat CPP_UTF8CHAR_USERDEF, CPP_UTF8CHAR tokens; (cpp_userdef_char_p()): Treat CPP_UTF8CHAR_USERDEF token; (eval_token(), _cpp_parse_expr()): Treat CPP_UTF8CHAR token. * lex.c (lex_string(), _cpp_lex_direct()): Include CPP_UTF8CHAR tokens. * charset.c (converter_for_type(), cpp_interpret_charconst()): Treat CPP_UTF8CHAR token. gcc/c-family: 2015-06-30 Edward Smith-Rowland <3dw4rd@verizon.net> Implement N4197 - Adding u8 character literals * c-family/c-ada-spec.c (print_ada_macros()): Treat CPP_UTF8CHAR like CPP_CHAR. * c-family/c-common.c (c_parse_error()): print CPP_UTF8CHAR and CPP_UTF8CHAR_USERDEF tokens. * c-family/c-lex.c (c_lex_with_flags()): Treat CPP_UTF8CHAR_USERDEF and CPP_UTF8CHAR tokens; (lex_charconst()): Treat CPP_UTF8CHAR token. gcc/cp: 2015-06-30 Edward Smith-Rowland <3dw4rd@verizon.net> Implement N4197 - Adding u8 character literals * parser.c (cp_parser_primary_expression()): Treat CPP_UTF8CHAR and CPP_UTF8CHAR_USERDEF tokens; (cp_parser_parenthesized_expression_list()): Treat CPP_UTF8CHAR token. gcc/testsuite: 2015-06-30 Edward Smith-Rowland <3dw4rd@verizon.net> Implement N4197 - Adding u8 character literals * g++.dg/cpp1z/utf8.C: New. * g++.dg/cpp1z/utf8-neg.C: New. * g++.dg/cpp1z/udlit-utf8char.C: New. From-SVN: r225185
2015-06-30 14:58:48 +02:00
case CPP_UTF8CHAR:
case CPP_NAME:
case CPP_HASH:
if (!want_value)
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
SYNTAX_ERROR2_AT (op.loc,
"missing binary operator before token \"%s\"",
cpp_token_as_text (pfile, op.token));
want_value = false;
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
top->value = eval_token (pfile, op.token, op.loc);
continue;
case CPP_NOT:
saw_leading_not = lex_count == 1;
break;
case CPP_PLUS:
if (want_value)
op.op = CPP_UPLUS;
break;
case CPP_MINUS:
if (want_value)
op.op = CPP_UMINUS;
break;
default:
if ((int) op.op <= (int) CPP_EQ || (int) op.op >= (int) CPP_PLUS_EQ)
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
SYNTAX_ERROR2_AT (op.loc,
"token \"%s\" is not valid in preprocessor expressions",
cpp_token_as_text (pfile, op.token));
break;
1995-03-16 22:59:07 +01:00
}
/* Check we have a value or operator as appropriate. */
if (optab[op.op].flags & NO_L_OPERAND)
1995-03-16 22:59:07 +01:00
{
if (!want_value)
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
SYNTAX_ERROR2_AT (op.loc,
"missing binary operator before token \"%s\"",
cpp_token_as_text (pfile, op.token));
}
else if (want_value)
{
/* We want a number (or expression) and haven't got one.
Try to emit a specific diagnostic. */
if (op.op == CPP_CLOSE_PAREN && top->op == CPP_OPEN_PAREN)
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
SYNTAX_ERROR_AT (op.loc,
"missing expression between '(' and ')'");
if (op.op == CPP_EOF && top->op == CPP_EOF)
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
SYNTAX_ERROR2_AT (op.loc,
"%s with no expression", is_if ? "#if" : "#elif");
if (top->op != CPP_EOF && top->op != CPP_OPEN_PAREN)
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
SYNTAX_ERROR2_AT (op.loc,
"operator '%s' has no right operand",
cpp_token_as_text (pfile, top->token));
else if (op.op == CPP_CLOSE_PAREN || op.op == CPP_EOF)
/* Complain about missing paren during reduction. */;
else
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
SYNTAX_ERROR2_AT (op.loc,
"operator '%s' has no left operand",
cpp_token_as_text (pfile, op.token));
1995-03-16 22:59:07 +01:00
}
top = reduce (pfile, top, op.op);
if (!top)
goto syntax_error;
if (op.op == CPP_EOF)
break;
switch (op.op)
{
case CPP_CLOSE_PAREN:
continue;
case CPP_OR_OR:
if (!num_zerop (top->value))
pfile->state.skip_eval++;
break;
case CPP_AND_AND:
case CPP_QUERY:
if (num_zerop (top->value))
pfile->state.skip_eval++;
break;
case CPP_COLON:
if (top->op != CPP_QUERY)
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
SYNTAX_ERROR_AT (op.loc,
" ':' without preceding '?'");
if (!num_zerop (top[-1].value)) /* Was '?' condition true? */
pfile->state.skip_eval++;
else
pfile->state.skip_eval--;
default:
break;
}
want_value = true;
1996-07-04 00:07:53 +02:00
/* Check for and handle stack overflow. */
if (++top == pfile->op_limit)
top = _cpp_expand_op_stack (pfile);
1995-03-16 22:59:07 +01:00
top->op = op.op;
top->token = op.token;
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
top->loc = op.loc;
1995-03-16 22:59:07 +01:00
}
/* The controlling macro expression is only valid if we called lex 3
times: <!> <defined expression> and <EOF>. push_conditional ()
checks that we are at top-of-file. */
if (pfile->mi_ind_cmacro && !(saw_leading_not && lex_count == 3))
pfile->mi_ind_cmacro = 0;
if (top != pfile->op_stack)
cpperror.c (print_location): Don't print include chain if line == 0. * cpperror.c (print_location): Don't print include chain if line == 0. (cpp_begin_message): Update to use DL_ macros. (cpp_ice, cpp_fatal, cpp_error_from_errno, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_notice, cpp_notice_from_errno): Remove. (cpp_error, cpp_error_with_line): Update to take a diagnostic level. (cpp_errno): New. * cppexp.c (CPP_ICE): Remove. (SYNTAX_ERROR, SYNTAX_ERROR2, parse_number, parse_defined, lex, integer_overflow, _cpp_parse_expr): Update. * cppfiles.c (read_include_file, find_include_file, handle_missing_header, _cpp_read_file, remap_filename): Update. * cpphash.h (enum error_type): Remove. (_cpp_begin_message): Update. * cppinit.c (append_include_chain, remove_dup_dirs, output_deps, cpp_handle_option, cpp_post_options): Update. * cpplex.c (trigraph_p, skip_escaped_newlines, skip_block_comment, skip_whitespace, parse_identifier, parse_slow, parse_string, _cpp_lex_direct, cpp_spell_token, maybe_read_ucs, cpp_parse_escape, cpp_interpret_charconst): Update. * cpplib.c (check_eol, directive_diagnostics, _cpp_handle_directive, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, read_flag, do_line, do_linemarker, do_ident, cpp_register_pragma, do_pragma_once, do_pragma_system_header, do_pragma_poison, do_pragma_dependency, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, parse_assertion, do_assert, _cpp_pop_buffer, do_diagnostic): Update. * cpplib.h (DL_WARNING, DL_WARNING_SYSHDR, DL_PEDWARN, DL_ERROR, DL_FATAL, DL_ICE, DL_EXTRACT, DL_WARNING_P): New. (cpp_ice, cpp_fatal, cpp_error_from_errno, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_notice, cpp_notice_from_errno): Remove. (cpp_error, cpp_error_with_line): Update to take a diagnostic level. (cpp_errno): New. * cppmacro.c (builtin_macro, stringify_arg, paste_all_tokens, collect_args, enter_macro_context, save_parameter, parse_params, _cpp_create_definition, check_trad_stringification, cpp_macro_definition): Update. * cppmain.c (cpp_preprocess_file): Update. * fix-header.c (read_scan_file): Update. From-SVN: r52302
2002-04-14 20:42:47 +02:00
{
PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens Now that we track token locations accross macro expansions, it would be cool to be able to fix PR preprocessor/7263 for real. That is, consider this example where we have a system header named header.h like this: #define _Complex __complex__ #define _Complex_I 1.0iF and then a normal C file like this: #include "header.h" static _Complex float c = _Complex_I; If we compile the file with -pedantic, the usages of _Complex or _Complex_I should not trigger any warning, even though __complex__ and the complex literal are extensions to the standard C. They shouldn't trigger any warning because _Complex and _Complex_I are defined in a system header (and expanded in normal user code). To be able to handle this, we must address two separate concerns. First, warnings about non-standard usage of numerical literals are emitted directly from within libcpp. So we must teach libcpp's parser for numerical literals to use virtual locations, instead of the spelling location it uses today. Once we have that, as the diagnostics machinery already knows how to avoid emitting errors happening on tokens that come from system headers, we win. Second, there is the issue of tracking locations for declaration specifiers, like the "_Complex" in the declaration: static _Complex float c; For that, we need to arrange for each possible declaration specifier to have its own location, because otherwise, we'd warn on e.g, on: _Complex float c; but not on: static _Complex float c; So this patch addresses the two concerns above. It's actually a follow-up on an earlier patch[1] I wrote as part of my initial work on virtual locations. We then agreed[2] that the second concern was important to address before the patch could get a chance to go in. [1]: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00957.html [2]: http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00264.html Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. libcpp/ PR preprocessor/7263 * include/cpplib.h (cpp_classify_number): Take a location parameter. * expr.c (SYNTAX_ERROR_AT, SYNTAX_ERROR2_AT): New diagnostic macros that take a location parameter. (cpp_classify_number): Take a (virtual) location parameter. Use it for diagnostics. Adjust comments. (eval_token): Take a location parameter. Pass it to cpp_classify_number and to diagnostic routines. (_cpp_parse_expr): Use virtual locations of tokens when parsing expressions. Pass a virtual location to eval_token and to diagnostic routines. gcc/c-family/ PR preprocessor/7263 * c-lex.c (c_lex_with_flags): Pass a virtual location to the call to cpp_classify_number. For diagnostics, use the precise location instead of the global input_location. gcc/ PR preprocessor/7263 * c-tree.h (enum c_declspec_word): Declare new enum. (struct c_declspecs::locations): New member. (declspecs_add_qual, declspecs_add_scspec) (declspecs_add_addrspace, declspecs_add_alignas): Take a new location parameter. * c-decl.c (build_null_declspecs): Initialize the new struct c_declspecs::locations member. (declspecs_add_addrspace): Take a location parameter for the address space. Store it onto declaration specifiers. (declspecs_add_qual): Likewise, take a location parameter for the qualifier. (declspecs_add_type): Likewise, take a location parameter for the type specifier. (declspecs_add_scspec): Likewise, take a location parameter for the storage class specifier. (declspecs_add_attrs): Likewise, take a location parameter for the first attribute. (declspecs_add_alignas): Likewise, take a location parameter for the alignas token. (finish_declspecs): For diagnostics, use the location of the relevant declspec, instead of the global input_location. * c-parser.c (c_parser_parameter_declaration): Pass the precise virtual location of the declspec to the declspecs-setters. (c_parser_declspecs): Likewise. Avoid calling c_parser_peek_token repeatedly. gcc/cp/ PR preprocessor/7263 * cp-tree.h (enum cp_decl_spec): Add new enumerators to cover all the possible declarator specifiers so far. (struct cp_decl_specifier_seq::locations): Declare new member. (cp_decl_specifier_seq::{specs, type_location}): Remove. (decl_spec_seq_has_spec_p): Declare new function. * parser.c (cp_parser_check_decl_spec): Remove. (set_and_check_decl_spec_loc): Define new static function. (decl_spec_seq_has_spec_p): Define new public function. (cp_parser_decl_specifier_seq, cp_parser_function_specifier_opt) (cp_parser_type_specifier, cp_parser_simple_type_specifier) (cp_parser_set_storage_class, cp_parser_set_decl_spec_type) (cp_parser_alias_declaration): Set the locations for each declspec, using set_and_check_decl_spec_loc. (cp_parser_explicit_instantiation, cp_parser_init_declarator) (cp_parser_member_declaration, cp_parser_init_declarator): Use the new declspec location for specifiers. Use the new decl_spec_seq_has_spec_p. (cp_parser_type_specifier_seq): Use the new set_and_check_decl_spec_loc. Stop using cp_parser_check_decl_spec. Use the new decl_spec_seq_has_spec_p. (, cp_parser_init_declarator): Use the new set_and_check_decl_spec_loc. (cp_parser_single_declaration, cp_parser_friend_p) (cp_parser_objc_class_ivars, cp_parser_objc_struct_declaration): Use the new decl_spec_seq_has_spec_p. * decl.c (check_tag_decl): Use new decl_spec_seq_has_spec_p. Use the more precise ds_redefined_builtin_type_spec location for diagnostics about re-declaring C++ built-in types. (start_decl, grokvardecl, grokdeclarator): Use the new decl_spec_seq_has_spec_p. gcc/testsuite/ PR preprocessor/7263 * gcc.dg/binary-constants-2.c: Run without tracking locations accross macro expansion. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/cpp/sysmac2.c: Likewise. * testsuite/gcc.dg/nofixed-point-2.c: Adjust for more precise location. * gcc.dg/cpp/syshdr3.c: New test. * gcc.dg/cpp/syshdr3.h: New header for the new test above. * gcc.dg/system-binary-constants-1.c: New test. * gcc.dg/system-binary-constants-1.h: New header for the new test above. * g++.dg/cpp/syshdr3.C: New test. * g++.dg/cpp/syshdr3.h: New header the new test above. * g++.dg/system-binary-constants-1.C: New test. * g++.dg/system-binary-constants-1.h: New header the new test above. From-SVN: r187587
2012-05-16 12:51:15 +02:00
cpp_error_with_line (pfile, CPP_DL_ICE, top->loc, 0,
"unbalanced stack in %s",
is_if ? "#if" : "#elif");
syntax_error:
return false; /* Return false on syntax error. */
}
return !num_zerop (top->value);
}
/* Reduce the operator / value stack if possible, in preparation for
pushing operator OP. Returns NULL on error, otherwise the top of
the stack. */
static struct op *
reduce (cpp_reader *pfile, struct op *top, enum cpp_ttype op)
{
unsigned int prio;
if (top->op <= CPP_EQ || top->op > CPP_LAST_CPP_OP + 2)
{
bad_op:
cpp_error (pfile, CPP_DL_ICE, "impossible operator '%u'", top->op);
return 0;
}
if (op == CPP_OPEN_PAREN)
return top;
/* Decrement the priority of left-associative operators to force a
reduction with operators of otherwise equal priority. */
prio = optab[op].prio - ((optab[op].flags & LEFT_ASSOC) != 0);
while (prio < optab[top->op].prio)
{
if (CPP_OPTION (pfile, warn_num_sign_change)
&& optab[top->op].flags & CHECK_PROMOTION)
check_promotion (pfile, top);
switch (top->op)
{
case CPP_UPLUS:
case CPP_UMINUS:
case CPP_NOT:
case CPP_COMPL:
top[-1].value = num_unary_op (pfile, top->value, top->op);
top[-1].loc = top->loc;
break;
case CPP_PLUS:
case CPP_MINUS:
case CPP_RSHIFT:
case CPP_LSHIFT:
case CPP_COMMA:
top[-1].value = num_binary_op (pfile, top[-1].value,
top->value, top->op);
top[-1].loc = top->loc;
break;
case CPP_GREATER:
case CPP_LESS:
case CPP_GREATER_EQ:
case CPP_LESS_EQ:
top[-1].value
= num_inequality_op (pfile, top[-1].value, top->value, top->op);
top[-1].loc = top->loc;
break;
case CPP_EQ_EQ:
case CPP_NOT_EQ:
top[-1].value
= num_equality_op (pfile, top[-1].value, top->value, top->op);
top[-1].loc = top->loc;
break;
case CPP_AND:
case CPP_OR:
case CPP_XOR:
top[-1].value
= num_bitwise_op (pfile, top[-1].value, top->value, top->op);
top[-1].loc = top->loc;
break;
case CPP_MULT:
top[-1].value = num_mul (pfile, top[-1].value, top->value);
top[-1].loc = top->loc;
break;
case CPP_DIV:
case CPP_MOD:
top[-1].value = num_div_op (pfile, top[-1].value,
top->value, top->op, top->loc);
top[-1].loc = top->loc;
break;
case CPP_OR_OR:
top--;
if (!num_zerop (top->value))
pfile->state.skip_eval--;
top->value.low = (!num_zerop (top->value)
|| !num_zerop (top[1].value));
top->value.high = 0;
top->value.unsignedp = false;
top->value.overflow = false;
top->loc = top[1].loc;
continue;
case CPP_AND_AND:
top--;
if (num_zerop (top->value))
pfile->state.skip_eval--;
top->value.low = (!num_zerop (top->value)
&& !num_zerop (top[1].value));
top->value.high = 0;
top->value.unsignedp = false;
top->value.overflow = false;
top->loc = top[1].loc;
continue;
case CPP_OPEN_PAREN:
if (op != CPP_CLOSE_PAREN)
{
cpp_error_with_line (pfile, CPP_DL_ERROR,
top->token->src_loc,
0, "missing ')' in expression");
return 0;
}
top--;
top->value = top[1].value;
top->loc = top[1].loc;
return top;
case CPP_COLON:
top -= 2;
if (!num_zerop (top->value))
{
pfile->state.skip_eval--;
top->value = top[1].value;
top->loc = top[1].loc;
}
else
{
top->value = top[2].value;
top->loc = top[2].loc;
}
top->value.unsignedp = (top[1].value.unsignedp
|| top[2].value.unsignedp);
continue;
case CPP_QUERY:
/* COMMA and COLON should not reduce a QUERY operator. */
if (op == CPP_COMMA || op == CPP_COLON)
return top;
cpp_error (pfile, CPP_DL_ERROR, "'?' without following ':'");
return 0;
default:
goto bad_op;
}
top--;
if (top->value.overflow && !pfile->state.skip_eval)
cpp_error (pfile, CPP_DL_PEDWARN,
"integer overflow in preprocessor expression");
}
if (op == CPP_CLOSE_PAREN)
{
cpp_error (pfile, CPP_DL_ERROR, "missing '(' in expression");
return 0;
}
return top;
}
/* Returns the position of the old top of stack after expansion. */
struct op *
_cpp_expand_op_stack (cpp_reader *pfile)
{
size_t old_size = (size_t) (pfile->op_limit - pfile->op_stack);
size_t new_size = old_size * 2 + 20;
configure.ac: Check declarations for asprintf and vasprintf. * configure.ac: Check declarations for asprintf and vasprintf. * config.in: Regenerate. * configure: Likewise. * charset.c (conversion_loop): Use XRESIZEVEC. (convert_no_conversion): Likewise. (convert_using_iconv): Likewise. (init_iconv_desc): Cast return value of alloca. (cpp_host_to_exec_charset): Use XNEWVEC. (emit_numeric_escape): Use XRESIZEVEC. (cpp_interpret_string): Use XNEWVEC. (cpp_interpret_string): Use XRESIZEVEC. (_cpp_interpret_identifier): Cast return value of alloca. (_cpp_convert_input): Use XNEWVEC and XRESIZEVEC. * directives.c (glue_header_name): Use XNEWVEC and XRESIZEVEC. (parse_include): Use XNEWVEC. (insert_pragma_entry): Rename local variable "new" to "new_entry". (save_registered_pragmas): Cast return value of xmemdup. (destringize_and_run): Same for alloca. (parse_assertion): Likewise. (do_assert): Cast allocated storage to proper type. (cpp_define): Likewise. (_cpp_define_builtin): Likewise. (cpp_undef): Likewise. (handle_assertion): Likewise. (cpp_push_buffer): Rename local variable "new" to "new_buffer". * expr.c (CPP_UPLUS): Cast value to type cpp_ttype. (CPP_UMINUS): Likewise. (struct cpp_operator): Rename from struct operator. (_cpp_expand_op_stack): Use XRESIZEVEC. * files.c (pch_open_file): Use XNEWVEC. (pch_open_file): Use XRESIZEVEC. (read_file_guts): Use XNEWVEC and XRESIZEVEC. (dir_name_of_file): Use XNEWVEC. (make_cpp_file): Use XCNEW. (make_cpp_dir): Likewise. (allocate_file_hash_entries): USE XNEWVEC. (cpp_included): Cast return value of htab_find_with_hash. (append_file_to_dir): Use XNEWVEC. (read_filename_string): Likewise. Use XRESIZEVEC too. (read_name_map): Cast return value of alloca. Use XRESIZEVEC. (remap_filename): Use XNEWVEC. (struct pchf_entry): Move definition out of struct pchf_data. (_cpp_save_file_entries): Use XCNEWVAR. (_cpp_read_file_entries): Use XNEWVAR. * identifiers.c (alloc_node): Use XOBNEW. * init.c (cpp_create_reader): Use XCNEW. (cpp_init_builtins): Cast of b->value to enum builtin_type. (read_original_directory): Cast return value of alloca. * lex.c (add_line_note): Use XRESIZEVEC. (warn_about_normalization): Use XNEWVEC. (_cpp_lex_direct): Cast node->directive_index to (enum cpp_ttype). (new_buff): Use XNEWVEC. * line-map.c (linemap_add): Use XRESIZEVEC. * macro.c (builtin_macro): Cast return value of alloca. (paste_tokens): Likewise. (expand_arg): Use XNEWVEC and XRESIZEVEC. (_cpp_save_parameter): Use XRESIZEVEC. (create_iso_definition): Cast allocated storage to proper type. (_cpp_create_definition): Likewise. (cpp_macro_definition): Use XRESIZEVEC. * makedepend.c (add_clm): Use XNEW. (add_dir): Likewise. * mkdeps.c (munge): Use XNEWVEC. (deps_init): Use XCNEW. (deps_add_target): Use XRESIZEVEC. (deps_add_default_target): Cast return value of alloca. (deps_add_dep): Use XRESIZEVEC. (deps_add_vpath): Likewise. Use XNEWVEC too. (deps_restore): Likewise. * pch.c (save_idents): Use XNEW and XNEWVEC. (cpp_save_state): Use XNEW. (count_defs): Cast return value of htab_find. (write_defs): Likewise. (cpp_write_pch_deps): Use XNEWVEC. (collect_ht_nodes): Use XRESIZEVEC. (cpp_valid_state): Use XNEWVEC. (save_macros): Use XRESIZEVEC. Cast return value of xmemdup. * symtab.c (ht_create): Use XCNEW. (ht_lookup_with_hash): Cast return value of obstack_copy0. (ht_expand): Use XCNEWVEC. * system.h (HAVE_DESIGNATED_INITIALIZERS): False if __cplusplus. (bool): Do not define if __cplusplus. From-SVN: r100295
2005-05-28 17:52:48 +02:00
pfile->op_stack = XRESIZEVEC (struct op, pfile->op_stack, new_size);
pfile->op_limit = pfile->op_stack + new_size;
return pfile->op_stack + old_size;
1995-03-16 22:59:07 +01:00
}
/* Emits a warning if the effective sign of either operand of OP
changes because of integer promotions. */
static void
check_promotion (cpp_reader *pfile, const struct op *op)
{
if (op->value.unsignedp == op[-1].value.unsignedp)
return;
if (op->value.unsignedp)
{
if (!num_positive (op[-1].value, CPP_OPTION (pfile, precision)))
cpp_error_with_line (pfile, CPP_DL_WARNING, op[-1].loc, 0,
"the left operand of \"%s\" changes sign when promoted",
cpp_token_as_text (pfile, op->token));
}
else if (!num_positive (op->value, CPP_OPTION (pfile, precision)))
cpp_error_with_line (pfile, CPP_DL_WARNING, op->loc, 0,
"the right operand of \"%s\" changes sign when promoted",
cpp_token_as_text (pfile, op->token));
}
/* Clears the unused high order bits of the number pointed to by PNUM. */
static cpp_num
num_trim (cpp_num num, size_t precision)
{
if (precision > PART_PRECISION)
{
precision -= PART_PRECISION;
if (precision < PART_PRECISION)
num.high &= ((cpp_num_part) 1 << precision) - 1;
}
else
{
if (precision < PART_PRECISION)
num.low &= ((cpp_num_part) 1 << precision) - 1;
num.high = 0;
}
return num;
}
/* True iff A (presumed signed) >= 0. */
static bool
num_positive (cpp_num num, size_t precision)
{
if (precision > PART_PRECISION)
{
precision -= PART_PRECISION;
return (num.high & (cpp_num_part) 1 << (precision - 1)) == 0;
}
return (num.low & (cpp_num_part) 1 << (precision - 1)) == 0;
}
/* Sign extend a number, with PRECISION significant bits and all
others assumed clear, to fill out a cpp_num structure. */
cpp_num
cpp_num_sign_extend (cpp_num num, size_t precision)
{
if (!num.unsignedp)
{
if (precision > PART_PRECISION)
{
precision -= PART_PRECISION;
if (precision < PART_PRECISION
&& (num.high & (cpp_num_part) 1 << (precision - 1)))
num.high |= ~(~(cpp_num_part) 0 >> (PART_PRECISION - precision));
}
else if (num.low & (cpp_num_part) 1 << (precision - 1))
{
if (precision < PART_PRECISION)
num.low |= ~(~(cpp_num_part) 0 >> (PART_PRECISION - precision));
num.high = ~(cpp_num_part) 0;
}
}
return num;
}
/* Returns the negative of NUM. */
static cpp_num
num_negate (cpp_num num, size_t precision)
{
cpp_num copy;
copy = num;
num.high = ~num.high;
num.low = ~num.low;
if (++num.low == 0)
num.high++;
num = num_trim (num, precision);
num.overflow = (!num.unsignedp && num_eq (num, copy) && !num_zerop (num));
return num;
}
/* Returns true if A >= B. */
static bool
num_greater_eq (cpp_num pa, cpp_num pb, size_t precision)
{
bool unsignedp;
unsignedp = pa.unsignedp || pb.unsignedp;
if (!unsignedp)
{
/* Both numbers have signed type. If they are of different
sign, the answer is the sign of A. */
unsignedp = num_positive (pa, precision);
if (unsignedp != num_positive (pb, precision))
return unsignedp;
/* Otherwise we can do an unsigned comparison. */
}
return (pa.high > pb.high) || (pa.high == pb.high && pa.low >= pb.low);
}
/* Returns LHS OP RHS, where OP is a bit-wise operation. */
static cpp_num
num_bitwise_op (cpp_reader *pfile ATTRIBUTE_UNUSED,
cpp_num lhs, cpp_num rhs, enum cpp_ttype op)
{
lhs.overflow = false;
lhs.unsignedp = lhs.unsignedp || rhs.unsignedp;
/* As excess precision is zeroed, there is no need to num_trim () as
these operations cannot introduce a set bit there. */
if (op == CPP_AND)
{
lhs.low &= rhs.low;
lhs.high &= rhs.high;
}
else if (op == CPP_OR)
{
lhs.low |= rhs.low;
lhs.high |= rhs.high;
}
else
{
lhs.low ^= rhs.low;
lhs.high ^= rhs.high;
}
return lhs;
}
/* Returns LHS OP RHS, where OP is an inequality. */
static cpp_num
num_inequality_op (cpp_reader *pfile, cpp_num lhs, cpp_num rhs,
enum cpp_ttype op)
{
bool gte = num_greater_eq (lhs, rhs, CPP_OPTION (pfile, precision));
if (op == CPP_GREATER_EQ)
lhs.low = gte;
else if (op == CPP_LESS)
lhs.low = !gte;
else if (op == CPP_GREATER)
lhs.low = gte && !num_eq (lhs, rhs);
else /* CPP_LESS_EQ. */
lhs.low = !gte || num_eq (lhs, rhs);
lhs.high = 0;
lhs.overflow = false;
lhs.unsignedp = false;
return lhs;
}
/* Returns LHS OP RHS, where OP is == or !=. */
static cpp_num
num_equality_op (cpp_reader *pfile ATTRIBUTE_UNUSED,
cpp_num lhs, cpp_num rhs, enum cpp_ttype op)
{
/* Work around a 3.0.4 bug; see PR 6950. */
bool eq = num_eq (lhs, rhs);
if (op == CPP_NOT_EQ)
eq = !eq;
lhs.low = eq;
lhs.high = 0;
lhs.overflow = false;
lhs.unsignedp = false;
return lhs;
}
/* Shift NUM, of width PRECISION, right by N bits. */
static cpp_num
num_rshift (cpp_num num, size_t precision, size_t n)
{
cpp_num_part sign_mask;
bool x = num_positive (num, precision);
if (num.unsignedp || x)
sign_mask = 0;
else
sign_mask = ~(cpp_num_part) 0;
if (n >= precision)
num.high = num.low = sign_mask;
else
{
/* Sign-extend. */
if (precision < PART_PRECISION)
num.high = sign_mask, num.low |= sign_mask << precision;
else if (precision < 2 * PART_PRECISION)
num.high |= sign_mask << (precision - PART_PRECISION);
if (n >= PART_PRECISION)
{
n -= PART_PRECISION;
num.low = num.high;
num.high = sign_mask;
}
if (n)
{
num.low = (num.low >> n) | (num.high << (PART_PRECISION - n));
num.high = (num.high >> n) | (sign_mask << (PART_PRECISION - n));
}
}
num = num_trim (num, precision);
num.overflow = false;
return num;
}
/* Shift NUM, of width PRECISION, left by N bits. */
static cpp_num
num_lshift (cpp_num num, size_t precision, size_t n)
{
if (n >= precision)
{
num.overflow = !num.unsignedp && !num_zerop (num);
num.high = num.low = 0;
}
else
{
cpp_num orig, maybe_orig;
size_t m = n;
orig = num;
if (m >= PART_PRECISION)
{
m -= PART_PRECISION;
num.high = num.low;
num.low = 0;
}
if (m)
{
num.high = (num.high << m) | (num.low >> (PART_PRECISION - m));
num.low <<= m;
}
num = num_trim (num, precision);
if (num.unsignedp)
num.overflow = false;
else
{
maybe_orig = num_rshift (num, precision, n);
num.overflow = !num_eq (orig, maybe_orig);
}
}
return num;
}
/* The four unary operators: +, -, ! and ~. */
static cpp_num
num_unary_op (cpp_reader *pfile, cpp_num num, enum cpp_ttype op)
{
switch (op)
{
case CPP_UPLUS:
if (CPP_WTRADITIONAL (pfile) && !pfile->state.skip_eval)
diagnostic.h (diagnostic_override_option_index): New macro to set a diagnostic's option_index. * diagnostic.h (diagnostic_override_option_index): New macro to set a diagnostic's option_index. * c-tree.h (c_cpp_error): Add warning reason argument. * opts.c (_warning_as_error_callback): New. (register_warning_as_error_callback): Store callback for warnings enabled via enable_warning_as_error. (enable_warning_as_error): Call callback, minor code tidy. * opts.h (register_warning_as_error_callback): Declare. * c-opts.c (warning_as_error_callback): New, set cpp_opts flag in response to -Werror=. (c_common_init_options): Register warning_as_error_callback in opts.c. * common.opt: Add -Wno-cpp option. * c-common.c (struct reason_option_codes_t): Map cpp warning reason codes to gcc option indexes. * (c_option_controlling_cpp_error): New function, lookup the gcc option index for a cpp warning reason code. * (c_cpp_error): Add warning reason argument, call c_option_controlling_cpp_error for diagnostic_override_option_index. * doc/invoke.texi: Document -Wno-cpp. * cpp.c (cb_cpp_error): Add warning reason argument, set a value for diagnostic_override_option_index if CPP_W_WARNING_DIRECTIVE. * directives.c (do_diagnostic): Add warning reason argument, call appropriate error reporting function for code. (directive_diagnostics): Call specific warning functions with warning reason where appropriate. (do_error, do_warning, do_pragma_dependency): Add warning reason argument to do_diagnostic calls. * macro.c (_cpp_warn_if_unused_macro, enter_macro_context, _cpp_create_definition): Call specific warning functions with warning reason where appropriate. * Makefile.in: Add new diagnostic functions to gettext translations. * include/cpplib.h (struct cpp_callbacks): Add warning reason code to error callback. (CPP_DL_WARNING, CPP_DL_WARNING_SYSHDR, CPP_DL_PEDWARN, CPP_DL_ERROR, CPP_DL_ICE, CPP_DL_NOTE, CPP_DL_FATAL): Replace macros with enums. (CPP_W_NONE, CPP_W_DEPRECATED, CPP_W_COMMENTS, CPP_W_MISSING_INCLUDE_DIRS, CPP_W_TRIGRAPHS, CPP_W_MULTICHAR, CPP_W_TRADITIONAL, CPP_W_LONG_LONG, CPP_W_ENDIF_LABELS, CPP_W_NUM_SIGN_CHANGE, CPP_W_VARIADIC_MACROS, CPP_W_BUILTIN_MACRO_REDEFINED, CPP_W_DOLLARS, CPP_W_UNDEF, CPP_W_UNUSED_MACROS, CPP_W_CXX_OPERATOR_NAMES, CPP_W_NORMALIZE, CPP_W_INVALID_PCH, CPP_W_WARNING_DIRECTIVE): New enums for cpp warning reason codes. (cpp_warning, cpp_pedwarning, cpp_warning_syshdr, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): New specific error reporting functions. * pch.c (cpp_valid_state): Call specific warning functions with warning reason where appropriate. * errors.c (cpp_diagnostic, cpp_diagnostic_with_line): New central diagnostic handlers. (cpp_warning, cpp_pedwarning, cpp_warning_syshdr, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): New specific error reporting functions. * expr.c (cpp_classify_number, eval_token, num_unary_op): Call specific warning functions with warning reason where appropriate. * lex.c (_cpp_process_line_notes, _cpp_skip_block_comment, warn_about_normalization, lex_identifier_intern, lex_identifier, _cpp_lex_direct): Ditto. * charset.c (_cpp_valid_ucn, convert_hex, convert_escape, narrow_str_to_charconst): Ditto. * gcc.dg/cpp/warn-undef-2.c: New. * gcc.dg/cpp/warn-traditional-2.c: New. * gcc.dg/cpp/warn-comments-2.c: New. * gcc.dg/cpp/warning-directive-1.c: New. * gcc.dg/cpp/warn-long-long.c: New. * gcc.dg/cpp/warn-traditional.c: New. * gcc.dg/cpp/warn-variadic-2.c: New. * gcc.dg/cpp/warn-undef.c: New. * gcc.dg/cpp/warn-normalized-1.c: New. * gcc.dg/cpp/warning-directive-2.c: New. * gcc.dg/cpp/warn-long-long-2.c: New. * gcc.dg/cpp/warn-variadic.c: New. * gcc.dg/cpp/warn-normalized-2.c: New. * gcc.dg/cpp/warning-directive-3.c: New. * gcc.dg/cpp/warn-deprecated-2.c: New. * gcc.dg/cpp/warn-trigraphs-1.c: New. * gcc.dg/cpp/warn-multichar-2.c: New. * gcc.dg/cpp/warn-normalized-3.c: New. * gcc.dg/cpp/warning-directive-4.c: New. * gcc.dg/cpp/warn-unused-macros.c: New. * gcc.dg/cpp/warn-trigraphs-2.c: New. * gcc.dg/cpp/warn-cxx-compat-2.c: New. * gcc.dg/cpp/warn-cxx-compat.c: New. * gcc.dg/cpp/warn-redefined.c: New. * gcc.dg/cpp/warn-trigraphs-3.c: New. * gcc.dg/cpp/warn-unused-macros-2.c: New. * gcc.dg/cpp/warn-deprecated.c: New. * gcc.dg/cpp/warn-trigraphs-4.c: New. * gcc.dg/cpp/warn-redefined-2.c: New. * gcc.dg/cpp/warn-comments.c: New. * gcc.dg/cpp/warn-multichar.c: New. * g++.dg/cpp/warning-directive-1.C: New. * g++.dg/cpp/warning-directive-2.C: New. * g++.dg/cpp/warning-directive-3.C: New. * g++.dg/cpp/warning-directive-4.C: New. * gfortran.dg/warning-directive-1.F90: New. * gfortran.dg/warning-directive-3.F90: New. * gfortran.dg/warning-directive-2.F90: New. * gfortran.dg/warning-directive-4.F90: New. From-SVN: r158079
2010-04-07 19:18:10 +02:00
cpp_warning (pfile, CPP_W_TRADITIONAL,
"traditional C rejects the unary plus operator");
num.overflow = false;
break;
case CPP_UMINUS:
num = num_negate (num, CPP_OPTION (pfile, precision));
break;
case CPP_COMPL:
num.high = ~num.high;
num.low = ~num.low;
num = num_trim (num, CPP_OPTION (pfile, precision));
num.overflow = false;
break;
default: /* case CPP_NOT: */
num.low = num_zerop (num);
num.high = 0;
num.overflow = false;
num.unsignedp = false;
break;
}
return num;
}
/* The various binary operators. */
static cpp_num
num_binary_op (cpp_reader *pfile, cpp_num lhs, cpp_num rhs, enum cpp_ttype op)
{
cpp_num result;
size_t precision = CPP_OPTION (pfile, precision);
size_t n;
switch (op)
{
/* Shifts. */
case CPP_LSHIFT:
case CPP_RSHIFT:
if (!rhs.unsignedp && !num_positive (rhs, precision))
{
/* A negative shift is a positive shift the other way. */
if (op == CPP_LSHIFT)
op = CPP_RSHIFT;
else
op = CPP_LSHIFT;
rhs = num_negate (rhs, precision);
}
if (rhs.high)
n = ~0; /* Maximal. */
else
n = rhs.low;
if (op == CPP_LSHIFT)
lhs = num_lshift (lhs, precision, n);
else
lhs = num_rshift (lhs, precision, n);
break;
/* Arithmetic. */
case CPP_MINUS:
result.low = lhs.low - rhs.low;
result.high = lhs.high - rhs.high;
if (result.low > lhs.low)
result.high--;
result.unsignedp = lhs.unsignedp || rhs.unsignedp;
result.overflow = false;
result = num_trim (result, precision);
if (!result.unsignedp)
{
bool lhsp = num_positive (lhs, precision);
result.overflow = (lhsp != num_positive (rhs, precision)
&& lhsp != num_positive (result, precision));
}
return result;
case CPP_PLUS:
result.low = lhs.low + rhs.low;
result.high = lhs.high + rhs.high;
if (result.low < lhs.low)
result.high++;
result.unsignedp = lhs.unsignedp || rhs.unsignedp;
result.overflow = false;
result = num_trim (result, precision);
if (!result.unsignedp)
{
bool lhsp = num_positive (lhs, precision);
result.overflow = (lhsp == num_positive (rhs, precision)
&& lhsp != num_positive (result, precision));
}
return result;
/* Comma. */
default: /* case CPP_COMMA: */
if (CPP_PEDANTIC (pfile) && (!CPP_OPTION (pfile, c99)
|| !pfile->state.skip_eval))
cpp_pedwarning (pfile, CPP_W_PEDANTIC,
"comma operator in operand of #if");
lhs = rhs;
break;
}
return lhs;
}
/* Multiplies two unsigned cpp_num_parts to give a cpp_num. This
cannot overflow. */
static cpp_num
num_part_mul (cpp_num_part lhs, cpp_num_part rhs)
{
cpp_num result;
cpp_num_part middle[2], temp;
result.low = LOW_PART (lhs) * LOW_PART (rhs);
result.high = HIGH_PART (lhs) * HIGH_PART (rhs);
middle[0] = LOW_PART (lhs) * HIGH_PART (rhs);
middle[1] = HIGH_PART (lhs) * LOW_PART (rhs);
temp = result.low;
result.low += LOW_PART (middle[0]) << (PART_PRECISION / 2);
if (result.low < temp)
result.high++;
temp = result.low;
result.low += LOW_PART (middle[1]) << (PART_PRECISION / 2);
if (result.low < temp)
result.high++;
result.high += HIGH_PART (middle[0]);
result.high += HIGH_PART (middle[1]);
result.unsignedp = true;
result.overflow = false;
return result;
}
/* Multiply two preprocessing numbers. */
static cpp_num
num_mul (cpp_reader *pfile, cpp_num lhs, cpp_num rhs)
{
cpp_num result, temp;
bool unsignedp = lhs.unsignedp || rhs.unsignedp;
bool overflow, negate = false;
size_t precision = CPP_OPTION (pfile, precision);
/* Prepare for unsigned multiplication. */
if (!unsignedp)
{
if (!num_positive (lhs, precision))
negate = !negate, lhs = num_negate (lhs, precision);
if (!num_positive (rhs, precision))
negate = !negate, rhs = num_negate (rhs, precision);
}
overflow = lhs.high && rhs.high;
result = num_part_mul (lhs.low, rhs.low);
temp = num_part_mul (lhs.high, rhs.low);
result.high += temp.low;
if (temp.high)
overflow = true;
temp = num_part_mul (lhs.low, rhs.high);
result.high += temp.low;
if (temp.high)
overflow = true;
temp.low = result.low, temp.high = result.high;
result = num_trim (result, precision);
if (!num_eq (result, temp))
overflow = true;
if (negate)
result = num_negate (result, precision);
if (unsignedp)
result.overflow = false;
else
result.overflow = overflow || (num_positive (result, precision) ^ !negate
&& !num_zerop (result));
result.unsignedp = unsignedp;
return result;
}
/* Divide two preprocessing numbers, LHS and RHS, returning the answer
or the remainder depending upon OP. LOCATION is the source location
of this operator (for diagnostics). */
static cpp_num
num_div_op (cpp_reader *pfile, cpp_num lhs, cpp_num rhs, enum cpp_ttype op,
source_location location)
{
cpp_num result, sub;
cpp_num_part mask;
bool unsignedp = lhs.unsignedp || rhs.unsignedp;
bool negate = false, lhs_neg = false;
size_t i, precision = CPP_OPTION (pfile, precision);
/* Prepare for unsigned division. */
if (!unsignedp)
{
if (!num_positive (lhs, precision))
negate = !negate, lhs_neg = true, lhs = num_negate (lhs, precision);
if (!num_positive (rhs, precision))
negate = !negate, rhs = num_negate (rhs, precision);
}
/* Find the high bit. */
if (rhs.high)
{
i = precision - 1;
mask = (cpp_num_part) 1 << (i - PART_PRECISION);
for (; ; i--, mask >>= 1)
if (rhs.high & mask)
break;
}
else if (rhs.low)
{
if (precision > PART_PRECISION)
i = precision - PART_PRECISION - 1;
else
i = precision - 1;
mask = (cpp_num_part) 1 << i;
for (; ; i--, mask >>= 1)
if (rhs.low & mask)
break;
}
else
{
if (!pfile->state.skip_eval)
cpp_error_with_line (pfile, CPP_DL_ERROR, location, 0,
"division by zero in #if");
return lhs;
}
/* First nonzero bit of RHS is bit I. Do naive division by
shifting the RHS fully left, and subtracting from LHS if LHS is
at least as big, and then repeating but with one less shift.
This is not very efficient, but is easy to understand. */
rhs.unsignedp = true;
lhs.unsignedp = true;
i = precision - i - 1;
sub = num_lshift (rhs, precision, i);
result.high = result.low = 0;
for (;;)
{
if (num_greater_eq (lhs, sub, precision))
{
lhs = num_binary_op (pfile, lhs, sub, CPP_MINUS);
if (i >= PART_PRECISION)
result.high |= (cpp_num_part) 1 << (i - PART_PRECISION);
else
result.low |= (cpp_num_part) 1 << i;
}
if (i-- == 0)
break;
sub.low = (sub.low >> 1) | (sub.high << (PART_PRECISION - 1));
sub.high >>= 1;
}
/* We divide so that the remainder has the sign of the LHS. */
if (op == CPP_DIV)
{
result.unsignedp = unsignedp;
result.overflow = false;
if (!unsignedp)
{
if (negate)
result = num_negate (result, precision);
result.overflow = (num_positive (result, precision) ^ !negate
&& !num_zerop (result));
}
return result;
}
/* CPP_MOD. */
lhs.unsignedp = unsignedp;
lhs.overflow = false;
if (lhs_neg)
lhs = num_negate (lhs, precision);
return lhs;
}
Implement SD-6: SG10 Feature Test Recommendations 2014-10-01 Edward Smith-Rowland <3dw4rd@verizon.net> Implement SD-6: SG10 Feature Test Recommendations * internal.h (lexer_state, spec_nodes): Add in__has_include__. * directives.c: Support __has_include__ builtin. * expr.c (parse_has_include): New function to parse __has_include__ builtin; (eval_token()): Use it. * files.c (_cpp_has_header()): New funtion to look for header; (open_file_failed()): Not an error to not find a header file for __has_include__. * identifiers.c (_cpp_init_hashtable()): Add entry for __has_include__. * pch.c (cpp_read_state): Lookup __has_include__. * traditional.c (enum ls, _cpp_scan_out_logical_line()): Walk through __has_include__ statements. 2014-10-01 Edward Smith-Rowland <3dw4rd@verizon.net> Implement SD-6: SG10 Feature Test Recommendations * c-cppbuiltin.c (c_cpp_builtins()): Define language feature macros and the __has_header macro. 2014-10-01 Edward Smith-Rowland <3dw4rd@verizon.net> Implement SD-6: SG10 Feature Test Recommendations * include/bits/basic_string.h: Add __cpp_lib feature test macro. * include/bits/stl_algobase.h: Ditto. * include/bits/stl_function.h: Ditto. * include/bits/unique_ptr.h: Ditto. * include/std/chrono: Ditto. * include/std/complex: Ditto. * include/std/iomanip: Ditto. * include/std/shared_mutex: Ditto. * include/std/tuple: Ditto. * include/std/type_traits: Ditto. * include/std/utility: Ditto. * testsuite/experimental/feat-cxx14.cc: New. * testsuite/experimental/feat-lib-fund.cc: New. * testsuite/20_util/declval/requirements/1_neg.cc: Adjust. * testsuite/20_util/duration/literals/range.cc: Adjust. * testsuite/20_util/duration/requirements/typedefs_neg1.cc: Adjust. * testsuite/20_util/duration/requirements/typedefs_neg2.cc: Adjust. * testsuite/20_util/duration/requirements/typedefs_neg3.cc: Adjust. * testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Adjust. * testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: Adjust. * testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust. * testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc: Adjust. 2014-10-01 Edward Smith-Rowland <3dw4rd@verizon.net> Implement SD-6: SG10 Feature Test Recommendations * g++.dg/cpp1y/feat-cxx11-neg.C: New. * g++.dg/cpp1y/feat-cxx11.C: New. * g++.dg/cpp1y/feat-cxx14.C: New. * g++.dg/cpp1y/feat-cxx98.C: New. * g++.dg/cpp1y/feat-cxx98-neg.C: New. * g++.dg/cpp1y/phoobhar.h: New. * g++.dg/cpp1y/testinc/phoobhar.h: New. From-SVN: r215752
2014-10-01 13:49:23 +02:00
/* Handle meeting "__has_include__" in a preprocessor expression. */
static cpp_num
parse_has_include (cpp_reader *pfile, enum include_type type)
{
cpp_num result;
bool paren = false;
cpp_hashnode *node = 0;
const cpp_token *token;
bool bracket = false;
char *fname = 0;
result.unsignedp = false;
result.high = 0;
result.overflow = false;
result.low = 0;
pfile->state.in__has_include__++;
token = cpp_get_token (pfile);
if (token->type == CPP_OPEN_PAREN)
{
paren = true;
token = cpp_get_token (pfile);
}
if (token->type == CPP_STRING || token->type == CPP_HEADER_NAME)
{
if (token->type == CPP_HEADER_NAME)
bracket = true;
fname = XNEWVEC (char, token->val.str.len - 1);
memcpy (fname, token->val.str.text + 1, token->val.str.len - 2);
fname[token->val.str.len - 2] = '\0';
node = token->val.node.node;
}
else if (token->type == CPP_LESS)
{
bracket = true;
fname = _cpp_bracket_include (pfile);
}
else
cpp_error (pfile, CPP_DL_ERROR,
"operator \"__has_include__\" requires a header string");
if (fname)
{
int angle_brackets = (bracket ? 1 : 0);
if (_cpp_has_header (pfile, fname, angle_brackets, type))
result.low = 1;
else
result.low = 0;
XDELETEVEC (fname);
}
if (paren && cpp_get_token (pfile)->type != CPP_CLOSE_PAREN)
cpp_error (pfile, CPP_DL_ERROR,
"missing ')' after \"__has_include__\"");
/* A possible controlling macro of the form #if !__has_include__ ().
_cpp_parse_expr checks there was no other junk on the line. */
if (node)
pfile->mi_ind_cmacro = node;
pfile->state.in__has_include__--;
return result;
}