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

FunctionDepsFinder: Check for declarations inside another declaration #46

Merged
merged 1 commit into from
Jun 14, 2024

Conversation

marcosps
Copy link
Collaborator

Closes: #44

* Check if the same Decl was already added into the closure but for a
* different typename.
*/
TypedefDecl *insideRangeOfDecl(TypedefDecl *decl)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use Decl and not only TypedefDecl.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There were some complaints from the compiler when I was using Decl, so I used the more specialized type. I'll check it tomorrow.

{
SourceRange range = decl->getSourceRange();

for (auto it = Dependencies.begin(); it != Dependencies.end(); ++it) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This algorithm is O(n ²). If the closure is small, I think this is acceptable, but if we want to do this extensively we may be in a better shape to sort by SourceLocation something to reduce it to O(n log n).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The idea in this case was to submit the solution to check with our CI. Also, for my current LP, it worked.

I'll think how this could be improved.

if (cur_range == range)
continue;

if (cur_range.getBegin() == range.getBegin() &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can use Contains_From_LineCol and get the Decl with larger Range.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Cool, I'll use it

SourceRange range = decl->getSourceRange();

for (auto it = Dependencies.begin(); it != Dependencies.end(); ++it) {
if (TypedefDecl *cur_decl = dynamic_cast<TypedefDecl *>(*it)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please avoid using dynamic_cast<type*> and use dyn_cast. This works on clang builds with RTTI disabled.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just copied this line from the FunctionDepsFinder :P

Thanks for the suggestion

@marcosps
Copy link
Collaborator Author

So I addressed all your comments besides the algorithm. Also, I added a testcase, which was simple to craft. Tomorrow I plans to rethink the algorithm so we can have this merged.

@giulianobelinassi giulianobelinassi merged commit 0925bdb into SUSE:main Jun 14, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error on ClosurePass: typedef redefinition with different types
2 participants