#
1f8ae9d7 |
| 27-Jul-2022 |
Weverything <rtrieu@google.com> |
Inline function calls.
Fix unused variable in non-assert builds after 300fbf56f89aebbe2ef9ed490066bab23e5356d1
|
#
300fbf56 |
| 26-Jul-2022 |
Sam Estep <sam@samestep.com> |
[clang][dataflow] Analyze calls to in-TU functions
This patch adds initial support for context-sensitive analysis of simple functions whose definition is available in the translation unit, guarded b
[clang][dataflow] Analyze calls to in-TU functions
This patch adds initial support for context-sensitive analysis of simple functions whose definition is available in the translation unit, guarded by the `ContextSensitive` flag in the new `TransferOptions` struct. When this option is true, the `VisitCallExpr` case in the builtin transfer function has a fallthrough case which checks for a direct callee with a body. In that case, it constructs a CFG from that callee body, uses the new `pushCall` method on the `Environment` to make an environment to analyze the callee, and then calls `runDataflowAnalysis` with a `NoopAnalysis` (disabling context-sensitive analysis on that sub-analysis, to avoid problems with recursion). After the sub-analysis completes, the `Environment` from its exit block is simply assigned back to the environment at the callsite.
The `pushCall` method (which currently only supports non-method functions with some restrictions) maps the `SourceLocation`s for all the parameters to the existing source locations for the corresponding arguments from the callsite.
This patch adds a few tests to check that this context-sensitive analysis works on simple functions. More sophisticated functionality will be added later; the most important next step is to explicitly model context in some fields of the `DataflowAnalysisContext` class, as mentioned in a `FIXME` comment in the `pushCall` implementation.
Reviewed By: ymandel, xazax.hun
Differential Revision: https://reviews.llvm.org/D130306
show more ...
|
#
cc9aa157 |
| 26-Jul-2022 |
Sam Estep <sam@samestep.com> |
Revert "[clang][dataflow] Analyze calls to in-TU functions"
This reverts commit fa2b83d07ecab3b24b4c5ee2e7dc4b6bbc895317.
|
#
fa2b83d0 |
| 26-Jul-2022 |
Sam Estep <sam@samestep.com> |
[clang][dataflow] Analyze calls to in-TU functions
Depends On D130305
This patch adds initial support for context-sensitive analysis of simple functions whose definition is available in the transla
[clang][dataflow] Analyze calls to in-TU functions
Depends On D130305
This patch adds initial support for context-sensitive analysis of simple functions whose definition is available in the translation unit, guarded by the `ContextSensitive` flag in the new `TransferOptions` struct. When this option is true, the `VisitCallExpr` case in the builtin transfer function has a fallthrough case which checks for a direct callee with a body. In that case, it constructs a CFG from that callee body, uses the new `pushCall` method on the `Environment` to make an environment to analyze the callee, and then calls `runDataflowAnalysis` with a `NoopAnalysis` (disabling context-sensitive analysis on that sub-analysis, to avoid problems with recursion). After the sub-analysis completes, the `Environment` from its exit block is simply assigned back to the environment at the callsite.
The `pushCall` method (which currently only supports non-method functions with some restrictions) first calls `initGlobalVars`, then maps the `SourceLocation`s for all the parameters to the existing source locations for the corresponding arguments from the callsite.
This patch adds a few tests to check that this context-sensitive analysis works on simple functions. More sophisticated functionality will be added later; the most important next step is to explicitly model context in some fields of the `DataflowAnalysisContext` class, as mentioned in a `TODO` comment in the `pushCall` implementation.
Reviewed By: ymandel, xazax.hun
Differential Revision: https://reviews.llvm.org/D130306
show more ...
|
#
c0c9d717 |
| 25-Jul-2022 |
Dmitri Gribenko <gribozavr@gmail.com> |
[clang][dataflow] Rename iterators from IT to It
The latter way to abbreviate is a lot more common in the LLVM codebase.
Reviewed By: sgatev, xazax.hun
Differential Revision: https://reviews.llvm.
[clang][dataflow] Rename iterators from IT to It
The latter way to abbreviate is a lot more common in the LLVM codebase.
Reviewed By: sgatev, xazax.hun
Differential Revision: https://reviews.llvm.org/D130423
show more ...
|
#
b5414b56 |
| 22-Jul-2022 |
Dmitri Gribenko <gribozavr@gmail.com> |
[clang][dataflow] Add DataflowEnvironment::dump()
Start by dumping the flow condition.
Reviewed By: ymandel
Differential Revision: https://reviews.llvm.org/D130398
|
#
b611376e |
| 27-Jun-2022 |
Wei Yi Tee <wyt@google.com> |
[clang][dataflow] Singleton pointer values for null pointers.
When a `nullptr` is assigned to a pointer variable, it is wrapped in a `ImplicitCastExpr` with cast kind `CK_NullTo(Member)Pointer`. Thi
[clang][dataflow] Singleton pointer values for null pointers.
When a `nullptr` is assigned to a pointer variable, it is wrapped in a `ImplicitCastExpr` with cast kind `CK_NullTo(Member)Pointer`. This patch assigns singleton pointer values representing null to these expressions.
For each pointee type, a singleton null `PointerValue` is created and stored in the `NullPointerVals` map of the `DataflowAnalysisContext` class. The pointee type is retrieved from the implicit cast expression, and used to initialise the `PointeeLoc` field of the `PointerValue`. The `PointeeLoc` created is not mapped to any `Value`, reflecting the absence of value indicated by null pointers.
Reviewed By: gribozavr2, sgatev, xazax.hun
Differential Revision: https://reviews.llvm.org/D128056
show more ...
|
#
12c7352f |
| 27-Jun-2022 |
Wei Yi Tee <wyt@google.com> |
[clang][dataflow] Move logic for `createStorageLocation` from `DataflowEnvironment` to `DataflowAnalysisContext`.
`createStorageLocation` in `DataflowEnvironment` is now a trivial wrapper around the
[clang][dataflow] Move logic for `createStorageLocation` from `DataflowEnvironment` to `DataflowAnalysisContext`.
`createStorageLocation` in `DataflowEnvironment` is now a trivial wrapper around the logic in `DataflowAnalysisContext`. Additionally, `getObjectFields` and `getFieldsFromClassHierarchy` (required for the implementation of `createStorageLocation`) are also moved to `DataflowAnalysisContext`.
Reviewed By: gribozavr2, sgatev
Differential Revision: https://reviews.llvm.org/D128359
show more ...
|
#
e363c596 |
| 20-Jun-2022 |
Stanislav Gatev <sgatev@google.com> |
[clang][dataflow] Extend flow condition in the body of a do/while loop
Extend flow condition in the body of a do/while loop.
Differential Revision: https://reviews.llvm.org/D128183
Reviewed-by: gr
[clang][dataflow] Extend flow condition in the body of a do/while loop
Extend flow condition in the body of a do/while loop.
Differential Revision: https://reviews.llvm.org/D128183
Reviewed-by: gribozavr2, xazax.hun
show more ...
|
#
80c12bdb |
| 18-Jun-2022 |
Kazu Hirata <kazu@google.com> |
[clang] Call *set::insert without checking membership first (NFC)
|
#
97d69cda |
| 14-Jun-2022 |
Wei Yi Tee <wyt@google.com> |
[clang][dataflow] Rename `getPointeeLoc` to `getReferentLoc` for ReferenceValue.
We distinguish between the referent location for `ReferenceValue` and pointee location for `PointerValue`. The former
[clang][dataflow] Rename `getPointeeLoc` to `getReferentLoc` for ReferenceValue.
We distinguish between the referent location for `ReferenceValue` and pointee location for `PointerValue`. The former must be non-empty but the latter may be empty in the case of a `nullptr`
Reviewed By: gribozavr2, sgatev
Differential Revision: https://reviews.llvm.org/D127745
show more ...
|
#
a1b2b7d9 |
| 08-Jun-2022 |
Wei Yi Tee <wyt@google.com> |
[clang][dataflow] Remove IndirectionValue class, moving PointeeLoc field into PointerValue and ReferenceValue
This patch precedes a future patch to make PointeeLoc for PointerValue possibly empty (f
[clang][dataflow] Remove IndirectionValue class, moving PointeeLoc field into PointerValue and ReferenceValue
This patch precedes a future patch to make PointeeLoc for PointerValue possibly empty (for nullptr), by using a pointer instead of a reference type. ReferenceValue should maintain a non-empty PointeeLoc reference.
Reviewed By: gribozavr2
Differential Revision: https://reviews.llvm.org/D127312
show more ...
|
#
67136d0e |
| 25-May-2022 |
Yitzhak Mandelbaum <yitzhakm@google.com> |
[clang][dataflow] Remove private-field filtering from `StorageLocation` creation.
The API for `AggregateStorageLocation` does not allow for missing fields (it asserts). Therefore, it is incorrect to
[clang][dataflow] Remove private-field filtering from `StorageLocation` creation.
The API for `AggregateStorageLocation` does not allow for missing fields (it asserts). Therefore, it is incorrect to filter out any fields at location-creation time which may be accessed by the code. Currently, we limit filtering to private, base-calss fields on the assumption that those can never be accessed. However, `friend` declarations can invalidate that assumption, thereby breaking our invariants.
This patch removes said field filtering to avoid violating the invariant of "no missing fields" for `AggregateStorageLocation`.
Differential Revision: https://reviews.llvm.org/D126420
show more ...
|
#
5520c583 |
| 25-May-2022 |
Eric Li <li.zhe.hua@gmail.com> |
[clang][dataflow] Fix incorrect CXXThisExpr pointee for lambdas
When constructing the `Environment`, the `this` pointee is established for a `CXXMethodDecl` by looking at its parent. However, inside
[clang][dataflow] Fix incorrect CXXThisExpr pointee for lambdas
When constructing the `Environment`, the `this` pointee is established for a `CXXMethodDecl` by looking at its parent. However, inside of lambdas, a `CXXThisExpr` refers to the captured `this` coming from the enclosing member function.
When establishing the `this` pointee for a function, we check whether the function is a lambda, and check for an enclosing member function to establish the `this` pointee storage location.
Differential Revision: https://reviews.llvm.org/D126413
show more ...
|
#
2f93bbb9 |
| 24-May-2022 |
Yitzhak Mandelbaum <yitzhakm@google.com> |
[clang][dataflow] Relax `Environment` comparison operation.
Ignore `MemberLocToStruct` in environment comparison. As an ancillary data structure, including it is redundant. We also can generate envi
[clang][dataflow] Relax `Environment` comparison operation.
Ignore `MemberLocToStruct` in environment comparison. As an ancillary data structure, including it is redundant. We also can generate environments which differ in their `MemberLocToStruct` but are otherwise equivalent.
Differential Revision: https://reviews.llvm.org/D126314
show more ...
|
#
45643cfc |
| 04-May-2022 |
Eric Li <li.zhe.hua@gmail.com> |
[clang][dataflow] Centralize expression skipping logic
A follow-up to 62b2a47 to centralize the logic that skips expressions that the CFG does not emit. This allows client code to avoid sprinkling t
[clang][dataflow] Centralize expression skipping logic
A follow-up to 62b2a47 to centralize the logic that skips expressions that the CFG does not emit. This allows client code to avoid sprinkling this logic everywhere.
Add redirects in the transfer function to similarly skip such expressions by forwarding the visit to the sub-expression.
Differential Revision: https://reviews.llvm.org/D124965
show more ...
|
#
62b2a47a |
| 02-May-2022 |
Eric Li <li.zhe.hua@gmail.com> |
[clang][dataflow] Only skip ExprWithCleanups when visiting terminators
`IgnoreParenImpCasts` will remove implicit casts to bool (e.g. `PointerToBoolean`), such that the resulting expression may not
[clang][dataflow] Only skip ExprWithCleanups when visiting terminators
`IgnoreParenImpCasts` will remove implicit casts to bool (e.g. `PointerToBoolean`), such that the resulting expression may not be of the `bool` type. The `cast_or_null<BoolValue>` in `extendFlowCondition` will then trigger an assert, as the pointer expression will not have a `BoolValue`.
Instead, we only skip `ExprWithCleanups` and `ParenExpr` nodes, as the CFG does not emit them.
Differential Revision: https://reviews.llvm.org/D124807
show more ...
|
#
955a05a2 |
| 25-Apr-2022 |
Stanislav Gatev <sgatev@google.com> |
[clang][dataflow] Optimize flow condition representation
Enable efficient implementation of context-aware joining of distinct boolean values. It can be used to join distinct boolean values while pre
[clang][dataflow] Optimize flow condition representation
Enable efficient implementation of context-aware joining of distinct boolean values. It can be used to join distinct boolean values while preserving flow condition information.
Flow conditions are represented as Token <=> Clause iff formulas. To perform context-aware joining, one can simply add the tokens of flow conditions to the formula when joining distinct boolean values, e.g: `makeOr(makeAnd(FC1, Val1), makeAnd(FC2, Val2))`. This significantly simplifies the implementation of `Environment::join`.
This patch removes the `DataflowAnalysisContext::getSolver` method. The `DataflowAnalysisContext::flowConditionImplies` method should be used instead.
Reviewed-by: ymandel, xazax.hun
Differential Revision: https://reviews.llvm.org/D124395
show more ...
|
#
6c81b572 |
| 27-Apr-2022 |
Yitzhak Mandelbaum <yitzhakm@google.com> |
[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
[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
show more ...
|
#
37b4782e |
| 14-Apr-2022 |
Yitzhak Mandelbaum <yitzhakm@google.com> |
[clang][dataflow] Fix `Environment::join`'s handling of flow-condition merging.
The current implementation mutates the environment as it performs the join. However, that interferes with the call to
[clang][dataflow] Fix `Environment::join`'s handling of flow-condition merging.
The current implementation mutates the environment as it performs the join. However, that interferes with the call to the model's `merge` operation, which can modify `MergedEnv`. Since any modifications are assumed to apply to the post-join environment, providing the same environment for both is incorrect. This mismatch is a particular concern for joining the flow conditions, where modifications in the old environment may not be propagated to the new one.
Differential Revision: https://reviews.llvm.org/D124104
show more ...
|
#
cfb81690 |
| 20-Apr-2022 |
Nathan James <n.james93@hotmail.co.uk> |
[clang] Add a raw_ostream operator<< overload for QualType
Under the hood this prints the same as `QualType::getAsString()` but cuts out the middle-man when that string is sent to another raw_ostrea
[clang] Add a raw_ostream operator<< overload for QualType
Under the hood this prints the same as `QualType::getAsString()` but cuts out the middle-man when that string is sent to another raw_ostream.
Also cleaned up all the call sites where this occurs.
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D123926
show more ...
|
#
bbcf11f5 |
| 05-Apr-2022 |
Yitzhak Mandelbaum <yitzhakm@google.com> |
[clang][dataflow] Weaken abstract comparison to enable loop termination.
Currently, when the framework is used with an analysis that does not override `compareEquivalent`, it does not terminate for
[clang][dataflow] Weaken abstract comparison to enable loop termination.
Currently, when the framework is used with an analysis that does not override `compareEquivalent`, it does not terminate for most loops. The root cause is the interaction of (the default implementation of) environment comparison (`compareEquivalent`) and the means by which locations and values are allocated. Specifically, the creation of certain values (including: reference and pointer values; merged values) results in allocations of fresh locations in the environment. As a result, analysis of even trivial loop bodies produces different (if isomorphic) environments, on identical inputs. At the same time, the default analysis relies on strict equality (versus some relaxed notion of equivalence). Together, when the analysis compares these isomorphic, yet unequal, environments, to determine whether the successors of the given block need to be (re)processed, the result is invariably "yes", thus preventing loop analysis from reaching a fixed point.
There are many possible solutions to this problem, including equivalence that is less than strict pointer equality (like structural equivalence) and/or the introduction of an explicit widening operation. However, these solutions will require care to be implemented correctly. While a high priority, it seems more urgent that we fix the current default implentation to allow termination. Therefore, this patch proposes, essentially, to change the default comparison to trivally equate any two values. As a result, we can say precisely that the analysis will process the loop exactly twice -- once to establish an initial result state and the second to produce an updated result which will (always) compare equal to the previous. While clearly unsound -- we are not reaching a fix point of the transfer function, in practice, this level of analysis will find many practical issues where a single iteration of the loop impacts abstract program state.
Note, however, that the change to the default `merge` operation does not affect soundness, because the framework already produces a fresh (sound) abstraction of the value when the two values are distinct. The previous setting was overly conservative.
Differential Revision: https://reviews.llvm.org/D123586
show more ...
|
#
01db1036 |
| 28-Mar-2022 |
Yitzhak Mandelbaum <yitzhakm@google.com> |
[clang][dataflow] Add support for correlation of boolean (tracked) values
This patch extends the join logic for environments to explicitly handle boolean values. It creates the disjunction of both s
[clang][dataflow] Add support for correlation of boolean (tracked) values
This patch extends the join logic for environments to explicitly handle boolean values. It creates the disjunction of both source values, guarded by the respective flow conditions from each input environment. This change allows the framework to reason about boolean correlations across multiple branches (and subsequent joins).
Differential Revision: https://reviews.llvm.org/D122838
show more ...
|
#
36d4e844 |
| 23-Mar-2022 |
Yitzhak Mandelbaum <yitzhakm@google.com> |
[clang][dataflow] Fix handling of base-class fields.
Currently, the framework does not track derived class access to base fields. This patch adds that support and a corresponding test.
Differential
[clang][dataflow] Fix handling of base-class fields.
Currently, the framework does not track derived class access to base fields. This patch adds that support and a corresponding test.
Differential Revision: https://reviews.llvm.org/D122273
show more ...
|
#
b000b770 |
| 16-Mar-2022 |
Stanislav Gatev <sgatev@google.com> |
[clang][dataflow] Model the behavior of non-standard optional assignment
Model nullopt, value, and conversion assignment operators.
Reviewed-by: xazax.hun
Differential Revision: https://reviews.ll
[clang][dataflow] Model the behavior of non-standard optional assignment
Model nullopt, value, and conversion assignment operators.
Reviewed-by: xazax.hun
Differential Revision: https://reviews.llvm.org/D121863
show more ...
|