[clang] [clang][dataflow] Merge `RecordValue`s with different locations correctly. (PR #65319)
Kinuko Yasuda via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 5 06:41:55 PDT 2023
================
@@ -121,18 +121,18 @@ static Value *mergeDistinctValues(QualType Type, Value &Val1,
Value *MergedVal = nullptr;
if (auto *RecordVal1 = dyn_cast<RecordValue>(&Val1)) {
- [[maybe_unused]] auto *RecordVal2 = cast<RecordValue>(&Val2);
-
- // Values to be merged are always associated with the same location in
- // `LocToVal`. The location stored in `RecordVal` should therefore also
- // be the same.
- assert(&RecordVal1->getLoc() == &RecordVal2->getLoc());
-
- // `RecordVal1` and `RecordVal2` may have different properties associated
- // with them. Create a new `RecordValue` without any properties so that we
- // soundly approximate both values. If a particular analysis needs to merge
- // properties, it should do so in `DataflowAnalysis::merge()`.
- MergedVal = &MergedEnv.create<RecordValue>(RecordVal1->getLoc());
+ auto *RecordVal2 = cast<RecordValue>(&Val2);
+
+ if (&RecordVal1->getLoc() == &RecordVal2->getLoc())
+ // `RecordVal1` and `RecordVal2` may have different properties associated
+ // with them. Create a new `RecordValue` without any properties so that we
+ // soundly approximate both values. If a particular analysis needs to
+ // merge properties, it should do so in `DataflowAnalysis::merge()`.
+ MergedVal = &MergedEnv.create<RecordValue>(RecordVal1->getLoc());
+ else
+ // If the locations for the two records are different, need to create a
+ // completely new value.
----------------
kinu wrote:
Given that how cryptic when this could happen, it might be helpful to have a brief comment that both could happen depending on a subtle order of CFG and therefore how merge happens.
https://github.com/llvm/llvm-project/pull/65319
More information about the cfe-commits
mailing list