From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16488 invoked by alias); 19 Sep 2014 14:10:38 -0000 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 Received: (qmail 16417 invoked by uid 48); 19 Sep 2014 14:10:34 -0000 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/58192] G++ emits incorrect code when passing enum classes as function parameters Date: Fri, 19 Sep 2014 14:10:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 4.8.1 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-09/txt/msg01952.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58192 --- Comment #10 from Jakub Jelinek --- When I compile: #ifdef CHAR typedef unsigned char Foo; #else enum class Foo : unsigned char { FOO }; #endif unsigned int v1, v2; __attribute__((noinline, noclone)) static void foo (Foo a) { v1 = (unsigned int) a; } __attribute__((noinline, noclone)) void bar (Foo a) { v2 = (unsigned int) a; } void baz (unsigned int a) { foo ((Foo) a); bar ((Foo) a); } with -DCHAR vs. -UCHAR, there is a difference visible already in *.original dump: <>>>>; + foo ((Foo) a) >>>>>; <>>>>; + bar ((Foo) a) >>>>>; i.e. there is explicit zero-extension for integral types smaller than int in the IL (i.e. for the -DCHAR) case, but nothing like that for the enum class with underlying type smaller than int. And presumably the middle-end and backends rely on this.