Skip to content

[clang][dataflow] Expose simple access to child StorageLocation presence. #145520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2025

Conversation

bazuzi
Copy link
Contributor

@bazuzi bazuzi commented Jun 24, 2025

getChild does not offer this knowledge, and a map lookup is significantly cheaper than iteration over children().

…tion is present.

`getChild` does not offer this knowledge, and a map lookup is significantly cheaper than iteration over `children()`.
@bazuzi bazuzi requested a review from martinboehme June 24, 2025 14:36
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:dataflow Clang Dataflow Analysis framework - https://clang.llvm.org/docs/DataFlowAnalysisIntro.html clang:analysis labels Jun 24, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 24, 2025

@llvm/pr-subscribers-clang-analysis

@llvm/pr-subscribers-clang

Author: Samira Bakon (bazuzi)

Changes

getChild does not offer this knowledge, and a map lookup is significantly cheaper than iteration over children().


Full diff: https://github.com/llvm/llvm-project/pull/145520.diff

1 Files Affected:

  • (modified) clang/include/clang/Analysis/FlowSensitive/StorageLocation.h (+2)
diff --git a/clang/include/clang/Analysis/FlowSensitive/StorageLocation.h b/clang/include/clang/Analysis/FlowSensitive/StorageLocation.h
index 8fcc6a44027a0..8b263b16d5b1e 100644
--- a/clang/include/clang/Analysis/FlowSensitive/StorageLocation.h
+++ b/clang/include/clang/Analysis/FlowSensitive/StorageLocation.h
@@ -168,6 +168,8 @@ class RecordStorageLocation final : public StorageLocation {
     return {Children.begin(), Children.end()};
   }
 
+  bool hasChild(const ValueDecl &D) const { return Children.contains(&D); }
+
 private:
   FieldToLoc Children;
   SyntheticFieldMap SyntheticFields;

@bazuzi bazuzi requested a review from jvoung June 24, 2025 14:42
@bazuzi bazuzi merged commit 09b43a5 into llvm:main Jun 24, 2025
11 checks passed
@bazuzi bazuzi deleted the getChild branch June 24, 2025 17:30
DrSergei pushed a commit to DrSergei/llvm-project that referenced this pull request Jun 24, 2025
…nce. (llvm#145520)

`getChild` does not offer this knowledge, and a map lookup is
significantly cheaper than iteration over `children()`.
@martinboehme
Copy link
Contributor

Can you explain what this is intended to be used for? I'd like to make sure we don't have an XY problem here.

Whether a RecordStorageLocation has a given child or not should always be very predictable, as we enforce the constraint that a RecordStorageLocation should always have exactly the fields returned by getModeledFields(). There shouldn't, therefore, ever really be a need to check whether a RecordStorageLocation has a given child -- and I'm worried that maybe you've run into a bug that you're using getChild() to work around, when in fact it would be better to fix the underlying bug.

@bazuzi
Copy link
Contributor Author

bazuzi commented Jun 25, 2025

No underlying bug, but I was able to simplify my approach out-of-tree and avoid exposing this function that doesn't capture the intended semantics.

I'll revert this.

bazuzi added a commit that referenced this pull request Jun 25, 2025
…on presence." (#145710)

Reverts #145520

Exposed function is no longer needed and side-stepped the intended
contract that the present children are the same set returned by
`getModeledFields()` and presence shouldn't need to be queried for
arbitrary fields.
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Jun 25, 2025
…orageLocation presence." (#145710)

Reverts llvm/llvm-project#145520

Exposed function is no longer needed and side-stepped the intended
contract that the present children are the same set returned by
`getModeledFields()` and presence shouldn't need to be queried for
arbitrary fields.
anthonyhatran pushed a commit to anthonyhatran/llvm-project that referenced this pull request Jun 26, 2025
…nce. (llvm#145520)

`getChild` does not offer this knowledge, and a map lookup is
significantly cheaper than iteration over `children()`.
anthonyhatran pushed a commit to anthonyhatran/llvm-project that referenced this pull request Jun 26, 2025
…on presence." (llvm#145710)

Reverts llvm#145520

Exposed function is no longer needed and side-stepped the intended
contract that the present children are the same set returned by
`getModeledFields()` and presence shouldn't need to be queried for
arbitrary fields.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:analysis clang:dataflow Clang Dataflow Analysis framework - https://clang.llvm.org/docs/DataFlowAnalysisIntro.html clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants