From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4296 invoked by alias); 27 Apr 2016 17:03:34 -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 3960 invoked by uid 89); 27 Apr 2016 17:03:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=incredible 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 27 Apr 2016 17:03:32 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 52DBCC04B30B for ; Wed, 27 Apr 2016 17:03:30 +0000 (UTC) Received: from redhat.com (ovpn-204-17.brq.redhat.com [10.40.204.17]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3RH3QiE008798 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 27 Apr 2016 13:03:29 -0400 Date: Wed, 27 Apr 2016 17:03:00 -0000 From: Marek Polacek To: GCC Patches , Jakub Jelinek Subject: [ubsan PATCH] Fix compile-time hog with &TARGET_EXPRs (PR sanitizer/70342) Message-ID: <20160427170325.GK28445@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-SW-Source: 2016-04/txt/msg01704.txt.bz2 This test took forever to compile with -fsanitize=null, because the instrumentation was creating incredible amount of duplicated expressions, in a quadratic fashion. I think the problem is that we instrument &TARGET_EXPR <> expressions, which doesn't seem to be needed -- we only need to instrument the initializers in TARGET_EXPRs. With this patch, we avoid creating tons of useless expressions and the compile time is reduced from ~ infinity to <1s. Jakub, do you see any problem with this? Bootstrapped/regtested on x86_64-linux, ok for trunk? 2016-04-27 Marek Polacek PR sanitizer/70342 * c-ubsan.c (ubsan_maybe_instrument_reference_or_call): Don't null-instrument &TARGET_EXPR <...>. * g++.dg/ubsan/null-7.C: New test. diff --git gcc/c-family/c-ubsan.c gcc/c-family/c-ubsan.c index 4022bdf..b829c04 100644 --- gcc/c-family/c-ubsan.c +++ gcc/c-family/c-ubsan.c @@ -395,8 +395,11 @@ ubsan_maybe_instrument_reference_or_call (location_t loc, tree op, tree ptype, int save_flag_delete_null_pointer_checks = flag_delete_null_pointer_checks; flag_delete_null_pointer_checks = 1; - if (!tree_single_nonzero_warnv_p (op, &strict_overflow_p) - || strict_overflow_p) + if ((!tree_single_nonzero_warnv_p (op, &strict_overflow_p) + || strict_overflow_p) + /* Instrumenting &TARGET_EXPR <...> is a waste and can result + in compile-time hog; see PR70342. */ + && TREE_CODE (TREE_OPERAND (op, 0)) != TARGET_EXPR) instrument = true; flag_delete_null_pointer_checks = save_flag_delete_null_pointer_checks; diff --git gcc/testsuite/g++.dg/ubsan/null-7.C gcc/testsuite/g++.dg/ubsan/null-7.C index e69de29..8284bc7 100644 --- gcc/testsuite/g++.dg/ubsan/null-7.C +++ gcc/testsuite/g++.dg/ubsan/null-7.C @@ -0,0 +1,24 @@ +// PR sanitizer/70342 +// { dg-do compile } +// { dg-options "-fsanitize=null" } + +class A {}; +class B { +public: + B(A); +}; +class C { +public: + C operator<<(B); +}; +class D { + D(const int &); + C m_blackList; +}; +D::D(const int &) { + m_blackList << A() << A() << A() << A() << A() << A() << A() << A() << A() + << A() << A() << A() << A() << A() << A() << A() << A() << A() + << A() << A() << A() << A() << A() << A() << A() << A() << A() + << A() << A() << A() << A() << A() << A() << A() << A() << A() + << A() << A() << A() << A() << A() << A() << A() << A() << A(); +} Marek