1//===--- Checkers.td - Static Analyzer Checkers -===-----------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10include "clang/StaticAnalyzer/Checkers/CheckerBase.td" 11 12//===----------------------------------------------------------------------===// 13// Packages. 14//===----------------------------------------------------------------------===// 15 16def Alpha : Package<"alpha">; 17 18def Core : Package<"core">; 19def CoreBuiltin : Package<"builtin">, InPackage<Core>; 20def CoreUninitialized : Package<"uninitialized">, InPackage<Core>; 21def CoreAlpha : Package<"core">, InPackage<Alpha>, Hidden; 22 23def Cplusplus : Package<"cplusplus">; 24def CplusplusAlpha : Package<"cplusplus">, InPackage<Alpha>, Hidden; 25 26def DeadCode : Package<"deadcode">; 27def DeadCodeAlpha : Package<"deadcode">, InPackage<Alpha>, Hidden; 28 29def Security : Package <"security">; 30def InsecureAPI : Package<"insecureAPI">, InPackage<Security>; 31def SecurityAlpha : Package<"security">, InPackage<Alpha>, Hidden; 32def Taint : Package<"taint">, InPackage<SecurityAlpha>, Hidden; 33 34def Unix : Package<"unix">; 35def UnixAlpha : Package<"unix">, InPackage<Alpha>, Hidden; 36def CString : Package<"cstring">, InPackage<Unix>, Hidden; 37def CStringAlpha : Package<"cstring">, InPackage<UnixAlpha>, Hidden; 38 39def OSX : Package<"osx">; 40def OSXAlpha : Package<"osx">, InPackage<Alpha>, Hidden; 41def Cocoa : Package<"cocoa">, InPackage<OSX>; 42def CocoaAlpha : Package<"cocoa">, InPackage<OSXAlpha>, Hidden; 43def CoreFoundation : Package<"coreFoundation">, InPackage<OSX>; 44def Containers : Package<"containers">, InPackage<CoreFoundation>; 45 46def LLVM : Package<"llvm">; 47def Debug : Package<"debug">; 48 49//===----------------------------------------------------------------------===// 50// Core Checkers. 51//===----------------------------------------------------------------------===// 52 53let ParentPackage = Core in { 54 55def DereferenceChecker : Checker<"NullDereference">, 56 HelpText<"Check for dereferences of null pointers">, 57 DescFile<"DereferenceChecker.cpp">; 58 59def CallAndMessageChecker : Checker<"CallAndMessage">, 60 HelpText<"Check for logical errors for function calls and Objective-C message expressions (e.g., uninitialized arguments, null function pointers)">, 61 DescFile<"CallAndMessageChecker.cpp">; 62 63def AttrNonNullChecker : Checker<"AttributeNonNull">, 64 HelpText<"Check for null pointers passed as arguments to a function whose arguments are marked with the 'nonnull' attribute">, 65 DescFile<"AttrNonNullChecker.cpp">; 66 67def VLASizeChecker : Checker<"VLASize">, 68 HelpText<"Check for declarations of VLA of undefined or zero size">, 69 DescFile<"VLASizeChecker.cpp">; 70 71def DivZeroChecker : Checker<"DivideZero">, 72 HelpText<"Check for division by zero">, 73 DescFile<"DivZeroChecker.cpp">; 74 75def UndefResultChecker : Checker<"UndefinedBinaryOperatorResult">, 76 HelpText<"Check for undefined results of binary operators">, 77 DescFile<"UndefResultChecker.cpp">; 78 79def StackAddrEscapeChecker : Checker<"StackAddressEscape">, 80 HelpText<"Check that addresses to stack memory do not escape the function">, 81 DescFile<"StackAddrEscapeChecker.cpp">; 82 83def DynamicTypePropagation : Checker<"DynamicTypePropagation">, 84 HelpText<"Generate dynamic type information">, 85 DescFile<"DynamicTypePropagation.cpp">; 86 87} // end "core" 88 89let ParentPackage = CoreAlpha in { 90 91def BoolAssignmentChecker : Checker<"BoolAssignment">, 92 HelpText<"Warn about assigning non-{0,1} values to Boolean variables">, 93 DescFile<"BoolAssignmentChecker.cpp">; 94 95def CastSizeChecker : Checker<"CastSize">, 96 HelpText<"Check when casting a malloc'ed type T, whether the size is a multiple of the size of T">, 97 DescFile<"CastSizeChecker.cpp">; 98 99def CastToStructChecker : Checker<"CastToStruct">, 100 HelpText<"Check for cast from non-struct pointer to struct pointer">, 101 DescFile<"CastToStructChecker.cpp">; 102 103def FixedAddressChecker : Checker<"FixedAddr">, 104 HelpText<"Check for assignment of a fixed address to a pointer">, 105 DescFile<"FixedAddressChecker.cpp">; 106 107def PointerArithChecker : Checker<"PointerArithm">, 108 HelpText<"Check for pointer arithmetic on locations other than array elements">, 109 DescFile<"PointerArithChecker">; 110 111def PointerSubChecker : Checker<"PointerSub">, 112 HelpText<"Check for pointer subtractions on two pointers pointing to different memory chunks">, 113 DescFile<"PointerSubChecker">; 114 115def SizeofPointerChecker : Checker<"SizeofPtr">, 116 HelpText<"Warn about unintended use of sizeof() on pointer expressions">, 117 DescFile<"CheckSizeofPointer.cpp">; 118 119} // end "core.experimental" 120 121//===----------------------------------------------------------------------===// 122// Evaluate "builtin" functions. 123//===----------------------------------------------------------------------===// 124 125let ParentPackage = CoreBuiltin in { 126 127def NoReturnFunctionChecker : Checker<"NoReturnFunctions">, 128 HelpText<"Evaluate \"panic\" functions that are known to not return to the caller">, 129 DescFile<"NoReturnFunctionChecker.cpp">; 130 131def BuiltinFunctionChecker : Checker<"BuiltinFunctions">, 132 HelpText<"Evaluate compiler builtin functions (e.g., alloca())">, 133 DescFile<"BuiltinFunctionChecker.cpp">; 134 135} // end "core.builtin" 136 137//===----------------------------------------------------------------------===// 138// Uninitialized values checkers. 139//===----------------------------------------------------------------------===// 140 141let ParentPackage = CoreUninitialized in { 142 143def UndefinedArraySubscriptChecker : Checker<"ArraySubscript">, 144 HelpText<"Check for uninitialized values used as array subscripts">, 145 DescFile<"UndefinedArraySubscriptChecker.cpp">; 146 147def UndefinedAssignmentChecker : Checker<"Assign">, 148 HelpText<"Check for assigning uninitialized values">, 149 DescFile<"UndefinedAssignmentChecker.cpp">; 150 151def UndefBranchChecker : Checker<"Branch">, 152 HelpText<"Check for uninitialized values used as branch conditions">, 153 DescFile<"UndefBranchChecker.cpp">; 154 155def UndefCapturedBlockVarChecker : Checker<"CapturedBlockVariable">, 156 HelpText<"Check for blocks that capture uninitialized values">, 157 DescFile<"UndefCapturedBlockVarChecker.cpp">; 158 159def ReturnUndefChecker : Checker<"UndefReturn">, 160 HelpText<"Check for uninitialized values being returned to the caller">, 161 DescFile<"ReturnUndefChecker.cpp">; 162 163} // end "core.uninitialized" 164 165//===----------------------------------------------------------------------===// 166// C++ checkers. 167//===----------------------------------------------------------------------===// 168 169let ParentPackage = CplusplusAlpha in { 170 171def VirtualCallChecker : Checker<"VirtualCall">, 172 HelpText<"Check virtual function calls during construction or destruction">, 173 DescFile<"VirtualCallChecker.cpp">; 174 175} // end: "cplusplus.experimental" 176 177//===----------------------------------------------------------------------===// 178// Deadcode checkers. 179//===----------------------------------------------------------------------===// 180 181let ParentPackage = DeadCode in { 182 183def DeadStoresChecker : Checker<"DeadStores">, 184 HelpText<"Check for values stored to variables that are never read afterwards">, 185 DescFile<"DeadStoresChecker.cpp">; 186} // end DeadCode 187 188let ParentPackage = DeadCodeAlpha in { 189 190def IdempotentOperationChecker : Checker<"IdempotentOperations">, 191 HelpText<"Warn about idempotent operations">, 192 DescFile<"IdempotentOperationChecker.cpp">; 193 194def UnreachableCodeChecker : Checker<"UnreachableCode">, 195 HelpText<"Check unreachable code">, 196 DescFile<"UnreachableCodeChecker.cpp">; 197 198} // end "deadcode.experimental" 199 200//===----------------------------------------------------------------------===// 201// Security checkers. 202//===----------------------------------------------------------------------===// 203 204let ParentPackage = InsecureAPI in { 205 def gets : Checker<"gets">, 206 HelpText<"Warn on uses of the 'gets' function">, 207 DescFile<"CheckSecuritySyntaxOnly.cpp">; 208 def getpw : Checker<"getpw">, 209 HelpText<"Warn on uses of the 'getpw' function">, 210 DescFile<"CheckSecuritySyntaxOnly.cpp">; 211 def mktemp : Checker<"mktemp">, 212 HelpText<"Warn on uses of the 'mktemp' function">, 213 DescFile<"CheckSecuritySyntaxOnly.cpp">; 214 def mkstemp : Checker<"mkstemp">, 215 HelpText<"Warn when 'mkstemp' is passed fewer than 6 X's in the format string">, 216 DescFile<"CheckSecuritySyntaxOnly.cpp">; 217 def rand : Checker<"rand">, 218 HelpText<"Warn on uses of the 'rand', 'random', and related functions">, 219 DescFile<"CheckSecuritySyntaxOnly.cpp">; 220 def strcpy : Checker<"strcpy">, 221 HelpText<"Warn on uses of the 'strcpy' and 'strcat' functions">, 222 DescFile<"CheckSecuritySyntaxOnly.cpp">; 223 def vfork : Checker<"vfork">, 224 HelpText<"Warn on uses of the 'vfork' function">, 225 DescFile<"CheckSecuritySyntaxOnly.cpp">; 226 def UncheckedReturn : Checker<"UncheckedReturn">, 227 HelpText<"Warn on uses of functions whose return values must be always checked">, 228 DescFile<"CheckSecuritySyntaxOnly.cpp">; 229} 230let ParentPackage = Security in { 231 def FloatLoopCounter : Checker<"FloatLoopCounter">, 232 HelpText<"Warn on using a floating point value as a loop counter (CERT: FLP30-C, FLP30-CPP)">, 233 DescFile<"CheckSecuritySyntaxOnly.cpp">; 234} 235 236let ParentPackage = SecurityAlpha in { 237 238def ArrayBoundChecker : Checker<"ArrayBound">, 239 HelpText<"Warn about buffer overflows (older checker)">, 240 DescFile<"ArrayBoundChecker.cpp">; 241 242def ArrayBoundCheckerV2 : Checker<"ArrayBoundV2">, 243 HelpText<"Warn about buffer overflows (newer checker)">, 244 DescFile<"ArrayBoundCheckerV2.cpp">; 245 246def ReturnPointerRangeChecker : Checker<"ReturnPtrRange">, 247 HelpText<"Check for an out-of-bound pointer being returned to callers">, 248 DescFile<"ReturnPointerRangeChecker.cpp">; 249 250def MallocOverflowSecurityChecker : Checker<"MallocOverflow">, 251 HelpText<"Check for overflows in the arguments to malloc()">, 252 DescFile<"MallocOverflowSecurityChecker.cpp">; 253 254} // end "security.experimental" 255 256//===----------------------------------------------------------------------===// 257// Taint checkers. 258//===----------------------------------------------------------------------===// 259 260let ParentPackage = Taint in { 261 262def GenericTaintChecker : Checker<"TaintPropagation">, 263 HelpText<"Generate taint information used by other checkers">, 264 DescFile<"GenericTaintChecker.cpp">; 265 266} // end "experimental.security.taint" 267 268//===----------------------------------------------------------------------===// 269// Unix API checkers. 270//===----------------------------------------------------------------------===// 271 272let ParentPackage = Unix in { 273 274def UnixAPIChecker : Checker<"API">, 275 HelpText<"Check calls to various UNIX/Posix functions">, 276 DescFile<"UnixAPIChecker.cpp">; 277 278def MallocPessimistic : Checker<"Malloc">, 279 HelpText<"Check for memory leaks, double free, and use-after-free problems.">, 280 DescFile<"MallocChecker.cpp">; 281 282def MallocSizeofChecker : Checker<"MallocSizeof">, 283 HelpText<"Check for dubious malloc arguments involving sizeof">, 284 DescFile<"MallocSizeofChecker.cpp">; 285 286} // end "unix" 287 288let ParentPackage = UnixAlpha in { 289 290def ChrootChecker : Checker<"Chroot">, 291 HelpText<"Check improper use of chroot">, 292 DescFile<"ChrootChecker.cpp">; 293 294def MallocOptimistic : Checker<"MallocWithAnnotations">, 295 HelpText<"Check for memory leaks, double free, and use-after-free problems. Assumes that all user-defined functions which might free a pointer are annotated.">, 296 DescFile<"MallocChecker.cpp">; 297 298def PthreadLockChecker : Checker<"PthreadLock">, 299 HelpText<"Simple lock -> unlock checker">, 300 DescFile<"PthreadLockChecker.cpp">; 301 302def StreamChecker : Checker<"Stream">, 303 HelpText<"Check stream handling functions">, 304 DescFile<"StreamChecker.cpp">; 305 306} // end "unix.experimental" 307 308let ParentPackage = CString in { 309 310def CStringNullArg : Checker<"NullArg">, 311 HelpText<"Check for null pointers being passed as arguments to C string functions">, 312 DescFile<"CStringChecker.cpp">; 313 314def CStringSyntaxChecker : Checker<"BadSizeArg">, 315 HelpText<"Check the size argument passed into C string functions for common erroneous patterns">, 316 DescFile<"CStringSyntaxChecker.cpp">; 317} 318 319let ParentPackage = CStringAlpha in { 320 321def CStringOutOfBounds : Checker<"OutOfBounds">, 322 HelpText<"Check for out-of-bounds access in string functions">, 323 DescFile<"CStringChecker.cpp">; 324 325def CStringBufferOverlap : Checker<"BufferOverlap">, 326 HelpText<"Checks for overlap in two buffer arguments">, 327 DescFile<"CStringChecker.cpp">; 328 329def CStringNotNullTerm : Checker<"NotNullTerminated">, 330 HelpText<"Check for arguments which are not null-terminating strings">, 331 DescFile<"CStringChecker.cpp">; 332} 333 334//===----------------------------------------------------------------------===// 335// Mac OS X, Cocoa, and Core Foundation checkers. 336//===----------------------------------------------------------------------===// 337 338let ParentPackage = OSX in { 339 340def MacOSXAPIChecker : Checker<"API">, 341 InPackage<OSX>, 342 HelpText<"Check for proper uses of various Mac OS X APIs">, 343 DescFile<"MacOSXAPIChecker.cpp">; 344 345def OSAtomicChecker : Checker<"AtomicCAS">, 346 InPackage<OSX>, 347 HelpText<"Evaluate calls to OSAtomic functions">, 348 DescFile<"OSAtomicChecker.cpp">; 349 350def MacOSKeychainAPIChecker : Checker<"SecKeychainAPI">, 351 InPackage<OSX>, 352 HelpText<"Check for proper uses of Secure Keychain APIs">, 353 DescFile<"MacOSKeychainAPIChecker.cpp">; 354 355} // end "macosx" 356 357let ParentPackage = Cocoa in { 358 359def ObjCAtSyncChecker : Checker<"AtSync">, 360 HelpText<"Check for nil pointers used as mutexes for @synchronized">, 361 DescFile<"ObjCAtSyncChecker.cpp">; 362 363def NilArgChecker : Checker<"NilArg">, 364 HelpText<"Check for prohibited nil arguments to ObjC method calls">, 365 DescFile<"BasicObjCFoundationChecks.cpp">; 366 367def ClassReleaseChecker : Checker<"ClassRelease">, 368 HelpText<"Check for sending 'retain', 'release', or 'autorelease' directly to a Class">, 369 DescFile<"BasicObjCFoundationChecks.cpp">; 370 371def VariadicMethodTypeChecker : Checker<"VariadicMethodTypes">, 372 HelpText<"Check for passing non-Objective-C types to variadic collection " 373 "initialization methods that expect only Objective-C types">, 374 DescFile<"BasicObjCFoundationChecks.cpp">; 375 376def NSAutoreleasePoolChecker : Checker<"NSAutoreleasePool">, 377 HelpText<"Warn for suboptimal uses of NSAutoreleasePool in Objective-C GC mode">, 378 DescFile<"NSAutoreleasePoolChecker.cpp">; 379 380def ObjCMethSigsChecker : Checker<"IncompatibleMethodTypes">, 381 HelpText<"Warn about Objective-C method signatures with type incompatibilities">, 382 DescFile<"CheckObjCInstMethSignature.cpp">; 383 384def ObjCUnusedIvarsChecker : Checker<"UnusedIvars">, 385 HelpText<"Warn about private ivars that are never used">, 386 DescFile<"ObjCUnusedIVarsChecker.cpp">; 387 388def ObjCSelfInitChecker : Checker<"SelfInit">, 389 HelpText<"Check that 'self' is properly initialized inside an initializer method">, 390 DescFile<"ObjCSelfInitChecker.cpp">; 391 392def ObjCLoopChecker : Checker<"Loops">, 393 HelpText<"Improved modeling of loops using Cocoa collection types">, 394 DescFile<"BasicObjCFoundationChecks.cpp">; 395 396def ObjCNonNilReturnValueChecker : Checker<"NonNilReturnValue">, 397 HelpText<"Model the APIs that are guaranteed to return a non-nil value">, 398 DescFile<"BasicObjCFoundationChecks.cpp">; 399 400def NSErrorChecker : Checker<"NSError">, 401 HelpText<"Check usage of NSError** parameters">, 402 DescFile<"NSErrorChecker.cpp">; 403 404def RetainCountChecker : Checker<"RetainCount">, 405 HelpText<"Check for leaks and improper reference count management">, 406 DescFile<"RetainCountChecker.cpp">; 407 408} // end "osx.cocoa" 409 410let ParentPackage = CocoaAlpha in { 411 412def ObjCDeallocChecker : Checker<"Dealloc">, 413 HelpText<"Warn about Objective-C classes that lack a correct implementation of -dealloc">, 414 DescFile<"CheckObjCDealloc.cpp">; 415 416} // end "cocoa.alpha" 417 418let ParentPackage = CoreFoundation in { 419 420def CFNumberCreateChecker : Checker<"CFNumber">, 421 HelpText<"Check for proper uses of CFNumberCreate">, 422 DescFile<"BasicObjCFoundationChecks.cpp">; 423 424def CFRetainReleaseChecker : Checker<"CFRetainRelease">, 425 HelpText<"Check for null arguments to CFRetain/CFRelease">, 426 DescFile<"BasicObjCFoundationChecks.cpp">; 427 428def CFErrorChecker : Checker<"CFError">, 429 HelpText<"Check usage of CFErrorRef* parameters">, 430 DescFile<"NSErrorChecker.cpp">; 431} 432 433let ParentPackage = Containers in { 434def ObjCContainersASTChecker : Checker<"PointerSizedValues">, 435 HelpText<"Warns if 'CFArray', 'CFDictionary', 'CFSet' are created with non-pointer-size values">, 436 DescFile<"ObjCContainersASTChecker.cpp">; 437 438def ObjCContainersChecker : Checker<"OutOfBounds">, 439 HelpText<"Checks for index out-of-bounds when using 'CFArray' API">, 440 DescFile<"ObjCContainersChecker.cpp">; 441 442} 443//===----------------------------------------------------------------------===// 444// Checkers for LLVM development. 445//===----------------------------------------------------------------------===// 446 447def LLVMConventionsChecker : Checker<"Conventions">, 448 InPackage<LLVM>, 449 HelpText<"Check code for LLVM codebase conventions">, 450 DescFile<"LLVMConventionsChecker.cpp">; 451 452//===----------------------------------------------------------------------===// 453// Debugging checkers (for analyzer development). 454//===----------------------------------------------------------------------===// 455 456let ParentPackage = Debug in { 457 458def DominatorsTreeDumper : Checker<"DumpDominators">, 459 HelpText<"Print the dominance tree for a given CFG">, 460 DescFile<"DebugCheckers.cpp">; 461 462def LiveVariablesDumper : Checker<"DumpLiveVars">, 463 HelpText<"Print results of live variable analysis">, 464 DescFile<"DebugCheckers.cpp">; 465 466def CFGViewer : Checker<"ViewCFG">, 467 HelpText<"View Control-Flow Graphs using GraphViz">, 468 DescFile<"DebugCheckers.cpp">; 469 470def CFGDumper : Checker<"DumpCFG">, 471 HelpText<"Display Control-Flow Graphs">, 472 DescFile<"DebugCheckers.cpp">; 473 474def CallGraphViewer : Checker<"ViewCallGraph">, 475 HelpText<"View Call Graph using GraphViz">, 476 DescFile<"DebugCheckers.cpp">; 477 478def CallGraphDumper : Checker<"DumpCallGraph">, 479 HelpText<"Display Call Graph">, 480 DescFile<"DebugCheckers.cpp">; 481 482def TraversalDumper : Checker<"DumpTraversal">, 483 HelpText<"Print branch conditions as they are traversed by the engine">, 484 DescFile<"TraversalChecker.cpp">; 485 486def CallDumper : Checker<"DumpCalls">, 487 HelpText<"Print calls as they are traversed by the engine">, 488 DescFile<"TraversalChecker.cpp">; 489 490def AnalyzerStatsChecker : Checker<"Stats">, 491 HelpText<"Emit warnings with analyzer statistics">, 492 DescFile<"AnalyzerStatsChecker.cpp">; 493 494def TaintTesterChecker : Checker<"TaintTest">, 495 HelpText<"Mark tainted symbols as such.">, 496 DescFile<"TaintTesterChecker.cpp">; 497 498def ExprInspectionChecker : Checker<"ExprInspection">, 499 HelpText<"Check the analyzer's understanding of expressions">, 500 DescFile<"ExprInspectionChecker.cpp">; 501 502} // end "debug" 503 504