diff --git a/gcc/testsuite/c-c++-common/goacc/pr102432.c b/gcc/testsuite/c-c++-common/goacc/pr102432.c new file mode 100644 index 00000000000..97450f30cf1 --- /dev/null +++ b/gcc/testsuite/c-c++-common/goacc/pr102432.c @@ -0,0 +1,23 @@ +/* PR preprocessor/102432 */ + +#define loop(x) + +void +foo (void) +{ + int i; +#pragma acc parallel +#pragma acc loop + for (i = 0; i < 64; i++) + ; +} + +void +bar (void) +{ + int i; + _Pragma ("acc parallel") + _Pragma ("acc loop") + for (i = 0; i < 64; i++) + ; +} diff --git a/gcc/testsuite/c-c++-common/gomp/pr102432.c b/gcc/testsuite/c-c++-common/gomp/pr102432.c new file mode 100644 index 00000000000..89b0f6d45b0 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/pr102432.c @@ -0,0 +1,23 @@ +/* PR preprocessor/102432 */ + +#define loop(x) + +void +foo (void) +{ + int i; +#pragma omp parallel +#pragma omp loop + for (i = 0; i < 64; i++) + ; +} + +void +bar (void) +{ + int i; + _Pragma ("omp parallel") + _Pragma ("omp loop") + for (i = 0; i < 64; i++) + ; +} diff --git a/libcpp/lex.c b/libcpp/lex.c index 7e56edc2131..49071743533 100644 --- a/libcpp/lex.c +++ b/libcpp/lex.c @@ -3530,7 +3530,21 @@ _cpp_lex_direct (cpp_reader *pfile) buffer = pfile->buffer; if (buffer->need_line) { - gcc_assert (!pfile->state.in_deferred_pragma); + if (pfile->state.in_deferred_pragma) + { + /* This can happen in cases like: + #define loop(x) whatever + #pragma omp loop + where when trying to expand loop we need to peek + next token after loop, but aren't still in_deferred_pragma + mode but are in in_directive mode, so buffer->need_line + is set, a CPP_EOF is peeked. */ + result->type = CPP_PRAGMA_EOL; + pfile->state.in_deferred_pragma = false; + if (!pfile->state.pragma_allow_expansion) + pfile->state.prevent_expansion--; + return result; + } if (!_cpp_get_fresh_line (pfile)) { result->type = CPP_EOF;