r243343 - [sema] Fix infinite loop when using a boolean value as designated initializer.
Richard Smith
metafoo at gmail.com
Wed Jul 29 12:50:58 PDT 2015
On Jul 27, 2015 4:22 PM, "Argyrios Kyrtzidis" <akyrtzi at gmail.com> wrote:
>
> Author: akirtzidis
> Date: Mon Jul 27 18:16:53 2015
> New Revision: 243343
>
> URL: http://llvm.org/viewvc/llvm-project?rev=243343&view=rev
> Log:
> [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
>
> Added:
> cfe/trunk/test/CodeGenObjCXX/designated-initializers.mm
> Modified:
> cfe/trunk/lib/Sema/SemaInit.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaInit.cpp
> URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=243343&r1=243342&r2=243343&view=diff
>
==============================================================================
> --- cfe/trunk/lib/Sema/SemaInit.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaInit.cpp Mon Jul 27 18:16:53 2015
> @@ -2372,14 +2372,12 @@ InitListChecker::CheckDesignatedInitiali
> 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);
Do we produce any kind of diagnostic in the case where this truncation is
lossy?
> DesignatedStartIndex.setIsUnsigned(true);
> DesignatedEndIndex.setIsUnsigned(true);
> }
>
> Added: cfe/trunk/test/CodeGenObjCXX/designated-initializers.mm
> URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/designated-initializers.mm?rev=243343&view=auto
>
==============================================================================
> --- cfe/trunk/test/CodeGenObjCXX/designated-initializers.mm (added)
> +++ cfe/trunk/test/CodeGenObjCXX/designated-initializers.mm Mon Jul 27
18:16:53 2015
> @@ -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]
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150729/abbedf01/attachment.html>
More information about the cfe-commits
mailing list