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 E451D3858C78 for ; Wed, 19 Jul 2023 22:01:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E451D3858C78 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689804071; h=from:from: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=WJkZOzoFc6hXVoplnKkbXBjdosrdUISkuiCNlppr+bA=; b=Kct7G5EQzzBcEj5g66v5/pA7BYXxzHKMWho2iBohLjC/kgxQ5+XitEX5Gi78HhkLzc1SwI GurnXfHh0TbMW0qh2BOIa6tG/9J++mvwDgstJKTlCQlwzOO2apE9UmTUJU1r0/M2Y6ryK5 dOfZOkNRNqcKyWE2DXDU0gUs/gOhm24= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-674-TD4gAJAmN7CY-c48Kxpteg-1; Wed, 19 Jul 2023 18:01:09 -0400 X-MC-Unique: TD4gAJAmN7CY-c48Kxpteg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AAE95185A78B for ; Wed, 19 Jul 2023 22:01:09 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.8.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id 856C040D283A; Wed, 19 Jul 2023 22:01:09 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [pushed] analyzer: fix ICE on division of tainted floating-point values [PR110700] Date: Wed, 19 Jul 2023 18:01:08 -0400 Message-Id: <20230719220108.255662-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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=-11.4 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,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 List-Id: Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r14-2658-gb86c0fe327a519. gcc/analyzer/ChangeLog: PR analyzer/110700 * region-model-manager.cc (region_model_manager::get_or_create_int_cst): Assert that we have an integral or pointer type. * sm-taint.cc (taint_state_machine::check_for_tainted_divisor): Don't check non-integral types. gcc/testsuite/ChangeLog: PR analyzer/110700 * gcc.dg/analyzer/taint-divisor-2.c: New test. --- gcc/analyzer/region-model-manager.cc | 1 + gcc/analyzer/sm-taint.cc | 6 ++++++ gcc/testsuite/gcc.dg/analyzer/taint-divisor-2.c | 13 +++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/analyzer/taint-divisor-2.c diff --git a/gcc/analyzer/region-model-manager.cc b/gcc/analyzer/region-model-manager.cc index 4f11ef4bd29..e43b99ae0ba 100644 --- a/gcc/analyzer/region-model-manager.cc +++ b/gcc/analyzer/region-model-manager.cc @@ -234,6 +234,7 @@ region_model_manager::get_or_create_int_cst (tree type, const poly_wide_int_ref &cst) { gcc_assert (type); + gcc_assert (INTEGRAL_TYPE_P (type) || POINTER_TYPE_P (type)); tree tree_cst = wide_int_to_tree (type, cst); return get_or_create_constant_svalue (tree_cst); } diff --git a/gcc/analyzer/sm-taint.cc b/gcc/analyzer/sm-taint.cc index 6d28d1f6f65..09c1e9368cd 100644 --- a/gcc/analyzer/sm-taint.cc +++ b/gcc/analyzer/sm-taint.cc @@ -1344,6 +1344,12 @@ taint_state_machine::check_for_tainted_divisor (sm_context *sm_ctxt, return; tree divisor_expr = gimple_assign_rhs2 (assign);; + + /* Until we track conditions on floating point values, we can't check to + see if they've been checked against zero. */ + if (!INTEGRAL_TYPE_P (TREE_TYPE (divisor_expr))) + return; + const svalue *divisor_sval = old_model->get_rvalue (divisor_expr, NULL); state_t state = sm_ctxt->get_state (assign, divisor_sval); diff --git a/gcc/testsuite/gcc.dg/analyzer/taint-divisor-2.c b/gcc/testsuite/gcc.dg/analyzer/taint-divisor-2.c new file mode 100644 index 00000000000..de9a1cb3a46 --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/taint-divisor-2.c @@ -0,0 +1,13 @@ +// TODO: remove need for this option: +/* { dg-additional-options "-fanalyzer-checker=taint" } */ + +#include "analyzer-decls.h" + +__attribute__ ((tainted_args)) +double pr110700 (double x, double y) +{ + /* Ideally we'd complain here with -Wanalyzer-tainted-divisor, but + until we track conditions on floating point values, we can't check to + see if they've been checked against zero. */ + return x / y; +} -- 2.26.3