From 16b10378a93e8644008289fd86c1caf737d1395c Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Thu, 3 Sep 2009 00:43:07 +0000 Subject: [PATCH] This patch does the following. 1) Issue digsnostics in non-fragile ABI, when an expression evaluates to an interface type (except when it is used to access a non-fragile ivar). 2) Issue unsupported error in fragile ABI when an expression evaluates to an interface type (except when it is used to access a fragile ivar). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80860 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 2 ++ lib/Sema/SemaExpr.cpp | 11 ++--------- lib/Sema/SemaStmt.cpp | 10 +++++++++- test/SemaObjC/method-bad-param.m | 2 +- test/SemaObjC/static-ivar-ref-1.m | 4 ++-- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index a5d318eb25..ea1b2a4689 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1363,6 +1363,8 @@ def err_typecheck_indirection_requires_pointer : Error< "indirection requires pointer operand (%0 invalid)">; def err_indirection_requires_nonfragile_object : Error< "indirection cannot be to an interface in non-fragile ABI (%0 invalid)">; +def err_direct_interface_unsupported : Error< + "indirection to an interface is not supported (%0 invalid)">; def err_typecheck_invalid_operands : Error< "invalid operands to binary expression (%0 and %1)">; def err_typecheck_sub_ptr_object : Error< diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 7072443829..c01097e363 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -5023,15 +5023,8 @@ QualType Sema::CheckIndirectionOperand(Expr *Op, SourceLocation OpLoc) { if (const PointerType *PT = Ty->getAs()) return PT->getPointeeType(); - if (const ObjCObjectPointerType *OPT = Ty->getAsObjCObjectPointerType()) { - QualType PTy = OPT->getPointeeType(); - if (LangOpts.ObjCNonFragileABI && PTy->isObjCInterfaceType()) { - Diag(OpLoc, diag::err_indirection_requires_nonfragile_object) - << Ty << Op->getSourceRange(); - return QualType(); - } - return PTy; - } + if (const ObjCObjectPointerType *OPT = Ty->getAsObjCObjectPointerType()) + return OPT->getPointeeType(); Diag(OpLoc, diag::err_typecheck_indirection_requires_pointer) << Ty << Op->getSourceRange(); diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index ae59aec565..76113107ba 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -26,7 +26,15 @@ using namespace clang; Sema::OwningStmtResult Sema::ActOnExprStmt(FullExprArg expr) { Expr *E = expr->takeAs(); assert(E && "ActOnExprStmt(): missing expression"); - + if (E->getType()->isObjCInterfaceType()) { + if (LangOpts.ObjCNonFragileABI) + Diag(E->getLocEnd(), diag::err_indirection_requires_nonfragile_object) + << E->getType(); + else + Diag(E->getLocEnd(), diag::err_direct_interface_unsupported) + << E->getType(); + return StmtError(); + } // C99 6.8.3p2: The expression in an expression statement is evaluated as a // void expression for its side effects. Conversion to void allows any // operand, even incomplete types. diff --git a/test/SemaObjC/method-bad-param.m b/test/SemaObjC/method-bad-param.m index 96d8a18092..f797188669 100644 --- a/test/SemaObjC/method-bad-param.m +++ b/test/SemaObjC/method-bad-param.m @@ -1,4 +1,4 @@ -// RUN: clang-cc -triple i386-unknown-unknown -fsyntax-only -verify %s +// RUN: clang-cc -fsyntax-only -verify %s @interface foo @end diff --git a/test/SemaObjC/static-ivar-ref-1.m b/test/SemaObjC/static-ivar-ref-1.m index 4d0e7ba899..6b1a31226b 100644 --- a/test/SemaObjC/static-ivar-ref-1.m +++ b/test/SemaObjC/static-ivar-ref-1.m @@ -1,4 +1,5 @@ -// RUN: clang-cc -triple i386-unknown-unknown -ast-print %s +// RUN: clang-cc -triple i386-unknown-unknown -ast-print %s && +// RUN: clang-cc -triple x86_64-apple-darwin10 -ast-print %s @interface current { @@ -13,6 +14,5 @@ current *pc; int foo() { - // FIXME. This should be OK in nonfragile-abi as well. return pc->ivar2 + (*pc).ivar + pc->ivar1; } -- 2.50.1