[clang] 3b0240e - [PowerPC] Add range check for vec_genpcvm builtins

Quinn Pham via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 24 09:15:49 PDT 2021


Author: Quinn Pham
Date: 2021-09-24T11:15:44-05:00
New Revision: 3b0240e6c89d9201430ee83b09fe7c94256e8838

URL: https://github.com/llvm/llvm-project/commit/3b0240e6c89d9201430ee83b09fe7c94256e8838
DIFF: https://github.com/llvm/llvm-project/commit/3b0240e6c89d9201430ee83b09fe7c94256e8838.diff

LOG: [PowerPC] Add range check for vec_genpcvm builtins

This patch adds range checking for some Power10 altivec builtins. Range
checking is done in SemaChecking.

Reviewed By: #powerpc, lei, Conanap

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

Added: 
    

Modified: 
    clang/lib/Sema/SemaChecking.cpp
    clang/test/CodeGen/builtins-ppc-p10vector-error.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 0310e10f93704..c3c653f6889ed 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3485,6 +3485,11 @@ bool Sema::CheckPPCBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID,
   case PPC::BI__builtin_darn_32:
     return SemaFeatureCheck(*this, TheCall, "isa-v30-instructions",
                             diag::err_ppc_builtin_only_on_arch, "9");
+  case PPC::BI__builtin_vsx_xxgenpcvbm:
+  case PPC::BI__builtin_vsx_xxgenpcvhm:
+  case PPC::BI__builtin_vsx_xxgenpcvwm:
+  case PPC::BI__builtin_vsx_xxgenpcvdm:
+    return SemaBuiltinConstantArgRange(TheCall, 1, 0, 3);
 #define CUSTOM_BUILTIN(Name, Intr, Types, Acc) \
   case PPC::BI__builtin_##Name: \
     return SemaBuiltinPPCMMACall(TheCall, Types);

diff  --git a/clang/test/CodeGen/builtins-ppc-p10vector-error.c b/clang/test/CodeGen/builtins-ppc-p10vector-error.c
index e509c5a82c5b0..27d24e3d441c0 100644
--- a/clang/test/CodeGen/builtins-ppc-p10vector-error.c
+++ b/clang/test/CodeGen/builtins-ppc-p10vector-error.c
@@ -30,3 +30,19 @@ unsigned long long test_vec_cntm_ui(void) {
 unsigned long long test_vec_cntm_ull(void) {
   return vec_cntm(vulla, 2); // expected-error 1+ {{argument value 2 is outside the valid range [0, 1]}}
 }
+
+vector unsigned char test_xxgenpcvbm(void) {
+  return vec_genpcvm(vuca, -1); // expected-error 1+ {{argument value -1 is outside the valid range [0, 3]}}
+}
+
+vector unsigned short test_xxgenpcvhm(void) {
+  return vec_genpcvm(vusa, -1); // expected-error 1+ {{argument value -1 is outside the valid range [0, 3]}}
+}
+
+vector unsigned int test_xxgenpcvwm(void) {
+  return vec_genpcvm(vuia, 4); // expected-error 1+ {{argument value 4 is outside the valid range [0, 3]}}
+}
+
+vector unsigned long long test_xxgenpcvdm(void) {
+  return vec_genpcvm(vulla, 4); // expected-error 1+ {{argument value 4 is outside the valid range [0, 3]}}
+}


        


More information about the cfe-commits mailing list