From patchwork Thu May 30 22:19:25 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Pluzhnikov X-Patchwork-Id: 247808 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 222872C007B for ; Fri, 31 May 2013 08:19:48 +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:from :to:cc:subject:date:message-id:mime-version:content-type; q=dns; s=default; b=nlqMNMvv7nZ1ESnVyRXhDYUtwKmO1fvN8nlPfze7QRis/gr1BD ZI7XoI7q+wwzvndRE5rLUrB93yL8+QtSDdjZBSl6vxYlt4d7uj5kTfjG2CNhwpEz SOD7D0LvQbt/fW8IGa6XIgCM1TRzN6eOaVjVrBhUBPdsnfR5chMbLc14g= 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:from :to:cc:subject:date:message-id:mime-version:content-type; s= default; bh=NrhqQEJ5g//3JMYu1E70PHwTwTw=; b=pduAKK/4+DRILYtR7yXR yFUmhelZ5SrYqGBoap3lvmlGsKdYAysNMIpV8tgnUJ4vAY944tiHwCK52xD+Ytiw mLGcmHBpItV5V7lyFBqa3H3HUKbOExwRN5bUqvmV/aDU0KShmAtz2sNQmaZieLA/ jsnsSdwRmjtCCqymb5qo/kc= Received: (qmail 12914 invoked by alias); 30 May 2013 22:19:42 -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 12844 invoked by uid 89); 30 May 2013 22:19:34 -0000 X-Spam-SWARE-Status: No, score=-4.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.1 Received: from mail-qe0-f74.google.com (HELO mail-qe0-f74.google.com) (209.85.128.74) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Thu, 30 May 2013 22:19:28 +0000 Received: by mail-qe0-f74.google.com with SMTP id 1so83835qec.3 for ; Thu, 30 May 2013 15:19:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:mime-version:content-type :x-gm-message-state; bh=ZZrzfsjvAyeS5GbVLYt+FGRCLQJDLRZjvT7vXWAuq0I=; b=CdABhesv6fHaUVsoFH4OH1FvqIVig44ra84OTxxfOHpGduW4scHVldJ45XOQLGwo6o aYILOxTK0G0udyfgaLvoMMsRksdZNTNL3cbPOzhB/C4GxWi4Ifu2xEXelQcUzPlavxHg KPPDOrH9dyC+wWo7FFJZ+/EcgwI+LJSdA9ETyn9r6pBVBxomWe0g1QfaTn+WkeqWNmUh CMc0HuC61NJtoCmYKsM+NOicXVdyZAf23MYjK9ix2QKpHX6AvcdPb3+5yVxUaDMIXwEF 2Xbf44ZqcY2f8NwFURUn+ovRI1VUT55uL1QPPnI1HlJMwcn+S1bGqcL67CA8jEk9vTeI 40Qw== X-Received: by 10.236.128.207 with SMTP id f55mr5141692yhi.28.1369952366273; Thu, 30 May 2013 15:19:26 -0700 (PDT) Received: from corp2gmr1-1.hot.corp.google.com (corp2gmr1-1.hot.corp.google.com [172.24.189.92]) by gmr-mx.google.com with ESMTPS id b23si3449374yhj.4.2013.05.30.15.19.26 for (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Thu, 30 May 2013 15:19:26 -0700 (PDT) Received: from elbrus2.mtv.corp.google.com (elbrus2.mtv.corp.google.com [172.17.128.95]) by corp2gmr1-1.hot.corp.google.com (Postfix) with ESMTP id 2324231C1EF; Thu, 30 May 2013 15:19:26 -0700 (PDT) Received: by elbrus2.mtv.corp.google.com (Postfix, from userid 74925) id 9FB021C0878; Thu, 30 May 2013 15:19:25 -0700 (PDT) From: Paul Pluzhnikov To: dnovillo@google.com Cc: ppluzhnikov@google.com, gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org Subject: [google gcc-4_7,gcc-4_8,integration] Relax vector validity checks Date: Thu, 30 May 2013 15:19:25 -0700 Message-ID: MIME-Version: 1.0 X-Gm-Message-State: ALoCoQl89u2B7moMADHtJ1NQQPdqihvqBsxVlk19UdlpxV6TwO9G/04FSvcSDpENsUIBIpAYuRPmDqNYX6Q6Chji1nVm6ZOaQj/NzyHXH/rPziuFh9mzZ3SzePuti1mssosHSX/g9KFoR/g4sdPSxpIgxU0r7+LwELu+hSiXwHXK5dgZWNppdx8pNbJRLrdQ/uLYC+B4mwT2dTP2U0UtTwl7j0gClPwouCjY1nguq4RWbQD3bBxQwA4= Greetings, The vector validity checks introduced here: http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00415.html proved too strict: older versions of GCC used to do this: _M_start = _M_end = _M_end_of_storage = new_allocator(sizeof(T) * n) even when n == 0, and we have code compiled by such version linked in with new code, and failing the check. Google ref b/9198806 Attached patch relaxes the check, while still catching dangling vector accesses. Ok for google/gcc_4-7, gcc-4_8 and integration branches? Thanks, --- Paul Pluzhnikov Index: libstdc++-v3/include/bits/stl_vector.h =================================================================== --- libstdc++-v3/include/bits/stl_vector.h (revision 199461) +++ libstdc++-v3/include/bits/stl_vector.h (working copy) @@ -244,12 +244,27 @@ bool _M_is_valid() const { - return (this->_M_impl._M_end_of_storage == 0 - && this->_M_impl._M_start == 0 - && this->_M_impl._M_finish == 0) - || (this->_M_impl._M_start <= this->_M_impl._M_finish - && this->_M_impl._M_finish <= this->_M_impl._M_end_of_storage - && this->_M_impl._M_start < this->_M_impl._M_end_of_storage); + if (this->_M_impl._M_end_of_storage == 0 + && this->_M_impl._M_start == 0 + && this->_M_impl._M_finish == 0) + return true; + + if (this->_M_impl._M_start <= this->_M_impl._M_finish + && this->_M_impl._M_finish <= this->_M_impl._M_end_of_storage) + { + if (this->_M_impl._M_start < this->_M_impl._M_end_of_storage) + return true; + else if (this->_M_impl._M_start == this->_M_impl._M_end_of_storage + && this->_M_impl._M_start == this->_M_impl._M_finish) + { + pointer _0xcdcd; + + __builtin_memset(&_0xcdcd, 0xcd, sizeof(_0xcdcd)); + return this->_M_impl._M_finish != _0xcdcd; + } + } + + return false; } public: