https://github.com/MainakSil updated https://github.com/llvm/llvm-project/pull/108804
>From 43e6c22f25f419b64678374dd247eaf8bc28fa57 Mon Sep 17 00:00:00 2001 From: Mainak Sil <mainaks...@gmail.com> Date: Mon, 16 Sep 2024 09:50:33 +0530 Subject: [PATCH 1/6] [clang] Increase VecLib bitfield size to 4 bits in CodeGenOptions.def --- clang/include/clang/Basic/CodeGenOptions.def | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index b600198998d85b..f2a96324936775 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -376,7 +376,7 @@ ENUM_CODEGENOPT(Inlining, InliningMethod, 2, NormalInlining) VALUE_CODEGENOPT(InlineMaxStackSize, 32, UINT_MAX) // Vector functions library to use. -ENUM_CODEGENOPT(VecLib, llvm::driver::VectorLibrary, 3, llvm::driver::VectorLibrary::NoLibrary) +ENUM_CODEGENOPT(VecLib, llvm::driver::VectorLibrary, 4, llvm::driver::VectorLibrary::NoLibrary) /// The default TLS model to use. ENUM_CODEGENOPT(DefaultTLSModel, TLSModel, 2, GeneralDynamicTLSModel) >From b30adc9c059d1af9b5874b5c0e258670d3190852 Mon Sep 17 00:00:00 2001 From: Mainak Sil <mainaks...@gmail.com> Date: Mon, 16 Sep 2024 14:18:03 +0530 Subject: [PATCH 2/6] Update CodeGenOptions.def --- clang/include/clang/Basic/CodeGenOptions.def | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index f2a96324936775..2d5bb84d1cc59c 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -375,6 +375,11 @@ ENUM_CODEGENOPT(Inlining, InliningMethod, 2, NormalInlining) /// The maximum stack size a function can have to be considered for inlining. VALUE_CODEGENOPT(InlineMaxStackSize, 32, UINT_MAX) +// Ensure the VecLib bitfield has enough space for future vector libraries. +// If new vector libraries are added beyond the current limit of 16, this static assertion will fail. +static_assert(static_cast<int>(llvm::driver::VectorLibrary::NoLibrary) <= 16, + "The VecLib bitfield in CodeGenOptions needs to be expanded to support more vector libraries."); + // Vector functions library to use. ENUM_CODEGENOPT(VecLib, llvm::driver::VectorLibrary, 4, llvm::driver::VectorLibrary::NoLibrary) >From d96f69105c5be85acf3614258911fbdf74dbc60f Mon Sep 17 00:00:00 2001 From: Mainak Sil <mainaks...@gmail.com> Date: Mon, 16 Sep 2024 14:32:26 +0530 Subject: [PATCH 3/6] Update CodeGenOptions.def >From 558038b29eedb81e9ce328f323914329af0d8f0f Mon Sep 17 00:00:00 2001 From: Mainak Sil <mainaks...@gmail.com> Date: Wed, 18 Sep 2024 08:57:16 +0530 Subject: [PATCH 4/6] Update CodeGenOptions.def --- clang/include/clang/Basic/CodeGenOptions.def | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index 2d5bb84d1cc59c..b78ae61e6509ea 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -375,13 +375,18 @@ ENUM_CODEGENOPT(Inlining, InliningMethod, 2, NormalInlining) /// The maximum stack size a function can have to be considered for inlining. VALUE_CODEGENOPT(InlineMaxStackSize, 32, UINT_MAX) -// Ensure the VecLib bitfield has enough space for future vector libraries. -// If new vector libraries are added beyond the current limit of 16, this static assertion will fail. -static_assert(static_cast<int>(llvm::driver::VectorLibrary::NoLibrary) <= 16, - "The VecLib bitfield in CodeGenOptions needs to be expanded to support more vector libraries."); +// Define the number of bits required for the VecLib enum +#define VECLIB_BIT_COUNT (llvm::countPopulation(llvm::driver::VectorLibrary::MaxLibrary)) -// Vector functions library to use. -ENUM_CODEGENOPT(VecLib, llvm::driver::VectorLibrary, 4, llvm::driver::VectorLibrary::NoLibrary) +// Ensure the VecLib bitfield has enough space for future vector libraries. +// The number of bits is determined automatically based on the number of enum values. +static_assert(static_cast<size_t>(llvm::driver::VectorLibrary::MaxLibrary) <= (1 << VECLIB_BIT_COUNT), + "VecLib bitfield size is too small to accommodate all vector libraries."); + +// VecLib definition in CodeGenOptions.def +ENUM_CODEGENOPT(VecLib, llvm::driver::VectorLibrary, VECLIB_BIT_COUNT, llvm::driver::VectorLibrary::NoLibrary) + +#undef VECLIB_BIT_COUNT /// The default TLS model to use. ENUM_CODEGENOPT(DefaultTLSModel, TLSModel, 2, GeneralDynamicTLSModel) >From d2f9b3f437c1ac406e3ef2e72f412d0194909ee0 Mon Sep 17 00:00:00 2001 From: Mainak Sil <mainaks...@gmail.com> Date: Wed, 18 Sep 2024 09:01:08 +0530 Subject: [PATCH 5/6] Create AllLibrariesFit.cpp --- clang/unittests/CodeGen/AllLibrariesFit.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 clang/unittests/CodeGen/AllLibrariesFit.cpp diff --git a/clang/unittests/CodeGen/AllLibrariesFit.cpp b/clang/unittests/CodeGen/AllLibrariesFit.cpp new file mode 100644 index 00000000000000..9c2c34ceee6992 --- /dev/null +++ b/clang/unittests/CodeGen/AllLibrariesFit.cpp @@ -0,0 +1,9 @@ +#include "clang/Basic/CodeGenOptions.h" +#include "llvm/Driver/Options.h" +#include "gtest/gtest.h" + +TEST(VecLibBitfieldTest, AllLibrariesFit) { + // We expect that all vector libraries fit in the bitfield size + EXPECT_LE(static_cast<size_t>(llvm::driver::VectorLibrary::MaxLibrary), + (1 << VECLIB_BIT_COUNT)) << "VecLib bitfield size is too small!"; +} >From 1b39ac4650e445a3babbd5b79c2ea9aef3b3a91b Mon Sep 17 00:00:00 2001 From: Mainak Sil <mainaks...@gmail.com> Date: Wed, 18 Sep 2024 09:02:05 +0530 Subject: [PATCH 6/6] Create SimulatedOverflowTest.cpp --- .../CodeGen/SimulatedOverflowTest.cpp | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 clang/unittests/CodeGen/SimulatedOverflowTest.cpp diff --git a/clang/unittests/CodeGen/SimulatedOverflowTest.cpp b/clang/unittests/CodeGen/SimulatedOverflowTest.cpp new file mode 100644 index 00000000000000..4c716d3480cf90 --- /dev/null +++ b/clang/unittests/CodeGen/SimulatedOverflowTest.cpp @@ -0,0 +1,23 @@ +// Simulate the addition of a new library without increasing the bitfield size +enum class SimulatedVectorLibrary { + Accelerate = 0, + LIBMVEC, + MASSV, + SVML, + SLEEF, + Darwin_libsystem_m, + ArmPL, + AMDLIBM, + NoLibrary, + // Simulate new addition + NewLibrary, + MaxLibrary +}; + +#define SIMULATED_VECLIB_BIT_COUNT 4 // The current bitfield size (should be 4 for 9 options) + +TEST(VecLibBitfieldTest, SimulatedOverflowTest) { + // Simulate the addition of a new library and check if the bitfield size is sufficient + EXPECT_LE(static_cast<size_t>(SimulatedVectorLibrary::MaxLibrary), + (1 << SIMULATED_VECLIB_BIT_COUNT)) << "Simulated VecLib bitfield size overflow!"; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits