Hi. In the course of my experiments with the C language, I encountered the following error: $ LC_ALL=C make cc -Wall -O2 -march=native -pipe -fomit-frame-pointer -c -o main.o main.c during GIMPLE pass: strlen main.c: In function 'main': main.c:57:5: internal compiler error: in tree_to_shwi, at tree.c:7452 57 | int main(){ | ^~~~ 0x15b5baf internal_error(char const*, ...) ???:0 0x60923b fancy_abort(char const*, int, char const*) ???:0 0x1482263 handle_printf_call(gimple_stmt_iterator*, pointer_query&) ???:0 0xcf0530 strlen_dom_walker::before_dom_children(basic_block_def*) ???:0 0x142a7b7 dom_walker::walk(basic_block_def*) ???:0 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <https://bugs.gentoo.org/> for instructions. make: *** [<builtin>: main.o] Error 1 Makefile: CFLAGS = -Wall -O2 -march=native -pipe -fomit-frame-pointer main: main.o main.c: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <semaphore.h> struct link_t { struct link_t* next; void* payload; }; struct trans_access_t { sem_t lock; size_t users; size_t size; char* data; struct link_t* links; //char buf[]; }; static void* allocTrans( int users, int size ){ struct trans_create { sem_t lock; size_t users; size_t size; char* data; struct link_t links[users]; char buf[size]; }; int i; struct trans_create* trans; trans = malloc( sizeof(*trans) ); if( !trans ) return NULL; sem_init( &trans->lock, 0, 1 ); trans->users = users; trans->size = size; trans->data = trans->buf; for( i = 0; i < users; i++ ) trans->links[i].payload = trans; memcpy( trans->buf, "test", 5 ); return trans; } int main(){ struct trans_access_t* trans; trans = allocTrans( 1, 50 ); sprintf( trans->data, "test" ); printf( "%s\n", trans->data ); return 0; } gcc --version gcc (Gentoo 11.2.1_p20220115 p4) 11.2.1 20220115 I noticed that this error occurs when I use sprintf() to fill the buffer. if i use memcpy() no error happens.
Works for me with GCC 11.3 and 12.1. Can you try 11.3?
(In reply to Sam James from comment #1) > Works for me with GCC 11.3 and 12.1. Can you try 11.3? With gcc 11.3.0 the behavior is the same
(In reply to cpu from comment #0) > Hi. In the course of my experiments with the C language, I encountered the > following error: > > $ LC_ALL=C make > cc -Wall -O2 -march=native -pipe -fomit-frame-pointer -c -o main.o main.c > during GIMPLE pass: strlen > main.c: In function 'main': > main.c:57:5: internal compiler error: in tree_to_shwi, at tree.c:7452 > 57 | int main(){ > | ^~~~ What does -march=native expand for you? You can follow https://wiki.gentoo.org/wiki/Gcc-ICE-reporting-guide#Expand_-march.3Dnative.2C_exact_gcc_version_and_other_system-specific_options to get the expansion. Try to identify minimum amount of -m options needed to trigger the failure.
(In reply to Sergei Trofimovich from comment #3) > (In reply to cpu from comment #0) > > Hi. In the course of my experiments with the C language, I encountered the > > following error: > > > > $ LC_ALL=C make > > cc -Wall -O2 -march=native -pipe -fomit-frame-pointer -c -o main.o main.c > > during GIMPLE pass: strlen > > main.c: In function 'main': > > main.c:57:5: internal compiler error: in tree_to_shwi, at tree.c:7452 > > 57 | int main(){ > > | ^~~~ > > What does -march=native expand for you? > > You can follow > https://wiki.gentoo.org/wiki/Gcc-ICE-reporting-guide#Expand_-march.3Dnative. > 2C_exact_gcc_version_and_other_system-specific_options to get the expansion. > > Try to identify minimum amount of -m options needed to trigger the failure. I experimented a bit and realized that -march has no effect on the appearance of the error. The error occurs when using the -Wall and -O2 options at the same time.
(In reply to cpu from comment #4) > I experimented a bit and realized that -march has no effect on the > appearance of the error. The error occurs when using the -Wall and -O2 > options at the same time. Aha, thank you! I reproduced locally as well. Filed https://gcc.gnu.org/PR105604 upstream.
Fixed for 12 (which is now stable). Upstream say on bug it doesn't apply cleanly to 11, so let's close.