From patchwork Fri Feb 12 00:12:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1439733 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=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=DEFh7kmm; dkim-atps=neutral Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DcDTv6swYz9sRf for ; Fri, 12 Feb 2021 11:12:48 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 91DB3388A419; Fri, 12 Feb 2021 00:12:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 91DB3388A419 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1613088765; bh=B4hj32w+mDE6xPv0jI6ZQgNvVksMQlVV8dRhhu63k5k=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=DEFh7kmmjZzDkfZWnBBoT37VlukdgOq79e0rC/MJMaSYlw7uc+swEIPs6/K9nuI2L GTaMD8ICoavmY5iaqrnYv8/g0XvsBs1Dk2neIASav6qEDA1P2BN19HHGlirD+IXt6T eNub1muA1/9BGKfc9N/d8y4C1043hgkkxBf/Sm5g= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) by sourceware.org (Postfix) with ESMTPS id 1DBA0386F013 for ; Fri, 12 Feb 2021 00:12:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1DBA0386F013 Received: by mail-qk1-x72f.google.com with SMTP id f17so3942812qkl.5 for ; Thu, 11 Feb 2021 16:12:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language; bh=B4hj32w+mDE6xPv0jI6ZQgNvVksMQlVV8dRhhu63k5k=; b=olPy9V7FIdMUxjcZeQ7fNS3Zb0UT8RcHvTUCK+28ng0w9JQiO8N/J+DnmPbiRRFYEz hxqZ5yQKOXTLJXh13vdNGuADvV1eGbxfZKVXK1uQcFgvPhVMsu9SQKtb/abTCW/5ksP1 ae0H9mfXK11S9SI1AYeC0Y2SpYFar9x7NDlwsNiXdfw6iBOqwFmr7oThFraFNKDknB6z EgFwmKJh169MmgYo6jF/OyZAHDFKRo3tMhTTD5VW0ozJi1lKxd6Zbf5odLB3CXoSlfDk OEr+nbx6C/bDuRid6D9fWoteddyQWdSlAnBFgdmaHHnw4nCVrP9Rh2IwixNmxSuBDc0n mCHQ== X-Gm-Message-State: AOAM5326OYnfxfIInWbsbr4iBVJFeBSPSPtNUtX9YGyGGnPDFGNH9sUW f9CmRWJsuAn65BSvcP1s92eO0y/yCiE= X-Google-Smtp-Source: ABdhPJwko7bHSvGhpUi3HIgibZGPM3kE+OjyfxgPiMs05DS+DUGqo0geLPlIxPUbKurullZFhrPyzg== X-Received: by 2002:ae9:e64a:: with SMTP id x10mr348116qkl.437.1613088759575; Thu, 11 Feb 2021 16:12:39 -0800 (PST) Received: from [192.168.0.41] (184-96-239-30.hlrn.qwest.net. [184.96.239.30]) by smtp.gmail.com with ESMTPSA id d193sm549555qkg.126.2021.02.11.16.12.38 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 11 Feb 2021 16:12:38 -0800 (PST) To: gcc-patches Subject: [stage 1 patch] remove unreachable code in expand_expr_real_1 (PR 21433) Message-ID: Date: Thu, 11 Feb 2021 17:12:37 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Martin Sebor via Gcc-patches From: Martin Sebor Reply-To: Martin Sebor Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" While trawling through old bugs I came across one from 2005: PR 21433 - The COMPONENT_REF case of expand_expr_real_1 is probably wrong. The report looks correct in that argument 0 in COMPONENT_REF cannot be a CONSTRUCTOR. In my tests it's only been one of the following codes: array_ref component_ref mem_ref parm_decl result_decl var_decl The attached patch removes the CONSTRUCTOR code and replaces it with an assert verifying it doesn't come up there. Besides testing on x86_64-linux, the change is supported by comments in code and also in the internals manual (although that looks incorrect and should be changed to avoid suggesting the first operand is a decl). tree.def: /* Value is structure or union component. Operand 0 is the structure or union (an expression). Operand 1 is the field (a node of type FIELD_DECL). Operand 2, if present, is the value of DECL_FIELD_OFFSET, measured in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. */ DEFTREECODE (COMPONENT_REF, "component_ref", tcc_reference, 3) generic.texi: @item COMPONENT_REF These nodes represent non-static data member accesses. The first operand is the object (rather than a pointer to it); the second operand is the @code{FIELD_DECL} for the data member. The third operand represents the byte offset of the field, but should not be used directly; call @code{component_ref_field_offset} instead. PR middle-end/21433 - The COMPONENT_REF case of expand_expr_real_1 is probably wrong gcc/ChangeLog: PR middle-end/21433 * expr.c (expand_expr_real_1): Replace unreachable code with an assert. diff --git a/gcc/expr.c b/gcc/expr.c index 86dc1b6c973..7d5efe5722a 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -10767,61 +10767,8 @@ expand_expr_real_1 (tree exp, rtx target, machine_mode tmode, goto normal_inner_ref; case COMPONENT_REF: - /* If the operand is a CONSTRUCTOR, we can just extract the - appropriate field if it is present. */ - if (TREE_CODE (treeop0) == CONSTRUCTOR) - { - unsigned HOST_WIDE_INT idx; - tree field, value; - scalar_int_mode field_mode; - - FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (treeop0), - idx, field, value) - if (field == treeop1 - /* We can normally use the value of the field in the - CONSTRUCTOR. However, if this is a bitfield in - an integral mode that we can fit in a HOST_WIDE_INT, - we must mask only the number of bits in the bitfield, - since this is done implicitly by the constructor. If - the bitfield does not meet either of those conditions, - we can't do this optimization. */ - && (! DECL_BIT_FIELD (field) - || (is_int_mode (DECL_MODE (field), &field_mode) - && (GET_MODE_PRECISION (field_mode) - <= HOST_BITS_PER_WIDE_INT)))) - { - if (DECL_BIT_FIELD (field) - && modifier == EXPAND_STACK_PARM) - target = 0; - op0 = expand_expr (value, target, tmode, modifier); - if (DECL_BIT_FIELD (field)) - { - HOST_WIDE_INT bitsize = TREE_INT_CST_LOW (DECL_SIZE (field)); - scalar_int_mode imode - = SCALAR_INT_TYPE_MODE (TREE_TYPE (field)); - - if (TYPE_UNSIGNED (TREE_TYPE (field))) - { - op1 = gen_int_mode ((HOST_WIDE_INT_1 << bitsize) - 1, - imode); - op0 = expand_and (imode, op0, op1, target); - } - else - { - int count = GET_MODE_PRECISION (imode) - bitsize; - - op0 = expand_shift (LSHIFT_EXPR, imode, op0, count, - target, 0); - op0 = expand_shift (RSHIFT_EXPR, imode, op0, count, - target, 0); - } - } - - return op0; - } - } - goto normal_inner_ref; - + gcc_assert (TREE_CODE (treeop0) != CONSTRUCTOR); + /* Fall through. */ case BIT_FIELD_REF: case ARRAY_RANGE_REF: normal_inner_ref: