Switch some array initialization over to the new init code.

llvm-svn: 94327
This commit is contained in:
Anders Carlsson 2010-01-23 20:13:41 +00:00
parent 0978af83b3
commit 0cf999b663
2 changed files with 25 additions and 7 deletions

View File

@ -242,7 +242,8 @@ class InitListChecker {
InitListExpr *StructuredList,
unsigned &StructuredIndex,
bool TopLevelObject = false);
void CheckArrayType(InitListExpr *IList, QualType &DeclType,
void CheckArrayType(const InitializedEntity *Entity,
InitListExpr *IList, QualType &DeclType,
llvm::APSInt elementIndex,
bool SubobjectIsDesignatorContext, unsigned &Index,
InitListExpr *StructuredList,
@ -640,7 +641,8 @@ void InitListChecker::CheckListElementTypes(const InitializedEntity *Entity,
llvm::APSInt Zero(
SemaRef.Context.getTypeSize(SemaRef.Context.getSizeType()),
false);
CheckArrayType(IList, DeclType, Zero, SubobjectIsDesignatorContext, Index,
CheckArrayType(Entity, IList, DeclType, Zero,
SubobjectIsDesignatorContext, Index,
StructuredList, StructuredIndex);
} else
assert(0 && "Aggregate that isn't a structure or array?!");
@ -932,7 +934,8 @@ void InitListChecker::CheckVectorType(const InitializedEntity *Entity,
}
}
void InitListChecker::CheckArrayType(InitListExpr *IList, QualType &DeclType,
void InitListChecker::CheckArrayType(const InitializedEntity *Entity,
InitListExpr *IList, QualType &DeclType,
llvm::APSInt elementIndex,
bool SubobjectIsDesignatorContext,
unsigned &Index,
@ -1020,9 +1023,20 @@ void InitListChecker::CheckArrayType(InitListExpr *IList, QualType &DeclType,
if (maxElementsKnown && elementIndex == maxElements)
break;
// Check this element.
CheckSubElementType(0, IList, elementType, Index,
StructuredList, StructuredIndex);
// FIXME: Once we know that Entity is not null, we can remove this check,
// and the else block.
if (Entity) {
InitializedEntity ElementEntity =
InitializedEntity::InitializeElement(SemaRef.Context, StructuredIndex,
*Entity);
// Check this element.
CheckSubElementType(&ElementEntity, IList, elementType, Index,
StructuredList, StructuredIndex);
} else {
// Check this element.
CheckSubElementType(0, IList, elementType, Index,
StructuredList, StructuredIndex);
}
++elementIndex;
// If the array is of incomplete type, keep track of the number of
@ -1649,7 +1663,8 @@ InitListChecker::CheckDesignatedInitializer(InitListExpr *IList,
// Check the remaining elements within this array subobject.
bool prevHadError = hadError;
CheckArrayType(IList, CurrentObjectType, DesignatedStartIndex, false, Index,
CheckArrayType(0, IList, CurrentObjectType, DesignatedStartIndex,
/*SubobjectIsDesignatorContext=*/false, Index,
StructuredList, ElementIndex);
return hadError && !prevHadError;
}

View File

@ -34,3 +34,6 @@ 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 *'}}
// Array initialization.
int a[] = { (void *)1 }; // expected-error {{cannot initialize an array element of type 'int' with an rvalue of type 'void *'}}