Bug 1150606 - summing bitfield generates invalid code(using sse2 in -O3)
Summary: summing bitfield generates invalid code(using sse2 in -O3)
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: gcc
Version: 6.5
Hardware: x86_64
OS: Linux
Target Milestone: rc
: ---
Assignee: Jakub Jelinek
QA Contact: Miroslav Franc
Depends On:
TreeView+ depends on / blocked
Reported: 2014-10-08 14:01 UTC by Rafal Wijata
Modified: 2016-02-01 02:29 UTC (History)
7 users (show)

Fixed In Version: gcc-4.4.7-12.el6
Doc Type: Bug Fix
Doc Text:
Previously, when the vectorization optimization was enabled, the compiler could extract a scalar component of a vector with element types whose precision did not match the precision of their mode. Consequently, GCC could terminate unexpectedly while trying to vectorize a code that was using bit-fields. With this update, the compiler no longer vectorizes such code and the code now compiles correctly.
Clone Of:
Last Closed: 2015-07-22 06:48:26 UTC

Attachments (Terms of Use)

System ID Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2015:1339 normal SHIPPED_LIVE gcc bug fix and enhancement update 2015-07-20 18:00:00 UTC

Description Rafal Wijata 2014-10-08 14:01:13 UTC
Description of problem:
iterating over vector/table of bitfield structs and summing generates wrong sum(using sse2 instructions in -O3).

Version-Release number of selected component (if applicable):
RHEL6.5 gcc-4.4.7-4.el6.x86_64
RHEL5 gcc44-4.4.7-1.el5

How reproducible:
#include <stdio.h>
#include <stdint.h>

struct Bitf
    uint64_t begin  : 40;
    uint64_t len : 24;
};// __attribute__((packed));

void main(int argc, char * argv[])

    struct Bitf bf[10];
    uint64_t i;
    for(i = 0; i < 10; ++i)
       struct Bitf b1 = {(1ULL << 40)-1, i};
       bf[i] = b1;

    uint64_t rv = 0;
    struct Bitf * it;
    for(it = bf; it != (bf + 10); ++it)
        rv += it->len;
    printf("%llu\n",  rv);

Steps to Reproduce:
1. /usr/bin/gcc -o a1 a1.c -O3 -m64
2. ./a1

Actual results:

Expected results:

Additional info:
-m32 -msse2 is buggy as well

Comment 2 Rafal Wijata 2014-10-08 14:36:13 UTC
-fno-tree-vectorize works this problem around

Comment 3 Marek Polacek 2014-10-08 15:19:57 UTC
r157624 seems to fix it.

Comment 7 errata-xmlrpc 2015-07-22 06:48:26 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.


Note You need to log in before you can comment on or make changes to this bug.