[cfe-commits] r41696 - in /cfe/trunk: Sema/Sema.h Sema/SemaDecl.cpp include/clang/AST/Expr.h
Steve Naroff
snaroff at apple.com
Tue Sep 4 07:36:54 PDT 2007
Author: snaroff
Date: Tue Sep 4 09:36:54 2007
New Revision: 41696
URL: http://llvm.org/viewvc/llvm-project?rev=41696&view=rev
Log:
Make sure initializer type promotions get propagated.
This fixes a recent regression with Codegen/mandel.c.
Modified:
cfe/trunk/Sema/Sema.h
cfe/trunk/Sema/SemaDecl.cpp
cfe/trunk/include/clang/AST/Expr.h
Modified: cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.h?rev=41696&r1=41695&r2=41696&view=diff
==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Tue Sep 4 09:36:54 2007
@@ -442,10 +442,11 @@
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);
Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=41696&r1=41695&r2=41696&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Tue Sep 4 09:36:54 2007
@@ -239,7 +239,7 @@
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 @@
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 @@
} 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 @@
maxElements, hadError);
}
} else {
- hadError = CheckInitExpr(expr, isStatic, ElementType);
+ hadError = CheckInitExpr(expr, IList, i, isStatic, ElementType);
}
nInitializers++;
}
@@ -366,7 +370,7 @@
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 @@
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);
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=41696&r1=41695&r2=41696&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Tue Sep 4 09:36:54 2007
@@ -991,6 +991,11 @@
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);
}
More information about the cfe-commits
mailing list