[cfe-commits] r109197 - in /cfe/trunk: include/clang/Basic/DiagnosticGroups.td include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExpr.cpp test/SemaObjC/conflict-nonfragile-abi2.m
Fariborz Jahanian
fjahanian at apple.com
Thu Jul 22 16:33:21 PDT 2010
Author: fjahanian
Date: Thu Jul 22 18:33:21 2010
New Revision: 109197
URL: http://llvm.org/viewvc/llvm-project?rev=109197&view=rev
Log:
Warn when property ivar lookup finds a global variable
of same name. In nonfragile-abi2, lookup accesses a synthesized
ivar. This is a transition warning. Radar 8225011.
Added:
cfe/trunk/test/SemaObjC/conflict-nonfragile-abi2.m
Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaExpr.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=109197&r1=109196&r2=109197&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Thu Jul 22 18:33:21 2010
@@ -135,6 +135,7 @@
def Reorder : DiagGroup<"reorder">;
def UndeclaredSelector : DiagGroup<"undeclared-selector">;
def Selector : DiagGroup<"selector">;
+def NonfragileAbi2 : DiagGroup<"nonfragile-abi2">;
def Protocol : DiagGroup<"protocol">;
def SuperSubClassMismatch : DiagGroup<"super-class-method-mismatch">;
def : DiagGroup<"variadic-macros">;
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=109197&r1=109196&r2=109197&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Jul 22 18:33:21 2010
@@ -2492,6 +2492,10 @@
def warn_value_always_zero : Warning<
"%0 is always %select{zero|false|NULL}1 in this context">;
+def warn_ivar_variable_conflict : Warning<
+ "%0 lookup will access the property ivar in nonfragile-abi2 mode">,
+ InGroup<NonfragileAbi2>;
+
// assignment related diagnostics (also for argument passing, returning, etc).
// In most of these diagnostics the %2 is a value from the
// Sema::AssignmentAction enumeration
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=109197&r1=109196&r2=109197&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Jul 22 18:33:21 2010
@@ -1005,6 +1005,25 @@
return true;
}
+static ObjCPropertyDecl *OkToSynthesizeProvisionalIvar(Sema &SemaRef,
+ IdentifierInfo *II,
+ SourceLocation NameLoc) {
+ ObjCMethodDecl *CurMeth = SemaRef.getCurMethodDecl();
+ ObjCInterfaceDecl *IDecl = CurMeth->getClassInterface();
+ if (!IDecl)
+ return 0;
+ ObjCImplementationDecl *ClassImpDecl = IDecl->getImplementation();
+ if (!ClassImpDecl)
+ return 0;
+ ObjCPropertyDecl *property = SemaRef.LookupPropertyDecl(IDecl, II);
+ if (!property)
+ return 0;
+ if (ObjCPropertyImplDecl *PIDecl = ClassImpDecl->FindPropertyImplDecl(II))
+ if (PIDecl->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic)
+ return 0;
+ return property;
+}
+
static ObjCIvarDecl *SynthesizeProvisionalIvar(Sema &SemaRef,
IdentifierInfo *II,
SourceLocation NameLoc) {
@@ -1077,7 +1096,7 @@
isAddressOfOperand,
TemplateArgs);
}
-
+ bool IvarLookupFollowUp = false;
// Perform the required lookup.
LookupResult R(*this, Name, NameLoc, LookupOrdinaryName);
if (TemplateArgs) {
@@ -1090,7 +1109,7 @@
LookupTemplateName(R, S, SS, QualType(), /*EnteringContext=*/false,
MemberOfUnknownSpecialization);
} else {
- bool IvarLookupFollowUp = (!SS.isSet() && II && getCurMethodDecl());
+ IvarLookupFollowUp = (!SS.isSet() && II && getCurMethodDecl());
LookupParsedName(R, S, &SS, !IvarLookupFollowUp);
// If this reference is in an Objective-C method, then we need to do
@@ -1151,6 +1170,16 @@
assert(!R.empty() || ADL);
if (VarDecl *Var = R.getAsSingle<VarDecl>()) {
+ if (getLangOptions().ObjCNonFragileABI && IvarLookupFollowUp &&
+ !getLangOptions().ObjCNonFragileABI2) {
+ ObjCPropertyDecl *Property =
+ OkToSynthesizeProvisionalIvar(*this, II, NameLoc);
+ if (Property) {
+ Diag(NameLoc, diag::warn_ivar_variable_conflict) << Var->getDeclName();
+ Diag(Property->getLocation(), diag::note_property_declare);
+ }
+ }
+
// Warn about constructs like:
// if (void *X = foo()) { ... } else { X }.
// In the else block, the pointer is always false.
Added: cfe/trunk/test/SemaObjC/conflict-nonfragile-abi2.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/conflict-nonfragile-abi2.m?rev=109197&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/conflict-nonfragile-abi2.m (added)
+++ cfe/trunk/test/SemaObjC/conflict-nonfragile-abi2.m Thu Jul 22 18:33:21 2010
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fobjc-nonfragile-abi -verify -fsyntax-only %s
+// rdar : // 8225011
+
+int glob;
+
+ at interface I
+ at property int glob; // expected-note {{property declared here}}
+ at end
+
+ at implementation I
+- (int) Meth { return glob; } // expected-warning {{'glob' lookup will access the property ivar in nonfragile-abi2 mode}}
+ at synthesize glob;
+ at end
More information about the cfe-commits
mailing list