1 //===--- Checkers.td - Static Analyzer Checkers -===-----------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 include "CheckerBase.td"
11 //===----------------------------------------------------------------------===//
13 //===----------------------------------------------------------------------===//
15 // The Alpha package is for checkers that have too many false positives to be
16 // turned on by default. The hierarchy under Alpha should be organized in the
17 // hierarchy checkers would have had if they were truly at the top level.
18 // (For example, a Cocoa-specific checker that is alpha should be in
20 def Alpha : Package<"alpha">;
22 def Core : Package<"core">;
23 def CoreBuiltin : Package<"builtin">, ParentPackage<Core>, Hidden;
24 def CoreUninitialized : Package<"uninitialized">, ParentPackage<Core>;
25 def CoreAlpha : Package<"core">, ParentPackage<Alpha>;
27 // The OptIn package is for checkers that are not alpha and that would normally
28 // be on by default but where the driver does not have enough information to
29 // determine when they are applicable. For example, localizability checkers fit
30 // this criterion because the driver cannot determine whether a project is
31 // localized or not -- this is best determined at the IDE or build-system level.
33 // The checker hierarchy under OptIn should mirror that in Alpha: checkers
34 // should be organized as if they were at the top level.
36 // Note: OptIn is *not* intended for checkers that are too noisy to be on by
37 // default. Such checkers belong in the alpha package.
38 def OptIn : Package<"optin">;
40 // In the Portability package reside checkers for finding code that relies on
41 // implementation-defined behavior. Such checks are wanted for cross-platform
42 // development, but unwanted for developers who target only a single platform.
43 def PortabilityOptIn : Package<"portability">, ParentPackage<OptIn>;
45 def Nullability : Package<"nullability">,
47 CmdLineOption<Boolean,
48 "NoDiagnoseCallsToSystemHeaders",
49 "Suppresses warnings for violating nullability annotations "
50 "of system header functions. This is useful if you are "
51 "concerned with your custom nullability annotations more "
52 "than with following nullability specifications of system "
58 def Cplusplus : Package<"cplusplus">;
59 def CplusplusAlpha : Package<"cplusplus">, ParentPackage<Alpha>;
60 def CplusplusOptIn : Package<"cplusplus">, ParentPackage<OptIn>;
62 def Valist : Package<"valist">;
64 def DeadCode : Package<"deadcode">;
65 def DeadCodeAlpha : Package<"deadcode">, ParentPackage<Alpha>;
67 def Performance : Package<"performance">, ParentPackage<OptIn>;
69 def Security : Package <"security">;
70 def InsecureAPI : Package<"insecureAPI">, ParentPackage<Security>;
71 def SecurityAlpha : Package<"security">, ParentPackage<Alpha>;
72 def Taint : Package<"taint">, ParentPackage<SecurityAlpha>;
74 def Unix : Package<"unix">;
75 def UnixAlpha : Package<"unix">, ParentPackage<Alpha>;
76 def CString : Package<"cstring">, ParentPackage<Unix>;
77 def CStringAlpha : Package<"cstring">, ParentPackage<UnixAlpha>;
79 def OSX : Package<"osx">;
80 def OSXAlpha : Package<"osx">, ParentPackage<Alpha>;
81 def OSXOptIn : Package<"osx">, ParentPackage<OptIn>;
83 def Cocoa : Package<"cocoa">, ParentPackage<OSX>;
84 def CocoaAlpha : Package<"cocoa">, ParentPackage<OSXAlpha>;
85 def CocoaOptIn : Package<"cocoa">, ParentPackage<OSXOptIn>;
87 def CoreFoundation : Package<"coreFoundation">, ParentPackage<OSX>;
88 def Containers : Package<"containers">, ParentPackage<CoreFoundation>;
90 def LocalizabilityAlpha : Package<"localizability">, ParentPackage<CocoaAlpha>;
91 def LocalizabilityOptIn : Package<"localizability">, ParentPackage<CocoaOptIn>;
93 def MPI : Package<"mpi">, ParentPackage<OptIn>;
95 def LLVM : Package<"llvm">;
96 def LLVMAlpha : Package<"llvm">, ParentPackage<Alpha>;
98 // The APIModeling package is for checkers that model APIs and don't perform
99 // any diagnostics. These checkers are always turned on; this package is
100 // intended for API modeling that is not controlled by the target triple.
101 def APIModeling : Package<"apiModeling">, Hidden;
102 def GoogleAPIModeling : Package<"google">, ParentPackage<APIModeling>, Hidden;
103 def LLVMAPIModeling : Package<"llvm">, ParentPackage<APIModeling>, Hidden;
105 def Debug : Package<"debug">, Hidden;
107 def CloneDetectionAlpha : Package<"clone">, ParentPackage<Alpha>;
109 def NonDeterminismAlpha : Package<"nondeterminism">, ParentPackage<Alpha>;
111 //===----------------------------------------------------------------------===//
113 //===----------------------------------------------------------------------===//
115 let ParentPackage = Core in {
117 def DereferenceChecker : Checker<"NullDereference">,
118 HelpText<"Check for dereferences of null pointers">,
119 Documentation<HasDocumentation>;
121 def CallAndMessageChecker : Checker<"CallAndMessage">,
122 HelpText<"Check for logical errors for function calls and Objective-C "
123 "message expressions (e.g., uninitialized arguments, null function "
125 Documentation<HasDocumentation>;
127 def NonNullParamChecker : Checker<"NonNullParamChecker">,
128 HelpText<"Check for null pointers passed as arguments to a function whose "
129 "arguments are references or marked with the 'nonnull' attribute">,
130 Documentation<HasDocumentation>;
132 def VLASizeChecker : Checker<"VLASize">,
133 HelpText<"Check for declarations of VLA of undefined or zero size">,
134 Documentation<HasDocumentation>;
136 def DivZeroChecker : Checker<"DivideZero">,
137 HelpText<"Check for division by zero">,
138 Documentation<HasDocumentation>;
140 def UndefResultChecker : Checker<"UndefinedBinaryOperatorResult">,
141 HelpText<"Check for undefined results of binary operators">,
142 Documentation<HasDocumentation>;
144 def StackAddrEscapeBase : Checker<"StackAddrEscapeBase">,
145 HelpText<"Generate information about stack address escapes.">,
146 Documentation<NotDocumented>,
149 def StackAddrEscapeChecker : Checker<"StackAddressEscape">,
150 HelpText<"Check that addresses to stack memory do not escape the function">,
151 Dependencies<[StackAddrEscapeBase]>,
152 Documentation<HasDocumentation>;
154 def DynamicTypePropagation : Checker<"DynamicTypePropagation">,
155 HelpText<"Generate dynamic type information">,
156 Documentation<NotDocumented>;
158 def NonnullGlobalConstantsChecker: Checker<"NonnilStringConstants">,
159 HelpText<"Assume that const string-like globals are non-null">,
160 Documentation<NotDocumented>,
165 let ParentPackage = CoreAlpha in {
167 def BoolAssignmentChecker : Checker<"BoolAssignment">,
168 HelpText<"Warn about assigning non-{0,1} values to Boolean variables">,
169 Documentation<HasAlphaDocumentation>;
171 def CastSizeChecker : Checker<"CastSize">,
172 HelpText<"Check when casting a malloc'ed type T, whether the size is a "
173 "multiple of the size of T">,
174 Documentation<HasAlphaDocumentation>;
176 def CastToStructChecker : Checker<"CastToStruct">,
177 HelpText<"Check for cast from non-struct pointer to struct pointer">,
178 Documentation<HasAlphaDocumentation>;
180 def ConversionChecker : Checker<"Conversion">,
181 HelpText<"Loss of sign/precision in implicit conversions">,
182 Documentation<HasAlphaDocumentation>;
184 def IdenticalExprChecker : Checker<"IdenticalExpr">,
185 HelpText<"Warn about unintended use of identical expressions in operators">,
186 Documentation<HasAlphaDocumentation>;
188 def FixedAddressChecker : Checker<"FixedAddr">,
189 HelpText<"Check for assignment of a fixed address to a pointer">,
190 Documentation<HasAlphaDocumentation>;
192 def PointerArithChecker : Checker<"PointerArithm">,
193 HelpText<"Check for pointer arithmetic on locations other than array "
195 Documentation<HasAlphaDocumentation>;
197 def PointerSubChecker : Checker<"PointerSub">,
198 HelpText<"Check for pointer subtractions on two pointers pointing to "
199 "different memory chunks">,
200 Documentation<HasAlphaDocumentation>;
202 def SizeofPointerChecker : Checker<"SizeofPtr">,
203 HelpText<"Warn about unintended use of sizeof() on pointer expressions">,
204 Documentation<HasAlphaDocumentation>;
206 def CallAndMessageUnInitRefArg : Checker<"CallAndMessageUnInitRefArg">,
207 HelpText<"Check for logical errors for function calls and Objective-C "
208 "message expressions (e.g., uninitialized arguments, null function "
209 "pointers, and pointer to undefined variables)">,
210 Dependencies<[CallAndMessageChecker]>,
211 Documentation<HasAlphaDocumentation>;
213 def TestAfterDivZeroChecker : Checker<"TestAfterDivZero">,
214 HelpText<"Check for division by variable that is later compared against 0. "
215 "Either the comparison is useless or there is division by zero.">,
216 Documentation<HasAlphaDocumentation>;
218 def DynamicTypeChecker : Checker<"DynamicTypeChecker">,
219 HelpText<"Check for cases where the dynamic and the static type of an object "
221 Documentation<HasAlphaDocumentation>;
223 def StackAddrAsyncEscapeChecker : Checker<"StackAddressAsyncEscape">,
224 HelpText<"Check that addresses to stack memory do not escape the function">,
225 Dependencies<[StackAddrEscapeBase]>,
226 Documentation<HasAlphaDocumentation>;
228 } // end "alpha.core"
230 //===----------------------------------------------------------------------===//
231 // Nullability checkers.
232 //===----------------------------------------------------------------------===//
234 let ParentPackage = Nullability in {
236 def NullabilityBase : Checker<"NullabilityBase">,
237 HelpText<"Stores information during the analysis about nullability.">,
238 Documentation<NotDocumented>,
241 def NullPassedToNonnullChecker : Checker<"NullPassedToNonnull">,
242 HelpText<"Warns when a null pointer is passed to a pointer which has a "
244 Dependencies<[NullabilityBase]>,
245 Documentation<HasDocumentation>;
247 def NullReturnedFromNonnullChecker : Checker<"NullReturnedFromNonnull">,
248 HelpText<"Warns when a null pointer is returned from a function that has "
249 "_Nonnull return type.">,
250 Dependencies<[NullabilityBase]>,
251 Documentation<HasDocumentation>;
253 def NullableDereferencedChecker : Checker<"NullableDereferenced">,
254 HelpText<"Warns when a nullable pointer is dereferenced.">,
255 Dependencies<[NullabilityBase]>,
256 Documentation<HasDocumentation>;
258 def NullablePassedToNonnullChecker : Checker<"NullablePassedToNonnull">,
259 HelpText<"Warns when a nullable pointer is passed to a pointer which has a "
261 Dependencies<[NullabilityBase]>,
262 Documentation<HasDocumentation>;
264 def NullableReturnedFromNonnullChecker : Checker<"NullableReturnedFromNonnull">,
265 HelpText<"Warns when a nullable pointer is returned from a function that has "
266 "_Nonnull return type.">,
267 Dependencies<[NullabilityBase]>,
268 Documentation<NotDocumented>;
270 } // end "nullability"
272 //===----------------------------------------------------------------------===//
274 //===----------------------------------------------------------------------===//
276 let ParentPackage = APIModeling in {
278 def StdCLibraryFunctionsChecker : Checker<"StdCLibraryFunctions">,
279 HelpText<"Improve modeling of the C standard library functions">,
280 Documentation<NotDocumented>;
282 def TrustNonnullChecker : Checker<"TrustNonnull">,
283 HelpText<"Trust that returns from framework methods annotated with _Nonnull "
285 Documentation<NotDocumented>;
287 } // end "apiModeling"
289 //===----------------------------------------------------------------------===//
290 // Evaluate "builtin" functions.
291 //===----------------------------------------------------------------------===//
293 let ParentPackage = CoreBuiltin in {
295 def NoReturnFunctionChecker : Checker<"NoReturnFunctions">,
296 HelpText<"Evaluate \"panic\" functions that are known to not return to the "
298 Documentation<NotDocumented>;
300 def BuiltinFunctionChecker : Checker<"BuiltinFunctions">,
301 HelpText<"Evaluate compiler builtin functions (e.g., alloca())">,
302 Documentation<NotDocumented>;
304 } // end "core.builtin"
306 //===----------------------------------------------------------------------===//
307 // Uninitialized values checkers.
308 //===----------------------------------------------------------------------===//
310 let ParentPackage = CoreUninitialized in {
312 def UndefinedArraySubscriptChecker : Checker<"ArraySubscript">,
313 HelpText<"Check for uninitialized values used as array subscripts">,
314 Documentation<HasDocumentation>;
316 def UndefinedAssignmentChecker : Checker<"Assign">,
317 HelpText<"Check for assigning uninitialized values">,
318 Documentation<HasDocumentation>;
320 def UndefBranchChecker : Checker<"Branch">,
321 HelpText<"Check for uninitialized values used as branch conditions">,
322 Documentation<HasDocumentation>;
324 def UndefCapturedBlockVarChecker : Checker<"CapturedBlockVariable">,
325 HelpText<"Check for blocks that capture uninitialized values">,
326 Documentation<NotDocumented>;
328 def ReturnUndefChecker : Checker<"UndefReturn">,
329 HelpText<"Check for uninitialized values being returned to the caller">,
330 Documentation<HasDocumentation>;
332 } // end "core.uninitialized"
334 //===----------------------------------------------------------------------===//
335 // Unix API checkers.
336 //===----------------------------------------------------------------------===//
338 let ParentPackage = CString in {
340 def CStringModeling : Checker<"CStringModeling">,
341 HelpText<"The base of several CString related checkers. On it's own it emits "
342 "no reports, but adds valuable information to the analysis when "
344 Documentation<NotDocumented>,
347 def CStringNullArg : Checker<"NullArg">,
348 HelpText<"Check for null pointers being passed as arguments to C string "
350 Dependencies<[CStringModeling]>,
351 Documentation<HasDocumentation>;
353 def CStringSyntaxChecker : Checker<"BadSizeArg">,
354 HelpText<"Check the size argument passed into C string functions for common "
355 "erroneous patterns">,
356 Dependencies<[CStringModeling]>,
357 Documentation<HasDocumentation>;
359 } // end "unix.cstring"
361 let ParentPackage = CStringAlpha in {
363 def CStringOutOfBounds : Checker<"OutOfBounds">,
364 HelpText<"Check for out-of-bounds access in string functions">,
365 Dependencies<[CStringModeling]>,
366 Documentation<HasAlphaDocumentation>;
368 def CStringBufferOverlap : Checker<"BufferOverlap">,
369 HelpText<"Checks for overlap in two buffer arguments">,
370 Dependencies<[CStringModeling]>,
371 Documentation<HasAlphaDocumentation>;
373 def CStringNotNullTerm : Checker<"NotNullTerminated">,
374 HelpText<"Check for arguments which are not null-terminating strings">,
375 Dependencies<[CStringModeling]>,
376 Documentation<HasAlphaDocumentation>;
378 } // end "alpha.unix.cstring"
380 let ParentPackage = Unix in {
382 def UnixAPIMisuseChecker : Checker<"API">,
383 HelpText<"Check calls to various UNIX/Posix functions">,
384 Documentation<HasDocumentation>;
386 def DynamicMemoryModeling: Checker<"DynamicMemoryModeling">,
387 HelpText<"The base of several malloc() related checkers. On it's own it "
388 "emits no reports, but adds valuable information to the analysis "
391 CmdLineOption<Boolean,
393 "If set to true, the checker assumes that all the "
394 "allocating and deallocating functions are annotated with "
395 "ownership_holds, ownership_takes and ownership_returns.",
399 Dependencies<[CStringModeling]>,
400 Documentation<NotDocumented>,
403 def MallocChecker: Checker<"Malloc">,
404 HelpText<"Check for memory leaks, double free, and use-after-free problems. "
405 "Traces memory managed by malloc()/free().">,
406 Dependencies<[DynamicMemoryModeling]>,
407 Documentation<HasDocumentation>;
409 def MallocSizeofChecker : Checker<"MallocSizeof">,
410 HelpText<"Check for dubious malloc arguments involving sizeof">,
411 Documentation<HasDocumentation>;
413 def MismatchedDeallocatorChecker : Checker<"MismatchedDeallocator">,
414 HelpText<"Check for mismatched deallocators.">,
415 Dependencies<[DynamicMemoryModeling]>,
416 Documentation<HasDocumentation>;
418 def VforkChecker : Checker<"Vfork">,
419 HelpText<"Check for proper usage of vfork">,
420 Documentation<HasDocumentation>;
424 let ParentPackage = UnixAlpha in {
426 def ChrootChecker : Checker<"Chroot">,
427 HelpText<"Check improper use of chroot">,
428 Documentation<HasAlphaDocumentation>;
430 def PthreadLockChecker : Checker<"PthreadLock">,
431 HelpText<"Simple lock -> unlock checker">,
432 Documentation<HasAlphaDocumentation>;
434 def StreamChecker : Checker<"Stream">,
435 HelpText<"Check stream handling functions">,
436 Documentation<HasAlphaDocumentation>;
438 def SimpleStreamChecker : Checker<"SimpleStream">,
439 HelpText<"Check for misuses of stream APIs">,
440 Documentation<HasAlphaDocumentation>;
442 def BlockInCriticalSectionChecker : Checker<"BlockInCriticalSection">,
443 HelpText<"Check for calls to blocking functions inside a critical section">,
444 Documentation<HasAlphaDocumentation>;
446 } // end "alpha.unix"
448 //===----------------------------------------------------------------------===//
450 //===----------------------------------------------------------------------===//
452 let ParentPackage = Cplusplus in {
454 def InnerPointerChecker : Checker<"InnerPointer">,
455 HelpText<"Check for inner pointers of C++ containers used after "
457 Dependencies<[DynamicMemoryModeling]>,
458 Documentation<NotDocumented>;
460 def NewDeleteChecker : Checker<"NewDelete">,
461 HelpText<"Check for double-free and use-after-free problems. Traces memory "
462 "managed by new/delete.">,
463 Dependencies<[DynamicMemoryModeling]>,
464 Documentation<HasDocumentation>;
466 def NewDeleteLeaksChecker : Checker<"NewDeleteLeaks">,
467 HelpText<"Check for memory leaks. Traces memory managed by new/delete.">,
468 Dependencies<[NewDeleteChecker]>,
469 Documentation<HasDocumentation>;
471 def CXXSelfAssignmentChecker : Checker<"SelfAssignment">,
472 HelpText<"Checks C++ copy and move assignment operators for self assignment">,
473 Documentation<NotDocumented>,
476 def SmartPtrModeling: Checker<"SmartPtr">,
477 HelpText<"Model behavior of C++ smart pointers">,
478 Documentation<NotDocumented>,
481 def MoveChecker: Checker<"Move">,
482 HelpText<"Find use-after-move bugs in C++">,
484 CmdLineOption<String,
486 "In non-aggressive mode, only warn on use-after-move of "
487 "local variables (or local rvalue references) and of STL "
488 "objects. The former is possible because local variables (or "
489 "local rvalue references) are not tempting their user to "
490 "re-use the storage. The latter is possible because STL "
491 "objects are known to end up in a valid but unspecified "
492 "state after the move and their state-reset methods are also "
493 "known, which allows us to predict precisely when "
494 "use-after-move is invalid. Some STL objects are known to "
495 "conform to additional contracts after move, so they are not "
496 "tracked. However, smart pointers specifically are tracked "
497 "because we can perform extra checking over them. In "
498 "aggressive mode, warn on any use-after-move because the "
499 "user has intentionally asked us to completely eliminate "
500 "use-after-move in his code. Values: \"KnownsOnly\", "
501 "\"KnownsAndLocals\", \"All\".",
505 Documentation<HasDocumentation>;
507 } // end: "cplusplus"
509 let ParentPackage = CplusplusOptIn in {
511 def UninitializedObjectChecker: Checker<"UninitializedObject">,
512 HelpText<"Reports uninitialized fields after object construction">,
514 CmdLineOption<Boolean,
516 "If set to false, the checker won't emit warnings "
517 "for objects that don't have at least one initialized "
521 CmdLineOption<Boolean,
523 "If set to true, the checker will emit a warning "
524 "for each uninitalized field, as opposed to emitting one "
525 "warning per constructor call, and listing the uninitialized "
526 "fields that belongs to it in notes.",
530 CmdLineOption<Boolean,
531 "CheckPointeeInitialization",
532 "If set to false, the checker will not analyze "
533 "the pointee of pointer/reference fields, and will only "
534 "check whether the object itself is initialized.",
537 CmdLineOption<String,
538 "IgnoreRecordsWithField",
539 "If supplied, the checker will not analyze "
540 "structures that have a field with a name or type name that "
541 "matches the given pattern.",
544 CmdLineOption<Boolean,
545 "IgnoreGuardedFields",
546 "If set to true, the checker will analyze _syntactically_ "
547 "whether the found uninitialized object is used without a "
548 "preceding assert call. Defaults to false.",
552 Documentation<HasAlphaDocumentation>;
554 def VirtualCallChecker : Checker<"VirtualCall">,
555 HelpText<"Check virtual function calls during construction or destruction">,
557 CmdLineOption<Boolean,
559 "Whether to only report calls to pure virtual methods.",
563 Documentation<HasDocumentation>;
565 } // end: "optin.cplusplus"
567 let ParentPackage = CplusplusAlpha in {
569 def DeleteWithNonVirtualDtorChecker : Checker<"DeleteWithNonVirtualDtor">,
570 HelpText<"Reports destructions of polymorphic objects with a non-virtual "
571 "destructor in their base class">,
572 Documentation<HasAlphaDocumentation>;
574 def EnumCastOutOfRangeChecker : Checker<"EnumCastOutOfRange">,
575 HelpText<"Check integer to enumeration casts for out of range values">,
576 Documentation<HasAlphaDocumentation>;
578 def IteratorModeling : Checker<"IteratorModeling">,
579 HelpText<"Models iterators of C++ containers">,
580 Documentation<NotDocumented>,
583 def InvalidatedIteratorChecker : Checker<"InvalidatedIterator">,
584 HelpText<"Check for use of invalidated iterators">,
585 Dependencies<[IteratorModeling]>,
586 Documentation<HasAlphaDocumentation>;
588 def IteratorRangeChecker : Checker<"IteratorRange">,
589 HelpText<"Check for iterators used outside their valid ranges">,
590 Dependencies<[IteratorModeling]>,
591 Documentation<HasAlphaDocumentation>;
593 def MismatchedIteratorChecker : Checker<"MismatchedIterator">,
594 HelpText<"Check for use of iterators of different containers where iterators "
595 "of the same container are expected">,
596 Dependencies<[IteratorModeling]>,
597 Documentation<HasAlphaDocumentation>;
599 } // end: "alpha.cplusplus"
602 //===----------------------------------------------------------------------===//
604 //===----------------------------------------------------------------------===//
606 let ParentPackage = Valist in {
608 def ValistBase : Checker<"ValistBase">,
609 HelpText<"Gathers information about va_lists.">,
610 Documentation<NotDocumented>,
613 def UninitializedChecker : Checker<"Uninitialized">,
614 HelpText<"Check for usages of uninitialized (or already released) va_lists.">,
615 Dependencies<[ValistBase]>,
616 Documentation<NotDocumented>;
618 def UnterminatedChecker : Checker<"Unterminated">,
619 HelpText<"Check for va_lists which are not released by a va_end call.">,
620 Dependencies<[ValistBase]>,
621 Documentation<NotDocumented>;
623 def CopyToSelfChecker : Checker<"CopyToSelf">,
624 HelpText<"Check for va_lists which are copied onto itself.">,
625 Dependencies<[ValistBase]>,
626 Documentation<NotDocumented>;
630 //===----------------------------------------------------------------------===//
631 // Deadcode checkers.
632 //===----------------------------------------------------------------------===//
634 let ParentPackage = DeadCode in {
636 def DeadStoresChecker : Checker<"DeadStores">,
637 HelpText<"Check for values stored to variables that are never read "
639 Documentation<HasDocumentation>;
643 let ParentPackage = DeadCodeAlpha in {
645 def UnreachableCodeChecker : Checker<"UnreachableCode">,
646 HelpText<"Check unreachable code">,
647 Documentation<HasAlphaDocumentation>;
649 } // end "alpha.deadcode"
651 //===----------------------------------------------------------------------===//
652 // Performance checkers.
653 //===----------------------------------------------------------------------===//
655 let ParentPackage = Performance in {
657 def PaddingChecker : Checker<"Padding">,
658 HelpText<"Check for excessively padded structs.">,
660 CmdLineOption<Integer,
662 "Reports are only generated if the excessive padding exceeds "
663 "'AllowedPad' in bytes.",
667 Documentation<NotDocumented>;
671 //===----------------------------------------------------------------------===//
672 // Security checkers.
673 //===----------------------------------------------------------------------===//
675 let ParentPackage = InsecureAPI in {
677 def SecuritySyntaxChecker : Checker<"SecuritySyntaxChecker">,
678 HelpText<"Base of various security function related checkers">,
679 Documentation<NotDocumented>,
682 def bcmp : Checker<"bcmp">,
683 HelpText<"Warn on uses of the 'bcmp' function">,
684 Dependencies<[SecuritySyntaxChecker]>,
685 Documentation<HasDocumentation>;
687 def bcopy : Checker<"bcopy">,
688 HelpText<"Warn on uses of the 'bcopy' function">,
689 Dependencies<[SecuritySyntaxChecker]>,
690 Documentation<HasDocumentation>;
692 def bzero : Checker<"bzero">,
693 HelpText<"Warn on uses of the 'bzero' function">,
694 Dependencies<[SecuritySyntaxChecker]>,
695 Documentation<HasDocumentation>;
697 def gets : Checker<"gets">,
698 HelpText<"Warn on uses of the 'gets' function">,
699 Dependencies<[SecuritySyntaxChecker]>,
700 Documentation<HasDocumentation>;
702 def getpw : Checker<"getpw">,
703 HelpText<"Warn on uses of the 'getpw' function">,
704 Dependencies<[SecuritySyntaxChecker]>,
705 Documentation<HasDocumentation>;
707 def mktemp : Checker<"mktemp">,
708 HelpText<"Warn on uses of the 'mktemp' function">,
709 Dependencies<[SecuritySyntaxChecker]>,
710 Documentation<HasDocumentation>;
712 def mkstemp : Checker<"mkstemp">,
713 HelpText<"Warn when 'mkstemp' is passed fewer than 6 X's in the format "
715 Dependencies<[SecuritySyntaxChecker]>,
716 Documentation<HasDocumentation>;
718 def rand : Checker<"rand">,
719 HelpText<"Warn on uses of the 'rand', 'random', and related functions">,
720 Dependencies<[SecuritySyntaxChecker]>,
721 Documentation<HasDocumentation>;
723 def strcpy : Checker<"strcpy">,
724 HelpText<"Warn on uses of the 'strcpy' and 'strcat' functions">,
725 Dependencies<[SecuritySyntaxChecker]>,
726 Documentation<HasDocumentation>;
728 def vfork : Checker<"vfork">,
729 HelpText<"Warn on uses of the 'vfork' function">,
730 Dependencies<[SecuritySyntaxChecker]>,
731 Documentation<HasDocumentation>;
733 def UncheckedReturn : Checker<"UncheckedReturn">,
734 HelpText<"Warn on uses of functions whose return values must be always "
736 Dependencies<[SecuritySyntaxChecker]>,
737 Documentation<HasDocumentation>;
739 def DeprecatedOrUnsafeBufferHandling :
740 Checker<"DeprecatedOrUnsafeBufferHandling">,
741 HelpText<"Warn on uses of unsecure or deprecated buffer manipulating "
743 Dependencies<[SecuritySyntaxChecker]>,
744 Documentation<HasDocumentation>;
746 } // end "security.insecureAPI"
748 let ParentPackage = Security in {
750 def FloatLoopCounter : Checker<"FloatLoopCounter">,
751 HelpText<"Warn on using a floating point value as a loop counter (CERT: "
752 "FLP30-C, FLP30-CPP)">,
753 Dependencies<[SecuritySyntaxChecker]>,
754 Documentation<HasDocumentation>;
758 let ParentPackage = SecurityAlpha in {
760 def ArrayBoundChecker : Checker<"ArrayBound">,
761 HelpText<"Warn about buffer overflows (older checker)">,
762 Documentation<HasAlphaDocumentation>;
764 def ArrayBoundCheckerV2 : Checker<"ArrayBoundV2">,
765 HelpText<"Warn about buffer overflows (newer checker)">,
766 Documentation<HasAlphaDocumentation>;
768 def ReturnPointerRangeChecker : Checker<"ReturnPtrRange">,
769 HelpText<"Check for an out-of-bound pointer being returned to callers">,
770 Documentation<HasAlphaDocumentation>;
772 def MallocOverflowSecurityChecker : Checker<"MallocOverflow">,
773 HelpText<"Check for overflows in the arguments to malloc()">,
774 Documentation<HasAlphaDocumentation>;
776 def MmapWriteExecChecker : Checker<"MmapWriteExec">,
777 HelpText<"Warn on mmap() calls that are both writable and executable">,
779 CmdLineOption<Integer,
781 "Specifies the value of PROT_EXEC",
784 CmdLineOption<Integer,
786 "Specifies the value of PROT_READ",
790 Documentation<HasAlphaDocumentation>;
792 } // end "alpha.security"
794 //===----------------------------------------------------------------------===//
796 //===----------------------------------------------------------------------===//
798 let ParentPackage = Taint in {
800 def GenericTaintChecker : Checker<"TaintPropagation">,
801 HelpText<"Generate taint information used by other checkers">,
802 Documentation<HasAlphaDocumentation>;
804 } // end "alpha.security.taint"
806 //===----------------------------------------------------------------------===//
807 // Mac OS X, Cocoa, and Core Foundation checkers.
808 //===----------------------------------------------------------------------===//
810 let ParentPackage = Cocoa in {
812 def RetainCountBase : Checker<"RetainCountBase">,
813 HelpText<"Common base of various retain count related checkers">,
814 Documentation<NotDocumented>,
819 let ParentPackage = OSX in {
821 def NSOrCFErrorDerefChecker : Checker<"NSOrCFErrorDerefChecker">,
822 HelpText<"Implementation checker for NSErrorChecker and CFErrorChecker">,
823 Documentation<NotDocumented>,
826 def NumberObjectConversionChecker : Checker<"NumberObjectConversion">,
827 HelpText<"Check for erroneous conversions of objects representing numbers "
830 CmdLineOption<Boolean,
832 "Enables detection of more conversion patterns (which are "
833 "most likely more harmless, and therefore are more likely to "
834 "produce false positives).",
838 Documentation<NotDocumented>;
840 def MacOSXAPIChecker : Checker<"API">,
841 HelpText<"Check for proper uses of various Apple APIs">,
842 Documentation<HasDocumentation>;
844 def MacOSKeychainAPIChecker : Checker<"SecKeychainAPI">,
845 HelpText<"Check for proper uses of Secure Keychain APIs">,
846 Documentation<HasDocumentation>;
848 def MIGChecker : Checker<"MIG">,
849 HelpText<"Find violations of the Mach Interface Generator "
850 "calling convention">,
851 Documentation<NotDocumented>;
853 def ObjCPropertyChecker : Checker<"ObjCProperty">,
854 HelpText<"Check for proper uses of Objective-C properties">,
855 Documentation<NotDocumented>;
857 def OSObjectRetainCountChecker : Checker<"OSObjectRetainCount">,
858 HelpText<"Check for leaks and improper reference count management for "
860 Dependencies<[RetainCountBase]>,
861 Documentation<NotDocumented>;
865 let ParentPackage = Cocoa in {
867 def RunLoopAutoreleaseLeakChecker : Checker<"RunLoopAutoreleaseLeak">,
868 HelpText<"Check for leaked memory in autorelease pools that will never be "
870 Documentation<NotDocumented>;
872 def ObjCAtSyncChecker : Checker<"AtSync">,
873 HelpText<"Check for nil pointers used as mutexes for @synchronized">,
874 Documentation<HasDocumentation>;
876 def NilArgChecker : Checker<"NilArg">,
877 HelpText<"Check for prohibited nil arguments to ObjC method calls">,
878 Documentation<HasDocumentation>;
880 def ClassReleaseChecker : Checker<"ClassRelease">,
881 HelpText<"Check for sending 'retain', 'release', or 'autorelease' directly "
883 Documentation<HasDocumentation>;
885 def VariadicMethodTypeChecker : Checker<"VariadicMethodTypes">,
886 HelpText<"Check for passing non-Objective-C types to variadic collection "
887 "initialization methods that expect only Objective-C types">,
888 Documentation<HasDocumentation>;
890 def NSAutoreleasePoolChecker : Checker<"NSAutoreleasePool">,
891 HelpText<"Warn for suboptimal uses of NSAutoreleasePool in Objective-C GC "
893 Documentation<HasDocumentation>;
895 def ObjCMethSigsChecker : Checker<"IncompatibleMethodTypes">,
896 HelpText<"Warn about Objective-C method signatures with type "
897 "incompatibilities">,
898 Documentation<HasDocumentation>;
900 def ObjCUnusedIvarsChecker : Checker<"UnusedIvars">,
901 HelpText<"Warn about private ivars that are never used">,
902 Documentation<HasDocumentation>;
904 def ObjCSelfInitChecker : Checker<"SelfInit">,
905 HelpText<"Check that 'self' is properly initialized inside an initializer "
907 Documentation<HasDocumentation>;
909 def ObjCLoopChecker : Checker<"Loops">,
910 HelpText<"Improved modeling of loops using Cocoa collection types">,
911 Documentation<NotDocumented>;
913 def ObjCNonNilReturnValueChecker : Checker<"NonNilReturnValue">,
914 HelpText<"Model the APIs that are guaranteed to return a non-nil value">,
915 Documentation<NotDocumented>;
917 def ObjCSuperCallChecker : Checker<"MissingSuperCall">,
918 HelpText<"Warn about Objective-C methods that lack a necessary call to "
920 Documentation<NotDocumented>;
922 def NSErrorChecker : Checker<"NSError">,
923 HelpText<"Check usage of NSError** parameters">,
924 Dependencies<[NSOrCFErrorDerefChecker]>,
925 Documentation<HasDocumentation>;
927 def RetainCountChecker : Checker<"RetainCount">,
928 HelpText<"Check for leaks and improper reference count management">,
930 CmdLineOption<Boolean,
932 "Find violations of retain-release rules applied to XNU "
933 "OSObject instances. By default, the checker only checks "
934 "retain-release rules for Objective-C NSObject instances "
935 "and CoreFoundation objects.",
939 CmdLineOption<Boolean,
940 "TrackNSCFStartParam",
941 "Check not only that the code follows retain-release rules "
942 "with respect to objects it allocates or borrows from "
943 "elsewhere, but also that it fulfills its own retain count "
944 "specification with respect to objects that it receives as "
949 Dependencies<[RetainCountBase]>,
950 Documentation<HasDocumentation>;
952 def ObjCGenericsChecker : Checker<"ObjCGenerics">,
953 HelpText<"Check for type errors when using Objective-C generics">,
954 Dependencies<[DynamicTypePropagation]>,
955 Documentation<HasDocumentation>;
957 def ObjCDeallocChecker : Checker<"Dealloc">,
958 HelpText<"Warn about Objective-C classes that lack a correct implementation "
960 Documentation<HasDocumentation>;
962 def ObjCSuperDeallocChecker : Checker<"SuperDealloc">,
963 HelpText<"Warn about improper use of '[super dealloc]' in Objective-C">,
964 Documentation<HasDocumentation>;
966 def AutoreleaseWriteChecker : Checker<"AutoreleaseWrite">,
967 HelpText<"Warn about potentially crashing writes to autoreleasing objects "
968 "from different autoreleasing pools in Objective-C">,
969 Documentation<NotDocumented>;
973 let ParentPackage = Performance in {
975 def GCDAntipattern : Checker<"GCDAntipattern">,
976 HelpText<"Check for performance anti-patterns when using Grand Central "
978 Documentation<NotDocumented>;
979 } // end "optin.performance"
981 let ParentPackage = OSXOptIn in {
983 def OSObjectCStyleCast : Checker<"OSObjectCStyleCast">,
984 HelpText<"Checker for C-style casts of OSObjects">,
985 Documentation<NotDocumented>;
989 let ParentPackage = CocoaAlpha in {
991 def IvarInvalidationModeling : Checker<"IvarInvalidationModeling">,
992 HelpText<"Gathers information for annotation driven invalidation checking "
993 "for classes that contains a method annotated with "
994 "'objc_instance_variable_invalidator'">,
995 Documentation<NotDocumented>,
998 def InstanceVariableInvalidation : Checker<"InstanceVariableInvalidation">,
999 HelpText<"Check that the invalidatable instance variables are invalidated in "
1000 "the methods annotated with objc_instance_variable_invalidator">,
1001 Dependencies<[IvarInvalidationModeling]>,
1002 Documentation<HasAlphaDocumentation>;
1004 def MissingInvalidationMethod : Checker<"MissingInvalidationMethod">,
1005 HelpText<"Check that the invalidation methods are present in classes that "
1006 "contain invalidatable instance variables">,
1007 Dependencies<[IvarInvalidationModeling]>,
1008 Documentation<HasAlphaDocumentation>;
1010 def DirectIvarAssignment : Checker<"DirectIvarAssignment">,
1011 HelpText<"Check for direct assignments to instance variables">,
1012 Documentation<HasAlphaDocumentation>;
1014 def DirectIvarAssignmentForAnnotatedFunctions :
1015 Checker<"DirectIvarAssignmentForAnnotatedFunctions">,
1016 HelpText<"Check for direct assignments to instance variables in the methods "
1017 "annotated with objc_no_direct_instance_variable_assignment">,
1018 Dependencies<[DirectIvarAssignment]>,
1019 Documentation<HasAlphaDocumentation>;
1021 } // end "alpha.osx.cocoa"
1023 let ParentPackage = CoreFoundation in {
1025 def CFNumberChecker : Checker<"CFNumber">,
1026 HelpText<"Check for proper uses of CFNumber APIs">,
1027 Documentation<HasDocumentation>;
1029 def CFRetainReleaseChecker : Checker<"CFRetainRelease">,
1030 HelpText<"Check for null arguments to CFRetain/CFRelease/CFMakeCollectable">,
1031 Documentation<HasDocumentation>;
1033 def CFErrorChecker : Checker<"CFError">,
1034 HelpText<"Check usage of CFErrorRef* parameters">,
1035 Dependencies<[NSOrCFErrorDerefChecker]>,
1036 Documentation<HasDocumentation>;
1038 } // end "osx.coreFoundation"
1040 let ParentPackage = Containers in {
1042 def ObjCContainersASTChecker : Checker<"PointerSizedValues">,
1043 HelpText<"Warns if 'CFArray', 'CFDictionary', 'CFSet' are created with "
1044 "non-pointer-size values">,
1045 Documentation<HasDocumentation>;
1047 def ObjCContainersChecker : Checker<"OutOfBounds">,
1048 HelpText<"Checks for index out-of-bounds when using 'CFArray' API">,
1049 Documentation<HasDocumentation>;
1051 } // end "osx.coreFoundation.containers"
1053 let ParentPackage = LocalizabilityOptIn in {
1055 def NonLocalizedStringChecker : Checker<"NonLocalizedStringChecker">,
1056 HelpText<"Warns about uses of non-localized NSStrings passed to UI methods "
1057 "expecting localized NSStrings">,
1059 CmdLineOption<Boolean,
1061 "Marks a string being returned by any call as localized if "
1062 "it is in LocStringFunctions (LSF) or the function is "
1063 "annotated. Otherwise, we mark it as NonLocalized "
1064 "(Aggressive) or NonLocalized only if it is not backed by a "
1065 "SymRegion (Non-Aggressive), basically leaving only string "
1066 "literals as NonLocalized.",
1071 Documentation<HasDocumentation>;
1073 def EmptyLocalizationContextChecker :
1074 Checker<"EmptyLocalizationContextChecker">,
1075 HelpText<"Check that NSLocalizedString macros include a comment for context">,
1076 Documentation<HasDocumentation>;
1078 } // end "optin.osx.cocoa.localizability"
1080 let ParentPackage = LocalizabilityAlpha in {
1082 def PluralMisuseChecker : Checker<"PluralMisuseChecker">,
1083 HelpText<"Warns against using one vs. many plural pattern in code when "
1084 "generating localized strings.">,
1085 Documentation<HasAlphaDocumentation>;
1087 } // end "alpha.osx.cocoa.localizability"
1089 let ParentPackage = MPI in {
1091 def MPIChecker : Checker<"MPI-Checker">,
1092 HelpText<"Checks MPI code">,
1093 Documentation<HasDocumentation>;
1095 } // end "optin.mpi"
1097 //===----------------------------------------------------------------------===//
1098 // Checkers for LLVM development.
1099 //===----------------------------------------------------------------------===//
1101 let ParentPackage = LLVMAlpha in {
1103 def LLVMConventionsChecker : Checker<"Conventions">,
1104 HelpText<"Check code for LLVM codebase conventions">,
1105 Documentation<HasAlphaDocumentation>;
1109 let ParentPackage = LLVMAPIModeling in {
1111 def CastValueChecker : Checker<"CastValue">,
1112 HelpText<"Model implementation of custom RTTIs">,
1113 Documentation<NotDocumented>;
1115 def ReturnValueChecker : Checker<"ReturnValue">,
1116 HelpText<"Model the guaranteed boolean return value of function calls">,
1117 Documentation<NotDocumented>;
1119 } // end "apiModeling.llvm"
1121 //===----------------------------------------------------------------------===//
1122 // Checkers modeling Google APIs.
1123 //===----------------------------------------------------------------------===//
1125 let ParentPackage = GoogleAPIModeling in {
1127 def GTestChecker : Checker<"GTest">,
1128 HelpText<"Model gtest assertion APIs">,
1129 Documentation<NotDocumented>;
1131 } // end "apiModeling.google"
1133 //===----------------------------------------------------------------------===//
1134 // Debugging checkers (for analyzer development).
1135 //===----------------------------------------------------------------------===//
1137 let ParentPackage = Debug in {
1139 def AnalysisOrderChecker : Checker<"AnalysisOrder">,
1140 HelpText<"Print callbacks that are called during analysis in order">,
1142 CmdLineOption<Boolean,
1148 CmdLineOption<Boolean,
1154 CmdLineOption<Boolean,
1155 "PreStmtArraySubscriptExpr",
1160 CmdLineOption<Boolean,
1161 "PostStmtArraySubscriptExpr",
1166 CmdLineOption<Boolean,
1167 "PreStmtCXXNewExpr",
1172 CmdLineOption<Boolean,
1173 "PostStmtCXXNewExpr",
1178 CmdLineOption<Boolean,
1179 "PreStmtOffsetOfExpr",
1184 CmdLineOption<Boolean,
1185 "PostStmtOffsetOfExpr",
1190 CmdLineOption<Boolean,
1196 CmdLineOption<Boolean,
1202 CmdLineOption<Boolean,
1208 CmdLineOption<Boolean,
1214 CmdLineOption<Boolean,
1220 CmdLineOption<Boolean,
1226 CmdLineOption<Boolean,
1232 CmdLineOption<Boolean,
1234 "Enables all callbacks.",
1239 Documentation<NotDocumented>;
1241 def DominatorsTreeDumper : Checker<"DumpDominators">,
1242 HelpText<"Print the dominance tree for a given CFG">,
1243 Documentation<NotDocumented>;
1245 def PostDominatorsTreeDumper : Checker<"DumpPostDominators">,
1246 HelpText<"Print the post dominance tree for a given CFG">,
1247 Documentation<NotDocumented>;
1249 def ControlDependencyTreeDumper : Checker<"DumpControlDependencies">,
1250 HelpText<"Print the post control dependency tree for a given CFG">,
1251 Documentation<NotDocumented>;
1253 def LiveVariablesDumper : Checker<"DumpLiveVars">,
1254 HelpText<"Print results of live variable analysis">,
1255 Documentation<NotDocumented>;
1257 def LiveStatementsDumper : Checker<"DumpLiveStmts">,
1258 HelpText<"Print results of live statement analysis">,
1259 Documentation<NotDocumented>;
1261 def CFGViewer : Checker<"ViewCFG">,
1262 HelpText<"View Control-Flow Graphs using GraphViz">,
1263 Documentation<NotDocumented>;
1265 def CFGDumper : Checker<"DumpCFG">,
1266 HelpText<"Display Control-Flow Graphs">,
1267 Documentation<NotDocumented>;
1269 def CallGraphViewer : Checker<"ViewCallGraph">,
1270 HelpText<"View Call Graph using GraphViz">,
1271 Documentation<NotDocumented>;
1273 def CallGraphDumper : Checker<"DumpCallGraph">,
1274 HelpText<"Display Call Graph">,
1275 Documentation<NotDocumented>;
1277 def ConfigDumper : Checker<"ConfigDumper">,
1278 HelpText<"Dump config table">,
1279 Documentation<NotDocumented>;
1281 def TraversalDumper : Checker<"DumpTraversal">,
1282 HelpText<"Print branch conditions as they are traversed by the engine">,
1283 Documentation<NotDocumented>;
1285 def CallDumper : Checker<"DumpCalls">,
1286 HelpText<"Print calls as they are traversed by the engine">,
1287 Documentation<NotDocumented>;
1289 def AnalyzerStatsChecker : Checker<"Stats">,
1290 HelpText<"Emit warnings with analyzer statistics">,
1291 Documentation<NotDocumented>;
1293 def TaintTesterChecker : Checker<"TaintTest">,
1294 HelpText<"Mark tainted symbols as such.">,
1295 Documentation<NotDocumented>;
1297 def ExprInspectionChecker : Checker<"ExprInspection">,
1298 HelpText<"Check the analyzer's understanding of expressions">,
1299 Documentation<NotDocumented>;
1301 def ExplodedGraphViewer : Checker<"ViewExplodedGraph">,
1302 HelpText<"View Exploded Graphs using GraphViz">,
1303 Documentation<NotDocumented>;
1305 def ReportStmts : Checker<"ReportStmts">,
1306 HelpText<"Emits a warning for every statement.">,
1307 Documentation<NotDocumented>;
1312 //===----------------------------------------------------------------------===//
1314 //===----------------------------------------------------------------------===//
1316 let ParentPackage = CloneDetectionAlpha in {
1318 def CloneChecker : Checker<"CloneChecker">,
1319 HelpText<"Reports similar pieces of code.">,
1321 CmdLineOption<Integer,
1322 "MinimumCloneComplexity",
1323 "Ensures that every clone has at least the given complexity. "
1324 "Complexity is here defined as the total amount of children "
1325 "of a statement. This constraint assumes the first statement "
1326 "in the group is representative for all other statements in "
1327 "the group in terms of complexity.",
1330 CmdLineOption<Boolean,
1331 "ReportNormalClones",
1332 "Report all clones, even less suspicious ones.",
1335 CmdLineOption<String,
1336 "IgnoredFilesPattern",
1337 "If supplied, the checker wont analyze files with a filename "
1338 "that matches the given pattern.",
1342 Documentation<HasAlphaDocumentation>;
1346 //===----------------------------------------------------------------------===//
1347 // Portability checkers.
1348 //===----------------------------------------------------------------------===//
1350 let ParentPackage = PortabilityOptIn in {
1352 def UnixAPIPortabilityChecker : Checker<"UnixAPI">,
1353 HelpText<"Finds implementation-defined behavior in UNIX/Posix functions">,
1354 Documentation<NotDocumented>;
1356 } // end optin.portability
1358 //===----------------------------------------------------------------------===//
1359 // NonDeterminism checkers.
1360 //===----------------------------------------------------------------------===//
1362 let ParentPackage = NonDeterminismAlpha in {
1364 def PointerIterationChecker : Checker<"PointerIteration">,
1365 HelpText<"Checks for non-determinism caused by iteration of unordered containers of pointers">,
1366 Documentation<HasDocumentation>;
1368 def PointerSortingChecker : Checker<"PointerSorting">,
1369 HelpText<"Check for non-determinism caused by sorting of pointers">,
1370 Documentation<HasDocumentation>;
1372 } // end alpha.nondeterminism