[Libreoffice-commits] core.git: compilerplugins/clang compilerplugins/Makefile-clang.mk config_host.mk.in configure.ac distro-configs/Jenkins

2020-03-09 Thread Stephan Bergmann (via logerrit)
 compilerplugins/Makefile-clang.mk|7 ++-
 compilerplugins/clang/sharedvisitor/analyzer.cxx |2 +-
 config_host.mk.in|1 +
 configure.ac |   10 ++
 distro-configs/Jenkins/linux_clang_dbgutil_64|1 +
 5 files changed, 15 insertions(+), 6 deletions(-)

New commits:
commit 5ab0f79748cad1069cc0d0c9cd4b57ccb1e14408
Author: Stephan Bergmann 
AuthorDate: Mon Mar 9 11:25:29 2020 +0100
Commit: Stephan Bergmann 
CommitDate: Mon Mar 9 13:48:35 2020 +0100

Add --disable-compiler-plugins-analyzer-pch for 
Jenkins/linux_clang_dbgutil_64

 had been 
a
case I noticed of a "Gerrit Linux clang/dbgutil" build failing due to stale 
PCH
information:

[...]
> [build GEN] compilerplugins/clang/sharedvisitor/makeshared.plugininfo
> fatal error: file '/usr/include/asm-generic/errno.h' has been modified 
since the precompiled header 
'/home/tdf/lode/jenkins/workspace/lo_gerrit/Config/linux_clang_dbgutil_64/compilerplugins/clang/sharedvisitor/clang.pch'
 was built
> note: please rebuild precompiled header 
'/home/tdf/lode/jenkins/workspace/lo_gerrit/Config/linux_clang_dbgutil_64/compilerplugins/clang/sharedvisitor/clang.pch'
[...]

and this issue had apparently caused all those Gerrit Jenkins builds to 
fail for
at least a day.  For unmaintained builds like those, I think it is better to
have a more robust setup, where stale PCH information cannot break the 
build.
Also, as those builds do not make compilerplugins.clean and rather share it
across builds, there should not be much of a performance impact when 
disabling
PCH in the analyzer.

(It turns out that compilerplugins/clang/sharedvisitor/analyzer.cxx would 
always
have enabled PCH, as compilerplugins/Makefile-clang.mk always passes in some
definition of LO_CLANG_USE_ANALYZER_PCH.  Fixed that now.)

Change-Id: I7b8b24c1049c501634bd59c5fb482bec72427cf6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90211
Reviewed-by: Luboš Luňák 
Reviewed-by: Stephan Bergmann 
Tested-by: Jenkins

diff --git a/compilerplugins/Makefile-clang.mk 
b/compilerplugins/Makefile-clang.mk
index 65cfa67cb1ec..9d6b46019344 100644
--- a/compilerplugins/Makefile-clang.mk
+++ b/compilerplugins/Makefile-clang.mk
@@ -47,9 +47,6 @@ endif
 # by gb_ENABLE_PCH like everywhere else, but unsetting this disables PCH.
 LO_CLANG_USE_PCH=1
 
-# Whether to use precompiled headers for the analyzer too. Does not apply to 
compiling sources.
-LO_CLANG_USE_ANALYZER_PCH=1
-
 # The uninteresting rest.
 
 include $(SRCDIR)/solenv/gbuild/gbuild.mk
@@ -275,7 +272,7 @@ $(CLANGOUTDIR)/sharedvisitor/analyzer$(CLANG_EXE_EXT): 
$(CLANGINDIR)/sharedvisit
$(call gb_Output_announce,$(subst $(BUILDDIR)/,,$@),$(true),GEN,1)
$(QUIET)$(COMPILER_PLUGINS_CXX) $(CLANGDEFS) $(CLANGCXXFLAGS) 
$(CLANGWERROR) $(CLANGINCLUDES) \
 -I$(BUILDDIR)/config_host -DCLANGFLAGS='"$(CLANGTOOLDEFS)"' \
