]> granicus.if.org Git - clang/commitdiff
Add EXTWARN Diagnostic class.
authorDaniel Dunbar <daniel@zuster.org>
Tue, 5 Aug 2008 00:07:51 +0000 (00:07 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Tue, 5 Aug 2008 00:07:51 +0000 (00:07 +0000)
 - Like EXTENSION but always generates a warning (even without
   -pedantic).
 - Updated ptr -> int, int -> ptr, and incompatible cast warnings to
   be EXTWARN.
 - Other EXTENSION level diagnostics should be audited for upgrade.
 - Updated several test cases to fix code which produced unanticipated
   warnings.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54335 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticKinds.def
lib/Basic/Diagnostic.cpp
test/Analysis/NSString.m
test/Analysis/dead-stores.c
test/Analysis/null-deref-ps.c
test/Sema/format-strings.c

index e5bbdd372aa503ed112b363a3d4da59c167d1175..7afe5723a4e24787382e993548cf54fb0198c979 100644 (file)
@@ -17,6 +17,9 @@
 //     NOTE      - Informational message.
 //     WARNING   - Warning.
 //     EXTENSION - Notification that an extension to the language is being used.
+//     EXTWARN   - Warning for behaviour that is supported as an extension. This 
+//                 differs from EXTENSION in that the warning is always emitted
+//                 by default.
 //     ERROR     - Error, compilation will stop after parsing completes.
 
 //===----------------------------------------------------------------------===//
@@ -943,15 +946,15 @@ DIAG(err_invalid_non_static_member_use, ERROR,
 // assignment related diagnostics (also for argument passing, returning, etc).
 DIAG(err_typecheck_convert_incompatible, ERROR,
      "incompatible type %2 '%1', expected '%0'")
-DIAG(ext_typecheck_convert_pointer_int, EXTENSION,
+DIAG(ext_typecheck_convert_pointer_int, EXTWARN,
      "incompatible pointer to integer conversion %2 '%1', expected '%0'")
-DIAG(ext_typecheck_convert_int_pointer, EXTENSION,
+DIAG(ext_typecheck_convert_int_pointer, EXTWARN,
      "incompatible integer to pointer conversion %2 '%1', expected '%0'")
 DIAG(ext_typecheck_convert_pointer_void_func, EXTENSION,
      "%2 '%1' converts between void* and function pointer, expected '%0'")
-DIAG(ext_typecheck_convert_incompatible_pointer, EXTENSION,
+DIAG(ext_typecheck_convert_incompatible_pointer, EXTWARN,
      "incompatible pointer types %2 '%1', expected '%0'")
-DIAG(ext_typecheck_convert_discards_qualifiers, EXTENSION,
+DIAG(ext_typecheck_convert_discards_qualifiers, EXTWARN,
      "%2 '%1' discards qualifiers, expected '%0'")
      
 DIAG(err_typecheck_array_not_modifiable_lvalue, ERROR,
index fbf118f27578da653a6f7fb2852af37f7e2e7daa..35d665d1a5c1cdc321779b8d3a0ff54fe2d2bbd3 100644 (file)
@@ -29,7 +29,8 @@ enum {
   NOTE       = 0x01,
   WARNING    = 0x02,
   EXTENSION  = 0x03,
-  ERROR      = 0x04,
+  EXTWARN    = 0x04,
+  ERROR      = 0x05,
   class_mask = 0x07
 };
 
@@ -182,6 +183,8 @@ Diagnostic::Level Diagnostic::getDiagnosticLevel(unsigned DiagID) const {
       DiagClass = WARNING;
     else
       return Ignored;
+  } else if (DiagClass == EXTWARN) {
+    DiagClass = ErrorOnExtensions ? ERROR : WARNING;
   }
   
   // If warnings are globally mapped to ignore or error, do it.
index a85a87aace022e1b4ed96fd3c69f2b196775694a..a56c5b858521838ece99b74835928b7cc88dc29b 100644 (file)
@@ -99,15 +99,16 @@ NSComparisonResult f5(NSString* s, NSStringCompareOptions op, NSRange R) {
   return [s compare:aString options:op range:R locale:0]; // expected-warning {{Argument to 'NSString' method 'compare:options:range:locale:' cannot be nil.}}
 }
 
-NSComparisonResult f6(NSString* s) {
+NSArray *f6(NSString* s) {
   return [s componentsSeparatedByCharactersInSet:0]; // expected-warning {{Argument to 'NSString' method 'componentsSeparatedByCharactersInSet:' cannot be nil.}}
 }
 
 NSString* f7(NSString* s1, NSString* s2, NSString* s3) {
 
-  NSString* s4 = CFStringCreateWithFormat(kCFAllocatorDefault, 0,
-                                          L"%@ %@ (%@)", 
-                                          s1, s2, s3);
+  NSString* s4 = (NSString*)
+    CFStringCreateWithFormat(kCFAllocatorDefault, 0,
+                             (CFStringRef) __builtin___CFStringMakeConstantString("%@ %@ (%@)"), 
+                             s1, s2, s3);
 
   CFRetain(s4);
   return s4; // expected-warning{{leak}}
index 0ca289231b9c042ce1e189e7d322ff092730f59f..6811ece1fe739478322ccf8bdb20555074b674e4 100644 (file)
@@ -54,6 +54,7 @@ int f7(int *p) {
 }
 
 int f8(int *p) {
+  extern int *baz();
   if (p = baz()) // expected-warning{{Although the value}}
     return 1;
   return 0;
index 57e4718fe699f6ef8ac36a8daccf791e54de885d..6da44d0c73fdd9bdc69753cd3d6c9428b546d4b5 100644 (file)
@@ -41,7 +41,7 @@ int f3_b(char* x) {
 
 int f4(int *p) {
   
-  uintptr_t x = p;
+  uintptr_t x = (uintptr_t) p;
   
   if (x)
     return 1;
index c1e690a3b80e3c39b0090eb0895e8ee3896098e2..2d6e719e3ad09f41c20514ba05d4eb40aab9f689 100644 (file)
@@ -61,8 +61,8 @@ void check_wide_string(char* b, ...)
   va_list ap;
   va_start(ap,b);
 
-  printf(L"foo %d",2); // expected-warning {{should not be a wide string}}
-  vasprintf(&b,L"bar %d",ap); // expected-warning {{should not be a wide string}}
+  printf(L"foo %d",2); // expected-warning {{incompatible pointer types}}, expected-warning {{should not be a wide string}}
+  vasprintf(&b,L"bar %d",ap); // expected-warning {{incompatible pointer types}}, expected-warning {{should not be a wide string}}
 }
 
 void check_asterisk_precision_width(int x) {
@@ -71,4 +71,4 @@ void check_asterisk_precision_width(int x) {
   printf("%*d",12,x); // no-warning
   printf("%*d","foo",x); // expected-warning {{field width should have type 'int', but argument has type 'char *'}}
   printf("%.*d","foo",x); // expected-warning {{field precision should have type 'int', but argument has type 'char *'}}
-}
\ No newline at end of file
+}