Bug 83729 - [8 Regression] AVR ICE on convert_memory_address_addr_space_1 at explow.c:300
Summary: [8 Regression] AVR ICE on convert_memory_address_addr_space_1 at explow.c:300
Status: RESOLVED DUPLICATE of bug 83801
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 8.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: addr-space, ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2018-01-07 18:27 UTC by gandalf
Modified: 2018-01-15 10:05 UTC (History)
0 users

See Also:
Host:
Target: avr
Build:
Known to work: 7.2.1
Known to fail:
Last reconfirmed: 2018-01-08 00:00:00


Attachments
Preprocessed file (2.35 KB, text/plain)
2018-01-07 18:27 UTC, gandalf
Details

Note You need to log in before you can comment on or make changes to this bug.
Description gandalf 2018-01-07 18:27:48 UTC
Created attachment 43054 [details]
Preprocessed file

gcc version 8.0.0 20180107 (experimental) (GCC) 
gcc svn r256323
Target: avr
Configured with: ../configure --target=avr --prefix=/usr/local/avr --disable-nls --enable-languages=c --disable-bootstrap --disable-libssp
Cross compiled on host using x86_64-pc-linux-gnu v7.2.0

ICE while compiling avr-libc svn r2546

Command:

avr-gcc -save-temps -DHAVE_CONFIG_H -I. -I../../..  -I../../../common -I../../../include -I../../../include  -Wall -W -Wstrict-prototypes -mmcu=avr2 -D__COMPILING_AVR_LIBC__ -mcall-prologues -Os  -MT asctime_r.o -MD -MP -MF .deps/asctime_r.Tpo -c -o asctime_r.o ../../../libc/time/asctime_r.c -Wextra

during RTL pass: expand
../../../libc/time/asctime_r.c: In function 'asctime_r':
../../../libc/time/asctime_r.c:57:16: internal compiler error: in convert_memory_address_addr_space_1, at explow.c:300
      buffer[i] = ascdays[d++];
      ~~~~~~~~~~^~~~~~~~~~~~~~
0x51b973 convert_memory_address_addr_space_1(scalar_int_mode, rtx_def*, unsigned char, bool, bool)
        ../../gcc/explow.c:300
0x7ab83a convert_memory_address_addr_space_1(scalar_int_mode, rtx_def*, unsigned char, bool, bool)
        ../../gcc/explow.c:474
0x7ab83a convert_memory_address_addr_space(scalar_int_mode, rtx_def*, unsigned char)
        ../../gcc/explow.c:402
0x7ab83a memory_address_addr_space(machine_mode, rtx_def*, unsigned char)
        ../../gcc/explow.c:416
0x791824 change_address_1
        ../../gcc/emit-rtl.c:2288
0x7c200f expand_expr_real_1(tree_node*, rtx_def*, machine_mode, expand_modifier, rtx_def**, bool)
        ../../gcc/expr.c:10185
0x7c1a6c expand_expr_real_1(tree_node*, rtx_def*, machine_mode, expand_modifier, rtx_def**, bool)
        ../../gcc/expr.c:10586
0x7c492f expand_expr_real_1(tree_node*, rtx_def*, machine_mode, expand_modifier, rtx_def**, bool)
        ../../gcc/expr.c:9923
0x7cf6d3 store_expr_with_bounds(tree_node*, rtx_def*, int, bool, bool, tree_node*)
        ../../gcc/expr.c:5632
0x7d0f87 expand_assignment(tree_node*, tree_node*, bool)
        ../../gcc/expr.c:5400
0x6ad998 expand_gimple_stmt_1
        ../../gcc/cfgexpand.c:3692
0x6ad998 expand_gimple_stmt
        ../../gcc/cfgexpand.c:3790
0x6afdf7 expand_gimple_basic_block
        ../../gcc/cfgexpand.c:5810
0x6b52ae execute
        ../../gcc/cfgexpand.c:6416
Comment 1 Georg-Johann Lay 2018-01-08 15:31:21 UTC
Confirmed for v8 with a reduced test case and -O for:

const __memx char ascdays[] = "SunMonTueWedThuFriSat";

void
asctime_r (int a, char *buffer)
{
    buffer[0] = ascdays[a];
}

v7 and v6 are ok.
Comment 2 Georg-Johann Lay 2018-01-08 16:54:06 UTC
...and this is a middle-end flaw because POINTERS_EXTEND_UNSIGNED states:

[...] You need not define this macro [which is the case for avr] if the ptr_mode, Pmode and word_mode are all the same width [which is also true for avr]. 

https://gcc.gnu.org/onlinedocs/gcc-7.2.0/gccint/Storage-Layout.html#index-POINTERS_005fEXTEND_005fUNSIGNED

Actually I don't see any readon for why an extension should be needed here as both targetm.addr_space.pointer_mode (__memx) and targetm.addr_space.address_mode (__memx) are PSImode.
Comment 3 gandalf 2018-01-10 04:23:02 UTC
Another regression test case (compile with -O):

void code_to_ascii(char buf[1], unsigned int code)
{
  __attribute__((used))
  static const char __flash test[5]="ABCDE";

  static const char __flash code_tab[32]="0123456789ABCDEFGHJKLMNPRSTUWXYZ";

  buf[0]=code_tab[code];
}

Variable "test" is correctly placed in section .progmem.data.

Variable "code_tab" is incorrectly placed in section .rodata.

This causes a problem for programs that are larger than 64KB in size. In my case, "code_to_ascii" is one of the last functions in my .c file, and therefore it is at the very end of the executable. Since "code_tab" appears next to "code_to_ascii" after the 64KB boundary, __flash no longer references the correct area in program memory.

GCC 7.2 correctly places both variables in .progmem.data.
Comment 4 Georg-Johann Lay 2018-01-11 13:54:07 UTC
(In reply to gandalf from comment #3)
> Another regression test case (compile with -O):
> 
> void code_to_ascii(char buf[1], unsigned int code)
> {
>   __attribute__((used))
>   static const char __flash test[5]="ABCDE";
> 
>   static const char __flash code_tab[32]="0123456789ABCDEFGHJKLMNPRSTUWXYZ";
> 
>   buf[0]=code_tab[code];
> }
> 
> Variable "code_tab" is incorrectly placed in section .rodata.

Different issue, likely a target thing.  Filed as PR83801.
Comment 5 Georg-Johann Lay 2018-01-15 09:55:38 UTC
Fixed by 256608.

*** This bug has been marked as a duplicate of bug 83801 ***
Comment 6 Georg-Johann Lay 2018-01-15 10:05:04 UTC
Author: gjl
Date: Mon Jan 15 10:04:32 2018
New Revision: 256687

URL: https://gcc.gnu.org/viewcvs?rev=256687&root=gcc&view=rev
Log:
	PR c/83801
	PR c/83729
	* gcc.target/avr/torture/pr83729.c: New test.
	* gcc.target/avr/torture/pr83801.c: New test.


Added:
    trunk/gcc/testsuite/gcc.target/avr/torture/pr83729.c
    trunk/gcc/testsuite/gcc.target/avr/torture/pr83801.c
Modified:
    trunk/gcc/testsuite/ChangeLog