//===----- UninitializedObject.h ---------------------------------*- C++ -*-==// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file defines helper classes for UninitializedObjectChecker and // documentation about the logic of it. // // The checker reports uninitialized fields in objects created after a // constructor call. // // This checker has several options: // - "Pedantic" (boolean). If its not set or is set to false, the checker // won't emit warnings for objects that don't have at least one initialized // field. This may be set with // // `-analyzer-config optin.cplusplus.UninitializedObject:Pedantic=true`. // // - "NotesAsWarnings" (boolean). If set to true, the checker will emit a // warning for each uninitialized field, as opposed to emitting one warning // per constructor call, and listing the uninitialized fields that belongs // to it in notes. Defaults to false. // // `-analyzer-config \ // optin.cplusplus.UninitializedObject:NotesAsWarnings=true`. // // - "CheckPointeeInitialization" (boolean). If set to false, the checker will // not analyze the pointee of pointer/reference fields, and will only check // whether the object itself is initialized. Defaults to false. // // `-analyzer-config \ // optin.cplusplus.UninitializedObject:CheckPointeeInitialization=true`. // // TODO: With some clever heuristics, some pointers should be dereferenced // by default. For example, if the pointee is constructed within the // constructor call, it's reasonable to say that no external object // references it, and we wouldn't generate multiple report on the same // pointee. // // - "IgnoreRecordsWithField" (string). If supplied, the checker will not // analyze structures that have a field with a name or type name that // matches the given pattern. Defaults to "". // // `-analyzer-config \ // optin.cplusplus.UninitializedObject:IgnoreRecordsWithField="[Tt]ag|[Kk]ind"`. // // - "IgnoreGuardedFields" (boolean). If set to true, the checker will analyze // _syntactically_ whether the found uninitialized object is used without a // preceding assert call. Defaults to false. // // `-analyzer-config \ // optin.cplusplus.UninitializedObject:IgnoreGuardedFields=true`. // // Most of the following methods as well as the checker itself is defined in // UninitializedObjectChecker.cpp. // // Some methods are implemented in UninitializedPointee.cpp, to reduce the // complexity of the main checker file. // //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_STATICANALYZER_UNINITIALIZEDOBJECT_H #define LLVM_CLANG_STATICANALYZER_UNINITIALIZEDOBJECT_H #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h" namespace clang { namespace ento { struct UninitObjCheckerOptions { … }; /// A lightweight polymorphic wrapper around FieldRegion *. We'll use this /// interface to store addinitional information about fields. As described /// later, a list of these objects (i.e. "fieldchain") will be constructed and /// used for printing note messages should an uninitialized value be found. class FieldNode { … }; /// Returns with Field's name. This is a helper function to get the correct name /// even if Field is a captured lambda variable. std::string getVariableName(const FieldDecl *Field); /// Represents a field chain. A field chain is a list 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 object /// that contains it. /// /// Note that this class is immutable (essentially a wrapper around an /// ImmutableList), new FieldChainInfo objects may be created by member /// functions such as add() and replaceHead(). class FieldChainInfo { … }; UninitFieldMap; /// Searches for and stores uninitialized fields in a non-union object. class FindUninitializedFields { … }; /// Returns true if T is a primitive type. An object of a primitive type only /// needs to be analyzed as much as checking whether their value is undefined. inline bool isPrimitiveType(const QualType &T) { … } inline bool isDereferencableType(const QualType &T) { … } // Template method definitions. template <class FieldNodeT> inline FieldChainInfo FieldChainInfo::add(const FieldNodeT &FN) { … } template <class FieldNodeT> inline FieldChainInfo FieldChainInfo::replaceHead(const FieldNodeT &FN) { … } } // end of namespace ento } // end of namespace clang #endif // LLVM_CLANG_STATICANALYZER_UNINITIALIZEDOBJECT_H