From patchwork Wed Sep 7 01:20:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1052 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp914718wrt; Tue, 6 Sep 2022 18:21:45 -0700 (PDT) X-Google-Smtp-Source: AA6agR7JS3ezoIY62ipc0jLCdDbVNo3IDgVHg1sLd6khdd9tsDMLiTqeNIMkyo2aON1qfeFN4Pnp X-Received: by 2002:a05:6402:2789:b0:440:44b6:849b with SMTP id b9-20020a056402278900b0044044b6849bmr1038762ede.387.1662513705619; Tue, 06 Sep 2022 18:21:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662513705; cv=none; d=google.com; s=arc-20160816; b=lXp+2zZYVgz1od62DYhETAoy/NvHvYumsye02GDxggoyGKYGx/0PfjjwglnGCxLgG+ v+B8GPaQwa2WSeIZEoG2ZMeUwcD6HGvq7msa7N8PrWmZmpWB1tA4ABrAJ0G7pwk5GRv1 cfjjvDXuXkF3qAe+hfxCmv+mgNNFiWY3Niz2sHKNUQTOumgv/Xx16m3Z4jrxzsMb7AZ1 +vUVxwiYcYwoPLsz/Zrbj4fdNBc0IVU6MdoWGlTUHlE/MTmd4TqLB9K6JA7U6GxAex9J F5JZm/1oN9s9qYjO7JFLlC/Ep4iXU0zpoCx4hce87uX809IxO2IePb4XHTSdvF2QmNs2 XPyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=LC6D3p4rZxQrlLd+VBY//Y3aXI/FMMWX5Udrqioq4AI=; b=VV66Ms7JuWP5vcnmS3oUB+bV1KtBtnF8Sx/uTX5YtDKPwhuVGdFg5DK7GX8Y59geUE Dt4nZvNX158mQCEctC+SWoNt1uauo9G/oHHFojZGY2VRKOXSJfDFwOVRpnLYGEZG7jMi /hZpsI512b4pPD2YdULFX2arl44D8SflwG7sD2W7YeUqkvkITSVayd3KyWow6sDb4Fmv 3o8S0TYjjTswisf/lMjsuJ+Pwtn3gDotU8OXaO2/od/mhBLuRE4bup7QzhazWlFDktsB 8F848PRguD4I9OdtaR7vqKamEZkv6kwM80EAA/IuaX/+O4byLitzAASkUaao1rVS8s8L HEnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=KMKAZ7l9; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id hr28-20020a1709073f9c00b00730c1868d6bsi3723039ejc.90.2022.09.06.18.21.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 18:21:45 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=KMKAZ7l9; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 76D7C3820546 for ; Wed, 7 Sep 2022 01:21:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 76D7C3820546 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662513704; bh=LC6D3p4rZxQrlLd+VBY//Y3aXI/FMMWX5Udrqioq4AI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=KMKAZ7l92uQRpAFgbL3ZZcx2a4B6jCgpQiSn6utNRmMqhpV8gzMtIqNDmJqr3hpRj 0TsWDSb9HQH2NjypmOUe6A8oTKR95wcXlvVIpQXd9H6dJMcmcHWVAfIvwmz7k9HFlZ oP+Mlr8GdeDrj/iPxGfxX2jeUXcjjYS3036iUGQY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 D9ECB388B6BA for ; Wed, 7 Sep 2022 01:20:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D9ECB388B6BA Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-28-9ZdkVFtLNee1yR4fdnHT5Q-1; Tue, 06 Sep 2022 21:20:57 -0400 X-MC-Unique: 9ZdkVFtLNee1yR4fdnHT5Q-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0B88938173C1 for ; Wed, 7 Sep 2022 01:20:57 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.2.17.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE8C6403162; Wed, 7 Sep 2022 01:20:56 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c: fix uninitialized c_expr::m_decimal [PR106830] Date: Tue, 6 Sep 2022 21:20:47 -0400 Message-Id: <20220907012047.425066-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.0 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, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: David Malcolm via Gcc-patches From: David Malcolm Reply-To: David Malcolm Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1743271971533400542?= X-GMAIL-MSGID: =?utf-8?q?1743271971533400542?= I added c_expr::m_decimal in r13-2386-gbedfca647a9e9c1a as part of the implementation of -Wxor-used-as-pow, but I missed various places where the field needed to be initialized. Fixed thusly (based on searching for places that assign to the original_code field). Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. OK for trunk? Thanks Dave gcc/c-family/ChangeLog: PR c/106830 * c-warn.cc (check_for_xor_used_as_pow): Don't try checking values that don't fit in uhwi. gcc/c/ChangeLog: PR c/106830 * c-parser.cc (c_parser_initelt): Initialize m_decimal. (c_parser_cast_expression): Likewise. (c_parser_alignof_expression): Likewise. (c_parser_postfix_expression_after_paren_type): Likewise. (c_parser_postfix_expression_after_primary): Likewise. (c_parser_expression): Likewise. (c_parser_omp_variable_list): Likewise. (c_parser_transaction_expression): Likewise. * c-tree.h (c_expr::set_error): Likewise. * c-typeck.cc (c_expr_sizeof_expr): Likewise. (parser_build_unary_op): Likewise. (parser_build_binary_op): Likewise. (digest_init): Likewise. (pop_init_level): Likewise. * gimple-parser.cc (c_parser_gimple_call_internal): Likewise. gcc/testsuite/ChangeLog: PR c/106830 * gcc.dg/Wxor-used-as-pow-pr106830.c: New test. Signed-off-by: David Malcolm --- gcc/c-family/c-warn.cc | 9 +++------ gcc/c/c-parser.cc | 12 ++++++++++++ gcc/c/c-tree.h | 3 ++- gcc/c/c-typeck.cc | 7 +++++++ gcc/c/gimple-parser.cc | 5 +++++ gcc/testsuite/gcc.dg/Wxor-used-as-pow-pr106830.c | 6 ++++++ 6 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/Wxor-used-as-pow-pr106830.c diff --git a/gcc/c-family/c-warn.cc b/gcc/c-family/c-warn.cc index ed79cc3ca40..6742f447ff5 100644 --- a/gcc/c-family/c-warn.cc +++ b/gcc/c-family/c-warn.cc @@ -3809,12 +3809,9 @@ check_for_xor_used_as_pow (location_t lhs_loc, tree lhs_val, location_t operator_loc, tree rhs_val) { - /* Only complain if both args are non-negative integer constants. */ - if (!(TREE_CODE (lhs_val) == INTEGER_CST - && tree_int_cst_sgn (lhs_val) >= 0)) - return; - if (!(TREE_CODE (rhs_val) == INTEGER_CST - && tree_int_cst_sgn (rhs_val) >= 0)) + /* Only complain if both args are non-negative integer constants that fit + in uhwi. */ + if (!tree_fits_uhwi_p (lhs_val) || !tree_fits_uhwi_p (rhs_val)) return; /* Only complain if the LHS is 2 or 10. */ diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index 72db5b527f8..600ba4429ed 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -5462,6 +5462,7 @@ c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack) = objc_build_message_expr (rec, args); mexpr.original_code = ERROR_MARK; mexpr.original_type = NULL; + mexpr.m_decimal = 0; /* Now parse and process the remainder of the initializer, starting with this message expression as a primary-expression. */ @@ -8144,6 +8145,7 @@ c_parser_cast_expression (c_parser *parser, struct c_expr *after) set_c_expr_source_range (&ret, cast_loc, expr.get_finish ()); ret.original_code = ERROR_MARK; ret.original_type = NULL; + ret.m_decimal = 0; return ret; } else @@ -8460,6 +8462,7 @@ c_parser_alignof_expression (c_parser *parser) ret.original_code = ERROR_MARK; ret.original_type = NULL; set_c_expr_source_range (&ret, start_loc, end_loc); + ret.m_decimal = 0; return ret; } else @@ -8479,6 +8482,7 @@ c_parser_alignof_expression (c_parser *parser) ret.original_code = ERROR_MARK; ret.original_type = NULL; set_c_expr_source_range (&ret, start_loc, end_loc); + ret.m_decimal = 0; return ret; } } @@ -10369,6 +10373,7 @@ c_parser_postfix_expression_after_paren_type (c_parser *parser, expr.value = build_compound_literal (start_loc, type, init.value, non_const, alignas_align); set_c_expr_source_range (&expr, init.src_range); + expr.m_decimal = 0; expr.original_code = ERROR_MARK; expr.original_type = NULL; if (type != error_mark_node @@ -10583,6 +10588,7 @@ c_parser_postfix_expression_after_primary (c_parser *parser, set_c_expr_source_range (&expr, start, finish); expr.original_code = ERROR_MARK; expr.original_type = NULL; + expr.m_decimal = 0; break; case CPP_OPEN_PAREN: /* Function call. */ @@ -10631,6 +10637,7 @@ c_parser_postfix_expression_after_primary (c_parser *parser, = c_build_function_call_vec (expr_loc, arg_loc, expr.value, exprlist, origtypes); set_c_expr_source_range (&expr, start, finish); + expr.m_decimal = 0; expr.original_code = ERROR_MARK; if (TREE_CODE (expr.value) == INTEGER_CST @@ -10681,6 +10688,7 @@ c_parser_postfix_expression_after_primary (c_parser *parser, else expr.original_type = DECL_BIT_FIELD_TYPE (field); } + expr.m_decimal = 0; break; case CPP_DEREF: /* Structure element reference. */ @@ -10722,6 +10730,7 @@ c_parser_postfix_expression_after_primary (c_parser *parser, else expr.original_type = DECL_BIT_FIELD_TYPE (field); } + expr.m_decimal = 0; break; case CPP_PLUS_PLUS: /* Postincrement. */ @@ -10792,6 +10801,7 @@ c_parser_expression (c_parser *parser) expr.value = build_compound_expr (loc, expr.value, next.value); expr.original_code = COMPOUND_EXPR; expr.original_type = next.original_type; + expr.m_decimal = 0; } return expr; } @@ -13242,6 +13252,7 @@ c_parser_omp_variable_list (c_parser *parser, t_expr.original_code = ERROR_MARK; t_expr.original_type = NULL; set_c_expr_source_range (&t_expr, op_loc, op_loc); + t_expr.m_decimal = 0; t_expr = convert_lvalue_to_rvalue (op_loc, t_expr, true, false); t = build_indirect_ref (op_loc, t_expr.value, RO_ARROW); @@ -23552,6 +23563,7 @@ c_parser_transaction_expression (c_parser *parser, enum rid keyword) TRANSACTION_EXPR_RELAXED (ret.value) = 1; SET_EXPR_LOCATION (ret.value, loc); ret.original_code = TRANSACTION_EXPR; + ret.m_decimal = 0; if (!parens.require_close (parser)) { c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h index b4231a17859..46a3e8e9709 100644 --- a/gcc/c/c-tree.h +++ b/gcc/c/c-tree.h @@ -164,12 +164,13 @@ struct c_expr } /* Set the value to error_mark_node whilst ensuring that src_range - is initialized. */ + and m_decimal are initialized. */ void set_error () { value = error_mark_node; src_range.m_start = UNKNOWN_LOCATION; src_range.m_finish = UNKNOWN_LOCATION; + m_decimal = 0; } }; diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index 9ada5d25531..ae9418a3f11 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -2994,6 +2994,7 @@ c_expr_sizeof_expr (location_t loc, struct c_expr expr) ret.value = error_mark_node; ret.original_code = ERROR_MARK; ret.original_type = NULL; + ret.m_decimal = 0; pop_maybe_used (false); } else @@ -3017,6 +3018,7 @@ c_expr_sizeof_expr (location_t loc, struct c_expr expr) c_last_sizeof_loc = loc; ret.original_code = SIZEOF_EXPR; ret.original_type = NULL; + ret.m_decimal = 0; if (C_TYPE_VARIABLE_SIZE (TREE_TYPE (folded_expr))) { /* sizeof is evaluated when given a vla (C99 6.5.3.4p2). */ @@ -3047,6 +3049,7 @@ c_expr_sizeof_type (location_t loc, struct c_type_name *t) c_last_sizeof_loc = loc; ret.original_code = SIZEOF_EXPR; ret.original_type = NULL; + ret.m_decimal = 0; if (type == error_mark_node) { ret.value = error_mark_node; @@ -3782,6 +3785,7 @@ parser_build_unary_op (location_t loc, enum tree_code code, struct c_expr arg) result.original_code = code; result.original_type = NULL; + result.m_decimal = 0; if (reject_gcc_builtin (arg.value)) { @@ -3844,6 +3848,7 @@ parser_build_binary_op (location_t location, enum tree_code code, arg1.value, arg2.value, true); result.original_code = code; result.original_type = NULL; + result.m_decimal = 0; if (TREE_CODE (result.value) == ERROR_MARK) { @@ -8072,6 +8077,7 @@ digest_init (location_t init_loc, tree type, tree init, tree origtype, expr.value = inside_init; expr.original_code = (strict_string ? STRING_CST : ERROR_MARK); expr.original_type = NULL; + expr.m_decimal = 0; maybe_warn_string_init (init_loc, type, expr); if (TYPE_DOMAIN (type) && !TYPE_MAX_VALUE (TYPE_DOMAIN (type))) @@ -8936,6 +8942,7 @@ pop_init_level (location_t loc, int implicit, ret.value = NULL_TREE; ret.original_code = ERROR_MARK; ret.original_type = NULL; + ret.m_decimal = 0; if (implicit == 0) { diff --git a/gcc/c/gimple-parser.cc b/gcc/c/gimple-parser.cc index b909eac498d..5a2da2cfa0e 100644 --- a/gcc/c/gimple-parser.cc +++ b/gcc/c/gimple-parser.cc @@ -1332,6 +1332,7 @@ c_parser_gimple_call_internal (gimple_parser &parser) exprlist.address ()); expr.original_code = ERROR_MARK; expr.original_type = NULL; + expr.m_decimal = 0; } } return expr; @@ -1751,6 +1752,7 @@ c_parser_gimple_postfix_expression_after_primary (gimple_parser &parser, finish = c_parser_tokens_buf (parser, 0)->location; expr.value = build_array_ref (op_loc, expr.value, idx); set_c_expr_source_range (&expr, start, finish); + expr.m_decimal = 0; expr.original_code = ERROR_MARK; expr.original_type = NULL; @@ -1774,6 +1776,7 @@ c_parser_gimple_postfix_expression_after_primary (gimple_parser &parser, expr.value = build_call_array_loc (expr_loc, TREE_TYPE (TREE_TYPE (expr.value)), expr.value, exprlist.length (), exprlist.address ()); + expr.m_decimal = 0; expr.original_code = ERROR_MARK; expr.original_type = NULL; break; @@ -1802,6 +1805,7 @@ c_parser_gimple_postfix_expression_after_primary (gimple_parser &parser, expr.value = build_component_ref (op_loc, expr.value, ident, comp_loc, UNKNOWN_LOCATION); set_c_expr_source_range (&expr, start, finish); + expr.m_decimal = 0; expr.original_code = ERROR_MARK; if (TREE_CODE (expr.value) != COMPONENT_REF) expr.original_type = NULL; @@ -1851,6 +1855,7 @@ c_parser_gimple_postfix_expression_after_primary (gimple_parser &parser, ident, comp_loc, expr.get_location ()); set_c_expr_source_range (&expr, start, finish); + expr.m_decimal = 0; expr.original_code = ERROR_MARK; if (TREE_CODE (expr.value) != COMPONENT_REF) expr.original_type = NULL; diff --git a/gcc/testsuite/gcc.dg/Wxor-used-as-pow-pr106830.c b/gcc/testsuite/gcc.dg/Wxor-used-as-pow-pr106830.c new file mode 100644 index 00000000000..104897a5f39 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wxor-used-as-pow-pr106830.c @@ -0,0 +1,6 @@ +/* { dg-require-effective-target int128 } + { dg-options "-Wno-pedantic" } */ + +void foo0_u16_0() { + (__int128)(18302628885633695743 << 4) ^ 0; /* { dg-warning "integer constant is so large that it is unsigned" } */ +}