summaryrefslogtreecommitdiff
path: root/compilerplugins/clang
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2015-10-30 16:05:42 +0100
committerMichael Stahl <mstahl@redhat.com>2015-11-02 16:39:19 +0100
commitbf18f1b3535dd17f9bf584cab15ee6a7fd431257 (patch)
treecb6e4c720f93f614372fc0c2ed8336a8bda78ce5 /compilerplugins/clang
parentbcd8da6849780b9680963ef3313d14209a46e5fa (diff)
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
Diffstat (limited to 'compilerplugins/clang')
-rw-r--r--compilerplugins/clang/badstatics.cxx57
1 files changed, 57 insertions, 0 deletions
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<BadStatics>
+ , 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<BadStatics> X("badstatics");
+
+} // namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */