mirror of
https://github.com/intel/llvm.git
synced 2026-01-27 06:06:34 +08:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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()));
|
||||
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user