Skip to content

Commit fbf915f

Browse files
committed
Add a FIXME and corresponding test coverage for some suspicious behavior
forming composite ObjC pointer types in comparisons.
1 parent f4df7f4 commit fbf915f

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

clang/lib/Sema/SemaExpr.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11055,6 +11055,9 @@ QualType Sema::CheckCompareOperands(ExprResult &LHS, ExprResult &RHS,
1105511055
diagnoseDistinctPointerComparison(*this, Loc, LHS, RHS,
1105611056
/*isError*/false);
1105711057
}
11058+
// FIXME: If LPtrToVoid, we should presumably convert the LHS rather than
11059+
// the RHS, but we have test coverage for this behavior.
11060+
// FIXME: Consider using convertPointersToCompositeType in C++.
1105811061
if (LHSIsNull && !RHSIsNull) {
1105911062
Expr *E = LHS.get();
1106011063
if (getLangOpts().ObjCAutoRefCount)

clang/test/SemaObjC/arc.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ void test11(id op, void *vp) {
295295
b = (vp == nil);
296296
b = (nil == vp);
297297

298+
// FIXME: Shouldn't these be consistent?
298299
b = (vp == op); // expected-error {{implicit conversion of Objective-C pointer type 'id' to C pointer type 'void *' requires a bridged cast}} expected-note {{use __bridge}} expected-note {{use CFBridgingRetain call}}
299300
b = (op == vp);
300301
}

clang/test/SemaObjCXX/arc-ptr-comparison.mm

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,32 @@ int testObjCComparisonRules(void *v, id x, id y) {
2222
return v == (void *)0;
2323
return x == y;
2424
}
25+
26+
@class A;
27+
28+
int testMixedQualComparisonRules(void *v, const void *cv, A *a, const A *ca) {
29+
return cv == ca;
30+
#ifndef NOARC
31+
// expected-error@-2 {{implicit conversion of Objective-C pointer type 'const A *' to C pointer type 'const void *' requires a bridged cast}}
32+
// expected-note@-3 {{use __bridge to convert directly (no change in ownership)}}
33+
// expected-note@-4 {{use __bridge_retained to make an ARC object available as a +1 'const void *'}}
34+
#endif
35+
// FIXME: The "to" type in this diagnostic is wrong; we should convert to "const void *".
36+
return v == ca;
37+
#ifndef NOARC
38+
// expected-error@-2 {{implicit conversion of Objective-C pointer type 'const A *' to C pointer type 'void *' requires a bridged cast}}
39+
// expected-note@-3 {{use __bridge to convert directly (no change in ownership)}}
40+
// expected-note@-4 {{use __bridge_retained to make an ARC object available as a +1 'void *'}}
41+
#endif
42+
return cv == a;
43+
#ifndef NOARC
44+
// expected-error@-2 {{implicit conversion of Objective-C pointer type 'A *' to C pointer type 'const void *' requires a bridged cast}}
45+
// expected-note@-3 {{use __bridge to convert directly (no change in ownership)}}
46+
// expected-note@-4 {{use __bridge_retained to make an ARC object available as a +1 'const void *'}}
47+
#endif
48+
49+
// FIXME: Shouldn't these be rejected in ARC mode too?
50+
return ca == cv;
51+
return a == cv;
52+
return ca == v;
53+
}

0 commit comments

Comments
 (0)