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

C++: update tests to pick up destructor changes #15329

Merged
merged 1 commit into from Jan 17, 2024

Conversation

AlexDenisov
Copy link
Contributor

No description provided.

@AlexDenisov AlexDenisov added C++ depends on internal PR This PR should only be merged in sync with an internal Semmle PR labels Jan 15, 2024
@AlexDenisov AlexDenisov force-pushed the alexdenisov/duplicate-destructor-calls branch from d590000 to c83a368 Compare January 16, 2024 07:37
@@ -1,2 +1,3 @@
| exceptions.cpp:25:13:25:19 | ExprStmt |
| exceptions.cpp:26:13:26:13 | ExprStmt |
| ms.cpp:38:1:38:1 | c101 |
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this change?

Copy link
Contributor

Choose a reason for hiding this comment

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

I assume there are now two copies of a destructor call, one reachable one, and one unreachable one, but it's not clear to me what the unreachable one is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question! I'm also wondering why is it considered as a basic block in the first place.

My immediate hypothesis would that the extractor change only uncovers the problem that was not visible before, and not actually causing the problem here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm also wondering why is it considered as a basic block in the first place.

I think the naming of the BasicBlocks might be a bit awkward in some cases, so I would not get too hung up on the name.

My immediate hypothesis would that the extractor change only uncovers the problem that was not visible before, and not actually causing the problem here.

Would it be possible to reduce this to some minimal example where we see this changing, so we can have a closer look? I agree that it probably uncovers a problem that was already there, but I would like to understand what the problem was.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll try to reduce it 🙌

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reduced it manually to the following case:

// semmle-extractor-options: --microsoft
class C {
public:
  ~C();
};

void f() {
  C c;
  __try {
    throw 1;
  }
  __except (1) {}
}

The issue is that we generate 3 destructor calls in this case (and 6 variable accesses, 2 per destructor) and some of these variable accesses (not destructor calls themselves) are marked as unreachable.
Marking these var accesses as children of the surrounding scope fixes the issue, but I'm not sure it's the right solution for all cases.

I think I'll file a separate issue to handle this specific issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the reduced test case!

and 6 variable accesses, 2 per destructor

Why two per destructor? There's probably an obvious reason, but I'm not too familiar with the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why two per destructor?

I think I was wrong, there is just one var access per destructor (accessing the variable being destructed).


I filed an issue internally.

@AlexDenisov AlexDenisov force-pushed the alexdenisov/duplicate-destructor-calls branch from c83a368 to f1049a4 Compare January 17, 2024 11:06
@AlexDenisov AlexDenisov marked this pull request as ready for review January 17, 2024 11:08
@AlexDenisov AlexDenisov requested a review from a team as a code owner January 17, 2024 11:08
@AlexDenisov AlexDenisov merged commit 8610c95 into main Jan 17, 2024
9 of 10 checks passed
@AlexDenisov AlexDenisov deleted the alexdenisov/duplicate-destructor-calls branch January 17, 2024 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ depends on internal PR This PR should only be merged in sync with an internal Semmle PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants