summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2022-01-19 08:14:12 +0100
committerStephan Bergmann <sbergman@redhat.com>2022-01-19 23:00:55 +0100
commitd923625d89fdaa3881d5ad1fef75a8b728b74879 (patch)
tree5d73f5f86ef37cecd9830f7e21b40c7149eed919 /compilerplugins
parent2cfa04cbf03fe5c2ce32a7384082cdc5de5a4785 (diff)
Let CppunitTest_odk_checkapi build against the SDK include directory
...which contains only the URE include files, rather than against the SRCDIR one which contains many more. This would have prevented 148536afc9838398100ca2267b99ab349dcbb38c "Drop config_global.h from osl/module.h", where an URE include file had accidentally started to include a non-URE file. (The way $(INCLUDE) is now set up in odk/CppunitTest_odk_checkapi.mk is a bit hacky, and this change required teaching compilerplugins about SDKDIR to avoid false warnings. Another approach would be to make the test compile in the SDK build environment, similarly to CustomTarget_odk/build-examples, but setting up the SDK build environment from within gbuild is not supported at least on Windows for now. A smaller improvement would be to drop the need to include any CppUnit include directories, by turning the test into some kind of compile-only test similar to a gb_CompilerTest.) Change-Id: If79761909c67c3162d01f847dfb5d4f538f91ca1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128591 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/plugin.cxx13
-rw-r--r--compilerplugins/clang/plugin.hxx4
-rw-r--r--compilerplugins/clang/reservedid.cxx10
3 files changed, 20 insertions, 7 deletions
diff --git a/compilerplugins/clang/plugin.cxx b/compilerplugins/clang/plugin.cxx
index 57fdf83b79ff..edf91f33d19b 100644
--- a/compilerplugins/clang/plugin.cxx
+++ b/compilerplugins/clang/plugin.cxx
@@ -285,7 +285,8 @@ bool Plugin::isInUnoIncludeFile(SourceLocation spellingLocation) const
|| hasPathnamePrefix(name, SRCDIR "/include/sal/")
|| hasPathnamePrefix(name, SRCDIR "/include/salhelper/")
|| hasPathnamePrefix(name, SRCDIR "/include/typelib/")
- || hasPathnamePrefix(name, SRCDIR "/include/uno/"));
+ || hasPathnamePrefix(name, SRCDIR "/include/uno/")
+ || hasPathnamePrefix(name, SDKDIR "/include/"));
}
bool Plugin::isInUnoIncludeFile(const FunctionDecl* functionDecl) const
@@ -722,6 +723,16 @@ bool isSamePathname(StringRef pathname, StringRef other)
pathname, other, [](StringRef p, StringRef a) { return p == a; });
}
+bool isSameUnoIncludePathname(StringRef fullPathname, StringRef includePathname)
+{
+ llvm::SmallVector<char, 256> buf;
+ if (isSamePathname(fullPathname, (SRCDIR "/include/" + includePathname).toStringRef(buf))) {
+ return true;
+ }
+ buf.clear();
+ return isSamePathname(fullPathname, (SDKDIR "/include/" + includePathname).toStringRef(buf));
+}
+
bool hasCLanguageLinkageType(FunctionDecl const * decl) {
assert(decl != nullptr);
if (decl->isExternC()) {
diff --git a/compilerplugins/clang/plugin.hxx b/compilerplugins/clang/plugin.hxx
index 540352df9868..1694bdb0782a 100644
--- a/compilerplugins/clang/plugin.hxx
+++ b/compilerplugins/clang/plugin.hxx
@@ -282,6 +282,10 @@ bool hasPathnamePrefix(StringRef pathname, StringRef prefix);
// also contain backslashes:
bool isSamePathname(StringRef pathname, StringRef other);
+// Check whether fullPathname is either SRCDIR/include/includePathname or
+// SDKDIR/include/includePathname:
+bool isSameUnoIncludePathname(StringRef fullPathname, StringRef includePathname);
+
// It appears that, given a function declaration, there is no way to determine
// the language linkage of the function's type, only of the function's name
// (via FunctionDecl::isExternC); however, in a case like
diff --git a/compilerplugins/clang/reservedid.cxx b/compilerplugins/clang/reservedid.cxx
index 2c7e9c8659e4..2a52e5629b2c 100644
--- a/compilerplugins/clang/reservedid.cxx
+++ b/compilerplugins/clang/reservedid.cxx
@@ -113,14 +113,12 @@ void ReservedId::postRun() {
auto loc = d->getLocation();
if (loc.isValid() && !ignoreLocation(loc)) {
auto file = getFilenameOfLocation(loc);
- if (!loplugin::isSamePathname(
+ if (!loplugin::isSameUnoIncludePathname(
file,
- SRCDIR
- "/include/cppuhelper/implbase_ex_post.hxx")
- && !loplugin::isSamePathname(
+ "cppuhelper/implbase_ex_post.hxx")
+ && !loplugin::isSameUnoIncludePathname(
file,
- SRCDIR
- "/include/cppuhelper/implbase_ex_pre.hxx"))
+ "cppuhelper/implbase_ex_pre.hxx"))
{
report(
DiagnosticsEngine::Warning,