https://github.com/Devanshi-cmd created https://github.com/llvm/llvm-project/pull/178709
None >From b35bb1ad82e5cd5fb1844ca62435c3d832b91da5 Mon Sep 17 00:00:00 2001 From: Devanshi-cmd <[email protected]> Date: Tue, 27 Jan 2026 20:33:57 +0530 Subject: [PATCH 1/4] [Clang][CIR] Replace -1ULL with std::numeric_limits in Itanium CXXABI Replace instances of -1ULL with std::numeric_limits<uint64_t>::max() in CIR Itanium C++ ABI implementations to address C4146 compiler warning. This change improves code clarity and eliminates MSVC warning C4146 (unary minus operator applied to unsigned type) in the experimental Clang IR (CIR) implementations. Files changed: - clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp - clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerItaniumCXXABI.cpp Fixes part of #147439 --- clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp | 4 +++- .../Dialect/Transforms/TargetLowering/LowerItaniumCXXABI.cpp | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp b/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp index 26465a804f1e6..e61e0390ee86d 100644 --- a/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp @@ -26,6 +26,8 @@ #include "clang/CIR/MissingFeatures.h" #include "llvm/Support/ErrorHandling.h" +#include <limits> + using namespace clang; using namespace clang::CIRGen; @@ -1939,7 +1941,7 @@ static CharUnits computeOffsetHint(ASTContext &astContext, // If the path contains a virtual base class we can't give any hint. // -1: no hint. if (pathElement.Base->isVirtual()) - return CharUnits::fromQuantity(-1ULL); + return CharUnits::fromQuantity( std::numeric_limits<uint64_t>::max()); if (numPublicPaths > 1) // Won't use offsets, skip computation. continue; diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerItaniumCXXABI.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerItaniumCXXABI.cpp index 10996e6b5fe29..c9d59539d55d6 100644 --- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerItaniumCXXABI.cpp +++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerItaniumCXXABI.cpp @@ -26,6 +26,8 @@ #include "mlir/IR/ImplicitLocOpBuilder.h" #include "llvm/Support/ErrorHandling.h" +#include <limits> + namespace cir { namespace { @@ -170,7 +172,7 @@ mlir::TypedAttr LowerItaniumCXXABI::lowerDataMemberConstant( if (attr.isNullPtr()) { // Itanium C++ ABI 2.3: // A NULL pointer is represented as -1. - memberOffset = -1ull; + memberOffset = std::numeric_limits<uint64_t>::max(); } else { // Itanium C++ ABI 2.3: // A pointer to data member is an offset from the base address of >From 204e82343109415de403ad6c40399aabb9496c5b Mon Sep 17 00:00:00 2001 From: Devanshi-cmd <[email protected]> Date: Wed, 28 Jan 2026 20:30:08 +0530 Subject: [PATCH 2/4] Use -1 instead of std::numeric_limits for signed parameter" Changed to use -1 since fromQuantity() expects int64_t (signed type). Using std::numeric_limits<uint64_t>::max() was incorrect for signed parameters. --- .../Dialect/Transforms/TargetLowering/LowerItaniumCXXABI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerItaniumCXXABI.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerItaniumCXXABI.cpp index c9d59539d55d6..f626c6d628ba1 100644 --- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerItaniumCXXABI.cpp +++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerItaniumCXXABI.cpp @@ -172,7 +172,7 @@ mlir::TypedAttr LowerItaniumCXXABI::lowerDataMemberConstant( if (attr.isNullPtr()) { // Itanium C++ ABI 2.3: // A NULL pointer is represented as -1. - memberOffset = std::numeric_limits<uint64_t>::max(); + memberOffset = -1; } else { // Itanium C++ ABI 2.3: // A pointer to data member is an offset from the base address of >From 5b55c34443eaa47158c16e9e39aac080ce00951d Mon Sep 17 00:00:00 2001 From: Devanshi-cmd <[email protected]> Date: Thu, 29 Jan 2026 22:47:11 +0530 Subject: [PATCH 3/4] [clang-tidy] Fix false positive in hicpp-vararg for __builtin_popcountg The hicpp-vararg check (alias for cppcoreguidelines-pro-type-vararg) was incorrectly flagging __builtin_popcountg as a c-style variadic function. While this builtin has a variadic signature internally, it is a safe, type-generic builtin that accepts exactly one argument of any integer type. This commit adds __builtin_popcountg to the AllowedVariadics list and includes a test case to verify it no longer triggers a warning. Fixes #178629 --- .../cppcoreguidelines/ProTypeVarargCheck.cpp | 1 + .../checkers/cppcoreguidelines/pro-type-vararg.cpp | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp index d5ff4af84b0b7..0601de71e57a3 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp @@ -55,6 +55,7 @@ static constexpr StringRef AllowedVariadics[] = { "__builtin_preserve_access_index", "__builtin_nontemporal_store", "__builtin_nontemporal_load", + "__builtin_popcountg", "__builtin_ms_va_start", // clang-format on }; diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp index 3f73d1de333f4..d2ee6cf477b34 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp @@ -57,6 +57,7 @@ void ignoredBuiltinsTest(void *ptr) { (void)__builtin_fpclassify(0, 0, 0, 0, 0, 0.f); (void)__builtin_isinf_sign(0.f); (void)__builtin_prefetch(nullptr); + (void)__builtin_popcountg(42); } // Some implementations of __builtin_va_list and __builtin_ms_va_list desugared @@ -68,7 +69,14 @@ void no_false_positive_desugar_va_list(char *in) { } namespace PR30542 { - struct X; + struct X;static cl::opt<unsigned long long> + MaxSamples("max-samples", + cl::init(-1ULL), + cl::desc("maximum number of samples to read from LBR profile"), + cl::Optional, + cl::Hidden, + cl::cat(AggregatorCategory)); + template <typename T> char IsNullConstant(X*); template <typename T> >From 9a1064601eeb6fe66e7c4bef835d730e1a620ee5 Mon Sep 17 00:00:00 2001 From: Devanshi-cmd <[email protected]> Date: Thu, 29 Jan 2026 23:19:32 +0530 Subject: [PATCH 4/4] [clang-tidy] Fix false positive in hicpp-vararg for __builtin_popcountg The hicpp-vararg check (alias for cppcoreguidelines-pro-type-vararg) was incorrectly flagging __builtin_popcountg as a c-style variadic function. While this builtin has a variadic signature internally, it is a safe, type-generic builtin that accepts exactly one argument of any integer type. This commit adds __builtin_popcountg to the AllowedVariadics list and includes a test case to verify it no longer triggers a warning. Fixes #178629 --- .../clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp | 1 + .../clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp index d5ff4af84b0b7..0601de71e57a3 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp @@ -55,6 +55,7 @@ static constexpr StringRef AllowedVariadics[] = { "__builtin_preserve_access_index", "__builtin_nontemporal_store", "__builtin_nontemporal_load", + "__builtin_popcountg", "__builtin_ms_va_start", // clang-format on }; diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp index 3f73d1de333f4..fcd5753a79ca3 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp @@ -57,6 +57,7 @@ void ignoredBuiltinsTest(void *ptr) { (void)__builtin_fpclassify(0, 0, 0, 0, 0, 0.f); (void)__builtin_isinf_sign(0.f); (void)__builtin_prefetch(nullptr); + (void)__builtin_popcountg(42); } // Some implementations of __builtin_va_list and __builtin_ms_va_list desugared _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
