Index: include/clang/Driver/CC1Options.td =================================================================== --- include/clang/Driver/CC1Options.td +++ include/clang/Driver/CC1Options.td @@ -108,7 +108,7 @@ ValuesCode<[{ const char *Values = #define GET_CHECKERS - #define CHECKER(FULLNAME, CLASS, HT) FULLNAME "," + #define CHECKER(FULLNAME, CLASS, HT, DOC_URI) FULLNAME "," #include "clang/StaticAnalyzer/Checkers/Checkers.inc" #undef GET_CHECKERS #define GET_PACKAGES Index: include/clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h =================================================================== --- include/clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h +++ include/clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h @@ -24,7 +24,7 @@ class CheckerRegistry; #define GET_CHECKERS -#define CHECKER(FULLNAME, CLASS, HELPTEXT) \ +#define CHECKER(FULLNAME, CLASS, HELPTEXT, DOC_URI) \ void register##CLASS(CheckerManager &mgr); #include "clang/StaticAnalyzer/Checkers/Checkers.inc" #undef CHECKER Index: include/clang/StaticAnalyzer/Checkers/CheckerBase.td =================================================================== --- include/clang/StaticAnalyzer/Checkers/CheckerBase.td +++ include/clang/StaticAnalyzer/Checkers/CheckerBase.td @@ -32,6 +32,18 @@ /// a '-help'-like command line option. class HelpText { string HelpText = text; } +/// Describes what kind of documentation exists for the checker. +class DocumentationEnum val> { + bits<2> Documentation = val; +} +def NotDocumented : DocumentationEnum<0>; +def HasDocumentation : DocumentationEnum<1>; +def HasAlphaDocumentation : DocumentationEnum<2>; + +class Documentation { + bits<2> Documentation = val.Documentation; +} + /// 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, @@ -40,5 +52,6 @@ class Checker { string CheckerName = name; string HelpText; + bits<2> Documentation; Package ParentPackage; } Index: include/clang/StaticAnalyzer/Checkers/Checkers.td =================================================================== --- include/clang/StaticAnalyzer/Checkers/Checkers.td +++ include/clang/StaticAnalyzer/Checkers/Checkers.td @@ -102,84 +102,106 @@ let ParentPackage = Core in { def DereferenceChecker : Checker<"NullDereference">, - HelpText<"Check for dereferences of null pointers">; + HelpText<"Check for dereferences of null pointers">, + Documentation; def CallAndMessageChecker : Checker<"CallAndMessage">, HelpText<"Check for logical errors for function calls and Objective-C " "message expressions (e.g., uninitialized arguments, null function " - "pointers)">; + "pointers)">, + Documentation; 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">; + "arguments are references or marked with the 'nonnull' attribute">, + Documentation; def VLASizeChecker : Checker<"VLASize">, - HelpText<"Check for declarations of VLA of undefined or zero size">; + HelpText<"Check for declarations of VLA of undefined or zero size">, + Documentation; def DivZeroChecker : Checker<"DivideZero">, - HelpText<"Check for division by zero">; + HelpText<"Check for division by zero">, + Documentation; def UndefResultChecker : Checker<"UndefinedBinaryOperatorResult">, - HelpText<"Check for undefined results of binary operators">; + HelpText<"Check for undefined results of binary operators">, + Documentation; def StackAddrEscapeChecker : Checker<"StackAddressEscape">, - HelpText<"Check that addresses to stack memory do not escape the function">; + HelpText<"Check that addresses to stack memory do not escape the function">, + Documentation; def DynamicTypePropagation : Checker<"DynamicTypePropagation">, - HelpText<"Generate dynamic type information">; + HelpText<"Generate dynamic type information">, + Documentation; def NonnullGlobalConstantsChecker: Checker<"NonnilStringConstants">, - HelpText<"Assume that const string-like globals are non-null">; + HelpText<"Assume that const string-like globals are non-null">, + Documentation; } // end "core" let ParentPackage = CoreAlpha in { def BoolAssignmentChecker : Checker<"BoolAssignment">, - HelpText<"Warn about assigning non-{0,1} values to Boolean variables">; + HelpText<"Warn about assigning non-{0,1} values to Boolean variables">, + Documentation; def CastSizeChecker : Checker<"CastSize">, HelpText<"Check when casting a malloc'ed type T, whether the size is a " - "multiple of the size of T">; + "multiple of the size of T">, + Documentation; def CastToStructChecker : Checker<"CastToStruct">, - HelpText<"Check for cast from non-struct pointer to struct pointer">; + HelpText<"Check for cast from non-struct pointer to struct pointer">, + Documentation; def ConversionChecker : Checker<"Conversion">, - HelpText<"Loss of sign/precision in implicit conversions">; + HelpText<"Loss of sign/precision in implicit conversions">, + Documentation; def IdenticalExprChecker : Checker<"IdenticalExpr">, - HelpText<"Warn about unintended use of identical expressions in operators">; + HelpText<"Warn about unintended use of identical expressions in operators">, + Documentation; def FixedAddressChecker : Checker<"FixedAddr">, - HelpText<"Check for assignment of a fixed address to a pointer">; + HelpText<"Check for assignment of a fixed address to a pointer">, + Documentation; def PointerArithChecker : Checker<"PointerArithm">, HelpText<"Check for pointer arithmetic on locations other than array " - "elements">; + "elements">, + Documentation; def PointerSubChecker : Checker<"PointerSub">, HelpText<"Check for pointer subtractions on two pointers pointing to " - "different memory chunks">; + "different memory chunks">, + Documentation; def SizeofPointerChecker : Checker<"SizeofPtr">, - HelpText<"Warn about unintended use of sizeof() on pointer expressions">; + HelpText<"Warn about unintended use of sizeof() on pointer expressions">, + Documentation; 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)">; + "pointers, and pointer to undefined variables)">, + Documentation; 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.">; + "Either the comparison is useless or there is division by zero.">, + Documentation; def DynamicTypeChecker : Checker<"DynamicTypeChecker">, HelpText<"Check for cases where the dynamic and the static type of an object " - "are unrelated.">; + "are unrelated.">, + Documentation; def StackAddrAsyncEscapeChecker : Checker<"StackAddressAsyncEscape">, - HelpText<"Check that addresses to stack memory do not escape the function">; + HelpText<"Check that addresses to stack memory do not escape the function">, + Documentation; } // end "alpha.core" @@ -187,33 +209,40 @@ def NullPassedToNonnullChecker : Checker<"NullPassedToNonnull">, HelpText<"Warns when a null pointer is passed to a pointer which has a " - "_Nonnull type.">; + "_Nonnull type.">, + Documentation; def NullReturnedFromNonnullChecker : Checker<"NullReturnedFromNonnull">, HelpText<"Warns when a null pointer is returned from a function that has " - "_Nonnull return type.">; + "_Nonnull return type.">, + Documentation; def NullableDereferencedChecker : Checker<"NullableDereferenced">, - HelpText<"Warns when a nullable pointer is dereferenced.">; + HelpText<"Warns when a nullable pointer is dereferenced.">, + Documentation; def NullablePassedToNonnullChecker : Checker<"NullablePassedToNonnull">, HelpText<"Warns when a nullable pointer is passed to a pointer which has a " - "_Nonnull type.">; + "_Nonnull type.">, + Documentation; def NullableReturnedFromNonnullChecker : Checker<"NullableReturnedFromNonnull">, HelpText<"Warns when a nullable pointer is returned from a function that has " - "_Nonnull return type.">; + "_Nonnull return type.">, + Documentation; } // end "nullability" let ParentPackage = APIModeling in { def StdCLibraryFunctionsChecker : Checker<"StdCLibraryFunctions">, - HelpText<"Improve modeling of the C standard library functions">; + HelpText<"Improve modeling of the C standard library functions">, + Documentation; def TrustNonnullChecker : Checker<"TrustNonnull">, HelpText<"Trust that returns from framework methods annotated with _Nonnull " - "are not null">; + "are not null">, + Documentation; } // end "apiModeling" @@ -225,10 +254,12 @@ def NoReturnFunctionChecker : Checker<"NoReturnFunctions">, HelpText<"Evaluate \"panic\" functions that are known to not return to the " - "caller">; + "caller">, + Documentation; def BuiltinFunctionChecker : Checker<"BuiltinFunctions">, - HelpText<"Evaluate compiler builtin functions (e.g., alloca())">; + HelpText<"Evaluate compiler builtin functions (e.g., alloca())">, + Documentation; } // end "core.builtin" @@ -239,19 +270,24 @@ let ParentPackage = CoreUninitialized in { def UndefinedArraySubscriptChecker : Checker<"ArraySubscript">, - HelpText<"Check for uninitialized values used as array subscripts">; + HelpText<"Check for uninitialized values used as array subscripts">, + Documentation; def UndefinedAssignmentChecker : Checker<"Assign">, - HelpText<"Check for assigning uninitialized values">; + HelpText<"Check for assigning uninitialized values">, + Documentation; def UndefBranchChecker : Checker<"Branch">, - HelpText<"Check for uninitialized values used as branch conditions">; + HelpText<"Check for uninitialized values used as branch conditions">, + Documentation; def UndefCapturedBlockVarChecker : Checker<"CapturedBlockVariable">, - HelpText<"Check for blocks that capture uninitialized values">; + HelpText<"Check for blocks that capture uninitialized values">, + Documentation; def ReturnUndefChecker : Checker<"UndefReturn">, - HelpText<"Check for uninitialized values being returned to the caller">; + HelpText<"Check for uninitialized values being returned to the caller">, + Documentation; } // end "core.uninitialized" @@ -263,27 +299,33 @@ def InnerPointerChecker : Checker<"InnerPointer">, HelpText<"Check for inner pointers of C++ containers used after " - "re/deallocation">; + "re/deallocation">, + Documentation; def NewDeleteChecker : Checker<"NewDelete">, HelpText<"Check for double-free and use-after-free problems. Traces memory " - "managed by new/delete.">; + "managed by new/delete.">, + Documentation; def NewDeleteLeaksChecker : Checker<"NewDeleteLeaks">, - HelpText<"Check for memory leaks. Traces memory managed by new/delete.">; + HelpText<"Check for memory leaks. Traces memory managed by new/delete.">, + Documentation; def CXXSelfAssignmentChecker : Checker<"SelfAssignment">, - HelpText<"Checks C++ copy and move assignment operators for self assignment">; + HelpText<"Checks C++ copy and move assignment operators for self assignment">, + Documentation; def MoveChecker: Checker<"Move">, - HelpText<"Find use-after-move bugs in C++">; + HelpText<"Find use-after-move bugs in C++">, + Documentation; } // end: "cplusplus" let ParentPackage = CplusplusOptIn in { def VirtualCallChecker : Checker<"VirtualCall">, - HelpText<"Check virtual function calls during construction or destruction">; + HelpText<"Check virtual function calls during construction or destruction">, + Documentation; } // end: "optin.cplusplus" @@ -291,23 +333,29 @@ def DeleteWithNonVirtualDtorChecker : Checker<"DeleteWithNonVirtualDtor">, HelpText<"Reports destructions of polymorphic objects with a non-virtual " - "destructor in their base class">; + "destructor in their base class">, + Documentation; def EnumCastOutOfRangeChecker : Checker<"EnumCastOutOfRange">, - HelpText<"Check integer to enumeration casts for out of range values">; + HelpText<"Check integer to enumeration casts for out of range values">, + Documentation; def InvalidatedIteratorChecker : Checker<"InvalidatedIterator">, - HelpText<"Check for use of invalidated iterators">; + HelpText<"Check for use of invalidated iterators">, + Documentation; def IteratorRangeChecker : Checker<"IteratorRange">, - HelpText<"Check for iterators used outside their valid ranges">; + HelpText<"Check for iterators used outside their valid ranges">, + Documentation; def MismatchedIteratorChecker : Checker<"MismatchedIterator">, HelpText<"Check for use of iterators of different containers where iterators " - "of the same container are expected">; + "of the same container are expected">, + Documentation; def UninitializedObjectChecker: Checker<"UninitializedObject">, - HelpText<"Reports uninitialized fields after object construction">; + HelpText<"Reports uninitialized fields after object construction">, + Documentation; } // end: "alpha.cplusplus" @@ -319,13 +367,16 @@ let ParentPackage = Valist in { def UninitializedChecker : Checker<"Uninitialized">, - HelpText<"Check for usages of uninitialized (or already released) va_lists.">; + HelpText<"Check for usages of uninitialized (or already released) va_lists.">, + Documentation; def UnterminatedChecker : Checker<"Unterminated">, - HelpText<"Check for va_lists which are not released by a va_end call.">; + HelpText<"Check for va_lists which are not released by a va_end call.">, + Documentation; def CopyToSelfChecker : Checker<"CopyToSelf">, - HelpText<"Check for va_lists which are copied onto itself.">; + HelpText<"Check for va_lists which are copied onto itself.">, + Documentation; } // end : "valist" @@ -337,14 +388,16 @@ def DeadStoresChecker : Checker<"DeadStores">, HelpText<"Check for values stored to variables that are never read " - "afterwards">; + "afterwards">, + Documentation; } // end DeadCode let ParentPackage = DeadCodeAlpha in { def UnreachableCodeChecker : Checker<"UnreachableCode">, - HelpText<"Check unreachable code">; + HelpText<"Check unreachable code">, + Documentation; } // end "alpha.deadcode" @@ -355,7 +408,8 @@ let ParentPackage = Performance in { def PaddingChecker : Checker<"Padding">, - HelpText<"Check for excessively padded structs.">; + HelpText<"Check for excessively padded structs.">, + Documentation; } // end: "padding" @@ -366,29 +420,40 @@ let ParentPackage = InsecureAPI in { def bcmp : Checker<"bcmp">, - HelpText<"Warn on uses of the 'bcmp' function">; + HelpText<"Warn on uses of the 'bcmp' function">, + Documentation; def bcopy : Checker<"bcopy">, - HelpText<"Warn on uses of the 'bcopy' function">; + HelpText<"Warn on uses of the 'bcopy' function">, + Documentation; def bzero : Checker<"bzero">, - HelpText<"Warn on uses of the 'bzero' function">; + HelpText<"Warn on uses of the 'bzero' function">, + Documentation; def gets : Checker<"gets">, - HelpText<"Warn on uses of the 'gets' function">; + HelpText<"Warn on uses of the 'gets' function">, + Documentation; def getpw : Checker<"getpw">, - HelpText<"Warn on uses of the 'getpw' function">; + HelpText<"Warn on uses of the 'getpw' function">, + Documentation; def mktemp : Checker<"mktemp">, - HelpText<"Warn on uses of the 'mktemp' function">; + HelpText<"Warn on uses of the 'mktemp' function">, + Documentation; def mkstemp : Checker<"mkstemp">, HelpText<"Warn when 'mkstemp' is passed fewer than 6 X's in the format " - "string">; + "string">, + Documentation; def rand : Checker<"rand">, - HelpText<"Warn on uses of the 'rand', 'random', and related functions">; + HelpText<"Warn on uses of the 'rand', 'random', and related functions">, + Documentation; def strcpy : Checker<"strcpy">, - HelpText<"Warn on uses of the 'strcpy' and 'strcat' functions">; + HelpText<"Warn on uses of the 'strcpy' and 'strcat' functions">, + Documentation; def vfork : Checker<"vfork">, - HelpText<"Warn on uses of the 'vfork' function">; + HelpText<"Warn on uses of the 'vfork' function">, + Documentation; def UncheckedReturn : Checker<"UncheckedReturn">, HelpText<"Warn on uses of functions whose return values must be always " - "checked">; + "checked">, + Documentation; } // end "security.insecureAPI" @@ -396,29 +461,35 @@ def FloatLoopCounter : Checker<"FloatLoopCounter">, HelpText<"Warn on using a floating point value as a loop counter (CERT: " - "FLP30-C, FLP30-CPP)">; + "FLP30-C, FLP30-CPP)">, + Documentation; } // end "security" let ParentPackage = SecurityAlpha in { def ArrayBoundChecker : Checker<"ArrayBound">, - HelpText<"Warn about buffer overflows (older checker)">; + HelpText<"Warn about buffer overflows (older checker)">, + Documentation; def ArrayBoundCheckerV2 : Checker<"ArrayBoundV2">, - HelpText<"Warn about buffer overflows (newer checker)">; + HelpText<"Warn about buffer overflows (newer checker)">, + Documentation; def ReturnPointerRangeChecker : Checker<"ReturnPtrRange">, - HelpText<"Check for an out-of-bound pointer being returned to callers">; + HelpText<"Check for an out-of-bound pointer being returned to callers">, + Documentation; def MallocOverflowSecurityChecker : Checker<"MallocOverflow">, - HelpText<"Check for overflows in the arguments to malloc()">; + HelpText<"Check for overflows in the arguments to malloc()">, + Documentation; // 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">; + HelpText<"Warn on mmap() calls that are both writable and executable">, + Documentation; } // end "alpha.security" @@ -429,7 +500,8 @@ let ParentPackage = Taint in { def GenericTaintChecker : Checker<"TaintPropagation">, - HelpText<"Generate taint information used by other checkers">; + HelpText<"Generate taint information used by other checkers">, + Documentation; } // end "alpha.security.taint" @@ -440,39 +512,49 @@ let ParentPackage = Unix in { def UnixAPIMisuseChecker : Checker<"API">, - HelpText<"Check calls to various UNIX/Posix functions">; + HelpText<"Check calls to various UNIX/Posix functions">, + Documentation; def MallocChecker: Checker<"Malloc">, HelpText<"Check for memory leaks, double free, and use-after-free problems. " - "Traces memory managed by malloc()/free().">; + "Traces memory managed by malloc()/free().">, + Documentation; def MallocSizeofChecker : Checker<"MallocSizeof">, - HelpText<"Check for dubious malloc arguments involving sizeof">; + HelpText<"Check for dubious malloc arguments involving sizeof">, + Documentation; def MismatchedDeallocatorChecker : Checker<"MismatchedDeallocator">, - HelpText<"Check for mismatched deallocators.">; + HelpText<"Check for mismatched deallocators.">, + Documentation; def VforkChecker : Checker<"Vfork">, - HelpText<"Check for proper usage of vfork">; + HelpText<"Check for proper usage of vfork">, + Documentation; } // end "unix" let ParentPackage = UnixAlpha in { def ChrootChecker : Checker<"Chroot">, - HelpText<"Check improper use of chroot">; + HelpText<"Check improper use of chroot">, + Documentation; def PthreadLockChecker : Checker<"PthreadLock">, - HelpText<"Simple lock -> unlock checker">; + HelpText<"Simple lock -> unlock checker">, + Documentation; def StreamChecker : Checker<"Stream">, - HelpText<"Check stream handling functions">; + HelpText<"Check stream handling functions">, + Documentation; def SimpleStreamChecker : Checker<"SimpleStream">, - HelpText<"Check for misuses of stream APIs">; + HelpText<"Check for misuses of stream APIs">, + Documentation; def BlockInCriticalSectionChecker : Checker<"BlockInCriticalSection">, - HelpText<"Check for calls to blocking functions inside a critical section">; + HelpText<"Check for calls to blocking functions inside a critical section">, + Documentation; } // end "alpha.unix" @@ -480,24 +562,29 @@ def CStringNullArg : Checker<"NullArg">, HelpText<"Check for null pointers being passed as arguments to C string " - "functions">; + "functions">, + Documentation; def CStringSyntaxChecker : Checker<"BadSizeArg">, HelpText<"Check the size argument passed into C string functions for common " - "erroneous patterns">; + "erroneous patterns">, + Documentation; } // end "unix.cstring" let ParentPackage = CStringAlpha in { def CStringOutOfBounds : Checker<"OutOfBounds">, - HelpText<"Check for out-of-bounds access in string functions">; + HelpText<"Check for out-of-bounds access in string functions">, + Documentation; def CStringBufferOverlap : Checker<"BufferOverlap">, - HelpText<"Checks for overlap in two buffer arguments">; + HelpText<"Checks for overlap in two buffer arguments">, + Documentation; def CStringNotNullTerm : Checker<"NotNullTerminated">, - HelpText<"Check for arguments which are not null-terminating strings">; + HelpText<"Check for arguments which are not null-terminating strings">, + Documentation; } // end "alpha.unix.cstring" @@ -509,19 +596,24 @@ def NumberObjectConversionChecker : Checker<"NumberObjectConversion">, HelpText<"Check for erroneous conversions of objects representing numbers " - "into numbers">; + "into numbers">, + Documentation; def MacOSXAPIChecker : Checker<"API">, - HelpText<"Check for proper uses of various Apple APIs">; + HelpText<"Check for proper uses of various Apple APIs">, + Documentation; def MacOSKeychainAPIChecker : Checker<"SecKeychainAPI">, - HelpText<"Check for proper uses of Secure Keychain APIs">; + HelpText<"Check for proper uses of Secure Keychain APIs">, + Documentation; def ObjCPropertyChecker : Checker<"ObjCProperty">, - HelpText<"Check for proper uses of Objective-C properties">; + HelpText<"Check for proper uses of Objective-C properties">, + Documentation; def OSObjectRetainCountChecker : Checker<"OSObjectRetainCount">, - HelpText<"Check for leaks and improper reference count management for OSObject">; + HelpText<"Check for leaks and improper reference count management for OSObject">, + Documentation; } // end "osx" @@ -529,66 +621,84 @@ def RunLoopAutoreleaseLeakChecker : Checker<"RunLoopAutoreleaseLeak">, HelpText<"Check for leaked memory in autorelease pools that will never be " - "drained">; + "drained">, + Documentation; def ObjCAtSyncChecker : Checker<"AtSync">, - HelpText<"Check for nil pointers used as mutexes for @synchronized">; + HelpText<"Check for nil pointers used as mutexes for @synchronized">, + Documentation; def NilArgChecker : Checker<"NilArg">, - HelpText<"Check for prohibited nil arguments to ObjC method calls">; + HelpText<"Check for prohibited nil arguments to ObjC method calls">, + Documentation; def ClassReleaseChecker : Checker<"ClassRelease">, HelpText<"Check for sending 'retain', 'release', or 'autorelease' directly " - "to a Class">; + "to a Class">, + Documentation; def VariadicMethodTypeChecker : Checker<"VariadicMethodTypes">, HelpText<"Check for passing non-Objective-C types to variadic collection " - "initialization methods that expect only Objective-C types">; + "initialization methods that expect only Objective-C types">, + Documentation; def NSAutoreleasePoolChecker : Checker<"NSAutoreleasePool">, HelpText<"Warn for suboptimal uses of NSAutoreleasePool in Objective-C GC " - "mode">; + "mode">, + Documentation; def ObjCMethSigsChecker : Checker<"IncompatibleMethodTypes">, HelpText<"Warn about Objective-C method signatures with type " - "incompatibilities">; + "incompatibilities">, + Documentation; def ObjCUnusedIvarsChecker : Checker<"UnusedIvars">, - HelpText<"Warn about private ivars that are never used">; + HelpText<"Warn about private ivars that are never used">, + Documentation; def ObjCSelfInitChecker : Checker<"SelfInit">, HelpText<"Check that 'self' is properly initialized inside an initializer " - "method">; + "method">, + Documentation; def ObjCLoopChecker : Checker<"Loops">, - HelpText<"Improved modeling of loops using Cocoa collection types">; + HelpText<"Improved modeling of loops using Cocoa collection types">, + Documentation; def ObjCNonNilReturnValueChecker : Checker<"NonNilReturnValue">, - HelpText<"Model the APIs that are guaranteed to return a non-nil value">; + HelpText<"Model the APIs that are guaranteed to return a non-nil value">, + Documentation; def ObjCSuperCallChecker : Checker<"MissingSuperCall">, HelpText<"Warn about Objective-C methods that lack a necessary call to " - "super">; + "super">, + Documentation; def NSErrorChecker : Checker<"NSError">, - HelpText<"Check usage of NSError** parameters">; + HelpText<"Check usage of NSError** parameters">, + Documentation; def RetainCountChecker : Checker<"RetainCount">, - HelpText<"Check for leaks and improper reference count management">; + HelpText<"Check for leaks and improper reference count management">, + Documentation; def ObjCGenericsChecker : Checker<"ObjCGenerics">, - HelpText<"Check for type errors when using Objective-C generics">; + HelpText<"Check for type errors when using Objective-C generics">, + Documentation; def ObjCDeallocChecker : Checker<"Dealloc">, HelpText<"Warn about Objective-C classes that lack a correct implementation " - "of -dealloc">; + "of -dealloc">, + Documentation; def ObjCSuperDeallocChecker : Checker<"SuperDealloc">, - HelpText<"Warn about improper use of '[super dealloc]' in Objective-C">; + HelpText<"Warn about improper use of '[super dealloc]' in Objective-C">, + Documentation; def AutoreleaseWriteChecker : Checker<"AutoreleaseWrite">, HelpText<"Warn about potentially crashing writes to autoreleasing objects " - "from different autoreleasing pools in Objective-C">; + "from different autoreleasing pools in Objective-C">, + Documentation; } // end "osx.cocoa" @@ -596,39 +706,47 @@ def GCDAntipattern : Checker<"GCDAntipattern">, HelpText<"Check for performance anti-patterns when using Grand Central " - "Dispatch">; + "Dispatch">, + Documentation; } // 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">; + "the methods annotated with objc_instance_variable_invalidator">, + Documentation; def MissingInvalidationMethod : Checker<"MissingInvalidationMethod">, HelpText<"Check that the invalidation methods are present in classes that " - "contain invalidatable instance variables">; + "contain invalidatable instance variables">, + Documentation; def DirectIvarAssignment : Checker<"DirectIvarAssignment">, - HelpText<"Check for direct assignments to instance variables">; + HelpText<"Check for direct assignments to instance variables">, + Documentation; def DirectIvarAssignmentForAnnotatedFunctions : Checker<"DirectIvarAssignmentForAnnotatedFunctions">, HelpText<"Check for direct assignments to instance variables in the methods " - "annotated with objc_no_direct_instance_variable_assignment">; + "annotated with objc_no_direct_instance_variable_assignment">, + Documentation; } // end "alpha.osx.cocoa" let ParentPackage = CoreFoundation in { def CFNumberChecker : Checker<"CFNumber">, - HelpText<"Check for proper uses of CFNumber APIs">; + HelpText<"Check for proper uses of CFNumber APIs">, + Documentation; def CFRetainReleaseChecker : Checker<"CFRetainRelease">, - HelpText<"Check for null arguments to CFRetain/CFRelease/CFMakeCollectable">; + HelpText<"Check for null arguments to CFRetain/CFRelease/CFMakeCollectable">, + Documentation; def CFErrorChecker : Checker<"CFError">, - HelpText<"Check usage of CFErrorRef* parameters">; + HelpText<"Check usage of CFErrorRef* parameters">, + Documentation; } // end "osx.coreFoundation" @@ -636,10 +754,12 @@ def ObjCContainersASTChecker : Checker<"PointerSizedValues">, HelpText<"Warns if 'CFArray', 'CFDictionary', 'CFSet' are created with " - "non-pointer-size values">; + "non-pointer-size values">, + Documentation; def ObjCContainersChecker : Checker<"OutOfBounds">, - HelpText<"Checks for index out-of-bounds when using 'CFArray' API">; + HelpText<"Checks for index out-of-bounds when using 'CFArray' API">, + Documentation; } // end "osx.coreFoundation.containers" @@ -647,11 +767,13 @@ def NonLocalizedStringChecker : Checker<"NonLocalizedStringChecker">, HelpText<"Warns about uses of non-localized NSStrings passed to UI methods " - "expecting localized NSStrings">; + "expecting localized NSStrings">, + Documentation; def EmptyLocalizationContextChecker : Checker<"EmptyLocalizationContextChecker">, - HelpText<"Check that NSLocalizedString macros include a comment for context">; + HelpText<"Check that NSLocalizedString macros include a comment for context">, + Documentation; } // end "optin.osx.cocoa.localizability" @@ -659,14 +781,16 @@ def PluralMisuseChecker : Checker<"PluralMisuseChecker">, HelpText<"Warns against using one vs. many plural pattern in code when " - "generating localized strings.">; + "generating localized strings.">, + Documentation; } // end "alpha.osx.cocoa.localizability" let ParentPackage = MPI in { def MPIChecker : Checker<"MPI-Checker">, - HelpText<"Checks MPI code">; + HelpText<"Checks MPI code">, + Documentation; } // end "optin.mpi" @@ -677,7 +801,8 @@ let ParentPackage = LLVMAlpha in { def LLVMConventionsChecker : Checker<"Conventions">, - HelpText<"Check code for LLVM codebase conventions">; + HelpText<"Check code for LLVM codebase conventions">, + Documentation; } // end "llvm" @@ -688,7 +813,8 @@ let ParentPackage = GoogleAPIModeling in { def GTestChecker : Checker<"GTest">, - HelpText<"Model gtest assertion APIs">; + HelpText<"Model gtest assertion APIs">, + Documentation; } // end "apiModeling.google" @@ -699,49 +825,64 @@ let ParentPackage = Debug in { def AnalysisOrderChecker : Checker<"AnalysisOrder">, - HelpText<"Print callbacks that are called during analysis in order">; + HelpText<"Print callbacks that are called during analysis in order">, + Documentation; def DominatorsTreeDumper : Checker<"DumpDominators">, - HelpText<"Print the dominance tree for a given CFG">; + HelpText<"Print the dominance tree for a given CFG">, + Documentation; def LiveVariablesDumper : Checker<"DumpLiveVars">, - HelpText<"Print results of live variable analysis">; + HelpText<"Print results of live variable analysis">, + Documentation; def LiveStatementsDumper : Checker<"DumpLiveStmts">, - HelpText<"Print results of live statement analysis">; + HelpText<"Print results of live statement analysis">, + Documentation; def CFGViewer : Checker<"ViewCFG">, - HelpText<"View Control-Flow Graphs using GraphViz">; + HelpText<"View Control-Flow Graphs using GraphViz">, + Documentation; def CFGDumper : Checker<"DumpCFG">, - HelpText<"Display Control-Flow Graphs">; + HelpText<"Display Control-Flow Graphs">, + Documentation; def CallGraphViewer : Checker<"ViewCallGraph">, - HelpText<"View Call Graph using GraphViz">; + HelpText<"View Call Graph using GraphViz">, + Documentation; def CallGraphDumper : Checker<"DumpCallGraph">, - HelpText<"Display Call Graph">; + HelpText<"Display Call Graph">, + Documentation; def ConfigDumper : Checker<"ConfigDumper">, - HelpText<"Dump config table">; + HelpText<"Dump config table">, + Documentation; def TraversalDumper : Checker<"DumpTraversal">, - HelpText<"Print branch conditions as they are traversed by the engine">; + HelpText<"Print branch conditions as they are traversed by the engine">, + Documentation; def CallDumper : Checker<"DumpCalls">, - HelpText<"Print calls as they are traversed by the engine">; + HelpText<"Print calls as they are traversed by the engine">, + Documentation; def AnalyzerStatsChecker : Checker<"Stats">, - HelpText<"Emit warnings with analyzer statistics">; + HelpText<"Emit warnings with analyzer statistics">, + Documentation; def TaintTesterChecker : Checker<"TaintTest">, - HelpText<"Mark tainted symbols as such.">; + HelpText<"Mark tainted symbols as such.">, + Documentation; def ExprInspectionChecker : Checker<"ExprInspection">, - HelpText<"Check the analyzer's understanding of expressions">; + HelpText<"Check the analyzer's understanding of expressions">, + Documentation; def ExplodedGraphViewer : Checker<"ViewExplodedGraph">, - HelpText<"View Exploded Graphs using GraphViz">; + HelpText<"View Exploded Graphs using GraphViz">, + Documentation; } // end "debug" @@ -753,7 +894,8 @@ let ParentPackage = CloneDetectionAlpha in { def CloneChecker : Checker<"CloneChecker">, - HelpText<"Reports similar pieces of code.">; + HelpText<"Reports similar pieces of code.">, + Documentation; } // end "clone" @@ -764,6 +906,7 @@ let ParentPackage = PortabilityOptIn in { def UnixAPIPortabilityChecker : Checker<"UnixAPI">, - HelpText<"Finds implementation-defined behavior in UNIX/Posix functions">; + HelpText<"Finds implementation-defined behavior in UNIX/Posix functions">, + Documentation; } // end optin.portability Index: include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h =================================================================== --- include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h +++ include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h @@ -91,9 +91,12 @@ InitializationFunction Initialize; StringRef FullName; StringRef Desc; + StringRef DocumentationUri; - CheckerInfo(InitializationFunction fn, StringRef name, StringRef desc) - : Initialize(fn), FullName(name), Desc(desc) {} + CheckerInfo(InitializationFunction Fn, StringRef Name, StringRef Desc, + StringRef DocsUri) + : Initialize(Fn), FullName(Name), Desc(Desc), + DocumentationUri(DocsUri) {} }; using CheckerInfoList = std::vector; @@ -108,16 +111,16 @@ public: /// Adds a checker to the registry. Use this non-templated overload when your /// checker requires custom initialization. - void addChecker(InitializationFunction fn, StringRef fullName, - StringRef desc); + void addChecker(InitializationFunction Fn, StringRef FullName, StringRef Desc, + StringRef DocsUri); /// Adds a checker to the registry. Use this templated overload when your /// checker does not require any custom initialization. template - void addChecker(StringRef fullName, StringRef desc) { + void addChecker(StringRef FullName, StringRef Desc, StringRef DocsUri) { // Avoid MSVC's Compiler Error C2276: // http://msdn.microsoft.com/en-us/library/850cstw1(v=VS.80).aspx - addChecker(&CheckerRegistry::initializeManager, fullName, desc); + addChecker(&CheckerRegistry::initializeManager, FullName, Desc, DocsUri); } /// Initializes a CheckerManager by calling the initialization functions for Index: lib/StaticAnalyzer/Core/AnalyzerOptions.cpp =================================================================== --- lib/StaticAnalyzer/Core/AnalyzerOptions.cpp +++ 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, HELPTEXT) \ +#define CHECKER(FULLNAME, CLASS, HELPTEXT, DOC_URI) \ FULLNAME, #include "clang/StaticAnalyzer/Checkers/Checkers.inc" #undef CHECKER Index: lib/StaticAnalyzer/Core/SarifDiagnostics.cpp =================================================================== --- lib/StaticAnalyzer/Core/SarifDiagnostics.cpp +++ lib/StaticAnalyzer/Core/SarifDiagnostics.cpp @@ -257,7 +257,7 @@ static StringRef getRuleDescription(StringRef CheckName) { return llvm::StringSwitch(CheckName) #define GET_CHECKERS -#define CHECKER(FULLNAME, CLASS, HELPTEXT) \ +#define CHECKER(FULLNAME, CLASS, HELPTEXT, DOC_URI) \ .Case(FULLNAME, HELPTEXT) #include "clang/StaticAnalyzer/Checkers/Checkers.inc" #undef CHECKER @@ -265,12 +265,29 @@ ; } +static StringRef getRuleHelpURIStr(StringRef CheckName) { + return llvm::StringSwitch(CheckName) +#define GET_CHECKERS +#define CHECKER(FULLNAME, CLASS, HELPTEXT, DOC_URI) \ + .Case(FULLNAME, DOC_URI) +#include "clang/StaticAnalyzer/Checkers/Checkers.inc" +#undef CHECKER +#undef GET_CHECKERS + ; +} + static json::Object createRule(const PathDiagnostic &Diag) { StringRef CheckName = Diag.getCheckName(); - return json::Object{ + json::Object Ret{ {"fullDescription", createMessage(getRuleDescription(CheckName))}, {"name", createMessage(CheckName)}, {"id", CheckName}}; + + std::string RuleURI = getRuleHelpURIStr(CheckName); + if (!RuleURI.empty()) + Ret["helpURI"] = RuleURI; + + return Ret; } static json::Array createRules(std::vector &Diags, Index: lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp =================================================================== --- lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp +++ lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp @@ -42,8 +42,8 @@ CheckerRegistry::CheckerRegistry(ArrayRef plugins, DiagnosticsEngine &diags) : Diags(diags) { #define GET_CHECKERS -#define CHECKER(FULLNAME, CLASS, HELPTEXT) \ - addChecker(register##CLASS, FULLNAME, HELPTEXT); +#define CHECKER(FULLNAME, CLASS, HELPTEXT, DOC_URI) \ + addChecker(register##CLASS, FULLNAME, HELPTEXT, DOC_URI); #include "clang/StaticAnalyzer/Checkers/Checkers.inc" #undef CHECKER #undef GET_CHECKERS @@ -115,7 +115,7 @@ for (const std::pair &opt : Opts.CheckersControlList) { // Use a binary search to find the possible start of the package. - CheckerRegistry::CheckerInfo packageInfo(nullptr, opt.first, ""); + CheckerRegistry::CheckerInfo packageInfo(nullptr, opt.first, "", ""); auto firstRelatedChecker = std::lower_bound(Checkers.cbegin(), end, packageInfo, checkerNameLT); @@ -147,13 +147,13 @@ return enabledCheckers; } -void CheckerRegistry::addChecker(InitializationFunction fn, StringRef name, - StringRef desc) { - Checkers.push_back(CheckerInfo(fn, name, desc)); +void CheckerRegistry::addChecker(InitializationFunction Fn, StringRef Name, + StringRef Desc, StringRef DocsUri) { + Checkers.emplace_back(Fn, Name, Desc, DocsUri); // Record the presence of the checker in its packages. StringRef packageName, leafName; - std::tie(packageName, leafName) = name.rsplit(PackageSeparator); + std::tie(packageName, leafName) = Name.rsplit(PackageSeparator); while (!leafName.empty()) { Packages[packageName] += 1; std::tie(packageName, leafName) = packageName.rsplit(PackageSeparator); Index: test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif =================================================================== --- test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif +++ test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif @@ -29,6 +29,7 @@ "fullDescription": { "text": "Check for logical errors for function calls and Objective-C message expressions (e.g., uninitialized arguments, null function pointers)" }, + "helpURI": "https://clang-analyzer.llvm.org/available_checks.html#core.CallAndMessage", "id": "core.CallAndMessage", "name": { "text": "core.CallAndMessage" @@ -38,6 +39,7 @@ "fullDescription": { "text": "Check for division by zero" }, + "helpURI": "https://clang-analyzer.llvm.org/available_checks.html#core.DivideZero", "id": "core.DivideZero", "name": { "text": "core.DivideZero" Index: utils/ClangVisualizers/clang.natvis =================================================================== --- utils/ClangVisualizers/clang.natvis +++ utils/ClangVisualizers/clang.natvis @@ -392,25 +392,32 @@ Empty {*(clang::IdentifierInfo *)(Ptr & ~PtrMask)} - {{Identifier ({*(clang::IdentifierInfo *)(Ptr & ~PtrMask)})}} - {{ObjC Zero Arg Selector (*{(clang::IdentifierInfo *)(Ptr & ~PtrMask)})}} - {{ObjC One Arg Selector (*{(clang::IdentifierInfo *)(Ptr & ~PtrMask)})}} + Identifier {*(clang::IdentifierInfo *)(Ptr & ~PtrMask)} + ObjC Zero Arg Selector {*(clang::IdentifierInfo *)(Ptr & ~PtrMask)} + ObjC One Arg Selector {*(clang::IdentifierInfo *)(Ptr & ~PtrMask)} + C++ Constructor {*(clang::detail::CXXSpecialNameExtra *)(Ptr & ~PtrMask)} + C++ Destructor {*(clang::detail::CXXSpecialNameExtra *)(Ptr & ~PtrMask)} + C++ Conversion function {*(clang::detail::CXXSpecialNameExtra *)(Ptr & ~PtrMask)} + C++ Operator {*(clang::detail::CXXOperatorIdName *)(Ptr & ~PtrMask)} {*(clang::DeclarationNameExtra *)(Ptr & ~PtrMask),view(cpp)} - {{Extra ({*(clang::DeclarationNameExtra *)(Ptr & ~PtrMask)})}} + Extra {*(clang::detail::DeclarationNameExtra *)(Ptr & ~PtrMask)} *(clang::IdentifierInfo *)(Ptr & ~PtrMask) *(clang::IdentifierInfo *)(Ptr & ~PtrMask) *(clang::IdentifierInfo *)(Ptr & ~PtrMask) - (clang::DeclarationNameExtra *)(Ptr & ~PtrMask) + *(clang::detail::CXXSpecialNameExtra *)(Ptr & ~PtrMask) + *(clang::detail::CXXSpecialNameExtra *)(Ptr & ~PtrMask) + *(clang::detail::CXXSpecialNameExtra *)(Ptr & ~PtrMask) + *(clang::detail::CXXOperatorIdName *)(Ptr & ~PtrMask) + *(clang::detail::DeclarationNameExtra *)(Ptr & ~PtrMask) - - {((clang::CXXSpecialName *)this)->Type,view(cpp)} - {(clang::DeclarationNameExtra::ExtraKind)ExtraKindOrNumArgs,en}{" ",sb}{*this,view(cpp)} + + C++ Deduction guide + C++ Literal operator + C++ Using directive + {(clang::detail::DeclarationNameExtra::ExtraKind)ExtraKindOrNumArgs,en}{" ",sb}{*this,view(cpp)} {(clang::tok::TokenKind)Kind,en} Index: utils/TableGen/ClangSACheckersEmitter.cpp =================================================================== --- utils/TableGen/ClangSACheckersEmitter.cpp +++ utils/TableGen/ClangSACheckersEmitter.cpp @@ -57,6 +57,36 @@ return std::string(); } +// Calculates the integer value representing the BitsInit object +static inline uint64_t getValueFromBitsInit(const BitsInit *B) { + assert(B->getNumBits() <= sizeof(uint64_t) * 8 && "BitInits' too long!"); + + uint64_t Value = 0; + for (unsigned i = 0, e = B->getNumBits(); i != e; ++i) { + const auto *Bit = cast(B->getBit(i)); + Value |= uint64_t(Bit->getValue()) << i; + } + return Value; +} + +static std::string getCheckerDocs(const Record &R) { + StringRef LandingPage; + if (BitsInit *BI = R.getValueAsBitsInit("Documentation")) { + uint64_t V = getValueFromBitsInit(BI); + if (V == 1) + LandingPage = "available_checks.html"; + else if (V == 2) + LandingPage = "alpha_checks.html"; + } + + if (LandingPage.empty()) + return ""; + + return (llvm::Twine("https://clang-analyzer.llvm.org/") + LandingPage + "#" + + getCheckerFullName(&R)) + .str(); +} + namespace clang { void EmitClangSACheckers(RecordKeeper &Records, raw_ostream &OS) { std::vector checkers = Records.getAllDerivedDefinitions("Checker"); @@ -64,6 +94,9 @@ using SortedRecords = llvm::StringMap; + OS << "// This file is automatically generated. Do not edit this file by " + "hand.\n"; + OS << "\n#ifdef GET_PACKAGES\n"; { SortedRecords sortedPackages; @@ -89,7 +122,10 @@ OS.write_escaped(getCheckerFullName(&R)) << "\", "; OS << R.getName() << ", "; OS << "\""; - OS.write_escaped(getStringValue(R, "HelpText")) << '\"'; + OS.write_escaped(getStringValue(R, "HelpText")) << "\", "; + OS << "\""; + OS.write_escaped(getCheckerDocs(R)); + OS << "\""; OS << ")\n"; } OS << "#endif // GET_CHECKERS\n\n"; Index: www/analyzer/alpha_checks.html =================================================================== --- www/analyzer/alpha_checks.html +++ www/analyzer/alpha_checks.html @@ -43,10 +43,10 @@ Name, DescriptionExample - - - - - - - - - - - - @@ -329,12 +329,12 @@ - - - - - - - - - - - - @@ -935,7 +935,7 @@ - + - -
@@ -1037,7 +1037,7 @@ - - - - - co - - - - - - - - - -
- - - - - - - - - -
 @interface Test : UIViewController
 @end
@@ -891,11 +891,11 @@
 
- - - - - - - - - - - - - - - - - - - - - - +rand_r - -
 int test() {
   return strlen(0); // warn