Bug 95782 - [s390] ICE in _cpp_pop_context
Summary: [s390] ICE in _cpp_pop_context
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 10.1.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2020-06-20 06:26 UTC by Evan Nemerson
Modified: 2024-03-27 06:11 UTC (History)
2 users (show)

See Also:
Host:
Target: s390
Build:
Known to work:
Known to fail: 10.1.0, 9.3.0
Last reconfirmed: 2024-03-26 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Evan Nemerson 2020-06-20 06:26:14 UTC
I'm running into an ICE on ppc64le:

  internal compiler error: in _cpp_pop_context, at libcpp/macro.c:2644

Here is a reproducer:

  #define a
  #define b(d) d
  #if defined(a)  
  b(vector double)
  #endif

Just running `gcc -E test.c` when targeting ppc64le triggers the issue.  It happens with at least GCC 9 and 10.
Comment 1 Evan Nemerson 2021-05-25 01:28:06 UTC
This seems to also happen on s390x with -mzvector:


# s390x-linux-gnu-gcc-10 -march=z14 -mzvector -o test test.c
test.c:4:1: internal compiler error: in _cpp_pop_context, at libcpp/macro.c:2644
    4 | b(vector double)
      | ^
0x11da337 _cpp_pop_context
	../../src/libcpp/macro.c:2644
0x11dcd67 expand_arg
	../../src/libcpp/macro.c:2601
0x11dc41f replace_args
	../../src/libcpp/macro.c:1879
0x11dc41f enter_macro_context
	../../src/libcpp/macro.c:1421
0x11dc7e8 cpp_get_token_1
	../../src/libcpp/macro.c:2891
0x6393fe c_lex_with_flags(tree_node**, unsigned int*, unsigned char*, int)
	../../src/gcc/c-family/c-lex.c:458
0x5c96a5 c_lex_one_token
	../../src/gcc/c/c-parser.c:270
0x5f6517 c_parser_peek_token(c_parser*)
	../../src/gcc/c/c-parser.c:474
0x5f6517 c_parse_file()
	../../src/gcc/c/c-parser.c:21742
0x64054b c_common_parse_file()
	../../src/gcc/c-family/c-opts.c:1190
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-10/README.Bugs> for instructions.
Comment 2 Andrew Pinski 2024-03-26 06:58:29 UTC
The powerpc issue was fixed in GCC 13 (most likely by r13-220-g067fe66c8ba9b16feacf66fce9ae668091e42821 ).

s390 most likely needs the same treatment:
```
[apinski@xeond2 rs6000]$ git diff ../s390/s390-c.cc
diff --git a/gcc/config/s390/s390-c.cc b/gcc/config/s390/s390-c.cc
index 8d3d1a467a8..8096b1ff7c1 100644
--- a/gcc/config/s390/s390-c.cc
+++ b/gcc/config/s390/s390-c.cc
@@ -275,7 +275,7 @@ s390_macro_to_expand (cpp_reader *pfile, const cpp_token *tok)
       /* __vector long __bool a; */
       if (ident == C_CPP_HASHNODE (__bool_keyword))
        expand_bool_p = true;
-      else
+      else if (ident)
        {
          /* Triggered with: __vector long long __bool a; */
          do

```

I cannot test this at all, and a similar testcase in PR 101168 should be added for s390.
Comment 3 Jiu Fu Guo 2024-03-27 06:11:51 UTC
(In reply to Andrew Pinski from comment #2)
> The powerpc issue was fixed in GCC 13 (most likely by
> r13-220-g067fe66c8ba9b16feacf66fce9ae668091e42821 ).
> 
> s390 most likely needs the same treatment:
> ```
> [apinski@xeond2 rs6000]$ git diff ../s390/s390-c.cc
> diff --git a/gcc/config/s390/s390-c.cc b/gcc/config/s390/s390-c.cc
> index 8d3d1a467a8..8096b1ff7c1 100644
> --- a/gcc/config/s390/s390-c.cc
> +++ b/gcc/config/s390/s390-c.cc
> @@ -275,7 +275,7 @@ s390_macro_to_expand (cpp_reader *pfile, const cpp_token
> *tok)
>        /* __vector long __bool a; */
>        if (ident == C_CPP_HASHNODE (__bool_keyword))
>         expand_bool_p = true;
> -      else
> +      else if (ident)
>         {
>           /* Triggered with: __vector long long __bool a; */
>           do
> 
> ```
> 
> I cannot test this at all, and a similar testcase in PR 101168 should be
> added for s390.

Test with cross-compiling, this code can fix the issue as expected.