From patchwork Fri Nov 29 23:35:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1202656 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-514903-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.b="OAPVvkOD"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="Hi8Fmg4F"; 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 47PrTs4P49z9sPh for ; Sat, 30 Nov 2019 10:35:29 +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=X5t TIULxXqg7GPp4Yu5ZIxstFwJH1mlvUC/MJ3gldUqK9L+upLHWwsloWuVu0ytlz0M z1j+BlMBOM2aWu/YQyhT2xkAR9at9wb5YuaIgYtwZAg5SU6kx+/Ha2WlGp3GBFiG 0yUlNUXIS024YUhIV4W4lxTCTY1TWdeizdqZPOvY= 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=JMJNkV+fH NJWwtfqqqeNeyIgSek=; b=OAPVvkODlReHdZN05pQTEKZzWSVxEhvfoMHvchZ5x WFdNPu/2ns8Z0YhBcvK1HMllHNR80T9R3gCjhnvwBFQkxiBWvZen3xUNcmtdANwF qeULB/S2KgXsRvq2csa9HWU0G55GofbFyeqhpkcD8wlpwBHGLpq0v4/OWe5+JMCi bc= Received: (qmail 63517 invoked by alias); 29 Nov 2019 23:35:19 -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 63470 invoked by uid 89); 29 Nov 2019 23:35:19 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (205.139.110.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 29 Nov 2019 23:35:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575070515; 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=L+6RD4Mt87pJFFAgGxtPMusa1MYdvKngoFBihPY4w14=; b=Hi8Fmg4FcVyJQq/dFE4xTJrDHAY7oJsMm/pCWzEQxPGBlc7oLVXPY5IxTfuJcviGh6OHOw z2CIoqlkw25slEaGFL1CAU071JXFBX6CF1v3noozCazJHhNlw9VJn21bWVmRV9eZM/ZZas 5FAcJqq7cneTJSGg2gIb1VzPV3hn5ZQ= 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-320-b1ubAgvYOC20u-KQHZl6Vw-1; Fri, 29 Nov 2019 18:35:12 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A8FDF184CAA0 for ; Fri, 29 Nov 2019 23:35:11 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-117-59.ams2.redhat.com [10.36.117.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 386DA5D9C9; Fri, 29 Nov 2019 23:35:11 +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 xATNZ9TK028942; Sat, 30 Nov 2019 00:35:09 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id xATNZ8Gm028926; Sat, 30 Nov 2019 00:35:08 +0100 Date: Sat, 30 Nov 2019 00:35:08 +0100 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Fix nsdmi handling for bitfields (PR c++/92732) Message-ID: <20191129233508.GP10088@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 User-Agent: Mutt/1.11.3 (2019-02-01) X-Mimecast-Spam-Score: 0 Content-Disposition: inline X-IsSubscribed: yes Hi! As the second testcase shows, we shouldn't be calling convert_for_* with TREE_TYPE (decl) for bitfields, we need DECL_BIT_FIELD_TYPE in that case instead (unlowered_expr_type doesn't work here, as that wants a COMPONENT_REF which we don't have). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2019-11-29 Jakub Jelinek PR c++/92732 * typeck2.c (digest_nsdmi_init): For bitfields, use DECL_BIT_FIELD_TYPE instead of TREE_TYPE. * g++.dg/cpp2a/bitfield3.C: Don't expect narrowing conversion warnings. * g++.dg/cpp2a/bitfield4.C: New test. Jakub --- gcc/cp/typeck2.c.jj 2019-11-25 22:44:24.911346688 +0100 +++ gcc/cp/typeck2.c 2019-11-29 21:48:58.825713516 +0100 @@ -1335,6 +1335,9 @@ digest_nsdmi_init (tree decl, tree init, gcc_assert (TREE_CODE (decl) == FIELD_DECL); tree type = TREE_TYPE (decl); + if (DECL_BIT_FIELD_TYPE (decl)) + type = cp_build_qualified_type (DECL_BIT_FIELD_TYPE (decl), + cp_type_quals (type)); int flags = LOOKUP_IMPLICIT; if (DIRECT_LIST_INIT_P (init)) { --- gcc/testsuite/g++.dg/cpp2a/bitfield3.C.jj 2017-09-29 19:49:17.684827064 +0200 +++ gcc/testsuite/g++.dg/cpp2a/bitfield3.C 2019-11-29 21:52:56.636122855 +0100 @@ -15,11 +15,9 @@ const int b = 0; struct S { int c : 5 = 2 * a; // { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } } int d : 6 { c + a }; // { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } } - // { dg-warning "narrowing conversion of" "" { target *-*-* } .-1 } int e : true ? 7 : a = 3; int f : (true ? 8 : b) = d + a; // { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } } int g : (true ? 9 : b) { f + a }; // { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } } - // { dg-warning "narrowing conversion of" "" { target *-*-* } .-1 } int h : 1 || new int { 0 }; int i = g + a; }; @@ -28,11 +26,9 @@ template struct U { int j : W = 3 * a; // { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } } int k : W { j + a }; // { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } } - // { dg-warning "narrowing conversion of" "" { target *-*-* } .-1 } int l : V ? 7 : a = 3; int m : (V ? W : b) = k + a; // { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } } int n : (V ? W : b) { m + a }; // { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } } - // { dg-warning "narrowing conversion of" "" { target *-*-* } .-1 } int o : 1 || new int { 0 }; int p = n + a; }; --- gcc/testsuite/g++.dg/cpp2a/bitfield4.C.jj 2019-11-29 21:48:28.752167687 +0100 +++ gcc/testsuite/g++.dg/cpp2a/bitfield4.C 2019-11-29 21:52:40.548365714 +0100 @@ -0,0 +1,12 @@ +// PR c++/92732 +// { dg-do compile { target c++17 } } +// { dg-options "" } + +enum class byte : unsigned char { }; +using uint8_t = unsigned char; + +struct T +{ + byte a : 2 = byte{0}; // { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } } + uint8_t b : 2 = 0; // { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } } +} t;