diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp --- a/clang/lib/Sema/SemaChecking.cpp +++ b/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; diff --git a/clang/test/CodeGen/LoongArch/intrinsic-error.c b/clang/test/CodeGen/LoongArch/intrinsic-error.c --- a/clang/test/CodeGen/LoongArch/intrinsic-error.c +++ b/clang/test/CodeGen/LoongArch/intrinsic-error.c @@ -6,3 +6,7 @@ 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() { + return __builtin_loongarch_dbar(32768); // expected-error {{argument value 32768 is outside the valid range [0, 32767]}} +}