[cfe-commits] r94325 - in /cfe/trunk: lib/Sema/SemaInit.cpp test/SemaCXX/aggregate-initialization.cpp
Anders Carlsson
andersca at mac.com
Sat Jan 23 11:55:29 PST 2010
Author: andersca
Date: Sat Jan 23 13:55:29 2010
New Revision: 94325
URL: http://llvm.org/viewvc/llvm-project?rev=94325&view=rev
Log:
Baby steps towards migrating the InitListChecker over to the new initialization code. Pass an InitializedEntity pointer through to most init checker functions. Right now, it's ignored everywhere except when initializing vectors in C++.
Modified:
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/SemaCXX/aggregate-initialization.cpp
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=94325&r1=94324&r2=94325&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Sat Jan 23 13:55:29 2010
@@ -206,21 +206,25 @@
unsigned &Index, InitListExpr *StructuredList,
unsigned &StructuredIndex,
bool TopLevelObject = false);
- void CheckExplicitInitList(InitListExpr *IList, QualType &T,
+ void CheckExplicitInitList(const InitializedEntity *Entity,
+ InitListExpr *IList, QualType &T,
unsigned &Index, InitListExpr *StructuredList,
unsigned &StructuredIndex,
bool TopLevelObject = false);
- void CheckListElementTypes(InitListExpr *IList, QualType &DeclType,
+ void CheckListElementTypes(const InitializedEntity *Entity,
+ InitListExpr *IList, QualType &DeclType,
bool SubobjectIsDesignatorContext,
unsigned &Index,
InitListExpr *StructuredList,
unsigned &StructuredIndex,
bool TopLevelObject = false);
- void CheckSubElementType(InitListExpr *IList, QualType ElemType,
+ void CheckSubElementType(const InitializedEntity *Entity,
+ InitListExpr *IList, QualType ElemType,
unsigned &Index,
InitListExpr *StructuredList,
unsigned &StructuredIndex);
- void CheckScalarType(InitListExpr *IList, QualType DeclType,
+ void CheckScalarType(const InitializedEntity *Entity,
+ InitListExpr *IList, QualType DeclType,
unsigned &Index,
InitListExpr *StructuredList,
unsigned &StructuredIndex);
@@ -228,7 +232,8 @@
unsigned &Index,
InitListExpr *StructuredList,
unsigned &StructuredIndex);
- void CheckVectorType(InitListExpr *IList, QualType DeclType, unsigned &Index,
+ void CheckVectorType(const InitializedEntity *Entity,
+ InitListExpr *IList, QualType DeclType, unsigned &Index,
InitListExpr *StructuredList,
unsigned &StructuredIndex);
void CheckStructUnionTypes(InitListExpr *IList, QualType DeclType,
@@ -461,7 +466,8 @@
unsigned newStructuredIndex = 0;
FullyStructuredList
= getStructuredSubobjectInit(IL, newIndex, T, 0, 0, IL->getSourceRange());
- CheckExplicitInitList(IL, T, newIndex, FullyStructuredList, newStructuredIndex,
+ CheckExplicitInitList(&Entity, IL, T, newIndex,
+ FullyStructuredList, newStructuredIndex,
/*TopLevelObject=*/true);
if (!hadError) {
@@ -532,7 +538,7 @@
// Check the element types and build the structural subobject.
unsigned StartIndex = Index;
- CheckListElementTypes(ParentIList, T, false, Index,
+ CheckListElementTypes(0, ParentIList, T, false, Index,
StructuredSubobjectInitList,
StructuredSubobjectInitIndex,
TopLevelObject);
@@ -548,7 +554,8 @@
}
}
-void InitListChecker::CheckExplicitInitList(InitListExpr *IList, QualType &T,
+void InitListChecker::CheckExplicitInitList(const InitializedEntity *Entity,
+ InitListExpr *IList, QualType &T,
unsigned &Index,
InitListExpr *StructuredList,
unsigned &StructuredIndex,
@@ -556,8 +563,8 @@
assert(IList->isExplicit() && "Illegal Implicit InitListExpr");
SyntacticToSemantic[IList] = StructuredList;
StructuredList->setSyntacticForm(IList);
- CheckListElementTypes(IList, T, true, Index, StructuredList,
- StructuredIndex, TopLevelObject);
+ CheckListElementTypes(Entity, IList, T, /*SubobjectIsDesignatorContext=*/true,
+ Index, StructuredList, StructuredIndex, TopLevelObject);
IList->setType(T);
StructuredList->setType(T);
if (hadError)
@@ -608,7 +615,8 @@
<< CodeModificationHint::CreateRemoval(IList->getLocEnd());
}
-void InitListChecker::CheckListElementTypes(InitListExpr *IList,
+void InitListChecker::CheckListElementTypes(const InitializedEntity *Entity,
+ InitListExpr *IList,
QualType &DeclType,
bool SubobjectIsDesignatorContext,
unsigned &Index,
@@ -616,9 +624,11 @@
unsigned &StructuredIndex,
bool TopLevelObject) {
if (DeclType->isScalarType()) {
- CheckScalarType(IList, DeclType, Index, StructuredList, StructuredIndex);
+ CheckScalarType(Entity, IList, DeclType, Index,
+ StructuredList, StructuredIndex);
} else if (DeclType->isVectorType()) {
- CheckVectorType(IList, DeclType, Index, StructuredList, StructuredIndex);
+ CheckVectorType(Entity, IList, DeclType, Index,
+ StructuredList, StructuredIndex);
} else if (DeclType->isAggregateType()) {
if (DeclType->isRecordType()) {
RecordDecl *RD = DeclType->getAs<RecordType>()->getDecl();
@@ -661,7 +671,8 @@
}
}
-void InitListChecker::CheckSubElementType(InitListExpr *IList,
+void InitListChecker::CheckSubElementType(const InitializedEntity *Entity,
+ InitListExpr *IList,
QualType ElemType,
unsigned &Index,
InitListExpr *StructuredList,
@@ -674,7 +685,7 @@
= getStructuredSubobjectInit(IList, Index, ElemType,
StructuredList, StructuredIndex,
SubInitList->getSourceRange());
- CheckExplicitInitList(SubInitList, ElemType, newIndex,
+ CheckExplicitInitList(Entity, SubInitList, ElemType, newIndex,
newStructuredList, newStructuredIndex);
++StructuredIndex;
++Index;
@@ -683,7 +694,8 @@
UpdateStructuredListElement(StructuredList, StructuredIndex, Str);
++Index;
} else if (ElemType->isScalarType()) {
- CheckScalarType(IList, ElemType, Index, StructuredList, StructuredIndex);
+ CheckScalarType(Entity, IList, ElemType, Index,
+ StructuredList, StructuredIndex);
} else if (ElemType->isReferenceType()) {
CheckReferenceType(IList, ElemType, Index, StructuredList, StructuredIndex);
} else {
@@ -749,7 +761,8 @@
}
}
-void InitListChecker::CheckScalarType(InitListExpr *IList, QualType DeclType,
+void InitListChecker::CheckScalarType(const InitializedEntity *Entity,
+ InitListExpr *IList, QualType DeclType,
unsigned &Index,
InitListExpr *StructuredList,
unsigned &StructuredIndex) {
@@ -774,7 +787,7 @@
}
Sema::OwningExprResult Result =
- CheckSingleInitializer(0, SemaRef.Owned(expr), DeclType, SemaRef);
+ CheckSingleInitializer(Entity, SemaRef.Owned(expr), DeclType, SemaRef);
Expr *ResultExpr;
@@ -850,7 +863,8 @@
}
}
-void InitListChecker::CheckVectorType(InitListExpr *IList, QualType DeclType,
+void InitListChecker::CheckVectorType(const InitializedEntity *Entity,
+ InitListExpr *IList, QualType DeclType,
unsigned &Index,
InitListExpr *StructuredList,
unsigned &StructuredIndex) {
@@ -861,13 +875,31 @@
QualType elementType = VT->getElementType();
if (!SemaRef.getLangOptions().OpenCL) {
- for (unsigned i = 0; i < maxElements; ++i, ++numEltsInit) {
- // Don't attempt to go past the end of the init list
- if (Index >= IList->getNumInits())
- break;
- CheckSubElementType(IList, elementType, Index,
- StructuredList, StructuredIndex);
- }
+ // FIXME: Once we know Entity is never null we can remove this check,
+ // as well as the else block.
+ if (Entity) {
+ InitializedEntity ElementEntity =
+ InitializedEntity::InitializeElement(SemaRef.Context, 0, *Entity);
+
+ for (unsigned i = 0; i < maxElements; ++i, ++numEltsInit) {
+ // Don't attempt to go past the end of the init list
+ if (Index >= IList->getNumInits())
+ break;
+
+ ElementEntity.setElementIndex(Index);
+ CheckSubElementType(&ElementEntity, IList, elementType, Index,
+ StructuredList, StructuredIndex);
+ }
+ } else {
+ for (unsigned i = 0; i < maxElements; ++i, ++numEltsInit) {
+ // Don't attempt to go past the end of the init list
+ if (Index >= IList->getNumInits())
+ break;
+
+ CheckSubElementType(0, IList, elementType, Index,
+ StructuredList, StructuredIndex);
+ }
+ }
} else {
// OpenCL initializers allows vectors to be constructed from vectors.
for (unsigned i = 0; i < maxElements; ++i) {
@@ -876,7 +908,7 @@
break;
QualType IType = IList->getInit(Index)->getType();
if (!IType->isVectorType()) {
- CheckSubElementType(IList, elementType, Index,
+ CheckSubElementType(0, IList, elementType, Index,
StructuredList, StructuredIndex);
++numEltsInit;
} else {
@@ -884,7 +916,7 @@
unsigned numIElts = IVT->getNumElements();
QualType VecType = SemaRef.Context.getExtVectorType(elementType,
numIElts);
- CheckSubElementType(IList, VecType, Index,
+ CheckSubElementType(0, IList, VecType, Index,
StructuredList, StructuredIndex);
numEltsInit += numIElts;
}
@@ -989,7 +1021,7 @@
break;
// Check this element.
- CheckSubElementType(IList, elementType, Index,
+ CheckSubElementType(0, IList, elementType, Index,
StructuredList, StructuredIndex);
++elementIndex;
@@ -1092,7 +1124,7 @@
continue;
}
- CheckSubElementType(IList, Field->getType(), Index,
+ CheckSubElementType(0, IList, Field->getType(), Index,
StructuredList, StructuredIndex);
InitializedSomething = true;
@@ -1129,7 +1161,7 @@
}
if (isa<InitListExpr>(IList->getInit(Index)))
- CheckSubElementType(IList, Field->getType(), Index, StructuredList,
+ CheckSubElementType(0, IList, Field->getType(), Index, StructuredList,
StructuredIndex);
else
CheckImplicitInitList(IList, Field->getType(), Index, StructuredList,
@@ -1251,7 +1283,7 @@
unsigned OldIndex = Index;
IList->setInit(OldIndex, DIE->getInit());
- CheckSubElementType(IList, CurrentObjectType, Index,
+ CheckSubElementType(0, IList, CurrentObjectType, Index,
StructuredList, StructuredIndex);
// Restore the designated initializer expression in the syntactic
@@ -1459,7 +1491,7 @@
unsigned newStructuredIndex = FieldIndex;
unsigned OldIndex = Index;
IList->setInit(Index, DIE->getInit());
- CheckSubElementType(IList, Field->getType(), Index,
+ CheckSubElementType(0, IList, Field->getType(), Index,
StructuredList, newStructuredIndex);
IList->setInit(OldIndex, DIE);
if (hadError && !prevHadError) {
Modified: cfe/trunk/test/SemaCXX/aggregate-initialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/aggregate-initialization.cpp?rev=94325&r1=94324&r2=94325&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/aggregate-initialization.cpp (original)
+++ cfe/trunk/test/SemaCXX/aggregate-initialization.cpp Sat Jan 23 13:55:29 2010
@@ -30,3 +30,7 @@
// PR5817
typedef int type[][2];
const type foo = {0};
+
+// Vector initialization.
+typedef short __v4hi __attribute__ ((__vector_size__ (8)));
+__v4hi v1 = { (void *)1, 2, 3 }; // expected-error {{cannot initialize a vector element of type 'short' with an rvalue of type 'void *'}}
More information about the cfe-commits
mailing list