[clang] 7cd1f3a - [analyzer] Remove deprecated analyzer-config options
Balazs Benics via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 7 04:25:11 PDT 2023
Author: Balazs Benics
Date: 2023-07-07T13:24:33+02:00
New Revision: 7cd1f3ad22e48924e7061539eb0acb0e0c49eb63
URL: https://github.com/llvm/llvm-project/commit/7cd1f3ad22e48924e7061539eb0acb0e0c49eb63
DIFF: https://github.com/llvm/llvm-project/commit/7cd1f3ad22e48924e7061539eb0acb0e0c49eb63.diff
LOG: [analyzer] Remove deprecated analyzer-config options
The `consider-single-element-arrays-as-flexible-array-members` analyzer
option was deprecated in clang-16, and now removed from clang-17 as
promised in
https://releases.llvm.org/16.0.0/tools/clang/docs/ReleaseNotes.html#static-analyzer
This shouldn't change observable behavior.
Differential Revision: https://reviews.llvm.org/D154481
Added:
Modified:
clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/StaticAnalyzer/Core/MemRegion.cpp
clang/test/Analysis/analyzer-config.c
clang/test/Analysis/deprecated-flags-and-options.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
index acfbcf67b1b9d6..2fc825c2af9c36 100644
--- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
+++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
@@ -326,15 +326,6 @@ ANALYZER_OPTION(bool, ShouldSupportSymbolicIntegerCasts,
"Produce cast symbols for integral types.",
false)
-ANALYZER_OPTION(
- bool, ShouldConsiderSingleElementArraysAsFlexibleArrayMembers,
- "consider-single-element-arrays-as-flexible-array-members",
- "Consider single element arrays as flexible array member candidates. "
- "This will prevent the analyzer from assuming that a single element array "
- "holds a single element. [DEPRECATED, removing in clang-17; "
- "use '-fstrict-flex-arrays=<N>' instead]",
- true)
-
ANALYZER_OPTION(
bool, ShouldAssumeControlledEnvironment, "assume-controlled-environment",
"Whether the analyzed application runs in a controlled environment. "
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index dca8853f1c2047..50440e65a62251 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1056,15 +1056,6 @@ static bool ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args,
A->claim();
Opts.Config[key] = std::string(val);
-
- // FIXME: Remove this hunk after clang-17 released.
- constexpr auto SingleFAM =
- "consider-single-element-arrays-as-flexible-array-members";
- if (key == SingleFAM) {
- Diags.Report(diag::warn_analyzer_deprecated_option_with_alternative)
- << SingleFAM << "clang-17"
- << "-fstrict-flex-arrays=<N>";
- }
}
}
diff --git a/clang/lib/StaticAnalyzer/Core/MemRegion.cpp b/clang/lib/StaticAnalyzer/Core/MemRegion.cpp
index 912ba71dd57381..f89e71a4f157b7 100644
--- a/clang/lib/StaticAnalyzer/Core/MemRegion.cpp
+++ b/clang/lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -805,49 +805,46 @@ DefinedOrUnknownSVal MemRegionManager::getStaticSize(const MemRegion *MR,
// We currently don't model flexible array members (FAMs), which are:
// - int array[]; of IncompleteArrayType
// - int array[0]; of ConstantArrayType with size 0
- // - int array[1]; of ConstantArrayType with size 1 (*)
- // (*): Consider single element array object members as FAM candidates only
- // if the consider-single-element-arrays-as-flexible-array-members
- // analyzer option is true.
+ // - int array[1]; of ConstantArrayType with size 1
// https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
- const auto isFlexibleArrayMemberCandidate = [this,
- &SVB](QualType Ty) -> bool {
- const ArrayType *AT = Ctx.getAsArrayType(Ty);
+ const auto isFlexibleArrayMemberCandidate =
+ [this](const ArrayType *AT) -> bool {
if (!AT)
return false;
- if (isa<IncompleteArrayType>(AT))
- return true;
- if (const auto *CAT = dyn_cast<ConstantArrayType>(AT)) {
- using FAMKind = LangOptions::StrictFlexArraysLevelKind;
- const FAMKind StrictFlexArraysLevel =
+ auto IsIncompleteArray = [](const ArrayType *AT) {
+ return isa<IncompleteArrayType>(AT);
+ };
+ auto IsArrayOfZero = [](const ArrayType *AT) {
+ const auto *CAT = dyn_cast<ConstantArrayType>(AT);
+ return CAT && CAT->getSize() == 0;
+ };
+ auto IsArrayOfOne = [](const ArrayType *AT) {
+ const auto *CAT = dyn_cast<ConstantArrayType>(AT);
+ return CAT && CAT->getSize() == 1;
+ };
+
+ using FAMKind = LangOptions::StrictFlexArraysLevelKind;
+ const FAMKind StrictFlexArraysLevel =
Ctx.getLangOpts().getStrictFlexArraysLevel();
- const AnalyzerOptions &Opts = SVB.getAnalyzerOptions();
- const llvm::APInt &Size = CAT->getSize();
-
- if (StrictFlexArraysLevel <= FAMKind::ZeroOrIncomplete && Size.isZero())
- return true;
-
- // The "-fstrict-flex-arrays" should have precedence over
- // consider-single-element-arrays-as-flexible-array-members
- // analyzer-config when checking single element arrays.
- if (StrictFlexArraysLevel == FAMKind::Default) {
- // FIXME: After clang-17 released, we should remove this branch.
- if (Opts.ShouldConsiderSingleElementArraysAsFlexibleArrayMembers &&
- Size.isOne())
- return true;
- } else {
- // -fstrict-flex-arrays was specified, since it's not the default, so
- // ignore analyzer-config.
- if (StrictFlexArraysLevel <= FAMKind::OneZeroOrIncomplete &&
- Size.isOne())
- return true;
- }
- }
- return false;
+
+ // "Default": Any trailing array member is a FAM.
+ // Since we cannot tell at this point if this array is a trailing member
+ // or not, let's just do the same as for "OneZeroOrIncomplete".
+ if (StrictFlexArraysLevel == FAMKind::Default)
+ return IsArrayOfOne(AT) || IsArrayOfZero(AT) || IsIncompleteArray(AT);
+
+ if (StrictFlexArraysLevel == FAMKind::OneZeroOrIncomplete)
+ return IsArrayOfOne(AT) || IsArrayOfZero(AT) || IsIncompleteArray(AT);
+
+ if (StrictFlexArraysLevel == FAMKind::ZeroOrIncomplete)
+ return IsArrayOfZero(AT) || IsIncompleteArray(AT);
+
+ assert(StrictFlexArraysLevel == FAMKind::IncompleteOnly);
+ return IsIncompleteArray(AT);
};
- if (isFlexibleArrayMemberCandidate(Ty))
+ if (isFlexibleArrayMemberCandidate(Ctx.getAsArrayType(Ty)))
return UnknownVal();
return Size;
diff --git a/clang/test/Analysis/analyzer-config.c b/clang/test/Analysis/analyzer-config.c
index ed5e6c8cca63c1..4fd00068b7d9c2 100644
--- a/clang/test/Analysis/analyzer-config.c
+++ b/clang/test/Analysis/analyzer-config.c
@@ -33,7 +33,6 @@
// CHECK-NEXT: cfg-rich-constructors = true
// CHECK-NEXT: cfg-scopes = false
// CHECK-NEXT: cfg-temporary-dtors = true
-// CHECK-NEXT: consider-single-element-arrays-as-flexible-array-members = true
// CHECK-NEXT: core.CallAndMessage:ArgInitializedness = true
// CHECK-NEXT: core.CallAndMessage:ArgPointeeInitializedness = false
// CHECK-NEXT: core.CallAndMessage:CXXDeallocationArg = true
diff --git a/clang/test/Analysis/deprecated-flags-and-options.cpp b/clang/test/Analysis/deprecated-flags-and-options.cpp
index 6fbb3113c829a0..588e27c4839feb 100644
--- a/clang/test/Analysis/deprecated-flags-and-options.cpp
+++ b/clang/test/Analysis/deprecated-flags-and-options.cpp
@@ -1,6 +1,3 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core %s 2>&1 \
-// RUN: | FileCheck %s --check-prefixes=CHECK
-
// RUN: not %clang_analyze_cc1 -analyzer-checker=core -analyzer-store=region %s 2>&1 \
// RUN: | FileCheck %s --check-prefixes=DEPRECATED-STORE
// DEPRECATED-STORE: error: unknown argument: '-analyzer-store=region'
@@ -9,16 +6,9 @@
// RUN: | FileCheck %s --check-prefixes=DEPRECATED-NESTED-BLOCKS
// DEPRECATED-NESTED-BLOCKS: error: unknown argument: '-analyzer-opt-analyze-nested-blocks'
-// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-config consider-single-element-arrays-as-flexible-array-members=true %s 2>&1 \
-// RUN: | FileCheck %s --check-prefixes=CHECK,DEPRECATED-SINGLE-ELEM-FAM
-// DEPRECATED-SINGLE-ELEM-FAM: warning: analyzer option 'consider-single-element-arrays-as-flexible-array-members' is deprecated. This flag will be removed in clang-17, and passing this option will be an error. Use '-fstrict-flex-arrays=<N>' instead.
+// RUN: not %clang_analyze_cc1 -analyzer-checker=core -analyzer-config consider-single-element-arrays-as-flexible-array-members=true %s 2>&1 \
+// RUN: | FileCheck %s --check-prefixes=DEPRECATED-SINGLE-ELEM-FAM
+// DEPRECATED-SINGLE-ELEM-FAM: error: unknown analyzer-config 'consider-single-element-arrays-as-flexible-array-members'
-// RUN: %clang_analyze_cc1 -analyzer-config-help 2>&1 \
-// RUN: | FileCheck %s --check-prefixes=CHECK-HELP
-// CHECK-HELP: [DEPRECATED, removing in clang-17; use '-fstrict-flex-arrays=<N>'
-// CHECK-HELP-NEXT: instead] (default: true)
-int empty(int x) {
- // CHECK: warning: Division by zero
- return x ? 0 : 0 / x;
-}
+void empty() {}
More information about the cfe-commits
mailing list