[PATCH] D106409: [PowerPC] Add diagnostic for out of range values for vec_cts,vec_ctf

Bardia Mahjour via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 21 08:16:50 PDT 2021


bmahjour added a comment.

Thanks for this patch @ZarkoCA.

We have six of these functions in altivec: `vec_ctd, vec_ctf, vec_cts, vec_ctsl, vec_ctu, vec_ctul`. They are all defined as macros in altivec.h and not all of them map to the builtins checked in this patch (eg `vec_ctul`). I realize this is an improvement over what we have, but just wondering if you've considered diagnosing cases like `vec_ctul` or the following:

  vector double a; 
  vector unsigned int res = vec_ctu(a, 32);

One solution I can think of is to introduce a noop pass-through builtin whose only purpose would be to allow semantic checking in places like `Sema::CheckPPCBuiltinFunctionCall`. For example say the builtin is called `_builtin_pass_through_with_rcheck_1_32` then we can change `vec_ctul` in altivec.h to the following:

  #define vec_ctul(__a, __b)                                                     \
    _Generic((__a), vector float                                                 \
             : __extension__({                                                   \
                 vector float __ret =                                            \
                     (vector float)(__a) *                                       \
                     (vector float)(vector unsigned)((0x7f + (__builtin_pass_through_with_rcheck_1_32(__b))) << 23);      \
                 __builtin_vsx_xvcvspuxds(                                       \
                     __builtin_vsx_xxsldwi(__ret, __ret, 1));                    \
               }),                                                               \

and the sema check would look something like:

  case PPC::BI__builtin_pass_through_with_rcheck_1_32:
      return SemaBuiltinConstantArgRange(TheCall, 0, 0, 31);

Any thoughts @nemanjai ?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106409/new/

https://reviews.llvm.org/D106409



More information about the cfe-commits mailing list