Bug 12404 - pointer to union member problem (aliasing problem)
Summary: pointer to union member problem (aliasing problem)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.3.1
: P2 normal
Target Milestone: 3.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2003-09-25 15:52 UTC by YAMAMOTO Takashi
Modified: 2003-12-25 03:13 UTC (History)
1 user (show)

See Also:
Host: i386--netbsdelf
Target: i386--netbsdelf
Build: i386-unknown-netbsdelf1.6W
Known to work:
Known to fail:
Last reconfirmed: 2003-09-25 21:21:14


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description YAMAMOTO Takashi 2003-09-25 15:52:17 UTC
compiling the following program with -O2 for i386
yields the latter asm output.

% gcc -v
Using built-in specs.
Configured with: /usr/src/tools/gcc/../../gnu/dist/gcc/configure --enable-long-long --disable-multilib --enable-threads --build=i386-unknown-netbsdelf --host=i386--netbsdelf --target=i386--netbsdelf : (reconfigured) /usr/src/tools/gcc/../../gnu/dist/gcc/configure --enable-long-long --disable-multilib --enable-threads --build=i386-unknown-netbsdelf1.6W --host=i386--netbsdelf --target=i386--netbsdelf
Thread model: posix
gcc version 3.3.1

============================================================
#include <stdio.h>

int
main()
{
	union { int i; short s; } u[] = {{1}, {2}, {3}};

	printf("%d\n", *&u->s);
}
============================================================
	.file	"a.c"
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d\n"
	.text
	.p2align 2,,3
.globl main
	.type	main, @function
main:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$24, %esp
	andl	$-16, %esp
	subl	$8, %esp
	movswl	-24(%ebp),%eax	# <= used before initialized.
	pushl	%eax
	pushl	$.LC0
	movl	$1, -24(%ebp)	# <= initialize here
	movl	$2, -20(%ebp)
	movl	$3, -16(%ebp)
	call	printf
	leave
	ret
	.size	main, .-main
	.ident	"GCC: (GNU) 3.3.1"
Comment 1 Andrew Pinski 2003-09-25 21:21:13 UTC
I can confirm this on the mainline (20030925), the problem is aliasing issue.
Comment 2 Andrew Pinski 2003-12-25 03:13:57 UTC
Fixed on the mainline (20031224).