From patchwork Wed Aug 14 15:07:22 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 267143 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 2C8402C01F1 for ; Thu, 15 Aug 2013 01:07:35 +1000 (EST) 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:subject:message-id:mime-version:content-type; q=dns; s= default; b=VytGdsoUicAONT1fzHdSkazB97cPngKwada8jZCBYzj7fq1/BeMVW MV8nzfyl0dBZJgzlQR+a2qkaDz6xgTL89aMbZ+8HF+YwM+uSyXxnr7aQ3fN/2Q3i FPLH1i5+d/9uo/4Mz+HiBjflH9i75iZQ5Xmb3mUCZ+OonR45mH8Sh8= 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:subject:message-id:mime-version:content-type; s= default; bh=7vwkartAPbvvLwzlJO51Apwnwys=; b=p13pHvc36afebM+4+cvL lHQMhRv/sj50StA840gaGmGSwjJjYSAaNe+WCWh44GDDKYTDIZmfV8OnLgpielGt +o/ZZVg+5FaditbSy9zTfEB6TkUFPkANEA5Rlb32VNYJ7BQ4hwPYF6QlCSKkf0gr Noiub9ygjLHEQMydqwJqtwo= Received: (qmail 418 invoked by alias); 14 Aug 2013 15:07:28 -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 409 invoked by uid 89); 14 Aug 2013 15:07:28 -0000 X-Spam-SWARE-Status: No, score=-7.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 14 Aug 2013 15:07:27 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r7EF7Q3A016046 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 14 Aug 2013 11:07:26 -0400 Received: from redhat.com (ovpn-116-26.ams2.redhat.com [10.36.116.26]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r7EF7Me8010889 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO) for ; Wed, 14 Aug 2013 11:07:25 -0400 Date: Wed, 14 Aug 2013 17:07:22 +0200 From: Marek Polacek To: GCC Patches Subject: [ubsan] Fix assert in c-ubsan.c Message-ID: <20130814150722.GU17022@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) We ICEd on the following testcase because even though the underlying types were the same, theirs TREE_TYPEs were not. We can use TYPE_MAIN_VARIANT to see through the typedefs which confused us. Tested x86_64-pc-linux-gnu, applying to the ubsan branch. 2013-08-14 Marek Polacek * c-ubsan.c (ubsan_instrument_division): Use TYPE_MAIN_VARIANT in the assert. * c-c++-common/ubsan/typedef-1.c: New test. Marek --- gcc/c-family/c-ubsan.c.mp 2013-08-14 16:55:56.322784886 +0200 +++ gcc/c-family/c-ubsan.c 2013-08-14 16:56:03.716812775 +0200 @@ -42,8 +42,10 @@ ubsan_instrument_division (location_t lo tree type = TREE_TYPE (op0); /* At this point both operands should have the same type, - because they are already converted to RESULT_TYPE. */ - gcc_assert (type == TREE_TYPE (op1)); + because they are already converted to RESULT_TYPE. + Use TYPE_MAIN_VARIANT since typedefs can confuse us. */ + gcc_assert (TYPE_MAIN_VARIANT (TREE_TYPE (op0)) + == TYPE_MAIN_VARIANT (TREE_TYPE (op1))); /* TODO: REAL_TYPE is not supported yet. */ if (TREE_CODE (type) != INTEGER_TYPE) --- gcc/testsuite/c-c++-common/ubsan/typedef-1.c.mp 2013-08-14 16:58:05.767181047 +0200 +++ gcc/testsuite/c-c++-common/ubsan/typedef-1.c 2013-08-14 16:57:21.086022479 +0200 @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=undefined" } */ + +typedef int V; +int +foo (void) +{ + V v = 9; + int a = 3; + v += v % a; + return v / 3; +}