From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 96792 invoked by alias); 27 Nov 2017 10:31:48 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 96779 invoked by uid 89); 27 Nov 2017 10:31:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.7 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KB_WAM_FROM_NAME_SINGLEWORD,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=Hx-languages-length:2711 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 27 Nov 2017 10:31:40 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 82BD95F7B8; Mon, 27 Nov 2017 10:31:39 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-77.ams2.redhat.com [10.36.116.77]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 299FE60C8A; Mon, 27 Nov 2017 10:31:39 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id vARAVaRM011733; Mon, 27 Nov 2017 11:31:36 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id vARAVYrj011732; Mon, 27 Nov 2017 11:31:34 +0100 Date: Mon, 27 Nov 2017 10:49:00 -0000 From: Jakub Jelinek To: Maxim Kuvyrkov Cc: GCC Patches Subject: Re: [C++ PATCH] Fix -fsanitize={null,alignment} of references (PR c++/79572) Message-ID: <20171127103134.GA2320@tucnak> Reply-To: Jakub Jelinek References: <20170323203705.GX11094@tucnak> <20171124142611.GY14653@tucnak> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171124142611.GY14653@tucnak> User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes X-SW-Source: 2017-11/txt/msg02275.txt.bz2 On Fri, Nov 24, 2017 at 03:26:11PM +0100, Jakub Jelinek wrote: > On Fri, Nov 24, 2017 at 05:16:27PM +0300, Maxim Kuvyrkov wrote: > > Using __builtin_printf causes this test to fail sporadically when > > cross-testing. Stdout and stderr output can get mixed in > > cross-testing, so dejagnu might see > > == > > g++.dg/ubsan/null-8.C:18:7: runtime error: reference binding to null > > pointer of type iref is NULL > > 'const int' > > == > > instead of > > == > > g++.dg/ubsan/null-8.C:18:7: runtime error: reference binding to null > > pointer of type 'const int' > > iref is NULL > > == > > > > Is it essential for this testcase to use __builtin_printf or simple > > "fprintf (stderr, ...)" would do just fine? > > That would mean bringing in stdio.h, which is very much undesirable. > > If you want, just revert the patch, verify the testcase FAILs, > and then tweak it to say: > __attribute__((noinline, noclone)) > void > bar (const *x, int y) > { > asm volatile ("" : : "g" (x), "g" (y) : "memory"); > } > > and change __builtin_printf ("iref %d\n", iref); > to bar ("iref %d\n", iref); > and __builtin_printf ("iref is NULL\n"); > to bar ("iref is NULL\n", 0); > If the test still FAILs and is fixed after you reapply the patch, > the change is preapproved. Verified myself: ./cc1plus.246620 -O0 -quiet -fsanitize=null -std=c++14 null-8.C; g++ -fsanitize=undefined -o null-8{,.s}; ./null-8 ./cc1plus.246621 -O0 -quiet -fsanitize=null -std=c++14 null-8.C; g++ -fsanitize=undefined -o null-8{,.s}; ./null-8 null-8.C:25:7: runtime error: reference binding to null pointer of type 'const int' ./cc1plus.246620 -O2 -quiet -fsanitize=null -std=c++14 null-8.C; g++ -fsanitize=undefined -o null-8{,.s}; ./null-8 ./cc1plus.246621 -O2 -quiet -fsanitize=null -std=c++14 null-8.C; g++ -fsanitize=undefined -o null-8{,.s}; ./null-8 null-8.C:25:7: runtime error: reference binding to null pointer of type 'const int' Committed to trunk: 2017-11-27 Jakub Jelinek * g++.dg/ubsan/null-8.C (bar): New function. (foo): Use bar instead of __builtin_printf. --- gcc/testsuite/g++.dg/ubsan/null-8.C.jj 2017-03-31 20:38:44.000000000 +0200 +++ gcc/testsuite/g++.dg/ubsan/null-8.C 2017-11-27 11:27:17.311529667 +0100 @@ -3,13 +3,20 @@ // { dg-options "-fsanitize=null -std=c++14" } // { dg-output "reference binding to null pointer of type 'const int'" } +__attribute__((noinline, noclone)) +void +bar (int x) +{ + asm volatile ("" : : "r" (x) : "memory"); +} + void foo (const int &iref) { if (&iref) - __builtin_printf ("iref %d\n", iref); + bar (iref); else - __builtin_printf ("iref is NULL\n"); + bar (1); } int Jakub