diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2018-09-24 15:41:53 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2018-09-24 17:22:05 +0200 |
commit | 928b1b04adc1cd49cc5d00069084e03675a320f3 (patch) | |
tree | 8710687a4a66a628bd12c5482d7d93cc27f8996a /compilerplugins | |
parent | ec709a8d5e808b970a8930a389c0a5a6f61fe8c7 (diff) |
loplugin:external (clang-cl)
Including:
* expanding STDAPI to its definition (as per
<https://msdn.microsoft.com/library/ms686631(vs.85).aspx> "STDAPI"), to add
__declspec(dllexport) into its middle, in
extensions/source/activex/so_activex.cxx; as discussed in the comments at
<https://gerrit.libreoffice.org/#/c/60691/> "Get rid of Windows .def files in
setup_native, use __declspec(dllexport)", having a function both listed in a
.def file EXPORTS and marking it dllexport is OK, and the latter helps the
heuristics of loplugin:external; however, the relevant functions in
extensions/source/activex/so_activex.cxx probably don't even need to be
exported in the first place?
* follow-up loplugin:salcall in sal/osl/w32/file-impl.hxx
Change-Id: Ida6e17eba19cfa3d7e5c72dda57409005c0a0191
Reviewed-on: https://gerrit.libreoffice.org/60938
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/external.cxx | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/compilerplugins/clang/external.cxx b/compilerplugins/clang/external.cxx index bb4bcbf36d08..d30b8cba3c5f 100644 --- a/compilerplugins/clang/external.cxx +++ b/compilerplugins/clang/external.cxx @@ -126,20 +126,29 @@ public: { return true; } - if (decl->isMain()) + if (decl->isMain() || decl->isMSVCRTEntryPoint()) { return true; } + if (hasCLanguageLinkageType(decl) + && loplugin::DeclCheck(decl).Function("_DllMainCRTStartup").GlobalNamespace()) + { + return true; + } + // If the function definition is explicit marked SAL_DLLPUBLIC_EXPORT or similar, then + // assume that it needs to be present (e.g., only called via dlopen, or a backwards- + // compatibility stub like in sal/osl/all/compat.cxx): if (auto const attr = decl->getAttr<VisibilityAttr>()) { if (attr->getVisibility() == VisibilityAttr::Default) { - // If the function definition has explicit default visibility, then assume that it - // needs to be present (e.g., only called via dlopen, or a backwards-compatibility - // stub like in sal/osl/all/compat.cxx): return true; } } + else if (decl->hasAttr<DLLExportAttr>()) + { + return true; + } auto const canon = decl->getCanonicalDecl(); if (hasCLanguageLinkageType(canon) && (canon->hasAttr<ConstructorAttr>() || canon->hasAttr<DestructorAttr>())) @@ -177,6 +186,10 @@ public: { return true; } + if (loplugin::DeclCheck(decl).Var("_pRawDllMain").GlobalNamespace()) + { + return true; + } return handleDeclaration(decl); } @@ -261,14 +274,27 @@ private: return true; } } - if (compiler.getSourceManager().isMacroBodyExpansion(decl->getLocation()) - && (Lexer::getImmediateMacroName(decl->getLocation(), compiler.getSourceManager(), + if (compiler.getSourceManager().isMacroBodyExpansion(decl->getLocation())) + { + if (Lexer::getImmediateMacroName(decl->getLocation(), compiler.getSourceManager(), compiler.getLangOpts()) - == "MDDS_MTV_DEFINE_ELEMENT_CALLBACKS")) + == "MDDS_MTV_DEFINE_ELEMENT_CALLBACKS") + { + // Even wrapping in an unnamed namespace or sneaking "static" into the macro + // wouldn't help, as then some of the functions it defines would be flagged as + // unused: + return true; + } + } + else if (compiler.getSourceManager().isMacroArgExpansion(decl->getLocation())) { - // Even wrapping in an unnamed namespace or sneaking "static" into the macro wouldn't - // help, as then some of the functions it defines would be flagged as unused: - return true; + if (Lexer::getImmediateMacroName(decl->getLocation(), compiler.getSourceManager(), + compiler.getLangOpts()) + == "DEFINE_GUID") + { + // Windows, guiddef.h: + return true; + } } TypedefNameDecl const* typedefed = nullptr; if (auto const d = dyn_cast<TagDecl>(decl)) |