[PATCH] D137809: [LoongArch] Add immediate operand validity check for __builtin_loongarch_dbar
Gong LingQin via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 14 19:55:55 PST 2022
gonglingqin updated this revision to Diff 475333.
gonglingqin added a comment.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Add test cases.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D137809/new/
https://reviews.llvm.org/D137809
Files:
clang/lib/Sema/SemaChecking.cpp
clang/test/CodeGen/LoongArch/intrinsic-error.c
llvm/test/CodeGen/LoongArch/intrinsic-error.ll
Index: llvm/test/CodeGen/LoongArch/intrinsic-error.ll
===================================================================
--- llvm/test/CodeGen/LoongArch/intrinsic-error.ll
+++ llvm/test/CodeGen/LoongArch/intrinsic-error.ll
@@ -8,11 +8,18 @@
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)
Index: clang/test/CodeGen/LoongArch/intrinsic-error.c
===================================================================
--- clang/test/CodeGen/LoongArch/intrinsic-error.c
+++ 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]}}
+}
Index: clang/lib/Sema/SemaChecking.cpp
===================================================================
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -3683,6 +3683,9 @@
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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137809.475333.patch
Type: text/x-patch
Size: 1923 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221115/ce772f28/attachment.bin>
More information about the cfe-commits
mailing list