Skip to content

Commit 3866995

Browse files
author
Fariborz Jahanian
committed
Computed length of a __func__ identifier used in an objective-c method correctly,
when creating its type. llvm-svn: 46109
1 parent 5630c4f commit 3866995

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

clang/AST/Decl.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,15 @@ ObjCMethodDecl *ObjCProtocolDecl::lookupClassMethod(Selector Sel) {
549549
return NULL;
550550
}
551551

552+
int ObjCMethodDecl::getSynthesizedSelectorSize() const {
553+
// syntesized method name is a concatenation of -/+[class-name selector]
554+
// Get length of this name.
555+
int length = 4; // for '+' or '-', '[', space in between and ']'
556+
length += getSelector().getName().size(); // for selector name.
557+
length += strlen(getMethodContext()->getName()); // for its class name
558+
return length;
559+
}
560+
552561
ObjCInterfaceDecl *const ObjCMethodDecl::getClassInterface() const {
553562
if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(MethodContext))
554563
return ID;

clang/Sema/SemaExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ Sema::ExprResult Sema::ActOnPreDefinedExpr(SourceLocation Loc,
131131
if (CurFunctionDecl)
132132
Length = CurFunctionDecl->getIdentifier()->getLength();
133133
else
134-
Length = CurMethodDecl->getSelector().getName().size();
134+
Length = CurMethodDecl->getSynthesizedSelectorSize();
135135

136136
llvm::APInt LengthI(32, Length + 1);
137137
QualType ResTy = Context.CharTy.getQualifiedType(QualType::Const);

clang/include/clang/AST/DeclObjC.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ class ObjCMethodDecl : public Decl {
116116
ObjCInterfaceDecl *const getClassInterface() const;
117117

118118
Selector getSelector() const { return SelName; }
119+
int getSynthesizedSelectorSize() const;
119120
QualType getResultType() const { return MethodDeclType; }
120121

121122
// Iterator access to formal parameters.

0 commit comments

Comments
 (0)