Index: cfe/trunk/include/clang/Driver/CC1Options.td =================================================================== --- cfe/trunk/include/clang/Driver/CC1Options.td +++ cfe/trunk/include/clang/Driver/CC1Options.td @@ -106,11 +106,11 @@ ValuesCode<[{ const char *Values = #define GET_CHECKERS - #define CHECKER(FULLNAME, CLASS, DESCFILE, HT, G, H) FULLNAME "," + #define CHECKER(FULLNAME, CLASS, HT) FULLNAME "," #include "clang/StaticAnalyzer/Checkers/Checkers.inc" #undef GET_CHECKERS #define GET_PACKAGES - #define PACKAGE(FULLNAME, G, D) FULLNAME "," + #define PACKAGE(FULLNAME) FULLNAME "," #include "clang/StaticAnalyzer/Checkers/Checkers.inc" #undef GET_PACKAGES ; Index: cfe/trunk/include/clang/StaticAnalyzer/Checkers/CheckerBase.td =================================================================== --- cfe/trunk/include/clang/StaticAnalyzer/Checkers/CheckerBase.td +++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/CheckerBase.td @@ -11,29 +11,34 @@ // //===----------------------------------------------------------------------===// -class CheckerGroup { - string GroupName = name; -} -class InGroup { CheckerGroup Group = G; } - +/// Describes a package. Every checker is a part of a package, for example, +/// 'NullDereference' is part of the 'core' package, hence it's full name is +/// 'core.NullDereference'. +/// Example: +/// def Core : Package<"core">; class Package { string PackageName = name; - bit Hidden = 0; Package ParentPackage; - CheckerGroup Group; } -class InPackage { Package ParentPackage = P; } -// All checkers are an indirect subclass of this. +/// Describes a 'super' package that holds another package inside it. This is +/// used to nest packages in one another. One may, for example, create the +/// 'builtin' package inside 'core', thus creating the package 'core.builtin'. +/// Example: +/// def CoreBuiltin : Package<"builtin">, ParentPackage; +class ParentPackage { Package ParentPackage = P; } + +/// A description. May be displayed to the user when clang is invoked with +/// a '-help'-like command line option. +class HelpText { string HelpText = text; } + +/// Describes a checker. Every builtin checker has to be registered with the use +/// of this class (out-of-trunk checkers loaded from plugins obviously don't). +/// Note that a checker has a name (e.g.: 'NullDereference'), and a fullname, +/// that is autogenerated with the help of the ParentPackage field, that also +/// includes package names (e.g.: 'core.NullDereference'). class Checker { string CheckerName = name; - string DescFile; string HelpText; - bit Hidden = 0; Package ParentPackage; - CheckerGroup Group; } - -class DescFile { string DescFile = filename; } -class HelpText { string HelpText = text; } -class Hidden { bit Hidden = 1; } Index: cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td =================================================================== --- cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td +++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td @@ -21,9 +21,9 @@ def Alpha : Package<"alpha">; def Core : Package<"core">; -def CoreBuiltin : Package<"builtin">, InPackage; -def CoreUninitialized : Package<"uninitialized">, InPackage; -def CoreAlpha : Package<"core">, InPackage, Hidden; +def CoreBuiltin : Package<"builtin">, ParentPackage; +def CoreUninitialized : Package<"uninitialized">, ParentPackage; +def CoreAlpha : Package<"core">, ParentPackage; // The OptIn package is for checkers that are not alpha and that would normally // be on by default but where the driver does not have enough information to @@ -41,59 +41,59 @@ // In the Portability package reside checkers for finding code that relies on // implementation-defined behavior. Such checks are wanted for cross-platform // development, but unwanted for developers who target only a single platform. -def PortabilityOptIn : Package<"portability">, InPackage; +def PortabilityOptIn : Package<"portability">, ParentPackage; def Nullability : Package<"nullability">; def Cplusplus : Package<"cplusplus">; -def CplusplusAlpha : Package<"cplusplus">, InPackage, Hidden; -def CplusplusOptIn : Package<"cplusplus">, InPackage; +def CplusplusAlpha : Package<"cplusplus">, ParentPackage; +def CplusplusOptIn : Package<"cplusplus">, ParentPackage; def Valist : Package<"valist">; def DeadCode : Package<"deadcode">; -def DeadCodeAlpha : Package<"deadcode">, InPackage, Hidden; +def DeadCodeAlpha : Package<"deadcode">, ParentPackage; -def Performance : Package<"performance">, InPackage; +def Performance : Package<"performance">, ParentPackage; def Security : Package <"security">; -def InsecureAPI : Package<"insecureAPI">, InPackage; -def SecurityAlpha : Package<"security">, InPackage, Hidden; -def Taint : Package<"taint">, InPackage, Hidden; +def InsecureAPI : Package<"insecureAPI">, ParentPackage; +def SecurityAlpha : Package<"security">, ParentPackage; +def Taint : Package<"taint">, ParentPackage; def Unix : Package<"unix">; -def UnixAlpha : Package<"unix">, InPackage, Hidden; -def CString : Package<"cstring">, InPackage, Hidden; -def CStringAlpha : Package<"cstring">, InPackage, Hidden; +def UnixAlpha : Package<"unix">, ParentPackage; +def CString : Package<"cstring">, ParentPackage; +def CStringAlpha : Package<"cstring">, ParentPackage; def OSX : Package<"osx">; -def OSXAlpha : Package<"osx">, InPackage, Hidden; -def OSXOptIn : Package<"osx">, InPackage; +def OSXAlpha : Package<"osx">, ParentPackage; +def OSXOptIn : Package<"osx">, ParentPackage; -def Cocoa : Package<"cocoa">, InPackage; -def CocoaAlpha : Package<"cocoa">, InPackage, Hidden; -def CocoaOptIn : Package<"cocoa">, InPackage; +def Cocoa : Package<"cocoa">, ParentPackage; +def CocoaAlpha : Package<"cocoa">, ParentPackage; +def CocoaOptIn : Package<"cocoa">, ParentPackage; -def CoreFoundation : Package<"coreFoundation">, InPackage; -def Containers : Package<"containers">, InPackage; +def CoreFoundation : Package<"coreFoundation">, ParentPackage; +def Containers : Package<"containers">, ParentPackage; -def LocalizabilityAlpha : Package<"localizability">, InPackage; -def LocalizabilityOptIn : Package<"localizability">, InPackage; +def LocalizabilityAlpha : Package<"localizability">, ParentPackage; +def LocalizabilityOptIn : Package<"localizability">, ParentPackage; -def MPI : Package<"mpi">, InPackage; +def MPI : Package<"mpi">, ParentPackage; def LLVM : Package<"llvm">; -def LLVMAlpha : Package<"llvm">, InPackage, Hidden; +def LLVMAlpha : Package<"llvm">, ParentPackage; // The APIModeling package is for checkers that model APIs and don't perform // any diagnostics. These checkers are always turned on; this package is // intended for API modeling that is not controlled by the target triple. -def APIModeling : Package<"apiModeling">, Hidden; -def GoogleAPIModeling : Package<"google">, InPackage; +def APIModeling : Package<"apiModeling">; +def GoogleAPIModeling : Package<"google">, ParentPackage; def Debug : Package<"debug">; -def CloneDetectionAlpha : Package<"clone">, InPackage, Hidden; +def CloneDetectionAlpha : Package<"clone">, ParentPackage; //===----------------------------------------------------------------------===// // Core Checkers. @@ -102,132 +102,118 @@ let ParentPackage = Core in { def DereferenceChecker : Checker<"NullDereference">, - HelpText<"Check for dereferences of null pointers">, - DescFile<"DereferenceChecker.cpp">; + HelpText<"Check for dereferences of null pointers">; def CallAndMessageChecker : Checker<"CallAndMessage">, - HelpText<"Check for logical errors for function calls and Objective-C message expressions (e.g., uninitialized arguments, null function pointers)">, - DescFile<"CallAndMessageChecker.cpp">; + HelpText<"Check for logical errors for function calls and Objective-C " + "message expressions (e.g., uninitialized arguments, null function " + "pointers)">; def NonNullParamChecker : Checker<"NonNullParamChecker">, - HelpText<"Check for null pointers passed as arguments to a function whose arguments are references or marked with the 'nonnull' attribute">, - DescFile<"NonNullParamChecker.cpp">; + HelpText<"Check for null pointers passed as arguments to a function whose " + "arguments are references or marked with the 'nonnull' attribute">; def VLASizeChecker : Checker<"VLASize">, - HelpText<"Check for declarations of VLA of undefined or zero size">, - DescFile<"VLASizeChecker.cpp">; + HelpText<"Check for declarations of VLA of undefined or zero size">; def DivZeroChecker : Checker<"DivideZero">, - HelpText<"Check for division by zero">, - DescFile<"DivZeroChecker.cpp">; + HelpText<"Check for division by zero">; def UndefResultChecker : Checker<"UndefinedBinaryOperatorResult">, - HelpText<"Check for undefined results of binary operators">, - DescFile<"UndefResultChecker.cpp">; + HelpText<"Check for undefined results of binary operators">; def StackAddrEscapeChecker : Checker<"StackAddressEscape">, - HelpText<"Check that addresses to stack memory do not escape the function">, - DescFile<"StackAddrEscapeChecker.cpp">; + HelpText<"Check that addresses to stack memory do not escape the function">; def DynamicTypePropagation : Checker<"DynamicTypePropagation">, - HelpText<"Generate dynamic type information">, - DescFile<"DynamicTypePropagation.cpp">; + HelpText<"Generate dynamic type information">; def NonnullGlobalConstantsChecker: Checker<"NonnilStringConstants">, - HelpText<"Assume that const string-like globals are non-null">, - DescFile<"NonilStringConstantsChecker.cpp">; + HelpText<"Assume that const string-like globals are non-null">; } // end "core" let ParentPackage = CoreAlpha in { def BoolAssignmentChecker : Checker<"BoolAssignment">, - HelpText<"Warn about assigning non-{0,1} values to Boolean variables">, - DescFile<"BoolAssignmentChecker.cpp">; + HelpText<"Warn about assigning non-{0,1} values to Boolean variables">; def CastSizeChecker : Checker<"CastSize">, - HelpText<"Check when casting a malloc'ed type T, whether the size is a multiple of the size of T">, - DescFile<"CastSizeChecker.cpp">; + HelpText<"Check when casting a malloc'ed type T, whether the size is a " + "multiple of the size of T">; def CastToStructChecker : Checker<"CastToStruct">, - HelpText<"Check for cast from non-struct pointer to struct pointer">, - DescFile<"CastToStructChecker.cpp">; + HelpText<"Check for cast from non-struct pointer to struct pointer">; def ConversionChecker : Checker<"Conversion">, - HelpText<"Loss of sign/precision in implicit conversions">, - DescFile<"ConversionChecker.cpp">; + HelpText<"Loss of sign/precision in implicit conversions">; def IdenticalExprChecker : Checker<"IdenticalExpr">, - HelpText<"Warn about unintended use of identical expressions in operators">, - DescFile<"IdenticalExprChecker.cpp">; + HelpText<"Warn about unintended use of identical expressions in operators">; def FixedAddressChecker : Checker<"FixedAddr">, - HelpText<"Check for assignment of a fixed address to a pointer">, - DescFile<"FixedAddressChecker.cpp">; + HelpText<"Check for assignment of a fixed address to a pointer">; def PointerArithChecker : Checker<"PointerArithm">, - HelpText<"Check for pointer arithmetic on locations other than array elements">, - DescFile<"PointerArithChecker">; + HelpText<"Check for pointer arithmetic on locations other than array " + "elements">; def PointerSubChecker : Checker<"PointerSub">, - HelpText<"Check for pointer subtractions on two pointers pointing to different memory chunks">, - DescFile<"PointerSubChecker">; + HelpText<"Check for pointer subtractions on two pointers pointing to " + "different memory chunks">; def SizeofPointerChecker : Checker<"SizeofPtr">, - HelpText<"Warn about unintended use of sizeof() on pointer expressions">, - DescFile<"CheckSizeofPointer.cpp">; + HelpText<"Warn about unintended use of sizeof() on pointer expressions">; def CallAndMessageUnInitRefArg : Checker<"CallAndMessageUnInitRefArg">, - HelpText<"Check for logical errors for function calls and Objective-C message expressions (e.g., uninitialized arguments, null function pointers, and pointer to undefined variables)">, - DescFile<"CallAndMessageChecker.cpp">; + HelpText<"Check for logical errors for function calls and Objective-C " + "message expressions (e.g., uninitialized arguments, null function " + "pointers, and pointer to undefined variables)">; def TestAfterDivZeroChecker : Checker<"TestAfterDivZero">, - HelpText<"Check for division by variable that is later compared against 0. Either the comparison is useless or there is division by zero.">, - DescFile<"TestAfterDivZeroChecker.cpp">; + HelpText<"Check for division by variable that is later compared against 0. " + "Either the comparison is useless or there is division by zero.">; def DynamicTypeChecker : Checker<"DynamicTypeChecker">, - HelpText<"Check for cases where the dynamic and the static type of an object are unrelated.">, - DescFile<"DynamicTypeChecker.cpp">; + HelpText<"Check for cases where the dynamic and the static type of an object " + "are unrelated.">; def StackAddrAsyncEscapeChecker : Checker<"StackAddressAsyncEscape">, - HelpText<"Check that addresses to stack memory do not escape the function">, - DescFile<"StackAddrEscapeChecker.cpp">; + HelpText<"Check that addresses to stack memory do not escape the function">; } // end "alpha.core" let ParentPackage = Nullability in { def NullPassedToNonnullChecker : Checker<"NullPassedToNonnull">, - HelpText<"Warns when a null pointer is passed to a pointer which has a _Nonnull type.">, - DescFile<"NullabilityChecker.cpp">; + HelpText<"Warns when a null pointer is passed to a pointer which has a " + "_Nonnull type.">; def NullReturnedFromNonnullChecker : Checker<"NullReturnedFromNonnull">, - HelpText<"Warns when a null pointer is returned from a function that has _Nonnull return type.">, - DescFile<"NullabilityChecker.cpp">; + HelpText<"Warns when a null pointer is returned from a function that has " + "_Nonnull return type.">; def NullableDereferencedChecker : Checker<"NullableDereferenced">, - HelpText<"Warns when a nullable pointer is dereferenced.">, - DescFile<"NullabilityChecker.cpp">; + HelpText<"Warns when a nullable pointer is dereferenced.">; def NullablePassedToNonnullChecker : Checker<"NullablePassedToNonnull">, - HelpText<"Warns when a nullable pointer is passed to a pointer which has a _Nonnull type.">, - DescFile<"NullabilityChecker.cpp">; + HelpText<"Warns when a nullable pointer is passed to a pointer which has a " + "_Nonnull type.">; def NullableReturnedFromNonnullChecker : Checker<"NullableReturnedFromNonnull">, - HelpText<"Warns when a nullable pointer is returned from a function that has _Nonnull return type.">, - DescFile<"NullabilityChecker.cpp">; + HelpText<"Warns when a nullable pointer is returned from a function that has " + "_Nonnull return type.">; } // end "nullability" let ParentPackage = APIModeling in { def StdCLibraryFunctionsChecker : Checker<"StdCLibraryFunctions">, - HelpText<"Improve modeling of the C standard library functions">, - DescFile<"StdLibraryFunctionsChecker.cpp">; + HelpText<"Improve modeling of the C standard library functions">; def TrustNonnullChecker : Checker<"TrustNonnull">, - HelpText<"Trust that returns from framework methods annotated with _Nonnull are not null">, - DescFile<"TrustNonnullChecker.cpp">; + HelpText<"Trust that returns from framework methods annotated with _Nonnull " + "are not null">; } // end "apiModeling" @@ -238,12 +224,11 @@ let ParentPackage = CoreBuiltin in { def NoReturnFunctionChecker : Checker<"NoReturnFunctions">, - HelpText<"Evaluate \"panic\" functions that are known to not return to the caller">, - DescFile<"NoReturnFunctionChecker.cpp">; + HelpText<"Evaluate \"panic\" functions that are known to not return to the " + "caller">; def BuiltinFunctionChecker : Checker<"BuiltinFunctions">, - HelpText<"Evaluate compiler builtin functions (e.g., alloca())">, - DescFile<"BuiltinFunctionChecker.cpp">; + HelpText<"Evaluate compiler builtin functions (e.g., alloca())">; } // end "core.builtin" @@ -254,24 +239,19 @@ let ParentPackage = CoreUninitialized in { def UndefinedArraySubscriptChecker : Checker<"ArraySubscript">, - HelpText<"Check for uninitialized values used as array subscripts">, - DescFile<"UndefinedArraySubscriptChecker.cpp">; + HelpText<"Check for uninitialized values used as array subscripts">; def UndefinedAssignmentChecker : Checker<"Assign">, - HelpText<"Check for assigning uninitialized values">, - DescFile<"UndefinedAssignmentChecker.cpp">; + HelpText<"Check for assigning uninitialized values">; def UndefBranchChecker : Checker<"Branch">, - HelpText<"Check for uninitialized values used as branch conditions">, - DescFile<"UndefBranchChecker.cpp">; + HelpText<"Check for uninitialized values used as branch conditions">; def UndefCapturedBlockVarChecker : Checker<"CapturedBlockVariable">, - HelpText<"Check for blocks that capture uninitialized values">, - DescFile<"UndefCapturedBlockVarChecker.cpp">; + HelpText<"Check for blocks that capture uninitialized values">; def ReturnUndefChecker : Checker<"UndefReturn">, - HelpText<"Check for uninitialized values being returned to the caller">, - DescFile<"ReturnUndefChecker.cpp">; + HelpText<"Check for uninitialized values being returned to the caller">; } // end "core.uninitialized" @@ -282,28 +262,25 @@ let ParentPackage = Cplusplus in { def InnerPointerChecker : Checker<"InnerPointer">, - HelpText<"Check for inner pointers of C++ containers used after re/deallocation">, - DescFile<"InnerPointerChecker.cpp">; + HelpText<"Check for inner pointers of C++ containers used after " + "re/deallocation">; def NewDeleteChecker : Checker<"NewDelete">, - HelpText<"Check for double-free and use-after-free problems. Traces memory managed by new/delete.">, - DescFile<"MallocChecker.cpp">; + HelpText<"Check for double-free and use-after-free problems. Traces memory " + "managed by new/delete.">; def NewDeleteLeaksChecker : Checker<"NewDeleteLeaks">, - HelpText<"Check for memory leaks. Traces memory managed by new/delete.">, - DescFile<"MallocChecker.cpp">; + HelpText<"Check for memory leaks. Traces memory managed by new/delete.">; def CXXSelfAssignmentChecker : Checker<"SelfAssignment">, - HelpText<"Checks C++ copy and move assignment operators for self assignment">, - DescFile<"CXXSelfAssignmentChecker.cpp">; + HelpText<"Checks C++ copy and move assignment operators for self assignment">; } // end: "cplusplus" let ParentPackage = CplusplusOptIn in { def VirtualCallChecker : Checker<"VirtualCall">, - HelpText<"Check virtual function calls during construction or destruction">, - DescFile<"VirtualCallChecker.cpp">; + HelpText<"Check virtual function calls during construction or destruction">; } // end: "optin.cplusplus" @@ -311,29 +288,24 @@ def DeleteWithNonVirtualDtorChecker : Checker<"DeleteWithNonVirtualDtor">, HelpText<"Reports destructions of polymorphic objects with a non-virtual " - "destructor in their base class">, - DescFile<"DeleteWithNonVirtualDtorChecker.cpp">; + "destructor in their base class">; def InvalidatedIteratorChecker : Checker<"InvalidatedIterator">, - HelpText<"Check for use of invalidated iterators">, - DescFile<"IteratorChecker.cpp">; + HelpText<"Check for use of invalidated iterators">; def IteratorRangeChecker : Checker<"IteratorRange">, - HelpText<"Check for iterators used outside their valid ranges">, - DescFile<"IteratorChecker.cpp">; + HelpText<"Check for iterators used outside their valid ranges">; def MismatchedIteratorChecker : Checker<"MismatchedIterator">, - HelpText<"Check for use of iterators of different containers where iterators of the same container are expected">, - DescFile<"IteratorChecker.cpp">; + HelpText<"Check for use of iterators of different containers where iterators " + "of the same container are expected">; def MisusedMovedObjectChecker: Checker<"MisusedMovedObject">, HelpText<"Method calls on a moved-from object and copying a moved-from " - "object will be reported">, - DescFile<"MisusedMovedObjectChecker.cpp">; + "object will be reported">; def UninitializedObjectChecker: Checker<"UninitializedObject">, - HelpText<"Reports uninitialized fields after object construction">, - DescFile<"UninitializedObjectChecker.cpp">; + HelpText<"Reports uninitialized fields after object construction">; } // end: "alpha.cplusplus" @@ -345,16 +317,13 @@ let ParentPackage = Valist in { def UninitializedChecker : Checker<"Uninitialized">, - HelpText<"Check for usages of uninitialized (or already released) va_lists.">, - DescFile<"ValistChecker.cpp">; + HelpText<"Check for usages of uninitialized (or already released) va_lists.">; def UnterminatedChecker : Checker<"Unterminated">, - HelpText<"Check for va_lists which are not released by a va_end call.">, - DescFile<"ValistChecker.cpp">; + HelpText<"Check for va_lists which are not released by a va_end call.">; def CopyToSelfChecker : Checker<"CopyToSelf">, - HelpText<"Check for va_lists which are copied onto itself.">, - DescFile<"ValistChecker.cpp">; + HelpText<"Check for va_lists which are copied onto itself.">; } // end : "valist" @@ -365,15 +334,15 @@ let ParentPackage = DeadCode in { def DeadStoresChecker : Checker<"DeadStores">, - HelpText<"Check for values stored to variables that are never read afterwards">, - DescFile<"DeadStoresChecker.cpp">; + HelpText<"Check for values stored to variables that are never read " + "afterwards">; + } // end DeadCode let ParentPackage = DeadCodeAlpha in { def UnreachableCodeChecker : Checker<"UnreachableCode">, - HelpText<"Check unreachable code">, - DescFile<"UnreachableCodeChecker.cpp">; + HelpText<"Check unreachable code">; } // end "alpha.deadcode" @@ -384,8 +353,7 @@ let ParentPackage = Performance in { def PaddingChecker : Checker<"Padding">, - HelpText<"Check for excessively padded structs.">, - DescFile<"PaddingChecker.cpp">; + HelpText<"Check for excessively padded structs.">; } // end: "padding" @@ -394,70 +362,61 @@ //===----------------------------------------------------------------------===// let ParentPackage = InsecureAPI in { - def bcmp : Checker<"bcmp">, - HelpText<"Warn on uses of the 'bcmp' function">, - DescFile<"CheckSecuritySyntaxOnly.cpp">; - def bcopy : Checker<"bcopy">, - HelpText<"Warn on uses of the 'bcopy' function">, - DescFile<"CheckSecuritySyntaxOnly.cpp">; - def bzero : Checker<"bzero">, - HelpText<"Warn on uses of the 'bzero' function">, - DescFile<"CheckSecuritySyntaxOnly.cpp">; - def gets : Checker<"gets">, - HelpText<"Warn on uses of the 'gets' function">, - DescFile<"CheckSecuritySyntaxOnly.cpp">; - def getpw : Checker<"getpw">, - HelpText<"Warn on uses of the 'getpw' function">, - DescFile<"CheckSecuritySyntaxOnly.cpp">; - def mktemp : Checker<"mktemp">, - HelpText<"Warn on uses of the 'mktemp' function">, - DescFile<"CheckSecuritySyntaxOnly.cpp">; - def mkstemp : Checker<"mkstemp">, - HelpText<"Warn when 'mkstemp' is passed fewer than 6 X's in the format string">, - DescFile<"CheckSecuritySyntaxOnly.cpp">; - def rand : Checker<"rand">, - HelpText<"Warn on uses of the 'rand', 'random', and related functions">, - DescFile<"CheckSecuritySyntaxOnly.cpp">; - def strcpy : Checker<"strcpy">, - HelpText<"Warn on uses of the 'strcpy' and 'strcat' functions">, - DescFile<"CheckSecuritySyntaxOnly.cpp">; - def vfork : Checker<"vfork">, - HelpText<"Warn on uses of the 'vfork' function">, - DescFile<"CheckSecuritySyntaxOnly.cpp">; - def UncheckedReturn : Checker<"UncheckedReturn">, - HelpText<"Warn on uses of functions whose return values must be always checked">, - DescFile<"CheckSecuritySyntaxOnly.cpp">; -} + +def bcmp : Checker<"bcmp">, + HelpText<"Warn on uses of the 'bcmp' function">; +def bcopy : Checker<"bcopy">, + HelpText<"Warn on uses of the 'bcopy' function">; +def bzero : Checker<"bzero">, + HelpText<"Warn on uses of the 'bzero' function">; +def gets : Checker<"gets">, + HelpText<"Warn on uses of the 'gets' function">; +def getpw : Checker<"getpw">, + HelpText<"Warn on uses of the 'getpw' function">; +def mktemp : Checker<"mktemp">, + HelpText<"Warn on uses of the 'mktemp' function">; +def mkstemp : Checker<"mkstemp">, + HelpText<"Warn when 'mkstemp' is passed fewer than 6 X's in the format " + "string">; +def rand : Checker<"rand">, + HelpText<"Warn on uses of the 'rand', 'random', and related functions">; +def strcpy : Checker<"strcpy">, + HelpText<"Warn on uses of the 'strcpy' and 'strcat' functions">; +def vfork : Checker<"vfork">, + HelpText<"Warn on uses of the 'vfork' function">; +def UncheckedReturn : Checker<"UncheckedReturn">, + HelpText<"Warn on uses of functions whose return values must be always " + "checked">; + +} // end "security.insecureAPI" + let ParentPackage = Security in { - def FloatLoopCounter : Checker<"FloatLoopCounter">, - HelpText<"Warn on using a floating point value as a loop counter (CERT: FLP30-C, FLP30-CPP)">, - DescFile<"CheckSecuritySyntaxOnly.cpp">; -} + +def FloatLoopCounter : Checker<"FloatLoopCounter">, + HelpText<"Warn on using a floating point value as a loop counter (CERT: " + "FLP30-C, FLP30-CPP)">; + +} // end "security" let ParentPackage = SecurityAlpha in { def ArrayBoundChecker : Checker<"ArrayBound">, - HelpText<"Warn about buffer overflows (older checker)">, - DescFile<"ArrayBoundChecker.cpp">; + HelpText<"Warn about buffer overflows (older checker)">; def ArrayBoundCheckerV2 : Checker<"ArrayBoundV2">, - HelpText<"Warn about buffer overflows (newer checker)">, - DescFile<"ArrayBoundCheckerV2.cpp">; + HelpText<"Warn about buffer overflows (newer checker)">; def ReturnPointerRangeChecker : Checker<"ReturnPtrRange">, - HelpText<"Check for an out-of-bound pointer being returned to callers">, - DescFile<"ReturnPointerRangeChecker.cpp">; + HelpText<"Check for an out-of-bound pointer being returned to callers">; def MallocOverflowSecurityChecker : Checker<"MallocOverflow">, - HelpText<"Check for overflows in the arguments to malloc()">, - DescFile<"MallocOverflowSecurityChecker.cpp">; + HelpText<"Check for overflows in the arguments to malloc()">; // Operating systems specific PROT_READ/PROT_WRITE values is not implemented, // the defaults are correct for several common operating systems though, // but may need to be overridden via the related analyzer-config flags. def MmapWriteExecChecker : Checker<"MmapWriteExec">, - HelpText<"Warn on mmap() calls that are both writable and executable">, - DescFile<"MmapWriteExecChecker.cpp">; + HelpText<"Warn on mmap() calls that are both writable and executable">; } // end "alpha.security" @@ -468,8 +427,7 @@ let ParentPackage = Taint in { def GenericTaintChecker : Checker<"TaintPropagation">, - HelpText<"Generate taint information used by other checkers">, - DescFile<"GenericTaintChecker.cpp">; + HelpText<"Generate taint information used by other checkers">; } // end "alpha.security.taint" @@ -480,76 +438,66 @@ let ParentPackage = Unix in { def UnixAPIMisuseChecker : Checker<"API">, - HelpText<"Check calls to various UNIX/Posix functions">, - DescFile<"UnixAPIChecker.cpp">; + HelpText<"Check calls to various UNIX/Posix functions">; def MallocChecker: Checker<"Malloc">, - HelpText<"Check for memory leaks, double free, and use-after-free problems. Traces memory managed by malloc()/free().">, - DescFile<"MallocChecker.cpp">; + HelpText<"Check for memory leaks, double free, and use-after-free problems. " + "Traces memory managed by malloc()/free().">; def MallocSizeofChecker : Checker<"MallocSizeof">, - HelpText<"Check for dubious malloc arguments involving sizeof">, - DescFile<"MallocSizeofChecker.cpp">; + HelpText<"Check for dubious malloc arguments involving sizeof">; def MismatchedDeallocatorChecker : Checker<"MismatchedDeallocator">, - HelpText<"Check for mismatched deallocators.">, - DescFile<"MallocChecker.cpp">; + HelpText<"Check for mismatched deallocators.">; def VforkChecker : Checker<"Vfork">, - HelpText<"Check for proper usage of vfork">, - DescFile<"VforkChecker.cpp">; + HelpText<"Check for proper usage of vfork">; } // end "unix" let ParentPackage = UnixAlpha in { def ChrootChecker : Checker<"Chroot">, - HelpText<"Check improper use of chroot">, - DescFile<"ChrootChecker.cpp">; + HelpText<"Check improper use of chroot">; def PthreadLockChecker : Checker<"PthreadLock">, - HelpText<"Simple lock -> unlock checker">, - DescFile<"PthreadLockChecker.cpp">; + HelpText<"Simple lock -> unlock checker">; def StreamChecker : Checker<"Stream">, - HelpText<"Check stream handling functions">, - DescFile<"StreamChecker.cpp">; + HelpText<"Check stream handling functions">; def SimpleStreamChecker : Checker<"SimpleStream">, - HelpText<"Check for misuses of stream APIs">, - DescFile<"SimpleStreamChecker.cpp">; + HelpText<"Check for misuses of stream APIs">; def BlockInCriticalSectionChecker : Checker<"BlockInCriticalSection">, - HelpText<"Check for calls to blocking functions inside a critical section">, - DescFile<"BlockInCriticalSectionChecker.cpp">; + HelpText<"Check for calls to blocking functions inside a critical section">; } // end "alpha.unix" let ParentPackage = CString in { def CStringNullArg : Checker<"NullArg">, - HelpText<"Check for null pointers being passed as arguments to C string functions">, - DescFile<"CStringChecker.cpp">; + HelpText<"Check for null pointers being passed as arguments to C string " + "functions">; def CStringSyntaxChecker : Checker<"BadSizeArg">, - HelpText<"Check the size argument passed into C string functions for common erroneous patterns">, - DescFile<"CStringSyntaxChecker.cpp">; -} + HelpText<"Check the size argument passed into C string functions for common " + "erroneous patterns">; + +} // end "unix.cstring" let ParentPackage = CStringAlpha in { def CStringOutOfBounds : Checker<"OutOfBounds">, - HelpText<"Check for out-of-bounds access in string functions">, - DescFile<"CStringChecker.cpp">; + HelpText<"Check for out-of-bounds access in string functions">; def CStringBufferOverlap : Checker<"BufferOverlap">, - HelpText<"Checks for overlap in two buffer arguments">, - DescFile<"CStringChecker.cpp">; + HelpText<"Checks for overlap in two buffer arguments">; def CStringNotNullTerm : Checker<"NotNullTerminated">, - HelpText<"Check for arguments which are not null-terminating strings">, - DescFile<"CStringChecker.cpp">; -} + HelpText<"Check for arguments which are not null-terminating strings">; + +} // end "alpha.unix.cstring" //===----------------------------------------------------------------------===// // Mac OS X, Cocoa, and Core Foundation checkers. @@ -558,193 +506,186 @@ let ParentPackage = OSX in { def NumberObjectConversionChecker : Checker<"NumberObjectConversion">, - HelpText<"Check for erroneous conversions of objects representing numbers into numbers">, - DescFile<"NumberObjectConversionChecker.cpp">; + HelpText<"Check for erroneous conversions of objects representing numbers " + "into numbers">; def MacOSXAPIChecker : Checker<"API">, - HelpText<"Check for proper uses of various Apple APIs">, - DescFile<"MacOSXAPIChecker.cpp">; + HelpText<"Check for proper uses of various Apple APIs">; def MacOSKeychainAPIChecker : Checker<"SecKeychainAPI">, - HelpText<"Check for proper uses of Secure Keychain APIs">, - DescFile<"MacOSKeychainAPIChecker.cpp">; + HelpText<"Check for proper uses of Secure Keychain APIs">; def ObjCPropertyChecker : Checker<"ObjCProperty">, - HelpText<"Check for proper uses of Objective-C properties">, - DescFile<"ObjCPropertyChecker.cpp">; + HelpText<"Check for proper uses of Objective-C properties">; } // end "osx" let ParentPackage = Cocoa in { def RunLoopAutoreleaseLeakChecker : Checker<"RunLoopAutoreleaseLeak">, - HelpText<"Check for leaked memory in autorelease pools that will never be drained">, - DescFile<"RunLoopAutoreleaseLeakChecker.cpp">; + HelpText<"Check for leaked memory in autorelease pools that will never be " + "drained">; def ObjCAtSyncChecker : Checker<"AtSync">, - HelpText<"Check for nil pointers used as mutexes for @synchronized">, - DescFile<"ObjCAtSyncChecker.cpp">; + HelpText<"Check for nil pointers used as mutexes for @synchronized">; def NilArgChecker : Checker<"NilArg">, - HelpText<"Check for prohibited nil arguments to ObjC method calls">, - DescFile<"BasicObjCFoundationChecks.cpp">; + HelpText<"Check for prohibited nil arguments to ObjC method calls">; def ClassReleaseChecker : Checker<"ClassRelease">, - HelpText<"Check for sending 'retain', 'release', or 'autorelease' directly to a Class">, - DescFile<"BasicObjCFoundationChecks.cpp">; + HelpText<"Check for sending 'retain', 'release', or 'autorelease' directly " + "to a Class">; def VariadicMethodTypeChecker : Checker<"VariadicMethodTypes">, HelpText<"Check for passing non-Objective-C types to variadic collection " - "initialization methods that expect only Objective-C types">, - DescFile<"BasicObjCFoundationChecks.cpp">; + "initialization methods that expect only Objective-C types">; def NSAutoreleasePoolChecker : Checker<"NSAutoreleasePool">, - HelpText<"Warn for suboptimal uses of NSAutoreleasePool in Objective-C GC mode">, - DescFile<"NSAutoreleasePoolChecker.cpp">; + HelpText<"Warn for suboptimal uses of NSAutoreleasePool in Objective-C GC " + "mode">; def ObjCMethSigsChecker : Checker<"IncompatibleMethodTypes">, - HelpText<"Warn about Objective-C method signatures with type incompatibilities">, - DescFile<"CheckObjCInstMethSignature.cpp">; + HelpText<"Warn about Objective-C method signatures with type " + "incompatibilities">; def ObjCUnusedIvarsChecker : Checker<"UnusedIvars">, - HelpText<"Warn about private ivars that are never used">, - DescFile<"ObjCUnusedIVarsChecker.cpp">; + HelpText<"Warn about private ivars that are never used">; def ObjCSelfInitChecker : Checker<"SelfInit">, - HelpText<"Check that 'self' is properly initialized inside an initializer method">, - DescFile<"ObjCSelfInitChecker.cpp">; + HelpText<"Check that 'self' is properly initialized inside an initializer " + "method">; def ObjCLoopChecker : Checker<"Loops">, - HelpText<"Improved modeling of loops using Cocoa collection types">, - DescFile<"BasicObjCFoundationChecks.cpp">; + HelpText<"Improved modeling of loops using Cocoa collection types">; def ObjCNonNilReturnValueChecker : Checker<"NonNilReturnValue">, - HelpText<"Model the APIs that are guaranteed to return a non-nil value">, - DescFile<"BasicObjCFoundationChecks.cpp">; + HelpText<"Model the APIs that are guaranteed to return a non-nil value">; def ObjCSuperCallChecker : Checker<"MissingSuperCall">, - HelpText<"Warn about Objective-C methods that lack a necessary call to super">, - DescFile<"ObjCMissingSuperCallChecker.cpp">; + HelpText<"Warn about Objective-C methods that lack a necessary call to " + "super">; def NSErrorChecker : Checker<"NSError">, - HelpText<"Check usage of NSError** parameters">, - DescFile<"NSErrorChecker.cpp">; + HelpText<"Check usage of NSError** parameters">; def RetainCountChecker : Checker<"RetainCount">, - HelpText<"Check for leaks and improper reference count management">, - DescFile<"RetainCountChecker.cpp">; + HelpText<"Check for leaks and improper reference count management">; def ObjCGenericsChecker : Checker<"ObjCGenerics">, - HelpText<"Check for type errors when using Objective-C generics">, - DescFile<"DynamicTypePropagation.cpp">; + HelpText<"Check for type errors when using Objective-C generics">; def ObjCDeallocChecker : Checker<"Dealloc">, - HelpText<"Warn about Objective-C classes that lack a correct implementation of -dealloc">, - DescFile<"CheckObjCDealloc.cpp">; + HelpText<"Warn about Objective-C classes that lack a correct implementation " + "of -dealloc">; def ObjCSuperDeallocChecker : Checker<"SuperDealloc">, - HelpText<"Warn about improper use of '[super dealloc]' in Objective-C">, - DescFile<"ObjCSuperDeallocChecker.cpp">; + HelpText<"Warn about improper use of '[super dealloc]' in Objective-C">; def AutoreleaseWriteChecker : Checker<"AutoreleaseWrite">, - HelpText<"Warn about potentially crashing writes to autoreleasing objects from different autoreleasing pools in Objective-C">, - DescFile<"ObjCAutoreleaseWriteChecker.cpp">; + HelpText<"Warn about potentially crashing writes to autoreleasing objects " + "from different autoreleasing pools in Objective-C">; + } // end "osx.cocoa" let ParentPackage = Performance in { def GCDAntipattern : Checker<"GCDAntipattern">, - HelpText<"Check for performance anti-patterns when using Grand Central Dispatch">, - DescFile<"GCDAntipatternChecker.cpp">; + HelpText<"Check for performance anti-patterns when using Grand Central " + "Dispatch">; } // end "optin.performance" let ParentPackage = CocoaAlpha in { def InstanceVariableInvalidation : Checker<"InstanceVariableInvalidation">, - HelpText<"Check that the invalidatable instance variables are invalidated in the methods annotated with objc_instance_variable_invalidator">, - DescFile<"IvarInvalidationChecker.cpp">; + HelpText<"Check that the invalidatable instance variables are invalidated in " + "the methods annotated with objc_instance_variable_invalidator">; def MissingInvalidationMethod : Checker<"MissingInvalidationMethod">, - HelpText<"Check that the invalidation methods are present in classes that contain invalidatable instance variables">, - DescFile<"IvarInvalidationChecker.cpp">; + HelpText<"Check that the invalidation methods are present in classes that " + "contain invalidatable instance variables">; def DirectIvarAssignment : Checker<"DirectIvarAssignment">, - HelpText<"Check for direct assignments to instance variables">, - DescFile<"DirectIvarAssignment.cpp">; + HelpText<"Check for direct assignments to instance variables">; -def DirectIvarAssignmentForAnnotatedFunctions : Checker<"DirectIvarAssignmentForAnnotatedFunctions">, - HelpText<"Check for direct assignments to instance variables in the methods annotated with objc_no_direct_instance_variable_assignment">, - DescFile<"DirectIvarAssignment.cpp">; +def DirectIvarAssignmentForAnnotatedFunctions : + Checker<"DirectIvarAssignmentForAnnotatedFunctions">, + HelpText<"Check for direct assignments to instance variables in the methods " + "annotated with objc_no_direct_instance_variable_assignment">; } // end "alpha.osx.cocoa" let ParentPackage = CoreFoundation in { def CFNumberChecker : Checker<"CFNumber">, - HelpText<"Check for proper uses of CFNumber APIs">, - DescFile<"BasicObjCFoundationChecks.cpp">; + HelpText<"Check for proper uses of CFNumber APIs">; def CFRetainReleaseChecker : Checker<"CFRetainRelease">, - HelpText<"Check for null arguments to CFRetain/CFRelease/CFMakeCollectable">, - DescFile<"BasicObjCFoundationChecks.cpp">; + HelpText<"Check for null arguments to CFRetain/CFRelease/CFMakeCollectable">; def CFErrorChecker : Checker<"CFError">, - HelpText<"Check usage of CFErrorRef* parameters">, - DescFile<"NSErrorChecker.cpp">; -} + HelpText<"Check usage of CFErrorRef* parameters">; + +} // end "osx.coreFoundation" let ParentPackage = Containers in { + def ObjCContainersASTChecker : Checker<"PointerSizedValues">, - HelpText<"Warns if 'CFArray', 'CFDictionary', 'CFSet' are created with non-pointer-size values">, - DescFile<"ObjCContainersASTChecker.cpp">; + HelpText<"Warns if 'CFArray', 'CFDictionary', 'CFSet' are created with " + "non-pointer-size values">; def ObjCContainersChecker : Checker<"OutOfBounds">, - HelpText<"Checks for index out-of-bounds when using 'CFArray' API">, - DescFile<"ObjCContainersChecker.cpp">; + HelpText<"Checks for index out-of-bounds when using 'CFArray' API">; -} +} // end "osx.coreFoundation.containers" let ParentPackage = LocalizabilityOptIn in { + def NonLocalizedStringChecker : Checker<"NonLocalizedStringChecker">, - HelpText<"Warns about uses of non-localized NSStrings passed to UI methods expecting localized NSStrings">, - DescFile<"LocalizationChecker.cpp">; + HelpText<"Warns about uses of non-localized NSStrings passed to UI methods " + "expecting localized NSStrings">; + +def EmptyLocalizationContextChecker : + Checker<"EmptyLocalizationContextChecker">, + HelpText<"Check that NSLocalizedString macros include a comment for context">; -def EmptyLocalizationContextChecker : Checker<"EmptyLocalizationContextChecker">, - HelpText<"Check that NSLocalizedString macros include a comment for context">, - DescFile<"LocalizationChecker.cpp">; -} +} // end "optin.osx.cocoa.localizability" let ParentPackage = LocalizabilityAlpha in { + def PluralMisuseChecker : Checker<"PluralMisuseChecker">, - HelpText<"Warns against using one vs. many plural pattern in code when generating localized strings.">, - DescFile<"LocalizationChecker.cpp">; -} + HelpText<"Warns against using one vs. many plural pattern in code when " + "generating localized strings.">; + +} // end "alpha.osx.cocoa.localizability" let ParentPackage = MPI in { - def MPIChecker : Checker<"MPI-Checker">, - HelpText<"Checks MPI code">, - DescFile<"MPIChecker.cpp">; -} + +def MPIChecker : Checker<"MPI-Checker">, + HelpText<"Checks MPI code">; + +} // end "optin.mpi" //===----------------------------------------------------------------------===// // Checkers for LLVM development. //===----------------------------------------------------------------------===// -def LLVMConventionsChecker : Checker<"Conventions">, - InPackage, - HelpText<"Check code for LLVM codebase conventions">, - DescFile<"LLVMConventionsChecker.cpp">; +let ParentPackage = LLVMAlpha in { +def LLVMConventionsChecker : Checker<"Conventions">, + HelpText<"Check code for LLVM codebase conventions">; +} // end "llvm" //===----------------------------------------------------------------------===// // Checkers modeling Google APIs. //===----------------------------------------------------------------------===// +let ParentPackage = GoogleAPIModeling in { + def GTestChecker : Checker<"GTest">, - InPackage, - HelpText<"Model gtest assertion APIs">, - DescFile<"GTestChecker.cpp">; + HelpText<"Model gtest assertion APIs">; + +} // end "apiModeling.google" //===----------------------------------------------------------------------===// // Debugging checkers (for analyzer development). @@ -753,60 +694,46 @@ let ParentPackage = Debug in { def AnalysisOrderChecker : Checker<"AnalysisOrder">, - HelpText<"Print callbacks that are called during analysis in order">, - DescFile<"AnalysisOrder.cpp">; + HelpText<"Print callbacks that are called during analysis in order">; def DominatorsTreeDumper : Checker<"DumpDominators">, - HelpText<"Print the dominance tree for a given CFG">, - DescFile<"DebugCheckers.cpp">; + HelpText<"Print the dominance tree for a given CFG">; def LiveVariablesDumper : Checker<"DumpLiveVars">, - HelpText<"Print results of live variable analysis">, - DescFile<"DebugCheckers.cpp">; + HelpText<"Print results of live variable analysis">; def CFGViewer : Checker<"ViewCFG">, - HelpText<"View Control-Flow Graphs using GraphViz">, - DescFile<"DebugCheckers.cpp">; + HelpText<"View Control-Flow Graphs using GraphViz">; def CFGDumper : Checker<"DumpCFG">, - HelpText<"Display Control-Flow Graphs">, - DescFile<"DebugCheckers.cpp">; + HelpText<"Display Control-Flow Graphs">; def CallGraphViewer : Checker<"ViewCallGraph">, - HelpText<"View Call Graph using GraphViz">, - DescFile<"DebugCheckers.cpp">; + HelpText<"View Call Graph using GraphViz">; def CallGraphDumper : Checker<"DumpCallGraph">, - HelpText<"Display Call Graph">, - DescFile<"DebugCheckers.cpp">; + HelpText<"Display Call Graph">; def ConfigDumper : Checker<"ConfigDumper">, - HelpText<"Dump config table">, - DescFile<"DebugCheckers.cpp">; + HelpText<"Dump config table">; def TraversalDumper : Checker<"DumpTraversal">, - HelpText<"Print branch conditions as they are traversed by the engine">, - DescFile<"TraversalChecker.cpp">; + HelpText<"Print branch conditions as they are traversed by the engine">; def CallDumper : Checker<"DumpCalls">, - HelpText<"Print calls as they are traversed by the engine">, - DescFile<"TraversalChecker.cpp">; + HelpText<"Print calls as they are traversed by the engine">; def AnalyzerStatsChecker : Checker<"Stats">, - HelpText<"Emit warnings with analyzer statistics">, - DescFile<"AnalyzerStatsChecker.cpp">; + HelpText<"Emit warnings with analyzer statistics">; def TaintTesterChecker : Checker<"TaintTest">, - HelpText<"Mark tainted symbols as such.">, - DescFile<"TaintTesterChecker.cpp">; + HelpText<"Mark tainted symbols as such.">; def ExprInspectionChecker : Checker<"ExprInspection">, - HelpText<"Check the analyzer's understanding of expressions">, - DescFile<"ExprInspectionChecker.cpp">; + HelpText<"Check the analyzer's understanding of expressions">; def ExplodedGraphViewer : Checker<"ViewExplodedGraph">, - HelpText<"View Exploded Graphs using GraphViz">, - DescFile<"DebugCheckers.cpp">; + HelpText<"View Exploded Graphs using GraphViz">; } // end "debug" @@ -818,8 +745,7 @@ let ParentPackage = CloneDetectionAlpha in { def CloneChecker : Checker<"CloneChecker">, - HelpText<"Reports similar pieces of code.">, - DescFile<"CloneChecker.cpp">; + HelpText<"Reports similar pieces of code.">; } // end "clone" @@ -830,7 +756,6 @@ let ParentPackage = PortabilityOptIn in { def UnixAPIPortabilityChecker : Checker<"UnixAPI">, - HelpText<"Finds implementation-defined behavior in UNIX/Posix functions">, - DescFile<"UnixAPIChecker.cpp">; + HelpText<"Finds implementation-defined behavior in UNIX/Posix functions">; } // end optin.portability Index: cfe/trunk/lib/StaticAnalyzer/Checkers/ClangCheckers.cpp =================================================================== --- cfe/trunk/lib/StaticAnalyzer/Checkers/ClangCheckers.cpp +++ cfe/trunk/lib/StaticAnalyzer/Checkers/ClangCheckers.cpp @@ -25,7 +25,7 @@ void ento::registerBuiltinCheckers(CheckerRegistry ®istry) { #define GET_CHECKERS -#define CHECKER(FULLNAME,CLASS,DESCFILE,HELPTEXT,GROUPINDEX,HIDDEN) \ +#define CHECKER(FULLNAME, CLASS, HELPTEXT) \ registry.addChecker(register##CLASS, FULLNAME, HELPTEXT); #include "clang/StaticAnalyzer/Checkers/Checkers.inc" #undef GET_CHECKERS Index: cfe/trunk/lib/StaticAnalyzer/Checkers/ClangSACheckers.h =================================================================== --- cfe/trunk/lib/StaticAnalyzer/Checkers/ClangSACheckers.h +++ cfe/trunk/lib/StaticAnalyzer/Checkers/ClangSACheckers.h @@ -24,7 +24,7 @@ class CheckerRegistry; #define GET_CHECKERS -#define CHECKER(FULLNAME,CLASS,CXXFILE,HELPTEXT,GROUPINDEX,HIDDEN) \ +#define CHECKER(FULLNAME, CLASS, HELPTEXT) \ void register##CLASS(CheckerManager &mgr); #include "clang/StaticAnalyzer/Checkers/Checkers.inc" #undef CHECKER Index: cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp =================================================================== --- cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp +++ cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp @@ -34,7 +34,7 @@ AnalyzerOptions::getRegisteredCheckers(bool IncludeExperimental /* = false */) { static const StringRef StaticAnalyzerChecks[] = { #define GET_CHECKERS -#define CHECKER(FULLNAME, CLASS, DESCFILE, HELPTEXT, GROUPINDEX, HIDDEN) \ +#define CHECKER(FULLNAME, CLASS, HELPTEXT) \ FULLNAME, #include "clang/StaticAnalyzer/Checkers/Checkers.inc" #undef CHECKER Index: cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp =================================================================== --- cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp +++ cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp @@ -237,7 +237,7 @@ static StringRef getRuleDescription(StringRef CheckName) { return llvm::StringSwitch(CheckName) #define GET_CHECKERS -#define CHECKER(FULLNAME, CLASS, CXXFILE, HELPTEXT, GROUPINDEX, HIDDEN) \ +#define CHECKER(FULLNAME, CLASS, HELPTEXT) \ .Case(FULLNAME, HELPTEXT) #include "clang/StaticAnalyzer/Checkers/Checkers.inc" #undef CHECKER Index: cfe/trunk/utils/TableGen/ClangSACheckersEmitter.cpp =================================================================== --- cfe/trunk/utils/TableGen/ClangSACheckersEmitter.cpp +++ cfe/trunk/utils/TableGen/ClangSACheckersEmitter.cpp @@ -11,34 +11,19 @@ // //===----------------------------------------------------------------------===// -#include "llvm/ADT/DenseSet.h" +#include "llvm/ADT/StringMap.h" #include "llvm/TableGen/Error.h" #include "llvm/TableGen/Record.h" #include "llvm/TableGen/TableGenBackend.h" #include #include + using namespace llvm; //===----------------------------------------------------------------------===// // Static Analyzer Checkers Tables generation //===----------------------------------------------------------------------===// -/// True if it is specified hidden or a parent package is specified -/// as hidden, otherwise false. -static bool isHidden(const Record &R) { - if (R.getValueAsBit("Hidden")) - return true; - // Not declared as hidden, check the parent package if it is hidden. - if (DefInit *DI = dyn_cast(R.getValueInit("ParentPackage"))) - return isHidden(*DI->getDef()); - - return false; -} - -static bool isCheckerNamed(const Record *R) { - return !R->getValueAsString("CheckerName").empty(); -} - static std::string getPackageFullName(const Record *R); static std::string getParentPackageFullName(const Record *R) { @@ -50,17 +35,19 @@ static std::string getPackageFullName(const Record *R) { std::string name = getParentPackageFullName(R); - if (!name.empty()) name += "."; + if (!name.empty()) + name += "."; + assert(!R->getValueAsString("PackageName").empty()); name += R->getValueAsString("PackageName"); return name; } static std::string getCheckerFullName(const Record *R) { std::string name = getParentPackageFullName(R); - if (isCheckerNamed(R)) { - if (!name.empty()) name += "."; - name += R->getValueAsString("CheckerName"); - } + if (!name.empty()) + name += "."; + assert(!R->getValueAsString("CheckerName").empty()); + name += R->getValueAsString("CheckerName"); return name; } @@ -70,129 +57,12 @@ return std::string(); } -namespace { -struct GroupInfo { - llvm::DenseSet Checkers; - llvm::DenseSet SubGroups; - bool Hidden; - unsigned Index; - - GroupInfo() : Hidden(false) { } -}; -} - -static void addPackageToCheckerGroup(const Record *package, const Record *group, - llvm::DenseMap &recordGroupMap) { - llvm::DenseSet &checkers = recordGroupMap[package]->Checkers; - for (llvm::DenseSet::iterator - I = checkers.begin(), E = checkers.end(); I != E; ++I) - recordGroupMap[group]->Checkers.insert(*I); - - llvm::DenseSet &subGroups = recordGroupMap[package]->SubGroups; - for (llvm::DenseSet::iterator - I = subGroups.begin(), E = subGroups.end(); I != E; ++I) - addPackageToCheckerGroup(*I, group, recordGroupMap); -} - namespace clang { void EmitClangSACheckers(RecordKeeper &Records, raw_ostream &OS) { std::vector checkers = Records.getAllDerivedDefinitions("Checker"); - llvm::DenseMap checkerRecIndexMap; - for (unsigned i = 0, e = checkers.size(); i != e; ++i) - checkerRecIndexMap[checkers[i]] = i; - - // Invert the mapping of checkers to package/group into a one to many - // mapping of packages/groups to checkers. - std::map groupInfoByName; - llvm::DenseMap recordGroupMap; - std::vector packages = Records.getAllDerivedDefinitions("Package"); - for (unsigned i = 0, e = packages.size(); i != e; ++i) { - Record *R = packages[i]; - std::string fullName = getPackageFullName(R); - if (!fullName.empty()) { - GroupInfo &info = groupInfoByName[fullName]; - info.Hidden = isHidden(*R); - recordGroupMap[R] = &info; - } - } - - std::vector - checkerGroups = Records.getAllDerivedDefinitions("CheckerGroup"); - for (unsigned i = 0, e = checkerGroups.size(); i != e; ++i) { - Record *R = checkerGroups[i]; - std::string name = R->getValueAsString("GroupName"); - if (!name.empty()) { - GroupInfo &info = groupInfoByName[name]; - recordGroupMap[R] = &info; - } - } - - for (unsigned i = 0, e = checkers.size(); i != e; ++i) { - Record *R = checkers[i]; - Record *package = nullptr; - if (DefInit * - DI = dyn_cast(R->getValueInit("ParentPackage"))) - package = DI->getDef(); - if (!isCheckerNamed(R) && !package) - PrintFatalError(R->getLoc(), "Checker '" + R->getName() + - "' is neither named, nor in a package!"); - - if (isCheckerNamed(R)) { - // Create a pseudo-group to hold this checker. - std::string fullName = getCheckerFullName(R); - GroupInfo &info = groupInfoByName[fullName]; - info.Hidden = R->getValueAsBit("Hidden"); - recordGroupMap[R] = &info; - info.Checkers.insert(R); - } else { - recordGroupMap[package]->Checkers.insert(R); - } - - Record *currR = isCheckerNamed(R) ? R : package; - // Insert the checker and its parent packages into the subgroups set of - // the corresponding parent package. - while (DefInit *DI - = dyn_cast(currR->getValueInit("ParentPackage"))) { - Record *parentPackage = DI->getDef(); - recordGroupMap[parentPackage]->SubGroups.insert(currR); - currR = parentPackage; - } - // Insert the checker into the set of its group. - if (DefInit *DI = dyn_cast(R->getValueInit("Group"))) - recordGroupMap[DI->getDef()]->Checkers.insert(R); - } - - // If a package is in group, add all its checkers and its sub-packages - // checkers into the group. - for (unsigned i = 0, e = packages.size(); i != e; ++i) - if (DefInit *DI = dyn_cast(packages[i]->getValueInit("Group"))) - addPackageToCheckerGroup(packages[i], DI->getDef(), recordGroupMap); - - typedef std::map SortedRecords; - typedef llvm::DenseMap RecToSortIndex; - - SortedRecords sortedGroups; - RecToSortIndex groupToSortIndex; - OS << "\n#ifdef GET_GROUPS\n"; - { - for (unsigned i = 0, e = checkerGroups.size(); i != e; ++i) - sortedGroups[checkerGroups[i]->getValueAsString("GroupName")] - = checkerGroups[i]; - - unsigned sortIndex = 0; - for (SortedRecords::iterator - I = sortedGroups.begin(), E = sortedGroups.end(); I != E; ++I) { - const Record *R = I->second; - - OS << "GROUP(" << "\""; - OS.write_escaped(R->getValueAsString("GroupName")) << "\""; - OS << ")\n"; - groupToSortIndex[R] = sortIndex++; - } - } - OS << "#endif // GET_GROUPS\n\n"; + using SortedRecords = llvm::StringMap; OS << "\n#ifdef GET_PACKAGES\n"; { @@ -205,17 +75,7 @@ const Record &R = *I->second; OS << "PACKAGE(" << "\""; - OS.write_escaped(getPackageFullName(&R)) << "\", "; - // Group index - if (DefInit *DI = dyn_cast(R.getValueInit("Group"))) - OS << groupToSortIndex[DI->getDef()] << ", "; - else - OS << "-1, "; - // Hidden bit - if (isHidden(R)) - OS << "true"; - else - OS << "false"; + OS.write_escaped(getPackageFullName(&R)) << '\"'; OS << ")\n"; } } @@ -226,98 +86,12 @@ const Record &R = *checkers[i]; OS << "CHECKER(" << "\""; - std::string name; - if (isCheckerNamed(&R)) - name = getCheckerFullName(&R); - OS.write_escaped(name) << "\", "; + OS.write_escaped(getCheckerFullName(&R)) << "\", "; OS << R.getName() << ", "; - OS << getStringValue(R, "DescFile") << ", "; OS << "\""; - OS.write_escaped(getStringValue(R, "HelpText")) << "\", "; - // Group index - if (DefInit *DI = dyn_cast(R.getValueInit("Group"))) - OS << groupToSortIndex[DI->getDef()] << ", "; - else - OS << "-1, "; - // Hidden bit - if (isHidden(R)) - OS << "true"; - else - OS << "false"; + OS.write_escaped(getStringValue(R, "HelpText")) << '\"'; OS << ")\n"; } OS << "#endif // GET_CHECKERS\n\n"; - - unsigned index = 0; - for (std::map::iterator - I = groupInfoByName.begin(), E = groupInfoByName.end(); I != E; ++I) - I->second.Index = index++; - - // Walk through the packages/groups/checkers emitting an array for each - // set of checkers and an array for each set of subpackages. - - OS << "\n#ifdef GET_MEMBER_ARRAYS\n"; - unsigned maxLen = 0; - for (std::map::iterator - I = groupInfoByName.begin(), E = groupInfoByName.end(); I != E; ++I) { - maxLen = std::max(maxLen, (unsigned)I->first.size()); - - llvm::DenseSet &checkers = I->second.Checkers; - if (!checkers.empty()) { - OS << "static const short CheckerArray" << I->second.Index << "[] = { "; - // Make the output order deterministic. - std::map sorted; - for (llvm::DenseSet::iterator - I = checkers.begin(), E = checkers.end(); I != E; ++I) - sorted[(*I)->getID()] = *I; - - for (std::map::iterator - I = sorted.begin(), E = sorted.end(); I != E; ++I) - OS << checkerRecIndexMap[I->second] << ", "; - OS << "-1 };\n"; - } - - llvm::DenseSet &subGroups = I->second.SubGroups; - if (!subGroups.empty()) { - OS << "static const short SubPackageArray" << I->second.Index << "[] = { "; - // Make the output order deterministic. - std::map sorted; - for (llvm::DenseSet::iterator - I = subGroups.begin(), E = subGroups.end(); I != E; ++I) - sorted[(*I)->getID()] = *I; - - for (std::map::iterator - I = sorted.begin(), E = sorted.end(); I != E; ++I) { - OS << recordGroupMap[I->second]->Index << ", "; - } - OS << "-1 };\n"; - } - } - OS << "#endif // GET_MEMBER_ARRAYS\n\n"; - - OS << "\n#ifdef GET_CHECKNAME_TABLE\n"; - for (std::map::iterator - I = groupInfoByName.begin(), E = groupInfoByName.end(); I != E; ++I) { - // Group option string. - OS << " { \""; - OS.write_escaped(I->first) << "\"," - << std::string(maxLen-I->first.size()+1, ' '); - - if (I->second.Checkers.empty()) - OS << "0, "; - else - OS << "CheckerArray" << I->second.Index << ", "; - - // Subgroups. - if (I->second.SubGroups.empty()) - OS << "0, "; - else - OS << "SubPackageArray" << I->second.Index << ", "; - - OS << (I->second.Hidden ? "true" : "false"); - - OS << " },\n"; - } - OS << "#endif // GET_CHECKNAME_TABLE\n\n"; } } // end namespace clang