update credits
[LibreOffice.git] / compilerplugins / clang / derefnullptr.cxx
blob35c4c7adcf6c0e4411e64dbb27bc7dfffbaffd5a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #ifndef LO_CLANG_SHARED_PLUGINS
12 #include "plugin.hxx"
14 namespace {
16 class DerefNullPtr:
17 public loplugin::FilteringPlugin<DerefNullPtr>
19 public:
20 explicit DerefNullPtr(loplugin::InstantiationData const & data):
21 FilteringPlugin(data) {}
23 void run() override
24 { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
26 bool VisitUnaryOperator(UnaryOperator const * op);
29 bool DerefNullPtr::VisitUnaryOperator(UnaryOperator const * op) {
30 if (op->getOpcode() != UO_Deref) {
31 return true;
33 if (!ignoreLocation(op)
34 && (op->getSubExpr()->IgnoreParenCasts()->isNullPointerConstant(
35 compiler.getASTContext(), Expr::NPC_ValueDependentIsNotNull/*TODO*/)
36 != Expr::NPCK_NotNull))
38 report(
39 DiagnosticsEngine::Warning, "null pointer dereference",
40 op->getBeginLoc())
41 << op->getSourceRange();
43 return true;
46 loplugin::Plugin::Registration<DerefNullPtr> derefnullptr("derefnullptr");
50 #endif // LO_CLANG_SHARED_PLUGINS
52 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */