From patchwork Tue Oct 11 17:52:36 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Delesley Hutchins X-Patchwork-Id: 119036 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]) by ozlabs.org (Postfix) with SMTP id C2D7EB6F6B for ; Wed, 12 Oct 2011 04:52:58 +1100 (EST) Received: (qmail 15308 invoked by alias); 11 Oct 2011 17:52:56 -0000 Received: (qmail 15292 invoked by uid 22791); 11 Oct 2011 17:52:54 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (74.125.121.67) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 11 Oct 2011 17:52:40 +0000 Received: from hpaq1.eem.corp.google.com (hpaq1.eem.corp.google.com [172.25.149.1]) by smtp-out.google.com with ESMTP id p9BHqcXS023683 for ; Tue, 11 Oct 2011 10:52:38 -0700 Received: from ggnh1 (ggnh1.prod.google.com [10.218.96.129]) by hpaq1.eem.corp.google.com with ESMTP id p9BHnJQb022135 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for ; Tue, 11 Oct 2011 10:52:37 -0700 Received: by ggnh1 with SMTP id h1so9316673ggn.5 for ; Tue, 11 Oct 2011 10:52:37 -0700 (PDT) Received: by 10.150.50.20 with SMTP id x20mr10834186ybx.28.1318355557152; Tue, 11 Oct 2011 10:52:37 -0700 (PDT) MIME-Version: 1.0 Received: by 10.150.50.20 with SMTP id x20mr10834166ybx.28.1318355556961; Tue, 11 Oct 2011 10:52:36 -0700 (PDT) Received: by 10.150.190.4 with HTTP; Tue, 11 Oct 2011 10:52:36 -0700 (PDT) Date: Tue, 11 Oct 2011 10:52:36 -0700 Message-ID: Subject: [PATCH] [Annotalysis] Bugfix where lock function is attached to a base class. From: Delesley Hutchins To: gcc-patches , Diego Novillo , Ollie Wild X-System-Of-Record: true X-IsSubscribed: yes 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 This patch fixes an error where Annotalysis generates bogus warnings when using lock and unlock functions that are attached to a base class. The canonicalize routine did not work correctly in this case. Bootstrapped and passed gcc regression testsuite on x86_64-unknown-linux-gnu. Okay for google/gcc-4_6? -DeLesley Changelog.google-4_6: 2011-10-11 DeLesley Hutchins * tree-threadsafe-analyze.c (get_canonical_lock_expr) testsuite/Changelog.google-4_6: 2011-10-11 DeLesley Hutchins * g++.dg/thread-ann/thread_annot_lock-83.C Index: gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-83.C =================================================================== --- gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-83.C (revision 0) +++ gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-83.C (revision 0) @@ -1,5 +1,8 @@ -// Regression test for bugfix, where shared locks are not properly -// removed from locksets if a "universal lock" is present. +// Regression test for two bugfixes. +// Bugfix 1: Shared locks are not properly removed from locksets +// if a "universal lock" is present. +// Bugfix 2: Canonicalization does not properly store the lock in +// the hash table if the lock function is attached to a base class. // { dg-do compile } // { dg-options "-Wthread-safety" } @@ -7,6 +10,7 @@ class Foo; +/* Bugfix 1 */ class Bar { public: Foo* foo; @@ -29,3 +33,23 @@ void Bar::bar() { ReaderMutexLock rlock(&mu_); } + +/* Bugfix 2 */ +class LOCKABLE Base { +public: + Mutex mu_; + + void Lock() EXCLUSIVE_LOCK_FUNCTION() { mu_.Lock(); } + void Unlock() UNLOCK_FUNCTION() { mu_.Unlock(); } +}; + +class Derived : public Base { +public: + int b; +}; + +void doSomething(Derived *d) { + d->Lock(); + d->Unlock(); +}; + Index: gcc/tree-threadsafe-analyze.c =================================================================== --- gcc/tree-threadsafe-analyze.c (revision 179771) +++ gcc/tree-threadsafe-analyze.c (working copy) @@ -927,7 +927,16 @@ get_canonical_lock_expr (tree lock, tree base_obj, NULL_TREE); if (lang_hooks.decl_is_base_field (component)) - return canon_base; + { + if (is_temp_expr) + return canon_base; + else + /* return canon_base, but recalculate it so that it is stored + in the hash table. */ + return get_canonical_lock_expr (base, base_obj, + false /* is_temp_expr */, + new_leftmost_base_var); + } if (base != canon_base) lock = build3 (COMPONENT_REF, TREE_TYPE (component),