[clang] 9aeecdf - Check supported architectures in sseXYZ/avxXYZ headers

via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 14 00:59:20 PDT 2021


Author: serge-sans-paille
Date: 2021-09-14T09:57:54+02:00
New Revision: 9aeecdfa8e9104392b435444a5f978d2eb71e51a

URL: https://github.com/llvm/llvm-project/commit/9aeecdfa8e9104392b435444a5f978d2eb71e51a
DIFF: https://github.com/llvm/llvm-project/commit/9aeecdfa8e9104392b435444a5f978d2eb71e51a.diff

LOG: Check supported architectures in sseXYZ/avxXYZ headers

It doesn't make sense to include those headers on the wrong architecture,
provide an explicit error message in that case.

Fix https://bugs.llvm.org/show_bug.cgi?id=48915

Differential Revision: https://reviews.llvm.org/D109686

Added: 
    clang/test/Headers/xmmintrin-unsupported.c

Modified: 
    clang/lib/Headers/ammintrin.h
    clang/lib/Headers/emmintrin.h
    clang/lib/Headers/immintrin.h
    clang/lib/Headers/mmintrin.h
    clang/lib/Headers/nmmintrin.h
    clang/lib/Headers/pmmintrin.h
    clang/lib/Headers/smmintrin.h
    clang/lib/Headers/tmmintrin.h
    clang/lib/Headers/wmmintrin.h
    clang/lib/Headers/xmmintrin.h

Removed: 
    


################################################################################
diff  --git a/clang/lib/Headers/ammintrin.h b/clang/lib/Headers/ammintrin.h
index 3806be6ebc437..1af2096595cac 100644
--- a/clang/lib/Headers/ammintrin.h
+++ b/clang/lib/Headers/ammintrin.h
@@ -10,6 +10,10 @@
 #ifndef __AMMINTRIN_H
 #define __AMMINTRIN_H
 
+#if !defined(__i386__) && !defined(__x86_64__)
+#error "This header is only meant to be used on x86 and x64 architecture"
+#endif
+
 #include <pmmintrin.h>
 
 /* Define the default attributes for the functions in this file. */

diff  --git a/clang/lib/Headers/emmintrin.h b/clang/lib/Headers/emmintrin.h
index b79a4f17f9c7f..6e9c3032c21f7 100644
--- a/clang/lib/Headers/emmintrin.h
+++ b/clang/lib/Headers/emmintrin.h
@@ -10,6 +10,10 @@
 #ifndef __EMMINTRIN_H
 #define __EMMINTRIN_H
 
+#if !defined(__i386__) && !defined(__x86_64__)
+#error "This header is only meant to be used on x86 and x64 architecture"
+#endif
+
 #include <xmmintrin.h>
 
 typedef double __m128d __attribute__((__vector_size__(16), __aligned__(16)));

diff  --git a/clang/lib/Headers/immintrin.h b/clang/lib/Headers/immintrin.h
index 8a75895c6c5f1..2b9ef61d27d2c 100644
--- a/clang/lib/Headers/immintrin.h
+++ b/clang/lib/Headers/immintrin.h
@@ -10,6 +10,10 @@
 #ifndef __IMMINTRIN_H
 #define __IMMINTRIN_H
 
+#if !defined(__i386__) && !defined(__x86_64__)
+#error "This header is only meant to be used on x86 and x64 architecture"
+#endif
+
 #include <x86gprintrin.h>
 
 #if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||      \

diff  --git a/clang/lib/Headers/mmintrin.h b/clang/lib/Headers/mmintrin.h
index 79a8b55016b19..03bac92198ad8 100644
--- a/clang/lib/Headers/mmintrin.h
+++ b/clang/lib/Headers/mmintrin.h
@@ -10,6 +10,10 @@
 #ifndef __MMINTRIN_H
 #define __MMINTRIN_H
 
+#if !defined(__i386__) && !defined(__x86_64__)
+#error "This header is only meant to be used on x86 and x64 architecture"
+#endif
+
 typedef long long __m64 __attribute__((__vector_size__(8), __aligned__(8)));
 
 typedef long long __v1di __attribute__((__vector_size__(8)));

diff  --git a/clang/lib/Headers/nmmintrin.h b/clang/lib/Headers/nmmintrin.h
index 672aea4966817..59fc7ec99e614 100644
--- a/clang/lib/Headers/nmmintrin.h
+++ b/clang/lib/Headers/nmmintrin.h
@@ -10,6 +10,10 @@
 #ifndef __NMMINTRIN_H
 #define __NMMINTRIN_H
 
