Skip to content

Commit

Permalink
[LoongArch] Add immediate operand validity check for __builtin_loonga…
Browse files Browse the repository at this point in the history
…rch_dbar

Differential Revision: https://reviews.llvm.org/D137809
  • Loading branch information
gonglingqin committed Nov 16, 2022
1 parent d599ac4 commit ddbb21b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions clang/lib/Sema/SemaChecking.cpp
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions clang/test/CodeGen/LoongArch/intrinsic-error.c
Expand Up @@ -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]}}
}
9 changes: 8 additions & 1 deletion llvm/test/CodeGen/LoongArch/intrinsic-error.ll
Expand Up @@ -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)

0 comments on commit ddbb21b

Please sign in to comment.