From: Eli Friedman Date: Mon, 11 Feb 2008 00:23:10 +0000 (+0000) Subject: Make unsupported constant exprs fail with a warning instead of crashing X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=546d94c77e4636a7dbce160c3c8e4157a2fe6d81;p=clang Make unsupported constant exprs fail with a warning instead of crashing codegen. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46943 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/CodeGen/CGExprConstant.cpp b/CodeGen/CGExprConstant.cpp index 569547549f..7a59457597 100644 --- a/CodeGen/CGExprConstant.cpp +++ b/CodeGen/CGExprConstant.cpp @@ -36,7 +36,7 @@ public: llvm::Constant *VisitStmt(Stmt *S) { CGM.WarnUnsupported(S, "constant expression"); - return 0; + return llvm::UndefValue::get(CGM.getTypes().ConvertType(cast(S)->getType())); } llvm::Constant *VisitParenExpr(ParenExpr *PE) { @@ -513,11 +513,7 @@ public: llvm::Constant *EmitLValue(Expr *E) { switch (E->getStmtClass()) { - default: { - CGM.WarnUnsupported(E, "constant l-value expression"); - llvm::Type *Ty = llvm::PointerType::getUnqual(ConvertType(E->getType())); - return llvm::UndefValue::get(Ty); - } + default: break; case Expr::ParenExprClass: // Elide parenthesis return EmitLValue(cast(E)->getSubExpr()); @@ -535,12 +531,11 @@ public: ValueDecl *Decl = cast(E)->getDecl(); if (const FunctionDecl *FD = dyn_cast(Decl)) return CGM.GetAddrOfFunctionDecl(FD, false); - if (const VarDecl* VD = dyn_cast(Decl)) + if (const FileVarDecl* VD = dyn_cast(Decl)) return CGM.GetAddrOfGlobalVar(VD, false); // We can end up here with static block-scope variables (and others?) // FIXME: How do we implement block-scope variables?! - assert(0 && "Unimplemented Decl type"); - return 0; + break; } case Expr::MemberExprClass: { MemberExpr* ME = cast(E); @@ -576,8 +571,8 @@ public: case Expr::UnaryOperatorClass: { UnaryOperator *Exp = cast(E); switch (Exp->getOpcode()) { - default: assert(0 && "Unsupported unary operator."); - case UnaryOperator::Extension: + default: break; + case UnaryOperator::Extension: // Extension is just a wrapper for expressions return EmitLValue(Exp->getSubExpr()); case UnaryOperator::Real: @@ -595,8 +590,12 @@ public: // The address of a deref is just the value of the expression return Visit(Exp->getSubExpr()); } + break; } - } + } + CGM.WarnUnsupported(E, "constant l-value expression"); + llvm::Type *Ty = llvm::PointerType::getUnqual(ConvertType(E->getType())); + return llvm::UndefValue::get(Ty); } };