From: Kristof Umann Date: Thu, 12 Jul 2018 13:13:46 +0000 (+0000) Subject: [analyzer][UninitializedObjectChecker] Moved non-member functions out of the anonymou... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=baad1141d2dd8105aaebd8c7bf79ee832b0e34a2;p=clang [analyzer][UninitializedObjectChecker] Moved non-member functions out of the anonymous namespace As the code for the checker grew, it became increasinly difficult to see whether a function was global or statically defined. In this patch, anything that isn't a type declaration or definition was moved out of the anonymous namespace and is marked as static. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@336901 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp b/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp index 773fcb2269..016be6fed8 100644 --- a/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp @@ -50,8 +50,6 @@ public: void checkEndFunction(CheckerContext &C) const; }; -llvm::ImmutableListFactory Factory; - /// Represents a field chain. A field chain is a vector of fields where the /// first element of the chain is the object under checking (not stored), and /// every other element is a field, and the element that precedes it is the @@ -205,32 +203,37 @@ private: // TODO: Add a support for nonloc::LocAsInteger. }; +} // end of anonymous namespace + +// Static variable instantionations. + +static llvm::ImmutableListFactory Factory; + // Utility function declarations. /// Returns the object that was constructed by CtorDecl, or None if that isn't /// possible. -Optional +static Optional getObjectVal(const CXXConstructorDecl *CtorDecl, CheckerContext &Context); /// Checks whether the constructor under checking is called by another /// constructor. -bool isCalledByConstructor(const CheckerContext &Context); +static bool isCalledByConstructor(const CheckerContext &Context); /// Returns whether FD can be (transitively) dereferenced to a void pointer type /// (void*, void**, ...). The type of the region behind a void pointer isn't /// known, and thus FD can not be analyzed. -bool isVoidPointer(const FieldDecl *FD); +static bool isVoidPointer(const FieldDecl *FD); /// Returns true if T is a primitive type. We'll call a type primitive if it's /// either a BuiltinType or an EnumeralType. -bool isPrimitiveType(const QualType &T) { +static bool isPrimitiveType(const QualType &T) { return T->isBuiltinType() || T->isEnumeralType(); } /// Constructs a note message for a given FieldChainInfo object. -void printNoteMessage(llvm::raw_ostream &Out, const FieldChainInfo &Chain); - -} // end of anonymous namespace +static void printNoteMessage(llvm::raw_ostream &Out, + const FieldChainInfo &Chain); //===----------------------------------------------------------------------===// // Methods for UninitializedObjectChecker. @@ -638,9 +641,7 @@ void FieldChainInfo::printTail( // Utility functions. //===----------------------------------------------------------------------===// -namespace { - -bool isVoidPointer(const FieldDecl *FD) { +static bool isVoidPointer(const FieldDecl *FD) { QualType T = FD->getType(); while (!T.isNull()) { @@ -651,7 +652,7 @@ bool isVoidPointer(const FieldDecl *FD) { return false; } -Optional +static Optional getObjectVal(const CXXConstructorDecl *CtorDecl, CheckerContext &Context) { Loc ThisLoc = Context.getSValBuilder().getCXXThis(CtorDecl->getParent(), @@ -668,7 +669,7 @@ getObjectVal(const CXXConstructorDecl *CtorDecl, CheckerContext &Context) { // TODO: We should also check that if the constructor was called by another // constructor, whether those two are in any relation to one another. In it's // current state, this introduces some false negatives. -bool isCalledByConstructor(const CheckerContext &Context) { +static bool isCalledByConstructor(const CheckerContext &Context) { const LocationContext *LC = Context.getLocationContext()->getParent(); while (LC) { @@ -680,7 +681,8 @@ bool isCalledByConstructor(const CheckerContext &Context) { return false; } -void printNoteMessage(llvm::raw_ostream &Out, const FieldChainInfo &Chain) { +static void printNoteMessage(llvm::raw_ostream &Out, + const FieldChainInfo &Chain) { if (Chain.isPointer()) { if (Chain.isDereferenced()) Out << "uninitialized pointee 'this->"; @@ -692,8 +694,6 @@ void printNoteMessage(llvm::raw_ostream &Out, const FieldChainInfo &Chain) { Out << "'"; } -} // end of anonymous namespace - void ento::registerUninitializedObjectChecker(CheckerManager &Mgr) { auto Chk = Mgr.registerChecker(); Chk->IsPedantic = Mgr.getAnalyzerOptions().getBooleanOption(