Skip to content

Commit 68bdd2b

Browse files
[Analysis] Make ThreadSafety correctly handle base class destructors
After the landing of llvm#169320, the clang CFG analyses are able to do slightly more analysis around destructors. This results in thread safety also seeing slightly more destructors. This exposed a bug in ThreadSafety, where we would call getDestructorDecl, which can return nullptr for base class destructors, but not do a null pointer check, resulting in a segmentation fault. This patch fixes the issue by adding a null pointer check and adds a regression test so this gets caught before downstream integration testing in the future.
1 parent 4cfbc44 commit 68bdd2b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

clang/lib/Analysis/ThreadSafety.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2820,7 +2820,7 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) {
28202820
case CFGElement::AutomaticObjectDtor: {
28212821
CFGAutomaticObjDtor AD = BI.castAs<CFGAutomaticObjDtor>();
28222822
const auto *DD = AD.getDestructorDecl(AC.getASTContext());
2823-
if (!DD->hasAttrs())
2823+
if (!DD || !DD->hasAttrs())
28242824
break;
28252825

28262826
LocksetBuilder.handleCall(
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wthread-safety -Wthread-safety-pointer -Wthread-safety-beta -Wno-thread-safety-negative -fcxx-exceptions -DUSE_CAPABILITY=0 %s
2+
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wthread-safety -Wthread-safety-pointer -Wthread-safety-beta -Wno-thread-safety-negative -fcxx-exceptions -DUSE_CAPABILITY=1 %s
3+
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 -Wthread-safety -Wthread-safety-pointer -Wthread-safety-beta -Wno-thread-safety-negative -fcxx-exceptions -DUSE_CAPABILITY=0 %s
4+
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 -Wthread-safety -Wthread-safety-pointer -Wthread-safety-beta -Wno-thread-safety-negative -fcxx-exceptions -DUSE_CAPABILITY=1 %s
5+
// expected-no-diagnostics
6+
7+
struct foo {
8+
~foo();
9+
};
10+
struct bar : foo {};
11+
struct baz : bar {};
12+
baz foobar(baz a) { return a; }

0 commit comments

Comments
 (0)