aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Pilkington <erik.pilkington@gmail.com>2019-01-30 20:34:53 +0000
committerErik Pilkington <erik.pilkington@gmail.com>2019-01-30 20:34:53 +0000
commit9c3b588db9ddf5582e4d1e3ff931d7b1cac7d8c8 (patch)
tree0439b51ec399448c56ccec56c50257efe0359f47 /clang/lib/Analysis/CFG.cpp
parentAdd a 'dynamic' parameter to the objectsize intrinsic (diff)
downloadllvm-project-9c3b588db9ddf5582e4d1e3ff931d7b1cac7d8c8.tar.gz
llvm-project-9c3b588db9ddf5582e4d1e3ff931d7b1cac7d8c8.tar.bz2
llvm-project-9c3b588db9ddf5582e4d1e3ff931d7b1cac7d8c8.zip
Add a new builtin: __builtin_dynamic_object_size
This builtin has the same UI as __builtin_object_size, but has the potential to be evaluated dynamically. It is meant to be used as a drop-in replacement for libraries that use __builtin_object_size when a dynamic checking mode is enabled. For instance, __builtin_object_size fails to provide any extra checking in the following function: void f(size_t alloc) { char* p = malloc(alloc); strcpy(p, "foobar"); // expands to __builtin___strcpy_chk(p, "foobar", __builtin_object_size(p, 0)) } This is an overflow if alloc < 7, but because LLVM can't fold the object size intrinsic statically, it folds __builtin_object_size to -1. With __builtin_dynamic_object_size, alloc is passed through to __builtin___strcpy_chk. rdar://32212419 Differential revision: https://reviews.llvm.org/D56760 llvm-svn: 352665
Diffstat (limited to 'clang/lib/Analysis/CFG.cpp')
-rw-r--r--clang/lib/Analysis/CFG.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index 0a62ed2c0367..f6b829147b34 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -2458,7 +2458,8 @@ CFGBlock *CFGBuilder::VisitCallExpr(CallExpr *C, AddStmtChoice asc) {
NoReturn = true;
if (FD->hasAttr<NoThrowAttr>())
AddEHEdge = false;
- if (FD->getBuiltinID() == Builtin::BI__builtin_object_size)
+ if (FD->getBuiltinID() == Builtin::BI__builtin_object_size ||
+ FD->getBuiltinID() == Builtin::BI__builtin_dynamic_object_size)
OmitArguments = true;
}