]> granicus.if.org Git - clang/commitdiff
In debugger mode, allow comparisons between pointers and integers
authorDouglas Gregor <dgregor@apple.com>
Fri, 14 Sep 2012 04:35:37 +0000 (04:35 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 14 Sep 2012 04:35:37 +0000 (04:35 +0000)
without a cast. Fixes <rdar://problem/11830912>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163873 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/SemaObjCXX/debugger-support.mm [new file with mode: 0644]

index cfa9ccbfc3347bf88cd397038971d54e091eda47..3d143c8097fae77de8433cc9e27bf5a6d017412f 100644 (file)
@@ -7214,7 +7214,10 @@ QualType Sema::CheckCompareOperands(ExprResult &LHS, ExprResult &RHS,
       (LHSType->isIntegerType() && RHSType->isAnyPointerType())) {
     unsigned DiagID = 0;
     bool isError = false;
-    if ((LHSIsNull && LHSType->isIntegerType()) ||
+    if (LangOpts.DebuggerSupport) {
+      // Under a debugger, allow the comparison of pointers to integers,
+      // since users tend to want to compare addresses.
+    } else if ((LHSIsNull && LHSType->isIntegerType()) ||
         (RHSIsNull && RHSType->isIntegerType())) {
       if (IsRelational && !getLangOpts().CPlusPlus)
         DiagID = diag::ext_typecheck_ordered_comparison_of_pointer_and_zero;
diff --git a/test/SemaObjCXX/debugger-support.mm b/test/SemaObjCXX/debugger-support.mm
new file mode 100644 (file)
index 0000000..1fb18b9
--- /dev/null
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fdebugger-support -fsyntax-only -verify %s
+
+@class NSString;
+void testCompareAgainstPtr(int *ptr, NSString *ns) {
+  if (ptr == 17) {}
+  if (ns != 42) {}
+}