]> granicus.if.org Git - clang/commitdiff
Fixes an instance method meta-data generation bug in
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 22 Apr 2011 22:02:28 +0000 (22:02 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 22 Apr 2011 22:02:28 +0000 (22:02 +0000)
ObjC NeXt runtime where method pointer registered in
metadata belongs to an unrelated method. Ast part of this fix,
I turned at @end missing warning (for class
implementations) into an error as we can never
be sure that meta-data being generated is correct.
// rdar://9072317

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130019 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticParseKinds.td
include/clang/Basic/DiagnosticSemaKinds.td
lib/CodeGen/CGObjCMac.cpp
lib/Parse/ParseObjc.cpp
lib/Sema/SemaDeclObjC.cpp
test/CodeGenObjC/instance-method-metadata.m [new file with mode: 0644]
test/CodeGenObjC/missing-atend-metadata.m [deleted file]
test/Index/rdar-8288645-invalid-code.mm
test/Parser/objc-missing-impl.m
test/SemaObjC/missing-atend-metadata.m [new file with mode: 0644]

index 4032944a2d5a5550f2b57053fa28e51088b72672..a297fd1ddcdc73e4d4e4cc990082a4416d70d7b9 100644 (file)
@@ -286,7 +286,7 @@ def err_missing_id_definition : Error<"cannot find definition of 'id'">;
 def err_missing_proto_definition : Error<
   "cannot find definition of 'Protocol'">;
 def err_missing_class_definition : Error<"cannot find definition of 'Class'">;
-def warn_expected_implementation : Warning<
+def err_expected_implementation : Error<
   "@end must appear in an @implementation context">;
 def error_property_ivar_decl : Error<
   "property synthesize requires specification of an ivar">;
index 86d5c2099f88abe54ebc39168161955b35f82008..dbc30c0dfb656038e201bc44ab01540d14b39954 100644 (file)
@@ -393,7 +393,7 @@ def note_declared_at : Note<"declared here">;
 def note_method_declared_at : Note<"method declared here">;
 def err_setter_type_void : Error<"type of setter must be void">;
 def err_duplicate_method_decl : Error<"duplicate declaration of method %0">;
-def warn_missing_atend : Warning<"'@end' is missing in implementation context">;
+def err_missing_atend : Error<"'@end' is missing in implementation context">;
 def err_objc_var_decl_inclass : 
     Error<"cannot declare variable inside @interface or @protocol">;
 def error_missing_method_context : Error<
index 9466c77ed37e54b0409e89c319fabfebe0d643d8..3447daf5c2fd67b87ff5e1b50b9aee9725f5a40d 100644 (file)
@@ -2069,6 +2069,8 @@ void CGObjCMac::GenerateCategory(const ObjCCategoryImplDecl *OCD) {
                       4, true);
   DefinedCategories.push_back(GV);
   DefinedCategoryNames.insert(ExtName.str());
+  // method definition entries must be clear for next implementation.
+  MethodDefinitions.clear();
 }
 
 // FIXME: Get from somewhere?
@@ -2196,6 +2198,8 @@ void CGObjCMac::GenerateClass(const ObjCImplementationDecl *ID) {
   else
     GV = CreateMetadataVar(Name, Init, Section, 4, true);
   DefinedClasses.push_back(GV);
+  // method definition entries must be clear for next implementation.
+  MethodDefinitions.clear();
 }
 
 llvm::Constant *CGObjCMac::EmitMetaClass(const ObjCImplementationDecl *ID,
@@ -4978,6 +4982,8 @@ void CGObjCNonFragileABIMac::GenerateClass(const ObjCImplementationDecl *ID) {
   // Force the definition of the EHType if necessary.
   if (flags & CLS_EXCEPTION)
     GetInterfaceEHType(ID->getClassInterface(), true);
+  // Make sure method definition entries are all clear for next implementation.
+  MethodDefinitions.clear();
 }
 
 /// GenerateProtocolRef - This routine is called to generate code for
@@ -5106,6 +5112,8 @@ void CGObjCNonFragileABIMac::GenerateCategory(const ObjCCategoryImplDecl *OCD) {
   // Determine if this category is also "non-lazy".
   if (ImplementationIsNonLazy(OCD))
     DefinedNonLazyCategories.push_back(GCATV);
+  // method definition entries must be clear for next implementation.
+  MethodDefinitions.clear();
 }
 
 /// GetMethodConstant - Return a struct objc_method constant for the
index b42cf9f0ae11ce229264051054df160291cf3910..fdbedc54d1cd2a16703250f643991b7168dc85ec 100644 (file)
@@ -1387,7 +1387,7 @@ Decl *Parser::ParseObjCAtEndDeclaration(SourceRange atEnd) {
   }
   else {
     // missing @implementation
-    Diag(atEnd.getBegin(), diag::warn_expected_implementation);
+    Diag(atEnd.getBegin(), diag::err_expected_implementation);
   }
   return Result;
 }
