r183713 - Objective-C [qoi]: Issue better warning when nsstring literal is missing

Jordan Rose jordan_rose at apple.com
Mon Jun 10 16:57:00 PDT 2013


Yay! But why is this under -Wobjc-literal-compare?


On Jun 10, 2013, at 16:51 , Fariborz Jahanian <fjahanian at apple.com> wrote:

> Author: fjahanian
> Date: Mon Jun 10 18:51:51 2013
> New Revision: 183713
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=183713&view=rev
> Log:
> Objective-C [qoi]: Issue better warning when nsstring literal is missing
> the '@'. PR16287 and // rdar://14106083
> 
> Modified:
>    cfe/trunk/include/clang/Basic/DiagnosticGroups.td
>    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>    cfe/trunk/lib/Sema/SemaExpr.cpp
>    cfe/trunk/test/FixIt/fixit-objc.m
> 
> Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=183713&r1=183712&r2=183713&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Mon Jun 10 18:51:51 2013
> @@ -539,8 +539,10 @@ def ObjCCocoaAPI : DiagGroup<"objc-cocoa
>   ]>;
> 
> def ObjCStringComparison : DiagGroup<"objc-string-compare">;
> +def ObjCLiteralMissingAtSign : DiagGroup<"objc-literal-missing-atsign">;
> def ObjCLiteralComparison : DiagGroup<"objc-literal-compare", [
> -    ObjCStringComparison
> +    ObjCStringComparison,
> +    ObjCLiteralMissingAtSign
>   ]>;
> 
> // Inline ASM warnings.
> 
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=183713&r1=183712&r2=183713&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Jun 10 18:51:51 2013
> @@ -1879,6 +1879,8 @@ def warn_objc_literal_comparison : Warni
>   "direct comparison of %select{an array literal|a dictionary literal|"
>   "a numeric literal|a boxed expression|}0 has undefined behavior">,
>   InGroup<ObjCLiteralComparison>;
> +def warn_missing_atsign_prefix : Warning<
> +  "string literal must be prefixed by '@' ">, InGroup<ObjCLiteralMissingAtSign>;
> def warn_objc_string_literal_comparison : Warning<
>   "direct comparison of a string literal has undefined behavior">, 
>   InGroup<ObjCStringComparison>;
> 
> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=183713&r1=183712&r2=183713&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Jun 10 18:51:51 2013
> @@ -10195,7 +10195,8 @@ ExprResult Sema::ActOnGNUNullExpr(Source
> }
> 
> static void MakeObjCStringLiteralFixItHint(Sema& SemaRef, QualType DstType,
> -                                           Expr *SrcExpr, FixItHint &Hint) {
> +                                           Expr *SrcExpr, FixItHint &Hint,
> +                                           bool &IsNSString) {
>   if (!SemaRef.getLangOpts().ObjC1)
>     return;
> 
> @@ -10209,6 +10210,7 @@ static void MakeObjCStringLiteralFixItHi
>     const ObjCInterfaceDecl *ID = PT->getInterfaceDecl();
>     if (!ID || !ID->getIdentifier()->isStr("NSString"))
>       return;
> +    IsNSString = true;
>   }
> 
>   // Ignore any parens, implicit casts (should only be
> @@ -10242,6 +10244,7 @@ bool Sema::DiagnoseAssignmentResult(Assi
>   ConversionFixItGenerator ConvHints;
>   bool MayHaveConvFixit = false;
>   bool MayHaveFunctionDiff = false;
> +  bool IsNSString = false;
> 
>   switch (ConvTy) {
>   case Compatible:
> @@ -10259,7 +10262,7 @@ bool Sema::DiagnoseAssignmentResult(Assi
>     MayHaveConvFixit = true;
>     break;
>   case IncompatiblePointer:
> -    MakeObjCStringLiteralFixItHint(*this, DstType, SrcExpr, Hint);
> +    MakeObjCStringLiteralFixItHint(*this, DstType, SrcExpr, Hint, IsNSString);
>     DiagKind = diag::ext_typecheck_convert_incompatible_pointer;
>     CheckInferredResultType = DstType->isObjCObjectPointerType() &&
>       SrcType->isObjCObjectPointerType();
> @@ -10270,6 +10273,8 @@ bool Sema::DiagnoseAssignmentResult(Assi
>       SrcType = SrcType.getUnqualifiedType();
>       DstType = DstType.getUnqualifiedType();
>     }
> +    else if (IsNSString && !Hint.isNull())
> +      DiagKind = diag::warn_missing_atsign_prefix;
>     MayHaveConvFixit = true;
>     break;
>   case IncompatiblePointerSign:
> 
> Modified: cfe/trunk/test/FixIt/fixit-objc.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit-objc.m?rev=183713&r1=183712&r2=183713&view=diff
> ==============================================================================
> --- cfe/trunk/test/FixIt/fixit-objc.m (original)
> +++ cfe/trunk/test/FixIt/fixit-objc.m Mon Jun 10 18:51:51 2013
> @@ -27,13 +27,13 @@ void g(NSString *a); // expected-note{{p
> void h(id a); // expected-note 2{{passing argument to parameter 'a' here}}
> 
> void f(Test *t) {
> -  NSString *a = "Foo"; // expected-warning {{incompatible pointer types initializing 'NSString *' with an expression of type 'char [4]'}}
> +  NSString *a = "Foo"; // expected-warning {{string literal must be prefixed by '@'}}
>   id b = "Foo"; // expected-warning {{incompatible pointer types initializing 'id' with an expression of type 'char [4]'}}
> -  g("Foo"); // expected-warning{{incompatible pointer types passing 'char [4]' to parameter of type 'NSString *'}}
> +  g("Foo"); // expected-warning {{string literal must be prefixed by '@'}}
>   h("Foo"); // expected-warning{{incompatible pointer types passing 'char [4]' to parameter of type 'id'}}
>   h(("Foo")); // expected-warning{{incompatible pointer types passing 'char [4]' to parameter of type 'id'}}
> -  [t test:"Foo"]; // expected-warning{{incompatible pointer types sending 'char [4]' to parameter of type 'NSString *'}}
> -  t.property = "Foo"; // expected-warning{{incompatible pointer types assigning to 'NSString *' from 'char [4]'}}
> +  [t test:"Foo"]; // expected-warning {{string literal must be prefixed by '@'}}
> +  t.property = "Foo"; // expected-warning {{string literal must be prefixed by '@'}}
> 
>   // <rdar://problem/6896493>
>   [t test:@"Foo"]]; // expected-error{{extraneous ']' before ';'}}
> 
> 
> _______________________________________________
> 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/20130610/e7d7f0c1/attachment.html>


More information about the cfe-commits mailing list