[cfe-commits] r77453 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaObjC/conditional-expr-4.m
Steve Naroff
snaroff at apple.com
Wed Jul 29 08:09:54 PDT 2009
Author: snaroff
Date: Wed Jul 29 10:09:39 2009
New Revision: 77453
URL: http://llvm.org/viewvc/llvm-project?rev=77453&view=rev
Log:
Fix <rdar://problem/7100524> regression: "error: incompatible operand types ('void *' and 'NSString *')".
Remove XFAIL from 'conditional-expr-4.m' test case (which would have caught this).
Also tweaked several aspects of the test to jive with the current type checking.
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaObjC/conditional-expr-4.m
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=77453&r1=77452&r2=77453&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Jul 29 10:09:39 2009
@@ -3206,6 +3206,25 @@
ImpCastExprToType(RHS, compositeType);
return compositeType;
}
+ // Check Objective-C object pointer types and 'void *'
+ if (LHSTy->isVoidPointerType() && RHSTy->isObjCObjectPointerType()) {
+ QualType lhptee = LHSTy->getAsPointerType()->getPointeeType();
+ QualType rhptee = RHSTy->getAsObjCObjectPointerType()->getPointeeType();
+ QualType destPointee = lhptee.getQualifiedType(rhptee.getCVRQualifiers());
+ QualType destType = Context.getPointerType(destPointee);
+ ImpCastExprToType(LHS, destType); // add qualifiers if necessary
+ ImpCastExprToType(RHS, destType); // promote to void*
+ return destType;
+ }
+ if (LHSTy->isObjCObjectPointerType() && RHSTy->isVoidPointerType()) {
+ QualType lhptee = LHSTy->getAsObjCObjectPointerType()->getPointeeType();
+ QualType rhptee = RHSTy->getAsPointerType()->getPointeeType();
+ QualType destPointee = rhptee.getQualifiedType(lhptee.getCVRQualifiers());
+ QualType destType = Context.getPointerType(destPointee);
+ ImpCastExprToType(RHS, destType); // add qualifiers if necessary
+ ImpCastExprToType(LHS, destType); // promote to void*
+ return destType;
+ }
// Check constraints for C object pointers types (C99 6.5.15p3,6).
if (LHSTy->isPointerType() && RHSTy->isPointerType()) {
// get the "pointed to" types
Modified: cfe/trunk/test/SemaObjC/conditional-expr-4.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/conditional-expr-4.m?rev=77453&r1=77452&r2=77453&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/conditional-expr-4.m (original)
+++ cfe/trunk/test/SemaObjC/conditional-expr-4.m Wed Jul 29 10:09:39 2009
@@ -1,5 +1,4 @@
-// RUN: clang-cc -fsyntax-only %s
-// XFAIL
+// RUN: clang-cc -fsyntax-only -verify %s
// <rdar://problem/6212771>
#define nil ((void*) 0)
@@ -26,6 +25,11 @@
return cond ? a : nil;
}
+void *f1_const_a(int x, void *p, const A * q) {
+ void *r = x ? p : q; // expected-warning{{initializing 'void const *' discards qualifiers, expected 'void *'}}
+ return r;
+}
+
// Check interaction with qualified id
@protocol P0 @end
@@ -48,9 +52,7 @@
@end
int f5(int cond, id<P1> a, id<P1> b) {
- // This should result in something with id type, currently. This is
- // almost certainly wrong and should be fixed.
- return (cond ? a : b).x; // expected-error {{member reference base type ('id') is not a structure or union}}
+ return (cond ? a : b).x;
}
int f5_a(int cond, A *a, A *b) {
return (cond ? a : b).x;
@@ -61,7 +63,7 @@
int f6(int cond, id<P1> a, void *b) {
// This should result in something with id type, currently.
- return (cond ? a : b).x; // expected-error {{member reference base type ('id') is not a structure or union}}
+ return (cond ? a : b).x; // expected-error {{member reference base type 'void *' is not a structure or union}}
}
int f7(int cond, id<P1> a) {
@@ -69,10 +71,10 @@
}
int f8(int cond, id<P1> a, A *b) {
- // GCC regards this as a warning (comparison of distinct Objective-C types lacks a cast)
- return a == b; // expected-error {{invalid operands to binary expression}}
+ return a == b; // expected-warning {{comparison of distinct pointer types ('id<P1>' and 'A *')}}
}
int f9(int cond, id<P1> a, A *b) {
- return (cond ? a : b).x; // expected-error {{incompatible operand types}}
+ return (cond ? a : b).x; // expected-warning {{incompatible operand types ('id<P1>' and 'A *')}} \
+ expected-error {{property 'x' not found on object of type 'id'}}
}
More information about the cfe-commits
mailing list