From d61ad660503d2e0c7ba9981ba6526ae0c2f3b7cc Mon Sep 17 00:00:00 2001 From: Jan Korous Date: Tue, 2 Jun 2020 10:17:01 -0700 Subject: [PATCH] [Analyzer][WebKit] Check record definition is available in NoUncountedMembers checker isRefCountable asserts that the record passed as an argument has a definition available. Fixes: https://bugs.llvm.org/show_bug.cgi?id=46142 Differential Revision: https://reviews.llvm.org/D81017 --- .../StaticAnalyzer/Checkers/WebKit/NoUncountedMembersChecker.cpp | 3 ++- .../Checkers/WebKit/uncounted-members-regression-46142.cpp | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 clang/test/Analysis/Checkers/WebKit/uncounted-members-regression-46142.cpp diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/NoUncountedMembersChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/NoUncountedMembersChecker.cpp index 89caf60..db53db1 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/NoUncountedMembersChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/NoUncountedMembersChecker.cpp @@ -75,7 +75,8 @@ public: continue; if (auto *MemberCXXRD = MemberType->getPointeeCXXRecordDecl()) { - if (isRefCountable(MemberCXXRD)) + // If we don't see the definition we just don't know. + if (MemberCXXRD->hasDefinition() && isRefCountable(MemberCXXRD)) reportBug(Member, MemberType, MemberCXXRD, RD); } } diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-members-regression-46142.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-members-regression-46142.cpp new file mode 100644 index 0000000..20e58e7 --- /dev/null +++ b/clang/test/Analysis/Checkers/WebKit/uncounted-members-regression-46142.cpp @@ -0,0 +1,9 @@ +// regression test for https://bugs.llvm.org/show_bug.cgi?id=46142 + +// RUN: %clang_analyze_cc1 -analyzer-checker=webkit.WebKitNoUncountedMemberChecker -verify %s +// expected-no-diagnostics + +class ClassWithoutADefinition; +class Foo { + const ClassWithoutADefinition *foo; +}; -- 2.7.4