[cfe-commits] r163873 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaObjCXX/debugger-support.mm

Douglas Gregor dgregor at apple.com
Thu Sep 13 21:35:38 PDT 2012


Author: dgregor
Date: Thu Sep 13 23:35:37 2012
New Revision: 163873

URL: http://llvm.org/viewvc/llvm-project?rev=163873&view=rev
Log:
In debugger mode, allow comparisons between pointers and integers
without a cast. Fixes <rdar://problem/11830912>.

Added:
    cfe/trunk/test/SemaObjCXX/debugger-support.mm
Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=163873&r1=163872&r2=163873&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Sep 13 23:35:37 2012
@@ -7214,7 +7214,10 @@
       (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;

Added: cfe/trunk/test/SemaObjCXX/debugger-support.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/debugger-support.mm?rev=163873&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjCXX/debugger-support.mm (added)
+++ cfe/trunk/test/SemaObjCXX/debugger-support.mm Thu Sep 13 23:35:37 2012
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fdebugger-support -fsyntax-only -verify %s
+
+ at class NSString;
+void testCompareAgainstPtr(int *ptr, NSString *ns) {
+  if (ptr == 17) {}
+  if (ns != 42) {}
+}





More information about the cfe-commits mailing list