* [PATCH][Preprocessor]patch to fix PR 90581
@ 2019-05-30 16:26 Qing Zhao
2019-05-30 19:20 ` Bernhard Reutner-Fischer
` (2 more replies)
0 siblings, 3 replies; 13+ messages in thread
From: Qing Zhao @ 2019-05-30 16:26 UTC (permalink / raw)
To: David Malcolm; +Cc: gcc Patches, bernhard Reutner-Fischer
[-- Attachment #1: Type: text/plain, Size: 1569 bytes --]
Hi,
PR 90581 (provide an option to adjust the maximum depth of nested #include)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90581
is to add a new cpp option -fmax-inlcude-depth to set the maximum depth of nested #include.
'-fmax-include-depth=DEPTH'
Set the maximum depth of the nested include. The default value is
200.
Please check the attached patch.
I have done bootstrap and regression test on X86, no any issue.
thanks a lot.
Qing.
gcc/ChangeLog:
2019-05-30 qing zhao <qing.zhao@oracle.com>
* doc/cppopts.texi: Add document for -fmax-include-depth.
* doc/invoke.texi (Preprocessor Options): List -fmax-include-depth.
libcpp/ChangeLog:
2019-05-30 qing zhao <qing.zhao@oracle.com>
* 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.
gcc/c-family/ChangeLog:
2019-05-30 qing zhao <qing.zhao@oracle.com>
* c-opts.c (c_common_handle_option): Handle -fmax-include-depth.
* c.opt: Add new option -fmax-include-depth.
gcc/testsuite/ChangeLog:
2019-05-30 qing zhao <qing.zhao@oracle.com>
* 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.
[-- Attachment #2: 0001-PR-preprocessor-90581.patch --]
[-- Type: application/octet-stream, Size: 6698 bytes --]
From 3ec276f1fe32f8adf495676586441e7d51d1e524 Mon Sep 17 00:00:00 2001
From: qing zhao <qing.zhao@oracle.com>
Date: Thu, 30 May 2019 11:10:59 -0400
Subject: [PATCH] PR preprocessor/90581 provide an option to adjust the maximum
depth of nested #include
Add a cpp option -fmax-include-depth to set the maximum depth
of nested #include.
---
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/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/directives.c | 2 +-
libcpp/include/cpplib.h | 3 +++
libcpp/init.c | 1 +
libcpp/internal.h | 4 ----
11 files changed, 24 insertions(+), 5 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/c-family/c-opts.c b/gcc/c-family/c-opts.c
index 954b6a4..188da43 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 046d489..071eed2 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -1563,6 +1563,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=<number> Set the maximum number of depth of 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 48c574f..53c9fbd 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 value 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 3e4f012..6f94c8b 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -515,6 +515,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/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 0000000..4e610c0
--- /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 0000000..c167587
--- /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 0000000..bf7b9de
--- /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 too deeply" } */
diff --git a/libcpp/directives.c b/libcpp/directives.c
index 3ee8bc4..480c282 100644
--- a/libcpp/directives.c
+++ b/libcpp/directives.c
@@ -831,7 +831,7 @@ do_include_common (cpp_reader *pfile, enum include_type type)
}
/* Prevent #include recursion. */
- if (pfile->line_table->depth >= CPP_STACK_MAX)
+ if (pfile->line_table->depth >= CPP_OPTION (pfile, max_include_depth))
cpp_error (pfile, CPP_DL_ERROR, "#include nested too deeply");
else
{
diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
index 3edb93d..44d6327 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 depths for 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 c0c9020..d06f95e 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 5b9c389..0ab4470 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
{
--
1.8.3.1
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH][Preprocessor]patch to fix PR 90581
2019-05-30 16:26 [PATCH][Preprocessor]patch to fix PR 90581 Qing Zhao
@ 2019-05-30 19:20 ` Bernhard Reutner-Fischer
2019-05-30 20:35 ` Qing Zhao
2019-05-30 20:49 ` David Malcolm
2019-06-03 14:49 ` [PATCH][Preprocessor][Version 2]patch " Qing Zhao
2 siblings, 1 reply; 13+ messages in thread
From: Bernhard Reutner-Fischer @ 2019-05-30 19:20 UTC (permalink / raw)
To: Qing Zhao, David Malcolm; +Cc: gcc Patches
On 30 May 2019 18:23:43 CEST, Qing Zhao <qing.zhao@oracle.com> wrote:
>Hi,
>
>PR 90581 (provide an option to adjust the maximum depth of nested
>#include)
>https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90581
>
>is to add a new cpp option -fmax-inlcude-depth
Typo inl vs inc.
Why isn't this a param?
Wouldn't a param ease range checking not to overflow the uint max and maybe automagically provide diagnostics for out of range input?
In the docs you mix "number" and "depth".
thanks,
> to set the maximum depth
>of nested #include.
>
>'-fmax-include-depth=DEPTH'
> Set the maximum depth of the nested include. The default value is
> 200.
>
>Please check the attached patch.
>I have done bootstrap and regression test on X86, no any issue.
>
>thanks a lot.
>
>Qing.
>
>
>
>gcc/ChangeLog:
>
>2019-05-30 qing zhao <qing.zhao@oracle.com>
>
> * doc/cppopts.texi: Add document for -fmax-include-depth.
> * doc/invoke.texi (Preprocessor Options): List -fmax-include-depth.
>
>libcpp/ChangeLog:
>
>2019-05-30 qing zhao <qing.zhao@oracle.com>
>
> * 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.
>
>gcc/c-family/ChangeLog:
>
>2019-05-30 qing zhao <qing.zhao@oracle.com>
>
> * c-opts.c (c_common_handle_option): Handle -fmax-include-depth.
> * c.opt: Add new option -fmax-include-depth.
>
>gcc/testsuite/ChangeLog:
>
>2019-05-30 qing zhao <qing.zhao@oracle.com>
>
> * 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.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH][Preprocessor]patch to fix PR 90581
2019-05-30 19:20 ` Bernhard Reutner-Fischer
@ 2019-05-30 20:35 ` Qing Zhao
2019-05-30 20:42 ` David Malcolm
0 siblings, 1 reply; 13+ messages in thread
From: Qing Zhao @ 2019-05-30 20:35 UTC (permalink / raw)
To: Bernhard Reutner-Fischer; +Cc: David Malcolm, gcc Patches
> On May 30, 2019, at 2:13 PM, Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> wrote:
>
> On 30 May 2019 18:23:43 CEST, Qing Zhao <qing.zhao@oracle.com> wrote:
>> Hi,
>>
>> PR 90581 (provide an option to adjust the maximum depth of nested
>> #include)
>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90581
>>
>> is to add a new cpp option -fmax-inlcude-depth
>
> Typo inl vs inc.
Okay, will fix this.
>
> Why isn't this a param?
do you mean to change “-fmax-include-depth=” to “-param max-include-depth=“?
> Wouldn't a param ease range checking not to overflow the uint max and maybe automagically provide diagnostics for out of range input?
>
> In the docs you mix "number" and "depth”.
will fix this.
thanks for the feedback.
Qing
>
> thanks,
>
>> to set the maximum depth
>> of nested #include.
>>
>> '-fmax-include-depth=DEPTH'
>> Set the maximum depth of the nested include. The default value is
>> 200.
>>
>> Please check the attached patch.
>> I have done bootstrap and regression test on X86, no any issue.
>>
>> thanks a lot.
>>
>> Qing.
>>
>>
>>
>> gcc/ChangeLog:
>>
>> 2019-05-30 qing zhao <qing.zhao@oracle.com>
>>
>> * doc/cppopts.texi: Add document for -fmax-include-depth.
>> * doc/invoke.texi (Preprocessor Options): List -fmax-include-depth.
>>
>> libcpp/ChangeLog:
>>
>> 2019-05-30 qing zhao <qing.zhao@oracle.com>
>>
>> * 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.
>>
>> gcc/c-family/ChangeLog:
>>
>> 2019-05-30 qing zhao <qing.zhao@oracle.com>
>>
>> * c-opts.c (c_common_handle_option): Handle -fmax-include-depth.
>> * c.opt: Add new option -fmax-include-depth.
>>
>> gcc/testsuite/ChangeLog:
>>
>> 2019-05-30 qing zhao <qing.zhao@oracle.com>
>>
>> * 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.
>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH][Preprocessor]patch to fix PR 90581
2019-05-30 20:35 ` Qing Zhao
@ 2019-05-30 20:42 ` David Malcolm
2019-05-30 20:46 ` Qing Zhao
0 siblings, 1 reply; 13+ messages in thread
From: David Malcolm @ 2019-05-30 20:42 UTC (permalink / raw)
To: Qing Zhao, Bernhard Reutner-Fischer; +Cc: gcc Patches
On Thu, 2019-05-30 at 15:17 -0500, Qing Zhao wrote:
> > On May 30, 2019, at 2:13 PM, Bernhard Reutner-Fischer <rep.dot.nop@
> > gmail.com> wrote:
> >
> > On 30 May 2019 18:23:43 CEST, Qing Zhao <qing.zhao@oracle.com>
> > wrote:
> > > Hi,
> > >
> > > PR 90581 (provide an option to adjust the maximum depth of nested
> > > #include)
> > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90581
> > >
> > > is to add a new cpp option -fmax-inlcude-depth
> >
> > Typo inl vs inc.
>
> Okay, will fix this.
>
> >
> > Why isn't this a param?
>
> do you mean to change â-fmax-include-depth=â to â-param max-include-
> depth=â?
>
That sounds like a good idea to me.
> > Wouldn't a param ease range checking not to overflow the uint max
> > and maybe automagically provide diagnostics for out of range input?
(indeed)
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH][Preprocessor]patch to fix PR 90581
2019-05-30 20:42 ` David Malcolm
@ 2019-05-30 20:46 ` Qing Zhao
0 siblings, 0 replies; 13+ messages in thread
From: Qing Zhao @ 2019-05-30 20:46 UTC (permalink / raw)
To: David Malcolm; +Cc: Bernhard Reutner-Fischer, gcc Patches
> On May 30, 2019, at 3:38 PM, David Malcolm <dmalcolm@redhat.com> wrote:
>
> On Thu, 2019-05-30 at 15:17 -0500, Qing Zhao wrote:
>>> On May 30, 2019, at 2:13 PM, Bernhard Reutner-Fischer <rep.dot.nop@
>>> gmail.com> wrote:
>>>
>>> On 30 May 2019 18:23:43 CEST, Qing Zhao <qing.zhao@oracle.com>
>>> wrote:
>>>> Hi,
>>>>
>>>> PR 90581 (provide an option to adjust the maximum depth of nested
>>>> #include)
>>>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90581
>>>>
>>>> is to add a new cpp option -fmax-inlcude-depth
>>>
>>> Typo inl vs inc.
>>
>> Okay, will fix this.
>>
>>>
>>> Why isn't this a param?
>>
>> do you mean to change “-fmax-include-depth=” to “-param max-include-
>> depth=“?
>>
>
> That sounds like a good idea to me.
can -param be accepted by preprocessor?
I didn’t see any -param in gcc/c-family/c.opt.
where should I define a -param for preprocessor?
thanks.
Qing
>
>>> Wouldn't a param ease range checking not to overflow the uint max
>>> and maybe automagically provide diagnostics for out of range input?
>
> (indeed)
>
>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH][Preprocessor]patch to fix PR 90581
2019-05-30 16:26 [PATCH][Preprocessor]patch to fix PR 90581 Qing Zhao
2019-05-30 19:20 ` Bernhard Reutner-Fischer
@ 2019-05-30 20:49 ` David Malcolm
2019-05-30 21:05 ` Qing Zhao
2019-05-31 9:01 ` Richard Biener
2019-06-03 14:49 ` [PATCH][Preprocessor][Version 2]patch " Qing Zhao
2 siblings, 2 replies; 13+ messages in thread
From: David Malcolm @ 2019-05-30 20:49 UTC (permalink / raw)
To: Qing Zhao; +Cc: gcc Patches, bernhard Reutner-Fischer
On Thu, 2019-05-30 at 11:23 -0500, Qing Zhao wrote:
> Hi,
>
> PR 90581 (provide an option to adjust the maximum depth of nested
> #include)
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90581
>
> is to add a new cpp option -fmax-inlcude-depth to set the maximum
> depth of nested #include.
>
> '-fmax-include-depth=DEPTH'
> Set the maximum depth of the nested include. The default value
> is
> 200.
>
> Please check the attached patch.
> I have done bootstrap and regression test on X86, no any issue.
>
> thanks a lot.
>
> Qing.
>
Thanks for working on this. It's looking promising, but I agree that a
param would be better than an option.
One idea that occurred to me looking at the patch...
> index 3ee8bc4..480c282 100644
> --- a/libcpp/directives.c
> +++ b/libcpp/directives.c
> @@ -831,7 +831,7 @@ do_include_common (cpp_reader *pfile, enum include_type type)
> }
>
> /* Prevent #include recursion. */
> - if (pfile->line_table->depth >= CPP_STACK_MAX)
> + if (pfile->line_table->depth >= CPP_OPTION (pfile, max_include_depth))
> cpp_error (pfile, CPP_DL_ERROR, "#include nested too deeply");
...a nice usability tweak here would be to give a hint about the new
param, to give the user an idea on how to increase the limit.
Maybe something like:
cpp_error (pfile, CPP_DL_ERROR,
"%<#include%> nested too deeply (depth %i);"
" use %<--param max-include-depth=LIMIT%> to support deeper nesting",
pfile->line_table->depth);
(though probably that would be better as a followup "note")
Dave
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH][Preprocessor]patch to fix PR 90581
2019-05-30 20:49 ` David Malcolm
@ 2019-05-30 21:05 ` Qing Zhao
2019-05-31 9:01 ` Richard Biener
1 sibling, 0 replies; 13+ messages in thread
From: Qing Zhao @ 2019-05-30 21:05 UTC (permalink / raw)
To: David Malcolm; +Cc: gcc Patches, bernhard Reutner-Fischer
> On May 30, 2019, at 3:46 PM, David Malcolm <dmalcolm@redhat.com> wrote:
>
> On Thu, 2019-05-30 at 11:23 -0500, Qing Zhao wrote:
>> Hi,
>>
>> PR 90581 (provide an option to adjust the maximum depth of nested
>> #include)
>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90581
>>
>> is to add a new cpp option -fmax-inlcude-depth to set the maximum
>> depth of nested #include.
>>
>> '-fmax-include-depth=DEPTH'
>> Set the maximum depth of the nested include. The default value
>> is
>> 200.
>>
>> Please check the attached patch.
>> I have done bootstrap and regression test on X86, no any issue.
>>
>> thanks a lot.
>>
>> Qing.
>>
> Thanks for working on this. It's looking promising, but I agree that a
> param would be better than an option.
I just checked both gcc source code and gcc documentation.
looks like that
—param name=value
is an option for “Options that Control Optimization”.
Since this new option is for preprocessor, I think that it might not be fit in?
let me know if I miss anything here.
>
> One idea that occurred to me looking at the patch...
>
>> index 3ee8bc4..480c282 100644
>> --- a/libcpp/directives.c
>> +++ b/libcpp/directives.c
>> @@ -831,7 +831,7 @@ do_include_common (cpp_reader *pfile, enum include_type type)
>> }
>>
>> /* Prevent #include recursion. */
>> - if (pfile->line_table->depth >= CPP_STACK_MAX)
>> + if (pfile->line_table->depth >= CPP_OPTION (pfile, max_include_depth))
>> cpp_error (pfile, CPP_DL_ERROR, "#include nested too deeply");
>
> ...a nice usability tweak here would be to give a hint about the new
> param, to give the user an idea on how to increase the limit.
Yes, I agree.
will fix this.
Thanks.
Qing
>
> Maybe something like:
>
> cpp_error (pfile, CPP_DL_ERROR,
> "%<#include%> nested too deeply (depth %i);"
> " use %<--param max-include-depth=LIMIT%> to support deeper nesting",
> pfile->line_table->depth);
>
> (though probably that would be better as a followup "note")
>
> Dave
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH][Preprocessor]patch to fix PR 90581
2019-05-30 20:49 ` David Malcolm
2019-05-30 21:05 ` Qing Zhao
@ 2019-05-31 9:01 ` Richard Biener
1 sibling, 0 replies; 13+ messages in thread
From: Richard Biener @ 2019-05-31 9:01 UTC (permalink / raw)
To: David Malcolm; +Cc: Qing Zhao, gcc Patches, bernhard Reutner-Fischer
On Thu, May 30, 2019 at 10:46 PM David Malcolm <dmalcolm@redhat.com> wrote:
>
> On Thu, 2019-05-30 at 11:23 -0500, Qing Zhao wrote:
> > Hi,
> >
> > PR 90581 (provide an option to adjust the maximum depth of nested
> > #include)
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90581
> >
> > is to add a new cpp option -fmax-inlcude-depth to set the maximum
> > depth of nested #include.
> >
> > '-fmax-include-depth=DEPTH'
> > Set the maximum depth of the nested include. The default value
> > is
> > 200.
> >
> > Please check the attached patch.
> > I have done bootstrap and regression test on X86, no any issue.
> >
> > thanks a lot.
> >
> > Qing.
> >
> Thanks for working on this. It's looking promising, but I agree that a
> param would be better than an option.
Not sure - this is for language limits and we do have existing
like -ftemplate-backtrace-limit and -ftemplate-depth.
> One idea that occurred to me looking at the patch...
>
> > index 3ee8bc4..480c282 100644
> > --- a/libcpp/directives.c
> > +++ b/libcpp/directives.c
> > @@ -831,7 +831,7 @@ do_include_common (cpp_reader *pfile, enum include_type type)
> > }
> >
> > /* Prevent #include recursion. */
> > - if (pfile->line_table->depth >= CPP_STACK_MAX)
> > + if (pfile->line_table->depth >= CPP_OPTION (pfile, max_include_depth))
> > cpp_error (pfile, CPP_DL_ERROR, "#include nested too deeply");
>
> ...a nice usability tweak here would be to give a hint about the new
> param, to give the user an idea on how to increase the limit.
>
> Maybe something like:
>
> cpp_error (pfile, CPP_DL_ERROR,
> "%<#include%> nested too deeply (depth %i);"
> " use %<--param max-include-depth=LIMIT%> to support deeper nesting",
> pfile->line_table->depth);
>
> (though probably that would be better as a followup "note")
>
> Dave
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH][Preprocessor][Version 2]patch to fix PR 90581
2019-05-30 16:26 [PATCH][Preprocessor]patch to fix PR 90581 Qing Zhao
2019-05-30 19:20 ` Bernhard Reutner-Fischer
2019-05-30 20:49 ` David Malcolm
@ 2019-06-03 14:49 ` Qing Zhao
2019-06-03 15:03 ` Paolo Carlini
2019-06-03 16:46 ` Qing Zhao
2 siblings, 2 replies; 13+ messages in thread
From: Qing Zhao @ 2019-06-03 14:49 UTC (permalink / raw)
To: David Malcolm; +Cc: gcc Patches, bernhard Reutner-Fischer
[-- Attachment #1: Type: text/plain, Size: 1357 bytes --]
Hi, this is the 2nd version of the patch.
the main changes are:
1. some typo.
2. enhance the error message to provide user idea on how to increase the limit.
bootstrap and regression tested on X86, no issue.
Okay for trunk?
thanks.
Qing
gcc/ChangeLog:
2019-06-03 qing zhao <qing.zhao@oracle.com>
* doc/cppopts.texi: Add document for -fmax-include-depth.
* doc/invoke.texi (Preprocessor Options): List -fmax-include-depth.
libcpp/ChangeLog:
2019-06-03 qing zhao <qing.zhao@oracle.com>
* 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.
gcc/c-family/ChangeLog:
2019-06-03 qing zhao <qing.zhao@oracle.com>
* c-opts.c (c_common_handle_option): Handle -fmax-include-depth.
* c.opt: Add new option -fmax-include-depth.
gcc/testsuite/ChangeLog:
2019-06-03 qing zhao <qing.zhao@oracle.com>
* 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.
[-- Attachment #2: 0001-PR-preprocessor-90581.patch --]
[-- Type: application/octet-stream, Size: 7101 bytes --]
From facae4813998fbca693d5b0dd93914e1af1b5dc4 Mon Sep 17 00:00:00 2001
From: qing zhao <qing.zhao@oracle.com>
Date: Fri, 31 May 2019 13:22:10 -0400
Subject: [PATCH] PR preprocessor/90581 provide an option to adjust the maximum
depth of nested #include
Add a cpp option -fmax-include-depth to set the maximum depth
of nested #include.
---
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/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/directives.c | 9 +++++++--
libcpp/include/cpplib.h | 3 +++
libcpp/init.c | 1 +
libcpp/internal.h | 4 ----
11 files changed, 30 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/c-family/c-opts.c b/gcc/c-family/c-opts.c
index 954b6a4..188da43 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 046d489..071eed2 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -1563,6 +1563,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=<number> Set the maximum number of depth of 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 48c574f..83ca9f8 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 number of 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 3e4f012..6f94c8b 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -515,6 +515,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/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 0000000..4e610c0
--- /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 0000000..c167587
--- /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 0000000..bd8cc3a
--- /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/directives.c b/libcpp/directives.c
index 3ee8bc4..2fdfaf0 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 3edb93d..44d6327 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 depths for 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 c0c9020..d06f95e 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 5b9c389..0ab4470 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
{
--
1.8.3.1
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH][Preprocessor][Version 2]patch to fix PR 90581
2019-06-03 14:49 ` [PATCH][Preprocessor][Version 2]patch " Qing Zhao
@ 2019-06-03 15:03 ` Paolo Carlini
2019-06-03 16:42 ` [PATCH][Preprocessor][Version 3]patch " Qing Zhao
2019-06-03 16:46 ` Qing Zhao
1 sibling, 1 reply; 13+ messages in thread
From: Paolo Carlini @ 2019-06-03 15:03 UTC (permalink / raw)
To: Qing Zhao, David Malcolm; +Cc: gcc Patches, bernhard Reutner-Fischer
Hi,
a few minor comments.
On 03/06/19 16:49, Qing Zhao wrote:
> +fmax-include-depth=
> +C ObjC C++ ObjC++ Joined RejectNegative UInteger
> +fmax-include-depth=<number> Set the maximum number of depth of nested #include.
I think you want something like "Set the maximum depth of nested #include".
> +@item -fmax-include-depth=@var{depth}
> +@opindex fmax-include-depth
> +Set the maximum number of depth of the nested include. The default is 200.
Likewise, plus include or #include?
In any case the wording should be consistent with the actual cpp_error
message below in your attachment, thus, in particular, no "number".
> + /* the maximum depths for nested #include. */
Upper case "The". "for" or "of"? Again, consistency.
Paolo.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH][Preprocessor][Version 3]patch to fix PR 90581
2019-06-03 15:03 ` Paolo Carlini
@ 2019-06-03 16:42 ` Qing Zhao
0 siblings, 0 replies; 13+ messages in thread
From: Qing Zhao @ 2019-06-03 16:42 UTC (permalink / raw)
To: Paolo Carlini; +Cc: gcc Patches, bernhard Reutner-Fischer, David Malcolm
Hi, Paolo,
thanks for the comment.
I will fix these issues.
Qing
> On Jun 3, 2019, at 10:03 AM, Paolo Carlini <paolo.carlini@oracle.com> wrote:
>
> Hi,
>
> a few minor comments.
>
> On 03/06/19 16:49, Qing Zhao wrote:
>> +fmax-include-depth=
>> +C ObjC C++ ObjC++ Joined RejectNegative UInteger
>> +fmax-include-depth=<number> Set the maximum number of depth of nested #include.
>
> I think you want something like "Set the maximum depth of nested #include".
>
>> +@item -fmax-include-depth=@var{depth}
>> +@opindex fmax-include-depth
>> +Set the maximum number of depth of the nested include. The default is 200.
>
> Likewise, plus include or #include?
>
> In any case the wording should be consistent with the actual cpp_error message below in your attachment, thus, in particular, no "number".
>
>> + /* the maximum depths for nested #include. */
>
> Upper case "The". "for" or "of"? Again, consistency.
>
> Paolo.
>
>
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH][Preprocessor][Version 3]patch to fix PR 90581
2019-06-03 14:49 ` [PATCH][Preprocessor][Version 2]patch " Qing Zhao
2019-06-03 15:03 ` Paolo Carlini
@ 2019-06-03 16:46 ` Qing Zhao
2019-06-07 8:26 ` Richard Biener
1 sibling, 1 reply; 13+ messages in thread
From: Qing Zhao @ 2019-06-03 16:46 UTC (permalink / raw)
To: David Malcolm; +Cc: gcc Patches, bernhard Reutner-Fischer
[-- Attachment #1: Type: text/plain, Size: 1214 bytes --]
Hi,
this is the 3rd version of the patch, which fixed the issues Paolo raised in the previous email.
Okay for trunk?
thanks.
gcc/ChangeLog:
2019-06-03 qing zhao <qing.zhao@oracle.com>
* doc/cppopts.texi: Add document for -fmax-include-depth.
* doc/invoke.texi (Preprocessor Options): List -fmax-include-depth.
libcpp/ChangeLog:
2019-06-03 qing zhao <qing.zhao@oracle.com>
* 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.
gcc/c-family/ChangeLog:
2019-06-03 qing zhao <qing.zhao@oracle.com>
* c-opts.c (c_common_handle_option): Handle -fmax-include-depth.
* c.opt: Add new option -fmax-include-depth.
gcc/testsuite/ChangeLog:
2019-06-03 qing zhao <qing.zhao@oracle.com>
* 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.
[-- Attachment #2: 0001-PR-preprocessor-90581.patch --]
[-- Type: application/octet-stream, Size: 7095 bytes --]
From de7495f1caa22c698a09e5c7d3a27db8ec31017c Mon Sep 17 00:00:00 2001
From: qing zhao <qing.zhao@oracle.com>
Date: Mon, 3 Jun 2019 12:12:43 -0400
Subject: [PATCH] PR preprocessor/90581 provide an option to adjust the maximum
depth of the nested #include
Add a cpp option -fmax-include-depth to set the maximum depth
of the nested #include.
---
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/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/directives.c | 9 +++++++--
libcpp/include/cpplib.h | 3 +++
libcpp/init.c | 1 +
libcpp/internal.h | 4 ----
11 files changed, 30 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/c-family/c-opts.c b/gcc/c-family/c-opts.c
index 954b6a4..188da43 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 046d489..5be5729 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -1563,6 +1563,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=<number> 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 48c574f..61e22cd 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 3e4f012..6f94c8b 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -515,6 +515,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/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 0000000..4e610c0
--- /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 0000000..c167587
--- /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 0000000..bd8cc3a
--- /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/directives.c b/libcpp/directives.c
index 3ee8bc4..2fdfaf0 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 3edb93d..91d97f9 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 c0c9020..d06f95e 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 5b9c389..0ab4470 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
{
--
1.8.3.1
[-- Attachment #3: Type: text/plain, Size: 3 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH][Preprocessor][Version 3]patch to fix PR 90581
2019-06-03 16:46 ` Qing Zhao
@ 2019-06-07 8:26 ` Richard Biener
0 siblings, 0 replies; 13+ messages in thread
From: Richard Biener @ 2019-06-07 8:26 UTC (permalink / raw)
To: Qing Zhao; +Cc: David Malcolm, gcc Patches, bernhard Reutner-Fischer
On Mon, Jun 3, 2019 at 6:46 PM Qing Zhao <qing.zhao@oracle.com> wrote:
>
> Hi,
>
> this is the 3rd version of the patch, which fixed the issues Paolo raised in the previous email.
>
> Okay for trunk?
OK.
Thanks,
Richard.
> thanks.
>
> gcc/ChangeLog:
>
> 2019-06-03 qing zhao <qing.zhao@oracle.com>
>
> * doc/cppopts.texi: Add document for -fmax-include-depth.
> * doc/invoke.texi (Preprocessor Options): List -fmax-include-depth.
>
> libcpp/ChangeLog:
>
> 2019-06-03 qing zhao <qing.zhao@oracle.com>
>
> * 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.
>
> gcc/c-family/ChangeLog:
>
> 2019-06-03 qing zhao <qing.zhao@oracle.com>
>
> * c-opts.c (c_common_handle_option): Handle -fmax-include-depth.
> * c.opt: Add new option -fmax-include-depth.
>
> gcc/testsuite/ChangeLog:
>
> 2019-06-03 qing zhao <qing.zhao@oracle.com>
>
> * 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.
>
>
>
>
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2019-06-07 8:26 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-30 16:26 [PATCH][Preprocessor]patch to fix PR 90581 Qing Zhao
2019-05-30 19:20 ` Bernhard Reutner-Fischer
2019-05-30 20:35 ` Qing Zhao
2019-05-30 20:42 ` David Malcolm
2019-05-30 20:46 ` Qing Zhao
2019-05-30 20:49 ` David Malcolm
2019-05-30 21:05 ` Qing Zhao
2019-05-31 9:01 ` Richard Biener
2019-06-03 14:49 ` [PATCH][Preprocessor][Version 2]patch " Qing Zhao
2019-06-03 15:03 ` Paolo Carlini
2019-06-03 16:42 ` [PATCH][Preprocessor][Version 3]patch " Qing Zhao
2019-06-03 16:46 ` Qing Zhao
2019-06-07 8:26 ` Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).