From bf18f1b3535dd17f9bf584cab15ee6a7fd431257 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Fri, 30 Oct 2015 16:05:42 +0100 Subject: compilerplugins: add "badstatics" to detect abuse of VCL Bitmaps VCL Image/Bitmap/BitmapEx instances must not have static life-time because then they will be destructed after DeInitVCL() and that likely segfaults. Change-Id: I3ff8d32de729c971b190028094cb4efe206395e2 --- compilerplugins/clang/badstatics.cxx | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 compilerplugins/clang/badstatics.cxx (limited to 'compilerplugins') diff --git a/compilerplugins/clang/badstatics.cxx b/compilerplugins/clang/badstatics.cxx new file mode 100644 index 000000000000..136e1db90d20 --- /dev/null +++ b/compilerplugins/clang/badstatics.cxx @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "plugin.hxx" + +namespace { + +class BadStatics + : public clang::RecursiveASTVisitor + , public loplugin::Plugin +{ + +public: + explicit BadStatics(InstantiationData const& rData) : Plugin(rData) {} + + void run() override { + if (compiler.getLangOpts().CPlusPlus) { // no non-trivial dtors in C + TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); + } + } + + bool VisitVarDecl(VarDecl const*const pVarDecl) + { + if (ignoreLocation(pVarDecl)) { + return true; + } + + if (pVarDecl->hasGlobalStorage()) { + auto const type(pVarDecl->getType().getUnqualifiedType().getCanonicalType().getAsString()); + if ( type == "class Image" + || type == "class Bitmap" + || type == "class BitmapEx" + ) + { + report(DiagnosticsEngine::Warning, + "bad static variable causes crash on shutdown", + pVarDecl->getLocation()) + << pVarDecl->getSourceRange(); + } + } + + return true; + } + +}; + +loplugin::Plugin::Registration X("badstatics"); + +} // namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit