Make CodeGen produce an error if we come across a non-constant initializer list that involves the GNU array-range designator extension

llvm-svn: 63327
This commit is contained in:
Douglas Gregor
2009-01-29 19:42:23 +00:00
parent 56b3b77c7d
commit bf7207a11f
7 changed files with 27 additions and 11 deletions

View File

@@ -1668,6 +1668,10 @@ class InitListExpr : public Expr {
/// field within the union will be initialized.
FieldDecl *UnionFieldInit;
/// Whether this initializer list originally had a GNU array-range
/// designator in it. This is a temporary marker used by CodeGen.
bool HadArrayRangeDesignator;
public:
InitListExpr(SourceLocation lbraceloc, Expr **initexprs, unsigned numinits,
SourceLocation rbraceloc);
@@ -1728,6 +1732,11 @@ public:
InitListExpr *getSyntacticForm() const { return SyntacticForm; }
void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; }
bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; }
void sawArrayRangeDesignator() {
HadArrayRangeDesignator = true;
}
virtual SourceRange getSourceRange() const {
return SourceRange(LBraceLoc, RBraceLoc);
}

View File

@@ -60,8 +60,6 @@ DIAG(warn_initializer_overrides, WARNING,
"initializer overrides prior initialization of this subobject")
DIAG(note_previous_initializer, NOTE,
"previous initialization %select{|with side effects }0is here%select{| (side effects may not occur at run time)}0")
DIAG(warn_gnu_array_range_designator_side_effects, WARNING,
"side effects due to the GNU array-range designator extension may occur multiple times")
// Declarations.
DIAG(ext_vla, EXTENSION,

View File

@@ -224,7 +224,7 @@ InitListExpr::InitListExpr(SourceLocation lbraceloc,
SourceLocation rbraceloc)
: Expr(InitListExprClass, QualType()),
LBraceLoc(lbraceloc), RBraceLoc(rbraceloc), SyntacticForm(0),
UnionFieldInit(0) {
UnionFieldInit(0), HadArrayRangeDesignator(false) {
InitExprs.insert(InitExprs.end(), initExprs, initExprs+numInits);
}

View File

@@ -307,6 +307,10 @@ void AggExprEmitter::EmitNonConstInit(InitListExpr *E) {
cast<llvm::PointerType>(DestPtr->getType());
const llvm::Type *DestType = APType->getElementType();
if (E->hadArrayRangeDesignator()) {
CGF.ErrorUnsupported(E, "GNU array range designator extension");
}
if (const llvm::ArrayType *AType = dyn_cast<llvm::ArrayType>(DestType)) {
unsigned NumInitElements = E->getNumInits();
@@ -397,6 +401,10 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) {
return;
}
#endif
if (E->hadArrayRangeDesignator()) {
CGF.ErrorUnsupported(E, "GNU array range designator extension");
}
// Handle initialization of an array.
if (E->getType()->isArrayType()) {
const llvm::PointerType *APType =

View File

@@ -169,6 +169,10 @@ public:
Value *VisitInitListExpr(InitListExpr *E) {
unsigned NumInitElements = E->getNumInits();
if (E->hadArrayRangeDesignator()) {
CGF.ErrorUnsupported(E, "GNU array range designator extension");
}
const llvm::VectorType *VType =
dyn_cast<llvm::VectorType>(ConvertType(E->getType()));

View File

@@ -867,9 +867,7 @@ InitListChecker::CheckDesignatedInitializer(InitListExpr *IList,
IndexExpr = DIE->getArrayRangeEnd(*D);
if (DesignatedStartIndex.getZExtValue() != DesignatedEndIndex.getZExtValue())
SemaRef->Diag(D->getEllipsisLoc(),
diag::warn_gnu_array_range_designator_side_effects)
<< SourceRange(D->getLBracketLoc(), D->getRBracketLoc());
FullyStructuredList->sawArrayRangeDesignator();
}
if (isa<ConstantArrayType>(AT)) {

View File

@@ -18,8 +18,7 @@ int iarray2[10] = {
};
int iarray3[10] = {
[5 ... 12] = 2 // expected-error{{array designator index (12) exceeds array bounds (10)}}\
// expected-warning{{side effects due to the GNU array-range designator extension may occur multiple times}}
[5 ... 12] = 2 // expected-error{{array designator index (12) exceeds array bounds (10)}}
};
struct point {
@@ -45,8 +44,8 @@ struct point array[10] = {
struct point array2[10] = {
[10].x = 2.0, // expected-error{{array designator index (10) exceeds array bounds (10)}}
[4 ... 5].y = 2.0, // expected-warning{{side effects due to the GNU array-range designator extension may occur multiple times}}
[4 ... 6] = { .x = 3, .y = 4.0 } // expected-warning{{side effects due to the GNU array-range designator extension may occur multiple times}}
[4 ... 5].y = 2.0,
[4 ... 6] = { .x = 3, .y = 4.0 }
};
struct point array3[10] = {
@@ -117,7 +116,7 @@ struct disklabel_ops disklabel64_ops = {
// PR clang/3378
int bitwidth[] = { [(long long int)1] = 5, [(short int)2] = 2 };
int a[]= { [sizeof(int)] = 0 };
int a2[]= { [0 ... sizeof(int)] = 0 }; // expected-warning{{side effects due to the GNU array-range designator extension may occur multiple times}}
int a2[]= { [0 ... sizeof(int)] = 0 };
// Test warnings about initializers overriding previous initializers
struct X {