]> granicus.if.org Git - clang/commitdiff
Fix the following bug...
authorSteve Naroff <snaroff@apple.com>
Thu, 18 Oct 2007 03:27:23 +0000 (03:27 +0000)
committerSteve Naroff <snaroff@apple.com>
Thu, 18 Oct 2007 03:27:23 +0000 (03:27 +0000)
unsigned char asso_values[] = { 34 };
int legal2() {
  return asso_values[0];
}

The code that creates the new constant array type was operating on the original type.

As a result, the constant type being generated was "unsigned char [1][]" (which is wrong).

The fix is to operate on the element type - in this case, the correct type is "unsigned char [1]"

I added this case to array-init.c, which clearly didn't catch this bogosity...

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

Sema/SemaDecl.cpp
clang.xcodeproj/project.pbxproj
test/Sema/array-init.c

index 390caafdc0bfa2391931f27ccfa3c26330cec47d..5b54d8be7dbcab3a6b84fec707fd49609a719a24 100644 (file)
@@ -472,7 +472,7 @@ bool Sema::CheckInitializer(Expr *&Init, QualType &DeclType, bool isStatic) {
       // Return a new array type from the number of initializers (C99 6.7.8p22).
       llvm::APSInt ConstVal(32);
       ConstVal = numInits;
-      DeclType = Context.getConstantArrayType(DeclType, ConstVal, 
+      DeclType = Context.getConstantArrayType(VAT->getElementType(), ConstVal, 
                                               ArrayType::Normal, 0);
     }
     return hadError;
index ab5c53c4075e2b3556eaa02d65f4ac321b0695c7..cf39da026b619876cb147c66b2afaf83b0c55bb2 100644 (file)
                08FB7793FE84155DC02AAC07 /* Project object */ = {
                        isa = PBXProject;
                        buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
-                       compatibilityVersion = "Xcode 2.4";
                        hasScannedForEncodings = 1;
                        mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
                        projectDirPath = "";
index 510a7792d138bf8f95da54eff37c319390819930..5b22681d1b9e084abe899808001cbccf480b3f93 100644 (file)
@@ -103,6 +103,11 @@ void legal() {
   };
 }
 
+unsigned char asso_values[] = { 34 };
+int legal2() { 
+  return asso_values[0]; 
+}
+
 void illegal() {
   short q2[4][][2] = { // expected-error{{array has incomplete element type 'short [][2]'}}
     { 1, 0, 0, 0, 0, 0 },