diff options
author | Zack Weinberg <zack@wolery.cumb.org> | 2000-02-02 21:41:35 +0000 |
---|---|---|
committer | Zack Weinberg <zack@gcc.gnu.org> | 2000-02-02 21:41:35 +0000 |
commit | 5237f531dafcdf5a118ec501b0bbea1ee4e0928c (patch) | |
tree | 85f4994520bd25edda71f41ae96e75498894cb12 /gcc | |
parent | 3e7cd49fee867f8af4815815ded1dd621d27ceab (diff) | |
download | gcc-5237f531dafcdf5a118ec501b0bbea1ee4e0928c.zip gcc-5237f531dafcdf5a118ec501b0bbea1ee4e0928c.tar.gz gcc-5237f531dafcdf5a118ec501b0bbea1ee4e0928c.tar.bz2 |
cpplib.h (cpp_reader): Add new flag, no_directives.
* cpplib.h (cpp_reader): Add new flag, no_directives.
* cpphash.c (macarg): Set it.
* cpplib.c (handle_directive): If no_directives is on and we
find a directive, issue an error and discard the line.
From-SVN: r31763
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/cpphash.c | 2 | ||||
-rw-r--r-- | gcc/cpplib.c | 10 | ||||
-rw-r--r-- | gcc/cpplib.h | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/undef.c | 14 |
5 files changed, 37 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9e38249..d3e73b9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2000-02-02 Zack Weinberg <zack@wolery.cumb.org> + + * cpplib.h (cpp_reader): Add new flag, no_directives. + * cpphash.c (macarg): Set it. + * cpplib.c (handle_directive): If no_directives is on and we + find a directive, issue an error and discard the line. + Wed Feb 2 13:07:10 2000 Jim Wilson <wilson@cygnus.com> * config/sparc/sparc.h (PREFERRED_RELOAD_CLASS): Delete 'E' check for diff --git a/gcc/cpphash.c b/gcc/cpphash.c index 8a0c887..a7f19f1 100644 --- a/gcc/cpphash.c +++ b/gcc/cpphash.c @@ -783,6 +783,7 @@ macarg (pfile, rest_args) /* Try to parse as much of the argument as exists at this input stack level. */ pfile->no_macro_expand++; + pfile->no_directives++; CPP_OPTIONS (pfile)->no_line_commands++; for (;;) { @@ -823,6 +824,7 @@ done: CPP_OPTIONS (pfile)->put_out_comments = save_put_out_comments; CPP_OPTIONS (pfile)->no_line_commands--; pfile->no_macro_expand--; + pfile->no_directives--; return token; } diff --git a/gcc/cpplib.c b/gcc/cpplib.c index cdfdaa3..5375d2b 100644 --- a/gcc/cpplib.c +++ b/gcc/cpplib.c @@ -568,7 +568,15 @@ handle_directive (pfile) } CPP_SET_WRITTEN (pfile, old_written); - (*kt->func) (pfile, kt); + + if (pfile->no_directives) + { + cpp_error (pfile, "`#%s' may not be used inside a macro argument", + kt->name); + skip_rest_of_line (pfile); + } + else + (*kt->func) (pfile, kt); return 1; } diff --git a/gcc/cpplib.h b/gcc/cpplib.h index 882f462..c225916 100644 --- a/gcc/cpplib.h +++ b/gcc/cpplib.h @@ -212,6 +212,11 @@ struct cpp_reader /* If non-zero, macros are not expanded. */ char no_macro_expand; + /* If non-zero, directives cause a hard error. Used when parsing + macro arguments. */ + + char no_directives; + /* Print column number in error messages. */ char show_column; diff --git a/gcc/testsuite/gcc.dg/undef.c b/gcc/testsuite/gcc.dg/undef.c new file mode 100644 index 0000000..024efce --- /dev/null +++ b/gcc/testsuite/gcc.dg/undef.c @@ -0,0 +1,14 @@ +/* { dg-do preprocess } */ + +/* 6.9.3.11: ...If there are sequences of preprocessing tokens within + the list of arguments that would otherwise act as preprocessing + directives, the behavior is undefined. + + I choose to make this a hard error. It definitely should not cause + a core dump. */ + +#define foo(bar) bar + +foo( blah +#undef foo /* { dg-error "may not be used inside" "foo(#undef foo)" } */ + blah ) |