summaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2006-06-09 21:13:25 +0000
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2006-06-09 21:13:25 +0000
commitadd258d7ce0f3efd6b7c2c635cc9d20c77fc938b (patch)
tree1069b42cba4da5d5d5b7ba05363311e967728b4e /libcpp
parent28143dbb145d8097411e0ebd7543f5d9752492e2 (diff)
downloadgcc-add258d7ce0f3efd6b7c2c635cc9d20c77fc938b.tar.gz
PR preprocessor/27746
* directives.c (do_pragma): Handle pragma with valid namespace and invalid name coming from macro expansion. * directives.c (destringize_and_run): Initialize next field in context. PR c/27747 PR c++/27748 * directives.c (destringize_and_run): Set NO_EXPAND on the tokens. * macro.c (_cpp_backup_tokens): Fix comment typo. testsuite/ PR c/27747 * gcc.dg/cpp/_Pragma6.c: New test. PR c++/27748 * g++.dg/cpp/_Pragma1.C: New test. PR preprocessor/27746 * gcc.dg/gomp/macro-3.c: New test. * gcc.dg/gomp/macro-4.c: New test. * g++.dg/gomp/macro-3.C: New test. * g++.dg/gomp/macro-4.C: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@114519 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog15
-rw-r--r--libcpp/directives.c25
-rw-r--r--libcpp/macro.c2
3 files changed, 39 insertions, 3 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index 80a1868d809..865287b2545 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,18 @@
+2006-06-09 Jakub Jelinek <jakub@redhat.com>
+
+ PR preprocessor/27746
+ * directives.c (do_pragma): Handle pragma with valid namespace
+ and invalid name coming from macro expansion.
+ * directives.c (destringize_and_run): Initialize next field in
+ context.
+
+ PR c/27747
+ PR c++/27748
+ * directives.c (destringize_and_run): Set NO_EXPAND on the
+ tokens.
+
+ * macro.c (_cpp_backup_tokens): Fix comment typo.
+
2006-05-31 Daniel Jacobowitz <dan@codesourcery.com>
* Makefile.in (CATALOGS): Add po/ prefix.
diff --git a/libcpp/directives.c b/libcpp/directives.c
index 0eea67d133c..e08698d76b7 100644
--- a/libcpp/directives.c
+++ b/libcpp/directives.c
@@ -1265,11 +1265,13 @@ do_pragma (cpp_reader *pfile)
{
const struct pragma_entry *p = NULL;
const cpp_token *token, *pragma_token = pfile->cur_token;
+ cpp_token ns_token;
unsigned int count = 1;
pfile->state.prevent_expansion++;
token = cpp_get_token (pfile);
+ ns_token = *token;
if (token->type == CPP_NAME)
{
p = lookup_pragma_entry (pfile->pragmas, token->val.node);
@@ -1318,7 +1320,22 @@ do_pragma (cpp_reader *pfile)
}
else if (pfile->cb.def_pragma)
{
- _cpp_backup_tokens (pfile, count);
+ if (count == 1 || pfile->context->prev == NULL)
+ _cpp_backup_tokens (pfile, count);
+ else
+ {
+ /* Invalid name comes from macro expansion, _cpp_backup_tokens
+ won't allow backing 2 tokens. */
+ /* ??? The token buffer is leaked. Perhaps if def_pragma hook
+ reads both tokens, we could perhaps free it, but if it doesn't,
+ we don't know the exact lifespan. */
+ cpp_token *toks = XNEWVEC (cpp_token, 2);
+ toks[0] = ns_token;
+ toks[0].flags |= NO_EXPAND;
+ toks[1] = *token;
+ toks[1].flags |= NO_EXPAND;
+ _cpp_push_token_context (pfile, NULL, toks, 2);
+ }
pfile->cb.def_pragma (pfile, pfile->directive_line);
}
@@ -1494,6 +1511,7 @@ destringize_and_run (cpp_reader *pfile, const cpp_string *in)
pfile->context = XNEW (cpp_context);
pfile->context->macro = 0;
pfile->context->prev = 0;
+ pfile->context->next = 0;
/* Inline run_directive, since we need to delay the _cpp_pop_buffer
until we've read all of the tokens that we want. */
@@ -1534,7 +1552,10 @@ destringize_and_run (cpp_reader *pfile, const cpp_string *in)
maxcount = maxcount * 3 / 2;
toks = XRESIZEVEC (cpp_token, toks, maxcount);
}
- toks[count++] = *cpp_get_token (pfile);
+ toks[count] = *cpp_get_token (pfile);
+ /* Macros have been already expanded by cpp_get_token
+ if the pragma allowed expansion. */
+ toks[count++].flags |= NO_EXPAND;
}
while (toks[count-1].type != CPP_PRAGMA_EOL);
}
diff --git a/libcpp/macro.c b/libcpp/macro.c
index 67e936ee31a..b29f3a0c1fa 100644
--- a/libcpp/macro.c
+++ b/libcpp/macro.c
@@ -1180,7 +1180,7 @@ cpp_scan_nooutput (cpp_reader *pfile)
pfile->state.prevent_expansion--;
}
-/* Step back one (or more) tokens. Can only step mack more than 1 if
+/* Step back one (or more) tokens. Can only step back more than 1 if
they are from the lexer, and not from macro expansion. */
void
_cpp_backup_tokens (cpp_reader *pfile, unsigned int count)