From: Mike Stump Date: Fri, 29 May 2009 16:34:15 +0000 (+0000) Subject: Avoid dumping during semantic analysis when checking array types when X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4f54f4e2f1af5850805033d69c5199df068d11e7;p=clang Avoid dumping during semantic analysis when checking array types when a vla is used. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72575 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 5dc40a4593..6090b79c5c 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -97,21 +97,22 @@ static void CheckStringInit(Expr *Str, QualType &DeclT, Sema &S) { return; } - const ConstantArrayType *CAT = cast(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); + if (const ConstantArrayType *CAT = dyn_cast(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, diff --git a/test/Sema/vla.c b/test/Sema/vla.c index 674547297a..3e380c6d95 100644 --- a/test/Sema/vla.c +++ b/test/Sema/vla.c @@ -51,3 +51,6 @@ int f4(int a[*][*]); int pr2044(int b) {int (*c(void))[b];**c() = 2;} // expected-error {{variably modified type}} int pr2044b; int (*pr2044c(void))[pr2044b]; // expected-error {{variably modified type}} + +const int f5_ci = 1; +void f5() { char a[][f5_ci] = {""}; }