From patchwork Thu Mar 22 21:30:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 889654 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-475303-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="JzeyiOzs"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 406fwh6ZQ3z9s0y for ; Fri, 23 Mar 2018 08:30:42 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=yJ+Vx+76HMawCkpHIm9vi0H1F+lLN jaoajRsi6h6aJ7+zjBCXlrXTeJ7f4mAGMUkeH8F4wQStLuy4XKNYa0pWzI0lCXQW 2Qs/jJM1C6naYlIg0UUN6lIVwlsQT/lt8/BOJT352GehcDWlaZGctNUnXaT+4iAv bLaVNP3pety6ZY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=u/6MVT9AJM15p5Wqw0ectGV3Ajw=; b=Jze yiOzsxNt6qeYCZRxM3skN1fcXBaoFYJHcQQoqPlbpXcHZVty7CqquFbw6EzqBkZP Wt3wHgYKJKASwUgQnet+wxqHP8ydAB94NDBB272GRAK4Zh7yM2xBu/tvAuFhD8pb 0CUXMH9DH9d0v+2ej16d28utFEzOehFsCzgR0zbQ= Received: (qmail 126682 invoked by alias); 22 Mar 2018 21:30:34 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 123890 invoked by uid 89); 22 Mar 2018 21:30:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 22 Mar 2018 21:30:30 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6F70B8151D46; Thu, 22 Mar 2018 21:30:19 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.36.118.110]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2C0B963533; Thu, 22 Mar 2018 21:30:19 +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 w2MLUHvj016551; Thu, 22 Mar 2018 22:30:17 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id w2MLUGvE016550; Thu, 22 Mar 2018 22:30:16 +0100 Date: Thu, 22 Mar 2018 22:30:16 +0100 From: Jakub Jelinek To: Richard Biener , Jeff Law Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix sanopt -fsanitize=pointer-overflow optimization (PR sanitizer/85029) Message-ID: <20180322213016.GW8577@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.2 (2017-12-15) X-IsSubscribed: yes Hi! As the testcase shows, we can hit the assertion here (with code that is rejected only later on during expansion). Instead of the assertion, this patch just doesn't try to optimize those, maybe_optimize_ubsan_ptr_ifn is a pure optimization. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2018-03-22 Jakub Jelinek PR sanitizer/85029 * sanopt.c (maybe_optimize_ubsan_ptr_ifn): If DECL_REGISTER (base), just don't try to optimize it rather than assert it never happens. * g++.dg/ubsan/pr85029.C: New test. Jakub --- gcc/sanopt.c.jj 2018-03-14 09:49:45.462028237 +0100 +++ gcc/sanopt.c 2018-03-22 08:20:30.639183003 +0100 @@ -488,9 +488,9 @@ maybe_optimize_ubsan_ptr_ifn (sanopt_ctx &unsignedp, &reversep, &volatilep); if ((offset == NULL_TREE || TREE_CODE (offset) == INTEGER_CST) && DECL_P (base) + && !DECL_REGISTER (base) && pbitpos.is_constant (&bitpos)) { - gcc_assert (!DECL_REGISTER (base)); offset_int expr_offset; if (offset) expr_offset = wi::to_offset (offset) + bitpos / BITS_PER_UNIT; --- gcc/testsuite/g++.dg/ubsan/pr85029.C.jj 2018-03-22 08:22:34.952174863 +0100 +++ gcc/testsuite/g++.dg/ubsan/pr85029.C 2018-03-22 08:31:49.554138533 +0100 @@ -0,0 +1,15 @@ +// PR sanitizer/85029 +// { dg-do compile } +// { dg-skip-if "" { *-*-* } { "-flto -fno-fat-lto-objects" } } +// { dg-options "-fsanitize=undefined" } + +struct B { + virtual B bar (); + int e; +} register a; // { dg-error "register name not specified for 'a'" } + +int +foo (...) +{ + return foo (a); +}