Bug 60017 - [4.7/4.8 Regression] Struct not returned correctly
Summary: [4.7/4.8 Regression] Struct not returned correctly
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.9.0
: P2 normal
Target Milestone: 4.7.4
Assignee: Uroš Bizjak
URL: http://gcc.gnu.org/ml/gcc-patches/201...
Keywords: ABI, wrong-code
Depends on:
Blocks:
 
Reported: 2014-02-01 03:52 UTC by Ishiura Lab Compiler Team
Modified: 2014-02-04 16:48 UTC (History)
1 user (show)

See Also:
Host:
Target: x86_64
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-02-01 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ishiura Lab Compiler Team 2014-02-01 03:52:15 UTC
GCC 4.9.0 for x86_64 miscompiles the following code.

    $ cat error.c
    
    struct S0 { short m0; short m1; };
    struct S1 { unsigned m0 : 1; char m1[2][2]; struct S0 m2[2]; };
    
    struct S1 x = {1,{{1,1},{1,1}},{{1,1},{1,1}}};
    
    struct S1 func(void) { return x; }
    
    int main(void)
    {
        struct S1 ret = func();
        if( ret.m2[1].m1 != 1 ) { __builtin_abort(); }
        
        return 0;
    }
    
    $ gcc-4.9 error.c 
    
    $ ./a.out
    Abort trap: 6

The value of ret.m2[1].m1 was 32767 instead of 1.
There was no problem with an i686 target.

    $ gcc-4.9 -v
    Using built-in specs.
    COLLECT_GCC=gcc-4.9
    COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc49/4.9-20140126/gcc/libexec/gcc/x86_64-apple-darwin13.0.0/4.9.0/lto-wrapper
    Target: x86_64-apple-darwin13.0.0
    Configured with: ../configure --build=x86_64-apple-darwin13.0.0 --prefix=/usr/local/Cellar/gcc49/4.9-20140126/gcc --datarootdir=/usr/local/Cellar/gcc49/4.9-20140126/share --bindir=/usr/local/Cellar/gcc49/4.9-20140126/bin --enable-languages=c --program-suffix=-4.9 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-cloog=/usr/local/opt/cloog --with-isl=/usr/local/opt/isl --with-system-zlib --enable-libstdcxx-time=yes --enable-stage1-checking --enable-checking=release --enable-plugin --enable-lto --disable-werror --disable-nls --disable-multilib --with-native-system-header-dir=/usr/include --with-sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk
    Thread model: posix
    gcc version 4.9.0 20140126 (experimental) (GCC)
Comment 1 Jakub Jelinek 2014-02-01 10:26:52 UTC
Started with r142059.
Comment 2 Uroš Bizjak 2014-02-02 14:02:31 UTC
I have a patch.
Comment 3 Uroš Bizjak 2014-02-02 15:33:23 UTC
Patch at [1].

[1] http://gcc.gnu.org/ml/gcc-patches/2014-02/msg00027.html
Comment 4 uros 2014-02-02 15:36:25 UTC
Author: uros
Date: Sun Feb  2 15:35:53 2014
New Revision: 207399

URL: http://gcc.gnu.org/viewcvs?rev=207399&root=gcc&view=rev
Log:
	PR target/60017
	* config/i386/i386.c (classify_argument): Fix handling of bit_offset
	when calculating size of integer atomic types.

testsuite/ChangeLog:

	PR target/60017
	* gcc.c-torture/execute/pr60017.c: New test.


Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/pr60017.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/i386.c
    trunk/gcc/testsuite/ChangeLog
Comment 5 uros 2014-02-04 16:43:32 UTC
Author: uros
Date: Tue Feb  4 16:43:00 2014
New Revision: 207475

URL: http://gcc.gnu.org/viewcvs?rev=207475&root=gcc&view=rev
Log:
	Backport from mainline
	2014-02-02  Uros Bizjak  <ubizjak@gmail.com>

	PR target/60017
	* config/i386/i386.c (classify_argument): Fix handling of bit_offset
	when calculating size of integer atomic types.

testsuite/ChangeLog:

	Backport from mainline
	2014-02-02  Uros Bizjak  <ubizjak@gmail.com>

	PR target/60017
	* gcc.c-torture/execute/pr60017.c: New test.


Added:
    branches/gcc-4_8-branch/gcc/testsuite/gcc.c-torture/execute/pr60017.c
Modified:
    branches/gcc-4_8-branch/gcc/ChangeLog
    branches/gcc-4_8-branch/gcc/config/i386/i386.c
    branches/gcc-4_8-branch/gcc/testsuite/ChangeLog
Comment 6 uros 2014-02-04 16:46:38 UTC
Author: uros
Date: Tue Feb  4 16:46:06 2014
New Revision: 207476

URL: http://gcc.gnu.org/viewcvs?rev=207476&root=gcc&view=rev
Log:
	Backport from mainline
	2014-02-02  Uros Bizjak  <ubizjak@gmail.com>

	PR target/60017
	* config/i386/i386.c (classify_argument): Fix handling of bit_offset
	when calculating size of integer atomic types.

testsuite/ChangeLog

	Backport from mainline
	2014-02-02  Uros Bizjak  <ubizjak@gmail.com>

	PR target/60017
	* gcc.c-torture/execute/pr60017.c: New test.


Added:
    branches/gcc-4_7-branch/gcc/testsuite/gcc.c-torture/execute/pr60017.c
Modified:
    branches/gcc-4_7-branch/gcc/ChangeLog
    branches/gcc-4_7-branch/gcc/config/i386/i386.c
    branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
Comment 7 Uroš Bizjak 2014-02-04 16:48:12 UTC
Fixed everywhere.