Bug 98636 - [ARM] ICE on passing incompatible options for fp16 - global_options’ are modified in local context
Summary: [ARM] ICE on passing incompatible options for fp16 - global_options’ are modi...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 11.0
: P3 normal
Target Milestone: ---
Assignee: Martin Liška
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2021-01-12 11:08 UTC by prathamesh3492
Modified: 2024-08-15 11:31 UTC (History)
7 users (show)

See Also:
Host: x86_64-unknown-linux-gnu
Target: arm-linux-gnueabihf
Build: x86_64-unknown-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2021-01-12 00:00:00


Attachments
Preprocessed test-case (29.62 KB, text/plain)
2021-01-12 13:00 UTC, prathamesh3492
Details
Output of passing --verbose (1.27 KB, text/plain)
2021-01-12 13:01 UTC, prathamesh3492
Details
untested fix (281 bytes, patch)
2021-01-19 07:08 UTC, prathamesh3492
Details | Diff
options-save.c (76.35 KB, text/plain)
2021-01-19 15:34 UTC, prathamesh3492
Details

Note You need to log in before you can comment on or make changes to this bug.
Description prathamesh3492 2021-01-12 11:08:12 UTC
For any test-case, that includes arm_neon.h, for instance:
#include <arm_neon.h>
void f() {}

Passing incompatible fp16 format seems to result in ICE.
For example, passing -mfp16-format=alternative resulted in:
In file included from test.c:1:
../arm-stage1-build/gcc/include/arm_neon.h:18122:9: error: selected fp16 options are incompatible
18122 | #pragma GCC target ("arch=armv8.2-a+fp16fml")
      |         ^~~
../arm-stage1-build/gcc/include/arm_neon.h:18324:9: internal compiler error: ‘global_options’ are modified in local context
18324 | #pragma GCC pop_options
      |         ^~~
0xdcb103 cl_optimization_compare(gcc_options*, gcc_options*)
        /home/bilbo/gnu-toolchain/gcc/vfma/arm-stage1-build/gcc/options-save.c:12555
0x97d54d handle_pragma_pop_options
        ../../gcc/gcc/c-family/c-pragma.c:1092
0x8f3cbb c_parser_pragma
        ../../gcc/gcc/c/c-parser.c:12525
0x91aab5 c_parser_external_declaration
        ../../gcc/gcc/c/c-parser.c:1758
0x91b269 c_parser_translation_unit
        ../../gcc/gcc/c/c-parser.c:1650
0x91b269 c_parse_file()
        ../../gcc/gcc/c/c-parser.c:21935
0x97b045 c_common_parse_file()
        ../../gcc/gcc/c-family/c-opts.c:1211


My built version is configured as:
Using built-in specs.
COLLECT_GCC=../arm-stage1-build/gcc/xgcc
Target: arm-linux-gnueabihf
Configured with: ../gcc/configure --enable-languages=c,c++ --disable-bootstrap --target=arm-linux-gnueabihf --with-arch=armv7-a --with-fpu=neon --with-float=hard --with-mode=thumb --with-sysroot=/home/bilbo/gnu-toolchain/sysroots/arm-linux-gnueabihf --disable-werror
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.0.0 20210111 (experimental) (GCC)

Thanks,
Prathamesh
Comment 1 Martin Liška 2021-01-12 12:52:14 UTC
Can you please attach a pre-processed source file and output of --verbose?
Comment 2 prathamesh3492 2021-01-12 13:00:08 UTC
Created attachment 49953 [details]
Preprocessed test-case
Comment 3 prathamesh3492 2021-01-12 13:01:44 UTC
Created attachment 49954 [details]
Output of passing --verbose

Command line option used to compile:
../arm-stage1-build/gcc/xgcc -B ../arm-stage1-build/gcc  -mfp16-format=alternative test.c -S -save-temps  --verbose >verbose_output.txt 2>&1
Comment 4 Martin Liška 2021-01-12 13:06:15 UTC
Thanks, with cross compiler I only see the error (not the internal compiler error).
Anyway, can you please test it with g:e91910d3576eeac714c93ec25ea3b15012007903?
Comment 5 prathamesh3492 2021-01-12 13:35:46 UTC
Hi,
Unfortunately I am still getting the same ICE with g:e91910d3576eeac714c93ec25ea3b15012007903.

