[cfe-commits] r137240 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/Sema/array-bounds-ptr-arith.c
Kaelyn Uhrain
rikka at google.com
Wed Aug 10 12:47:25 PDT 2011
Author: rikka
Date: Wed Aug 10 14:47:25 2011
New Revision: 137240
URL: http://llvm.org/viewvc/llvm-project?rev=137240&view=rev
Log:
Add a test case for the divide-by-zero fix in r137234
Added:
cfe/trunk/test/Sema/array-bounds-ptr-arith.c
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=137240&r1=137239&r2=137240&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Aug 10 14:47:25 2011
@@ -3553,6 +3553,7 @@
// Make sure we're comparing apples to apples when comparing index to size
uint64_t ptrarith_typesize = Context.getTypeSize(EffectiveType);
uint64_t array_typesize = Context.getTypeSize(BaseType);
+ // Handle ptrarith_typesize being zero, such as when casting to void*
if (!ptrarith_typesize) ptrarith_typesize = 1;
if (ptrarith_typesize != array_typesize) {
// There's a cast to a different size type involved
Added: cfe/trunk/test/Sema/array-bounds-ptr-arith.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/array-bounds-ptr-arith.c?rev=137240&view=auto
==============================================================================
--- cfe/trunk/test/Sema/array-bounds-ptr-arith.c (added)
+++ cfe/trunk/test/Sema/array-bounds-ptr-arith.c Wed Aug 10 14:47:25 2011
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -verify -Warray-bounds-pointer-arithmetic %s
+
+// Test case from PR10615
+struct ext2_super_block{
+ unsigned char s_uuid[8]; // expected-note {{declared here}}
+};
+void* ext2_statfs (struct ext2_super_block *es,int a)
+{
+ return (void *)es->s_uuid + sizeof(int); // no-warning
+}
+void* broken (struct ext2_super_block *es,int a)
+{
+ return (void *)es->s_uuid + 80; // expected-warning {{refers past the end of the array}}
+}
More information about the cfe-commits
mailing list