[PATCH] D97053: [clang][SVE] Don't warn on vector to sizeless builtin implicit conversion

Joe Ellis via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 19 07:51:33 PST 2021


joechrisellis created this revision.
joechrisellis added reviewers: c-rhodes, bsmith.
Herald added subscribers: psnobl, kristof.beyls, tschuett.
Herald added a reviewer: efriedma.
joechrisellis requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This commit prevents warnings from -Wconversion when a clang vector type
is implicitly converted to a sizeless builtin type -- for example, when
implicitly converting a fixed-predicate to a scalable predicate.

The code below:

  1    #include <arm_sve.h>
  2
  3    #define N __ARM_FEATURE_SVE_BITS
  4    #define FIXED_ATTR __attribute__((arm_sve_vector_bits (N)))
  5    typedef svbool_t fixed_svbool_t FIXED_ATTR;
  6
  7    inline fixed_svbool_t foo(fixed_svbool_t p) {
  8      return svnot_z(svptrue_b64(), p);
  9    }

would previously raise this warning:

  warning: implicit conversion turns vector to scalar: \
  'fixed_svbool_t' (vector of 8 'unsigned char' values) to 'svbool_t' \
  (aka '__SVBool_t') [-Wconversion]

Note that many cases of these implicit conversions were already
permitted because many functions inside arm_sve.h are spawned via
preprocessor macros, and the call to isInSystemMacro would cover us in
this case. This commit fixes the remaining cases.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97053

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/aarch64-fixed-vector-to-scalable-implicit-conversion.c


Index: clang/test/Sema/aarch64-fixed-vector-to-scalable-implicit-conversion.c
===================================================================
--- /dev/null
+++ clang/test/Sema/aarch64-fixed-vector-to-scalable-implicit-conversion.c
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve \
+// RUN: -msve-vector-bits=512 -Wconversion -fallow-half-arguments-and-returns \
+// RUN: -o /dev/null %s 2>&1 | FileCheck %s -allow-empty
+
+// CHECK-NOT: warning
+
+#include <arm_sve.h>
+
+#define N __ARM_FEATURE_SVE_BITS
+#define FIXED_ATTR __attribute__((arm_sve_vector_bits(N)))
+
+typedef svbool_t fixed_svbool_t FIXED_ATTR;
+
+fixed_svbool_t check_svnot(fixed_svbool_t p) {
+  return svnot_z(svptrue_b64(), p);
+}
+
+fixed_svbool_t check_svorr(fixed_svbool_t p1, fixed_svbool_t p2) {
+  return svorr_z(svptrue_b64(), p1, p2);
+}
+
+fixed_svbool_t check_svorn(fixed_svbool_t p1, fixed_svbool_t p2) {
+  return svorn_z(svptrue_b64(), p1, p2);
+}
+
+fixed_svbool_t check_svand(fixed_svbool_t p1, fixed_svbool_t p2) {
+  return svand_z(svptrue_b64(), p1, p2);
+}
+
+fixed_svbool_t check_svnand(fixed_svbool_t p1, fixed_svbool_t p2) {
+  return svnand_z(svptrue_b64(), p1, p2);
+}
Index: clang/lib/Sema/SemaChecking.cpp
===================================================================
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -12052,6 +12052,9 @@
 
   // Strip vector types.
   if (isa<VectorType>(Source)) {
+    // Converting from a vector to a sizeless builtin type is fine.
+    if (Target->isSizelessBuiltinType())
+      return;
     if (!isa<VectorType>(Target)) {
       if (S.SourceMgr.isInSystemMacro(CC))
         return;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97053.324984.patch
Type: text/x-patch
Size: 1698 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210219/6f99e69c/attachment.bin>


More information about the cfe-commits mailing list