From 9652786a609e66100b14169f5565f8bf6db1a46c Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Wed, 29 Jul 2015 19:58:23 +0000 Subject: [PATCH] Merging r243343: ------------------------------------------------------------------------ r243343 | akirtzidis | 2015-07-27 16:16:53 -0700 (Mon, 27 Jul 2015) | 4 lines [sema] Fix infinite loop when using a boolean value as designated initializer. For designated indices use the max array size type bitwidth, not the bitwidth of the index value itself. rdar://21942503 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_37@243562 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaInit.cpp | 14 ++++---- test/CodeGenObjCXX/designated-initializers.mm | 36 +++++++++++++++++++ 2 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 test/CodeGenObjCXX/designated-initializers.mm diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index f0f7cb93d3..d3a249eae3 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -2372,14 +2372,12 @@ InitListChecker::CheckDesignatedInitializer(const InitializedEntity &Entity, return true; } } else { - // Make sure the bit-widths and signedness match. - if (DesignatedStartIndex.getBitWidth() > DesignatedEndIndex.getBitWidth()) - DesignatedEndIndex - = DesignatedEndIndex.extend(DesignatedStartIndex.getBitWidth()); - else if (DesignatedStartIndex.getBitWidth() < - DesignatedEndIndex.getBitWidth()) - DesignatedStartIndex - = DesignatedStartIndex.extend(DesignatedEndIndex.getBitWidth()); + unsigned DesignatedIndexBitWidth = + ConstantArrayType::getMaxSizeBits(SemaRef.Context); + DesignatedStartIndex = + DesignatedStartIndex.extOrTrunc(DesignatedIndexBitWidth); + DesignatedEndIndex = + DesignatedEndIndex.extOrTrunc(DesignatedIndexBitWidth); DesignatedStartIndex.setIsUnsigned(true); DesignatedEndIndex.setIsUnsigned(true); } diff --git a/test/CodeGenObjCXX/designated-initializers.mm b/test/CodeGenObjCXX/designated-initializers.mm new file mode 100644 index 0000000000..41a4271bc8 --- /dev/null +++ b/test/CodeGenObjCXX/designated-initializers.mm @@ -0,0 +1,36 @@ +// RUN: %clang_cc1 -triple arm64 %s -verify -emit-llvm -o - | FileCheck %s +// expected-no-diagnostics + +// Make sure we don't enter an infinite loop (rdar://21942503) + +int vals1[] = { + [__objc_yes] = 1, + [__objc_no] = 2 +}; +// CHECK: @vals1 = global [2 x i32] [i32 2, i32 1] + +int vals2[] = { + [true] = 3, + [false] = 4 +}; +// CHECK: @vals2 = global [2 x i32] [i32 4, i32 3] + +int vals3[] = { + [false] = 1, + [true] = 2, + 5 +}; +// CHECK: @vals3 = global [3 x i32] [i32 1, i32 2, i32 5] + +int vals4[2] = { + [true] = 5, + [false] = 6 +}; +// CHECK: @vals4 = global [2 x i32] [i32 6, i32 5] + +int vals5[3] = { + [false] = 1, + [true] = 2, + 6 +}; +// CHECK: @vals5 = global [3 x i32] [i32 1, i32 2, i32 6] -- 2.50.1