[cfe-commits] r89934 - /cfe/trunk/lib/CodeGen/CGExprScalar.cpp
Sylvere Teissier
st at invia.fr
Fri Nov 27 08:51:57 PST 2009
Hi, this commit breaks this test case (infinite loop and finally seg fault)
$cat clang-bug.c
static inline int f(int i)
{
const int __t = (__t);
}
int g(void)
{
return f(0);
}
$clang-cc -emit-llvm clang-bug.c -o -
clang-bug.c:5:1: warning: control reaches end of non-void function
}
^
Segmentation fault
Eli Friedman a écrit :
> Author: efriedma
> Date: Wed Nov 25 21:22:21 2009
> New Revision: 89934
>
> URL: http://llvm.org/viewvc/llvm-project?rev=89934&view=rev
> Log:
> Use the more general Evaluate infrastructure for folding constant DeclRefs
> instead of checking explicitly for an EnumConstantDecl. This folds references
> to constant integer VarDecls, which has two benefits:
>
> 1. Slightly smaller emitted code from emitting a constant instead of a load,
> and skipping emitting some constant globals.
> 2. Some code forgets to define static constant member variables; emitting a
> load instead of the value in that case leads to a link error. (Such programs
> are technically not well-formed, but in practice build with g++.)
>
>
> Modified:
> cfe/trunk/lib/CodeGen/CGExprScalar.cpp
>
> Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=89934&r1=89933&r2=89934&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Wed Nov 25 21:22:21 2009
> @@ -141,8 +141,11 @@
>
> // l-values.
> Value *VisitDeclRefExpr(DeclRefExpr *E) {
> - if (const EnumConstantDecl *EC = dyn_cast<EnumConstantDecl>(E->getDecl()))
> - return llvm::ConstantInt::get(VMContext, EC->getInitVal());
> + Expr::EvalResult Result;
> + if (E->Evaluate(Result, CGF.getContext()) && Result.Val.isInt()) {
> + assert(!Result.HasSideEffects && "Constant declref with side-effect?!");
> + return llvm::ConstantInt::get(VMContext, Result.Val.getInt());
> + }
> return EmitLoadOfLValue(E);
> }
> Value *VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
> @@ -167,21 +170,7 @@
>
> Value *VisitArraySubscriptExpr(ArraySubscriptExpr *E);
> Value *VisitShuffleVectorExpr(ShuffleVectorExpr *E);
> - Value *VisitMemberExpr(MemberExpr *E) {
> - if (const EnumConstantDecl *EC =
> - dyn_cast<EnumConstantDecl>(E->getMemberDecl())) {
> -
> - // We still need to emit the base.
> - if (E->isArrow())
> - CGF.EmitScalarExpr(E->getBase());
> - else
> - CGF.EmitLValue(E->getBase());
> - return llvm::ConstantInt::get(VMContext, EC->getInitVal());
> - }
> -
> - return EmitLoadOfLValue(E);
> - }
> -
> + Value *VisitMemberExpr(MemberExpr *E);
> Value *VisitExtVectorElementExpr(Expr *E) { return EmitLoadOfLValue(E); }
> Value *VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
> return EmitLoadOfLValue(E);
> @@ -572,6 +561,17 @@
> Value* SV = llvm::ConstantVector::get(indices.begin(), indices.size());
> return Builder.CreateShuffleVector(V1, V2, SV, "shuffle");
> }
> +Value *ScalarExprEmitter::VisitMemberExpr(MemberExpr *E) {
> + Expr::EvalResult Result;
> + if (E->Evaluate(Result, CGF.getContext()) && Result.Val.isInt()) {
> + if (E->isArrow())
> + CGF.EmitScalarExpr(E->getBase());
> + else
> + EmitLValue(E->getBase());
> + return llvm::ConstantInt::get(VMContext, Result.Val.getInt());
> + }
> + return EmitLoadOfLValue(E);
> +}
>
> Value *ScalarExprEmitter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
> TestAndClearIgnoreResultAssign();
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
More information about the cfe-commits
mailing list