]> granicus.if.org Git - clang/commitdiff
Diagnose ++/-- op on objc pointers in
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 16 Jul 2009 17:59:14 +0000 (17:59 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 16 Jul 2009 17:59:14 +0000 (17:59 +0000)
nonfragile abi, instead of crashing.

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

lib/Sema/SemaExpr.cpp
test/SemaObjC/sizeof-interface.m

index 4b3f40aa937cf71448e6e0de884aae5b3205a6d2..1304558042808a5a37e656644da6412fe8672427 100644 (file)
@@ -4603,6 +4603,12 @@ QualType Sema::CheckIncrementDecrementOperand(Expr *Op, SourceLocation OpLoc,
                                    Op->getSourceRange(), SourceRange(),
                                    ResType))
       return QualType();
+    // Diagnose bad cases where we step over interface counts.
+    else if (PointeeTy->isObjCInterfaceType() && LangOpts.ObjCNonFragileABI) {
+      Diag(OpLoc, diag::err_arithmetic_nonfragile_interface)
+        << PointeeTy << Op->getSourceRange();
+      return QualType();
+    }
   } else if (ResType->isComplexType()) {
     // C99 does not support ++/-- on complex types, we allow as an extension.
     Diag(OpLoc, diag::ext_integer_increment_complex)
index 75d7daafbbcc278cb8f7dbfc882361ccc51e0f7e..140a980311e4eeaa68af5b07dcb6675674d2f5a4 100644 (file)
@@ -77,3 +77,14 @@ int bar(I0 *P) {
 }
 @end
 
+
+@interface Foo @end
+
+int foo()
+{
+  Foo *f;
+  
+  // Both of these crash clang nicely
+  ++f;         // expected-error {{arithmetic on pointer to interface 'Foo', which is not a constant size in non-fragile ABI}}
+  --f;         // expected-error {{arithmetic on pointer to interface 'Foo', which is not a constant size in non-fragile ABI}}
+}