[cfe-commits] r85157 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/CodeGen/object-size.c
Mike Stump
mrs at apple.com
Mon Oct 26 14:38:39 PDT 2009
Author: mrs
Date: Mon Oct 26 16:38:39 2009
New Revision: 85157
URL: http://llvm.org/viewvc/llvm-project?rev=85157&view=rev
Log:
__builtin_object_size refinements. When we run out of object, be sure
to clamp at 0 bytes left. WIP.
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=85157&r1=85156&r2=85157&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Oct 26 16:38:39 2009
@@ -884,7 +884,11 @@
if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(LVBase)) {
if (const VarDecl *VD = dyn_cast<VarDecl>(DRE->getDecl())) {
uint64_t Size = Info.Ctx.getTypeSize(VD->getType()) / 8;
- Size -= Base.Val.getLValueOffset();
+ uint64_t Offset = Base.Val.getLValueOffset();
+ if (Offset <= Size)
+ Size -= Base.Val.getLValueOffset();
+ else
+ Size = 0;
return Success(Size, E);
}
}
Modified: cfe/trunk/test/CodeGen/object-size.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/object-size.c?rev=85157&r1=85156&r2=85157&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/object-size.c (original)
+++ cfe/trunk/test/CodeGen/object-size.c Mon Oct 26 16:38:39 2009
@@ -21,13 +21,29 @@
strcpy(gbuf, "Hi there");
}
+void test3() {
+ // CHECK: movabsq $0, %rdx
+ // CHECK-NEXT: movq %rax, %rdi
+ // CHECK-NEXT: movq %rcx, %rsi
+ // CHECK-NEXT: call ___strcpy_chk
+ strcpy(&gbuf[100], "Hi there");
+}
+
void test4() {
+ // CHECK: movabsq $0, %rdx
+ // CHECK-NEXT: movq %rax, %rdi
+ // CHECK-NEXT: movq %rcx, %rsi
+ // CHECK-NEXT: call ___strcpy_chk
+ strcpy((char*)(void*)&gbuf[-1], "Hi there");
+}
+
+void test5() {
// CHECK: call ___inline_strcpy_chk
- strcpy(gp, "Hi");
+ strcpy(gp, "Hi there");
}
-void test3() {
+void test6() {
int i;
// CHECK: call ___inline_strcpy_chk
- strcpy((++i, gbuf), "Hi");
+ strcpy((++i, gbuf), "Hi there");
}
More information about the cfe-commits
mailing list