From 1c90c6f9c03360da9f6b01ef0ec28e309a0bb892 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 9 Jun 2006 23:13:25 +0200 Subject: [PATCH] re PR preprocessor/27746 (ICE on openmp code when using _Pragma from macro) 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. From-SVN: r114519 --- gcc/testsuite/ChangeLog | 14 ++++++++++++++ gcc/testsuite/g++.dg/cpp/_Pragma1.C | 10 ++++++++++ gcc/testsuite/g++.dg/gomp/macro-3.C | 25 +++++++++++++++++++++++++ gcc/testsuite/g++.dg/gomp/macro-4.C | 29 +++++++++++++++++++++++++++++ gcc/testsuite/gcc.dg/cpp/_Pragma6.c | 10 ++++++++++ gcc/testsuite/gcc.dg/gomp/macro-3.c | 25 +++++++++++++++++++++++++ gcc/testsuite/gcc.dg/gomp/macro-4.c | 29 +++++++++++++++++++++++++++++ libcpp/ChangeLog | 15 +++++++++++++++ libcpp/directives.c | 25 +++++++++++++++++++++++-- libcpp/macro.c | 2 +- 10 files changed, 181 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp/_Pragma1.C create mode 100644 gcc/testsuite/g++.dg/gomp/macro-3.C create mode 100644 gcc/testsuite/g++.dg/gomp/macro-4.C create mode 100644 gcc/testsuite/gcc.dg/cpp/_Pragma6.c create mode 100644 gcc/testsuite/gcc.dg/gomp/macro-3.c create mode 100644 gcc/testsuite/gcc.dg/gomp/macro-4.c diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f187c313572c..e3bd0e4324a9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,17 @@ +2006-06-09 Jakub Jelinek + + 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. + 2006-06-09 Richard Guenther PR tree-optimization/26998 diff --git a/gcc/testsuite/g++.dg/cpp/_Pragma1.C b/gcc/testsuite/g++.dg/cpp/_Pragma1.C new file mode 100644 index 000000000000..25a79f8863e4 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp/_Pragma1.C @@ -0,0 +1,10 @@ +// PR c++/27748 +// This is supposed to succeed only if +// the target doesn't define HANDLE_PRAGMA_PACK_WITH_EXPANSION. +// { dg-do compile { target { ! *-*-solaris2* } } } + +#define push bar +#define foo _Pragma ("pack(push)") +foo +int i; +#pragma pack(pop) diff --git a/gcc/testsuite/g++.dg/gomp/macro-3.C b/gcc/testsuite/g++.dg/gomp/macro-3.C new file mode 100644 index 000000000000..32623fde58ec --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/macro-3.C @@ -0,0 +1,25 @@ +// PR preprocessor/27746 +// { dg-do compile } +// { dg-options "-fopenmp -fdump-tree-omplower" } + +#define omp FOO +#define p parallel +#define omp_parallel _Pragma ("omp parallel") +#define omp_p _Pragma ("omp p") + +void bar (void); + +void +foo (void) +{ + #pragma omp parallel + bar (); + #pragma omp p + bar (); + omp_parallel + bar (); + omp_p + bar (); +} + +// { dg-final { scan-tree-dump-times "#pragma omp parallel" 4 "omplower" } } diff --git a/gcc/testsuite/g++.dg/gomp/macro-4.C b/gcc/testsuite/g++.dg/gomp/macro-4.C new file mode 100644 index 000000000000..9fc45b143d57 --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/macro-4.C @@ -0,0 +1,29 @@ +// PR preprocessor/27746 +// { dg-do compile } +// { dg-options "-fopenmp -Wunknown-pragmas" } + +#define p _Pragma ("omp parallel") +#define omp_p _Pragma ("omp p") + +void bar (void); + +void +foo (void) +{ +#pragma omp p // { dg-warning "ignoring #pragma omp _Pragma" } + bar (); + omp_p // { dg-warning "ignoring #pragma omp _Pragma" } + bar (); +} + +#define parallel serial +#define omp_parallel _Pragma ("omp parallel") + +void +baz (void) +{ +#pragma omp parallel // { dg-warning "ignoring #pragma omp serial" } + bar (); + omp_parallel // { dg-warning "ignoring #pragma omp serial" } + bar (); +} diff --git a/gcc/testsuite/gcc.dg/cpp/_Pragma6.c b/gcc/testsuite/gcc.dg/cpp/_Pragma6.c new file mode 100644 index 000000000000..369b334ae442 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/_Pragma6.c @@ -0,0 +1,10 @@ +/* PR c/27747 */ +/* This is supposed to succeed only if + the target doesn't define HANDLE_PRAGMA_PACK_WITH_EXPANSION. */ +/* { dg-do compile { target { ! *-*-solaris2* } } } */ + +#define push bar +#define foo _Pragma ("pack(push)") +foo +int i; +#pragma pack(pop) diff --git a/gcc/testsuite/gcc.dg/gomp/macro-3.c b/gcc/testsuite/gcc.dg/gomp/macro-3.c new file mode 100644 index 000000000000..dc4fe091b31d --- /dev/null +++ b/gcc/testsuite/gcc.dg/gomp/macro-3.c @@ -0,0 +1,25 @@ +/* PR preprocessor/27746 */ +/* { dg-do compile } */ +/* { dg-options "-fopenmp -fdump-tree-omplower" } */ + +#define omp FOO +#define p parallel +#define omp_parallel _Pragma ("omp parallel") +#define omp_p _Pragma ("omp p") + +void bar (void); + +void +foo (void) +{ + #pragma omp parallel + bar (); + #pragma omp p + bar (); + omp_parallel + bar (); + omp_p + bar (); +} + +/* { dg-final { scan-tree-dump-times "#pragma omp parallel" 4 "omplower" } } */ diff --git a/gcc/testsuite/gcc.dg/gomp/macro-4.c b/gcc/testsuite/gcc.dg/gomp/macro-4.c new file mode 100644 index 000000000000..7d20f4cd68d1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/gomp/macro-4.c @@ -0,0 +1,29 @@ +/* PR preprocessor/27746 */ +/* { dg-do compile } */ +/* { dg-options "-fopenmp -Wunknown-pragmas" } */ + +#define p _Pragma ("omp parallel") +#define omp_p _Pragma ("omp p") + +void bar (void); + +void +foo (void) +{ +#pragma omp p /* { dg-warning "ignoring #pragma omp _Pragma" } */ + bar (); + omp_p /* { dg-warning "ignoring #pragma omp _Pragma" } */ + bar (); +} + +#define parallel serial +#define omp_parallel _Pragma ("omp parallel") + +void +baz (void) +{ +#pragma omp parallel /* { dg-warning "ignoring #pragma omp serial" } */ + bar (); + omp_parallel /* { dg-warning "ignoring #pragma omp serial" } */ + bar (); +} diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index 80a1868d8098..865287b25455 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,18 @@ +2006-06-09 Jakub Jelinek + + 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 * Makefile.in (CATALOGS): Add po/ prefix. diff --git a/libcpp/directives.c b/libcpp/directives.c index 0eea67d133c8..e08698d76b7c 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 67e936ee31ae..b29f3a0c1fa7 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) -- 2.39.2