diff --git a/.gitignore b/.gitignore index d59b1b7a..def3363c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ CMakeFiles/ CMakeCache.txt CMakeLists.txt.user -ClangLazy.cbp +ClazyPlugin.cbp cmake_install.cmake lib/ compile.output diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f711981..84839466 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ # The man page is not available on Windows. # -project(ClangLazy) +project(clazy) cmake_minimum_required(VERSION 3.3) include(FeatureSummary) @@ -134,13 +134,13 @@ endmacro() set(SYMBOL_FILE Lazy.exports) if (NOT CLAZY_BUILD_WITH_CLANG) - add_clang_plugin(ClangLazy ${CLAZY_PLUGIN_SRCS}) - set_target_properties(ClangLazy PROPERTIES + add_clang_plugin(ClazyPlugin ${CLAZY_PLUGIN_SRCS}) + set_target_properties(ClazyPlugin PROPERTIES LINKER_LANGUAGE CXX PREFIX "" ) - install(TARGETS ClangLazy + install(TARGETS ClazyPlugin RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} @@ -190,10 +190,10 @@ if (NOT CLAZY_BUILD_WITH_CLANG) add_executable(clazy-standalone ${CLAZY_STANDALONE_SRCS}) if(MSVC) - # On MSVC clang-standalone crashes with a meaningless backtrace if linked to ClangLazy.dll + # On MSVC clang-standalone crashes with a meaningless backtrace if linked to ClazyPlugin.dll target_link_libraries(clazy-standalone clangFrontend) else() - target_link_libraries(clazy-standalone ClangLazy) + target_link_libraries(clazy-standalone ClazyPlugin) endif() link_to_llvm(clazy-standalone TRUE) diff --git a/Changelog b/Changelog index 6a9e64d1..b48b1f45 100644 --- a/Changelog +++ b/Changelog @@ -28,7 +28,7 @@ - clazy-standalone executable. Allows to run clazy against a JSON compilation database instead of as a plugin. clang-tidy doesn't support loading external modules (https://bugs.llvm.org/show_bug.cgi?id=32739) so this is a good workaround. - - qt-compat mode. Allows to disable Qt5 specific checks by passing -Xclang -plugin-arg-clang-lazy -Xclang qt4-compat + - qt-compat mode. Allows to disable Qt5 specific checks by passing -Xclang -plugin-arg-clazy -Xclang qt4-compat - New checks: install-event-filter qcolor-from-literal @@ -94,4 +94,5 @@ * v1.5 (, 2019) - New Checks: ifndef-define-typo - - Removed support for the obscure -DCLAZY_BUILD_UTILS_LIB to simplify the CMakeLists.txt. + - Removed support for the obscure -DCLAZY_BUILD_UTILS_LIB to simplify the CMakeLists.txt + - Renamed the clazy plugin from ClangLazy.so to ClazyPlugin.so diff --git a/README.md b/README.md index afd98b70..8785dcb3 100644 --- a/README.md +++ b/README.md @@ -181,7 +181,7 @@ You should now have the clazy command available to you, in `/bin/`. Compile your programs with it instead of clang++/g++. Note that this command is just a convenience wrapper which calls: -`clang++ -Xclang -load -Xclang ClangLazy.so -Xclang -add-plugin -Xclang clang-lazy` +`clang++ -Xclang -load -Xclang ClazyPlugin.so -Xclang -add-plugin -Xclang clazy` If you have multiple versions of clang installed (say clang++-3.8 and clang++-3.9) you can choose which one to use by setting the CLANGXX environment variable, like so: @@ -195,7 +195,7 @@ To make it the compiler for qmake projects, just run qmake like: `qmake -spec linux-clang QMAKE_CXX="clazy"` Alternatively, if you want to use clang directly, without the wrapper: -`qmake -spec linux-clang QMAKE_CXXFLAGS="-Xclang -load -Xclang ClangLazy.so -Xclang -add-plugin -Xclang clang-lazy"` +`qmake -spec linux-clang QMAKE_CXXFLAGS="-Xclang -load -Xclang ClazyPlugin.so -Xclang -add-plugin -Xclang clazy"` You can also edit mkspecs/common/clang.conf and change QMAKE_CXX to clazy instead of clang++ and run qmake -spec linux-clang @@ -317,7 +317,7 @@ export CLAZY_CHECKS="level0,no-qenums" # Enables all checks from level0, except export CLAZY_CHECKS="level0,detaching-temporary" # Enables all from level0 and also detaching-temporary ``` ## Example via compiler argument -`clazy -Xclang -plugin-arg-clang-lazy -Xclang level0,detaching-temporary` +`clazy -Xclang -plugin-arg-clazy -Xclang level0,detaching-temporary` Don't forget to re-run cmake/qmake/etc if you altered the c++ flags to specify flags. # clazy-standalone and JSON database support @@ -370,7 +370,7 @@ For better results don't use parallel builds, otherwise a fixit being applied in # Troubleshooting -- clang: symbol lookup error: `/usr/lib/x86_64-linux-gnu/ClangLazy.so: undefined symbol: _ZNK5clang15DeclarationName11getAsStringEv`. +- clang: symbol lookup error: `/usr/lib/x86_64-linux-gnu/ClazyPlugin.so: undefined symbol: _ZNK5clang15DeclarationName11getAsStringEv`. This is due to mixing ABIs. Your clang/llvm was compiled with the [new gcc c++ ABI][1] but you compiled the clazy plugin with clang (which uses [the old ABI][2]). The solution is to build the clazy plugin with gcc or use a distro which hasn't migrated to gcc5 ABI yet, such as archlinux. @@ -402,7 +402,7 @@ For better results don't use parallel builds, otherwise a fixit being applied in # Qt4 compatibility mode When running on codebases that must still compile with Qt4, you can pass `--qt4compat` -(a convenience option equivalent to passing `-Xclang -plugin-arg-clang-lazy -Xclang qt4-compat`) +(a convenience option equivalent to passing `-Xclang -plugin-arg-clazy -Xclang qt4-compat`) to disable checks that only make sense with Qt5. For example, to build a CMake project with Qt4 compatibility use: diff --git a/clazy-cl.bat b/clazy-cl.bat index 64e49f79..4d5497c9 100644 --- a/clazy-cl.bat +++ b/clazy-cl.bat @@ -1,2 +1,2 @@ @echo off -clang.exe --driver-mode=cl -Qunused-arguments -Xclang -load -Xclang ClangLazy.dll -Xclang -add-plugin -Xclang clang-lazy -Wno-microsoft-enum-value %* +clang.exe --driver-mode=cl -Qunused-arguments -Xclang -load -Xclang ClazyPlugin.dll -Xclang -add-plugin -Xclang clazy -Wno-microsoft-enum-value %* diff --git a/clazy.bat b/clazy.bat index 6aa80d15..1565b5b7 100644 --- a/clazy.bat +++ b/clazy.bat @@ -1,2 +1,2 @@ @echo off -clang.exe -Qunused-arguments -Xclang -load -Xclang ClangLazy.dll -Xclang -add-plugin -Xclang clang-lazy %* +clang.exe -Qunused-arguments -Xclang -load -Xclang ClazyPlugin.dll -Xclang -add-plugin -Xclang clazy %* diff --git a/clazy.cmake b/clazy.cmake index 325d3596..c86a8897 100644 --- a/clazy.cmake +++ b/clazy.cmake @@ -20,9 +20,9 @@ HELP() { echo echo "Convenience Options:" echo " --qt4compat Qt4 compatibility mode. useful for source code that can build with Qt4" - echo " (this is the same as passing \"-Xclang -plugin-arg-clang-lazy -Xclang qt4-compat\")" + echo " (this is the same as passing \"-Xclang -plugin-arg-clazy -Xclang qt4-compat\")" echo " --qtdeveloper Special option for building Qt5 itself resulting in fewer false positives" - echo " (this is the same as passing \"-Xclang -plugin-arg-clang-lazy -Xclang qt-developer\")" + echo " (this is the same as passing \"-Xclang -plugin-arg-clazy -Xclang qt-developer\")" echo echo "All other options are passed directly to clang++ and handled from there." echo @@ -87,31 +87,31 @@ ExtraClangOptions="" if ( test $# -gt 0 -a "$1" = "--qt4compat" ) then shift - ExtraClangOptions="-Xclang -plugin-arg-clang-lazy -Xclang qt4-compat" + ExtraClangOptions="-Xclang -plugin-arg-clazy -Xclang qt4-compat" fi if ( test $# -gt 0 -a "$1" = "--qtdeveloper" ) then shift - ExtraClangOptions="-Xclang -plugin-arg-clang-lazy -Xclang qt-developer" + ExtraClangOptions="-Xclang -plugin-arg-clazy -Xclang qt-developer" fi if ( test $# -gt 0 -a "$1" = "--visit-implicit-code" ) then shift - ExtraClangOptions="-Xclang -plugin-arg-clang-lazy -Xclang visit-implicit-code" + ExtraClangOptions="-Xclang -plugin-arg-clazy -Xclang visit-implicit-code" fi -ClangLazyLib=ClangLazy@CMAKE_SHARED_LIBRARY_SUFFIX@ +ClazyPluginLib=ClazyPlugin@CMAKE_SHARED_LIBRARY_SUFFIX@ -if ( test -f "$libdir/$ClangLazyLib" ) +if ( test -f "$libdir/$ClazyPluginLib" ) then # find plugin libraries in install dir export LD_LIBRARY_PATH=$libdir:$LD_LIBRARY_PATH export DYLD_LIBRARY_PATH=$libdir:$DYLD_LIBRARY_PATH -elif ( test -f "$(dirname $0)/lib/$ClangLazyLib" ) +elif ( test -f "$(dirname $0)/lib/$ClazyPluginLib" ) then # find plugin libraries in build dir export LD_LIBRARY_PATH=$(dirname $0)/lib:$LD_LIBRARY_PATH export DYLD_LIBRARY_PATH=$(dirname $0)/lib:$DYLD_LIBRARY_PATH fi -${CLANGXX:-clang++} -Qunused-arguments -Xclang -load -Xclang $ClangLazyLib -Xclang -add-plugin -Xclang clang-lazy $ExtraClangOptions "$@" +${CLANGXX:-clang++} -Qunused-arguments -Xclang -load -Xclang $ClazyPluginLib -Xclang -add-plugin -Xclang clazy $ExtraClangOptions "$@" diff --git a/dev-scripts/make_windows_package.py b/dev-scripts/make_windows_package.py index b060f158..d685db95 100644 --- a/dev-scripts/make_windows_package.py +++ b/dev-scripts/make_windows_package.py @@ -75,7 +75,7 @@ def copy_files(work_dir): copy("../README.md", PACKAGE_DIR + 'clazy/README-CLAZY.md') copy(LLVM_INSTALL_DIR + '/bin/clang.exe', PACKAGE_DIR + 'clazy/bin/clang/') copy(LLVM_INSTALL_DIR + '/bin/clang.exe', PACKAGE_DIR + 'clazy/bin/clang/clang-cl.exe') - copy(LLVM_INSTALL_DIR + '/bin/ClangLazy.dll', PACKAGE_DIR + 'clazy/bin/clang/') + copy(LLVM_INSTALL_DIR + '/bin/ClazyPlugin.dll', PACKAGE_DIR + 'clazy/bin/clang/') copy(LLVM_INSTALL_DIR + '/bin/clazy-standalone.exe', PACKAGE_DIR + 'clazy/bin/clang/') run_command("cp -r %s/lib/clang/ %s" % (LLVM_INSTALL_DIR, PACKAGE_DIR + 'clazy/bin/lib/')) diff --git a/docs/man/clazy.pod b/docs/man/clazy.pod index d693f25e..aff33233 100644 --- a/docs/man/clazy.pod +++ b/docs/man/clazy.pod @@ -54,7 +54,7 @@ Use this when your source code can build with Qt4 and Qt5 in order to easily suppress issues that cannot be fixed due to the requirement of the Qt4 API. This is a convenience option which is identical to directly passing: - "-Xclang -plugin-arg-clang-lazy -Xclang qt4-compat" + "-Xclang -plugin-arg-clazy -Xclang qt4-compat" =back @@ -66,7 +66,7 @@ B This option is special for running clazy on Qt itsel Will result in fewer false positives being reported in Qt code. This is a convenience option which is identical to directly passing: - "-Xclang -plugin-arg-clang-lazy -Xclang qt-developer" + "-Xclang -plugin-arg-clazy -Xclang qt-developer" =back diff --git a/src/Clazy.cpp b/src/Clazy.cpp index 0751a18f..642e4f96 100644 --- a/src/Clazy.cpp +++ b/src/Clazy.cpp @@ -355,7 +355,7 @@ void ClazyASTAction::PrintHelp(llvm::raw_ostream &ros) const ros << " export CLAZY_CHECKS=\"level0,reserve-candidates,qstring-allocations\"\n"; ros << " export CLAZY_CHECKS=\"reserve-candidates\"\n\n"; ros << "or pass as compiler arguments, for example:\n"; - ros << " -Xclang -plugin-arg-clang-lazy -Xclang reserve-candidates,qstring-allocations\n"; + ros << " -Xclang -plugin-arg-clazy -Xclang reserve-candidates,qstring-allocations\n"; ros << "\n"; ros << "To enable FixIts for a check, also set the env variable CLAZY_FIXIT, for example:\n"; ros << " export CLAZY_FIXIT=\"fix-qlatin1string-allocations\"\n\n"; @@ -398,4 +398,4 @@ unique_ptr ClazyStandaloneASTAction::CreateASTConsumer(CompilerInst volatile int ClazyPluginAnchorSource = 0; static FrontendPluginRegistry::Add -X("clang-lazy", "clang lazy plugin"); +X("clazy", "clang lazy plugin"); diff --git a/tests/clazy/test_requested_checks.sh b/tests/clazy/test_requested_checks.sh index ddb8cad8..365da2ea 100755 --- a/tests/clazy/test_requested_checks.sh +++ b/tests/clazy/test_requested_checks.sh @@ -1,6 +1,6 @@ unset CLAZY_CHECKS unset CLAZY_FIXIT -CLAZY_COMMAND="clazy -c -o /dev/null -xc++ -Xclang -plugin-arg-clang-lazy -Xclang print-requested-checks " +CLAZY_COMMAND="clazy -c -o /dev/null -xc++ -Xclang -plugin-arg-clazy -Xclang print-requested-checks " CLAZY_COMMAND_STDIN=$CLAZY_COMMAND"-" # Test without checks: @@ -46,28 +46,28 @@ unset CLAZY_FIXIT unset CLAZY_CHECKS # Test specifying check in command line -echo | $($CLAZY_COMMAND -Xclang -plugin-arg-clang-lazy -Xclang implicit-casts -) +echo | $($CLAZY_COMMAND -Xclang -plugin-arg-clazy -Xclang implicit-casts -) # Pass two checks in command line -echo | $($CLAZY_COMMAND -Xclang -plugin-arg-clang-lazy -Xclang implicit-casts,foreach -) +echo | $($CLAZY_COMMAND -Xclang -plugin-arg-clazy -Xclang implicit-casts,foreach -) # Pass fixits through the command-line -echo | $($CLAZY_COMMAND -Xclang -plugin-arg-clang-lazy -Xclang fix-old-style-connect -) +echo | $($CLAZY_COMMAND -Xclang -plugin-arg-clazy -Xclang fix-old-style-connect -) # Pass level0 -echo | $($CLAZY_COMMAND -Xclang -plugin-arg-clang-lazy -Xclang level0 -) +echo | $($CLAZY_COMMAND -Xclang -plugin-arg-clazy -Xclang level0 -) # Pass level1 -echo | $($CLAZY_COMMAND -Xclang -plugin-arg-clang-lazy -Xclang level1 -) +echo | $($CLAZY_COMMAND -Xclang -plugin-arg-clazy -Xclang level1 -) # Pass level0 + another check -echo | $($CLAZY_COMMAND -Xclang -plugin-arg-clang-lazy -Xclang reserve-candidates -Xclang -plugin-arg-clang-lazy -Xclang level0 -) +echo | $($CLAZY_COMMAND -Xclang -plugin-arg-clazy -Xclang reserve-candidates -Xclang -plugin-arg-clazy -Xclang level0 -) # Pass level0 + another check that's already in level0 -echo | $($CLAZY_COMMAND -Xclang -plugin-arg-clang-lazy -Xclang qdatetime-utc -Xclang -plugin-arg-clang-lazy -Xclang level0 -) +echo | $($CLAZY_COMMAND -Xclang -plugin-arg-clazy -Xclang qdatetime-utc -Xclang -plugin-arg-clazy -Xclang level0 -) # Use a level argument in the checks list -echo | $($CLAZY_COMMAND -Xclang -plugin-arg-clang-lazy -Xclang implicit-casts,foreach,level0 -) +echo | $($CLAZY_COMMAND -Xclang -plugin-arg-clazy -Xclang implicit-casts,foreach,level0 -) # Use a level in env-variable export CLAZY_CHECKS="level1" @@ -84,16 +84,16 @@ echo | $CLAZY_COMMAND_STDIN # Use both env variable and compiler argument export CLAZY_CHECKS="level0,reserve-candidates" -echo | $($CLAZY_COMMAND -Xclang -plugin-arg-clang-lazy -Xclang implicit-casts,level0 -) +echo | $($CLAZY_COMMAND -Xclang -plugin-arg-clazy -Xclang implicit-casts,level0 -) unset CLAZY_FIXIT unset CLAZY_CHECKS # Test disabling checks works -echo | $($CLAZY_COMMAND -Xclang -plugin-arg-clang-lazy -Xclang implicit-casts,foreach,no-foreach -) -echo | $($CLAZY_COMMAND -Xclang -plugin-arg-clang-lazy -Xclang implicit-casts,no-foreach -) -echo | $($CLAZY_COMMAND -Xclang -plugin-arg-clang-lazy -Xclang implicit-casts,no-implicit-casts -) -echo | $($CLAZY_COMMAND -Xclang -plugin-arg-clang-lazy -Xclang level0,no-qenums,no-qgetenv -) +echo | $($CLAZY_COMMAND -Xclang -plugin-arg-clazy -Xclang implicit-casts,foreach,no-foreach -) +echo | $($CLAZY_COMMAND -Xclang -plugin-arg-clazy -Xclang implicit-casts,no-foreach -) +echo | $($CLAZY_COMMAND -Xclang -plugin-arg-clazy -Xclang implicit-casts,no-implicit-casts -) +echo | $($CLAZY_COMMAND -Xclang -plugin-arg-clazy -Xclang level0,no-qenums,no-qgetenv -) # Test disabling checks works, now with env variables export CLAZY_CHECKS="implicit-casts,foreach,no-foreach" diff --git a/tests/clazy/test_requested_checks.sh.expected b/tests/clazy/test_requested_checks.sh.expected index f2a071cc..7075a5b8 100644 --- a/tests/clazy/test_requested_checks.sh.expected +++ b/tests/clazy/test_requested_checks.sh.expected @@ -111,7 +111,7 @@ To specify which checks to enable set the CLAZY_CHECKS env variable, for example export CLAZY_CHECKS="reserve-candidates" or pass as compiler arguments, for example: - -Xclang -plugin-arg-clang-lazy -Xclang reserve-candidates,qstring-allocations + -Xclang -plugin-arg-clazy -Xclang reserve-candidates,qstring-allocations To enable FixIts for a check, also set the env variable CLAZY_FIXIT, for example: export CLAZY_FIXIT="fix-qlatin1string-allocations" diff --git a/tests/run_tests.py b/tests/run_tests.py index 19dbc2a9..9873eae0 100755 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -198,11 +198,11 @@ def find_qt_installation(major_version, qmakes): def libraryName(): if _platform == 'win32': - return 'ClangLazy.dll' + return 'ClazyPlugin.dll' elif _platform == 'darwin': - return 'ClangLazy.dylib' + return 'ClazyPlugin.dylib' else: - return 'ClangLazy.so' + return 'ClazyPlugin.so' def link_flags(): flags = "-lQt5Core -lQt5Gui -lQt5Widgets" @@ -214,7 +214,7 @@ def clazy_cpp_args(): return "-Wno-unused-value -Qunused-arguments -std=c++14 " def more_clazy_args(): - return " -Xclang -plugin-arg-clang-lazy -Xclang no-inplace-fixits " + clazy_cpp_args() + return " -Xclang -plugin-arg-clazy -Xclang no-inplace-fixits " + clazy_cpp_args() def clazy_standalone_command(test, qt): result = " -- " + clazy_cpp_args() + qt.compiler_flags() + " " + test.flags @@ -248,23 +248,23 @@ def clazy_command(qt, test, filename): result = os.environ['CLAZY_CXX'] + more_clazy_args() + qt.compiler_flags() else: clang = os.getenv('CLANGXX', 'clang') - result = clang + " -Xclang -load -Xclang " + libraryName() + " -Xclang -add-plugin -Xclang clang-lazy " + more_clazy_args() + qt.compiler_flags() + result = clang + " -Xclang -load -Xclang " + libraryName() + " -Xclang -add-plugin -Xclang clazy " + more_clazy_args() + qt.compiler_flags() if test.qt4compat: - result = result + " -Xclang -plugin-arg-clang-lazy -Xclang qt4-compat " + result = result + " -Xclang -plugin-arg-clazy -Xclang qt4-compat " if test.only_qt: - result = result + " -Xclang -plugin-arg-clang-lazy -Xclang only-qt " + result = result + " -Xclang -plugin-arg-clazy -Xclang only-qt " if test.qt_developer: - result = result + " -Xclang -plugin-arg-clang-lazy -Xclang qt-developer " + result = result + " -Xclang -plugin-arg-clazy -Xclang qt-developer " if test.link and _platform.startswith('linux'): # Linking on one platform is enough. Won't waste time on macOS and Windows. result = result + " " + link_flags() else: result = result + " -c " - result = result + test.flags + " -Xclang -plugin-arg-clang-lazy -Xclang " + string.join(test.checks, ',') + " " + result = result + test.flags + " -Xclang -plugin-arg-clazy -Xclang " + string.join(test.checks, ',') + " " if not test.isFixedFile: # When compiling the already fixed file disable fixit, we don't want to fix twice result += _enable_fixits_argument + " " result += filename @@ -311,7 +311,7 @@ def compiler_name(): #------------------------------------------------------------------------------- # Global variables -_enable_fixits_argument = "-Xclang -plugin-arg-clang-lazy -Xclang enable-all-fixits" +_enable_fixits_argument = "-Xclang -plugin-arg-clazy -Xclang enable-all-fixits" _dump_ast = args.dump_ast _verbose = args.verbose _no_standalone = args.no_standalone diff --git a/windows-package/clazy-cl.bat b/windows-package/clazy-cl.bat index 84e02f9c..5e5f61e4 100644 --- a/windows-package/clazy-cl.bat +++ b/windows-package/clazy-cl.bat @@ -1,2 +1,2 @@ @echo off -"%~dp0\clang\clang.exe" --driver-mode=cl -Qunused-arguments -Xclang -load -Xclang ClangLazy.dll -Xclang -add-plugin -Xclang clang-lazy -Wno-microsoft-enum-value %* +"%~dp0\clang\clang.exe" --driver-mode=cl -Qunused-arguments -Xclang -load -Xclang ClazyPlugin.dll -Xclang -add-plugin -Xclang clazy -Wno-microsoft-enum-value %* diff --git a/windows-package/clazy.bat b/windows-package/clazy.bat index 272c9d9d..2031f4bd 100644 --- a/windows-package/clazy.bat +++ b/windows-package/clazy.bat @@ -1,2 +1,2 @@ @echo off -"%~dp0\clang\clang.exe" -Qunused-arguments -Xclang -load -Xclang ClangLazy.dll -Xclang -add-plugin -Xclang clang-lazy %* +"%~dp0\clang\clang.exe" -Qunused-arguments -Xclang -load -Xclang ClazyPlugin.dll -Xclang -add-plugin -Xclang clazy %*