summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
authorGeorge Burgess IV <george.burgess.iv@gmail.com>2017-02-22 02:35:51 +0000
committerGeorge Burgess IV <george.burgess.iv@gmail.com>2017-02-22 02:35:51 +0000
commit8856aa9a5436b82fdcc9c92f196eba0905708b53 (patch)
tree9de6280dae7b01d175dfb84e1b2f6044a2f90667 /clang/lib/CodeGen
parent38bd8cd04f0ae676b463129986c14ad35a4b3476 (diff)
downloadbcm5719-llvm-8856aa9a5436b82fdcc9c92f196eba0905708b53.tar.gz
bcm5719-llvm-8856aa9a5436b82fdcc9c92f196eba0905708b53.zip
Call the correct @llvm.objectsize.
The following code would crash clang: void foo(unsigned *const __attribute__((pass_object_size(0)))); void bar(unsigned *i) { foo(i); } This is because we were always selecting the version of `@llvm.objectsize` that takes an i8* in CodeGen. Passing an i32* as an i8* makes LLVM very unhappy. (Yes, I'm surprised that this remained uncaught for so long, too. :) ) As an added bonus, we'll now also use the appropriate address space when emitting @llvm.objectsize calls. llvm-svn: 295805
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CGBuiltin.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f8c6f2bc7d6..9f0cfa7db3b 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -460,13 +460,14 @@ CodeGenFunction::emitBuiltinObjectSize(const Expr *E, unsigned Type,
if (Type == 3 || E->HasSideEffects(getContext()))
return getDefaultBuiltinObjectSizeResult(Type, ResType);
- // LLVM only supports 0 and 2, make sure that we pass along that
- // as a boolean.
+ Value *Ptr = EmitScalarExpr(E);
+ assert(Ptr->getType()->isPointerTy() &&
+ "Non-pointer passed to __builtin_object_size?");
+
+ // LLVM only supports 0 and 2, make sure that we pass along that as a boolean.
auto *CI = ConstantInt::get(Builder.getInt1Ty(), (Type & 2) >> 1);
- // FIXME: Get right address space.
- llvm::Type *Tys[] = {ResType, Builder.getInt8PtrTy(0)};
- Value *F = CGM.getIntrinsic(Intrinsic::objectsize, Tys);
- return Builder.CreateCall(F, {EmitScalarExpr(E), CI});
+ Value *F = CGM.getIntrinsic(Intrinsic::objectsize, {ResType, Ptr->getType()});
+ return Builder.CreateCall(F, {Ptr, CI});
}
// Many of MSVC builtins are on both x64 and ARM; to avoid repeating code, we
OpenPOWER on IntegriCloud