From: Benjamin Kramer Date: Sun, 3 Jan 2010 18:18:37 +0000 (+0000) Subject: __builtin_object_size(ptr, type) returns -1 for type = {0,1} if there are any side... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3f27b384801de26ce7efaa395699b42719372f24;p=clang __builtin_object_size(ptr, type) returns -1 for type = {0,1} if there are any side-effects. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92453 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 06afec7675..d49a8216f3 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -989,7 +989,7 @@ bool IntExprEvaluator::VisitCallExpr(const CallExpr *E) { // TODO: Perhaps we should let LLVM lower this? if (E->getArg(0)->HasSideEffects(Info.Ctx)) { - if (E->getArg(1)->EvaluateAsInt(Info.Ctx).getZExtValue() == 0) + if (E->getArg(1)->EvaluateAsInt(Info.Ctx).getZExtValue() <= 1) return Success(-1ULL, E); return Success(0, E); } diff --git a/test/CodeGen/object-size.c b/test/CodeGen/object-size.c index 4947c19a5d..4b8cd55c28 100644 --- a/test/CodeGen/object-size.c +++ b/test/CodeGen/object-size.c @@ -109,3 +109,14 @@ void test16() { // CHECK: %call = call i8* @__inline_strcpy_chk(i8* %tmp1, i8* getelementptr inbounds ([9 x i8]* @.str, i32 0, i32 0)) strcpy(gp += 1, "Hi there"); } + +void test17() { + // CHECK: store i32 -1 + gi = __builtin_object_size(gp++, 0); + // CHECK: store i32 -1 + gi = __builtin_object_size(gp++, 1); + // CHECK: store i32 0 + gi = __builtin_object_size(gp++, 2); + // CHECK: store i32 0 + gi = __builtin_object_size(gp++, 3); +}