]> granicus.if.org Git - clang/commitdiff
[ubsan] array-bounds: Ignore params with constant size
authorVedant Kumar <vsk@apple.com>
Fri, 8 Dec 2017 19:51:42 +0000 (19:51 +0000)
committerVedant Kumar <vsk@apple.com>
Fri, 8 Dec 2017 19:51:42 +0000 (19:51 +0000)
This is a follow-up to r320128. Eli pointed out that there is some gray
area in the language standard about whether the constant size is exact,
or a lower bound.

https://reviews.llvm.org/D40940

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

lib/CodeGen/CGExpr.cpp
test/CodeGen/ubsan-pass-object-size.c

index 64af2096c98c9f838234c6d0d88f34764e7ff67f..c61bc0d642252332c32d9ca3ea46c645afafc58e 100644 (file)
@@ -829,14 +829,6 @@ llvm::Value *CodeGenFunction::LoadPassedObjectSize(const Expr *E,
   if (!ParamDecl)
     return nullptr;
 
-  // Arrays don't have pass_object_size attributes, but if they have a constant
-  // size modifier it's the array size (C99 6.5.7.2p1).
-  if (auto *DecayedArrayTy = dyn_cast<DecayedType>(ParamDecl->getType()))
-    if (auto *ArrayTy =
-            dyn_cast<ConstantArrayType>(DecayedArrayTy->getOriginalType()))
-      return llvm::ConstantInt::get(SizeTy,
-                                    ArrayTy->getSize().getLimitedValue());
-
   auto *POSAttr = ParamDecl->getAttr<PassObjectSizeAttr>();
   if (!POSAttr)
     return nullptr;
index 67970d2918af0d030be907b263486a03fc994256..d5d4f5a9e421e897b45d0f9654a1ce812991d126 100644 (file)
@@ -55,8 +55,7 @@ int pat(int *const p __attribute__((pass_object_size(3))), int n) {
 
 // CHECK-LABEL: define i32 @cat(
 int cat(int p[static 10], int n) {
-  // CHECK: icmp ult i64 {{.*}}, 10, !nosanitize
-  // CHECK: __ubsan_handle_out_of_bounds
+  // CHECK-NOT: __ubsan_handle_out_of_bounds
   // CHECK: ret i32
   return p[n];
 }