Thanks,
Prathamesh
Comment 6 Martin Liška 2021-01-12 13:42:55 UTC
I see. Is the 'error: selected fp16 options are incompatible' valid or not in this case?
Comment 7 prathamesh3492 2021-01-12 14:21:39 UTC
I think the error is correct.
CCing Kyrill -- could you please confirm if the error is valid for
above case ?
Thanks!
Comment 8 ktkachov 2021-01-12 14:55:17 UTC
(In reply to prathamesh3492 from comment #7)
> I think the error is correct.
> CCing Kyrill -- could you please confirm if the error is valid for
> above case ?
> Thanks!

Yes, -mfp16-format=alternative is incompatible with the intrinsics
Comment 9 Martin Liška 2021-01-12 14:58:10 UTC
All right.
@Prathamesh: Can you run that in debugger and show what option foo is causing the internal_error:

void
cl_optimization_compare (gcc_options *ptr1, gcc_options *ptr2)
{
...
  if (ptr1->x_foo != ptr2->x_help_foo)
    internal_error ("%<global_options%> are modified in local context");
Comment 10 prathamesh3492 2021-01-19 07:08:20 UTC
Created attachment 49997 [details]
untested fix

Hi,
Sorry for late response. The option that seemed to be causing the issue was arm_fp16_format. The attached patch fixes the issue by excluding it from checks in cl_optimization_compare, which prevents the ICE for me.
Does this look OK ?

Thanks,
Prathamesh
Comment 11 Martin Liška 2021-01-19 09:04:46 UTC
> Sorry for late response. The option that seemed to be causing the issue was
> arm_fp16_format.

How do the string values differ? Are they also different string pointers but having a same value?

> The attached patch fixes the issue by excluding it from
> checks in cl_optimization_compare, which prevents the ICE for me.
> Does this look OK ?

Can you please attach options-save.c file first?
Comment 12 prathamesh3492 2021-01-19 15:34:32 UTC
Created attachment 50003 [details]
options-save.c
Comment 13 prathamesh3492 2021-01-19 15:38:59 UTC
IIUC, the issue comes from the following mismatch in cl_optimization_compare:

  if (ptr1->x_arm_fp16_format != ptr2->x_arm_fp16_format)
    internal_error ("%<global_options%> are modified in local context");

x_arm_fp16_format is of following type defined in arm-opts.h:

/* Which __fp16 format to use.
   The enumeration values correspond to the numbering for the
   Tag_ABI_FP_16bit_format attribute.
 */
enum arm_fp16_format_type
{
  ARM_FP16_FORMAT_NONE = 0,
  ARM_FP16_FORMAT_IEEE = 1,
  ARM_FP16_FORMAT_ALTERNATIVE = 2
};

For the test-case passing -mfp16-format=alternative results in:
ptr1->x_arm_fp16_format == ARM_FP16_FORMAT_ALTERNATIVE and
ptr2->x_arm_fp16_format == ARM_FP16_FORMAT_IEEE,
and the mismatch results in ICE.

Thanks,
Prathamesh
Comment 14 Tamar Christina 2021-01-19 15:40:17 UTC
I just ran into the same problem, with a slightly different testcase:

> cat crash.c

#pragma GCC push_options
#pragma GCC target ("arch=armv8.2-a+fp16")
#pragma GCC pop_options

results in the same crash:

crash.c:3:9: internal compiler error: 'global_options' are modified in local context
    3 | #pragma GCC pop_options
      |         ^~~
0x1199c6d cl_optimization_compare(gcc_options*, gcc_options*)
        build-arm-none-eabi/obj/gcc2/gcc/options-save.c:14897
0xb38463 handle_pragma_pop_options
        src/gcc/gcc/c-family/c-pragma.c:1092
0xb38eef c_invoke_pragma_handler(unsigned int)
        src/gcc/gcc/c-family/c-pragma.c:1515
0xa80622 c_parser_pragma
        src/gcc/gcc/c/c-parser.c:12525
0xa63dc6 c_parser_external_declaration
        src/gcc/gcc/c/c-parser.c:1758
0xa63938 c_parser_translation_unit
        src/gcc/gcc/c/c-parser.c:1650
0xaa6139 c_parse_file()
        src/gcc/gcc/c/c-parser.c:21990
0xb322f2 c_common_parse_file()
        src/gcc/gcc/c-family/c-opts.c:1211
Comment 15 Martin Liška 2021-01-19 16:08:54 UTC
I see, so it's a real issue and I support the workaround mentioned in Comment 10.
Please send it to the mailing list.
Comment 16 prathamesh3492 2021-01-19 16:58:22 UTC
(In reply to Tamar Christina from comment #14)
> I just ran into the same problem, with a slightly different testcase:
This is a better one to reproduce the issue, thanks! I verified the patch in comment 10 resolves the ICE for this test-case.

Thanks,
Prathamesh
> 
> > cat crash.c
> 
> #pragma GCC push_options
> #pragma GCC target ("arch=armv8.2-a+fp16")
> #pragma GCC pop_options
> 
> results in the same crash:
> 
> crash.c:3:9: internal compiler error: 'global_options' are modified in local
> context
>     3 | #pragma GCC pop_options
>       |         ^~~
> 0x1199c6d cl_optimization_compare(gcc_options*, gcc_options*)
>         build-arm-none-eabi/obj/gcc2/gcc/options-save.c:14897
> 0xb38463 handle_pragma_pop_options
>         src/gcc/gcc/c-family/c-pragma.c:1092
> 0xb38eef c_invoke_pragma_handler(unsigned int)
>         src/gcc/gcc/c-family/c-pragma.c:1515
> 0xa80622 c_parser_pragma
>         src/gcc/gcc/c/c-parser.c:12525
> 0xa63dc6 c_parser_external_declaration
>         src/gcc/gcc/c/c-parser.c:1758
> 0xa63938 c_parser_translation_unit
>         src/gcc/gcc/c/c-parser.c:1650
> 0xaa6139 c_parse_file()
>         src/gcc/gcc/c/c-parser.c:21990
> 0xb322f2 c_common_parse_file()
>         src/gcc/gcc/c-family/c-opts.c:1211
Comment 17 prathamesh3492 2021-01-19 16:58:53 UTC
(In reply to Martin Liška from comment #15)
> I see, so it's a real issue and I support the workaround mentioned in
> Comment 10.
> Please send it to the mailing list.

Patch posted: https://gcc.gnu.org/pipermail/gcc-patches/2021-January/563848.html

Thanks,
Prathamesh
Comment 18 GCC Commits 2021-01-22 08:45:36 UTC
The master branch has been updated by Prathamesh Kulkarni <prathamesh3492@gcc.gnu.org>:

https://gcc.gnu.org/g:4e3beaca15cab2de88a68d76f0aabc68e68f678a

commit r11-6850-g4e3beaca15cab2de88a68d76f0aabc68e68f678a
Author: Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
Date:   Fri Jan 22 14:14:20 2021 +0530

    arm: Fix ICE with incompatible values for -mfp16-format [PR98636].
    
    gcc/
    2021-01-22  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>
    
            PR target/98636
            * optc-save-gen.awk: Add arm_fp16_format to checked_options.
    
    gcc/testsuite/
    2021-01-22  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>
    
            PR target/98636
            * gcc.target/arm/pr98636.c: New test.
Comment 19 Martin Liška 2021-01-22 09:06:07 UTC
Fixed now.
Comment 20 David Binderman 2021-05-28 05:44:06 UTC
Recently unfixed.

$ /home/dcb/raspberrypi/results/bin/arm-linux-gnueabihf-gcc -c ./gcc.target/arm/pr98636.c
./gcc.target/arm/pr98636.c:6:9: internal compiler error: ‘global_options’ are mo
dified in local context
    6 | #pragma GCC pop_options
      |         ^~~
0xe063eb cl_optimization_compare(gcc_options*, gcc_options*)
	/home/dcb/raspberrypi/build-gcc/gcc/options-save.c:12621
0x94b2ad handle_pragma_pop_options
	/home/dcb/gcc/trunk.git/gcc/c-family/c-pragma.c:1100
0x8c1ad1 c_parser_pragma
	/home/dcb/gcc/trunk.git/gcc/c/c-parser.c:12519
0x8e9c05 c_parser_external_declaration
	/home/dcb/gcc/trunk.git/gcc/c/c-parser.c:1758
Comment 21 Martin Liška 2021-06-01 09:15:42 UTC
Let me assign it.
Comment 22 GCC Commits 2021-06-23 13:31:59 UTC
The master branch has been updated by Martin Liska <marxin@gcc.gnu.org>:

https://gcc.gnu.org/g:371c1992624c9269e2d5747561a8b27b30e485ee

commit r12-1745-g371c1992624c9269e2d5747561a8b27b30e485ee
Author: Martin Liska <mliska@suse.cz>
Date:   Wed Jun 23 15:30:17 2021 +0200

    arm: Revert partially ebd5e86c0f41dc1d692f9b2b68a510b1f6835a3e
    
            PR target/98636
    
    gcc/ChangeLog:
    
            * optc-save-gen.awk: Put back arm_fp16_format to
            checked_options.
Comment 23 Martin Liška 2021-06-23 13:32:19 UTC
Fixed again.
Comment 24 Torbjorn SVENSSON 2024-08-15 11:31:51 UTC
The test case gcc.target/arm/pr98636.c fails for Cortex-M55 as the error is emitted during the process_options step in toplev.c rather than do_compile step.

In arm_option_reconfigure_globals, the following line can be found:
arm_fp16_inst = bitmap_bit_p (arm_active_target.isa, isa_bit_fp16);

For Cortex-A7 (just an example where the test case passes), the above statement results in arm_fp16_inst=0 when the call tree contains process_options. When the call tree contains do_compile, it's instead arm_fp16_inst=1 and the expected error is emitted.

For Cortex-M55, the above statement results in arm_fp16_inst=1 when the call tree contains process_options. As a result, the expected error is emitted, but at this point, input_location is 0, so there is no context and the test case fail.


I've debugged the above using the following command:
cc1 -quiet -D__USES_INITFINI__ gcc/testsuite/gcc.target/arm/pr98636.c -quiet -mthumb -mcpu=cortex-m55 -mfloat-abi=hard -mfpu=auto -mfp16-format=alternative -o /dev/null

Output with -mcpu=cortex-a7:
gcc/testsuite/gcc.target/arm/pr98636.c:6:10: error: selected fp16 options are incompatible
    6 | # pragma GCC target ("arch=armv8.2-a+fp16") /* { dg-error "selected fp16 options are incompatible" } */
      |          ^~~

Output with -mcpu=cortex-m55:
cc1: error: selected fp16 options are incompatible


Should the test case be updated to be this instead as it would allow both cases to pass?
# pragma GCC target ("arch=armv8.2-a+fp16") /* { dg-error "selected fp16 options are incompatible" "" { target *-*-* } 0 } */