diff options
author | Yitzhak Mandelbaum <yitzhakm@google.com> | 2023-01-03 20:50:01 +0000 |
---|---|---|
committer | Yitzhak Mandelbaum <yitzhakm@google.com> | 2023-01-03 21:57:39 +0000 |
commit | 0086a3555ac6cd76bb637252a0ba17c06c9b869b (patch) | |
tree | 0312dd84ea5254951a39ad32f929a930cedfc62c /clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp | |
parent | d36936fdb462fdda29326a51c2193a3fd10d6807 (diff) | |
download | llvm-0086a3555ac6cd76bb637252a0ba17c06c9b869b.zip llvm-0086a3555ac6cd76bb637252a0ba17c06c9b869b.tar.gz llvm-0086a3555ac6cd76bb637252a0ba17c06c9b869b.tar.bz2 |
[clang][dataflow] Fix bug in optional-checker's handling of nullopt constructor.
Currently, the checker only recognizes the nullopt constructor when it is called
without sugar, resulting in a crash in the (rare) case where it has been wrapped
in sugar. This relaxes the constraint by checking the constructor decl directly
(which always contains the same, desugared form) rather than the construct
expression (where the spelling depends on the context).
Differential Revision: https://reviews.llvm.org/D140921
Diffstat (limited to 'clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp')
-rw-r--r-- | clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp index 07ec16c..10b9866 100644 --- a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp +++ b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp @@ -22,6 +22,7 @@ #include "clang/Analysis/FlowSensitive/CFGMatchSwitch.h" #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h" #include "clang/Analysis/FlowSensitive/NoopLattice.h" +#include "clang/Analysis/FlowSensitive/StorageLocation.h" #include "clang/Analysis/FlowSensitive/Value.h" #include "clang/Basic/SourceLocation.h" #include "llvm/ADT/StringRef.h" @@ -100,8 +101,10 @@ auto inPlaceClass() { } auto isOptionalNulloptConstructor() { - return cxxConstructExpr(hasOptionalType(), argumentCountIs(1), - hasArgument(0, hasNulloptType())); + return cxxConstructExpr( + hasOptionalType(), + hasDeclaration(cxxConstructorDecl(parameterCountIs(1), + hasParameter(0, hasNulloptType())))); } auto isOptionalInPlaceConstructor() { @@ -452,6 +455,7 @@ void assignOptionalValue(const Expr &E, Environment &Env, BoolValue &valueOrConversionHasValue(const FunctionDecl &F, const Expr &E, const MatchFinder::MatchResult &MatchRes, LatticeTransferState &State) { + assert(F.getTemplateSpecializationArgs() != nullptr); assert(F.getTemplateSpecializationArgs()->size() > 0); const int TemplateParamOptionalWrappersCount = countOptionalWrappers( |