summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2009-07-16 17:59:14 +0000
committerFariborz Jahanian <fjahanian@apple.com>2009-07-16 17:59:14 +0000
commitca75db7c02c7c452cde8c8f56c898dff1c1b3e95 (patch)
treec15d41be3581e6052bffbb34c9e67dfb0c7641f0
parentdd27e5e10a88ab6db82d553109a65a0cb4f7e54b (diff)
downloadbcm5719-llvm-ca75db7c02c7c452cde8c8f56c898dff1c1b3e95.tar.gz
bcm5719-llvm-ca75db7c02c7c452cde8c8f56c898dff1c1b3e95.zip
Diagnose ++/-- op on objc pointers in
nonfragile abi, instead of crashing. llvm-svn: 76088
-rw-r--r--clang/lib/Sema/SemaExpr.cpp6
-rw-r--r--clang/test/SemaObjC/sizeof-interface.m11
2 files changed, 17 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 4b3f40aa937..13045580428 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -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)
diff --git a/clang/test/SemaObjC/sizeof-interface.m b/clang/test/SemaObjC/sizeof-interface.m
index 75d7daafbbc..140a980311e 100644
--- a/clang/test/SemaObjC/sizeof-interface.m
+++ b/clang/test/SemaObjC/sizeof-interface.m
@@ -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}}
+}
OpenPOWER on IntegriCloud