]> granicus.if.org Git - clang/commitdiff
add comments for the various AssignConvertType's, and split int->pointer from pointer...
authorChris Lattner <sabre@nondot.org>
Fri, 4 Jan 2008 18:22:42 +0000 (18:22 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 4 Jan 2008 18:22:42 +0000 (18:22 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45591 91177308-0d34-0410-b5e6-96231b3b80d8

Sema/Sema.h
Sema/SemaExpr.cpp
include/clang/Basic/DiagnosticKinds.def
test/Parser/implicit-casts.c
test/Sema/argument-checking.m
test/Sema/array-init.c
test/Sema/builtins.c
test/Sema/objc-comptypes-7.m

index e790a74251cc61a93ab84e35c43874cbaac386da..d8871d2a38a4d212456f5eabb82653359122c39c 100644 (file)
@@ -613,13 +613,39 @@ private:
   // responsible for emitting appropriate error diagnostics.
   QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr,
                                       bool isCompAssign = false);
+  
+  /// AssignConvertType - All of the 'assignment' semantic checks return this
+  /// enum to indicate whether the assignment was allowed.  These checks are
+  /// done for simple assignments, as well as initialization, return from
+  /// function, argument passing, etc.  The query is phrased in terms of a
+  /// source and destination type.
   enum AssignConvertType {
+    /// Compatible - the types are compatible according to the standard.
     Compatible,
-    Incompatible,
-    PointerInt, 
+    
+    /// PointerToInt - The assignment converts a pointer to an int, which we
+    /// accept as an extension.
+    PointerToInt,
+    
+    /// IntToPointer - The assignment converts an int to a pointer, which we
+    /// accept as an extension.
+    IntToPointer,
+    
+    /// FunctionVoidPointer - The assignment is between a function pointer and
+    /// void*, which the standard doesn't allow, but we accept as an extension.
     FunctionVoidPointer,
+
+    /// IncompatiblePointer - The assignment is between two pointers types that
+    /// are not compatible, but we accept them as an extension.
     IncompatiblePointer,
-    CompatiblePointerDiscardsQualifiers
+    
+    /// CompatiblePointerDiscardsQualifiers - The assignment discards
+    /// c/v/r qualifiers, which we accept as an extension.
+    CompatiblePointerDiscardsQualifiers,
+    
+    /// Incompatible - We reject this conversion outright, it is invalid to
+    /// represent it in the AST.
+    Incompatible
   };
   
   /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the
index 7ed0bf102a6da37f4e60a57ddd8bdfed88fbaacf..d41e2198c3ae01c2b0c0212980aec28018501b52 100644 (file)
@@ -1087,8 +1087,6 @@ Sema::CheckPointerTypesForAssignment(QualType lhsType, QualType rhsType) {
 ///
 Sema::AssignConvertType
 Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) {
-
-  
   if (lhsType.getCanonicalType().getUnqualifiedType() == 
       rhsType.getCanonicalType().getUnqualifiedType())
     return Compatible; // common case, fast path...
@@ -1131,14 +1129,14 @@ Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) {
     return Compatible;
   } else if (lhsType->isPointerType()) {
     if (rhsType->isIntegerType())
-      return PointerInt;
+      return IntToPointer;
       
     if (rhsType->isPointerType())
       return CheckPointerTypesForAssignment(lhsType, rhsType);
   } else if (rhsType->isPointerType()) {
     // C99 6.5.16.1p1: the left operand is _Bool and the right is a pointer.
     if ((lhsType->isIntegerType()) && (lhsType != Context.BoolTy))
-      return PointerInt;
+      return PointerToInt;
 
     if (lhsType->isPointerType()) 
       return CheckPointerTypesForAssignment(lhsType, rhsType);
@@ -2139,9 +2137,12 @@ bool Sema::DiagnoseAssignmentResult(AssignConvertType ConvTy,
   switch (ConvTy) {
   default: assert(0 && "Unknown conversion type");
   case Compatible: return false;
-  case PointerInt:
+  case PointerToInt:
     DiagKind = diag::ext_typecheck_convert_pointer_int;
     break;
+  case IntToPointer:
+    DiagKind = diag::ext_typecheck_convert_int_pointer;
+    break;
   case IncompatiblePointer:
     DiagKind = diag::ext_typecheck_convert_incompatible_pointer;
     break;
index 891d9317e0ff92baeb897385e8d9ec528a96f2d6..97d58382afa6cc85e15e388e560e62763c8db98e 100644 (file)
@@ -768,7 +768,9 @@ DIAG(err_typecheck_assign_const, ERROR,
 DIAG(err_typecheck_convert_incompatible, ERROR,
      "incompatible type %2 '%1', expected '%0'")
 DIAG(ext_typecheck_convert_pointer_int, EXTENSION,
-     "incompatible pointer/int conversion %2 '%1', expected '%0'")
+     "incompatible pointer to integer conversion %2 '%1', expected '%0'")
+DIAG(ext_typecheck_convert_int_pointer, EXTENSION,
+     "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,
index 3d055263bcb91dfb04f5921485dd3d141512aa65..1636f4993e457a0cf2a7f592d1513eea5a612b22 100644 (file)
@@ -14,7 +14,7 @@ void test2() {
 }
 int test3() {
   int a[2];
-  a[0] = test3; // expected-warning{{incompatible pointer/int conversion assigning 'int (void)', expected 'int'}}
+  a[0] = test3; // expected-warning{{incompatible pointer to integer conversion assigning 'int (void)', expected 'int'}}
 }
 short x; void test4(char c) { x += c; }
 int y; void test5(char c) { y += c; }
index cd84171ee73e77d986f6263eecc5c774dbf6da82..45eba87804aa203e922fc3ec8497ed894e40fbea 100644 (file)
@@ -16,10 +16,10 @@ void test() {
   id obj = [Test alloc];
   struct S sInst;
 
-  charStarFunc(1); // expected-warning {{incompatible pointer/int conversion passing 'int', expected 'char *'}}
-  charFunc("abc"); // expected-warning {{incompatible pointer/int conversion passing 'char *', expected 'char'}}
+  charStarFunc(1); // expected-warning {{incompatible integer to pointer conversion passing 'int', expected 'char *'}}
+  charFunc("abc"); // expected-warning {{incompatible pointer to integer conversion passing 'char *', expected 'char'}}
 
-  [obj charStarMeth:1]; // expected-warning {{incompatible pointer/int conversion sending 'int'}}
+  [obj charStarMeth:1]; // expected-warning {{incompatible integer to pointer conversion sending 'int'}}
   [obj structMeth:1]; // expected-error {{incompatible type sending 'int'}}
   [obj structMeth:sInst :1]; // expected-error {{incompatible type sending 'int'}}
 }
index 1875fab3890186e2a53e950f1196bfa8ebc74de5..af4b04b7253fd05b06e5ed7bea2f0f9ac7302951 100644 (file)
@@ -9,7 +9,7 @@ int ary2[] = { x, y, z }; // expected-error{{initializer element is not constant
 
 extern int fileScopeExtern[3] = { 1, 3, 5 }; // expected-warning{{'extern' variable has an initializer}}
 
-static int ary3[] = { 1, "abc", 3, 4 }; // expected-warning{{incompatible pointer/int conversion initializing 'char *', expected 'int'}}
+static int ary3[] = { 1, "abc", 3, 4 }; // expected-warning{{incompatible pointer to integer conversion initializing 'char *', expected 'int'}}
 
 void func() {
   int x = 1;
@@ -44,11 +44,11 @@ void func() {
     int a,b,c;
   } z = { 1 };
 
-  struct threeElements *p = 7; // expected-warning{{incompatible pointer/int conversion initializing 'int', expected 'struct threeElements *'}}
+  struct threeElements *p = 7; // expected-warning{{incompatible integer to pointer conversion initializing 'int', expected 'struct threeElements *'}}
   
   extern int blockScopeExtern[3] = { 1, 3, 5 }; // expected-error{{'extern' variable cannot have an initializer}}
   
-  static int x2[3] = { 1.0, "abc" , 5.8 }; // expected-warning{{incompatible pointer/int conversion initializing 'char *', expected 'int'}}
+  static int x2[3] = { 1.0, "abc" , 5.8 }; // expected-warning{{incompatible pointer to integer conversion initializing 'char *', expected 'int'}}
 }
 
 void test() {
index 59a339ad45b01bd9ad43122ff1ed01cda17de09a..ca3cbaf8dcaf3f5c278d990ad11fa45dd0adee71 100644 (file)
@@ -26,7 +26,7 @@ int test6(float a, long double b) {
 void cfstring() {
   CFSTR("\242"); // expected-warning {{ CFString literal contains non-ASCII character }}
   CFSTR("\0"); // expected-warning {{ CFString literal contains NUL character }}
-  CFSTR(242); // expected-error {{ CFString literal is not a string constant }} expected-warning {{incompatible pointer/int conversion}}
+  CFSTR(242); // expected-error {{ CFString literal is not a string constant }} expected-warning {{incompatible integer to pointer conversion}}
   CFSTR("foo", "bar"); // expected-error {{ error: too many arguments to function }}
 }
 
index 9d8f211da65721fd4fca10a8590f8025523394e8..3e6a9d343465ff9a58b44a30975d814162e1fdd0 100644 (file)
@@ -23,22 +23,22 @@ int main()
 
   /* These should all generate warnings.  */
   
-  obj = i; // expected-warning {{incompatible pointer/int conversion assigning 'int', expected 'id'}}
+  obj = i; // expected-warning {{incompatible integer to pointer conversion assigning 'int', expected 'id'}}
   obj = j; // expected-warning {{incompatible pointer types assigning 'int *', expected 'id'}}
 
   obj_p = i; // expected-error {{incompatible type assigning 'int', expected 'id<MyProtocol>' }}
   obj_p = j; // expected-error {{incompatible type assigning 'int *', expected 'id<MyProtocol>'}}
   
-  obj_c = i; // expected-warning {{incompatible pointer/int conversion assigning 'int', expected 'MyClass *'}}
+  obj_c = i; // expected-warning {{incompatible integer to pointer conversion assigning 'int', expected 'MyClass *'}}
   obj_c = j; // expected-warning {{incompatible pointer types assigning 'int *', expected 'MyClass *'}}
 
-  obj_C = i; // expected-warning {{incompatible pointer/int conversion assigning 'int', expected 'Class'}}
+  obj_C = i; // expected-warning {{incompatible integer to pointer conversion assigning 'int', expected 'Class'}}
   obj_C = j; // expected-warning {{incompatible pointer types assigning 'int *', expected 'Class'}}
   
-  i = obj;   // expected-warning {{incompatible pointer/int conversion assigning 'id', expected 'int'}}
+  i = obj;   // expected-warning {{incompatible pointer to integer conversion assigning 'id', expected 'int'}}
   i = obj_p; // expected-error {{incompatible type assigning 'id<MyProtocol>', expected 'int'}}
-  i = obj_c; // expected-warning {{incompatible pointer/int conversion assigning 'MyClass *', expected 'int'}}
-  i = obj_C; // expected-warning {{incompatible pointer/int conversion assigning 'Class', expected 'int'}}
+  i = obj_c; // expected-warning {{incompatible pointer to integer conversion assigning 'MyClass *', expected 'int'}}
+  i = obj_C; // expected-warning {{incompatible pointer to integer conversion assigning 'Class', expected 'int'}}
   
   j = obj;   // expected-warning {{incompatible pointer types assigning 'id', expected 'int *'}}
   j = obj_p; // expected-error {{incompatible type assigning 'id<MyProtocol>', expected 'int *'}}