Index: include/clang/StaticAnalyzer/Checkers/Checkers.td =================================================================== --- include/clang/StaticAnalyzer/Checkers/Checkers.td +++ include/clang/StaticAnalyzer/Checkers/Checkers.td @@ -522,6 +522,10 @@ HelpText<"Check for calls to blocking functions inside a critical section">, DescFile<"BlockInCriticalSectionChecker.cpp">; +def TimeChecker : Checker<"Time">, + HelpText<"Check time.h related functionality">, + DescFile<"TimeChecker.cpp">; + } // end "alpha.unix" let ParentPackage = CString in { Index: lib/StaticAnalyzer/Checkers/CMakeLists.txt =================================================================== --- lib/StaticAnalyzer/Checkers/CMakeLists.txt +++ lib/StaticAnalyzer/Checkers/CMakeLists.txt @@ -87,6 +87,7 @@ StreamChecker.cpp TaintTesterChecker.cpp TestAfterDivZeroChecker.cpp + TimeChecker.cpp TraversalChecker.cpp TrustNonnullChecker.cpp UndefBranchChecker.cpp Index: lib/StaticAnalyzer/Checkers/TimeChecker.cpp =================================================================== --- /dev/null +++ lib/StaticAnalyzer/Checkers/TimeChecker.cpp @@ -0,0 +1,59 @@ +//===-- TimeChecker.cpp -------------------------------------------*- C++ -*--// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Defines a checker for proper definition/use of time.h related functionality. +// +//===----------------------------------------------------------------------===// + +#include "ClangSACheckers.h" +#include "clang/AST/RecursiveASTVisitor.h" +#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h" +#include "clang/StaticAnalyzer/Core/Checker.h" +#include "clang/StaticAnalyzer/Core/CheckerManager.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h" + +using namespace clang; +using namespace ento; + +namespace { +class TimeVisitor : public RecursiveASTVisitor { + BugReporter &BR; + const CheckerBase *Checker; + AnalysisDeclContext *AC; + +public: + explicit TimeVisitor(BugReporter &B, const CheckerBase *Checker, + AnalysisDeclContext *A) + : BR(B), Checker(Checker), AC(A) {} + bool VisitCastExpr(const CastExpr *CE); +}; +} // namespace + +bool TimeVisitor::VisitCastExpr(const CastExpr *CE) { + + // Implement check for casts on time_t values to types + // that are of shorter width or are unsigned, etc. + + return true; +} + +namespace { +class TimeChecker : public Checker { +public: + void checkASTCodeBody(const Decl *D, AnalysisManager &Mgr, + BugReporter &BR) const { + TimeVisitor Visitor(BR, this, Mgr.getAnalysisDeclContext(D)); + Visitor.TraverseDecl(const_cast(D)); + } +}; +} // end anonymous namespace + +void ento::registerTimeChecker(CheckerManager &mgr) { + mgr.registerChecker(); +} Index: test/Analysis/TimeCheckerRegistration.cpp =================================================================== --- /dev/null +++ test/Analysis/TimeCheckerRegistration.cpp @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 -analyzer-checker-help | FileCheck %s + +CHECK: alpha.unix.Time Check time.h related functionality