blob: 549c3b5fe96801b849c4eb9ab132d9bf208d7051 [file] [log] [blame]
Zhongxing Xu8958fff2009-11-03 06:46:03 +00001//===--- 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
18using namespace clang;
19
20void *UndefinedArgChecker::getTag() {
21 static int x = 0;
22 return &x;
23}
24
25void 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 Kremenek2c791bd2009-11-06 00:44:32 +000032 BT = new BuiltinBug("Pass-by-value argument in function call is "
33 "undefined");
Zhongxing Xu8958fff2009-11-03 06:46:03 +000034 // 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}