compilerplugins/Makefile-clang.mk | 2 compilerplugins/clang/store/changefunctioncalls.cxx | 89 ++++++++++++++++++++ config_host.mk.in | 1 config_host/config_global.h.in | 3 configure.ac | 30 ++++++ include/sal/types.h | 4 solenv/gbuild/platform/solaris.mk | 2 solenv/gbuild/platform/unxgcc.mk | 2 8 files changed, 128 insertions(+), 5 deletions(-)
New commits: commit e584d4abbb4087a552c0848680275d90c691be01 Author: LuboÅ¡ LuÅák <[email protected]> Date: Wed Jul 3 12:10:44 2013 +0200 clang binary is in clang build directory, not with its sources Change-Id: If037eac010d3cb72ca185382232c211758d009e6 diff --git a/compilerplugins/Makefile-clang.mk b/compilerplugins/Makefile-clang.mk index 29ca356..82a4351 100644 --- a/compilerplugins/Makefile-clang.mk +++ b/compilerplugins/Makefile-clang.mk @@ -88,7 +88,7 @@ $(CLANGOUTDIR)/plugin.so: $(CLANGOBJS) $(QUIET)$(CXX) -shared $(CLANGOBJS) -o $@ # Clang most probably doesn't maintain binary compatibility, so rebuild when clang changes. -$(CLANGOUTDIR)/clang-timestamp: $(CLANGDIR)/bin/clang +$(CLANGOUTDIR)/clang-timestamp: $(CLANGBUILD)/bin/clang $(QUIET)touch $@ # vim: set noet sw=4 ts=4: commit c352f340c26fad1550bfe76adc49ed14742ec9ce Author: LuboÅ¡ LuÅák <[email protected]> Date: Tue Jul 2 14:00:01 2013 +0200 note about getDirectCallee() vs getCallee() Change-Id: I0a4cfd0ddb0c03b0db95d003004195df29a3f6df diff --git a/compilerplugins/clang/store/changefunctioncalls.cxx b/compilerplugins/clang/store/changefunctioncalls.cxx index 2d0ae91..8d79d62 100644 --- a/compilerplugins/clang/store/changefunctioncalls.cxx +++ b/compilerplugins/clang/store/changefunctioncalls.cxx @@ -21,6 +21,7 @@ complex expression, operator precedence may mean the result is actually differen This can be easily adjusted for different modifications to a function: - replace CallExpr with CXXOperatorCallExpr or CXXMemberCallExpr - check different names or arguments +- change getDirectCallee() to getCallee() - etc. */ @@ -53,6 +54,10 @@ bool ChangeFunctionCalls::VisitCallExpr( const CallExpr* call ) { if( ignoreLocation( call )) return true; + // Using getDirectCallee() here means that we find only calls + // that call the function directly (i.e. not using a pointer, for example). + // Use getCallee() to include also those : + // if( const FunctionDecl* func = dyn_cast_or_null< FunctionDecl >( call->getCalleeDecl())) if( const FunctionDecl* func = call->getDirectCallee()) { // Optimize, getQualifiedNameAsString() is reportedly expensive, commit 015d9327354bdd6a7495285eb35105c08e536a45 Author: LuboÅ¡ LuÅák <[email protected]> Date: Tue Jul 2 13:32:51 2013 +0200 'generic' compiler plugin to modify calls to a specific function Change-Id: I60756d9054dfa5c55aeae8ddc904ddf6d67d2088 diff --git a/compilerplugins/clang/store/changefunctioncalls.cxx b/compilerplugins/clang/store/changefunctioncalls.cxx new file mode 100644 index 0000000..2d0ae91 --- /dev/null +++ b/compilerplugins/clang/store/changefunctioncalls.cxx @@ -0,0 +1,84 @@ +/* + * This file is part of the LibreOffice project. + * + * Based on LLVM/Clang. + * + * This file is distributed under the University of Illinois Open Source + * License. See LICENSE.TXT for details. + * + */ + +/* +This is a rewriter. + +Changes all calls to a specific function (after it's been renamed or its +arguments have changed). + +This specific example checks for calls to function 'void bar(unsigned int)' +and adds '+ 10' to the argument (as plain text, so if the argument is a more +complex expression, operator precedence may mean the result is actually different). + +This can be easily adjusted for different modifications to a function: +- replace CallExpr with CXXOperatorCallExpr or CXXMemberCallExpr +- check different names or arguments +- etc. +*/ + +#include "plugin.hxx" + +namespace loplugin +{ + +class ChangeFunctionCalls + : public RecursiveASTVisitor< ChangeFunctionCalls > + , public RewritePlugin + { + public: + explicit ChangeFunctionCalls( CompilerInstance& compiler, Rewriter& rewriter ); + virtual void run() override; + bool VisitCallExpr( const CallExpr* call ); + }; + +ChangeFunctionCalls::ChangeFunctionCalls( CompilerInstance& compiler, Rewriter& rewriter ) + : RewritePlugin( compiler, rewriter ) + { + } + +void ChangeFunctionCalls::run() + { + TraverseDecl( compiler.getASTContext().getTranslationUnitDecl()); + } + +bool ChangeFunctionCalls::VisitCallExpr( const CallExpr* call ) + { + if( ignoreLocation( call )) + return true; + if( const FunctionDecl* func = call->getDirectCallee()) + { + // Optimize, getQualifiedNameAsString() is reportedly expensive, + // so first check fast details like number of arguments or the (unqualified) + // name before checking the fully qualified name. + // See FunctionDecl for all the API about the function. + if( func->getNumParams() == 1 && func->getIdentifier() != NULL + && ( func->getName() == "bar" )) + { + string qualifiedName = func->getQualifiedNameAsString(); + if( qualifiedName == "bar" ) + { + // Further checks about arguments. Check mainly ParmVarDecl, VarDecl, + // ValueDecl and QualType for Clang API details. + string arg0 = func->getParamDecl( 0 )->getType().getAsString(); + if( arg0 == "unsigned int" ) + { + insertTextAfterToken( call->getArg( 0 )->getLocEnd(), " + 10" ); + report( DiagnosticsEngine::Warning, "found", call->getLocStart()); + } + } + } + } + return true; + } + +static Plugin::Registration< ChangeFunctionCalls > X( "changefunctioncalls" ); + +} // namespace commit 1e0feb5cf916fada5dc2db66a358649624ece578 Author: LuboÅ¡ LuÅák <[email protected]> Date: Fri Aug 2 14:18:22 2013 +0200 do not base feature checks on gcc version Clang reports itself to be gcc4.2, so there fail there, instead use configure checks. Change-Id: Idb44a5c875b24a15546a6495de02a1b4af898443 diff --git a/config_host.mk.in b/config_host.mk.in index 88f3e34..e726480 100644 --- a/config_host.mk.in +++ b/config_host.mk.in @@ -225,6 +225,7 @@ export HAVE_GCC_FNO_ENFORCE_EH_SPECS=@HAVE_GCC_FNO_ENFORCE_EH_SPECS@ export HAVE_GCC_FNO_INLINE=@HAVE_GCC_FNO_INLINE@ export HAVE_GCC_GGDB2=@HAVE_GCC_GGDB2@ export HAVE_GCC_NO_LONG_DOUBLE=@HAVE_GCC_NO_LONG_DOUBLE@ +export HAVE_GCC_PRAGMA_OPERATOR=@HAVE_GCC_PRAGMA_OPERATOR@ export HAVE_GCC_VISIBILITY_BROKEN=@HAVE_GCC_VISIBILITY_BROKEN@ export HAVE_GCC_VISIBILITY_FEATURE=@HAVE_GCC_VISIBILITY_FEATURE@ export HAVE_GETOPT=@HAVE_GETOPT@ diff --git a/config_host/config_global.h.in b/config_host/config_global.h.in index 31f64e6..88b7a1f 100644 --- a/config_host/config_global.h.in +++ b/config_host/config_global.h.in @@ -21,6 +21,9 @@ Any change in this header will cause a rebuild of almost everything. #define HAVE_GCC_BUILTIN_ATOMIC 0 #define HAVE_GCC_PRAGMA_DIAGNOSTIC_MODIFY 0 #define HAVE_GCC_PRAGMA_DIAGNOSTIC_SCOPE 0 +/* _Pragma */ +#define HAVE_GCC_PRAGMA_OPERATOR 0 +#define HAVE_GCC_DEPRECATED_MESSAGE 0 #define HAVE_THREADSAFE_STATICS 0 #define HAVE_SYSLOG_H 0 /* Compiler supports __attribute__((warn_unused)). */ diff --git a/configure.ac b/configure.ac index c623f38..9ed63e2 100644 --- a/configure.ac +++ b/configure.ac @@ -5718,6 +5718,17 @@ if test "$GCC" = "yes"; then ], [AC_MSG_RESULT([no])]) CFLAGS=$save_CFLAGS + AC_MSG_CHECKING([whether $CC supports __attribute__((deprecated(message)))]) + save_CFLAGS=$CFLAGS + CFLAGS="$CFLAGS -Werror" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([ + __attribute__((deprecated(test))) void f(); + ])], [ + AC_DEFINE([HAVE_GCC_DEPRECATED_MESSAGE],[1]) + AC_MSG_RESULT([yes]) + ], [AC_MSG_RESULT([no])]) + CFLAGS=$save_CFLAGS + AC_MSG_CHECKING([whether $CXX declares __cxa_allocate_exception in cxxabi.h]) AC_LANG_PUSH([C++]) AC_COMPILE_IFELSE([AC_LANG_SOURCE([ @@ -6086,6 +6097,25 @@ if test "$HAVE_CXX11" = "TRUE"; then fi fi +HAVE_GCC_PRAGMA_OPERATOR= +dnl _Pragma support (may require C++11) +if test "$GCC" = "yes"; then + AC_MSG_CHECKING([whether $CXX supports _Pragma operator]) + AC_LANG_PUSH([C++]) + save_CXXFLAGS=$CXXFLAGS + CXXFLAGS="$CXXFLAGS $CXXFLAGS_CXX11 -Werror" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([ + _Pragma("GCC diagnostic ignored \"-Wformat\"") + ])], [ + AC_DEFINE([HAVE_GCC_PRAGMA_OPERATOR],[1]) + HAVE_GCC_PRAGMA_OPERATOR=1 + AC_MSG_RESULT([yes]) + ], [AC_MSG_RESULT([no])]) + AC_LANG_POP([C++]) + CXXFLAGS=$save_CXXFLAGS +fi +AC_SUBST(HAVE_GCC_PRAGMA_OPERATOR) + dnl =================================================================== dnl system stl sanity tests dnl =================================================================== diff --git a/include/sal/types.h b/include/sal/types.h index 9ce2cef..145d47e 100644 --- a/include/sal/types.h +++ b/include/sal/types.h @@ -469,7 +469,7 @@ template< typename T1, typename T2 > inline T1 static_int_cast(T2 n) { SAL_DEPRECATED("Dont use, its evil.") void doit(int nPara); */ -#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)) +#if HAVE_GCC_DEPRECATED_MESSAGE # define SAL_DEPRECATED(message) __attribute__((deprecated(message))) #elif (__GNUC__) # define SAL_DEPRECATED(message) __attribute__((deprecated)) @@ -501,7 +501,7 @@ template< typename T1, typename T2 > inline T1 static_int_cast(T2 n) { SAL_WNODEPRECATED_DECLARATIONS_POP */ -#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || defined(__clang__) +#if HAVE_GCC_PRAGMA_DIAGNOSTIC_MODIFY && HAVE_GCC_PRAGMA_DIAGNOSTIC_SCOPE && HAVE_GCC_PRAGMA_OPERATOR #define SAL_WNODEPRECATED_DECLARATIONS_PUSH \ _Pragma(SAL_STRINGIFY_ARG(GCC diagnostic push)) \ _Pragma(SAL_STRINGIFY_ARG(GCC diagnostic ignored "-Wdeprecated-declarations")) diff --git a/solenv/gbuild/platform/solaris.mk b/solenv/gbuild/platform/solaris.mk index 240204c..58c9b68 100644 --- a/solenv/gbuild/platform/solaris.mk +++ b/solenv/gbuild/platform/solaris.mk @@ -98,7 +98,7 @@ gb_CXXFLAGS += -std=c++0x #When we are using 4.6.0 we can use gcc pragmas to selectively silence auto_ptr #warnings in isolation, but for <= 4.5.X we need to globally disable #deprecation -ifeq ($(gb_GccLess460),1) +ifeq ($(HAVE_GCC_PRAGMA_OPERATOR),) gb_CXXFLAGS += -Wno-deprecated-declarations endif endif diff --git a/solenv/gbuild/platform/unxgcc.mk b/solenv/gbuild/platform/unxgcc.mk index 5b3805f..17b9eb2 100644 --- a/solenv/gbuild/platform/unxgcc.mk +++ b/solenv/gbuild/platform/unxgcc.mk @@ -94,7 +94,7 @@ gb_CXXFLAGS += $(CXXFLAGS_CXX11) #When we are using 4.6.0 we can use gcc pragmas to selectively silence auto_ptr #warnings in isolation, but for <= 4.5.X we need to globally disable #deprecation -ifeq ($(gb_GccLess460),1) +ifeq ($(HAVE_GCC_PRAGMA_OPERATOR),) gb_CXXFLAGS += -Wno-deprecated-declarations endif endif
_______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
