| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,4 @@ | |||
| 1 | + --- | ||
| 2 | + category: minorAnalysis | ||
| 3 | + --- | ||
| 4 | + * Implemented support for data flow through trait functions. For the purpose of data flow, calls to trait functions dispatch to all possible implementations. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -404,10 +404,20 @@ module RustDataFlow implements InputSig<Location> { | |||
| 404 | 404 | ||
| 405 | 405 | /** Gets a viable implementation of the target of the given `Call`. */ | |
| 406 | 406 | DataFlowCallable viableCallable(DataFlowCall call) { | |
| 407 | - exists(Callable target | target = call.asCallCfgNode().getCall().getStaticTarget() | | ||
| 408 | - target = result.asCfgScope() | ||
| 407 | + exists(Call c | c = call.asCallCfgNode().getCall() | | ||
| 408 | + result.asCfgScope() = c.getARuntimeTarget() | ||
| 409 | 409 | or | |
| 410 | - target = result.asSummarizedCallable() | ||
| 410 | + exists(SummarizedCallable sc, Function staticTarget | | ||
| 411 | + staticTarget = c.getStaticTarget() and | ||
| 412 | + sc = result.asSummarizedCallable() | ||
| 413 | + | | ||
| 414 | + sc = staticTarget | ||
| 415 | + or | ||
| 416 | + // only apply trait models to concrete implementations when they are not | ||
| 417 | + // defined in source code | ||
| 418 | + staticTarget.implements(sc) and | ||
| 419 | + not staticTarget.fromSource() | ||
| 420 | + ) | ||
| 411 | 421 | ) | |
| 412 | 422 | } | |
| 413 | 423 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,6 +32,8 @@ | |||
| 32 | 32 | * - `Field[t(i)]`: position `i` inside the variant/struct with canonical path `v`, for example | |
| 33 | 33 | * `Field[core::option::Option::Some(0)]`. | |
| 34 | 34 | * - `Field[i]`: the `i`th element of a tuple. | |
| 35 | + * - `Reference`: the referenced value. | ||
| 36 | + * - `Future`: the value being computed asynchronously. | ||
| 35 | 37 | * 3. The `kind` column is a tag that can be referenced from QL to determine to | |
| 36 | 38 | * which classes the interpreted elements should be added. For example, for | |
| 37 | 39 | * sources `"remote"` indicates a default remote flow source, and for summaries | |
@@ -211,6 +213,10 @@ private class SummarizedCallableFromModel extends SummarizedCallable::Range { | |||
| 211 | 213 | this.getCanonicalPath() = path | |
| 212 | 214 | } | |
| 213 | 215 | ||
| 216 | + override predicate hasProvenance(Provenance provenance) { | ||
| 217 | + summaryModel(path, _, _, _, provenance, _) | ||
| 218 | + } | ||
| 219 | + | ||
| 214 | 220 | override predicate propagatesFlow( | |
| 215 | 221 | string input, string output, boolean preservesValue, string model | |
| 216 | 222 | ) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,3 @@ | |||
| 1 | - // generated by codegen, remove this comment if you wish to edit this file | ||
| 2 | 1 | /** | |
| 3 | 2 | * This module provides a hand-modifiable wrapper around the generated class `AssocItem`. | |
| 4 | 3 | * | |
@@ -12,6 +11,10 @@ private import codeql.rust.elements.internal.generated.AssocItem | |||
| 12 | 11 | * be referenced directly. | |
| 13 | 12 | */ | |
| 14 | 13 | module Impl { | |
| 14 | + private import rust | ||
| 15 | + private import codeql.rust.internal.PathResolution | ||
| 16 | + | ||
| 17 | + // the following QLdoc is generated: if you need to edit it, do it in the schema file | ||
| 15 | 18 | /** | |
| 16 | 19 | * An associated item in a `Trait` or `Impl`. | |
| 17 | 20 | * | |
@@ -21,5 +24,15 @@ module Impl { | |||
| 21 | 24 | * // ^^^^^^^^^^^^^ | |
| 22 | 25 | * ``` | |
| 23 | 26 | */ | |
| 24 | - class AssocItem extends Generated::AssocItem { } | ||
| 27 | + class AssocItem extends Generated::AssocItem { | ||
| 28 | + /** Holds if this item implements trait item `other`. */ | ||
| 29 | + pragma[nomagic] | ||
| 30 | + predicate implements(AssocItem other) { | ||
| 31 | + exists(TraitItemNode t, ImplItemNode i, string name | | ||
| 32 | + other = t.getAssocItem(pragma[only_bind_into](name)) and | ||
| 33 | + t = i.resolveTraitTy() and | ||
| 34 | + this = i.getAssocItem(pragma[only_bind_into](name)) | ||
| 35 | + ) | ||
| 36 | + } | ||
| 37 | + } | ||
| 25 | 38 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -65,6 +65,17 @@ module Impl { | |||
| 65 | 65 | not exists(TypeInference::resolveMethodCallTarget(this)) and | |
| 66 | 66 | result = this.(CallExpr).getStaticTarget() | |
| 67 | 67 | } | |
| 68 | + | ||
| 69 | + /** Gets a runtime target of this call, if any. */ | ||
| 70 | + pragma[nomagic] | ||
| 71 | + Function getARuntimeTarget() { | ||
| 72 | + result.hasImplementation() and | ||
| 73 | + ( | ||
| 74 | + result = this.getStaticTarget() | ||
| 75 | + or | ||
| 76 | + result.implements(this.getStaticTarget()) | ||
| 77 | + ) | ||
| 78 | + } | ||
| 68 | 79 | } | |
| 69 | 80 | ||
| 70 | 81 | /** Holds if the call expression dispatches to a trait method. */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -540,6 +540,13 @@ abstract class ImplOrTraitItemNode extends ItemNode { | |||
| 540 | 540 | /** Gets an associated item belonging to this trait or `impl` block. */ | |
| 541 | 541 | abstract AssocItemNode getAnAssocItem(); | |
| 542 | 542 | ||
| 543 | + /** Gets the associated item named `name` belonging to this trait or `impl` block. */ | ||
| 544 | + pragma[nomagic] | ||
| 545 | + AssocItemNode getAssocItem(string name) { | ||
| 546 | + result = this.getAnAssocItem() and | ||
| 547 | + result.getName() = name | ||
| 548 | + } | ||
| 549 | + | ||
| 543 | 550 | /** Holds if this trait or `impl` block declares an associated item named `name`. */ | |
| 544 | 551 | pragma[nomagic] | |
| 545 | 552 | predicate hasAssocItem(string name) { name = this.getAnAssocItem().getName() } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,2 +1,2 @@ | |||
| 1 | 1 | multipleCallTargets | |
| 2 | - | main.rs:225:14:225:29 | ...::deref(...) | | ||
| 2 | + | main.rs:272:14:272:29 | ...::deref(...) | | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments