[cfe-commits] r72581 - in /cfe/trunk: lib/Sema/SemaInit.cpp test/Sema/vla.c
Eli Friedman
eli.friedman at gmail.com
Fri May 29 11:22:50 PDT 2009
Author: efriedma
Date: Fri May 29 13:22:49 2009
New Revision: 72581
URL: http://llvm.org/viewvc/llvm-project?rev=72581&view=rev
Log:
Revert r72575, which isn't really right, and fix up other code to
handle the construct in question correctly.
Modified:
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/Sema/vla.c
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=72581&r1=72580&r2=72581&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Fri May 29 13:22:49 2009
@@ -31,6 +31,9 @@
const ArrayType *AT = Context.getAsArrayType(DeclType);
if (!AT) return 0;
+ if (!isa<ConstantArrayType>(AT) && !isa<IncompleteArrayType>(AT))
+ return 0;
+
// See if this is a string literal or @encode.
Init = Init->IgnoreParens();
@@ -97,22 +100,21 @@
return;
}
- if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(AT)) {
- // C99 6.7.8p14. We have an array of character type with known size.
- // However, the size may be smaller or larger than the string we are
- // initializing.
- // FIXME: Avoid truncation for 64-bit length strings.
- if (StrLength-1 > CAT->getSize().getZExtValue())
- S.Diag(Str->getSourceRange().getBegin(),
- diag::warn_initializer_string_for_char_array_too_long)
- << Str->getSourceRange();
-
- // Set the type to the actual size that we are initializing. If we have
- // something like:
- // char x[1] = "foo";
- // then this will set the string literal's type to char[1].
- Str->setType(DeclT);
- }
+ const ConstantArrayType *CAT = cast<ConstantArrayType>(AT);
+
+ // C99 6.7.8p14. We have an array of character type with known size. However,
+ // the size may be smaller or larger than the string we are initializing.
+ // FIXME: Avoid truncation for 64-bit length strings.
+ if (StrLength-1 > CAT->getSize().getZExtValue())
+ S.Diag(Str->getSourceRange().getBegin(),
+ diag::warn_initializer_string_for_char_array_too_long)
+ << Str->getSourceRange();
+
+ // Set the type to the actual size that we are initializing. If we have
+ // something like:
+ // char x[1] = "foo";
+ // then this will set the string literal's type to char[1].
+ Str->setType(DeclT);
}
bool Sema::CheckInitializerTypes(Expr *&Init, QualType &DeclType,
@@ -670,10 +672,8 @@
// compatible structure or union type. In the latter case, the
// initial value of the object, including unnamed members, is
// that of the expression.
- QualType ExprType = SemaRef.Context.getCanonicalType(expr->getType());
- QualType ElemTypeCanon = SemaRef.Context.getCanonicalType(ElemType);
- if (SemaRef.Context.typesAreCompatible(ExprType.getUnqualifiedType(),
- ElemTypeCanon.getUnqualifiedType())) {
+ if (ElemType->isRecordType() &&
+ SemaRef.Context.hasSameUnqualifiedType(expr->getType(), ElemType)) {
UpdateStructuredListElement(StructuredList, StructuredIndex, expr);
++Index;
return;
Modified: cfe/trunk/test/Sema/vla.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/vla.c?rev=72581&r1=72580&r2=72581&view=diff
==============================================================================
--- cfe/trunk/test/Sema/vla.c (original)
+++ cfe/trunk/test/Sema/vla.c Fri May 29 13:22:49 2009
@@ -53,4 +53,4 @@
int (*pr2044c(void))[pr2044b]; // expected-error {{variably modified type}}
const int f5_ci = 1;
-void f5() { char a[][f5_ci] = {""}; }
+void f5() { char a[][f5_ci] = {""}; } // expected-error {{variable-sized object may not be initialized}}
More information about the cfe-commits
mailing list