-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Clang][RFC] Resugar attributed type alias #143143
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
Draft
zyn0217
wants to merge
2
commits into
llvm:main
Choose a base branch
from
zyn0217:resugar-attributed-type-alias
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// RUN: %clang_cc1 -fsyntax-only -verify %s | ||
|
||
namespace GH142608 { | ||
|
||
typedef void (*report_fn)(const char *err); | ||
|
||
void die_builtin(const char *err); | ||
|
||
__attribute__((noreturn)) | ||
report_fn die_routine; | ||
|
||
template <class T> | ||
void foo(T, typename T::size = 0); // #foo | ||
|
||
void bar() { | ||
foo<__attribute__((noreturn)) report_fn>(die_routine); | ||
// expected-error@-1 {{no matching function}} | ||
// expected-note@#foo {{substitution failure [with T = report_fn]: type 'report_fn' (aka 'void (*)(const char *) __attribute__((noreturn))')}} | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise, passing that second 'Underlying' argument would be unnecessary.
The reason we have that second parameter is to support a feature called 'divergent typedefs', which was added a couple of years ago in order to make resugaring more efficient.
This is currently used by the getCommonSugaredType infrastructure as well.
But yeah, this allows you to invent a different underlying type for a TypedefType, without having to create a fake TypedefDecl for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No? There's an assert in that function:
assert(hasSameType(Decl->getUnderlyingType(), Underlying));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's has same type, not identical types. Are we not just modifying the type sugar here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The context of this resugar is to find the FunctionType and add an attribute (by creating a new function type) on it.
The resugarer tries to add back anything it gets rid of, like the TypedefType in this case.
Or do you know if there's other way around to avoid copying the function type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but the new function type is still the same as the original one, it's just not identical (different sugar).
If that's the case, that's still under contract with getTypedefType.
If that's not the case, I think it would be possible to remove that assert, you just need to investigate and deal with the consequences elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I'll take a look
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In both cases, either divergent typedef or creating a new decl, if the types are not the same, you have to deal with these consequences.
For example, getCommonSugaredType expects all TypedefTypes of the same typedef declaration to be the same type.