[clang] [PowerPC] Align bcdsetsign Sema validation with other BCD builtins (PR #178121)
Aditi Medhane via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 3 22:46:44 PST 2026
https://github.com/AditiRM updated https://github.com/llvm/llvm-project/pull/178121
>From 05db13254aa41da2c441362c96b593bdfa7cab65 Mon Sep 17 00:00:00 2001
From: AditiRM <aditimedhane73 at gmail.com>
Date: Tue, 27 Jan 2026 06:32:13 +0000
Subject: [PATCH 1/2] Refactor bcdsetsign argument validation
---
clang/lib/Sema/SemaPPC.cpp | 9 ++++++++-
clang/test/Sema/builtins-bcd-format-conversion.c | 8 ++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Sema/SemaPPC.cpp b/clang/lib/Sema/SemaPPC.cpp
index 149c564bd5b84..7f7f2f9638129 100644
--- a/clang/lib/Sema/SemaPPC.cpp
+++ b/clang/lib/Sema/SemaPPC.cpp
@@ -147,7 +147,14 @@ bool SemaPPC::CheckPPCBuiltinFunctionCall(const TargetInfo &TI,
switch (BuiltinID) {
default:
return false;
- case PPC::BI__builtin_ppc_bcdsetsign:
+ case PPC::BI__builtin_ppc_bcdsetsign: {
+ // Arg0 must be vector unsigned char
+ if (!IsTypeVecUChar(TheCall->getArg(0)->getType(), 0))
+ return false;
+
+ // Restrict Arg1 constant range (0–1)
+ return SemaRef.BuiltinConstantArgRange(TheCall, 1, 0, 1);
+ }
case PPC::BI__builtin_ppc_national2packed:
case PPC::BI__builtin_ppc_packed2zoned:
case PPC::BI__builtin_ppc_zoned2packed:
diff --git a/clang/test/Sema/builtins-bcd-format-conversion.c b/clang/test/Sema/builtins-bcd-format-conversion.c
index 30bbd32a0f653..6529d99bc09b2 100644
--- a/clang/test/Sema/builtins-bcd-format-conversion.c
+++ b/clang/test/Sema/builtins-bcd-format-conversion.c
@@ -12,6 +12,14 @@
int i = 1; \
float f = 1.0f;
+vector unsigned char test_bcdsetsign(void) {
+ DECL_COMMON_VARS
+ vector unsigned char res_a = __builtin_ppc_bcdsetsign(scalar, '\1'); // expected-error {{argument 0 must be of type '__vector unsigned char' (vector of 16 'unsigned char' values}}
+ vector unsigned char res_b = __builtin_ppc_bcdsetsign(vec, 2); // expected-error-re {{argument value {{.*}} is outside the valid range}}
+ vector unsigned char res_c = __builtin_ppc_bcdsetsign(vec, -1); // expected-error-re {{argument value {{.*}} is outside the valid range}}
+ return __builtin_ppc_bcdsetsign(vec, '\1');
+}
+
vector unsigned char test_bcdshift(void) {
DECL_COMMON_VARS
vector unsigned char res_a = __builtin_ppc_bcdshift(scalar, i, i); // expected-error {{argument 0 must be of type '__vector unsigned char' (vector of 16 'unsigned char' values)}}
>From 8296d4f9f4dd7a82365f70316c472b11796e528c Mon Sep 17 00:00:00 2001
From: AditiRM <aditimedhane73 at gmail.com>
Date: Wed, 4 Feb 2026 06:57:17 +0000
Subject: [PATCH 2/2] [nit] address review comment
---
clang/test/Sema/builtins-bcd-format-conversion.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/clang/test/Sema/builtins-bcd-format-conversion.c b/clang/test/Sema/builtins-bcd-format-conversion.c
index 6529d99bc09b2..059340b0344e1 100644
--- a/clang/test/Sema/builtins-bcd-format-conversion.c
+++ b/clang/test/Sema/builtins-bcd-format-conversion.c
@@ -15,6 +15,7 @@
vector unsigned char test_bcdsetsign(void) {
DECL_COMMON_VARS
vector unsigned char res_a = __builtin_ppc_bcdsetsign(scalar, '\1'); // expected-error {{argument 0 must be of type '__vector unsigned char' (vector of 16 'unsigned char' values}}
+ vector unsigned char res_d = __builtin_ppc_bcdsetsign(vec, f); // expected-error-re {{argument to {{.*}} must be a constant integer}}
vector unsigned char res_b = __builtin_ppc_bcdsetsign(vec, 2); // expected-error-re {{argument value {{.*}} is outside the valid range}}
vector unsigned char res_c = __builtin_ppc_bcdsetsign(vec, -1); // expected-error-re {{argument value {{.*}} is outside the valid range}}
return __builtin_ppc_bcdsetsign(vec, '\1');
More information about the cfe-commits
mailing list