From bc8ffdb68ca93699080cf43f7d46a6a5cc0dba6f Mon Sep 17 00:00:00 2001 From: DeLesley Hutchins Date: Thu, 16 Feb 2012 17:03:24 +0000 Subject: Thread-Safety: added support for 'this' as a lock expression. llvm-svn: 150700 --- clang/lib/Analysis/ThreadSafety.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'clang/lib/Analysis/ThreadSafety.cpp') diff --git a/clang/lib/Analysis/ThreadSafety.cpp b/clang/lib/Analysis/ThreadSafety.cpp index f4386538d7a..5a08ec6b21d 100644 --- a/clang/lib/Analysis/ThreadSafety.cpp +++ b/clang/lib/Analysis/ThreadSafety.cpp @@ -62,11 +62,11 @@ namespace { /// /// Clang introduces an additional wrinkle, which is that it is difficult to /// derive canonical expressions, or compare expressions directly for equality. -/// Thus, we identify a mutex not by an Expr, but by the set of named +/// Thus, we identify a mutex not by an Expr, but by the list of named /// declarations that are referenced by the Expr. In other words, /// x->foo->bar.mu will be a four element vector with the Decls for /// mu, bar, and foo, and x. The vector will uniquely identify the expression -/// for all practical purposes. +/// for all practical purposes. Null is used to denote 'this'. /// /// Note we will need to perform substitution on "this" and function parameter /// names when constructing a lock expression. @@ -122,8 +122,10 @@ class MutexID { } else if (isa(Exp)) { if (Parent) buildMutexID(Parent, D, 0, 0, 0); - else + else { + DeclSeq.push_back(0); // Use 0 to represent 'this'. return; // mutexID is still valid in this case + } } else if (UnaryOperator *UOE = dyn_cast(Exp)) buildMutexID(UOE->getSubExpr(), D, Parent, NumArgs, FunArgs); else if (CastExpr *CE = dyn_cast(Exp)) @@ -233,6 +235,8 @@ public: /// We do not want to output the entire expression text for security reasons. StringRef getName() const { assert(isValid()); + if (!DeclSeq.front()) + return "this"; // Use 0 to represent 'this'. return DeclSeq.front()->getName(); } -- cgit v1.2.3