summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/Expr.cpp
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2011-12-21 00:43:02 +0000
committerEli Friedman <eli.friedman@gmail.com>2011-12-21 00:43:02 +0000
commit13ec75ba424882b2b36169551c1cb01e609f1674 (patch)
tree4fde79832ef37c7465f843a117b8b3e76e67555e /clang/lib/AST/Expr.cpp
parentc5af54ec899a71b7f8e3b5aa2802949581913c30 (diff)
downloadbcm5719-llvm-13ec75ba424882b2b36169551c1cb01e609f1674.tar.gz
bcm5719-llvm-13ec75ba424882b2b36169551c1cb01e609f1674.zip
Fix a case where Expr::isConstantInitializer would return true for an expression we can't support. In a slightly amusing twist, the case in question was already in the clang regression tests marked as a valid construct. <rdar://problem/10020074>
llvm-svn: 147026
Diffstat (limited to 'clang/lib/AST/Expr.cpp')
-rw-r--r--clang/lib/AST/Expr.cpp31
1 files changed, 22 insertions, 9 deletions
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 40da32284df..9f87161290e 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -2550,17 +2550,30 @@ bool Expr::isConstantInitializer(ASTContext &Ctx, bool IsForRef) const {
if (getType()->isVectorType() && CE->getCastKind() == CK_BitCast)
return CE->getSubExpr()->isConstantInitializer(Ctx, false);
- // Handle casts with a destination that's a struct or union; this
- // deals with both the gcc no-op struct cast extension and the
- // cast-to-union extension.
- if (getType()->isRecordType())
+ // Handle misc casts we want to ignore.
+ // FIXME: Is it really safe to ignore all these?
+ if (CE->getCastKind() == CK_NoOp ||
+ CE->getCastKind() == CK_LValueToRValue ||
+ CE->getCastKind() == CK_ToUnion ||
+ CE->getCastKind() == CK_ConstructorConversion)
return CE->getSubExpr()->isConstantInitializer(Ctx, false);
- // Integer->integer casts can be handled here, which is important for
- // things like (int)(&&x-&&y). Scary but true.
- if (getType()->isIntegerType() &&
- CE->getSubExpr()->getType()->isIntegerType())
- return CE->getSubExpr()->isConstantInitializer(Ctx, false);
+ // Handle things like (int)(&&x-&&y). It's a bit nasty, but we support it.
+ if (CE->getCastKind() == CK_IntegralCast) {
+ const Expr *E = CE->getSubExpr()->IgnoreParenNoopCasts(Ctx);
+ while (const CastExpr *InnerCE = dyn_cast<CastExpr>(E)) {
+ if (InnerCE->getCastKind() != CK_IntegralCast)
+ break;
+ E = InnerCE->getSubExpr()->IgnoreParenNoopCasts(Ctx);
+ }
+
+ if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) {
+ if (BO->getOpcode() == BO_Sub &&
+ isa<AddrLabelExpr>(BO->getLHS()->IgnoreParenNoopCasts(Ctx)) &&
+ isa<AddrLabelExpr>(BO->getRHS()->IgnoreParenNoopCasts(Ctx)))
+ return true;
+ }
+ }
break;
}
OpenPOWER on IntegriCloud