Author: Yitzhak Mandelbaum Date: 2022-04-28T17:55:09Z New Revision: 6c81b57237164319b5429ee33957004aa21db2fa
URL: https://github.com/llvm/llvm-project/commit/6c81b57237164319b5429ee33957004aa21db2fa DIFF: https://github.com/llvm/llvm-project/commit/6c81b57237164319b5429ee33957004aa21db2fa.diff LOG: [clang][dataflow] Perform structural comparison of indirection values in `join`. This patch changes `Environment::join`, in the case that two values at the same location are not (pointer) equal, to structurally compare indirection values (pointers and references) for equivalence (that is, equivalent pointees) before resorting to merging. This change makes join consistent with equivalence, which also performs structural comparison. It also fixes a bug where the values are `ReferenceValue` but the merge creates a non-reference value. This case arises when the `ReferenceValue`s were created to represent an lvalue, so the "reference-ness" is not reflected in the type. In this case, the pointees will always be equivalent, because lvalues at the same code location point to the location of a fixed declaration, whose location is itself stable across blocks. We were unable to reproduce a unit test for this latter bug, but have verified the fix in the context of a larger piece of code that triggers the bug. Differential Revision: https://reviews.llvm.org/D124540 Added: Modified: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp Removed: ################################################################################ diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp index 91e07bdb88ce0..68c55b665cc61 100644 --- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp +++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp @@ -21,6 +21,7 @@ #include "clang/Analysis/FlowSensitive/Value.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseSet.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/ErrorHandling.h" #include <cassert> #include <memory> @@ -105,6 +106,15 @@ static Value *mergeDistinctValues(QualType Type, Value *Val1, return &MergedEnv.makeOr(*Expr1, *Expr2); } + // FIXME: add unit tests that cover this statement. + if (auto *IndVal1 = dyn_cast<IndirectionValue>(Val1)) { + auto *IndVal2 = cast<IndirectionValue>(Val2); + assert(IndVal1->getKind() == IndVal2->getKind()); + if (&IndVal1->getPointeeLoc() == &IndVal2->getPointeeLoc()) { + return Val1; + } + } + // FIXME: Consider destroying `MergedValue` immediately if `ValueModel::merge` // returns false to avoid storing unneeded values in `DACtx`. if (Value *MergedVal = MergedEnv.createValue(Type)) _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits