]> granicus.if.org Git - clang/commitdiff
Make CodeGen produce an error if we come across a non-constant initializer list that...
authorDouglas Gregor <dgregor@apple.com>
Thu, 29 Jan 2009 19:42:23 +0000 (19:42 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 29 Jan 2009 19:42:23 +0000 (19:42 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63327 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Expr.h
include/clang/Basic/DiagnosticSemaKinds.def
lib/AST/Expr.cpp
lib/CodeGen/CGExprAgg.cpp
lib/CodeGen/CGExprScalar.cpp
lib/Sema/SemaInit.cpp
test/Sema/designated-initializers.c

index c6ac007a1316ddf8740f812a6e73dff3cc3e99da..94beaf31e2c7618603065fc0e35baca012cc7361 100644 (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);
   } 
index 63955adc13e6f1e0b97573dcecdc46135582eb90..8cafa318f0e435f06de42fdb4a6e772418dcd77a 100644 (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,
index 8a041982936cd5c92bdff4d92f35168c23ae50fd..35384d880c9fb8ef1824ea9982910e0237bf89d3 100644 (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);
 }
index f985763b5c39478b91c2fe0c657829597cd5b341..bf80b94d21e657b9208c56da56b7584a4cdf7463 100644 (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 =
index f855e23ba03f9f2261417550a17955890eaf4b47..1d389b6049c2f30af4da823308c5922f2016672f 100644 (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()));
     
index 5d7f705edb120d3a919cc29ce95da938d0c5165c..77679ee36f981e297499dbb6903bb65bd9c828b9 100644 (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)) {
index efd0d406511b82f7b6390ae1aae70d87a78309ca..53da306c4c320dec3b90d6d550e8d48a83368313 100644 (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 {