From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22160 invoked by alias); 11 Mar 2007 18:48:12 -0000 Received: (qmail 22105 invoked by uid 48); 11 Mar 2007 18:48:02 -0000 Date: Sun, 11 Mar 2007 18:48:00 -0000 Subject: [Bug tree-optimization/31136] New: FRE ignores bit-field truncation X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "TabonyEE at austin dot rr dot com" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2007-03/txt/msg00976.txt.bz2 With the tip of the 4.2 branch, the following program returns 1. Mainline returns 0. Is this defined behavior? I could not find anything on the subject. struct S { unsigned b4:4; unsigned b6:6; } s; int main(void){ s.b6 = 31; s.b4 = s.b6; s.b6 = s.b4; return s.b6 == 15 ? 0 : 1; } before FRE (-fdump-tree-ccp): ;; Function main (main) main () { short unsigned int D.1882; short unsigned int D.1881; int D.1880; D.1879; D.1878; D.1877; D.1876; : s.b6 = 31; D.1876_3 = s.b6; D.1877_4 = () D.1876_3; s.b4 = D.1877_4; D.1878_7 = s.b4; D.1879_8 = () D.1878_7; s.b6 = D.1879_8; D.1881_10 = BIT_FIELD_REF ; D.1882_11 = D.1881_10 & 1008; D.1880_12 = D.1882_11 != 240; return D.1880_12; } after FRE (-fdump-tree-fre): ;; Function main (main) main () { short unsigned int D.1882; short unsigned int D.1881; int D.1880; D.1879; D.1878; D.1877; D.1876; : s.b6 = 31; D.1876_3 = 31; D.1877_4 = () D.1876_3; s.b4 = D.1877_4; D.1878_7 = D.1877_4; D.1879_8 = 31; s.b6 = D.1879_8; D.1881_10 = BIT_FIELD_REF ; D.1882_11 = D.1881_10 & 1008; D.1880_12 = D.1882_11 != 240; return D.1880_12; } D.1879_8 was replaced by 31, ignoring the fact that the value should have been truncated to 15 when assigned to s.b4. -- Summary: FRE ignores bit-field truncation Product: gcc Version: 4.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: TabonyEE at austin dot rr dot com GCC build triplet: x86_64-unknown-linux-gnu GCC host triplet: x86_64-unknown-linux-gnu GCC target triplet: x86_64-unknown-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31136