diff options
author | Qing Zhao <qing.zhao@oracle.com> | 2019-07-02 20:23:30 +0000 |
---|---|---|
committer | Qing Zhao <qinzhao@gcc.gnu.org> | 2019-07-02 20:23:30 +0000 |
commit | 1c6ffbab63f55187909b6d71cfca6080e9cf43cf (patch) | |
tree | 679d86bed67edce3cb9d5cbc6390c7cbaa52e899 /libcpp | |
parent | 709877bf765cbef2d758ecb48c6e34b94e8a7151 (diff) |
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
Diffstat (limited to 'libcpp')
-rw-r--r-- | libcpp/ChangeLog | 10 | ||||
-rw-r--r-- | libcpp/directives.c | 9 | ||||
-rw-r--r-- | libcpp/include/cpplib.h | 3 | ||||
-rw-r--r-- | libcpp/init.c | 1 | ||||
-rw-r--r-- | libcpp/internal.h | 4 |
5 files changed, 21 insertions, 6 deletions
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 <qing.zhao@oracle.com> + + 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 <nathan@acm.org> 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 { |