]> granicus.if.org Git - clang/commit
Add a new builtin: __builtin_dynamic_object_size
authorErik Pilkington <erik.pilkington@gmail.com>
Wed, 30 Jan 2019 20:34:53 +0000 (20:34 +0000)
committerErik Pilkington <erik.pilkington@gmail.com>
Wed, 30 Jan 2019 20:34:53 +0000 (20:34 +0000)
commitc18e7e9007970a3105617f03bc9d1de89fa1a3e1
treead524e6827cb11bdd0ccad79a4bca9429bfc9474
parent932217bae430fefcb3df6c51c9c7d2dd4970b048
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@352665 91177308-0d34-0410-b5e6-96231b3b80d8
12 files changed:
docs/LanguageExtensions.rst
include/clang/Basic/Builtins.def
lib/AST/ExprConstant.cpp
lib/Analysis/CFG.cpp
lib/CodeGen/CGBuiltin.cpp
lib/CodeGen/CGCall.cpp
lib/CodeGen/CodeGenFunction.h
lib/Sema/SemaChecking.cpp
lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
test/CodeGen/alloc-size.c
test/CodeGen/object-size.c
test/Sema/builtin-object-size.c