-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[Clang] Fix cleanup attribute by delaying type checks after the type is deduced #164440
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
Changes from all commits
d325155
cb8afb6
a7ac571
45be8ae
a960e4f
b4c6722
5c5e06e
da4d991
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3511,16 +3511,6 @@ static void handleCleanupAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |
| return; | ||
| } | ||
|
|
||
| // We're currently more strict than GCC about what function types we accept. | ||
| // If this ever proves to be a problem it should be easy to fix. | ||
| QualType Ty = S.Context.getPointerType(cast<VarDecl>(D)->getType()); | ||
| QualType ParamTy = FD->getParamDecl(0)->getType(); | ||
| if (!S.IsAssignConvertCompatible(S.CheckAssignmentConstraints( | ||
| FD->getParamDecl(0)->getLocation(), ParamTy, Ty))) { | ||
| S.Diag(Loc, diag::err_attribute_cleanup_func_arg_incompatible_type) | ||
| << NI.getName() << ParamTy << Ty; | ||
| return; | ||
| } | ||
| VarDecl *VD = cast<VarDecl>(D); | ||
| // Create a reference to the variable declaration. This is a fake/dummy | ||
| // reference. | ||
|
|
@@ -8311,3 +8301,28 @@ void Sema::redelayDiagnostics(DelayedDiagnosticPool &pool) { | |
| assert(curPool && "re-emitting in undelayed context not supported"); | ||
| curPool->steal(pool); | ||
| } | ||
|
|
||
| void Sema::ActOnCleanupAttr(Decl *D, const Attr *A) { | ||
| VarDecl *VD = cast<VarDecl>(D); | ||
| if (VD->getType()->isDependentType()) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on my reading of the documentation in Attr.td this seems like it should be an assert on
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well no, if |
||
| return; | ||
|
|
||
| // Obtains the FunctionDecl that was found when handling the attribute | ||
| // earlier. | ||
| CleanupAttr *Attr = D->getAttr<CleanupAttr>(); | ||
| FunctionDecl *FD = Attr->getFunctionDecl(); | ||
| DeclarationNameInfo NI = FD->getNameInfo(); | ||
to268 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // We're currently more strict than GCC about what function types we accept. | ||
| // If this ever proves to be a problem it should be easy to fix. | ||
| QualType Ty = this->Context.getPointerType(VD->getType()); | ||
| QualType ParamTy = FD->getParamDecl(0)->getType(); | ||
| if (!this->IsAssignConvertCompatible(this->CheckAssignmentConstraints( | ||
| FD->getParamDecl(0)->getLocation(), ParamTy, Ty))) { | ||
| this->Diag(Attr->getArgLoc(), | ||
| diag::err_attribute_cleanup_func_arg_incompatible_type) | ||
| << NI.getName() << ParamTy << Ty; | ||
| D->dropAttr<CleanupAttr>(); | ||
| return; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // RUN: %clang_cc1 -std=c23 -fsyntax-only -verify %s | ||
|
|
||
| int open() { return 0; } | ||
| void close(typeof(open()) *) {} | ||
|
|
||
| void cleanup_attr() { | ||
| int fd_int [[gnu::cleanup(close)]] = open(); | ||
| auto fd_auto [[gnu::cleanup(close)]] = open(); | ||
| float fd_invalid [[gnu::cleanup(close)]] = open(); // expected-error {{'cleanup' function 'close' parameter has type 'typeof (open()) *' (aka 'int *') which is incompatible with type 'float *'}} | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.