[PATCH] D38458: Fix assertion failure in thread safety analysis (PR34800).
Alexander Kornienko via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 2 07:11:46 PDT 2017
alexfh created this revision.
Fix an assertion failure and clean up unused code relevant to the fixed logic.
https://reviews.llvm.org/D38458
Files:
include/clang/Analysis/Analyses/ThreadSafetyTIL.h
test/SemaCXX/warn-thread-safety-analysis.cpp
Index: test/SemaCXX/warn-thread-safety-analysis.cpp
===================================================================
--- test/SemaCXX/warn-thread-safety-analysis.cpp
+++ test/SemaCXX/warn-thread-safety-analysis.cpp
@@ -5233,3 +5233,18 @@
} // expected-warning {{mutex 'lock_' is still held at the end of function}}
Mutex lock_ ACQUIRED_BEFORE("");
};
+
+namespace PR34800 {
+struct A {
+ operator int() const;
+};
+struct B {
+ bool g() __attribute__((locks_excluded(h))); // expected-warning {{'locks_excluded' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'int'}}
+ int h;
+};
+struct C {
+ B *operator[](int);
+};
+C c;
+void f() { c[A()]->g(); }
+} // namespace PR34800
Index: include/clang/Analysis/Analyses/ThreadSafetyTIL.h
===================================================================
--- include/clang/Analysis/Analyses/ThreadSafetyTIL.h
+++ include/clang/Analysis/Analyses/ThreadSafetyTIL.h
@@ -909,15 +909,10 @@
public:
static bool classof(const SExpr *E) { return E->opcode() == COP_Project; }
- Project(SExpr *R, StringRef SName)
- : SExpr(COP_Project), Rec(R), SlotName(SName), Cvdecl(nullptr)
- { }
Project(SExpr *R, const clang::ValueDecl *Cvd)
- : SExpr(COP_Project), Rec(R), SlotName(Cvd->getName()), Cvdecl(Cvd)
- { }
- Project(const Project &P, SExpr *R)
- : SExpr(P), Rec(R), SlotName(P.SlotName), Cvdecl(P.Cvdecl)
- { }
+ : SExpr(COP_Project), Rec(R), Cvdecl(Cvd) {
+ assert(Cvd && "ValueDecl must not be null");
+ }
SExpr *record() { return Rec; }
const SExpr *record() const { return Rec; }
@@ -931,10 +926,15 @@
}
StringRef slotName() const {
- if (Cvdecl)
+ if (Cvdecl->getDeclName().isIdentifier())
return Cvdecl->getName();
- else
- return SlotName;
+ if (!SlotName) {
+ std::string Buffer;
+ llvm::raw_string_ostream OS(Buffer);
+ Cvdecl->printName(OS);
+ SlotName = OS.str();
+ }
+ return *SlotName;
}
template <class V>
@@ -953,7 +953,7 @@
private:
SExpr* Rec;
- StringRef SlotName;
+ mutable llvm::Optional<std::string> SlotName;
const clang::ValueDecl *Cvdecl;
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38458.117343.patch
Type: text/x-patch
Size: 2192 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171002/eba12a0d/attachment.bin>
More information about the cfe-commits
mailing list