From patchwork Fri Feb 14 16:46:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1238213 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-519552-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=kgpa+Lmm; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=JWrmbjO3; dkim-atps=neutral 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 48Jzmk1tcRzB3xH for ; Sat, 15 Feb 2020 03:46:44 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type:content-transfer-encoding; q=dns; s=default; b=jSD kvEWWDmVECAL+XX7ocrnRpv56TQi1NzW6SNQO2smxz+S9hPzmxCrECa/C5/NwHma t2VCzs1DpEaL6NWBNGNWEuCmpCy3n0Sj98ZPk5eQeY+03mwRQOfa1q/uel/B2MC2 oyqQ8rCVfVVzMUffuWtUlEQD9sXn/LNk8jxf3jBg= 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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type:content-transfer-encoding; s=default; bh=hsduRHkA8 WG5hi2vxGEqjEIMTFQ=; b=kgpa+LmmPIEtajanHeXjkHW/W5vNF+ee/Pf17913o Cv2jkJMTSbzgP0YJdteu1mHclKwrjvsaANqhmjI1otUwh5mc/OG4ePU0uxPUUVib kgITRraBq4IOoBZDdDOPcbzVZZ5ZNCw63eMUkZMaKl+GEWbEHw3c0FUK6z/soE5O Ls= Received: (qmail 100850 invoked by alias); 14 Feb 2020 16:46:37 -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 100839 invoked by uid 89); 14 Feb 2020 16:46:37 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-8.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-1.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (207.211.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 14 Feb 2020 16:46:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581698794; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=k2MzdEFMpFKYVETPLomZpxUpp70KT/KkT2VOKOHfcuo=; b=JWrmbjO3bVi5IGxFOIAsT7/UeC+9LwOoTzYeIR9TCgzmMts/D5sbuzDiIUyfUaZR1o8K+u Z8Sd67KD16iisbx5CelrtQkGfYGVodcXyd1uUmMFGeV5uuH1MvISdh0s93t+efFfuI338r 4OgTkzwh9EGOs2HEqNF1vR/OtPxT7+s= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-227-gmidqGllMjSvrdWTP0Oetw-1; Fri, 14 Feb 2020 11:46:30 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 91C3D8017CC for ; Fri, 14 Feb 2020 16:46:29 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-51.ams2.redhat.com [10.36.116.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 144285C115; Fri, 14 Feb 2020 16:46:28 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id 01EGkRQE001647; Fri, 14 Feb 2020 17:46:27 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id 01EGkQe9001646; Fri, 14 Feb 2020 17:46:26 +0100 Date: Fri, 14 Feb 2020 17:46:26 +0100 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [committed] c++: Fix thinko in enum_min_precision [PR61414] Message-ID: <20200214164626.GQ17695@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 User-Agent: Mutt/1.11.3 (2019-02-01) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-IsSubscribed: yes Hi! When backporting the PR61414 fix to 8.4, I've noticed that the caching of prec is actually broken, as it would fail to actually store the computed precision into the hash_map's value and so next time we'd think the enum needs 0 bits. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux and committed to trunk, 9.3 and 8.4. 2020-02-14 Jakub Jelinek PR c++/61414 * class.c (enum_min_precision): Change prec type from int to int &. * g++.dg/cpp0x/enum39.C: New test. Jakub --- gcc/cp/class.c.jj 2020-02-12 11:44:18.423371637 +0100 +++ gcc/cp/class.c 2020-02-14 14:33:41.842057349 +0100 @@ -3289,7 +3289,7 @@ enum_min_precision (tree type) enum_to_min_precision = hash_map::create_ggc (37); bool existed; - int prec = enum_to_min_precision->get_or_insert (type, &existed); + int &prec = enum_to_min_precision->get_or_insert (type, &existed); if (existed) return prec; --- gcc/testsuite/g++.dg/cpp0x/enum39.C.jj 2020-02-14 14:30:26.489972394 +0100 +++ gcc/testsuite/g++.dg/cpp0x/enum39.C 2020-02-14 14:30:22.530031482 +0100 @@ -0,0 +1,15 @@ +// PR c++/61414 +// { dg-do compile { target c++11 } } + +enum class E { E0 = -4, E1 = 3 }; +enum F : unsigned { F0 = 0, F1 = 15 }; + +struct S +{ + E a : 2; // { dg-warning "'S::a' is too small to hold all values of 'enum class E'" } + E b : 2; // { dg-warning "'S::b' is too small to hold all values of 'enum class E'" } + E c : 3; // { dg-bogus "'S::c' is too small to hold all values of 'enum class E'" } + F d : 3; // { dg-warning "'S::d' is too small to hold all values of 'enum F'" } + F e : 3; // { dg-warning "'S::e' is too small to hold all values of 'enum F'" } + F f : 4; // { dg-bogus "'S::f' is too small to hold all values of 'enum F'" } +};