Skip to content

[alpha.webkit.UncheckedCallArgsChecker] Checker fails to recognize CanMakeCheckedPtrBase #136500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
14 changes: 12 additions & 2 deletions clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,18 @@ hasPublicMethodInBase(const CXXBaseSpecifier *Base, StringRef NameToMatch) {
return std::nullopt;

const CXXRecordDecl *R = T->getAsCXXRecordDecl();
if (!R)
return std::nullopt;
if (!R) {
auto CT = Base->getType().getCanonicalType();
if (auto *TST = dyn_cast<TemplateSpecializationType>(CT)) {
auto TmplName = TST->getTemplateName();
if (!TmplName.isNull()) {
if (auto *TD = TmplName.getAsTemplateDecl())
R = dyn_cast_or_null<CXXRecordDecl>(TD->getTemplatedDecl());
}
}
if (!R)
return std::nullopt;
}
if (!R->hasDefinition())
return std::nullopt;

Expand Down
34 changes: 34 additions & 0 deletions clang/test/Analysis/Checkers/WebKit/unchecked-call-arg.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncheckedCallArgsChecker -verify %s

void WTFCrash(void);

enum class Tag : bool { Value };

template <typename StorageType, Tag> class CanMakeCheckedPtrBase {
public:
void incrementCheckedPtrCount() const { ++m_checkedPtrCount; }
inline void decrementCheckedPtrCount() const
{
if (!m_checkedPtrCount)
WTFCrash();
--m_checkedPtrCount;
}

private:
mutable StorageType m_checkedPtrCount { 0 };
};

template<typename T, Tag tag>
class CanMakeCheckedPtr : public CanMakeCheckedPtrBase<unsigned int, tag> {
};

class CheckedObject : public CanMakeCheckedPtr<CheckedObject, Tag::Value> {
public:
void doWork();
};

CheckedObject* provide();
void foo() {
provide()->doWork();
// expected-warning@-1{{Call argument for 'this' parameter is unchecked and unsafe}}
}
Loading