Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:32:05

0001 //== MutableMemberChecker.cpp - Checks for mutable members --------------*- C++ -*--==//
0002 //
0003 // by Thomas Hauth [ Thomas.Hauth@cern.ch ]
0004 //
0005 //===----------------------------------------------------------------------===//
0006 
0007 #include "MutableMemberChecker.h"
0008 #include <clang/AST/Attr.h>
0009 using namespace clang;
0010 using namespace ento;
0011 using namespace llvm;
0012 namespace clangcms {
0013 
0014   void MutableMemberChecker::checkASTDecl(const clang::FieldDecl *D,
0015                                           clang::ento::AnalysisManager &Mgr,
0016                                           clang::ento::BugReporter &BR) const {
0017     if (D->hasAttr<CMSThreadGuardAttr>() || D->hasAttr<CMSThreadSafeAttr>() || D->hasAttr<CMSSaAllowAttr>())
0018       return;
0019     if (D->isMutable() && D->getDeclContext()->isRecord()) {
0020       clang::QualType t = D->getType();
0021       clang::ento::PathDiagnosticLocation DLoc =
0022           clang::ento::PathDiagnosticLocation::createBegin(D, BR.getSourceManager());
0023 
0024       if (!m_exception.reportMutableMember(t, DLoc, BR))
0025         return;
0026       std::string mname = t.getCanonicalType().getAsString();
0027       if (support::isSafeClassName(mname))
0028         return;
0029       std::string buf;
0030       llvm::raw_string_ostream os(buf);
0031       std::string pname = D->getParent()->getQualifiedNameAsString();
0032       os << "Mutable member '" << *D << "' in class '" << pname
0033          << "', might be thread-unsafe when accessing via a const pointer.";
0034       BR.EmitBasicReport(D, this, "mutable member if accessed via const pointer", "ConstThreadSafety", os.str(), DLoc);
0035       std::string tname = "mutablemember-checker.txt.unsorted";
0036       std::string ostring = "flagged class '" + pname + "' mutable member '" + D->getQualifiedNameAsString();
0037       support::writeLog(ostring, tname);
0038     }
0039   }
0040 
0041 }  // namespace clangcms