[clang-tools-extra] [libcxx] Fixed uniform_real_distribution.h allowing initializing with non floating point types (PR #70468)

Pranav Tatavarthy via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 27 09:01:53 PDT 2023


https://github.com/Pranav10903 created https://github.com/llvm/llvm-project/pull/70468

None

>From 57c8eadd6ef3d40f14cefa7b88d70c43aac5757e Mon Sep 17 00:00:00 2001
From: Pranav Tatavarthy <97344709+Pranav10903 at users.noreply.github.com>
Date: Fri, 27 Oct 2023 21:13:45 +0530
Subject: [PATCH 1/3] Update uniform_real_distribution.h ( Include
 static_assert )

Included a static_assert to deal with the undefined behaviour because of uniform_real_type being initialized by non floating point type values.
reference:  https://en.cppreference.com/w/cpp/numeric/random/uniform_real_distribution
---
 libcxx/include/__random/uniform_real_distribution.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libcxx/include/__random/uniform_real_distribution.h b/libcxx/include/__random/uniform_real_distribution.h
index 1388cef95f39414..9b46873ad750787 100644
--- a/libcxx/include/__random/uniform_real_distribution.h
+++ b/libcxx/include/__random/uniform_real_distribution.h
@@ -27,6 +27,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 template<class _RealType = double>
 class _LIBCPP_TEMPLATE_VIS uniform_real_distribution
 {
+    static_assert(std::is_floating_point<_RealType>::value, "result_type must be a floating point type");
 public:
     // types
     typedef _RealType result_type;

>From c11d80bc9de91217a52fbdea4040704fa8f95fb0 Mon Sep 17 00:00:00 2001
From: Pranav Tatavarthy <97344709+Pranav10903 at users.noreply.github.com>
Date: Fri, 27 Oct 2023 21:19:15 +0530
Subject: [PATCH 2/3] Update mve-narrow.ll

---
 .../Transforms/InstCombine/ARM/mve-narrow.ll  | 24 -------------------
 1 file changed, 24 deletions(-)

diff --git a/llvm/test/Transforms/InstCombine/ARM/mve-narrow.ll b/llvm/test/Transforms/InstCombine/ARM/mve-narrow.ll
index 20babc29d535ec2..623e774ea2c31ac 100644
--- a/llvm/test/Transforms/InstCombine/ARM/mve-narrow.ll
+++ b/llvm/test/Transforms/InstCombine/ARM/mve-narrow.ll
@@ -241,30 +241,6 @@ define <8 x half> @test_cvtnp_v8i16_bt(<8 x half> %a, <8 x half> %b, <4 x float>
   ret <8 x half> %z
 }
 
-define <4 x i32> @test_vshrn_const(<8 x i16> %a) {
-; CHECK-LABEL: @test_vshrn_const(
-; CHECK-NEXT:    ret <4 x i32> zeroinitializer
-;
-  %y = call <8 x i16> @llvm.arm.mve.vshrn.v8i16.v4i32(<8 x i16> %a, <4 x i32> <i32 512, i32 0, i32 0, i32 0>, i32 3, i32 0, i32 0, i32 0, i32 0, i32 1)
-  %z = shufflevector <8 x i16> %y, <8 x i16> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
-  %za = zext <4 x i16> %z to <4 x i32>
-  ret <4 x i32> %za
-}
-
-define zeroext i16 @test_undef_bits() {
-; CHECK-LABEL: @test_undef_bits(
-; CHECK-NEXT:  e:
-; CHECK-NEXT:    ret i16 0
-;
-e:
-  %0 = call <8 x i16> @llvm.arm.mve.vshrn.v8i16.v4i32(<8 x i16> zeroinitializer, <4 x i32> <i32 256, i32 0, i32 0, i32 0>, i32 8, i32 1, i32 1, i32 1, i32 0, i32 1)
-  %1 = shufflevector <8 x i16> %0, <8 x i16> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
-  %2 = zext <4 x i16> %1 to <4 x i32>
-  %3 = bitcast <4 x i32> %2 to <8 x i16>
-  %4 = extractelement <8 x i16> %3, i32 0
-  ret i16 %4
-}
-
 declare <8 x i16> @llvm.arm.mve.vshrn.v8i16.v4i32(<8 x i16>, <4 x i32>, i32, i32, i32, i32, i32, i32)
 declare <8 x i16> @llvm.arm.mve.vshrn.predicated.v8i16.v4i32.v4i1(<8 x i16>, <4 x i32>, i32, i32, i32, i32, i32, i32, <4 x i1>)
 declare <16 x i8> @llvm.arm.mve.vshrn.v16i8.v8i16(<16 x i8>, <8 x i16>, i32, i32, i32, i32, i32, i32)



More information about the cfe-commits mailing list