Make sure to explicitly pass type/value dependence to Expr constructor. This
caught several cases where we were not doing the right thing. I'm
not completely sure all cases are being handled correctly, but this should
be an improvement.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92281 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h
index 1a615c1..0cb22df 100644
--- a/include/clang/AST/Expr.h
+++ b/include/clang/AST/Expr.h
@@ -53,14 +53,6 @@
/// (C++ [temp.dep.constexpr]).
bool ValueDependent : 1;
- // FIXME: Eventually, this constructor should go away and we should
- // require every subclass to provide type/value-dependence
- // information.
- Expr(StmtClass SC, QualType T)
- : Stmt(SC), TypeDependent(false), ValueDependent(false) {
- setType(T);
- }
-
Expr(StmtClass SC, QualType T, bool TD, bool VD)
: Stmt(SC), TypeDependent(TD), ValueDependent(VD) {
setType(T);
@@ -609,7 +601,7 @@
// type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
// or UnsignedLongLongTy
IntegerLiteral(const llvm::APInt &V, QualType type, SourceLocation l)
- : Expr(IntegerLiteralClass, type), Value(V), Loc(l) {
+ : Expr(IntegerLiteralClass, type, false, false), Value(V), Loc(l) {
assert(type->isIntegerType() && "Illegal type in IntegerLiteral");
}
@@ -643,7 +635,8 @@
public:
// type should be IntTy
CharacterLiteral(unsigned value, bool iswide, QualType type, SourceLocation l)
- : Expr(CharacterLiteralClass, type), Value(value), Loc(l), IsWide(iswide) {
+ : Expr(CharacterLiteralClass, type, false, false), Value(value), Loc(l),
+ IsWide(iswide) {
}
/// \brief Construct an empty character literal.
@@ -677,7 +670,8 @@
public:
FloatingLiteral(const llvm::APFloat &V, bool isexact,
QualType Type, SourceLocation L)
- : Expr(FloatingLiteralClass, Type), Value(V), IsExact(isexact), Loc(L) {}
+ : Expr(FloatingLiteralClass, Type, false, false), Value(V),
+ IsExact(isexact), Loc(L) {}
/// \brief Construct an empty floating-point literal.
explicit FloatingLiteral(EmptyShell Empty)
@@ -718,7 +712,7 @@
Stmt *Val;
public:
ImaginaryLiteral(Expr *val, QualType Ty)
- : Expr(ImaginaryLiteralClass, Ty), Val(val) {}
+ : Expr(ImaginaryLiteralClass, Ty, false, false), Val(val) {}
/// \brief Build an empty imaginary literal.
explicit ImaginaryLiteral(EmptyShell Empty)
@@ -762,7 +756,7 @@
unsigned NumConcatenated;
SourceLocation TokLocs[1];
- StringLiteral(QualType Ty) : Expr(StringLiteralClass, Ty) {}
+ StringLiteral(QualType Ty) : Expr(StringLiteralClass, Ty, false, false) {}
protected:
virtual void DoDestroy(ASTContext &C);
@@ -1466,10 +1460,11 @@
Stmt *Init;
bool FileScope;
public:
+ // FIXME: Can compound literals be value-dependent?
CompoundLiteralExpr(SourceLocation lparenloc, QualType ty, Expr *init,
bool fileScope)
- : Expr(CompoundLiteralExprClass, ty), LParenLoc(lparenloc), Init(init),
- FileScope(fileScope) {}
+ : Expr(CompoundLiteralExprClass, ty, ty->isDependentType(), false),
+ LParenLoc(lparenloc), Init(init), FileScope(fileScope) {}
/// \brief Construct an empty compound literal.
explicit CompoundLiteralExpr(EmptyShell Empty)
@@ -1903,8 +1898,11 @@
protected:
BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
- SourceLocation oploc, bool dead)
- : Expr(CompoundAssignOperatorClass, ResTy), Opc(opc), OpLoc(oploc) {
+ SourceLocation opLoc, bool dead)
+ : Expr(CompoundAssignOperatorClass, ResTy,
+ lhs->isTypeDependent() || rhs->isTypeDependent(),
+ lhs->isValueDependent() || rhs->isValueDependent()),
+ Opc(opc), OpLoc(opLoc) {
SubExprs[LHS] = lhs;
SubExprs[RHS] = rhs;
}
@@ -2033,7 +2031,8 @@
public:
AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L,
QualType t)
- : Expr(AddrLabelExprClass, t), AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
+ : Expr(AddrLabelExprClass, t, false, false),
+ AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
/// \brief Build an empty address of a label expression.
explicit AddrLabelExpr(EmptyShell Empty)
@@ -2068,9 +2067,11 @@
Stmt *SubStmt;
SourceLocation LParenLoc, RParenLoc;
public:
+ // FIXME: Does type-dependence need to be computed differently?
StmtExpr(CompoundStmt *substmt, QualType T,
SourceLocation lp, SourceLocation rp) :
- Expr(StmtExprClass, T), SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { }
+ Expr(StmtExprClass, T, T->isDependentType(), false),
+ SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { }
/// \brief Build an empty statement expression.
explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { }
@@ -2109,8 +2110,8 @@
public:
TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc,
QualType t1, QualType t2, SourceLocation RP) :
- Expr(TypesCompatibleExprClass, ReturnType), Type1(t1), Type2(t2),
- BuiltinLoc(BLoc), RParenLoc(RP) {}
+ Expr(TypesCompatibleExprClass, ReturnType, false, false),
+ Type1(t1), Type2(t2), BuiltinLoc(BLoc), RParenLoc(RP) {}
/// \brief Build an empty __builtin_type_compatible_p expression.
explicit TypesCompatibleExpr(EmptyShell Empty)
@@ -2160,11 +2161,13 @@
virtual void DoDestroy(ASTContext &C);
public:
+ // FIXME: Can a shufflevector be value-dependent? Does type-dependence need
+ // to be computed differently?
ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr,
QualType Type, SourceLocation BLoc,
SourceLocation RP) :
- Expr(ShuffleVectorExprClass, Type), BuiltinLoc(BLoc),
- RParenLoc(RP), NumExprs(nexpr) {
+ Expr(ShuffleVectorExprClass, Type, Type->isDependentType(), false),
+ BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(nexpr) {
SubExprs = new (C) Stmt*[nexpr];
for (unsigned i = 0; i < nexpr; i++)
@@ -2292,7 +2295,7 @@
public:
GNUNullExpr(QualType Ty, SourceLocation Loc)
- : Expr(GNUNullExprClass, Ty), TokenLoc(Loc) { }
+ : Expr(GNUNullExprClass, Ty, false, false), TokenLoc(Loc) { }
/// \brief Build an empty GNU __null expression.
explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { }
@@ -2320,7 +2323,7 @@
SourceLocation BuiltinLoc, RParenLoc;
public:
VAArgExpr(SourceLocation BLoc, Expr* e, QualType t, SourceLocation RPLoc)
- : Expr(VAArgExprClass, t),
+ : Expr(VAArgExprClass, t, t->isDependentType(), false),
Val(e),
BuiltinLoc(BLoc),
RParenLoc(RPLoc) { }
@@ -2802,7 +2805,7 @@
class ImplicitValueInitExpr : public Expr {
public:
explicit ImplicitValueInitExpr(QualType ty)
- : Expr(ImplicitValueInitExprClass, ty) { }
+ : Expr(ImplicitValueInitExprClass, ty, false, false) { }
/// \brief Construct an empty implicit value initialization.
explicit ImplicitValueInitExpr(EmptyShell Empty)
@@ -2890,7 +2893,8 @@
public:
ExtVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor,
SourceLocation loc)
- : Expr(ExtVectorElementExprClass, ty),
+ : Expr(ExtVectorElementExprClass, ty, base->isTypeDependent(),
+ base->isValueDependent()),
Base(base), Accessor(&accessor), AccessorLoc(loc) {}
/// \brief Build an empty vector element expression.
@@ -2945,7 +2949,7 @@
bool HasBlockDeclRefExprs;
public:
BlockExpr(BlockDecl *BD, QualType ty, bool hasBlockDeclRefExprs)
- : Expr(BlockExprClass, ty),
+ : Expr(BlockExprClass, ty, ty->isDependentType(), false),
TheBlock(BD), HasBlockDeclRefExprs(hasBlockDeclRefExprs) {}
/// \brief Build an empty block expression.
@@ -2990,10 +2994,11 @@
bool IsByRef : 1;
bool ConstQualAdded : 1;
public:
+ // FIXME: Fix type/value dependence!
BlockDeclRefExpr(ValueDecl *d, QualType t, SourceLocation l, bool ByRef,
- bool constAdded = false) :
- Expr(BlockDeclRefExprClass, t), D(d), Loc(l), IsByRef(ByRef),
- ConstQualAdded(constAdded) {}
+ bool constAdded = false)
+ : Expr(BlockDeclRefExprClass, t, false, false), D(d), Loc(l), IsByRef(ByRef),
+ ConstQualAdded(constAdded) {}
// \brief Build an empty reference to a declared variable in a
// block.
diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h
index 662dbb6..d0e21f5 100644
--- a/include/clang/AST/ExprCXX.h
+++ b/include/clang/AST/ExprCXX.h
@@ -224,7 +224,7 @@
SourceLocation Loc;
public:
CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
- Expr(CXXBoolLiteralExprClass, Ty), Value(val), Loc(l) {}
+ Expr(CXXBoolLiteralExprClass, Ty, false, false), Value(val), Loc(l) {}
bool getValue() const { return Value; }
@@ -245,7 +245,7 @@
SourceLocation Loc;
public:
CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) :
- Expr(CXXNullPtrLiteralExprClass, Ty), Loc(l) {}
+ Expr(CXXNullPtrLiteralExprClass, Ty, false, false), Loc(l) {}
virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
@@ -401,12 +401,13 @@
: Expr(SC,
param->hasUnparsedDefaultArg()
? param->getType().getNonReferenceType()
- : param->getDefaultArg()->getType()),
+ : param->getDefaultArg()->getType(),
+ false, false),
Param(param, false), Loc(Loc) { }
CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param,
Expr *SubExpr)
- : Expr(SC, SubExpr->getType()), Param(param, true), Loc(Loc)
+ : Expr(SC, SubExpr->getType(), false, false), Param(param, true), Loc(Loc)
{
*reinterpret_cast<Expr **>(this + 1) = SubExpr;
}
@@ -491,8 +492,8 @@
Stmt *SubExpr;
CXXBindTemporaryExpr(CXXTemporary *temp, Expr* subexpr)
- : Expr(CXXBindTemporaryExprClass,
- subexpr->getType()), Temp(temp), SubExpr(subexpr) { }
+ : Expr(CXXBindTemporaryExprClass, subexpr->getType(), false, false),
+ Temp(temp), SubExpr(subexpr) { }
~CXXBindTemporaryExpr() { }
protected:
diff --git a/include/clang/AST/ExprObjC.h b/include/clang/AST/ExprObjC.h
index 0613f4c..0b0cd64 100644
--- a/include/clang/AST/ExprObjC.h
+++ b/include/clang/AST/ExprObjC.h
@@ -30,7 +30,7 @@
SourceLocation AtLoc;
public:
ObjCStringLiteral(StringLiteral *SL, QualType T, SourceLocation L)
- : Expr(ObjCStringLiteralClass, T), String(SL), AtLoc(L) {}
+ : Expr(ObjCStringLiteralClass, T, false, false), String(SL), AtLoc(L) {}
explicit ObjCStringLiteral(EmptyShell Empty)
: Expr(ObjCStringLiteralClass, Empty) {}
@@ -100,7 +100,8 @@
public:
ObjCSelectorExpr(QualType T, Selector selInfo,
SourceLocation at, SourceLocation rp)
- : Expr(ObjCSelectorExprClass, T), SelName(selInfo), AtLoc(at), RParenLoc(rp){}
+ : Expr(ObjCSelectorExprClass, T, false, false), SelName(selInfo), AtLoc(at),
+ RParenLoc(rp){}
explicit ObjCSelectorExpr(EmptyShell Empty)
: Expr(ObjCSelectorExprClass, Empty) {}
@@ -139,7 +140,7 @@
public:
ObjCProtocolExpr(QualType T, ObjCProtocolDecl *protocol,
SourceLocation at, SourceLocation rp)
- : Expr(ObjCProtocolExprClass, T), TheProtocol(protocol),
+ : Expr(ObjCProtocolExprClass, T, false, false), TheProtocol(protocol),
AtLoc(at), RParenLoc(rp) {}
explicit ObjCProtocolExpr(EmptyShell Empty)
: Expr(ObjCProtocolExprClass, Empty) {}
@@ -178,7 +179,7 @@
ObjCIvarRefExpr(ObjCIvarDecl *d,
QualType t, SourceLocation l, Expr *base=0,
bool arrow = false, bool freeIvar = false) :
- Expr(ObjCIvarRefExprClass, t), D(d),
+ Expr(ObjCIvarRefExprClass, t, false, false), D(d),
Loc(l), Base(base), IsArrow(arrow),
IsFreeIvar(freeIvar) {}
@@ -227,7 +228,8 @@
public:
ObjCPropertyRefExpr(ObjCPropertyDecl *PD, QualType t,
SourceLocation l, Expr *base)
- : Expr(ObjCPropertyRefExprClass, t), AsProperty(PD), IdLoc(l), Base(base) {
+ : Expr(ObjCPropertyRefExprClass, t, false, false), AsProperty(PD),
+ IdLoc(l), Base(base) {
}
explicit ObjCPropertyRefExpr(EmptyShell Empty)
@@ -291,16 +293,17 @@
QualType t,
ObjCMethodDecl *setter,
SourceLocation l, Expr *base)
- : Expr(ObjCImplicitSetterGetterRefExprClass, t), Setter(setter),
- Getter(getter), MemberLoc(l), Base(base), InterfaceDecl(0),
- ClassLoc(SourceLocation()) {
+ : Expr(ObjCImplicitSetterGetterRefExprClass, t, false, false),
+ Setter(setter), Getter(getter), MemberLoc(l), Base(base),
+ InterfaceDecl(0), ClassLoc(SourceLocation()) {
}
ObjCImplicitSetterGetterRefExpr(ObjCMethodDecl *getter,
QualType t,
ObjCMethodDecl *setter,
SourceLocation l, ObjCInterfaceDecl *C, SourceLocation CL)
- : Expr(ObjCImplicitSetterGetterRefExprClass, t), Setter(setter),
- Getter(getter), MemberLoc(l), Base(0), InterfaceDecl(C), ClassLoc(CL) {
+ : Expr(ObjCImplicitSetterGetterRefExprClass, t, false, false),
+ Setter(setter), Getter(getter), MemberLoc(l), Base(0), InterfaceDecl(C),
+ ClassLoc(CL) {
}
explicit ObjCImplicitSetterGetterRefExpr(EmptyShell Empty)
: Expr(ObjCImplicitSetterGetterRefExprClass, Empty){}
@@ -488,7 +491,7 @@
SourceLocation Loc;
public:
ObjCSuperExpr(SourceLocation L, QualType Type)
- : Expr(ObjCSuperExprClass, Type), Loc(L) { }
+ : Expr(ObjCSuperExprClass, Type, false, false), Loc(L) { }
explicit ObjCSuperExpr(EmptyShell Empty) : Expr(ObjCSuperExprClass, Empty) {}
SourceLocation getLoc() const { return Loc; }
@@ -519,7 +522,7 @@
bool IsArrow;
public:
ObjCIsaExpr(Expr *base, bool isarrow, SourceLocation l, QualType ty)
- : Expr(ObjCIsaExprClass, ty),
+ : Expr(ObjCIsaExprClass, ty, false, false),
Base(base), IsaMemberLoc(l), IsArrow(isarrow) {}
/// \brief Build an empty expression.
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp
index a31a7f5..04a6abc 100644
--- a/lib/AST/Expr.cpp
+++ b/lib/AST/Expr.cpp
@@ -2032,7 +2032,7 @@
QualType retType, ObjCMethodDecl *mproto,
SourceLocation LBrac, SourceLocation RBrac,
Expr **ArgExprs, unsigned nargs)
- : Expr(ObjCMessageExprClass, retType), SelName(selInfo),
+ : Expr(ObjCMessageExprClass, retType, false, false), SelName(selInfo),
MethodProto(mproto) {
NumArgs = nargs;
SubExprs = new Stmt*[NumArgs+1];
@@ -2051,7 +2051,7 @@
QualType retType, ObjCMethodDecl *mproto,
SourceLocation LBrac, SourceLocation RBrac,
Expr **ArgExprs, unsigned nargs)
- : Expr(ObjCMessageExprClass, retType), SelName(selInfo),
+ : Expr(ObjCMessageExprClass, retType, false, false), SelName(selInfo),
MethodProto(mproto) {
NumArgs = nargs;
SubExprs = new Stmt*[NumArgs+1];
@@ -2069,7 +2069,7 @@
QualType retType, ObjCMethodDecl *mproto,
SourceLocation LBrac, SourceLocation RBrac,
Expr **ArgExprs, unsigned nargs)
-: Expr(ObjCMessageExprClass, retType), SelName(selInfo),
+: Expr(ObjCMessageExprClass, retType, false, false), SelName(selInfo),
MethodProto(mproto) {
NumArgs = nargs;
SubExprs = new Stmt*[NumArgs+1];