__builtin_object_size(ptr, type) returns -1 for type = {0,1} if there are any side-effects.

llvm-svn: 92453
This commit is contained in:
Benjamin Kramer 2010-01-03 18:18:37 +00:00
parent fd11f49b4e
commit 0128f668a9
2 changed files with 12 additions and 1 deletions

View File

@ -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);
}

View File

@ -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);
}