From 884b9adcde5fad32b279f195cc76c27e8be3be34 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 7 Sep 2023 17:49:48 +0200 Subject: [PATCH] Add info about recommended warning options with clang. * HACKING (Warning Options): Add info regarding clang. --- ChangeLog | 5 + HACKING | 423 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 426 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 989c92576e..3c03f1840b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2023-09-07 Bruno Haible + + Add info about recommended warning options with clang. + * HACKING (Warning Options): Add info regarding clang. + 2023-09-07 Bruno Haible uchar: Fix references to overridden functions with GNULIB_NAMESPACE. diff --git a/HACKING b/HACKING index e771239b21..a3c65213d2 100644 --- a/HACKING +++ b/HACKING @@ -71,7 +71,77 @@ there are three possible approaches: available, here's a recipe that will find more mistakes, but is nearly as easy to use. Here, different warning options are needed for C and for C++: - $ WARN_GCC13="-fanalyzer -Wall -Warith-conversion -Wcast-align=strict -Wdate-time -Wdisabled-optimization -Wduplicated-cond -Wextra -Wformat-signedness -Winit-self -Winvalid-pch -Wlogical-op -Wmissing-include-dirs -Wopenmp-simd -Woverlength-strings -Wpacked -Wpointer-arith -Wstrict-overflow -Wsuggest-final-methods -Wsuggest-final-types -Wsync-nand -Wsystem-headers -Wtrampolines -Wuninitialized -Wunknown-pragmas -Wunsafe-loop-optimizations -Wvariadic-macros -Wvector-operation-performance -Wwrite-strings -Warray-bounds=2 -Wattribute-alias=2 -Wformat-overflow=2 -Wformat-truncation=2 -Wshift-overflow=2 -Wunused-const-variable=2 -Wvla-larger-than=4031 -Wno-empty-body -Wno-analyzer-allocation-size -Wno-analyzer-fd-double-close -Wno-analyzer-double-fclose -Wno-analyzer-double-free -Wno-analyzer-fd-leak -Wno-analyzer-fd-use-after-close -Wno-analyzer-fd-use-without-check -Wno-analyzer-free-of-non-heap -Wno-analyzer-malloc-leak -Wno-analyzer-mismatching-deallocation -Wno-analyzer-null-argument -Wno-analyzer-null-dereference -Wno-analyzer-out-of-bounds -Wno-analyzer-possible-null-argument -Wno-analyzer-possible-null-dereference -Wno-analyzer-use-after-free -Wno-analyzer-use-of-pointer-in-stale-stack-frame -Wno-analyzer-use-of-uninitialized-value -Wno-analyzer-va-arg-type-mismatch -Wno-attribute-warning -Wno-cast-align -Wno-clobbered -Wno-dangling-pointer -Wno-format -Wno-implicit-fallthrough -Wno-maybe-uninitialized -Wno-missing-field-initializers -Wno-restrict -Wno-sign-compare -Wno-switch -Wno-type-limits -Wno-unused-parameter" + $ WARN_GCC13=`echo ' + -fanalyzer + -Wall + -Warith-conversion + -Wcast-align=strict + -Wdate-time + -Wdisabled-optimization + -Wduplicated-cond + -Wextra + -Wformat-signedness + -Winit-self + -Winvalid-pch + -Wlogical-op + -Wmissing-include-dirs + -Wopenmp-simd + -Woverlength-strings + -Wpacked + -Wpointer-arith + -Wstrict-overflow + -Wsuggest-final-methods + -Wsuggest-final-types + -Wsync-nand + -Wsystem-headers + -Wtrampolines + -Wuninitialized + -Wunknown-pragmas + -Wunsafe-loop-optimizations + -Wvariadic-macros + -Wvector-operation-performance + -Wwrite-strings + -Warray-bounds=2 + -Wattribute-alias=2 + -Wformat-overflow=2 + -Wformat-truncation=2 + -Wshift-overflow=2 + -Wunused-const-variable=2 + -Wvla-larger-than=4031 + -Wno-empty-body + -Wno-analyzer-allocation-size + -Wno-analyzer-fd-double-close + -Wno-analyzer-double-fclose + -Wno-analyzer-double-free + -Wno-analyzer-fd-leak + -Wno-analyzer-fd-use-after-close + -Wno-analyzer-fd-use-without-check + -Wno-analyzer-free-of-non-heap + -Wno-analyzer-malloc-leak + -Wno-analyzer-mismatching-deallocation + -Wno-analyzer-null-argument + -Wno-analyzer-null-dereference + -Wno-analyzer-out-of-bounds + -Wno-analyzer-possible-null-argument + -Wno-analyzer-possible-null-dereference + -Wno-analyzer-use-after-free + -Wno-analyzer-use-of-pointer-in-stale-stack-frame + -Wno-analyzer-use-of-uninitialized-value + -Wno-analyzer-va-arg-type-mismatch + -Wno-attribute-warning + -Wno-cast-align + -Wno-clobbered + -Wno-dangling-pointer + -Wno-format + -Wno-implicit-fallthrough + -Wno-maybe-uninitialized + -Wno-missing-field-initializers + -Wno-restrict + -Wno-sign-compare + -Wno-switch + -Wno-type-limits + -Wno-unused-parameter + ' | tr -d '\n' | sed -e 's/ */ /g'` $ WARN_CFLAGS_GCC13="$WARN_GCC13 -Wnested-externs -Wshadow=local -Wno-discarded-qualifiers" $ WARN_CXXFLAGS_GCC13="$WARN_GCC13 -Wno-cpp" $ ./configure CFLAGS="-O2 -g $WARN_CFLAGS_GCC13" CXXFLAGS="-O2 -g $WARN_CXXFLAGS_GCC13" @@ -83,7 +153,63 @@ there are three possible approaches: * If you are developing on a glibc system and have GCC version 13 binaries available: Here's a recipe that will find even more mistakes, but it requires that you are willing to filter out and ignore pointless warnings. - $ WARN_GCC13="-fanalyzer -Wall -Warith-conversion -Wcast-align=strict -Wdate-time -Wdisabled-optimization -Wduplicated-cond -Wextra -Wformat-signedness -Winit-self -Winvalid-pch -Wlogical-op -Wmissing-include-dirs -Wnull-dereference -Wopenmp-simd -Woverlength-strings -Wpacked -Wpointer-arith -Wstrict-overflow -Wsuggest-attribute=format -Wsuggest-final-methods -Wsuggest-final-types -Wsync-nand -Wsystem-headers -Wtrampolines -Wuninitialized -Wunknown-pragmas -Wunsafe-loop-optimizations -Wvariadic-macros -Wvector-operation-performance -Wwrite-strings -Warray-bounds=2 -Wattribute-alias=2 -Wformat-overflow=2 -Wformat=2 -Wformat-truncation=2 -Wimplicit-fallthrough=5 -Wshift-overflow=2 -Wunused-const-variable=2 -Wvla-larger-than=4031 -Wno-empty-body -Wno-analyzer-double-fclose -Wno-analyzer-double-free -Wno-analyzer-free-of-non-heap -Wno-analyzer-malloc-leak -Wno-analyzer-null-argument -Wno-analyzer-null-dereference -Wno-analyzer-use-after-free -Wno-attribute-warning -Wno-cast-align -Wno-clobbered -Wno-format-nonliteral -Wno-sign-compare -Wno-type-limits -Wno-unused-parameter" + $ WARN_GCC13=`echo ' + -fanalyzer + -Wall + -Warith-conversion + -Wcast-align=strict + -Wdate-time + -Wdisabled-optimization + -Wduplicated-cond + -Wextra + -Wformat-signedness + -Winit-self + -Winvalid-pch + -Wlogical-op + -Wmissing-include-dirs + -Wnull-dereference + -Wopenmp-simd + -Woverlength-strings + -Wpacked + -Wpointer-arith + -Wstrict-overflow + -Wsuggest-attribute=format + -Wsuggest-final-methods + -Wsuggest-final-types + -Wsync-nand + -Wsystem-headers + -Wtrampolines + -Wuninitialized + -Wunknown-pragmas + -Wunsafe-loop-optimizations + -Wvariadic-macros + -Wvector-operation-performance + -Wwrite-strings + -Warray-bounds=2 + -Wattribute-alias=2 + -Wformat-overflow=2 + -Wformat=2 + -Wformat-truncation=2 + -Wimplicit-fallthrough=5 + -Wshift-overflow=2 + -Wunused-const-variable=2 + -Wvla-larger-than=4031 + -Wno-empty-body + -Wno-analyzer-double-fclose + -Wno-analyzer-double-free + -Wno-analyzer-free-of-non-heap + -Wno-analyzer-malloc-leak + -Wno-analyzer-null-argument + -Wno-analyzer-null-dereference + -Wno-analyzer-use-after-free + -Wno-attribute-warning + -Wno-cast-align + -Wno-clobbered + -Wno-format-nonliteral + -Wno-sign-compare + -Wno-type-limits + -Wno-unused-parameter + ' | tr -d '\n' | sed -e 's/ */ /g'` $ WARN_CFLAGS_GCC13="$WARN_GCC13 -Wnested-externs -Wshadow=local" $ WARN_CXXFLAGS_GCC13="$WARN_GCC13 -Wno-cpp" $ ./configure CFLAGS="-O2 -g $WARN_CFLAGS_GCC13" CXXFLAGS="-O2 -g $WARN_CXXFLAGS_GCC13" @@ -95,3 +221,296 @@ there are three possible approaches: - Some of the warnings are false positives. Rather than silencing these warnings, we prefer to report them in the GCC bug tracker and wait until they are fixed in a future GCC release. + +Similarly, for clang version 16 you can use the following recipe, that uses +selected warning options from +https://releases.llvm.org/16.0.0/tools/clang/docs/DiagnosticsReference.html : + $ WARN_CLANG16=`echo ' + -Wall + -Wanon-enum-enum-conversion + -Warc-repeated-use-of-weak + -Warray-bounds-pointer-arithmetic + -Warray-parameter + -Watomic-properties + -Wbinary-literal + -Wbit-int-extension + -Wbitfield-enum-conversion + -Wbitwise-op-parentheses + -Wbool-operation + -Wc++-compat + -Wc2x-compat + -Wc2x-extensions + -Wc99-compat + -Wc99-designator + -Wc99-extensions + -Wcalled-once-parameter + -Wcast-function-type + -Wchar-subscripts + -Wcomment + -Wcompletion-handler + -Wcomplex-component-init + -Wcompound-token-split + -Wconsumed + -Wconversion + -Wcstring-format-directive + -Wcuda-compat + -Wdate-time + -Wdelimited-escape-sequence-extension + -Wdeprecated + -Wdeprecated-dynamic-exception-spec + -Wdeprecated-implementations + -Wdeprecated-this-capture + -Wdeprecated-writable-strings + -Wdirect-ivar-access + -Wdocumentation + -Wdocumentation-deprecated-sync + -Wdocumentation-html + -Wdocumentation-pedantic + -Wdocumentation-unknown-command + -Wdollar-in-identifier-extension + -Wduplicate-decl-specifier + -Wduplicate-enum + -Wduplicate-method-arg + -Wduplicate-method-match + -Wdynamic-exception-spec + -Wembedded-directive + -Wempty-init-stmt + -Wempty-translation-unit + -Wenum-compare-conditional + -Wenum-conversion + -Wenum-enum-conversion + -Wenum-float-conversion + -Wexit-time-destructors + -Wexpansion-to-defined + -Wexplicit-ownership-type + -Wextra + -Wextra-semi + -Wfixed-enum-extension + -Wflexible-array-extensions + -Wfloat-overflow-conversion + -Wfloat-zero-conversion + -Wfor-loop-analysis + -Wformat + -Wformat-pedantic + -Wformat-type-confusion + -Wformat=2 + -Wfour-char-constants + -Wframe-address + -Wfuse-ld-path + -Wfuture-attribute-extensions + -Wgcc-compat + -Wgnu + -Wgnu-anonymous-struct + -Wgnu-auto-type + -Wgnu-case-range + -Wgnu-complex-integer + -Wgnu-compound-literal-initializer + -Wgnu-conditional-omitted-operand + -Wgnu-designator + -Wgnu-empty-initializer + -Wgnu-empty-struct + -Wgnu-flexible-array-initializer + -Wgnu-flexible-array-union-member + -Wgnu-folding-constant + -Wgnu-imaginary-constant + -Wgnu-label-as-value + -Wgnu-line-marker + -Wgnu-null-pointer-arithmetic + -Wgnu-offsetof-extensions + -Wgnu-pointer-arith + -Wgnu-redeclared-enum + -Wgnu-statement-expression + -Wgnu-statement-expression-from-macro-expansion + -Wgnu-union-cast + -Wgnu-zero-line-directive + -Wgnu-zero-variadic-macro-arguments + -Wheader-hygiene + -Widiomatic-parentheses + -Wignored-qualifiers + -Wimplicit + -Wimplicit-fallthrough + -Wimplicit-fallthrough-per-function + -Wimplicit-function-declaration + -Wimplicit-int + -Wimplicit-retain-self + -Wimport-preprocessor-directive-pedantic + -Wincomplete-module + -Winconsistent-missing-destructor-override + -Winfinite-recursion + -Wint-in-bool-context + -Winvalid-or-nonexistent-directory + -Winvalid-utf8 + -Wkeyword-macro + -Wlanguage-extension-token + -Wlocal-type-template-args + -Wlogical-op-parentheses + -Wlong-long + -Wloop-analysis + -Wmain + -Wmax-tokens + -Wmethod-signatures + -Wmicrosoft + -Wmicrosoft-anon-tag + -Wmicrosoft-charize + -Wmicrosoft-comment-paste + -Wmicrosoft-cpp-macro + -Wmicrosoft-end-of-file + -Wmicrosoft-enum-value + -Wmicrosoft-exception-spec + -Wmicrosoft-fixed-enum + -Wmicrosoft-flexible-array + -Wmicrosoft-redeclare-static + -Wmisleading-indentation + -Wmismatched-tags + -Wmissing-braces + -Wmissing-method-return-type + -Wmost + -Wmove + -Wnested-anon-types + -Wnewline-eof + -Wnon-gcc + -Wnon-modular-include-in-framework-module + -Wnon-modular-include-in-module + -Wnon-virtual-dtor + -Wnonportable-system-include-path + -Wnull-pointer-arithmetic + -Wnull-pointer-subtraction + -Wnullability-extension + -Wnullable-to-nonnull-conversion + -Wopenmp + -Wover-aligned + -Woverlength-strings + -Woverloaded-virtual + -Woverriding-method-mismatch + -Wpacked + -Wpacked-non-pod + -Wparentheses + -Wpedantic + -Wpedantic-core-features + -Wpessimizing-move + -Wpointer-arith + -Wpoison-system-directories + -Wpragma-pack + -Wpragma-pack-suspicious-include + -Wpragmas + -Wpre-c2x-compat + -Wpre-openmp-51-compat + -Wprofile-instr-missing + -Wquoted-include-in-framework-header + -Wrange-loop-analysis + -Wrange-loop-bind-reference + -Wrange-loop-construct + -Wreceiver-forward-class + -Wredundant-move + -Wredundant-parens + -Wreorder + -Wreorder-ctor + -Wreserved-user-defined-literal + -Wretained-language-linkage + -Wselector + -Wselector-type-mismatch + -Wself-assign + -Wself-assign-overloaded + -Wself-move + -Wsemicolon-before-method-body + -Wshadow-all + -Wshadow-field + -Wshadow-field-in-constructor + -Wshadow-field-in-constructor-modified + -Wshadow-uncaptured-local + -Wshift-sign-overflow + -Wsigned-enum-bitfield + -Wsometimes-uninitialized + -Wsource-uses-openmp + -Wspir-compat + -Wstatic-in-inline + -Wstrict-potentially-direct-selector + -Wstrict-selector-match + -Wstring-concatenation + -Wstring-conversion + -Wsuggest-destructor-override + -Wsuggest-override + -Wsuper-class-method-mismatch + -Wtautological-bitwise-compare + -Wtautological-compare + -Wtautological-constant-in-range-compare + -Wtautological-overlap-compare + -Wtautological-type-limit-compare + -Wtautological-unsigned-char-zero-compare + -Wtautological-unsigned-enum-zero-compare + -Wtautological-unsigned-zero-compare + -Wtautological-value-range-compare + -Wthread-safety + -Wthread-safety-analysis + -Wthread-safety-attributes + -Wthread-safety-beta + -Wthread-safety-negative + -Wthread-safety-precise + -Wthread-safety-reference + -Wthread-safety-verbose + -Wtype-limits + -Wunaligned-access + -Wundeclared-selector + -Wundef-prefix + -Wundefined-func-template + -Wundefined-internal-type + -Wundefined-reinterpret-cast + -Wunguarded-availability + -Wuninitialized + -Wuninitialized-const-reference + -Wunknown-pragmas + -Wunnamed-type-template-args + -Wunneeded-internal-declaration + -Wunneeded-member-function + -Wunreachable-code-fallthrough + -Wunreachable-code-loop-increment + -Wunsupported-dll-base-class-template + -Wunused + -Wunused-but-set-parameter + -Wunused-but-set-variable + -Wunused-const-variable + -Wunused-exception-parameter + -Wunused-function + -Wunused-label + -Wunused-lambda-capture + -Wunused-local-typedef + -Wunused-member-function + -Wunused-private-field + -Wunused-property-ivar + -Wunused-template + -Wunused-variable + -Wvariadic-macros + -Wvector-conversion + -Wweak-template-vtables + -Wweak-vtables + -Wzero-length-array + -Wno-bitwise-instead-of-logical + -Wno-c11-extensions + -Wno-cast-function-type-strict + -Wno-float-conversion + -Wno-format-nonliteral + -Wno-gnu-include-next + -Wno-implicit-float-conversion + -Wno-implicit-int-conversion + -Wno-implicit-int-float-conversion + -Wno-include-next-absolute-path + -Wno-missing-field-initializers + -Wno-reserved-macro-identifier + -Wno-shadow + -Wno-shorten-64-to-32 + -Wno-sign-compare + -Wno-sign-conversion + -Wno-strict-prototypes + -Wno-switch + -Wno-unused-parameter + -Wno-tautological-constant-out-of-range-compare + -Wno-tautological-type-limit-compare + -Wno-tautological-unsigned-zero-compare + -Wno-tautological-value-range-compare + -Wno-unused-command-line-argument + -Wno-user-defined-warnings + ' | tr -d '\n' | sed -e 's/ */ /g'` + $ ./configure CFLAGS="-O2 -g $WARN_CLANG16" CXXFLAGS="-O2 -g $WARN_CLANG16" + $ make +Again, use your own judgement to determine whether to fix or ignore a +specific warning. -- 2.39.5