r180062 - Add a warning for Objective-C pointer introspection, which is solely the job of the Objective-C runtime.
jahanian
fjahanian at apple.com
Tue Apr 23 09:45:51 PDT 2013
Couple of points. Test case is missing. Can we suggest what those APIs are and provide fixit’s if it is not
too complicated to do?
- Fariborz
On Apr 22, 2013, at 3:46 PM, Ted Kremenek <kremenek at apple.com> wrote:
> Author: kremenek
> Date: Mon Apr 22 17:46:52 2013
> New Revision: 180062
>
> URL: http://llvm.org/viewvc/llvm-project?rev=180062&view=rev
> Log:
> Add a warning for Objective-C pointer introspection, which is solely the job of the Objective-C runtime.
>
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/lib/Sema/SemaExpr.cpp
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=180062&r1=180061&r2=180062&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Apr 22 17:46:52 2013
> @@ -642,6 +642,10 @@ def warn_objc_isa_use : Warning<
> def warn_objc_isa_assign : Warning<
> "assignment to Objective-C's isa is deprecated in favor of "
> "object_setClass()">, InGroup<DeprecatedObjCIsaUsage>;
> +def warn_objc_pointer_masking : Warning<
> + "bitmasking for introspection of Objective-C object pointers is strongly "
> + "discouraged in favor of using runtime APIs">,
> + InGroup<DiagGroup<"deprecated-objc-pointer-introspection">>;
> def warn_objc_property_default_assign_on_object : Warning<
> "default property attribute 'assign' not appropriate for non-GC object">,
> InGroup<ObjCPropertyNoAttribute>;
>
> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=180062&r1=180061&r2=180062&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Apr 22 17:46:52 2013
> @@ -8559,6 +8559,36 @@ static void DiagnoseSelfAssignment(Sema
> << LHSExpr->getSourceRange() << RHSExpr->getSourceRange();
> }
>
> +/// Check if a bitwise-& is performed on an Objective-C pointer. This
> +/// is usually indicative of introspection within the Objective-C pointer.
> +static void checkObjCPointerIntrospection(Sema &S, ExprResult &L, ExprResult &R,
> + SourceLocation OpLoc) {
> + if (!S.getLangOpts().ObjC1)
> + return;
> +
> + const Expr *ObjCPointerExpr = 0, *OtherExpr = 0;
> + const Expr *LHS = L.get();
> + const Expr *RHS = R.get();
> +
> + if (LHS->IgnoreParenCasts()->getType()->isObjCObjectPointerType()) {
> + ObjCPointerExpr = LHS;
> + OtherExpr = RHS;
> + }
> + else if (RHS->IgnoreParenCasts()->getType()->isObjCObjectPointerType()) {
> + ObjCPointerExpr = RHS;
> + OtherExpr = LHS;
> + }
> +
> + // This warning is deliberately made very specific to reduce false
> + // positives with logic that uses '&' for hashing. This logic mainly
> + // looks for code trying to introspect into tagged pointers, which
> + // code should generally never do.
> + if (ObjCPointerExpr && isa<IntegerLiteral>(OtherExpr->IgnoreParenCasts())) {
> + S.Diag(OpLoc, diag::warn_objc_pointer_masking)
> + << ObjCPointerExpr->getSourceRange();
> + }
> +}
> +
> /// CreateBuiltinBinOp - Creates a new built-in binary operation with
> /// operator @p Opc at location @c TokLoc. This routine only supports
> /// built-in operations; ActOnBinOp handles overloaded operators.
> @@ -8636,6 +8666,7 @@ ExprResult Sema::CreateBuiltinBinOp(Sour
> ResultTy = CheckCompareOperands(LHS, RHS, OpLoc, Opc, false);
> break;
> case BO_And:
> + checkObjCPointerIntrospection(*this, LHS, RHS, OpLoc);
> case BO_Xor:
> case BO_Or:
> ResultTy = CheckBitwiseOperands(LHS, RHS, OpLoc);
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130423/ed798676/attachment.html>
More information about the cfe-commits
mailing list