Skip to content

[CIR] Fix parsing of a generic TBAAAttr #1846

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Jezurko
Copy link
Contributor

@Jezurko Jezurko commented Aug 21, 2025

This PR fixes an issue when parsing TBAAAttr derived attributes.
The root cause of the issue is that the RTTI system is not capable of downcasting mlir::Attribute to the BaseType, which is cir::TBAAAttr, since each attribute has its unique TypeID. As such, the default generated parser fails, because the dyn_cast to cir::TBAAAttr fails (this happens for example with the attached test case).
If anyone can think of a solution that wouldn't require explicitly listing all the attributes I'm happy to modify it.

Copy link

github-actions bot commented Aug 21, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@bcardosolopes
Copy link
Member

If anyone can think of a solution that wouldn't require explicitly listing all the attributes I'm happy to modify it.

I'm not sure I do, maybe @xlauko knows some tricks

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

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

LGTM after nits

@Jezurko
Copy link
Contributor Author

Jezurko commented Aug 21, 2025

We've had a side-channel discussion with @xlauko and I reworked the solution.
I also reworked the tests as requested

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

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

This looks much nicer, thanks for the extra here. Few minor tweaks pending and LGTM

@@ -14,6 +14,7 @@
#define CLANG_CIR_DIALECT_IR_CIRTBAAATTRS_TD

include "clang/CIR/Dialect/IR/CIRTypes.td"
include "clang/CIR/Dialect/IR/CIRAttrs.td"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is cyclic dependency CIRAttrs.td include CIRTBAAAttrs.td

Copy link
Contributor Author

@Jezurko Jezurko Aug 22, 2025

Choose a reason for hiding this comment

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

Hm, I guess I will have to move CIR_Attr to a different file then. I need this include to be able to generate the hpp/cpp for the constraint from CIR_AnyTBAAAttr

Comment on lines +30 to +33
def CIR_TBAAAttrConstraint : AttrConstraint<CPred<"::cir::isTBAAAttr($_self)">>{
string cppType = "::mlir::Attribute";
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is literally the same as CIR_AnyTBAAAttr. Why don't you use that everywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the constraint is used in the definition of the TBAA Attributes and I can't define the CIR_AnyTBAAAttr before the attributes are defined

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.

3 participants