index 4fc1e6912ecf48be2cdd4c42e58aea72424522c1..01d37f47b2c1e5ef1f3e8600fc54f3eae6684abd 100644 (file)
@@ -1536,7 +1536,7 @@ void Sema::ActOnAtEnd(Scope *S, SourceRange AtEnd,
     SourceLocation L = ClassDecl->getLocation();
     AtEnd.setBegin(L);
     AtEnd.setEnd(L);
-    Diag(L, diag::warn_missing_atend);
+    Diag(L, diag::err_missing_atend);
   }
   
   // FIXME: Remove these and use the ObjCContainerDecl/DeclContext.
diff --git a/test/CodeGenObjC/instance-method-metadata.m b/test/CodeGenObjC/instance-method-metadata.m
new file mode 100644 (file)
index 0000000..ae87c7a
--- /dev/null
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -S -o %t %s 
+// RUN: FileCheck < %t %s
+
+// rdar://9072317
+
+/** The problem looks like clang getting confused when a single translation unit 
+    contains a protocol with a property and two classes that implement that protocol 
+    and synthesize the property.
+*/
+
+@protocol Proto
+@property (assign) id prop;
+@end
+
+@interface NSObject @end
+
+@interface Foo : NSObject <Proto> { int x; } @end
+
+@interface Bar : NSObject <Proto> @end
+
+@implementation Foo
+@synthesize prop;
+@end
+
+@implementation Bar
+@synthesize prop;
+@end
+
+// CHECK: l_OBJC_$_INSTANCE_METHODS_Bar:
+// CHECK-NEXT        .long   24
+// CHECK-NEXT        .long   2
+// CHECK-NEXT        .quad   L_OBJC_METH_VAR_NAME_
+// CHECK-NEXT        .quad   L_OBJC_METH_VAR_TYPE_
+// CHECK-NEXT        .quad   "-[Bar prop]"
diff --git a/test/CodeGenObjC/missing-atend-metadata.m b/test/CodeGenObjC/missing-atend-metadata.m
deleted file mode 100644 (file)
index 50e597c..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-// RUN: %clang_cc1 -triple i386-apple-darwin9 -emit-llvm %s -o - | FileCheck %s
-
-@interface I0 
-@end
-
-@implementation I0 // expected-warning {{'@end' is missing in implementation context}}
-- meth { return 0; }
-
-@interface I1 : I0 
-@end
-
-@implementation I1 // expected-warning {{'@end' is missing in implementation context}}
--(void) im0 { self = [super init]; }
-
-@interface I2 : I0
-- I2meth;
-@end
-
-@implementation I2 // expected-warning {{'@end' is missing in implementation context}}
-- I2meth { return 0; }
-
-@implementation  I2(CAT) // expected-warning {{'@end' is missing in implementation context}}
-
-// CHECK: @"\01L_OBJC_CLASS_I1" = internal global
index 3405f0a93270f053d509f32dd5f4712035b9b5d0..74e2365edcfef2b36fd4dc02f754b562acbc26e2 100644 (file)
@@ -5,4 +5,4 @@
 extern "C" { @implementation Foo  - (id)initWithBar:(Baz<WozBar>)pepper {
 
 // CHECK: warning: cannot find interface declaration for 'Foo'
-// CHECK: warning: '@end' is missing in implementation context
+// CHECK: error: '@end' is missing in implementation context
index 05d9d6c0b2326c6e74380192f0fdbb05faa4c80d..e9c37ab1b15870dbe437967be045b8419ebb5828 100644 (file)
@@ -1,2 +1,2 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
-@end // expected-warning {{@end must appear in an @implementation context}}
+@end // expected-error {{@end must appear in an @implementation context}}
diff --git a/test/SemaObjC/missing-atend-metadata.m b/test/SemaObjC/missing-atend-metadata.m
new file mode 100644 (file)
index 0000000..434706d
--- /dev/null
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s 
+
+@interface I0 
+@end
+
+@implementation I0 // expected-error {{'@end' is missing in implementation context}}
+- meth { return 0; }
+
+@interface I1 : I0 
+@end
+
+@implementation I1 // expected-error {{'@end' is missing in implementation context}}
+-(void) im0 { self = [super init]; } // expected-warning {{nstance method '-init' not found }}
+
+@interface I2 : I0
+- I2meth;
+@end
+
+@implementation I2 // expected-error {{'@end' is missing in implementation context}}
+- I2meth { return 0; }
+
+@implementation  I2(CAT) // expected-error {{'@end' is missing in implementation context}}