forked from OSchip/llvm-project
__builtin_object_size refinements. When we run out of object, be sure
to clamp at 0 bytes left. WIP. llvm-svn: 85157
This commit is contained in:
parent
72af806797
commit
10bd7e1c5b
|
@ -884,7 +884,11 @@ bool IntExprEvaluator::VisitCallExpr(const CallExpr *E) {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,13 +21,29 @@ void test2() {
|
|||
strcpy(gbuf, "Hi there");
|
||||
}
|
||||
|
||||
void test4() {
|
||||
// CHECK: call ___inline_strcpy_chk
|
||||
strcpy(gp, "Hi");
|
||||
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 test3() {
|
||||
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 there");
|
||||
}
|
||||
|
||||
void test6() {
|
||||
int i;
|
||||
// CHECK: call ___inline_strcpy_chk
|
||||
strcpy((++i, gbuf), "Hi");
|
||||
strcpy((++i, gbuf), "Hi there");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue