[llvm] ddbb21b - [LoongArch] Add immediate operand validity check for __builtin_loongarch_dbar

via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 15 22:48:14 PST 2022


Author: gonglingqin
Date: 2022-11-16T14:47:45+08:00
New Revision: ddbb21bdb579cc5b6092369b39aef376a8df4da1

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

LOG: [LoongArch] Add immediate operand validity check for __builtin_loongarch_dbar

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

Added: 
    

Modified: 
    clang/lib/Sema/SemaChecking.cpp
    clang/test/CodeGen/LoongArch/intrinsic-error.c
    llvm/test/CodeGen/LoongArch/intrinsic-error.ll

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 5a9c1750d8b32..75fb822f392dd 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3685,6 +3685,9 @@ bool Sema::CheckLoongArchBuiltinFunctionCall(const TargetInfo &TI,
                   diag::err_loongarch_builtin_requires_la64)
              << TheCall->getSourceRange();
     break;
+  case LoongArch::BI__builtin_loongarch_dbar:
+    // Check if immediate is in [0, 32767].
+    return SemaBuiltinConstantArgRange(TheCall, 0, 0, 32767);
   }
 
   return false;

diff  --git a/clang/test/CodeGen/LoongArch/intrinsic-error.c b/clang/test/CodeGen/LoongArch/intrinsic-error.c
index 5dc0cadd686ef..6f2b2ea3409e3 100644
--- a/clang/test/CodeGen/LoongArch/intrinsic-error.c
+++ b/clang/test/CodeGen/LoongArch/intrinsic-error.c
@@ -6,3 +6,11 @@
 int crc_w_d_w(long int a, int b) {
   return __builtin_loongarch_crc_w_d_w(a, b); // expected-error {{this builtin requires target: loongarch64}}
 }
+
+void dbar_out_of_hi_range() {
+  return __builtin_loongarch_dbar(32768); // expected-error {{argument value 32768 is outside the valid range [0, 32767]}}
+}
+
+void dbar_out_of_lo_range() {
+  return __builtin_loongarch_dbar(-1); // expected-error {{argument value 4294967295 is outside the valid range [0, 32767]}}
+}

diff  --git a/llvm/test/CodeGen/LoongArch/intrinsic-error.ll b/llvm/test/CodeGen/LoongArch/intrinsic-error.ll
index cdf69e9520508..a00cd8c5e6ac7 100644
--- a/llvm/test/CodeGen/LoongArch/intrinsic-error.ll
+++ b/llvm/test/CodeGen/LoongArch/intrinsic-error.ll
@@ -8,11 +8,18 @@ entry:
   ret void
 }
 
-define void @dbar_imm_out_of_range() nounwind {
+define void @dbar_imm_out_of_hi_range() nounwind {
 ; CHECK: argument to '__builtin_loongarch_dbar' out of range
 entry:
   call void @llvm.loongarch.dbar(i32 32769)
   ret void
 }
 
+define void @dbar_imm_out_of_lo_range() nounwind {
+; CHECK: argument to '__builtin_loongarch_dbar' out of range
+entry:
+  call void @llvm.loongarch.dbar(i32 -1)
+  ret void
+}
+
 declare void @llvm.loongarch.dbar(i32)


        


More information about the llvm-commits mailing list