Author: ahatanak Date: Wed Apr 11 23:01:41 2018 New Revision: 329879 URL: http://llvm.org/viewvc/llvm-project?rev=329879&view=rev Log: [Sema][ObjC] Ensure that the return type of an ObjC method is a complete type.
Copy the code in ActOnStartOfFunctionDef that checks a function's return type to ActOnStartOfObjCMethodDef. This fixes an assertion failure in IRGen caused by an uninstantiated return type. rdar://problem/38691818 Added: cfe/trunk/test/CodeGenObjCXX/instantiate-return.mm Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp cfe/trunk/test/SemaObjCXX/instantiate-method-return.mm Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=329879&r1=329878&r2=329879&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original) +++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Wed Apr 11 23:01:41 2018 @@ -341,6 +341,13 @@ void Sema::ActOnStartOfObjCMethodDef(Sco if (!MDecl) return; + QualType ResultType = MDecl->getReturnType(); + if (!ResultType->isDependentType() && !ResultType->isVoidType() && + !MDecl->isInvalidDecl() && + RequireCompleteType(MDecl->getLocation(), ResultType, + diag::err_func_def_incomplete_result)) + MDecl->setInvalidDecl(); + // Allow all of Sema to see that we are entering a method definition. PushDeclContext(FnBodyScope, MDecl); PushFunctionScope(); Added: cfe/trunk/test/CodeGenObjCXX/instantiate-return.mm URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/instantiate-return.mm?rev=329879&view=auto ============================================================================== --- cfe/trunk/test/CodeGenObjCXX/instantiate-return.mm (added) +++ cfe/trunk/test/CodeGenObjCXX/instantiate-return.mm Wed Apr 11 23:01:41 2018 @@ -0,0 +1,22 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -std=c++11 -o - %s | FileCheck %s + +template <class T> +struct TemplateClass { + int a = 0; +}; + +struct S0; + +@interface C1 +- (TemplateClass<S0>)m1; +@end + +// This code used to assert in CodeGen because the return type TemplateClass<S0> +// wasn't instantiated. + +// CHECK: define internal i32 @"\01-[C1 m1]"( + +@implementation C1 +- (TemplateClass<S0>)m1 { +} +@end Modified: cfe/trunk/test/SemaObjCXX/instantiate-method-return.mm URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/instantiate-method-return.mm?rev=329879&r1=329878&r2=329879&view=diff ============================================================================== --- cfe/trunk/test/SemaObjCXX/instantiate-method-return.mm (original) +++ cfe/trunk/test/SemaObjCXX/instantiate-method-return.mm Wed Apr 11 23:01:41 2018 @@ -1,14 +1,14 @@ // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s -// expected-no-diagnostics // PR7386 @class NSObject; -class A; -template<class T> class V {}; +class A; // expected-note {{forward declaration of 'A'}} +template<class T> class V { T x; }; // expected-error {{field has incomplete type 'A'}} @protocol Protocol - (V<A*>)protocolMethod; +- (V<A>)method2; @end @@ -24,4 +24,6 @@ template<class T> class V {}; - (V<A*>)protocolMethod { V<A*> va; return va; } +- (V<A>)method2 { // expected-note {{in instantiation of}} +} @end _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits