[cfe-commits] r85174 - in /cfe/trunk: include/clang/AST/Expr.h lib/AST/ExprConstant.cpp test/CodeGen/object-size.c
Mike Stump
mrs at apple.com
Mon Oct 26 16:05:19 PDT 2009
Author: mrs
Date: Mon Oct 26 18:05:19 2009
New Revision: 85174
URL: http://llvm.org/viewvc/llvm-project?rev=85174&view=rev
Log:
__builtin_object_size refinements. Also handle stack based objects. WIP.
Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/CodeGen/object-size.c
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=85174&r1=85173&r2=85174&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Mon Oct 26 18:05:19 2009
@@ -241,6 +241,10 @@
/// in Result.
bool Evaluate(EvalResult &Result, ASTContext &Ctx) const;
+ /// EvaluateAsAny - The same as Evaluate, except that it also succeeds on
+ /// stack based objects.
+ bool EvaluateAsAny(EvalResult &Result, ASTContext &Ctx) const;
+
/// isEvaluatable - Call Evaluate to see if this expression can be constant
/// folded, but discard the result.
bool isEvaluatable(ASTContext &Ctx) const;
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=85174&r1=85173&r2=85174&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Oct 26 18:05:19 2009
@@ -877,7 +877,7 @@
case Builtin::BI__builtin_object_size: {
const Expr *Arg = E->getArg(0)->IgnoreParens();
Expr::EvalResult Base;
- if (Arg->Evaluate(Base, Info.Ctx)
+ if (Arg->EvaluateAsAny(Base, Info.Ctx)
&& Base.Val.getKind() == APValue::LValue
&& !Base.HasSideEffects)
if (const Expr *LVBase = Base.Val.getLValueBase())
@@ -1830,6 +1830,33 @@
return true;
}
+bool Expr::EvaluateAsAny(EvalResult &Result, ASTContext &Ctx) const {
+ EvalInfo Info(Ctx, Result, true);
+
+ if (getType()->isVectorType()) {
+ if (!EvaluateVector(this, Result.Val, Info))
+ return false;
+ } else if (getType()->isIntegerType()) {
+ if (!IntExprEvaluator(Info, Result.Val).Visit(const_cast<Expr*>(this)))
+ return false;
+ } else if (getType()->hasPointerRepresentation()) {
+ if (!EvaluatePointer(this, Result.Val, Info))
+ return false;
+ } else if (getType()->isRealFloatingType()) {
+ llvm::APFloat f(0.0);
+ if (!EvaluateFloat(this, f, Info))
+ return false;
+
+ Result.Val = APValue(f);
+ } else if (getType()->isAnyComplexType()) {
+ if (!EvaluateComplex(this, Result.Val, Info))
+ return false;
+ } else
+ return false;
+
+ return true;
+}
+
bool Expr::EvaluateAsLValue(EvalResult &Result, ASTContext &Ctx) const {
EvalInfo Info(Ctx, Result);
Modified: cfe/trunk/test/CodeGen/object-size.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/object-size.c?rev=85174&r1=85173&r2=85174&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/object-size.c (original)
+++ cfe/trunk/test/CodeGen/object-size.c Mon Oct 26 18:05:19 2009
@@ -47,3 +47,13 @@
// CHECK: call ___inline_strcpy_chk
strcpy((++i, gbuf), "Hi there");
}
+
+void test7() {
+ char buf[57];
+
+ // CHECK: movabsq $53, %rdx
+ // CHECK-NEXT: movq %rax, %rdi
+ // CHECK-NEXT: movq %rcx, %rsi
+ // CHECK-NEXT: call ___strcpy_chk
+ strcpy(&buf[4], "Hi there");
+}
More information about the cfe-commits
mailing list