Fix the following bug...
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
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp
index 390caaf..5b54d8b 100644
--- a/Sema/SemaDecl.cpp
+++ b/Sema/SemaDecl.cpp
@@ -472,7 +472,7 @@
// 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;
diff --git a/clang.xcodeproj/project.pbxproj b/clang.xcodeproj/project.pbxproj
index ab5c53c..cf39da0 100644
--- a/clang.xcodeproj/project.pbxproj
+++ b/clang.xcodeproj/project.pbxproj
@@ -745,7 +745,6 @@
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
- compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1;
mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
projectDirPath = "";
diff --git a/test/Sema/array-init.c b/test/Sema/array-init.c
index 510a779..5b22681 100644
--- a/test/Sema/array-init.c
+++ b/test/Sema/array-init.c
@@ -103,6 +103,11 @@
};
}
+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 },