[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

llvm-svn: 329879
This commit is contained in:
Akira Hatanaka 2018-04-12 06:01:41 +00:00
parent bcadfee2ad
commit ff6c4f3702
3 changed files with 34 additions and 3 deletions

View File

@ -341,6 +341,13 @@ void Sema::ActOnStartOfObjCMethodDef(Scope *FnBodyScope, Decl *D) {
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();

View File

@ -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

View File

@ -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