[clang] [Sema] Check arg count for builtins with CustomTypeChecking (PR #222841)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Sep 13 11:08:03 PDT 2026
https://github.com/im-lunex updated https://github.com/llvm/llvm-project/pull/222841
>From 98a6983e0cb9301fbd5c88ea6365828b0d91c6e2 Mon Sep 17 00:00:00 2001
From: im-lunex <thisissamir04 at gmail.com>
Date: Fri, 11 Sep 2026 00:58:58 +0600
Subject: [PATCH 1/6] [Sema] Check arg count for builtins with
CustomTypeChecking
---
clang/lib/Sema/SemaChecking.cpp | 15 +++++++++++++
.../PowerPC/builtins-too-many-args-check.cpp | 22 +++++++++++++++++++
2 files changed, 37 insertions(+)
create mode 100644 clang/test/Sema/PowerPC/builtins-too-many-args-check.cpp
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 0e85af73696dc..cc68bf5ef5413 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -4193,6 +4193,21 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
if (getLangOpts().HLSL && HLSL().CheckBuiltinFunctionCall(BuiltinID, TheCall))
return ExprError();
+ // check if the builtin has CustomTypeChecking or not, if it dose we get the
+ // already parsed type string of the builtin and compare that with the
+ // caller's passed args and give error for too much args
+ if (Context.BuiltinInfo.hasCustomTypechecking(BuiltinID)) {
+ ASTContext::GetBuiltinTypeError Error;
+ QualType BuiltinFTy = Context.GetBuiltinType(BuiltinID, Error);
+ if (!BuiltinFTy.isNull() && !Error) {
+ if (const FunctionProtoType *FPT =
+ dyn_cast<FunctionProtoType>(BuiltinFTy.getTypePtr()))
+ if (!FPT->isVariadic() &&
+ checkArgCountAtMost(TheCall, FPT->getNumParams()))
+ return ExprError();
+ }
+ }
+
// Since the target specific builtins for each arch overlap, only check those
// of the arch we are compiling for.
if (Context.BuiltinInfo.isTSBuiltin(BuiltinID)) {
diff --git a/clang/test/Sema/PowerPC/builtins-too-many-args-check.cpp b/clang/test/Sema/PowerPC/builtins-too-many-args-check.cpp
new file mode 100644
index 0000000000000..15d30fd1dffe5
--- /dev/null
+++ b/clang/test/Sema/PowerPC/builtins-too-many-args-check.cpp
@@ -0,0 +1,22 @@
+// Testfile for (https://github.com/llvm/llvm-project/issues/216669)
+
+// REQUIRES: powerpc-registered-target
+// RUN: %clang_cc1 -target-feature +power9-vector -triple powerpc64-unknown-unknown -fsyntax-only -verify %s
+// RUN: %clang_cc1 -target-feature +power9-vector -triple powerpc64le-unknown-unknown -fsyntax-only -verify %s
+// RUN: %clang_cc1 -target-feature +power9-vector -triple powerpc-unknown-unknown -fsyntax-only -verify %s
+
+vector unsigned char test_bcdsetsign_too_many(vector unsigned char a) {
+ return __builtin_ppc_bcdsetsign(a, 1, 2); // expected-error {{too many arguments to function call, expected at most 2, have 3}}
+}
+
+vector unsigned char test_national2packed_too_many(vector unsigned char a) {
+ return __builtin_ppc_national2packed(a, 1, 0); // expected-error {{too many arguments to function call, expected at most 2, have 3}}
+}
+
+vector unsigned char test_packed2zoned_too_many(vector unsigned char a) {
+ return __builtin_ppc_packed2zoned(a, 1, 0); // expected-error {{too many arguments to function call, expected at most 2, have 3}}
+}
+
+vector unsigned char test_zoned2packed_too_many(vector unsigned char a) {
+ return __builtin_ppc_zoned2packed(a, 1, 0); // expected-error {{too many arguments to function call, expected at most 2, have 3}}
+}
>From 3ea9c6d8126538e7134c2eaa46244408a1c309df Mon Sep 17 00:00:00 2001
From: im-lunex <thisissamir04 at gmail.com>
Date: Fri, 11 Sep 2026 12:08:59 +0600
Subject: [PATCH 2/6] make error message from at most to just expected
---
clang/lib/Sema/SemaChecking.cpp | 5 ++---
clang/test/Sema/PowerPC/builtins-too-many-args-check.cpp | 8 ++++----
2 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index cc68bf5ef5413..4b398cdabf4bf 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -4195,15 +4195,14 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
// check if the builtin has CustomTypeChecking or not, if it dose we get the
// already parsed type string of the builtin and compare that with the
- // caller's passed args and give error for too much args
+ // caller's passed args and give error for too many args
if (Context.BuiltinInfo.hasCustomTypechecking(BuiltinID)) {
ASTContext::GetBuiltinTypeError Error;
QualType BuiltinFTy = Context.GetBuiltinType(BuiltinID, Error);
if (!BuiltinFTy.isNull() && !Error) {
if (const FunctionProtoType *FPT =
dyn_cast<FunctionProtoType>(BuiltinFTy.getTypePtr()))
- if (!FPT->isVariadic() &&
- checkArgCountAtMost(TheCall, FPT->getNumParams()))
+ if (!FPT->isVariadic() && checkArgCount(TheCall, FPT->getNumParams()))
return ExprError();
}
}
diff --git a/clang/test/Sema/PowerPC/builtins-too-many-args-check.cpp b/clang/test/Sema/PowerPC/builtins-too-many-args-check.cpp
index 15d30fd1dffe5..da2aba5e9768c 100644
--- a/clang/test/Sema/PowerPC/builtins-too-many-args-check.cpp
+++ b/clang/test/Sema/PowerPC/builtins-too-many-args-check.cpp
@@ -6,17 +6,17 @@
// RUN: %clang_cc1 -target-feature +power9-vector -triple powerpc-unknown-unknown -fsyntax-only -verify %s
vector unsigned char test_bcdsetsign_too_many(vector unsigned char a) {
- return __builtin_ppc_bcdsetsign(a, 1, 2); // expected-error {{too many arguments to function call, expected at most 2, have 3}}
+ return __builtin_ppc_bcdsetsign(a, 1, 2); // expected-error {{too many arguments to function call, expected 2, have 3}}
}
vector unsigned char test_national2packed_too_many(vector unsigned char a) {
- return __builtin_ppc_national2packed(a, 1, 0); // expected-error {{too many arguments to function call, expected at most 2, have 3}}
+ return __builtin_ppc_national2packed(a, 1, 0); // expected-error {{too many arguments to function call, expected 2, have 3}}
}
vector unsigned char test_packed2zoned_too_many(vector unsigned char a) {
- return __builtin_ppc_packed2zoned(a, 1, 0); // expected-error {{too many arguments to function call, expected at most 2, have 3}}
+ return __builtin_ppc_packed2zoned(a, 1, 0); // expected-error {{too many arguments to function call, expected 2, have 3}}
}
vector unsigned char test_zoned2packed_too_many(vector unsigned char a) {
- return __builtin_ppc_zoned2packed(a, 1, 0); // expected-error {{too many arguments to function call, expected at most 2, have 3}}
+ return __builtin_ppc_zoned2packed(a, 1, 0); // expected-error {{too many arguments to function call, expected 2, have 3}}
}
>From 24499797e15b852ac93731009baf69ea72990368 Mon Sep 17 00:00:00 2001
From: im-lunex <thisissamir04 at gmail.com>
Date: Fri, 11 Sep 2026 15:43:18 +0600
Subject: [PATCH 3/6] try new approach to have the validation specifically for
only the PPC architecture to avoid conflict with other architectures
---
clang/lib/Sema/SemaChecking.cpp | 14 -------------
clang/lib/Sema/SemaPPC.cpp | 16 +++++++++++++++
.../PowerPC/builtins-too-many-args-check.cpp | 20 +++++++++++++++----
3 files changed, 32 insertions(+), 18 deletions(-)
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 4b398cdabf4bf..0e85af73696dc 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -4193,20 +4193,6 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
if (getLangOpts().HLSL && HLSL().CheckBuiltinFunctionCall(BuiltinID, TheCall))
return ExprError();
- // check if the builtin has CustomTypeChecking or not, if it dose we get the
- // already parsed type string of the builtin and compare that with the
- // caller's passed args and give error for too many args
- if (Context.BuiltinInfo.hasCustomTypechecking(BuiltinID)) {
- ASTContext::GetBuiltinTypeError Error;
- QualType BuiltinFTy = Context.GetBuiltinType(BuiltinID, Error);
- if (!BuiltinFTy.isNull() && !Error) {
- if (const FunctionProtoType *FPT =
- dyn_cast<FunctionProtoType>(BuiltinFTy.getTypePtr()))
- if (!FPT->isVariadic() && checkArgCount(TheCall, FPT->getNumParams()))
- return ExprError();
- }
- }
-
// Since the target specific builtins for each arch overlap, only check those
// of the arch we are compiling for.
if (Context.BuiltinInfo.isTSBuiltin(BuiltinID)) {
diff --git a/clang/lib/Sema/SemaPPC.cpp b/clang/lib/Sema/SemaPPC.cpp
index 8a594fc86dea6..a9ac931dda8c3 100644
--- a/clang/lib/Sema/SemaPPC.cpp
+++ b/clang/lib/Sema/SemaPPC.cpp
@@ -145,6 +145,16 @@ bool SemaPPC::CheckPPCBuiltinFunctionCall(const TargetInfo &TI,
// - IsIntType: enforces any integer type
// Lambdas centralize type checks for BCD builtin handlers
+ // reject calls with more args than the builtin's declared prototype
+ auto CheckArgCountAtMost = [&](unsigned BuiltinID) -> bool {
+ ASTContext::GetBuiltinTypeError Error;
+ if (const auto *FPT = dyn_cast<FunctionProtoType>(
+ Context.GetBuiltinType(BuiltinID, Error).getTypePtr()))
+ if (!FPT->isVariadic())
+ return SemaRef.checkArgCountAtMost(TheCall, FPT->getNumParams());
+ return false;
+ };
+
// Lambda 1: verify vector unsigned char type
auto IsTypeVecUChar = [&](QualType ArgTy, unsigned ArgIndex) -> bool {
QualType VecType = Context.getVectorType(Context.UnsignedCharTy, 16,
@@ -173,6 +183,8 @@ bool SemaPPC::CheckPPCBuiltinFunctionCall(const TargetInfo &TI,
default:
return false;
case PPC::BI__builtin_ppc_bcdsetsign: {
+ if (CheckArgCountAtMost(BuiltinID))
+ return true;
// Arg0 must be vector unsigned char
if (!IsTypeVecUChar(TheCall->getArg(0)->getType(), 0))
return false;
@@ -183,10 +195,14 @@ bool SemaPPC::CheckPPCBuiltinFunctionCall(const TargetInfo &TI,
case PPC::BI__builtin_ppc_national2packed:
case PPC::BI__builtin_ppc_packed2zoned:
case PPC::BI__builtin_ppc_zoned2packed:
+ if (CheckArgCountAtMost(BuiltinID))
+ return true;
return SemaRef.BuiltinConstantArgRange(TheCall, 1, 0, 1);
case PPC::BI__builtin_ppc_bcdshift:
case PPC::BI__builtin_ppc_bcdshiftround:
case PPC::BI__builtin_ppc_bcdtruncate: {
+ if (CheckArgCountAtMost(BuiltinID))
+ return true;
// Arg0 must be vector unsigned char
if (!IsTypeVecUChar(TheCall->getArg(0)->getType(), 0))
diff --git a/clang/test/Sema/PowerPC/builtins-too-many-args-check.cpp b/clang/test/Sema/PowerPC/builtins-too-many-args-check.cpp
index da2aba5e9768c..d1fa1e543b04b 100644
--- a/clang/test/Sema/PowerPC/builtins-too-many-args-check.cpp
+++ b/clang/test/Sema/PowerPC/builtins-too-many-args-check.cpp
@@ -6,17 +6,29 @@
// RUN: %clang_cc1 -target-feature +power9-vector -triple powerpc-unknown-unknown -fsyntax-only -verify %s
vector unsigned char test_bcdsetsign_too_many(vector unsigned char a) {
- return __builtin_ppc_bcdsetsign(a, 1, 2); // expected-error {{too many arguments to function call, expected 2, have 3}}
+ return __builtin_ppc_bcdsetsign(a, 1, 2); // expected-error {{too many arguments to function call, expected at most 2, have 3}}
}
vector unsigned char test_national2packed_too_many(vector unsigned char a) {
- return __builtin_ppc_national2packed(a, 1, 0); // expected-error {{too many arguments to function call, expected 2, have 3}}
+ return __builtin_ppc_national2packed(a, 1, 0); // expected-error {{too many arguments to function call, expected at most 2, have 3}}
}
vector unsigned char test_packed2zoned_too_many(vector unsigned char a) {
- return __builtin_ppc_packed2zoned(a, 1, 0); // expected-error {{too many arguments to function call, expected 2, have 3}}
+ return __builtin_ppc_packed2zoned(a, 1, 0); // expected-error {{too many arguments to function call, expected at most 2, have 3}}
}
vector unsigned char test_zoned2packed_too_many(vector unsigned char a) {
- return __builtin_ppc_zoned2packed(a, 1, 0); // expected-error {{too many arguments to function call, expected 2, have 3}}
+ return __builtin_ppc_zoned2packed(a, 1, 0); // expected-error {{too many arguments to function call, expected at most 2, have 3}}
+}
+
+vector unsigned char test_bcdshift_too_many(vector unsigned char a) {
+ return __builtin_ppc_bcdshift(a, 1, 0, 3); // expected-error {{too many arguments to function call, expected at most 3, have 4}}
+}
+
+vector unsigned char test_bcdshiftround_too_many(vector unsigned char a) {
+ return __builtin_ppc_bcdshiftround(a, 1, 0, 3); // expected-error {{too many arguments to function call, expected at most 3, have 4}}
+}
+
+vector unsigned char test_bcdtruncate_too_many(vector unsigned char a) {
+ return __builtin_ppc_bcdtruncate(a, 1, 0, 3); // expected-error {{too many arguments to function call, expected at most 3, have 4}}
}
>From fdcc8f4318461e321b5a472121c2797cd4740855 Mon Sep 17 00:00:00 2001
From: im-lunex <thisissamir04 at gmail.com>
Date: Fri, 11 Sep 2026 22:19:44 +0600
Subject: [PATCH 4/6] undo the previus change and remove custom type checking
flag
---
clang/include/clang/Basic/BuiltinsPPC.def | 14 ++++++-------
clang/lib/Sema/SemaPPC.cpp | 20 ++-----------------
.../PowerPC/builtins-too-many-args-check.cpp | 14 ++++++-------
3 files changed, 16 insertions(+), 32 deletions(-)
diff --git a/clang/include/clang/Basic/BuiltinsPPC.def b/clang/include/clang/Basic/BuiltinsPPC.def
index 7970163c15f72..95d7e9d2613e2 100644
--- a/clang/include/clang/Basic/BuiltinsPPC.def
+++ b/clang/include/clang/Basic/BuiltinsPPC.def
@@ -581,16 +581,16 @@ TARGET_BUILTIN(__builtin_ppc_bcdsub_p, "iiV16UcV16Uc", "",
// P9 Binary-coded decimal (BCD) builtins.
TARGET_BUILTIN(__builtin_ppc_bcdcopysign, "V16UcV16UcV16Uc", "", "power9-vector")
-TARGET_BUILTIN(__builtin_ppc_bcdsetsign, "V16UcV16UcUc", "t", "power9-vector")
-TARGET_BUILTIN(__builtin_ppc_bcdshift, "V16UcV16UciUc", "t", "power9-vector")
-TARGET_BUILTIN(__builtin_ppc_bcdshiftround, "V16UcV16UciUc", "t", "power9-vector")
-TARGET_BUILTIN(__builtin_ppc_bcdtruncate, "V16UcV16UciUc", "t", "power9-vector")
+TARGET_BUILTIN(__builtin_ppc_bcdsetsign, "V16UcV16UcUc", "", "power9-vector")
+TARGET_BUILTIN(__builtin_ppc_bcdshift, "V16UcV16UciUc", "", "power9-vector")
+TARGET_BUILTIN(__builtin_ppc_bcdshiftround, "V16UcV16UciUc", "", "power9-vector")
+TARGET_BUILTIN(__builtin_ppc_bcdtruncate, "V16UcV16UciUc", "", "power9-vector")
TARGET_BUILTIN(__builtin_ppc_bcdunsignedtruncate, "V16UcV16Uci", "", "power9-vector")
TARGET_BUILTIN(__builtin_ppc_bcdunsignedshift, "V16UcV16Uci", "", "power9-vector")
-TARGET_BUILTIN(__builtin_ppc_national2packed, "V16UcV16UcUc", "t", "power9-vector")
+TARGET_BUILTIN(__builtin_ppc_national2packed, "V16UcV16UcUc", "", "power9-vector")
TARGET_BUILTIN(__builtin_ppc_packed2national, "V16UcV16Uc", "", "power9-vector")
-TARGET_BUILTIN(__builtin_ppc_packed2zoned, "V16UcV16UcUc", "t", "power9-vector")
-TARGET_BUILTIN(__builtin_ppc_zoned2packed, "V16UcV16UcUc", "t", "power9-vector")
+TARGET_BUILTIN(__builtin_ppc_packed2zoned, "V16UcV16UcUc", "", "power9-vector")
+TARGET_BUILTIN(__builtin_ppc_zoned2packed, "V16UcV16UcUc", "", "power9-vector")
TARGET_BUILTIN(__builtin_altivec_vclzlsbb, "SiV16Uc", "", "power9-vector")
TARGET_BUILTIN(__builtin_altivec_vctzlsbb, "SiV16Uc", "", "power9-vector")
diff --git a/clang/lib/Sema/SemaPPC.cpp b/clang/lib/Sema/SemaPPC.cpp
index a9ac931dda8c3..2eee9a6d7e222 100644
--- a/clang/lib/Sema/SemaPPC.cpp
+++ b/clang/lib/Sema/SemaPPC.cpp
@@ -139,22 +139,12 @@ bool SemaPPC::CheckPPCBuiltinFunctionCall(const TargetInfo &TI,
}
}
- // Common BCD type-validation helpers
+ // Common BCD type-validation helpers
// Emit error diagnostics and return true on success
// - IsTypeVecUChar: enforces vector unsigned char
// - IsIntType: enforces any integer type
// Lambdas centralize type checks for BCD builtin handlers
- // reject calls with more args than the builtin's declared prototype
- auto CheckArgCountAtMost = [&](unsigned BuiltinID) -> bool {
- ASTContext::GetBuiltinTypeError Error;
- if (const auto *FPT = dyn_cast<FunctionProtoType>(
- Context.GetBuiltinType(BuiltinID, Error).getTypePtr()))
- if (!FPT->isVariadic())
- return SemaRef.checkArgCountAtMost(TheCall, FPT->getNumParams());
- return false;
- };
-
// Lambda 1: verify vector unsigned char type
auto IsTypeVecUChar = [&](QualType ArgTy, unsigned ArgIndex) -> bool {
QualType VecType = Context.getVectorType(Context.UnsignedCharTy, 16,
@@ -182,9 +172,7 @@ bool SemaPPC::CheckPPCBuiltinFunctionCall(const TargetInfo &TI,
switch (BuiltinID) {
default:
return false;
- case PPC::BI__builtin_ppc_bcdsetsign: {
- if (CheckArgCountAtMost(BuiltinID))
- return true;
+ case PPC::BI__builtin_ppc_bcdsetsign: {
// Arg0 must be vector unsigned char
if (!IsTypeVecUChar(TheCall->getArg(0)->getType(), 0))
return false;
@@ -195,14 +183,10 @@ bool SemaPPC::CheckPPCBuiltinFunctionCall(const TargetInfo &TI,
case PPC::BI__builtin_ppc_national2packed:
case PPC::BI__builtin_ppc_packed2zoned:
case PPC::BI__builtin_ppc_zoned2packed:
- if (CheckArgCountAtMost(BuiltinID))
- return true;
return SemaRef.BuiltinConstantArgRange(TheCall, 1, 0, 1);
case PPC::BI__builtin_ppc_bcdshift:
case PPC::BI__builtin_ppc_bcdshiftround:
case PPC::BI__builtin_ppc_bcdtruncate: {
- if (CheckArgCountAtMost(BuiltinID))
- return true;
// Arg0 must be vector unsigned char
if (!IsTypeVecUChar(TheCall->getArg(0)->getType(), 0))
diff --git a/clang/test/Sema/PowerPC/builtins-too-many-args-check.cpp b/clang/test/Sema/PowerPC/builtins-too-many-args-check.cpp
index d1fa1e543b04b..4d6f50ab1922c 100644
--- a/clang/test/Sema/PowerPC/builtins-too-many-args-check.cpp
+++ b/clang/test/Sema/PowerPC/builtins-too-many-args-check.cpp
@@ -6,29 +6,29 @@
// RUN: %clang_cc1 -target-feature +power9-vector -triple powerpc-unknown-unknown -fsyntax-only -verify %s
vector unsigned char test_bcdsetsign_too_many(vector unsigned char a) {
- return __builtin_ppc_bcdsetsign(a, 1, 2); // expected-error {{too many arguments to function call, expected at most 2, have 3}}
+ return __builtin_ppc_bcdsetsign(a, 1, 2); // expected-error {{too many arguments to function call, expected 2, have 3}}
}
vector unsigned char test_national2packed_too_many(vector unsigned char a) {
- return __builtin_ppc_national2packed(a, 1, 0); // expected-error {{too many arguments to function call, expected at most 2, have 3}}
+ return __builtin_ppc_national2packed(a, 1, 0); // expected-error {{too many arguments to function call, expected 2, have 3}}
}
vector unsigned char test_packed2zoned_too_many(vector unsigned char a) {
- return __builtin_ppc_packed2zoned(a, 1, 0); // expected-error {{too many arguments to function call, expected at most 2, have 3}}
+ return __builtin_ppc_packed2zoned(a, 1, 0); // expected-error {{too many arguments to function call, expected 2, have 3}}
}
vector unsigned char test_zoned2packed_too_many(vector unsigned char a) {
- return __builtin_ppc_zoned2packed(a, 1, 0); // expected-error {{too many arguments to function call, expected at most 2, have 3}}
+ return __builtin_ppc_zoned2packed(a, 1, 0); // expected-error {{too many arguments to function call, expected 2, have 3}}
}
vector unsigned char test_bcdshift_too_many(vector unsigned char a) {
- return __builtin_ppc_bcdshift(a, 1, 0, 3); // expected-error {{too many arguments to function call, expected at most 3, have 4}}
+ return __builtin_ppc_bcdshift(a, 1, 0, 3); // expected-error {{too many arguments to function call, expected 3, have 4}}
}
vector unsigned char test_bcdshiftround_too_many(vector unsigned char a) {
- return __builtin_ppc_bcdshiftround(a, 1, 0, 3); // expected-error {{too many arguments to function call, expected at most 3, have 4}}
+ return __builtin_ppc_bcdshiftround(a, 1, 0, 3); // expected-error {{too many arguments to function call, expected 3, have 4}}
}
vector unsigned char test_bcdtruncate_too_many(vector unsigned char a) {
- return __builtin_ppc_bcdtruncate(a, 1, 0, 3); // expected-error {{too many arguments to function call, expected at most 3, have 4}}
+ return __builtin_ppc_bcdtruncate(a, 1, 0, 3); // expected-error {{too many arguments to function call, expected 3, have 4}}
}
>From 4fd9783cdd43c346d896a24a44e9e70e54a7f451 Mon Sep 17 00:00:00 2001
From: im-lunex <thisissamir04 at gmail.com>
Date: Fri, 11 Sep 2026 22:22:35 +0600
Subject: [PATCH 5/6] format
---
clang/lib/Sema/SemaPPC.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Sema/SemaPPC.cpp b/clang/lib/Sema/SemaPPC.cpp
index 2eee9a6d7e222..8a594fc86dea6 100644
--- a/clang/lib/Sema/SemaPPC.cpp
+++ b/clang/lib/Sema/SemaPPC.cpp
@@ -139,7 +139,7 @@ bool SemaPPC::CheckPPCBuiltinFunctionCall(const TargetInfo &TI,
}
}
- // Common BCD type-validation helpers
+ // Common BCD type-validation helpers
// Emit error diagnostics and return true on success
// - IsTypeVecUChar: enforces vector unsigned char
// - IsIntType: enforces any integer type
@@ -172,7 +172,7 @@ 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;
>From 944570441d3c16270fa37c07eebaf3951e1eaf10 Mon Sep 17 00:00:00 2001
From: im-lunex <thisissamir04 at gmail.com>
Date: Mon, 14 Sep 2026 00:07:47 +0600
Subject: [PATCH 6/6] add the target specific argument check for builtin's
---
clang/include/clang/Basic/BuiltinsPPC.def | 14 +++++++-------
clang/lib/Sema/SemaPPC.cpp | 21 ++++++++++++++++++++-
2 files changed, 27 insertions(+), 8 deletions(-)
diff --git a/clang/include/clang/Basic/BuiltinsPPC.def b/clang/include/clang/Basic/BuiltinsPPC.def
index 95d7e9d2613e2..7970163c15f72 100644
--- a/clang/include/clang/Basic/BuiltinsPPC.def
+++ b/clang/include/clang/Basic/BuiltinsPPC.def
@@ -581,16 +581,16 @@ TARGET_BUILTIN(__builtin_ppc_bcdsub_p, "iiV16UcV16Uc", "",
// P9 Binary-coded decimal (BCD) builtins.
TARGET_BUILTIN(__builtin_ppc_bcdcopysign, "V16UcV16UcV16Uc", "", "power9-vector")
-TARGET_BUILTIN(__builtin_ppc_bcdsetsign, "V16UcV16UcUc", "", "power9-vector")
-TARGET_BUILTIN(__builtin_ppc_bcdshift, "V16UcV16UciUc", "", "power9-vector")
-TARGET_BUILTIN(__builtin_ppc_bcdshiftround, "V16UcV16UciUc", "", "power9-vector")
-TARGET_BUILTIN(__builtin_ppc_bcdtruncate, "V16UcV16UciUc", "", "power9-vector")
+TARGET_BUILTIN(__builtin_ppc_bcdsetsign, "V16UcV16UcUc", "t", "power9-vector")
+TARGET_BUILTIN(__builtin_ppc_bcdshift, "V16UcV16UciUc", "t", "power9-vector")
+TARGET_BUILTIN(__builtin_ppc_bcdshiftround, "V16UcV16UciUc", "t", "power9-vector")
+TARGET_BUILTIN(__builtin_ppc_bcdtruncate, "V16UcV16UciUc", "t", "power9-vector")
TARGET_BUILTIN(__builtin_ppc_bcdunsignedtruncate, "V16UcV16Uci", "", "power9-vector")
TARGET_BUILTIN(__builtin_ppc_bcdunsignedshift, "V16UcV16Uci", "", "power9-vector")
-TARGET_BUILTIN(__builtin_ppc_national2packed, "V16UcV16UcUc", "", "power9-vector")
+TARGET_BUILTIN(__builtin_ppc_national2packed, "V16UcV16UcUc", "t", "power9-vector")
TARGET_BUILTIN(__builtin_ppc_packed2national, "V16UcV16Uc", "", "power9-vector")
-TARGET_BUILTIN(__builtin_ppc_packed2zoned, "V16UcV16UcUc", "", "power9-vector")
-TARGET_BUILTIN(__builtin_ppc_zoned2packed, "V16UcV16UcUc", "", "power9-vector")
+TARGET_BUILTIN(__builtin_ppc_packed2zoned, "V16UcV16UcUc", "t", "power9-vector")
+TARGET_BUILTIN(__builtin_ppc_zoned2packed, "V16UcV16UcUc", "t", "power9-vector")
TARGET_BUILTIN(__builtin_altivec_vclzlsbb, "SiV16Uc", "", "power9-vector")
TARGET_BUILTIN(__builtin_altivec_vctzlsbb, "SiV16Uc", "", "power9-vector")
diff --git a/clang/lib/Sema/SemaPPC.cpp b/clang/lib/Sema/SemaPPC.cpp
index 8a594fc86dea6..3fb8cca69632b 100644
--- a/clang/lib/Sema/SemaPPC.cpp
+++ b/clang/lib/Sema/SemaPPC.cpp
@@ -169,10 +169,22 @@ bool SemaPPC::CheckPPCBuiltinFunctionCall(const TargetInfo &TI,
return false;
};
+ // reject calls with more args than the builtin's declared prototype
+ auto CheckArgCount = [&]() -> bool {
+ ASTContext::GetBuiltinTypeError Error;
+ if (const auto *FPT = dyn_cast<FunctionProtoType>(
+ Context.GetBuiltinType(BuiltinID, Error).getTypePtr()))
+ if (!FPT->isVariadic())
+ return SemaRef.checkArgCount(TheCall, FPT->getNumParams());
+ return false;
+ };
+
switch (BuiltinID) {
default:
return false;
case PPC::BI__builtin_ppc_bcdsetsign: {
+ if (CheckArgCount())
+ return true;
// Arg0 must be vector unsigned char
if (!IsTypeVecUChar(TheCall->getArg(0)->getType(), 0))
return false;
@@ -182,11 +194,18 @@ bool SemaPPC::CheckPPCBuiltinFunctionCall(const TargetInfo &TI,
}
case PPC::BI__builtin_ppc_national2packed:
case PPC::BI__builtin_ppc_packed2zoned:
- case PPC::BI__builtin_ppc_zoned2packed:
+ case PPC::BI__builtin_ppc_zoned2packed: {
+ if (!IsTypeVecUChar(TheCall->getArg(0)->getType(), 0))
+ return false;
+ if (CheckArgCount())
+ return true;
return SemaRef.BuiltinConstantArgRange(TheCall, 1, 0, 1);
+ }
case PPC::BI__builtin_ppc_bcdshift:
case PPC::BI__builtin_ppc_bcdshiftround:
case PPC::BI__builtin_ppc_bcdtruncate: {
+ if (CheckArgCount())
+ return true;
// Arg0 must be vector unsigned char
if (!IsTypeVecUChar(TheCall->getArg(0)->getType(), 0))
More information about the cfe-commits
mailing list