Open springmeyer opened 7 years ago
@springmeyer - is your analyser buggy ^ ?? I'm not getting warnings, maybe I'm missing something.
LLVM (http://llvm.org/):
LLVM version 5.0.0svn
Optimized build.
Default target: x86_64-apple-darwin16.7.0
Host CPU: ivybridge
./scripts/clang-tidy.sh
* Already installed at /Users/artem/Projects/mapbox/variant/mason_packages/osx-x86_64/clang-tidy/4.0.1
* Linking /Users/artem/Projects/mapbox/variant/mason_packages/osx-x86_64/clang-tidy/4.0.1
* Links will be inside /Users/artem/Projects/mapbox/variant/mason_packages/.link/
* Using bash fallback for symlinking (install lndir for faster symlinking)
* Done linking /Users/artem/Projects/mapbox/variant/mason_packages/osx-x86_64/clang-tidy/4.0.1
Enabled checks:
boost-use-to-string
cert-dcl03-c
cert-dcl50-cpp
cert-dcl54-cpp
cert-dcl59-cpp
cert-env33-c
cert-err09-cpp
cert-err34-c
cert-err52-cpp
cert-err58-cpp
cert-err60-cpp
cert-err61-cpp
cert-fio38-c
cert-flp30-c
cert-msc30-c
cert-msc50-cpp
cert-oop11-cpp
clang-analyzer-apiModeling.google.GTest
clang-analyzer-core.CallAndMessage
clang-analyzer-core.DivideZero
clang-analyzer-core.DynamicTypePropagation
clang-analyzer-core.NonNullParamChecker
clang-analyzer-core.NullDereference
clang-analyzer-core.StackAddressEscape
clang-analyzer-core.UndefinedBinaryOperatorResult
clang-analyzer-core.VLASize
clang-analyzer-core.builtin.BuiltinFunctions
clang-analyzer-core.builtin.NoReturnFunctions
clang-analyzer-core.uninitialized.ArraySubscript
clang-analyzer-core.uninitialized.Assign
clang-analyzer-core.uninitialized.Branch
clang-analyzer-core.uninitialized.CapturedBlockVariable
clang-analyzer-core.uninitialized.UndefReturn
clang-analyzer-cplusplus.NewDelete
clang-analyzer-cplusplus.NewDeleteLeaks
clang-analyzer-cplusplus.SelfAssignment
clang-analyzer-deadcode.DeadStores
clang-analyzer-llvm.Conventions
clang-analyzer-nullability.NullPassedToNonnull
clang-analyzer-nullability.NullReturnedFromNonnull
clang-analyzer-nullability.NullableDereferenced
clang-analyzer-nullability.NullablePassedToNonnull
clang-analyzer-nullability.NullableReturnedFromNonnull
clang-analyzer-optin.cplusplus.VirtualCall
clang-analyzer-optin.mpi.MPI-Checker
clang-analyzer-optin.osx.cocoa.localizability.EmptyLocalizationContextChecker
clang-analyzer-optin.osx.cocoa.localizability.NonLocalizedStringChecker
clang-analyzer-optin.performance.Padding
clang-analyzer-osx.API
clang-analyzer-osx.NumberObjectConversion
clang-analyzer-osx.ObjCProperty
clang-analyzer-osx.SecKeychainAPI
clang-analyzer-osx.cocoa.AtSync
clang-analyzer-osx.cocoa.ClassRelease
clang-analyzer-osx.cocoa.Dealloc
clang-analyzer-osx.cocoa.IncompatibleMethodTypes
clang-analyzer-osx.cocoa.Loops
clang-analyzer-osx.cocoa.MissingSuperCall
clang-analyzer-osx.cocoa.NSAutoreleasePool
clang-analyzer-osx.cocoa.NSError
clang-analyzer-osx.cocoa.NilArg
clang-analyzer-osx.cocoa.NonNilReturnValue
clang-analyzer-osx.cocoa.ObjCGenerics
clang-analyzer-osx.cocoa.RetainCount
clang-analyzer-osx.cocoa.SelfInit
clang-analyzer-osx.cocoa.SuperDealloc
clang-analyzer-osx.cocoa.UnusedIvars
clang-analyzer-osx.cocoa.VariadicMethodTypes
clang-analyzer-osx.coreFoundation.CFError
clang-analyzer-osx.coreFoundation.CFNumber
clang-analyzer-osx.coreFoundation.CFRetainRelease
clang-analyzer-osx.coreFoundation.containers.OutOfBounds
clang-analyzer-osx.coreFoundation.containers.PointerSizedValues
clang-analyzer-security.FloatLoopCounter
clang-analyzer-security.insecureAPI.UncheckedReturn
clang-analyzer-security.insecureAPI.getpw
clang-analyzer-security.insecureAPI.gets
clang-analyzer-security.insecureAPI.mkstemp
clang-analyzer-security.insecureAPI.mktemp
clang-analyzer-security.insecureAPI.rand
clang-analyzer-security.insecureAPI.strcpy
clang-analyzer-security.insecureAPI.vfork
clang-analyzer-unix.API
clang-analyzer-unix.Malloc
clang-analyzer-unix.MallocSizeof
clang-analyzer-unix.MismatchedDeallocator
clang-analyzer-unix.StdCLibraryFunctions
clang-analyzer-unix.Vfork
clang-analyzer-unix.cstring.BadSizeArg
clang-analyzer-unix.cstring.NullArg
cppcoreguidelines-c-copy-assignment-signature
cppcoreguidelines-interfaces-global-init
cppcoreguidelines-no-malloc
cppcoreguidelines-pro-bounds-array-to-pointer-decay
cppcoreguidelines-pro-bounds-constant-array-index
cppcoreguidelines-pro-bounds-pointer-arithmetic
cppcoreguidelines-pro-type-const-cast
cppcoreguidelines-pro-type-cstyle-cast
cppcoreguidelines-pro-type-member-init
cppcoreguidelines-pro-type-reinterpret-cast
cppcoreguidelines-pro-type-static-cast-downcast
cppcoreguidelines-pro-type-union-access
cppcoreguidelines-pro-type-vararg
cppcoreguidelines-slicing
cppcoreguidelines-special-member-functions
google-build-explicit-make-pair
google-build-namespaces
google-build-using-namespace
google-default-arguments
google-explicit-constructor
google-global-names-in-headers
google-readability-braces-around-statements
google-readability-casting
google-readability-function-size
google-readability-namespace-comments
google-readability-redundant-smartptr-get
google-readability-todo
google-runtime-int
google-runtime-member-string-references
google-runtime-memset
google-runtime-operator
google-runtime-references
llvm-header-guard
llvm-include-order
llvm-namespace-comment
llvm-twine-local
misc-argument-comment
misc-assert-side-effect
misc-bool-pointer-implicit-conversion
misc-dangling-handle
misc-definitions-in-headers
misc-fold-init-type
misc-forward-declaration-namespace
misc-inaccurate-erase
misc-incorrect-roundings
misc-inefficient-algorithm
misc-macro-parentheses
misc-macro-repeated-side-effects
misc-misplaced-const
misc-misplaced-widening-cast
misc-move-const-arg
misc-move-constructor-init
misc-move-forwarding-reference
misc-multiple-statement-macro
misc-new-delete-overloads
misc-noexcept-move-constructor
misc-non-copyable-objects
misc-redundant-expression
misc-sizeof-container
misc-sizeof-expression
misc-static-assert
misc-string-compare
misc-string-constructor
misc-string-integer-assignment
misc-string-literal-with-embedded-nul
misc-suspicious-enum-usage
misc-suspicious-missing-comma
misc-suspicious-semicolon
misc-suspicious-string-compare
misc-swapped-arguments
misc-throw-by-value-catch-by-reference
misc-unconventional-assign-operator
misc-undelegated-constructor
misc-uniqueptr-reset-release
misc-unused-alias-decls
misc-unused-parameters
misc-unused-raii
misc-unused-using-decls
misc-use-after-move
misc-virtual-near-miss
modernize-avoid-bind
modernize-deprecated-headers
modernize-loop-convert
modernize-make-shared
modernize-make-unique
modernize-pass-by-value
modernize-raw-string-literal
modernize-redundant-void-arg
modernize-replace-auto-ptr
modernize-shrink-to-fit
modernize-use-auto
modernize-use-bool-literals
modernize-use-default-member-init
modernize-use-emplace
modernize-use-equals-default
modernize-use-equals-delete
modernize-use-nullptr
modernize-use-override
modernize-use-transparent-functors
modernize-use-using
mpi-buffer-deref
mpi-type-mismatch
performance-faster-string-find
performance-for-range-copy
performance-implicit-cast-in-loop
performance-inefficient-string-concatenation
performance-type-promotion-in-math-fn
performance-unnecessary-copy-initialization
performance-unnecessary-value-param
readability-avoid-const-params-in-decls
readability-braces-around-statements
readability-container-size-empty
readability-delete-null-pointer
readability-deleted-default
readability-else-after-return
readability-function-size
readability-identifier-naming
readability-implicit-bool-cast
readability-inconsistent-declaration-parameter-name
readability-misplaced-array-index
readability-named-parameter
readability-non-const-parameter
readability-redundant-control-flow
readability-redundant-declaration
readability-redundant-function-ptr-dereference
readability-redundant-member-init
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-redundant-string-init
readability-simplify-boolean-expr
readability-static-definition-in-anonymous-namespace
readability-uniqueptr-delete-release
clang-tidy -header-filter=^/Users/artem/Projects/mapbox/variant/build/.* -export-fixes /var/folders/83/rt7rty5j1v3gj5kpymxsq_0w0000gn/T/tmpk73w1f/tmpw0Mi8S.yaml -p=/Users/artem/Projects/mapbox/variant/build /Users/artem/Projects/mapbox/variant/test/bench_variant.cpp
Applying fixes ...
@artemp your output indicates that only bench_variant.cpp
is being checked. Not sure why that is. Mine is checking more .cpp
files locally. Can you share the build/compile_commands.json
that is on your machine in a gist? Also, for reference, here is my output https://gist.github.com/springmeyer/86c27ec500c81286bd124128b06f6bd8
@artemp Thinking more. The problem is likely that my script to produce compile_commands.json
is brittle. It has some minimal regex to try to detect which lines (coming from make) are compile commands: https://github.com/mapbox/variant/blob/bdd45a6aaad0de81f471898dfe958241b618361a/scripts/generate_compile_commands.py#L24
{
"directory": "/Users/artem/Projects/mapbox/variant",
"command": "/Users/artem/Projects/mapbox/variant/.toolchain/bin/clang++ -o out/bench-variant test/bench_variant.cpp -I./include -isystem test/include -s\
td=c++11 -Werror -Wall -Wextra -pedantic -Wformat=2 -Wsign-conversion -Wshadow -Wunused-parameter -O3 -DNDEBUG -march=native -DSINGLE_THREADED -fvisibility-inli\
nes-hidden -fvisibility=hidden -stdlib=libc++ -mmacosx-version-min=10.7 -isystem /Users/artem/Projects/mapbox/variant/mason_packages/headers/boost/1.62.0/incl\
ude/",
"file": "/Users/artem/Projects/mapbox/variant/test/bench_variant.cpp"
}
]
^ yep, looks rather minimal
This is still an issue that prevents us from running clang-tidy on a full codebase. Here's the clang-tidy 7.0.0 message that I'm getting:
Here's a minimal reproduction:
#include <mapbox/variant.hpp>
class Empty {};
inline bool operator==(const Empty&, const Empty&) { return true; }
int main() {
using type = mapbox::util::variant<Empty, int>;
type a;
type b = a;
(void)(a == b);
}
I'm invoking clang-tidy like this:
clang-tidy -checks=clang-analyzer-core.UndefinedBinaryOperatorResult variant.cpp -- -std=c++14 -I<path-to-variant>
and get this output:
Some observations:
type b = a
) is vital, it doesn't reproduce without itclass Empty
)@kkaefer I'll take a look, thanks.
More observations:
Empty() {}
) makes the UB go away, but adding a defaulted constructor (Empty() = default
) doesn'tquick workaround :
struct alignas(1) Empty
{
std::uint8_t val = 1u;
Empty() {};
};
I'll see if is_empty<T>
can be used to add overloads for empty
types.
I'm attempting to set up clang-tidy to run on codebases using
variant
. I am consistently seeing most warnings coming from variant. So these need to be addressed here, at the source, by either adding// NOLINT
where appropriate or fixing.@artemp can you please tackle this next week?
Here are the warnings:
Here is how I'm testing:
run-clang-tidy
branch: https://github.com/mapbox/variant/compare/run-clang-tidy./scripts/clang-tidy.sh
/cc @daniel-j-h