From patchwork Tue Jan 5 00:22:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1422302 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; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org 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=UvqcQhMv; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [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 4D8tWT4dk0z9sVk for ; Tue, 5 Jan 2021 11:23:16 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5565B388C037; Tue, 5 Jan 2021 00:23:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5565B388C037 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1609806193; bh=OyBUrv+MZCgOJoCxTc2Biq+3MhaOja+95zQBqI1zBXc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=UvqcQhMvQGKFgB4nNu0R72sPOltbXDm/pvuwOFKiIemc5DlIchvBx78g4nQL4A52T EjsxaZZg49yK/Ryl+6ECoTVqjiPjxF2/S1OWuEAHhr04MESLeblSB0UIps4PlYh4tL Gh75i+8RVUnGZNEIlCQzOgjcGuwZ/zuTGhujwKAA= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 9FB003857C49 for ; Tue, 5 Jan 2021 00:23:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9FB003857C49 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-255-xXmZkH44MCmlYw45BOqLmg-1; Mon, 04 Jan 2021 19:23:06 -0500 X-MC-Unique: xXmZkH44MCmlYw45BOqLmg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8C3BB801817 for ; Tue, 5 Jan 2021 00:23:05 +0000 (UTC) Received: from t470.redhat.com (ovpn-112-159.phx2.redhat.com [10.3.112.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id A8E2E271B1; Tue, 5 Jan 2021 00:23:03 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [committed] analyzer: fix ICE with -fsanitize=undefined [PR98293] Date: Mon, 4 Jan 2021 19:22:58 -0500 Message-Id: <20210105002258.3038219-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.9 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_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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: David Malcolm via Gcc-patches From: David Malcolm Reply-To: David Malcolm Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" -fsanitize=undefined with calls to nonnull functions creates struct __ubsan_nonnull_arg_data instances with CONSTRUCTORs for RECORD_TYPEs with NULL index values. The analyzer was mistakenly using INTEGER_CST for these fields, leading to ICEs. Fix the issue by iterating through the fields in the type for such cases, imitating similar logic in varasm.c's output_constructor. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to master as r11-6452-g15af33a88065f983181550fc53821f1c6e14c5c7. gcc/analyzer/ChangeLog: PR analyzer/98293 * store.cc (binding_map::apply_ctor_to_region): When "index" is NULL, iterate through the fields for RECORD_TYPEs, rather than creating an INTEGER_CST index. gcc/testsuite/ChangeLog: PR analyzer/98293 * gcc.dg/analyzer/pr98293.c: New test. --- gcc/analyzer/store.cc | 19 ++++++++++++++++++- gcc/testsuite/gcc.dg/analyzer/pr98293.c | 2 ++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/analyzer/pr98293.c diff --git a/gcc/analyzer/store.cc b/gcc/analyzer/store.cc index 35a7e2985cd..b4a4d5f3bb2 100644 --- a/gcc/analyzer/store.cc +++ b/gcc/analyzer/store.cc @@ -524,10 +524,27 @@ binding_map::apply_ctor_to_region (const region *parent_reg, tree ctor, unsigned ix; tree index; tree val; + tree parent_type = parent_reg->get_type (); + tree field; + if (TREE_CODE (parent_type) == RECORD_TYPE) + field = TYPE_FIELDS (parent_type); + else + field = NULL_TREE; FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), ix, index, val) { if (!index) - index = build_int_cst (integer_type_node, ix); + { + /* If index is NULL, then iterate through the fields for + a RECORD_TYPE, or use an INTEGER_CST otherwise. + Compare with similar logic in output_constructor. */ + if (field) + { + index = field; + field = DECL_CHAIN (field); + } + else + index = build_int_cst (integer_type_node, ix); + } else if (TREE_CODE (index) == RANGE_EXPR) { tree min_index = TREE_OPERAND (index, 0); diff --git a/gcc/testsuite/gcc.dg/analyzer/pr98293.c b/gcc/testsuite/gcc.dg/analyzer/pr98293.c new file mode 100644 index 00000000000..f750c902440 --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/pr98293.c @@ -0,0 +1,2 @@ +/* { dg-additional-options "-fsanitize=undefined" } */ +#include "../pr93399.c"