Skip to content

Commit

Permalink
[CORE] [Clang]Cleanup clang-analyzer warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
smuzaffar committed Oct 4, 2024
1 parent 180e6a5 commit 401976a
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Utilities/StaticAnalyzers/src/ClassChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ namespace clangcms {
MD = llvm::dyn_cast<clang::CXXMethodDecl>(AD);
if (llvm::isa<clang::CXXNewExpr>(RE))
return;
assert(MD);
clang::QualType RQT = MD->getCallResultType();
clang::QualType RTy = Ctx.getCanonicalType(RQT);
if ((RTy->isPointerType() || RTy->isReferenceType())) {
Expand Down Expand Up @@ -467,6 +468,7 @@ namespace clangcms {
const clang::MemberExpr *AME = llvm::dyn_cast_or_null<clang::MemberExpr>(E);
if (AME && AME->isImplicitAccess()) {
clang::ParmVarDecl *PVD = llvm::dyn_cast_or_null<clang::ParmVarDecl>(MD->getParamDecl(i));
assert(PVD);
clang::QualType QT = PVD->getOriginalType();
const clang::Type *T = QT.getTypePtr();
if (!support::isConst(QT) && T->isReferenceType() && ME && ME->isImplicitAccess())
Expand Down Expand Up @@ -575,9 +577,12 @@ namespace clangcms {
LangOpts.CPlusPlus = true;
clang::PrintingPolicy Policy(LangOpts);

assert(llvm::dyn_cast<clang::CXXMemberCallExpr>(CE));
clang::CXXMethodDecl *CMD = llvm::dyn_cast<clang::CXXMemberCallExpr>(CE)->getMethodDecl();
const clang::MemberExpr *E = llvm::dyn_cast<clang::MemberExpr>(CE->getArg(i));
assert(E);
clang::ValueDecl *VD = llvm::dyn_cast<clang::ValueDecl>(E->getMemberDecl());
assert(VD);
os << "Member data '" << VD->getQualifiedNameAsString();
os << "' is passed to a non-const reference parameter";
os << " of CXX method '" << CMD->getQualifiedNameAsString() << "' in const function";
Expand Down
1 change: 1 addition & 0 deletions Utilities/StaticAnalyzers/src/CmsSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace clangcms {
}
if (qt->isPointerType()) {
clang::PointerType const *pt = qt->getAs<clang::PointerType>();
assert(pt);
return pt->getPointeeType().isConstQualified();
}

Expand Down
2 changes: 2 additions & 0 deletions Utilities/StaticAnalyzers/src/ESRecordGetChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace clangcms {
LangOpts.CPlusPlus = true;
PrintingPolicy Policy(LangOpts);
const Decl *D = AC->getDecl();
assert(D);
std::string dname = "";
if (const NamedDecl *ND = llvm::dyn_cast_or_null<NamedDecl>(D))
dname = ND->getQualifiedNameAsString();
Expand All @@ -45,6 +46,7 @@ namespace clangcms {
llvm::SmallString<100> buf;
llvm::raw_svector_ostream os(buf);
os << "function '";
assert(llvm::dyn_cast<FunctionDecl>(D));
llvm::dyn_cast<FunctionDecl>(D)->getNameForDiagnostic(os, Policy, true);
os << "' ";
os << "calls function '";
Expand Down
2 changes: 1 addition & 1 deletion Utilities/StaticAnalyzers/src/FiniteMathChecker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace clangcms {
}

void FMWalkAST::VisitCallExpr(clang::CallExpr *CE) {
const clang::Expr *Callee = CE->getCallee();
assert(CE);
const FunctionDecl *FD = CE->getDirectCallee();
if (!FD)
return;
Expand Down
4 changes: 3 additions & 1 deletion Utilities/StaticAnalyzers/src/FunctionChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ namespace clangcms {

void FWalker::ReportDeclRef(const clang::DeclRefExpr *DRE) {
const clang::VarDecl *D = llvm::dyn_cast_or_null<clang::VarDecl>(DRE->getDecl());
if (D && (D->hasAttr<CMSThreadGuardAttr>() || D->hasAttr<CMSThreadSafeAttr>()) || D->hasAttr<CMSSaAllowAttr>())
if (!D)
return;
if ((D->hasAttr<CMSThreadGuardAttr>() || D->hasAttr<CMSThreadSafeAttr>()) || D->hasAttr<CMSSaAllowAttr>())
return;
if (support::isSafeClassName(D->getCanonicalDecl()->getQualifiedNameAsString()))
return;
Expand Down
3 changes: 3 additions & 0 deletions Utilities/StaticAnalyzers/src/getByChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace clangcms {
llvm::raw_svector_ostream os(buf);
if (mname == "edm::Event::getByLabel" || mname == "edm::Event::getManyByType") {
os << "function '";
assert(llvm::dyn_cast<CXXMethodDecl>(D));
llvm::dyn_cast<CXXMethodDecl>(D)->getNameForDiagnostic(os, Policy, true);
os << "' ";
if (mname == "edm::Event::getByLabel") {
Expand All @@ -58,6 +59,7 @@ namespace clangcms {
std::string rname = RD->getQualifiedNameAsString();
os << rname << " ";
const ClassTemplateSpecializationDecl *SD = dyn_cast<ClassTemplateSpecializationDecl>(RD);
assert(SD);
for (unsigned J = 0, F = SD->getTemplateArgs().size(); J != F; ++J) {
#if LLVM_VERSION_MAJOR >= 13
SD->getTemplateArgs().data()[J].print(Policy, os, false);
Expand All @@ -79,6 +81,7 @@ namespace clangcms {
const CXXRecordDecl *RD = QT->getAsCXXRecordDecl();
os << "getManyByType , ";
const ClassTemplateSpecializationDecl *SD = dyn_cast<ClassTemplateSpecializationDecl>(RD);
assert(SD);
const TemplateArgument TA = SD->getTemplateArgs().data()[0];
const QualType AQT = TA.getAsType();
const CXXRecordDecl *SRD = AQT->getAsCXXRecordDecl();
Expand Down
3 changes: 2 additions & 1 deletion Utilities/StorageFactory/src/LocalFileSystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ LocalFileSystem::FSInfo *LocalFileSystem::initFSInfo(void *arg) {
i->fsname = static_cast<char *>(memcpy(p += infolen, m->mnt_fsname, fslen));
i->type = static_cast<char *>(memcpy(p += fslen, m->mnt_type, typelen));
i->dir = static_cast<char *>(memcpy(p += typelen, m->mnt_dir, dirlen));
i->origin = static_cast<char *>(memcpy(p += dirlen, m->mnt_fsname, originlen));
[[clang::suppress]] i->origin = static_cast<char *>(memcpy(p += dirlen, m->mnt_fsname, originlen));
i->dev = -1;
i->fstype = -1;
i->freespc = 0;
Expand Down Expand Up @@ -361,6 +361,7 @@ LocalFileSystem::FSInfo *LocalFileSystem::findMount(const char *path,

prev_paths.push_back(path);
LocalFileSystem::FSInfo *new_best = findMount(fullpath, &sfs2, &s2, prev_paths);
free(fullpath);
return new_best ? new_best : best;
}

Expand Down

0 comments on commit 401976a

Please sign in to comment.