forked from OSchip/llvm-project
When list-initializing a vector, try to copy-initialize from vectors instead
of descending into the subelements. rdar://problem/8345836 llvm-svn: 117749
This commit is contained in:
parent
7d5cd97080
commit
6a16b2f10c
|
@ -839,66 +839,95 @@ void InitListChecker::CheckVectorType(const InitializedEntity &Entity,
|
||||||
unsigned &Index,
|
unsigned &Index,
|
||||||
InitListExpr *StructuredList,
|
InitListExpr *StructuredList,
|
||||||
unsigned &StructuredIndex) {
|
unsigned &StructuredIndex) {
|
||||||
if (Index < IList->getNumInits()) {
|
if (Index >= IList->getNumInits())
|
||||||
const VectorType *VT = DeclType->getAs<VectorType>();
|
return;
|
||||||
unsigned maxElements = VT->getNumElements();
|
|
||||||
unsigned numEltsInit = 0;
|
|
||||||
QualType elementType = VT->getElementType();
|
|
||||||
|
|
||||||
if (!SemaRef.getLangOptions().OpenCL) {
|
const VectorType *VT = DeclType->getAs<VectorType>();
|
||||||
InitializedEntity ElementEntity =
|
unsigned maxElements = VT->getNumElements();
|
||||||
InitializedEntity::InitializeElement(SemaRef.Context, 0, Entity);
|
unsigned numEltsInit = 0;
|
||||||
|
QualType elementType = VT->getElementType();
|
||||||
|
|
||||||
for (unsigned i = 0; i < maxElements; ++i, ++numEltsInit) {
|
if (!SemaRef.getLangOptions().OpenCL) {
|
||||||
// Don't attempt to go past the end of the init list
|
// If the initializing element is a vector, try to copy-initialize
|
||||||
if (Index >= IList->getNumInits())
|
// instead of breaking it apart (which is doomed to failure anyway).
|
||||||
break;
|
Expr *Init = IList->getInit(Index);
|
||||||
|
if (!isa<InitListExpr>(Init) && Init->getType()->isVectorType()) {
|
||||||
ElementEntity.setElementIndex(Index);
|
ExprResult Result =
|
||||||
CheckSubElementType(ElementEntity, IList, elementType, Index,
|
SemaRef.PerformCopyInitialization(Entity, Init->getLocStart(),
|
||||||
StructuredList, StructuredIndex);
|
SemaRef.Owned(Init));
|
||||||
}
|
|
||||||
} else {
|
Expr *ResultExpr = 0;
|
||||||
InitializedEntity ElementEntity =
|
if (Result.isInvalid())
|
||||||
InitializedEntity::InitializeElement(SemaRef.Context, 0, Entity);
|
hadError = true; // types weren't compatible.
|
||||||
|
else {
|
||||||
|
ResultExpr = Result.takeAs<Expr>();
|
||||||
|
|
||||||
// OpenCL initializers allows vectors to be constructed from vectors.
|
if (ResultExpr != Init) {
|
||||||
for (unsigned i = 0; i < maxElements; ++i) {
|
// The type was promoted, update initializer list.
|
||||||
// Don't attempt to go past the end of the init list
|
IList->setInit(Index, ResultExpr);
|
||||||
if (Index >= IList->getNumInits())
|
|
||||||
break;
|
|
||||||
|
|
||||||
ElementEntity.setElementIndex(Index);
|
|
||||||
|
|
||||||
QualType IType = IList->getInit(Index)->getType();
|
|
||||||
if (!IType->isVectorType()) {
|
|
||||||
CheckSubElementType(ElementEntity, IList, elementType, Index,
|
|
||||||
StructuredList, StructuredIndex);
|
|
||||||
++numEltsInit;
|
|
||||||
} else {
|
|
||||||
QualType VecType;
|
|
||||||
const VectorType *IVT = IType->getAs<VectorType>();
|
|
||||||
unsigned numIElts = IVT->getNumElements();
|
|
||||||
|
|
||||||
if (IType->isExtVectorType())
|
|
||||||
VecType = SemaRef.Context.getExtVectorType(elementType, numIElts);
|
|
||||||
else
|
|
||||||
VecType = SemaRef.Context.getVectorType(elementType, numIElts,
|
|
||||||
IVT->getAltiVecSpecific());
|
|
||||||
CheckSubElementType(ElementEntity, IList, VecType, Index,
|
|
||||||
StructuredList, StructuredIndex);
|
|
||||||
numEltsInit += numIElts;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (hadError)
|
||||||
|
++StructuredIndex;
|
||||||
|
else
|
||||||
|
UpdateStructuredListElement(StructuredList, StructuredIndex, ResultExpr);
|
||||||
|
++Index;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenCL requires all elements to be initialized.
|
InitializedEntity ElementEntity =
|
||||||
if (numEltsInit != maxElements)
|
InitializedEntity::InitializeElement(SemaRef.Context, 0, Entity);
|
||||||
if (SemaRef.getLangOptions().OpenCL)
|
|
||||||
SemaRef.Diag(IList->getSourceRange().getBegin(),
|
for (unsigned i = 0; i < maxElements; ++i, ++numEltsInit) {
|
||||||
diag::err_vector_incorrect_num_initializers)
|
// Don't attempt to go past the end of the init list
|
||||||
<< (numEltsInit < maxElements) << maxElements << numEltsInit;
|
if (Index >= IList->getNumInits())
|
||||||
|
break;
|
||||||
|
|
||||||
|
ElementEntity.setElementIndex(Index);
|
||||||
|
CheckSubElementType(ElementEntity, IList, elementType, Index,
|
||||||
|
StructuredList, StructuredIndex);
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InitializedEntity ElementEntity =
|
||||||
|
InitializedEntity::InitializeElement(SemaRef.Context, 0, Entity);
|
||||||
|
|
||||||
|
// OpenCL initializers allows vectors to be constructed from vectors.
|
||||||
|
for (unsigned i = 0; i < maxElements; ++i) {
|
||||||
|
// Don't attempt to go past the end of the init list
|
||||||
|
if (Index >= IList->getNumInits())
|
||||||
|
break;
|
||||||
|
|
||||||
|
ElementEntity.setElementIndex(Index);
|
||||||
|
|
||||||
|
QualType IType = IList->getInit(Index)->getType();
|
||||||
|
if (!IType->isVectorType()) {
|
||||||
|
CheckSubElementType(ElementEntity, IList, elementType, Index,
|
||||||
|
StructuredList, StructuredIndex);
|
||||||
|
++numEltsInit;
|
||||||
|
} else {
|
||||||
|
QualType VecType;
|
||||||
|
const VectorType *IVT = IType->getAs<VectorType>();
|
||||||
|
unsigned numIElts = IVT->getNumElements();
|
||||||
|
|
||||||
|
if (IType->isExtVectorType())
|
||||||
|
VecType = SemaRef.Context.getExtVectorType(elementType, numIElts);
|
||||||
|
else
|
||||||
|
VecType = SemaRef.Context.getVectorType(elementType, numIElts,
|
||||||
|
IVT->getAltiVecSpecific());
|
||||||
|
CheckSubElementType(ElementEntity, IList, VecType, Index,
|
||||||
|
StructuredList, StructuredIndex);
|
||||||
|
numEltsInit += numIElts;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OpenCL requires all elements to be initialized.
|
||||||
|
if (numEltsInit != maxElements)
|
||||||
|
if (SemaRef.getLangOptions().OpenCL)
|
||||||
|
SemaRef.Diag(IList->getSourceRange().getBegin(),
|
||||||
|
diag::err_vector_incorrect_num_initializers)
|
||||||
|
<< (numEltsInit < maxElements) << maxElements << numEltsInit;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitListChecker::CheckArrayType(const InitializedEntity &Entity,
|
void InitListChecker::CheckArrayType(const InitializedEntity &Entity,
|
||||||
|
|
|
@ -33,3 +33,12 @@ __attribute__((vector_size(16))) float f2(
|
||||||
typedef float __attribute__((ext_vector_type (3))) float3;
|
typedef float __attribute__((ext_vector_type (3))) float3;
|
||||||
int test2[sizeof(float3) == sizeof(float4) ? 1 : -1];
|
int test2[sizeof(float3) == sizeof(float4) ? 1 : -1];
|
||||||
|
|
||||||
|
// rdar://problem/8345836
|
||||||
|
typedef long long __attribute__((vector_size(16))) longlong2;
|
||||||
|
typedef short __attribute__((vector_size(16))) short8;
|
||||||
|
typedef short __attribute__((vector_size(8))) short4;
|
||||||
|
void test3() {
|
||||||
|
extern short8 test3_helper(void);
|
||||||
|
longlong2 arr1[2] = { test3_helper(), test3_helper() };
|
||||||
|
short4 arr2[2] = { test3_helper(), test3_helper() }; // expected-error 2 {{initializing 'short4' with an expression of incompatible type 'short8'}}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue