Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -4129,7 +4129,7 @@ def NoThreadSafetyAnalysis : InheritableAttr {
}

def GuardedBy : InheritableAttr {
let Spellings = [GNU<"guarded_by">];
let Spellings = [Clang<"guarded_by", 0>];
let Args = [ExprArgument<"Arg">];
let LateParsed = LateAttrParseExperimentalExt;
let TemplateDependent = 1;
Expand Down
7 changes: 7 additions & 0 deletions clang/lib/Analysis/ThreadSafetyCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,13 @@ til::SExpr *SExprBuilder::translateDeclRefExpr(const DeclRefExpr *DRE,
if (const auto *VarD = dyn_cast<VarDecl>(VD))
return translateVariable(VarD, Ctx);

if (const auto *FD = dyn_cast<FieldDecl>(VD)) {
if (Ctx && Ctx->SelfArg) {
til::SExpr *E = new (Arena) til::SApply(SelfVar);
return new (Arena) til::Project(E, FD);
}
}

// For non-local variables, treat it as a reference to a named object.
return new (Arena) til::LiteralPtr(VD);
}
Expand Down
25 changes: 25 additions & 0 deletions clang/test/SemaCXX/gh158116.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// RUN: %clang_cc1 -fsyntax-only -verify -Wthread-safety -std=c++11 %s

class __attribute__((lockable)) Mutex {
public:
void lock() __attribute__((exclusive_lock_function));
void unlock() __attribute__((unlock_function));
};

class Foo {
Mutex mu;
int y __attribute__((guarded_by(mu)));
int z [[clang::guarded_by(mu)]];

void func1() {
y = 0; // expected-warning{{writing variable 'y' requires holding}}
z = 1; // expected-warning{{writing variable 'z' requires holding}}
}

void func2() {
mu.lock();
y = 2;
z = 3;
mu.unlock();
}
};
4 changes: 0 additions & 4 deletions clang/test/SemaCXX/warn-thread-safety-analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3590,14 +3590,10 @@ void requireDecl(RelockableScope &scope) {
struct foo
{
Mutex mu;
// expected-note@+1{{see attribute on parameter here}}
void require(RelockableScope &scope EXCLUSIVE_LOCKS_REQUIRED(mu));
void callRequire(){
RelockableScope scope(&mu);
// TODO: False positive due to incorrect parsing of parameter attribute arguments.
require(scope);
// expected-warning@-1{{calling function 'require' requires holding mutex 'mu' exclusively}}
// expected-warning@-2{{mutex managed by 'scope' is 'mu' instead of 'mu'}}
}
};

Expand Down