https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120180
--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> --- Created attachment 61369 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=61369&action=edit C/C++ test case, compile with '-fopenmp' It is a bit UNCLEAR to me whether the attached TESTCASE is VALID OR NOT. The code is rejected with: error: intervening code must not contain OpenMP directives * * * ISSUE 1 – If valid, there is a rejects-valid issue (C, C++, Fortran) It comes from SPEC ACCEL 2023 (→ 452.ep) and appears multiple times there for C (as here) and for Fortran. However, clang-20/clang++-20 compile the code. The code has the pattern: omp metadirective when(cond : ... something collapse(1)) otherwise(... collapse(2)) for ( .... ) omp metadirective when(cond: simd) // otherwise(nothing) for (....) where 'cond' is a constant expression (for this test case: a literal). If one evaluates the constant first, the code is fine for any value of a constant 'cond'. However, if not, the problem is the 'collapse(2)' as there is a 'metadirective' between the two loops. * * * ISSUE 2 - There is definitely an error recovery issue in C/C++ (Fortran seems to be fine) (2.1) For C, it fails in the assert gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL); with: test.c: In function ‘main’: test.c:12:15: error: intervening code must not contain OpenMP directives 12 | #pragma omp metadirective when(user={condition(0)}: simd) default() | ^~~ test.c:12:15: internal compiler error: in c_parser_consume_token, at c/c-parser.cc:931 0x267f4df internal_error(char const*, ...) /home/tob/repos/gcc/gcc/diagnostic-global-context.cc:517 0x9e8b73 fancy_abort(char const*, int, char const*) /home/tob/repos/gcc/gcc/diagnostic.cc:1815 0x79deee c_parser_consume_token(c_parser*) /home/tob/repos/gcc/gcc/c/c-parser.cc:931 0xa95863 c_parser_omp_metadirective /home/tob/repos/gcc/gcc/cp/parser.cc:51759 (2.2) For C++, it fails in the assert gcc_checking_assert (cp_lexer_next_token_is_not (parser->lexer, CPP_EOF)); as follows. — Also note the bogus "otherwise clause must appear last". test.c: In function ‘int main()’: test.c:12:15: error: intervening code must not contain OpenMP directives 12 | #pragma omp metadirective when(user={condition(0)}: simd) default() | ^~~ test.c:13:7: error: ‘otherwise’ or ‘default’ clause must appear last in ‘metadirective’ 13 | for (i=0; i<nq; i++) | ^~~ test.c:15:5: internal compiler error: in cp_parser_skip_to_pragma_eol, at cp/parser.cc:4523 15 | } | ^ 0x29aa35f internal_error(char const*, ...) /home/tob/repos/gcc/gcc/diagnostic-global-context.cc:517 0xad0b6d fancy_abort(char const*, int, char const*) /home/tob/repos/gcc/gcc/diagnostic.cc:1815 0x82e8c0 cp_parser_skip_to_pragma_eol /home/tob/repos/gcc/gcc/cp/parser.cc:4523 0xcea7d5 cp_parser_omp_metadirective /home/tob/repos/gcc/gcc/cp/parser.cc:51759