[cfe-commits] r133639 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/CodeGen/CGException.cpp lib/CodeGen/CGObjCGNU.cpp lib/CodeGen/CGObjCMac.cpp lib/CodeGen/CGObjCRuntime.h lib/Sema/SemaDeclCXX.cpp test/CodeGenObjCXX/catch-id-type.mm
Fariborz Jahanian
fjahanian at apple.com
Wed Jun 22 13:21:51 PDT 2011
Author: fjahanian
Date: Wed Jun 22 15:21:51 2011
New Revision: 133639
URL: http://llvm.org/viewvc/llvm-project?rev=133639&view=rev
Log:
Alloa catching Objective-C id's being thrown with C++ throw
in Darwin's fragile abi mode. // rdar://8940528
Added:
cfe/trunk/test/CodeGenObjCXX/catch-id-type.mm
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/CodeGen/CGException.cpp
cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
cfe/trunk/lib/CodeGen/CGObjCRuntime.h
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=133639&r1=133638&r2=133639&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Jun 22 15:21:51 2011
@@ -3151,9 +3151,12 @@
"@catch parameter declarator cannot be qualified">;
def err_objc_pointer_cxx_catch_gnu : Error<
"can't catch Objective C exceptions in C++ in the GNU runtime">;
-def err_objc_pointer_cxx_catch_fragile : Error<
- "can't catch Objective C exceptions in C++ in the non-unified "
+def warn_objc_pointer_cxx_catch_fragile : Warning<
+ "catching Objective C id's exceptions in C++ in the non-unified "
"exception model">;
+def err_objc_pointer_cxx_catch_fragile : Error<
+"can't catch Objective C exceptions in C++ in the non-unified "
+"exception model">;
def err_objc_object_catch : Error<
"can't catch an Objective C object by value">;
def err_incomplete_type_objc_at_encode : Error<
Modified: cfe/trunk/lib/CodeGen/CGException.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=133639&r1=133638&r2=133639&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGException.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGException.cpp Wed Jun 22 15:21:51 2011
@@ -521,7 +521,7 @@
llvm::Value *TypeInfo = 0;
if (CaughtType->isObjCObjectPointerType())
- TypeInfo = CGM.getObjCRuntime().GetEHType(CaughtType);
+ TypeInfo = CGM.getObjCRuntime().GetEHType(CaughtType, this);
else
TypeInfo = CGM.GetAddrOfRTTIDescriptor(CaughtType, /*ForEH=*/true);
CatchScope->setHandler(I, TypeInfo, Handler);
Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=133639&r1=133638&r2=133639&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Wed Jun 22 15:21:51 2011
@@ -438,7 +438,7 @@
bool lval = false);
virtual llvm::Value *GetSelector(CGBuilderTy &Builder, const ObjCMethodDecl
*Method);
- virtual llvm::Constant *GetEHType(QualType T);
+ virtual llvm::Constant *GetEHType(QualType T, const CodeGenFunction *CGF=0);
virtual llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD,
const ObjCContainerDecl *CD);
@@ -832,7 +832,7 @@
return GetSelector(Builder, Method->getSelector(), SelTypes, false);
}
-llvm::Constant *CGObjCGNU::GetEHType(QualType T) {
+llvm::Constant *CGObjCGNU::GetEHType(QualType T, const CodeGenFunction *CGF) {
if (!CGM.getLangOptions().CPlusPlus) {
if (T->isObjCIdType()
|| T->isObjCQualifiedIdType()) {
Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=133639&r1=133638&r2=133639&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Wed Jun 22 15:21:51 2011
@@ -200,7 +200,7 @@
const llvm::Type *CacheTy;
/// CachePtrTy - LLVM type for struct objc_cache *.
const llvm::Type *CachePtrTy;
-
+
llvm::Constant *getGetPropertyFn() {
CodeGen::CodeGenTypes &Types = CGM.getTypes();
ASTContext &Ctx = CGM.getContext();
@@ -452,7 +452,7 @@
/// ExceptionDataTy - LLVM type for struct _objc_exception_data.
const llvm::Type *ExceptionDataTy;
-
+
/// ExceptionTryEnterFn - LLVM objc_exception_try_enter function.
llvm::Constant *getExceptionTryEnterFn() {
const llvm::Type *params[] = { ExceptionDataTy->getPointerTo() };
@@ -633,7 +633,7 @@
const llvm::StructType *EHTypeTy;
const llvm::Type *EHTypePtrTy;
-
+
ObjCNonFragileABITypesHelper(CodeGen::CodeGenModule &cgm);
~ObjCNonFragileABITypesHelper(){}
};
@@ -1010,7 +1010,7 @@
virtual llvm::Value *GetSelector(CGBuilderTy &Builder,
const ObjCMethodDecl *Method);
- virtual llvm::Constant *GetEHType(QualType T);
+ virtual llvm::Constant *GetEHType(QualType T, const CodeGenFunction *CGF=0);
virtual void GenerateCategory(const ObjCCategoryImplDecl *CMD);
@@ -1271,7 +1271,7 @@
virtual llvm::Value *GenerateProtocolRef(CGBuilderTy &Builder,
const ObjCProtocolDecl *PD);
- virtual llvm::Constant *GetEHType(QualType T);
+ virtual llvm::Constant *GetEHType(QualType T, const CodeGenFunction *CGF=0);
virtual llvm::Constant *GetPropertyGetFunction() {
return ObjCTypes.getGetPropertyFn();
@@ -1414,7 +1414,12 @@
return EmitSelector(Builder, Method->getSelector());
}
-llvm::Constant *CGObjCMac::GetEHType(QualType T) {
+llvm::Constant *CGObjCMac::GetEHType(QualType T, const CodeGenFunction *CGF) {
+ if (T->isObjCIdType() ||
+ T->isObjCQualifiedIdType()) {
+ return CGM.GetAddrOfRTTIDescriptor(
+ CGF->getContext().ObjCIdRedefinitionType, /*ForEH=*/true);
+ }
llvm_unreachable("asking for catch type for ObjC type in fragile runtime");
return 0;
}
@@ -4176,6 +4181,7 @@
CacheTy = llvm::OpaqueType::get(VMContext);
CGM.getModule().addTypeName("struct._objc_cache", CacheTy);
CachePtrTy = llvm::PointerType::getUnqual(CacheTy);
+
}
ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule &cgm)
@@ -4580,7 +4586,7 @@
// SuperMessageRefPtrTy - LLVM for struct _super_message_ref_t*
SuperMessageRefPtrTy = llvm::PointerType::getUnqual(SuperMessageRefTy);
-
+
// struct objc_typeinfo {
// const void** vtable; // objc_ehtype_vtable + 2
@@ -6015,7 +6021,7 @@
}
llvm::Constant *
-CGObjCNonFragileABIMac::GetEHType(QualType T) {
+CGObjCNonFragileABIMac::GetEHType(QualType T, const CodeGenFunction *CGF) {
// There's a particular fixed type info for 'id'.
if (T->isObjCIdType() ||
T->isObjCQualifiedIdType()) {
Modified: cfe/trunk/lib/CodeGen/CGObjCRuntime.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCRuntime.h?rev=133639&r1=133638&r2=133639&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCRuntime.h (original)
+++ cfe/trunk/lib/CodeGen/CGObjCRuntime.h Wed Jun 22 15:21:51 2011
@@ -128,7 +128,8 @@
/// This is used externally to implement catching ObjC types in C++.
/// Runtimes which don't support this should add the appropriate
/// error to Sema.
- virtual llvm::Constant *GetEHType(QualType T) = 0;
+ virtual llvm::Constant *GetEHType(QualType T,
+ const CodeGenFunction *CGF=0) = 0;
/// Generate a constant string object.
virtual llvm::Constant *GenerateConstantString(const StringLiteral *) = 0;
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=133639&r1=133638&r2=133639&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Jun 22 15:21:51 2011
@@ -8046,8 +8046,12 @@
Invalid = true;
} else if (T->isObjCObjectPointerType()) {
if (!getLangOptions().ObjCNonFragileABI) {
- Diag(Loc, diag::err_objc_pointer_cxx_catch_fragile);
- Invalid = true;
+ if (T->isObjCIdType() || T->isObjCQualifiedIdType())
+ Diag(Loc, diag::warn_objc_pointer_cxx_catch_fragile);
+ else {
+ Diag(Loc, diag::err_objc_pointer_cxx_catch_fragile);
+ Invalid = true;
+ }
}
}
}
Added: cfe/trunk/test/CodeGenObjCXX/catch-id-type.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/catch-id-type.mm?rev=133639&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjCXX/catch-id-type.mm (added)
+++ cfe/trunk/test/CodeGenObjCXX/catch-id-type.mm Wed Jun 22 15:21:51 2011
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -triple i386-apple-macosx10.6.6 -emit-llvm -fobjc-exceptions -fcxx-exceptions -fexceptions -o - %s | FileCheck %s
+// rdar://8940528
+
+ at interface ns_array
++ (id) array;
+ at end
+
+ at implementation ns_array
++ (id) array { return 0; }
+ at end
+
+id Groups();
+
+id FUNC() {
+ id groups;
+ try
+ {
+ groups = Groups(); // throws on errors.
+ }
+ catch( id error )
+ {
+ // CHECK: call i32 (i8*, i8*, ...)* @llvm.eh.selector({{.*}} @__gxx_personality_v0 {{.*}} @_ZTIP11objc_object
+ error = error;
+ groups = [ns_array array];
+ }
+ return groups;
+
+}
+
+int main() {
+ FUNC();
+ return 0;
+}
More information about the cfe-commits
mailing list