--DLO_CLANG_USE_ANALYZER_PCH=$(LO_CLANG_USE_ANALYZER_PCH) \
+-DLO_CLANG_USE_ANALYZER_PCH=$(if $(COMPILER_PLUGINS_ANALYZER_PCH),1,0) 
\
 -c $< -o $(CLANGOUTDIR)/sharedvisitor/analyzer.o -MMD -MT $@ -MP \
 -MF $(CLANGOUTDIR)/sharedvisitor/analyzer.d
$(QUIET)$(COMPILER_PLUGINS_CXX) $(CLANGDEFS) $(CLANGCXXFLAGS) 
$(CLANGOUTDIR)/sharedvisitor/analyzer.o \
@@ -342,7 +339,7 @@ endif
 
 endif
 
-ifdef LO_CLANG_USE_ANALYZER_PCH
+ifeq ($(COMPILER_PLUGINS_ANALYZER_PCH),TRUE)
 # the PCH for usage in sharedvisitor/analyzer
 
 # these are from the invocation in analyzer.cxx
diff --git a/compilerplugins/clang/sharedvisitor/analyzer.cxx 
b/compilerplugins/clang/sharedvisitor/analyzer.cxx
index 7c69e4a9381c..ea519abb0d95 100644
--- a/compilerplugins/clang/sharedvisitor/analyzer.cxx
+++ b/compilerplugins/clang/sharedvisitor/analyzer.cxx
@@ -273,7 +273,7 @@ int main(int argc, char** argv)
 args.end(),
 {   // These must match LO_CLANG_ANALYZER_PCH_CXXFLAGS in 
Makefile-clang.mk .
 "-I" BUILDDIR "/config_host" // plugin sources use e.g. 
config_global.h
-#ifdef LO_CLANG_USE_ANALYZER_PCH
+#if LO_CLANG_USE_ANALYZER_PCH
 ,
 "-include-pch", // use PCH with Clang headers to speed up 
parsing/analysing
 BUILDDIR "/compilerplugins/clang/sharedvisitor/clang.pch"
diff --git a/config_host.mk.in b/config_host.mk.in
index 215212a6f06a..13e5e906a3f6 100644
--- a/config_host.mk.in
+++ b/config_host.mk.in
@@ -78,6 +78,7 @@ export COMMONS_LOGGING_JAR=@COMMONS_LOGGING_JAR@
 export COMMONS_LOGGING_VERSION=@COMMONS_LOGGING_VERSION@
 export COMPATH=@COMPATH@
 export COMPILER_PLUGINS=@COMPILER_PLUGINS@
+export COMPILER_PLUGINS_ANALYZER_PCH=@COMPILER_PLUGINS_ANALYZER_PCH@
 export COMPILER_PLUGINS_COM_IS_CLANG=@COMPILER_PLUGINS_COM_IS_CLANG@
 export COMPILER_PLUGINS_CXX=@COMPILER_PLU

[Libreoffice-commits] core.git: compilerplugins/clang compilerplugins/Makefile-clang.mk config_host.mk.in configure.ac

2019-03-22 Thread Stephan Bergmann (via logerrit)
 compilerplugins/Makefile-clang.mk |4 ++-
 compilerplugins/clang/sharedvisitor/generator.cxx |   26 --
 config_host.mk.in |1 
 configure.ac  |1 
 4 files changed, 25 insertions(+), 7 deletions(-)

New commits:
commit ad7e2af4ed0c11f8571374fbb40d38b38c27959c
Author: Stephan Bergmann 
AuthorDate: Thu Mar 21 19:33:34 2019 +0100
Commit: Stephan Bergmann 
CommitDate: Fri Mar 22 11:38:51 2019 +0100

Allow to pass additional options into generator's clang::tooling

In my macOS build, that clang::tooling::runToolOnCodeWithArgs invocation 
failed
to find headers like cassert and assert.h, which works now with

  COMPILER_PLUGINS_TOOLING_ARGS=-isysroot 
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
 -isystem /Users/stephan/Software/llvm/inst/include/c++/v1

added to my autogen.input (I build against my Clang trunk libc++ whose 
headers
are at /Users/stephan/Software/llvm/inst/include/c++/v1).

Change-Id: Idbffa39c9fd4a88743fd498b8f7b6c9c56d7630d
Reviewed-on: https://gerrit.libreoffice.org/69538
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/compilerplugins/Makefile-clang.mk 
b/compilerplugins/Makefile-clang.mk
index 0d73bebb8daf..f342ec01b5f9 100644
--- a/compilerplugins/Makefile-clang.mk
+++ b/compilerplugins/Makefile-clang.mk
@@ -175,7 +175,9 @@ ifdef LO_CLANG_SHARED_PLUGINS
 $(CLANGINDIR)/sharedvisitor/sharedvisitor.cxx: $(shell grep -l 
"LO_CLANG_SHARED_PLUGINS" $(CLANGINDIR)/*.cxx)
 $(CLANGINDIR)/sharedvisitor/sharedvisitor.cxx: 
$(CLANGOUTDIR)/sharedvisitor/generator$(CLANG_EXE_EXT)
$(call gb_Output_announce,$(subst $(SRCDIR)/,,$@),$(true),GEN,1)
-   $(CLANGOUTDIR)/sharedvisitor/generator$(CLANG_EXE_EXT) $(shell grep -l 
"LO_CLANG_SHARED_PLUGINS" $(CLANGINDIR)/*.cxx) \
+   $(CLANGOUTDIR)/sharedvisitor/generator$(CLANG_EXE_EXT) \
+$(COMPILER_PLUGINS_TOOLING_ARGS:%=-arg=%) \
+$(shell grep -l "LO_CLANG_SHARED_PLUGINS" $(CLANGINDIR)/*.cxx) \
 > $(CLANGINDIR)/sharedvisitor/sharedvisitor.cxx
 
 CLANGTOOLLIBS = -lclangTooling -lclangDriver -lclangFrontend -lclangParse 
-lclangSema -lclangEdit -lclangAnalysis \
diff --git a/compilerplugins/clang/sharedvisitor/generator.cxx 
b/compilerplugins/clang/sharedvisitor/generator.cxx
index bd957a903ee6..b12939516d16 100644
--- a/compilerplugins/clang/sharedvisitor/generator.cxx
+++ b/compilerplugins/clang/sharedvisitor/generator.cxx
@@ -56,6 +56,8 @@ TODO:
 #include "clang/Frontend/FrontendAction.h"
 #include "clang/Tooling/Tooling.h"
 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -534,14 +536,21 @@ string readSourceFile( const char* filename )
 
 int main(int argc, char** argv)
 {
-for( int i = 1; i < argc; ++ i )
+vector< string > args;
+int i = 1;
+for( ; i < argc; ++ i )
 {
-string contents = readSourceFile(argv[i]);
-if( contents.empty())
-continue;
+constexpr std::size_t prefixlen = 5; // strlen("-arg=");
+if (std::strncmp(argv[i], "-arg=", prefixlen) != 0)
+{
+break;
+}
+args.push_back(argv[i] + prefixlen);
+}
 #define STRINGIFY2(a) #a
 #define STRINGIFY(a) STRINGIFY2(a)
-vector< string > args =
+args.insert(
+args.end(),
 {
 "-I" STRINGIFY(BUILDDIR) "/config_host", // plugin sources use 
e.g. config_global.h
 "-I" STRINGIFY(CLANGDIR) "/include", // clang's headers
@@ -550,7 +559,12 @@ int main(int argc, char** argv)
 "-D__STDC_CONSTANT_MACROS", // Clang headers require these.
 "-D__STDC_FORMAT_MACROS",
 "-D__STDC_LIMIT_MACROS",
-};
+});
+for( ; i < argc; ++ i )
+{
+string contents = readSourceFile(argv[i]);
+if( contents.empty())
+continue;
 foundSomething = false;
 if( !clang::tooling::runToolOnCodeWithArgs( new FindNamedClassAction, 
contents, args, argv[ i ] ))
 {
diff --git a/config_host.mk.in b/config_host.mk.in
index 5b4a54a8e3ed..ef174b790939 100644
--- a/config_host.mk.in
+++ b/config_host.mk.in
@@ -75,6 +75,7 @@ export COMPILER_PLUGINS=@COMPILER_PLUGINS@
 export COMPILER_PLUGINS_CXX=@COMPILER_PLUGINS_CXX@
 export COMPILER_PLUGINS_CXX_LINKFLAGS=@COMPILER_PLUGINS_CXX_LINKFLAGS@
 export COMPILER_PLUGINS_DEBUG=@COMPILER_PLUGINS_DEBUG@
+export COMPILER_PLUGINS_TOOLING_ARGS=@COMPILER_PLUGINS_TOOLING_ARGS@
 export COM_IS_CLANG=@COM_IS_CLANG@
 export CPPUNIT_CFLAGS=$(gb_SPACE)@CPPUNIT_CFLAGS@
 export CPPUNIT_LIBS=$(gb_SPACE)@CPPUNIT_LIBS@
diff --git a/configure.ac b/configure.ac
index 40dac2f7fa0f..8a3f1e2cdfeb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -6917,6 +6917,7 @@ AC_SUBST(COMPILER_PLUGINS)
 AC_SUBST(COMPILER_PLUGINS_CXX)
 AC_SUBST(COMPILER_PLUGINS_CXX_LINKFLAGS)
 AC_SUBST(COMPILER_PLUGINS_DEBU

[Libreoffice-commits] core.git: compilerplugins/clang compilerplugins/Makefile-clang.mk config_host.mk.in configure.ac solenv/gbuild

2017-09-30 Thread Stephan Bergmann
 compilerplugins/Makefile-clang.mk |   70 +++---
 compilerplugins/clang/pluginhandler.cxx   |2 
 compilerplugins/clang/unusedfieldsremove.cxx  |4 +
 compilerplugins/clang/unusedmethodsremove.cxx |4 +
 config_host.mk.in |2 
 configure.ac  |2 
 solenv/gbuild/platform/com_MSC_class.mk   |8 +-
 solenv/gbuild/platform/com_MSC_defs.mk|   24 
 8 files changed, 104 insertions(+), 12 deletions(-)

New commits:
commit 39e7a72b3e328e6b3d87479d693b01315610457b
Author: Stephan Bergmann 
Date:   Fri Sep 29 08:37:45 2017 +0200

Support loplugin in clang-cl

This works at least with a recent Clang trunk (towards Clang 6.0).

In order for the plugin.dll to find the LLVM/Clang symbols, it needs to be
loaded into clang.exe not clang-cl.exe, so set CC/CXX to 'clang.exe
--driver-mode=cl ...'.

Buidling the plugin requires some linker flags that must go at the very end 
of
the COMPILER_PLUGINS_CXX command line, after a /link switch, so introduce
another COMPILER_PLUGINS_CXX_LINKFLAGS variable for that.  Also, clang.lib 
is
not installed as part of LLVM's 'cmake --build ... --target install' step, 
so
is not available under CLANGDIR and needs to be taken from the build tree
instead, so introduce another CLANGLIBDIR variable for that.  autogen.input
settings that work for me on Windows 8.1 with Microsoft Visual Studio 14.0 
are:

> CLANGDIR=C:/llvm/inst
> CLANGLIBDIR=C:/llvm/build/lib
> COMPILER_PLUGINS_CXX=C:/PROGRA~2/MICROS~3.0/VC/bin/amd64/cl.exe 
/IC:\PROGRA~2\MICROS~3.0\VC\INCLUDE /IC:\PROGRA~2\MICROS~3.0\VC\ATLMFC\INCLUDE 
/IC:\PROGRA~2\WI3CF2~1\10\include\100102~1.0\ucrt 
/IC:\PROGRA~2\WI3CF2~1\NETFXSDK\46D346~1.1\include\um 
/IC:\PROGRA~2\WI3CF2~1\8.1\include\shared /IC:\PROGRA~2\WI3CF2~1\8.1\include\um 
/IC:\PROGRA~2\WI3CF2~1\8.1\include\winrt
> 
COMPILER_PLUGINS_CXX_LINKFLAGS=/LIBPATH:C:/PROGRA~2/MICROS~3.0/VC/LIB/amd64 
/LIBPATH:C:/PROGRA~2/MICROS~3.0/VC/ATLMFC/LIB/amd64 
/LIBPATH:C:/PROGRA~2/WI3CF2~1/10/lib/100102~1.0/ucrt/x64 
/LIBPATH:C:/PROGRA~2/WI3CF2~1/NETFXSDK/46D346~1.1/lib/um/x64 
/LIBPATH:C:/PROGRA~2/WI3CF2~1/8.1/lib/winv6.3/um/x64

(The last two are "C:/Program Files (x86)/Microsoft Visual Studio 
14.0/VC/bin/
amd64/cl.exe" and translations of %INCLUDE% and %LIB% as set in the "VS2015 
x64
Native Tools Command Prompt" shell.
AC_CHECK_HEADER(clang/AST/RecursiveASTVisitor.h, ...) in configure.ac 
wouldn't
like CXX to start with INCLUDE=... LIB=... environment variable settings, 
so it
wouldn't work to instead pass %INCLUDE% and %LIB% to cl.exe that way.  See
 for general
information about building with clang-cl on Windows.)

There's still some room for improvement marked "TODO".  (And some of the 
unused*
plugins, which are not run by default anyway, use Unix-style functionality, 
so
have been disabled for now.)

Change-Id: I6c28bdeb801af39ce2bae03111f455e2338d66c9
Reviewed-on: https://gerrit.libreoffice.org/42931
Tested-by: Jenkins 
Reviewed-by: Stephan Bergmann 

diff --git a/compilerplugins/Makefile-clang.mk 
b/compilerplugins/Makefile-clang.mk
index 4839fdef2feb..89a798ebd34a 100644
--- a/compilerplugins/Makefile-clang.mk
+++ b/compilerplugins/Makefile-clang.mk
@@ -10,6 +10,14 @@
 
 CLANG_COMMA :=,
 
+ifeq ($(OS),WNT)
+CLANG_DL_EXT = .dll
+CLANG_EXE_EXT = .exe
+else
+CLANG_DL_EXT = .so
+CLANG_EXE_EXT =
+endif
+
 ifeq ($(COMPILER_PLUGINS_CXX),)
 CLANGCXX=$(filter-out -m32 -m64 -fsanitize%,$(CXX))
 else
@@ -18,15 +26,32 @@ endif
 
 # Compile flags ('make CLANGCXXFLAGS=-g' if you need to debug the plugin); you
 # may occasionally want to override these:
+ifeq ($(OS),WNT)
+# See LLVM's cmake/modules/AddLLVM.cmake and LLVM build's
+# tools/llvm-config/BuildVariables.inc:
+# * Ignore "warning C4141: 'inline': used more than once" as emitted upon
+#   "LLVM_ATTRIBUTE_ALWAYS_INLINE inline" in various LLVM include files.
+# * Ignore "warning C4577: 'noexcept' used with no exception handling mode
+#   specified; termination on exception is not guaranteed. Specify /EHsc".
+CLANGCXXFLAGS=/nologo /D_HAS_EXCEPTIONS=0 /wd4141 /wd4577 /O2 /Oi /EHs-c- /GR-
+else
 CLANGCXXFLAGS=-O2 -Wall -Wextra -Wundef -g
+endif
 
 # The uninteresting rest.
 
 # Clang headers require these.
-CLANGDEFS=-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS 
-D__STDC_LIMIT_MACROS -fno-rtti
+CLANGDEFS=-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
+ifneq ($(OS),WNT)
+CLANGDEFS += -fno-rtti
+endif
 # All include locations needed (using -isystem silences various warnings when
 # including those files):
+ifeq ($(OS),WNT)
+CLANGINCLUDES=-I$(CLANGDIR)/include
+else
 CLANGINCLUDES=$(if $(filter /usr,$(CLANGDIR)),,-isystem $(CLANGDIR)/include)
+endif
 
 # Clang/LLVM libraries are intentiona