zlaski      02/09/23 15:52:38

  Modified:    gcc      c-common.c c-opts.c flags.h toplev.c
  Added:       gcc/testsuite/objc.dg const-cfstring-2.m
  Log:
  Bug #: 2167085 A flag to warn about non-ascii chars in "..." and @"..." would be nice
  Submitted by: zlaski
  Reviewed by: dalej
  
  Revision  Changes    Path
  1.79      +9 -0      gcc3/gcc/c-common.c
  
  Index: c-common.c
  ===================================================================
  RCS file: /cvs/Darwin/gcc3/gcc/c-common.c,v
  retrieving revision 1.78
  retrieving revision 1.79
  diff -u -r1.78 -r1.79
  --- c-common.c        2002/09/19 21:02:41     1.78
  +++ c-common.c        2002/09/23 22:52:35     1.79
  @@ -6759,6 +6759,15 @@
     int length;
   
     length = TREE_STRING_LENGTH (str) - 1;
  +  if (warn_nonportable_cfstrings)
  +    {
  +      char *s = TREE_STRING_POINTER (str);
  +      int l = 0;
  +      
  +      while (l < length && isascii (s[l])) l++;
  +      if (!isascii (s[l]))
  +     warning ("non-ASCII characters in CFString literal");
  +    }
   
     initlist = build_tree_list
             (NULL_TREE, convert (const_ptr_type_node, 
  
  
  
  1.5       +10 -0     gcc3/gcc/c-opts.c
  
  Index: c-opts.c
  ===================================================================
  RCS file: /cvs/Darwin/gcc3/gcc/c-opts.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- c-opts.c  2002/09/02 03:45:49     1.4
  +++ c-opts.c  2002/09/23 22:52:36     1.5
  @@ -179,6 +179,8 @@
     OPT("Wnon-template-friend",        CL_CXX,   OPT_Wnon_template_friend)          \
     OPT("Wnon-virtual-dtor",   CL_CXX,   OPT_Wnon_virtual_dtor)             \
     OPT("Wnonnull",            CL_C,     OPT_Wnonnull)                      \
  +  /* APPLE LOCAL constant cfstrings */  \
  +  OPT("Wnonportable-cfstrings",      CL_ALL,   OPT_Wnonportable_cfstrings)        \
     OPT("Wold-style-cast",     CL_CXX,   OPT_Wold_style_cast)               \
     OPT("Woverloaded-virtual", CL_CXX,   OPT_Woverloaded_virtual)           \
     OPT("Wparentheses",                CL_ALL,   OPT_Wparentheses)                  \
  @@ -733,6 +735,8 @@
         warn_return_type = on;
         warn_sequence_point = on;      /* Was C only.  */
         warn_sign_compare = on;        /* Was C++ only.  */
  +      /* APPLE LOCAL constant cfstrings */
  +      warn_nonportable_cfstrings = on;
         warn_switch = on;
   
         /* Only warn about unknown pragmas that are not in system
  @@ -877,6 +881,12 @@
         cpp_opts->warn_four_char_constants = on;
         break;
         /* APPLE LOCAL end -Wfour-char-constants */
  +
  +      /* APPLE LOCAL begin constant cfstrings */
  +    case OPT_Wnonportable_cfstrings:
  +      warn_nonportable_cfstrings = on;
  +      break;
  +      /* APPLE LOCAL end constant cfstrings */
   
       case OPT_Wimplicit:
         set_Wimplicit (on);
  
  
  
  1.37      +3 -0      gcc3/gcc/flags.h
  
  Index: flags.h
  ===================================================================
  RCS file: /cvs/Darwin/gcc3/gcc/flags.h,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- flags.h   2002/08/26 20:07:59     1.36
  +++ flags.h   2002/09/23 22:52:36     1.37
  @@ -260,6 +260,9 @@
      available, regardless of the setting of this flag), and (2) use
      the CFString layout to create @"..." strings in ObjC/ObjC++.  */
   extern int flag_constant_cfstrings;
  +/* Nonzero means that we should warn whenever non-ASCII characters appear
  +   inside of @"..." literals (as they may be non-portable).  */
  +extern int warn_nonportable_cfstrings;
   /* APPLE LOCAL end constant cfstrings */
      
   /* Nonzero for -fcaller-saves: allocate values in regs that need to
  
  
  
  1.157     +7 -0      gcc3/gcc/toplev.c
  
  Index: toplev.c
  ===================================================================
  RCS file: /cvs/Darwin/gcc3/gcc/toplev.c,v
  retrieving revision 1.156
  retrieving revision 1.157
  diff -u -r1.156 -r1.157
  --- toplev.c  2002/09/17 22:54:18     1.156
  +++ toplev.c  2002/09/23 22:52:36     1.157
  @@ -476,6 +476,9 @@
      available, regardless of the setting of this flag), and (2) use
      the CFString layout to create @"..." strings in ObjC/ObjC++.  */
   int flag_constant_cfstrings;
  +/* Nonzero means that we should warn whenever non-ASCII characters appear
  +   inside of @"..." literals (as they may be non-portable).  */
  +int warn_nonportable_cfstrings;
   /* APPLE LOCAL end constant cfstrings */
      
   /* Nonzero for -fcaller-saves: allocate values in regs that need to
  @@ -1469,6 +1472,10 @@
     { "-Wfour-char-constants",
       N_("Warn about use of 'abcd' four char literals") },
     { "-Wno-four-char-constants", "" },
  +  /* APPLE LOCAL constant cfstrings  */
  +  { "-Wnonportable-cfstrings",
  +    N_("Warn about use of non-ASCII chars in CFStrings") },
  +  { "-Wno-nonportable-cfstrings", "" },
     { "-Wnested-externs",
       N_("Warn about externs not at file scope level") },
     { "-Wno-nested-externs", "" },
  
  
  
  1.1                  gcc3/gcc/testsuite/objc.dg/const-cfstring-2.m
  
  Index: const-cfstring-2.m
  ===================================================================
  /* APPLE LOCAL file constant cfstrings */
  /* Test the -Wnonportable-cfstrings option, which should give
     warnings if non-ASCII characters are embedded in constant
     CFStrings.  This will only work on MacOS X 10.2 and later.  */
  /* Developed by Ziemowit Laski <[EMAIL PROTECTED]>.  */
  
  /* { dg-do compile { target *-apple-darwin* } } */
  /* { dg-options "-fconstant-cfstrings -Wnonportable-cfstrings" } */
  
  #import <Foundation/NSString.h>
  #import <CoreFoundation/CFString.h>
  
  #ifndef __CONSTANT_CFSTRINGS__
  #error The -fconstant-cfstrings option is not functioning properly
  #endif
  
  void foo(void) {
    NSString *s1 = @"Compile-time string literal";
    CFStringRef s2 = CFSTR("Compile-time string literal");
    NSString *s3 = @"Non-ASCII literal - \222";         /* { dg-warning "non-ASCII 
characters in CFString literal" } */
    CFStringRef s4 = CFSTR("\222 - Non-ASCII literal"); /* { dg-warning "non-ASCII 
characters in CFString literal" } */
    CFStringRef s5 = CFSTR("Non-ASCII (\222) literal"); /* { dg-warning "non-ASCII 
characters in CFString literal" } */
  }
  
  
  


Reply via email to