From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id A1E813858C55 for ; Fri, 29 Mar 2024 22:31:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A1E813858C55 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A1E813858C55 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711751469; cv=none; b=Wf31xb+kOqWK5Z4UNyuQw2CP4tGtGj0a1pQXal/+2hlSvPDleHxZCRcdOwMJpcMYM0ClwgVRiGo6C05+RYkg8yZ3/LnEE5Db63m2I+1WJQFoJ1WJIrApu/GC18BgTO/s4W8T+bxvIpqTU4KHYSAaS3VGtyByDa3xOnkfyI8ulhc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711751469; c=relaxed/simple; bh=iKMlN19gpWpmHBbuviEZWAfrwn75OF0xf2QnzjmoyC0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ljFjqcXCW/hPmNF4BIyrbGVh9ihnrT5Bg8ynb5DD4Cl6LRrBNQmPthzfTrydqHgHnTUQSzp09eQVUpwf3ScEhxTMNEVaUoXwoEAJc/zsSL+/eu7NDw/Lq+/Ek9nHMIFj1kCe6YzcGaMYS/to76JHGphcw2J2/eaL/buQVV+gzRk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711751466; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=tm+KbO/JXrPtMIPfPXq/wvufjUtdTMUg14/sSA6cass=; b=iw5hLdgB3svNuU92ryjzIRSsX8ZKYy3f0EzwDCg5GNoG7azdf8EjKsW6PolZTyvgAq+tqs 4xIxkzDxjwZXF+yL4MCWWdSEaHtBTjsUKaRndBu1y7I77aI0wRbg+WyGfLl7UduKaoRb+1 fNmdQ2Lp1nhgWkmuJGMjmEuZXeJ2CaU= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-164-f334g7O4ObyYa6vDJODf6w-1; Fri, 29 Mar 2024 18:31:04 -0400 X-MC-Unique: f334g7O4ObyYa6vDJODf6w-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8A9C91C051A6 for ; Fri, 29 Mar 2024 22:31:04 +0000 (UTC) Received: from pdp-11.lan (unknown [10.22.16.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6DE82492BD0; Fri, 29 Mar 2024 22:31:04 +0000 (UTC) From: Marek Polacek To: GCC Patches , Jason Merrill Subject: [PATCH] c++: ICE with scoped enum in switch condition [PR114451] Date: Fri, 29 Mar 2024 18:31:01 -0400 Message-ID: <20240329223101.421760-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/13? -- >8 -- Here we ICE when gimplifying enum class Type { Pawn }; struct Piece { Type type : 4; }; void foo() { switch (Piece().type) case Type::Pawn:; } because we ended up with TYPE_PRECISION (cond) < TYPE_PRECISION (case). That's because the case expr type here is the unlowered type Type, whereas the conditional's type is the lowered . This is not supposed to happen: see the comment in pop_switch around the is_bitfield_expr_with_lowered_type check. But here we did not revert to the lowered SWITCH_STMT_TYPE, because the conditional contains a TARGET_EXPR, which has side-effects, which means that finish_switch_cond -> maybe_cleanup_point_expr wraps it in a CLEANUP_POINT_EXPR. And is_bitfield_expr_with_lowered_type does not see through those. PR c++/103825 gcc/cp/ChangeLog: * typeck.cc (is_bitfield_expr_with_lowered_type): Handle CLEANUP_POINT_EXPR. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/enum44.C: New test. --- gcc/cp/typeck.cc | 1 + gcc/testsuite/g++.dg/cpp0x/enum44.C | 30 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/enum44.C diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc index f5a0a2273be..9a096b51d55 100644 --- a/gcc/cp/typeck.cc +++ b/gcc/cp/typeck.cc @@ -2400,6 +2400,7 @@ is_bitfield_expr_with_lowered_type (const_tree exp) case NEGATE_EXPR: case NON_LVALUE_EXPR: case BIT_NOT_EXPR: + case CLEANUP_POINT_EXPR: return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 0)); case COMPONENT_REF: diff --git a/gcc/testsuite/g++.dg/cpp0x/enum44.C b/gcc/testsuite/g++.dg/cpp0x/enum44.C new file mode 100644 index 00000000000..92408c92217 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/enum44.C @@ -0,0 +1,30 @@ +// PR c++/103825 +// { dg-do compile { target c++11 } } + +enum class Type { Pawn }; +struct Piece { + Type type : 4; +}; + +void +foo () +{ + switch (Piece().type) + case Type::Pawn:; + + auto x = Piece().type; + switch (x) + case Type::Pawn:; +} + +enum class En {A}; +struct St {En field :1;}; + +void +bar () +{ + volatile St s = {En::A}; + switch(s.field) { + case En::A : break; + } +} base-commit: 4c18ace1cb69a31af4ac719850a66de79ed12e93 -- 2.44.0