[LifetimeSafety] Add language option for experimental lifetime safety (#149592)
Add a language option flag for experimental lifetime safety analysis in C++. This change provides a language option to control the experimental lifetime safety analysis feature, making it more explicit and easier to enable/disable. Previously, the feature was controlled indirectly through a diagnostic warning flag, which we do not want to accidentally enable with `-Weverything` (atm)! ### Changes: - Added a new language option `EnableLifetimeSafety` in `LangOptions.def` for experimental lifetime safety analysis in C++ - Added corresponding driver options `-fexperimental-lifetime-safety` and `-fno-experimental-lifetime-safety` in `Options.td` - Modified `AnalysisBasedWarnings.cpp` to use the new language option flag instead of checking if a specific diagnostic is ignored - Updated a test case to use the new flag instead of relying on the warning flag alone
This commit is contained in:
parent
abdd654feb
commit
0d04789034
@ -491,6 +491,8 @@ LANGOPT(CheckConstexprFunctionBodies, 1, 1, Benign,
|
||||
|
||||
LANGOPT(BoundsSafety, 1, 0, NotCompatible, "Bounds safety extension for C")
|
||||
|
||||
LANGOPT(EnableLifetimeSafety, 1, 0, NotCompatible, "Experimental lifetime safety analysis for C++")
|
||||
|
||||
LANGOPT(PreserveVec3Type, 1, 0, NotCompatible, "Preserve 3-component vector type")
|
||||
|
||||
#undef LANGOPT
|
||||
|
@ -1904,6 +1904,14 @@ defm bounds_safety : BoolFOption<
|
||||
BothFlags<[], [CC1Option],
|
||||
" experimental bounds safety extension for C">>;
|
||||
|
||||
defm lifetime_safety : BoolFOption<
|
||||
"experimental-lifetime-safety",
|
||||
LangOpts<"EnableLifetimeSafety">, DefaultFalse,
|
||||
PosFlag<SetTrue, [], [CC1Option], "Enable">,
|
||||
NegFlag<SetFalse, [], [CC1Option], "Disable">,
|
||||
BothFlags<[], [CC1Option],
|
||||
" experimental lifetime safety for C++">>;
|
||||
|
||||
defm addrsig : BoolFOption<"addrsig",
|
||||
CodeGenOpts<"Addrsig">, DefaultFalse,
|
||||
PosFlag<SetTrue, [], [ClangOption, CC1Option], "Emit">,
|
||||
|
@ -2901,8 +2901,7 @@ void clang::sema::AnalysisBasedWarnings::IssueWarnings(
|
||||
.setAlwaysAdd(Stmt::UnaryOperatorClass);
|
||||
}
|
||||
|
||||
bool EnableLifetimeSafetyAnalysis = !Diags.isIgnored(
|
||||
diag::warn_experimental_lifetime_safety_dummy_warning, D->getBeginLoc());
|
||||
bool EnableLifetimeSafetyAnalysis = S.getLangOpts().EnableLifetimeSafety;
|
||||
// Install the logical handler.
|
||||
std::optional<LogicalErrorHandler> LEH;
|
||||
if (LogicalErrorHandler::hasActiveDiagnostics(Diags, D->getBeginLoc())) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
// RUN: %clang_cc1 -mllvm -debug-only=LifetimeFacts -Wexperimental-lifetime-safety %s 2>&1 | FileCheck %s
|
||||
// RUN: %clang_cc1 -fexperimental-lifetime-safety -mllvm -debug-only=LifetimeFacts -Wexperimental-lifetime-safety %s 2>&1 | FileCheck %s
|
||||
// REQUIRES: asserts
|
||||
|
||||
struct MyObj {
|
||||
|
Loading…
x
Reference in New Issue
Block a user