From 07b4a6d0461fe64e10d30029ed3d598e49ca3810 Mon Sep 17 00:00:00 2001 From: Balazs Benics Date: Fri, 10 Jun 2022 13:09:37 +0200 Subject: [PATCH] [analyzer] Deprecate the unused 'analyzer-opt-analyze-nested-blocks' cc1 flag This flag was introduced by https://github.com/llvm/llvm-project/commit/6818991d7165f68fe196922d9e5c6648dd57cc47 commit 6818991d7165f68fe196922d9e5c6648dd57cc47 Author: Ted Kremenek Date: Mon Dec 7 22:06:12 2009 +0000 Add clang-cc option '-analyzer-opt-analyze-nested-blocks' to treat block literals as an entry point for analyzer checks. The last reference was removed by this commit: https://github.com/llvm/llvm-project/commit/5c32dfc5fb1cfcff8ae3671284e17daa8da3a188 commit 5c32dfc5fb1cfcff8ae3671284e17daa8da3a188 Author: Anna Zaks Date: Fri Dec 21 01:19:15 2012 +0000 [analyzer] Add blocks and ObjC messages to the call graph. This paves the road for constructing a better function dependency graph. If we analyze a function before the functions it calls and inlines, there is more opportunity for optimization. Note, we add call edges to the called methods that correspond to function definitions (declarations with bodies). Consequently, we should remove this dead flag. However, this arises a couple of burning questions. - Should the `cc1` frontend still accept this flag - to keep tools/users passing this flag directly to `cc1` (which is unsupported, unadvertised) working. - If we should remain backward compatible, how long? - How can we get rid of deprecated and obsolete flags at some point? Reviewed By: martong Differential Revision: https://reviews.llvm.org/D126067 --- clang-tools-extra/clang-tidy/ClangTidy.cpp | 1 - clang/docs/ReleaseNotes.rst | 7 ++++--- clang/include/clang/Driver/Options.td | 4 ++-- clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h | 9 ++++----- clang/lib/Driver/ToolChains/Clang.cpp | 3 --- clang/lib/Frontend/CompilerInvocation.cpp | 4 ++++ clang/test/Analysis/OSAtomic_mac.cpp | 2 +- clang/test/Analysis/analyzer-stats.c | 2 +- clang/test/Analysis/blocks.m | 4 ++-- clang/test/Analysis/blocks.mm | 6 +++--- clang/test/Analysis/deprecated-flags-and-options.cpp | 5 +++++ clang/test/Analysis/misc-ps-arm.m | 2 +- clang/test/Analysis/misc-ps-region-store.cpp | 4 ++-- clang/test/Analysis/misc-ps-region-store.m | 4 ++-- clang/test/Analysis/misc-ps-region-store.mm | 4 ++-- clang/test/Analysis/objc-arc.m | 2 +- clang/test/Analysis/unreachable-code-path.c | 2 +- 17 files changed, 35 insertions(+), 30 deletions(-) diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp index cd0cbfd..fbfe27b 100644 --- a/clang-tools-extra/clang-tidy/ClangTidy.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp @@ -443,7 +443,6 @@ ClangTidyASTConsumerFactory::createASTConsumer( setStaticAnalyzerCheckerOpts(Context.getOptions(), *AnalyzerOptions); AnalyzerOptions->AnalysisStoreOpt = RegionStoreModel; AnalyzerOptions->AnalysisDiagOpt = PD_NONE; - AnalyzerOptions->AnalyzeNestedBlocks = true; AnalyzerOptions->eagerlyAssumeBinOpBifurcation = true; std::unique_ptr AnalysisConsumer = ento::CreateAnalysisConsumer(Compiler); diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 40e5381..3e64970 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -544,9 +544,10 @@ Static Analyzer `strcmp``, ``strncmp``, ``strcpy``, ``strlen``, ``strsep`` and many more. Although this checker currently is in list of alpha checkers due to a false positive. -- Deprecate ``-analyzer-store region`` analyzer flag. - This flag is still accepted, but a warning will be displayed. - This flag will be rejected, thus turned into a hard error starting with +- Deprecate the ``-analyzer-store region`` and + ``-analyzer-opt-analyze-nested-blocks`` analyzer flags. + These flags are still accepted, but a warning will be displayed. + These flags will be rejected, thus turned into a hard error starting with ``clang-16``. .. _release-notes-ubsan: diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 4895da7..991e858 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5018,9 +5018,9 @@ def analyzer_purge_EQ : Joined<["-"], "analyzer-purge=">, Alias; def analyzer_opt_analyze_headers : Flag<["-"], "analyzer-opt-analyze-headers">, HelpText<"Force the static analyzer to analyze functions defined in header files">, MarshallingInfoFlag>; +// We should remove this option in clang-16 release. def analyzer_opt_analyze_nested_blocks : Flag<["-"], "analyzer-opt-analyze-nested-blocks">, - HelpText<"Analyze the definitions of blocks in addition to functions">, - MarshallingInfoFlag>; + HelpText<"Analyze the definitions of blocks in addition to functions [DEPRECATED, removing in clang-16]">; def analyzer_display_progress : Flag<["-"], "analyzer-display-progress">, HelpText<"Emit verbose output about the analyzer's progress">, MarshallingInfoFlag>; diff --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h index 22c8cd7..2f19686 100644 --- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h +++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h @@ -236,7 +236,6 @@ public: unsigned ShouldEmitErrorsOnInvalidConfigValue : 1; unsigned AnalyzeAll : 1; unsigned AnalyzerDisplayProgress : 1; - unsigned AnalyzeNestedBlocks : 1; unsigned eagerlyAssumeBinOpBifurcation : 1; @@ -298,10 +297,10 @@ public: ShowCheckerOptionList(false), ShowCheckerOptionAlphaList(false), ShowCheckerOptionDeveloperList(false), ShowEnabledCheckerList(false), ShowConfigOptionsList(false), AnalyzeAll(false), - AnalyzerDisplayProgress(false), AnalyzeNestedBlocks(false), - eagerlyAssumeBinOpBifurcation(false), TrimGraph(false), - visualizeExplodedGraphWithGraphViz(false), UnoptimizedCFG(false), - PrintStats(false), NoRetryExhausted(false), AnalyzerWerror(false) { + AnalyzerDisplayProgress(false), eagerlyAssumeBinOpBifurcation(false), + TrimGraph(false), visualizeExplodedGraphWithGraphViz(false), + UnoptimizedCFG(false), PrintStats(false), NoRetryExhausted(false), + AnalyzerWerror(false) { llvm::sort(AnalyzerConfigCmdFlags); } diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 286824a..759cca8 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -3158,9 +3158,6 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, static void RenderAnalyzerOptions(const ArgList &Args, ArgStringList &CmdArgs, const llvm::Triple &Triple, const InputInfo &Input) { - // Treat blocks as analysis entry points. - CmdArgs.push_back("-analyzer-opt-analyze-nested-blocks"); - // Add default argument set. if (!Args.hasArg(options::OPT__analyzer_no_default_checks)) { CmdArgs.push_back("-analyzer-checker=core"); diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index e093582..12aa73c 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -906,6 +906,10 @@ static bool ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args, if (Arg *A = Args.getLastArg(OPT_analyzer_store)) Diags.Report(diag::warn_analyzer_deprecated_option) << "-analyzer-store" << "clang-16"; + if (Arg *A = Args.getLastArg(OPT_analyzer_opt_analyze_nested_blocks)) + Diags.Report(diag::warn_analyzer_deprecated_option) + << "-analyzer-opt-analyze-nested-blocks" + << "clang-16"; if (Arg *A = Args.getLastArg(OPT_analyzer_constraints)) { StringRef Name = A->getValue(); diff --git a/clang/test/Analysis/OSAtomic_mac.cpp b/clang/test/Analysis/OSAtomic_mac.cpp index 71a241f..6a97e1a 100644 --- a/clang/test/Analysis/OSAtomic_mac.cpp +++ b/clang/test/Analysis/OSAtomic_mac.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin9 -analyzer-checker=core,osx -verify -fblocks -analyzer-opt-analyze-nested-blocks %s +// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin9 -analyzer-checker=core,osx -verify -fblocks %s // expected-no-diagnostics // Test handling of OSAtomicCompareAndSwap when C++ inserts "no-op" casts and we diff --git a/clang/test/Analysis/analyzer-stats.c b/clang/test/Analysis/analyzer-stats.c index 69c61e1..7e2e916 100644 --- a/clang/test/Analysis/analyzer-stats.c +++ b/clang/test/Analysis/analyzer-stats.c @@ -1,4 +1,4 @@ -// RUN: %clang_analyze_cc1 -analyzer-checker=core,deadcode.DeadStores,debug.Stats -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks -analyzer-max-loop 4 %s +// RUN: %clang_analyze_cc1 -analyzer-checker=core,deadcode.DeadStores,debug.Stats -verify -Wno-unreachable-code -analyzer-max-loop 4 %s int foo(void); diff --git a/clang/test/Analysis/blocks.m b/clang/test/Analysis/blocks.m index a3776dd..be3964f 100644 --- a/clang/test/Analysis/blocks.m +++ b/clang/test/Analysis/blocks.m @@ -1,5 +1,5 @@ -// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core -fblocks -analyzer-opt-analyze-nested-blocks -verify -Wno-strict-prototypes %s -// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core -fblocks -analyzer-opt-analyze-nested-blocks -verify -x objective-c++ %s +// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core -fblocks -verify -Wno-strict-prototypes %s +// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core -fblocks -verify -x objective-c++ %s //===----------------------------------------------------------------------===// // The following code is reduced using delta-debugging from Mac OS X headers: diff --git a/clang/test/Analysis/blocks.mm b/clang/test/Analysis/blocks.mm index 97c531e..033be37 100644 --- a/clang/test/Analysis/blocks.mm +++ b/clang/test/Analysis/blocks.mm @@ -1,7 +1,7 @@ -// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core -fblocks -analyzer-opt-analyze-nested-blocks -verify -x objective-c++ %s -// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,debug.DumpCFG -fblocks -analyzer-opt-analyze-nested-blocks -analyzer-config cfg-rich-constructors=false %s > %t 2>&1 +// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core -fblocks -verify -x objective-c++ %s +// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,debug.DumpCFG -fblocks -analyzer-config cfg-rich-constructors=false %s > %t 2>&1 // RUN: FileCheck --input-file=%t -check-prefixes=CHECK,WARNINGS %s -// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,debug.DumpCFG -fblocks -analyzer-opt-analyze-nested-blocks -analyzer-config cfg-rich-constructors=true %s > %t 2>&1 +// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,debug.DumpCFG -fblocks -analyzer-config cfg-rich-constructors=true %s > %t 2>&1 // RUN: FileCheck --input-file=%t -check-prefixes=CHECK,ANALYZER %s // This file tests how we construct two different flavors of the Clang CFG - diff --git a/clang/test/Analysis/deprecated-flags-and-options.cpp b/clang/test/Analysis/deprecated-flags-and-options.cpp index bf8a077..262ce9d 100644 --- a/clang/test/Analysis/deprecated-flags-and-options.cpp +++ b/clang/test/Analysis/deprecated-flags-and-options.cpp @@ -5,8 +5,13 @@ // RUN: | FileCheck %s --check-prefixes=CHECK,DEPRECATED-STORE // DEPRECATED-STORE: warning: analyzer option '-analyzer-store' is deprecated. This flag will be removed in clang-16, and passing this option will be an error. +// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-opt-analyze-nested-blocks %s 2>&1 \ +// RUN: | FileCheck %s --check-prefixes=CHECK,DEPRECATED-NESTED-BLOCKS +// DEPRECATED-NESTED-BLOCKS: warning: analyzer option '-analyzer-opt-analyze-nested-blocks' is deprecated. This flag will be removed in clang-16, and passing this option will be an error. + // RUN: %clang_analyze_cc1 -analyzer-checker=core %s --help 2>&1 \ // RUN: | FileCheck %s --check-prefixes=CHECK-HELP +// CHECK-HELP: Analyze the definitions of blocks in addition to functions [DEPRECATED, removing in clang-16] // CHECK-HELP: -analyzer-store Source Code Analysis - Abstract Memory Store Models [DEPRECATED, removing in clang-16] int empty(int x) { diff --git a/clang/test/Analysis/misc-ps-arm.m b/clang/test/Analysis/misc-ps-arm.m index f5dc69a..e7c4475 100644 --- a/clang/test/Analysis/misc-ps-arm.m +++ b/clang/test/Analysis/misc-ps-arm.m @@ -1,4 +1,4 @@ -// RUN: %clang_analyze_cc1 -triple thumbv7-apple-ios0.0.0 -target-feature +neon -analyzer-checker=core -verify -fblocks -analyzer-opt-analyze-nested-blocks -Wno-objc-root-class %s +// RUN: %clang_analyze_cc1 -triple thumbv7-apple-ios0.0.0 -target-feature +neon -analyzer-checker=core -verify -fblocks -Wno-objc-root-class %s // expected-no-diagnostics // - Handle casts of vectors to structs, and loading diff --git a/clang/test/Analysis/misc-ps-region-store.cpp b/clang/test/Analysis/misc-ps-region-store.cpp index 9b8caca..c9bead5 100644 --- a/clang/test/Analysis/misc-ps-region-store.cpp +++ b/clang/test/Analysis/misc-ps-region-store.cpp @@ -1,5 +1,5 @@ -// RUN: %clang_analyze_cc1 -triple i386-apple-darwin9 -analyzer-checker=core,alpha.core,debug.ExprInspection -verify -fblocks -analyzer-opt-analyze-nested-blocks %s -fexceptions -fcxx-exceptions -Wno-tautological-undefined-compare -// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin9 -analyzer-checker=core,alpha.core,debug.ExprInspection -verify -fblocks -analyzer-opt-analyze-nested-blocks %s -fexceptions -fcxx-exceptions -Wno-tautological-undefined-compare +// RUN: %clang_analyze_cc1 -triple i386-apple-darwin9 -analyzer-checker=core,alpha.core,debug.ExprInspection -verify -fblocks %s -fexceptions -fcxx-exceptions -Wno-tautological-undefined-compare +// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin9 -analyzer-checker=core,alpha.core,debug.ExprInspection -verify -fblocks %s -fexceptions -fcxx-exceptions -Wno-tautological-undefined-compare void clang_analyzer_warnIfReached(); diff --git a/clang/test/Analysis/misc-ps-region-store.m b/clang/test/Analysis/misc-ps-region-store.m index ba8db77..199ff2f 100644 --- a/clang/test/Analysis/misc-ps-region-store.m +++ b/clang/test/Analysis/misc-ps-region-store.m @@ -1,5 +1,5 @@ -// RUN: %clang_analyze_cc1 -triple i386-apple-darwin9 -analyzer-checker=core,alpha.core.CastToStruct,alpha.security.ReturnPtrRange,alpha.security.ArrayBound -verify -fblocks -analyzer-opt-analyze-nested-blocks -Wno-objc-root-class -Wno-strict-prototypes -Wno-error=implicit-function-declaration %s -// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin9 -DTEST_64 -analyzer-checker=core,alpha.core.CastToStruct,alpha.security.ReturnPtrRange,alpha.security.ArrayBound -verify -fblocks -analyzer-opt-analyze-nested-blocks -Wno-objc-root-class -Wno-strict-prototypes -Wno-error=implicit-function-declaration %s +// RUN: %clang_analyze_cc1 -triple i386-apple-darwin9 -analyzer-checker=core,alpha.core.CastToStruct,alpha.security.ReturnPtrRange,alpha.security.ArrayBound -verify -fblocks -Wno-objc-root-class -Wno-strict-prototypes -Wno-error=implicit-function-declaration %s +// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin9 -DTEST_64 -analyzer-checker=core,alpha.core.CastToStruct,alpha.security.ReturnPtrRange,alpha.security.ArrayBound -verify -fblocks -Wno-objc-root-class -Wno-strict-prototypes -Wno-error=implicit-function-declaration %s typedef long unsigned int size_t; void *memcpy(void *, const void *, size_t); diff --git a/clang/test/Analysis/misc-ps-region-store.mm b/clang/test/Analysis/misc-ps-region-store.mm index ca9e77b..8e00a67 100644 --- a/clang/test/Analysis/misc-ps-region-store.mm +++ b/clang/test/Analysis/misc-ps-region-store.mm @@ -1,5 +1,5 @@ -// RUN: %clang_analyze_cc1 -triple i386-apple-darwin9 -analyzer-checker=core,alpha.core -verify -fblocks -analyzer-opt-analyze-nested-blocks %s -// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin9 -analyzer-checker=core,alpha.core -verify -fblocks -analyzer-opt-analyze-nested-blocks %s +// RUN: %clang_analyze_cc1 -triple i386-apple-darwin9 -analyzer-checker=core,alpha.core -verify -fblocks %s +// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin9 -analyzer-checker=core,alpha.core -verify -fblocks %s // expected-no-diagnostics //===------------------------------------------------------------------------------------------===// diff --git a/clang/test/Analysis/objc-arc.m b/clang/test/Analysis/objc-arc.m index 5fe5eb34..5489d50 100644 --- a/clang/test/Analysis/objc-arc.m +++ b/clang/test/Analysis/objc-arc.m @@ -1,4 +1,4 @@ -// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,osx.cocoa.RetainCount,deadcode -verify -fblocks -analyzer-opt-analyze-nested-blocks -fobjc-arc -analyzer-output=plist-multi-file -analyzer-config deadcode.DeadStores:ShowFixIts=true -o %t.plist %s +// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,osx.cocoa.RetainCount,deadcode -verify -fblocks -fobjc-arc -analyzer-output=plist-multi-file -analyzer-config deadcode.DeadStores:ShowFixIts=true -o %t.plist %s // RUN: %normalize_plist <%t.plist | diff -ub %S/Inputs/expected-plists/objc-arc.m.plist - typedef signed char BOOL; diff --git a/clang/test/Analysis/unreachable-code-path.c b/clang/test/Analysis/unreachable-code-path.c index 59bca57..cc526ade 100644 --- a/clang/test/Analysis/unreachable-code-path.c +++ b/clang/test/Analysis/unreachable-code-path.c @@ -1,4 +1,4 @@ -// RUN: %clang_analyze_cc1 -analyzer-checker=core,deadcode.DeadStores,alpha.deadcode.UnreachableCode -verify -analyzer-opt-analyze-nested-blocks -Wno-unused-value %s +// RUN: %clang_analyze_cc1 -analyzer-checker=core,deadcode.DeadStores,alpha.deadcode.UnreachableCode -verify -Wno-unused-value %s extern void foo(int a); -- 2.7.4