bump product version to 6.4.0.3
[LibreOffice.git] / compilerplugins / clang / dllprivate.cxx
blob5fbace1010b705e20d02eeb8fe2ee778206504df
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 */
9 #ifndef LO_CLANG_SHARED_PLUGINS
11 #include "plugin.hxx"
13 namespace {
15 class DllPrivate final:
16 public loplugin::FilteringPlugin<DllPrivate>
18 public:
19 explicit DllPrivate(loplugin::InstantiationData const & data): FilteringPlugin(data)
22 bool VisitNamedDecl(NamedDecl const * decl) {
23 if (!decl->getLocation().isInvalid()&&ignoreLocation(decl)) {
24 return true;
26 auto a = decl->getAttr<VisibilityAttr>();
27 if (a == nullptr || a->getVisibility() != VisibilityAttr::Hidden) {
28 return true;
30 if (compiler.getSourceManager().isMacroBodyExpansion(
31 decl->getLocation())
32 && (Lexer::getImmediateMacroName(
33 decl->getLocation(), compiler.getSourceManager(),
34 compiler.getLangOpts())
35 == "Q_OBJECT")) // from /usr/include/QtCore/qobjectdefs.h
37 return true;
39 auto p = dyn_cast<RecordDecl>(decl->getDeclContext());
40 if (p == nullptr) {
41 report(
42 DiagnosticsEngine::Warning,
43 "top-level declaration redundantly marked as DLLPRIVATE",
44 a->getLocation())
45 << decl->getSourceRange();
46 } else if (p->getVisibility() == HiddenVisibility) {
47 report(
48 DiagnosticsEngine::Warning,
49 ("declaration nested in DLLPRIVATE declaration redundantly"
50 " marked as DLLPRIVATE"),
51 a->getLocation())
52 << decl->getSourceRange();
53 report(
54 DiagnosticsEngine::Note, "parent declaration is here",
55 p->getLocation())
56 << p->getSourceRange();
58 return true;
61 bool preRun() override {
62 // DISABLE_DYNLOADING makes SAL_DLLPUBLIC_{EXPORT,IMPORT,TEMPLATE} expand
63 // to visibility("hidden") attributes, which would cause bogus warnings
64 // here (e.g., in UBSan builds that explicitly define DISABLE_DYNLOADING
65 // in jurt/source/pipe/staticsalhack.cxx); alternatively, change
66 // include/sal/types.h to make those SAL_DLLPUBLIC_* expand to nothing
67 // for DISABLE_DYNLOADING:
68 return !compiler.getPreprocessor().getIdentifierInfo("DISABLE_DYNLOADING")
69 ->hasMacroDefinition();
72 void run() override {
73 if (preRun()) {
74 TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
79 static loplugin::Plugin::Registration<DllPrivate> dllprivate("dllprivate");
81 } // namespace
83 #endif // LO_CLANG_SHARED_PLUGINS
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */