[cfe-commits] r76088 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaObjC/sizeof-interface.m
Fariborz Jahanian
fjahanian at apple.com
Thu Jul 16 10:59:14 PDT 2009
Author: fjahanian
Date: Thu Jul 16 12:59:14 2009
New Revision: 76088
URL: http://llvm.org/viewvc/llvm-project?rev=76088&view=rev
Log:
Diagnose ++/-- op on objc pointers in
nonfragile abi, instead of crashing.
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaObjC/sizeof-interface.m
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=76088&r1=76087&r2=76088&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Jul 16 12:59:14 2009
@@ -4603,6 +4603,12 @@
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)
Modified: cfe/trunk/test/SemaObjC/sizeof-interface.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/sizeof-interface.m?rev=76088&r1=76087&r2=76088&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/sizeof-interface.m (original)
+++ cfe/trunk/test/SemaObjC/sizeof-interface.m Thu Jul 16 12:59:14 2009
@@ -77,3 +77,14 @@
}
@end
+
+ at 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}}
+}
More information about the cfe-commits
mailing list