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

2019-10-07 Thread Luboš Luňák (via logerrit)
 compilerplugins/Makefile-clang.mk |   49 ++-
 compilerplugins/clang/sharedvisitor/analyzer.cxx  |   17 ++---
 compilerplugins/clang/sharedvisitor/generator.cxx |2 
 config_host.mk.in |3 
 configure.ac  |   69 --
 5 files changed, 96 insertions(+), 44 deletions(-)

New commits:
commit 79ca031fb2e8802aa4383362f83306fad6895729
Author: Luboš Luňák 
AuthorDate: Sat Oct 5 16:27:48 2019 +0200
Commit: Luboš Luňák 
CommitDate: Mon Oct 7 21:57:32 2019 +0200

make the clang plugins configure check faster

Use a header which is not so expensive to parse/compile.

Change-Id: I4197fb16938b19c18fed541dbf94bf2c97a60e66
Reviewed-on: https://gerrit.libreoffice.org/80301
Tested-by: Jenkins
Reviewed-by: Luboš Luňák 

diff --git a/configure.ac b/configure.ac
index 156dca7b1ed0..7ba93a3f5247 100644
--- a/configure.ac
+++ b/configure.ac
@@ -7036,7 +7036,7 @@ if test "$COM_IS_CLANG" = "TRUE"; then
 CXXCPP="$COMPILER_PLUGINS_CXX -E"
 CPPFLAGS="$COMPILER_PLUGINS_CXXFLAGS"
 CXXFLAGS="$COMPILER_PLUGINS_CXXFLAGS"
