Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit f3710ba

Browse files
author
Fariborz Jahanian
committed
Fixed a problem caused by foreward @Class use
which consequently caused a Seg fault. during meta-data generation. It also addresses an issue related to late binding of newly synthesize ivars (when we support it). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64563 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 59843ad commit f3710ba

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

include/clang/AST/ASTContext.h

+1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ class ASTContext {
263263
/// specified typename decl.
264264
QualType getTypedefType(TypedefDecl *Decl);
265265
QualType getObjCInterfaceType(ObjCInterfaceDecl *Decl);
266+
QualType buildObjCInterfaceType(ObjCInterfaceDecl *Decl);
266267

267268
QualType getTemplateTypeParmType(unsigned Depth, unsigned Index,
268269
IdentifierInfo *Name = 0);

lib/AST/ASTContext.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,18 @@ QualType ASTContext::getObjCInterfaceType(ObjCInterfaceDecl *Decl) {
12101210
return QualType(Decl->TypeForDecl, 0);
12111211
}
12121212

1213+
/// buildObjCInterfaceType - Returns a new type for the interface
1214+
/// declaration, regardless. It also removes any previously built
1215+
/// record declaration so caller can rebuild it.
1216+
QualType ASTContext::buildObjCInterfaceType(ObjCInterfaceDecl *Decl) {
1217+
const RecordDecl *&RD = ASTRecordForInterface[Decl];
1218+
if (RD)
1219+
RD = 0;
1220+
Decl->TypeForDecl = new(*this,8) ObjCInterfaceType(Type::ObjCInterface, Decl);
1221+
Types.push_back(Decl->TypeForDecl);
1222+
return QualType(Decl->TypeForDecl, 0);
1223+
}
1224+
12131225
/// \brief Retrieve the template type parameter type for a template
12141226
/// parameter with the given depth, index, and (optionally) name.
12151227
QualType ASTContext::getTemplateTypeParmType(unsigned Depth, unsigned Index,

lib/CodeGen/CGObjCMac.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1370,7 +1370,7 @@ void CGObjCMac::GenerateClass(const ObjCImplementationDecl *ID) {
13701370
Interface->protocol_begin(),
13711371
Interface->protocol_end());
13721372
const llvm::Type *InterfaceTy =
1373-
CGM.getTypes().ConvertType(CGM.getContext().getObjCInterfaceType(Interface));
1373+
CGM.getTypes().ConvertType(CGM.getContext().buildObjCInterfaceType(Interface));
13741374
unsigned Flags = eClassFlags_Factory;
13751375
unsigned Size = CGM.getTargetData().getTypePaddedSize(InterfaceTy);
13761376

@@ -3717,7 +3717,7 @@ void CGObjCNonFragileABIMac::GenerateClass(const ObjCImplementationDecl *ID) {
37173717
const_cast<ObjCInterfaceDecl*>(ID->getClassInterface())) {
37183718
// FIXME. Share this with the one in EmitIvarList.
37193719
const llvm::Type *InterfaceTy =
3720-
CGM.getTypes().ConvertType(CGM.getContext().getObjCInterfaceType(OID));
3720+
CGM.getTypes().ConvertType(CGM.getContext().buildObjCInterfaceType(OID));
37213721
const llvm::StructLayout *Layout =
37223722
CGM.getTargetData().getStructLayout(cast<llvm::StructType>(InterfaceTy));
37233723

test/CodeGenObjC/class-type.m

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: clang -triple x86_64-unknown-unknown -emit-llvm -o %t %s
2+
3+
@interface I0 {
4+
struct { int a; } a;
5+
}
6+
@end
7+
8+
@class I2;
9+
10+
@interface I1 {
11+
I2 *_imageBrowser;
12+
}
13+
@end
14+
15+
@implementation I1
16+
@end
17+
18+
@interface I2 : I0
19+
@end
20+
21+
@implementation I2
22+
@end
23+
24+

0 commit comments

Comments
 (0)