Message ID | CAPfxnSk8vgLAXGVJb_TZq+yJL1EEZ2B9x6yFnDDkruu5tTUUZA@mail.gmail.com |
---|---|
State | Corrupt patch |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:37c1:b0:101:2151:f287 with SMTP id y1csp1511053dyq; Tue, 9 Jan 2024 00:21:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IGG962Ek5viCxOOVfo5Jw6HOY9G+P/b02X4UhMeqPe4w/YXE05hpIgxpVtW1NmqRBny3fmj X-Received: by 2002:a81:524a:0:b0:5e8:8053:70d1 with SMTP id g71-20020a81524a000000b005e8805370d1mr3481908ywb.50.1704788479762; Tue, 09 Jan 2024 00:21:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704788479; cv=pass; d=google.com; s=arc-20160816; b=FRJotuR1ezti8dMVIiAl4y82aQK+/bghYBdC9nCJczi9fu4/VxOlziLl0ZwEFC7spr JLOF7Yz3n9CAcLLHUnSE2FJAPHHgSln0RclRYQDkvc01OXDR0Udcnz/gMArGdyJdheaw dwiFW5JkB17olxIT+RfKUij0e6CJTgktWQNGTb/vt9a0TR3wnORPTb577MTbX958e3aq RprspieMxWe08HNzIRW+25i+gWUhUQl1VgkpqXwZMvGCT9Va6Cuj8w9/eApd17XTrASF VOEnar9n2nzSlkG+ya18IxxcyblrOzBn6G83uPElWqH4LS1KhbwekipTcBGMVz/WFq6q iyFA== 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:to:subject:message-id:date:from :mime-version:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=pOjnonF1yx6xXwsLGgBqHSnou3/fcByYv7kMlowipds=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=QxdxbDFEp5jAG1gHfSsYnV5p8oBi5sN+H/Zbu6ARdHtlRtyneoxcZWqT+HjZwD6cSQ xobi5S62YiS7JvoRcwJwIOlpojU/cns+4bAR9ap4xvRJ6sftCn4IwDyWND4zDOyywF53 d6SuOM1KMiEyQIZRUfgjGF4s8xNfkCPm5LL2AvDGp7ch0UvAHaMvzRFEAuXmq6UXAkCq IAlo1T1kYhFfVNjsluZcr4UiFPTH76jkNycrA2iZG4BBtR62CvaJk1VR+i8i8aNVNHWX uon5Xn5qkg6vioRS1P24Bh9QwSiODAvQ64CVAUkgv4FoFcDBcNZIPg6T3L3YeHm+3fS0 9l2Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=AQ0XxQZj; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id q16-20020a05622a04d000b004280de35ab5si1561887qtx.729.2024.01.09.00.21.19 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 00:21:19 -0800 (PST) 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=@gmail.com header.s=20230601 header.b=AQ0XxQZj; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6A9013858288 for <ouuuleilei@gmail.com>; Tue, 9 Jan 2024 08:21:19 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by sourceware.org (Postfix) with ESMTPS id DA2DE3858C66 for <gcc-patches@gcc.gnu.org>; Tue, 9 Jan 2024 08:20:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DA2DE3858C66 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DA2DE3858C66 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::134 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704788417; cv=none; b=OBSwLZP0Nr59jQHymMeG0WEt7hTnj4k+Tv6OJdYsbhIcw6imnlxxmq/+WN369xOcujGuzO9uHL/9cxnjuchGSCl1TVBSJTaAn6rMFuvtndvd6wIPVRaVCLlOYog8LYpPV0ezzuMOMHuVAn96tnIRNAwFhQbN0CFlfO9+/KHsQP8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704788417; c=relaxed/simple; bh=zT/PP31yPLQYFRfjZQnyqGpqWphy2oiYjKD2mrkg73k=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=Cfm/+Bg62eNJ2GZMR2zYIT1MTum6nIzNCAvUNBwrmLsMdO8n2iLZP35BjF6NbLrPL4FMEM1qmrdVep7qqq7GR4phSh349FLaLAOiP3L4dT1XLV9sZy3vYvKW5QXAIz9B/3dPwo5TtRpt3InxW2BE5e5HWK+UTCAl4Ol0y+f+Jms= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-50e7e55c0f6so2684667e87.0 for <gcc-patches@gcc.gnu.org>; Tue, 09 Jan 2024 00:20:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704788412; x=1705393212; darn=gcc.gnu.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=pOjnonF1yx6xXwsLGgBqHSnou3/fcByYv7kMlowipds=; b=AQ0XxQZjP/4X9SnhH9YWLFkxTQhWO0qMq1wGvcfpioh1f1RM869EArDspXWDxn8kPH xb68/vvfK1ajoOwbzWObmtqCfxZ11asA52CfEf/nMmx09bauxYW/WwJ7PvfaQLGparXZ +hXHaiT0F6yj6kdDNnUTNGYT6KnUGPrF9dfzui2SI8ObUhk/dhYfE0nWSShDbZJ4peiA TuMois8gQeKFoeq2++cdp+7isVqOChXwan90FCK0nMvqt0tB36gGAnN8HlHtLE6clq91 eBMadlnOCxerkJepQ3PpXajQYes+NnBAjm+UVopy78VqQ+pYUaBF2OJ9O33mnoB+j3bH k1hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704788412; x=1705393212; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=pOjnonF1yx6xXwsLGgBqHSnou3/fcByYv7kMlowipds=; b=Odtyhjv26XBCuAxYj8N9YfcghZBcpUdh5EdsGmWugUEHqhZFONJqOKysDnGrYDmti5 UZVCWkdleeYpfgFzL7joNrXXYXH3iCWHW+TnQ+6gWo5J2VGW//4JIOp7e4MRzdMwcaU2 YnCrja1Uv24FCqV/pxNutIzSj6pCoCuhxiQwBbwa4n0pw+YGSSca6qnNCaq7MF7NutCm KIfsvya4ZCafqESnG06MxPiSqSfxNjUmmD9NrQwlUi2yNSglz8T72qimVCH19rT4N0Lv GMWj0euJxkiTyxDdoJQ3ogKddaTgCe3nfzwxOL/3A+g1HhiyS8Pd0i3ni8J0mUJbWk6Z B44Q== X-Gm-Message-State: AOJu0YzT0h6Drv/UT11OQF/WGgslKl24ho+rbwcyehpDcdFaUqjh5uNP U3oTjXr6jYqfOyIC+M7kRYOjsxj7QPco6Iu5WWP9EUlLWccVRw== X-Received: by 2002:ac2:46ca:0:b0:50e:b1b4:8e25 with SMTP id p10-20020ac246ca000000b0050eb1b48e25mr896191lfo.211.1704788411875; Tue, 09 Jan 2024 00:20:11 -0800 (PST) MIME-Version: 1.0 From: Dmitry Drozodv <da.drozdov85@gmail.com> Date: Tue, 9 Jan 2024 11:20:02 +0300 Message-ID: <CAPfxnSk8vgLAXGVJb_TZq+yJL1EEZ2B9x6yFnDDkruu5tTUUZA@mail.gmail.com> Subject: [PATCH] c++: side effect in nullptr_t conversion fix To: gcc-patches@gcc.gnu.org Content-Type: multipart/alternative; boundary="000000000000b507ab060e7efbec" X-Spam-Status: No, score=0.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, SPAM_FROM, SPF_HELO_NONE, SPF_PASS, 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 <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: 1787600285151312219 X-GMAIL-MSGID: 1787600285151312219 |
Series |
c++: side effect in nullptr_t conversion fix
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | warning | Git am fail log |
Commit Message
Dmitry Drozodv
Jan. 9, 2024, 8:20 a.m. UTC
According C++ standard [conv.lval]p3.1: If T is cv std::nullptr_t, the result is a null pointer constant. [Note: Since the conversion does not access the object to which the glvalue refers, there is no side effect even if T is volatile-qualified, and the glvalue can refer to an inactive member of a union. — end note] The following example demonstrates reading from a volatile std::nullptr_t variable: ```c++ int* foo() { volatile auto a = nullptr; int* b = a; return b; } ``` `g++ -O3 foo.cc` produces: ```asm mov QWORD PTR [rsp-8], 0 # volatile auto a = nullptr; mov rax, QWORD PTR [rsp-8 ] # int* b = a; xor eax, eax ret ``` Here reading from `a` does produce the side effect, which is contrary to the standard. --- else if (TYPE_PTRMEM_P (type) && INTEGRAL_CODE_P (form)) {
Comments
On Tue, Jan 09, 2024 at 11:20:02AM +0300, Dmitry Drozodv wrote: > diff --git a/gcc/cp/cvt.cc b/gcc/cp/cvt.cc > index cbed847b343..14462356a0e 100644 > --- a/gcc/cp/cvt.cc > +++ b/gcc/cp/cvt.cc > @@ -218,8 +218,9 @@ cp_convert_to_pointer (tree type, tree expr, bool > dofold, > ? build_int_cst_type (type, -1) > : build_int_cst (type, 0)); > > - return (TREE_SIDE_EFFECTS (expr) > - ? build2 (COMPOUND_EXPR, type, expr, val) : val); > + /* C++ [conv.lval]p3.1: > + If T is cv std::nullptr_t, the result is a null pointer constant. > */ > + return val; > } > else if (TYPE_PTRMEM_P (type) && INTEGRAL_CODE_P (form)) This looks incorrect. You can't throw all side-effects away. Consider expr being say a function call which returns std::nullptr_t, the function still has to be called, not ignored. Jakub
diff --git a/gcc/cp/cvt.cc b/gcc/cp/cvt.cc index cbed847b343..14462356a0e 100644 --- a/gcc/cp/cvt.cc +++ b/gcc/cp/cvt.cc @@ -218,8 +218,9 @@ cp_convert_to_pointer (tree type, tree expr, bool dofold, ? build_int_cst_type (type, -1) : build_int_cst (type, 0)); - return (TREE_SIDE_EFFECTS (expr) - ? build2 (COMPOUND_EXPR, type, expr, val) : val); + /* C++ [conv.lval]p3.1: + If T is cv std::nullptr_t, the result is a null pointer constant. */ + return val; }