[LoongArch] Only report the first range error if there is actually more than one for __builtin_loongarch_cacop_[wd]

Other builtins do the same. Align with them.
This commit is contained in:
Weining Lu 2025-05-30 10:27:06 +08:00
parent c9022a29b4
commit fbbae9ea2b
3 changed files with 11 additions and 5 deletions

View File

@ -28,10 +28,9 @@ bool SemaLoongArch::CheckLoongArchBuiltinFunctionCall(const TargetInfo &TI,
// Basic intrinsics.
case LoongArch::BI__builtin_loongarch_cacop_d:
case LoongArch::BI__builtin_loongarch_cacop_w: {
SemaRef.BuiltinConstantArgRange(TheCall, 0, 0, llvm::maxUIntN(5));
SemaRef.BuiltinConstantArgRange(TheCall, 2, llvm::minIntN(12),
llvm::maxIntN(12));
break;
return SemaRef.BuiltinConstantArgRange(TheCall, 0, 0, llvm::maxUIntN(5)) ||
SemaRef.BuiltinConstantArgRange(TheCall, 2, llvm::minIntN(12),
llvm::maxIntN(12));
}
case LoongArch::BI__builtin_loongarch_break:
case LoongArch::BI__builtin_loongarch_dbar:

View File

@ -52,11 +52,12 @@ void test_feature(long *v_l, unsigned long *v_ul, int *v_i, unsigned ui, char c,
}
#endif
void cacop_d(unsigned long int a) {
void cacop_w(unsigned long int a) {
__builtin_loongarch_cacop_w(-1, a, 1024); // expected-error {{argument value -1 is outside the valid range [0, 31]}}
__builtin_loongarch_cacop_w(32, a, 1024); // expected-error {{argument value 32 is outside the valid range [0, 31]}}
__builtin_loongarch_cacop_w(1, a, -4096); // expected-error {{argument value -4096 is outside the valid range [-2048, 2047]}}
__builtin_loongarch_cacop_w(1, a, 4096); // expected-error {{argument value 4096 is outside the valid range [-2048, 2047]}}
__builtin_loongarch_cacop_w(-2, a, 5000); // expected-error {{argument value -2 is outside the valid range [0, 31]}}
}
void dbar(int a) {

View File

@ -23,6 +23,12 @@ void test_feature(unsigned long *v_ul, int *v_i, float a, double b) {
}
#endif
void cacop_d(int a) {
__builtin_loongarch_cacop_d(-1, a, 0); // expected-error {{argument value -1 is outside the valid range [0, 31]}}
__builtin_loongarch_cacop_d(1, a, 4000); // expected-error {{argument value 4000 is outside the valid range [-2048, 2047]}}
__builtin_loongarch_cacop_d(-2, a, 5000); // expected-error {{argument value -2 is outside the valid range [0, 31]}}
}
void csrrd_d(int a) {
__builtin_loongarch_csrrd_d(16384); // expected-error {{argument value 16384 is outside the valid range [0, 16383]}}
__builtin_loongarch_csrrd_d(-1); // expected-error {{argument value 4294967295 is outside the valid range [0, 16383]}}