[cfe-commits] r92453 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/CodeGen/object-size.c
Benjamin Kramer
benny.kra at googlemail.com
Sun Jan 3 10:18:40 PST 2010
Author: d0k
Date: Sun Jan 3 12:18:37 2010
New Revision: 92453
URL: http://llvm.org/viewvc/llvm-project?rev=92453&view=rev
Log:
__builtin_object_size(ptr, type) returns -1 for type = {0,1} if there are any side-effects.
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/CodeGen/object-size.c
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=92453&r1=92452&r2=92453&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Sun Jan 3 12:18:37 2010
@@ -989,7 +989,7 @@
// 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);
}
Modified: cfe/trunk/test/CodeGen/object-size.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/object-size.c?rev=92453&r1=92452&r2=92453&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/object-size.c (original)
+++ cfe/trunk/test/CodeGen/object-size.c Sun Jan 3 12:18:37 2010
@@ -109,3 +109,14 @@
// 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);
+}
More information about the cfe-commits
mailing list