From patchwork Mon Oct 17 10:21:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Senthil Kumar Selvaraj X-Patchwork-Id: 682842 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3syDnL4NChz9s5g for ; Mon, 17 Oct 2016 21:23:33 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=c2G3pN7Y; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type; q=dns; s=default; b=p5j1W7NWN6MdXYH6S5h+TxjbLxE5EdzayoixXG0WMyd1IXrxXW luVrpzXhLkqwbVaf7Sza1uYovF01hPkh+ssPYmRHQX/fkWUnzv6I8z+1V2f/ytfy FIJ/p4OSHcXOLKEgYsVMMDVONT4z2mM9f6XjeSZHmMOj+ZXOdeI3bYHP4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type; s= default; bh=httUrrMjLT7VBleurwgMBe/MaQM=; b=c2G3pN7YbLiLSBV3I2ot xp1Hm/X5nBwLnFtf4kvclrwjzMG/Decfqkyf1iSAQLtSwKyXQ2PqlfsrsGLgms9r OHknvubJxTE0MuPRtpoglUNToIWqepHqD5q4228Oh4Kwq06kLnssZcKtDH1I5wTF /5F00/jPOhQz3CE/S35AS2I= Received: (qmail 5597 invoked by alias); 17 Oct 2016 10:23:24 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 5574 invoked by uid 89); 17 Oct 2016 10:23:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.8 required=5.0 tests=BAYES_00, RCVD_IN_BRBL_LASTEXT, RP_MATCHES_RCVD, SPF_PASS autolearn=no version=3.3.2 spammy=H*RU:212.144.249.242, H*RU:sk:eusmtp0, HX-HELO:sk:eusmtp0, H*r:10.145.145 X-HELO: eusmtp01.atmel.com Received: from eusmtp01.atmel.com (HELO eusmtp01.atmel.com) (212.144.249.242) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 17 Oct 2016 10:23:13 +0000 Received: from HNOCHT01.corp.atmel.com (10.145.133.40) by eusmtp01.atmel.com (10.145.145.30) with Microsoft SMTP Server (TLS) id 14.3.235.1; Mon, 17 Oct 2016 12:23:08 +0200 Received: from jaguar.atmel.com (10.145.133.18) by HNOCHT01.corp.atmel.com (10.145.133.40) with Microsoft SMTP Server (TLS) id 14.3.235.1; Mon, 17 Oct 2016 12:23:08 +0200 User-agent: mu4e 0.9.17; emacs 24.5.1 From: Senthil Kumar Selvaraj To: GCC Patches CC: Marek Polacek Subject: [Patch] Backport fix for PR 52085 to gcc-5-branch? Date: Mon, 17 Oct 2016 15:51:54 +0530 Message-ID: <87y41ne0n1.fsf@atmel.com> MIME-Version: 1.0 X-IsSubscribed: yes Hi, The fix for PR 52085 went into trunk when trunk was 6.0. I ran into the same issue on a gcc 5.x and found that the fix didn't get backported. Bootstrapped and reg tested below patch with x86-64-pc-linux. Ok to backport to gcc-5-branch? Regards Senthil gcc/c/ChangeLog 2016-10-17 Senthil Kumar Selvaraj Backport from mainline 2015-04-25 Marek Polacek PR c/52085 * c-decl.c (finish_enum): Copy over TYPE_ALIGN. Also check for "mode" attribute. gcc/testsuite/ChangeLog 2016-10-17 Senthil Kumar Selvaraj Backport from mainline 2015-04-25 Marek Polacek PR c/52085 * gcc.dg/enum-incomplete-2.c: New test. * gcc.dg/enum-mode-1.c: New test. diff --git gcc/c/c-decl.c gcc/c/c-decl.c index d1e7444..c508e7f 100644 --- gcc/c/c-decl.c +++ gcc/c/c-decl.c @@ -8050,7 +8050,7 @@ finish_enum (tree enumtype, tree values, tree attributes) /* If the precision of the type was specified with an attribute and it was too small, give an error. Otherwise, use it. */ - if (TYPE_PRECISION (enumtype)) + if (TYPE_PRECISION (enumtype) && lookup_attribute ("mode", attributes)) { if (precision > TYPE_PRECISION (enumtype)) { @@ -8078,6 +8078,7 @@ finish_enum (tree enumtype, tree values, tree attributes) TYPE_MIN_VALUE (enumtype) = TYPE_MIN_VALUE (tem); TYPE_MAX_VALUE (enumtype) = TYPE_MAX_VALUE (tem); TYPE_UNSIGNED (enumtype) = TYPE_UNSIGNED (tem); + TYPE_ALIGN (enumtype) = TYPE_ALIGN (tem); TYPE_SIZE (enumtype) = 0; TYPE_PRECISION (enumtype) = TYPE_PRECISION (tem); diff --git gcc/testsuite/gcc.dg/enum-incomplete-2.c gcc/testsuite/gcc.dg/enum-incomplete-2.c new file mode 100644 index 0000000..5970551 --- /dev/null +++ gcc/testsuite/gcc.dg/enum-incomplete-2.c @@ -0,0 +1,41 @@ +/* PR c/52085 */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +#define SA(X) _Static_assert((X),#X) + +enum e1; +enum e1 { A } __attribute__ ((__packed__)); +enum e2 { B } __attribute__ ((__packed__)); +SA (sizeof (enum e1) == sizeof (enum e2)); +SA (_Alignof (enum e1) == _Alignof (enum e2)); + +enum e3; +enum e3 { C = 256 } __attribute__ ((__packed__)); +enum e4 { D = 256 } __attribute__ ((__packed__)); +SA (sizeof (enum e3) == sizeof (enum e4)); +SA (_Alignof (enum e3) == _Alignof (enum e4)); + +enum e5; +enum e5 { E = __INT_MAX__ } __attribute__ ((__packed__)); +enum e6 { F = __INT_MAX__ } __attribute__ ((__packed__)); +SA (sizeof (enum e5) == sizeof (enum e6)); +SA (_Alignof (enum e5) == _Alignof (enum e6)); + +enum e7; +enum e7 { G } __attribute__ ((__mode__(__byte__))); +enum e8 { H } __attribute__ ((__mode__(__byte__))); +SA (sizeof (enum e7) == sizeof (enum e8)); +SA (_Alignof (enum e7) == _Alignof (enum e8)); + +enum e9; +enum e9 { I } __attribute__ ((__packed__, __mode__(__byte__))); +enum e10 { J } __attribute__ ((__packed__, __mode__(__byte__))); +SA (sizeof (enum e9) == sizeof (enum e10)); +SA (_Alignof (enum e9) == _Alignof (enum e10)); + +enum e11; +enum e11 { K } __attribute__ ((__mode__(__word__))); +enum e12 { L } __attribute__ ((__mode__(__word__))); +SA (sizeof (enum e11) == sizeof (enum e12)); +SA (_Alignof (enum e11) == _Alignof (enum e12)); diff --git gcc/testsuite/gcc.dg/enum-mode-1.c gcc/testsuite/gcc.dg/enum-mode-1.c new file mode 100644 index 0000000..a701123 --- /dev/null +++ gcc/testsuite/gcc.dg/enum-mode-1.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ + +enum e1 { A = 256 } __attribute__((__mode__(__byte__))); /* { dg-error "specified mode too small for enumeral values" } */ +enum e2 { B = 256 } __attribute__((__packed__, __mode__(__byte__))); /* { dg-error "specified mode too small for enumeral values" } */ + +enum e3 { C = __INT_MAX__ } __attribute__((__mode__(__QI__))); /* { dg-error "specified mode too small for enumeral values" } */ +enum e4 { D = __INT_MAX__ } __attribute__((__packed__, __mode__(__QI__))); /* { dg-error "specified mode too small for enumeral values" } */ + +enum e5 { E = __INT_MAX__ } __attribute__((__mode__(__HI__))); /* { dg-error "specified mode too small for enumeral values" } */ +enum e6 { F = __INT_MAX__ } __attribute__((__packed__, __mode__(__HI__))); /* { dg-error "specified mode too small for enumeral values" } */