gcc/libcpp/expr.cc

2330 lines
63 KiB
C++
Raw Normal View History

/* Parse C expressions for cpplib.
2024-01-03 19:19:35 +08:00
Copyright (C) 1987-2024 Free Software Foundation, Inc.
Contributed by Per Bothner, 1994.
1995-03-17 05:59:07 +08: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-17 05:59:07 +08: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-17 05:59:07 +08: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 16:42:48 +08: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 18:50:45 +08:00
#include "internal.h"
1995-03-17 05:59:07 +08: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. */
Eliminate source_location in favor of location_t Historically GCC used location_t, while libcpp used source_location. This inconsistency has been annoying me for a while, so this patch removes source_location in favor of location_t throughout (as the latter is shorter). gcc/ChangeLog: * builtins.c: Replace "source_location" with "location_t". * diagnostic-show-locus.c: Likewise. * diagnostic.c: Likewise. * dumpfile.c: Likewise. * gcc-rich-location.h: Likewise. * genmatch.c: Likewise. * gimple.h: Likewise. * gimplify.c: Likewise. * input.c: Likewise. * input.h: Likewise. Eliminate the typedef. * omp-expand.c: Likewise. * selftest.h: Likewise. * substring-locations.h (get_source_location_for_substring): Rename to.. (get_location_within_string): ...this. * tree-cfg.c: Replace "source_location" with "location_t". * tree-cfgcleanup.c: Likewise. * tree-diagnostic.c: Likewise. * tree-into-ssa.c: Likewise. * tree-outof-ssa.c: Likewise. * tree-parloops.c: Likewise. * tree-phinodes.c: Likewise. * tree-phinodes.h: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-manip.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-phiprop.c: Likewise. * tree-ssa-threadupdate.c: Likewise. * tree-ssa.c: Likewise. * tree-ssa.h: Likewise. * tree-vect-loop-manip.c: Likewise. gcc/c-family/ChangeLog: * c-common.c (c_get_substring_location): Update for renaming of get_source_location_for_substring to get_location_within_string. * c-lex.c: Replace "source_location" with "location_t". * c-opts.c: Likewise. * c-ppoutput.c: Likewise. gcc/c/ChangeLog: * c-decl.c: Replace "source_location" with "location_t". * c-tree.h: Likewise. * c-typeck.c: Likewise. * gimple-parser.c: Likewise. gcc/cp/ChangeLog: * call.c: Replace "source_location" with "location_t". * cp-tree.h: Likewise. * cvt.c: Likewise. * name-lookup.c: Likewise. * parser.c: Likewise. * typeck.c: Likewise. gcc/fortran/ChangeLog: * cpp.c: Replace "source_location" with "location_t". * gfortran.h: Likewise. gcc/go/ChangeLog: * go-gcc-diagnostics.cc: Replace "source_location" with "location_t". * go-gcc.cc: Likewise. * go-linemap.cc: Likewise. * go-location.h: Likewise. * gofrontend/README: Likewise. gcc/jit/ChangeLog: * jit-playback.c: Replace "source_location" with "location_t". gcc/testsuite/ChangeLog: * g++.dg/plugin/comment_plugin.c: Replace "source_location" with "location_t". * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c: Likewise. libcc1/ChangeLog: * libcc1plugin.cc: Replace "source_location" with "location_t". (plugin_context::get_source_location): Rename to... (plugin_context::get_location_t): ...this. * libcp1plugin.cc: Likewise. libcpp/ChangeLog: * charset.c: Replace "source_location" with "location_t". * directives-only.c: Likewise. * directives.c: Likewise. * errors.c: Likewise. * expr.c: Likewise. * files.c: Likewise. * include/cpplib.h: Likewise. Rename MAX_SOURCE_LOCATION to MAX_LOCATION_T. * include/line-map.h: Likewise. * init.c: Likewise. * internal.h: Likewise. * lex.c: Likewise. * line-map.c: Likewise. * location-example.txt: Likewise. * macro.c: Likewise. * pch.c: Likewise. * traditional.c: Likewise. From-SVN: r266085
2018-11-14 04:05:03 +08:00
location_t loc; /* The location of this value. */
enum cpp_ttype op;
1995-03-17 05:59:07 +08: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,
Eliminate source_location in favor of location_t Historically GCC used location_t, while libcpp used source_location. This inconsistency has been annoying me for a while, so this patch removes source_location in favor of location_t throughout (as the latter is shorter). gcc/ChangeLog: * builtins.c: Replace "source_location" with "location_t". * diagnostic-show-locus.c: Likewise. * diagnostic.c: Likewise. * dumpfile.c: Likewise. * gcc-rich-location.h: Likewise. * genmatch.c: Likewise. * gimple.h: Likewise. * gimplify.c: Likewise. * input.c: Likewise. * input.h: Likewise. Eliminate the typedef. * omp-expand.c: Likewise. * selftest.h: Likewise. * substring-locations.h (get_source_location_for_substring): Rename to.. (get_location_within_string): ...this. * tree-cfg.c: Replace "source_location" with "location_t". * tree-cfgcleanup.c: Likewise. * tree-diagnostic.c: Likewise. * tree-into-ssa.c: Likewise. * tree-outof-ssa.c: Likewise. * tree-parloops.c: Likewise. * tree-phinodes.c: Likewise. * tree-phinodes.h: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-manip.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-phiprop.c: Likewise. * tree-ssa-threadupdate.c: Likewise. * tree-ssa.c: Likewise. * tree-ssa.h: Likewise. * tree-vect-loop-manip.c: Likewise. gcc/c-family/ChangeLog: * c-common.c (c_get_substring_location): Update for renaming of get_source_location_for_substring to get_location_within_string. * c-lex.c: Replace "source_location" with "location_t". * c-opts.c: Likewise. * c-ppoutput.c: Likewise. gcc/c/ChangeLog: * c-decl.c: Replace "source_location" with "location_t". * c-tree.h: Likewise. * c-typeck.c: Likewise. * gimple-parser.c: Likewise. gcc/cp/ChangeLog: * call.c: Replace "source_location" with "location_t". * cp-tree.h: Likewise. * cvt.c: Likewise. * name-lookup.c: Likewise. * parser.c: Likewise. * typeck.c: Likewise. gcc/fortran/ChangeLog: * cpp.c: Replace "source_location" with "location_t". * gfortran.h: Likewise. gcc/go/ChangeLog: * go-gcc-diagnostics.cc: Replace "source_location" with "location_t". * go-gcc.cc: Likewise. * go-linemap.cc: Likewise. * go-location.h: Likewise. * gofrontend/README: Likewise. gcc/jit/ChangeLog: * jit-playback.c: Replace "source_location" with "location_t". gcc/testsuite/ChangeLog: * g++.dg/plugin/comment_plugin.c: Replace "source_location" with "location_t". * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c: Likewise. libcc1/ChangeLog: * libcc1plugin.cc: Replace "source_location" with "location_t". (plugin_context::get_source_location): Rename to... (plugin_context::get_location_t): ...this. * libcp1plugin.cc: Likewise. libcpp/ChangeLog: * charset.c: Replace "source_location" with "location_t". * directives-only.c: Likewise. * directives.c: Likewise. * errors.c: Likewise. * expr.c: Likewise. * files.c: Likewise. * include/cpplib.h: Likewise. Rename MAX_SOURCE_LOCATION to MAX_LOCATION_T. * include/line-map.h: Likewise. * init.c: Likewise. * internal.h: Likewise. * lex.c: Likewise. * line-map.c: Likewise. * location-example.txt: Likewise. * macro.c: Likewise. * pch.c: Likewise. * traditional.c: Likewise. From-SVN: r266085
2018-11-14 04:05:03 +08:00
location_t);
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 *);
Eliminate source_location in favor of location_t Historically GCC used location_t, while libcpp used source_location. This inconsistency has been annoying me for a while, so this patch removes source_location in favor of location_t throughout (as the latter is shorter). gcc/ChangeLog: * builtins.c: Replace "source_location" with "location_t". * diagnostic-show-locus.c: Likewise. * diagnostic.c: Likewise. * dumpfile.c: Likewise. * gcc-rich-location.h: Likewise. * genmatch.c: Likewise. * gimple.h: Likewise. * gimplify.c: Likewise. * input.c: Likewise. * input.h: Likewise. Eliminate the typedef. * omp-expand.c: Likewise. * selftest.h: Likewise. * substring-locations.h (get_source_location_for_substring): Rename to.. (get_location_within_string): ...this. * tree-cfg.c: Replace "source_location" with "location_t". * tree-cfgcleanup.c: Likewise. * tree-diagnostic.c: Likewise. * tree-into-ssa.c: Likewise. * tree-outof-ssa.c: Likewise. * tree-parloops.c: Likewise. * tree-phinodes.c: Likewise. * tree-phinodes.h: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-manip.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-phiprop.c: Likewise. * tree-ssa-threadupdate.c: Likewise. * tree-ssa.c: Likewise. * tree-ssa.h: Likewise. * tree-vect-loop-manip.c: Likewise. gcc/c-family/ChangeLog: * c-common.c (c_get_substring_location): Update for renaming of get_source_location_for_substring to get_location_within_string. * c-lex.c: Replace "source_location" with "location_t". * c-opts.c: Likewise. * c-ppoutput.c: Likewise. gcc/c/ChangeLog: * c-decl.c: Replace "source_location" with "location_t". * c-tree.h: Likewise. * c-typeck.c: Likewise. * gimple-parser.c: Likewise. gcc/cp/ChangeLog: * call.c: Replace "source_location" with "location_t". * cp-tree.h: Likewise. * cvt.c: Likewise. * name-lookup.c: Likewise. * parser.c: Likewise. * typeck.c: Likewise. gcc/fortran/ChangeLog: * cpp.c: Replace "source_location" with "location_t". * gfortran.h: Likewise. gcc/go/ChangeLog: * go-gcc-diagnostics.cc: Replace "source_location" with "location_t". * go-gcc.cc: Likewise. * go-linemap.cc: Likewise. * go-location.h: Likewise. * gofrontend/README: Likewise. gcc/jit/ChangeLog: * jit-playback.c: Replace "source_location" with "location_t". gcc/testsuite/ChangeLog: * g++.dg/plugin/comment_plugin.c: Replace "source_location" with "location_t". * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c: Likewise. libcc1/ChangeLog: * libcc1plugin.cc: Replace "source_location" with "location_t". (plugin_context::get_source_location): Rename to... (plugin_context::get_location_t): ...this. * libcp1plugin.cc: Likewise. libcpp/ChangeLog: * charset.c: Replace "source_location" with "location_t". * directives-only.c: Likewise. * directives.c: Likewise. * errors.c: Likewise. * expr.c: Likewise. * files.c: Likewise. * include/cpplib.h: Likewise. Rename MAX_SOURCE_LOCATION to MAX_LOCATION_T. * include/line-map.h: Likewise. * init.c: Likewise. * internal.h: Likewise. * lex.c: Likewise. * line-map.c: Likewise. * location-example.txt: Likewise. * macro.c: Likewise. * pch.c: Likewise. * traditional.c: Likewise. From-SVN: r266085
2018-11-14 04:05:03 +08:00
static cpp_num eval_token (cpp_reader *, const cpp_token *, location_t);
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 *);
/* 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 23:52:48 +08: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 23:55:46 +08: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 23:55:46 +08: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 18:51:15 +08: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 23:55:46 +08: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-20 01:43:26 +08: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 orig_len = len;
const uchar *orig_s = s;
size_t flags;
middle-end, c++, i386, libgcc: std::bfloat16_t and __bf16 arithmetic support Here is a complete patch to add std::bfloat16_t support on x86 (AArch64 and ARM left for later). Almost no BFmode optabs are added by the patch, so for binops/unops it extends to SFmode first and then truncates back to BFmode. For {HF,SF,DF,XF,TF}mode -> BFmode conversions libgcc has implementations of all those conversions so that we avoid double rounding, for BFmode -> {DF,XF,TF}mode conversions to avoid growing libgcc too much it emits BFmode -> SFmode conversion first and then converts to the even wider mode, neither step should be imprecise. For BFmode -> HFmode, it first emits a precise BFmode -> SFmode conversion and then SFmode -> HFmode, because neither format is subset or superset of the other, while SFmode is superset of both. expr.cc then contains a -ffast-math optimization of the BF -> SF and SF -> BF conversions if we don't optimize for space (and for the latter if -frounding-math isn't enabled either). For x86, perhaps truncsfbf2 optab could be defined for TARGET_AVX512BF16 but IMNSHO should FAIL if !flag_finite_math || flag_rounding_math || !flag_unsafe_math_optimizations, because I think the insn doesn't raise on sNaNs, hardcodes round to nearest and flushes denormals to zero. By default (unless x86 -fexcess-precision=16) we use float excess precision for BFmode, so truncate only on explicit casts and assignments. The patch introduces a single __bf16 builtin - __builtin_nansf16b, because (__bf16) __builtin_nansf ("") will drop the sNaN into qNaN, and uses f16b suffix instead of bf16 because there would be ambiguity on log vs. logb - __builtin_logbf16 could be either log with bf16 suffix or logb with f16 suffix. In other cases libstdc++ should mostly use __builtin_*f for std::bfloat16_t overloads (we have a problem with std::nextafter though but that one we have also for std::float16_t). 2022-10-14 Jakub Jelinek <jakub@redhat.com> gcc/ * tree-core.h (enum tree_index): Add TI_BFLOAT16_TYPE. * tree.h (bfloat16_type_node): Define. * tree.cc (excess_precision_type): Promote bfloat16_type_mode like float16_type_mode. (build_common_tree_nodes): Initialize bfloat16_type_node if BFmode is supported. * expmed.h (maybe_expand_shift): Declare. * expmed.cc (maybe_expand_shift): No longer static. * expr.cc (convert_mode_scalar): Don't ICE on BF -> HF or HF -> BF conversions. If there is no optab, handle BF -> {DF,XF,TF,HF} conversions as separate BF -> SF -> {DF,XF,TF,HF} conversions, add -ffast-math generic implementation for BF -> SF and SF -> BF conversions. * builtin-types.def (BT_BFLOAT16, BT_FN_BFLOAT16_CONST_STRING): New. * builtins.def (BUILT_IN_NANSF16B): New builtin. * fold-const-call.cc (fold_const_call): Handle CFN_BUILT_IN_NANSF16B. * config/i386/i386.cc (classify_argument): Handle E_BCmode. (ix86_libgcc_floating_mode_supported_p): Also return true for BFmode for -msse2. (ix86_mangle_type): Mangle BFmode as DF16b. (ix86_invalid_conversion, ix86_invalid_unary_op, ix86_invalid_binary_op): Remove. (TARGET_INVALID_CONVERSION, TARGET_INVALID_UNARY_OP, TARGET_INVALID_BINARY_OP): Don't redefine. * config/i386/i386-builtins.cc (ix86_bf16_type_node): Remove. (ix86_register_bf16_builtin_type): Use bfloat16_type_node rather than ix86_bf16_type_node, only create it if still NULL. * config/i386/i386-builtin-types.def (BFLOAT16): Likewise. * config/i386/i386.md (cbranchbf4, cstorebf4): New expanders. gcc/c-family/ * c-cppbuiltin.cc (c_cpp_builtins): If bfloat16_type_node, predefine __BFLT16_*__ macros and for C++23 also __STDCPP_BFLOAT16_T__. Predefine bfloat16_type_node related macros for -fbuilding-libgcc. * c-lex.cc (interpret_float): Handle CPP_N_BFLOAT16. gcc/c/ * c-typeck.cc (convert_arguments): Don't promote __bf16 to double. gcc/cp/ * cp-tree.h (extended_float_type_p): Return true for bfloat16_type_node. * typeck.cc (cp_compare_floating_point_conversion_ranks): Set extended{1,2} if mv{1,2} is bfloat16_type_node. Adjust comment. gcc/testsuite/ * lib/target-supports.exp (check_effective_target_bfloat16, check_effective_target_bfloat16_runtime, add_options_for_bfloat16): New. * gcc.dg/torture/bfloat16-basic.c: New test. * gcc.dg/torture/bfloat16-builtin.c: New test. * gcc.dg/torture/bfloat16-builtin-issignaling-1.c: New test. * gcc.dg/torture/bfloat16-complex.c: New test. * gcc.dg/torture/builtin-issignaling-1.c: Allow to be includable from bfloat16-builtin-issignaling-1.c. * gcc.dg/torture/floatn-basic.h: Allow to be includable from bfloat16-basic.c. * gcc.target/i386/vect-bfloat16-typecheck_2.c: Adjust expected diagnostics. * gcc.target/i386/sse2-bfloat16-scalar-typecheck.c: Likewise. * gcc.target/i386/vect-bfloat16-typecheck_1.c: Likewise. * g++.target/i386/bfloat_cpp_typecheck.C: Likewise. libcpp/ * include/cpplib.h (CPP_N_BFLOAT16): Define. * expr.cc (interpret_float_suffix): Handle bf16 and BF16 suffixes for C++. libgcc/ * config/i386/t-softfp (softfp_extensions): Add bfsf. (softfp_truncations): Add tfbf xfbf dfbf sfbf hfbf. (CFLAGS-extendbfsf2.c, CFLAGS-truncsfbf2.c, CFLAGS-truncdfbf2.c, CFLAGS-truncxfbf2.c, CFLAGS-trunctfbf2.c, CFLAGS-trunchfbf2.c): Add -msse2. * config/i386/libgcc-glibc.ver (GCC_13.0.0): Export __extendbfsf2 and __trunc{s,d,x,t,h}fbf2. * config/i386/sfp-machine.h (_FP_NANSIGN_B): Define. * config/i386/64/sfp-machine.h (_FP_NANFRAC_B): Define. * config/i386/32/sfp-machine.h (_FP_NANFRAC_B): Define. * soft-fp/brain.h: New file. * soft-fp/truncsfbf2.c: New file. * soft-fp/truncdfbf2.c: New file. * soft-fp/truncxfbf2.c: New file. * soft-fp/trunctfbf2.c: New file. * soft-fp/trunchfbf2.c: New file. * soft-fp/truncbfhf2.c: New file. * soft-fp/extendbfsf2.c: New file. libiberty/ * cp-demangle.h (D_BUILTIN_TYPE_COUNT): Increment. * cp-demangle.c (cplus_demangle_builtin_types): Add std::bfloat16_t entry. (cplus_demangle_type): Demangle DF16b. * testsuite/demangle-expected (_Z3xxxDF16b): New test.
2022-10-14 15:37:01 +08:00
size_t f, d, l, w, q, i, fn, fnx, fn_bits, bf16;
flags = 0;
middle-end, c++, i386, libgcc: std::bfloat16_t and __bf16 arithmetic support Here is a complete patch to add std::bfloat16_t support on x86 (AArch64 and ARM left for later). Almost no BFmode optabs are added by the patch, so for binops/unops it extends to SFmode first and then truncates back to BFmode. For {HF,SF,DF,XF,TF}mode -> BFmode conversions libgcc has implementations of all those conversions so that we avoid double rounding, for BFmode -> {DF,XF,TF}mode conversions to avoid growing libgcc too much it emits BFmode -> SFmode conversion first and then converts to the even wider mode, neither step should be imprecise. For BFmode -> HFmode, it first emits a precise BFmode -> SFmode conversion and then SFmode -> HFmode, because neither format is subset or superset of the other, while SFmode is superset of both. expr.cc then contains a -ffast-math optimization of the BF -> SF and SF -> BF conversions if we don't optimize for space (and for the latter if -frounding-math isn't enabled either). For x86, perhaps truncsfbf2 optab could be defined for TARGET_AVX512BF16 but IMNSHO should FAIL if !flag_finite_math || flag_rounding_math || !flag_unsafe_math_optimizations, because I think the insn doesn't raise on sNaNs, hardcodes round to nearest and flushes denormals to zero. By default (unless x86 -fexcess-precision=16) we use float excess precision for BFmode, so truncate only on explicit casts and assignments. The patch introduces a single __bf16 builtin - __builtin_nansf16b, because (__bf16) __builtin_nansf ("") will drop the sNaN into qNaN, and uses f16b suffix instead of bf16 because there would be ambiguity on log vs. logb - __builtin_logbf16 could be either log with bf16 suffix or logb with f16 suffix. In other cases libstdc++ should mostly use __builtin_*f for std::bfloat16_t overloads (we have a problem with std::nextafter though but that one we have also for std::float16_t). 2022-10-14 Jakub Jelinek <jakub@redhat.com> gcc/ * tree-core.h (enum tree_index): Add TI_BFLOAT16_TYPE. * tree.h (bfloat16_type_node): Define. * tree.cc (excess_precision_type): Promote bfloat16_type_mode like float16_type_mode. (build_common_tree_nodes): Initialize bfloat16_type_node if BFmode is supported. * expmed.h (maybe_expand_shift): Declare. * expmed.cc (maybe_expand_shift): No longer static. * expr.cc (convert_mode_scalar): Don't ICE on BF -> HF or HF -> BF conversions. If there is no optab, handle BF -> {DF,XF,TF,HF} conversions as separate BF -> SF -> {DF,XF,TF,HF} conversions, add -ffast-math generic implementation for BF -> SF and SF -> BF conversions. * builtin-types.def (BT_BFLOAT16, BT_FN_BFLOAT16_CONST_STRING): New. * builtins.def (BUILT_IN_NANSF16B): New builtin. * fold-const-call.cc (fold_const_call): Handle CFN_BUILT_IN_NANSF16B. * config/i386/i386.cc (classify_argument): Handle E_BCmode. (ix86_libgcc_floating_mode_supported_p): Also return true for BFmode for -msse2. (ix86_mangle_type): Mangle BFmode as DF16b. (ix86_invalid_conversion, ix86_invalid_unary_op, ix86_invalid_binary_op): Remove. (TARGET_INVALID_CONVERSION, TARGET_INVALID_UNARY_OP, TARGET_INVALID_BINARY_OP): Don't redefine. * config/i386/i386-builtins.cc (ix86_bf16_type_node): Remove. (ix86_register_bf16_builtin_type): Use bfloat16_type_node rather than ix86_bf16_type_node, only create it if still NULL. * config/i386/i386-builtin-types.def (BFLOAT16): Likewise. * config/i386/i386.md (cbranchbf4, cstorebf4): New expanders. gcc/c-family/ * c-cppbuiltin.cc (c_cpp_builtins): If bfloat16_type_node, predefine __BFLT16_*__ macros and for C++23 also __STDCPP_BFLOAT16_T__. Predefine bfloat16_type_node related macros for -fbuilding-libgcc. * c-lex.cc (interpret_float): Handle CPP_N_BFLOAT16. gcc/c/ * c-typeck.cc (convert_arguments): Don't promote __bf16 to double. gcc/cp/ * cp-tree.h (extended_float_type_p): Return true for bfloat16_type_node. * typeck.cc (cp_compare_floating_point_conversion_ranks): Set extended{1,2} if mv{1,2} is bfloat16_type_node. Adjust comment. gcc/testsuite/ * lib/target-supports.exp (check_effective_target_bfloat16, check_effective_target_bfloat16_runtime, add_options_for_bfloat16): New. * gcc.dg/torture/bfloat16-basic.c: New test. * gcc.dg/torture/bfloat16-builtin.c: New test. * gcc.dg/torture/bfloat16-builtin-issignaling-1.c: New test. * gcc.dg/torture/bfloat16-complex.c: New test. * gcc.dg/torture/builtin-issignaling-1.c: Allow to be includable from bfloat16-builtin-issignaling-1.c. * gcc.dg/torture/floatn-basic.h: Allow to be includable from bfloat16-basic.c. * gcc.target/i386/vect-bfloat16-typecheck_2.c: Adjust expected diagnostics. * gcc.target/i386/sse2-bfloat16-scalar-typecheck.c: Likewise. * gcc.target/i386/vect-bfloat16-typecheck_1.c: Likewise. * g++.target/i386/bfloat_cpp_typecheck.C: Likewise. libcpp/ * include/cpplib.h (CPP_N_BFLOAT16): Define. * expr.cc (interpret_float_suffix): Handle bf16 and BF16 suffixes for C++. libgcc/ * config/i386/t-softfp (softfp_extensions): Add bfsf. (softfp_truncations): Add tfbf xfbf dfbf sfbf hfbf. (CFLAGS-extendbfsf2.c, CFLAGS-truncsfbf2.c, CFLAGS-truncdfbf2.c, CFLAGS-truncxfbf2.c, CFLAGS-trunctfbf2.c, CFLAGS-trunchfbf2.c): Add -msse2. * config/i386/libgcc-glibc.ver (GCC_13.0.0): Export __extendbfsf2 and __trunc{s,d,x,t,h}fbf2. * config/i386/sfp-machine.h (_FP_NANSIGN_B): Define. * config/i386/64/sfp-machine.h (_FP_NANFRAC_B): Define. * config/i386/32/sfp-machine.h (_FP_NANFRAC_B): Define. * soft-fp/brain.h: New file. * soft-fp/truncsfbf2.c: New file. * soft-fp/truncdfbf2.c: New file. * soft-fp/truncxfbf2.c: New file. * soft-fp/trunctfbf2.c: New file. * soft-fp/trunchfbf2.c: New file. * soft-fp/truncbfhf2.c: New file. * soft-fp/extendbfsf2.c: New file. libiberty/ * cp-demangle.h (D_BUILTIN_TYPE_COUNT): Increment. * cp-demangle.c (cplus_demangle_builtin_types): Add std::bfloat16_t entry. (cplus_demangle_type): Demangle DF16b. * testsuite/demangle-expected (_Z3xxxDF16b): New test.
2022-10-14 15:37:01 +08:00
f = d = l = w = q = i = fn = fnx = fn_bits = bf16 = 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-20 01:43:26 +08:00
/* The following decimal float suffixes, from TR 24732:2009, TS
c: Refer more consistently to C23 not C2X Continuing the move to refer to C23 in place of C2X throughout the source tree, update documentation, diagnostics, comments, variable and function names, etc., to use the C23 name. Testsuite updates are left for a future patch, except for testcases that test diagnostics that previously mentioned C2X (but in those testcases, sometimes other comments are updated, not just the diagnostic expectations). Bootstrapped with no regressions for x86_64-pc-linux-gnu. gcc/ * builtins.def (DEF_C2X_BUILTIN): Rename to DEF_C23_BUILTIN and use flag_isoc23 and function_c23_misc. * config/rl78/rl78.cc (rl78_option_override): Compare lang_hooks.name with "GNU C23" not "GNU C2X". * coretypes.h (function_c2x_misc): Rename to function_c23_misc. * doc/cpp.texi (@code{__has_attribute}): Refer to C23 instead of C2x. * doc/extend.texi: Likewise. * doc/invoke.texi: Likewise. * dwarf2out.cc (highest_c_language, gen_compile_unit_die): Compare against and return "GNU C23" language string instead of "GNU C2X". * ginclude/float.h: Refer to C23 instead of C2X in comments. * ginclude/stdint-gcc.h: Likewise. * glimits.h: Likewise. * tree.h: Likewise. gcc/ada/ * gcc-interface/utils.cc (flag_isoc2x): Rename to flag_isoc23. gcc/c-family/ * c-common.cc (flag_isoc2x): Rename to flag_isoc23. (c_common_reswords): Use D_C23 instead of D_C2X. * c-common.h: Refer throughout to C23 instead of C2X in comments. (D_C2X): Rename to D_C23. (flag_isoc2x): Rename to flag_isoc23. * c-cppbuiltin.cc (builtin_define_float_constants): Use flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2x in comments. * c-format.cc: Use STD_C23 instead of STD_C2X and flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2X in comments. * c-format.h: Use STD_C23 instead of STD_C2X. * c-lex.cc: Use warn_c11_c23_compat instead of warn_c11_c2x_compat and flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2X in diagnostics. * c-opts.cc: Use flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2X in comments. (set_std_c2x): Rename to set_std_c23. * c.opt (Wc11-c23-compat): Use CPP(cpp_warn_c11_c23_compat) CppReason(CPP_W_C11_C23_COMPAT) Var(warn_c11_c23_compat) instead of CPP(cpp_warn_c11_c2x_compat) CppReason(CPP_W_C11_C2X_COMPAT) Var(warn_c11_c2x_compat). gcc/c/ * c-decl.cc: Use flag_isoc23 instead of flag_isoc2x and c23_auto_p instead of c2x_auto_p. Refer to C23 instead of C2X in diagnostics and comments. * c-errors.cc: Use flag_isoc23 instead of flag_isoc2x and warn_c11_c23_compat instead of warn_c11_c2x_compat. Refer to C23 instead of C2X in comments. * c-parser.cc: Use flag_isoc23 instead of flag_isoc2x, warn_c11_c23_compat instead of warn_c11_c2x_compat, c23_auto_p instead of c2x_auto_p and D_C23 instead of D_C2X. Refer to C23 instead of C2X in diagnostics and comments. * c-tree.h: Refer to C23 instead of C2X in comments. (struct c_declspecs): Rename c2x_auto_p to c23_auto_p. * c-typeck.cc: Use flag_isoc23 instead of flag_isoc2x and warn_c11_c23_compat instead of warn_c11_c2x_compat. Refer to C23 instead of C2X in diagnostics and comments. gcc/fortran/ * gfortran.h (gfc_real_info): Refer to C23 instead of C2X in comment. gcc/lto/ * lto-lang.cc (flag_isoc2x): Rename to flag_isoc23. gcc/testsuite/ * gcc.dg/binary-constants-2.c: Refer to C23 instead of C2X. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/bitint-23.c: Likewise. * gcc.dg/bitint-26.c: Likewise. * gcc.dg/bitint-27.c: Likewise. * gcc.dg/c11-attr-syntax-1.c: Likewise. * gcc.dg/c11-attr-syntax-2.c: Likewise. * gcc.dg/c11-floatn-1.c: Likewise. * gcc.dg/c11-floatn-2.c: Likewise. * gcc.dg/c11-floatn-3.c: Likewise. * gcc.dg/c11-floatn-4.c: Likewise. * gcc.dg/c11-floatn-5.c: Likewise. * gcc.dg/c11-floatn-6.c: Likewise. * gcc.dg/c11-floatn-7.c: Likewise. * gcc.dg/c11-floatn-8.c: Likewise. * gcc.dg/c2x-attr-syntax-4.c: Likewise. * gcc.dg/c2x-attr-syntax-6.c: Likewise. * gcc.dg/c2x-attr-syntax-7.c: Likewise. * gcc.dg/c2x-binary-constants-2.c: Likewise. * gcc.dg/c2x-floatn-5.c: Likewise. * gcc.dg/c2x-floatn-6.c: Likewise. * gcc.dg/c2x-floatn-7.c: Likewise. * gcc.dg/c2x-floatn-8.c: Likewise. * gcc.dg/c2x-nullptr-4.c: Likewise. * gcc.dg/c2x-qual-2.c: Likewise. * gcc.dg/c2x-qual-3.c: Likewise. * gcc.dg/c2x-qual-6.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c2x-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu2x-warning-2.c: Likewise. * gcc.dg/dfp/c11-constants-1.c: Likewise. * gcc.dg/dfp/c11-constants-2.c: Likewise. * gcc.dg/dfp/c2x-constants-2.c: Likewise. * gcc.dg/dfp/constants-pedantic.c: Likewise. * gcc.dg/pr30260.c: Likewise. * gcc.dg/system-binary-constants-1.c: Likewise. libcpp/ * directives.cc: Refer to C23 instead of C2X in diagnostics and comments. (STDC2X): Rename to STDC23. * expr.cc: Use cpp_warn_c11_c23_compat instead of cpp_warn_c11_c2x_compat and CPP_W_C11_C23_COMPAT instead of CPP_W_C11_C2X_COMPAT. Refer to C23 instead of C2X in diagnostics and comments. * include/cpplib.h: Refer to C23 instead of C2X in diagnostics and comments. (CLK_GNUC2X): Rename to CLK_GNUC23. (CLK_STDC2X): Rename to CLK_STDC23. (CPP_W_C11_C2X_COMPAT): Rename to CPP_W_C11_C23_COMPAT. * init.cc: Use GNUC23 instead of GNUC2X, STDC23 instead of STDC2X and cpp_warn_c11_c23_compat instead of cpp_warn_c11_c2x_compat. * lex.cc (maybe_va_opt_error): Refer to C23 instead of C2X in diagnostic. * macro.cc (_cpp_arguments_ok): Refer to C23 instead of C2X in comment.
2023-11-07 22:19:36 +08:00
18661-2:2015 and C23, are supported:
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-20 01:43:26 +08:00
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).
middle-end, c++, i386, libgcc: std::bfloat16_t and __bf16 arithmetic support Here is a complete patch to add std::bfloat16_t support on x86 (AArch64 and ARM left for later). Almost no BFmode optabs are added by the patch, so for binops/unops it extends to SFmode first and then truncates back to BFmode. For {HF,SF,DF,XF,TF}mode -> BFmode conversions libgcc has implementations of all those conversions so that we avoid double rounding, for BFmode -> {DF,XF,TF}mode conversions to avoid growing libgcc too much it emits BFmode -> SFmode conversion first and then converts to the even wider mode, neither step should be imprecise. For BFmode -> HFmode, it first emits a precise BFmode -> SFmode conversion and then SFmode -> HFmode, because neither format is subset or superset of the other, while SFmode is superset of both. expr.cc then contains a -ffast-math optimization of the BF -> SF and SF -> BF conversions if we don't optimize for space (and for the latter if -frounding-math isn't enabled either). For x86, perhaps truncsfbf2 optab could be defined for TARGET_AVX512BF16 but IMNSHO should FAIL if !flag_finite_math || flag_rounding_math || !flag_unsafe_math_optimizations, because I think the insn doesn't raise on sNaNs, hardcodes round to nearest and flushes denormals to zero. By default (unless x86 -fexcess-precision=16) we use float excess precision for BFmode, so truncate only on explicit casts and assignments. The patch introduces a single __bf16 builtin - __builtin_nansf16b, because (__bf16) __builtin_nansf ("") will drop the sNaN into qNaN, and uses f16b suffix instead of bf16 because there would be ambiguity on log vs. logb - __builtin_logbf16 could be either log with bf16 suffix or logb with f16 suffix. In other cases libstdc++ should mostly use __builtin_*f for std::bfloat16_t overloads (we have a problem with std::nextafter though but that one we have also for std::float16_t). 2022-10-14 Jakub Jelinek <jakub@redhat.com> gcc/ * tree-core.h (enum tree_index): Add TI_BFLOAT16_TYPE. * tree.h (bfloat16_type_node): Define. * tree.cc (excess_precision_type): Promote bfloat16_type_mode like float16_type_mode. (build_common_tree_nodes): Initialize bfloat16_type_node if BFmode is supported. * expmed.h (maybe_expand_shift): Declare. * expmed.cc (maybe_expand_shift): No longer static. * expr.cc (convert_mode_scalar): Don't ICE on BF -> HF or HF -> BF conversions. If there is no optab, handle BF -> {DF,XF,TF,HF} conversions as separate BF -> SF -> {DF,XF,TF,HF} conversions, add -ffast-math generic implementation for BF -> SF and SF -> BF conversions. * builtin-types.def (BT_BFLOAT16, BT_FN_BFLOAT16_CONST_STRING): New. * builtins.def (BUILT_IN_NANSF16B): New builtin. * fold-const-call.cc (fold_const_call): Handle CFN_BUILT_IN_NANSF16B. * config/i386/i386.cc (classify_argument): Handle E_BCmode. (ix86_libgcc_floating_mode_supported_p): Also return true for BFmode for -msse2. (ix86_mangle_type): Mangle BFmode as DF16b. (ix86_invalid_conversion, ix86_invalid_unary_op, ix86_invalid_binary_op): Remove. (TARGET_INVALID_CONVERSION, TARGET_INVALID_UNARY_OP, TARGET_INVALID_BINARY_OP): Don't redefine. * config/i386/i386-builtins.cc (ix86_bf16_type_node): Remove. (ix86_register_bf16_builtin_type): Use bfloat16_type_node rather than ix86_bf16_type_node, only create it if still NULL. * config/i386/i386-builtin-types.def (BFLOAT16): Likewise. * config/i386/i386.md (cbranchbf4, cstorebf4): New expanders. gcc/c-family/ * c-cppbuiltin.cc (c_cpp_builtins): If bfloat16_type_node, predefine __BFLT16_*__ macros and for C++23 also __STDCPP_BFLOAT16_T__. Predefine bfloat16_type_node related macros for -fbuilding-libgcc. * c-lex.cc (interpret_float): Handle CPP_N_BFLOAT16. gcc/c/ * c-typeck.cc (convert_arguments): Don't promote __bf16 to double. gcc/cp/ * cp-tree.h (extended_float_type_p): Return true for bfloat16_type_node. * typeck.cc (cp_compare_floating_point_conversion_ranks): Set extended{1,2} if mv{1,2} is bfloat16_type_node. Adjust comment. gcc/testsuite/ * lib/target-supports.exp (check_effective_target_bfloat16, check_effective_target_bfloat16_runtime, add_options_for_bfloat16): New. * gcc.dg/torture/bfloat16-basic.c: New test. * gcc.dg/torture/bfloat16-builtin.c: New test. * gcc.dg/torture/bfloat16-builtin-issignaling-1.c: New test. * gcc.dg/torture/bfloat16-complex.c: New test. * gcc.dg/torture/builtin-issignaling-1.c: Allow to be includable from bfloat16-builtin-issignaling-1.c. * gcc.dg/torture/floatn-basic.h: Allow to be includable from bfloat16-basic.c. * gcc.target/i386/vect-bfloat16-typecheck_2.c: Adjust expected diagnostics. * gcc.target/i386/sse2-bfloat16-scalar-typecheck.c: Likewise. * gcc.target/i386/vect-bfloat16-typecheck_1.c: Likewise. * g++.target/i386/bfloat_cpp_typecheck.C: Likewise. libcpp/ * include/cpplib.h (CPP_N_BFLOAT16): Define. * expr.cc (interpret_float_suffix): Handle bf16 and BF16 suffixes for C++. libgcc/ * config/i386/t-softfp (softfp_extensions): Add bfsf. (softfp_truncations): Add tfbf xfbf dfbf sfbf hfbf. (CFLAGS-extendbfsf2.c, CFLAGS-truncsfbf2.c, CFLAGS-truncdfbf2.c, CFLAGS-truncxfbf2.c, CFLAGS-trunctfbf2.c, CFLAGS-trunchfbf2.c): Add -msse2. * config/i386/libgcc-glibc.ver (GCC_13.0.0): Export __extendbfsf2 and __trunc{s,d,x,t,h}fbf2. * config/i386/sfp-machine.h (_FP_NANSIGN_B): Define. * config/i386/64/sfp-machine.h (_FP_NANFRAC_B): Define. * config/i386/32/sfp-machine.h (_FP_NANFRAC_B): Define. * soft-fp/brain.h: New file. * soft-fp/truncsfbf2.c: New file. * soft-fp/truncdfbf2.c: New file. * soft-fp/truncxfbf2.c: New file. * soft-fp/trunctfbf2.c: New file. * soft-fp/trunchfbf2.c: New file. * soft-fp/truncbfhf2.c: New file. * soft-fp/extendbfsf2.c: New file. libiberty/ * cp-demangle.h (D_BUILTIN_TYPE_COUNT): Increment. * cp-demangle.c (cplus_demangle_builtin_types): Add std::bfloat16_t entry. (cplus_demangle_type): Demangle DF16b. * testsuite/demangle-expected (_Z3xxxDF16b): New test.
2022-10-14 15:37:01 +08:00
fNx, FNx - _FloatNx (TS 18661-3:2015).
bf16, BF16 - std::bfloat16_t (ISO C++23). */
/* 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])
{
Ternary operator formatting fixes While working on PR117028 C2Y changes, I've noticed weird ternary operator formatting (operand1 ? operand2: operand3). The usual formatting is operand1 ? operand2 : operand3 where we have around 18000+ cases of that (counting only what fits on one line) and indent -nbad -bap -nbc -bbo -bl -bli2 -bls -ncdb -nce -cp1 -cs -di2 -ndj \ -nfc1 -nfca -hnl -i2 -ip5 -lp -pcs -psl -nsc -nsob documented in https://www.gnu.org/prep/standards/html_node/Formatting.html#Formatting does the same. Some code was even trying to save space as much as possible and used operand1?operand2:operand3 or operand1 ? operand2:operand3 Today I've grepped for such cases (the grep was '?.*[^ ]:' and I had to skim through various false positives with that where the : matched e.g. stuff inside of strings, or *.md pattern macros or :: scope) and the following patch is a fix for what I found. 2024-10-16 Jakub Jelinek <jakub@redhat.com> gcc/ * attribs.cc (lookup_scoped_attribute_spec): ?: operator formatting fixes. * basic-block.h (FOR_BB_INSNS_SAFE): Likewise. * cfgcleanup.cc (outgoing_edges_match): Likewise. * cgraph.cc (cgraph_node::dump): Likewise. * config/arc/arc.cc (gen_acc1, gen_acc2): Likewise. * config/arc/arc.h (CLASS_MAX_NREGS, CONSTANT_ADDRESS_P): Likewise. * config/arm/arm.cc (arm_print_operand): Likewise. * config/cris/cris.md (*b<rnzcond:code><mode>): Likewise. * config/darwin.cc (darwin_asm_declare_object_name, darwin_emit_common): Likewise. * config/darwin-driver.cc (darwin_driver_init): Likewise. * config/epiphany/epiphany.md (call, sibcall, call_value, sibcall_value): Likewise. * config/i386/i386.cc (gen_push2): Likewise. * config/i386/i386.h (ix86_cur_cost): Likewise. * config/i386/openbsdelf.h (FUNCTION_PROFILER): Likewise. * config/loongarch/loongarch-c.cc (loongarch_cpu_cpp_builtins): Likewise. * config/loongarch/loongarch-cpu.cc (fill_native_cpu_config): Likewise. * config/riscv/riscv.cc (riscv_union_memmodels): Likewise. * config/riscv/zc.md (*mva01s<X:mode>, *mvsa01<X:mode>): Likewise. * config/rs6000/mmintrin.h (_mm_cmpeq_pi8, _mm_cmpgt_pi8, _mm_cmpeq_pi16, _mm_cmpgt_pi16, _mm_cmpeq_pi32, _mm_cmpgt_pi32): Likewise. * config/v850/predicates.md (pattern_is_ok_for_prologue): Likewise. * config/xtensa/constraints.md (d, C, W): Likewise. * coverage.cc (coverage_begin_function, build_init_ctor, build_gcov_exit_decl): Likewise. * df-problems.cc (df_create_unused_note): Likewise. * diagnostic.cc (diagnostic_set_caret_max_width): Likewise. * diagnostic-path.cc (path_summary::path_summary): Likewise. * expr.cc (expand_expr_divmod): Likewise. * gcov.cc (format_gcov): Likewise. * gcov-dump.cc (dump_gcov_file): Likewise. * genmatch.cc (main): Likewise. * incpath.cc (remove_duplicates, register_include_chains): Likewise. * ipa-devirt.cc (dump_odr_type): Likewise. * ipa-icf.cc (sem_item_optimizer::merge_classes): Likewise. * ipa-inline.cc (inline_small_functions): Likewise. * ipa-polymorphic-call.cc (ipa_polymorphic_call_context::dump): Likewise. * ipa-sra.cc (create_parameter_descriptors): Likewise. * ipa-utils.cc (find_always_executed_bbs): Likewise. * predict.cc (predict_loops): Likewise. * selftest.cc (read_file): Likewise. * sreal.h (SREAL_SIGN, SREAL_ABS): Likewise. * tree-dump.cc (dequeue_and_dump): Likewise. * tree-ssa-ccp.cc (bit_value_binop): Likewise. gcc/c-family/ * c-opts.cc (c_common_init_options, c_common_handle_option, c_common_finish, set_std_c89, set_std_c99, set_std_c11, set_std_c17, set_std_c23, set_std_cxx98, set_std_cxx11, set_std_cxx14, set_std_cxx17, set_std_cxx20, set_std_cxx23, set_std_cxx26): ?: operator formatting fixes. gcc/cp/ * search.cc (lookup_member): ?: operator formatting fixes. * typeck.cc (cp_build_modify_expr): Likewise. libcpp/ * expr.cc (interpret_float_suffix): ?: operator formatting fixes.
2024-10-16 20:44:32 +08:00
case 'f': return (!uppercase ? (CPP_N_DFLOAT | CPP_N_SMALL) : 0); break;
case 'F': return (uppercase ? (CPP_N_DFLOAT | CPP_N_SMALL) : 0); break;
Ternary operator formatting fixes While working on PR117028 C2Y changes, I've noticed weird ternary operator formatting (operand1 ? operand2: operand3). The usual formatting is operand1 ? operand2 : operand3 where we have around 18000+ cases of that (counting only what fits on one line) and indent -nbad -bap -nbc -bbo -bl -bli2 -bls -ncdb -nce -cp1 -cs -di2 -ndj \ -nfc1 -nfca -hnl -i2 -ip5 -lp -pcs -psl -nsc -nsob documented in https://www.gnu.org/prep/standards/html_node/Formatting.html#Formatting does the same. Some code was even trying to save space as much as possible and used operand1?operand2:operand3 or operand1 ? operand2:operand3 Today I've grepped for such cases (the grep was '?.*[^ ]:' and I had to skim through various false positives with that where the : matched e.g. stuff inside of strings, or *.md pattern macros or :: scope) and the following patch is a fix for what I found. 2024-10-16 Jakub Jelinek <jakub@redhat.com> gcc/ * attribs.cc (lookup_scoped_attribute_spec): ?: operator formatting fixes. * basic-block.h (FOR_BB_INSNS_SAFE): Likewise. * cfgcleanup.cc (outgoing_edges_match): Likewise. * cgraph.cc (cgraph_node::dump): Likewise. * config/arc/arc.cc (gen_acc1, gen_acc2): Likewise. * config/arc/arc.h (CLASS_MAX_NREGS, CONSTANT_ADDRESS_P): Likewise. * config/arm/arm.cc (arm_print_operand): Likewise. * config/cris/cris.md (*b<rnzcond:code><mode>): Likewise. * config/darwin.cc (darwin_asm_declare_object_name, darwin_emit_common): Likewise. * config/darwin-driver.cc (darwin_driver_init): Likewise. * config/epiphany/epiphany.md (call, sibcall, call_value, sibcall_value): Likewise. * config/i386/i386.cc (gen_push2): Likewise. * config/i386/i386.h (ix86_cur_cost): Likewise. * config/i386/openbsdelf.h (FUNCTION_PROFILER): Likewise. * config/loongarch/loongarch-c.cc (loongarch_cpu_cpp_builtins): Likewise. * config/loongarch/loongarch-cpu.cc (fill_native_cpu_config): Likewise. * config/riscv/riscv.cc (riscv_union_memmodels): Likewise. * config/riscv/zc.md (*mva01s<X:mode>, *mvsa01<X:mode>): Likewise. * config/rs6000/mmintrin.h (_mm_cmpeq_pi8, _mm_cmpgt_pi8, _mm_cmpeq_pi16, _mm_cmpgt_pi16, _mm_cmpeq_pi32, _mm_cmpgt_pi32): Likewise. * config/v850/predicates.md (pattern_is_ok_for_prologue): Likewise. * config/xtensa/constraints.md (d, C, W): Likewise. * coverage.cc (coverage_begin_function, build_init_ctor, build_gcov_exit_decl): Likewise. * df-problems.cc (df_create_unused_note): Likewise. * diagnostic.cc (diagnostic_set_caret_max_width): Likewise. * diagnostic-path.cc (path_summary::path_summary): Likewise. * expr.cc (expand_expr_divmod): Likewise. * gcov.cc (format_gcov): Likewise. * gcov-dump.cc (dump_gcov_file): Likewise. * genmatch.cc (main): Likewise. * incpath.cc (remove_duplicates, register_include_chains): Likewise. * ipa-devirt.cc (dump_odr_type): Likewise. * ipa-icf.cc (sem_item_optimizer::merge_classes): Likewise. * ipa-inline.cc (inline_small_functions): Likewise. * ipa-polymorphic-call.cc (ipa_polymorphic_call_context::dump): Likewise. * ipa-sra.cc (create_parameter_descriptors): Likewise. * ipa-utils.cc (find_always_executed_bbs): Likewise. * predict.cc (predict_loops): Likewise. * selftest.cc (read_file): Likewise. * sreal.h (SREAL_SIGN, SREAL_ABS): Likewise. * tree-dump.cc (dequeue_and_dump): Likewise. * tree-ssa-ccp.cc (bit_value_binop): Likewise. gcc/c-family/ * c-opts.cc (c_common_init_options, c_common_handle_option, c_common_finish, set_std_c89, set_std_c99, set_std_c11, set_std_c17, set_std_c23, set_std_cxx98, set_std_cxx11, set_std_cxx14, set_std_cxx17, set_std_cxx20, set_std_cxx23, set_std_cxx26): ?: operator formatting fixes. gcc/cp/ * search.cc (lookup_member): ?: operator formatting fixes. * typeck.cc (cp_build_modify_expr): Likewise. libcpp/ * expr.cc (interpret_float_suffix): ?: operator formatting fixes.
2024-10-16 20:44:32 +08:00
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-20 01:43:26 +08:00
{
switch (s[0])
{
case 'f': case 'F':
f++;
if (len > 0
&& 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;
middle-end, c++, i386, libgcc: std::bfloat16_t and __bf16 arithmetic support Here is a complete patch to add std::bfloat16_t support on x86 (AArch64 and ARM left for later). Almost no BFmode optabs are added by the patch, so for binops/unops it extends to SFmode first and then truncates back to BFmode. For {HF,SF,DF,XF,TF}mode -> BFmode conversions libgcc has implementations of all those conversions so that we avoid double rounding, for BFmode -> {DF,XF,TF}mode conversions to avoid growing libgcc too much it emits BFmode -> SFmode conversion first and then converts to the even wider mode, neither step should be imprecise. For BFmode -> HFmode, it first emits a precise BFmode -> SFmode conversion and then SFmode -> HFmode, because neither format is subset or superset of the other, while SFmode is superset of both. expr.cc then contains a -ffast-math optimization of the BF -> SF and SF -> BF conversions if we don't optimize for space (and for the latter if -frounding-math isn't enabled either). For x86, perhaps truncsfbf2 optab could be defined for TARGET_AVX512BF16 but IMNSHO should FAIL if !flag_finite_math || flag_rounding_math || !flag_unsafe_math_optimizations, because I think the insn doesn't raise on sNaNs, hardcodes round to nearest and flushes denormals to zero. By default (unless x86 -fexcess-precision=16) we use float excess precision for BFmode, so truncate only on explicit casts and assignments. The patch introduces a single __bf16 builtin - __builtin_nansf16b, because (__bf16) __builtin_nansf ("") will drop the sNaN into qNaN, and uses f16b suffix instead of bf16 because there would be ambiguity on log vs. logb - __builtin_logbf16 could be either log with bf16 suffix or logb with f16 suffix. In other cases libstdc++ should mostly use __builtin_*f for std::bfloat16_t overloads (we have a problem with std::nextafter though but that one we have also for std::float16_t). 2022-10-14 Jakub Jelinek <jakub@redhat.com> gcc/ * tree-core.h (enum tree_index): Add TI_BFLOAT16_TYPE. * tree.h (bfloat16_type_node): Define. * tree.cc (excess_precision_type): Promote bfloat16_type_mode like float16_type_mode. (build_common_tree_nodes): Initialize bfloat16_type_node if BFmode is supported. * expmed.h (maybe_expand_shift): Declare. * expmed.cc (maybe_expand_shift): No longer static. * expr.cc (convert_mode_scalar): Don't ICE on BF -> HF or HF -> BF conversions. If there is no optab, handle BF -> {DF,XF,TF,HF} conversions as separate BF -> SF -> {DF,XF,TF,HF} conversions, add -ffast-math generic implementation for BF -> SF and SF -> BF conversions. * builtin-types.def (BT_BFLOAT16, BT_FN_BFLOAT16_CONST_STRING): New. * builtins.def (BUILT_IN_NANSF16B): New builtin. * fold-const-call.cc (fold_const_call): Handle CFN_BUILT_IN_NANSF16B. * config/i386/i386.cc (classify_argument): Handle E_BCmode. (ix86_libgcc_floating_mode_supported_p): Also return true for BFmode for -msse2. (ix86_mangle_type): Mangle BFmode as DF16b. (ix86_invalid_conversion, ix86_invalid_unary_op, ix86_invalid_binary_op): Remove. (TARGET_INVALID_CONVERSION, TARGET_INVALID_UNARY_OP, TARGET_INVALID_BINARY_OP): Don't redefine. * config/i386/i386-builtins.cc (ix86_bf16_type_node): Remove. (ix86_register_bf16_builtin_type): Use bfloat16_type_node rather than ix86_bf16_type_node, only create it if still NULL. * config/i386/i386-builtin-types.def (BFLOAT16): Likewise. * config/i386/i386.md (cbranchbf4, cstorebf4): New expanders. gcc/c-family/ * c-cppbuiltin.cc (c_cpp_builtins): If bfloat16_type_node, predefine __BFLT16_*__ macros and for C++23 also __STDCPP_BFLOAT16_T__. Predefine bfloat16_type_node related macros for -fbuilding-libgcc. * c-lex.cc (interpret_float): Handle CPP_N_BFLOAT16. gcc/c/ * c-typeck.cc (convert_arguments): Don't promote __bf16 to double. gcc/cp/ * cp-tree.h (extended_float_type_p): Return true for bfloat16_type_node. * typeck.cc (cp_compare_floating_point_conversion_ranks): Set extended{1,2} if mv{1,2} is bfloat16_type_node. Adjust comment. gcc/testsuite/ * lib/target-supports.exp (check_effective_target_bfloat16, check_effective_target_bfloat16_runtime, add_options_for_bfloat16): New. * gcc.dg/torture/bfloat16-basic.c: New test. * gcc.dg/torture/bfloat16-builtin.c: New test. * gcc.dg/torture/bfloat16-builtin-issignaling-1.c: New test. * gcc.dg/torture/bfloat16-complex.c: New test. * gcc.dg/torture/builtin-issignaling-1.c: Allow to be includable from bfloat16-builtin-issignaling-1.c. * gcc.dg/torture/floatn-basic.h: Allow to be includable from bfloat16-basic.c. * gcc.target/i386/vect-bfloat16-typecheck_2.c: Adjust expected diagnostics. * gcc.target/i386/sse2-bfloat16-scalar-typecheck.c: Likewise. * gcc.target/i386/vect-bfloat16-typecheck_1.c: Likewise. * g++.target/i386/bfloat_cpp_typecheck.C: Likewise. libcpp/ * include/cpplib.h (CPP_N_BFLOAT16): Define. * expr.cc (interpret_float_suffix): Handle bf16 and BF16 suffixes for C++. libgcc/ * config/i386/t-softfp (softfp_extensions): Add bfsf. (softfp_truncations): Add tfbf xfbf dfbf sfbf hfbf. (CFLAGS-extendbfsf2.c, CFLAGS-truncsfbf2.c, CFLAGS-truncdfbf2.c, CFLAGS-truncxfbf2.c, CFLAGS-trunctfbf2.c, CFLAGS-trunchfbf2.c): Add -msse2. * config/i386/libgcc-glibc.ver (GCC_13.0.0): Export __extendbfsf2 and __trunc{s,d,x,t,h}fbf2. * config/i386/sfp-machine.h (_FP_NANSIGN_B): Define. * config/i386/64/sfp-machine.h (_FP_NANFRAC_B): Define. * config/i386/32/sfp-machine.h (_FP_NANFRAC_B): Define. * soft-fp/brain.h: New file. * soft-fp/truncsfbf2.c: New file. * soft-fp/truncdfbf2.c: New file. * soft-fp/truncxfbf2.c: New file. * soft-fp/trunctfbf2.c: New file. * soft-fp/trunchfbf2.c: New file. * soft-fp/truncbfhf2.c: New file. * soft-fp/extendbfsf2.c: New file. libiberty/ * cp-demangle.h (D_BUILTIN_TYPE_COUNT): Increment. * cp-demangle.c (cplus_demangle_builtin_types): Add std::bfloat16_t entry. (cplus_demangle_type): Demangle DF16b. * testsuite/demangle-expected (_Z3xxxDF16b): New test.
2022-10-14 15:37:01 +08:00
case 'b': case 'B':
if (len > 2
/* Except for bf16 / BF16 where case is significant. */
&& s[1] == (s[0] == 'b' ? 'f' : 'F')
&& s[2] == '1'
&& s[3] == '6')
{
bf16++;
len -= 3;
s += 3;
break;
}
return 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-20 01:43:26 +08:00
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-17 05:59:07 +08: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-20 01:43:26 +08: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. */
middle-end, c++, i386, libgcc: std::bfloat16_t and __bf16 arithmetic support Here is a complete patch to add std::bfloat16_t support on x86 (AArch64 and ARM left for later). Almost no BFmode optabs are added by the patch, so for binops/unops it extends to SFmode first and then truncates back to BFmode. For {HF,SF,DF,XF,TF}mode -> BFmode conversions libgcc has implementations of all those conversions so that we avoid double rounding, for BFmode -> {DF,XF,TF}mode conversions to avoid growing libgcc too much it emits BFmode -> SFmode conversion first and then converts to the even wider mode, neither step should be imprecise. For BFmode -> HFmode, it first emits a precise BFmode -> SFmode conversion and then SFmode -> HFmode, because neither format is subset or superset of the other, while SFmode is superset of both. expr.cc then contains a -ffast-math optimization of the BF -> SF and SF -> BF conversions if we don't optimize for space (and for the latter if -frounding-math isn't enabled either). For x86, perhaps truncsfbf2 optab could be defined for TARGET_AVX512BF16 but IMNSHO should FAIL if !flag_finite_math || flag_rounding_math || !flag_unsafe_math_optimizations, because I think the insn doesn't raise on sNaNs, hardcodes round to nearest and flushes denormals to zero. By default (unless x86 -fexcess-precision=16) we use float excess precision for BFmode, so truncate only on explicit casts and assignments. The patch introduces a single __bf16 builtin - __builtin_nansf16b, because (__bf16) __builtin_nansf ("") will drop the sNaN into qNaN, and uses f16b suffix instead of bf16 because there would be ambiguity on log vs. logb - __builtin_logbf16 could be either log with bf16 suffix or logb with f16 suffix. In other cases libstdc++ should mostly use __builtin_*f for std::bfloat16_t overloads (we have a problem with std::nextafter though but that one we have also for std::float16_t). 2022-10-14 Jakub Jelinek <jakub@redhat.com> gcc/ * tree-core.h (enum tree_index): Add TI_BFLOAT16_TYPE. * tree.h (bfloat16_type_node): Define. * tree.cc (excess_precision_type): Promote bfloat16_type_mode like float16_type_mode. (build_common_tree_nodes): Initialize bfloat16_type_node if BFmode is supported. * expmed.h (maybe_expand_shift): Declare. * expmed.cc (maybe_expand_shift): No longer static. * expr.cc (convert_mode_scalar): Don't ICE on BF -> HF or HF -> BF conversions. If there is no optab, handle BF -> {DF,XF,TF,HF} conversions as separate BF -> SF -> {DF,XF,TF,HF} conversions, add -ffast-math generic implementation for BF -> SF and SF -> BF conversions. * builtin-types.def (BT_BFLOAT16, BT_FN_BFLOAT16_CONST_STRING): New. * builtins.def (BUILT_IN_NANSF16B): New builtin. * fold-const-call.cc (fold_const_call): Handle CFN_BUILT_IN_NANSF16B. * config/i386/i386.cc (classify_argument): Handle E_BCmode. (ix86_libgcc_floating_mode_supported_p): Also return true for BFmode for -msse2. (ix86_mangle_type): Mangle BFmode as DF16b. (ix86_invalid_conversion, ix86_invalid_unary_op, ix86_invalid_binary_op): Remove. (TARGET_INVALID_CONVERSION, TARGET_INVALID_UNARY_OP, TARGET_INVALID_BINARY_OP): Don't redefine. * config/i386/i386-builtins.cc (ix86_bf16_type_node): Remove. (ix86_register_bf16_builtin_type): Use bfloat16_type_node rather than ix86_bf16_type_node, only create it if still NULL. * config/i386/i386-builtin-types.def (BFLOAT16): Likewise. * config/i386/i386.md (cbranchbf4, cstorebf4): New expanders. gcc/c-family/ * c-cppbuiltin.cc (c_cpp_builtins): If bfloat16_type_node, predefine __BFLT16_*__ macros and for C++23 also __STDCPP_BFLOAT16_T__. Predefine bfloat16_type_node related macros for -fbuilding-libgcc. * c-lex.cc (interpret_float): Handle CPP_N_BFLOAT16. gcc/c/ * c-typeck.cc (convert_arguments): Don't promote __bf16 to double. gcc/cp/ * cp-tree.h (extended_float_type_p): Return true for bfloat16_type_node. * typeck.cc (cp_compare_floating_point_conversion_ranks): Set extended{1,2} if mv{1,2} is bfloat16_type_node. Adjust comment. gcc/testsuite/ * lib/target-supports.exp (check_effective_target_bfloat16, check_effective_target_bfloat16_runtime, add_options_for_bfloat16): New. * gcc.dg/torture/bfloat16-basic.c: New test. * gcc.dg/torture/bfloat16-builtin.c: New test. * gcc.dg/torture/bfloat16-builtin-issignaling-1.c: New test. * gcc.dg/torture/bfloat16-complex.c: New test. * gcc.dg/torture/builtin-issignaling-1.c: Allow to be includable from bfloat16-builtin-issignaling-1.c. * gcc.dg/torture/floatn-basic.h: Allow to be includable from bfloat16-basic.c. * gcc.target/i386/vect-bfloat16-typecheck_2.c: Adjust expected diagnostics. * gcc.target/i386/sse2-bfloat16-scalar-typecheck.c: Likewise. * gcc.target/i386/vect-bfloat16-typecheck_1.c: Likewise. * g++.target/i386/bfloat_cpp_typecheck.C: Likewise. libcpp/ * include/cpplib.h (CPP_N_BFLOAT16): Define. * expr.cc (interpret_float_suffix): Handle bf16 and BF16 suffixes for C++. libgcc/ * config/i386/t-softfp (softfp_extensions): Add bfsf. (softfp_truncations): Add tfbf xfbf dfbf sfbf hfbf. (CFLAGS-extendbfsf2.c, CFLAGS-truncsfbf2.c, CFLAGS-truncdfbf2.c, CFLAGS-truncxfbf2.c, CFLAGS-trunctfbf2.c, CFLAGS-trunchfbf2.c): Add -msse2. * config/i386/libgcc-glibc.ver (GCC_13.0.0): Export __extendbfsf2 and __trunc{s,d,x,t,h}fbf2. * config/i386/sfp-machine.h (_FP_NANSIGN_B): Define. * config/i386/64/sfp-machine.h (_FP_NANFRAC_B): Define. * config/i386/32/sfp-machine.h (_FP_NANFRAC_B): Define. * soft-fp/brain.h: New file. * soft-fp/truncsfbf2.c: New file. * soft-fp/truncdfbf2.c: New file. * soft-fp/truncxfbf2.c: New file. * soft-fp/trunctfbf2.c: New file. * soft-fp/trunchfbf2.c: New file. * soft-fp/truncbfhf2.c: New file. * soft-fp/extendbfsf2.c: New file. libiberty/ * cp-demangle.h (D_BUILTIN_TYPE_COUNT): Increment. * cp-demangle.c (cplus_demangle_builtin_types): Add std::bfloat16_t entry. (cplus_demangle_type): Demangle DF16b. * testsuite/demangle-expected (_Z3xxxDF16b): New test.
2022-10-14 15:37:01 +08:00
if (f + d + l + w + q + fn + fnx + bf16 > 1 || i > 1)
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-20 01:43:26 +08:00
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)
{
if (!CPP_OPTION (pfile, ext_numeric_literals))
return 0;
/* In C++14 and up these suffixes are in the standard library, so treat
them as user-defined literals. */
if (CPP_OPTION (pfile, cplusplus)
&& CPP_OPTION (pfile, lang) > CLK_CXX11
&& orig_s[0] == 'i'
&& (orig_len == 1
|| (orig_len == 2
&& (orig_s[1] == 'f' || orig_s[1] == 'l'))))
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-20 01:43:26 +08:00
q ? CPP_N_MD_Q :
fn ? CPP_N_FLOATN | (fn_bits << CPP_FLOATN_SHIFT) :
fnx ? CPP_N_FLOATNX | (fn_bits << CPP_FLOATN_SHIFT) :
middle-end, c++, i386, libgcc: std::bfloat16_t and __bf16 arithmetic support Here is a complete patch to add std::bfloat16_t support on x86 (AArch64 and ARM left for later). Almost no BFmode optabs are added by the patch, so for binops/unops it extends to SFmode first and then truncates back to BFmode. For {HF,SF,DF,XF,TF}mode -> BFmode conversions libgcc has implementations of all those conversions so that we avoid double rounding, for BFmode -> {DF,XF,TF}mode conversions to avoid growing libgcc too much it emits BFmode -> SFmode conversion first and then converts to the even wider mode, neither step should be imprecise. For BFmode -> HFmode, it first emits a precise BFmode -> SFmode conversion and then SFmode -> HFmode, because neither format is subset or superset of the other, while SFmode is superset of both. expr.cc then contains a -ffast-math optimization of the BF -> SF and SF -> BF conversions if we don't optimize for space (and for the latter if -frounding-math isn't enabled either). For x86, perhaps truncsfbf2 optab could be defined for TARGET_AVX512BF16 but IMNSHO should FAIL if !flag_finite_math || flag_rounding_math || !flag_unsafe_math_optimizations, because I think the insn doesn't raise on sNaNs, hardcodes round to nearest and flushes denormals to zero. By default (unless x86 -fexcess-precision=16) we use float excess precision for BFmode, so truncate only on explicit casts and assignments. The patch introduces a single __bf16 builtin - __builtin_nansf16b, because (__bf16) __builtin_nansf ("") will drop the sNaN into qNaN, and uses f16b suffix instead of bf16 because there would be ambiguity on log vs. logb - __builtin_logbf16 could be either log with bf16 suffix or logb with f16 suffix. In other cases libstdc++ should mostly use __builtin_*f for std::bfloat16_t overloads (we have a problem with std::nextafter though but that one we have also for std::float16_t). 2022-10-14 Jakub Jelinek <jakub@redhat.com> gcc/ * tree-core.h (enum tree_index): Add TI_BFLOAT16_TYPE. * tree.h (bfloat16_type_node): Define. * tree.cc (excess_precision_type): Promote bfloat16_type_mode like float16_type_mode. (build_common_tree_nodes): Initialize bfloat16_type_node if BFmode is supported. * expmed.h (maybe_expand_shift): Declare. * expmed.cc (maybe_expand_shift): No longer static. * expr.cc (convert_mode_scalar): Don't ICE on BF -> HF or HF -> BF conversions. If there is no optab, handle BF -> {DF,XF,TF,HF} conversions as separate BF -> SF -> {DF,XF,TF,HF} conversions, add -ffast-math generic implementation for BF -> SF and SF -> BF conversions. * builtin-types.def (BT_BFLOAT16, BT_FN_BFLOAT16_CONST_STRING): New. * builtins.def (BUILT_IN_NANSF16B): New builtin. * fold-const-call.cc (fold_const_call): Handle CFN_BUILT_IN_NANSF16B. * config/i386/i386.cc (classify_argument): Handle E_BCmode. (ix86_libgcc_floating_mode_supported_p): Also return true for BFmode for -msse2. (ix86_mangle_type): Mangle BFmode as DF16b. (ix86_invalid_conversion, ix86_invalid_unary_op, ix86_invalid_binary_op): Remove. (TARGET_INVALID_CONVERSION, TARGET_INVALID_UNARY_OP, TARGET_INVALID_BINARY_OP): Don't redefine. * config/i386/i386-builtins.cc (ix86_bf16_type_node): Remove. (ix86_register_bf16_builtin_type): Use bfloat16_type_node rather than ix86_bf16_type_node, only create it if still NULL. * config/i386/i386-builtin-types.def (BFLOAT16): Likewise. * config/i386/i386.md (cbranchbf4, cstorebf4): New expanders. gcc/c-family/ * c-cppbuiltin.cc (c_cpp_builtins): If bfloat16_type_node, predefine __BFLT16_*__ macros and for C++23 also __STDCPP_BFLOAT16_T__. Predefine bfloat16_type_node related macros for -fbuilding-libgcc. * c-lex.cc (interpret_float): Handle CPP_N_BFLOAT16. gcc/c/ * c-typeck.cc (convert_arguments): Don't promote __bf16 to double. gcc/cp/ * cp-tree.h (extended_float_type_p): Return true for bfloat16_type_node. * typeck.cc (cp_compare_floating_point_conversion_ranks): Set extended{1,2} if mv{1,2} is bfloat16_type_node. Adjust comment. gcc/testsuite/ * lib/target-supports.exp (check_effective_target_bfloat16, check_effective_target_bfloat16_runtime, add_options_for_bfloat16): New. * gcc.dg/torture/bfloat16-basic.c: New test. * gcc.dg/torture/bfloat16-builtin.c: New test. * gcc.dg/torture/bfloat16-builtin-issignaling-1.c: New test. * gcc.dg/torture/bfloat16-complex.c: New test. * gcc.dg/torture/builtin-issignaling-1.c: Allow to be includable from bfloat16-builtin-issignaling-1.c. * gcc.dg/torture/floatn-basic.h: Allow to be includable from bfloat16-basic.c. * gcc.target/i386/vect-bfloat16-typecheck_2.c: Adjust expected diagnostics. * gcc.target/i386/sse2-bfloat16-scalar-typecheck.c: Likewise. * gcc.target/i386/vect-bfloat16-typecheck_1.c: Likewise. * g++.target/i386/bfloat_cpp_typecheck.C: Likewise. libcpp/ * include/cpplib.h (CPP_N_BFLOAT16): Define. * expr.cc (interpret_float_suffix): Handle bf16 and BF16 suffixes for C++. libgcc/ * config/i386/t-softfp (softfp_extensions): Add bfsf. (softfp_truncations): Add tfbf xfbf dfbf sfbf hfbf. (CFLAGS-extendbfsf2.c, CFLAGS-truncsfbf2.c, CFLAGS-truncdfbf2.c, CFLAGS-truncxfbf2.c, CFLAGS-trunctfbf2.c, CFLAGS-trunchfbf2.c): Add -msse2. * config/i386/libgcc-glibc.ver (GCC_13.0.0): Export __extendbfsf2 and __trunc{s,d,x,t,h}fbf2. * config/i386/sfp-machine.h (_FP_NANSIGN_B): Define. * config/i386/64/sfp-machine.h (_FP_NANFRAC_B): Define. * config/i386/32/sfp-machine.h (_FP_NANFRAC_B): Define. * soft-fp/brain.h: New file. * soft-fp/truncsfbf2.c: New file. * soft-fp/truncdfbf2.c: New file. * soft-fp/truncxfbf2.c: New file. * soft-fp/trunctfbf2.c: New file. * soft-fp/trunchfbf2.c: New file. * soft-fp/truncbfhf2.c: New file. * soft-fp/extendbfsf2.c: New file. libiberty/ * cp-demangle.h (D_BUILTIN_TYPE_COUNT): Increment. * cp-demangle.c (cplus_demangle_builtin_types): Add std::bfloat16_t entry. (cplus_demangle_type): Demangle DF16b. * testsuite/demangle-expected (_Z3xxxDF16b): New test.
2022-10-14 15:37:01 +08:00
bf16 ? CPP_N_BFLOAT16 :
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-20 01:43:26 +08:00
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-27 03:30:59 +08: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-27 03:30:59 +08: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-27 03:30:59 +08: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 orig_len = len;
C _BitInt support [PR102989] This patch adds the C FE support, c-family support, small libcpp change so that 123wb and 42uwb suffixes are handled plus glimits.h change to define BITINT_MAXWIDTH macro. The previous patches really do nothing without this, which enables all the support. 2023-09-06 Jakub Jelinek <jakub@redhat.com> PR c/102989 gcc/ * glimits.h (BITINT_MAXWIDTH): Define if __BITINT_MAXWIDTH__ is predefined. gcc/c-family/ * c-common.cc (c_common_reswords): Add _BitInt as keyword. (unsafe_conversion_p): Handle BITINT_TYPE like INTEGER_TYPE. (c_common_signed_or_unsigned_type): Handle BITINT_TYPE. (c_common_truthvalue_conversion, c_common_get_alias_set, check_builtin_function_arguments): Handle BITINT_TYPE like INTEGER_TYPE. (sync_resolve_size): Add ORIG_FORMAT argument. If FETCH && !ORIG_FORMAT, type is BITINT_TYPE, return -1 if size isn't one of 1, 2, 4, 8 or 16 or if it is 16 but TImode is not supported. (atomic_bitint_fetch_using_cas_loop): New function. (resolve_overloaded_builtin): Adjust sync_resolve_size caller. If -1 is returned, use atomic_bitint_fetch_using_cas_loop to lower it. Formatting fix. (keyword_begins_type_specifier): Handle RID_BITINT. * c-common.h (enum rid): Add RID_BITINT enumerator. * c-cppbuiltin.cc (c_cpp_builtins): For C call targetm.c.bitint_type_info and predefine __BITINT_MAXWIDTH__ and for -fbuilding-libgcc also __LIBGCC_BITINT_LIMB_WIDTH__ and __LIBGCC_BITINT_ORDER__ macros if _BitInt is supported. * c-lex.cc (interpret_integer): Handle CPP_N_BITINT. * c-pretty-print.cc (c_pretty_printer::simple_type_specifier, c_pretty_printer::direct_abstract_declarator, c_pretty_printer::direct_declarator, c_pretty_printer::declarator): Handle BITINT_TYPE. (pp_c_integer_constant): Handle printing of large precision wide_ints which would buffer overflow digit_buffer. * c-warn.cc (conversion_warning, warnings_for_convert_and_check, warnings_for_convert_and_check): Handle BITINT_TYPE like INTEGER_TYPE. gcc/c/ * c-convert.cc (c_convert): Handle BITINT_TYPE like INTEGER_TYPE. * c-decl.cc (check_bitfield_type_and_width): Allow BITINT_TYPE bit-fields. (finish_struct): Prefer to use BITINT_TYPE for BITINT_TYPE bit-fields if possible. (declspecs_add_type): Formatting fixes. Handle cts_bitint. Adjust for added union in *specs. Handle RID_BITINT. (finish_declspecs): Handle cts_bitint. Adjust for added union in *specs. * c-parser.cc (c_keyword_starts_typename, c_token_starts_declspecs, c_parser_declspecs, c_parser_gnu_attribute_any_word): Handle RID_BITINT. (c_parser_omp_clause_schedule): Handle BITINT_TYPE like INTEGER_TYPE. * c-tree.h (enum c_typespec_keyword): Mention _BitInt in comment. Add cts_bitint enumerator. (struct c_declspecs): Move int_n_idx and floatn_nx_idx into a union and add bitint_prec there as well. * c-typeck.cc (c_common_type, comptypes_internal): Handle BITINT_TYPE. (perform_integral_promotions): Promote BITINT_TYPE bit-fields to their declared type. (build_array_ref, build_unary_op, build_conditional_expr, build_c_cast, convert_for_assignment, digest_init, build_binary_op): Handle BITINT_TYPE. * c-fold.cc (c_fully_fold_internal): Handle BITINT_TYPE like INTEGER_TYPE. * c-aux-info.cc (gen_type): Handle BITINT_TYPE. libcpp/ * expr.cc (interpret_int_suffix): Handle wb and WB suffixes. * include/cpplib.h (CPP_N_BITINT): Define.
2023-09-06 23:34:49 +08:00
size_t u, l, i, z, wb;
C _BitInt support [PR102989] This patch adds the C FE support, c-family support, small libcpp change so that 123wb and 42uwb suffixes are handled plus glimits.h change to define BITINT_MAXWIDTH macro. The previous patches really do nothing without this, which enables all the support. 2023-09-06 Jakub Jelinek <jakub@redhat.com> PR c/102989 gcc/ * glimits.h (BITINT_MAXWIDTH): Define if __BITINT_MAXWIDTH__ is predefined. gcc/c-family/ * c-common.cc (c_common_reswords): Add _BitInt as keyword. (unsafe_conversion_p): Handle BITINT_TYPE like INTEGER_TYPE. (c_common_signed_or_unsigned_type): Handle BITINT_TYPE. (c_common_truthvalue_conversion, c_common_get_alias_set, check_builtin_function_arguments): Handle BITINT_TYPE like INTEGER_TYPE. (sync_resolve_size): Add ORIG_FORMAT argument. If FETCH && !ORIG_FORMAT, type is BITINT_TYPE, return -1 if size isn't one of 1, 2, 4, 8 or 16 or if it is 16 but TImode is not supported. (atomic_bitint_fetch_using_cas_loop): New function. (resolve_overloaded_builtin): Adjust sync_resolve_size caller. If -1 is returned, use atomic_bitint_fetch_using_cas_loop to lower it. Formatting fix. (keyword_begins_type_specifier): Handle RID_BITINT. * c-common.h (enum rid): Add RID_BITINT enumerator. * c-cppbuiltin.cc (c_cpp_builtins): For C call targetm.c.bitint_type_info and predefine __BITINT_MAXWIDTH__ and for -fbuilding-libgcc also __LIBGCC_BITINT_LIMB_WIDTH__ and __LIBGCC_BITINT_ORDER__ macros if _BitInt is supported. * c-lex.cc (interpret_integer): Handle CPP_N_BITINT. * c-pretty-print.cc (c_pretty_printer::simple_type_specifier, c_pretty_printer::direct_abstract_declarator, c_pretty_printer::direct_declarator, c_pretty_printer::declarator): Handle BITINT_TYPE. (pp_c_integer_constant): Handle printing of large precision wide_ints which would buffer overflow digit_buffer. * c-warn.cc (conversion_warning, warnings_for_convert_and_check, warnings_for_convert_and_check): Handle BITINT_TYPE like INTEGER_TYPE. gcc/c/ * c-convert.cc (c_convert): Handle BITINT_TYPE like INTEGER_TYPE. * c-decl.cc (check_bitfield_type_and_width): Allow BITINT_TYPE bit-fields. (finish_struct): Prefer to use BITINT_TYPE for BITINT_TYPE bit-fields if possible. (declspecs_add_type): Formatting fixes. Handle cts_bitint. Adjust for added union in *specs. Handle RID_BITINT. (finish_declspecs): Handle cts_bitint. Adjust for added union in *specs. * c-parser.cc (c_keyword_starts_typename, c_token_starts_declspecs, c_parser_declspecs, c_parser_gnu_attribute_any_word): Handle RID_BITINT. (c_parser_omp_clause_schedule): Handle BITINT_TYPE like INTEGER_TYPE. * c-tree.h (enum c_typespec_keyword): Mention _BitInt in comment. Add cts_bitint enumerator. (struct c_declspecs): Move int_n_idx and floatn_nx_idx into a union and add bitint_prec there as well. * c-typeck.cc (c_common_type, comptypes_internal): Handle BITINT_TYPE. (perform_integral_promotions): Promote BITINT_TYPE bit-fields to their declared type. (build_array_ref, build_unary_op, build_conditional_expr, build_c_cast, convert_for_assignment, digest_init, build_binary_op): Handle BITINT_TYPE. * c-fold.cc (c_fully_fold_internal): Handle BITINT_TYPE like INTEGER_TYPE. * c-aux-info.cc (gen_type): Handle BITINT_TYPE. libcpp/ * expr.cc (interpret_int_suffix): Handle wb and WB suffixes. * include/cpplib.h (CPP_N_BITINT): Define.
2023-09-06 23:34:49 +08:00
u = l = i = z = wb = 0;
while (len--)
switch (s[len])
{
case 'z': case 'Z': z++; break;
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;
C _BitInt support [PR102989] This patch adds the C FE support, c-family support, small libcpp change so that 123wb and 42uwb suffixes are handled plus glimits.h change to define BITINT_MAXWIDTH macro. The previous patches really do nothing without this, which enables all the support. 2023-09-06 Jakub Jelinek <jakub@redhat.com> PR c/102989 gcc/ * glimits.h (BITINT_MAXWIDTH): Define if __BITINT_MAXWIDTH__ is predefined. gcc/c-family/ * c-common.cc (c_common_reswords): Add _BitInt as keyword. (unsafe_conversion_p): Handle BITINT_TYPE like INTEGER_TYPE. (c_common_signed_or_unsigned_type): Handle BITINT_TYPE. (c_common_truthvalue_conversion, c_common_get_alias_set, check_builtin_function_arguments): Handle BITINT_TYPE like INTEGER_TYPE. (sync_resolve_size): Add ORIG_FORMAT argument. If FETCH && !ORIG_FORMAT, type is BITINT_TYPE, return -1 if size isn't one of 1, 2, 4, 8 or 16 or if it is 16 but TImode is not supported. (atomic_bitint_fetch_using_cas_loop): New function. (resolve_overloaded_builtin): Adjust sync_resolve_size caller. If -1 is returned, use atomic_bitint_fetch_using_cas_loop to lower it. Formatting fix. (keyword_begins_type_specifier): Handle RID_BITINT. * c-common.h (enum rid): Add RID_BITINT enumerator. * c-cppbuiltin.cc (c_cpp_builtins): For C call targetm.c.bitint_type_info and predefine __BITINT_MAXWIDTH__ and for -fbuilding-libgcc also __LIBGCC_BITINT_LIMB_WIDTH__ and __LIBGCC_BITINT_ORDER__ macros if _BitInt is supported. * c-lex.cc (interpret_integer): Handle CPP_N_BITINT. * c-pretty-print.cc (c_pretty_printer::simple_type_specifier, c_pretty_printer::direct_abstract_declarator, c_pretty_printer::direct_declarator, c_pretty_printer::declarator): Handle BITINT_TYPE. (pp_c_integer_constant): Handle printing of large precision wide_ints which would buffer overflow digit_buffer. * c-warn.cc (conversion_warning, warnings_for_convert_and_check, warnings_for_convert_and_check): Handle BITINT_TYPE like INTEGER_TYPE. gcc/c/ * c-convert.cc (c_convert): Handle BITINT_TYPE like INTEGER_TYPE. * c-decl.cc (check_bitfield_type_and_width): Allow BITINT_TYPE bit-fields. (finish_struct): Prefer to use BITINT_TYPE for BITINT_TYPE bit-fields if possible. (declspecs_add_type): Formatting fixes. Handle cts_bitint. Adjust for added union in *specs. Handle RID_BITINT. (finish_declspecs): Handle cts_bitint. Adjust for added union in *specs. * c-parser.cc (c_keyword_starts_typename, c_token_starts_declspecs, c_parser_declspecs, c_parser_gnu_attribute_any_word): Handle RID_BITINT. (c_parser_omp_clause_schedule): Handle BITINT_TYPE like INTEGER_TYPE. * c-tree.h (enum c_typespec_keyword): Mention _BitInt in comment. Add cts_bitint enumerator. (struct c_declspecs): Move int_n_idx and floatn_nx_idx into a union and add bitint_prec there as well. * c-typeck.cc (c_common_type, comptypes_internal): Handle BITINT_TYPE. (perform_integral_promotions): Promote BITINT_TYPE bit-fields to their declared type. (build_array_ref, build_unary_op, build_conditional_expr, build_c_cast, convert_for_assignment, digest_init, build_binary_op): Handle BITINT_TYPE. * c-fold.cc (c_fully_fold_internal): Handle BITINT_TYPE like INTEGER_TYPE. * c-aux-info.cc (gen_type): Handle BITINT_TYPE. libcpp/ * expr.cc (interpret_int_suffix): Handle wb and WB suffixes. * include/cpplib.h (CPP_N_BITINT): Define.
2023-09-06 23:34:49 +08:00
case 'b':
if (len == 0 || s[len - 1] != 'w')
return 0;
wb++;
len--;
break;
case 'B':
if (len == 0 || s[len - 1] != 'W')
return 0;
wb++;
len--;
break;
default:
return 0;
}
C _BitInt support [PR102989] This patch adds the C FE support, c-family support, small libcpp change so that 123wb and 42uwb suffixes are handled plus glimits.h change to define BITINT_MAXWIDTH macro. The previous patches really do nothing without this, which enables all the support. 2023-09-06 Jakub Jelinek <jakub@redhat.com> PR c/102989 gcc/ * glimits.h (BITINT_MAXWIDTH): Define if __BITINT_MAXWIDTH__ is predefined. gcc/c-family/ * c-common.cc (c_common_reswords): Add _BitInt as keyword. (unsafe_conversion_p): Handle BITINT_TYPE like INTEGER_TYPE. (c_common_signed_or_unsigned_type): Handle BITINT_TYPE. (c_common_truthvalue_conversion, c_common_get_alias_set, check_builtin_function_arguments): Handle BITINT_TYPE like INTEGER_TYPE. (sync_resolve_size): Add ORIG_FORMAT argument. If FETCH && !ORIG_FORMAT, type is BITINT_TYPE, return -1 if size isn't one of 1, 2, 4, 8 or 16 or if it is 16 but TImode is not supported. (atomic_bitint_fetch_using_cas_loop): New function. (resolve_overloaded_builtin): Adjust sync_resolve_size caller. If -1 is returned, use atomic_bitint_fetch_using_cas_loop to lower it. Formatting fix. (keyword_begins_type_specifier): Handle RID_BITINT. * c-common.h (enum rid): Add RID_BITINT enumerator. * c-cppbuiltin.cc (c_cpp_builtins): For C call targetm.c.bitint_type_info and predefine __BITINT_MAXWIDTH__ and for -fbuilding-libgcc also __LIBGCC_BITINT_LIMB_WIDTH__ and __LIBGCC_BITINT_ORDER__ macros if _BitInt is supported. * c-lex.cc (interpret_integer): Handle CPP_N_BITINT. * c-pretty-print.cc (c_pretty_printer::simple_type_specifier, c_pretty_printer::direct_abstract_declarator, c_pretty_printer::direct_declarator, c_pretty_printer::declarator): Handle BITINT_TYPE. (pp_c_integer_constant): Handle printing of large precision wide_ints which would buffer overflow digit_buffer. * c-warn.cc (conversion_warning, warnings_for_convert_and_check, warnings_for_convert_and_check): Handle BITINT_TYPE like INTEGER_TYPE. gcc/c/ * c-convert.cc (c_convert): Handle BITINT_TYPE like INTEGER_TYPE. * c-decl.cc (check_bitfield_type_and_width): Allow BITINT_TYPE bit-fields. (finish_struct): Prefer to use BITINT_TYPE for BITINT_TYPE bit-fields if possible. (declspecs_add_type): Formatting fixes. Handle cts_bitint. Adjust for added union in *specs. Handle RID_BITINT. (finish_declspecs): Handle cts_bitint. Adjust for added union in *specs. * c-parser.cc (c_keyword_starts_typename, c_token_starts_declspecs, c_parser_declspecs, c_parser_gnu_attribute_any_word): Handle RID_BITINT. (c_parser_omp_clause_schedule): Handle BITINT_TYPE like INTEGER_TYPE. * c-tree.h (enum c_typespec_keyword): Mention _BitInt in comment. Add cts_bitint enumerator. (struct c_declspecs): Move int_n_idx and floatn_nx_idx into a union and add bitint_prec there as well. * c-typeck.cc (c_common_type, comptypes_internal): Handle BITINT_TYPE. (perform_integral_promotions): Promote BITINT_TYPE bit-fields to their declared type. (build_array_ref, build_unary_op, build_conditional_expr, build_c_cast, convert_for_assignment, digest_init, build_binary_op): Handle BITINT_TYPE. * c-fold.cc (c_fully_fold_internal): Handle BITINT_TYPE like INTEGER_TYPE. * c-aux-info.cc (gen_type): Handle BITINT_TYPE. libcpp/ * expr.cc (interpret_int_suffix): Handle wb and WB suffixes. * include/cpplib.h (CPP_N_BITINT): Define.
2023-09-06 23:34:49 +08:00
if (l > 2 || u > 1 || i > 1 || z > 1 || wb > 1)
return 0;
if (z)
{
if (l > 0 || i > 0)
return 0;
if (!CPP_OPTION (pfile, cplusplus))
return 0;
}
C _BitInt support [PR102989] This patch adds the C FE support, c-family support, small libcpp change so that 123wb and 42uwb suffixes are handled plus glimits.h change to define BITINT_MAXWIDTH macro. The previous patches really do nothing without this, which enables all the support. 2023-09-06 Jakub Jelinek <jakub@redhat.com> PR c/102989 gcc/ * glimits.h (BITINT_MAXWIDTH): Define if __BITINT_MAXWIDTH__ is predefined. gcc/c-family/ * c-common.cc (c_common_reswords): Add _BitInt as keyword. (unsafe_conversion_p): Handle BITINT_TYPE like INTEGER_TYPE. (c_common_signed_or_unsigned_type): Handle BITINT_TYPE. (c_common_truthvalue_conversion, c_common_get_alias_set, check_builtin_function_arguments): Handle BITINT_TYPE like INTEGER_TYPE. (sync_resolve_size): Add ORIG_FORMAT argument. If FETCH && !ORIG_FORMAT, type is BITINT_TYPE, return -1 if size isn't one of 1, 2, 4, 8 or 16 or if it is 16 but TImode is not supported. (atomic_bitint_fetch_using_cas_loop): New function. (resolve_overloaded_builtin): Adjust sync_resolve_size caller. If -1 is returned, use atomic_bitint_fetch_using_cas_loop to lower it. Formatting fix. (keyword_begins_type_specifier): Handle RID_BITINT. * c-common.h (enum rid): Add RID_BITINT enumerator. * c-cppbuiltin.cc (c_cpp_builtins): For C call targetm.c.bitint_type_info and predefine __BITINT_MAXWIDTH__ and for -fbuilding-libgcc also __LIBGCC_BITINT_LIMB_WIDTH__ and __LIBGCC_BITINT_ORDER__ macros if _BitInt is supported. * c-lex.cc (interpret_integer): Handle CPP_N_BITINT. * c-pretty-print.cc (c_pretty_printer::simple_type_specifier, c_pretty_printer::direct_abstract_declarator, c_pretty_printer::direct_declarator, c_pretty_printer::declarator): Handle BITINT_TYPE. (pp_c_integer_constant): Handle printing of large precision wide_ints which would buffer overflow digit_buffer. * c-warn.cc (conversion_warning, warnings_for_convert_and_check, warnings_for_convert_and_check): Handle BITINT_TYPE like INTEGER_TYPE. gcc/c/ * c-convert.cc (c_convert): Handle BITINT_TYPE like INTEGER_TYPE. * c-decl.cc (check_bitfield_type_and_width): Allow BITINT_TYPE bit-fields. (finish_struct): Prefer to use BITINT_TYPE for BITINT_TYPE bit-fields if possible. (declspecs_add_type): Formatting fixes. Handle cts_bitint. Adjust for added union in *specs. Handle RID_BITINT. (finish_declspecs): Handle cts_bitint. Adjust for added union in *specs. * c-parser.cc (c_keyword_starts_typename, c_token_starts_declspecs, c_parser_declspecs, c_parser_gnu_attribute_any_word): Handle RID_BITINT. (c_parser_omp_clause_schedule): Handle BITINT_TYPE like INTEGER_TYPE. * c-tree.h (enum c_typespec_keyword): Mention _BitInt in comment. Add cts_bitint enumerator. (struct c_declspecs): Move int_n_idx and floatn_nx_idx into a union and add bitint_prec there as well. * c-typeck.cc (c_common_type, comptypes_internal): Handle BITINT_TYPE. (perform_integral_promotions): Promote BITINT_TYPE bit-fields to their declared type. (build_array_ref, build_unary_op, build_conditional_expr, build_c_cast, convert_for_assignment, digest_init, build_binary_op): Handle BITINT_TYPE. * c-fold.cc (c_fully_fold_internal): Handle BITINT_TYPE like INTEGER_TYPE. * c-aux-info.cc (gen_type): Handle BITINT_TYPE. libcpp/ * expr.cc (interpret_int_suffix): Handle wb and WB suffixes. * include/cpplib.h (CPP_N_BITINT): Define.
2023-09-06 23:34:49 +08:00
if (wb)
{
if (CPP_OPTION (pfile, cplusplus))
return 0;
if (l > 0 || i > 0 || z > 0)
return 0;
}
if (i)
{
if (!CPP_OPTION (pfile, ext_numeric_literals))
return 0;
/* In C++14 and up these suffixes are in the standard library, so treat
them as user-defined literals. */
if (CPP_OPTION (pfile, cplusplus)
&& CPP_OPTION (pfile, lang) > CLK_CXX11
&& s[0] == 'i'
&& (orig_len == 1 || (orig_len == 2 && s[1] == 'l')))
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)
C _BitInt support [PR102989] This patch adds the C FE support, c-family support, small libcpp change so that 123wb and 42uwb suffixes are handled plus glimits.h change to define BITINT_MAXWIDTH macro. The previous patches really do nothing without this, which enables all the support. 2023-09-06 Jakub Jelinek <jakub@redhat.com> PR c/102989 gcc/ * glimits.h (BITINT_MAXWIDTH): Define if __BITINT_MAXWIDTH__ is predefined. gcc/c-family/ * c-common.cc (c_common_reswords): Add _BitInt as keyword. (unsafe_conversion_p): Handle BITINT_TYPE like INTEGER_TYPE. (c_common_signed_or_unsigned_type): Handle BITINT_TYPE. (c_common_truthvalue_conversion, c_common_get_alias_set, check_builtin_function_arguments): Handle BITINT_TYPE like INTEGER_TYPE. (sync_resolve_size): Add ORIG_FORMAT argument. If FETCH && !ORIG_FORMAT, type is BITINT_TYPE, return -1 if size isn't one of 1, 2, 4, 8 or 16 or if it is 16 but TImode is not supported. (atomic_bitint_fetch_using_cas_loop): New function. (resolve_overloaded_builtin): Adjust sync_resolve_size caller. If -1 is returned, use atomic_bitint_fetch_using_cas_loop to lower it. Formatting fix. (keyword_begins_type_specifier): Handle RID_BITINT. * c-common.h (enum rid): Add RID_BITINT enumerator. * c-cppbuiltin.cc (c_cpp_builtins): For C call targetm.c.bitint_type_info and predefine __BITINT_MAXWIDTH__ and for -fbuilding-libgcc also __LIBGCC_BITINT_LIMB_WIDTH__ and __LIBGCC_BITINT_ORDER__ macros if _BitInt is supported. * c-lex.cc (interpret_integer): Handle CPP_N_BITINT. * c-pretty-print.cc (c_pretty_printer::simple_type_specifier, c_pretty_printer::direct_abstract_declarator, c_pretty_printer::direct_declarator, c_pretty_printer::declarator): Handle BITINT_TYPE. (pp_c_integer_constant): Handle printing of large precision wide_ints which would buffer overflow digit_buffer. * c-warn.cc (conversion_warning, warnings_for_convert_and_check, warnings_for_convert_and_check): Handle BITINT_TYPE like INTEGER_TYPE. gcc/c/ * c-convert.cc (c_convert): Handle BITINT_TYPE like INTEGER_TYPE. * c-decl.cc (check_bitfield_type_and_width): Allow BITINT_TYPE bit-fields. (finish_struct): Prefer to use BITINT_TYPE for BITINT_TYPE bit-fields if possible. (declspecs_add_type): Formatting fixes. Handle cts_bitint. Adjust for added union in *specs. Handle RID_BITINT. (finish_declspecs): Handle cts_bitint. Adjust for added union in *specs. * c-parser.cc (c_keyword_starts_typename, c_token_starts_declspecs, c_parser_declspecs, c_parser_gnu_attribute_any_word): Handle RID_BITINT. (c_parser_omp_clause_schedule): Handle BITINT_TYPE like INTEGER_TYPE. * c-tree.h (enum c_typespec_keyword): Mention _BitInt in comment. Add cts_bitint enumerator. (struct c_declspecs): Move int_n_idx and floatn_nx_idx into a union and add bitint_prec there as well. * c-typeck.cc (c_common_type, comptypes_internal): Handle BITINT_TYPE. (perform_integral_promotions): Promote BITINT_TYPE bit-fields to their declared type. (build_array_ref, build_unary_op, build_conditional_expr, build_c_cast, convert_for_assignment, digest_init, build_binary_op): Handle BITINT_TYPE. * c-fold.cc (c_fully_fold_internal): Handle BITINT_TYPE like INTEGER_TYPE. * c-aux-info.cc (gen_type): Handle BITINT_TYPE. libcpp/ * expr.cc (interpret_int_suffix): Handle wb and WB suffixes. * include/cpplib.h (CPP_N_BITINT): Define.
2023-09-06 23:34:49 +08:00
| (z ? CPP_N_SIZE_T : 0)
| (wb ? CPP_N_BITINT : 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-27 03:30:59 +08: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-27 03:30:59 +08: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-27 03:30:59 +08: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-27 03:30:59 +08: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 20:58:48 +08: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-27 03:30:59 +08: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 20:58:48 +08: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-27 03:30:59 +08: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 20:58:48 +08: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-27 03:30:59 +08: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 18:51:15 +08: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-27 03:30:59 +08:00
cpp_classify_number (cpp_reader *pfile, const cpp_token *token,
Eliminate source_location in favor of location_t Historically GCC used location_t, while libcpp used source_location. This inconsistency has been annoying me for a while, so this patch removes source_location in favor of location_t throughout (as the latter is shorter). gcc/ChangeLog: * builtins.c: Replace "source_location" with "location_t". * diagnostic-show-locus.c: Likewise. * diagnostic.c: Likewise. * dumpfile.c: Likewise. * gcc-rich-location.h: Likewise. * genmatch.c: Likewise. * gimple.h: Likewise. * gimplify.c: Likewise. * input.c: Likewise. * input.h: Likewise. Eliminate the typedef. * omp-expand.c: Likewise. * selftest.h: Likewise. * substring-locations.h (get_source_location_for_substring): Rename to.. (get_location_within_string): ...this. * tree-cfg.c: Replace "source_location" with "location_t". * tree-cfgcleanup.c: Likewise. * tree-diagnostic.c: Likewise. * tree-into-ssa.c: Likewise. * tree-outof-ssa.c: Likewise. * tree-parloops.c: Likewise. * tree-phinodes.c: Likewise. * tree-phinodes.h: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-manip.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-phiprop.c: Likewise. * tree-ssa-threadupdate.c: Likewise. * tree-ssa.c: Likewise. * tree-ssa.h: Likewise. * tree-vect-loop-manip.c: Likewise. gcc/c-family/ChangeLog: * c-common.c (c_get_substring_location): Update for renaming of get_source_location_for_substring to get_location_within_string. * c-lex.c: Replace "source_location" with "location_t". * c-opts.c: Likewise. * c-ppoutput.c: Likewise. gcc/c/ChangeLog: * c-decl.c: Replace "source_location" with "location_t". * c-tree.h: Likewise. * c-typeck.c: Likewise. * gimple-parser.c: Likewise. gcc/cp/ChangeLog: * call.c: Replace "source_location" with "location_t". * cp-tree.h: Likewise. * cvt.c: Likewise. * name-lookup.c: Likewise. * parser.c: Likewise. * typeck.c: Likewise. gcc/fortran/ChangeLog: * cpp.c: Replace "source_location" with "location_t". * gfortran.h: Likewise. gcc/go/ChangeLog: * go-gcc-diagnostics.cc: Replace "source_location" with "location_t". * go-gcc.cc: Likewise. * go-linemap.cc: Likewise. * go-location.h: Likewise. * gofrontend/README: Likewise. gcc/jit/ChangeLog: * jit-playback.c: Replace "source_location" with "location_t". gcc/testsuite/ChangeLog: * g++.dg/plugin/comment_plugin.c: Replace "source_location" with "location_t". * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c: Likewise. libcc1/ChangeLog: * libcc1plugin.cc: Replace "source_location" with "location_t". (plugin_context::get_source_location): Rename to... (plugin_context::get_location_t): ...this. * libcp1plugin.cc: Likewise. libcpp/ChangeLog: * charset.c: Replace "source_location" with "location_t". * directives-only.c: Likewise. * directives.c: Likewise. * errors.c: Likewise. * expr.c: Likewise. * files.c: Likewise. * include/cpplib.h: Likewise. Rename MAX_SOURCE_LOCATION to MAX_LOCATION_T. * include/line-map.h: Likewise. * init.c: Likewise. * internal.h: Likewise. * lex.c: Likewise. * line-map.c: Likewise. * location-example.txt: Likewise. * macro.c: Likewise. * pch.c: Likewise. * traditional.c: Likewise. From-SVN: r266085
2018-11-14 04:05:03 +08:00
const char **ud_suffix, location_t 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-27 03:30:59 +08: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))
preprocessor: Fix pp-number lexing of digit separators [PR83873, PR97604] When the preprocessor lexes preprocessing numbers in lex_number, it accepts digit separators in more cases than actually permitted in pp-numbers by the standard syntax. One thing this accepts is adjacent digit separators; there is some code to reject those later, but as noted in bug 83873 it fails to cover the case of adjacent digit separators within a floating-point exponent. Accepting adjacent digit separators only results in a missing diagnostic, not in valid code being rejected or being accepted with incorrect semantics, because the correct lexing in such a case would have '' start the following preprocessing tokens, and no valid preprocessing token starts '' while ' isn't valid on its own as a preprocessing token either. So this patch fixes that case by moving the error for adjacent digit separators to lex_number (allowing a more specific diagnostic than if '' were excluded from the pp-number completely). Other cases inappropriately accepted involve digit separators before '.', 'e+', 'e-', 'p+' or 'p-' (or corresponding uppercase variants). In those cases, as shown by the test digit-sep-pp-number.C added, this can result in valid code being wrongly rejected as a result of too many characters being included in the pp-number. So this case is fixed by terminating the pp-number at the correct character according to the standard. That test also covers the case where a digit separator was followed by an identifier-nondigit that is not a nondigit (e.g. a UCN); that case was already handled correctly. Bootstrapped with no regressions for x86_64-pc-linux-gnu. libcpp/ PR c++/83873 PR preprocessor/97604 * lex.c (lex_number): Reject adjacent digit separators here. Do not allow digit separators before '.' or an exponent with sign. * expr.c (cpp_classify_number): Do not check for adjacent digit separators here. gcc/testsuite/ PR c++/83873 PR preprocessor/97604 * g++.dg/cpp1y/digit-sep-neg-2.C, g++.dg/cpp1y/digit-sep-pp-number.C: New tests. * g++.dg/cpp1y/digit-sep-line-neg.C, g++.dg/cpp1y/digit-sep-neg.C: Adjust expected messages.
2021-05-07 07:20:35 +08:00
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 18:51:15 +08: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;
libcpp: adjust pedwarn handling Using cpp_pedwarning (CPP_W_PEDANTIC instead of if (CPP_PEDANTIC cpp_error lets users suppress these diagnostics with #pragma GCC diagnostic ignored "-Wpedantic". This patch changes all instances of the cpp_error (CPP_DL_PEDWARN to cpp_pedwarning. In cases where the extension appears in a later C++ revision, we now condition the warning on the relevant -Wc++??-extensions flag instead of -Wpedantic; in such cases often the if (CPP_PEDANTIC) check is retained to preserve the default non-warning behavior. I didn't attempt to adjust the warning flags for the C compiler, since it seems to follow a different system than C++. The CPP_PEDANTIC check is also kept in _cpp_lex_direct to avoid an ICE in the self-tests from cb.diagnostics not being initialized. While working on testcases for these changes I noticed that the c-c++-common tests are not run with -pedantic-errors by default like the gcc.dg and g++.dg directories are. And if I specify -pedantic-errors with dg-options, the default -std= changes from c++?? to gnu++??, which interferes with some other pedwarns. So two of the tests are C++-only. libcpp/ChangeLog: * include/cpplib.h (enum cpp_warning_reason): Add CPP_W_CXX{14,17,20,23}_EXTENSIONS. * charset.cc (_cpp_valid_ucn, convert_hex, convert_oct) (convert_escape, narrow_str_to_charconst): Use cpp_pedwarning instead of cpp_error for pedwarns. * directives.cc (directive_diagnostics, _cpp_handle_directive) (do_line, do_elif): Likewise. * expr.cc (cpp_classify_number, eval_token): Likewise. * lex.cc (skip_whitespace, maybe_va_opt_error) (_cpp_lex_direct): Likewise. * macro.cc (_cpp_arguments_ok): Likewise. (replace_args): Use -Wvariadic-macros for pedwarn about empty macro arguments. gcc/c-family/ChangeLog: * c.opt: Add CppReason for Wc++{14,17,20,23}-extensions. * c-pragma.cc (handle_pragma_diagnostic_impl): Don't check OPT_Wc__23_extensions. gcc/testsuite/ChangeLog: * c-c++-common/pragma-diag-17.c: New test. * g++.dg/cpp0x/va-opt1.C: New test. * g++.dg/cpp23/named-universal-char-escape3.C: New test.
2024-08-28 01:15:16 +08:00
cpp_pedwarning_with_line
(pfile, CPP_W_PEDANTIC, 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 18:51:15 +08:00
SYNTAX_ERROR2_AT (virtual_location,
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics When working on #embed support, or -Wheader-guard or other recent libcpp changes, I've been annoyed by the libcpp diagnostics being visually different from normal gcc diagnostics, especially in the area of quoting stuff in the diagnostic messages. Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use %</%>, %qs etc. in there, while libcpp diagnostics was marked as printf and in libcpp we've been very creative with quoting stuff, either no quotes at all, or "something" quoting, or 'something' quoting, or `something' quoting (but in none of the cases it used colors consistently with the rest of the compiler). Now, libcpp diagnostics is always emitted using a callback, pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with genmatch.cc: cb->diagnostic = diagnostic_cb; c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic; fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic; where the latter two just use diagnostic_report_diagnostic, so actually support all the gcc_diag stuff, only the genmatch.cc case didn't. So, the following patch changes genmatch.cc to use pp_format* instead of vfprintf so that it supports the gcc_diag formatting (pretty-print.o unfortunately has various dependencies, so had to link genmatch with libcommon.a libbacktrace.a and tweak Makefile.in so that there are no circular dependencies) and marks the libcpp diagnostic routines as gcc_diag rather than printf. That change resulted in hundreds of -Wformat-diag new warnings (most of them useful and resulting IMHO in better diagnostics), so the rest of the patch is changing the format strings to make -Wformat-diag happy and adjusting the testsuite for the differences in how is the diagnostic reformatted. Dunno if some out of GCC tree projects use libcpp, that case would make it harder because one couldn't use vfprintf in the diagnostic callback anymore, but there is always David's libdiagnostic which could be used for that purpose IMHO. 2024-10-12 Jakub Jelinek <jakub@redhat.com> libcpp/ * include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define. (struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF on diagnostic callback. (cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3. (cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. (cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6) instead of ATTRIBUTE_PRINTF_5. (cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. * Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather than --language=c. * errors.cc (cpp_diagnostic_at, cpp_diagnostic, cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of -ATTRIBUTE_FPTR_PRINTF. * charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex, convert_oct, convert_escape): Fix up -Wformat-diag warnings. (cpp_interpret_string_ranges, count_source_chars): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF. (narrow_str_to_charconst): Fix up -Wformat-diag warnings. * directives.cc (check_eol_1, directive_diagnostics, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, do_include_next, _cpp_parse_embed_params, do_embed, read_flag, do_line, do_linemarker, register_pragma_1, do_pragma_once, do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison, do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, do_assert, cpp_define_unused): Likewise. * expr.cc (cpp_classify_number, parse_defined, eval_token, _cpp_parse_expr, reduce, check_promotion): Likewise. * files.cc (_cpp_find_file, finish_base64_embed, _cpp_pop_file_buffer): Likewise. * init.cc (sanity_checks): Likewise. * lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char, _cpp_warn_invalid_utf8, _cpp_skip_block_comment, warn_about_normalization, forms_identifier_p, maybe_va_opt_error, identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise. * macro.cc (class vaopt_state, builtin_has_include_1, builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro, _cpp_builtin_macro_text, builtin_macro, stringify_arg, _cpp_arguments_ok, collect_args, enter_macro_context, _cpp_save_parameter, parse_params, create_iso_definition, _cpp_create_definition, check_trad_stringification): Likewise. * pch.cc (cpp_valid_state): Likewise. * traditional.cc (_cpp_scan_out_logical_line, recursive_macro): Likewise. gcc/ * Makefile.in (generated_files): Remove {gimple,generic}-match*. (generated_match_files): New variable. Add a dependency of $(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those. (build/genmatch$(build_exeext)): Depend on and link against libcommon.a and $(LIBBACKTRACE). * genmatch.cc: Include pretty-print.h and input.h. (ggc_internal_cleared_alloc, ggc_free): Remove. (fatal): New function. (line_table): Remove. (linemap_client_expand_location_to_spelling_point): Remove. (diagnostic_cb): Use gcc_diag rather than printf format. Use pp_format_verbatim on a temporary pretty_printer instead of vfprintf. (fatal_at, warning_at): Use gcc_diag rather than printf format. (output_line_directive): Rename location_hash to loc_hash. (parser::eat_ident, parser::parse_operation, parser::parse_expr, parser::parse_pattern, parser::finish_match_operand): Fix up -Wformat-diag warnings. gcc/c-family/ * c-lex.cc (c_common_has_attribute, c_common_lex_availability_macro): Fix up -Wformat-diag warnings. gcc/testsuite/ * c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for libcpp diagnostic formatting changes. * c-c++-common/cpp/embed-3.c: Likewise. * c-c++-common/cpp/embed-4.c: Likewise. * c-c++-common/cpp/embed-16.c: Likewise. * c-c++-common/cpp/embed-18.c: Likewise. * c-c++-common/cpp/eof-2.c: Likewise. * c-c++-common/cpp/eof-3.c: Likewise. * c-c++-common/cpp/fmax-include-depth.c: Likewise. * c-c++-common/cpp/has-builtin.c: Likewise. * c-c++-common/cpp/line-2.c: Likewise. * c-c++-common/cpp/line-3.c: Likewise. * c-c++-common/cpp/macro-arg-count-1.c: Likewise. * c-c++-common/cpp/macro-arg-count-2.c: Likewise. * c-c++-common/cpp/macro-ranges.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-4.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-5.c: Likewise. * c-c++-common/cpp/pr88974.c: Likewise. * c-c++-common/cpp/va-opt-error.c: Likewise. * c-c++-common/cpp/va-opt-pedantic.c: Likewise. * c-c++-common/cpp/Wheader-guard-2.c: Likewise. * c-c++-common/cpp/Wheader-guard-3.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-1.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-2.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-3.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c: Likewise. * c-c++-common/pr68833-3.c: Likewise. * c-c++-common/raw-string-directive-1.c: Likewise. * gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise. * gcc.dg/binary-constants-4.c: Likewise. * gcc.dg/builtin-redefine.c: Likewise. * gcc.dg/cpp/19951025-1.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c23-elifdef-2.c: Likewise. * gcc.dg/cpp/c23-warning-2.c: Likewise. * gcc.dg/cpp/embed-2.c: Likewise. * gcc.dg/cpp/embed-3.c: Likewise. * gcc.dg/cpp/embed-4.c: Likewise. * gcc.dg/cpp/expr.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu23-warning-2.c: Likewise. * gcc.dg/cpp/include6.c: Likewise. * gcc.dg/cpp/pr35322.c: Likewise. * gcc.dg/cpp/tr-warn6.c: Likewise. * gcc.dg/cpp/undef2.c: Likewise. * gcc.dg/cpp/warn-comments.c: Likewise. * gcc.dg/cpp/warn-comments-2.c: Likewise. * gcc.dg/cpp/warn-comments-3.c: Likewise. * gcc.dg/cpp/warn-cxx-compat.c: Likewise. * gcc.dg/cpp/warn-cxx-compat-2.c: Likewise. * gcc.dg/cpp/warn-deprecated.c: Likewise. * gcc.dg/cpp/warn-deprecated-2.c: Likewise. * gcc.dg/cpp/warn-long-long.c: Likewise. * gcc.dg/cpp/warn-long-long-2.c: Likewise. * gcc.dg/cpp/warn-normalized-1.c: Likewise. * gcc.dg/cpp/warn-normalized-2.c: Likewise. * gcc.dg/cpp/warn-normalized-3.c: Likewise. * gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise. * gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise. * gcc.dg/cpp/warn-redefined.c: Likewise. * gcc.dg/cpp/warn-redefined-2.c: Likewise. * gcc.dg/cpp/warn-traditional.c: Likewise. * gcc.dg/cpp/warn-traditional-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-1.c: Likewise. * gcc.dg/cpp/warn-trigraphs-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-3.c: Likewise. * gcc.dg/cpp/warn-trigraphs-4.c: Likewise. * gcc.dg/cpp/warn-undef.c: Likewise. * gcc.dg/cpp/warn-undef-2.c: Likewise. * gcc.dg/cpp/warn-unused-macros.c: Likewise. * gcc.dg/cpp/warn-unused-macros-2.c: Likewise. * gcc.dg/pch/counter-2.c: Likewise. * g++.dg/cpp0x/udlit-error1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-1.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-3.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-4.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-5.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-6.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-7.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-8.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-9.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-10.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-11.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-12.C: Likewise. * g++.dg/cpp/elifdef-3.C: Likewise. * g++.dg/cpp/elifdef-5.C: Likewise. * g++.dg/cpp/elifdef-6.C: Likewise. * g++.dg/cpp/elifdef-7.C: Likewise. * g++.dg/cpp/embed-1.C: Likewise. * g++.dg/cpp/embed-2.C: Likewise. * g++.dg/cpp/pedantic-errors.C: Likewise. * g++.dg/cpp/warning-1.C: Likewise. * g++.dg/cpp/warning-2.C: Likewise. * g++.dg/ext/bitint1.C: Likewise. * g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
"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 18:51:15 +08:00
SYNTAX_ERROR2_AT (virtual_location,
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics When working on #embed support, or -Wheader-guard or other recent libcpp changes, I've been annoyed by the libcpp diagnostics being visually different from normal gcc diagnostics, especially in the area of quoting stuff in the diagnostic messages. Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use %</%>, %qs etc. in there, while libcpp diagnostics was marked as printf and in libcpp we've been very creative with quoting stuff, either no quotes at all, or "something" quoting, or 'something' quoting, or `something' quoting (but in none of the cases it used colors consistently with the rest of the compiler). Now, libcpp diagnostics is always emitted using a callback, pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with genmatch.cc: cb->diagnostic = diagnostic_cb; c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic; fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic; where the latter two just use diagnostic_report_diagnostic, so actually support all the gcc_diag stuff, only the genmatch.cc case didn't. So, the following patch changes genmatch.cc to use pp_format* instead of vfprintf so that it supports the gcc_diag formatting (pretty-print.o unfortunately has various dependencies, so had to link genmatch with libcommon.a libbacktrace.a and tweak Makefile.in so that there are no circular dependencies) and marks the libcpp diagnostic routines as gcc_diag rather than printf. That change resulted in hundreds of -Wformat-diag new warnings (most of them useful and resulting IMHO in better diagnostics), so the rest of the patch is changing the format strings to make -Wformat-diag happy and adjusting the testsuite for the differences in how is the diagnostic reformatted. Dunno if some out of GCC tree projects use libcpp, that case would make it harder because one couldn't use vfprintf in the diagnostic callback anymore, but there is always David's libdiagnostic which could be used for that purpose IMHO. 2024-10-12 Jakub Jelinek <jakub@redhat.com> libcpp/ * include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define. (struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF on diagnostic callback. (cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3. (cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. (cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6) instead of ATTRIBUTE_PRINTF_5. (cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. * Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather than --language=c. * errors.cc (cpp_diagnostic_at, cpp_diagnostic, cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of -ATTRIBUTE_FPTR_PRINTF. * charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex, convert_oct, convert_escape): Fix up -Wformat-diag warnings. (cpp_interpret_string_ranges, count_source_chars): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF. (narrow_str_to_charconst): Fix up -Wformat-diag warnings. * directives.cc (check_eol_1, directive_diagnostics, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, do_include_next, _cpp_parse_embed_params, do_embed, read_flag, do_line, do_linemarker, register_pragma_1, do_pragma_once, do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison, do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, do_assert, cpp_define_unused): Likewise. * expr.cc (cpp_classify_number, parse_defined, eval_token, _cpp_parse_expr, reduce, check_promotion): Likewise. * files.cc (_cpp_find_file, finish_base64_embed, _cpp_pop_file_buffer): Likewise. * init.cc (sanity_checks): Likewise. * lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char, _cpp_warn_invalid_utf8, _cpp_skip_block_comment, warn_about_normalization, forms_identifier_p, maybe_va_opt_error, identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise. * macro.cc (class vaopt_state, builtin_has_include_1, builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro, _cpp_builtin_macro_text, builtin_macro, stringify_arg, _cpp_arguments_ok, collect_args, enter_macro_context, _cpp_save_parameter, parse_params, create_iso_definition, _cpp_create_definition, check_trad_stringification): Likewise. * pch.cc (cpp_valid_state): Likewise. * traditional.cc (_cpp_scan_out_logical_line, recursive_macro): Likewise. gcc/ * Makefile.in (generated_files): Remove {gimple,generic}-match*. (generated_match_files): New variable. Add a dependency of $(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those. (build/genmatch$(build_exeext)): Depend on and link against libcommon.a and $(LIBBACKTRACE). * genmatch.cc: Include pretty-print.h and input.h. (ggc_internal_cleared_alloc, ggc_free): Remove. (fatal): New function. (line_table): Remove. (linemap_client_expand_location_to_spelling_point): Remove. (diagnostic_cb): Use gcc_diag rather than printf format. Use pp_format_verbatim on a temporary pretty_printer instead of vfprintf. (fatal_at, warning_at): Use gcc_diag rather than printf format. (output_line_directive): Rename location_hash to loc_hash. (parser::eat_ident, parser::parse_operation, parser::parse_expr, parser::parse_pattern, parser::finish_match_operand): Fix up -Wformat-diag warnings. gcc/c-family/ * c-lex.cc (c_common_has_attribute, c_common_lex_availability_macro): Fix up -Wformat-diag warnings. gcc/testsuite/ * c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for libcpp diagnostic formatting changes. * c-c++-common/cpp/embed-3.c: Likewise. * c-c++-common/cpp/embed-4.c: Likewise. * c-c++-common/cpp/embed-16.c: Likewise. * c-c++-common/cpp/embed-18.c: Likewise. * c-c++-common/cpp/eof-2.c: Likewise. * c-c++-common/cpp/eof-3.c: Likewise. * c-c++-common/cpp/fmax-include-depth.c: Likewise. * c-c++-common/cpp/has-builtin.c: Likewise. * c-c++-common/cpp/line-2.c: Likewise. * c-c++-common/cpp/line-3.c: Likewise. * c-c++-common/cpp/macro-arg-count-1.c: Likewise. * c-c++-common/cpp/macro-arg-count-2.c: Likewise. * c-c++-common/cpp/macro-ranges.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-4.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-5.c: Likewise. * c-c++-common/cpp/pr88974.c: Likewise. * c-c++-common/cpp/va-opt-error.c: Likewise. * c-c++-common/cpp/va-opt-pedantic.c: Likewise. * c-c++-common/cpp/Wheader-guard-2.c: Likewise. * c-c++-common/cpp/Wheader-guard-3.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-1.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-2.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-3.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c: Likewise. * c-c++-common/pr68833-3.c: Likewise. * c-c++-common/raw-string-directive-1.c: Likewise. * gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise. * gcc.dg/binary-constants-4.c: Likewise. * gcc.dg/builtin-redefine.c: Likewise. * gcc.dg/cpp/19951025-1.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c23-elifdef-2.c: Likewise. * gcc.dg/cpp/c23-warning-2.c: Likewise. * gcc.dg/cpp/embed-2.c: Likewise. * gcc.dg/cpp/embed-3.c: Likewise. * gcc.dg/cpp/embed-4.c: Likewise. * gcc.dg/cpp/expr.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu23-warning-2.c: Likewise. * gcc.dg/cpp/include6.c: Likewise. * gcc.dg/cpp/pr35322.c: Likewise. * gcc.dg/cpp/tr-warn6.c: Likewise. * gcc.dg/cpp/undef2.c: Likewise. * gcc.dg/cpp/warn-comments.c: Likewise. * gcc.dg/cpp/warn-comments-2.c: Likewise. * gcc.dg/cpp/warn-comments-3.c: Likewise. * gcc.dg/cpp/warn-cxx-compat.c: Likewise. * gcc.dg/cpp/warn-cxx-compat-2.c: Likewise. * gcc.dg/cpp/warn-deprecated.c: Likewise. * gcc.dg/cpp/warn-deprecated-2.c: Likewise. * gcc.dg/cpp/warn-long-long.c: Likewise. * gcc.dg/cpp/warn-long-long-2.c: Likewise. * gcc.dg/cpp/warn-normalized-1.c: Likewise. * gcc.dg/cpp/warn-normalized-2.c: Likewise. * gcc.dg/cpp/warn-normalized-3.c: Likewise. * gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise. * gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise. * gcc.dg/cpp/warn-redefined.c: Likewise. * gcc.dg/cpp/warn-redefined-2.c: Likewise. * gcc.dg/cpp/warn-traditional.c: Likewise. * gcc.dg/cpp/warn-traditional-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-1.c: Likewise. * gcc.dg/cpp/warn-trigraphs-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-3.c: Likewise. * gcc.dg/cpp/warn-trigraphs-4.c: Likewise. * gcc.dg/cpp/warn-undef.c: Likewise. * gcc.dg/cpp/warn-undef-2.c: Likewise. * gcc.dg/cpp/warn-unused-macros.c: Likewise. * gcc.dg/cpp/warn-unused-macros-2.c: Likewise. * gcc.dg/pch/counter-2.c: Likewise. * g++.dg/cpp0x/udlit-error1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-1.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-3.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-4.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-5.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-6.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-7.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-8.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-9.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-10.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-11.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-12.C: Likewise. * g++.dg/cpp/elifdef-3.C: Likewise. * g++.dg/cpp/elifdef-5.C: Likewise. * g++.dg/cpp/elifdef-6.C: Likewise. * g++.dg/cpp/elifdef-7.C: Likewise. * g++.dg/cpp/embed-1.C: Likewise. * g++.dg/cpp/embed-2.C: Likewise. * g++.dg/cpp/pedantic-errors.C: Likewise. * g++.dg/cpp/warning-1.C: Likewise. * g++.dg/cpp/warning-2.C: Likewise. * g++.dg/ext/bitint1.C: Likewise. * g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
"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 18:51:15 +08:00
cpp_error_with_line (pfile, CPP_DL_ERROR, virtual_location, 0,
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics When working on #embed support, or -Wheader-guard or other recent libcpp changes, I've been annoyed by the libcpp diagnostics being visually different from normal gcc diagnostics, especially in the area of quoting stuff in the diagnostic messages. Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use %</%>, %qs etc. in there, while libcpp diagnostics was marked as printf and in libcpp we've been very creative with quoting stuff, either no quotes at all, or "something" quoting, or 'something' quoting, or `something' quoting (but in none of the cases it used colors consistently with the rest of the compiler). Now, libcpp diagnostics is always emitted using a callback, pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with genmatch.cc: cb->diagnostic = diagnostic_cb; c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic; fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic; where the latter two just use diagnostic_report_diagnostic, so actually support all the gcc_diag stuff, only the genmatch.cc case didn't. So, the following patch changes genmatch.cc to use pp_format* instead of vfprintf so that it supports the gcc_diag formatting (pretty-print.o unfortunately has various dependencies, so had to link genmatch with libcommon.a libbacktrace.a and tweak Makefile.in so that there are no circular dependencies) and marks the libcpp diagnostic routines as gcc_diag rather than printf. That change resulted in hundreds of -Wformat-diag new warnings (most of them useful and resulting IMHO in better diagnostics), so the rest of the patch is changing the format strings to make -Wformat-diag happy and adjusting the testsuite for the differences in how is the diagnostic reformatted. Dunno if some out of GCC tree projects use libcpp, that case would make it harder because one couldn't use vfprintf in the diagnostic callback anymore, but there is always David's libdiagnostic which could be used for that purpose IMHO. 2024-10-12 Jakub Jelinek <jakub@redhat.com> libcpp/ * include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define. (struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF on diagnostic callback. (cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3. (cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. (cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6) instead of ATTRIBUTE_PRINTF_5. (cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. * Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather than --language=c. * errors.cc (cpp_diagnostic_at, cpp_diagnostic, cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of -ATTRIBUTE_FPTR_PRINTF. * charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex, convert_oct, convert_escape): Fix up -Wformat-diag warnings. (cpp_interpret_string_ranges, count_source_chars): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF. (narrow_str_to_charconst): Fix up -Wformat-diag warnings. * directives.cc (check_eol_1, directive_diagnostics, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, do_include_next, _cpp_parse_embed_params, do_embed, read_flag, do_line, do_linemarker, register_pragma_1, do_pragma_once, do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison, do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, do_assert, cpp_define_unused): Likewise. * expr.cc (cpp_classify_number, parse_defined, eval_token, _cpp_parse_expr, reduce, check_promotion): Likewise. * files.cc (_cpp_find_file, finish_base64_embed, _cpp_pop_file_buffer): Likewise. * init.cc (sanity_checks): Likewise. * lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char, _cpp_warn_invalid_utf8, _cpp_skip_block_comment, warn_about_normalization, forms_identifier_p, maybe_va_opt_error, identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise. * macro.cc (class vaopt_state, builtin_has_include_1, builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro, _cpp_builtin_macro_text, builtin_macro, stringify_arg, _cpp_arguments_ok, collect_args, enter_macro_context, _cpp_save_parameter, parse_params, create_iso_definition, _cpp_create_definition, check_trad_stringification): Likewise. * pch.cc (cpp_valid_state): Likewise. * traditional.cc (_cpp_scan_out_logical_line, recursive_macro): Likewise. gcc/ * Makefile.in (generated_files): Remove {gimple,generic}-match*. (generated_match_files): New variable. Add a dependency of $(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those. (build/genmatch$(build_exeext)): Depend on and link against libcommon.a and $(LIBBACKTRACE). * genmatch.cc: Include pretty-print.h and input.h. (ggc_internal_cleared_alloc, ggc_free): Remove. (fatal): New function. (line_table): Remove. (linemap_client_expand_location_to_spelling_point): Remove. (diagnostic_cb): Use gcc_diag rather than printf format. Use pp_format_verbatim on a temporary pretty_printer instead of vfprintf. (fatal_at, warning_at): Use gcc_diag rather than printf format. (output_line_directive): Rename location_hash to loc_hash. (parser::eat_ident, parser::parse_operation, parser::parse_expr, parser::parse_pattern, parser::finish_match_operand): Fix up -Wformat-diag warnings. gcc/c-family/ * c-lex.cc (c_common_has_attribute, c_common_lex_availability_macro): Fix up -Wformat-diag warnings. gcc/testsuite/ * c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for libcpp diagnostic formatting changes. * c-c++-common/cpp/embed-3.c: Likewise. * c-c++-common/cpp/embed-4.c: Likewise. * c-c++-common/cpp/embed-16.c: Likewise. * c-c++-common/cpp/embed-18.c: Likewise. * c-c++-common/cpp/eof-2.c: Likewise. * c-c++-common/cpp/eof-3.c: Likewise. * c-c++-common/cpp/fmax-include-depth.c: Likewise. * c-c++-common/cpp/has-builtin.c: Likewise. * c-c++-common/cpp/line-2.c: Likewise. * c-c++-common/cpp/line-3.c: Likewise. * c-c++-common/cpp/macro-arg-count-1.c: Likewise. * c-c++-common/cpp/macro-arg-count-2.c: Likewise. * c-c++-common/cpp/macro-ranges.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-4.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-5.c: Likewise. * c-c++-common/cpp/pr88974.c: Likewise. * c-c++-common/cpp/va-opt-error.c: Likewise. * c-c++-common/cpp/va-opt-pedantic.c: Likewise. * c-c++-common/cpp/Wheader-guard-2.c: Likewise. * c-c++-common/cpp/Wheader-guard-3.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-1.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-2.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-3.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c: Likewise. * c-c++-common/pr68833-3.c: Likewise. * c-c++-common/raw-string-directive-1.c: Likewise. * gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise. * gcc.dg/binary-constants-4.c: Likewise. * gcc.dg/builtin-redefine.c: Likewise. * gcc.dg/cpp/19951025-1.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c23-elifdef-2.c: Likewise. * gcc.dg/cpp/c23-warning-2.c: Likewise. * gcc.dg/cpp/embed-2.c: Likewise. * gcc.dg/cpp/embed-3.c: Likewise. * gcc.dg/cpp/embed-4.c: Likewise. * gcc.dg/cpp/expr.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu23-warning-2.c: Likewise. * gcc.dg/cpp/include6.c: Likewise. * gcc.dg/cpp/pr35322.c: Likewise. * gcc.dg/cpp/tr-warn6.c: Likewise. * gcc.dg/cpp/undef2.c: Likewise. * gcc.dg/cpp/warn-comments.c: Likewise. * gcc.dg/cpp/warn-comments-2.c: Likewise. * gcc.dg/cpp/warn-comments-3.c: Likewise. * gcc.dg/cpp/warn-cxx-compat.c: Likewise. * gcc.dg/cpp/warn-cxx-compat-2.c: Likewise. * gcc.dg/cpp/warn-deprecated.c: Likewise. * gcc.dg/cpp/warn-deprecated-2.c: Likewise. * gcc.dg/cpp/warn-long-long.c: Likewise. * gcc.dg/cpp/warn-long-long-2.c: Likewise. * gcc.dg/cpp/warn-normalized-1.c: Likewise. * gcc.dg/cpp/warn-normalized-2.c: Likewise. * gcc.dg/cpp/warn-normalized-3.c: Likewise. * gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise. * gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise. * gcc.dg/cpp/warn-redefined.c: Likewise. * gcc.dg/cpp/warn-redefined-2.c: Likewise. * gcc.dg/cpp/warn-traditional.c: Likewise. * gcc.dg/cpp/warn-traditional-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-1.c: Likewise. * gcc.dg/cpp/warn-trigraphs-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-3.c: Likewise. * gcc.dg/cpp/warn-trigraphs-4.c: Likewise. * gcc.dg/cpp/warn-undef.c: Likewise. * gcc.dg/cpp/warn-undef-2.c: Likewise. * gcc.dg/cpp/warn-unused-macros.c: Likewise. * gcc.dg/cpp/warn-unused-macros-2.c: Likewise. * gcc.dg/pch/counter-2.c: Likewise. * g++.dg/cpp0x/udlit-error1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-1.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-3.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-4.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-5.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-6.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-7.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-8.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-9.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-10.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-11.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-12.C: Likewise. * g++.dg/cpp/elifdef-3.C: Likewise. * g++.dg/cpp/elifdef-5.C: Likewise. * g++.dg/cpp/elifdef-6.C: Likewise. * g++.dg/cpp/elifdef-7.C: Likewise. * g++.dg/cpp/embed-1.C: Likewise. * g++.dg/cpp/embed-2.C: Likewise. * g++.dg/cpp/pedantic-errors.C: Likewise. * g++.dg/cpp/warning-1.C: Likewise. * g++.dg/cpp/warning-2.C: Likewise. * g++.dg/ext/bitint1.C: Likewise. * g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
"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 18:51:15 +08: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))
libcpp: adjust pedwarn handling Using cpp_pedwarning (CPP_W_PEDANTIC instead of if (CPP_PEDANTIC cpp_error lets users suppress these diagnostics with #pragma GCC diagnostic ignored "-Wpedantic". This patch changes all instances of the cpp_error (CPP_DL_PEDWARN to cpp_pedwarning. In cases where the extension appears in a later C++ revision, we now condition the warning on the relevant -Wc++??-extensions flag instead of -Wpedantic; in such cases often the if (CPP_PEDANTIC) check is retained to preserve the default non-warning behavior. I didn't attempt to adjust the warning flags for the C compiler, since it seems to follow a different system than C++. The CPP_PEDANTIC check is also kept in _cpp_lex_direct to avoid an ICE in the self-tests from cb.diagnostics not being initialized. While working on testcases for these changes I noticed that the c-c++-common tests are not run with -pedantic-errors by default like the gcc.dg and g++.dg directories are. And if I specify -pedantic-errors with dg-options, the default -std= changes from c++?? to gnu++??, which interferes with some other pedwarns. So two of the tests are C++-only. libcpp/ChangeLog: * include/cpplib.h (enum cpp_warning_reason): Add CPP_W_CXX{14,17,20,23}_EXTENSIONS. * charset.cc (_cpp_valid_ucn, convert_hex, convert_oct) (convert_escape, narrow_str_to_charconst): Use cpp_pedwarning instead of cpp_error for pedwarns. * directives.cc (directive_diagnostics, _cpp_handle_directive) (do_line, do_elif): Likewise. * expr.cc (cpp_classify_number, eval_token): Likewise. * lex.cc (skip_whitespace, maybe_va_opt_error) (_cpp_lex_direct): Likewise. * macro.cc (_cpp_arguments_ok): Likewise. (replace_args): Use -Wvariadic-macros for pedwarn about empty macro arguments. gcc/c-family/ChangeLog: * c.opt: Add CppReason for Wc++{14,17,20,23}-extensions. * c-pragma.cc (handle_pragma_diagnostic_impl): Don't check OPT_Wc__23_extensions. gcc/testsuite/ChangeLog: * c-c++-common/pragma-diag-17.c: New test. * g++.dg/cpp0x/va-opt1.C: New test. * g++.dg/cpp23/named-universal-char-escape3.C: New test.
2024-08-28 01:15:16 +08:00
cpp_pedwarning_with_line (pfile, CPP_W_CXX17_EXTENSIONS,
virtual_location, 0, "use of C++17 "
"hexadecimal floating constant");
else
libcpp: adjust pedwarn handling Using cpp_pedwarning (CPP_W_PEDANTIC instead of if (CPP_PEDANTIC cpp_error lets users suppress these diagnostics with #pragma GCC diagnostic ignored "-Wpedantic". This patch changes all instances of the cpp_error (CPP_DL_PEDWARN to cpp_pedwarning. In cases where the extension appears in a later C++ revision, we now condition the warning on the relevant -Wc++??-extensions flag instead of -Wpedantic; in such cases often the if (CPP_PEDANTIC) check is retained to preserve the default non-warning behavior. I didn't attempt to adjust the warning flags for the C compiler, since it seems to follow a different system than C++. The CPP_PEDANTIC check is also kept in _cpp_lex_direct to avoid an ICE in the self-tests from cb.diagnostics not being initialized. While working on testcases for these changes I noticed that the c-c++-common tests are not run with -pedantic-errors by default like the gcc.dg and g++.dg directories are. And if I specify -pedantic-errors with dg-options, the default -std= changes from c++?? to gnu++??, which interferes with some other pedwarns. So two of the tests are C++-only. libcpp/ChangeLog: * include/cpplib.h (enum cpp_warning_reason): Add CPP_W_CXX{14,17,20,23}_EXTENSIONS. * charset.cc (_cpp_valid_ucn, convert_hex, convert_oct) (convert_escape, narrow_str_to_charconst): Use cpp_pedwarning instead of cpp_error for pedwarns. * directives.cc (directive_diagnostics, _cpp_handle_directive) (do_line, do_elif): Likewise. * expr.cc (cpp_classify_number, eval_token): Likewise. * lex.cc (skip_whitespace, maybe_va_opt_error) (_cpp_lex_direct): Likewise. * macro.cc (_cpp_arguments_ok): Likewise. (replace_args): Use -Wvariadic-macros for pedwarn about empty macro arguments. gcc/c-family/ChangeLog: * c.opt: Add CppReason for Wc++{14,17,20,23}-extensions. * c-pragma.cc (handle_pragma_diagnostic_impl): Don't check OPT_Wc__23_extensions. gcc/testsuite/ChangeLog: * c-c++-common/pragma-diag-17.c: New test. * g++.dg/cpp0x/va-opt1.C: New test. * g++.dg/cpp23/named-universal-char-escape3.C: New test.
2024-08-28 01:15:16 +08:00
cpp_pedwarning_with_line (pfile, CPP_W_PEDANTIC,
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 18:51:15 +08: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-27 03:30:59 +08: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 18:51:15 +08:00
cpp_error_with_line (pfile, CPP_DL_ERROR, virtual_location, 0,
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics When working on #embed support, or -Wheader-guard or other recent libcpp changes, I've been annoyed by the libcpp diagnostics being visually different from normal gcc diagnostics, especially in the area of quoting stuff in the diagnostic messages. Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use %</%>, %qs etc. in there, while libcpp diagnostics was marked as printf and in libcpp we've been very creative with quoting stuff, either no quotes at all, or "something" quoting, or 'something' quoting, or `something' quoting (but in none of the cases it used colors consistently with the rest of the compiler). Now, libcpp diagnostics is always emitted using a callback, pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with genmatch.cc: cb->diagnostic = diagnostic_cb; c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic; fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic; where the latter two just use diagnostic_report_diagnostic, so actually support all the gcc_diag stuff, only the genmatch.cc case didn't. So, the following patch changes genmatch.cc to use pp_format* instead of vfprintf so that it supports the gcc_diag formatting (pretty-print.o unfortunately has various dependencies, so had to link genmatch with libcommon.a libbacktrace.a and tweak Makefile.in so that there are no circular dependencies) and marks the libcpp diagnostic routines as gcc_diag rather than printf. That change resulted in hundreds of -Wformat-diag new warnings (most of them useful and resulting IMHO in better diagnostics), so the rest of the patch is changing the format strings to make -Wformat-diag happy and adjusting the testsuite for the differences in how is the diagnostic reformatted. Dunno if some out of GCC tree projects use libcpp, that case would make it harder because one couldn't use vfprintf in the diagnostic callback anymore, but there is always David's libdiagnostic which could be used for that purpose IMHO. 2024-10-12 Jakub Jelinek <jakub@redhat.com> libcpp/ * include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define. (struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF on diagnostic callback. (cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3. (cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. (cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6) instead of ATTRIBUTE_PRINTF_5. (cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. * Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather than --language=c. * errors.cc (cpp_diagnostic_at, cpp_diagnostic, cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of -ATTRIBUTE_FPTR_PRINTF. * charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex, convert_oct, convert_escape): Fix up -Wformat-diag warnings. (cpp_interpret_string_ranges, count_source_chars): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF. (narrow_str_to_charconst): Fix up -Wformat-diag warnings. * directives.cc (check_eol_1, directive_diagnostics, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, do_include_next, _cpp_parse_embed_params, do_embed, read_flag, do_line, do_linemarker, register_pragma_1, do_pragma_once, do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison, do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, do_assert, cpp_define_unused): Likewise. * expr.cc (cpp_classify_number, parse_defined, eval_token, _cpp_parse_expr, reduce, check_promotion): Likewise. * files.cc (_cpp_find_file, finish_base64_embed, _cpp_pop_file_buffer): Likewise. * init.cc (sanity_checks): Likewise. * lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char, _cpp_warn_invalid_utf8, _cpp_skip_block_comment, warn_about_normalization, forms_identifier_p, maybe_va_opt_error, identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise. * macro.cc (class vaopt_state, builtin_has_include_1, builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro, _cpp_builtin_macro_text, builtin_macro, stringify_arg, _cpp_arguments_ok, collect_args, enter_macro_context, _cpp_save_parameter, parse_params, create_iso_definition, _cpp_create_definition, check_trad_stringification): Likewise. * pch.cc (cpp_valid_state): Likewise. * traditional.cc (_cpp_scan_out_logical_line, recursive_macro): Likewise. gcc/ * Makefile.in (generated_files): Remove {gimple,generic}-match*. (generated_match_files): New variable. Add a dependency of $(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those. (build/genmatch$(build_exeext)): Depend on and link against libcommon.a and $(LIBBACKTRACE). * genmatch.cc: Include pretty-print.h and input.h. (ggc_internal_cleared_alloc, ggc_free): Remove. (fatal): New function. (line_table): Remove. (linemap_client_expand_location_to_spelling_point): Remove. (diagnostic_cb): Use gcc_diag rather than printf format. Use pp_format_verbatim on a temporary pretty_printer instead of vfprintf. (fatal_at, warning_at): Use gcc_diag rather than printf format. (output_line_directive): Rename location_hash to loc_hash. (parser::eat_ident, parser::parse_operation, parser::parse_expr, parser::parse_pattern, parser::finish_match_operand): Fix up -Wformat-diag warnings. gcc/c-family/ * c-lex.cc (c_common_has_attribute, c_common_lex_availability_macro): Fix up -Wformat-diag warnings. gcc/testsuite/ * c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for libcpp diagnostic formatting changes. * c-c++-common/cpp/embed-3.c: Likewise. * c-c++-common/cpp/embed-4.c: Likewise. * c-c++-common/cpp/embed-16.c: Likewise. * c-c++-common/cpp/embed-18.c: Likewise. * c-c++-common/cpp/eof-2.c: Likewise. * c-c++-common/cpp/eof-3.c: Likewise. * c-c++-common/cpp/fmax-include-depth.c: Likewise. * c-c++-common/cpp/has-builtin.c: Likewise. * c-c++-common/cpp/line-2.c: Likewise. * c-c++-common/cpp/line-3.c: Likewise. * c-c++-common/cpp/macro-arg-count-1.c: Likewise. * c-c++-common/cpp/macro-arg-count-2.c: Likewise. * c-c++-common/cpp/macro-ranges.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-4.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-5.c: Likewise. * c-c++-common/cpp/pr88974.c: Likewise. * c-c++-common/cpp/va-opt-error.c: Likewise. * c-c++-common/cpp/va-opt-pedantic.c: Likewise. * c-c++-common/cpp/Wheader-guard-2.c: Likewise. * c-c++-common/cpp/Wheader-guard-3.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-1.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-2.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-3.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c: Likewise. * c-c++-common/pr68833-3.c: Likewise. * c-c++-common/raw-string-directive-1.c: Likewise. * gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise. * gcc.dg/binary-constants-4.c: Likewise. * gcc.dg/builtin-redefine.c: Likewise. * gcc.dg/cpp/19951025-1.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c23-elifdef-2.c: Likewise. * gcc.dg/cpp/c23-warning-2.c: Likewise. * gcc.dg/cpp/embed-2.c: Likewise. * gcc.dg/cpp/embed-3.c: Likewise. * gcc.dg/cpp/embed-4.c: Likewise. * gcc.dg/cpp/expr.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu23-warning-2.c: Likewise. * gcc.dg/cpp/include6.c: Likewise. * gcc.dg/cpp/pr35322.c: Likewise. * gcc.dg/cpp/tr-warn6.c: Likewise. * gcc.dg/cpp/undef2.c: Likewise. * gcc.dg/cpp/warn-comments.c: Likewise. * gcc.dg/cpp/warn-comments-2.c: Likewise. * gcc.dg/cpp/warn-comments-3.c: Likewise. * gcc.dg/cpp/warn-cxx-compat.c: Likewise. * gcc.dg/cpp/warn-cxx-compat-2.c: Likewise. * gcc.dg/cpp/warn-deprecated.c: Likewise. * gcc.dg/cpp/warn-deprecated-2.c: Likewise. * gcc.dg/cpp/warn-long-long.c: Likewise. * gcc.dg/cpp/warn-long-long-2.c: Likewise. * gcc.dg/cpp/warn-normalized-1.c: Likewise. * gcc.dg/cpp/warn-normalized-2.c: Likewise. * gcc.dg/cpp/warn-normalized-3.c: Likewise. * gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise. * gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise. * gcc.dg/cpp/warn-redefined.c: Likewise. * gcc.dg/cpp/warn-redefined-2.c: Likewise. * gcc.dg/cpp/warn-traditional.c: Likewise. * gcc.dg/cpp/warn-traditional-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-1.c: Likewise. * gcc.dg/cpp/warn-trigraphs-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-3.c: Likewise. * gcc.dg/cpp/warn-trigraphs-4.c: Likewise. * gcc.dg/cpp/warn-undef.c: Likewise. * gcc.dg/cpp/warn-undef-2.c: Likewise. * gcc.dg/cpp/warn-unused-macros.c: Likewise. * gcc.dg/cpp/warn-unused-macros-2.c: Likewise. * gcc.dg/pch/counter-2.c: Likewise. * g++.dg/cpp0x/udlit-error1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-1.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-3.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-4.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-5.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-6.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-7.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-8.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-9.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-10.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-11.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-12.C: Likewise. * g++.dg/cpp/elifdef-3.C: Likewise. * g++.dg/cpp/elifdef-5.C: Likewise. * g++.dg/cpp/elifdef-6.C: Likewise. * g++.dg/cpp/elifdef-7.C: Likewise. * g++.dg/cpp/embed-1.C: Likewise. * g++.dg/cpp/embed-2.C: Likewise. * g++.dg/cpp/pedantic-errors.C: Likewise. * g++.dg/cpp/warning-1.C: Likewise. * g++.dg/cpp/warning-2.C: Likewise. * g++.dg/ext/bitint1.C: Likewise. * g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
"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-27 03:30:59 +08: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 18:51:15 +08:00
cpp_warning_with_line (pfile, CPP_W_TRADITIONAL, virtual_location, 0,
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics When working on #embed support, or -Wheader-guard or other recent libcpp changes, I've been annoyed by the libcpp diagnostics being visually different from normal gcc diagnostics, especially in the area of quoting stuff in the diagnostic messages. Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use %</%>, %qs etc. in there, while libcpp diagnostics was marked as printf and in libcpp we've been very creative with quoting stuff, either no quotes at all, or "something" quoting, or 'something' quoting, or `something' quoting (but in none of the cases it used colors consistently with the rest of the compiler). Now, libcpp diagnostics is always emitted using a callback, pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with genmatch.cc: cb->diagnostic = diagnostic_cb; c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic; fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic; where the latter two just use diagnostic_report_diagnostic, so actually support all the gcc_diag stuff, only the genmatch.cc case didn't. So, the following patch changes genmatch.cc to use pp_format* instead of vfprintf so that it supports the gcc_diag formatting (pretty-print.o unfortunately has various dependencies, so had to link genmatch with libcommon.a libbacktrace.a and tweak Makefile.in so that there are no circular dependencies) and marks the libcpp diagnostic routines as gcc_diag rather than printf. That change resulted in hundreds of -Wformat-diag new warnings (most of them useful and resulting IMHO in better diagnostics), so the rest of the patch is changing the format strings to make -Wformat-diag happy and adjusting the testsuite for the differences in how is the diagnostic reformatted. Dunno if some out of GCC tree projects use libcpp, that case would make it harder because one couldn't use vfprintf in the diagnostic callback anymore, but there is always David's libdiagnostic which could be used for that purpose IMHO. 2024-10-12 Jakub Jelinek <jakub@redhat.com> libcpp/ * include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define. (struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF on diagnostic callback. (cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3. (cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. (cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6) instead of ATTRIBUTE_PRINTF_5. (cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. * Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather than --language=c. * errors.cc (cpp_diagnostic_at, cpp_diagnostic, cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of -ATTRIBUTE_FPTR_PRINTF. * charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex, convert_oct, convert_escape): Fix up -Wformat-diag warnings. (cpp_interpret_string_ranges, count_source_chars): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF. (narrow_str_to_charconst): Fix up -Wformat-diag warnings. * directives.cc (check_eol_1, directive_diagnostics, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, do_include_next, _cpp_parse_embed_params, do_embed, read_flag, do_line, do_linemarker, register_pragma_1, do_pragma_once, do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison, do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, do_assert, cpp_define_unused): Likewise. * expr.cc (cpp_classify_number, parse_defined, eval_token, _cpp_parse_expr, reduce, check_promotion): Likewise. * files.cc (_cpp_find_file, finish_base64_embed, _cpp_pop_file_buffer): Likewise. * init.cc (sanity_checks): Likewise. * lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char, _cpp_warn_invalid_utf8, _cpp_skip_block_comment, warn_about_normalization, forms_identifier_p, maybe_va_opt_error, identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise. * macro.cc (class vaopt_state, builtin_has_include_1, builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro, _cpp_builtin_macro_text, builtin_macro, stringify_arg, _cpp_arguments_ok, collect_args, enter_macro_context, _cpp_save_parameter, parse_params, create_iso_definition, _cpp_create_definition, check_trad_stringification): Likewise. * pch.cc (cpp_valid_state): Likewise. * traditional.cc (_cpp_scan_out_logical_line, recursive_macro): Likewise. gcc/ * Makefile.in (generated_files): Remove {gimple,generic}-match*. (generated_match_files): New variable. Add a dependency of $(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those. (build/genmatch$(build_exeext)): Depend on and link against libcommon.a and $(LIBBACKTRACE). * genmatch.cc: Include pretty-print.h and input.h. (ggc_internal_cleared_alloc, ggc_free): Remove. (fatal): New function. (line_table): Remove. (linemap_client_expand_location_to_spelling_point): Remove. (diagnostic_cb): Use gcc_diag rather than printf format. Use pp_format_verbatim on a temporary pretty_printer instead of vfprintf. (fatal_at, warning_at): Use gcc_diag rather than printf format. (output_line_directive): Rename location_hash to loc_hash. (parser::eat_ident, parser::parse_operation, parser::parse_expr, parser::parse_pattern, parser::finish_match_operand): Fix up -Wformat-diag warnings. gcc/c-family/ * c-lex.cc (c_common_has_attribute, c_common_lex_availability_macro): Fix up -Wformat-diag warnings. gcc/testsuite/ * c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for libcpp diagnostic formatting changes. * c-c++-common/cpp/embed-3.c: Likewise. * c-c++-common/cpp/embed-4.c: Likewise. * c-c++-common/cpp/embed-16.c: Likewise. * c-c++-common/cpp/embed-18.c: Likewise. * c-c++-common/cpp/eof-2.c: Likewise. * c-c++-common/cpp/eof-3.c: Likewise. * c-c++-common/cpp/fmax-include-depth.c: Likewise. * c-c++-common/cpp/has-builtin.c: Likewise. * c-c++-common/cpp/line-2.c: Likewise. * c-c++-common/cpp/line-3.c: Likewise. * c-c++-common/cpp/macro-arg-count-1.c: Likewise. * c-c++-common/cpp/macro-arg-count-2.c: Likewise. * c-c++-common/cpp/macro-ranges.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-4.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-5.c: Likewise. * c-c++-common/cpp/pr88974.c: Likewise. * c-c++-common/cpp/va-opt-error.c: Likewise. * c-c++-common/cpp/va-opt-pedantic.c: Likewise. * c-c++-common/cpp/Wheader-guard-2.c: Likewise. * c-c++-common/cpp/Wheader-guard-3.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-1.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-2.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-3.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c: Likewise. * c-c++-common/pr68833-3.c: Likewise. * c-c++-common/raw-string-directive-1.c: Likewise. * gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise. * gcc.dg/binary-constants-4.c: Likewise. * gcc.dg/builtin-redefine.c: Likewise. * gcc.dg/cpp/19951025-1.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c23-elifdef-2.c: Likewise. * gcc.dg/cpp/c23-warning-2.c: Likewise. * gcc.dg/cpp/embed-2.c: Likewise. * gcc.dg/cpp/embed-3.c: Likewise. * gcc.dg/cpp/embed-4.c: Likewise. * gcc.dg/cpp/expr.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu23-warning-2.c: Likewise. * gcc.dg/cpp/include6.c: Likewise. * gcc.dg/cpp/pr35322.c: Likewise. * gcc.dg/cpp/tr-warn6.c: Likewise. * gcc.dg/cpp/undef2.c: Likewise. * gcc.dg/cpp/warn-comments.c: Likewise. * gcc.dg/cpp/warn-comments-2.c: Likewise. * gcc.dg/cpp/warn-comments-3.c: Likewise. * gcc.dg/cpp/warn-cxx-compat.c: Likewise. * gcc.dg/cpp/warn-cxx-compat-2.c: Likewise. * gcc.dg/cpp/warn-deprecated.c: Likewise. * gcc.dg/cpp/warn-deprecated-2.c: Likewise. * gcc.dg/cpp/warn-long-long.c: Likewise. * gcc.dg/cpp/warn-long-long-2.c: Likewise. * gcc.dg/cpp/warn-normalized-1.c: Likewise. * gcc.dg/cpp/warn-normalized-2.c: Likewise. * gcc.dg/cpp/warn-normalized-3.c: Likewise. * gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise. * gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise. * gcc.dg/cpp/warn-redefined.c: Likewise. * gcc.dg/cpp/warn-redefined-2.c: Likewise. * gcc.dg/cpp/warn-traditional.c: Likewise. * gcc.dg/cpp/warn-traditional-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-1.c: Likewise. * gcc.dg/cpp/warn-trigraphs-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-3.c: Likewise. * gcc.dg/cpp/warn-trigraphs-4.c: Likewise. * gcc.dg/cpp/warn-undef.c: Likewise. * gcc.dg/cpp/warn-undef-2.c: Likewise. * gcc.dg/cpp/warn-unused-macros.c: Likewise. * gcc.dg/cpp/warn-unused-macros-2.c: Likewise. * gcc.dg/pch/counter-2.c: Likewise. * g++.dg/cpp0x/udlit-error1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-1.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-3.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-4.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-5.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-6.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-7.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-8.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-9.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-10.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-11.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-12.C: Likewise. * g++.dg/cpp/elifdef-3.C: Likewise. * g++.dg/cpp/elifdef-5.C: Likewise. * g++.dg/cpp/elifdef-6.C: Likewise. * g++.dg/cpp/elifdef-7.C: Likewise. * g++.dg/cpp/embed-1.C: Likewise. * g++.dg/cpp/embed-2.C: Likewise. * g++.dg/cpp/pedantic-errors.C: Likewise. * g++.dg/cpp/warning-1.C: Likewise. * g++.dg/cpp/warning-2.C: Likewise. * g++.dg/ext/bitint1.C: Likewise. * g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
"traditional C rejects the %<%.*s%> suffix",
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 18:51:15 +08:00
(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. */
libcpp: adjust pedwarn handling Using cpp_pedwarning (CPP_W_PEDANTIC instead of if (CPP_PEDANTIC cpp_error lets users suppress these diagnostics with #pragma GCC diagnostic ignored "-Wpedantic". This patch changes all instances of the cpp_error (CPP_DL_PEDWARN to cpp_pedwarning. In cases where the extension appears in a later C++ revision, we now condition the warning on the relevant -Wc++??-extensions flag instead of -Wpedantic; in such cases often the if (CPP_PEDANTIC) check is retained to preserve the default non-warning behavior. I didn't attempt to adjust the warning flags for the C compiler, since it seems to follow a different system than C++. The CPP_PEDANTIC check is also kept in _cpp_lex_direct to avoid an ICE in the self-tests from cb.diagnostics not being initialized. While working on testcases for these changes I noticed that the c-c++-common tests are not run with -pedantic-errors by default like the gcc.dg and g++.dg directories are. And if I specify -pedantic-errors with dg-options, the default -std= changes from c++?? to gnu++??, which interferes with some other pedwarns. So two of the tests are C++-only. libcpp/ChangeLog: * include/cpplib.h (enum cpp_warning_reason): Add CPP_W_CXX{14,17,20,23}_EXTENSIONS. * charset.cc (_cpp_valid_ucn, convert_hex, convert_oct) (convert_escape, narrow_str_to_charconst): Use cpp_pedwarning instead of cpp_error for pedwarns. * directives.cc (directive_diagnostics, _cpp_handle_directive) (do_line, do_elif): Likewise. * expr.cc (cpp_classify_number, eval_token): Likewise. * lex.cc (skip_whitespace, maybe_va_opt_error) (_cpp_lex_direct): Likewise. * macro.cc (_cpp_arguments_ok): Likewise. (replace_args): Use -Wvariadic-macros for pedwarn about empty macro arguments. gcc/c-family/ChangeLog: * c.opt: Add CppReason for Wc++{14,17,20,23}-extensions. * c-pragma.cc (handle_pragma_diagnostic_impl): Don't check OPT_Wc__23_extensions. gcc/testsuite/ChangeLog: * c-c++-common/pragma-diag-17.c: New test. * g++.dg/cpp0x/va-opt1.C: New test. * g++.dg/cpp23/named-universal-char-escape3.C: New test.
2024-08-28 01:15:16 +08:00
if (result == CPP_N_MEDIUM)
cpp_pedwarning_with_line
(pfile, CPP_W_PEDANTIC, 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 18:51:15 +08:00
cpp_error_with_line (pfile, CPP_DL_ERROR, virtual_location, 0,
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics When working on #embed support, or -Wheader-guard or other recent libcpp changes, I've been annoyed by the libcpp diagnostics being visually different from normal gcc diagnostics, especially in the area of quoting stuff in the diagnostic messages. Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use %</%>, %qs etc. in there, while libcpp diagnostics was marked as printf and in libcpp we've been very creative with quoting stuff, either no quotes at all, or "something" quoting, or 'something' quoting, or `something' quoting (but in none of the cases it used colors consistently with the rest of the compiler). Now, libcpp diagnostics is always emitted using a callback, pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with genmatch.cc: cb->diagnostic = diagnostic_cb; c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic; fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic; where the latter two just use diagnostic_report_diagnostic, so actually support all the gcc_diag stuff, only the genmatch.cc case didn't. So, the following patch changes genmatch.cc to use pp_format* instead of vfprintf so that it supports the gcc_diag formatting (pretty-print.o unfortunately has various dependencies, so had to link genmatch with libcommon.a libbacktrace.a and tweak Makefile.in so that there are no circular dependencies) and marks the libcpp diagnostic routines as gcc_diag rather than printf. That change resulted in hundreds of -Wformat-diag new warnings (most of them useful and resulting IMHO in better diagnostics), so the rest of the patch is changing the format strings to make -Wformat-diag happy and adjusting the testsuite for the differences in how is the diagnostic reformatted. Dunno if some out of GCC tree projects use libcpp, that case would make it harder because one couldn't use vfprintf in the diagnostic callback anymore, but there is always David's libdiagnostic which could be used for that purpose IMHO. 2024-10-12 Jakub Jelinek <jakub@redhat.com> libcpp/ * include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define. (struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF on diagnostic callback. (cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3. (cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. (cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6) instead of ATTRIBUTE_PRINTF_5. (cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. * Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather than --language=c. * errors.cc (cpp_diagnostic_at, cpp_diagnostic, cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of -ATTRIBUTE_FPTR_PRINTF. * charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex, convert_oct, convert_escape): Fix up -Wformat-diag warnings. (cpp_interpret_string_ranges, count_source_chars): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF. (narrow_str_to_charconst): Fix up -Wformat-diag warnings. * directives.cc (check_eol_1, directive_diagnostics, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, do_include_next, _cpp_parse_embed_params, do_embed, read_flag, do_line, do_linemarker, register_pragma_1, do_pragma_once, do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison, do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, do_assert, cpp_define_unused): Likewise. * expr.cc (cpp_classify_number, parse_defined, eval_token, _cpp_parse_expr, reduce, check_promotion): Likewise. * files.cc (_cpp_find_file, finish_base64_embed, _cpp_pop_file_buffer): Likewise. * init.cc (sanity_checks): Likewise. * lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char, _cpp_warn_invalid_utf8, _cpp_skip_block_comment, warn_about_normalization, forms_identifier_p, maybe_va_opt_error, identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise. * macro.cc (class vaopt_state, builtin_has_include_1, builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro, _cpp_builtin_macro_text, builtin_macro, stringify_arg, _cpp_arguments_ok, collect_args, enter_macro_context, _cpp_save_parameter, parse_params, create_iso_definition, _cpp_create_definition, check_trad_stringification): Likewise. * pch.cc (cpp_valid_state): Likewise. * traditional.cc (_cpp_scan_out_logical_line, recursive_macro): Likewise. gcc/ * Makefile.in (generated_files): Remove {gimple,generic}-match*. (generated_match_files): New variable. Add a dependency of $(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those. (build/genmatch$(build_exeext)): Depend on and link against libcommon.a and $(LIBBACKTRACE). * genmatch.cc: Include pretty-print.h and input.h. (ggc_internal_cleared_alloc, ggc_free): Remove. (fatal): New function. (line_table): Remove. (linemap_client_expand_location_to_spelling_point): Remove. (diagnostic_cb): Use gcc_diag rather than printf format. Use pp_format_verbatim on a temporary pretty_printer instead of vfprintf. (fatal_at, warning_at): Use gcc_diag rather than printf format. (output_line_directive): Rename location_hash to loc_hash. (parser::eat_ident, parser::parse_operation, parser::parse_expr, parser::parse_pattern, parser::finish_match_operand): Fix up -Wformat-diag warnings. gcc/c-family/ * c-lex.cc (c_common_has_attribute, c_common_lex_availability_macro): Fix up -Wformat-diag warnings. gcc/testsuite/ * c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for libcpp diagnostic formatting changes. * c-c++-common/cpp/embed-3.c: Likewise. * c-c++-common/cpp/embed-4.c: Likewise. * c-c++-common/cpp/embed-16.c: Likewise. * c-c++-common/cpp/embed-18.c: Likewise. * c-c++-common/cpp/eof-2.c: Likewise. * c-c++-common/cpp/eof-3.c: Likewise. * c-c++-common/cpp/fmax-include-depth.c: Likewise. * c-c++-common/cpp/has-builtin.c: Likewise. * c-c++-common/cpp/line-2.c: Likewise. * c-c++-common/cpp/line-3.c: Likewise. * c-c++-common/cpp/macro-arg-count-1.c: Likewise. * c-c++-common/cpp/macro-arg-count-2.c: Likewise. * c-c++-common/cpp/macro-ranges.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-4.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-5.c: Likewise. * c-c++-common/cpp/pr88974.c: Likewise. * c-c++-common/cpp/va-opt-error.c: Likewise. * c-c++-common/cpp/va-opt-pedantic.c: Likewise. * c-c++-common/cpp/Wheader-guard-2.c: Likewise. * c-c++-common/cpp/Wheader-guard-3.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-1.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-2.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-3.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c: Likewise. * c-c++-common/pr68833-3.c: Likewise. * c-c++-common/raw-string-directive-1.c: Likewise. * gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise. * gcc.dg/binary-constants-4.c: Likewise. * gcc.dg/builtin-redefine.c: Likewise. * gcc.dg/cpp/19951025-1.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c23-elifdef-2.c: Likewise. * gcc.dg/cpp/c23-warning-2.c: Likewise. * gcc.dg/cpp/embed-2.c: Likewise. * gcc.dg/cpp/embed-3.c: Likewise. * gcc.dg/cpp/embed-4.c: Likewise. * gcc.dg/cpp/expr.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu23-warning-2.c: Likewise. * gcc.dg/cpp/include6.c: Likewise. * gcc.dg/cpp/pr35322.c: Likewise. * gcc.dg/cpp/tr-warn6.c: Likewise. * gcc.dg/cpp/undef2.c: Likewise. * gcc.dg/cpp/warn-comments.c: Likewise. * gcc.dg/cpp/warn-comments-2.c: Likewise. * gcc.dg/cpp/warn-comments-3.c: Likewise. * gcc.dg/cpp/warn-cxx-compat.c: Likewise. * gcc.dg/cpp/warn-cxx-compat-2.c: Likewise. * gcc.dg/cpp/warn-deprecated.c: Likewise. * gcc.dg/cpp/warn-deprecated-2.c: Likewise. * gcc.dg/cpp/warn-long-long.c: Likewise. * gcc.dg/cpp/warn-long-long-2.c: Likewise. * gcc.dg/cpp/warn-normalized-1.c: Likewise. * gcc.dg/cpp/warn-normalized-2.c: Likewise. * gcc.dg/cpp/warn-normalized-3.c: Likewise. * gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise. * gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise. * gcc.dg/cpp/warn-redefined.c: Likewise. * gcc.dg/cpp/warn-redefined-2.c: Likewise. * gcc.dg/cpp/warn-traditional.c: Likewise. * gcc.dg/cpp/warn-traditional-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-1.c: Likewise. * gcc.dg/cpp/warn-trigraphs-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-3.c: Likewise. * gcc.dg/cpp/warn-trigraphs-4.c: Likewise. * gcc.dg/cpp/warn-undef.c: Likewise. * gcc.dg/cpp/warn-undef-2.c: Likewise. * gcc.dg/cpp/warn-unused-macros.c: Likewise. * gcc.dg/cpp/warn-unused-macros-2.c: Likewise. * gcc.dg/pch/counter-2.c: Likewise. * g++.dg/cpp0x/udlit-error1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-1.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-3.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-4.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-5.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-6.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-7.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-8.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-9.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-10.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-11.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-12.C: Likewise. * g++.dg/cpp/elifdef-3.C: Likewise. * g++.dg/cpp/elifdef-5.C: Likewise. * g++.dg/cpp/elifdef-6.C: Likewise. * g++.dg/cpp/elifdef-7.C: Likewise. * g++.dg/cpp/embed-1.C: Likewise. * g++.dg/cpp/embed-2.C: Likewise. * g++.dg/cpp/pedantic-errors.C: Likewise. * g++.dg/cpp/warning-1.C: Likewise. * g++.dg/cpp/warning-2.C: Likewise. * g++.dg/ext/bitint1.C: Likewise. * g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
"invalid suffix %<%.*s%> with hexadecimal "
"floating constant", (int) (limit - str), str);
return CPP_N_INVALID;
}
libcpp: adjust pedwarn handling Using cpp_pedwarning (CPP_W_PEDANTIC instead of if (CPP_PEDANTIC cpp_error lets users suppress these diagnostics with #pragma GCC diagnostic ignored "-Wpedantic". This patch changes all instances of the cpp_error (CPP_DL_PEDWARN to cpp_pedwarning. In cases where the extension appears in a later C++ revision, we now condition the warning on the relevant -Wc++??-extensions flag instead of -Wpedantic; in such cases often the if (CPP_PEDANTIC) check is retained to preserve the default non-warning behavior. I didn't attempt to adjust the warning flags for the C compiler, since it seems to follow a different system than C++. The CPP_PEDANTIC check is also kept in _cpp_lex_direct to avoid an ICE in the self-tests from cb.diagnostics not being initialized. While working on testcases for these changes I noticed that the c-c++-common tests are not run with -pedantic-errors by default like the gcc.dg and g++.dg directories are. And if I specify -pedantic-errors with dg-options, the default -std= changes from c++?? to gnu++??, which interferes with some other pedwarns. So two of the tests are C++-only. libcpp/ChangeLog: * include/cpplib.h (enum cpp_warning_reason): Add CPP_W_CXX{14,17,20,23}_EXTENSIONS. * charset.cc (_cpp_valid_ucn, convert_hex, convert_oct) (convert_escape, narrow_str_to_charconst): Use cpp_pedwarning instead of cpp_error for pedwarns. * directives.cc (directive_diagnostics, _cpp_handle_directive) (do_line, do_elif): Likewise. * expr.cc (cpp_classify_number, eval_token): Likewise. * lex.cc (skip_whitespace, maybe_va_opt_error) (_cpp_lex_direct): Likewise. * macro.cc (_cpp_arguments_ok): Likewise. (replace_args): Use -Wvariadic-macros for pedwarn about empty macro arguments. gcc/c-family/ChangeLog: * c.opt: Add CppReason for Wc++{14,17,20,23}-extensions. * c-pragma.cc (handle_pragma_diagnostic_impl): Don't check OPT_Wc__23_extensions. gcc/testsuite/ChangeLog: * c-c++-common/pragma-diag-17.c: New test. * g++.dg/cpp0x/va-opt1.C: New test. * g++.dg/cpp23/named-universal-char-escape3.C: New test.
2024-08-28 01:15:16 +08:00
if (result & (CPP_N_FRACT | CPP_N_ACCUM))
cpp_pedwarning_with_line (pfile, CPP_W_PEDANTIC, virtual_location, 0,
"fixed-point constants are a GCC extension");
if (result & CPP_N_DFLOAT)
{
libcpp: adjust pedwarn handling Using cpp_pedwarning (CPP_W_PEDANTIC instead of if (CPP_PEDANTIC cpp_error lets users suppress these diagnostics with #pragma GCC diagnostic ignored "-Wpedantic". This patch changes all instances of the cpp_error (CPP_DL_PEDWARN to cpp_pedwarning. In cases where the extension appears in a later C++ revision, we now condition the warning on the relevant -Wc++??-extensions flag instead of -Wpedantic; in such cases often the if (CPP_PEDANTIC) check is retained to preserve the default non-warning behavior. I didn't attempt to adjust the warning flags for the C compiler, since it seems to follow a different system than C++. The CPP_PEDANTIC check is also kept in _cpp_lex_direct to avoid an ICE in the self-tests from cb.diagnostics not being initialized. While working on testcases for these changes I noticed that the c-c++-common tests are not run with -pedantic-errors by default like the gcc.dg and g++.dg directories are. And if I specify -pedantic-errors with dg-options, the default -std= changes from c++?? to gnu++??, which interferes with some other pedwarns. So two of the tests are C++-only. libcpp/ChangeLog: * include/cpplib.h (enum cpp_warning_reason): Add CPP_W_CXX{14,17,20,23}_EXTENSIONS. * charset.cc (_cpp_valid_ucn, convert_hex, convert_oct) (convert_escape, narrow_str_to_charconst): Use cpp_pedwarning instead of cpp_error for pedwarns. * directives.cc (directive_diagnostics, _cpp_handle_directive) (do_line, do_elif): Likewise. * expr.cc (cpp_classify_number, eval_token): Likewise. * lex.cc (skip_whitespace, maybe_va_opt_error) (_cpp_lex_direct): Likewise. * macro.cc (_cpp_arguments_ok): Likewise. (replace_args): Use -Wvariadic-macros for pedwarn about empty macro arguments. gcc/c-family/ChangeLog: * c.opt: Add CppReason for Wc++{14,17,20,23}-extensions. * c-pragma.cc (handle_pragma_diagnostic_impl): Don't check OPT_Wc__23_extensions. gcc/testsuite/ChangeLog: * c-c++-common/pragma-diag-17.c: New test. * g++.dg/cpp0x/va-opt1.C: New test. * g++.dg/cpp23/named-universal-char-escape3.C: New test.
2024-08-28 01:15:16 +08:00
if (!CPP_OPTION (pfile, dfp_constants))
cpp_pedwarning_with_line
(pfile, CPP_W_PEDANTIC, virtual_location, 0,
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics When working on #embed support, or -Wheader-guard or other recent libcpp changes, I've been annoyed by the libcpp diagnostics being visually different from normal gcc diagnostics, especially in the area of quoting stuff in the diagnostic messages. Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use %</%>, %qs etc. in there, while libcpp diagnostics was marked as printf and in libcpp we've been very creative with quoting stuff, either no quotes at all, or "something" quoting, or 'something' quoting, or `something' quoting (but in none of the cases it used colors consistently with the rest of the compiler). Now, libcpp diagnostics is always emitted using a callback, pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with genmatch.cc: cb->diagnostic = diagnostic_cb; c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic; fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic; where the latter two just use diagnostic_report_diagnostic, so actually support all the gcc_diag stuff, only the genmatch.cc case didn't. So, the following patch changes genmatch.cc to use pp_format* instead of vfprintf so that it supports the gcc_diag formatting (pretty-print.o unfortunately has various dependencies, so had to link genmatch with libcommon.a libbacktrace.a and tweak Makefile.in so that there are no circular dependencies) and marks the libcpp diagnostic routines as gcc_diag rather than printf. That change resulted in hundreds of -Wformat-diag new warnings (most of them useful and resulting IMHO in better diagnostics), so the rest of the patch is changing the format strings to make -Wformat-diag happy and adjusting the testsuite for the differences in how is the diagnostic reformatted. Dunno if some out of GCC tree projects use libcpp, that case would make it harder because one couldn't use vfprintf in the diagnostic callback anymore, but there is always David's libdiagnostic which could be used for that purpose IMHO. 2024-10-12 Jakub Jelinek <jakub@redhat.com> libcpp/ * include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define. (struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF on diagnostic callback. (cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3. (cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. (cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6) instead of ATTRIBUTE_PRINTF_5. (cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. * Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather than --language=c. * errors.cc (cpp_diagnostic_at, cpp_diagnostic, cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of -ATTRIBUTE_FPTR_PRINTF. * charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex, convert_oct, convert_escape): Fix up -Wformat-diag warnings. (cpp_interpret_string_ranges, count_source_chars): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF. (narrow_str_to_charconst): Fix up -Wformat-diag warnings. * directives.cc (check_eol_1, directive_diagnostics, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, do_include_next, _cpp_parse_embed_params, do_embed, read_flag, do_line, do_linemarker, register_pragma_1, do_pragma_once, do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison, do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, do_assert, cpp_define_unused): Likewise. * expr.cc (cpp_classify_number, parse_defined, eval_token, _cpp_parse_expr, reduce, check_promotion): Likewise. * files.cc (_cpp_find_file, finish_base64_embed, _cpp_pop_file_buffer): Likewise. * init.cc (sanity_checks): Likewise. * lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char, _cpp_warn_invalid_utf8, _cpp_skip_block_comment, warn_about_normalization, forms_identifier_p, maybe_va_opt_error, identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise. * macro.cc (class vaopt_state, builtin_has_include_1, builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro, _cpp_builtin_macro_text, builtin_macro, stringify_arg, _cpp_arguments_ok, collect_args, enter_macro_context, _cpp_save_parameter, parse_params, create_iso_definition, _cpp_create_definition, check_trad_stringification): Likewise. * pch.cc (cpp_valid_state): Likewise. * traditional.cc (_cpp_scan_out_logical_line, recursive_macro): Likewise. gcc/ * Makefile.in (generated_files): Remove {gimple,generic}-match*. (generated_match_files): New variable. Add a dependency of $(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those. (build/genmatch$(build_exeext)): Depend on and link against libcommon.a and $(LIBBACKTRACE). * genmatch.cc: Include pretty-print.h and input.h. (ggc_internal_cleared_alloc, ggc_free): Remove. (fatal): New function. (line_table): Remove. (linemap_client_expand_location_to_spelling_point): Remove. (diagnostic_cb): Use gcc_diag rather than printf format. Use pp_format_verbatim on a temporary pretty_printer instead of vfprintf. (fatal_at, warning_at): Use gcc_diag rather than printf format. (output_line_directive): Rename location_hash to loc_hash. (parser::eat_ident, parser::parse_operation, parser::parse_expr, parser::parse_pattern, parser::finish_match_operand): Fix up -Wformat-diag warnings. gcc/c-family/ * c-lex.cc (c_common_has_attribute, c_common_lex_availability_macro): Fix up -Wformat-diag warnings. gcc/testsuite/ * c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for libcpp diagnostic formatting changes. * c-c++-common/cpp/embed-3.c: Likewise. * c-c++-common/cpp/embed-4.c: Likewise. * c-c++-common/cpp/embed-16.c: Likewise. * c-c++-common/cpp/embed-18.c: Likewise. * c-c++-common/cpp/eof-2.c: Likewise. * c-c++-common/cpp/eof-3.c: Likewise. * c-c++-common/cpp/fmax-include-depth.c: Likewise. * c-c++-common/cpp/has-builtin.c: Likewise. * c-c++-common/cpp/line-2.c: Likewise. * c-c++-common/cpp/line-3.c: Likewise. * c-c++-common/cpp/macro-arg-count-1.c: Likewise. * c-c++-common/cpp/macro-arg-count-2.c: Likewise. * c-c++-common/cpp/macro-ranges.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-4.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-5.c: Likewise. * c-c++-common/cpp/pr88974.c: Likewise. * c-c++-common/cpp/va-opt-error.c: Likewise. * c-c++-common/cpp/va-opt-pedantic.c: Likewise. * c-c++-common/cpp/Wheader-guard-2.c: Likewise. * c-c++-common/cpp/Wheader-guard-3.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-1.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-2.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-3.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c: Likewise. * c-c++-common/pr68833-3.c: Likewise. * c-c++-common/raw-string-directive-1.c: Likewise. * gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise. * gcc.dg/binary-constants-4.c: Likewise. * gcc.dg/builtin-redefine.c: Likewise. * gcc.dg/cpp/19951025-1.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c23-elifdef-2.c: Likewise. * gcc.dg/cpp/c23-warning-2.c: Likewise. * gcc.dg/cpp/embed-2.c: Likewise. * gcc.dg/cpp/embed-3.c: Likewise. * gcc.dg/cpp/embed-4.c: Likewise. * gcc.dg/cpp/expr.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu23-warning-2.c: Likewise. * gcc.dg/cpp/include6.c: Likewise. * gcc.dg/cpp/pr35322.c: Likewise. * gcc.dg/cpp/tr-warn6.c: Likewise. * gcc.dg/cpp/undef2.c: Likewise. * gcc.dg/cpp/warn-comments.c: Likewise. * gcc.dg/cpp/warn-comments-2.c: Likewise. * gcc.dg/cpp/warn-comments-3.c: Likewise. * gcc.dg/cpp/warn-cxx-compat.c: Likewise. * gcc.dg/cpp/warn-cxx-compat-2.c: Likewise. * gcc.dg/cpp/warn-deprecated.c: Likewise. * gcc.dg/cpp/warn-deprecated-2.c: Likewise. * gcc.dg/cpp/warn-long-long.c: Likewise. * gcc.dg/cpp/warn-long-long-2.c: Likewise. * gcc.dg/cpp/warn-normalized-1.c: Likewise. * gcc.dg/cpp/warn-normalized-2.c: Likewise. * gcc.dg/cpp/warn-normalized-3.c: Likewise. * gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise. * gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise. * gcc.dg/cpp/warn-redefined.c: Likewise. * gcc.dg/cpp/warn-redefined-2.c: Likewise. * gcc.dg/cpp/warn-traditional.c: Likewise. * gcc.dg/cpp/warn-traditional-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-1.c: Likewise. * gcc.dg/cpp/warn-trigraphs-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-3.c: Likewise. * gcc.dg/cpp/warn-trigraphs-4.c: Likewise. * gcc.dg/cpp/warn-undef.c: Likewise. * gcc.dg/cpp/warn-undef-2.c: Likewise. * gcc.dg/cpp/warn-unused-macros.c: Likewise. * gcc.dg/cpp/warn-unused-macros-2.c: Likewise. * gcc.dg/pch/counter-2.c: Likewise. * g++.dg/cpp0x/udlit-error1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-1.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-3.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-4.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-5.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-6.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-7.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-8.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-9.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-10.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-11.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-12.C: Likewise. * g++.dg/cpp/elifdef-3.C: Likewise. * g++.dg/cpp/elifdef-5.C: Likewise. * g++.dg/cpp/elifdef-6.C: Likewise. * g++.dg/cpp/elifdef-7.C: Likewise. * g++.dg/cpp/embed-1.C: Likewise. * g++.dg/cpp/embed-2.C: Likewise. * g++.dg/cpp/pedantic-errors.C: Likewise. * g++.dg/cpp/warning-1.C: Likewise. * g++.dg/cpp/warning-2.C: Likewise. * g++.dg/ext/bitint1.C: Likewise. * g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
"decimal floating constants are a C23 feature");
c: Refer more consistently to C23 not C2X Continuing the move to refer to C23 in place of C2X throughout the source tree, update documentation, diagnostics, comments, variable and function names, etc., to use the C23 name. Testsuite updates are left for a future patch, except for testcases that test diagnostics that previously mentioned C2X (but in those testcases, sometimes other comments are updated, not just the diagnostic expectations). Bootstrapped with no regressions for x86_64-pc-linux-gnu. gcc/ * builtins.def (DEF_C2X_BUILTIN): Rename to DEF_C23_BUILTIN and use flag_isoc23 and function_c23_misc. * config/rl78/rl78.cc (rl78_option_override): Compare lang_hooks.name with "GNU C23" not "GNU C2X". * coretypes.h (function_c2x_misc): Rename to function_c23_misc. * doc/cpp.texi (@code{__has_attribute}): Refer to C23 instead of C2x. * doc/extend.texi: Likewise. * doc/invoke.texi: Likewise. * dwarf2out.cc (highest_c_language, gen_compile_unit_die): Compare against and return "GNU C23" language string instead of "GNU C2X". * ginclude/float.h: Refer to C23 instead of C2X in comments. * ginclude/stdint-gcc.h: Likewise. * glimits.h: Likewise. * tree.h: Likewise. gcc/ada/ * gcc-interface/utils.cc (flag_isoc2x): Rename to flag_isoc23. gcc/c-family/ * c-common.cc (flag_isoc2x): Rename to flag_isoc23. (c_common_reswords): Use D_C23 instead of D_C2X. * c-common.h: Refer throughout to C23 instead of C2X in comments. (D_C2X): Rename to D_C23. (flag_isoc2x): Rename to flag_isoc23. * c-cppbuiltin.cc (builtin_define_float_constants): Use flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2x in comments. * c-format.cc: Use STD_C23 instead of STD_C2X and flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2X in comments. * c-format.h: Use STD_C23 instead of STD_C2X. * c-lex.cc: Use warn_c11_c23_compat instead of warn_c11_c2x_compat and flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2X in diagnostics. * c-opts.cc: Use flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2X in comments. (set_std_c2x): Rename to set_std_c23. * c.opt (Wc11-c23-compat): Use CPP(cpp_warn_c11_c23_compat) CppReason(CPP_W_C11_C23_COMPAT) Var(warn_c11_c23_compat) instead of CPP(cpp_warn_c11_c2x_compat) CppReason(CPP_W_C11_C2X_COMPAT) Var(warn_c11_c2x_compat). gcc/c/ * c-decl.cc: Use flag_isoc23 instead of flag_isoc2x and c23_auto_p instead of c2x_auto_p. Refer to C23 instead of C2X in diagnostics and comments. * c-errors.cc: Use flag_isoc23 instead of flag_isoc2x and warn_c11_c23_compat instead of warn_c11_c2x_compat. Refer to C23 instead of C2X in comments. * c-parser.cc: Use flag_isoc23 instead of flag_isoc2x, warn_c11_c23_compat instead of warn_c11_c2x_compat, c23_auto_p instead of c2x_auto_p and D_C23 instead of D_C2X. Refer to C23 instead of C2X in diagnostics and comments. * c-tree.h: Refer to C23 instead of C2X in comments. (struct c_declspecs): Rename c2x_auto_p to c23_auto_p. * c-typeck.cc: Use flag_isoc23 instead of flag_isoc2x and warn_c11_c23_compat instead of warn_c11_c2x_compat. Refer to C23 instead of C2X in diagnostics and comments. gcc/fortran/ * gfortran.h (gfc_real_info): Refer to C23 instead of C2X in comment. gcc/lto/ * lto-lang.cc (flag_isoc2x): Rename to flag_isoc23. gcc/testsuite/ * gcc.dg/binary-constants-2.c: Refer to C23 instead of C2X. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/bitint-23.c: Likewise. * gcc.dg/bitint-26.c: Likewise. * gcc.dg/bitint-27.c: Likewise. * gcc.dg/c11-attr-syntax-1.c: Likewise. * gcc.dg/c11-attr-syntax-2.c: Likewise. * gcc.dg/c11-floatn-1.c: Likewise. * gcc.dg/c11-floatn-2.c: Likewise. * gcc.dg/c11-floatn-3.c: Likewise. * gcc.dg/c11-floatn-4.c: Likewise. * gcc.dg/c11-floatn-5.c: Likewise. * gcc.dg/c11-floatn-6.c: Likewise. * gcc.dg/c11-floatn-7.c: Likewise. * gcc.dg/c11-floatn-8.c: Likewise. * gcc.dg/c2x-attr-syntax-4.c: Likewise. * gcc.dg/c2x-attr-syntax-6.c: Likewise. * gcc.dg/c2x-attr-syntax-7.c: Likewise. * gcc.dg/c2x-binary-constants-2.c: Likewise. * gcc.dg/c2x-floatn-5.c: Likewise. * gcc.dg/c2x-floatn-6.c: Likewise. * gcc.dg/c2x-floatn-7.c: Likewise. * gcc.dg/c2x-floatn-8.c: Likewise. * gcc.dg/c2x-nullptr-4.c: Likewise. * gcc.dg/c2x-qual-2.c: Likewise. * gcc.dg/c2x-qual-3.c: Likewise. * gcc.dg/c2x-qual-6.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c2x-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu2x-warning-2.c: Likewise. * gcc.dg/dfp/c11-constants-1.c: Likewise. * gcc.dg/dfp/c11-constants-2.c: Likewise. * gcc.dg/dfp/c2x-constants-2.c: Likewise. * gcc.dg/dfp/constants-pedantic.c: Likewise. * gcc.dg/pr30260.c: Likewise. * gcc.dg/system-binary-constants-1.c: Likewise. libcpp/ * directives.cc: Refer to C23 instead of C2X in diagnostics and comments. (STDC2X): Rename to STDC23. * expr.cc: Use cpp_warn_c11_c23_compat instead of cpp_warn_c11_c2x_compat and CPP_W_C11_C23_COMPAT instead of CPP_W_C11_C2X_COMPAT. Refer to C23 instead of C2X in diagnostics and comments. * include/cpplib.h: Refer to C23 instead of C2X in diagnostics and comments. (CLK_GNUC2X): Rename to CLK_GNUC23. (CLK_STDC2X): Rename to CLK_STDC23. (CPP_W_C11_C2X_COMPAT): Rename to CPP_W_C11_C23_COMPAT. * init.cc: Use GNUC23 instead of GNUC2X, STDC23 instead of STDC2X and cpp_warn_c11_c23_compat instead of cpp_warn_c11_c2x_compat. * lex.cc (maybe_va_opt_error): Refer to C23 instead of C2X in diagnostic. * macro.cc (_cpp_arguments_ok): Refer to C23 instead of C2X in comment.
2023-11-07 22:19:36 +08:00
else if (CPP_OPTION (pfile, cpp_warn_c11_c23_compat) > 0)
cpp_warning_with_line (pfile, CPP_W_C11_C23_COMPAT,
virtual_location, 0,
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics When working on #embed support, or -Wheader-guard or other recent libcpp changes, I've been annoyed by the libcpp diagnostics being visually different from normal gcc diagnostics, especially in the area of quoting stuff in the diagnostic messages. Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use %</%>, %qs etc. in there, while libcpp diagnostics was marked as printf and in libcpp we've been very creative with quoting stuff, either no quotes at all, or "something" quoting, or 'something' quoting, or `something' quoting (but in none of the cases it used colors consistently with the rest of the compiler). Now, libcpp diagnostics is always emitted using a callback, pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with genmatch.cc: cb->diagnostic = diagnostic_cb; c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic; fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic; where the latter two just use diagnostic_report_diagnostic, so actually support all the gcc_diag stuff, only the genmatch.cc case didn't. So, the following patch changes genmatch.cc to use pp_format* instead of vfprintf so that it supports the gcc_diag formatting (pretty-print.o unfortunately has various dependencies, so had to link genmatch with libcommon.a libbacktrace.a and tweak Makefile.in so that there are no circular dependencies) and marks the libcpp diagnostic routines as gcc_diag rather than printf. That change resulted in hundreds of -Wformat-diag new warnings (most of them useful and resulting IMHO in better diagnostics), so the rest of the patch is changing the format strings to make -Wformat-diag happy and adjusting the testsuite for the differences in how is the diagnostic reformatted. Dunno if some out of GCC tree projects use libcpp, that case would make it harder because one couldn't use vfprintf in the diagnostic callback anymore, but there is always David's libdiagnostic which could be used for that purpose IMHO. 2024-10-12 Jakub Jelinek <jakub@redhat.com> libcpp/ * include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define. (struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF on diagnostic callback. (cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3. (cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. (cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6) instead of ATTRIBUTE_PRINTF_5. (cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. * Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather than --language=c. * errors.cc (cpp_diagnostic_at, cpp_diagnostic, cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of -ATTRIBUTE_FPTR_PRINTF. * charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex, convert_oct, convert_escape): Fix up -Wformat-diag warnings. (cpp_interpret_string_ranges, count_source_chars): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF. (narrow_str_to_charconst): Fix up -Wformat-diag warnings. * directives.cc (check_eol_1, directive_diagnostics, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, do_include_next, _cpp_parse_embed_params, do_embed, read_flag, do_line, do_linemarker, register_pragma_1, do_pragma_once, do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison, do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, do_assert, cpp_define_unused): Likewise. * expr.cc (cpp_classify_number, parse_defined, eval_token, _cpp_parse_expr, reduce, check_promotion): Likewise. * files.cc (_cpp_find_file, finish_base64_embed, _cpp_pop_file_buffer): Likewise. * init.cc (sanity_checks): Likewise. * lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char, _cpp_warn_invalid_utf8, _cpp_skip_block_comment, warn_about_normalization, forms_identifier_p, maybe_va_opt_error, identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise. * macro.cc (class vaopt_state, builtin_has_include_1, builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro, _cpp_builtin_macro_text, builtin_macro, stringify_arg, _cpp_arguments_ok, collect_args, enter_macro_context, _cpp_save_parameter, parse_params, create_iso_definition, _cpp_create_definition, check_trad_stringification): Likewise. * pch.cc (cpp_valid_state): Likewise. * traditional.cc (_cpp_scan_out_logical_line, recursive_macro): Likewise. gcc/ * Makefile.in (generated_files): Remove {gimple,generic}-match*. (generated_match_files): New variable. Add a dependency of $(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those. (build/genmatch$(build_exeext)): Depend on and link against libcommon.a and $(LIBBACKTRACE). * genmatch.cc: Include pretty-print.h and input.h. (ggc_internal_cleared_alloc, ggc_free): Remove. (fatal): New function. (line_table): Remove. (linemap_client_expand_location_to_spelling_point): Remove. (diagnostic_cb): Use gcc_diag rather than printf format. Use pp_format_verbatim on a temporary pretty_printer instead of vfprintf. (fatal_at, warning_at): Use gcc_diag rather than printf format. (output_line_directive): Rename location_hash to loc_hash. (parser::eat_ident, parser::parse_operation, parser::parse_expr, parser::parse_pattern, parser::finish_match_operand): Fix up -Wformat-diag warnings. gcc/c-family/ * c-lex.cc (c_common_has_attribute, c_common_lex_availability_macro): Fix up -Wformat-diag warnings. gcc/testsuite/ * c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for libcpp diagnostic formatting changes. * c-c++-common/cpp/embed-3.c: Likewise. * c-c++-common/cpp/embed-4.c: Likewise. * c-c++-common/cpp/embed-16.c: Likewise. * c-c++-common/cpp/embed-18.c: Likewise. * c-c++-common/cpp/eof-2.c: Likewise. * c-c++-common/cpp/eof-3.c: Likewise. * c-c++-common/cpp/fmax-include-depth.c: Likewise. * c-c++-common/cpp/has-builtin.c: Likewise. * c-c++-common/cpp/line-2.c: Likewise. * c-c++-common/cpp/line-3.c: Likewise. * c-c++-common/cpp/macro-arg-count-1.c: Likewise. * c-c++-common/cpp/macro-arg-count-2.c: Likewise. * c-c++-common/cpp/macro-ranges.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-4.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-5.c: Likewise. * c-c++-common/cpp/pr88974.c: Likewise. * c-c++-common/cpp/va-opt-error.c: Likewise. * c-c++-common/cpp/va-opt-pedantic.c: Likewise. * c-c++-common/cpp/Wheader-guard-2.c: Likewise. * c-c++-common/cpp/Wheader-guard-3.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-1.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-2.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-3.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c: Likewise. * c-c++-common/pr68833-3.c: Likewise. * c-c++-common/raw-string-directive-1.c: Likewise. * gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise. * gcc.dg/binary-constants-4.c: Likewise. * gcc.dg/builtin-redefine.c: Likewise. * gcc.dg/cpp/19951025-1.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c23-elifdef-2.c: Likewise. * gcc.dg/cpp/c23-warning-2.c: Likewise. * gcc.dg/cpp/embed-2.c: Likewise. * gcc.dg/cpp/embed-3.c: Likewise. * gcc.dg/cpp/embed-4.c: Likewise. * gcc.dg/cpp/expr.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu23-warning-2.c: Likewise. * gcc.dg/cpp/include6.c: Likewise. * gcc.dg/cpp/pr35322.c: Likewise. * gcc.dg/cpp/tr-warn6.c: Likewise. * gcc.dg/cpp/undef2.c: Likewise. * gcc.dg/cpp/warn-comments.c: Likewise. * gcc.dg/cpp/warn-comments-2.c: Likewise. * gcc.dg/cpp/warn-comments-3.c: Likewise. * gcc.dg/cpp/warn-cxx-compat.c: Likewise. * gcc.dg/cpp/warn-cxx-compat-2.c: Likewise. * gcc.dg/cpp/warn-deprecated.c: Likewise. * gcc.dg/cpp/warn-deprecated-2.c: Likewise. * gcc.dg/cpp/warn-long-long.c: Likewise. * gcc.dg/cpp/warn-long-long-2.c: Likewise. * gcc.dg/cpp/warn-normalized-1.c: Likewise. * gcc.dg/cpp/warn-normalized-2.c: Likewise. * gcc.dg/cpp/warn-normalized-3.c: Likewise. * gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise. * gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise. * gcc.dg/cpp/warn-redefined.c: Likewise. * gcc.dg/cpp/warn-redefined-2.c: Likewise. * gcc.dg/cpp/warn-traditional.c: Likewise. * gcc.dg/cpp/warn-traditional-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-1.c: Likewise. * gcc.dg/cpp/warn-trigraphs-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-3.c: Likewise. * gcc.dg/cpp/warn-trigraphs-4.c: Likewise. * gcc.dg/cpp/warn-undef.c: Likewise. * gcc.dg/cpp/warn-undef-2.c: Likewise. * gcc.dg/cpp/warn-unused-macros.c: Likewise. * gcc.dg/cpp/warn-unused-macros-2.c: Likewise. * gcc.dg/pch/counter-2.c: Likewise. * g++.dg/cpp0x/udlit-error1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-1.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-3.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-4.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-5.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-6.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-7.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-8.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-9.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-10.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-11.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-12.C: Likewise. * g++.dg/cpp/elifdef-3.C: Likewise. * g++.dg/cpp/elifdef-5.C: Likewise. * g++.dg/cpp/elifdef-6.C: Likewise. * g++.dg/cpp/elifdef-7.C: Likewise. * g++.dg/cpp/embed-1.C: Likewise. * g++.dg/cpp/embed-2.C: Likewise. * g++.dg/cpp/pedantic-errors.C: Likewise. * g++.dg/cpp/warning-1.C: Likewise. * g++.dg/cpp/warning-2.C: Likewise. * g++.dg/ext/bitint1.C: Likewise. * g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
"decimal floating constants are a C23 "
"feature");
}
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-27 03:30:59 +08: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 18:51:15 +08:00
cpp_error_with_line (pfile, CPP_DL_ERROR, virtual_location, 0,
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics When working on #embed support, or -Wheader-guard or other recent libcpp changes, I've been annoyed by the libcpp diagnostics being visually different from normal gcc diagnostics, especially in the area of quoting stuff in the diagnostic messages. Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use %</%>, %qs etc. in there, while libcpp diagnostics was marked as printf and in libcpp we've been very creative with quoting stuff, either no quotes at all, or "something" quoting, or 'something' quoting, or `something' quoting (but in none of the cases it used colors consistently with the rest of the compiler). Now, libcpp diagnostics is always emitted using a callback, pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with genmatch.cc: cb->diagnostic = diagnostic_cb; c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic; fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic; where the latter two just use diagnostic_report_diagnostic, so actually support all the gcc_diag stuff, only the genmatch.cc case didn't. So, the following patch changes genmatch.cc to use pp_format* instead of vfprintf so that it supports the gcc_diag formatting (pretty-print.o unfortunately has various dependencies, so had to link genmatch with libcommon.a libbacktrace.a and tweak Makefile.in so that there are no circular dependencies) and marks the libcpp diagnostic routines as gcc_diag rather than printf. That change resulted in hundreds of -Wformat-diag new warnings (most of them useful and resulting IMHO in better diagnostics), so the rest of the patch is changing the format strings to make -Wformat-diag happy and adjusting the testsuite for the differences in how is the diagnostic reformatted. Dunno if some out of GCC tree projects use libcpp, that case would make it harder because one couldn't use vfprintf in the diagnostic callback anymore, but there is always David's libdiagnostic which could be used for that purpose IMHO. 2024-10-12 Jakub Jelinek <jakub@redhat.com> libcpp/ * include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define. (struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF on diagnostic callback. (cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3. (cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. (cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6) instead of ATTRIBUTE_PRINTF_5. (cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. * Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather than --language=c. * errors.cc (cpp_diagnostic_at, cpp_diagnostic, cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of -ATTRIBUTE_FPTR_PRINTF. * charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex, convert_oct, convert_escape): Fix up -Wformat-diag warnings. (cpp_interpret_string_ranges, count_source_chars): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF. (narrow_str_to_charconst): Fix up -Wformat-diag warnings. * directives.cc (check_eol_1, directive_diagnostics, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, do_include_next, _cpp_parse_embed_params, do_embed, read_flag, do_line, do_linemarker, register_pragma_1, do_pragma_once, do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison, do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, do_assert, cpp_define_unused): Likewise. * expr.cc (cpp_classify_number, parse_defined, eval_token, _cpp_parse_expr, reduce, check_promotion): Likewise. * files.cc (_cpp_find_file, finish_base64_embed, _cpp_pop_file_buffer): Likewise. * init.cc (sanity_checks): Likewise. * lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char, _cpp_warn_invalid_utf8, _cpp_skip_block_comment, warn_about_normalization, forms_identifier_p, maybe_va_opt_error, identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise. * macro.cc (class vaopt_state, builtin_has_include_1, builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro, _cpp_builtin_macro_text, builtin_macro, stringify_arg, _cpp_arguments_ok, collect_args, enter_macro_context, _cpp_save_parameter, parse_params, create_iso_definition, _cpp_create_definition, check_trad_stringification): Likewise. * pch.cc (cpp_valid_state): Likewise. * traditional.cc (_cpp_scan_out_logical_line, recursive_macro): Likewise. gcc/ * Makefile.in (generated_files): Remove {gimple,generic}-match*. (generated_match_files): New variable. Add a dependency of $(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those. (build/genmatch$(build_exeext)): Depend on and link against libcommon.a and $(LIBBACKTRACE). * genmatch.cc: Include pretty-print.h and input.h. (ggc_internal_cleared_alloc, ggc_free): Remove. (fatal): New function. (line_table): Remove. (linemap_client_expand_location_to_spelling_point): Remove. (diagnostic_cb): Use gcc_diag rather than printf format. Use pp_format_verbatim on a temporary pretty_printer instead of vfprintf. (fatal_at, warning_at): Use gcc_diag rather than printf format. (output_line_directive): Rename location_hash to loc_hash. (parser::eat_ident, parser::parse_operation, parser::parse_expr, parser::parse_pattern, parser::finish_match_operand): Fix up -Wformat-diag warnings. gcc/c-family/ * c-lex.cc (c_common_has_attribute, c_common_lex_availability_macro): Fix up -Wformat-diag warnings. gcc/testsuite/ * c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for libcpp diagnostic formatting changes. * c-c++-common/cpp/embed-3.c: Likewise. * c-c++-common/cpp/embed-4.c: Likewise. * c-c++-common/cpp/embed-16.c: Likewise. * c-c++-common/cpp/embed-18.c: Likewise. * c-c++-common/cpp/eof-2.c: Likewise. * c-c++-common/cpp/eof-3.c: Likewise. * c-c++-common/cpp/fmax-include-depth.c: Likewise. * c-c++-common/cpp/has-builtin.c: Likewise. * c-c++-common/cpp/line-2.c: Likewise. * c-c++-common/cpp/line-3.c: Likewise. * c-c++-common/cpp/macro-arg-count-1.c: Likewise. * c-c++-common/cpp/macro-arg-count-2.c: Likewise. * c-c++-common/cpp/macro-ranges.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-4.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-5.c: Likewise. * c-c++-common/cpp/pr88974.c: Likewise. * c-c++-common/cpp/va-opt-error.c: Likewise. * c-c++-common/cpp/va-opt-pedantic.c: Likewise. * c-c++-common/cpp/Wheader-guard-2.c: Likewise. * c-c++-common/cpp/Wheader-guard-3.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-1.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-2.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-3.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c: Likewise. * c-c++-common/pr68833-3.c: Likewise. * c-c++-common/raw-string-directive-1.c: Likewise. * gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise. * gcc.dg/binary-constants-4.c: Likewise. * gcc.dg/builtin-redefine.c: Likewise. * gcc.dg/cpp/19951025-1.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c23-elifdef-2.c: Likewise. * gcc.dg/cpp/c23-warning-2.c: Likewise. * gcc.dg/cpp/embed-2.c: Likewise. * gcc.dg/cpp/embed-3.c: Likewise. * gcc.dg/cpp/embed-4.c: Likewise. * gcc.dg/cpp/expr.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu23-warning-2.c: Likewise. * gcc.dg/cpp/include6.c: Likewise. * gcc.dg/cpp/pr35322.c: Likewise. * gcc.dg/cpp/tr-warn6.c: Likewise. * gcc.dg/cpp/undef2.c: Likewise. * gcc.dg/cpp/warn-comments.c: Likewise. * gcc.dg/cpp/warn-comments-2.c: Likewise. * gcc.dg/cpp/warn-comments-3.c: Likewise. * gcc.dg/cpp/warn-cxx-compat.c: Likewise. * gcc.dg/cpp/warn-cxx-compat-2.c: Likewise. * gcc.dg/cpp/warn-deprecated.c: Likewise. * gcc.dg/cpp/warn-deprecated-2.c: Likewise. * gcc.dg/cpp/warn-long-long.c: Likewise. * gcc.dg/cpp/warn-long-long-2.c: Likewise. * gcc.dg/cpp/warn-normalized-1.c: Likewise. * gcc.dg/cpp/warn-normalized-2.c: Likewise. * gcc.dg/cpp/warn-normalized-3.c: Likewise. * gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise. * gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise. * gcc.dg/cpp/warn-redefined.c: Likewise. * gcc.dg/cpp/warn-redefined-2.c: Likewise. * gcc.dg/cpp/warn-traditional.c: Likewise. * gcc.dg/cpp/warn-traditional-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-1.c: Likewise. * gcc.dg/cpp/warn-trigraphs-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-3.c: Likewise. * gcc.dg/cpp/warn-trigraphs-4.c: Likewise. * gcc.dg/cpp/warn-undef.c: Likewise. * gcc.dg/cpp/warn-undef-2.c: Likewise. * gcc.dg/cpp/warn-unused-macros.c: Likewise. * gcc.dg/cpp/warn-unused-macros-2.c: Likewise. * gcc.dg/pch/counter-2.c: Likewise. * g++.dg/cpp0x/udlit-error1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-1.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-3.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-4.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-5.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-6.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-7.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-8.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-9.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-10.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-11.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-12.C: Likewise. * g++.dg/cpp/elifdef-3.C: Likewise. * g++.dg/cpp/elifdef-5.C: Likewise. * g++.dg/cpp/elifdef-6.C: Likewise. * g++.dg/cpp/elifdef-7.C: Likewise. * g++.dg/cpp/embed-1.C: Likewise. * g++.dg/cpp/embed-2.C: Likewise. * g++.dg/cpp/pedantic-errors.C: Likewise. * g++.dg/cpp/warning-1.C: Likewise. * g++.dg/cpp/warning-2.C: Likewise. * g++.dg/ext/bitint1.C: Likewise. * g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
"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-27 03:30:59 +08: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-08 01:18:10 +08: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 22:49:14 +08: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-08 01:18:10 +08: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 18:51:15 +08:00
cpp_warning_with_line (pfile, large ? CPP_W_LONG_LONG : CPP_W_TRADITIONAL,
virtual_location, 0,
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics When working on #embed support, or -Wheader-guard or other recent libcpp changes, I've been annoyed by the libcpp diagnostics being visually different from normal gcc diagnostics, especially in the area of quoting stuff in the diagnostic messages. Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use %</%>, %qs etc. in there, while libcpp diagnostics was marked as printf and in libcpp we've been very creative with quoting stuff, either no quotes at all, or "something" quoting, or 'something' quoting, or `something' quoting (but in none of the cases it used colors consistently with the rest of the compiler). Now, libcpp diagnostics is always emitted using a callback, pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with genmatch.cc: cb->diagnostic = diagnostic_cb; c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic; fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic; where the latter two just use diagnostic_report_diagnostic, so actually support all the gcc_diag stuff, only the genmatch.cc case didn't. So, the following patch changes genmatch.cc to use pp_format* instead of vfprintf so that it supports the gcc_diag formatting (pretty-print.o unfortunately has various dependencies, so had to link genmatch with libcommon.a libbacktrace.a and tweak Makefile.in so that there are no circular dependencies) and marks the libcpp diagnostic routines as gcc_diag rather than printf. That change resulted in hundreds of -Wformat-diag new warnings (most of them useful and resulting IMHO in better diagnostics), so the rest of the patch is changing the format strings to make -Wformat-diag happy and adjusting the testsuite for the differences in how is the diagnostic reformatted. Dunno if some out of GCC tree projects use libcpp, that case would make it harder because one couldn't use vfprintf in the diagnostic callback anymore, but there is always David's libdiagnostic which could be used for that purpose IMHO. 2024-10-12 Jakub Jelinek <jakub@redhat.com> libcpp/ * include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define. (struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF on diagnostic callback. (cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3. (cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. (cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6) instead of ATTRIBUTE_PRINTF_5. (cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. * Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather than --language=c. * errors.cc (cpp_diagnostic_at, cpp_diagnostic, cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of -ATTRIBUTE_FPTR_PRINTF. * charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex, convert_oct, convert_escape): Fix up -Wformat-diag warnings. (cpp_interpret_string_ranges, count_source_chars): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF. (narrow_str_to_charconst): Fix up -Wformat-diag warnings. * directives.cc (check_eol_1, directive_diagnostics, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, do_include_next, _cpp_parse_embed_params, do_embed, read_flag, do_line, do_linemarker, register_pragma_1, do_pragma_once, do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison, do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, do_assert, cpp_define_unused): Likewise. * expr.cc (cpp_classify_number, parse_defined, eval_token, _cpp_parse_expr, reduce, check_promotion): Likewise. * files.cc (_cpp_find_file, finish_base64_embed, _cpp_pop_file_buffer): Likewise. * init.cc (sanity_checks): Likewise. * lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char, _cpp_warn_invalid_utf8, _cpp_skip_block_comment, warn_about_normalization, forms_identifier_p, maybe_va_opt_error, identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise. * macro.cc (class vaopt_state, builtin_has_include_1, builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro, _cpp_builtin_macro_text, builtin_macro, stringify_arg, _cpp_arguments_ok, collect_args, enter_macro_context, _cpp_save_parameter, parse_params, create_iso_definition, _cpp_create_definition, check_trad_stringification): Likewise. * pch.cc (cpp_valid_state): Likewise. * traditional.cc (_cpp_scan_out_logical_line, recursive_macro): Likewise. gcc/ * Makefile.in (generated_files): Remove {gimple,generic}-match*. (generated_match_files): New variable. Add a dependency of $(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those. (build/genmatch$(build_exeext)): Depend on and link against libcommon.a and $(LIBBACKTRACE). * genmatch.cc: Include pretty-print.h and input.h. (ggc_internal_cleared_alloc, ggc_free): Remove. (fatal): New function. (line_table): Remove. (linemap_client_expand_location_to_spelling_point): Remove. (diagnostic_cb): Use gcc_diag rather than printf format. Use pp_format_verbatim on a temporary pretty_printer instead of vfprintf. (fatal_at, warning_at): Use gcc_diag rather than printf format. (output_line_directive): Rename location_hash to loc_hash. (parser::eat_ident, parser::parse_operation, parser::parse_expr, parser::parse_pattern, parser::finish_match_operand): Fix up -Wformat-diag warnings. gcc/c-family/ * c-lex.cc (c_common_has_attribute, c_common_lex_availability_macro): Fix up -Wformat-diag warnings. gcc/testsuite/ * c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for libcpp diagnostic formatting changes. * c-c++-common/cpp/embed-3.c: Likewise. * c-c++-common/cpp/embed-4.c: Likewise. * c-c++-common/cpp/embed-16.c: Likewise. * c-c++-common/cpp/embed-18.c: Likewise. * c-c++-common/cpp/eof-2.c: Likewise. * c-c++-common/cpp/eof-3.c: Likewise. * c-c++-common/cpp/fmax-include-depth.c: Likewise. * c-c++-common/cpp/has-builtin.c: Likewise. * c-c++-common/cpp/line-2.c: Likewise. * c-c++-common/cpp/line-3.c: Likewise. * c-c++-common/cpp/macro-arg-count-1.c: Likewise. * c-c++-common/cpp/macro-arg-count-2.c: Likewise. * c-c++-common/cpp/macro-ranges.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-4.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-5.c: Likewise. * c-c++-common/cpp/pr88974.c: Likewise. * c-c++-common/cpp/va-opt-error.c: Likewise. * c-c++-common/cpp/va-opt-pedantic.c: Likewise. * c-c++-common/cpp/Wheader-guard-2.c: Likewise. * c-c++-common/cpp/Wheader-guard-3.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-1.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-2.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-3.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c: Likewise. * c-c++-common/pr68833-3.c: Likewise. * c-c++-common/raw-string-directive-1.c: Likewise. * gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise. * gcc.dg/binary-constants-4.c: Likewise. * gcc.dg/builtin-redefine.c: Likewise. * gcc.dg/cpp/19951025-1.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c23-elifdef-2.c: Likewise. * gcc.dg/cpp/c23-warning-2.c: Likewise. * gcc.dg/cpp/embed-2.c: Likewise. * gcc.dg/cpp/embed-3.c: Likewise. * gcc.dg/cpp/embed-4.c: Likewise. * gcc.dg/cpp/expr.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu23-warning-2.c: Likewise. * gcc.dg/cpp/include6.c: Likewise. * gcc.dg/cpp/pr35322.c: Likewise. * gcc.dg/cpp/tr-warn6.c: Likewise. * gcc.dg/cpp/undef2.c: Likewise. * gcc.dg/cpp/warn-comments.c: Likewise. * gcc.dg/cpp/warn-comments-2.c: Likewise. * gcc.dg/cpp/warn-comments-3.c: Likewise. * gcc.dg/cpp/warn-cxx-compat.c: Likewise. * gcc.dg/cpp/warn-cxx-compat-2.c: Likewise. * gcc.dg/cpp/warn-deprecated.c: Likewise. * gcc.dg/cpp/warn-deprecated-2.c: Likewise. * gcc.dg/cpp/warn-long-long.c: Likewise. * gcc.dg/cpp/warn-long-long-2.c: Likewise. * gcc.dg/cpp/warn-normalized-1.c: Likewise. * gcc.dg/cpp/warn-normalized-2.c: Likewise. * gcc.dg/cpp/warn-normalized-3.c: Likewise. * gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise. * gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise. * gcc.dg/cpp/warn-redefined.c: Likewise. * gcc.dg/cpp/warn-redefined-2.c: Likewise. * gcc.dg/cpp/warn-traditional.c: Likewise. * gcc.dg/cpp/warn-traditional-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-1.c: Likewise. * gcc.dg/cpp/warn-trigraphs-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-3.c: Likewise. * gcc.dg/cpp/warn-trigraphs-4.c: Likewise. * gcc.dg/cpp/warn-undef.c: Likewise. * gcc.dg/cpp/warn-undef-2.c: Likewise. * gcc.dg/cpp/warn-unused-macros.c: Likewise. * gcc.dg/cpp/warn-unused-macros-2.c: Likewise. * gcc.dg/pch/counter-2.c: Likewise. * g++.dg/cpp0x/udlit-error1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-1.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-3.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-4.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-5.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-6.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-7.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-8.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-9.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-10.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-11.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-12.C: Likewise. * g++.dg/cpp/elifdef-3.C: Likewise. * g++.dg/cpp/elifdef-5.C: Likewise. * g++.dg/cpp/elifdef-6.C: Likewise. * g++.dg/cpp/elifdef-7.C: Likewise. * g++.dg/cpp/embed-1.C: Likewise. * g++.dg/cpp/embed-2.C: Likewise. * g++.dg/cpp/pedantic-errors.C: Likewise. * g++.dg/cpp/warning-1.C: Likewise. * g++.dg/cpp/warning-2.C: Likewise. * g++.dg/ext/bitint1.C: Likewise. * g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
"traditional C rejects the %<%.*s%> suffix",
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 18:51:15 +08:00
(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 22:49:14 +08: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-08 01:18:10 +08: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-08 01:18:10 +08: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 18:51:15 +08: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-08 01:18:10 +08: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 18:51:15 +08: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-08 01:18:10 +08:00
}
if ((result & CPP_N_SIZE_T) == CPP_N_SIZE_T
&& !CPP_OPTION (pfile, size_t_literals))
{
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics When working on #embed support, or -Wheader-guard or other recent libcpp changes, I've been annoyed by the libcpp diagnostics being visually different from normal gcc diagnostics, especially in the area of quoting stuff in the diagnostic messages. Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use %</%>, %qs etc. in there, while libcpp diagnostics was marked as printf and in libcpp we've been very creative with quoting stuff, either no quotes at all, or "something" quoting, or 'something' quoting, or `something' quoting (but in none of the cases it used colors consistently with the rest of the compiler). Now, libcpp diagnostics is always emitted using a callback, pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with genmatch.cc: cb->diagnostic = diagnostic_cb; c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic; fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic; where the latter two just use diagnostic_report_diagnostic, so actually support all the gcc_diag stuff, only the genmatch.cc case didn't. So, the following patch changes genmatch.cc to use pp_format* instead of vfprintf so that it supports the gcc_diag formatting (pretty-print.o unfortunately has various dependencies, so had to link genmatch with libcommon.a libbacktrace.a and tweak Makefile.in so that there are no circular dependencies) and marks the libcpp diagnostic routines as gcc_diag rather than printf. That change resulted in hundreds of -Wformat-diag new warnings (most of them useful and resulting IMHO in better diagnostics), so the rest of the patch is changing the format strings to make -Wformat-diag happy and adjusting the testsuite for the differences in how is the diagnostic reformatted. Dunno if some out of GCC tree projects use libcpp, that case would make it harder because one couldn't use vfprintf in the diagnostic callback anymore, but there is always David's libdiagnostic which could be used for that purpose IMHO. 2024-10-12 Jakub Jelinek <jakub@redhat.com> libcpp/ * include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define. (struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF on diagnostic callback. (cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3. (cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. (cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6) instead of ATTRIBUTE_PRINTF_5. (cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. * Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather than --language=c. * errors.cc (cpp_diagnostic_at, cpp_diagnostic, cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of -ATTRIBUTE_FPTR_PRINTF. * charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex, convert_oct, convert_escape): Fix up -Wformat-diag warnings. (cpp_interpret_string_ranges, count_source_chars): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF. (narrow_str_to_charconst): Fix up -Wformat-diag warnings. * directives.cc (check_eol_1, directive_diagnostics, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, do_include_next, _cpp_parse_embed_params, do_embed, read_flag, do_line, do_linemarker, register_pragma_1, do_pragma_once, do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison, do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, do_assert, cpp_define_unused): Likewise. * expr.cc (cpp_classify_number, parse_defined, eval_token, _cpp_parse_expr, reduce, check_promotion): Likewise. * files.cc (_cpp_find_file, finish_base64_embed, _cpp_pop_file_buffer): Likewise. * init.cc (sanity_checks): Likewise. * lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char, _cpp_warn_invalid_utf8, _cpp_skip_block_comment, warn_about_normalization, forms_identifier_p, maybe_va_opt_error, identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise. * macro.cc (class vaopt_state, builtin_has_include_1, builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro, _cpp_builtin_macro_text, builtin_macro, stringify_arg, _cpp_arguments_ok, collect_args, enter_macro_context, _cpp_save_parameter, parse_params, create_iso_definition, _cpp_create_definition, check_trad_stringification): Likewise. * pch.cc (cpp_valid_state): Likewise. * traditional.cc (_cpp_scan_out_logical_line, recursive_macro): Likewise. gcc/ * Makefile.in (generated_files): Remove {gimple,generic}-match*. (generated_match_files): New variable. Add a dependency of $(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those. (build/genmatch$(build_exeext)): Depend on and link against libcommon.a and $(LIBBACKTRACE). * genmatch.cc: Include pretty-print.h and input.h. (ggc_internal_cleared_alloc, ggc_free): Remove. (fatal): New function. (line_table): Remove. (linemap_client_expand_location_to_spelling_point): Remove. (diagnostic_cb): Use gcc_diag rather than printf format. Use pp_format_verbatim on a temporary pretty_printer instead of vfprintf. (fatal_at, warning_at): Use gcc_diag rather than printf format. (output_line_directive): Rename location_hash to loc_hash. (parser::eat_ident, parser::parse_operation, parser::parse_expr, parser::parse_pattern, parser::finish_match_operand): Fix up -Wformat-diag warnings. gcc/c-family/ * c-lex.cc (c_common_has_attribute, c_common_lex_availability_macro): Fix up -Wformat-diag warnings. gcc/testsuite/ * c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for libcpp diagnostic formatting changes. * c-c++-common/cpp/embed-3.c: Likewise. * c-c++-common/cpp/embed-4.c: Likewise. * c-c++-common/cpp/embed-16.c: Likewise. * c-c++-common/cpp/embed-18.c: Likewise. * c-c++-common/cpp/eof-2.c: Likewise. * c-c++-common/cpp/eof-3.c: Likewise. * c-c++-common/cpp/fmax-include-depth.c: Likewise. * c-c++-common/cpp/has-builtin.c: Likewise. * c-c++-common/cpp/line-2.c: Likewise. * c-c++-common/cpp/line-3.c: Likewise. * c-c++-common/cpp/macro-arg-count-1.c: Likewise. * c-c++-common/cpp/macro-arg-count-2.c: Likewise. * c-c++-common/cpp/macro-ranges.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-4.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-5.c: Likewise. * c-c++-common/cpp/pr88974.c: Likewise. * c-c++-common/cpp/va-opt-error.c: Likewise. * c-c++-common/cpp/va-opt-pedantic.c: Likewise. * c-c++-common/cpp/Wheader-guard-2.c: Likewise. * c-c++-common/cpp/Wheader-guard-3.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-1.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-2.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-3.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c: Likewise. * c-c++-common/pr68833-3.c: Likewise. * c-c++-common/raw-string-directive-1.c: Likewise. * gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise. * gcc.dg/binary-constants-4.c: Likewise. * gcc.dg/builtin-redefine.c: Likewise. * gcc.dg/cpp/19951025-1.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c23-elifdef-2.c: Likewise. * gcc.dg/cpp/c23-warning-2.c: Likewise. * gcc.dg/cpp/embed-2.c: Likewise. * gcc.dg/cpp/embed-3.c: Likewise. * gcc.dg/cpp/embed-4.c: Likewise. * gcc.dg/cpp/expr.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu23-warning-2.c: Likewise. * gcc.dg/cpp/include6.c: Likewise. * gcc.dg/cpp/pr35322.c: Likewise. * gcc.dg/cpp/tr-warn6.c: Likewise. * gcc.dg/cpp/undef2.c: Likewise. * gcc.dg/cpp/warn-comments.c: Likewise. * gcc.dg/cpp/warn-comments-2.c: Likewise. * gcc.dg/cpp/warn-comments-3.c: Likewise. * gcc.dg/cpp/warn-cxx-compat.c: Likewise. * gcc.dg/cpp/warn-cxx-compat-2.c: Likewise. * gcc.dg/cpp/warn-deprecated.c: Likewise. * gcc.dg/cpp/warn-deprecated-2.c: Likewise. * gcc.dg/cpp/warn-long-long.c: Likewise. * gcc.dg/cpp/warn-long-long-2.c: Likewise. * gcc.dg/cpp/warn-normalized-1.c: Likewise. * gcc.dg/cpp/warn-normalized-2.c: Likewise. * gcc.dg/cpp/warn-normalized-3.c: Likewise. * gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise. * gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise. * gcc.dg/cpp/warn-redefined.c: Likewise. * gcc.dg/cpp/warn-redefined-2.c: Likewise. * gcc.dg/cpp/warn-traditional.c: Likewise. * gcc.dg/cpp/warn-traditional-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-1.c: Likewise. * gcc.dg/cpp/warn-trigraphs-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-3.c: Likewise. * gcc.dg/cpp/warn-trigraphs-4.c: Likewise. * gcc.dg/cpp/warn-undef.c: Likewise. * gcc.dg/cpp/warn-undef-2.c: Likewise. * gcc.dg/cpp/warn-unused-macros.c: Likewise. * gcc.dg/cpp/warn-unused-macros-2.c: Likewise. * gcc.dg/pch/counter-2.c: Likewise. * g++.dg/cpp0x/udlit-error1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-1.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-3.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-4.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-5.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-6.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-7.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-8.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-9.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-10.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-11.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-12.C: Likewise. * g++.dg/cpp/elifdef-3.C: Likewise. * g++.dg/cpp/elifdef-5.C: Likewise. * g++.dg/cpp/elifdef-6.C: Likewise. * g++.dg/cpp/elifdef-7.C: Likewise. * g++.dg/cpp/embed-1.C: Likewise. * g++.dg/cpp/embed-2.C: Likewise. * g++.dg/cpp/pedantic-errors.C: Likewise. * g++.dg/cpp/warning-1.C: Likewise. * g++.dg/cpp/warning-2.C: Likewise. * g++.dg/ext/bitint1.C: Likewise. * g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
const char *message
= (result & CPP_N_UNSIGNED) == CPP_N_UNSIGNED
? N_("use of C++23 %<size_t%> integer constant")
: N_("use of C++23 %<make_signed_t<size_t>%> integer constant");
cpp_warning_with_line (pfile, CPP_W_SIZE_T_LITERALS,
virtual_location, 0, message);
}
C _BitInt incremental fixes [PR102989] On Wed, Aug 09, 2023 at 09:17:57PM +0000, Joseph Myers wrote: > > - _Complex _BitInt(N) isn't supported; again mainly because none of the psABIs > > mention how those should be passed/returned; in a limited way they are > > supported internally because the internal functions into which > > __builtin_{add,sub,mul}_overflow{,_p} is lowered return COMPLEX_TYPE as a > > hack to return 2 values without using references/pointers > > What happens when the usual arithmetic conversions are applied to > operands, one of which is a complex integer type and the other of which is > a wider _BitInt type? I don't see anything in the code to disallow this > case (which would produce an expression with a _Complex _BitInt type), or > any testcases for it. I've added a sorry for that case (+ return the narrower COMPLEX_TYPE). Also added testcase to verify we don't create VECTOR_TYPEs of BITINT_TYPE even if they have mode precision and suitable size (others were rejected already before). > Other testcases I think should be present (along with any corresponding > changes needed to the code itself): > > * Verifying that the new integer constant suffix is rejected for C++. Done. > * Verifying appropriate pedwarn-if-pedantic for the new constant suffix > for versions of C before C2x (and probably for use of _BitInt type > specifiers before C2x as well) - along with the expected -Wc11-c2x-compat > handling (in C2x mode) / -pedantic -Wno-c11-c2x-compat in older modes. Done. Here is an incremental patch which does that. 2023-09-06 Jakub Jelinek <jakub@redhat.com> PR c/102989 gcc/c/ * c-decl.cc (finish_declspecs): Emit pedwarn_c11 on _BitInt. * c-typeck.cc (c_common_type): Emit sorry for common type between _Complex integer and larger _BitInt and return the _Complex integer. gcc/c-family/ * c-attribs.cc (type_valid_for_vector_size): Reject vector types with BITINT_TYPE elements even if they have mode precision and suitable size. gcc/testsuite/ * gcc.dg/bitint-19.c: New test. * gcc.dg/bitint-20.c: New test. * gcc.dg/bitint-21.c: New test. * gcc.dg/bitint-22.c: New test. * gcc.dg/bitint-23.c: New test. * gcc.dg/bitint-24.c: New test. * gcc.dg/bitint-25.c: New test. * gcc.dg/bitint-26.c: New test. * gcc.dg/bitint-27.c: New test. * g++.dg/ext/bitint1.C: New test. * g++.dg/ext/bitint2.C: New test. * g++.dg/ext/bitint3.C: New test. * g++.dg/ext/bitint4.C: New test. libcpp/ * expr.cc (cpp_classify_number): Diagnose wb literal suffixes for -pedantic* before C2X or -Wc11-c2x-compat.
2023-09-06 23:39:15 +08:00
if ((result & CPP_N_BITINT) != 0
c: Refer more consistently to C23 not C2X Continuing the move to refer to C23 in place of C2X throughout the source tree, update documentation, diagnostics, comments, variable and function names, etc., to use the C23 name. Testsuite updates are left for a future patch, except for testcases that test diagnostics that previously mentioned C2X (but in those testcases, sometimes other comments are updated, not just the diagnostic expectations). Bootstrapped with no regressions for x86_64-pc-linux-gnu. gcc/ * builtins.def (DEF_C2X_BUILTIN): Rename to DEF_C23_BUILTIN and use flag_isoc23 and function_c23_misc. * config/rl78/rl78.cc (rl78_option_override): Compare lang_hooks.name with "GNU C23" not "GNU C2X". * coretypes.h (function_c2x_misc): Rename to function_c23_misc. * doc/cpp.texi (@code{__has_attribute}): Refer to C23 instead of C2x. * doc/extend.texi: Likewise. * doc/invoke.texi: Likewise. * dwarf2out.cc (highest_c_language, gen_compile_unit_die): Compare against and return "GNU C23" language string instead of "GNU C2X". * ginclude/float.h: Refer to C23 instead of C2X in comments. * ginclude/stdint-gcc.h: Likewise. * glimits.h: Likewise. * tree.h: Likewise. gcc/ada/ * gcc-interface/utils.cc (flag_isoc2x): Rename to flag_isoc23. gcc/c-family/ * c-common.cc (flag_isoc2x): Rename to flag_isoc23. (c_common_reswords): Use D_C23 instead of D_C2X. * c-common.h: Refer throughout to C23 instead of C2X in comments. (D_C2X): Rename to D_C23. (flag_isoc2x): Rename to flag_isoc23. * c-cppbuiltin.cc (builtin_define_float_constants): Use flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2x in comments. * c-format.cc: Use STD_C23 instead of STD_C2X and flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2X in comments. * c-format.h: Use STD_C23 instead of STD_C2X. * c-lex.cc: Use warn_c11_c23_compat instead of warn_c11_c2x_compat and flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2X in diagnostics. * c-opts.cc: Use flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2X in comments. (set_std_c2x): Rename to set_std_c23. * c.opt (Wc11-c23-compat): Use CPP(cpp_warn_c11_c23_compat) CppReason(CPP_W_C11_C23_COMPAT) Var(warn_c11_c23_compat) instead of CPP(cpp_warn_c11_c2x_compat) CppReason(CPP_W_C11_C2X_COMPAT) Var(warn_c11_c2x_compat). gcc/c/ * c-decl.cc: Use flag_isoc23 instead of flag_isoc2x and c23_auto_p instead of c2x_auto_p. Refer to C23 instead of C2X in diagnostics and comments. * c-errors.cc: Use flag_isoc23 instead of flag_isoc2x and warn_c11_c23_compat instead of warn_c11_c2x_compat. Refer to C23 instead of C2X in comments. * c-parser.cc: Use flag_isoc23 instead of flag_isoc2x, warn_c11_c23_compat instead of warn_c11_c2x_compat, c23_auto_p instead of c2x_auto_p and D_C23 instead of D_C2X. Refer to C23 instead of C2X in diagnostics and comments. * c-tree.h: Refer to C23 instead of C2X in comments. (struct c_declspecs): Rename c2x_auto_p to c23_auto_p. * c-typeck.cc: Use flag_isoc23 instead of flag_isoc2x and warn_c11_c23_compat instead of warn_c11_c2x_compat. Refer to C23 instead of C2X in diagnostics and comments. gcc/fortran/ * gfortran.h (gfc_real_info): Refer to C23 instead of C2X in comment. gcc/lto/ * lto-lang.cc (flag_isoc2x): Rename to flag_isoc23. gcc/testsuite/ * gcc.dg/binary-constants-2.c: Refer to C23 instead of C2X. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/bitint-23.c: Likewise. * gcc.dg/bitint-26.c: Likewise. * gcc.dg/bitint-27.c: Likewise. * gcc.dg/c11-attr-syntax-1.c: Likewise. * gcc.dg/c11-attr-syntax-2.c: Likewise. * gcc.dg/c11-floatn-1.c: Likewise. * gcc.dg/c11-floatn-2.c: Likewise. * gcc.dg/c11-floatn-3.c: Likewise. * gcc.dg/c11-floatn-4.c: Likewise. * gcc.dg/c11-floatn-5.c: Likewise. * gcc.dg/c11-floatn-6.c: Likewise. * gcc.dg/c11-floatn-7.c: Likewise. * gcc.dg/c11-floatn-8.c: Likewise. * gcc.dg/c2x-attr-syntax-4.c: Likewise. * gcc.dg/c2x-attr-syntax-6.c: Likewise. * gcc.dg/c2x-attr-syntax-7.c: Likewise. * gcc.dg/c2x-binary-constants-2.c: Likewise. * gcc.dg/c2x-floatn-5.c: Likewise. * gcc.dg/c2x-floatn-6.c: Likewise. * gcc.dg/c2x-floatn-7.c: Likewise. * gcc.dg/c2x-floatn-8.c: Likewise. * gcc.dg/c2x-nullptr-4.c: Likewise. * gcc.dg/c2x-qual-2.c: Likewise. * gcc.dg/c2x-qual-3.c: Likewise. * gcc.dg/c2x-qual-6.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c2x-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu2x-warning-2.c: Likewise. * gcc.dg/dfp/c11-constants-1.c: Likewise. * gcc.dg/dfp/c11-constants-2.c: Likewise. * gcc.dg/dfp/c2x-constants-2.c: Likewise. * gcc.dg/dfp/constants-pedantic.c: Likewise. * gcc.dg/pr30260.c: Likewise. * gcc.dg/system-binary-constants-1.c: Likewise. libcpp/ * directives.cc: Refer to C23 instead of C2X in diagnostics and comments. (STDC2X): Rename to STDC23. * expr.cc: Use cpp_warn_c11_c23_compat instead of cpp_warn_c11_c2x_compat and CPP_W_C11_C23_COMPAT instead of CPP_W_C11_C2X_COMPAT. Refer to C23 instead of C2X in diagnostics and comments. * include/cpplib.h: Refer to C23 instead of C2X in diagnostics and comments. (CLK_GNUC2X): Rename to CLK_GNUC23. (CLK_STDC2X): Rename to CLK_STDC23. (CPP_W_C11_C2X_COMPAT): Rename to CPP_W_C11_C23_COMPAT. * init.cc: Use GNUC23 instead of GNUC2X, STDC23 instead of STDC2X and cpp_warn_c11_c23_compat instead of cpp_warn_c11_c2x_compat. * lex.cc (maybe_va_opt_error): Refer to C23 instead of C2X in diagnostic. * macro.cc (_cpp_arguments_ok): Refer to C23 instead of C2X in comment.
2023-11-07 22:19:36 +08:00
&& CPP_OPTION (pfile, cpp_warn_c11_c23_compat) != 0)
C _BitInt incremental fixes [PR102989] On Wed, Aug 09, 2023 at 09:17:57PM +0000, Joseph Myers wrote: > > - _Complex _BitInt(N) isn't supported; again mainly because none of the psABIs > > mention how those should be passed/returned; in a limited way they are > > supported internally because the internal functions into which > > __builtin_{add,sub,mul}_overflow{,_p} is lowered return COMPLEX_TYPE as a > > hack to return 2 values without using references/pointers > > What happens when the usual arithmetic conversions are applied to > operands, one of which is a complex integer type and the other of which is > a wider _BitInt type? I don't see anything in the code to disallow this > case (which would produce an expression with a _Complex _BitInt type), or > any testcases for it. I've added a sorry for that case (+ return the narrower COMPLEX_TYPE). Also added testcase to verify we don't create VECTOR_TYPEs of BITINT_TYPE even if they have mode precision and suitable size (others were rejected already before). > Other testcases I think should be present (along with any corresponding > changes needed to the code itself): > > * Verifying that the new integer constant suffix is rejected for C++. Done. > * Verifying appropriate pedwarn-if-pedantic for the new constant suffix > for versions of C before C2x (and probably for use of _BitInt type > specifiers before C2x as well) - along with the expected -Wc11-c2x-compat > handling (in C2x mode) / -pedantic -Wno-c11-c2x-compat in older modes. Done. Here is an incremental patch which does that. 2023-09-06 Jakub Jelinek <jakub@redhat.com> PR c/102989 gcc/c/ * c-decl.cc (finish_declspecs): Emit pedwarn_c11 on _BitInt. * c-typeck.cc (c_common_type): Emit sorry for common type between _Complex integer and larger _BitInt and return the _Complex integer. gcc/c-family/ * c-attribs.cc (type_valid_for_vector_size): Reject vector types with BITINT_TYPE elements even if they have mode precision and suitable size. gcc/testsuite/ * gcc.dg/bitint-19.c: New test. * gcc.dg/bitint-20.c: New test. * gcc.dg/bitint-21.c: New test. * gcc.dg/bitint-22.c: New test. * gcc.dg/bitint-23.c: New test. * gcc.dg/bitint-24.c: New test. * gcc.dg/bitint-25.c: New test. * gcc.dg/bitint-26.c: New test. * gcc.dg/bitint-27.c: New test. * g++.dg/ext/bitint1.C: New test. * g++.dg/ext/bitint2.C: New test. * g++.dg/ext/bitint3.C: New test. * g++.dg/ext/bitint4.C: New test. libcpp/ * expr.cc (cpp_classify_number): Diagnose wb literal suffixes for -pedantic* before C2X or -Wc11-c2x-compat.
2023-09-06 23:39:15 +08:00
{
c: Refer more consistently to C23 not C2X Continuing the move to refer to C23 in place of C2X throughout the source tree, update documentation, diagnostics, comments, variable and function names, etc., to use the C23 name. Testsuite updates are left for a future patch, except for testcases that test diagnostics that previously mentioned C2X (but in those testcases, sometimes other comments are updated, not just the diagnostic expectations). Bootstrapped with no regressions for x86_64-pc-linux-gnu. gcc/ * builtins.def (DEF_C2X_BUILTIN): Rename to DEF_C23_BUILTIN and use flag_isoc23 and function_c23_misc. * config/rl78/rl78.cc (rl78_option_override): Compare lang_hooks.name with "GNU C23" not "GNU C2X". * coretypes.h (function_c2x_misc): Rename to function_c23_misc. * doc/cpp.texi (@code{__has_attribute}): Refer to C23 instead of C2x. * doc/extend.texi: Likewise. * doc/invoke.texi: Likewise. * dwarf2out.cc (highest_c_language, gen_compile_unit_die): Compare against and return "GNU C23" language string instead of "GNU C2X". * ginclude/float.h: Refer to C23 instead of C2X in comments. * ginclude/stdint-gcc.h: Likewise. * glimits.h: Likewise. * tree.h: Likewise. gcc/ada/ * gcc-interface/utils.cc (flag_isoc2x): Rename to flag_isoc23. gcc/c-family/ * c-common.cc (flag_isoc2x): Rename to flag_isoc23. (c_common_reswords): Use D_C23 instead of D_C2X. * c-common.h: Refer throughout to C23 instead of C2X in comments. (D_C2X): Rename to D_C23. (flag_isoc2x): Rename to flag_isoc23. * c-cppbuiltin.cc (builtin_define_float_constants): Use flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2x in comments. * c-format.cc: Use STD_C23 instead of STD_C2X and flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2X in comments. * c-format.h: Use STD_C23 instead of STD_C2X. * c-lex.cc: Use warn_c11_c23_compat instead of warn_c11_c2x_compat and flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2X in diagnostics. * c-opts.cc: Use flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2X in comments. (set_std_c2x): Rename to set_std_c23. * c.opt (Wc11-c23-compat): Use CPP(cpp_warn_c11_c23_compat) CppReason(CPP_W_C11_C23_COMPAT) Var(warn_c11_c23_compat) instead of CPP(cpp_warn_c11_c2x_compat) CppReason(CPP_W_C11_C2X_COMPAT) Var(warn_c11_c2x_compat). gcc/c/ * c-decl.cc: Use flag_isoc23 instead of flag_isoc2x and c23_auto_p instead of c2x_auto_p. Refer to C23 instead of C2X in diagnostics and comments. * c-errors.cc: Use flag_isoc23 instead of flag_isoc2x and warn_c11_c23_compat instead of warn_c11_c2x_compat. Refer to C23 instead of C2X in comments. * c-parser.cc: Use flag_isoc23 instead of flag_isoc2x, warn_c11_c23_compat instead of warn_c11_c2x_compat, c23_auto_p instead of c2x_auto_p and D_C23 instead of D_C2X. Refer to C23 instead of C2X in diagnostics and comments. * c-tree.h: Refer to C23 instead of C2X in comments. (struct c_declspecs): Rename c2x_auto_p to c23_auto_p. * c-typeck.cc: Use flag_isoc23 instead of flag_isoc2x and warn_c11_c23_compat instead of warn_c11_c2x_compat. Refer to C23 instead of C2X in diagnostics and comments. gcc/fortran/ * gfortran.h (gfc_real_info): Refer to C23 instead of C2X in comment. gcc/lto/ * lto-lang.cc (flag_isoc2x): Rename to flag_isoc23. gcc/testsuite/ * gcc.dg/binary-constants-2.c: Refer to C23 instead of C2X. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/bitint-23.c: Likewise. * gcc.dg/bitint-26.c: Likewise. * gcc.dg/bitint-27.c: Likewise. * gcc.dg/c11-attr-syntax-1.c: Likewise. * gcc.dg/c11-attr-syntax-2.c: Likewise. * gcc.dg/c11-floatn-1.c: Likewise. * gcc.dg/c11-floatn-2.c: Likewise. * gcc.dg/c11-floatn-3.c: Likewise. * gcc.dg/c11-floatn-4.c: Likewise. * gcc.dg/c11-floatn-5.c: Likewise. * gcc.dg/c11-floatn-6.c: Likewise. * gcc.dg/c11-floatn-7.c: Likewise. * gcc.dg/c11-floatn-8.c: Likewise. * gcc.dg/c2x-attr-syntax-4.c: Likewise. * gcc.dg/c2x-attr-syntax-6.c: Likewise. * gcc.dg/c2x-attr-syntax-7.c: Likewise. * gcc.dg/c2x-binary-constants-2.c: Likewise. * gcc.dg/c2x-floatn-5.c: Likewise. * gcc.dg/c2x-floatn-6.c: Likewise. * gcc.dg/c2x-floatn-7.c: Likewise. * gcc.dg/c2x-floatn-8.c: Likewise. * gcc.dg/c2x-nullptr-4.c: Likewise. * gcc.dg/c2x-qual-2.c: Likewise. * gcc.dg/c2x-qual-3.c: Likewise. * gcc.dg/c2x-qual-6.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c2x-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu2x-warning-2.c: Likewise. * gcc.dg/dfp/c11-constants-1.c: Likewise. * gcc.dg/dfp/c11-constants-2.c: Likewise. * gcc.dg/dfp/c2x-constants-2.c: Likewise. * gcc.dg/dfp/constants-pedantic.c: Likewise. * gcc.dg/pr30260.c: Likewise. * gcc.dg/system-binary-constants-1.c: Likewise. libcpp/ * directives.cc: Refer to C23 instead of C2X in diagnostics and comments. (STDC2X): Rename to STDC23. * expr.cc: Use cpp_warn_c11_c23_compat instead of cpp_warn_c11_c2x_compat and CPP_W_C11_C23_COMPAT instead of CPP_W_C11_C2X_COMPAT. Refer to C23 instead of C2X in diagnostics and comments. * include/cpplib.h: Refer to C23 instead of C2X in diagnostics and comments. (CLK_GNUC2X): Rename to CLK_GNUC23. (CLK_STDC2X): Rename to CLK_STDC23. (CPP_W_C11_C2X_COMPAT): Rename to CPP_W_C11_C23_COMPAT. * init.cc: Use GNUC23 instead of GNUC2X, STDC23 instead of STDC2X and cpp_warn_c11_c23_compat instead of cpp_warn_c11_c2x_compat. * lex.cc (maybe_va_opt_error): Refer to C23 instead of C2X in diagnostic. * macro.cc (_cpp_arguments_ok): Refer to C23 instead of C2X in comment.
2023-11-07 22:19:36 +08:00
if (CPP_OPTION (pfile, cpp_warn_c11_c23_compat) > 0)
C _BitInt incremental fixes [PR102989] On Wed, Aug 09, 2023 at 09:17:57PM +0000, Joseph Myers wrote: > > - _Complex _BitInt(N) isn't supported; again mainly because none of the psABIs > > mention how those should be passed/returned; in a limited way they are > > supported internally because the internal functions into which > > __builtin_{add,sub,mul}_overflow{,_p} is lowered return COMPLEX_TYPE as a > > hack to return 2 values without using references/pointers > > What happens when the usual arithmetic conversions are applied to > operands, one of which is a complex integer type and the other of which is > a wider _BitInt type? I don't see anything in the code to disallow this > case (which would produce an expression with a _Complex _BitInt type), or > any testcases for it. I've added a sorry for that case (+ return the narrower COMPLEX_TYPE). Also added testcase to verify we don't create VECTOR_TYPEs of BITINT_TYPE even if they have mode precision and suitable size (others were rejected already before). > Other testcases I think should be present (along with any corresponding > changes needed to the code itself): > > * Verifying that the new integer constant suffix is rejected for C++. Done. > * Verifying appropriate pedwarn-if-pedantic for the new constant suffix > for versions of C before C2x (and probably for use of _BitInt type > specifiers before C2x as well) - along with the expected -Wc11-c2x-compat > handling (in C2x mode) / -pedantic -Wno-c11-c2x-compat in older modes. Done. Here is an incremental patch which does that. 2023-09-06 Jakub Jelinek <jakub@redhat.com> PR c/102989 gcc/c/ * c-decl.cc (finish_declspecs): Emit pedwarn_c11 on _BitInt. * c-typeck.cc (c_common_type): Emit sorry for common type between _Complex integer and larger _BitInt and return the _Complex integer. gcc/c-family/ * c-attribs.cc (type_valid_for_vector_size): Reject vector types with BITINT_TYPE elements even if they have mode precision and suitable size. gcc/testsuite/ * gcc.dg/bitint-19.c: New test. * gcc.dg/bitint-20.c: New test. * gcc.dg/bitint-21.c: New test. * gcc.dg/bitint-22.c: New test. * gcc.dg/bitint-23.c: New test. * gcc.dg/bitint-24.c: New test. * gcc.dg/bitint-25.c: New test. * gcc.dg/bitint-26.c: New test. * gcc.dg/bitint-27.c: New test. * g++.dg/ext/bitint1.C: New test. * g++.dg/ext/bitint2.C: New test. * g++.dg/ext/bitint3.C: New test. * g++.dg/ext/bitint4.C: New test. libcpp/ * expr.cc (cpp_classify_number): Diagnose wb literal suffixes for -pedantic* before C2X or -Wc11-c2x-compat.
2023-09-06 23:39:15 +08:00
{
const char *message = N_("ISO C does not support literal "
c: Refer more consistently to C23 not C2X Continuing the move to refer to C23 in place of C2X throughout the source tree, update documentation, diagnostics, comments, variable and function names, etc., to use the C23 name. Testsuite updates are left for a future patch, except for testcases that test diagnostics that previously mentioned C2X (but in those testcases, sometimes other comments are updated, not just the diagnostic expectations). Bootstrapped with no regressions for x86_64-pc-linux-gnu. gcc/ * builtins.def (DEF_C2X_BUILTIN): Rename to DEF_C23_BUILTIN and use flag_isoc23 and function_c23_misc. * config/rl78/rl78.cc (rl78_option_override): Compare lang_hooks.name with "GNU C23" not "GNU C2X". * coretypes.h (function_c2x_misc): Rename to function_c23_misc. * doc/cpp.texi (@code{__has_attribute}): Refer to C23 instead of C2x. * doc/extend.texi: Likewise. * doc/invoke.texi: Likewise. * dwarf2out.cc (highest_c_language, gen_compile_unit_die): Compare against and return "GNU C23" language string instead of "GNU C2X". * ginclude/float.h: Refer to C23 instead of C2X in comments. * ginclude/stdint-gcc.h: Likewise. * glimits.h: Likewise. * tree.h: Likewise. gcc/ada/ * gcc-interface/utils.cc (flag_isoc2x): Rename to flag_isoc23. gcc/c-family/ * c-common.cc (flag_isoc2x): Rename to flag_isoc23. (c_common_reswords): Use D_C23 instead of D_C2X. * c-common.h: Refer throughout to C23 instead of C2X in comments. (D_C2X): Rename to D_C23. (flag_isoc2x): Rename to flag_isoc23. * c-cppbuiltin.cc (builtin_define_float_constants): Use flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2x in comments. * c-format.cc: Use STD_C23 instead of STD_C2X and flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2X in comments. * c-format.h: Use STD_C23 instead of STD_C2X. * c-lex.cc: Use warn_c11_c23_compat instead of warn_c11_c2x_compat and flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2X in diagnostics. * c-opts.cc: Use flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2X in comments. (set_std_c2x): Rename to set_std_c23. * c.opt (Wc11-c23-compat): Use CPP(cpp_warn_c11_c23_compat) CppReason(CPP_W_C11_C23_COMPAT) Var(warn_c11_c23_compat) instead of CPP(cpp_warn_c11_c2x_compat) CppReason(CPP_W_C11_C2X_COMPAT) Var(warn_c11_c2x_compat). gcc/c/ * c-decl.cc: Use flag_isoc23 instead of flag_isoc2x and c23_auto_p instead of c2x_auto_p. Refer to C23 instead of C2X in diagnostics and comments. * c-errors.cc: Use flag_isoc23 instead of flag_isoc2x and warn_c11_c23_compat instead of warn_c11_c2x_compat. Refer to C23 instead of C2X in comments. * c-parser.cc: Use flag_isoc23 instead of flag_isoc2x, warn_c11_c23_compat instead of warn_c11_c2x_compat, c23_auto_p instead of c2x_auto_p and D_C23 instead of D_C2X. Refer to C23 instead of C2X in diagnostics and comments. * c-tree.h: Refer to C23 instead of C2X in comments. (struct c_declspecs): Rename c2x_auto_p to c23_auto_p. * c-typeck.cc: Use flag_isoc23 instead of flag_isoc2x and warn_c11_c23_compat instead of warn_c11_c2x_compat. Refer to C23 instead of C2X in diagnostics and comments. gcc/fortran/ * gfortran.h (gfc_real_info): Refer to C23 instead of C2X in comment. gcc/lto/ * lto-lang.cc (flag_isoc2x): Rename to flag_isoc23. gcc/testsuite/ * gcc.dg/binary-constants-2.c: Refer to C23 instead of C2X. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/bitint-23.c: Likewise. * gcc.dg/bitint-26.c: Likewise. * gcc.dg/bitint-27.c: Likewise. * gcc.dg/c11-attr-syntax-1.c: Likewise. * gcc.dg/c11-attr-syntax-2.c: Likewise. * gcc.dg/c11-floatn-1.c: Likewise. * gcc.dg/c11-floatn-2.c: Likewise. * gcc.dg/c11-floatn-3.c: Likewise. * gcc.dg/c11-floatn-4.c: Likewise. * gcc.dg/c11-floatn-5.c: Likewise. * gcc.dg/c11-floatn-6.c: Likewise. * gcc.dg/c11-floatn-7.c: Likewise. * gcc.dg/c11-floatn-8.c: Likewise. * gcc.dg/c2x-attr-syntax-4.c: Likewise. * gcc.dg/c2x-attr-syntax-6.c: Likewise. * gcc.dg/c2x-attr-syntax-7.c: Likewise. * gcc.dg/c2x-binary-constants-2.c: Likewise. * gcc.dg/c2x-floatn-5.c: Likewise. * gcc.dg/c2x-floatn-6.c: Likewise. * gcc.dg/c2x-floatn-7.c: Likewise. * gcc.dg/c2x-floatn-8.c: Likewise. * gcc.dg/c2x-nullptr-4.c: Likewise. * gcc.dg/c2x-qual-2.c: Likewise. * gcc.dg/c2x-qual-3.c: Likewise. * gcc.dg/c2x-qual-6.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c2x-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu2x-warning-2.c: Likewise. * gcc.dg/dfp/c11-constants-1.c: Likewise. * gcc.dg/dfp/c11-constants-2.c: Likewise. * gcc.dg/dfp/c2x-constants-2.c: Likewise. * gcc.dg/dfp/constants-pedantic.c: Likewise. * gcc.dg/pr30260.c: Likewise. * gcc.dg/system-binary-constants-1.c: Likewise. libcpp/ * directives.cc: Refer to C23 instead of C2X in diagnostics and comments. (STDC2X): Rename to STDC23. * expr.cc: Use cpp_warn_c11_c23_compat instead of cpp_warn_c11_c2x_compat and CPP_W_C11_C23_COMPAT instead of CPP_W_C11_C2X_COMPAT. Refer to C23 instead of C2X in diagnostics and comments. * include/cpplib.h: Refer to C23 instead of C2X in diagnostics and comments. (CLK_GNUC2X): Rename to CLK_GNUC23. (CLK_STDC2X): Rename to CLK_STDC23. (CPP_W_C11_C2X_COMPAT): Rename to CPP_W_C11_C23_COMPAT. * init.cc: Use GNUC23 instead of GNUC2X, STDC23 instead of STDC2X and cpp_warn_c11_c23_compat instead of cpp_warn_c11_c2x_compat. * lex.cc (maybe_va_opt_error): Refer to C23 instead of C2X in diagnostic. * macro.cc (_cpp_arguments_ok): Refer to C23 instead of C2X in comment.
2023-11-07 22:19:36 +08:00
"%<wb%> suffixes before C23");
C _BitInt incremental fixes [PR102989] On Wed, Aug 09, 2023 at 09:17:57PM +0000, Joseph Myers wrote: > > - _Complex _BitInt(N) isn't supported; again mainly because none of the psABIs > > mention how those should be passed/returned; in a limited way they are > > supported internally because the internal functions into which > > __builtin_{add,sub,mul}_overflow{,_p} is lowered return COMPLEX_TYPE as a > > hack to return 2 values without using references/pointers > > What happens when the usual arithmetic conversions are applied to > operands, one of which is a complex integer type and the other of which is > a wider _BitInt type? I don't see anything in the code to disallow this > case (which would produce an expression with a _Complex _BitInt type), or > any testcases for it. I've added a sorry for that case (+ return the narrower COMPLEX_TYPE). Also added testcase to verify we don't create VECTOR_TYPEs of BITINT_TYPE even if they have mode precision and suitable size (others were rejected already before). > Other testcases I think should be present (along with any corresponding > changes needed to the code itself): > > * Verifying that the new integer constant suffix is rejected for C++. Done. > * Verifying appropriate pedwarn-if-pedantic for the new constant suffix > for versions of C before C2x (and probably for use of _BitInt type > specifiers before C2x as well) - along with the expected -Wc11-c2x-compat > handling (in C2x mode) / -pedantic -Wno-c11-c2x-compat in older modes. Done. Here is an incremental patch which does that. 2023-09-06 Jakub Jelinek <jakub@redhat.com> PR c/102989 gcc/c/ * c-decl.cc (finish_declspecs): Emit pedwarn_c11 on _BitInt. * c-typeck.cc (c_common_type): Emit sorry for common type between _Complex integer and larger _BitInt and return the _Complex integer. gcc/c-family/ * c-attribs.cc (type_valid_for_vector_size): Reject vector types with BITINT_TYPE elements even if they have mode precision and suitable size. gcc/testsuite/ * gcc.dg/bitint-19.c: New test. * gcc.dg/bitint-20.c: New test. * gcc.dg/bitint-21.c: New test. * gcc.dg/bitint-22.c: New test. * gcc.dg/bitint-23.c: New test. * gcc.dg/bitint-24.c: New test. * gcc.dg/bitint-25.c: New test. * gcc.dg/bitint-26.c: New test. * gcc.dg/bitint-27.c: New test. * g++.dg/ext/bitint1.C: New test. * g++.dg/ext/bitint2.C: New test. * g++.dg/ext/bitint3.C: New test. * g++.dg/ext/bitint4.C: New test. libcpp/ * expr.cc (cpp_classify_number): Diagnose wb literal suffixes for -pedantic* before C2X or -Wc11-c2x-compat.
2023-09-06 23:39:15 +08:00
if (CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, true_false))
c: Refer more consistently to C23 not C2X Continuing the move to refer to C23 in place of C2X throughout the source tree, update documentation, diagnostics, comments, variable and function names, etc., to use the C23 name. Testsuite updates are left for a future patch, except for testcases that test diagnostics that previously mentioned C2X (but in those testcases, sometimes other comments are updated, not just the diagnostic expectations). Bootstrapped with no regressions for x86_64-pc-linux-gnu. gcc/ * builtins.def (DEF_C2X_BUILTIN): Rename to DEF_C23_BUILTIN and use flag_isoc23 and function_c23_misc. * config/rl78/rl78.cc (rl78_option_override): Compare lang_hooks.name with "GNU C23" not "GNU C2X". * coretypes.h (function_c2x_misc): Rename to function_c23_misc. * doc/cpp.texi (@code{__has_attribute}): Refer to C23 instead of C2x. * doc/extend.texi: Likewise. * doc/invoke.texi: Likewise. * dwarf2out.cc (highest_c_language, gen_compile_unit_die): Compare against and return "GNU C23" language string instead of "GNU C2X". * ginclude/float.h: Refer to C23 instead of C2X in comments. * ginclude/stdint-gcc.h: Likewise. * glimits.h: Likewise. * tree.h: Likewise. gcc/ada/ * gcc-interface/utils.cc (flag_isoc2x): Rename to flag_isoc23. gcc/c-family/ * c-common.cc (flag_isoc2x): Rename to flag_isoc23. (c_common_reswords): Use D_C23 instead of D_C2X. * c-common.h: Refer throughout to C23 instead of C2X in comments. (D_C2X): Rename to D_C23. (flag_isoc2x): Rename to flag_isoc23. * c-cppbuiltin.cc (builtin_define_float_constants): Use flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2x in comments. * c-format.cc: Use STD_C23 instead of STD_C2X and flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2X in comments. * c-format.h: Use STD_C23 instead of STD_C2X. * c-lex.cc: Use warn_c11_c23_compat instead of warn_c11_c2x_compat and flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2X in diagnostics. * c-opts.cc: Use flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2X in comments. (set_std_c2x): Rename to set_std_c23. * c.opt (Wc11-c23-compat): Use CPP(cpp_warn_c11_c23_compat) CppReason(CPP_W_C11_C23_COMPAT) Var(warn_c11_c23_compat) instead of CPP(cpp_warn_c11_c2x_compat) CppReason(CPP_W_C11_C2X_COMPAT) Var(warn_c11_c2x_compat). gcc/c/ * c-decl.cc: Use flag_isoc23 instead of flag_isoc2x and c23_auto_p instead of c2x_auto_p. Refer to C23 instead of C2X in diagnostics and comments. * c-errors.cc: Use flag_isoc23 instead of flag_isoc2x and warn_c11_c23_compat instead of warn_c11_c2x_compat. Refer to C23 instead of C2X in comments. * c-parser.cc: Use flag_isoc23 instead of flag_isoc2x, warn_c11_c23_compat instead of warn_c11_c2x_compat, c23_auto_p instead of c2x_auto_p and D_C23 instead of D_C2X. Refer to C23 instead of C2X in diagnostics and comments. * c-tree.h: Refer to C23 instead of C2X in comments. (struct c_declspecs): Rename c2x_auto_p to c23_auto_p. * c-typeck.cc: Use flag_isoc23 instead of flag_isoc2x and warn_c11_c23_compat instead of warn_c11_c2x_compat. Refer to C23 instead of C2X in diagnostics and comments. gcc/fortran/ * gfortran.h (gfc_real_info): Refer to C23 instead of C2X in comment. gcc/lto/ * lto-lang.cc (flag_isoc2x): Rename to flag_isoc23. gcc/testsuite/ * gcc.dg/binary-constants-2.c: Refer to C23 instead of C2X. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/bitint-23.c: Likewise. * gcc.dg/bitint-26.c: Likewise. * gcc.dg/bitint-27.c: Likewise. * gcc.dg/c11-attr-syntax-1.c: Likewise. * gcc.dg/c11-attr-syntax-2.c: Likewise. * gcc.dg/c11-floatn-1.c: Likewise. * gcc.dg/c11-floatn-2.c: Likewise. * gcc.dg/c11-floatn-3.c: Likewise. * gcc.dg/c11-floatn-4.c: Likewise. * gcc.dg/c11-floatn-5.c: Likewise. * gcc.dg/c11-floatn-6.c: Likewise. * gcc.dg/c11-floatn-7.c: Likewise. * gcc.dg/c11-floatn-8.c: Likewise. * gcc.dg/c2x-attr-syntax-4.c: Likewise. * gcc.dg/c2x-attr-syntax-6.c: Likewise. * gcc.dg/c2x-attr-syntax-7.c: Likewise. * gcc.dg/c2x-binary-constants-2.c: Likewise. * gcc.dg/c2x-floatn-5.c: Likewise. * gcc.dg/c2x-floatn-6.c: Likewise. * gcc.dg/c2x-floatn-7.c: Likewise. * gcc.dg/c2x-floatn-8.c: Likewise. * gcc.dg/c2x-nullptr-4.c: Likewise. * gcc.dg/c2x-qual-2.c: Likewise. * gcc.dg/c2x-qual-3.c: Likewise. * gcc.dg/c2x-qual-6.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c2x-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu2x-warning-2.c: Likewise. * gcc.dg/dfp/c11-constants-1.c: Likewise. * gcc.dg/dfp/c11-constants-2.c: Likewise. * gcc.dg/dfp/c2x-constants-2.c: Likewise. * gcc.dg/dfp/constants-pedantic.c: Likewise. * gcc.dg/pr30260.c: Likewise. * gcc.dg/system-binary-constants-1.c: Likewise. libcpp/ * directives.cc: Refer to C23 instead of C2X in diagnostics and comments. (STDC2X): Rename to STDC23. * expr.cc: Use cpp_warn_c11_c23_compat instead of cpp_warn_c11_c2x_compat and CPP_W_C11_C23_COMPAT instead of CPP_W_C11_C2X_COMPAT. Refer to C23 instead of C2X in diagnostics and comments. * include/cpplib.h: Refer to C23 instead of C2X in diagnostics and comments. (CLK_GNUC2X): Rename to CLK_GNUC23. (CLK_STDC2X): Rename to CLK_STDC23. (CPP_W_C11_C2X_COMPAT): Rename to CPP_W_C11_C23_COMPAT. * init.cc: Use GNUC23 instead of GNUC2X, STDC23 instead of STDC2X and cpp_warn_c11_c23_compat instead of cpp_warn_c11_c2x_compat. * lex.cc (maybe_va_opt_error): Refer to C23 instead of C2X in diagnostic. * macro.cc (_cpp_arguments_ok): Refer to C23 instead of C2X in comment.
2023-11-07 22:19:36 +08:00
cpp_pedwarning_with_line (pfile, CPP_W_C11_C23_COMPAT,
C _BitInt incremental fixes [PR102989] On Wed, Aug 09, 2023 at 09:17:57PM +0000, Joseph Myers wrote: > > - _Complex _BitInt(N) isn't supported; again mainly because none of the psABIs > > mention how those should be passed/returned; in a limited way they are > > supported internally because the internal functions into which > > __builtin_{add,sub,mul}_overflow{,_p} is lowered return COMPLEX_TYPE as a > > hack to return 2 values without using references/pointers > > What happens when the usual arithmetic conversions are applied to > operands, one of which is a complex integer type and the other of which is > a wider _BitInt type? I don't see anything in the code to disallow this > case (which would produce an expression with a _Complex _BitInt type), or > any testcases for it. I've added a sorry for that case (+ return the narrower COMPLEX_TYPE). Also added testcase to verify we don't create VECTOR_TYPEs of BITINT_TYPE even if they have mode precision and suitable size (others were rejected already before). > Other testcases I think should be present (along with any corresponding > changes needed to the code itself): > > * Verifying that the new integer constant suffix is rejected for C++. Done. > * Verifying appropriate pedwarn-if-pedantic for the new constant suffix > for versions of C before C2x (and probably for use of _BitInt type > specifiers before C2x as well) - along with the expected -Wc11-c2x-compat > handling (in C2x mode) / -pedantic -Wno-c11-c2x-compat in older modes. Done. Here is an incremental patch which does that. 2023-09-06 Jakub Jelinek <jakub@redhat.com> PR c/102989 gcc/c/ * c-decl.cc (finish_declspecs): Emit pedwarn_c11 on _BitInt. * c-typeck.cc (c_common_type): Emit sorry for common type between _Complex integer and larger _BitInt and return the _Complex integer. gcc/c-family/ * c-attribs.cc (type_valid_for_vector_size): Reject vector types with BITINT_TYPE elements even if they have mode precision and suitable size. gcc/testsuite/ * gcc.dg/bitint-19.c: New test. * gcc.dg/bitint-20.c: New test. * gcc.dg/bitint-21.c: New test. * gcc.dg/bitint-22.c: New test. * gcc.dg/bitint-23.c: New test. * gcc.dg/bitint-24.c: New test. * gcc.dg/bitint-25.c: New test. * gcc.dg/bitint-26.c: New test. * gcc.dg/bitint-27.c: New test. * g++.dg/ext/bitint1.C: New test. * g++.dg/ext/bitint2.C: New test. * g++.dg/ext/bitint3.C: New test. * g++.dg/ext/bitint4.C: New test. libcpp/ * expr.cc (cpp_classify_number): Diagnose wb literal suffixes for -pedantic* before C2X or -Wc11-c2x-compat.
2023-09-06 23:39:15 +08:00
virtual_location, 0, message);
else
c: Refer more consistently to C23 not C2X Continuing the move to refer to C23 in place of C2X throughout the source tree, update documentation, diagnostics, comments, variable and function names, etc., to use the C23 name. Testsuite updates are left for a future patch, except for testcases that test diagnostics that previously mentioned C2X (but in those testcases, sometimes other comments are updated, not just the diagnostic expectations). Bootstrapped with no regressions for x86_64-pc-linux-gnu. gcc/ * builtins.def (DEF_C2X_BUILTIN): Rename to DEF_C23_BUILTIN and use flag_isoc23 and function_c23_misc. * config/rl78/rl78.cc (rl78_option_override): Compare lang_hooks.name with "GNU C23" not "GNU C2X". * coretypes.h (function_c2x_misc): Rename to function_c23_misc. * doc/cpp.texi (@code{__has_attribute}): Refer to C23 instead of C2x. * doc/extend.texi: Likewise. * doc/invoke.texi: Likewise. * dwarf2out.cc (highest_c_language, gen_compile_unit_die): Compare against and return "GNU C23" language string instead of "GNU C2X". * ginclude/float.h: Refer to C23 instead of C2X in comments. * ginclude/stdint-gcc.h: Likewise. * glimits.h: Likewise. * tree.h: Likewise. gcc/ada/ * gcc-interface/utils.cc (flag_isoc2x): Rename to flag_isoc23. gcc/c-family/ * c-common.cc (flag_isoc2x): Rename to flag_isoc23. (c_common_reswords): Use D_C23 instead of D_C2X. * c-common.h: Refer throughout to C23 instead of C2X in comments. (D_C2X): Rename to D_C23. (flag_isoc2x): Rename to flag_isoc23. * c-cppbuiltin.cc (builtin_define_float_constants): Use flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2x in comments. * c-format.cc: Use STD_C23 instead of STD_C2X and flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2X in comments. * c-format.h: Use STD_C23 instead of STD_C2X. * c-lex.cc: Use warn_c11_c23_compat instead of warn_c11_c2x_compat and flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2X in diagnostics. * c-opts.cc: Use flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2X in comments. (set_std_c2x): Rename to set_std_c23. * c.opt (Wc11-c23-compat): Use CPP(cpp_warn_c11_c23_compat) CppReason(CPP_W_C11_C23_COMPAT) Var(warn_c11_c23_compat) instead of CPP(cpp_warn_c11_c2x_compat) CppReason(CPP_W_C11_C2X_COMPAT) Var(warn_c11_c2x_compat). gcc/c/ * c-decl.cc: Use flag_isoc23 instead of flag_isoc2x and c23_auto_p instead of c2x_auto_p. Refer to C23 instead of C2X in diagnostics and comments. * c-errors.cc: Use flag_isoc23 instead of flag_isoc2x and warn_c11_c23_compat instead of warn_c11_c2x_compat. Refer to C23 instead of C2X in comments. * c-parser.cc: Use flag_isoc23 instead of flag_isoc2x, warn_c11_c23_compat instead of warn_c11_c2x_compat, c23_auto_p instead of c2x_auto_p and D_C23 instead of D_C2X. Refer to C23 instead of C2X in diagnostics and comments. * c-tree.h: Refer to C23 instead of C2X in comments. (struct c_declspecs): Rename c2x_auto_p to c23_auto_p. * c-typeck.cc: Use flag_isoc23 instead of flag_isoc2x and warn_c11_c23_compat instead of warn_c11_c2x_compat. Refer to C23 instead of C2X in diagnostics and comments. gcc/fortran/ * gfortran.h (gfc_real_info): Refer to C23 instead of C2X in comment. gcc/lto/ * lto-lang.cc (flag_isoc2x): Rename to flag_isoc23. gcc/testsuite/ * gcc.dg/binary-constants-2.c: Refer to C23 instead of C2X. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/bitint-23.c: Likewise. * gcc.dg/bitint-26.c: Likewise. * gcc.dg/bitint-27.c: Likewise. * gcc.dg/c11-attr-syntax-1.c: Likewise. * gcc.dg/c11-attr-syntax-2.c: Likewise. * gcc.dg/c11-floatn-1.c: Likewise. * gcc.dg/c11-floatn-2.c: Likewise. * gcc.dg/c11-floatn-3.c: Likewise. * gcc.dg/c11-floatn-4.c: Likewise. * gcc.dg/c11-floatn-5.c: Likewise. * gcc.dg/c11-floatn-6.c: Likewise. * gcc.dg/c11-floatn-7.c: Likewise. * gcc.dg/c11-floatn-8.c: Likewise. * gcc.dg/c2x-attr-syntax-4.c: Likewise. * gcc.dg/c2x-attr-syntax-6.c: Likewise. * gcc.dg/c2x-attr-syntax-7.c: Likewise. * gcc.dg/c2x-binary-constants-2.c: Likewise. * gcc.dg/c2x-floatn-5.c: Likewise. * gcc.dg/c2x-floatn-6.c: Likewise. * gcc.dg/c2x-floatn-7.c: Likewise. * gcc.dg/c2x-floatn-8.c: Likewise. * gcc.dg/c2x-nullptr-4.c: Likewise. * gcc.dg/c2x-qual-2.c: Likewise. * gcc.dg/c2x-qual-3.c: Likewise. * gcc.dg/c2x-qual-6.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c2x-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu2x-warning-2.c: Likewise. * gcc.dg/dfp/c11-constants-1.c: Likewise. * gcc.dg/dfp/c11-constants-2.c: Likewise. * gcc.dg/dfp/c2x-constants-2.c: Likewise. * gcc.dg/dfp/constants-pedantic.c: Likewise. * gcc.dg/pr30260.c: Likewise. * gcc.dg/system-binary-constants-1.c: Likewise. libcpp/ * directives.cc: Refer to C23 instead of C2X in diagnostics and comments. (STDC2X): Rename to STDC23. * expr.cc: Use cpp_warn_c11_c23_compat instead of cpp_warn_c11_c2x_compat and CPP_W_C11_C23_COMPAT instead of CPP_W_C11_C2X_COMPAT. Refer to C23 instead of C2X in diagnostics and comments. * include/cpplib.h: Refer to C23 instead of C2X in diagnostics and comments. (CLK_GNUC2X): Rename to CLK_GNUC23. (CLK_STDC2X): Rename to CLK_STDC23. (CPP_W_C11_C2X_COMPAT): Rename to CPP_W_C11_C23_COMPAT. * init.cc: Use GNUC23 instead of GNUC2X, STDC23 instead of STDC2X and cpp_warn_c11_c23_compat instead of cpp_warn_c11_c2x_compat. * lex.cc (maybe_va_opt_error): Refer to C23 instead of C2X in diagnostic. * macro.cc (_cpp_arguments_ok): Refer to C23 instead of C2X in comment.
2023-11-07 22:19:36 +08:00
cpp_warning_with_line (pfile, CPP_W_C11_C23_COMPAT,
C _BitInt incremental fixes [PR102989] On Wed, Aug 09, 2023 at 09:17:57PM +0000, Joseph Myers wrote: > > - _Complex _BitInt(N) isn't supported; again mainly because none of the psABIs > > mention how those should be passed/returned; in a limited way they are > > supported internally because the internal functions into which > > __builtin_{add,sub,mul}_overflow{,_p} is lowered return COMPLEX_TYPE as a > > hack to return 2 values without using references/pointers > > What happens when the usual arithmetic conversions are applied to > operands, one of which is a complex integer type and the other of which is > a wider _BitInt type? I don't see anything in the code to disallow this > case (which would produce an expression with a _Complex _BitInt type), or > any testcases for it. I've added a sorry for that case (+ return the narrower COMPLEX_TYPE). Also added testcase to verify we don't create VECTOR_TYPEs of BITINT_TYPE even if they have mode precision and suitable size (others were rejected already before). > Other testcases I think should be present (along with any corresponding > changes needed to the code itself): > > * Verifying that the new integer constant suffix is rejected for C++. Done. > * Verifying appropriate pedwarn-if-pedantic for the new constant suffix > for versions of C before C2x (and probably for use of _BitInt type > specifiers before C2x as well) - along with the expected -Wc11-c2x-compat > handling (in C2x mode) / -pedantic -Wno-c11-c2x-compat in older modes. Done. Here is an incremental patch which does that. 2023-09-06 Jakub Jelinek <jakub@redhat.com> PR c/102989 gcc/c/ * c-decl.cc (finish_declspecs): Emit pedwarn_c11 on _BitInt. * c-typeck.cc (c_common_type): Emit sorry for common type between _Complex integer and larger _BitInt and return the _Complex integer. gcc/c-family/ * c-attribs.cc (type_valid_for_vector_size): Reject vector types with BITINT_TYPE elements even if they have mode precision and suitable size. gcc/testsuite/ * gcc.dg/bitint-19.c: New test. * gcc.dg/bitint-20.c: New test. * gcc.dg/bitint-21.c: New test. * gcc.dg/bitint-22.c: New test. * gcc.dg/bitint-23.c: New test. * gcc.dg/bitint-24.c: New test. * gcc.dg/bitint-25.c: New test. * gcc.dg/bitint-26.c: New test. * gcc.dg/bitint-27.c: New test. * g++.dg/ext/bitint1.C: New test. * g++.dg/ext/bitint2.C: New test. * g++.dg/ext/bitint3.C: New test. * g++.dg/ext/bitint4.C: New test. libcpp/ * expr.cc (cpp_classify_number): Diagnose wb literal suffixes for -pedantic* before C2X or -Wc11-c2x-compat.
2023-09-06 23:39:15 +08:00
virtual_location, 0, message);
}
libcpp: adjust pedwarn handling Using cpp_pedwarning (CPP_W_PEDANTIC instead of if (CPP_PEDANTIC cpp_error lets users suppress these diagnostics with #pragma GCC diagnostic ignored "-Wpedantic". This patch changes all instances of the cpp_error (CPP_DL_PEDWARN to cpp_pedwarning. In cases where the extension appears in a later C++ revision, we now condition the warning on the relevant -Wc++??-extensions flag instead of -Wpedantic; in such cases often the if (CPP_PEDANTIC) check is retained to preserve the default non-warning behavior. I didn't attempt to adjust the warning flags for the C compiler, since it seems to follow a different system than C++. The CPP_PEDANTIC check is also kept in _cpp_lex_direct to avoid an ICE in the self-tests from cb.diagnostics not being initialized. While working on testcases for these changes I noticed that the c-c++-common tests are not run with -pedantic-errors by default like the gcc.dg and g++.dg directories are. And if I specify -pedantic-errors with dg-options, the default -std= changes from c++?? to gnu++??, which interferes with some other pedwarns. So two of the tests are C++-only. libcpp/ChangeLog: * include/cpplib.h (enum cpp_warning_reason): Add CPP_W_CXX{14,17,20,23}_EXTENSIONS. * charset.cc (_cpp_valid_ucn, convert_hex, convert_oct) (convert_escape, narrow_str_to_charconst): Use cpp_pedwarning instead of cpp_error for pedwarns. * directives.cc (directive_diagnostics, _cpp_handle_directive) (do_line, do_elif): Likewise. * expr.cc (cpp_classify_number, eval_token): Likewise. * lex.cc (skip_whitespace, maybe_va_opt_error) (_cpp_lex_direct): Likewise. * macro.cc (_cpp_arguments_ok): Likewise. (replace_args): Use -Wvariadic-macros for pedwarn about empty macro arguments. gcc/c-family/ChangeLog: * c.opt: Add CppReason for Wc++{14,17,20,23}-extensions. * c-pragma.cc (handle_pragma_diagnostic_impl): Don't check OPT_Wc__23_extensions. gcc/testsuite/ChangeLog: * c-c++-common/pragma-diag-17.c: New test. * g++.dg/cpp0x/va-opt1.C: New test. * g++.dg/cpp23/named-universal-char-escape3.C: New test.
2024-08-28 01:15:16 +08:00
else if (!CPP_OPTION (pfile, true_false))
C _BitInt incremental fixes [PR102989] On Wed, Aug 09, 2023 at 09:17:57PM +0000, Joseph Myers wrote: > > - _Complex _BitInt(N) isn't supported; again mainly because none of the psABIs > > mention how those should be passed/returned; in a limited way they are > > supported internally because the internal functions into which > > __builtin_{add,sub,mul}_overflow{,_p} is lowered return COMPLEX_TYPE as a > > hack to return 2 values without using references/pointers > > What happens when the usual arithmetic conversions are applied to > operands, one of which is a complex integer type and the other of which is > a wider _BitInt type? I don't see anything in the code to disallow this > case (which would produce an expression with a _Complex _BitInt type), or > any testcases for it. I've added a sorry for that case (+ return the narrower COMPLEX_TYPE). Also added testcase to verify we don't create VECTOR_TYPEs of BITINT_TYPE even if they have mode precision and suitable size (others were rejected already before). > Other testcases I think should be present (along with any corresponding > changes needed to the code itself): > > * Verifying that the new integer constant suffix is rejected for C++. Done. > * Verifying appropriate pedwarn-if-pedantic for the new constant suffix > for versions of C before C2x (and probably for use of _BitInt type > specifiers before C2x as well) - along with the expected -Wc11-c2x-compat > handling (in C2x mode) / -pedantic -Wno-c11-c2x-compat in older modes. Done. Here is an incremental patch which does that. 2023-09-06 Jakub Jelinek <jakub@redhat.com> PR c/102989 gcc/c/ * c-decl.cc (finish_declspecs): Emit pedwarn_c11 on _BitInt. * c-typeck.cc (c_common_type): Emit sorry for common type between _Complex integer and larger _BitInt and return the _Complex integer. gcc/c-family/ * c-attribs.cc (type_valid_for_vector_size): Reject vector types with BITINT_TYPE elements even if they have mode precision and suitable size. gcc/testsuite/ * gcc.dg/bitint-19.c: New test. * gcc.dg/bitint-20.c: New test. * gcc.dg/bitint-21.c: New test. * gcc.dg/bitint-22.c: New test. * gcc.dg/bitint-23.c: New test. * gcc.dg/bitint-24.c: New test. * gcc.dg/bitint-25.c: New test. * gcc.dg/bitint-26.c: New test. * gcc.dg/bitint-27.c: New test. * g++.dg/ext/bitint1.C: New test. * g++.dg/ext/bitint2.C: New test. * g++.dg/ext/bitint3.C: New test. * g++.dg/ext/bitint4.C: New test. libcpp/ * expr.cc (cpp_classify_number): Diagnose wb literal suffixes for -pedantic* before C2X or -Wc11-c2x-compat.
2023-09-06 23:39:15 +08:00
{
const char *message = N_("ISO C does not support literal "
c: Refer more consistently to C23 not C2X Continuing the move to refer to C23 in place of C2X throughout the source tree, update documentation, diagnostics, comments, variable and function names, etc., to use the C23 name. Testsuite updates are left for a future patch, except for testcases that test diagnostics that previously mentioned C2X (but in those testcases, sometimes other comments are updated, not just the diagnostic expectations). Bootstrapped with no regressions for x86_64-pc-linux-gnu. gcc/ * builtins.def (DEF_C2X_BUILTIN): Rename to DEF_C23_BUILTIN and use flag_isoc23 and function_c23_misc. * config/rl78/rl78.cc (rl78_option_override): Compare lang_hooks.name with "GNU C23" not "GNU C2X". * coretypes.h (function_c2x_misc): Rename to function_c23_misc. * doc/cpp.texi (@code{__has_attribute}): Refer to C23 instead of C2x. * doc/extend.texi: Likewise. * doc/invoke.texi: Likewise. * dwarf2out.cc (highest_c_language, gen_compile_unit_die): Compare against and return "GNU C23" language string instead of "GNU C2X". * ginclude/float.h: Refer to C23 instead of C2X in comments. * ginclude/stdint-gcc.h: Likewise. * glimits.h: Likewise. * tree.h: Likewise. gcc/ada/ * gcc-interface/utils.cc (flag_isoc2x): Rename to flag_isoc23. gcc/c-family/ * c-common.cc (flag_isoc2x): Rename to flag_isoc23. (c_common_reswords): Use D_C23 instead of D_C2X. * c-common.h: Refer throughout to C23 instead of C2X in comments. (D_C2X): Rename to D_C23. (flag_isoc2x): Rename to flag_isoc23. * c-cppbuiltin.cc (builtin_define_float_constants): Use flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2x in comments. * c-format.cc: Use STD_C23 instead of STD_C2X and flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2X in comments. * c-format.h: Use STD_C23 instead of STD_C2X. * c-lex.cc: Use warn_c11_c23_compat instead of warn_c11_c2x_compat and flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2X in diagnostics. * c-opts.cc: Use flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2X in comments. (set_std_c2x): Rename to set_std_c23. * c.opt (Wc11-c23-compat): Use CPP(cpp_warn_c11_c23_compat) CppReason(CPP_W_C11_C23_COMPAT) Var(warn_c11_c23_compat) instead of CPP(cpp_warn_c11_c2x_compat) CppReason(CPP_W_C11_C2X_COMPAT) Var(warn_c11_c2x_compat). gcc/c/ * c-decl.cc: Use flag_isoc23 instead of flag_isoc2x and c23_auto_p instead of c2x_auto_p. Refer to C23 instead of C2X in diagnostics and comments. * c-errors.cc: Use flag_isoc23 instead of flag_isoc2x and warn_c11_c23_compat instead of warn_c11_c2x_compat. Refer to C23 instead of C2X in comments. * c-parser.cc: Use flag_isoc23 instead of flag_isoc2x, warn_c11_c23_compat instead of warn_c11_c2x_compat, c23_auto_p instead of c2x_auto_p and D_C23 instead of D_C2X. Refer to C23 instead of C2X in diagnostics and comments. * c-tree.h: Refer to C23 instead of C2X in comments. (struct c_declspecs): Rename c2x_auto_p to c23_auto_p. * c-typeck.cc: Use flag_isoc23 instead of flag_isoc2x and warn_c11_c23_compat instead of warn_c11_c2x_compat. Refer to C23 instead of C2X in diagnostics and comments. gcc/fortran/ * gfortran.h (gfc_real_info): Refer to C23 instead of C2X in comment. gcc/lto/ * lto-lang.cc (flag_isoc2x): Rename to flag_isoc23. gcc/testsuite/ * gcc.dg/binary-constants-2.c: Refer to C23 instead of C2X. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/bitint-23.c: Likewise. * gcc.dg/bitint-26.c: Likewise. * gcc.dg/bitint-27.c: Likewise. * gcc.dg/c11-attr-syntax-1.c: Likewise. * gcc.dg/c11-attr-syntax-2.c: Likewise. * gcc.dg/c11-floatn-1.c: Likewise. * gcc.dg/c11-floatn-2.c: Likewise. * gcc.dg/c11-floatn-3.c: Likewise. * gcc.dg/c11-floatn-4.c: Likewise. * gcc.dg/c11-floatn-5.c: Likewise. * gcc.dg/c11-floatn-6.c: Likewise. * gcc.dg/c11-floatn-7.c: Likewise. * gcc.dg/c11-floatn-8.c: Likewise. * gcc.dg/c2x-attr-syntax-4.c: Likewise. * gcc.dg/c2x-attr-syntax-6.c: Likewise. * gcc.dg/c2x-attr-syntax-7.c: Likewise. * gcc.dg/c2x-binary-constants-2.c: Likewise. * gcc.dg/c2x-floatn-5.c: Likewise. * gcc.dg/c2x-floatn-6.c: Likewise. * gcc.dg/c2x-floatn-7.c: Likewise. * gcc.dg/c2x-floatn-8.c: Likewise. * gcc.dg/c2x-nullptr-4.c: Likewise. * gcc.dg/c2x-qual-2.c: Likewise. * gcc.dg/c2x-qual-3.c: Likewise. * gcc.dg/c2x-qual-6.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c2x-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu2x-warning-2.c: Likewise. * gcc.dg/dfp/c11-constants-1.c: Likewise. * gcc.dg/dfp/c11-constants-2.c: Likewise. * gcc.dg/dfp/c2x-constants-2.c: Likewise. * gcc.dg/dfp/constants-pedantic.c: Likewise. * gcc.dg/pr30260.c: Likewise. * gcc.dg/system-binary-constants-1.c: Likewise. libcpp/ * directives.cc: Refer to C23 instead of C2X in diagnostics and comments. (STDC2X): Rename to STDC23. * expr.cc: Use cpp_warn_c11_c23_compat instead of cpp_warn_c11_c2x_compat and CPP_W_C11_C23_COMPAT instead of CPP_W_C11_C2X_COMPAT. Refer to C23 instead of C2X in diagnostics and comments. * include/cpplib.h: Refer to C23 instead of C2X in diagnostics and comments. (CLK_GNUC2X): Rename to CLK_GNUC23. (CLK_STDC2X): Rename to CLK_STDC23. (CPP_W_C11_C2X_COMPAT): Rename to CPP_W_C11_C23_COMPAT. * init.cc: Use GNUC23 instead of GNUC2X, STDC23 instead of STDC2X and cpp_warn_c11_c23_compat instead of cpp_warn_c11_c2x_compat. * lex.cc (maybe_va_opt_error): Refer to C23 instead of C2X in diagnostic. * macro.cc (_cpp_arguments_ok): Refer to C23 instead of C2X in comment.
2023-11-07 22:19:36 +08:00
"%<wb%> suffixes before C23");
libcpp: adjust pedwarn handling Using cpp_pedwarning (CPP_W_PEDANTIC instead of if (CPP_PEDANTIC cpp_error lets users suppress these diagnostics with #pragma GCC diagnostic ignored "-Wpedantic". This patch changes all instances of the cpp_error (CPP_DL_PEDWARN to cpp_pedwarning. In cases where the extension appears in a later C++ revision, we now condition the warning on the relevant -Wc++??-extensions flag instead of -Wpedantic; in such cases often the if (CPP_PEDANTIC) check is retained to preserve the default non-warning behavior. I didn't attempt to adjust the warning flags for the C compiler, since it seems to follow a different system than C++. The CPP_PEDANTIC check is also kept in _cpp_lex_direct to avoid an ICE in the self-tests from cb.diagnostics not being initialized. While working on testcases for these changes I noticed that the c-c++-common tests are not run with -pedantic-errors by default like the gcc.dg and g++.dg directories are. And if I specify -pedantic-errors with dg-options, the default -std= changes from c++?? to gnu++??, which interferes with some other pedwarns. So two of the tests are C++-only. libcpp/ChangeLog: * include/cpplib.h (enum cpp_warning_reason): Add CPP_W_CXX{14,17,20,23}_EXTENSIONS. * charset.cc (_cpp_valid_ucn, convert_hex, convert_oct) (convert_escape, narrow_str_to_charconst): Use cpp_pedwarning instead of cpp_error for pedwarns. * directives.cc (directive_diagnostics, _cpp_handle_directive) (do_line, do_elif): Likewise. * expr.cc (cpp_classify_number, eval_token): Likewise. * lex.cc (skip_whitespace, maybe_va_opt_error) (_cpp_lex_direct): Likewise. * macro.cc (_cpp_arguments_ok): Likewise. (replace_args): Use -Wvariadic-macros for pedwarn about empty macro arguments. gcc/c-family/ChangeLog: * c.opt: Add CppReason for Wc++{14,17,20,23}-extensions. * c-pragma.cc (handle_pragma_diagnostic_impl): Don't check OPT_Wc__23_extensions. gcc/testsuite/ChangeLog: * c-c++-common/pragma-diag-17.c: New test. * g++.dg/cpp0x/va-opt1.C: New test. * g++.dg/cpp23/named-universal-char-escape3.C: New test.
2024-08-28 01:15:16 +08:00
cpp_pedwarning_with_line (pfile, CPP_W_PEDANTIC,
virtual_location, 0, message);
C _BitInt incremental fixes [PR102989] On Wed, Aug 09, 2023 at 09:17:57PM +0000, Joseph Myers wrote: > > - _Complex _BitInt(N) isn't supported; again mainly because none of the psABIs > > mention how those should be passed/returned; in a limited way they are > > supported internally because the internal functions into which > > __builtin_{add,sub,mul}_overflow{,_p} is lowered return COMPLEX_TYPE as a > > hack to return 2 values without using references/pointers > > What happens when the usual arithmetic conversions are applied to > operands, one of which is a complex integer type and the other of which is > a wider _BitInt type? I don't see anything in the code to disallow this > case (which would produce an expression with a _Complex _BitInt type), or > any testcases for it. I've added a sorry for that case (+ return the narrower COMPLEX_TYPE). Also added testcase to verify we don't create VECTOR_TYPEs of BITINT_TYPE even if they have mode precision and suitable size (others were rejected already before). > Other testcases I think should be present (along with any corresponding > changes needed to the code itself): > > * Verifying that the new integer constant suffix is rejected for C++. Done. > * Verifying appropriate pedwarn-if-pedantic for the new constant suffix > for versions of C before C2x (and probably for use of _BitInt type > specifiers before C2x as well) - along with the expected -Wc11-c2x-compat > handling (in C2x mode) / -pedantic -Wno-c11-c2x-compat in older modes. Done. Here is an incremental patch which does that. 2023-09-06 Jakub Jelinek <jakub@redhat.com> PR c/102989 gcc/c/ * c-decl.cc (finish_declspecs): Emit pedwarn_c11 on _BitInt. * c-typeck.cc (c_common_type): Emit sorry for common type between _Complex integer and larger _BitInt and return the _Complex integer. gcc/c-family/ * c-attribs.cc (type_valid_for_vector_size): Reject vector types with BITINT_TYPE elements even if they have mode precision and suitable size. gcc/testsuite/ * gcc.dg/bitint-19.c: New test. * gcc.dg/bitint-20.c: New test. * gcc.dg/bitint-21.c: New test. * gcc.dg/bitint-22.c: New test. * gcc.dg/bitint-23.c: New test. * gcc.dg/bitint-24.c: New test. * gcc.dg/bitint-25.c: New test. * gcc.dg/bitint-26.c: New test. * gcc.dg/bitint-27.c: New test. * g++.dg/ext/bitint1.C: New test. * g++.dg/ext/bitint2.C: New test. * g++.dg/ext/bitint3.C: New test. * g++.dg/ext/bitint4.C: New test. libcpp/ * expr.cc (cpp_classify_number): Diagnose wb literal suffixes for -pedantic* before C2X or -Wc11-c2x-compat.
2023-09-06 23:39:15 +08:00
}
}
result |= CPP_N_INTEGER;
}
syntax_ok:
libcpp: adjust pedwarn handling Using cpp_pedwarning (CPP_W_PEDANTIC instead of if (CPP_PEDANTIC cpp_error lets users suppress these diagnostics with #pragma GCC diagnostic ignored "-Wpedantic". This patch changes all instances of the cpp_error (CPP_DL_PEDWARN to cpp_pedwarning. In cases where the extension appears in a later C++ revision, we now condition the warning on the relevant -Wc++??-extensions flag instead of -Wpedantic; in such cases often the if (CPP_PEDANTIC) check is retained to preserve the default non-warning behavior. I didn't attempt to adjust the warning flags for the C compiler, since it seems to follow a different system than C++. The CPP_PEDANTIC check is also kept in _cpp_lex_direct to avoid an ICE in the self-tests from cb.diagnostics not being initialized. While working on testcases for these changes I noticed that the c-c++-common tests are not run with -pedantic-errors by default like the gcc.dg and g++.dg directories are. And if I specify -pedantic-errors with dg-options, the default -std= changes from c++?? to gnu++??, which interferes with some other pedwarns. So two of the tests are C++-only. libcpp/ChangeLog: * include/cpplib.h (enum cpp_warning_reason): Add CPP_W_CXX{14,17,20,23}_EXTENSIONS. * charset.cc (_cpp_valid_ucn, convert_hex, convert_oct) (convert_escape, narrow_str_to_charconst): Use cpp_pedwarning instead of cpp_error for pedwarns. * directives.cc (directive_diagnostics, _cpp_handle_directive) (do_line, do_elif): Likewise. * expr.cc (cpp_classify_number, eval_token): Likewise. * lex.cc (skip_whitespace, maybe_va_opt_error) (_cpp_lex_direct): Likewise. * macro.cc (_cpp_arguments_ok): Likewise. (replace_args): Use -Wvariadic-macros for pedwarn about empty macro arguments. gcc/c-family/ChangeLog: * c.opt: Add CppReason for Wc++{14,17,20,23}-extensions. * c-pragma.cc (handle_pragma_diagnostic_impl): Don't check OPT_Wc__23_extensions. gcc/testsuite/ChangeLog: * c-c++-common/pragma-diag-17.c: New test. * g++.dg/cpp0x/va-opt1.C: New test. * g++.dg/cpp23/named-universal-char-escape3.C: New test.
2024-08-28 01:15:16 +08:00
if (result & CPP_N_IMAGINARY)
cpp_pedwarning_with_line (pfile, CPP_W_PEDANTIC, virtual_location, 0,
"imaginary constants are a GCC extension");
if (radix == 2)
{
libcpp: adjust pedwarn handling Using cpp_pedwarning (CPP_W_PEDANTIC instead of if (CPP_PEDANTIC cpp_error lets users suppress these diagnostics with #pragma GCC diagnostic ignored "-Wpedantic". This patch changes all instances of the cpp_error (CPP_DL_PEDWARN to cpp_pedwarning. In cases where the extension appears in a later C++ revision, we now condition the warning on the relevant -Wc++??-extensions flag instead of -Wpedantic; in such cases often the if (CPP_PEDANTIC) check is retained to preserve the default non-warning behavior. I didn't attempt to adjust the warning flags for the C compiler, since it seems to follow a different system than C++. The CPP_PEDANTIC check is also kept in _cpp_lex_direct to avoid an ICE in the self-tests from cb.diagnostics not being initialized. While working on testcases for these changes I noticed that the c-c++-common tests are not run with -pedantic-errors by default like the gcc.dg and g++.dg directories are. And if I specify -pedantic-errors with dg-options, the default -std= changes from c++?? to gnu++??, which interferes with some other pedwarns. So two of the tests are C++-only. libcpp/ChangeLog: * include/cpplib.h (enum cpp_warning_reason): Add CPP_W_CXX{14,17,20,23}_EXTENSIONS. * charset.cc (_cpp_valid_ucn, convert_hex, convert_oct) (convert_escape, narrow_str_to_charconst): Use cpp_pedwarning instead of cpp_error for pedwarns. * directives.cc (directive_diagnostics, _cpp_handle_directive) (do_line, do_elif): Likewise. * expr.cc (cpp_classify_number, eval_token): Likewise. * lex.cc (skip_whitespace, maybe_va_opt_error) (_cpp_lex_direct): Likewise. * macro.cc (_cpp_arguments_ok): Likewise. (replace_args): Use -Wvariadic-macros for pedwarn about empty macro arguments. gcc/c-family/ChangeLog: * c.opt: Add CppReason for Wc++{14,17,20,23}-extensions. * c-pragma.cc (handle_pragma_diagnostic_impl): Don't check OPT_Wc__23_extensions. gcc/testsuite/ChangeLog: * c-c++-common/pragma-diag-17.c: New test. * g++.dg/cpp0x/va-opt1.C: New test. * g++.dg/cpp23/named-universal-char-escape3.C: New test.
2024-08-28 01:15:16 +08:00
bool warned = false;
if (!CPP_OPTION (pfile, binary_constants)
&& CPP_PEDANTIC (pfile))
libcpp: adjust pedwarn handling Using cpp_pedwarning (CPP_W_PEDANTIC instead of if (CPP_PEDANTIC cpp_error lets users suppress these diagnostics with #pragma GCC diagnostic ignored "-Wpedantic". This patch changes all instances of the cpp_error (CPP_DL_PEDWARN to cpp_pedwarning. In cases where the extension appears in a later C++ revision, we now condition the warning on the relevant -Wc++??-extensions flag instead of -Wpedantic; in such cases often the if (CPP_PEDANTIC) check is retained to preserve the default non-warning behavior. I didn't attempt to adjust the warning flags for the C compiler, since it seems to follow a different system than C++. The CPP_PEDANTIC check is also kept in _cpp_lex_direct to avoid an ICE in the self-tests from cb.diagnostics not being initialized. While working on testcases for these changes I noticed that the c-c++-common tests are not run with -pedantic-errors by default like the gcc.dg and g++.dg directories are. And if I specify -pedantic-errors with dg-options, the default -std= changes from c++?? to gnu++??, which interferes with some other pedwarns. So two of the tests are C++-only. libcpp/ChangeLog: * include/cpplib.h (enum cpp_warning_reason): Add CPP_W_CXX{14,17,20,23}_EXTENSIONS. * charset.cc (_cpp_valid_ucn, convert_hex, convert_oct) (convert_escape, narrow_str_to_charconst): Use cpp_pedwarning instead of cpp_error for pedwarns. * directives.cc (directive_diagnostics, _cpp_handle_directive) (do_line, do_elif): Likewise. * expr.cc (cpp_classify_number, eval_token): Likewise. * lex.cc (skip_whitespace, maybe_va_opt_error) (_cpp_lex_direct): Likewise. * macro.cc (_cpp_arguments_ok): Likewise. (replace_args): Use -Wvariadic-macros for pedwarn about empty macro arguments. gcc/c-family/ChangeLog: * c.opt: Add CppReason for Wc++{14,17,20,23}-extensions. * c-pragma.cc (handle_pragma_diagnostic_impl): Don't check OPT_Wc__23_extensions. gcc/testsuite/ChangeLog: * c-c++-common/pragma-diag-17.c: New test. * g++.dg/cpp0x/va-opt1.C: New test. * g++.dg/cpp23/named-universal-char-escape3.C: New test.
2024-08-28 01:15:16 +08:00
{
if (CPP_OPTION (pfile, cplusplus))
warned
= (cpp_pedwarning_with_line
(pfile, CPP_W_CXX14_EXTENSIONS, virtual_location, 0,
"binary constants are a C++14 feature or GCC extension"));
else
warned
= (cpp_pedwarning_with_line
(pfile, CPP_W_PEDANTIC, virtual_location, 0,
"binary constants are a C23 feature or GCC extension"));
}
if (!warned && CPP_OPTION (pfile, cpp_warn_c11_c23_compat) > 0)
c: Refer more consistently to C23 not C2X Continuing the move to refer to C23 in place of C2X throughout the source tree, update documentation, diagnostics, comments, variable and function names, etc., to use the C23 name. Testsuite updates are left for a future patch, except for testcases that test diagnostics that previously mentioned C2X (but in those testcases, sometimes other comments are updated, not just the diagnostic expectations). Bootstrapped with no regressions for x86_64-pc-linux-gnu. gcc/ * builtins.def (DEF_C2X_BUILTIN): Rename to DEF_C23_BUILTIN and use flag_isoc23 and function_c23_misc. * config/rl78/rl78.cc (rl78_option_override): Compare lang_hooks.name with "GNU C23" not "GNU C2X". * coretypes.h (function_c2x_misc): Rename to function_c23_misc. * doc/cpp.texi (@code{__has_attribute}): Refer to C23 instead of C2x. * doc/extend.texi: Likewise. * doc/invoke.texi: Likewise. * dwarf2out.cc (highest_c_language, gen_compile_unit_die): Compare against and return "GNU C23" language string instead of "GNU C2X". * ginclude/float.h: Refer to C23 instead of C2X in comments. * ginclude/stdint-gcc.h: Likewise. * glimits.h: Likewise. * tree.h: Likewise. gcc/ada/ * gcc-interface/utils.cc (flag_isoc2x): Rename to flag_isoc23. gcc/c-family/ * c-common.cc (flag_isoc2x): Rename to flag_isoc23. (c_common_reswords): Use D_C23 instead of D_C2X. * c-common.h: Refer throughout to C23 instead of C2X in comments. (D_C2X): Rename to D_C23. (flag_isoc2x): Rename to flag_isoc23. * c-cppbuiltin.cc (builtin_define_float_constants): Use flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2x in comments. * c-format.cc: Use STD_C23 instead of STD_C2X and flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2X in comments. * c-format.h: Use STD_C23 instead of STD_C2X. * c-lex.cc: Use warn_c11_c23_compat instead of warn_c11_c2x_compat and flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2X in diagnostics. * c-opts.cc: Use flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2X in comments. (set_std_c2x): Rename to set_std_c23. * c.opt (Wc11-c23-compat): Use CPP(cpp_warn_c11_c23_compat) CppReason(CPP_W_C11_C23_COMPAT) Var(warn_c11_c23_compat) instead of CPP(cpp_warn_c11_c2x_compat) CppReason(CPP_W_C11_C2X_COMPAT) Var(warn_c11_c2x_compat). gcc/c/ * c-decl.cc: Use flag_isoc23 instead of flag_isoc2x and c23_auto_p instead of c2x_auto_p. Refer to C23 instead of C2X in diagnostics and comments. * c-errors.cc: Use flag_isoc23 instead of flag_isoc2x and warn_c11_c23_compat instead of warn_c11_c2x_compat. Refer to C23 instead of C2X in comments. * c-parser.cc: Use flag_isoc23 instead of flag_isoc2x, warn_c11_c23_compat instead of warn_c11_c2x_compat, c23_auto_p instead of c2x_auto_p and D_C23 instead of D_C2X. Refer to C23 instead of C2X in diagnostics and comments. * c-tree.h: Refer to C23 instead of C2X in comments. (struct c_declspecs): Rename c2x_auto_p to c23_auto_p. * c-typeck.cc: Use flag_isoc23 instead of flag_isoc2x and warn_c11_c23_compat instead of warn_c11_c2x_compat. Refer to C23 instead of C2X in diagnostics and comments. gcc/fortran/ * gfortran.h (gfc_real_info): Refer to C23 instead of C2X in comment. gcc/lto/ * lto-lang.cc (flag_isoc2x): Rename to flag_isoc23. gcc/testsuite/ * gcc.dg/binary-constants-2.c: Refer to C23 instead of C2X. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/bitint-23.c: Likewise. * gcc.dg/bitint-26.c: Likewise. * gcc.dg/bitint-27.c: Likewise. * gcc.dg/c11-attr-syntax-1.c: Likewise. * gcc.dg/c11-attr-syntax-2.c: Likewise. * gcc.dg/c11-floatn-1.c: Likewise. * gcc.dg/c11-floatn-2.c: Likewise. * gcc.dg/c11-floatn-3.c: Likewise. * gcc.dg/c11-floatn-4.c: Likewise. * gcc.dg/c11-floatn-5.c: Likewise. * gcc.dg/c11-floatn-6.c: Likewise. * gcc.dg/c11-floatn-7.c: Likewise. * gcc.dg/c11-floatn-8.c: Likewise. * gcc.dg/c2x-attr-syntax-4.c: Likewise. * gcc.dg/c2x-attr-syntax-6.c: Likewise. * gcc.dg/c2x-attr-syntax-7.c: Likewise. * gcc.dg/c2x-binary-constants-2.c: Likewise. * gcc.dg/c2x-floatn-5.c: Likewise. * gcc.dg/c2x-floatn-6.c: Likewise. * gcc.dg/c2x-floatn-7.c: Likewise. * gcc.dg/c2x-floatn-8.c: Likewise. * gcc.dg/c2x-nullptr-4.c: Likewise. * gcc.dg/c2x-qual-2.c: Likewise. * gcc.dg/c2x-qual-3.c: Likewise. * gcc.dg/c2x-qual-6.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c2x-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu2x-warning-2.c: Likewise. * gcc.dg/dfp/c11-constants-1.c: Likewise. * gcc.dg/dfp/c11-constants-2.c: Likewise. * gcc.dg/dfp/c2x-constants-2.c: Likewise. * gcc.dg/dfp/constants-pedantic.c: Likewise. * gcc.dg/pr30260.c: Likewise. * gcc.dg/system-binary-constants-1.c: Likewise. libcpp/ * directives.cc: Refer to C23 instead of C2X in diagnostics and comments. (STDC2X): Rename to STDC23. * expr.cc: Use cpp_warn_c11_c23_compat instead of cpp_warn_c11_c2x_compat and CPP_W_C11_C23_COMPAT instead of CPP_W_C11_C2X_COMPAT. Refer to C23 instead of C2X in diagnostics and comments. * include/cpplib.h: Refer to C23 instead of C2X in diagnostics and comments. (CLK_GNUC2X): Rename to CLK_GNUC23. (CLK_STDC2X): Rename to CLK_STDC23. (CPP_W_C11_C2X_COMPAT): Rename to CPP_W_C11_C23_COMPAT. * init.cc: Use GNUC23 instead of GNUC2X, STDC23 instead of STDC2X and cpp_warn_c11_c23_compat instead of cpp_warn_c11_c2x_compat. * lex.cc (maybe_va_opt_error): Refer to C23 instead of C2X in diagnostic. * macro.cc (_cpp_arguments_ok): Refer to C23 instead of C2X in comment.
2023-11-07 22:19:36 +08:00
cpp_warning_with_line (pfile, CPP_W_C11_C23_COMPAT,
virtual_location, 0,
c: Refer more consistently to C23 not C2X Continuing the move to refer to C23 in place of C2X throughout the source tree, update documentation, diagnostics, comments, variable and function names, etc., to use the C23 name. Testsuite updates are left for a future patch, except for testcases that test diagnostics that previously mentioned C2X (but in those testcases, sometimes other comments are updated, not just the diagnostic expectations). Bootstrapped with no regressions for x86_64-pc-linux-gnu. gcc/ * builtins.def (DEF_C2X_BUILTIN): Rename to DEF_C23_BUILTIN and use flag_isoc23 and function_c23_misc. * config/rl78/rl78.cc (rl78_option_override): Compare lang_hooks.name with "GNU C23" not "GNU C2X". * coretypes.h (function_c2x_misc): Rename to function_c23_misc. * doc/cpp.texi (@code{__has_attribute}): Refer to C23 instead of C2x. * doc/extend.texi: Likewise. * doc/invoke.texi: Likewise. * dwarf2out.cc (highest_c_language, gen_compile_unit_die): Compare against and return "GNU C23" language string instead of "GNU C2X". * ginclude/float.h: Refer to C23 instead of C2X in comments. * ginclude/stdint-gcc.h: Likewise. * glimits.h: Likewise. * tree.h: Likewise. gcc/ada/ * gcc-interface/utils.cc (flag_isoc2x): Rename to flag_isoc23. gcc/c-family/ * c-common.cc (flag_isoc2x): Rename to flag_isoc23. (c_common_reswords): Use D_C23 instead of D_C2X. * c-common.h: Refer throughout to C23 instead of C2X in comments. (D_C2X): Rename to D_C23. (flag_isoc2x): Rename to flag_isoc23. * c-cppbuiltin.cc (builtin_define_float_constants): Use flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2x in comments. * c-format.cc: Use STD_C23 instead of STD_C2X and flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2X in comments. * c-format.h: Use STD_C23 instead of STD_C2X. * c-lex.cc: Use warn_c11_c23_compat instead of warn_c11_c2x_compat and flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2X in diagnostics. * c-opts.cc: Use flag_isoc23 instead of flag_isoc2x. Refer to C23 instead of C2X in comments. (set_std_c2x): Rename to set_std_c23. * c.opt (Wc11-c23-compat): Use CPP(cpp_warn_c11_c23_compat) CppReason(CPP_W_C11_C23_COMPAT) Var(warn_c11_c23_compat) instead of CPP(cpp_warn_c11_c2x_compat) CppReason(CPP_W_C11_C2X_COMPAT) Var(warn_c11_c2x_compat). gcc/c/ * c-decl.cc: Use flag_isoc23 instead of flag_isoc2x and c23_auto_p instead of c2x_auto_p. Refer to C23 instead of C2X in diagnostics and comments. * c-errors.cc: Use flag_isoc23 instead of flag_isoc2x and warn_c11_c23_compat instead of warn_c11_c2x_compat. Refer to C23 instead of C2X in comments. * c-parser.cc: Use flag_isoc23 instead of flag_isoc2x, warn_c11_c23_compat instead of warn_c11_c2x_compat, c23_auto_p instead of c2x_auto_p and D_C23 instead of D_C2X. Refer to C23 instead of C2X in diagnostics and comments. * c-tree.h: Refer to C23 instead of C2X in comments. (struct c_declspecs): Rename c2x_auto_p to c23_auto_p. * c-typeck.cc: Use flag_isoc23 instead of flag_isoc2x and warn_c11_c23_compat instead of warn_c11_c2x_compat. Refer to C23 instead of C2X in diagnostics and comments. gcc/fortran/ * gfortran.h (gfc_real_info): Refer to C23 instead of C2X in comment. gcc/lto/ * lto-lang.cc (flag_isoc2x): Rename to flag_isoc23. gcc/testsuite/ * gcc.dg/binary-constants-2.c: Refer to C23 instead of C2X. * gcc.dg/binary-constants-3.c: Likewise. * gcc.dg/bitint-23.c: Likewise. * gcc.dg/bitint-26.c: Likewise. * gcc.dg/bitint-27.c: Likewise. * gcc.dg/c11-attr-syntax-1.c: Likewise. * gcc.dg/c11-attr-syntax-2.c: Likewise. * gcc.dg/c11-floatn-1.c: Likewise. * gcc.dg/c11-floatn-2.c: Likewise. * gcc.dg/c11-floatn-3.c: Likewise. * gcc.dg/c11-floatn-4.c: Likewise. * gcc.dg/c11-floatn-5.c: Likewise. * gcc.dg/c11-floatn-6.c: Likewise. * gcc.dg/c11-floatn-7.c: Likewise. * gcc.dg/c11-floatn-8.c: Likewise. * gcc.dg/c2x-attr-syntax-4.c: Likewise. * gcc.dg/c2x-attr-syntax-6.c: Likewise. * gcc.dg/c2x-attr-syntax-7.c: Likewise. * gcc.dg/c2x-binary-constants-2.c: Likewise. * gcc.dg/c2x-floatn-5.c: Likewise. * gcc.dg/c2x-floatn-6.c: Likewise. * gcc.dg/c2x-floatn-7.c: Likewise. * gcc.dg/c2x-floatn-8.c: Likewise. * gcc.dg/c2x-nullptr-4.c: Likewise. * gcc.dg/c2x-qual-2.c: Likewise. * gcc.dg/c2x-qual-3.c: Likewise. * gcc.dg/c2x-qual-6.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c2x-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu2x-warning-2.c: Likewise. * gcc.dg/dfp/c11-constants-1.c: Likewise. * gcc.dg/dfp/c11-constants-2.c: Likewise. * gcc.dg/dfp/c2x-constants-2.c: Likewise. * gcc.dg/dfp/constants-pedantic.c: Likewise. * gcc.dg/pr30260.c: Likewise. * gcc.dg/system-binary-constants-1.c: Likewise. libcpp/ * directives.cc: Refer to C23 instead of C2X in diagnostics and comments. (STDC2X): Rename to STDC23. * expr.cc: Use cpp_warn_c11_c23_compat instead of cpp_warn_c11_c2x_compat and CPP_W_C11_C23_COMPAT instead of CPP_W_C11_C2X_COMPAT. Refer to C23 instead of C2X in diagnostics and comments. * include/cpplib.h: Refer to C23 instead of C2X in diagnostics and comments. (CLK_GNUC2X): Rename to CLK_GNUC23. (CLK_STDC2X): Rename to CLK_STDC23. (CPP_W_C11_C2X_COMPAT): Rename to CPP_W_C11_C23_COMPAT. * init.cc: Use GNUC23 instead of GNUC2X, STDC23 instead of STDC2X and cpp_warn_c11_c23_compat instead of cpp_warn_c11_c2x_compat. * lex.cc (maybe_va_opt_error): Refer to C23 instead of C2X in diagnostic. * macro.cc (_cpp_arguments_ok): Refer to C23 instead of C2X in comment.
2023-11-07 22:19:36 +08:00
"binary constants are a C23 feature");
}
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-27 03:30:59 +08: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 08:57:09 +08: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-29 01:59:06 +08: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 06:53:12 +08: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 08:57:09 +08:00
libcpp, c-family: Add (dumb) C23 N3017 #embed support [PR105863] The following patch implements the C23 N3017 "#embed - a scannable, tooling-friendly binary resource inclusion mechanism" paper. The implementation is intentionally dumb, in that it doesn't significantly speed up compilation of larger initializers and doesn't make it possible to use huge #embeds (like several gigabytes large, that is compile time and memory still infeasible). There are 2 reasons for this. One is that I think like it is implemented now in the patch is how we should use it for the smaller #embed sizes, dunno with which boundary, whether 32 bytes or 64 or something like that, certainly handling the single byte cases which is something that can appear anywhere in the source where constant integer literal can appear is desirable and I think for a few bytes it isn't worth it to come up with something smarter and users would like to e.g. see it in -E readably as well (perhaps the slow vs. fast boundary should be determined by command line option). And the other one is to be able to more easily find regressions in behavior caused by the optimizations, so we have something to get back in git to compare against. I'm definitely willing to work on the optimizations (likely introduce a new CPP_* token type to refer to a range of libcpp owned memory (start + size) and similarly some tree which can do the same, and can be at any time e.g. split into 2 subparts + say INTEGER_CST in between if needed say for const unsigned char d[] = { #embed "2GB.dat" prefix (0, 0, ) suffix (, [0x40000000] = 42) }; still without having to copy around huge amounts of data; STRING_CST owns the memory it points to and can be only 2GB in size), but would like to do that incrementally. And would like to first include some extensions also not included in this patch, like gnu::offset (off) parameter to allow to skip certain constant amount of bytes at the start of the files, plus gnu::base64 ("base64_encoded_data") parameter to add something which can store more efficiently large amounts of the #embed data in preprocessed source. I've been cross-checking all the tests also against the LLVM implementation https://github.com/llvm/llvm-project/pull/68620 which has been for a few hours even committed to LLVM trunk but reverted afterwards. LLVM now has the support committed and I admit I haven't rechecked whether the behavior on the below mentioned spots have been fixed in it already or not yet. The patch uses --embed-dir= option that clang plans to add above and doesn't use other variants on the search directories yet, plus there are no default directories at least for the time being where to search for embed files. So, #embed "..." works if it is found in the same directory (or relative to the current file's directory) and #embed "/..." or #embed </...> work always, but relative #embed <...> doesn't unless at least one --embed-dir= is specified. There is no reason to differentiate between system and non-system directories, so we don't need -isystem like counterpart, perhaps -iquote like counterpart could be useful in the future, dunno what else. It has --embed-directory=dir and --embed-directory dir as aliases. There are some differences beyond clang ICEs, so I'd like to point them out to make sure there is agreement on the choices in the patch. They are also mentioned in the comments of the llvm pull request. The most important is that the GCC patch (as well as the original thephd.dev LLVM branch on godbolt) expands #embed (or acts as if it is expanded) into a mere sequence of numbers like 123,2,35,26 rather then what clang effectively treats as (unsigned char)123,(unsigned char)2,(unsigned char)35,(unsigned char)26 but only does that when using integrated preprocessor, not when using -save-temps where it acts as GCC. JeanHeyd as the original author agrees that is how it is currently worded in C23. Another difference (not tested in the testsuite, not sure how to check for effective target /dev/urandom nor am sure it is desirable to check that during testsuite) is how to treat character devices, named pipes etc. (block devices are errored on). The original paper uses /dev/urandom in various examples and seems to assume that unlike regular files the devices aren't really cached, so #embed </dev/urandom> limit(1) prefix(int a = ) suffix(;) #embed </dev/urandom> limit(1) prefix(int b = ) suffix(;) usually results in a != b. That is what the godbolt thephd.dev branch implements too and what this patch does as well, but clang actually seems to just go from st.st_size == 0, ergo it must be zero-sized resource and so just copies over if_empty if present. It is really questionable what to do about the character devices/named pipes with __has_embed, for regular files the patch doesn't read anything from them, relies on st.st_size + limit for whether it is empty or non-empty. But I don't know of a way to check if read on say a character device would read anything or not (the </dev/null> limit (1) vs. </dev/zero> limit (1) cases), and if we read something, that would be better cached for later because #embed later if it reads again could read no further data even when it first read something. So, the patch currently for __has_embed just always returns 2 on the non-regular files, like the thephd.dev branch does as well and like the clang pull request as well. A question is also what to do for gnu::offset on the non-regular files even for #embed, those aren't seekable and do we want to just read and throw away the offset bytes each time we see it used? clang also chokes on the #if __has_embed (__FILE__ __limit__ (1) __prefix__ () suffix (1 / 0) \ __if_empty__ ((({{[0[0{0{0(0(0)1)1}1}]]}})))) != __STDC_EMBED_FOUND__ #error "__has_embed fail" #endif in embed-1.c, but thephd.dev branch accepts it and I don't see why it shouldn't, (({{[0[0{0{0(0(0)1)1}1}]]}}))) is a balanced token sequence and the file isn't empty, so it should just be parsed and discarded. clang also IMHO mishandles const unsigned char w[] = { #embed __FILE__ prefix([0] = 42, [15] =) limit(32) }; but again only without -save-temps, seems like it treats it as [0] = 42, [15] = (99,111,110,115,116,32,117,110,115,105,103,110,101,100, 32,99,104,97,114,32,119,91,93,32,61,32,123,10,35,101,109,98) rather than [0] = 42, [15] = 99,111,110,115,116,32,117,110,115,105,103,110,101,100, 32,99,104,97,114,32,119,91,93,32,61,32,123,10,35,101,109,98 and warns on it for -Wunused-value and just compiles it as [0] = 42, [15] = 98 And also void foo (int, int, int, int); void bar (void) { foo ( #embed __FILE__ limit (4) prefix (172 + ) suffix (+ 2) ); } is treated as 172 + (118, 111, 105, 100) + 2 rather than 172 + 118, 111, 105, 100 + 2 which clang -save-temps or GCC treats it like, so results in just one argument passed rather than 4. if (!strstr ((const char *) magna_carta, "imprisonétur")) abort (); in the testcase fails as well, but in that case calling it in gdb succeeds: p ((char *(*)(char *, char *))__strstr_sse2) (magna_carta, "imprisonétur") $2 = 0x555555558d3c <magna_carta+11564> "imprisonétur aut disseisiátur"... so I guess they are just trying to constant evaluate strstr and do it incorrectly. They started with making the optimizations together in the initial patch set, so they don't have the luxury to compare if it is just because of the optimization they are trying to do or because that is how the feature works for them. At least unless they use -save-temps for now. There is also different behavior between clang and gcc on -M or other dependency generating options. Seems clang includes the __has_embed searched files in dependencies, while my patch doesn't. But so does clang for __has_include and GCC doesn't. Emitting a hard dependency on some header just because there was __has_include/__has_embed for it seems wrong to me, because (at least when properly written) the source likely doesn't mind if the file is missing, it will do something else, so a hard error from make because of it doesn't seem right. Does make have some weaker dependencies, such that if some file can be remade it is but if it doesn't exist, it isn't fatal? I wonder whether #embed <non-existent-file> really needs to be fatal or whether we could simply after diagnosing it pretend the file exists and is empty. For #include I think fatal errors make tons of sense, but perhaps for #embed which is more localized we'd get better error reporting if we didn't bail out immediately. Note, both GCC and clang currently treat those as fatal errors. clang also added -dE option which with -E instead of preprocessing the #embed directives keeps them as is, but the preprocessed source then isn't self-contained. That option looks more harmful than useful to me. Also, it isn't clear to me from C23 whether it is possible to have __has_include/__has_c_attribute/__has_embed expressions inside of the limit #embed/__has_embed argument. 6.10.3.2/2 says that defined should not appear there (and the patch diagnoses it and testsuite tests), but for __has_include/__has_embed etc. 6.10.1/11 says: "The identifiers __has_include, __has_embed, and __has_c_attribute shall not appear in any context not mentioned in this subclause." If that subclause in that case means 6.10.1, then it presumably shouldn't appear in #embed in 6.10.3, but __has_embed is in 6.10.1... But 6.10.3.2/3 says that it should be parsed according to the 6.10.1 rules. Haven't included tests like #if __has_embed (__FILE__ limit (__has_embed (__FILE__ limit (1)))) or #embed __FILE__ limit (__has_include (__FILE__)) into the testsuite because of the doubts but I think the patch should handle those right now. The reason I've used Magna Carta text in some of the testcases is that I hope it shouldn't be copyrighted after the centuries and I'd strongly prefer not to have binary blobs in git after the xz backdoor lesson and wanted something larger which doesn't change all the time. Oh, BTW, I see in C23 draft 6.10.3.2 in Example 4 if (f_source == NULL); return 1; (note the spurious semicolon after closing paren), has that been fixed already? Like the thephd.dev and clang implementations, the patch always macro expands the whole #embed and __has_embed directives except for the embed keyword. That is most likely not what C23 says, my limited understanding right now is that in #embed one needs to parse the whole directive line with macro expansion disabled and check if it satisfies the grammar, if not, the whole directive is macro expanded, if yes, only the limit parameter argument is macro expanded and the prefix/suffix/if_empty arguments are maybe macro expanded when actually used (and not at all if unused). And I think __has_embed macro expansion has conflicting rules. 2024-09-12 Jakub Jelinek <jakub@redhat.com> PR c/105863 libcpp/ * include/cpplib.h: Implement C23 N3017 #embed - a scannable, tooling-friendly binary resource inclusion mechanism paper. (struct cpp_options): Add embed member. (enum cpp_builtin_type): Add BT_HAS_EMBED. (cpp_set_include_chains): Add another cpp_dir * argument to the declaration. * internal.h (enum include_type): Add IT_EMBED. (struct cpp_reader): Add embed_include member. (struct cpp_embed_params_tokens): New type. (struct cpp_embed_params): New type. (_cpp_get_token_no_padding): Declare. (enum _cpp_find_file_kind): Add _cpp_FFK_EMBED and _cpp_FFK_HAS_EMBED. (_cpp_stack_embed): Declare. (_cpp_parse_expr): Change return type to cpp_num_part instead of bool, change second argument from bool to const char * and add third argument. (_cpp_parse_embed_params): Declare. * directives.cc (DIRECTIVE_TABLE): Add embed entry. (end_directive): Don't call skip_rest_of_line for T_EMBED directive. (_cpp_handle_directive): Return 2 rather than 1 for T_EMBED in directives-only mode. (parse_include): Don't Call check_eol for T_EMBED directive. (skip_balanced_token_seq): New function. (EMBED_PARAMS): Define. (enum embed_param_kind): New type. (embed_params): New variable. (_cpp_parse_embed_params): New function. (do_embed): New function. (do_if): Adjust _cpp_parse_expr caller. (do_elif): Likewise. * expr.cc (parse_defined): Diagnose defined in #embed or __has_embed parameters. (_cpp_parse_expr): Change return type to cpp_num_part instead of bool, change second argument from bool to const char * and add third argument. Adjust function comment. For #embed/__has_embed parameters add an artificial CPP_OPEN_PAREN. Use the second argument DIR directly instead of string literals conditional on IS_IF. For #embed/__has_embed parameter, stop on reaching CPP_CLOSE_PAREN matching the artificial one. Diagnose negative or too large embed parameter operands. (num_binary_op): Use #embed instead of #if for diagnostics if inside #embed/__has_embed parameter. (num_div_op): Likewise. * files.cc (struct _cpp_file): Add limit member and embed bitfield. (search_cache): Add IS_EMBED argument, formatting fix. Skip over files with different file->embed from the argument. (find_file_in_dir): Don't call pch_open_file if file->embed. (_cpp_find_file): Handle _cpp_FFK_EMBED and _cpp_FFK_HAS_EMBED. (read_file_guts): Formatting fix. (has_unique_contents): Ignore file->embed files. (search_path_head): Handle IT_EMBED type. (_cpp_stack_embed): New function. (_cpp_get_file_stat): Formatting fix. (cpp_set_include_chains): Add embed argument, save it to pfile->embed_include and compute lens for the chain. * init.cc (struct lang_flags): Add embed member. (lang_defaults): Add embed initializers. (cpp_set_lang): Initialize CPP_OPTION (pfile, embed). (builtin_array): Add __has_embed entry. (cpp_init_builtins): Predefine __STDC_EMBED_NOT_FOUND__, __STDC_EMBED_FOUND__ and __STDC_EMBED_EMPTY__. * lex.cc (cpp_directive_only_process): Handle #embed. * macro.cc (cpp_get_token_no_padding): Rename to ... (_cpp_get_token_no_padding): ... this. No longer static. (builtin_has_include_1): New function. (builtin_has_include): Use it. Use _cpp_get_token_no_padding instead of cpp_get_token_no_padding. (builtin_has_embed): New function. (_cpp_builtin_macro_text): Handle BT_HAS_EMBED. gcc/ * doc/cppdiropts.texi (--embed-dir=): Document. * doc/cpp.texi (Binary Resource Inclusion): New chapter. (__has_embed): Document. * doc/invoke.texi (Directory Options): Mention --embed-dir=. * gcc.cc (cpp_unique_options): Add %{-embed*}. * genmatch.cc (main): Adjust cpp_set_include_chains caller. * incpath.h (enum incpath_kind): Add INC_EMBED. * incpath.cc (merge_include_chains): Handle INC_EMBED. (register_include_chains): Adjust cpp_set_include_chains caller. gcc/c-family/ * c.opt (-embed-dir=): New option. (-embed-directory): New alias. (-embed-directory=): New alias. * c-opts.cc (c_common_handle_option): Handle OPT__embed_dir_. gcc/testsuite/ * c-c++-common/cpp/embed-1.c: New test. * c-c++-common/cpp/embed-2.c: New test. * c-c++-common/cpp/embed-3.c: New test. * c-c++-common/cpp/embed-4.c: New test. * c-c++-common/cpp/embed-5.c: New test. * c-c++-common/cpp/embed-6.c: New test. * c-c++-common/cpp/embed-7.c: New test. * c-c++-common/cpp/embed-8.c: New test. * c-c++-common/cpp/embed-9.c: New test. * c-c++-common/cpp/embed-10.c: New test. * c-c++-common/cpp/embed-11.c: New test. * c-c++-common/cpp/embed-12.c: New test. * c-c++-common/cpp/embed-13.c: New test. * c-c++-common/cpp/embed-14.c: New test. * c-c++-common/cpp/embed-25.c: New test. * c-c++-common/cpp/embed-26.c: New test. * c-c++-common/cpp/embed-dir/embed-1.inc: New test. * c-c++-common/cpp/embed-dir/embed-3.c: New test. * c-c++-common/cpp/embed-dir/embed-4.c: New test. * c-c++-common/cpp/embed-dir/magna-carta.txt: New test. * gcc.dg/cpp/embed-1.c: New test. * gcc.dg/cpp/embed-2.c: New test. * gcc.dg/cpp/embed-3.c: New test. * gcc.dg/cpp/embed-4.c: New test. * g++.dg/cpp/embed-1.C: New test. * g++.dg/cpp/embed-2.C: New test. * g++.dg/cpp/embed-3.C: New test.
2024-09-12 17:15:38 +08:00
if (pfile->state.in_directive == 3)
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics When working on #embed support, or -Wheader-guard or other recent libcpp changes, I've been annoyed by the libcpp diagnostics being visually different from normal gcc diagnostics, especially in the area of quoting stuff in the diagnostic messages. Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use %</%>, %qs etc. in there, while libcpp diagnostics was marked as printf and in libcpp we've been very creative with quoting stuff, either no quotes at all, or "something" quoting, or 'something' quoting, or `something' quoting (but in none of the cases it used colors consistently with the rest of the compiler). Now, libcpp diagnostics is always emitted using a callback, pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with genmatch.cc: cb->diagnostic = diagnostic_cb; c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic; fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic; where the latter two just use diagnostic_report_diagnostic, so actually support all the gcc_diag stuff, only the genmatch.cc case didn't. So, the following patch changes genmatch.cc to use pp_format* instead of vfprintf so that it supports the gcc_diag formatting (pretty-print.o unfortunately has various dependencies, so had to link genmatch with libcommon.a libbacktrace.a and tweak Makefile.in so that there are no circular dependencies) and marks the libcpp diagnostic routines as gcc_diag rather than printf. That change resulted in hundreds of -Wformat-diag new warnings (most of them useful and resulting IMHO in better diagnostics), so the rest of the patch is changing the format strings to make -Wformat-diag happy and adjusting the testsuite for the differences in how is the diagnostic reformatted. Dunno if some out of GCC tree projects use libcpp, that case would make it harder because one couldn't use vfprintf in the diagnostic callback anymore, but there is always David's libdiagnostic which could be used for that purpose IMHO. 2024-10-12 Jakub Jelinek <jakub@redhat.com> libcpp/ * include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define. (struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF on diagnostic callback. (cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3. (cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. (cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6) instead of ATTRIBUTE_PRINTF_5. (cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. * Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather than --language=c. * errors.cc (cpp_diagnostic_at, cpp_diagnostic, cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of -ATTRIBUTE_FPTR_PRINTF. * charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex, convert_oct, convert_escape): Fix up -Wformat-diag warnings. (cpp_interpret_string_ranges, count_source_chars): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF. (narrow_str_to_charconst): Fix up -Wformat-diag warnings. * directives.cc (check_eol_1, directive_diagnostics, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, do_include_next, _cpp_parse_embed_params, do_embed, read_flag, do_line, do_linemarker, register_pragma_1, do_pragma_once, do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison, do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, do_assert, cpp_define_unused): Likewise. * expr.cc (cpp_classify_number, parse_defined, eval_token, _cpp_parse_expr, reduce, check_promotion): Likewise. * files.cc (_cpp_find_file, finish_base64_embed, _cpp_pop_file_buffer): Likewise. * init.cc (sanity_checks): Likewise. * lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char, _cpp_warn_invalid_utf8, _cpp_skip_block_comment, warn_about_normalization, forms_identifier_p, maybe_va_opt_error, identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise. * macro.cc (class vaopt_state, builtin_has_include_1, builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro, _cpp_builtin_macro_text, builtin_macro, stringify_arg, _cpp_arguments_ok, collect_args, enter_macro_context, _cpp_save_parameter, parse_params, create_iso_definition, _cpp_create_definition, check_trad_stringification): Likewise. * pch.cc (cpp_valid_state): Likewise. * traditional.cc (_cpp_scan_out_logical_line, recursive_macro): Likewise. gcc/ * Makefile.in (generated_files): Remove {gimple,generic}-match*. (generated_match_files): New variable. Add a dependency of $(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those. (build/genmatch$(build_exeext)): Depend on and link against libcommon.a and $(LIBBACKTRACE). * genmatch.cc: Include pretty-print.h and input.h. (ggc_internal_cleared_alloc, ggc_free): Remove. (fatal): New function. (line_table): Remove. (linemap_client_expand_location_to_spelling_point): Remove. (diagnostic_cb): Use gcc_diag rather than printf format. Use pp_format_verbatim on a temporary pretty_printer instead of vfprintf. (fatal_at, warning_at): Use gcc_diag rather than printf format. (output_line_directive): Rename location_hash to loc_hash. (parser::eat_ident, parser::parse_operation, parser::parse_expr, parser::parse_pattern, parser::finish_match_operand): Fix up -Wformat-diag warnings. gcc/c-family/ * c-lex.cc (c_common_has_attribute, c_common_lex_availability_macro): Fix up -Wformat-diag warnings. gcc/testsuite/ * c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for libcpp diagnostic formatting changes. * c-c++-common/cpp/embed-3.c: Likewise. * c-c++-common/cpp/embed-4.c: Likewise. * c-c++-common/cpp/embed-16.c: Likewise. * c-c++-common/cpp/embed-18.c: Likewise. * c-c++-common/cpp/eof-2.c: Likewise. * c-c++-common/cpp/eof-3.c: Likewise. * c-c++-common/cpp/fmax-include-depth.c: Likewise. * c-c++-common/cpp/has-builtin.c: Likewise. * c-c++-common/cpp/line-2.c: Likewise. * c-c++-common/cpp/line-3.c: Likewise. * c-c++-common/cpp/macro-arg-count-1.c: Likewise. * c-c++-common/cpp/macro-arg-count-2.c: Likewise. * c-c++-common/cpp/macro-ranges.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-4.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-5.c: Likewise. * c-c++-common/cpp/pr88974.c: Likewise. * c-c++-common/cpp/va-opt-error.c: Likewise. * c-c++-common/cpp/va-opt-pedantic.c: Likewise. * c-c++-common/cpp/Wheader-guard-2.c: Likewise. * c-c++-common/cpp/Wheader-guard-3.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-1.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-2.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-3.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c: Likewise. * c-c++-common/pr68833-3.c: Likewise. * c-c++-common/raw-string-directive-1.c: Likewise. * gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise. * gcc.dg/binary-constants-4.c: Likewise. * gcc.dg/builtin-redefine.c: Likewise. * gcc.dg/cpp/19951025-1.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c23-elifdef-2.c: Likewise. * gcc.dg/cpp/c23-warning-2.c: Likewise. * gcc.dg/cpp/embed-2.c: Likewise. * gcc.dg/cpp/embed-3.c: Likewise. * gcc.dg/cpp/embed-4.c: Likewise. * gcc.dg/cpp/expr.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu23-warning-2.c: Likewise. * gcc.dg/cpp/include6.c: Likewise. * gcc.dg/cpp/pr35322.c: Likewise. * gcc.dg/cpp/tr-warn6.c: Likewise. * gcc.dg/cpp/undef2.c: Likewise. * gcc.dg/cpp/warn-comments.c: Likewise. * gcc.dg/cpp/warn-comments-2.c: Likewise. * gcc.dg/cpp/warn-comments-3.c: Likewise. * gcc.dg/cpp/warn-cxx-compat.c: Likewise. * gcc.dg/cpp/warn-cxx-compat-2.c: Likewise. * gcc.dg/cpp/warn-deprecated.c: Likewise. * gcc.dg/cpp/warn-deprecated-2.c: Likewise. * gcc.dg/cpp/warn-long-long.c: Likewise. * gcc.dg/cpp/warn-long-long-2.c: Likewise. * gcc.dg/cpp/warn-normalized-1.c: Likewise. * gcc.dg/cpp/warn-normalized-2.c: Likewise. * gcc.dg/cpp/warn-normalized-3.c: Likewise. * gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise. * gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise. * gcc.dg/cpp/warn-redefined.c: Likewise. * gcc.dg/cpp/warn-redefined-2.c: Likewise. * gcc.dg/cpp/warn-traditional.c: Likewise. * gcc.dg/cpp/warn-traditional-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-1.c: Likewise. * gcc.dg/cpp/warn-trigraphs-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-3.c: Likewise. * gcc.dg/cpp/warn-trigraphs-4.c: Likewise. * gcc.dg/cpp/warn-undef.c: Likewise. * gcc.dg/cpp/warn-undef-2.c: Likewise. * gcc.dg/cpp/warn-unused-macros.c: Likewise. * gcc.dg/cpp/warn-unused-macros-2.c: Likewise. * gcc.dg/pch/counter-2.c: Likewise. * g++.dg/cpp0x/udlit-error1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-1.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-3.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-4.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-5.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-6.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-7.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-8.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-9.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-10.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-11.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-12.C: Likewise. * g++.dg/cpp/elifdef-3.C: Likewise. * g++.dg/cpp/elifdef-5.C: Likewise. * g++.dg/cpp/elifdef-6.C: Likewise. * g++.dg/cpp/elifdef-7.C: Likewise. * g++.dg/cpp/embed-1.C: Likewise. * g++.dg/cpp/embed-2.C: Likewise. * g++.dg/cpp/pedantic-errors.C: Likewise. * g++.dg/cpp/warning-1.C: Likewise. * g++.dg/cpp/warning-2.C: Likewise. * g++.dg/ext/bitint1.C: Likewise. * g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
cpp_error (pfile, CPP_DL_ERROR, "%<defined%> in %<#embed%> parameter");
libcpp, c-family: Add (dumb) C23 N3017 #embed support [PR105863] The following patch implements the C23 N3017 "#embed - a scannable, tooling-friendly binary resource inclusion mechanism" paper. The implementation is intentionally dumb, in that it doesn't significantly speed up compilation of larger initializers and doesn't make it possible to use huge #embeds (like several gigabytes large, that is compile time and memory still infeasible). There are 2 reasons for this. One is that I think like it is implemented now in the patch is how we should use it for the smaller #embed sizes, dunno with which boundary, whether 32 bytes or 64 or something like that, certainly handling the single byte cases which is something that can appear anywhere in the source where constant integer literal can appear is desirable and I think for a few bytes it isn't worth it to come up with something smarter and users would like to e.g. see it in -E readably as well (perhaps the slow vs. fast boundary should be determined by command line option). And the other one is to be able to more easily find regressions in behavior caused by the optimizations, so we have something to get back in git to compare against. I'm definitely willing to work on the optimizations (likely introduce a new CPP_* token type to refer to a range of libcpp owned memory (start + size) and similarly some tree which can do the same, and can be at any time e.g. split into 2 subparts + say INTEGER_CST in between if needed say for const unsigned char d[] = { #embed "2GB.dat" prefix (0, 0, ) suffix (, [0x40000000] = 42) }; still without having to copy around huge amounts of data; STRING_CST owns the memory it points to and can be only 2GB in size), but would like to do that incrementally. And would like to first include some extensions also not included in this patch, like gnu::offset (off) parameter to allow to skip certain constant amount of bytes at the start of the files, plus gnu::base64 ("base64_encoded_data") parameter to add something which can store more efficiently large amounts of the #embed data in preprocessed source. I've been cross-checking all the tests also against the LLVM implementation https://github.com/llvm/llvm-project/pull/68620 which has been for a few hours even committed to LLVM trunk but reverted afterwards. LLVM now has the support committed and I admit I haven't rechecked whether the behavior on the below mentioned spots have been fixed in it already or not yet. The patch uses --embed-dir= option that clang plans to add above and doesn't use other variants on the search directories yet, plus there are no default directories at least for the time being where to search for embed files. So, #embed "..." works if it is found in the same directory (or relative to the current file's directory) and #embed "/..." or #embed </...> work always, but relative #embed <...> doesn't unless at least one --embed-dir= is specified. There is no reason to differentiate between system and non-system directories, so we don't need -isystem like counterpart, perhaps -iquote like counterpart could be useful in the future, dunno what else. It has --embed-directory=dir and --embed-directory dir as aliases. There are some differences beyond clang ICEs, so I'd like to point them out to make sure there is agreement on the choices in the patch. They are also mentioned in the comments of the llvm pull request. The most important is that the GCC patch (as well as the original thephd.dev LLVM branch on godbolt) expands #embed (or acts as if it is expanded) into a mere sequence of numbers like 123,2,35,26 rather then what clang effectively treats as (unsigned char)123,(unsigned char)2,(unsigned char)35,(unsigned char)26 but only does that when using integrated preprocessor, not when using -save-temps where it acts as GCC. JeanHeyd as the original author agrees that is how it is currently worded in C23. Another difference (not tested in the testsuite, not sure how to check for effective target /dev/urandom nor am sure it is desirable to check that during testsuite) is how to treat character devices, named pipes etc. (block devices are errored on). The original paper uses /dev/urandom in various examples and seems to assume that unlike regular files the devices aren't really cached, so #embed </dev/urandom> limit(1) prefix(int a = ) suffix(;) #embed </dev/urandom> limit(1) prefix(int b = ) suffix(;) usually results in a != b. That is what the godbolt thephd.dev branch implements too and what this patch does as well, but clang actually seems to just go from st.st_size == 0, ergo it must be zero-sized resource and so just copies over if_empty if present. It is really questionable what to do about the character devices/named pipes with __has_embed, for regular files the patch doesn't read anything from them, relies on st.st_size + limit for whether it is empty or non-empty. But I don't know of a way to check if read on say a character device would read anything or not (the </dev/null> limit (1) vs. </dev/zero> limit (1) cases), and if we read something, that would be better cached for later because #embed later if it reads again could read no further data even when it first read something. So, the patch currently for __has_embed just always returns 2 on the non-regular files, like the thephd.dev branch does as well and like the clang pull request as well. A question is also what to do for gnu::offset on the non-regular files even for #embed, those aren't seekable and do we want to just read and throw away the offset bytes each time we see it used? clang also chokes on the #if __has_embed (__FILE__ __limit__ (1) __prefix__ () suffix (1 / 0) \ __if_empty__ ((({{[0[0{0{0(0(0)1)1}1}]]}})))) != __STDC_EMBED_FOUND__ #error "__has_embed fail" #endif in embed-1.c, but thephd.dev branch accepts it and I don't see why it shouldn't, (({{[0[0{0{0(0(0)1)1}1}]]}}))) is a balanced token sequence and the file isn't empty, so it should just be parsed and discarded. clang also IMHO mishandles const unsigned char w[] = { #embed __FILE__ prefix([0] = 42, [15] =) limit(32) }; but again only without -save-temps, seems like it treats it as [0] = 42, [15] = (99,111,110,115,116,32,117,110,115,105,103,110,101,100, 32,99,104,97,114,32,119,91,93,32,61,32,123,10,35,101,109,98) rather than [0] = 42, [15] = 99,111,110,115,116,32,117,110,115,105,103,110,101,100, 32,99,104,97,114,32,119,91,93,32,61,32,123,10,35,101,109,98 and warns on it for -Wunused-value and just compiles it as [0] = 42, [15] = 98 And also void foo (int, int, int, int); void bar (void) { foo ( #embed __FILE__ limit (4) prefix (172 + ) suffix (+ 2) ); } is treated as 172 + (118, 111, 105, 100) + 2 rather than 172 + 118, 111, 105, 100 + 2 which clang -save-temps or GCC treats it like, so results in just one argument passed rather than 4. if (!strstr ((const char *) magna_carta, "imprisonétur")) abort (); in the testcase fails as well, but in that case calling it in gdb succeeds: p ((char *(*)(char *, char *))__strstr_sse2) (magna_carta, "imprisonétur") $2 = 0x555555558d3c <magna_carta+11564> "imprisonétur aut disseisiátur"... so I guess they are just trying to constant evaluate strstr and do it incorrectly. They started with making the optimizations together in the initial patch set, so they don't have the luxury to compare if it is just because of the optimization they are trying to do or because that is how the feature works for them. At least unless they use -save-temps for now. There is also different behavior between clang and gcc on -M or other dependency generating options. Seems clang includes the __has_embed searched files in dependencies, while my patch doesn't. But so does clang for __has_include and GCC doesn't. Emitting a hard dependency on some header just because there was __has_include/__has_embed for it seems wrong to me, because (at least when properly written) the source likely doesn't mind if the file is missing, it will do something else, so a hard error from make because of it doesn't seem right. Does make have some weaker dependencies, such that if some file can be remade it is but if it doesn't exist, it isn't fatal? I wonder whether #embed <non-existent-file> really needs to be fatal or whether we could simply after diagnosing it pretend the file exists and is empty. For #include I think fatal errors make tons of sense, but perhaps for #embed which is more localized we'd get better error reporting if we didn't bail out immediately. Note, both GCC and clang currently treat those as fatal errors. clang also added -dE option which with -E instead of preprocessing the #embed directives keeps them as is, but the preprocessed source then isn't self-contained. That option looks more harmful than useful to me. Also, it isn't clear to me from C23 whether it is possible to have __has_include/__has_c_attribute/__has_embed expressions inside of the limit #embed/__has_embed argument. 6.10.3.2/2 says that defined should not appear there (and the patch diagnoses it and testsuite tests), but for __has_include/__has_embed etc. 6.10.1/11 says: "The identifiers __has_include, __has_embed, and __has_c_attribute shall not appear in any context not mentioned in this subclause." If that subclause in that case means 6.10.1, then it presumably shouldn't appear in #embed in 6.10.3, but __has_embed is in 6.10.1... But 6.10.3.2/3 says that it should be parsed according to the 6.10.1 rules. Haven't included tests like #if __has_embed (__FILE__ limit (__has_embed (__FILE__ limit (1)))) or #embed __FILE__ limit (__has_include (__FILE__)) into the testsuite because of the doubts but I think the patch should handle those right now. The reason I've used Magna Carta text in some of the testcases is that I hope it shouldn't be copyrighted after the centuries and I'd strongly prefer not to have binary blobs in git after the xz backdoor lesson and wanted something larger which doesn't change all the time. Oh, BTW, I see in C23 draft 6.10.3.2 in Example 4 if (f_source == NULL); return 1; (note the spurious semicolon after closing paren), has that been fixed already? Like the thephd.dev and clang implementations, the patch always macro expands the whole #embed and __has_embed directives except for the embed keyword. That is most likely not what C23 says, my limited understanding right now is that in #embed one needs to parse the whole directive line with macro expansion disabled and check if it satisfies the grammar, if not, the whole directive is macro expanded, if yes, only the limit parameter argument is macro expanded and the prefix/suffix/if_empty arguments are maybe macro expanded when actually used (and not at all if unused). And I think __has_embed macro expansion has conflicting rules. 2024-09-12 Jakub Jelinek <jakub@redhat.com> PR c/105863 libcpp/ * include/cpplib.h: Implement C23 N3017 #embed - a scannable, tooling-friendly binary resource inclusion mechanism paper. (struct cpp_options): Add embed member. (enum cpp_builtin_type): Add BT_HAS_EMBED. (cpp_set_include_chains): Add another cpp_dir * argument to the declaration. * internal.h (enum include_type): Add IT_EMBED. (struct cpp_reader): Add embed_include member. (struct cpp_embed_params_tokens): New type. (struct cpp_embed_params): New type. (_cpp_get_token_no_padding): Declare. (enum _cpp_find_file_kind): Add _cpp_FFK_EMBED and _cpp_FFK_HAS_EMBED. (_cpp_stack_embed): Declare. (_cpp_parse_expr): Change return type to cpp_num_part instead of bool, change second argument from bool to const char * and add third argument. (_cpp_parse_embed_params): Declare. * directives.cc (DIRECTIVE_TABLE): Add embed entry. (end_directive): Don't call skip_rest_of_line for T_EMBED directive. (_cpp_handle_directive): Return 2 rather than 1 for T_EMBED in directives-only mode. (parse_include): Don't Call check_eol for T_EMBED directive. (skip_balanced_token_seq): New function. (EMBED_PARAMS): Define. (enum embed_param_kind): New type. (embed_params): New variable. (_cpp_parse_embed_params): New function. (do_embed): New function. (do_if): Adjust _cpp_parse_expr caller. (do_elif): Likewise. * expr.cc (parse_defined): Diagnose defined in #embed or __has_embed parameters. (_cpp_parse_expr): Change return type to cpp_num_part instead of bool, change second argument from bool to const char * and add third argument. Adjust function comment. For #embed/__has_embed parameters add an artificial CPP_OPEN_PAREN. Use the second argument DIR directly instead of string literals conditional on IS_IF. For #embed/__has_embed parameter, stop on reaching CPP_CLOSE_PAREN matching the artificial one. Diagnose negative or too large embed parameter operands. (num_binary_op): Use #embed instead of #if for diagnostics if inside #embed/__has_embed parameter. (num_div_op): Likewise. * files.cc (struct _cpp_file): Add limit member and embed bitfield. (search_cache): Add IS_EMBED argument, formatting fix. Skip over files with different file->embed from the argument. (find_file_in_dir): Don't call pch_open_file if file->embed. (_cpp_find_file): Handle _cpp_FFK_EMBED and _cpp_FFK_HAS_EMBED. (read_file_guts): Formatting fix. (has_unique_contents): Ignore file->embed files. (search_path_head): Handle IT_EMBED type. (_cpp_stack_embed): New function. (_cpp_get_file_stat): Formatting fix. (cpp_set_include_chains): Add embed argument, save it to pfile->embed_include and compute lens for the chain. * init.cc (struct lang_flags): Add embed member. (lang_defaults): Add embed initializers. (cpp_set_lang): Initialize CPP_OPTION (pfile, embed). (builtin_array): Add __has_embed entry. (cpp_init_builtins): Predefine __STDC_EMBED_NOT_FOUND__, __STDC_EMBED_FOUND__ and __STDC_EMBED_EMPTY__. * lex.cc (cpp_directive_only_process): Handle #embed. * macro.cc (cpp_get_token_no_padding): Rename to ... (_cpp_get_token_no_padding): ... this. No longer static. (builtin_has_include_1): New function. (builtin_has_include): Use it. Use _cpp_get_token_no_padding instead of cpp_get_token_no_padding. (builtin_has_embed): New function. (_cpp_builtin_macro_text): Handle BT_HAS_EMBED. gcc/ * doc/cppdiropts.texi (--embed-dir=): Document. * doc/cpp.texi (Binary Resource Inclusion): New chapter. (__has_embed): Document. * doc/invoke.texi (Directory Options): Mention --embed-dir=. * gcc.cc (cpp_unique_options): Add %{-embed*}. * genmatch.cc (main): Adjust cpp_set_include_chains caller. * incpath.h (enum incpath_kind): Add INC_EMBED. * incpath.cc (merge_include_chains): Handle INC_EMBED. (register_include_chains): Adjust cpp_set_include_chains caller. gcc/c-family/ * c.opt (-embed-dir=): New option. (-embed-directory): New alias. (-embed-directory=): New alias. * c-opts.cc (c_common_handle_option): Handle OPT__embed_dir_. gcc/testsuite/ * c-c++-common/cpp/embed-1.c: New test. * c-c++-common/cpp/embed-2.c: New test. * c-c++-common/cpp/embed-3.c: New test. * c-c++-common/cpp/embed-4.c: New test. * c-c++-common/cpp/embed-5.c: New test. * c-c++-common/cpp/embed-6.c: New test. * c-c++-common/cpp/embed-7.c: New test. * c-c++-common/cpp/embed-8.c: New test. * c-c++-common/cpp/embed-9.c: New test. * c-c++-common/cpp/embed-10.c: New test. * c-c++-common/cpp/embed-11.c: New test. * c-c++-common/cpp/embed-12.c: New test. * c-c++-common/cpp/embed-13.c: New test. * c-c++-common/cpp/embed-14.c: New test. * c-c++-common/cpp/embed-25.c: New test. * c-c++-common/cpp/embed-26.c: New test. * c-c++-common/cpp/embed-dir/embed-1.inc: New test. * c-c++-common/cpp/embed-dir/embed-3.c: New test. * c-c++-common/cpp/embed-dir/embed-4.c: New test. * c-c++-common/cpp/embed-dir/magna-carta.txt: New test. * gcc.dg/cpp/embed-1.c: New test. * gcc.dg/cpp/embed-2.c: New test. * gcc.dg/cpp/embed-3.c: New test. * gcc.dg/cpp/embed-4.c: New test. * g++.dg/cpp/embed-1.C: New test. * g++.dg/cpp/embed-2.C: New test. * g++.dg/cpp/embed-3.C: New test.
2024-09-12 17:15:38 +08: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-29 01:59:06 +08: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 06:53:12 +08: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 08:57:09 +08: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 06:53:12 +08: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 08:57:09 +08: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 06:53:12 +08: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-29 01:59:06 +08: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 06:53:12 +08: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-29 01:59:06 +08:00
{
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics When working on #embed support, or -Wheader-guard or other recent libcpp changes, I've been annoyed by the libcpp diagnostics being visually different from normal gcc diagnostics, especially in the area of quoting stuff in the diagnostic messages. Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use %</%>, %qs etc. in there, while libcpp diagnostics was marked as printf and in libcpp we've been very creative with quoting stuff, either no quotes at all, or "something" quoting, or 'something' quoting, or `something' quoting (but in none of the cases it used colors consistently with the rest of the compiler). Now, libcpp diagnostics is always emitted using a callback, pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with genmatch.cc: cb->diagnostic = diagnostic_cb; c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic; fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic; where the latter two just use diagnostic_report_diagnostic, so actually support all the gcc_diag stuff, only the genmatch.cc case didn't. So, the following patch changes genmatch.cc to use pp_format* instead of vfprintf so that it supports the gcc_diag formatting (pretty-print.o unfortunately has various dependencies, so had to link genmatch with libcommon.a libbacktrace.a and tweak Makefile.in so that there are no circular dependencies) and marks the libcpp diagnostic routines as gcc_diag rather than printf. That change resulted in hundreds of -Wformat-diag new warnings (most of them useful and resulting IMHO in better diagnostics), so the rest of the patch is changing the format strings to make -Wformat-diag happy and adjusting the testsuite for the differences in how is the diagnostic reformatted. Dunno if some out of GCC tree projects use libcpp, that case would make it harder because one couldn't use vfprintf in the diagnostic callback anymore, but there is always David's libdiagnostic which could be used for that purpose IMHO. 2024-10-12 Jakub Jelinek <jakub@redhat.com> libcpp/ * include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define. (struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF on diagnostic callback. (cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3. (cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. (cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6) instead of ATTRIBUTE_PRINTF_5. (cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. * Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather than --language=c. * errors.cc (cpp_diagnostic_at, cpp_diagnostic, cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of -ATTRIBUTE_FPTR_PRINTF. * charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex, convert_oct, convert_escape): Fix up -Wformat-diag warnings. (cpp_interpret_string_ranges, count_source_chars): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF. (narrow_str_to_charconst): Fix up -Wformat-diag warnings. * directives.cc (check_eol_1, directive_diagnostics, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, do_include_next, _cpp_parse_embed_params, do_embed, read_flag, do_line, do_linemarker, register_pragma_1, do_pragma_once, do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison, do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, do_assert, cpp_define_unused): Likewise. * expr.cc (cpp_classify_number, parse_defined, eval_token, _cpp_parse_expr, reduce, check_promotion): Likewise. * files.cc (_cpp_find_file, finish_base64_embed, _cpp_pop_file_buffer): Likewise. * init.cc (sanity_checks): Likewise. * lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char, _cpp_warn_invalid_utf8, _cpp_skip_block_comment, warn_about_normalization, forms_identifier_p, maybe_va_opt_error, identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise. * macro.cc (class vaopt_state, builtin_has_include_1, builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro, _cpp_builtin_macro_text, builtin_macro, stringify_arg, _cpp_arguments_ok, collect_args, enter_macro_context, _cpp_save_parameter, parse_params, create_iso_definition, _cpp_create_definition, check_trad_stringification): Likewise. * pch.cc (cpp_valid_state): Likewise. * traditional.cc (_cpp_scan_out_logical_line, recursive_macro): Likewise. gcc/ * Makefile.in (generated_files): Remove {gimple,generic}-match*. (generated_match_files): New variable. Add a dependency of $(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those. (build/genmatch$(build_exeext)): Depend on and link against libcommon.a and $(LIBBACKTRACE). * genmatch.cc: Include pretty-print.h and input.h. (ggc_internal_cleared_alloc, ggc_free): Remove. (fatal): New function. (line_table): Remove. (linemap_client_expand_location_to_spelling_point): Remove. (diagnostic_cb): Use gcc_diag rather than printf format. Use pp_format_verbatim on a temporary pretty_printer instead of vfprintf. (fatal_at, warning_at): Use gcc_diag rather than printf format. (output_line_directive): Rename location_hash to loc_hash. (parser::eat_ident, parser::parse_operation, parser::parse_expr, parser::parse_pattern, parser::finish_match_operand): Fix up -Wformat-diag warnings. gcc/c-family/ * c-lex.cc (c_common_has_attribute, c_common_lex_availability_macro): Fix up -Wformat-diag warnings. gcc/testsuite/ * c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for libcpp diagnostic formatting changes. * c-c++-common/cpp/embed-3.c: Likewise. * c-c++-common/cpp/embed-4.c: Likewise. * c-c++-common/cpp/embed-16.c: Likewise. * c-c++-common/cpp/embed-18.c: Likewise. * c-c++-common/cpp/eof-2.c: Likewise. * c-c++-common/cpp/eof-3.c: Likewise. * c-c++-common/cpp/fmax-include-depth.c: Likewise. * c-c++-common/cpp/has-builtin.c: Likewise. * c-c++-common/cpp/line-2.c: Likewise. * c-c++-common/cpp/line-3.c: Likewise. * c-c++-common/cpp/macro-arg-count-1.c: Likewise. * c-c++-common/cpp/macro-arg-count-2.c: Likewise. * c-c++-common/cpp/macro-ranges.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-4.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-5.c: Likewise. * c-c++-common/cpp/pr88974.c: Likewise. * c-c++-common/cpp/va-opt-error.c: Likewise. * c-c++-common/cpp/va-opt-pedantic.c: Likewise. * c-c++-common/cpp/Wheader-guard-2.c: Likewise. * c-c++-common/cpp/Wheader-guard-3.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-1.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-2.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-3.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c: Likewise. * c-c++-common/pr68833-3.c: Likewise. * c-c++-common/raw-string-directive-1.c: Likewise. * gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise. * gcc.dg/binary-constants-4.c: Likewise. * gcc.dg/builtin-redefine.c: Likewise. * gcc.dg/cpp/19951025-1.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c23-elifdef-2.c: Likewise. * gcc.dg/cpp/c23-warning-2.c: Likewise. * gcc.dg/cpp/embed-2.c: Likewise. * gcc.dg/cpp/embed-3.c: Likewise. * gcc.dg/cpp/embed-4.c: Likewise. * gcc.dg/cpp/expr.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu23-warning-2.c: Likewise. * gcc.dg/cpp/include6.c: Likewise. * gcc.dg/cpp/pr35322.c: Likewise. * gcc.dg/cpp/tr-warn6.c: Likewise. * gcc.dg/cpp/undef2.c: Likewise. * gcc.dg/cpp/warn-comments.c: Likewise. * gcc.dg/cpp/warn-comments-2.c: Likewise. * gcc.dg/cpp/warn-comments-3.c: Likewise. * gcc.dg/cpp/warn-cxx-compat.c: Likewise. * gcc.dg/cpp/warn-cxx-compat-2.c: Likewise. * gcc.dg/cpp/warn-deprecated.c: Likewise. * gcc.dg/cpp/warn-deprecated-2.c: Likewise. * gcc.dg/cpp/warn-long-long.c: Likewise. * gcc.dg/cpp/warn-long-long-2.c: Likewise. * gcc.dg/cpp/warn-normalized-1.c: Likewise. * gcc.dg/cpp/warn-normalized-2.c: Likewise. * gcc.dg/cpp/warn-normalized-3.c: Likewise. * gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise. * gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise. * gcc.dg/cpp/warn-redefined.c: Likewise. * gcc.dg/cpp/warn-redefined-2.c: Likewise. * gcc.dg/cpp/warn-traditional.c: Likewise. * gcc.dg/cpp/warn-traditional-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-1.c: Likewise. * gcc.dg/cpp/warn-trigraphs-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-3.c: Likewise. * gcc.dg/cpp/warn-trigraphs-4.c: Likewise. * gcc.dg/cpp/warn-undef.c: Likewise. * gcc.dg/cpp/warn-undef-2.c: Likewise. * gcc.dg/cpp/warn-unused-macros.c: Likewise. * gcc.dg/cpp/warn-unused-macros-2.c: Likewise. * gcc.dg/pch/counter-2.c: Likewise. * g++.dg/cpp0x/udlit-error1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-1.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-3.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-4.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-5.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-6.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-7.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-8.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-9.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-10.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-11.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-12.C: Likewise. * g++.dg/cpp/elifdef-3.C: Likewise. * g++.dg/cpp/elifdef-5.C: Likewise. * g++.dg/cpp/elifdef-6.C: Likewise. * g++.dg/cpp/elifdef-7.C: Likewise. * g++.dg/cpp/embed-1.C: Likewise. * g++.dg/cpp/embed-2.C: Likewise. * g++.dg/cpp/pedantic-errors.C: Likewise. * g++.dg/cpp/warning-1.C: Likewise. * g++.dg/cpp/warning-2.C: Likewise. * g++.dg/ext/bitint1.C: Likewise. * g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08: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 06:53:12 +08: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-29 01:59:06 +08:00
}
}
else
{
cpp_error (pfile, CPP_DL_ERROR,
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics When working on #embed support, or -Wheader-guard or other recent libcpp changes, I've been annoyed by the libcpp diagnostics being visually different from normal gcc diagnostics, especially in the area of quoting stuff in the diagnostic messages. Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use %</%>, %qs etc. in there, while libcpp diagnostics was marked as printf and in libcpp we've been very creative with quoting stuff, either no quotes at all, or "something" quoting, or 'something' quoting, or `something' quoting (but in none of the cases it used colors consistently with the rest of the compiler). Now, libcpp diagnostics is always emitted using a callback, pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with genmatch.cc: cb->diagnostic = diagnostic_cb; c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic; fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic; where the latter two just use diagnostic_report_diagnostic, so actually support all the gcc_diag stuff, only the genmatch.cc case didn't. So, the following patch changes genmatch.cc to use pp_format* instead of vfprintf so that it supports the gcc_diag formatting (pretty-print.o unfortunately has various dependencies, so had to link genmatch with libcommon.a libbacktrace.a and tweak Makefile.in so that there are no circular dependencies) and marks the libcpp diagnostic routines as gcc_diag rather than printf. That change resulted in hundreds of -Wformat-diag new warnings (most of them useful and resulting IMHO in better diagnostics), so the rest of the patch is changing the format strings to make -Wformat-diag happy and adjusting the testsuite for the differences in how is the diagnostic reformatted. Dunno if some out of GCC tree projects use libcpp, that case would make it harder because one couldn't use vfprintf in the diagnostic callback anymore, but there is always David's libdiagnostic which could be used for that purpose IMHO. 2024-10-12 Jakub Jelinek <jakub@redhat.com> libcpp/ * include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define. (struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF on diagnostic callback. (cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3. (cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. (cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6) instead of ATTRIBUTE_PRINTF_5. (cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. * Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather than --language=c. * errors.cc (cpp_diagnostic_at, cpp_diagnostic, cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of -ATTRIBUTE_FPTR_PRINTF. * charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex, convert_oct, convert_escape): Fix up -Wformat-diag warnings. (cpp_interpret_string_ranges, count_source_chars): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF. (narrow_str_to_charconst): Fix up -Wformat-diag warnings. * directives.cc (check_eol_1, directive_diagnostics, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, do_include_next, _cpp_parse_embed_params, do_embed, read_flag, do_line, do_linemarker, register_pragma_1, do_pragma_once, do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison, do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, do_assert, cpp_define_unused): Likewise. * expr.cc (cpp_classify_number, parse_defined, eval_token, _cpp_parse_expr, reduce, check_promotion): Likewise. * files.cc (_cpp_find_file, finish_base64_embed, _cpp_pop_file_buffer): Likewise. * init.cc (sanity_checks): Likewise. * lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char, _cpp_warn_invalid_utf8, _cpp_skip_block_comment, warn_about_normalization, forms_identifier_p, maybe_va_opt_error, identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise. * macro.cc (class vaopt_state, builtin_has_include_1, builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro, _cpp_builtin_macro_text, builtin_macro, stringify_arg, _cpp_arguments_ok, collect_args, enter_macro_context, _cpp_save_parameter, parse_params, create_iso_definition, _cpp_create_definition, check_trad_stringification): Likewise. * pch.cc (cpp_valid_state): Likewise. * traditional.cc (_cpp_scan_out_logical_line, recursive_macro): Likewise. gcc/ * Makefile.in (generated_files): Remove {gimple,generic}-match*. (generated_match_files): New variable. Add a dependency of $(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those. (build/genmatch$(build_exeext)): Depend on and link against libcommon.a and $(LIBBACKTRACE). * genmatch.cc: Include pretty-print.h and input.h. (ggc_internal_cleared_alloc, ggc_free): Remove. (fatal): New function. (line_table): Remove. (linemap_client_expand_location_to_spelling_point): Remove. (diagnostic_cb): Use gcc_diag rather than printf format. Use pp_format_verbatim on a temporary pretty_printer instead of vfprintf. (fatal_at, warning_at): Use gcc_diag rather than printf format. (output_line_directive): Rename location_hash to loc_hash. (parser::eat_ident, parser::parse_operation, parser::parse_expr, parser::parse_pattern, parser::finish_match_operand): Fix up -Wformat-diag warnings. gcc/c-family/ * c-lex.cc (c_common_has_attribute, c_common_lex_availability_macro): Fix up -Wformat-diag warnings. gcc/testsuite/ * c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for libcpp diagnostic formatting changes. * c-c++-common/cpp/embed-3.c: Likewise. * c-c++-common/cpp/embed-4.c: Likewise. * c-c++-common/cpp/embed-16.c: Likewise. * c-c++-common/cpp/embed-18.c: Likewise. * c-c++-common/cpp/eof-2.c: Likewise. * c-c++-common/cpp/eof-3.c: Likewise. * c-c++-common/cpp/fmax-include-depth.c: Likewise. * c-c++-common/cpp/has-builtin.c: Likewise. * c-c++-common/cpp/line-2.c: Likewise. * c-c++-common/cpp/line-3.c: Likewise. * c-c++-common/cpp/macro-arg-count-1.c: Likewise. * c-c++-common/cpp/macro-arg-count-2.c: Likewise. * c-c++-common/cpp/macro-ranges.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-4.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-5.c: Likewise. * c-c++-common/cpp/pr88974.c: Likewise. * c-c++-common/cpp/va-opt-error.c: Likewise. * c-c++-common/cpp/va-opt-pedantic.c: Likewise. * c-c++-common/cpp/Wheader-guard-2.c: Likewise. * c-c++-common/cpp/Wheader-guard-3.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-1.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-2.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-3.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c: Likewise. * c-c++-common/pr68833-3.c: Likewise. * c-c++-common/raw-string-directive-1.c: Likewise. * gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise. * gcc.dg/binary-constants-4.c: Likewise. * gcc.dg/builtin-redefine.c: Likewise. * gcc.dg/cpp/19951025-1.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c23-elifdef-2.c: Likewise. * gcc.dg/cpp/c23-warning-2.c: Likewise. * gcc.dg/cpp/embed-2.c: Likewise. * gcc.dg/cpp/embed-3.c: Likewise. * gcc.dg/cpp/embed-4.c: Likewise. * gcc.dg/cpp/expr.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu23-warning-2.c: Likewise. * gcc.dg/cpp/include6.c: Likewise. * gcc.dg/cpp/pr35322.c: Likewise. * gcc.dg/cpp/tr-warn6.c: Likewise. * gcc.dg/cpp/undef2.c: Likewise. * gcc.dg/cpp/warn-comments.c: Likewise. * gcc.dg/cpp/warn-comments-2.c: Likewise. * gcc.dg/cpp/warn-comments-3.c: Likewise. * gcc.dg/cpp/warn-cxx-compat.c: Likewise. * gcc.dg/cpp/warn-cxx-compat-2.c: Likewise. * gcc.dg/cpp/warn-deprecated.c: Likewise. * gcc.dg/cpp/warn-deprecated-2.c: Likewise. * gcc.dg/cpp/warn-long-long.c: Likewise. * gcc.dg/cpp/warn-long-long-2.c: Likewise. * gcc.dg/cpp/warn-normalized-1.c: Likewise. * gcc.dg/cpp/warn-normalized-2.c: Likewise. * gcc.dg/cpp/warn-normalized-3.c: Likewise. * gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise. * gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise. * gcc.dg/cpp/warn-redefined.c: Likewise. * gcc.dg/cpp/warn-redefined-2.c: Likewise. * gcc.dg/cpp/warn-traditional.c: Likewise. * gcc.dg/cpp/warn-traditional-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-1.c: Likewise. * gcc.dg/cpp/warn-trigraphs-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-3.c: Likewise. * gcc.dg/cpp/warn-trigraphs-4.c: Likewise. * gcc.dg/cpp/warn-undef.c: Likewise. * gcc.dg/cpp/warn-undef-2.c: Likewise. * gcc.dg/cpp/warn-unused-macros.c: Likewise. * gcc.dg/cpp/warn-unused-macros-2.c: Likewise. * gcc.dg/pch/counter-2.c: Likewise. * g++.dg/cpp0x/udlit-error1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-1.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-3.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-4.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-5.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-6.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-7.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-8.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-9.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-10.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-11.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-12.C: Likewise. * g++.dg/cpp/elifdef-3.C: Likewise. * g++.dg/cpp/elifdef-5.C: Likewise. * g++.dg/cpp/elifdef-6.C: Likewise. * g++.dg/cpp/elifdef-7.C: Likewise. * g++.dg/cpp/embed-1.C: Likewise. * g++.dg/cpp/embed-2.C: Likewise. * g++.dg/cpp/pedantic-errors.C: Likewise. * g++.dg/cpp/warning-1.C: Likewise. * g++.dg/cpp/warning-2.C: Likewise. * g++.dg/ext/bitint1.C: Likewise. * g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08: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 06:53:12 +08: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 06:53:12 +08:00
op.type = token->type;
cpp_error (pfile, CPP_DL_ERROR,
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics When working on #embed support, or -Wheader-guard or other recent libcpp changes, I've been annoyed by the libcpp diagnostics being visually different from normal gcc diagnostics, especially in the area of quoting stuff in the diagnostic messages. Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use %</%>, %qs etc. in there, while libcpp diagnostics was marked as printf and in libcpp we've been very creative with quoting stuff, either no quotes at all, or "something" quoting, or 'something' quoting, or `something' quoting (but in none of the cases it used colors consistently with the rest of the compiler). Now, libcpp diagnostics is always emitted using a callback, pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with genmatch.cc: cb->diagnostic = diagnostic_cb; c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic; fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic; where the latter two just use diagnostic_report_diagnostic, so actually support all the gcc_diag stuff, only the genmatch.cc case didn't. So, the following patch changes genmatch.cc to use pp_format* instead of vfprintf so that it supports the gcc_diag formatting (pretty-print.o unfortunately has various dependencies, so had to link genmatch with libcommon.a libbacktrace.a and tweak Makefile.in so that there are no circular dependencies) and marks the libcpp diagnostic routines as gcc_diag rather than printf. That change resulted in hundreds of -Wformat-diag new warnings (most of them useful and resulting IMHO in better diagnostics), so the rest of the patch is changing the format strings to make -Wformat-diag happy and adjusting the testsuite for the differences in how is the diagnostic reformatted. Dunno if some out of GCC tree projects use libcpp, that case would make it harder because one couldn't use vfprintf in the diagnostic callback anymore, but there is always David's libdiagnostic which could be used for that purpose IMHO. 2024-10-12 Jakub Jelinek <jakub@redhat.com> libcpp/ * include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define. (struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF on diagnostic callback. (cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3. (cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. (cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6) instead of ATTRIBUTE_PRINTF_5. (cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. * Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather than --language=c. * errors.cc (cpp_diagnostic_at, cpp_diagnostic, cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of -ATTRIBUTE_FPTR_PRINTF. * charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex, convert_oct, convert_escape): Fix up -Wformat-diag warnings. (cpp_interpret_string_ranges, count_source_chars): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF. (narrow_str_to_charconst): Fix up -Wformat-diag warnings. * directives.cc (check_eol_1, directive_diagnostics, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, do_include_next, _cpp_parse_embed_params, do_embed, read_flag, do_line, do_linemarker, register_pragma_1, do_pragma_once, do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison, do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, do_assert, cpp_define_unused): Likewise. * expr.cc (cpp_classify_number, parse_defined, eval_token, _cpp_parse_expr, reduce, check_promotion): Likewise. * files.cc (_cpp_find_file, finish_base64_embed, _cpp_pop_file_buffer): Likewise. * init.cc (sanity_checks): Likewise. * lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char, _cpp_warn_invalid_utf8, _cpp_skip_block_comment, warn_about_normalization, forms_identifier_p, maybe_va_opt_error, identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise. * macro.cc (class vaopt_state, builtin_has_include_1, builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro, _cpp_builtin_macro_text, builtin_macro, stringify_arg, _cpp_arguments_ok, collect_args, enter_macro_context, _cpp_save_parameter, parse_params, create_iso_definition, _cpp_create_definition, check_trad_stringification): Likewise. * pch.cc (cpp_valid_state): Likewise. * traditional.cc (_cpp_scan_out_logical_line, recursive_macro): Likewise. gcc/ * Makefile.in (generated_files): Remove {gimple,generic}-match*. (generated_match_files): New variable. Add a dependency of $(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those. (build/genmatch$(build_exeext)): Depend on and link against libcommon.a and $(LIBBACKTRACE). * genmatch.cc: Include pretty-print.h and input.h. (ggc_internal_cleared_alloc, ggc_free): Remove. (fatal): New function. (line_table): Remove. (linemap_client_expand_location_to_spelling_point): Remove. (diagnostic_cb): Use gcc_diag rather than printf format. Use pp_format_verbatim on a temporary pretty_printer instead of vfprintf. (fatal_at, warning_at): Use gcc_diag rather than printf format. (output_line_directive): Rename location_hash to loc_hash. (parser::eat_ident, parser::parse_operation, parser::parse_expr, parser::parse_pattern, parser::finish_match_operand): Fix up -Wformat-diag warnings. gcc/c-family/ * c-lex.cc (c_common_has_attribute, c_common_lex_availability_macro): Fix up -Wformat-diag warnings. gcc/testsuite/ * c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for libcpp diagnostic formatting changes. * c-c++-common/cpp/embed-3.c: Likewise. * c-c++-common/cpp/embed-4.c: Likewise. * c-c++-common/cpp/embed-16.c: Likewise. * c-c++-common/cpp/embed-18.c: Likewise. * c-c++-common/cpp/eof-2.c: Likewise. * c-c++-common/cpp/eof-3.c: Likewise. * c-c++-common/cpp/fmax-include-depth.c: Likewise. * c-c++-common/cpp/has-builtin.c: Likewise. * c-c++-common/cpp/line-2.c: Likewise. * c-c++-common/cpp/line-3.c: Likewise. * c-c++-common/cpp/macro-arg-count-1.c: Likewise. * c-c++-common/cpp/macro-arg-count-2.c: Likewise. * c-c++-common/cpp/macro-ranges.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-4.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-5.c: Likewise. * c-c++-common/cpp/pr88974.c: Likewise. * c-c++-common/cpp/va-opt-error.c: Likewise. * c-c++-common/cpp/va-opt-pedantic.c: Likewise. * c-c++-common/cpp/Wheader-guard-2.c: Likewise. * c-c++-common/cpp/Wheader-guard-3.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-1.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-2.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-3.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c: Likewise. * c-c++-common/pr68833-3.c: Likewise. * c-c++-common/raw-string-directive-1.c: Likewise. * gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise. * gcc.dg/binary-constants-4.c: Likewise. * gcc.dg/builtin-redefine.c: Likewise. * gcc.dg/cpp/19951025-1.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c23-elifdef-2.c: Likewise. * gcc.dg/cpp/c23-warning-2.c: Likewise. * gcc.dg/cpp/embed-2.c: Likewise. * gcc.dg/cpp/embed-3.c: Likewise. * gcc.dg/cpp/embed-4.c: Likewise. * gcc.dg/cpp/expr.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu23-warning-2.c: Likewise. * gcc.dg/cpp/include6.c: Likewise. * gcc.dg/cpp/pr35322.c: Likewise. * gcc.dg/cpp/tr-warn6.c: Likewise. * gcc.dg/cpp/undef2.c: Likewise. * gcc.dg/cpp/warn-comments.c: Likewise. * gcc.dg/cpp/warn-comments-2.c: Likewise. * gcc.dg/cpp/warn-comments-3.c: Likewise. * gcc.dg/cpp/warn-cxx-compat.c: Likewise. * gcc.dg/cpp/warn-cxx-compat-2.c: Likewise. * gcc.dg/cpp/warn-deprecated.c: Likewise. * gcc.dg/cpp/warn-deprecated-2.c: Likewise. * gcc.dg/cpp/warn-long-long.c: Likewise. * gcc.dg/cpp/warn-long-long-2.c: Likewise. * gcc.dg/cpp/warn-normalized-1.c: Likewise. * gcc.dg/cpp/warn-normalized-2.c: Likewise. * gcc.dg/cpp/warn-normalized-3.c: Likewise. * gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise. * gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise. * gcc.dg/cpp/warn-redefined.c: Likewise. * gcc.dg/cpp/warn-redefined-2.c: Likewise. * gcc.dg/cpp/warn-traditional.c: Likewise. * gcc.dg/cpp/warn-traditional-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-1.c: Likewise. * gcc.dg/cpp/warn-trigraphs-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-3.c: Likewise. * gcc.dg/cpp/warn-trigraphs-4.c: Likewise. * gcc.dg/cpp/warn-undef.c: Likewise. * gcc.dg/cpp/warn-undef-2.c: Likewise. * gcc.dg/cpp/warn-unused-macros.c: Likewise. * gcc.dg/cpp/warn-unused-macros-2.c: Likewise. * gcc.dg/pch/counter-2.c: Likewise. * g++.dg/cpp0x/udlit-error1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-1.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-3.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-4.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-5.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-6.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-7.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-8.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-9.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-10.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-11.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-12.C: Likewise. * g++.dg/cpp/elifdef-3.C: Likewise. * g++.dg/cpp/elifdef-5.C: Likewise. * g++.dg/cpp/elifdef-6.C: Likewise. * g++.dg/cpp/elifdef-7.C: Likewise. * g++.dg/cpp/embed-1.C: Likewise. * g++.dg/cpp/embed-2.C: Likewise. * g++.dg/cpp/pedantic-errors.C: Likewise. * g++.dg/cpp/warning-1.C: Likewise. * g++.dg/cpp/warning-2.C: Likewise. * g++.dg/ext/bitint1.C: Likewise. * g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
"(%qs is an alternative token for %qs 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 06:53:12 +08: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 23:55:46 +08:00
preprocessor: Add deferred macros Deferred macros are needed for C++ modules. Header units may export macro definitions and undefinitions. These are resolved lazily at the point of (potential) use. (The language specifies that, it's not just a useful optimization.) Thus, identifier nodes grow a 'deferred' field, which fortunately doesn't expand the structure on 64-bit systems as there was padding there. This is non-zero on NT_MACRO nodes, if the macro is deferred. When such an identifier is lexed, it is resolved via a callback that I added recently. That will either provide the macro definition, or discover it there was an overriding undef. Either way the identifier is no longer a deferred macro. Notice it is now possible for NT_MACRO nodes to have a NULL macro expansion. libcpp/ * include/cpplib.h (struct cpp_hashnode): Add deferred field. (cpp_set_deferred_macro): Define. (cpp_get_deferred_macro): Declare. (cpp_macro_definition): Reformat, add overload. (cpp_macro_definition_location): Deal with deferred macro. (cpp_alloc_token_string, cpp_compare_macro): Declare. * internal.h (_cpp_notify_macro_use): Return bool (_cpp_maybe_notify_macro_use): Likewise. * directives.c (do_undef): Check macro is not undef before warning. (do_ifdef, do_ifndef): Deal with deferred macro. * expr.c (parse_defined): Likewise. * lex.c (cpp_allocate_token_string): Break out of ... (create_literal): ... here. Call it. (cpp_maybe_module_directive): Deal with deferred macro. * macro.c (cpp_get_token_1): Deal with deferred macro. (warn_of_redefinition): Deal with deferred macro. (compare_macros): Rename to ... (cpp_compare_macro): ... here. Make extern. (cpp_get_deferred_macro): New. (_cpp_notify_macro_use): Deal with deferred macro, return bool indicating definedness. (cpp_macro_definition): Deal with deferred macro.
2020-11-25 00:23:55 +08:00
bool is_defined = false;
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 23:55:46 +08: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,
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics When working on #embed support, or -Wheader-guard or other recent libcpp changes, I've been annoyed by the libcpp diagnostics being visually different from normal gcc diagnostics, especially in the area of quoting stuff in the diagnostic messages. Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use %</%>, %qs etc. in there, while libcpp diagnostics was marked as printf and in libcpp we've been very creative with quoting stuff, either no quotes at all, or "something" quoting, or 'something' quoting, or `something' quoting (but in none of the cases it used colors consistently with the rest of the compiler). Now, libcpp diagnostics is always emitted using a callback, pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with genmatch.cc: cb->diagnostic = diagnostic_cb; c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic; fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic; where the latter two just use diagnostic_report_diagnostic, so actually support all the gcc_diag stuff, only the genmatch.cc case didn't. So, the following patch changes genmatch.cc to use pp_format* instead of vfprintf so that it supports the gcc_diag formatting (pretty-print.o unfortunately has various dependencies, so had to link genmatch with libcommon.a libbacktrace.a and tweak Makefile.in so that there are no circular dependencies) and marks the libcpp diagnostic routines as gcc_diag rather than printf. That change resulted in hundreds of -Wformat-diag new warnings (most of them useful and resulting IMHO in better diagnostics), so the rest of the patch is changing the format strings to make -Wformat-diag happy and adjusting the testsuite for the differences in how is the diagnostic reformatted. Dunno if some out of GCC tree projects use libcpp, that case would make it harder because one couldn't use vfprintf in the diagnostic callback anymore, but there is always David's libdiagnostic which could be used for that purpose IMHO. 2024-10-12 Jakub Jelinek <jakub@redhat.com> libcpp/ * include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define. (struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF on diagnostic callback. (cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3. (cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. (cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6) instead of ATTRIBUTE_PRINTF_5. (cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. * Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather than --language=c. * errors.cc (cpp_diagnostic_at, cpp_diagnostic, cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of -ATTRIBUTE_FPTR_PRINTF. * charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex, convert_oct, convert_escape): Fix up -Wformat-diag warnings. (cpp_interpret_string_ranges, count_source_chars): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF. (narrow_str_to_charconst): Fix up -Wformat-diag warnings. * directives.cc (check_eol_1, directive_diagnostics, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, do_include_next, _cpp_parse_embed_params, do_embed, read_flag, do_line, do_linemarker, register_pragma_1, do_pragma_once, do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison, do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, do_assert, cpp_define_unused): Likewise. * expr.cc (cpp_classify_number, parse_defined, eval_token, _cpp_parse_expr, reduce, check_promotion): Likewise. * files.cc (_cpp_find_file, finish_base64_embed, _cpp_pop_file_buffer): Likewise. * init.cc (sanity_checks): Likewise. * lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char, _cpp_warn_invalid_utf8, _cpp_skip_block_comment, warn_about_normalization, forms_identifier_p, maybe_va_opt_error, identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise. * macro.cc (class vaopt_state, builtin_has_include_1, builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro, _cpp_builtin_macro_text, builtin_macro, stringify_arg, _cpp_arguments_ok, collect_args, enter_macro_context, _cpp_save_parameter, parse_params, create_iso_definition, _cpp_create_definition, check_trad_stringification): Likewise. * pch.cc (cpp_valid_state): Likewise. * traditional.cc (_cpp_scan_out_logical_line, recursive_macro): Likewise. gcc/ * Makefile.in (generated_files): Remove {gimple,generic}-match*. (generated_match_files): New variable. Add a dependency of $(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those. (build/genmatch$(build_exeext)): Depend on and link against libcommon.a and $(LIBBACKTRACE). * genmatch.cc: Include pretty-print.h and input.h. (ggc_internal_cleared_alloc, ggc_free): Remove. (fatal): New function. (line_table): Remove. (linemap_client_expand_location_to_spelling_point): Remove. (diagnostic_cb): Use gcc_diag rather than printf format. Use pp_format_verbatim on a temporary pretty_printer instead of vfprintf. (fatal_at, warning_at): Use gcc_diag rather than printf format. (output_line_directive): Rename location_hash to loc_hash. (parser::eat_ident, parser::parse_operation, parser::parse_expr, parser::parse_pattern, parser::finish_match_operand): Fix up -Wformat-diag warnings. gcc/c-family/ * c-lex.cc (c_common_has_attribute, c_common_lex_availability_macro): Fix up -Wformat-diag warnings. gcc/testsuite/ * c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for libcpp diagnostic formatting changes. * c-c++-common/cpp/embed-3.c: Likewise. * c-c++-common/cpp/embed-4.c: Likewise. * c-c++-common/cpp/embed-16.c: Likewise. * c-c++-common/cpp/embed-18.c: Likewise. * c-c++-common/cpp/eof-2.c: Likewise. * c-c++-common/cpp/eof-3.c: Likewise. * c-c++-common/cpp/fmax-include-depth.c: Likewise. * c-c++-common/cpp/has-builtin.c: Likewise. * c-c++-common/cpp/line-2.c: Likewise. * c-c++-common/cpp/line-3.c: Likewise. * c-c++-common/cpp/macro-arg-count-1.c: Likewise. * c-c++-common/cpp/macro-arg-count-2.c: Likewise. * c-c++-common/cpp/macro-ranges.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-4.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-5.c: Likewise. * c-c++-common/cpp/pr88974.c: Likewise. * c-c++-common/cpp/va-opt-error.c: Likewise. * c-c++-common/cpp/va-opt-pedantic.c: Likewise. * c-c++-common/cpp/Wheader-guard-2.c: Likewise. * c-c++-common/cpp/Wheader-guard-3.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-1.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-2.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-3.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c: Likewise. * c-c++-common/pr68833-3.c: Likewise. * c-c++-common/raw-string-directive-1.c: Likewise. * gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise. * gcc.dg/binary-constants-4.c: Likewise. * gcc.dg/builtin-redefine.c: Likewise. * gcc.dg/cpp/19951025-1.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c23-elifdef-2.c: Likewise. * gcc.dg/cpp/c23-warning-2.c: Likewise. * gcc.dg/cpp/embed-2.c: Likewise. * gcc.dg/cpp/embed-3.c: Likewise. * gcc.dg/cpp/embed-4.c: Likewise. * gcc.dg/cpp/expr.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu23-warning-2.c: Likewise. * gcc.dg/cpp/include6.c: Likewise. * gcc.dg/cpp/pr35322.c: Likewise. * gcc.dg/cpp/tr-warn6.c: Likewise. * gcc.dg/cpp/undef2.c: Likewise. * gcc.dg/cpp/warn-comments.c: Likewise. * gcc.dg/cpp/warn-comments-2.c: Likewise. * gcc.dg/cpp/warn-comments-3.c: Likewise. * gcc.dg/cpp/warn-cxx-compat.c: Likewise. * gcc.dg/cpp/warn-cxx-compat-2.c: Likewise. * gcc.dg/cpp/warn-deprecated.c: Likewise. * gcc.dg/cpp/warn-deprecated-2.c: Likewise. * gcc.dg/cpp/warn-long-long.c: Likewise. * gcc.dg/cpp/warn-long-long-2.c: Likewise. * gcc.dg/cpp/warn-normalized-1.c: Likewise. * gcc.dg/cpp/warn-normalized-2.c: Likewise. * gcc.dg/cpp/warn-normalized-3.c: Likewise. * gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise. * gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise. * gcc.dg/cpp/warn-redefined.c: Likewise. * gcc.dg/cpp/warn-redefined-2.c: Likewise. * gcc.dg/cpp/warn-traditional.c: Likewise. * gcc.dg/cpp/warn-traditional-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-1.c: Likewise. * gcc.dg/cpp/warn-trigraphs-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-3.c: Likewise. * gcc.dg/cpp/warn-trigraphs-4.c: Likewise. * gcc.dg/cpp/warn-undef.c: Likewise. * gcc.dg/cpp/warn-undef-2.c: Likewise. * gcc.dg/cpp/warn-unused-macros.c: Likewise. * gcc.dg/cpp/warn-unused-macros-2.c: Likewise. * gcc.dg/pch/counter-2.c: Likewise. * g++.dg/cpp0x/udlit-error1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-1.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-3.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-4.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-5.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-6.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-7.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-8.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-9.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-10.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-11.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-12.C: Likewise. * g++.dg/cpp/elifdef-3.C: Likewise. * g++.dg/cpp/elifdef-5.C: Likewise. * g++.dg/cpp/elifdef-6.C: Likewise. * g++.dg/cpp/elifdef-7.C: Likewise. * g++.dg/cpp/embed-1.C: Likewise. * g++.dg/cpp/embed-2.C: Likewise. * g++.dg/cpp/pedantic-errors.C: Likewise. * g++.dg/cpp/warning-1.C: Likewise. * g++.dg/cpp/warning-2.C: Likewise. * g++.dg/ext/bitint1.C: Likewise. * g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
"this use of %<defined%> may not be portable");
preprocessor: Add deferred macros Deferred macros are needed for C++ modules. Header units may export macro definitions and undefinitions. These are resolved lazily at the point of (potential) use. (The language specifies that, it's not just a useful optimization.) Thus, identifier nodes grow a 'deferred' field, which fortunately doesn't expand the structure on 64-bit systems as there was padding there. This is non-zero on NT_MACRO nodes, if the macro is deferred. When such an identifier is lexed, it is resolved via a callback that I added recently. That will either provide the macro definition, or discover it there was an overriding undef. Either way the identifier is no longer a deferred macro. Notice it is now possible for NT_MACRO nodes to have a NULL macro expansion. libcpp/ * include/cpplib.h (struct cpp_hashnode): Add deferred field. (cpp_set_deferred_macro): Define. (cpp_get_deferred_macro): Declare. (cpp_macro_definition): Reformat, add overload. (cpp_macro_definition_location): Deal with deferred macro. (cpp_alloc_token_string, cpp_compare_macro): Declare. * internal.h (_cpp_notify_macro_use): Return bool (_cpp_maybe_notify_macro_use): Likewise. * directives.c (do_undef): Check macro is not undef before warning. (do_ifdef, do_ifndef): Deal with deferred macro. * expr.c (parse_defined): Likewise. * lex.c (cpp_allocate_token_string): Break out of ... (create_literal): ... here. Call it. (cpp_maybe_module_directive): Deal with deferred macro. * macro.c (cpp_get_token_1): Deal with deferred macro. (warn_of_redefinition): Deal with deferred macro. (compare_macros): Rename to ... (cpp_compare_macro): ... here. Make extern. (cpp_get_deferred_macro): New. (_cpp_notify_macro_use): Deal with deferred macro, return bool indicating definedness. (cpp_macro_definition): Deal with deferred macro.
2020-11-25 00:23:55 +08:00
is_defined = _cpp_defined_macro_p (node);
if (!_cpp_maybe_notify_macro_use (pfile, node, token->src_loc))
/* It wasn't a macro after all. */
is_defined = false;
_cpp_mark_macro_used (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 23:55:46 +08: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-29 01:59:06 +08:00
pfile->state.prevent_expansion--;
/* Do not treat conditional macros as being defined. This is due to the
powerpc port 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;
preprocessor: Add deferred macros Deferred macros are needed for C++ modules. Header units may export macro definitions and undefinitions. These are resolved lazily at the point of (potential) use. (The language specifies that, it's not just a useful optimization.) Thus, identifier nodes grow a 'deferred' field, which fortunately doesn't expand the structure on 64-bit systems as there was padding there. This is non-zero on NT_MACRO nodes, if the macro is deferred. When such an identifier is lexed, it is resolved via a callback that I added recently. That will either provide the macro definition, or discover it there was an overriding undef. Either way the identifier is no longer a deferred macro. Notice it is now possible for NT_MACRO nodes to have a NULL macro expansion. libcpp/ * include/cpplib.h (struct cpp_hashnode): Add deferred field. (cpp_set_deferred_macro): Define. (cpp_get_deferred_macro): Declare. (cpp_macro_definition): Reformat, add overload. (cpp_macro_definition_location): Deal with deferred macro. (cpp_alloc_token_string, cpp_compare_macro): Declare. * internal.h (_cpp_notify_macro_use): Return bool (_cpp_maybe_notify_macro_use): Likewise. * directives.c (do_undef): Check macro is not undef before warning. (do_ifdef, do_ifndef): Deal with deferred macro. * expr.c (parse_defined): Likewise. * lex.c (cpp_allocate_token_string): Break out of ... (create_literal): ... here. Call it. (cpp_maybe_module_directive): Deal with deferred macro. * macro.c (cpp_get_token_1): Deal with deferred macro. (warn_of_redefinition): Deal with deferred macro. (compare_macros): Rename to ... (cpp_compare_macro): ... here. Make extern. (cpp_get_deferred_macro): New. (_cpp_notify_macro_use): Deal with deferred macro, return bool indicating definedness. (cpp_macro_definition): Deal with deferred macro.
2020-11-25 00:23:55 +08:00
result.low = is_defined;
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 23:55:46 +08: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 18:51:15 +08:00
eval_token (cpp_reader *pfile, const cpp_token *token,
Eliminate source_location in favor of location_t Historically GCC used location_t, while libcpp used source_location. This inconsistency has been annoying me for a while, so this patch removes source_location in favor of location_t throughout (as the latter is shorter). gcc/ChangeLog: * builtins.c: Replace "source_location" with "location_t". * diagnostic-show-locus.c: Likewise. * diagnostic.c: Likewise. * dumpfile.c: Likewise. * gcc-rich-location.h: Likewise. * genmatch.c: Likewise. * gimple.h: Likewise. * gimplify.c: Likewise. * input.c: Likewise. * input.h: Likewise. Eliminate the typedef. * omp-expand.c: Likewise. * selftest.h: Likewise. * substring-locations.h (get_source_location_for_substring): Rename to.. (get_location_within_string): ...this. * tree-cfg.c: Replace "source_location" with "location_t". * tree-cfgcleanup.c: Likewise. * tree-diagnostic.c: Likewise. * tree-into-ssa.c: Likewise. * tree-outof-ssa.c: Likewise. * tree-parloops.c: Likewise. * tree-phinodes.c: Likewise. * tree-phinodes.h: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-manip.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-phiprop.c: Likewise. * tree-ssa-threadupdate.c: Likewise. * tree-ssa.c: Likewise. * tree-ssa.h: Likewise. * tree-vect-loop-manip.c: Likewise. gcc/c-family/ChangeLog: * c-common.c (c_get_substring_location): Update for renaming of get_source_location_for_substring to get_location_within_string. * c-lex.c: Replace "source_location" with "location_t". * c-opts.c: Likewise. * c-ppoutput.c: Likewise. gcc/c/ChangeLog: * c-decl.c: Replace "source_location" with "location_t". * c-tree.h: Likewise. * c-typeck.c: Likewise. * gimple-parser.c: Likewise. gcc/cp/ChangeLog: * call.c: Replace "source_location" with "location_t". * cp-tree.h: Likewise. * cvt.c: Likewise. * name-lookup.c: Likewise. * parser.c: Likewise. * typeck.c: Likewise. gcc/fortran/ChangeLog: * cpp.c: Replace "source_location" with "location_t". * gfortran.h: Likewise. gcc/go/ChangeLog: * go-gcc-diagnostics.cc: Replace "source_location" with "location_t". * go-gcc.cc: Likewise. * go-linemap.cc: Likewise. * go-location.h: Likewise. * gofrontend/README: Likewise. gcc/jit/ChangeLog: * jit-playback.c: Replace "source_location" with "location_t". gcc/testsuite/ChangeLog: * g++.dg/plugin/comment_plugin.c: Replace "source_location" with "location_t". * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c: Likewise. libcc1/ChangeLog: * libcc1plugin.cc: Replace "source_location" with "location_t". (plugin_context::get_source_location): Rename to... (plugin_context::get_location_t): ...this. * libcp1plugin.cc: Likewise. libcpp/ChangeLog: * charset.c: Replace "source_location" with "location_t". * directives-only.c: Likewise. * directives.c: Likewise. * errors.c: Likewise. * expr.c: Likewise. * files.c: Likewise. * include/cpplib.h: Likewise. Rename MAX_SOURCE_LOCATION to MAX_LOCATION_T. * include/line-map.h: Likewise. * init.c: Likewise. * internal.h: Likewise. * lex.c: Likewise. * line-map.c: Likewise. * location-example.txt: Likewise. * macro.c: Likewise. * pch.c: Likewise. * traditional.c: Likewise. From-SVN: r266085
2018-11-14 04:05:03 +08:00
location_t virtual_location)
1995-03-17 05:59:07 +08: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 09:58:21 +08: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-29 01:59:06 +08: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 08:57:09 +08:00
{
1995-03-17 05:59:07 +08: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 18:51:15 +08: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-27 03:30:59 +08: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 18:51:15 +08: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 18:51:15 +08: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 21:58:08 +08: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 20:58:48 +08: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 08:57:09 +08:00
case CPP_NAME:
if (token->val.node.node == pfile->spec_nodes.n_defined)
return parse_defined (pfile);
c: New C2x keywords C2x follows C++ in making alignas, alignof, bool, false, static_assert, thread_local and true keywords; implement this accordingly. This implementation makes them normal keywords in C2x mode just like any other keyword (C2x leaves open the possibility of implementation using predefined macros instead - thus, there aren't any testcases asserting that they aren't macros). As in C++ and previous versions of C, true and false are handled like signed 1 and 0 in #if (there was an intermediate state in some C2x drafts where they had different macro expansions that were unsigned in #if). Bootstrapped with no regressions for x86_64-pc-linux-gnu. As with the removal of unprototyped functions, this change has a high risk of breaking some old code and people doing GNU/Linux distribution builds may wish to see how much is broken in a build with a -std=gnu2x default. gcc/ * ginclude/stdalign.h [defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L]: Disable all content. * ginclude/stdbool.h [defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L] (bool, true, false): Do not define. gcc/c-family/ * c-common.cc (c_common_reswords): Use D_C2X instead of D_CXXONLY for alignas, alignof, bool, false, static_assert, thread_local and true. gcc/c/ * c-parser.cc (c_parser_static_assert_declaration_no_semi) (c_parser_alignas_specifier, c_parser_alignof_expression): Allow for C2x spellings of keywords. (c_parser_postfix_expression): Handle RID_TRUE and RID_FALSE. gcc/testsuite/ * gcc.dg/c11-keywords-1.c, gcc.dg/c2x-align-1.c, gcc.dg/c2x-align-6.c, gcc.dg/c2x-bool-2.c, gcc.dg/c2x-static-assert-3.c, gcc.dg/c2x-static-assert-4.c, gcc.dg/c2x-thread-local-1.c: New tests. * gcc.dg/c2x-bool-1.c: Update expectations. libcpp/ * include/cpplib.h (struct cpp_options): Add true_false. * expr.cc (eval_token): Check true_false not cplusplus to determine whether to handle true and false keywords. * init.cc (struct lang_flags): Add true_false. (lang_defaults): Update. (cpp_set_lang): Set true_false.
2022-09-07 21:56:25 +08:00
else if (CPP_OPTION (pfile, true_false)
&& (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 18:51:15 +08:00
cpp_warning_with_line (pfile, CPP_W_UNDEF, virtual_location, 0,
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics When working on #embed support, or -Wheader-guard or other recent libcpp changes, I've been annoyed by the libcpp diagnostics being visually different from normal gcc diagnostics, especially in the area of quoting stuff in the diagnostic messages. Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use %</%>, %qs etc. in there, while libcpp diagnostics was marked as printf and in libcpp we've been very creative with quoting stuff, either no quotes at all, or "something" quoting, or 'something' quoting, or `something' quoting (but in none of the cases it used colors consistently with the rest of the compiler). Now, libcpp diagnostics is always emitted using a callback, pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with genmatch.cc: cb->diagnostic = diagnostic_cb; c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic; fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic; where the latter two just use diagnostic_report_diagnostic, so actually support all the gcc_diag stuff, only the genmatch.cc case didn't. So, the following patch changes genmatch.cc to use pp_format* instead of vfprintf so that it supports the gcc_diag formatting (pretty-print.o unfortunately has various dependencies, so had to link genmatch with libcommon.a libbacktrace.a and tweak Makefile.in so that there are no circular dependencies) and marks the libcpp diagnostic routines as gcc_diag rather than printf. That change resulted in hundreds of -Wformat-diag new warnings (most of them useful and resulting IMHO in better diagnostics), so the rest of the patch is changing the format strings to make -Wformat-diag happy and adjusting the testsuite for the differences in how is the diagnostic reformatted. Dunno if some out of GCC tree projects use libcpp, that case would make it harder because one couldn't use vfprintf in the diagnostic callback anymore, but there is always David's libdiagnostic which could be used for that purpose IMHO. 2024-10-12 Jakub Jelinek <jakub@redhat.com> libcpp/ * include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define. (struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF on diagnostic callback. (cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3. (cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. (cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6) instead of ATTRIBUTE_PRINTF_5. (cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. * Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather than --language=c. * errors.cc (cpp_diagnostic_at, cpp_diagnostic, cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of -ATTRIBUTE_FPTR_PRINTF. * charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex, convert_oct, convert_escape): Fix up -Wformat-diag warnings. (cpp_interpret_string_ranges, count_source_chars): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF. (narrow_str_to_charconst): Fix up -Wformat-diag warnings. * directives.cc (check_eol_1, directive_diagnostics, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, do_include_next, _cpp_parse_embed_params, do_embed, read_flag, do_line, do_linemarker, register_pragma_1, do_pragma_once, do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison, do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, do_assert, cpp_define_unused): Likewise. * expr.cc (cpp_classify_number, parse_defined, eval_token, _cpp_parse_expr, reduce, check_promotion): Likewise. * files.cc (_cpp_find_file, finish_base64_embed, _cpp_pop_file_buffer): Likewise. * init.cc (sanity_checks): Likewise. * lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char, _cpp_warn_invalid_utf8, _cpp_skip_block_comment, warn_about_normalization, forms_identifier_p, maybe_va_opt_error, identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise. * macro.cc (class vaopt_state, builtin_has_include_1, builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro, _cpp_builtin_macro_text, builtin_macro, stringify_arg, _cpp_arguments_ok, collect_args, enter_macro_context, _cpp_save_parameter, parse_params, create_iso_definition, _cpp_create_definition, check_trad_stringification): Likewise. * pch.cc (cpp_valid_state): Likewise. * traditional.cc (_cpp_scan_out_logical_line, recursive_macro): Likewise. gcc/ * Makefile.in (generated_files): Remove {gimple,generic}-match*. (generated_match_files): New variable. Add a dependency of $(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those. (build/genmatch$(build_exeext)): Depend on and link against libcommon.a and $(LIBBACKTRACE). * genmatch.cc: Include pretty-print.h and input.h. (ggc_internal_cleared_alloc, ggc_free): Remove. (fatal): New function. (line_table): Remove. (linemap_client_expand_location_to_spelling_point): Remove. (diagnostic_cb): Use gcc_diag rather than printf format. Use pp_format_verbatim on a temporary pretty_printer instead of vfprintf. (fatal_at, warning_at): Use gcc_diag rather than printf format. (output_line_directive): Rename location_hash to loc_hash. (parser::eat_ident, parser::parse_operation, parser::parse_expr, parser::parse_pattern, parser::finish_match_operand): Fix up -Wformat-diag warnings. gcc/c-family/ * c-lex.cc (c_common_has_attribute, c_common_lex_availability_macro): Fix up -Wformat-diag warnings. gcc/testsuite/ * c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for libcpp diagnostic formatting changes. * c-c++-common/cpp/embed-3.c: Likewise. * c-c++-common/cpp/embed-4.c: Likewise. * c-c++-common/cpp/embed-16.c: Likewise. * c-c++-common/cpp/embed-18.c: Likewise. * c-c++-common/cpp/eof-2.c: Likewise. * c-c++-common/cpp/eof-3.c: Likewise. * c-c++-common/cpp/fmax-include-depth.c: Likewise. * c-c++-common/cpp/has-builtin.c: Likewise. * c-c++-common/cpp/line-2.c: Likewise. * c-c++-common/cpp/line-3.c: Likewise. * c-c++-common/cpp/macro-arg-count-1.c: Likewise. * c-c++-common/cpp/macro-arg-count-2.c: Likewise. * c-c++-common/cpp/macro-ranges.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-4.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-5.c: Likewise. * c-c++-common/cpp/pr88974.c: Likewise. * c-c++-common/cpp/va-opt-error.c: Likewise. * c-c++-common/cpp/va-opt-pedantic.c: Likewise. * c-c++-common/cpp/Wheader-guard-2.c: Likewise. * c-c++-common/cpp/Wheader-guard-3.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-1.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-2.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-3.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c: Likewise. * c-c++-common/pr68833-3.c: Likewise. * c-c++-common/raw-string-directive-1.c: Likewise. * gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise. * gcc.dg/binary-constants-4.c: Likewise. * gcc.dg/builtin-redefine.c: Likewise. * gcc.dg/cpp/19951025-1.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c23-elifdef-2.c: Likewise. * gcc.dg/cpp/c23-warning-2.c: Likewise. * gcc.dg/cpp/embed-2.c: Likewise. * gcc.dg/cpp/embed-3.c: Likewise. * gcc.dg/cpp/embed-4.c: Likewise. * gcc.dg/cpp/expr.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu23-warning-2.c: Likewise. * gcc.dg/cpp/include6.c: Likewise. * gcc.dg/cpp/pr35322.c: Likewise. * gcc.dg/cpp/tr-warn6.c: Likewise. * gcc.dg/cpp/undef2.c: Likewise. * gcc.dg/cpp/warn-comments.c: Likewise. * gcc.dg/cpp/warn-comments-2.c: Likewise. * gcc.dg/cpp/warn-comments-3.c: Likewise. * gcc.dg/cpp/warn-cxx-compat.c: Likewise. * gcc.dg/cpp/warn-cxx-compat-2.c: Likewise. * gcc.dg/cpp/warn-deprecated.c: Likewise. * gcc.dg/cpp/warn-deprecated-2.c: Likewise. * gcc.dg/cpp/warn-long-long.c: Likewise. * gcc.dg/cpp/warn-long-long-2.c: Likewise. * gcc.dg/cpp/warn-normalized-1.c: Likewise. * gcc.dg/cpp/warn-normalized-2.c: Likewise. * gcc.dg/cpp/warn-normalized-3.c: Likewise. * gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise. * gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise. * gcc.dg/cpp/warn-redefined.c: Likewise. * gcc.dg/cpp/warn-redefined-2.c: Likewise. * gcc.dg/cpp/warn-traditional.c: Likewise. * gcc.dg/cpp/warn-traditional-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-1.c: Likewise. * gcc.dg/cpp/warn-trigraphs-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-3.c: Likewise. * gcc.dg/cpp/warn-trigraphs-4.c: Likewise. * gcc.dg/cpp/warn-undef.c: Likewise. * gcc.dg/cpp/warn-undef-2.c: Likewise. * gcc.dg/cpp/warn-unused-macros.c: Likewise. * gcc.dg/cpp/warn-unused-macros-2.c: Likewise. * gcc.dg/pch/counter-2.c: Likewise. * g++.dg/cpp0x/udlit-error1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-1.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-3.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-4.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-5.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-6.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-7.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-8.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-9.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-10.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-11.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-12.C: Likewise. * g++.dg/cpp/elifdef-3.C: Likewise. * g++.dg/cpp/elifdef-5.C: Likewise. * g++.dg/cpp/elifdef-6.C: Likewise. * g++.dg/cpp/elifdef-7.C: Likewise. * g++.dg/cpp/embed-1.C: Likewise. * g++.dg/cpp/embed-2.C: Likewise. * g++.dg/cpp/pedantic-errors.C: Likewise. * g++.dg/cpp/warning-1.C: Likewise. * g++.dg/cpp/warning-2.C: Likewise. * g++.dg/ext/bitint1.C: Likewise. * g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
"%qs 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 18:51:15 +08:00
NODE_NAME (token->val.node.node));
1995-03-17 05:59:07 +08:00
}
break;
1995-03-17 05:59:07 +08: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 22:50:27 +08:00
case CPP_HASH:
if (!pfile->state.skipping)
{
/* A pedantic warning takes precedence over a deprecated
warning here. */
libcpp: adjust pedwarn handling Using cpp_pedwarning (CPP_W_PEDANTIC instead of if (CPP_PEDANTIC cpp_error lets users suppress these diagnostics with #pragma GCC diagnostic ignored "-Wpedantic". This patch changes all instances of the cpp_error (CPP_DL_PEDWARN to cpp_pedwarning. In cases where the extension appears in a later C++ revision, we now condition the warning on the relevant -Wc++??-extensions flag instead of -Wpedantic; in such cases often the if (CPP_PEDANTIC) check is retained to preserve the default non-warning behavior. I didn't attempt to adjust the warning flags for the C compiler, since it seems to follow a different system than C++. The CPP_PEDANTIC check is also kept in _cpp_lex_direct to avoid an ICE in the self-tests from cb.diagnostics not being initialized. While working on testcases for these changes I noticed that the c-c++-common tests are not run with -pedantic-errors by default like the gcc.dg and g++.dg directories are. And if I specify -pedantic-errors with dg-options, the default -std= changes from c++?? to gnu++??, which interferes with some other pedwarns. So two of the tests are C++-only. libcpp/ChangeLog: * include/cpplib.h (enum cpp_warning_reason): Add CPP_W_CXX{14,17,20,23}_EXTENSIONS. * charset.cc (_cpp_valid_ucn, convert_hex, convert_oct) (convert_escape, narrow_str_to_charconst): Use cpp_pedwarning instead of cpp_error for pedwarns. * directives.cc (directive_diagnostics, _cpp_handle_directive) (do_line, do_elif): Likewise. * expr.cc (cpp_classify_number, eval_token): Likewise. * lex.cc (skip_whitespace, maybe_va_opt_error) (_cpp_lex_direct): Likewise. * macro.cc (_cpp_arguments_ok): Likewise. (replace_args): Use -Wvariadic-macros for pedwarn about empty macro arguments. gcc/c-family/ChangeLog: * c.opt: Add CppReason for Wc++{14,17,20,23}-extensions. * c-pragma.cc (handle_pragma_diagnostic_impl): Don't check OPT_Wc__23_extensions. gcc/testsuite/ChangeLog: * c-c++-common/pragma-diag-17.c: New test. * g++.dg/cpp0x/va-opt1.C: New test. * g++.dg/cpp23/named-universal-char-escape3.C: New test.
2024-08-28 01:15:16 +08:00
if (cpp_pedwarning_with_line (pfile, CPP_W_PEDANTIC,
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 22:49:14 +08: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 18:51:15 +08: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 22:50:27 +08: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 22:50:27 +08: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-29 01:59:06 +08:00
}
result.unsignedp = !!unsignedp;
return result;
1995-03-17 05:59:07 +08: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 23:52:48 +08: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-17 05:59:07 +08:00
/* Parse and evaluate a C expression, reading from PFILE.
libcpp, c-family: Add (dumb) C23 N3017 #embed support [PR105863] The following patch implements the C23 N3017 "#embed - a scannable, tooling-friendly binary resource inclusion mechanism" paper. The implementation is intentionally dumb, in that it doesn't significantly speed up compilation of larger initializers and doesn't make it possible to use huge #embeds (like several gigabytes large, that is compile time and memory still infeasible). There are 2 reasons for this. One is that I think like it is implemented now in the patch is how we should use it for the smaller #embed sizes, dunno with which boundary, whether 32 bytes or 64 or something like that, certainly handling the single byte cases which is something that can appear anywhere in the source where constant integer literal can appear is desirable and I think for a few bytes it isn't worth it to come up with something smarter and users would like to e.g. see it in -E readably as well (perhaps the slow vs. fast boundary should be determined by command line option). And the other one is to be able to more easily find regressions in behavior caused by the optimizations, so we have something to get back in git to compare against. I'm definitely willing to work on the optimizations (likely introduce a new CPP_* token type to refer to a range of libcpp owned memory (start + size) and similarly some tree which can do the same, and can be at any time e.g. split into 2 subparts + say INTEGER_CST in between if needed say for const unsigned char d[] = { #embed "2GB.dat" prefix (0, 0, ) suffix (, [0x40000000] = 42) }; still without having to copy around huge amounts of data; STRING_CST owns the memory it points to and can be only 2GB in size), but would like to do that incrementally. And would like to first include some extensions also not included in this patch, like gnu::offset (off) parameter to allow to skip certain constant amount of bytes at the start of the files, plus gnu::base64 ("base64_encoded_data") parameter to add something which can store more efficiently large amounts of the #embed data in preprocessed source. I've been cross-checking all the tests also against the LLVM implementation https://github.com/llvm/llvm-project/pull/68620 which has been for a few hours even committed to LLVM trunk but reverted afterwards. LLVM now has the support committed and I admit I haven't rechecked whether the behavior on the below mentioned spots have been fixed in it already or not yet. The patch uses --embed-dir= option that clang plans to add above and doesn't use other variants on the search directories yet, plus there are no default directories at least for the time being where to search for embed files. So, #embed "..." works if it is found in the same directory (or relative to the current file's directory) and #embed "/..." or #embed </...> work always, but relative #embed <...> doesn't unless at least one --embed-dir= is specified. There is no reason to differentiate between system and non-system directories, so we don't need -isystem like counterpart, perhaps -iquote like counterpart could be useful in the future, dunno what else. It has --embed-directory=dir and --embed-directory dir as aliases. There are some differences beyond clang ICEs, so I'd like to point them out to make sure there is agreement on the choices in the patch. They are also mentioned in the comments of the llvm pull request. The most important is that the GCC patch (as well as the original thephd.dev LLVM branch on godbolt) expands #embed (or acts as if it is expanded) into a mere sequence of numbers like 123,2,35,26 rather then what clang effectively treats as (unsigned char)123,(unsigned char)2,(unsigned char)35,(unsigned char)26 but only does that when using integrated preprocessor, not when using -save-temps where it acts as GCC. JeanHeyd as the original author agrees that is how it is currently worded in C23. Another difference (not tested in the testsuite, not sure how to check for effective target /dev/urandom nor am sure it is desirable to check that during testsuite) is how to treat character devices, named pipes etc. (block devices are errored on). The original paper uses /dev/urandom in various examples and seems to assume that unlike regular files the devices aren't really cached, so #embed </dev/urandom> limit(1) prefix(int a = ) suffix(;) #embed </dev/urandom> limit(1) prefix(int b = ) suffix(;) usually results in a != b. That is what the godbolt thephd.dev branch implements too and what this patch does as well, but clang actually seems to just go from st.st_size == 0, ergo it must be zero-sized resource and so just copies over if_empty if present. It is really questionable what to do about the character devices/named pipes with __has_embed, for regular files the patch doesn't read anything from them, relies on st.st_size + limit for whether it is empty or non-empty. But I don't know of a way to check if read on say a character device would read anything or not (the </dev/null> limit (1) vs. </dev/zero> limit (1) cases), and if we read something, that would be better cached for later because #embed later if it reads again could read no further data even when it first read something. So, the patch currently for __has_embed just always returns 2 on the non-regular files, like the thephd.dev branch does as well and like the clang pull request as well. A question is also what to do for gnu::offset on the non-regular files even for #embed, those aren't seekable and do we want to just read and throw away the offset bytes each time we see it used? clang also chokes on the #if __has_embed (__FILE__ __limit__ (1) __prefix__ () suffix (1 / 0) \ __if_empty__ ((({{[0[0{0{0(0(0)1)1}1}]]}})))) != __STDC_EMBED_FOUND__ #error "__has_embed fail" #endif in embed-1.c, but thephd.dev branch accepts it and I don't see why it shouldn't, (({{[0[0{0{0(0(0)1)1}1}]]}}))) is a balanced token sequence and the file isn't empty, so it should just be parsed and discarded. clang also IMHO mishandles const unsigned char w[] = { #embed __FILE__ prefix([0] = 42, [15] =) limit(32) }; but again only without -save-temps, seems like it treats it as [0] = 42, [15] = (99,111,110,115,116,32,117,110,115,105,103,110,101,100, 32,99,104,97,114,32,119,91,93,32,61,32,123,10,35,101,109,98) rather than [0] = 42, [15] = 99,111,110,115,116,32,117,110,115,105,103,110,101,100, 32,99,104,97,114,32,119,91,93,32,61,32,123,10,35,101,109,98 and warns on it for -Wunused-value and just compiles it as [0] = 42, [15] = 98 And also void foo (int, int, int, int); void bar (void) { foo ( #embed __FILE__ limit (4) prefix (172 + ) suffix (+ 2) ); } is treated as 172 + (118, 111, 105, 100) + 2 rather than 172 + 118, 111, 105, 100 + 2 which clang -save-temps or GCC treats it like, so results in just one argument passed rather than 4. if (!strstr ((const char *) magna_carta, "imprisonétur")) abort (); in the testcase fails as well, but in that case calling it in gdb succeeds: p ((char *(*)(char *, char *))__strstr_sse2) (magna_carta, "imprisonétur") $2 = 0x555555558d3c <magna_carta+11564> "imprisonétur aut disseisiátur"... so I guess they are just trying to constant evaluate strstr and do it incorrectly. They started with making the optimizations together in the initial patch set, so they don't have the luxury to compare if it is just because of the optimization they are trying to do or because that is how the feature works for them. At least unless they use -save-temps for now. There is also different behavior between clang and gcc on -M or other dependency generating options. Seems clang includes the __has_embed searched files in dependencies, while my patch doesn't. But so does clang for __has_include and GCC doesn't. Emitting a hard dependency on some header just because there was __has_include/__has_embed for it seems wrong to me, because (at least when properly written) the source likely doesn't mind if the file is missing, it will do something else, so a hard error from make because of it doesn't seem right. Does make have some weaker dependencies, such that if some file can be remade it is but if it doesn't exist, it isn't fatal? I wonder whether #embed <non-existent-file> really needs to be fatal or whether we could simply after diagnosing it pretend the file exists and is empty. For #include I think fatal errors make tons of sense, but perhaps for #embed which is more localized we'd get better error reporting if we didn't bail out immediately. Note, both GCC and clang currently treat those as fatal errors. clang also added -dE option which with -E instead of preprocessing the #embed directives keeps them as is, but the preprocessed source then isn't self-contained. That option looks more harmful than useful to me. Also, it isn't clear to me from C23 whether it is possible to have __has_include/__has_c_attribute/__has_embed expressions inside of the limit #embed/__has_embed argument. 6.10.3.2/2 says that defined should not appear there (and the patch diagnoses it and testsuite tests), but for __has_include/__has_embed etc. 6.10.1/11 says: "The identifiers __has_include, __has_embed, and __has_c_attribute shall not appear in any context not mentioned in this subclause." If that subclause in that case means 6.10.1, then it presumably shouldn't appear in #embed in 6.10.3, but __has_embed is in 6.10.1... But 6.10.3.2/3 says that it should be parsed according to the 6.10.1 rules. Haven't included tests like #if __has_embed (__FILE__ limit (__has_embed (__FILE__ limit (1)))) or #embed __FILE__ limit (__has_include (__FILE__)) into the testsuite because of the doubts but I think the patch should handle those right now. The reason I've used Magna Carta text in some of the testcases is that I hope it shouldn't be copyrighted after the centuries and I'd strongly prefer not to have binary blobs in git after the xz backdoor lesson and wanted something larger which doesn't change all the time. Oh, BTW, I see in C23 draft 6.10.3.2 in Example 4 if (f_source == NULL); return 1; (note the spurious semicolon after closing paren), has that been fixed already? Like the thephd.dev and clang implementations, the patch always macro expands the whole #embed and __has_embed directives except for the embed keyword. That is most likely not what C23 says, my limited understanding right now is that in #embed one needs to parse the whole directive line with macro expansion disabled and check if it satisfies the grammar, if not, the whole directive is macro expanded, if yes, only the limit parameter argument is macro expanded and the prefix/suffix/if_empty arguments are maybe macro expanded when actually used (and not at all if unused). And I think __has_embed macro expansion has conflicting rules. 2024-09-12 Jakub Jelinek <jakub@redhat.com> PR c/105863 libcpp/ * include/cpplib.h: Implement C23 N3017 #embed - a scannable, tooling-friendly binary resource inclusion mechanism paper. (struct cpp_options): Add embed member. (enum cpp_builtin_type): Add BT_HAS_EMBED. (cpp_set_include_chains): Add another cpp_dir * argument to the declaration. * internal.h (enum include_type): Add IT_EMBED. (struct cpp_reader): Add embed_include member. (struct cpp_embed_params_tokens): New type. (struct cpp_embed_params): New type. (_cpp_get_token_no_padding): Declare. (enum _cpp_find_file_kind): Add _cpp_FFK_EMBED and _cpp_FFK_HAS_EMBED. (_cpp_stack_embed): Declare. (_cpp_parse_expr): Change return type to cpp_num_part instead of bool, change second argument from bool to const char * and add third argument. (_cpp_parse_embed_params): Declare. * directives.cc (DIRECTIVE_TABLE): Add embed entry. (end_directive): Don't call skip_rest_of_line for T_EMBED directive. (_cpp_handle_directive): Return 2 rather than 1 for T_EMBED in directives-only mode. (parse_include): Don't Call check_eol for T_EMBED directive. (skip_balanced_token_seq): New function. (EMBED_PARAMS): Define. (enum embed_param_kind): New type. (embed_params): New variable. (_cpp_parse_embed_params): New function. (do_embed): New function. (do_if): Adjust _cpp_parse_expr caller. (do_elif): Likewise. * expr.cc (parse_defined): Diagnose defined in #embed or __has_embed parameters. (_cpp_parse_expr): Change return type to cpp_num_part instead of bool, change second argument from bool to const char * and add third argument. Adjust function comment. For #embed/__has_embed parameters add an artificial CPP_OPEN_PAREN. Use the second argument DIR directly instead of string literals conditional on IS_IF. For #embed/__has_embed parameter, stop on reaching CPP_CLOSE_PAREN matching the artificial one. Diagnose negative or too large embed parameter operands. (num_binary_op): Use #embed instead of #if for diagnostics if inside #embed/__has_embed parameter. (num_div_op): Likewise. * files.cc (struct _cpp_file): Add limit member and embed bitfield. (search_cache): Add IS_EMBED argument, formatting fix. Skip over files with different file->embed from the argument. (find_file_in_dir): Don't call pch_open_file if file->embed. (_cpp_find_file): Handle _cpp_FFK_EMBED and _cpp_FFK_HAS_EMBED. (read_file_guts): Formatting fix. (has_unique_contents): Ignore file->embed files. (search_path_head): Handle IT_EMBED type. (_cpp_stack_embed): New function. (_cpp_get_file_stat): Formatting fix. (cpp_set_include_chains): Add embed argument, save it to pfile->embed_include and compute lens for the chain. * init.cc (struct lang_flags): Add embed member. (lang_defaults): Add embed initializers. (cpp_set_lang): Initialize CPP_OPTION (pfile, embed). (builtin_array): Add __has_embed entry. (cpp_init_builtins): Predefine __STDC_EMBED_NOT_FOUND__, __STDC_EMBED_FOUND__ and __STDC_EMBED_EMPTY__. * lex.cc (cpp_directive_only_process): Handle #embed. * macro.cc (cpp_get_token_no_padding): Rename to ... (_cpp_get_token_no_padding): ... this. No longer static. (builtin_has_include_1): New function. (builtin_has_include): Use it. Use _cpp_get_token_no_padding instead of cpp_get_token_no_padding. (builtin_has_embed): New function. (_cpp_builtin_macro_text): Handle BT_HAS_EMBED. gcc/ * doc/cppdiropts.texi (--embed-dir=): Document. * doc/cpp.texi (Binary Resource Inclusion): New chapter. (__has_embed): Document. * doc/invoke.texi (Directory Options): Mention --embed-dir=. * gcc.cc (cpp_unique_options): Add %{-embed*}. * genmatch.cc (main): Adjust cpp_set_include_chains caller. * incpath.h (enum incpath_kind): Add INC_EMBED. * incpath.cc (merge_include_chains): Handle INC_EMBED. (register_include_chains): Adjust cpp_set_include_chains caller. gcc/c-family/ * c.opt (-embed-dir=): New option. (-embed-directory): New alias. (-embed-directory=): New alias. * c-opts.cc (c_common_handle_option): Handle OPT__embed_dir_. gcc/testsuite/ * c-c++-common/cpp/embed-1.c: New test. * c-c++-common/cpp/embed-2.c: New test. * c-c++-common/cpp/embed-3.c: New test. * c-c++-common/cpp/embed-4.c: New test. * c-c++-common/cpp/embed-5.c: New test. * c-c++-common/cpp/embed-6.c: New test. * c-c++-common/cpp/embed-7.c: New test. * c-c++-common/cpp/embed-8.c: New test. * c-c++-common/cpp/embed-9.c: New test. * c-c++-common/cpp/embed-10.c: New test. * c-c++-common/cpp/embed-11.c: New test. * c-c++-common/cpp/embed-12.c: New test. * c-c++-common/cpp/embed-13.c: New test. * c-c++-common/cpp/embed-14.c: New test. * c-c++-common/cpp/embed-25.c: New test. * c-c++-common/cpp/embed-26.c: New test. * c-c++-common/cpp/embed-dir/embed-1.inc: New test. * c-c++-common/cpp/embed-dir/embed-3.c: New test. * c-c++-common/cpp/embed-dir/embed-4.c: New test. * c-c++-common/cpp/embed-dir/magna-carta.txt: New test. * gcc.dg/cpp/embed-1.c: New test. * gcc.dg/cpp/embed-2.c: New test. * gcc.dg/cpp/embed-3.c: New test. * gcc.dg/cpp/embed-4.c: New test. * g++.dg/cpp/embed-1.C: New test. * g++.dg/cpp/embed-2.C: New test. * g++.dg/cpp/embed-3.C: New test.
2024-09-12 17:15:38 +08:00
Returns the truth value of the expression if OPEN_PAREN
is NULL, otherwise the low 64-bits of the result (when parsing
#embed/__has_embed parameters).
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. */
libcpp, c-family: Add (dumb) C23 N3017 #embed support [PR105863] The following patch implements the C23 N3017 "#embed - a scannable, tooling-friendly binary resource inclusion mechanism" paper. The implementation is intentionally dumb, in that it doesn't significantly speed up compilation of larger initializers and doesn't make it possible to use huge #embeds (like several gigabytes large, that is compile time and memory still infeasible). There are 2 reasons for this. One is that I think like it is implemented now in the patch is how we should use it for the smaller #embed sizes, dunno with which boundary, whether 32 bytes or 64 or something like that, certainly handling the single byte cases which is something that can appear anywhere in the source where constant integer literal can appear is desirable and I think for a few bytes it isn't worth it to come up with something smarter and users would like to e.g. see it in -E readably as well (perhaps the slow vs. fast boundary should be determined by command line option). And the other one is to be able to more easily find regressions in behavior caused by the optimizations, so we have something to get back in git to compare against. I'm definitely willing to work on the optimizations (likely introduce a new CPP_* token type to refer to a range of libcpp owned memory (start + size) and similarly some tree which can do the same, and can be at any time e.g. split into 2 subparts + say INTEGER_CST in between if needed say for const unsigned char d[] = { #embed "2GB.dat" prefix (0, 0, ) suffix (, [0x40000000] = 42) }; still without having to copy around huge amounts of data; STRING_CST owns the memory it points to and can be only 2GB in size), but would like to do that incrementally. And would like to first include some extensions also not included in this patch, like gnu::offset (off) parameter to allow to skip certain constant amount of bytes at the start of the files, plus gnu::base64 ("base64_encoded_data") parameter to add something which can store more efficiently large amounts of the #embed data in preprocessed source. I've been cross-checking all the tests also against the LLVM implementation https://github.com/llvm/llvm-project/pull/68620 which has been for a few hours even committed to LLVM trunk but reverted afterwards. LLVM now has the support committed and I admit I haven't rechecked whether the behavior on the below mentioned spots have been fixed in it already or not yet. The patch uses --embed-dir= option that clang plans to add above and doesn't use other variants on the search directories yet, plus there are no default directories at least for the time being where to search for embed files. So, #embed "..." works if it is found in the same directory (or relative to the current file's directory) and #embed "/..." or #embed </...> work always, but relative #embed <...> doesn't unless at least one --embed-dir= is specified. There is no reason to differentiate between system and non-system directories, so we don't need -isystem like counterpart, perhaps -iquote like counterpart could be useful in the future, dunno what else. It has --embed-directory=dir and --embed-directory dir as aliases. There are some differences beyond clang ICEs, so I'd like to point them out to make sure there is agreement on the choices in the patch. They are also mentioned in the comments of the llvm pull request. The most important is that the GCC patch (as well as the original thephd.dev LLVM branch on godbolt) expands #embed (or acts as if it is expanded) into a mere sequence of numbers like 123,2,35,26 rather then what clang effectively treats as (unsigned char)123,(unsigned char)2,(unsigned char)35,(unsigned char)26 but only does that when using integrated preprocessor, not when using -save-temps where it acts as GCC. JeanHeyd as the original author agrees that is how it is currently worded in C23. Another difference (not tested in the testsuite, not sure how to check for effective target /dev/urandom nor am sure it is desirable to check that during testsuite) is how to treat character devices, named pipes etc. (block devices are errored on). The original paper uses /dev/urandom in various examples and seems to assume that unlike regular files the devices aren't really cached, so #embed </dev/urandom> limit(1) prefix(int a = ) suffix(;) #embed </dev/urandom> limit(1) prefix(int b = ) suffix(;) usually results in a != b. That is what the godbolt thephd.dev branch implements too and what this patch does as well, but clang actually seems to just go from st.st_size == 0, ergo it must be zero-sized resource and so just copies over if_empty if present. It is really questionable what to do about the character devices/named pipes with __has_embed, for regular files the patch doesn't read anything from them, relies on st.st_size + limit for whether it is empty or non-empty. But I don't know of a way to check if read on say a character device would read anything or not (the </dev/null> limit (1) vs. </dev/zero> limit (1) cases), and if we read something, that would be better cached for later because #embed later if it reads again could read no further data even when it first read something. So, the patch currently for __has_embed just always returns 2 on the non-regular files, like the thephd.dev branch does as well and like the clang pull request as well. A question is also what to do for gnu::offset on the non-regular files even for #embed, those aren't seekable and do we want to just read and throw away the offset bytes each time we see it used? clang also chokes on the #if __has_embed (__FILE__ __limit__ (1) __prefix__ () suffix (1 / 0) \ __if_empty__ ((({{[0[0{0{0(0(0)1)1}1}]]}})))) != __STDC_EMBED_FOUND__ #error "__has_embed fail" #endif in embed-1.c, but thephd.dev branch accepts it and I don't see why it shouldn't, (({{[0[0{0{0(0(0)1)1}1}]]}}))) is a balanced token sequence and the file isn't empty, so it should just be parsed and discarded. clang also IMHO mishandles const unsigned char w[] = { #embed __FILE__ prefix([0] = 42, [15] =) limit(32) }; but again only without -save-temps, seems like it treats it as [0] = 42, [15] = (99,111,110,115,116,32,117,110,115,105,103,110,101,100, 32,99,104,97,114,32,119,91,93,32,61,32,123,10,35,101,109,98) rather than [0] = 42, [15] = 99,111,110,115,116,32,117,110,115,105,103,110,101,100, 32,99,104,97,114,32,119,91,93,32,61,32,123,10,35,101,109,98 and warns on it for -Wunused-value and just compiles it as [0] = 42, [15] = 98 And also void foo (int, int, int, int); void bar (void) { foo ( #embed __FILE__ limit (4) prefix (172 + ) suffix (+ 2) ); } is treated as 172 + (118, 111, 105, 100) + 2 rather than 172 + 118, 111, 105, 100 + 2 which clang -save-temps or GCC treats it like, so results in just one argument passed rather than 4. if (!strstr ((const char *) magna_carta, "imprisonétur")) abort (); in the testcase fails as well, but in that case calling it in gdb succeeds: p ((char *(*)(char *, char *))__strstr_sse2) (magna_carta, "imprisonétur") $2 = 0x555555558d3c <magna_carta+11564> "imprisonétur aut disseisiátur"... so I guess they are just trying to constant evaluate strstr and do it incorrectly. They started with making the optimizations together in the initial patch set, so they don't have the luxury to compare if it is just because of the optimization they are trying to do or because that is how the feature works for them. At least unless they use -save-temps for now. There is also different behavior between clang and gcc on -M or other dependency generating options. Seems clang includes the __has_embed searched files in dependencies, while my patch doesn't. But so does clang for __has_include and GCC doesn't. Emitting a hard dependency on some header just because there was __has_include/__has_embed for it seems wrong to me, because (at least when properly written) the source likely doesn't mind if the file is missing, it will do something else, so a hard error from make because of it doesn't seem right. Does make have some weaker dependencies, such that if some file can be remade it is but if it doesn't exist, it isn't fatal? I wonder whether #embed <non-existent-file> really needs to be fatal or whether we could simply after diagnosing it pretend the file exists and is empty. For #include I think fatal errors make tons of sense, but perhaps for #embed which is more localized we'd get better error reporting if we didn't bail out immediately. Note, both GCC and clang currently treat those as fatal errors. clang also added -dE option which with -E instead of preprocessing the #embed directives keeps them as is, but the preprocessed source then isn't self-contained. That option looks more harmful than useful to me. Also, it isn't clear to me from C23 whether it is possible to have __has_include/__has_c_attribute/__has_embed expressions inside of the limit #embed/__has_embed argument. 6.10.3.2/2 says that defined should not appear there (and the patch diagnoses it and testsuite tests), but for __has_include/__has_embed etc. 6.10.1/11 says: "The identifiers __has_include, __has_embed, and __has_c_attribute shall not appear in any context not mentioned in this subclause." If that subclause in that case means 6.10.1, then it presumably shouldn't appear in #embed in 6.10.3, but __has_embed is in 6.10.1... But 6.10.3.2/3 says that it should be parsed according to the 6.10.1 rules. Haven't included tests like #if __has_embed (__FILE__ limit (__has_embed (__FILE__ limit (1)))) or #embed __FILE__ limit (__has_include (__FILE__)) into the testsuite because of the doubts but I think the patch should handle those right now. The reason I've used Magna Carta text in some of the testcases is that I hope it shouldn't be copyrighted after the centuries and I'd strongly prefer not to have binary blobs in git after the xz backdoor lesson and wanted something larger which doesn't change all the time. Oh, BTW, I see in C23 draft 6.10.3.2 in Example 4 if (f_source == NULL); return 1; (note the spurious semicolon after closing paren), has that been fixed already? Like the thephd.dev and clang implementations, the patch always macro expands the whole #embed and __has_embed directives except for the embed keyword. That is most likely not what C23 says, my limited understanding right now is that in #embed one needs to parse the whole directive line with macro expansion disabled and check if it satisfies the grammar, if not, the whole directive is macro expanded, if yes, only the limit parameter argument is macro expanded and the prefix/suffix/if_empty arguments are maybe macro expanded when actually used (and not at all if unused). And I think __has_embed macro expansion has conflicting rules. 2024-09-12 Jakub Jelinek <jakub@redhat.com> PR c/105863 libcpp/ * include/cpplib.h: Implement C23 N3017 #embed - a scannable, tooling-friendly binary resource inclusion mechanism paper. (struct cpp_options): Add embed member. (enum cpp_builtin_type): Add BT_HAS_EMBED. (cpp_set_include_chains): Add another cpp_dir * argument to the declaration. * internal.h (enum include_type): Add IT_EMBED. (struct cpp_reader): Add embed_include member. (struct cpp_embed_params_tokens): New type. (struct cpp_embed_params): New type. (_cpp_get_token_no_padding): Declare. (enum _cpp_find_file_kind): Add _cpp_FFK_EMBED and _cpp_FFK_HAS_EMBED. (_cpp_stack_embed): Declare. (_cpp_parse_expr): Change return type to cpp_num_part instead of bool, change second argument from bool to const char * and add third argument. (_cpp_parse_embed_params): Declare. * directives.cc (DIRECTIVE_TABLE): Add embed entry. (end_directive): Don't call skip_rest_of_line for T_EMBED directive. (_cpp_handle_directive): Return 2 rather than 1 for T_EMBED in directives-only mode. (parse_include): Don't Call check_eol for T_EMBED directive. (skip_balanced_token_seq): New function. (EMBED_PARAMS): Define. (enum embed_param_kind): New type. (embed_params): New variable. (_cpp_parse_embed_params): New function. (do_embed): New function. (do_if): Adjust _cpp_parse_expr caller. (do_elif): Likewise. * expr.cc (parse_defined): Diagnose defined in #embed or __has_embed parameters. (_cpp_parse_expr): Change return type to cpp_num_part instead of bool, change second argument from bool to const char * and add third argument. Adjust function comment. For #embed/__has_embed parameters add an artificial CPP_OPEN_PAREN. Use the second argument DIR directly instead of string literals conditional on IS_IF. For #embed/__has_embed parameter, stop on reaching CPP_CLOSE_PAREN matching the artificial one. Diagnose negative or too large embed parameter operands. (num_binary_op): Use #embed instead of #if for diagnostics if inside #embed/__has_embed parameter. (num_div_op): Likewise. * files.cc (struct _cpp_file): Add limit member and embed bitfield. (search_cache): Add IS_EMBED argument, formatting fix. Skip over files with different file->embed from the argument. (find_file_in_dir): Don't call pch_open_file if file->embed. (_cpp_find_file): Handle _cpp_FFK_EMBED and _cpp_FFK_HAS_EMBED. (read_file_guts): Formatting fix. (has_unique_contents): Ignore file->embed files. (search_path_head): Handle IT_EMBED type. (_cpp_stack_embed): New function. (_cpp_get_file_stat): Formatting fix. (cpp_set_include_chains): Add embed argument, save it to pfile->embed_include and compute lens for the chain. * init.cc (struct lang_flags): Add embed member. (lang_defaults): Add embed initializers. (cpp_set_lang): Initialize CPP_OPTION (pfile, embed). (builtin_array): Add __has_embed entry. (cpp_init_builtins): Predefine __STDC_EMBED_NOT_FOUND__, __STDC_EMBED_FOUND__ and __STDC_EMBED_EMPTY__. * lex.cc (cpp_directive_only_process): Handle #embed. * macro.cc (cpp_get_token_no_padding): Rename to ... (_cpp_get_token_no_padding): ... this. No longer static. (builtin_has_include_1): New function. (builtin_has_include): Use it. Use _cpp_get_token_no_padding instead of cpp_get_token_no_padding. (builtin_has_embed): New function. (_cpp_builtin_macro_text): Handle BT_HAS_EMBED. gcc/ * doc/cppdiropts.texi (--embed-dir=): Document. * doc/cpp.texi (Binary Resource Inclusion): New chapter. (__has_embed): Document. * doc/invoke.texi (Directory Options): Mention --embed-dir=. * gcc.cc (cpp_unique_options): Add %{-embed*}. * genmatch.cc (main): Adjust cpp_set_include_chains caller. * incpath.h (enum incpath_kind): Add INC_EMBED. * incpath.cc (merge_include_chains): Handle INC_EMBED. (register_include_chains): Adjust cpp_set_include_chains caller. gcc/c-family/ * c.opt (-embed-dir=): New option. (-embed-directory): New alias. (-embed-directory=): New alias. * c-opts.cc (c_common_handle_option): Handle OPT__embed_dir_. gcc/testsuite/ * c-c++-common/cpp/embed-1.c: New test. * c-c++-common/cpp/embed-2.c: New test. * c-c++-common/cpp/embed-3.c: New test. * c-c++-common/cpp/embed-4.c: New test. * c-c++-common/cpp/embed-5.c: New test. * c-c++-common/cpp/embed-6.c: New test. * c-c++-common/cpp/embed-7.c: New test. * c-c++-common/cpp/embed-8.c: New test. * c-c++-common/cpp/embed-9.c: New test. * c-c++-common/cpp/embed-10.c: New test. * c-c++-common/cpp/embed-11.c: New test. * c-c++-common/cpp/embed-12.c: New test. * c-c++-common/cpp/embed-13.c: New test. * c-c++-common/cpp/embed-14.c: New test. * c-c++-common/cpp/embed-25.c: New test. * c-c++-common/cpp/embed-26.c: New test. * c-c++-common/cpp/embed-dir/embed-1.inc: New test. * c-c++-common/cpp/embed-dir/embed-3.c: New test. * c-c++-common/cpp/embed-dir/embed-4.c: New test. * c-c++-common/cpp/embed-dir/magna-carta.txt: New test. * gcc.dg/cpp/embed-1.c: New test. * gcc.dg/cpp/embed-2.c: New test. * gcc.dg/cpp/embed-3.c: New test. * gcc.dg/cpp/embed-4.c: New test. * g++.dg/cpp/embed-1.C: New test. * g++.dg/cpp/embed-2.C: New test. * g++.dg/cpp/embed-3.C: New test.
2024-09-12 17:15:38 +08:00
cpp_num_part
_cpp_parse_expr (cpp_reader *pfile, const char *dir,
const cpp_token *open_paren)
1995-03-17 05:59:07 +08:00
{
struct op *top = pfile->op_stack;
unsigned int lex_count;
bool saw_leading_not, want_value = true;
Eliminate source_location in favor of location_t Historically GCC used location_t, while libcpp used source_location. This inconsistency has been annoying me for a while, so this patch removes source_location in favor of location_t throughout (as the latter is shorter). gcc/ChangeLog: * builtins.c: Replace "source_location" with "location_t". * diagnostic-show-locus.c: Likewise. * diagnostic.c: Likewise. * dumpfile.c: Likewise. * gcc-rich-location.h: Likewise. * genmatch.c: Likewise. * gimple.h: Likewise. * gimplify.c: Likewise. * input.c: Likewise. * input.h: Likewise. Eliminate the typedef. * omp-expand.c: Likewise. * selftest.h: Likewise. * substring-locations.h (get_source_location_for_substring): Rename to.. (get_location_within_string): ...this. * tree-cfg.c: Replace "source_location" with "location_t". * tree-cfgcleanup.c: Likewise. * tree-diagnostic.c: Likewise. * tree-into-ssa.c: Likewise. * tree-outof-ssa.c: Likewise. * tree-parloops.c: Likewise. * tree-phinodes.c: Likewise. * tree-phinodes.h: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-manip.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-phiprop.c: Likewise. * tree-ssa-threadupdate.c: Likewise. * tree-ssa.c: Likewise. * tree-ssa.h: Likewise. * tree-vect-loop-manip.c: Likewise. gcc/c-family/ChangeLog: * c-common.c (c_get_substring_location): Update for renaming of get_source_location_for_substring to get_location_within_string. * c-lex.c: Replace "source_location" with "location_t". * c-opts.c: Likewise. * c-ppoutput.c: Likewise. gcc/c/ChangeLog: * c-decl.c: Replace "source_location" with "location_t". * c-tree.h: Likewise. * c-typeck.c: Likewise. * gimple-parser.c: Likewise. gcc/cp/ChangeLog: * call.c: Replace "source_location" with "location_t". * cp-tree.h: Likewise. * cvt.c: Likewise. * name-lookup.c: Likewise. * parser.c: Likewise. * typeck.c: Likewise. gcc/fortran/ChangeLog: * cpp.c: Replace "source_location" with "location_t". * gfortran.h: Likewise. gcc/go/ChangeLog: * go-gcc-diagnostics.cc: Replace "source_location" with "location_t". * go-gcc.cc: Likewise. * go-linemap.cc: Likewise. * go-location.h: Likewise. * gofrontend/README: Likewise. gcc/jit/ChangeLog: * jit-playback.c: Replace "source_location" with "location_t". gcc/testsuite/ChangeLog: * g++.dg/plugin/comment_plugin.c: Replace "source_location" with "location_t". * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c: Likewise. libcc1/ChangeLog: * libcc1plugin.cc: Replace "source_location" with "location_t". (plugin_context::get_source_location): Rename to... (plugin_context::get_location_t): ...this. * libcp1plugin.cc: Likewise. libcpp/ChangeLog: * charset.c: Replace "source_location" with "location_t". * directives-only.c: Likewise. * directives.c: Likewise. * errors.c: Likewise. * expr.c: Likewise. * files.c: Likewise. * include/cpplib.h: Likewise. Rename MAX_SOURCE_LOCATION to MAX_LOCATION_T. * include/line-map.h: Likewise. * init.c: Likewise. * internal.h: Likewise. * lex.c: Likewise. * line-map.c: Likewise. * location-example.txt: Likewise. * macro.c: Likewise. * pch.c: Likewise. * traditional.c: Likewise. From-SVN: r266085
2018-11-14 04:05:03 +08:00
location_t virtual_location = 0;
pfile->state.skip_eval = 0;
1995-03-17 05:59:07 +08: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-29 01:59:06 +08: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-29 01:59:06 +08:00
/* Lowest priority operator prevents further reductions. */
top->op = CPP_EOF;
libcpp, c-family: Add (dumb) C23 N3017 #embed support [PR105863] The following patch implements the C23 N3017 "#embed - a scannable, tooling-friendly binary resource inclusion mechanism" paper. The implementation is intentionally dumb, in that it doesn't significantly speed up compilation of larger initializers and doesn't make it possible to use huge #embeds (like several gigabytes large, that is compile time and memory still infeasible). There are 2 reasons for this. One is that I think like it is implemented now in the patch is how we should use it for the smaller #embed sizes, dunno with which boundary, whether 32 bytes or 64 or something like that, certainly handling the single byte cases which is something that can appear anywhere in the source where constant integer literal can appear is desirable and I think for a few bytes it isn't worth it to come up with something smarter and users would like to e.g. see it in -E readably as well (perhaps the slow vs. fast boundary should be determined by command line option). And the other one is to be able to more easily find regressions in behavior caused by the optimizations, so we have something to get back in git to compare against. I'm definitely willing to work on the optimizations (likely introduce a new CPP_* token type to refer to a range of libcpp owned memory (start + size) and similarly some tree which can do the same, and can be at any time e.g. split into 2 subparts + say INTEGER_CST in between if needed say for const unsigned char d[] = { #embed "2GB.dat" prefix (0, 0, ) suffix (, [0x40000000] = 42) }; still without having to copy around huge amounts of data; STRING_CST owns the memory it points to and can be only 2GB in size), but would like to do that incrementally. And would like to first include some extensions also not included in this patch, like gnu::offset (off) parameter to allow to skip certain constant amount of bytes at the start of the files, plus gnu::base64 ("base64_encoded_data") parameter to add something which can store more efficiently large amounts of the #embed data in preprocessed source. I've been cross-checking all the tests also against the LLVM implementation https://github.com/llvm/llvm-project/pull/68620 which has been for a few hours even committed to LLVM trunk but reverted afterwards. LLVM now has the support committed and I admit I haven't rechecked whether the behavior on the below mentioned spots have been fixed in it already or not yet. The patch uses --embed-dir= option that clang plans to add above and doesn't use other variants on the search directories yet, plus there are no default directories at least for the time being where to search for embed files. So, #embed "..." works if it is found in the same directory (or relative to the current file's directory) and #embed "/..." or #embed </...> work always, but relative #embed <...> doesn't unless at least one --embed-dir= is specified. There is no reason to differentiate between system and non-system directories, so we don't need -isystem like counterpart, perhaps -iquote like counterpart could be useful in the future, dunno what else. It has --embed-directory=dir and --embed-directory dir as aliases. There are some differences beyond clang ICEs, so I'd like to point them out to make sure there is agreement on the choices in the patch. They are also mentioned in the comments of the llvm pull request. The most important is that the GCC patch (as well as the original thephd.dev LLVM branch on godbolt) expands #embed (or acts as if it is expanded) into a mere sequence of numbers like 123,2,35,26 rather then what clang effectively treats as (unsigned char)123,(unsigned char)2,(unsigned char)35,(unsigned char)26 but only does that when using integrated preprocessor, not when using -save-temps where it acts as GCC. JeanHeyd as the original author agrees that is how it is currently worded in C23. Another difference (not tested in the testsuite, not sure how to check for effective target /dev/urandom nor am sure it is desirable to check that during testsuite) is how to treat character devices, named pipes etc. (block devices are errored on). The original paper uses /dev/urandom in various examples and seems to assume that unlike regular files the devices aren't really cached, so #embed </dev/urandom> limit(1) prefix(int a = ) suffix(;) #embed </dev/urandom> limit(1) prefix(int b = ) suffix(;) usually results in a != b. That is what the godbolt thephd.dev branch implements too and what this patch does as well, but clang actually seems to just go from st.st_size == 0, ergo it must be zero-sized resource and so just copies over if_empty if present. It is really questionable what to do about the character devices/named pipes with __has_embed, for regular files the patch doesn't read anything from them, relies on st.st_size + limit for whether it is empty or non-empty. But I don't know of a way to check if read on say a character device would read anything or not (the </dev/null> limit (1) vs. </dev/zero> limit (1) cases), and if we read something, that would be better cached for later because #embed later if it reads again could read no further data even when it first read something. So, the patch currently for __has_embed just always returns 2 on the non-regular files, like the thephd.dev branch does as well and like the clang pull request as well. A question is also what to do for gnu::offset on the non-regular files even for #embed, those aren't seekable and do we want to just read and throw away the offset bytes each time we see it used? clang also chokes on the #if __has_embed (__FILE__ __limit__ (1) __prefix__ () suffix (1 / 0) \ __if_empty__ ((({{[0[0{0{0(0(0)1)1}1}]]}})))) != __STDC_EMBED_FOUND__ #error "__has_embed fail" #endif in embed-1.c, but thephd.dev branch accepts it and I don't see why it shouldn't, (({{[0[0{0{0(0(0)1)1}1}]]}}))) is a balanced token sequence and the file isn't empty, so it should just be parsed and discarded. clang also IMHO mishandles const unsigned char w[] = { #embed __FILE__ prefix([0] = 42, [15] =) limit(32) }; but again only without -save-temps, seems like it treats it as [0] = 42, [15] = (99,111,110,115,116,32,117,110,115,105,103,110,101,100, 32,99,104,97,114,32,119,91,93,32,61,32,123,10,35,101,109,98) rather than [0] = 42, [15] = 99,111,110,115,116,32,117,110,115,105,103,110,101,100, 32,99,104,97,114,32,119,91,93,32,61,32,123,10,35,101,109,98 and warns on it for -Wunused-value and just compiles it as [0] = 42, [15] = 98 And also void foo (int, int, int, int); void bar (void) { foo ( #embed __FILE__ limit (4) prefix (172 + ) suffix (+ 2) ); } is treated as 172 + (118, 111, 105, 100) + 2 rather than 172 + 118, 111, 105, 100 + 2 which clang -save-temps or GCC treats it like, so results in just one argument passed rather than 4. if (!strstr ((const char *) magna_carta, "imprisonétur")) abort (); in the testcase fails as well, but in that case calling it in gdb succeeds: p ((char *(*)(char *, char *))__strstr_sse2) (magna_carta, "imprisonétur") $2 = 0x555555558d3c <magna_carta+11564> "imprisonétur aut disseisiátur"... so I guess they are just trying to constant evaluate strstr and do it incorrectly. They started with making the optimizations together in the initial patch set, so they don't have the luxury to compare if it is just because of the optimization they are trying to do or because that is how the feature works for them. At least unless they use -save-temps for now. There is also different behavior between clang and gcc on -M or other dependency generating options. Seems clang includes the __has_embed searched files in dependencies, while my patch doesn't. But so does clang for __has_include and GCC doesn't. Emitting a hard dependency on some header just because there was __has_include/__has_embed for it seems wrong to me, because (at least when properly written) the source likely doesn't mind if the file is missing, it will do something else, so a hard error from make because of it doesn't seem right. Does make have some weaker dependencies, such that if some file can be remade it is but if it doesn't exist, it isn't fatal? I wonder whether #embed <non-existent-file> really needs to be fatal or whether we could simply after diagnosing it pretend the file exists and is empty. For #include I think fatal errors make tons of sense, but perhaps for #embed which is more localized we'd get better error reporting if we didn't bail out immediately. Note, both GCC and clang currently treat those as fatal errors. clang also added -dE option which with -E instead of preprocessing the #embed directives keeps them as is, but the preprocessed source then isn't self-contained. That option looks more harmful than useful to me. Also, it isn't clear to me from C23 whether it is possible to have __has_include/__has_c_attribute/__has_embed expressions inside of the limit #embed/__has_embed argument. 6.10.3.2/2 says that defined should not appear there (and the patch diagnoses it and testsuite tests), but for __has_include/__has_embed etc. 6.10.1/11 says: "The identifiers __has_include, __has_embed, and __has_c_attribute shall not appear in any context not mentioned in this subclause." If that subclause in that case means 6.10.1, then it presumably shouldn't appear in #embed in 6.10.3, but __has_embed is in 6.10.1... But 6.10.3.2/3 says that it should be parsed according to the 6.10.1 rules. Haven't included tests like #if __has_embed (__FILE__ limit (__has_embed (__FILE__ limit (1)))) or #embed __FILE__ limit (__has_include (__FILE__)) into the testsuite because of the doubts but I think the patch should handle those right now. The reason I've used Magna Carta text in some of the testcases is that I hope it shouldn't be copyrighted after the centuries and I'd strongly prefer not to have binary blobs in git after the xz backdoor lesson and wanted something larger which doesn't change all the time. Oh, BTW, I see in C23 draft 6.10.3.2 in Example 4 if (f_source == NULL); return 1; (note the spurious semicolon after closing paren), has that been fixed already? Like the thephd.dev and clang implementations, the patch always macro expands the whole #embed and __has_embed directives except for the embed keyword. That is most likely not what C23 says, my limited understanding right now is that in #embed one needs to parse the whole directive line with macro expansion disabled and check if it satisfies the grammar, if not, the whole directive is macro expanded, if yes, only the limit parameter argument is macro expanded and the prefix/suffix/if_empty arguments are maybe macro expanded when actually used (and not at all if unused). And I think __has_embed macro expansion has conflicting rules. 2024-09-12 Jakub Jelinek <jakub@redhat.com> PR c/105863 libcpp/ * include/cpplib.h: Implement C23 N3017 #embed - a scannable, tooling-friendly binary resource inclusion mechanism paper. (struct cpp_options): Add embed member. (enum cpp_builtin_type): Add BT_HAS_EMBED. (cpp_set_include_chains): Add another cpp_dir * argument to the declaration. * internal.h (enum include_type): Add IT_EMBED. (struct cpp_reader): Add embed_include member. (struct cpp_embed_params_tokens): New type. (struct cpp_embed_params): New type. (_cpp_get_token_no_padding): Declare. (enum _cpp_find_file_kind): Add _cpp_FFK_EMBED and _cpp_FFK_HAS_EMBED. (_cpp_stack_embed): Declare. (_cpp_parse_expr): Change return type to cpp_num_part instead of bool, change second argument from bool to const char * and add third argument. (_cpp_parse_embed_params): Declare. * directives.cc (DIRECTIVE_TABLE): Add embed entry. (end_directive): Don't call skip_rest_of_line for T_EMBED directive. (_cpp_handle_directive): Return 2 rather than 1 for T_EMBED in directives-only mode. (parse_include): Don't Call check_eol for T_EMBED directive. (skip_balanced_token_seq): New function. (EMBED_PARAMS): Define. (enum embed_param_kind): New type. (embed_params): New variable. (_cpp_parse_embed_params): New function. (do_embed): New function. (do_if): Adjust _cpp_parse_expr caller. (do_elif): Likewise. * expr.cc (parse_defined): Diagnose defined in #embed or __has_embed parameters. (_cpp_parse_expr): Change return type to cpp_num_part instead of bool, change second argument from bool to const char * and add third argument. Adjust function comment. For #embed/__has_embed parameters add an artificial CPP_OPEN_PAREN. Use the second argument DIR directly instead of string literals conditional on IS_IF. For #embed/__has_embed parameter, stop on reaching CPP_CLOSE_PAREN matching the artificial one. Diagnose negative or too large embed parameter operands. (num_binary_op): Use #embed instead of #if for diagnostics if inside #embed/__has_embed parameter. (num_div_op): Likewise. * files.cc (struct _cpp_file): Add limit member and embed bitfield. (search_cache): Add IS_EMBED argument, formatting fix. Skip over files with different file->embed from the argument. (find_file_in_dir): Don't call pch_open_file if file->embed. (_cpp_find_file): Handle _cpp_FFK_EMBED and _cpp_FFK_HAS_EMBED. (read_file_guts): Formatting fix. (has_unique_contents): Ignore file->embed files. (search_path_head): Handle IT_EMBED type. (_cpp_stack_embed): New function. (_cpp_get_file_stat): Formatting fix. (cpp_set_include_chains): Add embed argument, save it to pfile->embed_include and compute lens for the chain. * init.cc (struct lang_flags): Add embed member. (lang_defaults): Add embed initializers. (cpp_set_lang): Initialize CPP_OPTION (pfile, embed). (builtin_array): Add __has_embed entry. (cpp_init_builtins): Predefine __STDC_EMBED_NOT_FOUND__, __STDC_EMBED_FOUND__ and __STDC_EMBED_EMPTY__. * lex.cc (cpp_directive_only_process): Handle #embed. * macro.cc (cpp_get_token_no_padding): Rename to ... (_cpp_get_token_no_padding): ... this. No longer static. (builtin_has_include_1): New function. (builtin_has_include): Use it. Use _cpp_get_token_no_padding instead of cpp_get_token_no_padding. (builtin_has_embed): New function. (_cpp_builtin_macro_text): Handle BT_HAS_EMBED. gcc/ * doc/cppdiropts.texi (--embed-dir=): Document. * doc/cpp.texi (Binary Resource Inclusion): New chapter. (__has_embed): Document. * doc/invoke.texi (Directory Options): Mention --embed-dir=. * gcc.cc (cpp_unique_options): Add %{-embed*}. * genmatch.cc (main): Adjust cpp_set_include_chains caller. * incpath.h (enum incpath_kind): Add INC_EMBED. * incpath.cc (merge_include_chains): Handle INC_EMBED. (register_include_chains): Adjust cpp_set_include_chains caller. gcc/c-family/ * c.opt (-embed-dir=): New option. (-embed-directory): New alias. (-embed-directory=): New alias. * c-opts.cc (c_common_handle_option): Handle OPT__embed_dir_. gcc/testsuite/ * c-c++-common/cpp/embed-1.c: New test. * c-c++-common/cpp/embed-2.c: New test. * c-c++-common/cpp/embed-3.c: New test. * c-c++-common/cpp/embed-4.c: New test. * c-c++-common/cpp/embed-5.c: New test. * c-c++-common/cpp/embed-6.c: New test. * c-c++-common/cpp/embed-7.c: New test. * c-c++-common/cpp/embed-8.c: New test. * c-c++-common/cpp/embed-9.c: New test. * c-c++-common/cpp/embed-10.c: New test. * c-c++-common/cpp/embed-11.c: New test. * c-c++-common/cpp/embed-12.c: New test. * c-c++-common/cpp/embed-13.c: New test. * c-c++-common/cpp/embed-14.c: New test. * c-c++-common/cpp/embed-25.c: New test. * c-c++-common/cpp/embed-26.c: New test. * c-c++-common/cpp/embed-dir/embed-1.inc: New test. * c-c++-common/cpp/embed-dir/embed-3.c: New test. * c-c++-common/cpp/embed-dir/embed-4.c: New test. * c-c++-common/cpp/embed-dir/magna-carta.txt: New test. * gcc.dg/cpp/embed-1.c: New test. * gcc.dg/cpp/embed-2.c: New test. * gcc.dg/cpp/embed-3.c: New test. * gcc.dg/cpp/embed-4.c: New test. * g++.dg/cpp/embed-1.C: New test. * g++.dg/cpp/embed-2.C: New test. * g++.dg/cpp/embed-3.C: New test.
2024-09-12 17:15:38 +08:00
if (pfile->state.in_directive == 3)
{
++top;
top->op = CPP_OPEN_PAREN;
top->token = open_paren;
top->loc = open_paren->src_loc;
}
1995-03-17 05:59:07 +08:00
for (;;)
{
struct op op;
1995-03-17 05:59:07 +08: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 18:51:15 +08: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 18:51:15 +08:00
op.loc = virtual_location;
1995-03-17 05:59:07 +08: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 21:58:08 +08: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 20:58:48 +08: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 18:51:15 +08:00
SYNTAX_ERROR2_AT (op.loc,
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics When working on #embed support, or -Wheader-guard or other recent libcpp changes, I've been annoyed by the libcpp diagnostics being visually different from normal gcc diagnostics, especially in the area of quoting stuff in the diagnostic messages. Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use %</%>, %qs etc. in there, while libcpp diagnostics was marked as printf and in libcpp we've been very creative with quoting stuff, either no quotes at all, or "something" quoting, or 'something' quoting, or `something' quoting (but in none of the cases it used colors consistently with the rest of the compiler). Now, libcpp diagnostics is always emitted using a callback, pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with genmatch.cc: cb->diagnostic = diagnostic_cb; c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic; fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic; where the latter two just use diagnostic_report_diagnostic, so actually support all the gcc_diag stuff, only the genmatch.cc case didn't. So, the following patch changes genmatch.cc to use pp_format* instead of vfprintf so that it supports the gcc_diag formatting (pretty-print.o unfortunately has various dependencies, so had to link genmatch with libcommon.a libbacktrace.a and tweak Makefile.in so that there are no circular dependencies) and marks the libcpp diagnostic routines as gcc_diag rather than printf. That change resulted in hundreds of -Wformat-diag new warnings (most of them useful and resulting IMHO in better diagnostics), so the rest of the patch is changing the format strings to make -Wformat-diag happy and adjusting the testsuite for the differences in how is the diagnostic reformatted. Dunno if some out of GCC tree projects use libcpp, that case would make it harder because one couldn't use vfprintf in the diagnostic callback anymore, but there is always David's libdiagnostic which could be used for that purpose IMHO. 2024-10-12 Jakub Jelinek <jakub@redhat.com> libcpp/ * include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define. (struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF on diagnostic callback. (cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3. (cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. (cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6) instead of ATTRIBUTE_PRINTF_5. (cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. * Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather than --language=c. * errors.cc (cpp_diagnostic_at, cpp_diagnostic, cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of -ATTRIBUTE_FPTR_PRINTF. * charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex, convert_oct, convert_escape): Fix up -Wformat-diag warnings. (cpp_interpret_string_ranges, count_source_chars): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF. (narrow_str_to_charconst): Fix up -Wformat-diag warnings. * directives.cc (check_eol_1, directive_diagnostics, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, do_include_next, _cpp_parse_embed_params, do_embed, read_flag, do_line, do_linemarker, register_pragma_1, do_pragma_once, do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison, do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, do_assert, cpp_define_unused): Likewise. * expr.cc (cpp_classify_number, parse_defined, eval_token, _cpp_parse_expr, reduce, check_promotion): Likewise. * files.cc (_cpp_find_file, finish_base64_embed, _cpp_pop_file_buffer): Likewise. * init.cc (sanity_checks): Likewise. * lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char, _cpp_warn_invalid_utf8, _cpp_skip_block_comment, warn_about_normalization, forms_identifier_p, maybe_va_opt_error, identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise. * macro.cc (class vaopt_state, builtin_has_include_1, builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro, _cpp_builtin_macro_text, builtin_macro, stringify_arg, _cpp_arguments_ok, collect_args, enter_macro_context, _cpp_save_parameter, parse_params, create_iso_definition, _cpp_create_definition, check_trad_stringification): Likewise. * pch.cc (cpp_valid_state): Likewise. * traditional.cc (_cpp_scan_out_logical_line, recursive_macro): Likewise. gcc/ * Makefile.in (generated_files): Remove {gimple,generic}-match*. (generated_match_files): New variable. Add a dependency of $(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those. (build/genmatch$(build_exeext)): Depend on and link against libcommon.a and $(LIBBACKTRACE). * genmatch.cc: Include pretty-print.h and input.h. (ggc_internal_cleared_alloc, ggc_free): Remove. (fatal): New function. (line_table): Remove. (linemap_client_expand_location_to_spelling_point): Remove. (diagnostic_cb): Use gcc_diag rather than printf format. Use pp_format_verbatim on a temporary pretty_printer instead of vfprintf. (fatal_at, warning_at): Use gcc_diag rather than printf format. (output_line_directive): Rename location_hash to loc_hash. (parser::eat_ident, parser::parse_operation, parser::parse_expr, parser::parse_pattern, parser::finish_match_operand): Fix up -Wformat-diag warnings. gcc/c-family/ * c-lex.cc (c_common_has_attribute, c_common_lex_availability_macro): Fix up -Wformat-diag warnings. gcc/testsuite/ * c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for libcpp diagnostic formatting changes. * c-c++-common/cpp/embed-3.c: Likewise. * c-c++-common/cpp/embed-4.c: Likewise. * c-c++-common/cpp/embed-16.c: Likewise. * c-c++-common/cpp/embed-18.c: Likewise. * c-c++-common/cpp/eof-2.c: Likewise. * c-c++-common/cpp/eof-3.c: Likewise. * c-c++-common/cpp/fmax-include-depth.c: Likewise. * c-c++-common/cpp/has-builtin.c: Likewise. * c-c++-common/cpp/line-2.c: Likewise. * c-c++-common/cpp/line-3.c: Likewise. * c-c++-common/cpp/macro-arg-count-1.c: Likewise. * c-c++-common/cpp/macro-arg-count-2.c: Likewise. * c-c++-common/cpp/macro-ranges.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-4.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-5.c: Likewise. * c-c++-common/cpp/pr88974.c: Likewise. * c-c++-common/cpp/va-opt-error.c: Likewise. * c-c++-common/cpp/va-opt-pedantic.c: Likewise. * c-c++-common/cpp/Wheader-guard-2.c: Likewise. * c-c++-common/cpp/Wheader-guard-3.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-1.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-2.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-3.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c: Likewise. * c-c++-common/pr68833-3.c: Likewise. * c-c++-common/raw-string-directive-1.c: Likewise. * gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise. * gcc.dg/binary-constants-4.c: Likewise. * gcc.dg/builtin-redefine.c: Likewise. * gcc.dg/cpp/19951025-1.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c23-elifdef-2.c: Likewise. * gcc.dg/cpp/c23-warning-2.c: Likewise. * gcc.dg/cpp/embed-2.c: Likewise. * gcc.dg/cpp/embed-3.c: Likewise. * gcc.dg/cpp/embed-4.c: Likewise. * gcc.dg/cpp/expr.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu23-warning-2.c: Likewise. * gcc.dg/cpp/include6.c: Likewise. * gcc.dg/cpp/pr35322.c: Likewise. * gcc.dg/cpp/tr-warn6.c: Likewise. * gcc.dg/cpp/undef2.c: Likewise. * gcc.dg/cpp/warn-comments.c: Likewise. * gcc.dg/cpp/warn-comments-2.c: Likewise. * gcc.dg/cpp/warn-comments-3.c: Likewise. * gcc.dg/cpp/warn-cxx-compat.c: Likewise. * gcc.dg/cpp/warn-cxx-compat-2.c: Likewise. * gcc.dg/cpp/warn-deprecated.c: Likewise. * gcc.dg/cpp/warn-deprecated-2.c: Likewise. * gcc.dg/cpp/warn-long-long.c: Likewise. * gcc.dg/cpp/warn-long-long-2.c: Likewise. * gcc.dg/cpp/warn-normalized-1.c: Likewise. * gcc.dg/cpp/warn-normalized-2.c: Likewise. * gcc.dg/cpp/warn-normalized-3.c: Likewise. * gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise. * gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise. * gcc.dg/cpp/warn-redefined.c: Likewise. * gcc.dg/cpp/warn-redefined-2.c: Likewise. * gcc.dg/cpp/warn-traditional.c: Likewise. * gcc.dg/cpp/warn-traditional-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-1.c: Likewise. * gcc.dg/cpp/warn-trigraphs-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-3.c: Likewise. * gcc.dg/cpp/warn-trigraphs-4.c: Likewise. * gcc.dg/cpp/warn-undef.c: Likewise. * gcc.dg/cpp/warn-undef-2.c: Likewise. * gcc.dg/cpp/warn-unused-macros.c: Likewise. * gcc.dg/cpp/warn-unused-macros-2.c: Likewise. * gcc.dg/pch/counter-2.c: Likewise. * g++.dg/cpp0x/udlit-error1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-1.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-3.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-4.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-5.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-6.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-7.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-8.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-9.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-10.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-11.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-12.C: Likewise. * g++.dg/cpp/elifdef-3.C: Likewise. * g++.dg/cpp/elifdef-5.C: Likewise. * g++.dg/cpp/elifdef-6.C: Likewise. * g++.dg/cpp/elifdef-7.C: Likewise. * g++.dg/cpp/embed-1.C: Likewise. * g++.dg/cpp/embed-2.C: Likewise. * g++.dg/cpp/pedantic-errors.C: Likewise. * g++.dg/cpp/warning-1.C: Likewise. * g++.dg/cpp/warning-2.C: Likewise. * g++.dg/ext/bitint1.C: Likewise. * g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
"missing binary operator before token %qs",
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 18:51:15 +08:00
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 18:51:15 +08: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;
case CPP_PADDING:
lex_count--;
continue;
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 18:51:15 +08:00
SYNTAX_ERROR2_AT (op.loc,
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics When working on #embed support, or -Wheader-guard or other recent libcpp changes, I've been annoyed by the libcpp diagnostics being visually different from normal gcc diagnostics, especially in the area of quoting stuff in the diagnostic messages. Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use %</%>, %qs etc. in there, while libcpp diagnostics was marked as printf and in libcpp we've been very creative with quoting stuff, either no quotes at all, or "something" quoting, or 'something' quoting, or `something' quoting (but in none of the cases it used colors consistently with the rest of the compiler). Now, libcpp diagnostics is always emitted using a callback, pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with genmatch.cc: cb->diagnostic = diagnostic_cb; c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic; fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic; where the latter two just use diagnostic_report_diagnostic, so actually support all the gcc_diag stuff, only the genmatch.cc case didn't. So, the following patch changes genmatch.cc to use pp_format* instead of vfprintf so that it supports the gcc_diag formatting (pretty-print.o unfortunately has various dependencies, so had to link genmatch with libcommon.a libbacktrace.a and tweak Makefile.in so that there are no circular dependencies) and marks the libcpp diagnostic routines as gcc_diag rather than printf. That change resulted in hundreds of -Wformat-diag new warnings (most of them useful and resulting IMHO in better diagnostics), so the rest of the patch is changing the format strings to make -Wformat-diag happy and adjusting the testsuite for the differences in how is the diagnostic reformatted. Dunno if some out of GCC tree projects use libcpp, that case would make it harder because one couldn't use vfprintf in the diagnostic callback anymore, but there is always David's libdiagnostic which could be used for that purpose IMHO. 2024-10-12 Jakub Jelinek <jakub@redhat.com> libcpp/ * include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define. (struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF on diagnostic callback. (cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3. (cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. (cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6) instead of ATTRIBUTE_PRINTF_5. (cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. * Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather than --language=c. * errors.cc (cpp_diagnostic_at, cpp_diagnostic, cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of -ATTRIBUTE_FPTR_PRINTF. * charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex, convert_oct, convert_escape): Fix up -Wformat-diag warnings. (cpp_interpret_string_ranges, count_source_chars): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF. (narrow_str_to_charconst): Fix up -Wformat-diag warnings. * directives.cc (check_eol_1, directive_diagnostics, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, do_include_next, _cpp_parse_embed_params, do_embed, read_flag, do_line, do_linemarker, register_pragma_1, do_pragma_once, do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison, do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, do_assert, cpp_define_unused): Likewise. * expr.cc (cpp_classify_number, parse_defined, eval_token, _cpp_parse_expr, reduce, check_promotion): Likewise. * files.cc (_cpp_find_file, finish_base64_embed, _cpp_pop_file_buffer): Likewise. * init.cc (sanity_checks): Likewise. * lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char, _cpp_warn_invalid_utf8, _cpp_skip_block_comment, warn_about_normalization, forms_identifier_p, maybe_va_opt_error, identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise. * macro.cc (class vaopt_state, builtin_has_include_1, builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro, _cpp_builtin_macro_text, builtin_macro, stringify_arg, _cpp_arguments_ok, collect_args, enter_macro_context, _cpp_save_parameter, parse_params, create_iso_definition, _cpp_create_definition, check_trad_stringification): Likewise. * pch.cc (cpp_valid_state): Likewise. * traditional.cc (_cpp_scan_out_logical_line, recursive_macro): Likewise. gcc/ * Makefile.in (generated_files): Remove {gimple,generic}-match*. (generated_match_files): New variable. Add a dependency of $(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those. (build/genmatch$(build_exeext)): Depend on and link against libcommon.a and $(LIBBACKTRACE). * genmatch.cc: Include pretty-print.h and input.h. (ggc_internal_cleared_alloc, ggc_free): Remove. (fatal): New function. (line_table): Remove. (linemap_client_expand_location_to_spelling_point): Remove. (diagnostic_cb): Use gcc_diag rather than printf format. Use pp_format_verbatim on a temporary pretty_printer instead of vfprintf. (fatal_at, warning_at): Use gcc_diag rather than printf format. (output_line_directive): Rename location_hash to loc_hash. (parser::eat_ident, parser::parse_operation, parser::parse_expr, parser::parse_pattern, parser::finish_match_operand): Fix up -Wformat-diag warnings. gcc/c-family/ * c-lex.cc (c_common_has_attribute, c_common_lex_availability_macro): Fix up -Wformat-diag warnings. gcc/testsuite/ * c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for libcpp diagnostic formatting changes. * c-c++-common/cpp/embed-3.c: Likewise. * c-c++-common/cpp/embed-4.c: Likewise. * c-c++-common/cpp/embed-16.c: Likewise. * c-c++-common/cpp/embed-18.c: Likewise. * c-c++-common/cpp/eof-2.c: Likewise. * c-c++-common/cpp/eof-3.c: Likewise. * c-c++-common/cpp/fmax-include-depth.c: Likewise. * c-c++-common/cpp/has-builtin.c: Likewise. * c-c++-common/cpp/line-2.c: Likewise. * c-c++-common/cpp/line-3.c: Likewise. * c-c++-common/cpp/macro-arg-count-1.c: Likewise. * c-c++-common/cpp/macro-arg-count-2.c: Likewise. * c-c++-common/cpp/macro-ranges.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-4.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-5.c: Likewise. * c-c++-common/cpp/pr88974.c: Likewise. * c-c++-common/cpp/va-opt-error.c: Likewise. * c-c++-common/cpp/va-opt-pedantic.c: Likewise. * c-c++-common/cpp/Wheader-guard-2.c: Likewise. * c-c++-common/cpp/Wheader-guard-3.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-1.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-2.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-3.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c: Likewise. * c-c++-common/pr68833-3.c: Likewise. * c-c++-common/raw-string-directive-1.c: Likewise. * gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise. * gcc.dg/binary-constants-4.c: Likewise. * gcc.dg/builtin-redefine.c: Likewise. * gcc.dg/cpp/19951025-1.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c23-elifdef-2.c: Likewise. * gcc.dg/cpp/c23-warning-2.c: Likewise. * gcc.dg/cpp/embed-2.c: Likewise. * gcc.dg/cpp/embed-3.c: Likewise. * gcc.dg/cpp/embed-4.c: Likewise. * gcc.dg/cpp/expr.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu23-warning-2.c: Likewise. * gcc.dg/cpp/include6.c: Likewise. * gcc.dg/cpp/pr35322.c: Likewise. * gcc.dg/cpp/tr-warn6.c: Likewise. * gcc.dg/cpp/undef2.c: Likewise. * gcc.dg/cpp/warn-comments.c: Likewise. * gcc.dg/cpp/warn-comments-2.c: Likewise. * gcc.dg/cpp/warn-comments-3.c: Likewise. * gcc.dg/cpp/warn-cxx-compat.c: Likewise. * gcc.dg/cpp/warn-cxx-compat-2.c: Likewise. * gcc.dg/cpp/warn-deprecated.c: Likewise. * gcc.dg/cpp/warn-deprecated-2.c: Likewise. * gcc.dg/cpp/warn-long-long.c: Likewise. * gcc.dg/cpp/warn-long-long-2.c: Likewise. * gcc.dg/cpp/warn-normalized-1.c: Likewise. * gcc.dg/cpp/warn-normalized-2.c: Likewise. * gcc.dg/cpp/warn-normalized-3.c: Likewise. * gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise. * gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise. * gcc.dg/cpp/warn-redefined.c: Likewise. * gcc.dg/cpp/warn-redefined-2.c: Likewise. * gcc.dg/cpp/warn-traditional.c: Likewise. * gcc.dg/cpp/warn-traditional-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-1.c: Likewise. * gcc.dg/cpp/warn-trigraphs-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-3.c: Likewise. * gcc.dg/cpp/warn-trigraphs-4.c: Likewise. * gcc.dg/cpp/warn-undef.c: Likewise. * gcc.dg/cpp/warn-undef-2.c: Likewise. * gcc.dg/cpp/warn-unused-macros.c: Likewise. * gcc.dg/cpp/warn-unused-macros-2.c: Likewise. * gcc.dg/pch/counter-2.c: Likewise. * g++.dg/cpp0x/udlit-error1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-1.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-3.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-4.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-5.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-6.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-7.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-8.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-9.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-10.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-11.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-12.C: Likewise. * g++.dg/cpp/elifdef-3.C: Likewise. * g++.dg/cpp/elifdef-5.C: Likewise. * g++.dg/cpp/elifdef-6.C: Likewise. * g++.dg/cpp/elifdef-7.C: Likewise. * g++.dg/cpp/embed-1.C: Likewise. * g++.dg/cpp/embed-2.C: Likewise. * g++.dg/cpp/pedantic-errors.C: Likewise. * g++.dg/cpp/warning-1.C: Likewise. * g++.dg/cpp/warning-2.C: Likewise. * g++.dg/ext/bitint1.C: Likewise. * g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
"token %qs is not valid in preprocessor "
"expressions",
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 18:51:15 +08:00
cpp_token_as_text (pfile, op.token));
break;
1995-03-17 05:59:07 +08:00
}
/* Check we have a value or operator as appropriate. */
if (optab[op.op].flags & NO_L_OPERAND)
1995-03-17 05:59:07 +08: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 18:51:15 +08:00
SYNTAX_ERROR2_AT (op.loc,
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics When working on #embed support, or -Wheader-guard or other recent libcpp changes, I've been annoyed by the libcpp diagnostics being visually different from normal gcc diagnostics, especially in the area of quoting stuff in the diagnostic messages. Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use %</%>, %qs etc. in there, while libcpp diagnostics was marked as printf and in libcpp we've been very creative with quoting stuff, either no quotes at all, or "something" quoting, or 'something' quoting, or `something' quoting (but in none of the cases it used colors consistently with the rest of the compiler). Now, libcpp diagnostics is always emitted using a callback, pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with genmatch.cc: cb->diagnostic = diagnostic_cb; c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic; fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic; where the latter two just use diagnostic_report_diagnostic, so actually support all the gcc_diag stuff, only the genmatch.cc case didn't. So, the following patch changes genmatch.cc to use pp_format* instead of vfprintf so that it supports the gcc_diag formatting (pretty-print.o unfortunately has various dependencies, so had to link genmatch with libcommon.a libbacktrace.a and tweak Makefile.in so that there are no circular dependencies) and marks the libcpp diagnostic routines as gcc_diag rather than printf. That change resulted in hundreds of -Wformat-diag new warnings (most of them useful and resulting IMHO in better diagnostics), so the rest of the patch is changing the format strings to make -Wformat-diag happy and adjusting the testsuite for the differences in how is the diagnostic reformatted. Dunno if some out of GCC tree projects use libcpp, that case would make it harder because one couldn't use vfprintf in the diagnostic callback anymore, but there is always David's libdiagnostic which could be used for that purpose IMHO. 2024-10-12 Jakub Jelinek <jakub@redhat.com> libcpp/ * include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define. (struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF on diagnostic callback. (cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3. (cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. (cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6) instead of ATTRIBUTE_PRINTF_5. (cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. * Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather than --language=c. * errors.cc (cpp_diagnostic_at, cpp_diagnostic, cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of -ATTRIBUTE_FPTR_PRINTF. * charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex, convert_oct, convert_escape): Fix up -Wformat-diag warnings. (cpp_interpret_string_ranges, count_source_chars): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF. (narrow_str_to_charconst): Fix up -Wformat-diag warnings. * directives.cc (check_eol_1, directive_diagnostics, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, do_include_next, _cpp_parse_embed_params, do_embed, read_flag, do_line, do_linemarker, register_pragma_1, do_pragma_once, do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison, do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, do_assert, cpp_define_unused): Likewise. * expr.cc (cpp_classify_number, parse_defined, eval_token, _cpp_parse_expr, reduce, check_promotion): Likewise. * files.cc (_cpp_find_file, finish_base64_embed, _cpp_pop_file_buffer): Likewise. * init.cc (sanity_checks): Likewise. * lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char, _cpp_warn_invalid_utf8, _cpp_skip_block_comment, warn_about_normalization, forms_identifier_p, maybe_va_opt_error, identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise. * macro.cc (class vaopt_state, builtin_has_include_1, builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro, _cpp_builtin_macro_text, builtin_macro, stringify_arg, _cpp_arguments_ok, collect_args, enter_macro_context, _cpp_save_parameter, parse_params, create_iso_definition, _cpp_create_definition, check_trad_stringification): Likewise. * pch.cc (cpp_valid_state): Likewise. * traditional.cc (_cpp_scan_out_logical_line, recursive_macro): Likewise. gcc/ * Makefile.in (generated_files): Remove {gimple,generic}-match*. (generated_match_files): New variable. Add a dependency of $(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those. (build/genmatch$(build_exeext)): Depend on and link against libcommon.a and $(LIBBACKTRACE). * genmatch.cc: Include pretty-print.h and input.h. (ggc_internal_cleared_alloc, ggc_free): Remove. (fatal): New function. (line_table): Remove. (linemap_client_expand_location_to_spelling_point): Remove. (diagnostic_cb): Use gcc_diag rather than printf format. Use pp_format_verbatim on a temporary pretty_printer instead of vfprintf. (fatal_at, warning_at): Use gcc_diag rather than printf format. (output_line_directive): Rename location_hash to loc_hash. (parser::eat_ident, parser::parse_operation, parser::parse_expr, parser::parse_pattern, parser::finish_match_operand): Fix up -Wformat-diag warnings. gcc/c-family/ * c-lex.cc (c_common_has_attribute, c_common_lex_availability_macro): Fix up -Wformat-diag warnings. gcc/testsuite/ * c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for libcpp diagnostic formatting changes. * c-c++-common/cpp/embed-3.c: Likewise. * c-c++-common/cpp/embed-4.c: Likewise. * c-c++-common/cpp/embed-16.c: Likewise. * c-c++-common/cpp/embed-18.c: Likewise. * c-c++-common/cpp/eof-2.c: Likewise. * c-c++-common/cpp/eof-3.c: Likewise. * c-c++-common/cpp/fmax-include-depth.c: Likewise. * c-c++-common/cpp/has-builtin.c: Likewise. * c-c++-common/cpp/line-2.c: Likewise. * c-c++-common/cpp/line-3.c: Likewise. * c-c++-common/cpp/macro-arg-count-1.c: Likewise. * c-c++-common/cpp/macro-arg-count-2.c: Likewise. * c-c++-common/cpp/macro-ranges.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-4.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-5.c: Likewise. * c-c++-common/cpp/pr88974.c: Likewise. * c-c++-common/cpp/va-opt-error.c: Likewise. * c-c++-common/cpp/va-opt-pedantic.c: Likewise. * c-c++-common/cpp/Wheader-guard-2.c: Likewise. * c-c++-common/cpp/Wheader-guard-3.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-1.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-2.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-3.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c: Likewise. * c-c++-common/pr68833-3.c: Likewise. * c-c++-common/raw-string-directive-1.c: Likewise. * gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise. * gcc.dg/binary-constants-4.c: Likewise. * gcc.dg/builtin-redefine.c: Likewise. * gcc.dg/cpp/19951025-1.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c23-elifdef-2.c: Likewise. * gcc.dg/cpp/c23-warning-2.c: Likewise. * gcc.dg/cpp/embed-2.c: Likewise. * gcc.dg/cpp/embed-3.c: Likewise. * gcc.dg/cpp/embed-4.c: Likewise. * gcc.dg/cpp/expr.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu23-warning-2.c: Likewise. * gcc.dg/cpp/include6.c: Likewise. * gcc.dg/cpp/pr35322.c: Likewise. * gcc.dg/cpp/tr-warn6.c: Likewise. * gcc.dg/cpp/undef2.c: Likewise. * gcc.dg/cpp/warn-comments.c: Likewise. * gcc.dg/cpp/warn-comments-2.c: Likewise. * gcc.dg/cpp/warn-comments-3.c: Likewise. * gcc.dg/cpp/warn-cxx-compat.c: Likewise. * gcc.dg/cpp/warn-cxx-compat-2.c: Likewise. * gcc.dg/cpp/warn-deprecated.c: Likewise. * gcc.dg/cpp/warn-deprecated-2.c: Likewise. * gcc.dg/cpp/warn-long-long.c: Likewise. * gcc.dg/cpp/warn-long-long-2.c: Likewise. * gcc.dg/cpp/warn-normalized-1.c: Likewise. * gcc.dg/cpp/warn-normalized-2.c: Likewise. * gcc.dg/cpp/warn-normalized-3.c: Likewise. * gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise. * gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise. * gcc.dg/cpp/warn-redefined.c: Likewise. * gcc.dg/cpp/warn-redefined-2.c: Likewise. * gcc.dg/cpp/warn-traditional.c: Likewise. * gcc.dg/cpp/warn-traditional-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-1.c: Likewise. * gcc.dg/cpp/warn-trigraphs-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-3.c: Likewise. * gcc.dg/cpp/warn-trigraphs-4.c: Likewise. * gcc.dg/cpp/warn-undef.c: Likewise. * gcc.dg/cpp/warn-undef-2.c: Likewise. * gcc.dg/cpp/warn-unused-macros.c: Likewise. * gcc.dg/cpp/warn-unused-macros-2.c: Likewise. * gcc.dg/pch/counter-2.c: Likewise. * g++.dg/cpp0x/udlit-error1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-1.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-3.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-4.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-5.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-6.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-7.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-8.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-9.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-10.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-11.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-12.C: Likewise. * g++.dg/cpp/elifdef-3.C: Likewise. * g++.dg/cpp/elifdef-5.C: Likewise. * g++.dg/cpp/elifdef-6.C: Likewise. * g++.dg/cpp/elifdef-7.C: Likewise. * g++.dg/cpp/embed-1.C: Likewise. * g++.dg/cpp/embed-2.C: Likewise. * g++.dg/cpp/pedantic-errors.C: Likewise. * g++.dg/cpp/warning-1.C: Likewise. * g++.dg/cpp/warning-2.C: Likewise. * g++.dg/ext/bitint1.C: Likewise. * g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
"missing binary operator before token %qs",
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 18:51:15 +08:00
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 18:51:15 +08:00
SYNTAX_ERROR_AT (op.loc,
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics When working on #embed support, or -Wheader-guard or other recent libcpp changes, I've been annoyed by the libcpp diagnostics being visually different from normal gcc diagnostics, especially in the area of quoting stuff in the diagnostic messages. Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use %</%>, %qs etc. in there, while libcpp diagnostics was marked as printf and in libcpp we've been very creative with quoting stuff, either no quotes at all, or "something" quoting, or 'something' quoting, or `something' quoting (but in none of the cases it used colors consistently with the rest of the compiler). Now, libcpp diagnostics is always emitted using a callback, pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with genmatch.cc: cb->diagnostic = diagnostic_cb; c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic; fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic; where the latter two just use diagnostic_report_diagnostic, so actually support all the gcc_diag stuff, only the genmatch.cc case didn't. So, the following patch changes genmatch.cc to use pp_format* instead of vfprintf so that it supports the gcc_diag formatting (pretty-print.o unfortunately has various dependencies, so had to link genmatch with libcommon.a libbacktrace.a and tweak Makefile.in so that there are no circular dependencies) and marks the libcpp diagnostic routines as gcc_diag rather than printf. That change resulted in hundreds of -Wformat-diag new warnings (most of them useful and resulting IMHO in better diagnostics), so the rest of the patch is changing the format strings to make -Wformat-diag happy and adjusting the testsuite for the differences in how is the diagnostic reformatted. Dunno if some out of GCC tree projects use libcpp, that case would make it harder because one couldn't use vfprintf in the diagnostic callback anymore, but there is always David's libdiagnostic which could be used for that purpose IMHO. 2024-10-12 Jakub Jelinek <jakub@redhat.com> libcpp/ * include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define. (struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF on diagnostic callback. (cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3. (cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. (cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6) instead of ATTRIBUTE_PRINTF_5. (cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. * Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather than --language=c. * errors.cc (cpp_diagnostic_at, cpp_diagnostic, cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of -ATTRIBUTE_FPTR_PRINTF. * charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex, convert_oct, convert_escape): Fix up -Wformat-diag warnings. (cpp_interpret_string_ranges, count_source_chars): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF. (narrow_str_to_charconst): Fix up -Wformat-diag warnings. * directives.cc (check_eol_1, directive_diagnostics, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, do_include_next, _cpp_parse_embed_params, do_embed, read_flag, do_line, do_linemarker, register_pragma_1, do_pragma_once, do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison, do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, do_assert, cpp_define_unused): Likewise. * expr.cc (cpp_classify_number, parse_defined, eval_token, _cpp_parse_expr, reduce, check_promotion): Likewise. * files.cc (_cpp_find_file, finish_base64_embed, _cpp_pop_file_buffer): Likewise. * init.cc (sanity_checks): Likewise. * lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char, _cpp_warn_invalid_utf8, _cpp_skip_block_comment, warn_about_normalization, forms_identifier_p, maybe_va_opt_error, identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise. * macro.cc (class vaopt_state, builtin_has_include_1, builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro, _cpp_builtin_macro_text, builtin_macro, stringify_arg, _cpp_arguments_ok, collect_args, enter_macro_context, _cpp_save_parameter, parse_params, create_iso_definition, _cpp_create_definition, check_trad_stringification): Likewise. * pch.cc (cpp_valid_state): Likewise. * traditional.cc (_cpp_scan_out_logical_line, recursive_macro): Likewise. gcc/ * Makefile.in (generated_files): Remove {gimple,generic}-match*. (generated_match_files): New variable. Add a dependency of $(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those. (build/genmatch$(build_exeext)): Depend on and link against libcommon.a and $(LIBBACKTRACE). * genmatch.cc: Include pretty-print.h and input.h. (ggc_internal_cleared_alloc, ggc_free): Remove. (fatal): New function. (line_table): Remove. (linemap_client_expand_location_to_spelling_point): Remove. (diagnostic_cb): Use gcc_diag rather than printf format. Use pp_format_verbatim on a temporary pretty_printer instead of vfprintf. (fatal_at, warning_at): Use gcc_diag rather than printf format. (output_line_directive): Rename location_hash to loc_hash. (parser::eat_ident, parser::parse_operation, parser::parse_expr, parser::parse_pattern, parser::finish_match_operand): Fix up -Wformat-diag warnings. gcc/c-family/ * c-lex.cc (c_common_has_attribute, c_common_lex_availability_macro): Fix up -Wformat-diag warnings. gcc/testsuite/ * c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for libcpp diagnostic formatting changes. * c-c++-common/cpp/embed-3.c: Likewise. * c-c++-common/cpp/embed-4.c: Likewise. * c-c++-common/cpp/embed-16.c: Likewise. * c-c++-common/cpp/embed-18.c: Likewise. * c-c++-common/cpp/eof-2.c: Likewise. * c-c++-common/cpp/eof-3.c: Likewise. * c-c++-common/cpp/fmax-include-depth.c: Likewise. * c-c++-common/cpp/has-builtin.c: Likewise. * c-c++-common/cpp/line-2.c: Likewise. * c-c++-common/cpp/line-3.c: Likewise. * c-c++-common/cpp/macro-arg-count-1.c: Likewise. * c-c++-common/cpp/macro-arg-count-2.c: Likewise. * c-c++-common/cpp/macro-ranges.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-4.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-5.c: Likewise. * c-c++-common/cpp/pr88974.c: Likewise. * c-c++-common/cpp/va-opt-error.c: Likewise. * c-c++-common/cpp/va-opt-pedantic.c: Likewise. * c-c++-common/cpp/Wheader-guard-2.c: Likewise. * c-c++-common/cpp/Wheader-guard-3.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-1.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-2.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-3.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c: Likewise. * c-c++-common/pr68833-3.c: Likewise. * c-c++-common/raw-string-directive-1.c: Likewise. * gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise. * gcc.dg/binary-constants-4.c: Likewise. * gcc.dg/builtin-redefine.c: Likewise. * gcc.dg/cpp/19951025-1.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c23-elifdef-2.c: Likewise. * gcc.dg/cpp/c23-warning-2.c: Likewise. * gcc.dg/cpp/embed-2.c: Likewise. * gcc.dg/cpp/embed-3.c: Likewise. * gcc.dg/cpp/embed-4.c: Likewise. * gcc.dg/cpp/expr.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu23-warning-2.c: Likewise. * gcc.dg/cpp/include6.c: Likewise. * gcc.dg/cpp/pr35322.c: Likewise. * gcc.dg/cpp/tr-warn6.c: Likewise. * gcc.dg/cpp/undef2.c: Likewise. * gcc.dg/cpp/warn-comments.c: Likewise. * gcc.dg/cpp/warn-comments-2.c: Likewise. * gcc.dg/cpp/warn-comments-3.c: Likewise. * gcc.dg/cpp/warn-cxx-compat.c: Likewise. * gcc.dg/cpp/warn-cxx-compat-2.c: Likewise. * gcc.dg/cpp/warn-deprecated.c: Likewise. * gcc.dg/cpp/warn-deprecated-2.c: Likewise. * gcc.dg/cpp/warn-long-long.c: Likewise. * gcc.dg/cpp/warn-long-long-2.c: Likewise. * gcc.dg/cpp/warn-normalized-1.c: Likewise. * gcc.dg/cpp/warn-normalized-2.c: Likewise. * gcc.dg/cpp/warn-normalized-3.c: Likewise. * gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise. * gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise. * gcc.dg/cpp/warn-redefined.c: Likewise. * gcc.dg/cpp/warn-redefined-2.c: Likewise. * gcc.dg/cpp/warn-traditional.c: Likewise. * gcc.dg/cpp/warn-traditional-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-1.c: Likewise. * gcc.dg/cpp/warn-trigraphs-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-3.c: Likewise. * gcc.dg/cpp/warn-trigraphs-4.c: Likewise. * gcc.dg/cpp/warn-undef.c: Likewise. * gcc.dg/cpp/warn-undef-2.c: Likewise. * gcc.dg/cpp/warn-unused-macros.c: Likewise. * gcc.dg/cpp/warn-unused-macros-2.c: Likewise. * gcc.dg/pch/counter-2.c: Likewise. * g++.dg/cpp0x/udlit-error1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-1.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-3.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-4.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-5.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-6.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-7.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-8.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-9.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-10.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-11.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-12.C: Likewise. * g++.dg/cpp/elifdef-3.C: Likewise. * g++.dg/cpp/elifdef-5.C: Likewise. * g++.dg/cpp/elifdef-6.C: Likewise. * g++.dg/cpp/elifdef-7.C: Likewise. * g++.dg/cpp/embed-1.C: Likewise. * g++.dg/cpp/embed-2.C: Likewise. * g++.dg/cpp/pedantic-errors.C: Likewise. * g++.dg/cpp/warning-1.C: Likewise. * g++.dg/cpp/warning-2.C: Likewise. * g++.dg/ext/bitint1.C: Likewise. * g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
"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 18:51:15 +08:00
SYNTAX_ERROR2_AT (op.loc,
libcpp, c-family: Add (dumb) C23 N3017 #embed support [PR105863] The following patch implements the C23 N3017 "#embed - a scannable, tooling-friendly binary resource inclusion mechanism" paper. The implementation is intentionally dumb, in that it doesn't significantly speed up compilation of larger initializers and doesn't make it possible to use huge #embeds (like several gigabytes large, that is compile time and memory still infeasible). There are 2 reasons for this. One is that I think like it is implemented now in the patch is how we should use it for the smaller #embed sizes, dunno with which boundary, whether 32 bytes or 64 or something like that, certainly handling the single byte cases which is something that can appear anywhere in the source where constant integer literal can appear is desirable and I think for a few bytes it isn't worth it to come up with something smarter and users would like to e.g. see it in -E readably as well (perhaps the slow vs. fast boundary should be determined by command line option). And the other one is to be able to more easily find regressions in behavior caused by the optimizations, so we have something to get back in git to compare against. I'm definitely willing to work on the optimizations (likely introduce a new CPP_* token type to refer to a range of libcpp owned memory (start + size) and similarly some tree which can do the same, and can be at any time e.g. split into 2 subparts + say INTEGER_CST in between if needed say for const unsigned char d[] = { #embed "2GB.dat" prefix (0, 0, ) suffix (, [0x40000000] = 42) }; still without having to copy around huge amounts of data; STRING_CST owns the memory it points to and can be only 2GB in size), but would like to do that incrementally. And would like to first include some extensions also not included in this patch, like gnu::offset (off) parameter to allow to skip certain constant amount of bytes at the start of the files, plus gnu::base64 ("base64_encoded_data") parameter to add something which can store more efficiently large amounts of the #embed data in preprocessed source. I've been cross-checking all the tests also against the LLVM implementation https://github.com/llvm/llvm-project/pull/68620 which has been for a few hours even committed to LLVM trunk but reverted afterwards. LLVM now has the support committed and I admit I haven't rechecked whether the behavior on the below mentioned spots have been fixed in it already or not yet. The patch uses --embed-dir= option that clang plans to add above and doesn't use other variants on the search directories yet, plus there are no default directories at least for the time being where to search for embed files. So, #embed "..." works if it is found in the same directory (or relative to the current file's directory) and #embed "/..." or #embed </...> work always, but relative #embed <...> doesn't unless at least one --embed-dir= is specified. There is no reason to differentiate between system and non-system directories, so we don't need -isystem like counterpart, perhaps -iquote like counterpart could be useful in the future, dunno what else. It has --embed-directory=dir and --embed-directory dir as aliases. There are some differences beyond clang ICEs, so I'd like to point them out to make sure there is agreement on the choices in the patch. They are also mentioned in the comments of the llvm pull request. The most important is that the GCC patch (as well as the original thephd.dev LLVM branch on godbolt) expands #embed (or acts as if it is expanded) into a mere sequence of numbers like 123,2,35,26 rather then what clang effectively treats as (unsigned char)123,(unsigned char)2,(unsigned char)35,(unsigned char)26 but only does that when using integrated preprocessor, not when using -save-temps where it acts as GCC. JeanHeyd as the original author agrees that is how it is currently worded in C23. Another difference (not tested in the testsuite, not sure how to check for effective target /dev/urandom nor am sure it is desirable to check that during testsuite) is how to treat character devices, named pipes etc. (block devices are errored on). The original paper uses /dev/urandom in various examples and seems to assume that unlike regular files the devices aren't really cached, so #embed </dev/urandom> limit(1) prefix(int a = ) suffix(;) #embed </dev/urandom> limit(1) prefix(int b = ) suffix(;) usually results in a != b. That is what the godbolt thephd.dev branch implements too and what this patch does as well, but clang actually seems to just go from st.st_size == 0, ergo it must be zero-sized resource and so just copies over if_empty if present. It is really questionable what to do about the character devices/named pipes with __has_embed, for regular files the patch doesn't read anything from them, relies on st.st_size + limit for whether it is empty or non-empty. But I don't know of a way to check if read on say a character device would read anything or not (the </dev/null> limit (1) vs. </dev/zero> limit (1) cases), and if we read something, that would be better cached for later because #embed later if it reads again could read no further data even when it first read something. So, the patch currently for __has_embed just always returns 2 on the non-regular files, like the thephd.dev branch does as well and like the clang pull request as well. A question is also what to do for gnu::offset on the non-regular files even for #embed, those aren't seekable and do we want to just read and throw away the offset bytes each time we see it used? clang also chokes on the #if __has_embed (__FILE__ __limit__ (1) __prefix__ () suffix (1 / 0) \ __if_empty__ ((({{[0[0{0{0(0(0)1)1}1}]]}})))) != __STDC_EMBED_FOUND__ #error "__has_embed fail" #endif in embed-1.c, but thephd.dev branch accepts it and I don't see why it shouldn't, (({{[0[0{0{0(0(0)1)1}1}]]}}))) is a balanced token sequence and the file isn't empty, so it should just be parsed and discarded. clang also IMHO mishandles const unsigned char w[] = { #embed __FILE__ prefix([0] = 42, [15] =) limit(32) }; but again only without -save-temps, seems like it treats it as [0] = 42, [15] = (99,111,110,115,116,32,117,110,115,105,103,110,101,100, 32,99,104,97,114,32,119,91,93,32,61,32,123,10,35,101,109,98) rather than [0] = 42, [15] = 99,111,110,115,116,32,117,110,115,105,103,110,101,100, 32,99,104,97,114,32,119,91,93,32,61,32,123,10,35,101,109,98 and warns on it for -Wunused-value and just compiles it as [0] = 42, [15] = 98 And also void foo (int, int, int, int); void bar (void) { foo ( #embed __FILE__ limit (4) prefix (172 + ) suffix (+ 2) ); } is treated as 172 + (118, 111, 105, 100) + 2 rather than 172 + 118, 111, 105, 100 + 2 which clang -save-temps or GCC treats it like, so results in just one argument passed rather than 4. if (!strstr ((const char *) magna_carta, "imprisonétur")) abort (); in the testcase fails as well, but in that case calling it in gdb succeeds: p ((char *(*)(char *, char *))__strstr_sse2) (magna_carta, "imprisonétur") $2 = 0x555555558d3c <magna_carta+11564> "imprisonétur aut disseisiátur"... so I guess they are just trying to constant evaluate strstr and do it incorrectly. They started with making the optimizations together in the initial patch set, so they don't have the luxury to compare if it is just because of the optimization they are trying to do or because that is how the feature works for them. At least unless they use -save-temps for now. There is also different behavior between clang and gcc on -M or other dependency generating options. Seems clang includes the __has_embed searched files in dependencies, while my patch doesn't. But so does clang for __has_include and GCC doesn't. Emitting a hard dependency on some header just because there was __has_include/__has_embed for it seems wrong to me, because (at least when properly written) the source likely doesn't mind if the file is missing, it will do something else, so a hard error from make because of it doesn't seem right. Does make have some weaker dependencies, such that if some file can be remade it is but if it doesn't exist, it isn't fatal? I wonder whether #embed <non-existent-file> really needs to be fatal or whether we could simply after diagnosing it pretend the file exists and is empty. For #include I think fatal errors make tons of sense, but perhaps for #embed which is more localized we'd get better error reporting if we didn't bail out immediately. Note, both GCC and clang currently treat those as fatal errors. clang also added -dE option which with -E instead of preprocessing the #embed directives keeps them as is, but the preprocessed source then isn't self-contained. That option looks more harmful than useful to me. Also, it isn't clear to me from C23 whether it is possible to have __has_include/__has_c_attribute/__has_embed expressions inside of the limit #embed/__has_embed argument. 6.10.3.2/2 says that defined should not appear there (and the patch diagnoses it and testsuite tests), but for __has_include/__has_embed etc. 6.10.1/11 says: "The identifiers __has_include, __has_embed, and __has_c_attribute shall not appear in any context not mentioned in this subclause." If that subclause in that case means 6.10.1, then it presumably shouldn't appear in #embed in 6.10.3, but __has_embed is in 6.10.1... But 6.10.3.2/3 says that it should be parsed according to the 6.10.1 rules. Haven't included tests like #if __has_embed (__FILE__ limit (__has_embed (__FILE__ limit (1)))) or #embed __FILE__ limit (__has_include (__FILE__)) into the testsuite because of the doubts but I think the patch should handle those right now. The reason I've used Magna Carta text in some of the testcases is that I hope it shouldn't be copyrighted after the centuries and I'd strongly prefer not to have binary blobs in git after the xz backdoor lesson and wanted something larger which doesn't change all the time. Oh, BTW, I see in C23 draft 6.10.3.2 in Example 4 if (f_source == NULL); return 1; (note the spurious semicolon after closing paren), has that been fixed already? Like the thephd.dev and clang implementations, the patch always macro expands the whole #embed and __has_embed directives except for the embed keyword. That is most likely not what C23 says, my limited understanding right now is that in #embed one needs to parse the whole directive line with macro expansion disabled and check if it satisfies the grammar, if not, the whole directive is macro expanded, if yes, only the limit parameter argument is macro expanded and the prefix/suffix/if_empty arguments are maybe macro expanded when actually used (and not at all if unused). And I think __has_embed macro expansion has conflicting rules. 2024-09-12 Jakub Jelinek <jakub@redhat.com> PR c/105863 libcpp/ * include/cpplib.h: Implement C23 N3017 #embed - a scannable, tooling-friendly binary resource inclusion mechanism paper. (struct cpp_options): Add embed member. (enum cpp_builtin_type): Add BT_HAS_EMBED. (cpp_set_include_chains): Add another cpp_dir * argument to the declaration. * internal.h (enum include_type): Add IT_EMBED. (struct cpp_reader): Add embed_include member. (struct cpp_embed_params_tokens): New type. (struct cpp_embed_params): New type. (_cpp_get_token_no_padding): Declare. (enum _cpp_find_file_kind): Add _cpp_FFK_EMBED and _cpp_FFK_HAS_EMBED. (_cpp_stack_embed): Declare. (_cpp_parse_expr): Change return type to cpp_num_part instead of bool, change second argument from bool to const char * and add third argument. (_cpp_parse_embed_params): Declare. * directives.cc (DIRECTIVE_TABLE): Add embed entry. (end_directive): Don't call skip_rest_of_line for T_EMBED directive. (_cpp_handle_directive): Return 2 rather than 1 for T_EMBED in directives-only mode. (parse_include): Don't Call check_eol for T_EMBED directive. (skip_balanced_token_seq): New function. (EMBED_PARAMS): Define. (enum embed_param_kind): New type. (embed_params): New variable. (_cpp_parse_embed_params): New function. (do_embed): New function. (do_if): Adjust _cpp_parse_expr caller. (do_elif): Likewise. * expr.cc (parse_defined): Diagnose defined in #embed or __has_embed parameters. (_cpp_parse_expr): Change return type to cpp_num_part instead of bool, change second argument from bool to const char * and add third argument. Adjust function comment. For #embed/__has_embed parameters add an artificial CPP_OPEN_PAREN. Use the second argument DIR directly instead of string literals conditional on IS_IF. For #embed/__has_embed parameter, stop on reaching CPP_CLOSE_PAREN matching the artificial one. Diagnose negative or too large embed parameter operands. (num_binary_op): Use #embed instead of #if for diagnostics if inside #embed/__has_embed parameter. (num_div_op): Likewise. * files.cc (struct _cpp_file): Add limit member and embed bitfield. (search_cache): Add IS_EMBED argument, formatting fix. Skip over files with different file->embed from the argument. (find_file_in_dir): Don't call pch_open_file if file->embed. (_cpp_find_file): Handle _cpp_FFK_EMBED and _cpp_FFK_HAS_EMBED. (read_file_guts): Formatting fix. (has_unique_contents): Ignore file->embed files. (search_path_head): Handle IT_EMBED type. (_cpp_stack_embed): New function. (_cpp_get_file_stat): Formatting fix. (cpp_set_include_chains): Add embed argument, save it to pfile->embed_include and compute lens for the chain. * init.cc (struct lang_flags): Add embed member. (lang_defaults): Add embed initializers. (cpp_set_lang): Initialize CPP_OPTION (pfile, embed). (builtin_array): Add __has_embed entry. (cpp_init_builtins): Predefine __STDC_EMBED_NOT_FOUND__, __STDC_EMBED_FOUND__ and __STDC_EMBED_EMPTY__. * lex.cc (cpp_directive_only_process): Handle #embed. * macro.cc (cpp_get_token_no_padding): Rename to ... (_cpp_get_token_no_padding): ... this. No longer static. (builtin_has_include_1): New function. (builtin_has_include): Use it. Use _cpp_get_token_no_padding instead of cpp_get_token_no_padding. (builtin_has_embed): New function. (_cpp_builtin_macro_text): Handle BT_HAS_EMBED. gcc/ * doc/cppdiropts.texi (--embed-dir=): Document. * doc/cpp.texi (Binary Resource Inclusion): New chapter. (__has_embed): Document. * doc/invoke.texi (Directory Options): Mention --embed-dir=. * gcc.cc (cpp_unique_options): Add %{-embed*}. * genmatch.cc (main): Adjust cpp_set_include_chains caller. * incpath.h (enum incpath_kind): Add INC_EMBED. * incpath.cc (merge_include_chains): Handle INC_EMBED. (register_include_chains): Adjust cpp_set_include_chains caller. gcc/c-family/ * c.opt (-embed-dir=): New option. (-embed-directory): New alias. (-embed-directory=): New alias. * c-opts.cc (c_common_handle_option): Handle OPT__embed_dir_. gcc/testsuite/ * c-c++-common/cpp/embed-1.c: New test. * c-c++-common/cpp/embed-2.c: New test. * c-c++-common/cpp/embed-3.c: New test. * c-c++-common/cpp/embed-4.c: New test. * c-c++-common/cpp/embed-5.c: New test. * c-c++-common/cpp/embed-6.c: New test. * c-c++-common/cpp/embed-7.c: New test. * c-c++-common/cpp/embed-8.c: New test. * c-c++-common/cpp/embed-9.c: New test. * c-c++-common/cpp/embed-10.c: New test. * c-c++-common/cpp/embed-11.c: New test. * c-c++-common/cpp/embed-12.c: New test. * c-c++-common/cpp/embed-13.c: New test. * c-c++-common/cpp/embed-14.c: New test. * c-c++-common/cpp/embed-25.c: New test. * c-c++-common/cpp/embed-26.c: New test. * c-c++-common/cpp/embed-dir/embed-1.inc: New test. * c-c++-common/cpp/embed-dir/embed-3.c: New test. * c-c++-common/cpp/embed-dir/embed-4.c: New test. * c-c++-common/cpp/embed-dir/magna-carta.txt: New test. * gcc.dg/cpp/embed-1.c: New test. * gcc.dg/cpp/embed-2.c: New test. * gcc.dg/cpp/embed-3.c: New test. * gcc.dg/cpp/embed-4.c: New test. * g++.dg/cpp/embed-1.C: New test. * g++.dg/cpp/embed-2.C: New test. * g++.dg/cpp/embed-3.C: New test.
2024-09-12 17:15:38 +08:00
"%s with no expression", dir);
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 18:51:15 +08:00
SYNTAX_ERROR2_AT (op.loc,
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics When working on #embed support, or -Wheader-guard or other recent libcpp changes, I've been annoyed by the libcpp diagnostics being visually different from normal gcc diagnostics, especially in the area of quoting stuff in the diagnostic messages. Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use %</%>, %qs etc. in there, while libcpp diagnostics was marked as printf and in libcpp we've been very creative with quoting stuff, either no quotes at all, or "something" quoting, or 'something' quoting, or `something' quoting (but in none of the cases it used colors consistently with the rest of the compiler). Now, libcpp diagnostics is always emitted using a callback, pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with genmatch.cc: cb->diagnostic = diagnostic_cb; c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic; fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic; where the latter two just use diagnostic_report_diagnostic, so actually support all the gcc_diag stuff, only the genmatch.cc case didn't. So, the following patch changes genmatch.cc to use pp_format* instead of vfprintf so that it supports the gcc_diag formatting (pretty-print.o unfortunately has various dependencies, so had to link genmatch with libcommon.a libbacktrace.a and tweak Makefile.in so that there are no circular dependencies) and marks the libcpp diagnostic routines as gcc_diag rather than printf. That change resulted in hundreds of -Wformat-diag new warnings (most of them useful and resulting IMHO in better diagnostics), so the rest of the patch is changing the format strings to make -Wformat-diag happy and adjusting the testsuite for the differences in how is the diagnostic reformatted. Dunno if some out of GCC tree projects use libcpp, that case would make it harder because one couldn't use vfprintf in the diagnostic callback anymore, but there is always David's libdiagnostic which could be used for that purpose IMHO. 2024-10-12 Jakub Jelinek <jakub@redhat.com> libcpp/ * include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define. (struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF on diagnostic callback. (cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3. (cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. (cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6) instead of ATTRIBUTE_PRINTF_5. (cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. * Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather than --language=c. * errors.cc (cpp_diagnostic_at, cpp_diagnostic, cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of -ATTRIBUTE_FPTR_PRINTF. * charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex, convert_oct, convert_escape): Fix up -Wformat-diag warnings. (cpp_interpret_string_ranges, count_source_chars): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF. (narrow_str_to_charconst): Fix up -Wformat-diag warnings. * directives.cc (check_eol_1, directive_diagnostics, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, do_include_next, _cpp_parse_embed_params, do_embed, read_flag, do_line, do_linemarker, register_pragma_1, do_pragma_once, do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison, do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, do_assert, cpp_define_unused): Likewise. * expr.cc (cpp_classify_number, parse_defined, eval_token, _cpp_parse_expr, reduce, check_promotion): Likewise. * files.cc (_cpp_find_file, finish_base64_embed, _cpp_pop_file_buffer): Likewise. * init.cc (sanity_checks): Likewise. * lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char, _cpp_warn_invalid_utf8, _cpp_skip_block_comment, warn_about_normalization, forms_identifier_p, maybe_va_opt_error, identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise. * macro.cc (class vaopt_state, builtin_has_include_1, builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro, _cpp_builtin_macro_text, builtin_macro, stringify_arg, _cpp_arguments_ok, collect_args, enter_macro_context, _cpp_save_parameter, parse_params, create_iso_definition, _cpp_create_definition, check_trad_stringification): Likewise. * pch.cc (cpp_valid_state): Likewise. * traditional.cc (_cpp_scan_out_logical_line, recursive_macro): Likewise. gcc/ * Makefile.in (generated_files): Remove {gimple,generic}-match*. (generated_match_files): New variable. Add a dependency of $(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those. (build/genmatch$(build_exeext)): Depend on and link against libcommon.a and $(LIBBACKTRACE). * genmatch.cc: Include pretty-print.h and input.h. (ggc_internal_cleared_alloc, ggc_free): Remove. (fatal): New function. (line_table): Remove. (linemap_client_expand_location_to_spelling_point): Remove. (diagnostic_cb): Use gcc_diag rather than printf format. Use pp_format_verbatim on a temporary pretty_printer instead of vfprintf. (fatal_at, warning_at): Use gcc_diag rather than printf format. (output_line_directive): Rename location_hash to loc_hash. (parser::eat_ident, parser::parse_operation, parser::parse_expr, parser::parse_pattern, parser::finish_match_operand): Fix up -Wformat-diag warnings. gcc/c-family/ * c-lex.cc (c_common_has_attribute, c_common_lex_availability_macro): Fix up -Wformat-diag warnings. gcc/testsuite/ * c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for libcpp diagnostic formatting changes. * c-c++-common/cpp/embed-3.c: Likewise. * c-c++-common/cpp/embed-4.c: Likewise. * c-c++-common/cpp/embed-16.c: Likewise. * c-c++-common/cpp/embed-18.c: Likewise. * c-c++-common/cpp/eof-2.c: Likewise. * c-c++-common/cpp/eof-3.c: Likewise. * c-c++-common/cpp/fmax-include-depth.c: Likewise. * c-c++-common/cpp/has-builtin.c: Likewise. * c-c++-common/cpp/line-2.c: Likewise. * c-c++-common/cpp/line-3.c: Likewise. * c-c++-common/cpp/macro-arg-count-1.c: Likewise. * c-c++-common/cpp/macro-arg-count-2.c: Likewise. * c-c++-common/cpp/macro-ranges.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-4.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-5.c: Likewise. * c-c++-common/cpp/pr88974.c: Likewise. * c-c++-common/cpp/va-opt-error.c: Likewise. * c-c++-common/cpp/va-opt-pedantic.c: Likewise. * c-c++-common/cpp/Wheader-guard-2.c: Likewise. * c-c++-common/cpp/Wheader-guard-3.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-1.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-2.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-3.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c: Likewise. * c-c++-common/pr68833-3.c: Likewise. * c-c++-common/raw-string-directive-1.c: Likewise. * gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise. * gcc.dg/binary-constants-4.c: Likewise. * gcc.dg/builtin-redefine.c: Likewise. * gcc.dg/cpp/19951025-1.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c23-elifdef-2.c: Likewise. * gcc.dg/cpp/c23-warning-2.c: Likewise. * gcc.dg/cpp/embed-2.c: Likewise. * gcc.dg/cpp/embed-3.c: Likewise. * gcc.dg/cpp/embed-4.c: Likewise. * gcc.dg/cpp/expr.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu23-warning-2.c: Likewise. * gcc.dg/cpp/include6.c: Likewise. * gcc.dg/cpp/pr35322.c: Likewise. * gcc.dg/cpp/tr-warn6.c: Likewise. * gcc.dg/cpp/undef2.c: Likewise. * gcc.dg/cpp/warn-comments.c: Likewise. * gcc.dg/cpp/warn-comments-2.c: Likewise. * gcc.dg/cpp/warn-comments-3.c: Likewise. * gcc.dg/cpp/warn-cxx-compat.c: Likewise. * gcc.dg/cpp/warn-cxx-compat-2.c: Likewise. * gcc.dg/cpp/warn-deprecated.c: Likewise. * gcc.dg/cpp/warn-deprecated-2.c: Likewise. * gcc.dg/cpp/warn-long-long.c: Likewise. * gcc.dg/cpp/warn-long-long-2.c: Likewise. * gcc.dg/cpp/warn-normalized-1.c: Likewise. * gcc.dg/cpp/warn-normalized-2.c: Likewise. * gcc.dg/cpp/warn-normalized-3.c: Likewise. * gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise. * gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise. * gcc.dg/cpp/warn-redefined.c: Likewise. * gcc.dg/cpp/warn-redefined-2.c: Likewise. * gcc.dg/cpp/warn-traditional.c: Likewise. * gcc.dg/cpp/warn-traditional-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-1.c: Likewise. * gcc.dg/cpp/warn-trigraphs-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-3.c: Likewise. * gcc.dg/cpp/warn-trigraphs-4.c: Likewise. * gcc.dg/cpp/warn-undef.c: Likewise. * gcc.dg/cpp/warn-undef-2.c: Likewise. * gcc.dg/cpp/warn-unused-macros.c: Likewise. * gcc.dg/cpp/warn-unused-macros-2.c: Likewise. * gcc.dg/pch/counter-2.c: Likewise. * g++.dg/cpp0x/udlit-error1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-1.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-3.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-4.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-5.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-6.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-7.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-8.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-9.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-10.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-11.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-12.C: Likewise. * g++.dg/cpp/elifdef-3.C: Likewise. * g++.dg/cpp/elifdef-5.C: Likewise. * g++.dg/cpp/elifdef-6.C: Likewise. * g++.dg/cpp/elifdef-7.C: Likewise. * g++.dg/cpp/embed-1.C: Likewise. * g++.dg/cpp/embed-2.C: Likewise. * g++.dg/cpp/pedantic-errors.C: Likewise. * g++.dg/cpp/warning-1.C: Likewise. * g++.dg/cpp/warning-2.C: Likewise. * g++.dg/ext/bitint1.C: Likewise. * g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
"operator %qs has no right operand",
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 18:51:15 +08:00
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 18:51:15 +08:00
SYNTAX_ERROR2_AT (op.loc,
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics When working on #embed support, or -Wheader-guard or other recent libcpp changes, I've been annoyed by the libcpp diagnostics being visually different from normal gcc diagnostics, especially in the area of quoting stuff in the diagnostic messages. Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use %</%>, %qs etc. in there, while libcpp diagnostics was marked as printf and in libcpp we've been very creative with quoting stuff, either no quotes at all, or "something" quoting, or 'something' quoting, or `something' quoting (but in none of the cases it used colors consistently with the rest of the compiler). Now, libcpp diagnostics is always emitted using a callback, pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with genmatch.cc: cb->diagnostic = diagnostic_cb; c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic; fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic; where the latter two just use diagnostic_report_diagnostic, so actually support all the gcc_diag stuff, only the genmatch.cc case didn't. So, the following patch changes genmatch.cc to use pp_format* instead of vfprintf so that it supports the gcc_diag formatting (pretty-print.o unfortunately has various dependencies, so had to link genmatch with libcommon.a libbacktrace.a and tweak Makefile.in so that there are no circular dependencies) and marks the libcpp diagnostic routines as gcc_diag rather than printf. That change resulted in hundreds of -Wformat-diag new warnings (most of them useful and resulting IMHO in better diagnostics), so the rest of the patch is changing the format strings to make -Wformat-diag happy and adjusting the testsuite for the differences in how is the diagnostic reformatted. Dunno if some out of GCC tree projects use libcpp, that case would make it harder because one couldn't use vfprintf in the diagnostic callback anymore, but there is always David's libdiagnostic which could be used for that purpose IMHO. 2024-10-12 Jakub Jelinek <jakub@redhat.com> libcpp/ * include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define. (struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF on diagnostic callback. (cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3. (cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. (cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6) instead of ATTRIBUTE_PRINTF_5. (cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. * Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather than --language=c. * errors.cc (cpp_diagnostic_at, cpp_diagnostic, cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of -ATTRIBUTE_FPTR_PRINTF. * charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex, convert_oct, convert_escape): Fix up -Wformat-diag warnings. (cpp_interpret_string_ranges, count_source_chars): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF. (narrow_str_to_charconst): Fix up -Wformat-diag warnings. * directives.cc (check_eol_1, directive_diagnostics, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, do_include_next, _cpp_parse_embed_params, do_embed, read_flag, do_line, do_linemarker, register_pragma_1, do_pragma_once, do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison, do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, do_assert, cpp_define_unused): Likewise. * expr.cc (cpp_classify_number, parse_defined, eval_token, _cpp_parse_expr, reduce, check_promotion): Likewise. * files.cc (_cpp_find_file, finish_base64_embed, _cpp_pop_file_buffer): Likewise. * init.cc (sanity_checks): Likewise. * lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char, _cpp_warn_invalid_utf8, _cpp_skip_block_comment, warn_about_normalization, forms_identifier_p, maybe_va_opt_error, identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise. * macro.cc (class vaopt_state, builtin_has_include_1, builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro, _cpp_builtin_macro_text, builtin_macro, stringify_arg, _cpp_arguments_ok, collect_args, enter_macro_context, _cpp_save_parameter, parse_params, create_iso_definition, _cpp_create_definition, check_trad_stringification): Likewise. * pch.cc (cpp_valid_state): Likewise. * traditional.cc (_cpp_scan_out_logical_line, recursive_macro): Likewise. gcc/ * Makefile.in (generated_files): Remove {gimple,generic}-match*. (generated_match_files): New variable. Add a dependency of $(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those. (build/genmatch$(build_exeext)): Depend on and link against libcommon.a and $(LIBBACKTRACE). * genmatch.cc: Include pretty-print.h and input.h. (ggc_internal_cleared_alloc, ggc_free): Remove. (fatal): New function. (line_table): Remove. (linemap_client_expand_location_to_spelling_point): Remove. (diagnostic_cb): Use gcc_diag rather than printf format. Use pp_format_verbatim on a temporary pretty_printer instead of vfprintf. (fatal_at, warning_at): Use gcc_diag rather than printf format. (output_line_directive): Rename location_hash to loc_hash. (parser::eat_ident, parser::parse_operation, parser::parse_expr, parser::parse_pattern, parser::finish_match_operand): Fix up -Wformat-diag warnings. gcc/c-family/ * c-lex.cc (c_common_has_attribute, c_common_lex_availability_macro): Fix up -Wformat-diag warnings. gcc/testsuite/ * c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for libcpp diagnostic formatting changes. * c-c++-common/cpp/embed-3.c: Likewise. * c-c++-common/cpp/embed-4.c: Likewise. * c-c++-common/cpp/embed-16.c: Likewise. * c-c++-common/cpp/embed-18.c: Likewise. * c-c++-common/cpp/eof-2.c: Likewise. * c-c++-common/cpp/eof-3.c: Likewise. * c-c++-common/cpp/fmax-include-depth.c: Likewise. * c-c++-common/cpp/has-builtin.c: Likewise. * c-c++-common/cpp/line-2.c: Likewise. * c-c++-common/cpp/line-3.c: Likewise. * c-c++-common/cpp/macro-arg-count-1.c: Likewise. * c-c++-common/cpp/macro-arg-count-2.c: Likewise. * c-c++-common/cpp/macro-ranges.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-4.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-5.c: Likewise. * c-c++-common/cpp/pr88974.c: Likewise. * c-c++-common/cpp/va-opt-error.c: Likewise. * c-c++-common/cpp/va-opt-pedantic.c: Likewise. * c-c++-common/cpp/Wheader-guard-2.c: Likewise. * c-c++-common/cpp/Wheader-guard-3.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-1.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-2.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-3.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c: Likewise. * c-c++-common/pr68833-3.c: Likewise. * c-c++-common/raw-string-directive-1.c: Likewise. * gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise. * gcc.dg/binary-constants-4.c: Likewise. * gcc.dg/builtin-redefine.c: Likewise. * gcc.dg/cpp/19951025-1.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c23-elifdef-2.c: Likewise. * gcc.dg/cpp/c23-warning-2.c: Likewise. * gcc.dg/cpp/embed-2.c: Likewise. * gcc.dg/cpp/embed-3.c: Likewise. * gcc.dg/cpp/embed-4.c: Likewise. * gcc.dg/cpp/expr.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu23-warning-2.c: Likewise. * gcc.dg/cpp/include6.c: Likewise. * gcc.dg/cpp/pr35322.c: Likewise. * gcc.dg/cpp/tr-warn6.c: Likewise. * gcc.dg/cpp/undef2.c: Likewise. * gcc.dg/cpp/warn-comments.c: Likewise. * gcc.dg/cpp/warn-comments-2.c: Likewise. * gcc.dg/cpp/warn-comments-3.c: Likewise. * gcc.dg/cpp/warn-cxx-compat.c: Likewise. * gcc.dg/cpp/warn-cxx-compat-2.c: Likewise. * gcc.dg/cpp/warn-deprecated.c: Likewise. * gcc.dg/cpp/warn-deprecated-2.c: Likewise. * gcc.dg/cpp/warn-long-long.c: Likewise. * gcc.dg/cpp/warn-long-long-2.c: Likewise. * gcc.dg/cpp/warn-normalized-1.c: Likewise. * gcc.dg/cpp/warn-normalized-2.c: Likewise. * gcc.dg/cpp/warn-normalized-3.c: Likewise. * gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise. * gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise. * gcc.dg/cpp/warn-redefined.c: Likewise. * gcc.dg/cpp/warn-redefined-2.c: Likewise. * gcc.dg/cpp/warn-traditional.c: Likewise. * gcc.dg/cpp/warn-traditional-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-1.c: Likewise. * gcc.dg/cpp/warn-trigraphs-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-3.c: Likewise. * gcc.dg/cpp/warn-trigraphs-4.c: Likewise. * gcc.dg/cpp/warn-undef.c: Likewise. * gcc.dg/cpp/warn-undef-2.c: Likewise. * gcc.dg/cpp/warn-unused-macros.c: Likewise. * gcc.dg/cpp/warn-unused-macros-2.c: Likewise. * gcc.dg/pch/counter-2.c: Likewise. * g++.dg/cpp0x/udlit-error1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-1.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-3.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-4.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-5.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-6.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-7.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-8.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-9.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-10.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-11.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-12.C: Likewise. * g++.dg/cpp/elifdef-3.C: Likewise. * g++.dg/cpp/elifdef-5.C: Likewise. * g++.dg/cpp/elifdef-6.C: Likewise. * g++.dg/cpp/elifdef-7.C: Likewise. * g++.dg/cpp/embed-1.C: Likewise. * g++.dg/cpp/embed-2.C: Likewise. * g++.dg/cpp/pedantic-errors.C: Likewise. * g++.dg/cpp/warning-1.C: Likewise. * g++.dg/cpp/warning-2.C: Likewise. * g++.dg/ext/bitint1.C: Likewise. * g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
"operator %qs has no left operand",
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 18:51:15 +08:00
cpp_token_as_text (pfile, op.token));
1995-03-17 05:59:07 +08: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:
libcpp, c-family: Add (dumb) C23 N3017 #embed support [PR105863] The following patch implements the C23 N3017 "#embed - a scannable, tooling-friendly binary resource inclusion mechanism" paper. The implementation is intentionally dumb, in that it doesn't significantly speed up compilation of larger initializers and doesn't make it possible to use huge #embeds (like several gigabytes large, that is compile time and memory still infeasible). There are 2 reasons for this. One is that I think like it is implemented now in the patch is how we should use it for the smaller #embed sizes, dunno with which boundary, whether 32 bytes or 64 or something like that, certainly handling the single byte cases which is something that can appear anywhere in the source where constant integer literal can appear is desirable and I think for a few bytes it isn't worth it to come up with something smarter and users would like to e.g. see it in -E readably as well (perhaps the slow vs. fast boundary should be determined by command line option). And the other one is to be able to more easily find regressions in behavior caused by the optimizations, so we have something to get back in git to compare against. I'm definitely willing to work on the optimizations (likely introduce a new CPP_* token type to refer to a range of libcpp owned memory (start + size) and similarly some tree which can do the same, and can be at any time e.g. split into 2 subparts + say INTEGER_CST in between if needed say for const unsigned char d[] = { #embed "2GB.dat" prefix (0, 0, ) suffix (, [0x40000000] = 42) }; still without having to copy around huge amounts of data; STRING_CST owns the memory it points to and can be only 2GB in size), but would like to do that incrementally. And would like to first include some extensions also not included in this patch, like gnu::offset (off) parameter to allow to skip certain constant amount of bytes at the start of the files, plus gnu::base64 ("base64_encoded_data") parameter to add something which can store more efficiently large amounts of the #embed data in preprocessed source. I've been cross-checking all the tests also against the LLVM implementation https://github.com/llvm/llvm-project/pull/68620 which has been for a few hours even committed to LLVM trunk but reverted afterwards. LLVM now has the support committed and I admit I haven't rechecked whether the behavior on the below mentioned spots have been fixed in it already or not yet. The patch uses --embed-dir= option that clang plans to add above and doesn't use other variants on the search directories yet, plus there are no default directories at least for the time being where to search for embed files. So, #embed "..." works if it is found in the same directory (or relative to the current file's directory) and #embed "/..." or #embed </...> work always, but relative #embed <...> doesn't unless at least one --embed-dir= is specified. There is no reason to differentiate between system and non-system directories, so we don't need -isystem like counterpart, perhaps -iquote like counterpart could be useful in the future, dunno what else. It has --embed-directory=dir and --embed-directory dir as aliases. There are some differences beyond clang ICEs, so I'd like to point them out to make sure there is agreement on the choices in the patch. They are also mentioned in the comments of the llvm pull request. The most important is that the GCC patch (as well as the original thephd.dev LLVM branch on godbolt) expands #embed (or acts as if it is expanded) into a mere sequence of numbers like 123,2,35,26 rather then what clang effectively treats as (unsigned char)123,(unsigned char)2,(unsigned char)35,(unsigned char)26 but only does that when using integrated preprocessor, not when using -save-temps where it acts as GCC. JeanHeyd as the original author agrees that is how it is currently worded in C23. Another difference (not tested in the testsuite, not sure how to check for effective target /dev/urandom nor am sure it is desirable to check that during testsuite) is how to treat character devices, named pipes etc. (block devices are errored on). The original paper uses /dev/urandom in various examples and seems to assume that unlike regular files the devices aren't really cached, so #embed </dev/urandom> limit(1) prefix(int a = ) suffix(;) #embed </dev/urandom> limit(1) prefix(int b = ) suffix(;) usually results in a != b. That is what the godbolt thephd.dev branch implements too and what this patch does as well, but clang actually seems to just go from st.st_size == 0, ergo it must be zero-sized resource and so just copies over if_empty if present. It is really questionable what to do about the character devices/named pipes with __has_embed, for regular files the patch doesn't read anything from them, relies on st.st_size + limit for whether it is empty or non-empty. But I don't know of a way to check if read on say a character device would read anything or not (the </dev/null> limit (1) vs. </dev/zero> limit (1) cases), and if we read something, that would be better cached for later because #embed later if it reads again could read no further data even when it first read something. So, the patch currently for __has_embed just always returns 2 on the non-regular files, like the thephd.dev branch does as well and like the clang pull request as well. A question is also what to do for gnu::offset on the non-regular files even for #embed, those aren't seekable and do we want to just read and throw away the offset bytes each time we see it used? clang also chokes on the #if __has_embed (__FILE__ __limit__ (1) __prefix__ () suffix (1 / 0) \ __if_empty__ ((({{[0[0{0{0(0(0)1)1}1}]]}})))) != __STDC_EMBED_FOUND__ #error "__has_embed fail" #endif in embed-1.c, but thephd.dev branch accepts it and I don't see why it shouldn't, (({{[0[0{0{0(0(0)1)1}1}]]}}))) is a balanced token sequence and the file isn't empty, so it should just be parsed and discarded. clang also IMHO mishandles const unsigned char w[] = { #embed __FILE__ prefix([0] = 42, [15] =) limit(32) }; but again only without -save-temps, seems like it treats it as [0] = 42, [15] = (99,111,110,115,116,32,117,110,115,105,103,110,101,100, 32,99,104,97,114,32,119,91,93,32,61,32,123,10,35,101,109,98) rather than [0] = 42, [15] = 99,111,110,115,116,32,117,110,115,105,103,110,101,100, 32,99,104,97,114,32,119,91,93,32,61,32,123,10,35,101,109,98 and warns on it for -Wunused-value and just compiles it as [0] = 42, [15] = 98 And also void foo (int, int, int, int); void bar (void) { foo ( #embed __FILE__ limit (4) prefix (172 + ) suffix (+ 2) ); } is treated as 172 + (118, 111, 105, 100) + 2 rather than 172 + 118, 111, 105, 100 + 2 which clang -save-temps or GCC treats it like, so results in just one argument passed rather than 4. if (!strstr ((const char *) magna_carta, "imprisonétur")) abort (); in the testcase fails as well, but in that case calling it in gdb succeeds: p ((char *(*)(char *, char *))__strstr_sse2) (magna_carta, "imprisonétur") $2 = 0x555555558d3c <magna_carta+11564> "imprisonétur aut disseisiátur"... so I guess they are just trying to constant evaluate strstr and do it incorrectly. They started with making the optimizations together in the initial patch set, so they don't have the luxury to compare if it is just because of the optimization they are trying to do or because that is how the feature works for them. At least unless they use -save-temps for now. There is also different behavior between clang and gcc on -M or other dependency generating options. Seems clang includes the __has_embed searched files in dependencies, while my patch doesn't. But so does clang for __has_include and GCC doesn't. Emitting a hard dependency on some header just because there was __has_include/__has_embed for it seems wrong to me, because (at least when properly written) the source likely doesn't mind if the file is missing, it will do something else, so a hard error from make because of it doesn't seem right. Does make have some weaker dependencies, such that if some file can be remade it is but if it doesn't exist, it isn't fatal? I wonder whether #embed <non-existent-file> really needs to be fatal or whether we could simply after diagnosing it pretend the file exists and is empty. For #include I think fatal errors make tons of sense, but perhaps for #embed which is more localized we'd get better error reporting if we didn't bail out immediately. Note, both GCC and clang currently treat those as fatal errors. clang also added -dE option which with -E instead of preprocessing the #embed directives keeps them as is, but the preprocessed source then isn't self-contained. That option looks more harmful than useful to me. Also, it isn't clear to me from C23 whether it is possible to have __has_include/__has_c_attribute/__has_embed expressions inside of the limit #embed/__has_embed argument. 6.10.3.2/2 says that defined should not appear there (and the patch diagnoses it and testsuite tests), but for __has_include/__has_embed etc. 6.10.1/11 says: "The identifiers __has_include, __has_embed, and __has_c_attribute shall not appear in any context not mentioned in this subclause." If that subclause in that case means 6.10.1, then it presumably shouldn't appear in #embed in 6.10.3, but __has_embed is in 6.10.1... But 6.10.3.2/3 says that it should be parsed according to the 6.10.1 rules. Haven't included tests like #if __has_embed (__FILE__ limit (__has_embed (__FILE__ limit (1)))) or #embed __FILE__ limit (__has_include (__FILE__)) into the testsuite because of the doubts but I think the patch should handle those right now. The reason I've used Magna Carta text in some of the testcases is that I hope it shouldn't be copyrighted after the centuries and I'd strongly prefer not to have binary blobs in git after the xz backdoor lesson and wanted something larger which doesn't change all the time. Oh, BTW, I see in C23 draft 6.10.3.2 in Example 4 if (f_source == NULL); return 1; (note the spurious semicolon after closing paren), has that been fixed already? Like the thephd.dev and clang implementations, the patch always macro expands the whole #embed and __has_embed directives except for the embed keyword. That is most likely not what C23 says, my limited understanding right now is that in #embed one needs to parse the whole directive line with macro expansion disabled and check if it satisfies the grammar, if not, the whole directive is macro expanded, if yes, only the limit parameter argument is macro expanded and the prefix/suffix/if_empty arguments are maybe macro expanded when actually used (and not at all if unused). And I think __has_embed macro expansion has conflicting rules. 2024-09-12 Jakub Jelinek <jakub@redhat.com> PR c/105863 libcpp/ * include/cpplib.h: Implement C23 N3017 #embed - a scannable, tooling-friendly binary resource inclusion mechanism paper. (struct cpp_options): Add embed member. (enum cpp_builtin_type): Add BT_HAS_EMBED. (cpp_set_include_chains): Add another cpp_dir * argument to the declaration. * internal.h (enum include_type): Add IT_EMBED. (struct cpp_reader): Add embed_include member. (struct cpp_embed_params_tokens): New type. (struct cpp_embed_params): New type. (_cpp_get_token_no_padding): Declare. (enum _cpp_find_file_kind): Add _cpp_FFK_EMBED and _cpp_FFK_HAS_EMBED. (_cpp_stack_embed): Declare. (_cpp_parse_expr): Change return type to cpp_num_part instead of bool, change second argument from bool to const char * and add third argument. (_cpp_parse_embed_params): Declare. * directives.cc (DIRECTIVE_TABLE): Add embed entry. (end_directive): Don't call skip_rest_of_line for T_EMBED directive. (_cpp_handle_directive): Return 2 rather than 1 for T_EMBED in directives-only mode. (parse_include): Don't Call check_eol for T_EMBED directive. (skip_balanced_token_seq): New function. (EMBED_PARAMS): Define. (enum embed_param_kind): New type. (embed_params): New variable. (_cpp_parse_embed_params): New function. (do_embed): New function. (do_if): Adjust _cpp_parse_expr caller. (do_elif): Likewise. * expr.cc (parse_defined): Diagnose defined in #embed or __has_embed parameters. (_cpp_parse_expr): Change return type to cpp_num_part instead of bool, change second argument from bool to const char * and add third argument. Adjust function comment. For #embed/__has_embed parameters add an artificial CPP_OPEN_PAREN. Use the second argument DIR directly instead of string literals conditional on IS_IF. For #embed/__has_embed parameter, stop on reaching CPP_CLOSE_PAREN matching the artificial one. Diagnose negative or too large embed parameter operands. (num_binary_op): Use #embed instead of #if for diagnostics if inside #embed/__has_embed parameter. (num_div_op): Likewise. * files.cc (struct _cpp_file): Add limit member and embed bitfield. (search_cache): Add IS_EMBED argument, formatting fix. Skip over files with different file->embed from the argument. (find_file_in_dir): Don't call pch_open_file if file->embed. (_cpp_find_file): Handle _cpp_FFK_EMBED and _cpp_FFK_HAS_EMBED. (read_file_guts): Formatting fix. (has_unique_contents): Ignore file->embed files. (search_path_head): Handle IT_EMBED type. (_cpp_stack_embed): New function. (_cpp_get_file_stat): Formatting fix. (cpp_set_include_chains): Add embed argument, save it to pfile->embed_include and compute lens for the chain. * init.cc (struct lang_flags): Add embed member. (lang_defaults): Add embed initializers. (cpp_set_lang): Initialize CPP_OPTION (pfile, embed). (builtin_array): Add __has_embed entry. (cpp_init_builtins): Predefine __STDC_EMBED_NOT_FOUND__, __STDC_EMBED_FOUND__ and __STDC_EMBED_EMPTY__. * lex.cc (cpp_directive_only_process): Handle #embed. * macro.cc (cpp_get_token_no_padding): Rename to ... (_cpp_get_token_no_padding): ... this. No longer static. (builtin_has_include_1): New function. (builtin_has_include): Use it. Use _cpp_get_token_no_padding instead of cpp_get_token_no_padding. (builtin_has_embed): New function. (_cpp_builtin_macro_text): Handle BT_HAS_EMBED. gcc/ * doc/cppdiropts.texi (--embed-dir=): Document. * doc/cpp.texi (Binary Resource Inclusion): New chapter. (__has_embed): Document. * doc/invoke.texi (Directory Options): Mention --embed-dir=. * gcc.cc (cpp_unique_options): Add %{-embed*}. * genmatch.cc (main): Adjust cpp_set_include_chains caller. * incpath.h (enum incpath_kind): Add INC_EMBED. * incpath.cc (merge_include_chains): Handle INC_EMBED. (register_include_chains): Adjust cpp_set_include_chains caller. gcc/c-family/ * c.opt (-embed-dir=): New option. (-embed-directory): New alias. (-embed-directory=): New alias. * c-opts.cc (c_common_handle_option): Handle OPT__embed_dir_. gcc/testsuite/ * c-c++-common/cpp/embed-1.c: New test. * c-c++-common/cpp/embed-2.c: New test. * c-c++-common/cpp/embed-3.c: New test. * c-c++-common/cpp/embed-4.c: New test. * c-c++-common/cpp/embed-5.c: New test. * c-c++-common/cpp/embed-6.c: New test. * c-c++-common/cpp/embed-7.c: New test. * c-c++-common/cpp/embed-8.c: New test. * c-c++-common/cpp/embed-9.c: New test. * c-c++-common/cpp/embed-10.c: New test. * c-c++-common/cpp/embed-11.c: New test. * c-c++-common/cpp/embed-12.c: New test. * c-c++-common/cpp/embed-13.c: New test. * c-c++-common/cpp/embed-14.c: New test. * c-c++-common/cpp/embed-25.c: New test. * c-c++-common/cpp/embed-26.c: New test. * c-c++-common/cpp/embed-dir/embed-1.inc: New test. * c-c++-common/cpp/embed-dir/embed-3.c: New test. * c-c++-common/cpp/embed-dir/embed-4.c: New test. * c-c++-common/cpp/embed-dir/magna-carta.txt: New test. * gcc.dg/cpp/embed-1.c: New test. * gcc.dg/cpp/embed-2.c: New test. * gcc.dg/cpp/embed-3.c: New test. * gcc.dg/cpp/embed-4.c: New test. * g++.dg/cpp/embed-1.C: New test. * g++.dg/cpp/embed-2.C: New test. * g++.dg/cpp/embed-3.C: New test.
2024-09-12 17:15:38 +08:00
if (pfile->state.in_directive == 3 && top == pfile->op_stack)
goto embed_done;
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 18:51:15 +08:00
SYNTAX_ERROR_AT (op.loc,
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics When working on #embed support, or -Wheader-guard or other recent libcpp changes, I've been annoyed by the libcpp diagnostics being visually different from normal gcc diagnostics, especially in the area of quoting stuff in the diagnostic messages. Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use %</%>, %qs etc. in there, while libcpp diagnostics was marked as printf and in libcpp we've been very creative with quoting stuff, either no quotes at all, or "something" quoting, or 'something' quoting, or `something' quoting (but in none of the cases it used colors consistently with the rest of the compiler). Now, libcpp diagnostics is always emitted using a callback, pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with genmatch.cc: cb->diagnostic = diagnostic_cb; c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic; fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic; where the latter two just use diagnostic_report_diagnostic, so actually support all the gcc_diag stuff, only the genmatch.cc case didn't. So, the following patch changes genmatch.cc to use pp_format* instead of vfprintf so that it supports the gcc_diag formatting (pretty-print.o unfortunately has various dependencies, so had to link genmatch with libcommon.a libbacktrace.a and tweak Makefile.in so that there are no circular dependencies) and marks the libcpp diagnostic routines as gcc_diag rather than printf. That change resulted in hundreds of -Wformat-diag new warnings (most of them useful and resulting IMHO in better diagnostics), so the rest of the patch is changing the format strings to make -Wformat-diag happy and adjusting the testsuite for the differences in how is the diagnostic reformatted. Dunno if some out of GCC tree projects use libcpp, that case would make it harder because one couldn't use vfprintf in the diagnostic callback anymore, but there is always David's libdiagnostic which could be used for that purpose IMHO. 2024-10-12 Jakub Jelinek <jakub@redhat.com> libcpp/ * include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define. (struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF on diagnostic callback. (cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3. (cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. (cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6) instead of ATTRIBUTE_PRINTF_5. (cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. * Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather than --language=c. * errors.cc (cpp_diagnostic_at, cpp_diagnostic, cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of -ATTRIBUTE_FPTR_PRINTF. * charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex, convert_oct, convert_escape): Fix up -Wformat-diag warnings. (cpp_interpret_string_ranges, count_source_chars): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF. (narrow_str_to_charconst): Fix up -Wformat-diag warnings. * directives.cc (check_eol_1, directive_diagnostics, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, do_include_next, _cpp_parse_embed_params, do_embed, read_flag, do_line, do_linemarker, register_pragma_1, do_pragma_once, do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison, do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, do_assert, cpp_define_unused): Likewise. * expr.cc (cpp_classify_number, parse_defined, eval_token, _cpp_parse_expr, reduce, check_promotion): Likewise. * files.cc (_cpp_find_file, finish_base64_embed, _cpp_pop_file_buffer): Likewise. * init.cc (sanity_checks): Likewise. * lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char, _cpp_warn_invalid_utf8, _cpp_skip_block_comment, warn_about_normalization, forms_identifier_p, maybe_va_opt_error, identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise. * macro.cc (class vaopt_state, builtin_has_include_1, builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro, _cpp_builtin_macro_text, builtin_macro, stringify_arg, _cpp_arguments_ok, collect_args, enter_macro_context, _cpp_save_parameter, parse_params, create_iso_definition, _cpp_create_definition, check_trad_stringification): Likewise. * pch.cc (cpp_valid_state): Likewise. * traditional.cc (_cpp_scan_out_logical_line, recursive_macro): Likewise. gcc/ * Makefile.in (generated_files): Remove {gimple,generic}-match*. (generated_match_files): New variable. Add a dependency of $(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those. (build/genmatch$(build_exeext)): Depend on and link against libcommon.a and $(LIBBACKTRACE). * genmatch.cc: Include pretty-print.h and input.h. (ggc_internal_cleared_alloc, ggc_free): Remove. (fatal): New function. (line_table): Remove. (linemap_client_expand_location_to_spelling_point): Remove. (diagnostic_cb): Use gcc_diag rather than printf format. Use pp_format_verbatim on a temporary pretty_printer instead of vfprintf. (fatal_at, warning_at): Use gcc_diag rather than printf format. (output_line_directive): Rename location_hash to loc_hash. (parser::eat_ident, parser::parse_operation, parser::parse_expr, parser::parse_pattern, parser::finish_match_operand): Fix up -Wformat-diag warnings. gcc/c-family/ * c-lex.cc (c_common_has_attribute, c_common_lex_availability_macro): Fix up -Wformat-diag warnings. gcc/testsuite/ * c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for libcpp diagnostic formatting changes. * c-c++-common/cpp/embed-3.c: Likewise. * c-c++-common/cpp/embed-4.c: Likewise. * c-c++-common/cpp/embed-16.c: Likewise. * c-c++-common/cpp/embed-18.c: Likewise. * c-c++-common/cpp/eof-2.c: Likewise. * c-c++-common/cpp/eof-3.c: Likewise. * c-c++-common/cpp/fmax-include-depth.c: Likewise. * c-c++-common/cpp/has-builtin.c: Likewise. * c-c++-common/cpp/line-2.c: Likewise. * c-c++-common/cpp/line-3.c: Likewise. * c-c++-common/cpp/macro-arg-count-1.c: Likewise. * c-c++-common/cpp/macro-arg-count-2.c: Likewise. * c-c++-common/cpp/macro-ranges.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-4.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-5.c: Likewise. * c-c++-common/cpp/pr88974.c: Likewise. * c-c++-common/cpp/va-opt-error.c: Likewise. * c-c++-common/cpp/va-opt-pedantic.c: Likewise. * c-c++-common/cpp/Wheader-guard-2.c: Likewise. * c-c++-common/cpp/Wheader-guard-3.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-1.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-2.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-3.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c: Likewise. * c-c++-common/pr68833-3.c: Likewise. * c-c++-common/raw-string-directive-1.c: Likewise. * gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise. * gcc.dg/binary-constants-4.c: Likewise. * gcc.dg/builtin-redefine.c: Likewise. * gcc.dg/cpp/19951025-1.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c23-elifdef-2.c: Likewise. * gcc.dg/cpp/c23-warning-2.c: Likewise. * gcc.dg/cpp/embed-2.c: Likewise. * gcc.dg/cpp/embed-3.c: Likewise. * gcc.dg/cpp/embed-4.c: Likewise. * gcc.dg/cpp/expr.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu23-warning-2.c: Likewise. * gcc.dg/cpp/include6.c: Likewise. * gcc.dg/cpp/pr35322.c: Likewise. * gcc.dg/cpp/tr-warn6.c: Likewise. * gcc.dg/cpp/undef2.c: Likewise. * gcc.dg/cpp/warn-comments.c: Likewise. * gcc.dg/cpp/warn-comments-2.c: Likewise. * gcc.dg/cpp/warn-comments-3.c: Likewise. * gcc.dg/cpp/warn-cxx-compat.c: Likewise. * gcc.dg/cpp/warn-cxx-compat-2.c: Likewise. * gcc.dg/cpp/warn-deprecated.c: Likewise. * gcc.dg/cpp/warn-deprecated-2.c: Likewise. * gcc.dg/cpp/warn-long-long.c: Likewise. * gcc.dg/cpp/warn-long-long-2.c: Likewise. * gcc.dg/cpp/warn-normalized-1.c: Likewise. * gcc.dg/cpp/warn-normalized-2.c: Likewise. * gcc.dg/cpp/warn-normalized-3.c: Likewise. * gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise. * gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise. * gcc.dg/cpp/warn-redefined.c: Likewise. * gcc.dg/cpp/warn-redefined-2.c: Likewise. * gcc.dg/cpp/warn-traditional.c: Likewise. * gcc.dg/cpp/warn-traditional-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-1.c: Likewise. * gcc.dg/cpp/warn-trigraphs-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-3.c: Likewise. * gcc.dg/cpp/warn-trigraphs-4.c: Likewise. * gcc.dg/cpp/warn-undef.c: Likewise. * gcc.dg/cpp/warn-undef-2.c: Likewise. * gcc.dg/cpp/warn-unused-macros.c: Likewise. * gcc.dg/cpp/warn-unused-macros-2.c: Likewise. * gcc.dg/pch/counter-2.c: Likewise. * g++.dg/cpp0x/udlit-error1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-1.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-3.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-4.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-5.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-6.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-7.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-8.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-9.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-10.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-11.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-12.C: Likewise. * g++.dg/cpp/elifdef-3.C: Likewise. * g++.dg/cpp/elifdef-5.C: Likewise. * g++.dg/cpp/elifdef-6.C: Likewise. * g++.dg/cpp/elifdef-7.C: Likewise. * g++.dg/cpp/embed-1.C: Likewise. * g++.dg/cpp/embed-2.C: Likewise. * g++.dg/cpp/pedantic-errors.C: Likewise. * g++.dg/cpp/warning-1.C: Likewise. * g++.dg/cpp/warning-2.C: Likewise. * g++.dg/ext/bitint1.C: Likewise. * g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
" %<:%> 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 06:07:53 +08:00
/* Check for and handle stack overflow. */
if (++top == pfile->op_limit)
top = _cpp_expand_op_stack (pfile);
1995-03-17 05:59:07 +08: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 18:51:15 +08:00
top->loc = op.loc;
1995-03-17 05:59:07 +08: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-15 02:42:47 +08: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 18:51:15 +08:00
cpp_error_with_line (pfile, CPP_DL_ICE, top->loc, 0,
libcpp, c-family: Add (dumb) C23 N3017 #embed support [PR105863] The following patch implements the C23 N3017 "#embed - a scannable, tooling-friendly binary resource inclusion mechanism" paper. The implementation is intentionally dumb, in that it doesn't significantly speed up compilation of larger initializers and doesn't make it possible to use huge #embeds (like several gigabytes large, that is compile time and memory still infeasible). There are 2 reasons for this. One is that I think like it is implemented now in the patch is how we should use it for the smaller #embed sizes, dunno with which boundary, whether 32 bytes or 64 or something like that, certainly handling the single byte cases which is something that can appear anywhere in the source where constant integer literal can appear is desirable and I think for a few bytes it isn't worth it to come up with something smarter and users would like to e.g. see it in -E readably as well (perhaps the slow vs. fast boundary should be determined by command line option). And the other one is to be able to more easily find regressions in behavior caused by the optimizations, so we have something to get back in git to compare against. I'm definitely willing to work on the optimizations (likely introduce a new CPP_* token type to refer to a range of libcpp owned memory (start + size) and similarly some tree which can do the same, and can be at any time e.g. split into 2 subparts + say INTEGER_CST in between if needed say for const unsigned char d[] = { #embed "2GB.dat" prefix (0, 0, ) suffix (, [0x40000000] = 42) }; still without having to copy around huge amounts of data; STRING_CST owns the memory it points to and can be only 2GB in size), but would like to do that incrementally. And would like to first include some extensions also not included in this patch, like gnu::offset (off) parameter to allow to skip certain constant amount of bytes at the start of the files, plus gnu::base64 ("base64_encoded_data") parameter to add something which can store more efficiently large amounts of the #embed data in preprocessed source. I've been cross-checking all the tests also against the LLVM implementation https://github.com/llvm/llvm-project/pull/68620 which has been for a few hours even committed to LLVM trunk but reverted afterwards. LLVM now has the support committed and I admit I haven't rechecked whether the behavior on the below mentioned spots have been fixed in it already or not yet. The patch uses --embed-dir= option that clang plans to add above and doesn't use other variants on the search directories yet, plus there are no default directories at least for the time being where to search for embed files. So, #embed "..." works if it is found in the same directory (or relative to the current file's directory) and #embed "/..." or #embed </...> work always, but relative #embed <...> doesn't unless at least one --embed-dir= is specified. There is no reason to differentiate between system and non-system directories, so we don't need -isystem like counterpart, perhaps -iquote like counterpart could be useful in the future, dunno what else. It has --embed-directory=dir and --embed-directory dir as aliases. There are some differences beyond clang ICEs, so I'd like to point them out to make sure there is agreement on the choices in the patch. They are also mentioned in the comments of the llvm pull request. The most important is that the GCC patch (as well as the original thephd.dev LLVM branch on godbolt) expands #embed (or acts as if it is expanded) into a mere sequence of numbers like 123,2,35,26 rather then what clang effectively treats as (unsigned char)123,(unsigned char)2,(unsigned char)35,(unsigned char)26 but only does that when using integrated preprocessor, not when using -save-temps where it acts as GCC. JeanHeyd as the original author agrees that is how it is currently worded in C23. Another difference (not tested in the testsuite, not sure how to check for effective target /dev/urandom nor am sure it is desirable to check that during testsuite) is how to treat character devices, named pipes etc. (block devices are errored on). The original paper uses /dev/urandom in various examples and seems to assume that unlike regular files the devices aren't really cached, so #embed </dev/urandom> limit(1) prefix(int a = ) suffix(;) #embed </dev/urandom> limit(1) prefix(int b = ) suffix(;) usually results in a != b. That is what the godbolt thephd.dev branch implements too and what this patch does as well, but clang actually seems to just go from st.st_size == 0, ergo it must be zero-sized resource and so just copies over if_empty if present. It is really questionable what to do about the character devices/named pipes with __has_embed, for regular files the patch doesn't read anything from them, relies on st.st_size + limit for whether it is empty or non-empty. But I don't know of a way to check if read on say a character device would read anything or not (the </dev/null> limit (1) vs. </dev/zero> limit (1) cases), and if we read something, that would be better cached for later because #embed later if it reads again could read no further data even when it first read something. So, the patch currently for __has_embed just always returns 2 on the non-regular files, like the thephd.dev branch does as well and like the clang pull request as well. A question is also what to do for gnu::offset on the non-regular files even for #embed, those aren't seekable and do we want to just read and throw away the offset bytes each time we see it used? clang also chokes on the #if __has_embed (__FILE__ __limit__ (1) __prefix__ () suffix (1 / 0) \ __if_empty__ ((({{[0[0{0{0(0(0)1)1}1}]]}})))) != __STDC_EMBED_FOUND__ #error "__has_embed fail" #endif in embed-1.c, but thephd.dev branch accepts it and I don't see why it shouldn't, (({{[0[0{0{0(0(0)1)1}1}]]}}))) is a balanced token sequence and the file isn't empty, so it should just be parsed and discarded. clang also IMHO mishandles const unsigned char w[] = { #embed __FILE__ prefix([0] = 42, [15] =) limit(32) }; but again only without -save-temps, seems like it treats it as [0] = 42, [15] = (99,111,110,115,116,32,117,110,115,105,103,110,101,100, 32,99,104,97,114,32,119,91,93,32,61,32,123,10,35,101,109,98) rather than [0] = 42, [15] = 99,111,110,115,116,32,117,110,115,105,103,110,101,100, 32,99,104,97,114,32,119,91,93,32,61,32,123,10,35,101,109,98 and warns on it for -Wunused-value and just compiles it as [0] = 42, [15] = 98 And also void foo (int, int, int, int); void bar (void) { foo ( #embed __FILE__ limit (4) prefix (172 + ) suffix (+ 2) ); } is treated as 172 + (118, 111, 105, 100) + 2 rather than 172 + 118, 111, 105, 100 + 2 which clang -save-temps or GCC treats it like, so results in just one argument passed rather than 4. if (!strstr ((const char *) magna_carta, "imprisonétur")) abort (); in the testcase fails as well, but in that case calling it in gdb succeeds: p ((char *(*)(char *, char *))__strstr_sse2) (magna_carta, "imprisonétur") $2 = 0x555555558d3c <magna_carta+11564> "imprisonétur aut disseisiátur"... so I guess they are just trying to constant evaluate strstr and do it incorrectly. They started with making the optimizations together in the initial patch set, so they don't have the luxury to compare if it is just because of the optimization they are trying to do or because that is how the feature works for them. At least unless they use -save-temps for now. There is also different behavior between clang and gcc on -M or other dependency generating options. Seems clang includes the __has_embed searched files in dependencies, while my patch doesn't. But so does clang for __has_include and GCC doesn't. Emitting a hard dependency on some header just because there was __has_include/__has_embed for it seems wrong to me, because (at least when properly written) the source likely doesn't mind if the file is missing, it will do something else, so a hard error from make because of it doesn't seem right. Does make have some weaker dependencies, such that if some file can be remade it is but if it doesn't exist, it isn't fatal? I wonder whether #embed <non-existent-file> really needs to be fatal or whether we could simply after diagnosing it pretend the file exists and is empty. For #include I think fatal errors make tons of sense, but perhaps for #embed which is more localized we'd get better error reporting if we didn't bail out immediately. Note, both GCC and clang currently treat those as fatal errors. clang also added -dE option which with -E instead of preprocessing the #embed directives keeps them as is, but the preprocessed source then isn't self-contained. That option looks more harmful than useful to me. Also, it isn't clear to me from C23 whether it is possible to have __has_include/__has_c_attribute/__has_embed expressions inside of the limit #embed/__has_embed argument. 6.10.3.2/2 says that defined should not appear there (and the patch diagnoses it and testsuite tests), but for __has_include/__has_embed etc. 6.10.1/11 says: "The identifiers __has_include, __has_embed, and __has_c_attribute shall not appear in any context not mentioned in this subclause." If that subclause in that case means 6.10.1, then it presumably shouldn't appear in #embed in 6.10.3, but __has_embed is in 6.10.1... But 6.10.3.2/3 says that it should be parsed according to the 6.10.1 rules. Haven't included tests like #if __has_embed (__FILE__ limit (__has_embed (__FILE__ limit (1)))) or #embed __FILE__ limit (__has_include (__FILE__)) into the testsuite because of the doubts but I think the patch should handle those right now. The reason I've used Magna Carta text in some of the testcases is that I hope it shouldn't be copyrighted after the centuries and I'd strongly prefer not to have binary blobs in git after the xz backdoor lesson and wanted something larger which doesn't change all the time. Oh, BTW, I see in C23 draft 6.10.3.2 in Example 4 if (f_source == NULL); return 1; (note the spurious semicolon after closing paren), has that been fixed already? Like the thephd.dev and clang implementations, the patch always macro expands the whole #embed and __has_embed directives except for the embed keyword. That is most likely not what C23 says, my limited understanding right now is that in #embed one needs to parse the whole directive line with macro expansion disabled and check if it satisfies the grammar, if not, the whole directive is macro expanded, if yes, only the limit parameter argument is macro expanded and the prefix/suffix/if_empty arguments are maybe macro expanded when actually used (and not at all if unused). And I think __has_embed macro expansion has conflicting rules. 2024-09-12 Jakub Jelinek <jakub@redhat.com> PR c/105863 libcpp/ * include/cpplib.h: Implement C23 N3017 #embed - a scannable, tooling-friendly binary resource inclusion mechanism paper. (struct cpp_options): Add embed member. (enum cpp_builtin_type): Add BT_HAS_EMBED. (cpp_set_include_chains): Add another cpp_dir * argument to the declaration. * internal.h (enum include_type): Add IT_EMBED. (struct cpp_reader): Add embed_include member. (struct cpp_embed_params_tokens): New type. (struct cpp_embed_params): New type. (_cpp_get_token_no_padding): Declare. (enum _cpp_find_file_kind): Add _cpp_FFK_EMBED and _cpp_FFK_HAS_EMBED. (_cpp_stack_embed): Declare. (_cpp_parse_expr): Change return type to cpp_num_part instead of bool, change second argument from bool to const char * and add third argument. (_cpp_parse_embed_params): Declare. * directives.cc (DIRECTIVE_TABLE): Add embed entry. (end_directive): Don't call skip_rest_of_line for T_EMBED directive. (_cpp_handle_directive): Return 2 rather than 1 for T_EMBED in directives-only mode. (parse_include): Don't Call check_eol for T_EMBED directive. (skip_balanced_token_seq): New function. (EMBED_PARAMS): Define. (enum embed_param_kind): New type. (embed_params): New variable. (_cpp_parse_embed_params): New function. (do_embed): New function. (do_if): Adjust _cpp_parse_expr caller. (do_elif): Likewise. * expr.cc (parse_defined): Diagnose defined in #embed or __has_embed parameters. (_cpp_parse_expr): Change return type to cpp_num_part instead of bool, change second argument from bool to const char * and add third argument. Adjust function comment. For #embed/__has_embed parameters add an artificial CPP_OPEN_PAREN. Use the second argument DIR directly instead of string literals conditional on IS_IF. For #embed/__has_embed parameter, stop on reaching CPP_CLOSE_PAREN matching the artificial one. Diagnose negative or too large embed parameter operands. (num_binary_op): Use #embed instead of #if for diagnostics if inside #embed/__has_embed parameter. (num_div_op): Likewise. * files.cc (struct _cpp_file): Add limit member and embed bitfield. (search_cache): Add IS_EMBED argument, formatting fix. Skip over files with different file->embed from the argument. (find_file_in_dir): Don't call pch_open_file if file->embed. (_cpp_find_file): Handle _cpp_FFK_EMBED and _cpp_FFK_HAS_EMBED. (read_file_guts): Formatting fix. (has_unique_contents): Ignore file->embed files. (search_path_head): Handle IT_EMBED type. (_cpp_stack_embed): New function. (_cpp_get_file_stat): Formatting fix. (cpp_set_include_chains): Add embed argument, save it to pfile->embed_include and compute lens for the chain. * init.cc (struct lang_flags): Add embed member. (lang_defaults): Add embed initializers. (cpp_set_lang): Initialize CPP_OPTION (pfile, embed). (builtin_array): Add __has_embed entry. (cpp_init_builtins): Predefine __STDC_EMBED_NOT_FOUND__, __STDC_EMBED_FOUND__ and __STDC_EMBED_EMPTY__. * lex.cc (cpp_directive_only_process): Handle #embed. * macro.cc (cpp_get_token_no_padding): Rename to ... (_cpp_get_token_no_padding): ... this. No longer static. (builtin_has_include_1): New function. (builtin_has_include): Use it. Use _cpp_get_token_no_padding instead of cpp_get_token_no_padding. (builtin_has_embed): New function. (_cpp_builtin_macro_text): Handle BT_HAS_EMBED. gcc/ * doc/cppdiropts.texi (--embed-dir=): Document. * doc/cpp.texi (Binary Resource Inclusion): New chapter. (__has_embed): Document. * doc/invoke.texi (Directory Options): Mention --embed-dir=. * gcc.cc (cpp_unique_options): Add %{-embed*}. * genmatch.cc (main): Adjust cpp_set_include_chains caller. * incpath.h (enum incpath_kind): Add INC_EMBED. * incpath.cc (merge_include_chains): Handle INC_EMBED. (register_include_chains): Adjust cpp_set_include_chains caller. gcc/c-family/ * c.opt (-embed-dir=): New option. (-embed-directory): New alias. (-embed-directory=): New alias. * c-opts.cc (c_common_handle_option): Handle OPT__embed_dir_. gcc/testsuite/ * c-c++-common/cpp/embed-1.c: New test. * c-c++-common/cpp/embed-2.c: New test. * c-c++-common/cpp/embed-3.c: New test. * c-c++-common/cpp/embed-4.c: New test. * c-c++-common/cpp/embed-5.c: New test. * c-c++-common/cpp/embed-6.c: New test. * c-c++-common/cpp/embed-7.c: New test. * c-c++-common/cpp/embed-8.c: New test. * c-c++-common/cpp/embed-9.c: New test. * c-c++-common/cpp/embed-10.c: New test. * c-c++-common/cpp/embed-11.c: New test. * c-c++-common/cpp/embed-12.c: New test. * c-c++-common/cpp/embed-13.c: New test. * c-c++-common/cpp/embed-14.c: New test. * c-c++-common/cpp/embed-25.c: New test. * c-c++-common/cpp/embed-26.c: New test. * c-c++-common/cpp/embed-dir/embed-1.inc: New test. * c-c++-common/cpp/embed-dir/embed-3.c: New test. * c-c++-common/cpp/embed-dir/embed-4.c: New test. * c-c++-common/cpp/embed-dir/magna-carta.txt: New test. * gcc.dg/cpp/embed-1.c: New test. * gcc.dg/cpp/embed-2.c: New test. * gcc.dg/cpp/embed-3.c: New test. * gcc.dg/cpp/embed-4.c: New test. * g++.dg/cpp/embed-1.C: New test. * g++.dg/cpp/embed-2.C: New test. * g++.dg/cpp/embed-3.C: New test.
2024-09-12 17:15:38 +08:00
"unbalanced stack in %s", dir);
syntax_error:
return false; /* Return false on syntax error. */
}
libcpp, c-family: Add (dumb) C23 N3017 #embed support [PR105863] The following patch implements the C23 N3017 "#embed - a scannable, tooling-friendly binary resource inclusion mechanism" paper. The implementation is intentionally dumb, in that it doesn't significantly speed up compilation of larger initializers and doesn't make it possible to use huge #embeds (like several gigabytes large, that is compile time and memory still infeasible). There are 2 reasons for this. One is that I think like it is implemented now in the patch is how we should use it for the smaller #embed sizes, dunno with which boundary, whether 32 bytes or 64 or something like that, certainly handling the single byte cases which is something that can appear anywhere in the source where constant integer literal can appear is desirable and I think for a few bytes it isn't worth it to come up with something smarter and users would like to e.g. see it in -E readably as well (perhaps the slow vs. fast boundary should be determined by command line option). And the other one is to be able to more easily find regressions in behavior caused by the optimizations, so we have something to get back in git to compare against. I'm definitely willing to work on the optimizations (likely introduce a new CPP_* token type to refer to a range of libcpp owned memory (start + size) and similarly some tree which can do the same, and can be at any time e.g. split into 2 subparts + say INTEGER_CST in between if needed say for const unsigned char d[] = { #embed "2GB.dat" prefix (0, 0, ) suffix (, [0x40000000] = 42) }; still without having to copy around huge amounts of data; STRING_CST owns the memory it points to and can be only 2GB in size), but would like to do that incrementally. And would like to first include some extensions also not included in this patch, like gnu::offset (off) parameter to allow to skip certain constant amount of bytes at the start of the files, plus gnu::base64 ("base64_encoded_data") parameter to add something which can store more efficiently large amounts of the #embed data in preprocessed source. I've been cross-checking all the tests also against the LLVM implementation https://github.com/llvm/llvm-project/pull/68620 which has been for a few hours even committed to LLVM trunk but reverted afterwards. LLVM now has the support committed and I admit I haven't rechecked whether the behavior on the below mentioned spots have been fixed in it already or not yet. The patch uses --embed-dir= option that clang plans to add above and doesn't use other variants on the search directories yet, plus there are no default directories at least for the time being where to search for embed files. So, #embed "..." works if it is found in the same directory (or relative to the current file's directory) and #embed "/..." or #embed </...> work always, but relative #embed <...> doesn't unless at least one --embed-dir= is specified. There is no reason to differentiate between system and non-system directories, so we don't need -isystem like counterpart, perhaps -iquote like counterpart could be useful in the future, dunno what else. It has --embed-directory=dir and --embed-directory dir as aliases. There are some differences beyond clang ICEs, so I'd like to point them out to make sure there is agreement on the choices in the patch. They are also mentioned in the comments of the llvm pull request. The most important is that the GCC patch (as well as the original thephd.dev LLVM branch on godbolt) expands #embed (or acts as if it is expanded) into a mere sequence of numbers like 123,2,35,26 rather then what clang effectively treats as (unsigned char)123,(unsigned char)2,(unsigned char)35,(unsigned char)26 but only does that when using integrated preprocessor, not when using -save-temps where it acts as GCC. JeanHeyd as the original author agrees that is how it is currently worded in C23. Another difference (not tested in the testsuite, not sure how to check for effective target /dev/urandom nor am sure it is desirable to check that during testsuite) is how to treat character devices, named pipes etc. (block devices are errored on). The original paper uses /dev/urandom in various examples and seems to assume that unlike regular files the devices aren't really cached, so #embed </dev/urandom> limit(1) prefix(int a = ) suffix(;) #embed </dev/urandom> limit(1) prefix(int b = ) suffix(;) usually results in a != b. That is what the godbolt thephd.dev branch implements too and what this patch does as well, but clang actually seems to just go from st.st_size == 0, ergo it must be zero-sized resource and so just copies over if_empty if present. It is really questionable what to do about the character devices/named pipes with __has_embed, for regular files the patch doesn't read anything from them, relies on st.st_size + limit for whether it is empty or non-empty. But I don't know of a way to check if read on say a character device would read anything or not (the </dev/null> limit (1) vs. </dev/zero> limit (1) cases), and if we read something, that would be better cached for later because #embed later if it reads again could read no further data even when it first read something. So, the patch currently for __has_embed just always returns 2 on the non-regular files, like the thephd.dev branch does as well and like the clang pull request as well. A question is also what to do for gnu::offset on the non-regular files even for #embed, those aren't seekable and do we want to just read and throw away the offset bytes each time we see it used? clang also chokes on the #if __has_embed (__FILE__ __limit__ (1) __prefix__ () suffix (1 / 0) \ __if_empty__ ((({{[0[0{0{0(0(0)1)1}1}]]}})))) != __STDC_EMBED_FOUND__ #error "__has_embed fail" #endif in embed-1.c, but thephd.dev branch accepts it and I don't see why it shouldn't, (({{[0[0{0{0(0(0)1)1}1}]]}}))) is a balanced token sequence and the file isn't empty, so it should just be parsed and discarded. clang also IMHO mishandles const unsigned char w[] = { #embed __FILE__ prefix([0] = 42, [15] =) limit(32) }; but again only without -save-temps, seems like it treats it as [0] = 42, [15] = (99,111,110,115,116,32,117,110,115,105,103,110,101,100, 32,99,104,97,114,32,119,91,93,32,61,32,123,10,35,101,109,98) rather than [0] = 42, [15] = 99,111,110,115,116,32,117,110,115,105,103,110,101,100, 32,99,104,97,114,32,119,91,93,32,61,32,123,10,35,101,109,98 and warns on it for -Wunused-value and just compiles it as [0] = 42, [15] = 98 And also void foo (int, int, int, int); void bar (void) { foo ( #embed __FILE__ limit (4) prefix (172 + ) suffix (+ 2) ); } is treated as 172 + (118, 111, 105, 100) + 2 rather than 172 + 118, 111, 105, 100 + 2 which clang -save-temps or GCC treats it like, so results in just one argument passed rather than 4. if (!strstr ((const char *) magna_carta, "imprisonétur")) abort (); in the testcase fails as well, but in that case calling it in gdb succeeds: p ((char *(*)(char *, char *))__strstr_sse2) (magna_carta, "imprisonétur") $2 = 0x555555558d3c <magna_carta+11564> "imprisonétur aut disseisiátur"... so I guess they are just trying to constant evaluate strstr and do it incorrectly. They started with making the optimizations together in the initial patch set, so they don't have the luxury to compare if it is just because of the optimization they are trying to do or because that is how the feature works for them. At least unless they use -save-temps for now. There is also different behavior between clang and gcc on -M or other dependency generating options. Seems clang includes the __has_embed searched files in dependencies, while my patch doesn't. But so does clang for __has_include and GCC doesn't. Emitting a hard dependency on some header just because there was __has_include/__has_embed for it seems wrong to me, because (at least when properly written) the source likely doesn't mind if the file is missing, it will do something else, so a hard error from make because of it doesn't seem right. Does make have some weaker dependencies, such that if some file can be remade it is but if it doesn't exist, it isn't fatal? I wonder whether #embed <non-existent-file> really needs to be fatal or whether we could simply after diagnosing it pretend the file exists and is empty. For #include I think fatal errors make tons of sense, but perhaps for #embed which is more localized we'd get better error reporting if we didn't bail out immediately. Note, both GCC and clang currently treat those as fatal errors. clang also added -dE option which with -E instead of preprocessing the #embed directives keeps them as is, but the preprocessed source then isn't self-contained. That option looks more harmful than useful to me. Also, it isn't clear to me from C23 whether it is possible to have __has_include/__has_c_attribute/__has_embed expressions inside of the limit #embed/__has_embed argument. 6.10.3.2/2 says that defined should not appear there (and the patch diagnoses it and testsuite tests), but for __has_include/__has_embed etc. 6.10.1/11 says: "The identifiers __has_include, __has_embed, and __has_c_attribute shall not appear in any context not mentioned in this subclause." If that subclause in that case means 6.10.1, then it presumably shouldn't appear in #embed in 6.10.3, but __has_embed is in 6.10.1... But 6.10.3.2/3 says that it should be parsed according to the 6.10.1 rules. Haven't included tests like #if __has_embed (__FILE__ limit (__has_embed (__FILE__ limit (1)))) or #embed __FILE__ limit (__has_include (__FILE__)) into the testsuite because of the doubts but I think the patch should handle those right now. The reason I've used Magna Carta text in some of the testcases is that I hope it shouldn't be copyrighted after the centuries and I'd strongly prefer not to have binary blobs in git after the xz backdoor lesson and wanted something larger which doesn't change all the time. Oh, BTW, I see in C23 draft 6.10.3.2 in Example 4 if (f_source == NULL); return 1; (note the spurious semicolon after closing paren), has that been fixed already? Like the thephd.dev and clang implementations, the patch always macro expands the whole #embed and __has_embed directives except for the embed keyword. That is most likely not what C23 says, my limited understanding right now is that in #embed one needs to parse the whole directive line with macro expansion disabled and check if it satisfies the grammar, if not, the whole directive is macro expanded, if yes, only the limit parameter argument is macro expanded and the prefix/suffix/if_empty arguments are maybe macro expanded when actually used (and not at all if unused). And I think __has_embed macro expansion has conflicting rules. 2024-09-12 Jakub Jelinek <jakub@redhat.com> PR c/105863 libcpp/ * include/cpplib.h: Implement C23 N3017 #embed - a scannable, tooling-friendly binary resource inclusion mechanism paper. (struct cpp_options): Add embed member. (enum cpp_builtin_type): Add BT_HAS_EMBED. (cpp_set_include_chains): Add another cpp_dir * argument to the declaration. * internal.h (enum include_type): Add IT_EMBED. (struct cpp_reader): Add embed_include member. (struct cpp_embed_params_tokens): New type. (struct cpp_embed_params): New type. (_cpp_get_token_no_padding): Declare. (enum _cpp_find_file_kind): Add _cpp_FFK_EMBED and _cpp_FFK_HAS_EMBED. (_cpp_stack_embed): Declare. (_cpp_parse_expr): Change return type to cpp_num_part instead of bool, change second argument from bool to const char * and add third argument. (_cpp_parse_embed_params): Declare. * directives.cc (DIRECTIVE_TABLE): Add embed entry. (end_directive): Don't call skip_rest_of_line for T_EMBED directive. (_cpp_handle_directive): Return 2 rather than 1 for T_EMBED in directives-only mode. (parse_include): Don't Call check_eol for T_EMBED directive. (skip_balanced_token_seq): New function. (EMBED_PARAMS): Define. (enum embed_param_kind): New type. (embed_params): New variable. (_cpp_parse_embed_params): New function. (do_embed): New function. (do_if): Adjust _cpp_parse_expr caller. (do_elif): Likewise. * expr.cc (parse_defined): Diagnose defined in #embed or __has_embed parameters. (_cpp_parse_expr): Change return type to cpp_num_part instead of bool, change second argument from bool to const char * and add third argument. Adjust function comment. For #embed/__has_embed parameters add an artificial CPP_OPEN_PAREN. Use the second argument DIR directly instead of string literals conditional on IS_IF. For #embed/__has_embed parameter, stop on reaching CPP_CLOSE_PAREN matching the artificial one. Diagnose negative or too large embed parameter operands. (num_binary_op): Use #embed instead of #if for diagnostics if inside #embed/__has_embed parameter. (num_div_op): Likewise. * files.cc (struct _cpp_file): Add limit member and embed bitfield. (search_cache): Add IS_EMBED argument, formatting fix. Skip over files with different file->embed from the argument. (find_file_in_dir): Don't call pch_open_file if file->embed. (_cpp_find_file): Handle _cpp_FFK_EMBED and _cpp_FFK_HAS_EMBED. (read_file_guts): Formatting fix. (has_unique_contents): Ignore file->embed files. (search_path_head): Handle IT_EMBED type. (_cpp_stack_embed): New function. (_cpp_get_file_stat): Formatting fix. (cpp_set_include_chains): Add embed argument, save it to pfile->embed_include and compute lens for the chain. * init.cc (struct lang_flags): Add embed member. (lang_defaults): Add embed initializers. (cpp_set_lang): Initialize CPP_OPTION (pfile, embed). (builtin_array): Add __has_embed entry. (cpp_init_builtins): Predefine __STDC_EMBED_NOT_FOUND__, __STDC_EMBED_FOUND__ and __STDC_EMBED_EMPTY__. * lex.cc (cpp_directive_only_process): Handle #embed. * macro.cc (cpp_get_token_no_padding): Rename to ... (_cpp_get_token_no_padding): ... this. No longer static. (builtin_has_include_1): New function. (builtin_has_include): Use it. Use _cpp_get_token_no_padding instead of cpp_get_token_no_padding. (builtin_has_embed): New function. (_cpp_builtin_macro_text): Handle BT_HAS_EMBED. gcc/ * doc/cppdiropts.texi (--embed-dir=): Document. * doc/cpp.texi (Binary Resource Inclusion): New chapter. (__has_embed): Document. * doc/invoke.texi (Directory Options): Mention --embed-dir=. * gcc.cc (cpp_unique_options): Add %{-embed*}. * genmatch.cc (main): Adjust cpp_set_include_chains caller. * incpath.h (enum incpath_kind): Add INC_EMBED. * incpath.cc (merge_include_chains): Handle INC_EMBED. (register_include_chains): Adjust cpp_set_include_chains caller. gcc/c-family/ * c.opt (-embed-dir=): New option. (-embed-directory): New alias. (-embed-directory=): New alias. * c-opts.cc (c_common_handle_option): Handle OPT__embed_dir_. gcc/testsuite/ * c-c++-common/cpp/embed-1.c: New test. * c-c++-common/cpp/embed-2.c: New test. * c-c++-common/cpp/embed-3.c: New test. * c-c++-common/cpp/embed-4.c: New test. * c-c++-common/cpp/embed-5.c: New test. * c-c++-common/cpp/embed-6.c: New test. * c-c++-common/cpp/embed-7.c: New test. * c-c++-common/cpp/embed-8.c: New test. * c-c++-common/cpp/embed-9.c: New test. * c-c++-common/cpp/embed-10.c: New test. * c-c++-common/cpp/embed-11.c: New test. * c-c++-common/cpp/embed-12.c: New test. * c-c++-common/cpp/embed-13.c: New test. * c-c++-common/cpp/embed-14.c: New test. * c-c++-common/cpp/embed-25.c: New test. * c-c++-common/cpp/embed-26.c: New test. * c-c++-common/cpp/embed-dir/embed-1.inc: New test. * c-c++-common/cpp/embed-dir/embed-3.c: New test. * c-c++-common/cpp/embed-dir/embed-4.c: New test. * c-c++-common/cpp/embed-dir/magna-carta.txt: New test. * gcc.dg/cpp/embed-1.c: New test. * gcc.dg/cpp/embed-2.c: New test. * gcc.dg/cpp/embed-3.c: New test. * gcc.dg/cpp/embed-4.c: New test. * g++.dg/cpp/embed-1.C: New test. * g++.dg/cpp/embed-2.C: New test. * g++.dg/cpp/embed-3.C: New test.
2024-09-12 17:15:38 +08:00
if (pfile->state.in_directive == 3)
{
embed_done:
if (num_zerop (top->value))
return 0;
if (!top->value.unsignedp
&& !num_positive (top->value, CPP_OPTION (pfile, precision)))
{
cpp_error_with_line (pfile, CPP_DL_ERROR, top->loc, 0,
"negative embed parameter operand");
return 1;
}
if (top->value.high)
{
cpp_error_with_line (pfile, CPP_DL_ERROR, top->loc, 0,
"too large embed parameter operand");
return 1;
}
return top->value.low;
}
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,
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics When working on #embed support, or -Wheader-guard or other recent libcpp changes, I've been annoyed by the libcpp diagnostics being visually different from normal gcc diagnostics, especially in the area of quoting stuff in the diagnostic messages. Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use %</%>, %qs etc. in there, while libcpp diagnostics was marked as printf and in libcpp we've been very creative with quoting stuff, either no quotes at all, or "something" quoting, or 'something' quoting, or `something' quoting (but in none of the cases it used colors consistently with the rest of the compiler). Now, libcpp diagnostics is always emitted using a callback, pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with genmatch.cc: cb->diagnostic = diagnostic_cb; c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic; fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic; where the latter two just use diagnostic_report_diagnostic, so actually support all the gcc_diag stuff, only the genmatch.cc case didn't. So, the following patch changes genmatch.cc to use pp_format* instead of vfprintf so that it supports the gcc_diag formatting (pretty-print.o unfortunately has various dependencies, so had to link genmatch with libcommon.a libbacktrace.a and tweak Makefile.in so that there are no circular dependencies) and marks the libcpp diagnostic routines as gcc_diag rather than printf. That change resulted in hundreds of -Wformat-diag new warnings (most of them useful and resulting IMHO in better diagnostics), so the rest of the patch is changing the format strings to make -Wformat-diag happy and adjusting the testsuite for the differences in how is the diagnostic reformatted. Dunno if some out of GCC tree projects use libcpp, that case would make it harder because one couldn't use vfprintf in the diagnostic callback anymore, but there is always David's libdiagnostic which could be used for that purpose IMHO. 2024-10-12 Jakub Jelinek <jakub@redhat.com> libcpp/ * include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define. (struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF on diagnostic callback. (cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3. (cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. (cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6) instead of ATTRIBUTE_PRINTF_5. (cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. * Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather than --language=c. * errors.cc (cpp_diagnostic_at, cpp_diagnostic, cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of -ATTRIBUTE_FPTR_PRINTF. * charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex, convert_oct, convert_escape): Fix up -Wformat-diag warnings. (cpp_interpret_string_ranges, count_source_chars): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF. (narrow_str_to_charconst): Fix up -Wformat-diag warnings. * directives.cc (check_eol_1, directive_diagnostics, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, do_include_next, _cpp_parse_embed_params, do_embed, read_flag, do_line, do_linemarker, register_pragma_1, do_pragma_once, do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison, do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, do_assert, cpp_define_unused): Likewise. * expr.cc (cpp_classify_number, parse_defined, eval_token, _cpp_parse_expr, reduce, check_promotion): Likewise. * files.cc (_cpp_find_file, finish_base64_embed, _cpp_pop_file_buffer): Likewise. * init.cc (sanity_checks): Likewise. * lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char, _cpp_warn_invalid_utf8, _cpp_skip_block_comment, warn_about_normalization, forms_identifier_p, maybe_va_opt_error, identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise. * macro.cc (class vaopt_state, builtin_has_include_1, builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro, _cpp_builtin_macro_text, builtin_macro, stringify_arg, _cpp_arguments_ok, collect_args, enter_macro_context, _cpp_save_parameter, parse_params, create_iso_definition, _cpp_create_definition, check_trad_stringification): Likewise. * pch.cc (cpp_valid_state): Likewise. * traditional.cc (_cpp_scan_out_logical_line, recursive_macro): Likewise. gcc/ * Makefile.in (generated_files): Remove {gimple,generic}-match*. (generated_match_files): New variable. Add a dependency of $(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those. (build/genmatch$(build_exeext)): Depend on and link against libcommon.a and $(LIBBACKTRACE). * genmatch.cc: Include pretty-print.h and input.h. (ggc_internal_cleared_alloc, ggc_free): Remove. (fatal): New function. (line_table): Remove. (linemap_client_expand_location_to_spelling_point): Remove. (diagnostic_cb): Use gcc_diag rather than printf format. Use pp_format_verbatim on a temporary pretty_printer instead of vfprintf. (fatal_at, warning_at): Use gcc_diag rather than printf format. (output_line_directive): Rename location_hash to loc_hash. (parser::eat_ident, parser::parse_operation, parser::parse_expr, parser::parse_pattern, parser::finish_match_operand): Fix up -Wformat-diag warnings. gcc/c-family/ * c-lex.cc (c_common_has_attribute, c_common_lex_availability_macro): Fix up -Wformat-diag warnings. gcc/testsuite/ * c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for libcpp diagnostic formatting changes. * c-c++-common/cpp/embed-3.c: Likewise. * c-c++-common/cpp/embed-4.c: Likewise. * c-c++-common/cpp/embed-16.c: Likewise. * c-c++-common/cpp/embed-18.c: Likewise. * c-c++-common/cpp/eof-2.c: Likewise. * c-c++-common/cpp/eof-3.c: Likewise. * c-c++-common/cpp/fmax-include-depth.c: Likewise. * c-c++-common/cpp/has-builtin.c: Likewise. * c-c++-common/cpp/line-2.c: Likewise. * c-c++-common/cpp/line-3.c: Likewise. * c-c++-common/cpp/macro-arg-count-1.c: Likewise. * c-c++-common/cpp/macro-arg-count-2.c: Likewise. * c-c++-common/cpp/macro-ranges.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-4.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-5.c: Likewise. * c-c++-common/cpp/pr88974.c: Likewise. * c-c++-common/cpp/va-opt-error.c: Likewise. * c-c++-common/cpp/va-opt-pedantic.c: Likewise. * c-c++-common/cpp/Wheader-guard-2.c: Likewise. * c-c++-common/cpp/Wheader-guard-3.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-1.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-2.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-3.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c: Likewise. * c-c++-common/pr68833-3.c: Likewise. * c-c++-common/raw-string-directive-1.c: Likewise. * gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise. * gcc.dg/binary-constants-4.c: Likewise. * gcc.dg/builtin-redefine.c: Likewise. * gcc.dg/cpp/19951025-1.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c23-elifdef-2.c: Likewise. * gcc.dg/cpp/c23-warning-2.c: Likewise. * gcc.dg/cpp/embed-2.c: Likewise. * gcc.dg/cpp/embed-3.c: Likewise. * gcc.dg/cpp/embed-4.c: Likewise. * gcc.dg/cpp/expr.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu23-warning-2.c: Likewise. * gcc.dg/cpp/include6.c: Likewise. * gcc.dg/cpp/pr35322.c: Likewise. * gcc.dg/cpp/tr-warn6.c: Likewise. * gcc.dg/cpp/undef2.c: Likewise. * gcc.dg/cpp/warn-comments.c: Likewise. * gcc.dg/cpp/warn-comments-2.c: Likewise. * gcc.dg/cpp/warn-comments-3.c: Likewise. * gcc.dg/cpp/warn-cxx-compat.c: Likewise. * gcc.dg/cpp/warn-cxx-compat-2.c: Likewise. * gcc.dg/cpp/warn-deprecated.c: Likewise. * gcc.dg/cpp/warn-deprecated-2.c: Likewise. * gcc.dg/cpp/warn-long-long.c: Likewise. * gcc.dg/cpp/warn-long-long-2.c: Likewise. * gcc.dg/cpp/warn-normalized-1.c: Likewise. * gcc.dg/cpp/warn-normalized-2.c: Likewise. * gcc.dg/cpp/warn-normalized-3.c: Likewise. * gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise. * gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise. * gcc.dg/cpp/warn-redefined.c: Likewise. * gcc.dg/cpp/warn-redefined-2.c: Likewise. * gcc.dg/cpp/warn-traditional.c: Likewise. * gcc.dg/cpp/warn-traditional-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-1.c: Likewise. * gcc.dg/cpp/warn-trigraphs-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-3.c: Likewise. * gcc.dg/cpp/warn-trigraphs-4.c: Likewise. * gcc.dg/cpp/warn-undef.c: Likewise. * gcc.dg/cpp/warn-undef-2.c: Likewise. * gcc.dg/cpp/warn-unused-macros.c: Likewise. * gcc.dg/cpp/warn-unused-macros-2.c: Likewise. * gcc.dg/pch/counter-2.c: Likewise. * g++.dg/cpp0x/udlit-error1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-1.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-3.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-4.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-5.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-6.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-7.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-8.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-9.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-10.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-11.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-12.C: Likewise. * g++.dg/cpp/elifdef-3.C: Likewise. * g++.dg/cpp/elifdef-5.C: Likewise. * g++.dg/cpp/elifdef-6.C: Likewise. * g++.dg/cpp/elifdef-7.C: Likewise. * g++.dg/cpp/embed-1.C: Likewise. * g++.dg/cpp/embed-2.C: Likewise. * g++.dg/cpp/pedantic-errors.C: Likewise. * g++.dg/cpp/warning-1.C: Likewise. * g++.dg/cpp/warning-2.C: Likewise. * g++.dg/ext/bitint1.C: Likewise. * g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
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;
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics When working on #embed support, or -Wheader-guard or other recent libcpp changes, I've been annoyed by the libcpp diagnostics being visually different from normal gcc diagnostics, especially in the area of quoting stuff in the diagnostic messages. Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use %</%>, %qs etc. in there, while libcpp diagnostics was marked as printf and in libcpp we've been very creative with quoting stuff, either no quotes at all, or "something" quoting, or 'something' quoting, or `something' quoting (but in none of the cases it used colors consistently with the rest of the compiler). Now, libcpp diagnostics is always emitted using a callback, pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with genmatch.cc: cb->diagnostic = diagnostic_cb; c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic; fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic; where the latter two just use diagnostic_report_diagnostic, so actually support all the gcc_diag stuff, only the genmatch.cc case didn't. So, the following patch changes genmatch.cc to use pp_format* instead of vfprintf so that it supports the gcc_diag formatting (pretty-print.o unfortunately has various dependencies, so had to link genmatch with libcommon.a libbacktrace.a and tweak Makefile.in so that there are no circular dependencies) and marks the libcpp diagnostic routines as gcc_diag rather than printf. That change resulted in hundreds of -Wformat-diag new warnings (most of them useful and resulting IMHO in better diagnostics), so the rest of the patch is changing the format strings to make -Wformat-diag happy and adjusting the testsuite for the differences in how is the diagnostic reformatted. Dunno if some out of GCC tree projects use libcpp, that case would make it harder because one couldn't use vfprintf in the diagnostic callback anymore, but there is always David's libdiagnostic which could be used for that purpose IMHO. 2024-10-12 Jakub Jelinek <jakub@redhat.com> libcpp/ * include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define. (struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF on diagnostic callback. (cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3. (cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. (cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6) instead of ATTRIBUTE_PRINTF_5. (cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. * Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather than --language=c. * errors.cc (cpp_diagnostic_at, cpp_diagnostic, cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of -ATTRIBUTE_FPTR_PRINTF. * charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex, convert_oct, convert_escape): Fix up -Wformat-diag warnings. (cpp_interpret_string_ranges, count_source_chars): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF. (narrow_str_to_charconst): Fix up -Wformat-diag warnings. * directives.cc (check_eol_1, directive_diagnostics, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, do_include_next, _cpp_parse_embed_params, do_embed, read_flag, do_line, do_linemarker, register_pragma_1, do_pragma_once, do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison, do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, do_assert, cpp_define_unused): Likewise. * expr.cc (cpp_classify_number, parse_defined, eval_token, _cpp_parse_expr, reduce, check_promotion): Likewise. * files.cc (_cpp_find_file, finish_base64_embed, _cpp_pop_file_buffer): Likewise. * init.cc (sanity_checks): Likewise. * lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char, _cpp_warn_invalid_utf8, _cpp_skip_block_comment, warn_about_normalization, forms_identifier_p, maybe_va_opt_error, identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise. * macro.cc (class vaopt_state, builtin_has_include_1, builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro, _cpp_builtin_macro_text, builtin_macro, stringify_arg, _cpp_arguments_ok, collect_args, enter_macro_context, _cpp_save_parameter, parse_params, create_iso_definition, _cpp_create_definition, check_trad_stringification): Likewise. * pch.cc (cpp_valid_state): Likewise. * traditional.cc (_cpp_scan_out_logical_line, recursive_macro): Likewise. gcc/ * Makefile.in (generated_files): Remove {gimple,generic}-match*. (generated_match_files): New variable. Add a dependency of $(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those. (build/genmatch$(build_exeext)): Depend on and link against libcommon.a and $(LIBBACKTRACE). * genmatch.cc: Include pretty-print.h and input.h. (ggc_internal_cleared_alloc, ggc_free): Remove. (fatal): New function. (line_table): Remove. (linemap_client_expand_location_to_spelling_point): Remove. (diagnostic_cb): Use gcc_diag rather than printf format. Use pp_format_verbatim on a temporary pretty_printer instead of vfprintf. (fatal_at, warning_at): Use gcc_diag rather than printf format. (output_line_directive): Rename location_hash to loc_hash. (parser::eat_ident, parser::parse_operation, parser::parse_expr, parser::parse_pattern, parser::finish_match_operand): Fix up -Wformat-diag warnings. gcc/c-family/ * c-lex.cc (c_common_has_attribute, c_common_lex_availability_macro): Fix up -Wformat-diag warnings. gcc/testsuite/ * c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for libcpp diagnostic formatting changes. * c-c++-common/cpp/embed-3.c: Likewise. * c-c++-common/cpp/embed-4.c: Likewise. * c-c++-common/cpp/embed-16.c: Likewise. * c-c++-common/cpp/embed-18.c: Likewise. * c-c++-common/cpp/eof-2.c: Likewise. * c-c++-common/cpp/eof-3.c: Likewise. * c-c++-common/cpp/fmax-include-depth.c: Likewise. * c-c++-common/cpp/has-builtin.c: Likewise. * c-c++-common/cpp/line-2.c: Likewise. * c-c++-common/cpp/line-3.c: Likewise. * c-c++-common/cpp/macro-arg-count-1.c: Likewise. * c-c++-common/cpp/macro-arg-count-2.c: Likewise. * c-c++-common/cpp/macro-ranges.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-4.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-5.c: Likewise. * c-c++-common/cpp/pr88974.c: Likewise. * c-c++-common/cpp/va-opt-error.c: Likewise. * c-c++-common/cpp/va-opt-pedantic.c: Likewise. * c-c++-common/cpp/Wheader-guard-2.c: Likewise. * c-c++-common/cpp/Wheader-guard-3.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-1.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-2.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-3.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c: Likewise. * c-c++-common/pr68833-3.c: Likewise. * c-c++-common/raw-string-directive-1.c: Likewise. * gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise. * gcc.dg/binary-constants-4.c: Likewise. * gcc.dg/builtin-redefine.c: Likewise. * gcc.dg/cpp/19951025-1.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c23-elifdef-2.c: Likewise. * gcc.dg/cpp/c23-warning-2.c: Likewise. * gcc.dg/cpp/embed-2.c: Likewise. * gcc.dg/cpp/embed-3.c: Likewise. * gcc.dg/cpp/embed-4.c: Likewise. * gcc.dg/cpp/expr.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu23-warning-2.c: Likewise. * gcc.dg/cpp/include6.c: Likewise. * gcc.dg/cpp/pr35322.c: Likewise. * gcc.dg/cpp/tr-warn6.c: Likewise. * gcc.dg/cpp/undef2.c: Likewise. * gcc.dg/cpp/warn-comments.c: Likewise. * gcc.dg/cpp/warn-comments-2.c: Likewise. * gcc.dg/cpp/warn-comments-3.c: Likewise. * gcc.dg/cpp/warn-cxx-compat.c: Likewise. * gcc.dg/cpp/warn-cxx-compat-2.c: Likewise. * gcc.dg/cpp/warn-deprecated.c: Likewise. * gcc.dg/cpp/warn-deprecated-2.c: Likewise. * gcc.dg/cpp/warn-long-long.c: Likewise. * gcc.dg/cpp/warn-long-long-2.c: Likewise. * gcc.dg/cpp/warn-normalized-1.c: Likewise. * gcc.dg/cpp/warn-normalized-2.c: Likewise. * gcc.dg/cpp/warn-normalized-3.c: Likewise. * gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise. * gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise. * gcc.dg/cpp/warn-redefined.c: Likewise. * gcc.dg/cpp/warn-redefined-2.c: Likewise. * gcc.dg/cpp/warn-traditional.c: Likewise. * gcc.dg/cpp/warn-traditional-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-1.c: Likewise. * gcc.dg/cpp/warn-trigraphs-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-3.c: Likewise. * gcc.dg/cpp/warn-trigraphs-4.c: Likewise. * gcc.dg/cpp/warn-undef.c: Likewise. * gcc.dg/cpp/warn-undef-2.c: Likewise. * gcc.dg/cpp/warn-unused-macros.c: Likewise. * gcc.dg/cpp/warn-unused-macros-2.c: Likewise. * gcc.dg/pch/counter-2.c: Likewise. * g++.dg/cpp0x/udlit-error1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-1.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-3.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-4.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-5.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-6.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-7.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-8.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-9.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-10.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-11.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-12.C: Likewise. * g++.dg/cpp/elifdef-3.C: Likewise. * g++.dg/cpp/elifdef-5.C: Likewise. * g++.dg/cpp/elifdef-6.C: Likewise. * g++.dg/cpp/elifdef-7.C: Likewise. * g++.dg/cpp/embed-1.C: Likewise. * g++.dg/cpp/embed-2.C: Likewise. * g++.dg/cpp/pedantic-errors.C: Likewise. * g++.dg/cpp/warning-1.C: Likewise. * g++.dg/cpp/warning-2.C: Likewise. * g++.dg/ext/bitint1.C: Likewise. * g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
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)
{
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics When working on #embed support, or -Wheader-guard or other recent libcpp changes, I've been annoyed by the libcpp diagnostics being visually different from normal gcc diagnostics, especially in the area of quoting stuff in the diagnostic messages. Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use %</%>, %qs etc. in there, while libcpp diagnostics was marked as printf and in libcpp we've been very creative with quoting stuff, either no quotes at all, or "something" quoting, or 'something' quoting, or `something' quoting (but in none of the cases it used colors consistently with the rest of the compiler). Now, libcpp diagnostics is always emitted using a callback, pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with genmatch.cc: cb->diagnostic = diagnostic_cb; c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic; fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic; where the latter two just use diagnostic_report_diagnostic, so actually support all the gcc_diag stuff, only the genmatch.cc case didn't. So, the following patch changes genmatch.cc to use pp_format* instead of vfprintf so that it supports the gcc_diag formatting (pretty-print.o unfortunately has various dependencies, so had to link genmatch with libcommon.a libbacktrace.a and tweak Makefile.in so that there are no circular dependencies) and marks the libcpp diagnostic routines as gcc_diag rather than printf. That change resulted in hundreds of -Wformat-diag new warnings (most of them useful and resulting IMHO in better diagnostics), so the rest of the patch is changing the format strings to make -Wformat-diag happy and adjusting the testsuite for the differences in how is the diagnostic reformatted. Dunno if some out of GCC tree projects use libcpp, that case would make it harder because one couldn't use vfprintf in the diagnostic callback anymore, but there is always David's libdiagnostic which could be used for that purpose IMHO. 2024-10-12 Jakub Jelinek <jakub@redhat.com> libcpp/ * include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define. (struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF on diagnostic callback. (cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3. (cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. (cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6) instead of ATTRIBUTE_PRINTF_5. (cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. * Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather than --language=c. * errors.cc (cpp_diagnostic_at, cpp_diagnostic, cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of -ATTRIBUTE_FPTR_PRINTF. * charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex, convert_oct, convert_escape): Fix up -Wformat-diag warnings. (cpp_interpret_string_ranges, count_source_chars): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF. (narrow_str_to_charconst): Fix up -Wformat-diag warnings. * directives.cc (check_eol_1, directive_diagnostics, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, do_include_next, _cpp_parse_embed_params, do_embed, read_flag, do_line, do_linemarker, register_pragma_1, do_pragma_once, do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison, do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, do_assert, cpp_define_unused): Likewise. * expr.cc (cpp_classify_number, parse_defined, eval_token, _cpp_parse_expr, reduce, check_promotion): Likewise. * files.cc (_cpp_find_file, finish_base64_embed, _cpp_pop_file_buffer): Likewise. * init.cc (sanity_checks): Likewise. * lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char, _cpp_warn_invalid_utf8, _cpp_skip_block_comment, warn_about_normalization, forms_identifier_p, maybe_va_opt_error, identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise. * macro.cc (class vaopt_state, builtin_has_include_1, builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro, _cpp_builtin_macro_text, builtin_macro, stringify_arg, _cpp_arguments_ok, collect_args, enter_macro_context, _cpp_save_parameter, parse_params, create_iso_definition, _cpp_create_definition, check_trad_stringification): Likewise. * pch.cc (cpp_valid_state): Likewise. * traditional.cc (_cpp_scan_out_logical_line, recursive_macro): Likewise. gcc/ * Makefile.in (generated_files): Remove {gimple,generic}-match*. (generated_match_files): New variable. Add a dependency of $(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those. (build/genmatch$(build_exeext)): Depend on and link against libcommon.a and $(LIBBACKTRACE). * genmatch.cc: Include pretty-print.h and input.h. (ggc_internal_cleared_alloc, ggc_free): Remove. (fatal): New function. (line_table): Remove. (linemap_client_expand_location_to_spelling_point): Remove. (diagnostic_cb): Use gcc_diag rather than printf format. Use pp_format_verbatim on a temporary pretty_printer instead of vfprintf. (fatal_at, warning_at): Use gcc_diag rather than printf format. (output_line_directive): Rename location_hash to loc_hash. (parser::eat_ident, parser::parse_operation, parser::parse_expr, parser::parse_pattern, parser::finish_match_operand): Fix up -Wformat-diag warnings. gcc/c-family/ * c-lex.cc (c_common_has_attribute, c_common_lex_availability_macro): Fix up -Wformat-diag warnings. gcc/testsuite/ * c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for libcpp diagnostic formatting changes. * c-c++-common/cpp/embed-3.c: Likewise. * c-c++-common/cpp/embed-4.c: Likewise. * c-c++-common/cpp/embed-16.c: Likewise. * c-c++-common/cpp/embed-18.c: Likewise. * c-c++-common/cpp/eof-2.c: Likewise. * c-c++-common/cpp/eof-3.c: Likewise. * c-c++-common/cpp/fmax-include-depth.c: Likewise. * c-c++-common/cpp/has-builtin.c: Likewise. * c-c++-common/cpp/line-2.c: Likewise. * c-c++-common/cpp/line-3.c: Likewise. * c-c++-common/cpp/macro-arg-count-1.c: Likewise. * c-c++-common/cpp/macro-arg-count-2.c: Likewise. * c-c++-common/cpp/macro-ranges.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-4.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-5.c: Likewise. * c-c++-common/cpp/pr88974.c: Likewise. * c-c++-common/cpp/va-opt-error.c: Likewise. * c-c++-common/cpp/va-opt-pedantic.c: Likewise. * c-c++-common/cpp/Wheader-guard-2.c: Likewise. * c-c++-common/cpp/Wheader-guard-3.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-1.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-2.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-3.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c: Likewise. * c-c++-common/pr68833-3.c: Likewise. * c-c++-common/raw-string-directive-1.c: Likewise. * gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise. * gcc.dg/binary-constants-4.c: Likewise. * gcc.dg/builtin-redefine.c: Likewise. * gcc.dg/cpp/19951025-1.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c23-elifdef-2.c: Likewise. * gcc.dg/cpp/c23-warning-2.c: Likewise. * gcc.dg/cpp/embed-2.c: Likewise. * gcc.dg/cpp/embed-3.c: Likewise. * gcc.dg/cpp/embed-4.c: Likewise. * gcc.dg/cpp/expr.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu23-warning-2.c: Likewise. * gcc.dg/cpp/include6.c: Likewise. * gcc.dg/cpp/pr35322.c: Likewise. * gcc.dg/cpp/tr-warn6.c: Likewise. * gcc.dg/cpp/undef2.c: Likewise. * gcc.dg/cpp/warn-comments.c: Likewise. * gcc.dg/cpp/warn-comments-2.c: Likewise. * gcc.dg/cpp/warn-comments-3.c: Likewise. * gcc.dg/cpp/warn-cxx-compat.c: Likewise. * gcc.dg/cpp/warn-cxx-compat-2.c: Likewise. * gcc.dg/cpp/warn-deprecated.c: Likewise. * gcc.dg/cpp/warn-deprecated-2.c: Likewise. * gcc.dg/cpp/warn-long-long.c: Likewise. * gcc.dg/cpp/warn-long-long-2.c: Likewise. * gcc.dg/cpp/warn-normalized-1.c: Likewise. * gcc.dg/cpp/warn-normalized-2.c: Likewise. * gcc.dg/cpp/warn-normalized-3.c: Likewise. * gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise. * gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise. * gcc.dg/cpp/warn-redefined.c: Likewise. * gcc.dg/cpp/warn-redefined-2.c: Likewise. * gcc.dg/cpp/warn-traditional.c: Likewise. * gcc.dg/cpp/warn-traditional-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-1.c: Likewise. * gcc.dg/cpp/warn-trigraphs-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-3.c: Likewise. * gcc.dg/cpp/warn-trigraphs-4.c: Likewise. * gcc.dg/cpp/warn-undef.c: Likewise. * gcc.dg/cpp/warn-undef-2.c: Likewise. * gcc.dg/cpp/warn-unused-macros.c: Likewise. * gcc.dg/cpp/warn-unused-macros-2.c: Likewise. * gcc.dg/pch/counter-2.c: Likewise. * g++.dg/cpp0x/udlit-error1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-1.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-3.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-4.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-5.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-6.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-7.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-8.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-9.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-10.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-11.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-12.C: Likewise. * g++.dg/cpp/elifdef-3.C: Likewise. * g++.dg/cpp/elifdef-5.C: Likewise. * g++.dg/cpp/elifdef-6.C: Likewise. * g++.dg/cpp/elifdef-7.C: Likewise. * g++.dg/cpp/embed-1.C: Likewise. * g++.dg/cpp/embed-2.C: Likewise. * g++.dg/cpp/pedantic-errors.C: Likewise. * g++.dg/cpp/warning-1.C: Likewise. * g++.dg/cpp/warning-2.C: Likewise. * g++.dg/ext/bitint1.C: Likewise. * g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
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 23:52:48 +08: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-17 05:59:07 +08: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,
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics When working on #embed support, or -Wheader-guard or other recent libcpp changes, I've been annoyed by the libcpp diagnostics being visually different from normal gcc diagnostics, especially in the area of quoting stuff in the diagnostic messages. Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use %</%>, %qs etc. in there, while libcpp diagnostics was marked as printf and in libcpp we've been very creative with quoting stuff, either no quotes at all, or "something" quoting, or 'something' quoting, or `something' quoting (but in none of the cases it used colors consistently with the rest of the compiler). Now, libcpp diagnostics is always emitted using a callback, pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with genmatch.cc: cb->diagnostic = diagnostic_cb; c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic; fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic; where the latter two just use diagnostic_report_diagnostic, so actually support all the gcc_diag stuff, only the genmatch.cc case didn't. So, the following patch changes genmatch.cc to use pp_format* instead of vfprintf so that it supports the gcc_diag formatting (pretty-print.o unfortunately has various dependencies, so had to link genmatch with libcommon.a libbacktrace.a and tweak Makefile.in so that there are no circular dependencies) and marks the libcpp diagnostic routines as gcc_diag rather than printf. That change resulted in hundreds of -Wformat-diag new warnings (most of them useful and resulting IMHO in better diagnostics), so the rest of the patch is changing the format strings to make -Wformat-diag happy and adjusting the testsuite for the differences in how is the diagnostic reformatted. Dunno if some out of GCC tree projects use libcpp, that case would make it harder because one couldn't use vfprintf in the diagnostic callback anymore, but there is always David's libdiagnostic which could be used for that purpose IMHO. 2024-10-12 Jakub Jelinek <jakub@redhat.com> libcpp/ * include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define. (struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF on diagnostic callback. (cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3. (cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. (cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6) instead of ATTRIBUTE_PRINTF_5. (cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. * Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather than --language=c. * errors.cc (cpp_diagnostic_at, cpp_diagnostic, cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of -ATTRIBUTE_FPTR_PRINTF. * charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex, convert_oct, convert_escape): Fix up -Wformat-diag warnings. (cpp_interpret_string_ranges, count_source_chars): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF. (narrow_str_to_charconst): Fix up -Wformat-diag warnings. * directives.cc (check_eol_1, directive_diagnostics, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, do_include_next, _cpp_parse_embed_params, do_embed, read_flag, do_line, do_linemarker, register_pragma_1, do_pragma_once, do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison, do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, do_assert, cpp_define_unused): Likewise. * expr.cc (cpp_classify_number, parse_defined, eval_token, _cpp_parse_expr, reduce, check_promotion): Likewise. * files.cc (_cpp_find_file, finish_base64_embed, _cpp_pop_file_buffer): Likewise. * init.cc (sanity_checks): Likewise. * lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char, _cpp_warn_invalid_utf8, _cpp_skip_block_comment, warn_about_normalization, forms_identifier_p, maybe_va_opt_error, identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise. * macro.cc (class vaopt_state, builtin_has_include_1, builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro, _cpp_builtin_macro_text, builtin_macro, stringify_arg, _cpp_arguments_ok, collect_args, enter_macro_context, _cpp_save_parameter, parse_params, create_iso_definition, _cpp_create_definition, check_trad_stringification): Likewise. * pch.cc (cpp_valid_state): Likewise. * traditional.cc (_cpp_scan_out_logical_line, recursive_macro): Likewise. gcc/ * Makefile.in (generated_files): Remove {gimple,generic}-match*. (generated_match_files): New variable. Add a dependency of $(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those. (build/genmatch$(build_exeext)): Depend on and link against libcommon.a and $(LIBBACKTRACE). * genmatch.cc: Include pretty-print.h and input.h. (ggc_internal_cleared_alloc, ggc_free): Remove. (fatal): New function. (line_table): Remove. (linemap_client_expand_location_to_spelling_point): Remove. (diagnostic_cb): Use gcc_diag rather than printf format. Use pp_format_verbatim on a temporary pretty_printer instead of vfprintf. (fatal_at, warning_at): Use gcc_diag rather than printf format. (output_line_directive): Rename location_hash to loc_hash. (parser::eat_ident, parser::parse_operation, parser::parse_expr, parser::parse_pattern, parser::finish_match_operand): Fix up -Wformat-diag warnings. gcc/c-family/ * c-lex.cc (c_common_has_attribute, c_common_lex_availability_macro): Fix up -Wformat-diag warnings. gcc/testsuite/ * c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for libcpp diagnostic formatting changes. * c-c++-common/cpp/embed-3.c: Likewise. * c-c++-common/cpp/embed-4.c: Likewise. * c-c++-common/cpp/embed-16.c: Likewise. * c-c++-common/cpp/embed-18.c: Likewise. * c-c++-common/cpp/eof-2.c: Likewise. * c-c++-common/cpp/eof-3.c: Likewise. * c-c++-common/cpp/fmax-include-depth.c: Likewise. * c-c++-common/cpp/has-builtin.c: Likewise. * c-c++-common/cpp/line-2.c: Likewise. * c-c++-common/cpp/line-3.c: Likewise. * c-c++-common/cpp/macro-arg-count-1.c: Likewise. * c-c++-common/cpp/macro-arg-count-2.c: Likewise. * c-c++-common/cpp/macro-ranges.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-4.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-5.c: Likewise. * c-c++-common/cpp/pr88974.c: Likewise. * c-c++-common/cpp/va-opt-error.c: Likewise. * c-c++-common/cpp/va-opt-pedantic.c: Likewise. * c-c++-common/cpp/Wheader-guard-2.c: Likewise. * c-c++-common/cpp/Wheader-guard-3.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-1.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-2.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-3.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c: Likewise. * c-c++-common/pr68833-3.c: Likewise. * c-c++-common/raw-string-directive-1.c: Likewise. * gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise. * gcc.dg/binary-constants-4.c: Likewise. * gcc.dg/builtin-redefine.c: Likewise. * gcc.dg/cpp/19951025-1.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c23-elifdef-2.c: Likewise. * gcc.dg/cpp/c23-warning-2.c: Likewise. * gcc.dg/cpp/embed-2.c: Likewise. * gcc.dg/cpp/embed-3.c: Likewise. * gcc.dg/cpp/embed-4.c: Likewise. * gcc.dg/cpp/expr.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu23-warning-2.c: Likewise. * gcc.dg/cpp/include6.c: Likewise. * gcc.dg/cpp/pr35322.c: Likewise. * gcc.dg/cpp/tr-warn6.c: Likewise. * gcc.dg/cpp/undef2.c: Likewise. * gcc.dg/cpp/warn-comments.c: Likewise. * gcc.dg/cpp/warn-comments-2.c: Likewise. * gcc.dg/cpp/warn-comments-3.c: Likewise. * gcc.dg/cpp/warn-cxx-compat.c: Likewise. * gcc.dg/cpp/warn-cxx-compat-2.c: Likewise. * gcc.dg/cpp/warn-deprecated.c: Likewise. * gcc.dg/cpp/warn-deprecated-2.c: Likewise. * gcc.dg/cpp/warn-long-long.c: Likewise. * gcc.dg/cpp/warn-long-long-2.c: Likewise. * gcc.dg/cpp/warn-normalized-1.c: Likewise. * gcc.dg/cpp/warn-normalized-2.c: Likewise. * gcc.dg/cpp/warn-normalized-3.c: Likewise. * gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise. * gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise. * gcc.dg/cpp/warn-redefined.c: Likewise. * gcc.dg/cpp/warn-redefined-2.c: Likewise. * gcc.dg/cpp/warn-traditional.c: Likewise. * gcc.dg/cpp/warn-traditional-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-1.c: Likewise. * gcc.dg/cpp/warn-trigraphs-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-3.c: Likewise. * gcc.dg/cpp/warn-trigraphs-4.c: Likewise. * gcc.dg/cpp/warn-undef.c: Likewise. * gcc.dg/cpp/warn-undef-2.c: Likewise. * gcc.dg/cpp/warn-unused-macros.c: Likewise. * gcc.dg/cpp/warn-unused-macros-2.c: Likewise. * gcc.dg/pch/counter-2.c: Likewise. * g++.dg/cpp0x/udlit-error1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-1.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-3.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-4.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-5.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-6.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-7.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-8.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-9.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-10.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-11.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-12.C: Likewise. * g++.dg/cpp/elifdef-3.C: Likewise. * g++.dg/cpp/elifdef-5.C: Likewise. * g++.dg/cpp/elifdef-6.C: Likewise. * g++.dg/cpp/elifdef-7.C: Likewise. * g++.dg/cpp/embed-1.C: Likewise. * g++.dg/cpp/embed-2.C: Likewise. * g++.dg/cpp/pedantic-errors.C: Likewise. * g++.dg/cpp/warning-1.C: Likewise. * g++.dg/cpp/warning-2.C: Likewise. * g++.dg/ext/bitint1.C: Likewise. * g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
"the left operand of %qs 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,
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics When working on #embed support, or -Wheader-guard or other recent libcpp changes, I've been annoyed by the libcpp diagnostics being visually different from normal gcc diagnostics, especially in the area of quoting stuff in the diagnostic messages. Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use %</%>, %qs etc. in there, while libcpp diagnostics was marked as printf and in libcpp we've been very creative with quoting stuff, either no quotes at all, or "something" quoting, or 'something' quoting, or `something' quoting (but in none of the cases it used colors consistently with the rest of the compiler). Now, libcpp diagnostics is always emitted using a callback, pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with genmatch.cc: cb->diagnostic = diagnostic_cb; c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic; fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic; where the latter two just use diagnostic_report_diagnostic, so actually support all the gcc_diag stuff, only the genmatch.cc case didn't. So, the following patch changes genmatch.cc to use pp_format* instead of vfprintf so that it supports the gcc_diag formatting (pretty-print.o unfortunately has various dependencies, so had to link genmatch with libcommon.a libbacktrace.a and tweak Makefile.in so that there are no circular dependencies) and marks the libcpp diagnostic routines as gcc_diag rather than printf. That change resulted in hundreds of -Wformat-diag new warnings (most of them useful and resulting IMHO in better diagnostics), so the rest of the patch is changing the format strings to make -Wformat-diag happy and adjusting the testsuite for the differences in how is the diagnostic reformatted. Dunno if some out of GCC tree projects use libcpp, that case would make it harder because one couldn't use vfprintf in the diagnostic callback anymore, but there is always David's libdiagnostic which could be used for that purpose IMHO. 2024-10-12 Jakub Jelinek <jakub@redhat.com> libcpp/ * include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define. (struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF on diagnostic callback. (cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3. (cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. (cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line, cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6) instead of ATTRIBUTE_PRINTF_5. (cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of ATTRIBUTE_PRINTF_4. * Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather than --language=c. * errors.cc (cpp_diagnostic_at, cpp_diagnostic, cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of -ATTRIBUTE_FPTR_PRINTF. * charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex, convert_oct, convert_escape): Fix up -Wformat-diag warnings. (cpp_interpret_string_ranges, count_source_chars): Use ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF. (narrow_str_to_charconst): Fix up -Wformat-diag warnings. * directives.cc (check_eol_1, directive_diagnostics, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, do_include_next, _cpp_parse_embed_params, do_embed, read_flag, do_line, do_linemarker, register_pragma_1, do_pragma_once, do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison, do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, do_assert, cpp_define_unused): Likewise. * expr.cc (cpp_classify_number, parse_defined, eval_token, _cpp_parse_expr, reduce, check_promotion): Likewise. * files.cc (_cpp_find_file, finish_base64_embed, _cpp_pop_file_buffer): Likewise. * init.cc (sanity_checks): Likewise. * lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char, _cpp_warn_invalid_utf8, _cpp_skip_block_comment, warn_about_normalization, forms_identifier_p, maybe_va_opt_error, identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise. * macro.cc (class vaopt_state, builtin_has_include_1, builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro, _cpp_builtin_macro_text, builtin_macro, stringify_arg, _cpp_arguments_ok, collect_args, enter_macro_context, _cpp_save_parameter, parse_params, create_iso_definition, _cpp_create_definition, check_trad_stringification): Likewise. * pch.cc (cpp_valid_state): Likewise. * traditional.cc (_cpp_scan_out_logical_line, recursive_macro): Likewise. gcc/ * Makefile.in (generated_files): Remove {gimple,generic}-match*. (generated_match_files): New variable. Add a dependency of $(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those. (build/genmatch$(build_exeext)): Depend on and link against libcommon.a and $(LIBBACKTRACE). * genmatch.cc: Include pretty-print.h and input.h. (ggc_internal_cleared_alloc, ggc_free): Remove. (fatal): New function. (line_table): Remove. (linemap_client_expand_location_to_spelling_point): Remove. (diagnostic_cb): Use gcc_diag rather than printf format. Use pp_format_verbatim on a temporary pretty_printer instead of vfprintf. (fatal_at, warning_at): Use gcc_diag rather than printf format. (output_line_directive): Rename location_hash to loc_hash. (parser::eat_ident, parser::parse_operation, parser::parse_expr, parser::parse_pattern, parser::finish_match_operand): Fix up -Wformat-diag warnings. gcc/c-family/ * c-lex.cc (c_common_has_attribute, c_common_lex_availability_macro): Fix up -Wformat-diag warnings. gcc/testsuite/ * c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for libcpp diagnostic formatting changes. * c-c++-common/cpp/embed-3.c: Likewise. * c-c++-common/cpp/embed-4.c: Likewise. * c-c++-common/cpp/embed-16.c: Likewise. * c-c++-common/cpp/embed-18.c: Likewise. * c-c++-common/cpp/eof-2.c: Likewise. * c-c++-common/cpp/eof-3.c: Likewise. * c-c++-common/cpp/fmax-include-depth.c: Likewise. * c-c++-common/cpp/has-builtin.c: Likewise. * c-c++-common/cpp/line-2.c: Likewise. * c-c++-common/cpp/line-3.c: Likewise. * c-c++-common/cpp/macro-arg-count-1.c: Likewise. * c-c++-common/cpp/macro-arg-count-2.c: Likewise. * c-c++-common/cpp/macro-ranges.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-4.c: Likewise. * c-c++-common/cpp/named-universal-char-escape-5.c: Likewise. * c-c++-common/cpp/pr88974.c: Likewise. * c-c++-common/cpp/va-opt-error.c: Likewise. * c-c++-common/cpp/va-opt-pedantic.c: Likewise. * c-c++-common/cpp/Wheader-guard-2.c: Likewise. * c-c++-common/cpp/Wheader-guard-3.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-1.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-2.c: Likewise. * c-c++-common/cpp/Winvalid-utf8-3.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c: Likewise. * c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c: Likewise. * c-c++-common/pr68833-3.c: Likewise. * c-c++-common/raw-string-directive-1.c: Likewise. * gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise. * gcc.dg/binary-constants-4.c: Likewise. * gcc.dg/builtin-redefine.c: Likewise. * gcc.dg/cpp/19951025-1.c: Likewise. * gcc.dg/cpp/c11-warning-1.c: Likewise. * gcc.dg/cpp/c11-warning-2.c: Likewise. * gcc.dg/cpp/c11-warning-3.c: Likewise. * gcc.dg/cpp/c23-elifdef-2.c: Likewise. * gcc.dg/cpp/c23-warning-2.c: Likewise. * gcc.dg/cpp/embed-2.c: Likewise. * gcc.dg/cpp/embed-3.c: Likewise. * gcc.dg/cpp/embed-4.c: Likewise. * gcc.dg/cpp/expr.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-2.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-3.c: Likewise. * gcc.dg/cpp/gnu11-elifdef-4.c: Likewise. * gcc.dg/cpp/gnu11-warning-1.c: Likewise. * gcc.dg/cpp/gnu11-warning-2.c: Likewise. * gcc.dg/cpp/gnu11-warning-3.c: Likewise. * gcc.dg/cpp/gnu23-warning-2.c: Likewise. * gcc.dg/cpp/include6.c: Likewise. * gcc.dg/cpp/pr35322.c: Likewise. * gcc.dg/cpp/tr-warn6.c: Likewise. * gcc.dg/cpp/undef2.c: Likewise. * gcc.dg/cpp/warn-comments.c: Likewise. * gcc.dg/cpp/warn-comments-2.c: Likewise. * gcc.dg/cpp/warn-comments-3.c: Likewise. * gcc.dg/cpp/warn-cxx-compat.c: Likewise. * gcc.dg/cpp/warn-cxx-compat-2.c: Likewise. * gcc.dg/cpp/warn-deprecated.c: Likewise. * gcc.dg/cpp/warn-deprecated-2.c: Likewise. * gcc.dg/cpp/warn-long-long.c: Likewise. * gcc.dg/cpp/warn-long-long-2.c: Likewise. * gcc.dg/cpp/warn-normalized-1.c: Likewise. * gcc.dg/cpp/warn-normalized-2.c: Likewise. * gcc.dg/cpp/warn-normalized-3.c: Likewise. * gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise. * gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise. * gcc.dg/cpp/warn-redefined.c: Likewise. * gcc.dg/cpp/warn-redefined-2.c: Likewise. * gcc.dg/cpp/warn-traditional.c: Likewise. * gcc.dg/cpp/warn-traditional-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-1.c: Likewise. * gcc.dg/cpp/warn-trigraphs-2.c: Likewise. * gcc.dg/cpp/warn-trigraphs-3.c: Likewise. * gcc.dg/cpp/warn-trigraphs-4.c: Likewise. * gcc.dg/cpp/warn-undef.c: Likewise. * gcc.dg/cpp/warn-undef-2.c: Likewise. * gcc.dg/cpp/warn-unused-macros.c: Likewise. * gcc.dg/cpp/warn-unused-macros-2.c: Likewise. * gcc.dg/pch/counter-2.c: Likewise. * g++.dg/cpp0x/udlit-error1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape1.C: Likewise. * g++.dg/cpp23/named-universal-char-escape2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-1.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-2.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-3.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-4.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-5.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-6.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-7.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-8.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-9.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-10.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-11.C: Likewise. * g++.dg/cpp23/Winvalid-utf8-12.C: Likewise. * g++.dg/cpp/elifdef-3.C: Likewise. * g++.dg/cpp/elifdef-5.C: Likewise. * g++.dg/cpp/elifdef-6.C: Likewise. * g++.dg/cpp/elifdef-7.C: Likewise. * g++.dg/cpp/embed-1.C: Likewise. * g++.dg/cpp/embed-2.C: Likewise. * g++.dg/cpp/pedantic-errors.C: Likewise. * g++.dg/cpp/warning-1.C: Likewise. * g++.dg/cpp/warning-2.C: Likewise. * g++.dg/ext/bitint1.C: Likewise. * g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
"the right operand of %qs 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-08 01:18:10 +08: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,
libcpp, c-family: Add (dumb) C23 N3017 #embed support [PR105863] The following patch implements the C23 N3017 "#embed - a scannable, tooling-friendly binary resource inclusion mechanism" paper. The implementation is intentionally dumb, in that it doesn't significantly speed up compilation of larger initializers and doesn't make it possible to use huge #embeds (like several gigabytes large, that is compile time and memory still infeasible). There are 2 reasons for this. One is that I think like it is implemented now in the patch is how we should use it for the smaller #embed sizes, dunno with which boundary, whether 32 bytes or 64 or something like that, certainly handling the single byte cases which is something that can appear anywhere in the source where constant integer literal can appear is desirable and I think for a few bytes it isn't worth it to come up with something smarter and users would like to e.g. see it in -E readably as well (perhaps the slow vs. fast boundary should be determined by command line option). And the other one is to be able to more easily find regressions in behavior caused by the optimizations, so we have something to get back in git to compare against. I'm definitely willing to work on the optimizations (likely introduce a new CPP_* token type to refer to a range of libcpp owned memory (start + size) and similarly some tree which can do the same, and can be at any time e.g. split into 2 subparts + say INTEGER_CST in between if needed say for const unsigned char d[] = { #embed "2GB.dat" prefix (0, 0, ) suffix (, [0x40000000] = 42) }; still without having to copy around huge amounts of data; STRING_CST owns the memory it points to and can be only 2GB in size), but would like to do that incrementally. And would like to first include some extensions also not included in this patch, like gnu::offset (off) parameter to allow to skip certain constant amount of bytes at the start of the files, plus gnu::base64 ("base64_encoded_data") parameter to add something which can store more efficiently large amounts of the #embed data in preprocessed source. I've been cross-checking all the tests also against the LLVM implementation https://github.com/llvm/llvm-project/pull/68620 which has been for a few hours even committed to LLVM trunk but reverted afterwards. LLVM now has the support committed and I admit I haven't rechecked whether the behavior on the below mentioned spots have been fixed in it already or not yet. The patch uses --embed-dir= option that clang plans to add above and doesn't use other variants on the search directories yet, plus there are no default directories at least for the time being where to search for embed files. So, #embed "..." works if it is found in the same directory (or relative to the current file's directory) and #embed "/..." or #embed </...> work always, but relative #embed <...> doesn't unless at least one --embed-dir= is specified. There is no reason to differentiate between system and non-system directories, so we don't need -isystem like counterpart, perhaps -iquote like counterpart could be useful in the future, dunno what else. It has --embed-directory=dir and --embed-directory dir as aliases. There are some differences beyond clang ICEs, so I'd like to point them out to make sure there is agreement on the choices in the patch. They are also mentioned in the comments of the llvm pull request. The most important is that the GCC patch (as well as the original thephd.dev LLVM branch on godbolt) expands #embed (or acts as if it is expanded) into a mere sequence of numbers like 123,2,35,26 rather then what clang effectively treats as (unsigned char)123,(unsigned char)2,(unsigned char)35,(unsigned char)26 but only does that when using integrated preprocessor, not when using -save-temps where it acts as GCC. JeanHeyd as the original author agrees that is how it is currently worded in C23. Another difference (not tested in the testsuite, not sure how to check for effective target /dev/urandom nor am sure it is desirable to check that during testsuite) is how to treat character devices, named pipes etc. (block devices are errored on). The original paper uses /dev/urandom in various examples and seems to assume that unlike regular files the devices aren't really cached, so #embed </dev/urandom> limit(1) prefix(int a = ) suffix(;) #embed </dev/urandom> limit(1) prefix(int b = ) suffix(;) usually results in a != b. That is what the godbolt thephd.dev branch implements too and what this patch does as well, but clang actually seems to just go from st.st_size == 0, ergo it must be zero-sized resource and so just copies over if_empty if present. It is really questionable what to do about the character devices/named pipes with __has_embed, for regular files the patch doesn't read anything from them, relies on st.st_size + limit for whether it is empty or non-empty. But I don't know of a way to check if read on say a character device would read anything or not (the </dev/null> limit (1) vs. </dev/zero> limit (1) cases), and if we read something, that would be better cached for later because #embed later if it reads again could read no further data even when it first read something. So, the patch currently for __has_embed just always returns 2 on the non-regular files, like the thephd.dev branch does as well and like the clang pull request as well. A question is also what to do for gnu::offset on the non-regular files even for #embed, those aren't seekable and do we want to just read and throw away the offset bytes each time we see it used? clang also chokes on the #if __has_embed (__FILE__ __limit__ (1) __prefix__ () suffix (1 / 0) \ __if_empty__ ((({{[0[0{0{0(0(0)1)1}1}]]}})))) != __STDC_EMBED_FOUND__ #error "__has_embed fail" #endif in embed-1.c, but thephd.dev branch accepts it and I don't see why it shouldn't, (({{[0[0{0{0(0(0)1)1}1}]]}}))) is a balanced token sequence and the file isn't empty, so it should just be parsed and discarded. clang also IMHO mishandles const unsigned char w[] = { #embed __FILE__ prefix([0] = 42, [15] =) limit(32) }; but again only without -save-temps, seems like it treats it as [0] = 42, [15] = (99,111,110,115,116,32,117,110,115,105,103,110,101,100, 32,99,104,97,114,32,119,91,93,32,61,32,123,10,35,101,109,98) rather than [0] = 42, [15] = 99,111,110,115,116,32,117,110,115,105,103,110,101,100, 32,99,104,97,114,32,119,91,93,32,61,32,123,10,35,101,109,98 and warns on it for -Wunused-value and just compiles it as [0] = 42, [15] = 98 And also void foo (int, int, int, int); void bar (void) { foo ( #embed __FILE__ limit (4) prefix (172 + ) suffix (+ 2) ); } is treated as 172 + (118, 111, 105, 100) + 2 rather than 172 + 118, 111, 105, 100 + 2 which clang -save-temps or GCC treats it like, so results in just one argument passed rather than 4. if (!strstr ((const char *) magna_carta, "imprisonétur")) abort (); in the testcase fails as well, but in that case calling it in gdb succeeds: p ((char *(*)(char *, char *))__strstr_sse2) (magna_carta, "imprisonétur") $2 = 0x555555558d3c <magna_carta+11564> "imprisonétur aut disseisiátur"... so I guess they are just trying to constant evaluate strstr and do it incorrectly. They started with making the optimizations together in the initial patch set, so they don't have the luxury to compare if it is just because of the optimization they are trying to do or because that is how the feature works for them. At least unless they use -save-temps for now. There is also different behavior between clang and gcc on -M or other dependency generating options. Seems clang includes the __has_embed searched files in dependencies, while my patch doesn't. But so does clang for __has_include and GCC doesn't. Emitting a hard dependency on some header just because there was __has_include/__has_embed for it seems wrong to me, because (at least when properly written) the source likely doesn't mind if the file is missing, it will do something else, so a hard error from make because of it doesn't seem right. Does make have some weaker dependencies, such that if some file can be remade it is but if it doesn't exist, it isn't fatal? I wonder whether #embed <non-existent-file> really needs to be fatal or whether we could simply after diagnosing it pretend the file exists and is empty. For #include I think fatal errors make tons of sense, but perhaps for #embed which is more localized we'd get better error reporting if we didn't bail out immediately. Note, both GCC and clang currently treat those as fatal errors. clang also added -dE option which with -E instead of preprocessing the #embed directives keeps them as is, but the preprocessed source then isn't self-contained. That option looks more harmful than useful to me. Also, it isn't clear to me from C23 whether it is possible to have __has_include/__has_c_attribute/__has_embed expressions inside of the limit #embed/__has_embed argument. 6.10.3.2/2 says that defined should not appear there (and the patch diagnoses it and testsuite tests), but for __has_include/__has_embed etc. 6.10.1/11 says: "The identifiers __has_include, __has_embed, and __has_c_attribute shall not appear in any context not mentioned in this subclause." If that subclause in that case means 6.10.1, then it presumably shouldn't appear in #embed in 6.10.3, but __has_embed is in 6.10.1... But 6.10.3.2/3 says that it should be parsed according to the 6.10.1 rules. Haven't included tests like #if __has_embed (__FILE__ limit (__has_embed (__FILE__ limit (1)))) or #embed __FILE__ limit (__has_include (__FILE__)) into the testsuite because of the doubts but I think the patch should handle those right now. The reason I've used Magna Carta text in some of the testcases is that I hope it shouldn't be copyrighted after the centuries and I'd strongly prefer not to have binary blobs in git after the xz backdoor lesson and wanted something larger which doesn't change all the time. Oh, BTW, I see in C23 draft 6.10.3.2 in Example 4 if (f_source == NULL); return 1; (note the spurious semicolon after closing paren), has that been fixed already? Like the thephd.dev and clang implementations, the patch always macro expands the whole #embed and __has_embed directives except for the embed keyword. That is most likely not what C23 says, my limited understanding right now is that in #embed one needs to parse the whole directive line with macro expansion disabled and check if it satisfies the grammar, if not, the whole directive is macro expanded, if yes, only the limit parameter argument is macro expanded and the prefix/suffix/if_empty arguments are maybe macro expanded when actually used (and not at all if unused). And I think __has_embed macro expansion has conflicting rules. 2024-09-12 Jakub Jelinek <jakub@redhat.com> PR c/105863 libcpp/ * include/cpplib.h: Implement C23 N3017 #embed - a scannable, tooling-friendly binary resource inclusion mechanism paper. (struct cpp_options): Add embed member. (enum cpp_builtin_type): Add BT_HAS_EMBED. (cpp_set_include_chains): Add another cpp_dir * argument to the declaration. * internal.h (enum include_type): Add IT_EMBED. (struct cpp_reader): Add embed_include member. (struct cpp_embed_params_tokens): New type. (struct cpp_embed_params): New type. (_cpp_get_token_no_padding): Declare. (enum _cpp_find_file_kind): Add _cpp_FFK_EMBED and _cpp_FFK_HAS_EMBED. (_cpp_stack_embed): Declare. (_cpp_parse_expr): Change return type to cpp_num_part instead of bool, change second argument from bool to const char * and add third argument. (_cpp_parse_embed_params): Declare. * directives.cc (DIRECTIVE_TABLE): Add embed entry. (end_directive): Don't call skip_rest_of_line for T_EMBED directive. (_cpp_handle_directive): Return 2 rather than 1 for T_EMBED in directives-only mode. (parse_include): Don't Call check_eol for T_EMBED directive. (skip_balanced_token_seq): New function. (EMBED_PARAMS): Define. (enum embed_param_kind): New type. (embed_params): New variable. (_cpp_parse_embed_params): New function. (do_embed): New function. (do_if): Adjust _cpp_parse_expr caller. (do_elif): Likewise. * expr.cc (parse_defined): Diagnose defined in #embed or __has_embed parameters. (_cpp_parse_expr): Change return type to cpp_num_part instead of bool, change second argument from bool to const char * and add third argument. Adjust function comment. For #embed/__has_embed parameters add an artificial CPP_OPEN_PAREN. Use the second argument DIR directly instead of string literals conditional on IS_IF. For #embed/__has_embed parameter, stop on reaching CPP_CLOSE_PAREN matching the artificial one. Diagnose negative or too large embed parameter operands. (num_binary_op): Use #embed instead of #if for diagnostics if inside #embed/__has_embed parameter. (num_div_op): Likewise. * files.cc (struct _cpp_file): Add limit member and embed bitfield. (search_cache): Add IS_EMBED argument, formatting fix. Skip over files with different file->embed from the argument. (find_file_in_dir): Don't call pch_open_file if file->embed. (_cpp_find_file): Handle _cpp_FFK_EMBED and _cpp_FFK_HAS_EMBED. (read_file_guts): Formatting fix. (has_unique_contents): Ignore file->embed files. (search_path_head): Handle IT_EMBED type. (_cpp_stack_embed): New function. (_cpp_get_file_stat): Formatting fix. (cpp_set_include_chains): Add embed argument, save it to pfile->embed_include and compute lens for the chain. * init.cc (struct lang_flags): Add embed member. (lang_defaults): Add embed initializers. (cpp_set_lang): Initialize CPP_OPTION (pfile, embed). (builtin_array): Add __has_embed entry. (cpp_init_builtins): Predefine __STDC_EMBED_NOT_FOUND__, __STDC_EMBED_FOUND__ and __STDC_EMBED_EMPTY__. * lex.cc (cpp_directive_only_process): Handle #embed. * macro.cc (cpp_get_token_no_padding): Rename to ... (_cpp_get_token_no_padding): ... this. No longer static. (builtin_has_include_1): New function. (builtin_has_include): Use it. Use _cpp_get_token_no_padding instead of cpp_get_token_no_padding. (builtin_has_embed): New function. (_cpp_builtin_macro_text): Handle BT_HAS_EMBED. gcc/ * doc/cppdiropts.texi (--embed-dir=): Document. * doc/cpp.texi (Binary Resource Inclusion): New chapter. (__has_embed): Document. * doc/invoke.texi (Directory Options): Mention --embed-dir=. * gcc.cc (cpp_unique_options): Add %{-embed*}. * genmatch.cc (main): Adjust cpp_set_include_chains caller. * incpath.h (enum incpath_kind): Add INC_EMBED. * incpath.cc (merge_include_chains): Handle INC_EMBED. (register_include_chains): Adjust cpp_set_include_chains caller. gcc/c-family/ * c.opt (-embed-dir=): New option. (-embed-directory): New alias. (-embed-directory=): New alias. * c-opts.cc (c_common_handle_option): Handle OPT__embed_dir_. gcc/testsuite/ * c-c++-common/cpp/embed-1.c: New test. * c-c++-common/cpp/embed-2.c: New test. * c-c++-common/cpp/embed-3.c: New test. * c-c++-common/cpp/embed-4.c: New test. * c-c++-common/cpp/embed-5.c: New test. * c-c++-common/cpp/embed-6.c: New test. * c-c++-common/cpp/embed-7.c: New test. * c-c++-common/cpp/embed-8.c: New test. * c-c++-common/cpp/embed-9.c: New test. * c-c++-common/cpp/embed-10.c: New test. * c-c++-common/cpp/embed-11.c: New test. * c-c++-common/cpp/embed-12.c: New test. * c-c++-common/cpp/embed-13.c: New test. * c-c++-common/cpp/embed-14.c: New test. * c-c++-common/cpp/embed-25.c: New test. * c-c++-common/cpp/embed-26.c: New test. * c-c++-common/cpp/embed-dir/embed-1.inc: New test. * c-c++-common/cpp/embed-dir/embed-3.c: New test. * c-c++-common/cpp/embed-dir/embed-4.c: New test. * c-c++-common/cpp/embed-dir/magna-carta.txt: New test. * gcc.dg/cpp/embed-1.c: New test. * gcc.dg/cpp/embed-2.c: New test. * gcc.dg/cpp/embed-3.c: New test. * gcc.dg/cpp/embed-4.c: New test. * g++.dg/cpp/embed-1.C: New test. * g++.dg/cpp/embed-2.C: New test. * g++.dg/cpp/embed-3.C: New test.
2024-09-12 17:15:38 +08:00
"comma operator in operand of #%s",
pfile->state.in_directive == 3
? "embed" : "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,
Eliminate source_location in favor of location_t Historically GCC used location_t, while libcpp used source_location. This inconsistency has been annoying me for a while, so this patch removes source_location in favor of location_t throughout (as the latter is shorter). gcc/ChangeLog: * builtins.c: Replace "source_location" with "location_t". * diagnostic-show-locus.c: Likewise. * diagnostic.c: Likewise. * dumpfile.c: Likewise. * gcc-rich-location.h: Likewise. * genmatch.c: Likewise. * gimple.h: Likewise. * gimplify.c: Likewise. * input.c: Likewise. * input.h: Likewise. Eliminate the typedef. * omp-expand.c: Likewise. * selftest.h: Likewise. * substring-locations.h (get_source_location_for_substring): Rename to.. (get_location_within_string): ...this. * tree-cfg.c: Replace "source_location" with "location_t". * tree-cfgcleanup.c: Likewise. * tree-diagnostic.c: Likewise. * tree-into-ssa.c: Likewise. * tree-outof-ssa.c: Likewise. * tree-parloops.c: Likewise. * tree-phinodes.c: Likewise. * tree-phinodes.h: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-manip.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-phiprop.c: Likewise. * tree-ssa-threadupdate.c: Likewise. * tree-ssa.c: Likewise. * tree-ssa.h: Likewise. * tree-vect-loop-manip.c: Likewise. gcc/c-family/ChangeLog: * c-common.c (c_get_substring_location): Update for renaming of get_source_location_for_substring to get_location_within_string. * c-lex.c: Replace "source_location" with "location_t". * c-opts.c: Likewise. * c-ppoutput.c: Likewise. gcc/c/ChangeLog: * c-decl.c: Replace "source_location" with "location_t". * c-tree.h: Likewise. * c-typeck.c: Likewise. * gimple-parser.c: Likewise. gcc/cp/ChangeLog: * call.c: Replace "source_location" with "location_t". * cp-tree.h: Likewise. * cvt.c: Likewise. * name-lookup.c: Likewise. * parser.c: Likewise. * typeck.c: Likewise. gcc/fortran/ChangeLog: * cpp.c: Replace "source_location" with "location_t". * gfortran.h: Likewise. gcc/go/ChangeLog: * go-gcc-diagnostics.cc: Replace "source_location" with "location_t". * go-gcc.cc: Likewise. * go-linemap.cc: Likewise. * go-location.h: Likewise. * gofrontend/README: Likewise. gcc/jit/ChangeLog: * jit-playback.c: Replace "source_location" with "location_t". gcc/testsuite/ChangeLog: * g++.dg/plugin/comment_plugin.c: Replace "source_location" with "location_t". * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c: Likewise. libcc1/ChangeLog: * libcc1plugin.cc: Replace "source_location" with "location_t". (plugin_context::get_source_location): Rename to... (plugin_context::get_location_t): ...this. * libcp1plugin.cc: Likewise. libcpp/ChangeLog: * charset.c: Replace "source_location" with "location_t". * directives-only.c: Likewise. * directives.c: Likewise. * errors.c: Likewise. * expr.c: Likewise. * files.c: Likewise. * include/cpplib.h: Likewise. Rename MAX_SOURCE_LOCATION to MAX_LOCATION_T. * include/line-map.h: Likewise. * init.c: Likewise. * internal.h: Likewise. * lex.c: Likewise. * line-map.c: Likewise. * location-example.txt: Likewise. * macro.c: Likewise. * pch.c: Likewise. * traditional.c: Likewise. From-SVN: r266085
2018-11-14 04:05:03 +08:00
location_t 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,
libcpp, c-family: Add (dumb) C23 N3017 #embed support [PR105863] The following patch implements the C23 N3017 "#embed - a scannable, tooling-friendly binary resource inclusion mechanism" paper. The implementation is intentionally dumb, in that it doesn't significantly speed up compilation of larger initializers and doesn't make it possible to use huge #embeds (like several gigabytes large, that is compile time and memory still infeasible). There are 2 reasons for this. One is that I think like it is implemented now in the patch is how we should use it for the smaller #embed sizes, dunno with which boundary, whether 32 bytes or 64 or something like that, certainly handling the single byte cases which is something that can appear anywhere in the source where constant integer literal can appear is desirable and I think for a few bytes it isn't worth it to come up with something smarter and users would like to e.g. see it in -E readably as well (perhaps the slow vs. fast boundary should be determined by command line option). And the other one is to be able to more easily find regressions in behavior caused by the optimizations, so we have something to get back in git to compare against. I'm definitely willing to work on the optimizations (likely introduce a new CPP_* token type to refer to a range of libcpp owned memory (start + size) and similarly some tree which can do the same, and can be at any time e.g. split into 2 subparts + say INTEGER_CST in between if needed say for const unsigned char d[] = { #embed "2GB.dat" prefix (0, 0, ) suffix (, [0x40000000] = 42) }; still without having to copy around huge amounts of data; STRING_CST owns the memory it points to and can be only 2GB in size), but would like to do that incrementally. And would like to first include some extensions also not included in this patch, like gnu::offset (off) parameter to allow to skip certain constant amount of bytes at the start of the files, plus gnu::base64 ("base64_encoded_data") parameter to add something which can store more efficiently large amounts of the #embed data in preprocessed source. I've been cross-checking all the tests also against the LLVM implementation https://github.com/llvm/llvm-project/pull/68620 which has been for a few hours even committed to LLVM trunk but reverted afterwards. LLVM now has the support committed and I admit I haven't rechecked whether the behavior on the below mentioned spots have been fixed in it already or not yet. The patch uses --embed-dir= option that clang plans to add above and doesn't use other variants on the search directories yet, plus there are no default directories at least for the time being where to search for embed files. So, #embed "..." works if it is found in the same directory (or relative to the current file's directory) and #embed "/..." or #embed </...> work always, but relative #embed <...> doesn't unless at least one --embed-dir= is specified. There is no reason to differentiate between system and non-system directories, so we don't need -isystem like counterpart, perhaps -iquote like counterpart could be useful in the future, dunno what else. It has --embed-directory=dir and --embed-directory dir as aliases. There are some differences beyond clang ICEs, so I'd like to point them out to make sure there is agreement on the choices in the patch. They are also mentioned in the comments of the llvm pull request. The most important is that the GCC patch (as well as the original thephd.dev LLVM branch on godbolt) expands #embed (or acts as if it is expanded) into a mere sequence of numbers like 123,2,35,26 rather then what clang effectively treats as (unsigned char)123,(unsigned char)2,(unsigned char)35,(unsigned char)26 but only does that when using integrated preprocessor, not when using -save-temps where it acts as GCC. JeanHeyd as the original author agrees that is how it is currently worded in C23. Another difference (not tested in the testsuite, not sure how to check for effective target /dev/urandom nor am sure it is desirable to check that during testsuite) is how to treat character devices, named pipes etc. (block devices are errored on). The original paper uses /dev/urandom in various examples and seems to assume that unlike regular files the devices aren't really cached, so #embed </dev/urandom> limit(1) prefix(int a = ) suffix(;) #embed </dev/urandom> limit(1) prefix(int b = ) suffix(;) usually results in a != b. That is what the godbolt thephd.dev branch implements too and what this patch does as well, but clang actually seems to just go from st.st_size == 0, ergo it must be zero-sized resource and so just copies over if_empty if present. It is really questionable what to do about the character devices/named pipes with __has_embed, for regular files the patch doesn't read anything from them, relies on st.st_size + limit for whether it is empty or non-empty. But I don't know of a way to check if read on say a character device would read anything or not (the </dev/null> limit (1) vs. </dev/zero> limit (1) cases), and if we read something, that would be better cached for later because #embed later if it reads again could read no further data even when it first read something. So, the patch currently for __has_embed just always returns 2 on the non-regular files, like the thephd.dev branch does as well and like the clang pull request as well. A question is also what to do for gnu::offset on the non-regular files even for #embed, those aren't seekable and do we want to just read and throw away the offset bytes each time we see it used? clang also chokes on the #if __has_embed (__FILE__ __limit__ (1) __prefix__ () suffix (1 / 0) \ __if_empty__ ((({{[0[0{0{0(0(0)1)1}1}]]}})))) != __STDC_EMBED_FOUND__ #error "__has_embed fail" #endif in embed-1.c, but thephd.dev branch accepts it and I don't see why it shouldn't, (({{[0[0{0{0(0(0)1)1}1}]]}}))) is a balanced token sequence and the file isn't empty, so it should just be parsed and discarded. clang also IMHO mishandles const unsigned char w[] = { #embed __FILE__ prefix([0] = 42, [15] =) limit(32) }; but again only without -save-temps, seems like it treats it as [0] = 42, [15] = (99,111,110,115,116,32,117,110,115,105,103,110,101,100, 32,99,104,97,114,32,119,91,93,32,61,32,123,10,35,101,109,98) rather than [0] = 42, [15] = 99,111,110,115,116,32,117,110,115,105,103,110,101,100, 32,99,104,97,114,32,119,91,93,32,61,32,123,10,35,101,109,98 and warns on it for -Wunused-value and just compiles it as [0] = 42, [15] = 98 And also void foo (int, int, int, int); void bar (void) { foo ( #embed __FILE__ limit (4) prefix (172 + ) suffix (+ 2) ); } is treated as 172 + (118, 111, 105, 100) + 2 rather than 172 + 118, 111, 105, 100 + 2 which clang -save-temps or GCC treats it like, so results in just one argument passed rather than 4. if (!strstr ((const char *) magna_carta, "imprisonétur")) abort (); in the testcase fails as well, but in that case calling it in gdb succeeds: p ((char *(*)(char *, char *))__strstr_sse2) (magna_carta, "imprisonétur") $2 = 0x555555558d3c <magna_carta+11564> "imprisonétur aut disseisiátur"... so I guess they are just trying to constant evaluate strstr and do it incorrectly. They started with making the optimizations together in the initial patch set, so they don't have the luxury to compare if it is just because of the optimization they are trying to do or because that is how the feature works for them. At least unless they use -save-temps for now. There is also different behavior between clang and gcc on -M or other dependency generating options. Seems clang includes the __has_embed searched files in dependencies, while my patch doesn't. But so does clang for __has_include and GCC doesn't. Emitting a hard dependency on some header just because there was __has_include/__has_embed for it seems wrong to me, because (at least when properly written) the source likely doesn't mind if the file is missing, it will do something else, so a hard error from make because of it doesn't seem right. Does make have some weaker dependencies, such that if some file can be remade it is but if it doesn't exist, it isn't fatal? I wonder whether #embed <non-existent-file> really needs to be fatal or whether we could simply after diagnosing it pretend the file exists and is empty. For #include I think fatal errors make tons of sense, but perhaps for #embed which is more localized we'd get better error reporting if we didn't bail out immediately. Note, both GCC and clang currently treat those as fatal errors. clang also added -dE option which with -E instead of preprocessing the #embed directives keeps them as is, but the preprocessed source then isn't self-contained. That option looks more harmful than useful to me. Also, it isn't clear to me from C23 whether it is possible to have __has_include/__has_c_attribute/__has_embed expressions inside of the limit #embed/__has_embed argument. 6.10.3.2/2 says that defined should not appear there (and the patch diagnoses it and testsuite tests), but for __has_include/__has_embed etc. 6.10.1/11 says: "The identifiers __has_include, __has_embed, and __has_c_attribute shall not appear in any context not mentioned in this subclause." If that subclause in that case means 6.10.1, then it presumably shouldn't appear in #embed in 6.10.3, but __has_embed is in 6.10.1... But 6.10.3.2/3 says that it should be parsed according to the 6.10.1 rules. Haven't included tests like #if __has_embed (__FILE__ limit (__has_embed (__FILE__ limit (1)))) or #embed __FILE__ limit (__has_include (__FILE__)) into the testsuite because of the doubts but I think the patch should handle those right now. The reason I've used Magna Carta text in some of the testcases is that I hope it shouldn't be copyrighted after the centuries and I'd strongly prefer not to have binary blobs in git after the xz backdoor lesson and wanted something larger which doesn't change all the time. Oh, BTW, I see in C23 draft 6.10.3.2 in Example 4 if (f_source == NULL); return 1; (note the spurious semicolon after closing paren), has that been fixed already? Like the thephd.dev and clang implementations, the patch always macro expands the whole #embed and __has_embed directives except for the embed keyword. That is most likely not what C23 says, my limited understanding right now is that in #embed one needs to parse the whole directive line with macro expansion disabled and check if it satisfies the grammar, if not, the whole directive is macro expanded, if yes, only the limit parameter argument is macro expanded and the prefix/suffix/if_empty arguments are maybe macro expanded when actually used (and not at all if unused). And I think __has_embed macro expansion has conflicting rules. 2024-09-12 Jakub Jelinek <jakub@redhat.com> PR c/105863 libcpp/ * include/cpplib.h: Implement C23 N3017 #embed - a scannable, tooling-friendly binary resource inclusion mechanism paper. (struct cpp_options): Add embed member. (enum cpp_builtin_type): Add BT_HAS_EMBED. (cpp_set_include_chains): Add another cpp_dir * argument to the declaration. * internal.h (enum include_type): Add IT_EMBED. (struct cpp_reader): Add embed_include member. (struct cpp_embed_params_tokens): New type. (struct cpp_embed_params): New type. (_cpp_get_token_no_padding): Declare. (enum _cpp_find_file_kind): Add _cpp_FFK_EMBED and _cpp_FFK_HAS_EMBED. (_cpp_stack_embed): Declare. (_cpp_parse_expr): Change return type to cpp_num_part instead of bool, change second argument from bool to const char * and add third argument. (_cpp_parse_embed_params): Declare. * directives.cc (DIRECTIVE_TABLE): Add embed entry. (end_directive): Don't call skip_rest_of_line for T_EMBED directive. (_cpp_handle_directive): Return 2 rather than 1 for T_EMBED in directives-only mode. (parse_include): Don't Call check_eol for T_EMBED directive. (skip_balanced_token_seq): New function. (EMBED_PARAMS): Define. (enum embed_param_kind): New type. (embed_params): New variable. (_cpp_parse_embed_params): New function. (do_embed): New function. (do_if): Adjust _cpp_parse_expr caller. (do_elif): Likewise. * expr.cc (parse_defined): Diagnose defined in #embed or __has_embed parameters. (_cpp_parse_expr): Change return type to cpp_num_part instead of bool, change second argument from bool to const char * and add third argument. Adjust function comment. For #embed/__has_embed parameters add an artificial CPP_OPEN_PAREN. Use the second argument DIR directly instead of string literals conditional on IS_IF. For #embed/__has_embed parameter, stop on reaching CPP_CLOSE_PAREN matching the artificial one. Diagnose negative or too large embed parameter operands. (num_binary_op): Use #embed instead of #if for diagnostics if inside #embed/__has_embed parameter. (num_div_op): Likewise. * files.cc (struct _cpp_file): Add limit member and embed bitfield. (search_cache): Add IS_EMBED argument, formatting fix. Skip over files with different file->embed from the argument. (find_file_in_dir): Don't call pch_open_file if file->embed. (_cpp_find_file): Handle _cpp_FFK_EMBED and _cpp_FFK_HAS_EMBED. (read_file_guts): Formatting fix. (has_unique_contents): Ignore file->embed files. (search_path_head): Handle IT_EMBED type. (_cpp_stack_embed): New function. (_cpp_get_file_stat): Formatting fix. (cpp_set_include_chains): Add embed argument, save it to pfile->embed_include and compute lens for the chain. * init.cc (struct lang_flags): Add embed member. (lang_defaults): Add embed initializers. (cpp_set_lang): Initialize CPP_OPTION (pfile, embed). (builtin_array): Add __has_embed entry. (cpp_init_builtins): Predefine __STDC_EMBED_NOT_FOUND__, __STDC_EMBED_FOUND__ and __STDC_EMBED_EMPTY__. * lex.cc (cpp_directive_only_process): Handle #embed. * macro.cc (cpp_get_token_no_padding): Rename to ... (_cpp_get_token_no_padding): ... this. No longer static. (builtin_has_include_1): New function. (builtin_has_include): Use it. Use _cpp_get_token_no_padding instead of cpp_get_token_no_padding. (builtin_has_embed): New function. (_cpp_builtin_macro_text): Handle BT_HAS_EMBED. gcc/ * doc/cppdiropts.texi (--embed-dir=): Document. * doc/cpp.texi (Binary Resource Inclusion): New chapter. (__has_embed): Document. * doc/invoke.texi (Directory Options): Mention --embed-dir=. * gcc.cc (cpp_unique_options): Add %{-embed*}. * genmatch.cc (main): Adjust cpp_set_include_chains caller. * incpath.h (enum incpath_kind): Add INC_EMBED. * incpath.cc (merge_include_chains): Handle INC_EMBED. (register_include_chains): Adjust cpp_set_include_chains caller. gcc/c-family/ * c.opt (-embed-dir=): New option. (-embed-directory): New alias. (-embed-directory=): New alias. * c-opts.cc (c_common_handle_option): Handle OPT__embed_dir_. gcc/testsuite/ * c-c++-common/cpp/embed-1.c: New test. * c-c++-common/cpp/embed-2.c: New test. * c-c++-common/cpp/embed-3.c: New test. * c-c++-common/cpp/embed-4.c: New test. * c-c++-common/cpp/embed-5.c: New test. * c-c++-common/cpp/embed-6.c: New test. * c-c++-common/cpp/embed-7.c: New test. * c-c++-common/cpp/embed-8.c: New test. * c-c++-common/cpp/embed-9.c: New test. * c-c++-common/cpp/embed-10.c: New test. * c-c++-common/cpp/embed-11.c: New test. * c-c++-common/cpp/embed-12.c: New test. * c-c++-common/cpp/embed-13.c: New test. * c-c++-common/cpp/embed-14.c: New test. * c-c++-common/cpp/embed-25.c: New test. * c-c++-common/cpp/embed-26.c: New test. * c-c++-common/cpp/embed-dir/embed-1.inc: New test. * c-c++-common/cpp/embed-dir/embed-3.c: New test. * c-c++-common/cpp/embed-dir/embed-4.c: New test. * c-c++-common/cpp/embed-dir/magna-carta.txt: New test. * gcc.dg/cpp/embed-1.c: New test. * gcc.dg/cpp/embed-2.c: New test. * gcc.dg/cpp/embed-3.c: New test. * gcc.dg/cpp/embed-4.c: New test. * g++.dg/cpp/embed-1.C: New test. * g++.dg/cpp/embed-2.C: New test. * g++.dg/cpp/embed-3.C: New test.
2024-09-12 17:15:38 +08:00
"division by zero in #%s",
pfile->state.in_directive == 3
? "embed" : "if");
lhs.unsignedp = unsignedp;
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 19:49:23 +08:00