]> granicus.if.org Git - clang/commitdiff
Make sure initializer type promotions get propagated.
authorSteve Naroff <snaroff@apple.com>
Tue, 4 Sep 2007 14:36:54 +0000 (14:36 +0000)
committerSteve Naroff <snaroff@apple.com>
Tue, 4 Sep 2007 14:36:54 +0000 (14:36 +0000)
This fixes a recent regression with Codegen/mandel.c.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41696 91177308-0d34-0410-b5e6-96231b3b80d8

Sema/Sema.h
Sema/SemaDecl.cpp
include/clang/AST/Expr.h

index 95b89002ed8a59ef10c8c467006c1568e30c5697..b7500f86888985dee7285fc6fb01fe97c2098afb 100644 (file)
@@ -442,10 +442,11 @@ private:
                                    IdentifierInfo &Comp, SourceLocation CmpLoc);
   
   /// type checking declaration initializers (C99 6.7.8)
-  bool CheckInitializer(Expr *simpleInit_or_initList, QualType &declType,
+  bool CheckInitializer(Expr *&simpleInit_or_initList, QualType &declType,
                         bool isStatic);
-  bool CheckSingleInitializer(Expr *simpleInit, QualType declType);
-  bool CheckInitExpr(Expr *expr, bool isStatic, QualType ElementType);
+  bool CheckSingleInitializer(Expr *&simpleInit, QualType declType);
+  bool CheckInitExpr(Expr *expr, InitListExpr *IList, unsigned slot,
+                     bool isStatic, QualType ElementType);
   void CheckVariableInitList(QualType DeclType, InitListExpr *IList, 
                              QualType ElementType, bool isStatic, 
                              int &nInitializers, bool &hadError);
index a1ef816b01ef1b740021e970496068781749a077..b178e099ba21b8a4d0b7789a73e547cf480c4789 100644 (file)
@@ -239,7 +239,7 @@ Sema::DeclTy *Sema::ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS) {
   return 0;
 }
 
-bool Sema::CheckSingleInitializer(Expr *Init, QualType DeclType) {
+bool Sema::CheckSingleInitializer(Expr *&Init, QualType DeclType) {
   AssignmentCheckResult result;
   SourceLocation loc = Init->getLocStart();
   // Get the type before calling CheckSingleAssignmentConstraints(), since
@@ -289,8 +289,10 @@ bool Sema::CheckSingleInitializer(Expr *Init, QualType DeclType) {
   return false;
 }
 
-bool Sema::CheckInitExpr(Expr *expr, bool isStatic, QualType ElementType) {
+bool Sema::CheckInitExpr(Expr *expr, InitListExpr *IList, unsigned slot,
+                         bool isStatic, QualType ElementType) {
   SourceLocation loc;
+  Expr *savExpr = expr; // Might be promoted by CheckSingleInitializer.
 
   if (isStatic && !expr->isConstantExpr(Context, &loc)) { // C99 6.7.8p4.
     Diag(loc, diag::err_init_element_not_constant, expr->getSourceRange());
@@ -298,6 +300,8 @@ bool Sema::CheckInitExpr(Expr *expr, bool isStatic, QualType ElementType) {
   } else if (CheckSingleInitializer(expr, ElementType)) {
     return true; // types weren't compatible.
   }
+  if (savExpr != expr) // The type was promoted, update initializer list.
+    IList->setInit(slot, expr);
   return false;
 }
 
@@ -322,7 +326,7 @@ void Sema::CheckVariableInitList(QualType DeclType, InitListExpr *IList,
                               maxElements, hadError);
       }
     } else {
-      hadError = CheckInitExpr(expr, isStatic, ElementType);
+      hadError = CheckInitExpr(expr, IList, i, isStatic, ElementType);
     }
     nInitializers++;
   }
@@ -366,7 +370,7 @@ void Sema::CheckConstantInitList(QualType DeclType, InitListExpr *IList,
         CheckConstantInitList(DeclType, InitList, ElementType, isStatic, 
                               totalInits, hadError);
       } else {
-        hadError = CheckInitExpr(expr, isStatic, ElementType);
+        hadError = CheckInitExpr(expr, IList, i, isStatic, ElementType);
         nInitsAtLevel++; // increment the number of initializers at this level.
         totalInits--;    // decrement the total number of initializers.
         
@@ -388,7 +392,7 @@ void Sema::CheckConstantInitList(QualType DeclType, InitListExpr *IList,
   return;
 }
 
-bool Sema::CheckInitializer(Expr *Init, QualType &DeclType, bool isStatic) {
+bool Sema::CheckInitializer(Expr *&Init, QualType &DeclType, bool isStatic) {
   InitListExpr *InitList = dyn_cast<InitListExpr>(Init);
   if (!InitList)
     return CheckSingleInitializer(Init, DeclType);
index 037fecb64c87313660e24a0e096cc72ba5b8d74b..c5e0a6d272301272699702a8ed600d995ae45752 100644 (file)
@@ -991,6 +991,11 @@ public:
     return InitExprs[Init];
   }
   
+  void setInit(unsigned Init, Expr *expr) { 
+    assert(Init < NumInits && "Initializer access out of range!");
+    InitExprs[Init] = expr;
+  }
+  
   virtual SourceRange getSourceRange() const {
     return SourceRange(LBraceLoc, RBraceLoc);
   }