[clang] 08fab9e - [X86] Fix implicit sign conversion warnings in X86 headers.
Pierre Gousseau via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 7 03:30:15 PDT 2020
Author: Pierre Gousseau
Date: 2020-04-07T11:25:08+01:00
New Revision: 08fab9ebecf72a682279d75489dc2460121cbeed
URL: https://github.com/llvm/llvm-project/commit/08fab9ebecf72a682279d75489dc2460121cbeed
DIFF: https://github.com/llvm/llvm-project/commit/08fab9ebecf72a682279d75489dc2460121cbeed.diff
LOG: [X86] Fix implicit sign conversion warnings in X86 headers.
Warnings in emmintrin.h and xmmintrin.h are reported by
-fsanitize=implicit-integer-sign-change.
Reviewed By: RKSimon, craig.topper
Differential Revision: https://reviews.llvm.org/D77393
Added:
clang/test/Headers/x86-header-warnings.c
Modified:
clang/lib/Headers/emmintrin.h
clang/lib/Headers/xmmintrin.h
Removed:
################################################################################
diff --git a/clang/lib/Headers/emmintrin.h b/clang/lib/Headers/emmintrin.h
index 993c688ce818..73a777b107c6 100644
--- a/clang/lib/Headers/emmintrin.h
+++ b/clang/lib/Headers/emmintrin.h
@@ -4970,10 +4970,10 @@ void _mm_pause(void);
#define _MM_SHUFFLE2(x, y) (((x) << 1) | (y))
-#define _MM_DENORMALS_ZERO_ON (0x0040)
-#define _MM_DENORMALS_ZERO_OFF (0x0000)
+#define _MM_DENORMALS_ZERO_ON (0x0040U)
+#define _MM_DENORMALS_ZERO_OFF (0x0000U)
-#define _MM_DENORMALS_ZERO_MASK (0x0040)
+#define _MM_DENORMALS_ZERO_MASK (0x0040U)
#define _MM_GET_DENORMALS_ZERO_MODE() (_mm_getcsr() & _MM_DENORMALS_ZERO_MASK)
#define _MM_SET_DENORMALS_ZERO_MODE(x) (_mm_setcsr((_mm_getcsr() & ~_MM_DENORMALS_ZERO_MASK) | (x)))
diff --git a/clang/lib/Headers/xmmintrin.h b/clang/lib/Headers/xmmintrin.h
index 9b8de63f04d5..f4686691c7ed 100644
--- a/clang/lib/Headers/xmmintrin.h
+++ b/clang/lib/Headers/xmmintrin.h
@@ -2931,31 +2931,31 @@ _mm_movemask_ps(__m128 __a)
#define _MM_SHUFFLE(z, y, x, w) (((z) << 6) | ((y) << 4) | ((x) << 2) | (w))
-#define _MM_EXCEPT_INVALID (0x0001)
-#define _MM_EXCEPT_DENORM (0x0002)
-#define _MM_EXCEPT_DIV_ZERO (0x0004)
-#define _MM_EXCEPT_OVERFLOW (0x0008)
-#define _MM_EXCEPT_UNDERFLOW (0x0010)
-#define _MM_EXCEPT_INEXACT (0x0020)
-#define _MM_EXCEPT_MASK (0x003f)
-
-#define _MM_MASK_INVALID (0x0080)
-#define _MM_MASK_DENORM (0x0100)
-#define _MM_MASK_DIV_ZERO (0x0200)
-#define _MM_MASK_OVERFLOW (0x0400)
-#define _MM_MASK_UNDERFLOW (0x0800)
-#define _MM_MASK_INEXACT (0x1000)
-#define _MM_MASK_MASK (0x1f80)
-
-#define _MM_ROUND_NEAREST (0x0000)
-#define _MM_ROUND_DOWN (0x2000)
-#define _MM_ROUND_UP (0x4000)
-#define _MM_ROUND_TOWARD_ZERO (0x6000)
-#define _MM_ROUND_MASK (0x6000)
-
-#define _MM_FLUSH_ZERO_MASK (0x8000)
-#define _MM_FLUSH_ZERO_ON (0x8000)
-#define _MM_FLUSH_ZERO_OFF (0x0000)
+#define _MM_EXCEPT_INVALID (0x0001U)
+#define _MM_EXCEPT_DENORM (0x0002U)
+#define _MM_EXCEPT_DIV_ZERO (0x0004U)
+#define _MM_EXCEPT_OVERFLOW (0x0008U)
+#define _MM_EXCEPT_UNDERFLOW (0x0010U)
+#define _MM_EXCEPT_INEXACT (0x0020U)
+#define _MM_EXCEPT_MASK (0x003fU)
+
+#define _MM_MASK_INVALID (0x0080U)
+#define _MM_MASK_DENORM (0x0100U)
+#define _MM_MASK_DIV_ZERO (0x0200U)
+#define _MM_MASK_OVERFLOW (0x0400U)
+#define _MM_MASK_UNDERFLOW (0x0800U)
+#define _MM_MASK_INEXACT (0x1000U)
+#define _MM_MASK_MASK (0x1f80U)
+
+#define _MM_ROUND_NEAREST (0x0000U)
+#define _MM_ROUND_DOWN (0x2000U)
+#define _MM_ROUND_UP (0x4000U)
+#define _MM_ROUND_TOWARD_ZERO (0x6000U)
+#define _MM_ROUND_MASK (0x6000U)
+
+#define _MM_FLUSH_ZERO_MASK (0x8000U)
+#define _MM_FLUSH_ZERO_ON (0x8000U)
+#define _MM_FLUSH_ZERO_OFF (0x0000U)
#define _MM_GET_EXCEPTION_MASK() (_mm_getcsr() & _MM_MASK_MASK)
#define _MM_GET_EXCEPTION_STATE() (_mm_getcsr() & _MM_EXCEPT_MASK)
diff --git a/clang/test/Headers/x86-header-warnings.c b/clang/test/Headers/x86-header-warnings.c
new file mode 100644
index 000000000000..ec7cfc6adaad
--- /dev/null
+++ b/clang/test/Headers/x86-header-warnings.c
@@ -0,0 +1,43 @@
+// Fix sign conversion warnings found by fsanitize=implicit-integer-sign-change
+// in intrinsic headers.
+// Preprocess file to workaround no warnings in system headers.
+// RUN: %clang_cc1 %s -triple x86_64-pc-linux-gnu -ffreestanding -E 2>&1 \
+// RUN: | %clang_cc1 -x c - -triple x86_64-pc-linux-gnu -ffreestanding -Wsign-conversion -E -o - 2>&1 \
+// RUN: | FileCheck --allow-empty %s
+// REQUIRES: x86-registered-target
+
+#include <x86intrin.h>
+
+void test0() {
+ // CHECK-LABEL: test0
+ // CHECK-NOT: warning:
+ _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
+ _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_OFF);
+ _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_MASK);
+
+ _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_INVALID);
+ _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_DENORM);
+ _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_DIV_ZERO);
+ _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_OVERFLOW);
+ _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_UNDERFLOW);
+ _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_INEXACT);
+ _MM_SET_EXCEPTION_STATE(_MM_EXCEPT_MASK);
+
+ _MM_SET_EXCEPTION_MASK(_MM_MASK_INVALID);
+ _MM_SET_EXCEPTION_MASK(_MM_MASK_DENORM);
+ _MM_SET_EXCEPTION_MASK(_MM_MASK_DIV_ZERO);
+ _MM_SET_EXCEPTION_MASK(_MM_MASK_OVERFLOW);
+ _MM_SET_EXCEPTION_MASK(_MM_MASK_UNDERFLOW);
+ _MM_SET_EXCEPTION_MASK(_MM_MASK_INEXACT);
+ _MM_SET_EXCEPTION_MASK(_MM_MASK_MASK);
+
+ _MM_SET_ROUNDING_MODE(_MM_ROUND_NEAREST);
+ _MM_SET_ROUNDING_MODE(_MM_ROUND_DOWN);
+ _MM_SET_ROUNDING_MODE(_MM_ROUND_UP);
+ _MM_SET_ROUNDING_MODE(_MM_ROUND_TOWARD_ZERO);
+ _MM_SET_ROUNDING_MODE(_MM_ROUND_MASK);
+
+ _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_MASK);
+ _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
+ _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_OFF);
+}
More information about the cfe-commits
mailing list