Skip to content
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

[FlowSensitive] Allow to dump nested RecordStorageLocation #112457

Conversation

fmayer
Copy link
Contributor

@fmayer fmayer commented Oct 16, 2024

We have an internal analysis that uses them, and the HTML dump would
fail on the assertion.

Created using spr 1.3.4
@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 Oct 16, 2024
@llvmbot
Copy link
Member

llvmbot commented Oct 16, 2024

@llvm/pr-subscribers-clang-analysis

Author: Florian Mayer (fmayer)

Changes

We have an internal analysis that uses them, and the HTML dump would
fail on the assertion.


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

1 Files Affected:

  • (modified) clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp (+1-2)
diff --git a/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp b/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
index a36cb41a63dfb1..557df218837941 100644
--- a/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
+++ b/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
@@ -133,8 +133,7 @@ class ModelDumper {
       for (const auto &Child : RLoc->children())
         JOS.attributeObject("f:" + Child.first->getNameAsString(), [&] {
           if (Child.second)
-            if (Value *Val = Env.getValue(*Child.second))
-              dump(*Val);
+            dump(*Child.second);
         });
 
       for (const auto &SyntheticField : RLoc->synthetic_fields())

@llvmbot
Copy link
Member

llvmbot commented Oct 16, 2024

@llvm/pr-subscribers-clang

Author: Florian Mayer (fmayer)

Changes

We have an internal analysis that uses them, and the HTML dump would
fail on the assertion.


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

1 Files Affected:

  • (modified) clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp (+1-2)
diff --git a/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp b/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
index a36cb41a63dfb1..557df218837941 100644
--- a/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
+++ b/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
@@ -133,8 +133,7 @@ class ModelDumper {
       for (const auto &Child : RLoc->children())
         JOS.attributeObject("f:" + Child.first->getNameAsString(), [&] {
           if (Child.second)
-            if (Value *Val = Env.getValue(*Child.second))
-              dump(*Val);
+            dump(*Child.second);
         });
 
       for (const auto &SyntheticField : RLoc->synthetic_fields())

@fmayer fmayer requested a review from kinu October 16, 2024 00:53
@fmayer
Copy link
Contributor Author

fmayer commented Oct 16, 2024

An example dump that is now possible but crashed before
image

@fmayer fmayer requested a review from ymand October 16, 2024 17:26
Copy link
Collaborator

@ymand ymand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest a brief comment explaining the choice not to filter.

@fmayer
Copy link
Contributor Author

fmayer commented Oct 22, 2024

I would suggest a brief comment explaining the choice not to filter.

I'm not sure I understand. There wasn't a choice to filter before, there was just the (incorrect) assumption that we don't have nested RecordStorageLocation, leading to a crash.

@martinboehme
Copy link
Contributor

I think this is the right change.

What I don't understand, though, is why you were getting an assert failure before. (Which line is the assertion on that failed?) I would have thought if you don't dump the nested record, you just get less information. Apparently not so?

I would suggest a brief comment explaining the choice not to filter.

I'm not sure I understand. There wasn't a choice to filter before, there was just the (incorrect) assumption that we don't have nested RecordStorageLocation, leading to a crash.

@ymand I think maybe what you're missing is that the code is calling a different overload of dump() now? Previously, it called the Value overload, now it's calling the StorageLocation overload. And of course the StorageLocation doesn't care whether there's a value at the location (or rather, it will figure that out itself and dump the value if so).

@fmayer Just as an explanation of why this check is there: I think this isn't because the code assumed that nested RecordStorageLocations don't exist; rather, we used to have a concept of a RecordValue, and when that existed, it made more sense to do this check here. When I eliminated the RecordValue concept, I updated some of the code in ModelDumper but didn't notice that this check now no longer made sense.

@fmayer
Copy link
Contributor Author

fmayer commented Oct 23, 2024

I think this is the right change.

What I don't understand, though, is why you were getting an assert failure before. (Which line is the assertion on that failed?) I would have thought if you don't dump the nested record, you just get less information. Apparently not so?

Because the first line of Env.getValue is

  assert(!isa<RecordStorageLocation>(Loc));

@martinboehme
Copy link
Contributor

I think this is the right change.
What I don't understand, though, is why you were getting an assert failure before. (Which line is the assertion on that failed?) I would have thought if you don't dump the nested record, you just get less information. Apparently not so?

Because the first line of Env.getValue is

  assert(!isa<RecordStorageLocation>(Loc));

Ah, of course, that makes sense. Thanks!

@fmayer fmayer merged commit 564fd62 into main Oct 24, 2024
10 of 12 checks passed
@fmayer fmayer deleted the users/fmayer/spr/flowsensitive-allow-to-dump-nested-recordstoragelocation branch October 24, 2024 18:05
@frobtech frobtech mentioned this pull request Oct 25, 2024
NoumanAmir657 pushed a commit to NoumanAmir657/llvm-project that referenced this pull request Nov 4, 2024
We have an internal analysis that uses them, and the HTML dump would
fail on the assertion.
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