diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-01-29 19:42:23 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-01-29 19:42:23 +0000 |
commit | a9c878086036de36482cc21e35a33cabe9699b0a (patch) | |
tree | 209336586d89088ff8f03a2ef9bda580c7d195d7 | |
parent | da3200986d9ec2ed0920e4d84ac210c889136946 (diff) |
Make CodeGen produce an error if we come across a non-constant initializer list that involves the GNU array-range designator extension
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63327 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/AST/Expr.h | 9 | ||||
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.def | 2 | ||||
-rw-r--r-- | lib/AST/Expr.cpp | 2 | ||||
-rw-r--r-- | lib/CodeGen/CGExprAgg.cpp | 8 | ||||
-rw-r--r-- | lib/CodeGen/CGExprScalar.cpp | 4 | ||||
-rw-r--r-- | lib/Sema/SemaInit.cpp | 4 | ||||
-rw-r--r-- | test/Sema/designated-initializers.c | 9 |
7 files changed, 27 insertions, 11 deletions
diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index c6ac007a13..94beaf31e2 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -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); } diff --git a/include/clang/Basic/DiagnosticSemaKinds.def b/include/clang/Basic/DiagnosticSemaKinds.def index 63955adc13..8cafa318f0 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.def +++ b/include/clang/Basic/DiagnosticSemaKinds.def @@ -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, diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 8a04198293..35384d880c 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -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); } diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp index f985763b5c..bf80b94d21 100644 --- a/lib/CodeGen/CGExprAgg.cpp +++ b/lib/CodeGen/CGExprAgg.cpp @@ -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 = diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index f855e23ba0..1d389b6049 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -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())); diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 5d7f705edb..77679ee36f 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -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)) { diff --git a/test/Sema/designated-initializers.c b/test/Sema/designated-initializers.c index efd0d40651..53da306c4c 100644 --- a/test/Sema/designated-initializers.c +++ b/test/Sema/designated-initializers.c @@ -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 { |