-AC_CHECK_HEADER(clang/AST/RecursiveASTVisitor.h,
+AC_CHECK_HEADER(clang/Basic/SourceLocation.h,
 [COMPILER_PLUGINS=TRUE],
 [
 if test "$compiler_plugins" = "yes"; then
@@ -7053,15 +7053,15 @@ if test "$COM_IS_CLANG" = "TRUE"; then
 LIBS="-lclangTooling -lclangDriver -lclangFrontend 
-lclangParse -lclangSema -lclangEdit \
  -lclangAnalysis -lclangAST -lclangLex -lclangSerialization -lclangBasic 
$COMPILER_PLUGINS_CXX_LINKFLAGS"
 AC_LINK_IFELSE([
-AC_LANG_PROGRAM([[#include "clang/Tooling/Tooling.h"]],
-[[ clang::tooling::runToolOnCode( nullptr, "some code" 
); ]])
+AC_LANG_PROGRAM([[#include 
"clang/Basic/SourceLocation.h"]],
+[[ clang::FullSourceLoc().dump(); ]])
 ],[CLANGTOOLLIBS="$LIBS"],[])
 fi
 if test -z "$CLANGTOOLLIBS"; then
 LIBS="-lclang-cpp $COMPILER_PLUGINS_CXX_LINKFLAGS"
 AC_LINK_IFELSE([
-AC_LANG_PROGRAM([[#include "clang/Tooling/Tooling.h"]],
-[[ clang::tooling::runToolOnCode( nullptr, "some code" 
); ]])
+AC_LANG_PROGRAM([[#include 
"clang/Basic/SourceLocation.h"]],
+[[ clang::FullSourceLoc().dump(); ]])
 ],[CLANGTOOLLIBS="$LIBS"],[])
 fi
 AC_MSG_RESULT([$CLANGTOOLLIBS])
commit ad5cbcf6ba0afdc1d8d7405c2641cce8de4a360b
Author: Luboš Luňák 
AuthorDate: Sun Oct 6 15:01:07 2019 +0200
Commit: Luboš Luňák 
CommitDate: Mon Oct 7 21:57:13 2019 +0200

try to autodetect flags needed to build Clang plugins

Instead of having a lot of it hardcoded, which brings problems like:
- Clang-to-be-10 has switched to -std=c++14, so our hardcoded c++11
  makes the build fail
- I cannot compile with my openSUSE-shipped clang, because it ships
  only libclang-cpp and not the other libClangSomething libs
The possibility to explicitly set the necessary variables is still there.

Change-Id: I58d401d4584fa064f1c1351a8a06ff4e29643063
Reviewed-on: https://gerrit.libreoffice.org/80300
Tested-by: Jenkins
Reviewed-by: Luboš Luňák 

diff --git a/compilerplugins/Makefile-clang.mk 
b/compilerplugins/Makefile-clang.mk
index 14356d1548fd..a132df918b50 100644
--- a/compilerplugins/Makefile-clang.mk
+++ b/compilerplugins/Makefile-clang.mk
@@ -23,14 +23,14 @@ CLANGCXXFLAGS=/nologo /D_HAS_EXCEPTIONS=0 /wd4141 /wd4577 
/EHs-c- /GR-
 ifeq ($(CLANGDEBUG),)
 CLANGCXXFLAGS+=/O2 /Oi
 else
-CLANGCXXFLAGS+=/DEBUG
+CLANGCXXFLAGS+=/DEBUG /Od
 endif
 else # WNT
 CLANGCXXFLAGS=-Wall -Wextra -Wundef
 ifeq ($(CLANGDEBUG),)
 CLANGCXXFLAGS+=-O2
 else
-CLANGCXXFLAGS+=-g
+CLANGCXXFLAGS+=-g -O0 -UNDEBUG
 endif
 endif
 
@@ -61,20 +61,13 @@ CLANG_EXE_EXT =
 endif
 
 # Clang headers require these.
-CLANGDEFS=-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
-ifneq ($(OS),WNT)
-CLANGDEFS += -fno-rtti
-endif
+CLANGDEFS:=$(COMPILER_PLUGINS_CXXFLAGS)
 # 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)
+ifneq ($(OS),WNT)
+CLANGDEFS:=$(filter-out -isystem/usr/include,$(foreach 
opt,$(CLANGDEFS),$(patsubst -I%,-isystem%,$(opt
 endif
 
-LLVMCONFIG=$(CLANGDIR)/bin/llvm-config
-
 # Clang/LLVM libraries are intentionally not linked in, they are usually built 
as static libraries, which means the resulting
 # plugin would be big (even though the clang binary already includes it all) 
and it'd be necessary to explicitly specify
 # also all the dependency 

[Libreoffice-commits] core.git: 2 commits - compilerplugins/clang compilerplugins/Makefile-clang.mk

2019-10-07 Thread Luboš Luňák (via logerrit)
 compilerplugins/Makefile-clang.mk |8 ++--
 compilerplugins/clang/constfieldsrewrite.cxx  |1 +
 compilerplugins/clang/dbgunhandledexception.cxx   |1 +
 compilerplugins/clang/dyncastvisibility.cxx   |4 ++--
 compilerplugins/clang/empty.cxx   |2 +-
 compilerplugins/clang/getimplementationname.cxx   |3 +--
 compilerplugins/clang/implicitboolconversion.cxx  |1 +
 compilerplugins/clang/nullptr.cxx |6 ++
 compilerplugins/clang/sharedvisitor/generator.cxx |1 +
 compilerplugins/clang/stringconstant.cxx  |3 +--
 compilerplugins/clang/unusedfieldsremove.cxx  |1 +
 compilerplugins/clang/unusedmethodsremove.cxx |1 +
 12 files changed, 19 insertions(+), 13 deletions(-)

New commits:
commit b1c14c30ba99ede85e41934b565195b0cbc69703
Author: Luboš Luňák 
AuthorDate: Sun Oct 6 14:22:59 2019 +0200
Commit: Luboš Luňák 
CommitDate: Mon Oct 7 21:56:55 2019 +0200

fix various warnings in compilerplugins

These are triggered when using llvm-config --cxxflags for building,
and sometimes there's -Werror. The warnings were mostly unused
variables because of being used only in assert(), or default case
in switch that covers all enums (it's better to not handle default
to get warning if a case is not handled).

Change-Id: I0ecdd1f27390aadf033852b0d1ee0ca424ae3c37
Reviewed-on: https://gerrit.libreoffice.org/80317
Tested-by: Jenkins
Reviewed-by: Luboš Luňák 

diff --git a/compilerplugins/clang/constfieldsrewrite.cxx 
b/compilerplugins/clang/constfieldsrewrite.cxx
index 209d97423a23..03fb3d0c3609 100644
--- a/compilerplugins/clang/constfieldsrewrite.cxx
+++ b/compilerplugins/clang/constfieldsrewrite.cxx
@@ -78,6 +78,7 @@ ConstFieldsRewrite::~ConstFieldsRewrite()
 //Cleanup
 int rc = munmap(mmappedData, mmapFilesize);
 assert(rc == 0);
+(void)rc;
 close(mmapFD);
 }
 
diff --git a/compilerplugins/clang/dbgunhandledexception.cxx 
b/compilerplugins/clang/dbgunhandledexception.cxx
index 81d6126fb3af..d1406c18a9dd 100644
--- a/compilerplugins/clang/dbgunhandledexception.cxx
+++ b/compilerplugins/clang/dbgunhandledexception.cxx
@@ -59,6 +59,7 @@ bool 
DbgUnhandledException::PreTraverseCXXCatchStmt(CXXCatchStmt* catchStmt)
 bool DbgUnhandledException::PostTraverseCXXCatchStmt(CXXCatchStmt* catchStmt, 
bool)
 {
 assert(currCatchStmt.top() == catchStmt);
+(void)catchStmt;
 currCatchStmt.pop();
 return true;
 }
diff --git a/compilerplugins/clang/dyncastvisibility.cxx 
b/compilerplugins/clang/dyncastvisibility.cxx
index 0f6021101e2b..3aa66e0dc21b 100644
--- a/compilerplugins/clang/dyncastvisibility.cxx
+++ b/compilerplugins/clang/dyncastvisibility.cxx
@@ -59,6 +59,7 @@ bool isDerivedFrom(
 if (bases->insert(bd).second) {
 auto const d = isDerivedFrom(bd, base, bases, hidden);
 assert(d);
+(void)d;
 *hidden |= getTypeVisibility(bd) != DefaultVisibility;
 }
 derived = true;
@@ -75,9 +76,8 @@ StringRef vis(Visibility v) {
 return "protected";
 case DefaultVisibility:
 return "default";
-default:
-llvm_unreachable("unknown visibility");
 }
+llvm_unreachable("unknown visibility");
 }
 
 class DynCastVisibility final:
diff --git a/compilerplugins/clang/empty.cxx b/compilerplugins/clang/empty.cxx
index 6ddbf2a84a2d..108745460d0c 100644
--- a/compilerplugins/clang/empty.cxx
+++ b/compilerplugins/clang/empty.cxx
@@ -35,7 +35,7 @@ BinaryOperatorKind reverse(BinaryOperatorKind op)
 case BO_NE:
 return op;
 default:
-assert(false);
+abort();
 }
 }
 
diff --git a/compilerplugins/clang/getimplementationname.cxx 
b/compilerplugins/clang/getimplementationname.cxx
index cf234079750e..acc45acb7442 100644
--- a/compilerplugins/clang/getimplementationname.cxx
+++ b/compilerplugins/clang/getimplementationname.cxx
@@ -209,8 +209,7 @@ bool GetImplementationName::isStringConstant(
 return false;//TODO
 }
 default:
-assert(false); //TODO???
-return "BAD11";
+abort(); //TODO???
 }
 }
 
diff --git a/compilerplugins/clang/implicitboolconversion.cxx 
b/compilerplugins/clang/implicitboolconversion.cxx
index a6ff1c53c26d..84addf67f858 100644
--- a/compilerplugins/clang/implicitboolconversion.cxx
+++ b/compilerplugins/clang/implicitboolconversion.cxx
@@ -174,6 +174,7 @@ bool isBoolExpr(Expr const * expr) {
 CXXOperatorCallExpr const * op
 = dyn_cast(stack.top());
 assert(op != nullptr);
+(void)op;
 TemplateDecl const * d
 = t->getTemplateName().getAsTemplateDecl();
 if (d == nullptr
diff --git a/compilerplugins/clang/nullptr.cxx 
b/compilerplugins/clang/nullptr.cxx
index 30458d7f7f5a..89535daa9849 

[Libreoffice-commits] core.git: 2 commits - compilerplugins/clang compilerplugins/Makefile-clang.mk

2019-10-06 Thread Luboš Luňák (via logerrit)
 compilerplugins/Makefile-clang.mk |2 +-
 compilerplugins/clang/flatten.cxx |   10 --
 2 files changed, 9 insertions(+), 3 deletions(-)

New commits:
commit 3e5d4ecbde512efe169536544489635f7f076fd2
Author: Luboš Luňák 
AuthorDate: Sun Oct 6 15:01:23 2019 +0200
Commit: Luboš Luňák 
CommitDate: Sun Oct 6 16:57:34 2019 +0200

the PCH in compilerplugins should also depend on the Makefile

Otherwise it may not get rebuilt in Jenkins when flags in the Makefile
change.

Change-Id: I9a06c5bbfd4af2714497c5658d8c523a6c929f68
Reviewed-on: https://gerrit.libreoffice.org/80318
Tested-by: Jenkins
Reviewed-by: Luboš Luňák 

diff --git a/compilerplugins/Makefile-clang.mk 
b/compilerplugins/Makefile-clang.mk
index 1a2ceef369df..6e18ee55487a 100644
--- a/compilerplugins/Makefile-clang.mk
+++ b/compilerplugins/Makefile-clang.mk
@@ -306,7 +306,7 @@ LO_CLANG_ANALYZER_PCH_CXXFLAGS := -I$(BUILDDIR)/config_host 
-I$(CLANGDIR)/includ
 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
 
 $(CLANGOUTDIR)/sharedvisitor/clang.pch: 
$(CLANGINDIR)/sharedvisitor/precompiled_clang.hxx \
-$(CLANGOUTDIR)/clang-timestamp \
+$(SRCDIR)/compilerplugins/Makefile-clang.mk 
$(CLANGOUTDIR)/clang-timestamp \
 | $(CLANGOUTDIR)/sharedvisitor
$(call gb_Output_announce,$(subst $(BUILDDIR)/,,$@),$(true),PCH,1)
$(QUIET)$(CLANGDIR)/bin/clang -x c++-header 
$(LO_CLANG_ANALYZER_PCH_CXXFLAGS) \
commit 1cccad3dd24e4a5cf5d7299326ae302e71980971
Author: Luboš Luňák 
AuthorDate: Sat Oct 5 13:27:55 2019 +0200
Commit: Luboš Luňák 
CommitDate: Sun Oct 6 16:57:23 2019 +0200

replace throw with abort

There is nothing catching the exception anyway, and this fails
to compile if compiling the plugin with Clang's CXXFLAGS (which
include -fno-exceptions).

Change-Id: Iad9316ad9613e4fd66d0e5a16fd71bbb8066cc2b
Reviewed-on: https://gerrit.libreoffice.org/80299
Reviewed-by: Noel Grandin 
Tested-by: Jenkins
Reviewed-by: Luboš Luňák 

diff --git a/compilerplugins/clang/flatten.cxx 
b/compilerplugins/clang/flatten.cxx
index e56d21603774..81f897cb0ee3 100644
--- a/compilerplugins/clang/flatten.cxx
+++ b/compilerplugins/clang/flatten.cxx
@@ -474,7 +474,10 @@ std::string stripOpenAndCloseBrace(std::string s)
 {
 size_t i = s.find("{");
 if (i == std::string::npos)
-throw "did not find {";
+{
+assert( !"did not find {" );
+abort();
+}
 
 ++i;
 // strip to line end
@@ -486,7 +489,10 @@ std::string stripOpenAndCloseBrace(std::string s)
 
 i = s.rfind("}");
 if (i == std::string::npos)
-throw "did not find }";
+{
+assert( !"did not find }" );
+abort();
+}
 --i;
 while (s[i] == ' ')
 --i;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] core.git: 2 commits - compilerplugins/clang compilerplugins/Makefile-clang.mk

2013-03-19 Thread Stephan Bergmann
 compilerplugins/Makefile-clang.mk|2 
 compilerplugins/clang/literalalternative.cxx |  111 +++
 2 files changed, 112 insertions(+), 1 deletion(-)

New commits:
commit 24387f1c58b30cae26618c377acd95a336c28380
Author: Stephan Bergmann sberg...@redhat.com
Date:   Tue Mar 19 10:48:22 2013 +0100

A plugin to find suboptimal equalsIgnoreAsciiCaseAscii[L] calls

Change-Id: Id2572982ca899223b89016ee7482ccb960032805

diff --git a/compilerplugins/clang/literalalternative.cxx 
b/compilerplugins/clang/literalalternative.cxx
new file mode 100644
index 000..e90b688
--- /dev/null
+++ b/compilerplugins/clang/literalalternative.cxx
@@ -0,0 +1,111 @@
+/* -*- 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 string
+
+#include plugin.hxx
+
+// Find those calls of rtl::OUString::equalsIgnoreAsciiCaseAscii and
+// rtl::OUString::equalsIgnoreAsciiCaseAsciiL that could be simplified to call
+// rtl::OUString::equalsIgnoreAsciiCase instead:
+
+namespace {
+
+class LiteralAlternative:
+public RecursiveASTVisitorLiteralAlternative, public loplugin::Plugin
+{
+public:
+explicit LiteralAlternative(ASTContext  context): Plugin(context) {}
+
+virtual void run() { TraverseDecl(context.getTranslationUnitDecl()); }
+
+bool VisitCallExpr(CallExpr * expr);
+};
+
+bool LiteralAlternative::VisitCallExpr(CallExpr * expr) {
+if (ignoreLocation(expr)) {
+return true;
+}
+FunctionDecl const * fdecl = expr-getDirectCallee();
+if (fdecl == nullptr) {
+return true;
+}
+std::string qname { fdecl-getQualifiedNameAsString() };
+if (qname == rtl::OUString::equalsIgnoreAsciiCaseAscii
+ fdecl-getNumParams() == 1  expr-getNumArgs() == 1)
+{
+// equalsIgnoreAsciiCaseAscii(foo) - equalsIngoreAsciiCase(foo):
+StringLiteral const * lit
+= dyn_castStringLiteral(expr-getArg(0)-IgnoreParenImpCasts());
+if (lit != nullptr) {
+report(
+DiagnosticsEngine::Warning,
+(rewrite call of rtl::OUString::equalsIgnoreAsciiCaseAscii
+  with string literal argument as call of
+  rtl::OUString::equalsIgnoreAsciiCase),
+expr-getExprLoc());
+//TODO: a better loc (the equalsIgnoreAsciiCaseAscii part)?
+}
+return true;
+}
+if (qname == rtl::OUString::equalsIgnoreAsciiCaseAsciiL
+ fdecl-getNumParams() == 2  expr-getNumArgs() == 2)
+{
+// equalsIgnoreAsciiCaseAsciiL(foo, 3) - 
equalsIngoreAsciiCase(foo)
+// especially also for
+// equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM(foo)), 
where
+// RTL_CONSTASCII_STRINGPARAM expands to complicated expressions
+// involving ((X)[0] sub-expressions (and it might or might not be
+// better to handle that at the level of non-expanded macros instead,
+// but I have not found out how to do that yet anyway):
+APSInt res;
+if (expr-getArg(1)-isIntegerConstantExpr(res, context)) {
+Expr const * arg0 = expr-getArg(0)-IgnoreParenImpCasts();
+StringLiteral const * lit = dyn_castStringLiteral(arg0);
+bool match = false;
+if (lit != nullptr) {
+match = res == lit-getLength();
+} else {
+UnaryOperator const * op = dyn_castUnaryOperator(arg0);
+if (op != nullptr  op-getOpcode() == UO_AddrOf) {
+ArraySubscriptExpr const * subs
+= dyn_castArraySubscriptExpr(
+op-getSubExpr()-IgnoreParenImpCasts());
+if (subs != nullptr) {
+lit = dyn_castStringLiteral(
+subs-getBase()-IgnoreParenImpCasts());
+match = lit != nullptr
+ subs-getIdx()-isIntegerConstantExpr(
+res, context)
+ res == 0;
+}
+}
+}
+if (match) {
+report(
+DiagnosticsEngine::Warning,
+(rewrite call of
+  rtl::OUString::equalsIgnoreAsciiCaseAsciiL with string
+  literal and matching length arguments as call of
+  rtl::OUString::equalsIgnoreAsciiCase),
+expr-getExprLoc());
+//TODO: a better loc (the equalsIgnoreAsciiCaseAsciiL
+// part)?
+}
+}
+return true;
+}
+return true;
+}
+