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 <[email protected]> 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 <[email protected]> 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 <[email protected]> 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 <[email protected]> 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 e7959c53bc19d66f345ebf8270db2792a1ec9394 Mon Sep 17 00:00:00 2001 From: im-lunex <[email protected]> Date: Sat, 10 Oct 2026 00:55:02 +0600 Subject: [PATCH 5/6] teach sema to choose the correct vector kind according to how we should treat is as a builtin or else --- clang/include/clang/Basic/BuiltinsPPC.def | 16 ++++++++-------- clang/lib/AST/ASTContext.cpp | 6 +++++- clang/lib/Sema/SemaPPC.cpp | 4 ++-- .../PowerPC/builtins-bcd-format-conversion.c | 14 +++++++------- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/clang/include/clang/Basic/BuiltinsPPC.def b/clang/include/clang/Basic/BuiltinsPPC.def index 95d7e9d2613e2..6eb82c1292f4a 100644 --- a/clang/include/clang/Basic/BuiltinsPPC.def +++ b/clang/include/clang/Basic/BuiltinsPPC.def @@ -579,18 +579,18 @@ TARGET_BUILTIN(__builtin_ppc_bcdadd_p, "iiV16UcV16Uc", "", TARGET_BUILTIN(__builtin_ppc_bcdsub_p, "iiV16UcV16Uc", "", "isa-v207-instructions") -// P9 Binary-coded decimal (BCD) builtins. +// 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, "V16UcV16Uci", "", "power9-vector") +TARGET_BUILTIN(__builtin_ppc_bcdshift, "V16UcV16Ucii", "", "power9-vector") +TARGET_BUILTIN(__builtin_ppc_bcdshiftround, "V16UcV16Ucii", "", "power9-vector") +TARGET_BUILTIN(__builtin_ppc_bcdtruncate, "V16UcV16Ucii", "", "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, "V16UcV16Uci", "", "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, "V16UcV16Uci", "", "power9-vector") +TARGET_BUILTIN(__builtin_ppc_zoned2packed, "V16UcV16Uci", "", "power9-vector") TARGET_BUILTIN(__builtin_altivec_vclzlsbb, "SiV16Uc", "", "power9-vector") TARGET_BUILTIN(__builtin_altivec_vctzlsbb, "SiV16Uc", "", "power9-vector") diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index f4a63073aaed1..a51a1045d0f04 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -12862,7 +12862,11 @@ static QualType DecodeTypeFromStr(const char *&Str, const ASTContext &Context, assert(!RequiresICE && "Can't require vector ICE"); // TODO: No way to make AltiVec vectors in builtins yet. - Type = Context.getVectorType(ElementType, NumElements, VectorKind::Generic); + VectorKind VecKind = VectorKind::Generic; + if (Context.getTargetInfo().getTriple().isPPC() && + Context.getLangOpts().AltiVec) + VecKind = VectorKind::AltiVecVector; + Type = Context.getVectorType(ElementType, NumElements, VecKind); break; } case 'E': { 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; diff --git a/clang/test/Sema/PowerPC/builtins-bcd-format-conversion.c b/clang/test/Sema/PowerPC/builtins-bcd-format-conversion.c index d49783c692aaa..a0c1d0bc7a6a4 100644 --- a/clang/test/Sema/PowerPC/builtins-bcd-format-conversion.c +++ b/clang/test/Sema/PowerPC/builtins-bcd-format-conversion.c @@ -13,7 +13,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_a = __builtin_ppc_bcdsetsign(scalar, '\1'); // expected-error {{passing 'unsigned char' to parameter of incompatible 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}} @@ -22,8 +22,8 @@ vector unsigned char test_bcdsetsign(void) { 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)}} - vector unsigned char res_b = __builtin_ppc_bcdshift(vec, f, i); // expected-error {{argument 1 must be of type integer}} + vector unsigned char res_a = __builtin_ppc_bcdshift(scalar, i, i); // expected-error {{passing 'unsigned char' to parameter of incompatible type '__vector unsigned char' (vector of 16 'unsigned char' values)}} + vector unsigned char res_b = __builtin_ppc_bcdshift(vec, f, i); // expected-error {{argument to '__builtin_ppc_bcdshift' must be a constant integer}} vector unsigned char res_c = __builtin_ppc_bcdshift(vec, i, 2); // expected-error-re {{argument value {{.*}} is outside the valid range}} vector unsigned char res_d = __builtin_ppc_bcdshift(vec, i, -1); // expected-error-re {{argument value {{.*}} is outside the valid range}} return __builtin_ppc_bcdshift(vec, i, 1); @@ -31,8 +31,8 @@ vector unsigned char test_bcdshift(void) { vector unsigned char test_bcdshiftround(void) { DECL_COMMON_VARS - vector unsigned char res_a = __builtin_ppc_bcdshiftround(scalar, i, i); // expected-error {{argument 0 must be of type '__vector unsigned char' (vector of 16 'unsigned char' values)}} - vector unsigned char res_b = __builtin_ppc_bcdshiftround(vec, f, i); // expected-error {{argument 1 must be of type integer}} + vector unsigned char res_a = __builtin_ppc_bcdshiftround(scalar, i, i); // expected-error {{passing 'unsigned char' to parameter of incompatible type '__vector unsigned char' (vector of 16 'unsigned char' values)}} + vector unsigned char res_b = __builtin_ppc_bcdshiftround(vec, f, i); // expected-error {{argument to '__builtin_ppc_bcdshiftround' must be a constant integer}} vector unsigned char res_c = __builtin_ppc_bcdshiftround(vec, i, 2); // expected-error-re {{argument value {{.*}} is outside the valid range}} vector unsigned char res_d = __builtin_ppc_bcdshiftround(vec, i, -1); // expected-error-re {{argument value {{.*}} is outside the valid range}} return __builtin_ppc_bcdshiftround(vec, i, 1); @@ -40,8 +40,8 @@ vector unsigned char test_bcdshiftround(void) { vector unsigned char test_bcdtruncate(void) { DECL_COMMON_VARS - vector unsigned char res_a = __builtin_ppc_bcdtruncate(scalar, i, i); // expected-error {{argument 0 must be of type '__vector unsigned char' (vector of 16 'unsigned char' values)}} - vector unsigned char res_b = __builtin_ppc_bcdtruncate(vec, f, i); // expected-error {{argument 1 must be of type integer}} + vector unsigned char res_a = __builtin_ppc_bcdtruncate(scalar, i, i); // expected-error {{passing 'unsigned char' to parameter of incompatible type '__vector unsigned char' (vector of 16 'unsigned char' values)}} + vector unsigned char res_b = __builtin_ppc_bcdtruncate(vec, f, i); // expected-error {{argument to '__builtin_ppc_bcdtruncate' must be a constant integer}} vector unsigned char res_c = __builtin_ppc_bcdtruncate(vec, i, 2); // expected-error-re {{argument value {{.*}} is outside the valid range}} vector unsigned char res_d = __builtin_ppc_bcdtruncate(vec, i, -1); // expected-error-re {{argument value {{.*}} is outside the valid range}} return __builtin_ppc_bcdtruncate(vec, i, 1); From b7ba0cc9b4f0e770bcad7de0ad65e58ec1a6e551 Mon Sep 17 00:00:00 2001 From: im-lunex <[email protected]> Date: Sun, 11 Oct 2026 12:55:15 +0600 Subject: [PATCH 6/6] ci re-run _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
