Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 844091 - sys-devel/gcc-11.2.1_p20220115: internal compiler error in tree_to_shwi with vla in struct and sprintf
Summary: sys-devel/gcc-11.2.1_p20220115: internal compiler error in tree_to_shwi with ...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Toolchain Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-05-13 18:45 UTC by cpu
Modified: 2023-01-24 10:59 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description cpu 2022-05-13 18:45:29 UTC
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.
Comment 1 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-05-13 19:02:14 UTC
Works for me with GCC 11.3 and 12.1. Can you try 11.3?
Comment 2 cpu 2022-05-13 22:12:01 UTC
(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
Comment 3 Sergei Trofimovich 2022-05-14 14:32:58 UTC
(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.
Comment 4 cpu 2022-05-14 19:12:14 UTC
(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.
Comment 5 Sergei Trofimovich 2022-05-14 20:21:12 UTC
(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.
Comment 6 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-01-24 10:59:31 UTC
Fixed for 12 (which is now stable). Upstream say on bug it doesn't apply cleanly to 11, so let's close.