[cfe-commits] r120900 - in /cfe/trunk: include/clang/AST/DeclCXX.h include/clang/Sema/Initialization.h include/clang/Sema/Sema.h lib/AST/DeclCXX.cpp lib/AST/DeclPrinter.cpp lib/Analysis/CFG.cpp lib/Checker/GRExprEngine.cpp lib/CodeGen/CGClass.cpp lib/CodeGen/CGExpr.cpp lib/CodeGen/CGObjC.cpp lib/CodeGen/CodeGenFunction.h lib/Sema/SemaCodeComplete.cpp lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaTemplateInstantiateDecl.cpp lib/Serialization/ASTReader.cpp lib/Serialization/ASTWriter.cpp tools/libclang/CIndex.cpp
Francois Pichet
pichet2000 at gmail.com
Sat Dec 4 01:14:42 PST 2010
Author: fpichet
Date: Sat Dec 4 03:14:42 2010
New Revision: 120900
URL: http://llvm.org/viewvc/llvm-project?rev=120900&view=rev
Log:
More anonymous struct/union redesign. This one deals with anonymous field used in a constructor initializer list:
struct X {
X() : au_i1(123) {}
union {
int au_i1;
float au_f1;
};
};
clang will now deal with au_i1 explicitly as an IndirectFieldDecl.
Modified:
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/include/clang/Sema/Initialization.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/DeclCXX.cpp
cfe/trunk/lib/AST/DeclPrinter.cpp
cfe/trunk/lib/Analysis/CFG.cpp
cfe/trunk/lib/Checker/GRExprEngine.cpp
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/tools/libclang/CIndex.cpp
Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=120900&r1=120899&r2=120900&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Sat Dec 4 03:14:42 2010
@@ -1108,9 +1108,9 @@
/// };
/// @endcode
class CXXBaseOrMemberInitializer {
- /// \brief Either the base class name (stored as a TypeSourceInfo*) or the
- /// field being initialized.
- llvm::PointerUnion<TypeSourceInfo *, FieldDecl *> BaseOrMember;
+ /// \brief Either the base class name (stored as a TypeSourceInfo*), an normal
+ /// field (FieldDecl) or an anonymous field (IndirectFieldDecl*) being initialized.
+ llvm::PointerUnion3<TypeSourceInfo *, FieldDecl *, IndirectFieldDecl *> BaseOrMember;
/// \brief The source location for the field name.
SourceLocation MemberLocation;
@@ -1118,26 +1118,6 @@
/// \brief The argument used to initialize the base or member, which may
/// end up constructing an object (when multiple arguments are involved).
Stmt *Init;
-
- /// \brief Stores either the constructor to call to initialize this base or
- /// member (a CXXConstructorDecl pointer), or stores the anonymous union of
- /// which the initialized value is a member.
- ///
- /// When the value is a FieldDecl pointer, 'BaseOrMember' is class's
- /// anonymous union data member, this field holds the FieldDecl for the
- /// member of the anonymous union being initialized.
- /// @code
- /// struct X {
- /// X() : au_i1(123) {}
- /// union {
- /// int au_i1;
- /// float au_f1;
- /// };
- /// };
- /// @endcode
- /// In above example, BaseOrMember holds the field decl. for anonymous union
- /// and AnonUnionMember holds field decl for au_i1.
- FieldDecl *AnonUnionMember;
/// LParenLoc - Location of the left paren of the ctor-initializer.
SourceLocation LParenLoc;
@@ -1152,6 +1132,7 @@
/// IsWritten - Whether or not the initializer is explicitly written
/// in the sources.
bool IsWritten : 1;
+
/// SourceOrderOrNumArrayIndices - If IsWritten is true, then this
/// number keeps track of the textual order of this initializer in the
/// original sources, counting from 0; otherwise, if IsWritten is false,
@@ -1184,6 +1165,14 @@
Expr *Init,
SourceLocation R);
+ explicit
+ CXXBaseOrMemberInitializer(ASTContext &Context,
+ IndirectFieldDecl *Member,
+ SourceLocation MemberLoc,
+ SourceLocation L,
+ Expr *Init,
+ SourceLocation R);
+
/// \brief Creates a new member initializer that optionally contains
/// array indices used to describe an elementwise initialization.
static CXXBaseOrMemberInitializer *Create(ASTContext &Context,
@@ -1203,6 +1192,14 @@
/// initializing a non-static data member.
bool isMemberInitializer() const { return BaseOrMember.is<FieldDecl*>(); }
+ bool isAnyMemberInitializer() const {
+ return isMemberInitializer() || isIndirectMemberInitializer();
+ }
+
+ bool isIndirectMemberInitializer() const {
+ return BaseOrMember.is<IndirectFieldDecl*>();
+ }
+
/// If this is a base class initializer, returns the type of the
/// base class with location information. Otherwise, returns an NULL
/// type location.
@@ -1234,14 +1231,24 @@
else
return 0;
}
+ FieldDecl *getAnyMember() const {
+ if (isMemberInitializer())
+ return BaseOrMember.get<FieldDecl*>();
+ else if (isIndirectMemberInitializer())
+ return BaseOrMember.get<IndirectFieldDecl*>()->getAnonField();
+ else
+ return 0;
+ }
- SourceLocation getMemberLocation() const {
- return MemberLocation;
+ IndirectFieldDecl *getIndirectMember() const {
+ if (isIndirectMemberInitializer())
+ return BaseOrMember.get<IndirectFieldDecl*>();
+ else
+ return 0;
}
- void setMember(FieldDecl *Member) {
- assert(isMemberInitializer());
- BaseOrMember = Member;
+ SourceLocation getMemberLocation() const {
+ return MemberLocation;
}
/// \brief Determine the source location of the initializer.
@@ -1273,15 +1280,7 @@
IsWritten = true;
SourceOrderOrNumArrayIndices = static_cast<unsigned>(pos);
}
-
- FieldDecl *getAnonUnionMember() const {
- return AnonUnionMember;
- }
- void setAnonUnionMember(FieldDecl *anonMember) {
- AnonUnionMember = anonMember;
- }
-
SourceLocation getLParenLoc() const { return LParenLoc; }
SourceLocation getRParenLoc() const { return RParenLoc; }
Modified: cfe/trunk/include/clang/Sema/Initialization.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Initialization.h?rev=120900&r1=120899&r2=120900&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Initialization.h (original)
+++ cfe/trunk/include/clang/Sema/Initialization.h Sat Dec 4 03:14:42 2010
@@ -217,6 +217,12 @@
return InitializedEntity(Member, Parent);
}
+ /// \brief Create the initialization entity for a member subobject.
+ static InitializedEntity InitializeMember(IndirectFieldDecl *Member,
+ const InitializedEntity *Parent = 0) {
+ return InitializedEntity(Member->getAnonField(), Parent);
+ }
+
/// \brief Create the initialization entity for an array element.
static InitializedEntity InitializeElement(ASTContext &Context,
unsigned Index,
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=120900&r1=120899&r2=120900&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Sat Dec 4 03:14:42 2010
@@ -2530,7 +2530,8 @@
Expr **Args, unsigned NumArgs,
SourceLocation RParenLoc);
- MemInitResult BuildMemberInitializer(FieldDecl *Member, Expr **Args,
+ template<typename T>
+ MemInitResult BuildMemberInitializer(T *Member, Expr **Args,
unsigned NumArgs, SourceLocation IdLoc,
SourceLocation LParenLoc,
SourceLocation RParenLoc);
Modified: cfe/trunk/lib/AST/DeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=120900&r1=120899&r2=120900&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)
+++ cfe/trunk/lib/AST/DeclCXX.cpp Sat Dec 4 03:14:42 2010
@@ -1004,7 +1004,7 @@
CXXBaseOrMemberInitializer(ASTContext &Context,
TypeSourceInfo *TInfo, bool IsVirtual,
SourceLocation L, Expr *Init, SourceLocation R)
- : BaseOrMember(TInfo), Init(Init), AnonUnionMember(0),
+ : BaseOrMember(TInfo), Init(Init),
LParenLoc(L), RParenLoc(R), IsVirtual(IsVirtual), IsWritten(false),
SourceOrderOrNumArrayIndices(0)
{
@@ -1015,7 +1015,17 @@
FieldDecl *Member, SourceLocation MemberLoc,
SourceLocation L, Expr *Init, SourceLocation R)
: BaseOrMember(Member), MemberLocation(MemberLoc), Init(Init),
- AnonUnionMember(0), LParenLoc(L), RParenLoc(R), IsVirtual(false),
+ LParenLoc(L), RParenLoc(R), IsVirtual(false),
+ IsWritten(false), SourceOrderOrNumArrayIndices(0)
+{
+}
+
+CXXBaseOrMemberInitializer::
+CXXBaseOrMemberInitializer(ASTContext &Context,
+ IndirectFieldDecl *Member, SourceLocation MemberLoc,
+ SourceLocation L, Expr *Init, SourceLocation R)
+ : BaseOrMember(Member), MemberLocation(MemberLoc), Init(Init),
+ LParenLoc(L), RParenLoc(R), IsVirtual(false),
IsWritten(false), SourceOrderOrNumArrayIndices(0)
{
}
@@ -1027,7 +1037,7 @@
VarDecl **Indices,
unsigned NumIndices)
: BaseOrMember(Member), MemberLocation(MemberLoc), Init(Init),
- AnonUnionMember(0), LParenLoc(L), RParenLoc(R), IsVirtual(false),
+ LParenLoc(L), RParenLoc(R), IsVirtual(false),
IsWritten(false), SourceOrderOrNumArrayIndices(NumIndices)
{
VarDecl **MyIndices = reinterpret_cast<VarDecl **> (this + 1);
@@ -1072,7 +1082,7 @@
}
SourceLocation CXXBaseOrMemberInitializer::getSourceLocation() const {
- if (isMemberInitializer())
+ if (isAnyMemberInitializer())
return getMemberLocation();
return getBaseClassLoc().getLocalSourceRange().getBegin();
Modified: cfe/trunk/lib/AST/DeclPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclPrinter.cpp?rev=120900&r1=120899&r2=120900&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclPrinter.cpp (original)
+++ cfe/trunk/lib/AST/DeclPrinter.cpp Sat Dec 4 03:14:42 2010
@@ -436,8 +436,8 @@
CXXBaseOrMemberInitializer * BMInitializer = (*B);
if (B != CDecl->init_begin())
Out << ", ";
- if (BMInitializer->isMemberInitializer()) {
- FieldDecl *FD = BMInitializer->getMember();
+ if (BMInitializer->isAnyMemberInitializer()) {
+ FieldDecl *FD = BMInitializer->getAnyMember();
Out << FD;
} else {
Out << QualType(BMInitializer->getBaseClass(),
Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=120900&r1=120899&r2=120900&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Sat Dec 4 03:14:42 2010
@@ -553,7 +553,7 @@
// after initialization finishes.
Expr *Init = I->getInit();
if (Init) {
- if (FieldDecl *FD = I->getMember())
+ if (FieldDecl *FD = I->getAnyMember())
IsReference = FD->getType()->isReferenceType();
HasTemporaries = isa<CXXExprWithTemporaries>(Init);
@@ -3093,7 +3093,7 @@
CXXBaseOrMemberInitializer* I = IE;
if (I->isBaseInitializer())
OS << I->getBaseClass()->getAsCXXRecordDecl()->getName();
- else OS << I->getMember()->getName();
+ else OS << I->getAnyMember()->getName();
OS << "(";
if (Expr* IE = I->getInit())
Modified: cfe/trunk/lib/Checker/GRExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/GRExprEngine.cpp?rev=120900&r1=120899&r2=120900&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Checker/GRExprEngine.cpp Sat Dec 4 03:14:42 2010
@@ -687,7 +687,7 @@
ExplodedNode *Pred = builder.getBasePredecessor();
const LocationContext *LC = Pred->getLocationContext();
- if (BMI->isMemberInitializer()) {
+ if (BMI->isAnyMemberInitializer()) {
ExplodedNodeSet Dst;
// Evaluate the initializer.
@@ -697,7 +697,7 @@
ExplodedNode *Pred = *I;
const GRState *state = Pred->getState();
- const FieldDecl *FD = BMI->getMember();
+ const FieldDecl *FD = BMI->getAnyMember();
const RecordDecl *RD = FD->getParent();
const CXXThisRegion *ThisR = getCXXThisRegion(cast<CXXRecordDecl>(RD),
cast<StackFrameContext>(LC));
Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=120900&r1=120899&r2=120900&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Sat Dec 4 03:14:42 2010
@@ -512,21 +512,21 @@
CXXBaseOrMemberInitializer *MemberInit,
const CXXConstructorDecl *Constructor,
FunctionArgList &Args) {
- assert(MemberInit->isMemberInitializer() &&
+ assert(MemberInit->isAnyMemberInitializer() &&
"Must have member initializer!");
// non-static data member initializers.
- FieldDecl *Field = MemberInit->getMember();
+ FieldDecl *Field = MemberInit->getAnyMember();
QualType FieldType = CGF.getContext().getCanonicalType(Field->getType());
llvm::Value *ThisPtr = CGF.LoadCXXThis();
LValue LHS;
// If we are initializing an anonymous union field, drill down to the field.
- if (MemberInit->getAnonUnionMember()) {
- Field = MemberInit->getAnonUnionMember();
- LHS = CGF.EmitLValueForAnonRecordField(ThisPtr, Field, 0);
- FieldType = Field->getType();
+ if (MemberInit->isIndirectMemberInitializer()) {
+ LHS = CGF.EmitLValueForAnonRecordField(ThisPtr,
+ MemberInit->getIndirectMember(), 0);
+ FieldType = MemberInit->getIndirectMember()->getAnonField()->getType();
} else {
LHS = CGF.EmitLValueForFieldInitialization(ThisPtr, Field, 0);
}
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=120900&r1=120899&r2=120900&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Sat Dec 4 03:14:42 2010
@@ -1574,23 +1574,13 @@
/// that the base value is a pointer to the enclosing record, derive
/// an lvalue for the ultimate field.
LValue CodeGenFunction::EmitLValueForAnonRecordField(llvm::Value *BaseValue,
- const FieldDecl *Field,
+ const IndirectFieldDecl *Field,
unsigned CVRQualifiers) {
- llvm::SmallVector<const FieldDecl *, 8> Path;
- Path.push_back(Field);
-
- while (Field->getParent()->isAnonymousStructOrUnion()) {
- const ValueDecl *VD = Field->getParent()->getAnonymousStructOrUnionObject();
- if (!isa<FieldDecl>(VD)) break;
- Field = cast<FieldDecl>(VD);
- Path.push_back(Field);
- }
-
- llvm::SmallVectorImpl<const FieldDecl*>::reverse_iterator
- I = Path.rbegin(), E = Path.rend();
+ IndirectFieldDecl::chain_iterator I = Field->chain_begin(),
+ IEnd = Field->chain_end();
while (true) {
- LValue LV = EmitLValueForField(BaseValue, *I, CVRQualifiers);
- if (++I == E) return LV;
+ LValue LV = EmitLValueForField(BaseValue, cast<FieldDecl>(*I), CVRQualifiers);
+ if (++I == IEnd) return LV;
assert(LV.isSimple());
BaseValue = LV.getAddress();
Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=120900&r1=120899&r2=120900&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Sat Dec 4 03:14:42 2010
@@ -432,7 +432,7 @@
if (ctor) {
for (unsigned I = 0, E = IvarInitializers.size(); I != E; ++I) {
CXXBaseOrMemberInitializer *IvarInit = IvarInitializers[I];
- FieldDecl *Field = IvarInit->getMember();
+ FieldDecl *Field = IvarInit->getAnyMember();
QualType FieldType = Field->getType();
ObjCIvarDecl *Ivar = cast<ObjCIvarDecl>(Field);
LValue LV = EmitLValueForIvar(TypeOfSelfObject(),
@@ -448,7 +448,7 @@
} else {
// dtor
for (size_t i = IvarInitializers.size(); i > 0; --i) {
- FieldDecl *Field = IvarInitializers[i - 1]->getMember();
+ FieldDecl *Field = IvarInitializers[i - 1]->getAnyMember();
QualType FieldType = Field->getType();
const ConstantArrayType *Array =
getContext().getAsConstantArrayType(FieldType);
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=120900&r1=120899&r2=120900&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Sat Dec 4 03:14:42 2010
@@ -1429,7 +1429,7 @@
llvm::Value *EmitIvarOffset(const ObjCInterfaceDecl *Interface,
const ObjCIvarDecl *Ivar);
LValue EmitLValueForAnonRecordField(llvm::Value* Base,
- const FieldDecl* Field,
+ const IndirectFieldDecl* Field,
unsigned CVRQualifiers);
LValue EmitLValueForField(llvm::Value* Base, const FieldDecl* Field,
unsigned CVRQualifiers);
Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=120900&r1=120899&r2=120900&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Sat Dec 4 03:14:42 2010
@@ -3608,7 +3608,8 @@
InitializedBases.insert(
Context.getCanonicalType(QualType(Initializers[I]->getBaseClass(), 0)));
else
- InitializedFields.insert(cast<FieldDecl>(Initializers[I]->getMember()));
+ InitializedFields.insert(cast<FieldDecl>(
+ Initializers[I]->getAnyMember()));
}
// Add completions for base classes.
@@ -3670,8 +3671,8 @@
if (!InitializedFields.insert(cast<FieldDecl>(Field->getCanonicalDecl()))) {
SawLastInitializer
= NumInitializers > 0 &&
- Initializers[NumInitializers - 1]->isMemberInitializer() &&
- Initializers[NumInitializers - 1]->getMember() == *Field;
+ Initializers[NumInitializers - 1]->isAnyMemberInitializer() &&
+ Initializers[NumInitializers - 1]->getAnyMember() == *Field;
continue;
}
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=120900&r1=120899&r2=120900&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Sat Dec 4 03:14:42 2010
@@ -1070,16 +1070,16 @@
if (Result.first != Result.second) {
Member = dyn_cast<FieldDecl>(*Result.first);
- // Handle anonymous union case.
- if (!Member)
+ if (Member)
+ return BuildMemberInitializer(Member, (Expr**)Args, NumArgs, IdLoc,
+ LParenLoc, RParenLoc);
+ // Handle anonymous union case.
if (IndirectFieldDecl* IndirectField
- = dyn_cast<IndirectFieldDecl>(*Result.first))
- Member = IndirectField->getAnonField();
+ = dyn_cast<IndirectFieldDecl>(*Result.first))
+ return BuildMemberInitializer(IndirectField, (Expr**)Args,
+ NumArgs, IdLoc,
+ LParenLoc, RParenLoc);
}
-
- if (Member)
- return BuildMemberInitializer(Member, (Expr**)Args, NumArgs, IdLoc,
- LParenLoc, RParenLoc);
}
// It didn't name a member, so see if it names a class.
QualType BaseType;
@@ -1195,8 +1195,10 @@
/// uninitialized field was used an updates the SourceLocation parameter; false
/// otherwise.
static bool InitExprContainsUninitializedFields(const Stmt *S,
- const FieldDecl *LhsField,
+ const ValueDecl *LhsField,
SourceLocation *L) {
+ assert(isa<FieldDecl>(LhsField) || isa<IndirectFieldDecl>(LhsField));
+
if (isa<CallExpr>(S)) {
// Do not descend into function calls or constructors, as the use
// of an uninitialized field may be valid. One would have to inspect
@@ -1257,11 +1259,15 @@
return false;
}
+template <typename T>
MemInitResult
-Sema::BuildMemberInitializer(FieldDecl *Member, Expr **Args,
+Sema::BuildMemberInitializer(T *Member, Expr **Args,
unsigned NumArgs, SourceLocation IdLoc,
SourceLocation LParenLoc,
SourceLocation RParenLoc) {
+ assert((isa<FieldDecl>(Member) || isa<IndirectFieldDecl>(Member)) ||
+ "Member must be a FieldDecl or IndirectFieldDecl");
+
if (Member->isInvalidDecl())
return true;
@@ -1750,26 +1756,12 @@
};
}
-static void RecordFieldInitializer(BaseAndFieldInfo &Info,
- FieldDecl *Top, FieldDecl *Field,
- CXXBaseOrMemberInitializer *Init) {
- // If the member doesn't need to be initialized, Init will still be null.
- if (!Init)
- return;
-
- Info.AllToInit.push_back(Init);
- if (Field != Top) {
- Init->setMember(Top);
- Init->setAnonUnionMember(Field);
- }
-}
-
static bool CollectFieldInitializer(BaseAndFieldInfo &Info,
FieldDecl *Top, FieldDecl *Field) {
// Overwhelmingly common case: we have a direct initializer for this field.
if (CXXBaseOrMemberInitializer *Init = Info.AllBaseFields.lookup(Field)) {
- RecordFieldInitializer(Info, Top, Field, Init);
+ Info.AllToInit.push_back(Init);
return false;
}
@@ -1789,7 +1781,7 @@
for (RecordDecl::field_iterator FA = FieldClassDecl->field_begin(),
EA = FieldClassDecl->field_end(); FA != EA; FA++) {
if (CXXBaseOrMemberInitializer *Init = Info.AllBaseFields.lookup(*FA)) {
- RecordFieldInitializer(Info, Top, *FA, Init);
+ Info.AllToInit.push_back(Init);
// Once we've initialized a field of an anonymous union, the union
// field in the class is also initialized, so exit immediately.
@@ -1826,7 +1818,9 @@
if (BuildImplicitMemberInitializer(Info.S, Info.Ctor, Info.IIK, Field, Init))
return true;
- RecordFieldInitializer(Info, Top, Field, Init);
+ if (Init)
+ Info.AllToInit.push_back(Init);
+
return false;
}
@@ -1866,7 +1860,7 @@
if (Member->isBaseInitializer())
Info.AllBaseFields[Member->getBaseClass()->getAs<RecordType>()] = Member;
else
- Info.AllBaseFields[Member->getMember()] = Member;
+ Info.AllBaseFields[Member->getAnyMember()] = Member;
}
// Keep track of the direct virtual bases.
@@ -1965,21 +1959,14 @@
}
static void *GetKeyForMember(ASTContext &Context,
- CXXBaseOrMemberInitializer *Member,
- bool MemberMaybeAnon = false) {
- if (!Member->isMemberInitializer())
+ CXXBaseOrMemberInitializer *Member) {
+ if (!Member->isAnyMemberInitializer())
return GetKeyForBase(Context, QualType(Member->getBaseClass(), 0));
// For fields injected into the class via declaration of an anonymous union,
// use its anonymous union class declaration as the unique key.
- FieldDecl *Field = Member->getMember();
-
- // After SetBaseOrMemberInitializers call, Field is the anonymous union
- // data member of the class. Data member used in the initializer list is
- // in AnonUnionMember field.
- if (MemberMaybeAnon && Field->isAnonymousStructOrUnion())
- Field = Member->getAnonUnionMember();
-
+ FieldDecl *Field = Member->getAnyMember();
+
// If the field is a member of an anonymous struct or union, our key
// is the anonymous record decl that's a direct child of the class.
RecordDecl *RD = Field->getParent();
@@ -2042,7 +2029,7 @@
CXXBaseOrMemberInitializer *PrevInit = 0;
for (unsigned InitIndex = 0; InitIndex != NumInits; ++InitIndex) {
CXXBaseOrMemberInitializer *Init = Inits[InitIndex];
- void *InitKey = GetKeyForMember(SemaRef.Context, Init, true);
+ void *InitKey = GetKeyForMember(SemaRef.Context, Init);
// Scan forward to try to find this initializer in the idealized
// initializers list.
@@ -2058,13 +2045,13 @@
SemaRef.Diag(PrevInit->getSourceLocation(),
diag::warn_initializer_out_of_order);
- if (PrevInit->isMemberInitializer())
- D << 0 << PrevInit->getMember()->getDeclName();
+ if (PrevInit->isAnyMemberInitializer())
+ D << 0 << PrevInit->getAnyMember()->getDeclName();
else
D << 1 << PrevInit->getBaseClassInfo()->getType();
- if (Init->isMemberInitializer())
- D << 0 << Init->getMember()->getDeclName();
+ if (Init->isAnyMemberInitializer())
+ D << 0 << Init->getAnyMember()->getDeclName();
else
D << 1 << Init->getBaseClassInfo()->getType();
@@ -2115,7 +2102,7 @@
bool CheckRedundantUnionInit(Sema &S,
CXXBaseOrMemberInitializer *Init,
RedundantUnionMap &Unions) {
- FieldDecl *Field = Init->getMember();
+ FieldDecl *Field = Init->getAnyMember();
RecordDecl *Parent = Field->getParent();
if (!Parent->isAnonymousStructOrUnion())
return false;
@@ -2182,8 +2169,8 @@
// Set the source order index.
Init->setSourceOrder(i);
- if (Init->isMemberInitializer()) {
- FieldDecl *Field = Init->getMember();
+ if (Init->isAnyMemberInitializer()) {
+ FieldDecl *Field = Init->getAnyMember();
if (CheckRedundantInit(*this, Init, Members[Field]) ||
CheckRedundantUnionInit(*this, Init, MemberUnions))
HadError = true;
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=120900&r1=120899&r2=120900&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Sat Dec 4 03:14:42 2010
@@ -2341,22 +2341,27 @@
Init->getRParenLoc(),
New->getParent());
} else if (Init->isMemberInitializer()) {
- FieldDecl *Member;
-
- // Is this an anonymous union?
- if (FieldDecl *UnionInit = Init->getAnonUnionMember())
- Member = cast<FieldDecl>(FindInstantiatedDecl(Init->getMemberLocation(),
- UnionInit, TemplateArgs));
- else
- Member = cast<FieldDecl>(FindInstantiatedDecl(Init->getMemberLocation(),
- Init->getMember(),
- TemplateArgs));
+ FieldDecl *Member = cast<FieldDecl>(FindInstantiatedDecl(
+ Init->getMemberLocation(),
+ Init->getMember(),
+ TemplateArgs));
NewInit = BuildMemberInitializer(Member, (Expr **)NewArgs.data(),
NewArgs.size(),
Init->getSourceLocation(),
Init->getLParenLoc(),
Init->getRParenLoc());
+ } else if (Init->isIndirectMemberInitializer()) {
+ IndirectFieldDecl *IndirectMember =
+ cast<IndirectFieldDecl>(FindInstantiatedDecl(
+ Init->getMemberLocation(),
+ Init->getIndirectMember(), TemplateArgs));
+
+ NewInit = BuildMemberInitializer(IndirectMember, (Expr **)NewArgs.data(),
+ NewArgs.size(),
+ Init->getSourceLocation(),
+ Init->getLParenLoc(),
+ Init->getRParenLoc());
}
if (NewInit.isInvalid()) {
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=120900&r1=120899&r2=120900&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Sat Dec 4 03:14:42 2010
@@ -4270,18 +4270,21 @@
TypeSourceInfo *BaseClassInfo = 0;
bool IsBaseVirtual = false;
FieldDecl *Member = 0;
+ IndirectFieldDecl *IndirectMember = 0;
bool IsBaseInitializer = Record[Idx++];
if (IsBaseInitializer) {
BaseClassInfo = GetTypeSourceInfo(F, Record, Idx);
IsBaseVirtual = Record[Idx++];
} else {
- Member = cast<FieldDecl>(GetDecl(Record[Idx++]));
+ bool IsIndirectMemberInitializer = Record[Idx++];
+ if (IsIndirectMemberInitializer)
+ IndirectMember = cast<IndirectFieldDecl>(GetDecl(Record[Idx++]));
+ else
+ Member = cast<FieldDecl>(GetDecl(Record[Idx++]));
}
SourceLocation MemberLoc = ReadSourceLocation(F, Record, Idx);
Expr *Init = ReadExpr(F);
- FieldDecl *AnonUnionMember
- = cast_or_null<FieldDecl>(GetDecl(Record[Idx++]));
SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx);
SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx);
bool IsWritten = Record[Idx++];
@@ -4302,8 +4305,14 @@
IsBaseVirtual, LParenLoc,
Init, RParenLoc);
} else if (IsWritten) {
- BOMInit = new (C) CXXBaseOrMemberInitializer(C, Member, MemberLoc,
- LParenLoc, Init, RParenLoc);
+ if (Member)
+ BOMInit = new (C) CXXBaseOrMemberInitializer(C, Member, MemberLoc,
+ LParenLoc, Init,
+ RParenLoc);
+ else
+ BOMInit = new (C) CXXBaseOrMemberInitializer(C, IndirectMember,
+ MemberLoc, LParenLoc,
+ Init, RParenLoc);
} else {
BOMInit = CXXBaseOrMemberInitializer::Create(C, Member, MemberLoc,
LParenLoc, Init, RParenLoc,
@@ -4313,7 +4322,6 @@
if (IsWritten)
BOMInit->setSourceOrder(SourceOrderOrNumArrayIndices);
- BOMInit->setAnonUnionMember(AnonUnionMember);
BaseOrMemberInitializers[i] = BOMInit;
}
}
Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=120900&r1=120899&r2=120900&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Sat Dec 4 03:14:42 2010
@@ -3255,11 +3255,15 @@
AddTypeSourceInfo(Init->getBaseClassInfo(), Record);
Record.push_back(Init->isBaseVirtual());
} else {
- AddDeclRef(Init->getMember(), Record);
+ Record.push_back(Init->isIndirectMemberInitializer());
+ if (Init->isIndirectMemberInitializer())
+ AddDeclRef(Init->getIndirectMember(), Record);
+ else
+ AddDeclRef(Init->getMember(), Record);
}
+
AddSourceLocation(Init->getMemberLocation(), Record);
AddStmt(Init->getInit());
- AddDeclRef(Init->getAnonUnionMember(), Record);
AddSourceLocation(Init->getLParenLoc(), Record);
AddSourceLocation(Init->getRParenLoc(), Record);
Record.push_back(Init->isWritten());
Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=120900&r1=120899&r2=120900&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Sat Dec 4 03:14:42 2010
@@ -740,8 +740,8 @@
// Visit the initializers in source order
for (unsigned I = 0, N = WrittenInits.size(); I != N; ++I) {
CXXBaseOrMemberInitializer *Init = WrittenInits[I];
- if (Init->isMemberInitializer()) {
- if (Visit(MakeCursorMemberRef(Init->getMember(),
+ if (Init->isAnyMemberInitializer()) {
+ if (Visit(MakeCursorMemberRef(Init->getAnyMember(),
Init->getMemberLocation(), TU)))
return true;
} else if (TypeSourceInfo *BaseInfo = Init->getBaseClassInfo()) {
More information about the cfe-commits
mailing list