[cfe-commits] r45591 - in /cfe/trunk: 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
Chris Lattner
sabre at nondot.org
Fri Jan 4 10:22:42 PST 2008
Author: lattner
Date: Fri Jan 4 12:22:42 2008
New Revision: 45591
URL: http://llvm.org/viewvc/llvm-project?rev=45591&view=rev
Log:
add comments for the various AssignConvertType's, and split int->pointer from pointer->int.
Modified:
cfe/trunk/Sema/Sema.h
cfe/trunk/Sema/SemaExpr.cpp
cfe/trunk/include/clang/Basic/DiagnosticKinds.def
cfe/trunk/test/Parser/implicit-casts.c
cfe/trunk/test/Sema/argument-checking.m
cfe/trunk/test/Sema/array-init.c
cfe/trunk/test/Sema/builtins.c
cfe/trunk/test/Sema/objc-comptypes-7.m
Modified: cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.h?rev=45591&r1=45590&r2=45591&view=diff
==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Fri Jan 4 12:22:42 2008
@@ -613,13 +613,39 @@
// 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
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=45591&r1=45590&r2=45591&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Fri Jan 4 12:22:42 2008
@@ -1087,8 +1087,6 @@
///
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 @@
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 @@
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;
Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=45591&r1=45590&r2=45591&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Fri Jan 4 12:22:42 2008
@@ -768,7 +768,9 @@
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,
Modified: cfe/trunk/test/Parser/implicit-casts.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/implicit-casts.c?rev=45591&r1=45590&r2=45591&view=diff
==============================================================================
--- cfe/trunk/test/Parser/implicit-casts.c (original)
+++ cfe/trunk/test/Parser/implicit-casts.c Fri Jan 4 12:22:42 2008
@@ -14,7 +14,7 @@
}
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; }
Modified: cfe/trunk/test/Sema/argument-checking.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/argument-checking.m?rev=45591&r1=45590&r2=45591&view=diff
==============================================================================
--- cfe/trunk/test/Sema/argument-checking.m (original)
+++ cfe/trunk/test/Sema/argument-checking.m Fri Jan 4 12:22:42 2008
@@ -16,10 +16,10 @@
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'}}
}
Modified: cfe/trunk/test/Sema/array-init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/array-init.c?rev=45591&r1=45590&r2=45591&view=diff
==============================================================================
--- cfe/trunk/test/Sema/array-init.c (original)
+++ cfe/trunk/test/Sema/array-init.c Fri Jan 4 12:22:42 2008
@@ -9,7 +9,7 @@
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 @@
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() {
Modified: cfe/trunk/test/Sema/builtins.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/builtins.c?rev=45591&r1=45590&r2=45591&view=diff
==============================================================================
--- cfe/trunk/test/Sema/builtins.c (original)
+++ cfe/trunk/test/Sema/builtins.c Fri Jan 4 12:22:42 2008
@@ -26,7 +26,7 @@
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 }}
}
Modified: cfe/trunk/test/Sema/objc-comptypes-7.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/objc-comptypes-7.m?rev=45591&r1=45590&r2=45591&view=diff
==============================================================================
--- cfe/trunk/test/Sema/objc-comptypes-7.m (original)
+++ cfe/trunk/test/Sema/objc-comptypes-7.m Fri Jan 4 12:22:42 2008
@@ -23,22 +23,22 @@
/* 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 *'}}
More information about the cfe-commits
mailing list