diff options
author | dmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4> | 2016-01-27 18:57:51 +0000 |
---|---|---|
committer | dmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4> | 2016-01-27 18:57:51 +0000 |
commit | eec964263bcfb34e76b533f7685b320024f6d972 (patch) | |
tree | f6cecd18c9211abd83605d0385a9448c4f50e786 | |
parent | 7795ac510ed6693ab398710d4e4d5633718c8f76 (diff) | |
download | gcc-eec964263bcfb34e76b533f7685b320024f6d972.tar.gz |
libcpp: use better locations for _Pragma tokens (preprocessor/69126)
gcc/testsuite/ChangeLog:
PR preprocessor/69126
* c-c++-common/pr69126.c: New test case.
libcpp/ChangeLog:
PR preprocessor/69126
* directives.c (destringize_and_run): Add expansion_loc param; use
it when handling unexpanded pragmas to fixup the locations of the
synthesized tokens.
(_cpp_do__Pragma): Add expansion_loc param and use it when calling
destringize_and_run.
* internal.h (_cpp_do__Pragma): Add expansion_loc param.
* macro.c (builtin_macro): Pass expansion location of _Pragma to
_cpp_do__Pragma.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@232893 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/pr69126.c | 22 | ||||
-rw-r--r-- | libcpp/ChangeLog | 12 | ||||
-rw-r--r-- | libcpp/directives.c | 13 | ||||
-rw-r--r-- | libcpp/internal.h | 2 | ||||
-rw-r--r-- | libcpp/macro.c | 2 |
6 files changed, 51 insertions, 5 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b3af22c448d..e674bf495ba 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-01-27 David Malcolm <dmalcolm@redhat.com> + + PR preprocessor/69126 + * c-c++-common/pr69126.c: New test case. + 2016-01-27 Ian Lance Taylor <iant@google.com> * gcc.dg/tree-ssa/ivopt_5.c: New test. diff --git a/gcc/testsuite/c-c++-common/pr69126.c b/gcc/testsuite/c-c++-common/pr69126.c new file mode 100644 index 00000000000..fb4dcfb0169 --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr69126.c @@ -0,0 +1,22 @@ +/* { dg-options "-Wunused-variable" } */ + +#pragma GCC diagnostic push +int f() +{ + _Pragma("GCC diagnostic ignored \"-Wunused-variable\"") + int x; + return 0; +} +#pragma GCC diagnostic pop + +#pragma GCC diagnostic push +#define MACRO \ + _Pragma("GCC diagnostic ignored \"-Wunused-variable\"") \ + int x; + +int g() +{ + MACRO; + return 0; +} +#pragma GCC diagnostic pop diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index da733b705b0..eff304f0920 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,15 @@ +2016-01-27 David Malcolm <dmalcolm@redhat.com> + + PR preprocessor/69126 + * directives.c (destringize_and_run): Add expansion_loc param; use + it when handling unexpanded pragmas to fixup the locations of the + synthesized tokens. + (_cpp_do__Pragma): Add expansion_loc param and use it when calling + destringize_and_run. + * internal.h (_cpp_do__Pragma): Add expansion_loc param. + * macro.c (builtin_macro): Pass expansion location of _Pragma to + _cpp_do__Pragma. + 2016-01-14 David Malcolm <dmalcolm@redhat.com> PR preprocessor/69177 diff --git a/libcpp/directives.c b/libcpp/directives.c index eff1861fceb..a1e1239bf99 100644 --- a/libcpp/directives.c +++ b/libcpp/directives.c @@ -1753,7 +1753,8 @@ get__Pragma_string (cpp_reader *pfile) /* Destringize IN into a temporary buffer, by removing the first \ of \" and \\ sequences, and process the result as a #pragma directive. */ static void -destringize_and_run (cpp_reader *pfile, const cpp_string *in) +destringize_and_run (cpp_reader *pfile, const cpp_string *in, + source_location expansion_loc) { const unsigned char *src, *limit; char *dest, *result; @@ -1833,6 +1834,12 @@ destringize_and_run (cpp_reader *pfile, const cpp_string *in) toks = XRESIZEVEC (cpp_token, toks, maxcount); } toks[count] = *cpp_get_token (pfile); + /* _Pragma is a builtin, so we're not within a macro-map, and so + the token locations are set to bogus ordinary locations + near to, but after that of the "_Pragma". + Paper over this by setting them equal to the location of the + _Pragma itself (PR preprocessor/69126). */ + toks[count].src_loc = expansion_loc; /* Macros have been already expanded by cpp_get_token if the pragma allowed expansion. */ toks[count++].flags |= NO_EXPAND; @@ -1867,14 +1874,14 @@ destringize_and_run (cpp_reader *pfile, const cpp_string *in) /* Handle the _Pragma operator. Return 0 on error, 1 if ok. */ int -_cpp_do__Pragma (cpp_reader *pfile) +_cpp_do__Pragma (cpp_reader *pfile, source_location expansion_loc) { const cpp_token *string = get__Pragma_string (pfile); pfile->directive_result.type = CPP_PADDING; if (string) { - destringize_and_run (pfile, &string->val.str); + destringize_and_run (pfile, &string->val.str, expansion_loc); return 1; } cpp_error (pfile, CPP_DL_ERROR, diff --git a/libcpp/internal.h b/libcpp/internal.h index e04ae68ce04..bafd4803865 100644 --- a/libcpp/internal.h +++ b/libcpp/internal.h @@ -688,7 +688,7 @@ extern int _cpp_handle_directive (cpp_reader *, int); extern void _cpp_define_builtin (cpp_reader *, const char *); extern char ** _cpp_save_pragma_names (cpp_reader *); extern void _cpp_restore_pragma_names (cpp_reader *, char **); -extern int _cpp_do__Pragma (cpp_reader *); +extern int _cpp_do__Pragma (cpp_reader *, source_location); extern void _cpp_init_directives (cpp_reader *); extern void _cpp_init_internal_pragmas (cpp_reader *); extern void _cpp_do_file_change (cpp_reader *, enum lc_reason, const char *, diff --git a/libcpp/macro.c b/libcpp/macro.c index ca1d1d6fdde..cfb09ceaddd 100644 --- a/libcpp/macro.c +++ b/libcpp/macro.c @@ -430,7 +430,7 @@ builtin_macro (cpp_reader *pfile, cpp_hashnode *node, source_location loc) if (pfile->state.in_directive) return 0; - return _cpp_do__Pragma (pfile); + return _cpp_do__Pragma (pfile, loc); } buf = _cpp_builtin_macro_text (pfile, node); |