diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 8516d41df6..0e4a29f916 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -1281,6 +1281,13 @@ bool Expr::isConstantInitializer(ASTContext &Ctx) const { // cast-to-union extension. if (getType()->isRecordType()) return cast(this)->getSubExpr()->isConstantInitializer(Ctx); + + // Integer->integer casts can be handled here, which is important for + // things like (int)(&&x-&&y). Scary but true. + if (getType()->isIntegerType() && + cast(this)->getSubExpr()->getType()->isIntegerType()) + return cast(this)->getSubExpr()->isConstantInitializer(Ctx); + break; } return isEvaluatable(Ctx); diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index 119b6f31e4..7f540c3c06 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -548,7 +548,18 @@ public: // Explicit and implicit no-op casts QualType Ty = E->getType(), SubTy = E->getSubExpr()->getType(); if (CGM.getContext().hasSameUnqualifiedType(Ty, SubTy)) - return Visit(E->getSubExpr()); + return Visit(E->getSubExpr()); + + // Handle integer->integer casts for address-of-label differences. + if (Ty->isIntegerType() && SubTy->isIntegerType() && + CGF) { + llvm::Value *Src = Visit(E->getSubExpr()); + if (Src == 0) return 0; + + // Use EmitScalarConversion to perform the conversion. + return cast(CGF->EmitScalarConversion(Src, SubTy, Ty)); + } + return 0; } }