Message ID | 20231023234924.2971461-1-ppalka@redhat.com |
---|---|
State | Accepted |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1618698vqx; Mon, 23 Oct 2023 16:50:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEXTaVECm2wSSWxwBTcRyogzYy7hISiVhHqLxarfW8w8+pv7MsVuqigp6cvwlwuf5NVCZoB X-Received: by 2002:a05:622a:1a15:b0:41e:28d1:c8ff with SMTP id f21-20020a05622a1a1500b0041e28d1c8ffmr631282qtb.51.1698105017187; Mon, 23 Oct 2023 16:50:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698105017; cv=pass; d=google.com; s=arc-20160816; b=T6xBKIUSyNvF0SMLAqqpHXxBbLGy0k3YHFdi0okpvlQVJebmKkhvL/NeVvd47vSFTQ dNvQPwLXHKlQ7tjW+fOpGWbiA716aPbcQ0599WmtaAC5gFyfaURApVTAtyfop0NSUQOk DdMQ+eWwtNafeyhHkoTshcc1uz8Q7bc1G3aAzTvAu9ywfKCgdp+dLXFHWh9puvCFCpgG NSMTetlH0xf0c5qCSSTEykDzTOL5GWIqJAztvia9q5bbCPLRTAnyu7sFk+vZBDBWHH1n lag7fp1kTzDoCP5/5erK3sx2Cp0oW2PL67z8oZeamDSJ3F9rb9ZSSUWsWkMq9SOazwad mQAQ== 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 :arc-filter:dmarc-filter:delivered-to; bh=KzzB/epD+oXTXGAhzgr4h1ZoX7N6GW+/3vcOErLscbY=; fh=1Hi9m88IqcWZGtfSxUrMGG+GBgL26N02X1SANXM6iTs=; b=ptSTmIlyA7yOjwvDbTqvJCQKPRn08cvtXSaSrRUT+OlX4oYcj20FDkBj8Aw5BR6dbP BpuKF96n+aNgBG4U4OhKbXT8t0PGXeuPieZ8rggU7hYJJj3HIwDDkcMvQxek06TqoPY/ Xv/ajINJvLgyNLKxOqKZNtBxjfSLsfBLYL0Mn40gXRfqyZ0C58K8C5G5AJwwlfb06BK4 4S8l8L3zmUHZ1cWYrc4GK/E1S7PD2NS2SnwojfExoxN6mY+UgRB/qH6/3QprbVTwcuGz +OfUZg/uJyF85nK0XHC2X/S8rmd+echgrDLEeIe6xFdjHvWs/68VKRa8EQ767OY8PDMV 6fNQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=K0w5N7Jg; 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 g16-20020ac85810000000b0041964cad786si6196648qtg.141.2023.10.23.16.50.17 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 16:50:17 -0700 (PDT) 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=K0w5N7Jg; 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 EF2233858412 for <ouuuleilei@gmail.com>; Mon, 23 Oct 2023 23:50:16 +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 1B0903858C2C for <gcc-patches@gcc.gnu.org>; Mon, 23 Oct 2023 23:49:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1B0903858C2C 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 1B0903858C2C 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=1698104994; cv=none; b=Jway3+OewTn7Qmu6PceZB4N4hxCsKnzXYcK0xb8iDGvVUF2FvC/8C0sYLJfzPmCbmr/Hc/C07ZA0Kq6G1srxKMXe/oX7ZJGnTZHj7z9cJjpeL/4Df5vUdtN/Fcqwyd5Q7yfzgqJww1DcQJdWqSCCFe0OInOhUpXl4dOhalD3Ohk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698104994; c=relaxed/simple; bh=dSa9u+5+uEAL77U+STfDIxMbgyOqtR5FdutGZ42nTsk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=eW1c5ejZfbOjbicOp+1XE4ZryARAFnH84kyh2MvvIk5hyPKgPGkYojP3jjbxILISMwjleZC25YtmLJBESqedmmKWTXJhS+aRRV1HNkdydEoyAZ8yW1CLnYl6zS1HYl4BbcfzdXaqFS8Jdl+WP7sqHLdZrU78QloZ9AKWFPWTSN0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698104992; 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=KzzB/epD+oXTXGAhzgr4h1ZoX7N6GW+/3vcOErLscbY=; b=K0w5N7Jg0O9/thCAyFT9rnBWKTpm8no7ho1LoRrDN/qvZo2xkBAffH0/Yn7Th4Ha7ORI4g 9dPtiAdgLVIELZqGX9neEUl/gtO4Daym4yWtCvNGmQ6QVLVnedJ+A5PgguAPhDVCDy9dHd 5iaxAsYa+uf2SsSmzzwHDa2x70M1ze4= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-352-3SAL9P2xM_e93YqJIPxAnw-1; Mon, 23 Oct 2023 19:49:29 -0400 X-MC-Unique: 3SAL9P2xM_e93YqJIPxAnw-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-66d040c58eeso56601166d6.3 for <gcc-patches@gcc.gnu.org>; Mon, 23 Oct 2023 16:49:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698104968; x=1698709768; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=KzzB/epD+oXTXGAhzgr4h1ZoX7N6GW+/3vcOErLscbY=; b=i34Advc1/nHDwIpAL6twyHxmREM18Cox+J4KaTZurG2rfkzqreY76lUzFaarKQYn79 3ktoCucMOZr1WO3kkr3dGgwr92+MA/YjuunPtJZoMRu6Y8mblE/lrXNiEBb26J9C0rp3 MGEm8C8InTnLuAyGoToNxw3D7MEeYHTSx6zvgGdc1evnUkppa/g0MZwFw1NginvL1erk oz36PKI/aY2qbmGXvcXQPKgS6ULsKC3zKRMNwh/u3lftp0hnHsfvTCPi/tzH3b7DxqbS Whn565zvbkInotsSaSi7xPEZpQRFc8BdYPQnbaagwLgksJwtuI1g1yAZ0n8JPl9bQHky bLag== X-Gm-Message-State: AOJu0Yy4Q22DNayPg+YAqCKzP3HRkxUO/GjKF1bxqxx+Um6EfNtkLedS UomHYjv/YCBib+hEbgFaAt/E14xGKoP11GvuCyc2SxUx2wYlqMy8c5oIhbcU/D30vk732hAIDi1 i8cXS0XP/ojfdccO3ks8uEEVJFnOpa4rwIe3VeciKkGiFgFu7aJgvPhg3lSu5dHo9My2UwYhBlK I= X-Received: by 2002:ad4:4eed:0:b0:66d:2e59:4fca with SMTP id dv13-20020ad44eed000000b0066d2e594fcamr14821857qvb.35.1698104968069; Mon, 23 Oct 2023 16:49:28 -0700 (PDT) X-Received: by 2002:ad4:4eed:0:b0:66d:2e59:4fca with SMTP id dv13-20020ad44eed000000b0066d2e594fcamr14821847qvb.35.1698104967785; Mon, 23 Oct 2023 16:49:27 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id px9-20020a056214050900b0066db33eeeb7sm1308381qvb.131.2023.10.23.16.49.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 16:49:27 -0700 (PDT) From: Patrick Palka <ppalka@redhat.com> To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka <ppalka@redhat.com> Subject: [PATCH] c++: cp_stabilize_reference and non-dep exprs [PR111919] Date: Mon, 23 Oct 2023 19:49:24 -0400 Message-ID: <20231023234924.2971461-1-ppalka@redhat.com> X-Mailer: git-send-email 2.42.0.424.gceadf0f3cf MIME-Version: 1.0 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=-13.6 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_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780592166261256031 X-GMAIL-MSGID: 1780592166261256031 |
Series |
c++: cp_stabilize_reference and non-dep exprs [PR111919]
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | success | Github commit url |
Commit Message
Patrick Palka
Oct. 23, 2023, 11:49 p.m. UTC
Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? -- >8 -- After the removal of NON_DEPENDENT_EXPR, cp_stabilize_reference which used to just exit early for NON_DEPENDENT_EXPR is now more prone to passing a weird templated tree to middle-end routines, which leads to a crash from contains_placeholder_p in the testcase below. It seems the best fix is to just disable cp_stabilize_reference when in a template context like we already do for cp_save_expr; it seems SAVE_EXPR should never appear in a templated tree (since e.g. tsubst doesn't handle it). PR c++/111919 gcc/cp/ChangeLog: * tree.cc (cp_stabilize_reference): Do nothing when processing_template_decl. gcc/testsuite/ChangeLog: * g++.dg/template/non-dependent27.C: New test. --- gcc/cp/tree.cc | 4 ++++ gcc/testsuite/g++.dg/template/non-dependent27.C | 8 ++++++++ 2 files changed, 12 insertions(+) create mode 100644 gcc/testsuite/g++.dg/template/non-dependent27.C
Comments
On 10/23/23 19:49, Patrick Palka wrote: > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK > for trunk? > > -- >8 -- > > After the removal of NON_DEPENDENT_EXPR, cp_stabilize_reference which > used to just exit early for NON_DEPENDENT_EXPR is now more prone to > passing a weird templated tree to middle-end routines, which leads to a > crash from contains_placeholder_p in the testcase below. It seems the > best fix is to just disable cp_stabilize_reference when in a template > context like we already do for cp_save_expr; it seems SAVE_EXPR should > never appear in a templated tree (since e.g. tsubst doesn't handle it). Hmm. We don't want the result of cp_stabilize_reference (or cp_save_expr) to end up in the resulting trees in template context. Having a SAVE_EXPR in the result would actually be helpful for catching such a bug. That said, the patch is OK. > PR c++/111919 > > gcc/cp/ChangeLog: > > * tree.cc (cp_stabilize_reference): Do nothing when > processing_template_decl. > > gcc/testsuite/ChangeLog: > > * g++.dg/template/non-dependent27.C: New test. > --- > gcc/cp/tree.cc | 4 ++++ > gcc/testsuite/g++.dg/template/non-dependent27.C | 8 ++++++++ > 2 files changed, 12 insertions(+) > create mode 100644 gcc/testsuite/g++.dg/template/non-dependent27.C > > diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc > index a3d61d3e7c9..417c92ba76f 100644 > --- a/gcc/cp/tree.cc > +++ b/gcc/cp/tree.cc > @@ -408,6 +408,10 @@ bitfield_p (const_tree ref) > tree > cp_stabilize_reference (tree ref) > { > + if (processing_template_decl) > + /* As in cp_save_expr. */ > + return ref; > + > STRIP_ANY_LOCATION_WRAPPER (ref); > switch (TREE_CODE (ref)) > { > diff --git a/gcc/testsuite/g++.dg/template/non-dependent27.C b/gcc/testsuite/g++.dg/template/non-dependent27.C > new file mode 100644 > index 00000000000..cf7af6e6425 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/template/non-dependent27.C > @@ -0,0 +1,8 @@ > +// PR c++/111919 > + > +int i[3]; > + > +template<class T> > +void f() { > + i[42 / (int) sizeof (T)] |= 0; > +}
diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc index a3d61d3e7c9..417c92ba76f 100644 --- a/gcc/cp/tree.cc +++ b/gcc/cp/tree.cc @@ -408,6 +408,10 @@ bitfield_p (const_tree ref) tree cp_stabilize_reference (tree ref) { + if (processing_template_decl) + /* As in cp_save_expr. */ + return ref; + STRIP_ANY_LOCATION_WRAPPER (ref); switch (TREE_CODE (ref)) { diff --git a/gcc/testsuite/g++.dg/template/non-dependent27.C b/gcc/testsuite/g++.dg/template/non-dependent27.C new file mode 100644 index 00000000000..cf7af6e6425 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/non-dependent27.C @@ -0,0 +1,8 @@ +// PR c++/111919 + +int i[3]; + +template<class T> +void f() { + i[42 / (int) sizeof (T)] |= 0; +}