From patchwork Tue Aug 13 12:20:49 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 266783 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 2F6332C00F4 for ; Tue, 13 Aug 2013 22:21:04 +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:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=s/+lEZoOyVIBToM74QGMad0yF3yBB9okSZcY856IDlE4wrAbKp XDffvnJRKmBrcCT4uTPxGN2DFM/zddTJ+YImRhvGhegR6Z6lvlqqW/nJlux983UR Z5Dt91bAUxLzrd9VNOj6+ZcqJwiXXoLrJDY5GyTLLwhSFi/bJWGm8IrLc= 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:mime-version:content-type; s= default; bh=n2l3t3gFMP12AZG7YghkuJZY6p4=; b=Qwfb8BMtPNkdnFEk4jhH E0T623nAWe8axUH85D5ft3ftBTMStsNCbVwxqPkO8uDP9ifsVswTf7mwByNRpBt4 ffneGAE9p/5KcA9sI+iSB/VOXJvD+VZcwtmbNq1lE6JJNPzxefp5/gbl7JZMF5Cu NXsg8x2U2u3RDEfA5r6TBas= Received: (qmail 15761 invoked by alias); 13 Aug 2013 12:20:57 -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 15746 invoked by uid 89); 13 Aug 2013 12:20:56 -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; Tue, 13 Aug 2013 12:20:56 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r7DCKskk015185 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 13 Aug 2013 08:20:54 -0400 Received: from redhat.com (ovpn-116-26.ams2.redhat.com [10.36.116.26]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r7DCKo72003414 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Tue, 13 Aug 2013 08:20:53 -0400 Date: Tue, 13 Aug 2013 14:20:49 +0200 From: Marek Polacek To: Jan Hubicka Cc: Martin Jambor , GCC Patches Subject: [PATCH] Quash undefined behavior in ipa-inline-analysis.c Message-ID: <20130813122049.GQ17022@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) When doing bootstrap with -fsanitize=undefined, I noticed undefined behavior in this file. We basically do 1 << 32, since NUM_CONDITIONS is #defined to 32, which is not defined. I admit I didn't followed the algorithm at all, but this patch passed bootstrap + regtesting on x86_64-linux. So, ok for trunk? 2013-08-13 Marek Polacek * ipa-inline-analysis.c (add_clause): Avoid undefined behavior when shifting integer. Marek --- gcc/ipa-inline-analysis.c.mp 2013-08-13 14:07:48.632662047 +0200 +++ gcc/ipa-inline-analysis.c 2013-08-13 14:08:16.728770973 +0200 @@ -337,7 +337,7 @@ add_clause (conditions conditions, struc and thus there is no point for looking for them. */ if (cc1->code == CHANGED || cc1->code == IS_NOT_CONSTANT) continue; - for (c2 = c1 + 1; c2 <= NUM_CONDITIONS; c2++) + for (c2 = c1 + 1; c2 < NUM_CONDITIONS; c2++) if (clause & (1 << c2)) { condition *cc1 =