diff options
author | martinboehme <mboehme@google.com> | 2024-03-08 08:19:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-08 08:19:02 +0100 |
commit | 2d539db246fd9d26201255b84d04dacf2782eddf (patch) | |
tree | 522da129e97e6eab5e0b8274c398a548281b03b7 /clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp | |
parent | 23c658ac4183272221ef358575dca0d386096d36 (diff) | |
download | llvm-2d539db246fd9d26201255b84d04dacf2782eddf.zip llvm-2d539db246fd9d26201255b84d04dacf2782eddf.tar.gz llvm-2d539db246fd9d26201255b84d04dacf2782eddf.tar.bz2 |
[clang][dataflow] When analyzing ctors, don't initialize fields of `*this` with values. (#84164)
This is the constructor's job, and we want to be able to test that it
does this.
Diffstat (limited to 'clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp')
-rw-r--r-- | clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp index 62332a1..1d2bd9a 100644 --- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp +++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp @@ -432,8 +432,15 @@ void Environment::initialize() { } } else if (MethodDecl->isImplicitObjectMemberFunction()) { QualType ThisPointeeType = MethodDecl->getFunctionObjectParameterType(); - setThisPointeeStorageLocation( - cast<RecordStorageLocation>(createObject(ThisPointeeType))); + auto &ThisLoc = + cast<RecordStorageLocation>(createStorageLocation(ThisPointeeType)); + setThisPointeeStorageLocation(ThisLoc); + refreshRecordValue(ThisLoc, *this); + // Initialize fields of `*this` with values, but only if we're not + // analyzing a constructor; after all, it's the constructor's job to do + // this (and we want to be able to test that). + if (!isa<CXXConstructorDecl>(MethodDecl)) + initializeFieldsWithValues(ThisLoc); } } } @@ -819,6 +826,16 @@ PointerValue &Environment::getOrCreateNullPointerValue(QualType PointeeType) { return DACtx->getOrCreateNullPointerValue(PointeeType); } +void Environment::initializeFieldsWithValues(RecordStorageLocation &Loc) { + llvm::DenseSet<QualType> Visited; + int CreatedValuesCount = 0; + initializeFieldsWithValues(Loc, Visited, 0, CreatedValuesCount); + if (CreatedValuesCount > MaxCompositeValueSize) { + llvm::errs() << "Attempting to initialize a huge value of type: " + << Loc.getType() << '\n'; + } +} + void Environment::setValue(const StorageLocation &Loc, Value &Val) { assert(!isa<RecordValue>(&Val) || &cast<RecordValue>(&Val)->getLoc() == &Loc); |