Zhongxing Xu | 8958fff | 2009-11-03 06:46:03 +0000 | [diff] [blame] | 1 | //===--- UndefinedArgChecker.h - Undefined arguments checker ----*- C++ -*--==// |
| 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 | // |
| 10 | // This defines BadCallChecker, a builtin check in GRExprEngine that performs |
| 11 | // checks for undefined arguments. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "clang/Analysis/PathSensitive/Checkers/UndefinedArgChecker.h" |
| 16 | #include "clang/Analysis/PathSensitive/BugReporter.h" |
| 17 | |
| 18 | using namespace clang; |
| 19 | |
| 20 | void *UndefinedArgChecker::getTag() { |
| 21 | static int x = 0; |
| 22 | return &x; |
| 23 | } |
| 24 | |
| 25 | void UndefinedArgChecker::PreVisitCallExpr(CheckerContext &C, |
| 26 | const CallExpr *CE){ |
| 27 | for (CallExpr::const_arg_iterator I = CE->arg_begin(), E = CE->arg_end(); |
| 28 | I != E; ++I) { |
| 29 | if (C.getState()->getSVal(*I).isUndef()) { |
| 30 | if (ExplodedNode *N = C.GenerateNode(CE, true)) { |
| 31 | if (!BT) |
Ted Kremenek | 2c791bd | 2009-11-06 00:44:32 +0000 | [diff] [blame^] | 32 | BT = new BuiltinBug("Pass-by-value argument in function call is " |
| 33 | "undefined"); |
Zhongxing Xu | 8958fff | 2009-11-03 06:46:03 +0000 | [diff] [blame] | 34 | // Generate a report for this bug. |
| 35 | EnhancedBugReport *R = new EnhancedBugReport(*BT, BT->getName().c_str(), |
| 36 | N); |
| 37 | R->addRange((*I)->getSourceRange()); |
| 38 | R->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue, *I); |
| 39 | C.EmitReport(R); |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | } |