Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/lib/Sema/CheckExprLifetime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ static bool isNormalAssignmentOperator(const FunctionDecl *FD) {
return false;
}

static bool implicitObjectParamIsLifetimeBound(const FunctionDecl *FD) {
bool implicitObjectParamIsLifetimeBound(const FunctionDecl *FD) {
const TypeSourceInfo *TSI = FD->getTypeSourceInfo();
if (!TSI)
return false;
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Sema/CheckExprLifetime.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ void checkCaptureByLifetime(Sema &SemaRef, const CapturingEntity &Entity,
void checkExprLifetimeMustTailArg(Sema &SemaRef,
const InitializedEntity &Entity, Expr *Init);

bool implicitObjectParamIsLifetimeBound(const FunctionDecl *FD);

} // namespace clang::sema

#endif // LLVM_CLANG_SEMA_CHECK_EXPR_LIFETIME_H
4 changes: 3 additions & 1 deletion clang/lib/Sema/SemaAPINotes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//
//===----------------------------------------------------------------------===//

#include "CheckExprLifetime.h"
#include "TypeLocBuilder.h"
#include "clang/APINotes/APINotesReader.h"
#include "clang/AST/Decl.h"
Expand Down Expand Up @@ -568,7 +569,8 @@ static void ProcessAPINotes(Sema &S, FunctionOrMethod AnyFunc,
static void ProcessAPINotes(Sema &S, CXXMethodDecl *Method,
const api_notes::CXXMethodInfo &Info,
VersionedInfoMetadata Metadata) {
if (Info.This && Info.This->isLifetimebound()) {
if (Info.This && Info.This->isLifetimebound() &&
!sema::implicitObjectParamIsLifetimeBound(Method)) {
auto MethodType = Method->getType();
auto *attr = ::new (S.Context)
LifetimeBoundAttr(S.Context, getPlaceholderAttrInfo());
Expand Down
4 changes: 4 additions & 0 deletions clang/test/APINotes/Inputs/Headers/Lifetimebound.apinotes
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Tags:
Parameters:
- Position: -1
Lifetimebound: true
- Name: annotateThis2
Parameters:
- Position: -1
Lifetimebound: true
- Name: methodToAnnotate
Parameters:
- Position: 0
Expand Down
1 change: 1 addition & 0 deletions clang/test/APINotes/Inputs/Headers/Lifetimebound.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ int *funcToAnnotate(int *p);
struct MyClass {
MyClass(int*);
int *annotateThis();
int *annotateThis2() [[clang::lifetimebound]];
int *methodToAnnotate(int *p);
};
1 change: 1 addition & 0 deletions clang/test/APINotes/lifetimebound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
// CHECK-METHOD-NEXT: LifetimeBoundAttr

// CHECK-METHOD-THIS: CXXMethodDecl {{.+}} annotateThis 'int *() {{\[\[}}clang::lifetimebound{{\]\]}}'
// CHECK-METHOD-THIS: CXXMethodDecl {{.+}} annotateThis2 'int *() {{\[\[}}clang::lifetimebound{{\]\]}}'
Loading