From 1c6ffbab63f55187909b6d71cfca6080e9cf43cf Mon Sep 17 00:00:00 2001 From: Qing Zhao Date: Tue, 2 Jul 2019 20:23:30 +0000 Subject: [PATCH] re PR preprocessor/90581 (provide an option to adjust the maximum depth of nested #include) PR preprocessor/90581 Add a cpp option -fmax-include-depth to set the maximum depth of the nested #include. From-SVN: r272948 --- gcc/ChangeLog | 6 ++++++ gcc/c-family/ChangeLog | 6 ++++++ gcc/c-family/c-opts.c | 4 ++++ gcc/c-family/c.opt | 4 ++++ gcc/doc/cppopts.texi | 4 ++++ gcc/doc/invoke.texi | 1 + gcc/testsuite/ChangeLog | 7 +++++++ gcc/testsuite/c-c++-common/cpp/fmax-include-depth-1a.h | 1 + gcc/testsuite/c-c++-common/cpp/fmax-include-depth-1b.h | 1 + gcc/testsuite/c-c++-common/cpp/fmax-include-depth.c | 4 ++++ libcpp/ChangeLog | 10 ++++++++++ libcpp/directives.c | 9 +++++++-- libcpp/include/cpplib.h | 3 +++ libcpp/init.c | 1 + libcpp/internal.h | 4 ---- 15 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/cpp/fmax-include-depth-1a.h create mode 100644 gcc/testsuite/c-c++-common/cpp/fmax-include-depth-1b.h create mode 100644 gcc/testsuite/c-c++-common/cpp/fmax-include-depth.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f40d55e0d3f..62b126fb5b8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2019-07-02 qing zhao + + PR preprocessor/90581 + * doc/cppopts.texi: Add document for -fmax-include-depth. + * doc/invoke.texi (Preprocessor Options): List -fmax-include-depth. + 2019-07-02 Uroš Bizjak * config/i386/mmx.md (mmx_packswb): diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 22d7c6ecf7c..e56bd7a8e35 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,9 @@ +2019-07-02 qing zhao + + PR preprocessor/90581 + * c-opts.c (c_common_handle_option): Handle -fmax-include-depth. + * c.opt: Add new option -fmax-include-depth. + 2019-06-26 Jason Merrill PR c++/55442 - memory-hog with highly recursive constexpr. diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c index 954b6a494f8..188da437507 100644 --- a/gcc/c-family/c-opts.c +++ b/gcc/c-family/c-opts.c @@ -460,6 +460,10 @@ c_common_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value, cpp_opts->extended_identifiers = value; break; + case OPT_fmax_include_depth_: + cpp_opts->max_include_depth = value; + break; + case OPT_foperator_names: cpp_opts->operator_names = value; break; diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index 080066fa608..4c8b0026000 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -1575,6 +1575,10 @@ flax-vector-conversions C ObjC C++ ObjC++ Var(flag_lax_vector_conversions) Allow implicit conversions between vectors with differing numbers of subparts and/or differing element types. +fmax-include-depth= +C ObjC C++ ObjC++ Joined RejectNegative UInteger +fmax-include-depth= Set the maximum depth of the nested #include. + fms-extensions C ObjC C++ ObjC++ Var(flag_ms_extensions) Don't warn about uses of Microsoft extensions. diff --git a/gcc/doc/cppopts.texi b/gcc/doc/cppopts.texi index 48c574f419f..61e22cd93ae 100644 --- a/gcc/doc/cppopts.texi +++ b/gcc/doc/cppopts.texi @@ -261,6 +261,10 @@ enabled by default for C99 (and later C standard versions) and C++. @opindex fno-canonical-system-headers When preprocessing, do not shorten system header paths with canonicalization. +@item -fmax-include-depth=@var{depth} +@opindex fmax-include-depth +Set the maximum depth of the nested #include. The default is 200. + @item -ftabstop=@var{width} @opindex ftabstop Set the distance between tab stops. This helps the preprocessor report diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 9c6050b574b..ae1a7d25277 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -518,6 +518,7 @@ Objective-C and Objective-C++ Dialects}. -fdebug-cpp -fdirectives-only -fdollars-in-identifiers @gol -fexec-charset=@var{charset} -fextended-identifiers @gol -finput-charset=@var{charset} -fmacro-prefix-map=@var{old}=@var{new} @gol +-fmax-include-depth=@var{depth} @gol -fno-canonical-system-headers -fpch-deps -fpch-preprocess @gol -fpreprocessed -ftabstop=@var{width} -ftrack-macro-expansion @gol -fwide-exec-charset=@var{charset} -fworking-directory @gol diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 423e075a9dc..55deef7255d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2019-07-02 qing zhao + + PR preprocessor/90581 + * c-c++-common/cpp/fmax-include-depth-1a.h: New test. + * c-c++-common/cpp/fmax-include-depth-1b.h: New test. + * c-c++-common/cpp/fmax-include-depth.c: New test. + 2019-07-02 Jan Hubicka * gcc.dg/tree-ssa/alias-access-path-7.c: New testcase. diff --git a/gcc/testsuite/c-c++-common/cpp/fmax-include-depth-1a.h b/gcc/testsuite/c-c++-common/cpp/fmax-include-depth-1a.h new file mode 100644 index 00000000000..4e610c04d58 --- /dev/null +++ b/gcc/testsuite/c-c++-common/cpp/fmax-include-depth-1a.h @@ -0,0 +1 @@ +int a; diff --git a/gcc/testsuite/c-c++-common/cpp/fmax-include-depth-1b.h b/gcc/testsuite/c-c++-common/cpp/fmax-include-depth-1b.h new file mode 100644 index 00000000000..c167587ebbe --- /dev/null +++ b/gcc/testsuite/c-c++-common/cpp/fmax-include-depth-1b.h @@ -0,0 +1 @@ +#include "fmax-include-depth-1a.h" diff --git a/gcc/testsuite/c-c++-common/cpp/fmax-include-depth.c b/gcc/testsuite/c-c++-common/cpp/fmax-include-depth.c new file mode 100644 index 00000000000..bd8cc3adcdd --- /dev/null +++ b/gcc/testsuite/c-c++-common/cpp/fmax-include-depth.c @@ -0,0 +1,4 @@ +/* { dg-do preprocess} */ +/* { dg-options "-fmax-include-depth=1" } */ + +#include "fmax-include-depth-1b.h" /* { dg-error ".include nested depth 1 exceeds maximum of 1 .use -fmax-include-depth=DEPTH to increase the maximum." } */ diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index 1575d4bcda2..a3185e3109c 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,13 @@ +2019-07-02 qing zhao + + PR preprocessor/90581 + * directives.c (do_include_common): Replace CPP_STACK_MAX with + CPP_OPTION (pfile, max_include_depth). + * include/cpplib.h (struct cpp_options): Add new field + max_include_depth. + * init.c (cpp_create_reader): Initiate new field max_include_depth. + * internal.h: Delete CPP_STACK_MAX. + 2019-06-26 Nathan Sidwell PR preprocessor/90927 diff --git a/libcpp/directives.c b/libcpp/directives.c index 3ee8bc4053b..2fdfaf0242c 100644 --- a/libcpp/directives.c +++ b/libcpp/directives.c @@ -831,8 +831,13 @@ do_include_common (cpp_reader *pfile, enum include_type type) } /* Prevent #include recursion. */ - if (pfile->line_table->depth >= CPP_STACK_MAX) - cpp_error (pfile, CPP_DL_ERROR, "#include nested too deeply"); + if (pfile->line_table->depth >= CPP_OPTION (pfile, max_include_depth)) + cpp_error (pfile, + CPP_DL_ERROR, + "#include nested depth %u exceeds maximum of %u" + " (use -fmax-include-depth=DEPTH to increase the maximum)", + pfile->line_table->depth, + CPP_OPTION (pfile, max_include_depth)); else { /* Get out of macro context, if we are. */ diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index 3edb93dce46..91d97f9f097 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -550,6 +550,9 @@ struct cpp_options /* True enables canonicalization of system header file paths. */ bool canonical_system_headers; + + /* The maximum depth of the nested #include. */ + unsigned int max_include_depth; }; /* Diagnostic levels. To get a diagnostic without associating a diff --git a/libcpp/init.c b/libcpp/init.c index c0c9020fdb7..d06f95e68b0 100644 --- a/libcpp/init.c +++ b/libcpp/init.c @@ -185,6 +185,7 @@ cpp_create_reader (enum c_lang lang, cpp_hash_table *table, CPP_OPTION (pfile, warn_multichar) = 1; CPP_OPTION (pfile, discard_comments) = 1; CPP_OPTION (pfile, discard_comments_in_macro_exp) = 1; + CPP_OPTION (pfile, max_include_depth) = 200; CPP_OPTION (pfile, tabstop) = 8; CPP_OPTION (pfile, operator_names) = 1; CPP_OPTION (pfile, warn_trigraphs) = 2; diff --git a/libcpp/internal.h b/libcpp/internal.h index 5b9c389bb49..0ab44706864 100644 --- a/libcpp/internal.h +++ b/libcpp/internal.h @@ -74,10 +74,6 @@ struct cset_converter linemap_line_start (PFILE->line_table, line + 1, COLS_HINT); \ } while (0) -/* Maximum nesting of cpp_buffers. We use a static limit, partly for - efficiency, and partly to limit runaway recursion. */ -#define CPP_STACK_MAX 200 - /* Host alignment handling. */ struct dummy { -- 2.30.2