Skip to content

Commit 5436ada

Browse files
author
git apple-llvm automerger
committed
Merge commit '3339a0045d66' from llvm.org/main into next
2 parents 9f87401 + 3339a00 commit 5436ada

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ Bug Fixes to Attribute Support
172172

173173
- ``[[nodiscard]]`` is now respected on Objective-C and Objective-C++ methods.
174174
(#GH141504)
175+
- Using ``[[gnu::cleanup(some_func)]]`` where some_func is annotated with
176+
``[[gnu::error("some error")]]`` now correctly triggers an error. (#GH146520)
175177

176178
Bug Fixes to C++ Support
177179
^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/CodeGen/CGDecl.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -600,10 +600,11 @@ namespace {
600600
llvm::Constant *CleanupFn;
601601
const CGFunctionInfo &FnInfo;
602602
const VarDecl &Var;
603+
const CleanupAttr *Attribute;
603604

604605
CallCleanupFunction(llvm::Constant *CleanupFn, const CGFunctionInfo *Info,
605-
const VarDecl *Var)
606-
: CleanupFn(CleanupFn), FnInfo(*Info), Var(*Var) {}
606+
const VarDecl *Var, const CleanupAttr *Attr)
607+
: CleanupFn(CleanupFn), FnInfo(*Info), Var(*Var), Attribute(Attr) {}
607608

608609
void Emit(CodeGenFunction &CGF, Flags flags) override {
609610
DeclRefExpr DRE(CGF.getContext(), const_cast<VarDecl *>(&Var), false,
@@ -625,8 +626,11 @@ namespace {
625626
CallArgList Args;
626627
Args.add(RValue::get(Arg),
627628
CGF.getContext().getPointerType(Var.getType()));
628-
auto Callee = CGCallee::forDirect(CleanupFn);
629-
CGF.EmitCall(FnInfo, Callee, ReturnValueSlot(), Args);
629+
GlobalDecl GD = GlobalDecl(Attribute->getFunctionDecl());
630+
auto Callee = CGCallee::forDirect(CleanupFn, CGCalleeInfo(GD));
631+
CGF.EmitCall(FnInfo, Callee, ReturnValueSlot(), Args,
632+
/*callOrInvoke*/ nullptr, /*IsMustTail*/ false,
633+
Attribute->getLoc());
630634
}
631635
};
632636
} // end anonymous namespace
@@ -2361,7 +2365,8 @@ void CodeGenFunction::EmitAutoVarCleanups(const AutoVarEmission &emission) {
23612365
assert(F && "Could not find function!");
23622366

23632367
const CGFunctionInfo &Info = CGM.getTypes().arrangeFunctionDeclaration(FD);
2364-
EHStack.pushCleanup<CallCleanupFunction>(NormalAndEHCleanup, F, &Info, &D);
2368+
EHStack.pushCleanup<CallCleanupFunction>(NormalAndEHCleanup, F, &Info, &D,
2369+
CA);
23652370
}
23662371

23672372
// If this is a block variable, call _Block_object_destroy

clang/test/Frontend/backend-attribute-error-warning-optimize.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,13 @@ void indirect(void) {
2020
quux = foo;
2121
quux();
2222
}
23+
24+
// https://github.com/llvm/llvm-project/issues/146520
25+
26+
[[gnu::error("error please")]]
27+
void cleaner_function(char*);
28+
29+
void asdf(void){
30+
[[gnu::cleanup(cleaner_function)]] // expected-error {{call to 'cleaner_function' declared with 'error' attribute: error please}}
31+
char x;
32+
}

0 commit comments

Comments
 (0)