[cfe-commits] r125229 - in /cfe/trunk: include/clang/Basic/DiagnosticCommonKinds.td include/clang/Sema/Sema.h lib/Parse/ParseObjc.cpp lib/Sema/SemaDeclObjC.cpp test/Parser/objc-forcollection-neg-2.m test/Parser/objc-forcollection-neg.m test/Parser/objc-foreach-syntax.m test/SemaObjC/method-prototype-scope.m
Fariborz Jahanian
fjahanian at apple.com
Wed Feb 9 14:20:01 PST 2011
Author: fjahanian
Date: Wed Feb 9 16:20:01 2011
New Revision: 125229
URL: http://llvm.org/viewvc/llvm-project?rev=125229&view=rev
Log:
Fix scoping of method declarations and issue
warning when same parameter name used multiple times.
// rdar://8877730
Added:
cfe/trunk/test/SemaObjC/method-prototype-scope.m
Modified:
cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/test/Parser/objc-forcollection-neg-2.m
cfe/trunk/test/Parser/objc-forcollection-neg.m
cfe/trunk/test/Parser/objc-foreach-syntax.m
Modified: cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td?rev=125229&r1=125228&r2=125229&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td Wed Feb 9 16:20:01 2011
@@ -44,6 +44,7 @@
def ext_no_declarators : ExtWarn<"declaration does not declare anything">,
InGroup<MissingDeclarations>;
def err_param_redefinition : Error<"redefinition of parameter %0">;
+def warn_method_param_redefinition : Warning<"redefinition of method parameter %0">;
def err_invalid_storage_class_in_func_decl : Error<
"invalid storage class specifier in function declarator">;
def err_expected_namespace_name : Error<"expected namespace name">;
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=125229&r1=125228&r2=125229&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Feb 9 16:20:01 2011
@@ -4251,6 +4251,7 @@
};
Decl *ActOnMethodDeclaration(
+ Scope *S,
SourceLocation BeginLoc, // location of the + or -.
SourceLocation EndLoc, // location of the ; or {.
tok::TokenKind MethodType,
Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=125229&r1=125228&r2=125229&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Wed Feb 9 16:20:01 2011
@@ -868,7 +868,7 @@
Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent);
Decl *Result
- = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(),
+ = Actions.ActOnMethodDeclaration(getCurScope(), mLoc, Tok.getLocation(),
mType, IDecl, DSRet, ReturnType, Sel,
0,
CParamInfo.data(), CParamInfo.size(),
@@ -879,7 +879,9 @@
llvm::SmallVector<IdentifierInfo *, 12> KeyIdents;
llvm::SmallVector<Sema::ObjCArgInfo, 12> ArgInfos;
-
+ ParseScope PrototypeScope(this,
+ Scope::FunctionPrototypeScope|Scope::DeclScope);
+
while (1) {
Sema::ObjCArgInfo ArgInfo;
@@ -976,18 +978,25 @@
// If attributes exist after the method, parse them.
if (getLang().ObjC2)
MaybeParseGNUAttributes(attrs);
-
- if (KeyIdents.size() == 0)
+
+ if (KeyIdents.size() == 0) {
+ // Leave prototype scope.
+ PrototypeScope.Exit();
return 0;
+ }
+
Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(),
&KeyIdents[0]);
Decl *Result
- = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(),
+ = Actions.ActOnMethodDeclaration(getCurScope(), mLoc, Tok.getLocation(),
mType, IDecl, DSRet, ReturnType, Sel,
&ArgInfos[0],
CParamInfo.data(), CParamInfo.size(),
attrs.getList(),
MethodImplKind, isVariadic);
+ // Leave prototype scope.
+ PrototypeScope.Exit();
+
PD.complete(Result);
return Result;
}
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=125229&r1=125228&r2=125229&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Wed Feb 9 16:20:01 2011
@@ -1664,6 +1664,7 @@
}
Decl *Sema::ActOnMethodDeclaration(
+ Scope *S,
SourceLocation MethodLoc, SourceLocation EndLoc,
tok::TokenKind MethodType, Decl *ClassDecl,
ObjCDeclSpec &ReturnQT, ParsedType ReturnType,
@@ -1721,6 +1722,20 @@
ArgType = adjustParameterType(ArgType);
}
+ LookupResult R(*this, ArgInfo[i].Name, ArgInfo[i].NameLoc,
+ LookupOrdinaryName, ForRedeclaration);
+ LookupName(R, S);
+ if (R.isSingleResult()) {
+ NamedDecl *PrevDecl = R.getFoundDecl();
+ if (S->isDeclScope(PrevDecl)) {
+ // FIXME. This should be an error; but will break projects.
+ Diag(ArgInfo[i].NameLoc, diag::warn_method_param_redefinition)
+ << ArgInfo[i].Name;
+ Diag(PrevDecl->getLocation(),
+ diag::note_previous_declaration);
+ }
+ }
+
ParmVarDecl* Param
= ParmVarDecl::Create(Context, ObjCMethod, ArgInfo[i].NameLoc,
ArgInfo[i].Name, ArgType, DI,
@@ -1739,9 +1754,12 @@
// Apply the attributes to the parameter.
ProcessDeclAttributeList(TUScope, Param, ArgInfo[i].ArgAttrs);
+ S->AddDecl(Param);
+ IdResolver.AddDecl(Param);
+
Params.push_back(Param);
}
-
+
for (unsigned i = 0, e = CNumArgs; i != e; ++i) {
ParmVarDecl *Param = cast<ParmVarDecl>(CParamInfo[i].Param);
QualType ArgType = Param->getType();
@@ -1757,8 +1775,7 @@
Param->setInvalidDecl();
}
Param->setDeclContext(ObjCMethod);
- if (Param->getDeclName())
- IdResolver.RemoveDecl(Param);
+
Params.push_back(Param);
}
Modified: cfe/trunk/test/Parser/objc-forcollection-neg-2.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-forcollection-neg-2.m?rev=125229&r1=125228&r2=125229&view=diff
==============================================================================
--- cfe/trunk/test/Parser/objc-forcollection-neg-2.m (original)
+++ cfe/trunk/test/Parser/objc-forcollection-neg-2.m Wed Feb 9 16:20:01 2011
@@ -1,11 +1,11 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
typedef struct objc_class *Class;
+struct __objcFastEnumerationState;
typedef struct objc_object {
Class isa;
} *id;
-
@protocol P @end
@interface MyList
Modified: cfe/trunk/test/Parser/objc-forcollection-neg.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-forcollection-neg.m?rev=125229&r1=125228&r2=125229&view=diff
==============================================================================
--- cfe/trunk/test/Parser/objc-forcollection-neg.m (original)
+++ cfe/trunk/test/Parser/objc-forcollection-neg.m Wed Feb 9 16:20:01 2011
@@ -1,5 +1,6 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
+struct __objcFastEnumerationState;
typedef struct objc_class *Class;
typedef struct objc_object {
Class isa;
Modified: cfe/trunk/test/Parser/objc-foreach-syntax.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-foreach-syntax.m?rev=125229&r1=125228&r2=125229&view=diff
==============================================================================
--- cfe/trunk/test/Parser/objc-foreach-syntax.m (original)
+++ cfe/trunk/test/Parser/objc-foreach-syntax.m Wed Feb 9 16:20:01 2011
@@ -1,7 +1,6 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
-
-
+struct __objcFastEnumerationState;
@implementation MyList // expected-warning {{cannot find interface declaration for 'MyList'}}
- (unsigned int)countByEnumeratingWithState: (struct __objcFastEnumerationState *)state objects: (id *)items count:(unsigned int)stackcount
{
Added: cfe/trunk/test/SemaObjC/method-prototype-scope.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/method-prototype-scope.m?rev=125229&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/method-prototype-scope.m (added)
+++ cfe/trunk/test/SemaObjC/method-prototype-scope.m Wed Feb 9 16:20:01 2011
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// rdar://8877730
+
+int object;
+
+ at class NSString, NSArray;
+
+ at interface Test
+- Func:(int)XXXX, id object;
+
+- doSomethingElseWith:(id)object;
+
+- (NSString *)doSomethingWith:(NSString *)object and:(NSArray *)object; // expected-warning {{redefinition of method parameter 'object'}} \
+ // expected-note {{previous declaration is here}}
+ at end
+
+ at implementation Test
+
+- (NSString *)doSomethingWith:(NSString *)object and:(NSArray *)object // expected-warning {{redefinition of method parameter 'object'}} \
+ // expected-note {{previous declaration is here}}
+{
+ return object; // expected-warning {{incompatible pointer types returning 'NSArray *' from a function with result type 'NSString *'}}
+}
+
+- Func:(int)XXXX, id object { return object; }
+
+- doSomethingElseWith:(id)object { return object; }
+
+ at end
+
+struct P;
+
+ at interface Test1
+- doSomethingWith:(struct S *)object and:(struct P *)obj; // expected-warning {{declaration of 'struct S' will not be visible outside of this function}}
+ at end
+
+int obj;
More information about the cfe-commits
mailing list