+#if !defined(__i386__) && !defined(__x86_64__)
+#error "This header is only meant to be used on x86 and x64 architecture"
+#endif
+
 /* To match expectations of gcc we put the sse4.2 definitions into smmintrin.h,
    just include it now then.  */
 #include <smmintrin.h>

diff  --git a/clang/lib/Headers/pmmintrin.h b/clang/lib/Headers/pmmintrin.h
index a83b2eb6d8e26..eda83567cd058 100644
--- a/clang/lib/Headers/pmmintrin.h
+++ b/clang/lib/Headers/pmmintrin.h
@@ -10,6 +10,10 @@
 #ifndef __PMMINTRIN_H
 #define __PMMINTRIN_H
 
+#if !defined(__i386__) && !defined(__x86_64__)
+#error "This header is only meant to be used on x86 and x64 architecture"
+#endif
+
 #include <emmintrin.h>
 
 /* Define the default attributes for the functions in this file. */

diff  --git a/clang/lib/Headers/smmintrin.h b/clang/lib/Headers/smmintrin.h
index 5028fd5ea5955..710e55aaa1203 100644
--- a/clang/lib/Headers/smmintrin.h
+++ b/clang/lib/Headers/smmintrin.h
@@ -10,6 +10,10 @@
 #ifndef __SMMINTRIN_H
 #define __SMMINTRIN_H
 
+#if !defined(__i386__) && !defined(__x86_64__)
+#error "This header is only meant to be used on x86 and x64 architecture"
+#endif
+
 #include <tmmintrin.h>
 
 /* Define the default attributes for the functions in this file. */

diff  --git a/clang/lib/Headers/tmmintrin.h b/clang/lib/Headers/tmmintrin.h
index dbd959d0a62cb..bcffa8187801c 100644
--- a/clang/lib/Headers/tmmintrin.h
+++ b/clang/lib/Headers/tmmintrin.h
@@ -10,6 +10,10 @@
 #ifndef __TMMINTRIN_H
 #define __TMMINTRIN_H
 
+#if !defined(__i386__) && !defined(__x86_64__)
+#error "This header is only meant to be used on x86 and x64 architecture"
+#endif
+
 #include <pmmintrin.h>
 
 /* Define the default attributes for the functions in this file. */

diff  --git a/clang/lib/Headers/wmmintrin.h b/clang/lib/Headers/wmmintrin.h
index f932ca81089ca..49148dbf3ac61 100644
--- a/clang/lib/Headers/wmmintrin.h
+++ b/clang/lib/Headers/wmmintrin.h
@@ -10,6 +10,10 @@
 #ifndef __WMMINTRIN_H
 #define __WMMINTRIN_H
 
+#if !defined(__i386__) && !defined(__x86_64__)
+#error "This header is only meant to be used on x86 and x64 architecture"
+#endif
+
 #include <emmintrin.h>
 
 #include <__wmmintrin_aes.h>

diff  --git a/clang/lib/Headers/xmmintrin.h b/clang/lib/Headers/xmmintrin.h
index 620453c97783c..1612d3d2773d5 100644
--- a/clang/lib/Headers/xmmintrin.h
+++ b/clang/lib/Headers/xmmintrin.h
@@ -10,6 +10,10 @@
 #ifndef __XMMINTRIN_H
 #define __XMMINTRIN_H
 
+#if !defined(__i386__) && !defined(__x86_64__)
+#error "This header is only meant to be used on x86 and x64 architecture"
+#endif
+
 #include <mmintrin.h>
 
 typedef int __v4si __attribute__((__vector_size__(16)));

diff  --git a/clang/test/Headers/xmmintrin-unsupported.c b/clang/test/Headers/xmmintrin-unsupported.c
new file mode 100644
index 0000000000000..1991a132f451c
--- /dev/null
+++ b/clang/test/Headers/xmmintrin-unsupported.c
@@ -0,0 +1,5 @@
+// RUN: not %clang_cc1 %s -triple aarch64-eabi -fsyntax-only 2>&1 | FileCheck %s
+//
+// REQUIRES: x86-registered-target
+// CHECK: This header is only meant to be used on x86 and x64 architecture
+#include <xmmintrin.h>


        


More information about the cfe-commits mailing list