diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 5e9c7486d34b..e29e6ab4c773 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -1355,6 +1355,8 @@ def err_typecheck_unary_expr : Error< "invalid argument type %0 to unary expression">; 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_typecheck_invalid_operands : Error< "invalid operands to binary expression (%0 and %1)">; def err_typecheck_sub_ptr_object : Error< diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index c01097e363c1..7072443829a2 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -5023,8 +5023,15 @@ QualType Sema::CheckIndirectionOperand(Expr *Op, SourceLocation OpLoc) { if (const PointerType *PT = Ty->getAs()) return PT->getPointeeType(); - if (const ObjCObjectPointerType *OPT = Ty->getAsObjCObjectPointerType()) - return OPT->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; + } Diag(OpLoc, diag::err_typecheck_indirection_requires_pointer) << Ty << Op->getSourceRange();