]> granicus.if.org Git - clang/commitdiff
Fix rdar://6880874 - [sema] crash on array types with different index sizes
authorChris Lattner <sabre@nondot.org>
Wed, 13 May 2009 04:12:56 +0000 (04:12 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 13 May 2009 04:12:56 +0000 (04:12 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71634 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ASTContext.cpp
test/Sema/types.c

index ac46180b94d8f97c39e07e717b28dec1f781d60c..ccd3762da05b7a3833c57e0acf46671628496b93 100644 (file)
@@ -1133,9 +1133,14 @@ QualType ASTContext::getMemberPointerType(QualType T, const Type *Cls)
 /// getConstantArrayType - Return the unique reference to the type for an 
 /// array of the specified element type.
 QualType ASTContext::getConstantArrayType(QualType EltTy, 
-                                          const llvm::APInt &ArySize,
+                                          const llvm::APInt &ArySizeIn,
                                           ArrayType::ArraySizeModifier ASM,
                                           unsigned EltTypeQuals) {
+  // Convert the array size into a canonical width matching the pointer size for
+  // the target.
+  llvm::APInt ArySize(ArySizeIn);
+  ArySize.zextOrTrunc(Target.getPointerWidth(EltTy.getAddressSpace()));
+  
   llvm::FoldingSetNodeID ID;
   ConstantArrayType::Profile(ID, EltTy, ArySize, ASM, EltTypeQuals);
       
index 3ee76756eebc4a416678e41e4eb0b7023ee548de..7ab4e0672ce6a2450926034481b46d8c6ddcc3ba 100644 (file)
@@ -19,3 +19,14 @@ int b() {
   int __int128_t;
   int __uint128_t;
 }
+
+
+// Array type merging should convert array size to whatever matches the target
+// pointer size.
+// rdar://6880874
+extern int i[1LL];
+int i[(short)1];
+
+enum e { e_1 };
+extern int j[sizeof(enum e)];  // expected-note {{previous definition}}
+int j[42];   // expected-error {{redefinition of 'j' with a different type}}