From patchwork Wed Dec 13 09:49:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 177841 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp7658753dys; Wed, 13 Dec 2023 01:49:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IHRxRu/SLCOGMr7e/46Q5iONwnbXye1piRot1AlZHfbUjiZpXoGi6OEet7ZLKC4SDOierCj X-Received: by 2002:a05:620a:2109:b0:77d:9f5e:91b5 with SMTP id l9-20020a05620a210900b0077d9f5e91b5mr7583819qkl.52.1702460973670; Wed, 13 Dec 2023 01:49:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702460973; cv=pass; d=google.com; s=arc-20160816; b=qOt+RU6+2tgBKInFzMi7qmsl5VBAZdApmUGjFfC9zlGq3Kr9cGtXq+pG3HOhqUYhha yMY1WafFEO6XbkPYd3VciXWbLtDJ4qnUcKl/WxuPUAyCGVsdiN3ExsfnJSdSuWVr7zeF HHnFFoptbNX0LRC/bfEUNsQVPaqADVKBV5OAdhJvHLuklS9aE+dl4x+FkcNeWzRNIkU2 /LsvppiXFcmKo86+3gdtpTI8zbvdkMYy9oW0YnDbp2I9K2GhQt9H4CMQ6zYCVkYtJpcB UN4RmPLu+DXF4NXPZc+Tmrg6AzPH1Tub9q5zBgi0PXFqyiVYd3vgzfIm1tvGsKy52YgB 5ljQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=egS3XFIqGB02oy8lxB4p+ksPaArbUZ5RVo2+bA6XvR4=; fh=0xZT+NBKSeH8qOu04/61f1ZGePpF4jF/gxp331YE14k=; b=mefLoV5ms1f3+q7CUDYMtk2J0VNWmxeFPUuMMt+93V1Wpe/yHSuJ0GPrncI4rbeAjv IWJp8oo1J+U0mC8UEPCEavcdPvmQN6BizSNtNkK/bEmSSXG83yHss1wIzdsHk21/wSGz ZM5+/49Oio+42iZ2IfOo9958qfKAzgvoMuImOQfkvRIkVRkHLhtuFQDMILrLFZSFM5EI KAHKdWn7aNvdo50M4OTYXSjjBdytnFh9MV69F/R18+mRwCQTqQmgEBwMCf9BAd+Ppx2G NpYQw00dQ0uvnRJftAuw8mMr5BYFCk16tIpUJJjTUh1OJqvMFIb+pyZ6J4hbjzz+BEY5 d/AA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=K5V8Kc1B; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id h17-20020a05620a245100b0077d98648b4csi11080718qkn.155.2023.12.13.01.49.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 01:49:33 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=K5V8Kc1B; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6669B385AE65 for ; Wed, 13 Dec 2023 09:49:33 +0000 (GMT) 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 BF696385841A for ; Wed, 13 Dec 2023 09:49:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BF696385841A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BF696385841A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702460951; cv=none; b=oA1Md7DM7U6JhX1rRfoO6yMxVeSRLmPQjQeyXqAnaxwiPTyfTRBs8yMiVBSpESxfTsH8zOv7Bwy5j1EWqcEC7Pi7LQGMcvxRdwDewYaSNB97FOjM/YVdForr4zz8mmHEgx5JVttO/rIWMD6Is++zWMQaWkOT8KF9Y56+wxmIW8o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702460951; c=relaxed/simple; bh=t32FBqJBMDoZCgfkWSHIGS1IXn3/z6tElQ7n402EJDA=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=CisZLZrfBSetIyH5wQErOCSnSs1FOevuxz9OVetUIJg6dS0XatQn1aiV4RSltRKtj4jrOc/H1tunGmYBNwzEvsjq83HB3JnadkFxebXk/+r2Gq9rz4zM37eti8VChrNcGB8NyJncYsXxdDcK1+dYcaOhoaZaW/hSLBtdSMbj504= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702460949; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=egS3XFIqGB02oy8lxB4p+ksPaArbUZ5RVo2+bA6XvR4=; b=K5V8Kc1BSNXnUFENpLD+87CuO6uHvKJDJU6hVWvrNU6iBWiLRBmjogL6W0YzvE88B+SmfV 2pIavVoRElm4s3nIzgGu5fh3gG5O/v74LFe1Kj9d2LW7cSGGZPwRiCo42/MY4otPO+PDUB iZnRplGmZTXPrSJhymExvip3bGTcFx8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-404-eFqN5uFPMYWXPBfxxQrxQw-1; Wed, 13 Dec 2023 04:49:06 -0500 X-MC-Unique: eFqN5uFPMYWXPBfxxQrxQw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C08DA101AA4D for ; Wed, 13 Dec 2023 09:49:05 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 458461C060AF; Wed, 13 Dec 2023 09:49:05 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 3BD9n2Hj2489814 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 13 Dec 2023 10:49:03 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3BD9n2Oq2489813; Wed, 13 Dec 2023 10:49:02 +0100 Date: Wed, 13 Dec 2023 10:49:02 +0100 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Fix tinst_level::to_list [PR112968] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, 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 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: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785159717846288436 X-GMAIL-MSGID: 1785159717846288436 Hi! With valgrind checking, there are various errors reported on some C++26 libstdc++ tests, like: ==2009913== Conditional jump or move depends on uninitialised value(s) ==2009913== at 0x914C59: gt_ggc_mx_lang_tree_node(void*) (gt-cp-tree.h:107) ==2009913== by 0x8AB7A5: gt_ggc_mx_tinst_level(void*) (gt-cp-pt.h:32) ==2009913== by 0xB89B25: ggc_mark_root_tab(ggc_root_tab const*) (ggc-common.cc:75) ==2009913== by 0xB89DF4: ggc_mark_roots() (ggc-common.cc:104) ==2009913== by 0x9D6311: ggc_collect(ggc_collect) (ggc-page.cc:2227) ==2009913== by 0xDB70F6: execute_one_pass(opt_pass*) (passes.cc:2738) ==2009913== by 0xDB721F: execute_pass_list_1(opt_pass*) (passes.cc:2755) ==2009913== by 0xDB7258: execute_pass_list(function*, opt_pass*) (passes.cc:2766) ==2009913== by 0xA55525: cgraph_node::analyze() (cgraphunit.cc:695) ==2009913== by 0xA57CC7: analyze_functions(bool) (cgraphunit.cc:1248) ==2009913== by 0xA5890D: symbol_table::finalize_compilation_unit() (cgraphunit.cc:2555) ==2009913== by 0xEB02A1: compile_file() (toplev.cc:473) I think the problem is in the tinst_level::to_list optimization from 2018. That function returns a TREE_LIST with TREE_PURPOSE/TREE_VALUE filled in. Either it freshly allocates using build_tree_list (NULL, NULL); + stores TREE_PURPOSE/TREE_VALUE, that case is fine (the whole tree_list object is zeros, except for TREE_CODE set to TREE_LIST and TREE_PURPOSE/TREE_VALUE modified later; the above also means in particular TREE_TYPE of it is NULL and TREE_CHAIN is NULL and both are accessible/initialized even in valgrind annotations. Or it grabs a TREE_LIST node from a freelist. If defined(ENABLE_GC_CHECKING), the object is still all zeros except for TREE_CODE/TREE_PURPOSE/TREE_VALUE like in the fresh allocation case (but unlike the build_tree_list case in the valgrind annotations TREE_TYPE and TREE_CHAIN are marked as uninitialized). If !defined(ENABLE_GC_CHECKING), I believe the actual memory content is that everything but TREE_CODE/TREE_PURPOSE/TREE_VALUE/TREE_CHAIN is zeros and TREE_CHAIN is something random (whatever next entry is in the freelist, nothing overwrote it) and from valgrind POV again, TREE_TYPE and TREE_CHAIN are marked as uninitialized. When using the other freelist instantiations (pending_template and tinst_level) I believe everything is correct, from valgrind POV it marks the whole pending_template or tinst_level as uninitialized, but the caller initializes it all). One way to fix this would be let tinst_level::to_list not store just TREE_PURPOSE (ret) = tldcl; TREE_VALUE (ret) = targs; but also TREE_TYPE (ret) = NULL_TREE; TREE_CHAIN (ret) = NULL_TREE; Though, that seems like wasted effort in the build_tree_list case to me. So, the following patch instead does that TREE_CHAIN = NULL_TREE store only in the case where it isn't already done and marks both TREE_CHAIN and TREE_TYPE as initialized (the latter is at that spot, the former is because we never really touch TREE_TYPE of a TREE_LIST anywhere and so the NULL gets stored into the freelist and restored from there (except for ENABLE_GC_CHECKING where it is poisoned and then cleared again). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-12-13 Jakub Jelinek PR c++/112968 * pt.cc (freelist::reinit): Make whole obj->common defined for valgrind annotations rather than just obj->base, and do it even for ENABLE_GC_CHECKING. If not ENABLE_GC_CHECKING, clear TREE_CHAIN (obj). Jakub --- gcc/cp/pt.cc.jj 2023-12-11 23:52:03.592513063 +0100 +++ gcc/cp/pt.cc 2023-12-12 16:40:09.259903877 +0100 @@ -9525,7 +9525,7 @@ template <> inline void freelist::reinit (tree obj ATTRIBUTE_UNUSED) { - tree_base *b ATTRIBUTE_UNUSED = &obj->base; + tree_common *c ATTRIBUTE_UNUSED = &obj->common; #ifdef ENABLE_GC_CHECKING gcc_checking_assert (TREE_CODE (obj) == TREE_LIST); @@ -9540,8 +9540,9 @@ freelist::reinit (tree obj AT #ifdef ENABLE_GC_CHECKING TREE_SET_CODE (obj, TREE_LIST); #else - VALGRIND_DISCARD (VALGRIND_MAKE_MEM_DEFINED (b, sizeof (*b))); + TREE_CHAIN (obj) = NULL_TREE; #endif + VALGRIND_DISCARD (VALGRIND_MAKE_MEM_DEFINED (c, sizeof (*c))); } /* Point to the first object in the TREE_LIST freelist. */