From patchwork Sat Oct 14 12:26:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 152940 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2452646vqb; Sat, 14 Oct 2023 05:26:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEtoyM0bluoPwvlO4EUzT45d/+f/TeJQEoB/MsWUmzmet3ZHgpEOaQElRSUzCG2XtMDeZsk X-Received: by 2002:a05:620a:29c2:b0:775:9bda:b12d with SMTP id s2-20020a05620a29c200b007759bdab12dmr3873675qkp.32.1697286390856; Sat, 14 Oct 2023 05:26:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697286390; cv=pass; d=google.com; s=arc-20160816; b=prDX6lXWWGPPuA5KdXNNwQyGlDEv3IW0SbOXWf2cLJESxW9ZVxZ/y+9KRKstBC+1RK jF5qHq4G9lHW3TUdjB96a0Bwsa17Hrub07BKGFuk6SEBLuZ2uvKOU+sonkhir5WK8GEt C7srDQ3HVe1yAP6RkdailsfmOUK1SDU5XVvknjpCQRjM2AwuaQNydKWsP/kxUkb4H9tG Krq2w+aMuGsyI5z8v50FTtETyMIC2cuoMyXlmLDNAkl+NNvTnG0CEyKj/PinXiTqcpIZ KE/UdFzOHEOlcTeNDBGj8gxBIWrVJziHcrUDnLFkffXJZtU+5u8/X22nEjEykjN6WGdE MjvA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dmarc-filter:arc-filter:delivered-to; bh=B617/ZdxRn/RsUzQ69c81lES8LLjLnb149IHlok2fS4=; fh=D2tRalIjW6KCgVuqwFHStdMb9uqe8HSQc2WEvRJ6uLE=; b=CjxlCefIpCrDlsyOS8XGT1hDDk1pYpyZpYN43sE9D2Wy7JpI5wfhEOSysrSa+LO9iS 1GUk5CjoG/6Yk2aZgzQPNML9YdjES1IUzmXvaK5CieowSEWMR4Nr2wbp5dbOheYp6Ioa cTqYSUMLoYymyh9l6VXJM2F9dtksoz0mlusSPFqTMno+mHT2JEkditcC6Hn87uizi6hQ njCZfFJxPd0eo5CNpskz7OeDH+8C0JBNSUtUn8z2ThMI2P2pM4LZWU9TF/5QKPRl7tQw qMojkIImEiEx7zmGy/2UjuBeL99qCqhEMdbbGr7h5uHqmrUPYeL4qubkCyfOb+dG+ycu bKEQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gdcproject.org header.s=MBO0001 header.b=nFYmDlAw; arc=pass (i=1); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=gdcproject.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id o21-20020ac85a55000000b0041978cbdcc3si2590317qta.498.2023.10.14.05.26.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Oct 2023 05:26:30 -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=@gdcproject.org header.s=MBO0001 header.b=nFYmDlAw; arc=pass (i=1); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=gdcproject.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7F369385771B for ; Sat, 14 Oct 2023 12:26:30 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [IPv6:2001:67c:2050:0:465::101]) by sourceware.org (Postfix) with ESMTPS id 363713858C60 for ; Sat, 14 Oct 2023 12:26:07 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 363713858C60 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:67c:2050:0:465::101 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697286368; cv=none; b=sZUrr7KFEB3o3zMlG7UoAGxdNje5ZJkeFEwgHUTzwBxNhjVejNMJheQeKqku6f87AKmuPACOCroTMSuz6ZQoZqeuyzlOkRVT6KfqX+MQCnWTq6Ab3cn3C6Vysxs8khtYTe7Mwe4F9CjUVBKgQf9OntXbdAbfQbb3PPf68HEAgUM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697286368; c=relaxed/simple; bh=fbQNAe8NB974fbNV2jHWbnO1MeR4YOwfo6MEyk7ZWjE=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=NkPOk/NnQwAKkjInWIsGTdAMihx7iv6TYDWUsuFQwIqwcfUt6DsRvzUC4BLCZWw8Hrm5VQ46/zcAujDAfYRpKeKqdeUJ8uyTa6txlU/admRWr0GuAgURAil5r2PvntTp3ngU71KYGH51aVHfgXjxXHw4UO6rAA9pznF/Df/BSSA= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 363713858C60 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=gdcproject.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gdcproject.org Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1]) (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 mout-p-101.mailbox.org (Postfix) with ESMTPS id 4S72fN1FKZz9sWP; Sat, 14 Oct 2023 14:26:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gdcproject.org; s=MBO0001; t=1697286364; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=B617/ZdxRn/RsUzQ69c81lES8LLjLnb149IHlok2fS4=; b=nFYmDlAwnugcWpcWj+Cp6sJPc6dA9Iq5CCOy4fNlOx+KYxeqdfYj3FocPO3GK8RIWi5chG 75FwSCpLWYiGY39en1hCrpqtmt2mfkFISk3V1jkmlV5x7Km88goToOqYS3H6t6t52fl0yn 7d7RDtl+D/3jIivJC90F3udmkll0b2CSuOjsJPf1k9ZL6/5++Q4mufDjrTcv4ERM8XZM1L bmqJKEHjdgPRxxpJDGYuAff63fvUgHNwP1ieqd9ChJwOl+hG5F3NtbZl7/EesqCLKG6+oG yzt7VJw4ZZEt9jxz8A3k4daA6/OJ6zdTK9FfFmW4XptGKyTZGdfch4O0OjfqGg== From: Iain Buclaw To: gcc-patches@gcc.gnu.org Cc: Iain Buclaw Subject: [committed] Fix ICE in set_cell_span, at text-art/table.cc:148 with D front-end and -fanalyzer Date: Sat, 14 Oct 2023 14:26:01 +0200 Message-Id: <20231014122601.1667638-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP, WEIRD_PORT 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779733774527142310 X-GMAIL-MSGID: 1779733774527142310 Hi, The internal error in analyzer turned out to be caused by a subtly invalid tree representation of STRING_CSTs in the D front-end, fixed by including the terminating NULL as part of the TREE_STRING_POINTER. When adding a first analyzer test for D, it flagged up another subtle mismatch in one assignment in the module support routines as well, fixed by generating the correct field type for the compiler-generated struct. Bootstrapped and regression tested on x86_64-linux-gnu/-m32, and committed to mainline. Regards, Iain. --- PR d/111537 gcc/d/ChangeLog: * expr.cc (ExprVisitor::visit (StringExp *)): Include null terminator in STRING_CST string. * modules.cc (get_compiler_dso_type): Generate ModuleInfo** type for the minfo fields. gcc/testsuite/ChangeLog: * gdc.dg/analyzer/analyzer.exp: New test. * gdc.dg/analyzer/pr111537.d: New test. --- gcc/d/expr.cc | 6 +-- gcc/d/modules.cc | 9 ++-- gcc/testsuite/gdc.dg/analyzer/analyzer.exp | 51 ++++++++++++++++++++++ gcc/testsuite/gdc.dg/analyzer/pr111537.d | 7 +++ 4 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gdc.dg/analyzer/analyzer.exp create mode 100644 gcc/testsuite/gdc.dg/analyzer/pr111537.d diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc index 7038655bc94..551d004c241 100644 --- a/gcc/d/expr.cc +++ b/gcc/d/expr.cc @@ -2535,13 +2535,13 @@ public: { /* Copy the string contents to a null terminated string. */ dinteger_t length = (e->len * e->sz); - char *string = XALLOCAVEC (char, length + 1); + char *string = XALLOCAVEC (char, length + e->sz); + memset (string, 0, length + e->sz); if (length > 0) memcpy (string, e->string, length); - string[length] = '\0'; /* String value and type includes the null terminator. */ - tree value = build_string (length, string); + tree value = build_string (length + e->sz, string); TREE_TYPE (value) = make_array_type (tb->nextOf (), length + 1); value = build_address (value); diff --git a/gcc/d/modules.cc b/gcc/d/modules.cc index f2180d30546..8d6c8f0f9ad 100644 --- a/gcc/d/modules.cc +++ b/gcc/d/modules.cc @@ -277,12 +277,13 @@ get_compiler_dso_type (void) DECL_CHAIN (field) = fields; fields = field; - field = create_field_decl (build_pointer_type (get_moduleinfo_type ()), - NULL, 1, 1); + tree moduleinfo_ptr_ptr_type = + build_pointer_type (build_pointer_type (get_moduleinfo_type ())); + + field = create_field_decl (moduleinfo_ptr_ptr_type, NULL, 1, 1); DECL_CHAIN (field) = fields; fields = field; - field = create_field_decl (build_pointer_type (get_moduleinfo_type ()), - NULL, 1, 1); + field = create_field_decl (moduleinfo_ptr_ptr_type, NULL, 1, 1); DECL_CHAIN (field) = fields; fields = field; diff --git a/gcc/testsuite/gdc.dg/analyzer/analyzer.exp b/gcc/testsuite/gdc.dg/analyzer/analyzer.exp new file mode 100644 index 00000000000..7b82b8e0cd1 --- /dev/null +++ b/gcc/testsuite/gdc.dg/analyzer/analyzer.exp @@ -0,0 +1,51 @@ +# Copyright (C) 2023 Free Software Foundation, Inc. + +# This file is part of GCC. +# +# GCC is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation; either version 3, or (at your option) any later +# version. +# +# GCC is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# . + +# GCC testsuite that uses the `dg.exp' driver. + +# Load support procs. +load_lib gdc-dg.exp + +# If the analyzer has not been enabled, bail. +if { ![check_effective_target_analyzer] } { + return +} + +global DEFAULT_DFLAGS +if [info exists DEFAULT_DFLAGS] then { + set save_default_dflags $DEFAULT_DFLAGS +} + +# If a testcase doesn't have special options, use these. +set DEFAULT_DFLAGS "-fanalyzer -Wanalyzer-too-complex -fanalyzer-call-summaries" + +# Initialize `dg'. +dg-init + +# Main loop. +gdc-dg-runtest [lsort \ + [glob -nocomplain $srcdir/$subdir/*.d ] ] "" $DEFAULT_DFLAGS + +# All done. +dg-finish + +if [info exists save_default_dflags] { + set DEFAULT_DFLAGS $save_default_dflags +} else { + unset DEFAULT_DFLAGS +} diff --git a/gcc/testsuite/gdc.dg/analyzer/pr111537.d b/gcc/testsuite/gdc.dg/analyzer/pr111537.d new file mode 100644 index 00000000000..e50b05a3f79 --- /dev/null +++ b/gcc/testsuite/gdc.dg/analyzer/pr111537.d @@ -0,0 +1,7 @@ +// { dg-do compile } +import core.stdc.string; +void main() +{ + char[5] arr; + strcpy(arr.ptr, "hello world"); // { dg-warning "stack-based buffer overflow" } +}