"incompatible integer to pointer conversion %2 %1, expected %0">;
def ext_typecheck_convert_pointer_void_func : Extension<
"%2 %1 converts between void* and function pointer, expected %0">;
+def ext_typecheck_convert_incompatible_pointer_sign : ExtWarn<
+ "pointer types point to integer types with different sign %2 %1, expected %0">;
def ext_typecheck_convert_incompatible_pointer : ExtWarn<
"incompatible pointer types %2 %1, expected %0">;
def ext_typecheck_convert_discards_qualifiers : ExtWarn<
/// IncompatiblePointer - The assignment is between two pointers types that
/// are not compatible, but we accept them as an extension.
IncompatiblePointer,
-
+
+ /// IncompatiblePointer - The assignment is between two pointers types which
+ /// point to integers which have a different sign, but are otherwise identical.
+ /// This is a subset of the above, but broken out because it's by far the most
+ /// common case of incompatible pointers.
+ IncompatiblePointerSign,
+
/// CompatiblePointerDiscardsQualifiers - The assignment discards
/// c/v/r qualifiers, which we accept as an extension.
CompatiblePointerDiscardsQualifiers,
}
// C99 6.5.16.1p1 (constraint 3): both operands are pointers to qualified or
// unqualified versions of compatible types, ...
- if (!Context.typesAreCompatible(lhptee.getUnqualifiedType(),
- rhptee.getUnqualifiedType()))
- return IncompatiblePointer; // this "trumps" PointerAssignDiscardsQualifiers
+ lhptee = lhptee.getUnqualifiedType();
+ rhptee = rhptee.getUnqualifiedType();
+ if (!Context.typesAreCompatible(lhptee, rhptee)) {
+ // Check if the pointee types are compatible ignoring the sign.
+ // We explicitly check for char so that we catch "char" vs
+ // "unsigned char" on systems where "char" is unsigned.
+ if (lhptee->isCharType()) {
+ lhptee = Context.UnsignedCharTy;
+ } else if (lhptee->isSignedIntegerType()) {
+ lhptee = Context.getCorrespondingUnsignedType(lhptee);
+ }
+ if (rhptee->isCharType()) {
+ rhptee = Context.UnsignedCharTy;
+ } else if (rhptee->isSignedIntegerType()) {
+ rhptee = Context.getCorrespondingUnsignedType(rhptee);
+ }
+ if (lhptee == rhptee) {
+ // Types are compatible ignoring the sign. Qualifier incompatibility
+ // takes priority over sign incompatibility because the sign
+ // warning can be disabled.
+ if (ConvTy != Compatible)
+ return ConvTy;
+ return IncompatiblePointerSign;
+ }
+ // General pointer incompatibility takes priority over qualifiers.
+ return IncompatiblePointer;
+ }
return ConvTy;
}
case IncompatiblePointer:
DiagKind = diag::ext_typecheck_convert_incompatible_pointer;
break;
+ case IncompatiblePointerSign:
+ DiagKind = diag::ext_typecheck_convert_incompatible_pointer_sign;
+ break;
case FunctionVoidPointer:
DiagKind = diag::ext_typecheck_convert_pointer_void_func;
break;