[clang-tools-extra] [clang-tidy] Improve documentation of bugprone-pointer-arithmetic-on-polymorphic-object (PR #108324)

2024-09-11 Thread Mainak Sil via cfe-commits

https://github.com/MainakSil created 
https://github.com/llvm/llvm-project/pull/108324

This pull request addresses issue #107831 by improving the documentation for 
the `bugprone-pointer-arithmetic-on-polymorphic-object` Clang-Tidy check.

### Changes Made:
1. **Fixed Syntax Error**: Corrected the syntax for the virtual destructor in 
the `Base` class (`virtual ~Base();` instead of `virtual void ~Base();`).
2. **Improved Example**: Replaced the current example with a more accurate one, 
showing how pointer arithmetic on an array of derived objects can trigger a 
warning due to potential undefined behavior.
3. **Added Final Keyword Example**: Introduced an additional example where 
marking the derived class as `final` suppresses the warning, as further 
inheritance is disallowed.
4. **Clarified Documentation**: Added comments explaining how making a class 
`final` eliminates the risk of polymorphic pointer arithmetic and suppresses 
the warning.

This PR improves the clarity of the documentation and provides more relevant 
examples to help users better understand the behavior of this check.

>From edb6664fbdafb5127d141fde633779865a90dde1 Mon Sep 17 00:00:00 2001
From: Mainak Sil 
Date: Thu, 12 Sep 2024 08:58:15 +0530
Subject: [PATCH] Improve documentation for
 bugprone-pointer-arithmetic-on-polymorphic-object

---
 ...inter-arithmetic-on-polymorphic-object.rst | 38 ++-
 1 file changed, 28 insertions(+), 10 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
index 1884acd5f12b3e..4f926808f9e408 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
@@ -19,20 +19,33 @@ Example:
 .. code-block:: c++
 
   struct Base {
-virtual void ~Base();
+  virtual ~Base();
+  int i;
   };
 
   struct Derived : public Base {};
 
   void foo() {
-Base *b = new Derived[10];
+  Base *b = new Derived[10];
 
-b += 1;
-// warning: pointer arithmetic on class that declares a virtual function 
can
-// result in undefined behavior if the dynamic type differs from the
-// pointer type
+  b += 1;
+  // warning: pointer arithmetic on class that declares a virtual function can
+  // result in undefined behavior if the dynamic type differs from the
+  // pointer type
 
-delete[] static_cast(b);
+  delete[] static_cast(b);
+  }
+
+  // Another example showing array access with polymorphic objects.
+  int bar(const Derived d[]) {
+return d[1].i; // warning due to pointer arithmetic on polymorphic object
+  }
+
+  // Making Derived final suppresses the warning
+  struct FinalDerived final : public Base {};
+
+  int baz(const FinalDerived d[]) {
+return d[1].i; // no warning as FinalDerived is final
   }
 
 Options
@@ -50,14 +63,19 @@ Options
 void bar() {
   Base *b = new Base[10];
   b += 1; // warning, as Base declares a virtual destructor
-  
+
   delete[] b;
-  
+
   Derived *d = new Derived[10]; // Derived overrides the destructor, and
 // declares no other virtual functions
   d += 1; // warning only if IgnoreVirtualDeclarationsOnly is set to false
-  
+
   delete[] d;
+
+  FinalDerived *f = new FinalDerived[10];
+  f += 1; // no warning, FinalDerived is final and cannot be further 
derived
+
+  delete[] f;
 }
 
 References

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improve documentation of bugprone-pointer-arithmetic-on-polymorphic-object (PR #108324)

2024-09-12 Thread Mainak Sil via cfe-commits

https://github.com/MainakSil updated 
https://github.com/llvm/llvm-project/pull/108324

>From edb6664fbdafb5127d141fde633779865a90dde1 Mon Sep 17 00:00:00 2001
From: Mainak Sil 
Date: Thu, 12 Sep 2024 08:58:15 +0530
Subject: [PATCH] Improve documentation for
 bugprone-pointer-arithmetic-on-polymorphic-object

---
 ...inter-arithmetic-on-polymorphic-object.rst | 38 ++-
 1 file changed, 28 insertions(+), 10 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
index 1884acd5f12b3e..4f926808f9e408 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
@@ -19,20 +19,33 @@ Example:
 .. code-block:: c++
 
   struct Base {
-virtual void ~Base();
+  virtual ~Base();
+  int i;
   };
 
   struct Derived : public Base {};
 
   void foo() {
-Base *b = new Derived[10];
+  Base *b = new Derived[10];
 
-b += 1;
-// warning: pointer arithmetic on class that declares a virtual function 
can
-// result in undefined behavior if the dynamic type differs from the
-// pointer type
+  b += 1;
+  // warning: pointer arithmetic on class that declares a virtual function can
+  // result in undefined behavior if the dynamic type differs from the
+  // pointer type
 
-delete[] static_cast(b);
+  delete[] static_cast(b);
+  }
+
+  // Another example showing array access with polymorphic objects.
+  int bar(const Derived d[]) {
+return d[1].i; // warning due to pointer arithmetic on polymorphic object
+  }
+
+  // Making Derived final suppresses the warning
+  struct FinalDerived final : public Base {};
+
+  int baz(const FinalDerived d[]) {
+return d[1].i; // no warning as FinalDerived is final
   }
 
 Options
@@ -50,14 +63,19 @@ Options
 void bar() {
   Base *b = new Base[10];
   b += 1; // warning, as Base declares a virtual destructor
-  
+
   delete[] b;
-  
+
   Derived *d = new Derived[10]; // Derived overrides the destructor, and
 // declares no other virtual functions
   d += 1; // warning only if IgnoreVirtualDeclarationsOnly is set to false
-  
+
   delete[] d;
+
+  FinalDerived *f = new FinalDerived[10];
+  f += 1; // no warning, FinalDerived is final and cannot be further 
derived
+
+  delete[] f;
 }
 
 References

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improve documentation of bugprone-pointer-arithmetic-on-polymorphic-object (PR #108324)

2024-09-12 Thread Mainak Sil via cfe-commits

https://github.com/MainakSil updated 
https://github.com/llvm/llvm-project/pull/108324

>From edb6664fbdafb5127d141fde633779865a90dde1 Mon Sep 17 00:00:00 2001
From: Mainak Sil 
Date: Thu, 12 Sep 2024 08:58:15 +0530
Subject: [PATCH] Improve documentation for
 bugprone-pointer-arithmetic-on-polymorphic-object

---
 ...inter-arithmetic-on-polymorphic-object.rst | 38 ++-
 1 file changed, 28 insertions(+), 10 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
index 1884acd5f12b3e..4f926808f9e408 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
@@ -19,20 +19,33 @@ Example:
 .. code-block:: c++
 
   struct Base {
-virtual void ~Base();
+  virtual ~Base();
+  int i;
   };
 
   struct Derived : public Base {};
 
   void foo() {
-Base *b = new Derived[10];
+  Base *b = new Derived[10];
 
-b += 1;
-// warning: pointer arithmetic on class that declares a virtual function 
can
-// result in undefined behavior if the dynamic type differs from the
-// pointer type
+  b += 1;
+  // warning: pointer arithmetic on class that declares a virtual function can
+  // result in undefined behavior if the dynamic type differs from the
+  // pointer type
 
-delete[] static_cast(b);
+  delete[] static_cast(b);
+  }
+
+  // Another example showing array access with polymorphic objects.
+  int bar(const Derived d[]) {
+return d[1].i; // warning due to pointer arithmetic on polymorphic object
+  }
+
+  // Making Derived final suppresses the warning
+  struct FinalDerived final : public Base {};
+
+  int baz(const FinalDerived d[]) {
+return d[1].i; // no warning as FinalDerived is final
   }
 
 Options
@@ -50,14 +63,19 @@ Options
 void bar() {
   Base *b = new Base[10];
   b += 1; // warning, as Base declares a virtual destructor
-  
+
   delete[] b;
-  
+
   Derived *d = new Derived[10]; // Derived overrides the destructor, and
 // declares no other virtual functions
   d += 1; // warning only if IgnoreVirtualDeclarationsOnly is set to false
-  
+
   delete[] d;
+
+  FinalDerived *f = new FinalDerived[10];
+  f += 1; // no warning, FinalDerived is final and cannot be further 
derived
+
+  delete[] f;
 }
 
 References

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improve documentation of bugprone-pointer-arithmetic-on-polymorphic-object (PR #108324)

2024-09-12 Thread Mainak Sil via cfe-commits

https://github.com/MainakSil updated 
https://github.com/llvm/llvm-project/pull/108324

>From edb6664fbdafb5127d141fde633779865a90dde1 Mon Sep 17 00:00:00 2001
From: Mainak Sil 
Date: Thu, 12 Sep 2024 08:58:15 +0530
Subject: [PATCH] Improve documentation for
 bugprone-pointer-arithmetic-on-polymorphic-object

---
 ...inter-arithmetic-on-polymorphic-object.rst | 38 ++-
 1 file changed, 28 insertions(+), 10 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
index 1884acd5f12b3e..4f926808f9e408 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
@@ -19,20 +19,33 @@ Example:
 .. code-block:: c++
 
   struct Base {
-virtual void ~Base();
+  virtual ~Base();
+  int i;
   };
 
   struct Derived : public Base {};
 
   void foo() {
-Base *b = new Derived[10];
+  Base *b = new Derived[10];
 
-b += 1;
-// warning: pointer arithmetic on class that declares a virtual function 
can
-// result in undefined behavior if the dynamic type differs from the
-// pointer type
+  b += 1;
+  // warning: pointer arithmetic on class that declares a virtual function can
+  // result in undefined behavior if the dynamic type differs from the
+  // pointer type
 
-delete[] static_cast(b);
+  delete[] static_cast(b);
+  }
+
+  // Another example showing array access with polymorphic objects.
+  int bar(const Derived d[]) {
+return d[1].i; // warning due to pointer arithmetic on polymorphic object
+  }
+
+  // Making Derived final suppresses the warning
+  struct FinalDerived final : public Base {};
+
+  int baz(const FinalDerived d[]) {
+return d[1].i; // no warning as FinalDerived is final
   }
 
 Options
@@ -50,14 +63,19 @@ Options
 void bar() {
   Base *b = new Base[10];
   b += 1; // warning, as Base declares a virtual destructor
-  
+
   delete[] b;
-  
+
   Derived *d = new Derived[10]; // Derived overrides the destructor, and
 // declares no other virtual functions
   d += 1; // warning only if IgnoreVirtualDeclarationsOnly is set to false
-  
+
   delete[] d;
+
+  FinalDerived *f = new FinalDerived[10];
+  f += 1; // no warning, FinalDerived is final and cannot be further 
derived
+
+  delete[] f;
 }
 
 References

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improve documentation of bugprone-pointer-arithmetic-on-polymorphic-object (PR #108324)

2024-09-12 Thread Mainak Sil via cfe-commits

https://github.com/MainakSil updated 
https://github.com/llvm/llvm-project/pull/108324

>From edb6664fbdafb5127d141fde633779865a90dde1 Mon Sep 17 00:00:00 2001
From: Mainak Sil 
Date: Thu, 12 Sep 2024 08:58:15 +0530
Subject: [PATCH 1/2] Improve documentation for
 bugprone-pointer-arithmetic-on-polymorphic-object

---
 ...inter-arithmetic-on-polymorphic-object.rst | 38 ++-
 1 file changed, 28 insertions(+), 10 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
index 1884acd5f12b3e..4f926808f9e408 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
@@ -19,20 +19,33 @@ Example:
 .. code-block:: c++
 
   struct Base {
-virtual void ~Base();
+  virtual ~Base();
+  int i;
   };
 
   struct Derived : public Base {};
 
   void foo() {
-Base *b = new Derived[10];
+  Base *b = new Derived[10];
 
-b += 1;
-// warning: pointer arithmetic on class that declares a virtual function 
can
-// result in undefined behavior if the dynamic type differs from the
-// pointer type
+  b += 1;
+  // warning: pointer arithmetic on class that declares a virtual function can
+  // result in undefined behavior if the dynamic type differs from the
+  // pointer type
 
-delete[] static_cast(b);
+  delete[] static_cast(b);
+  }
+
+  // Another example showing array access with polymorphic objects.
+  int bar(const Derived d[]) {
+return d[1].i; // warning due to pointer arithmetic on polymorphic object
+  }
+
+  // Making Derived final suppresses the warning
+  struct FinalDerived final : public Base {};
+
+  int baz(const FinalDerived d[]) {
+return d[1].i; // no warning as FinalDerived is final
   }
 
 Options
@@ -50,14 +63,19 @@ Options
 void bar() {
   Base *b = new Base[10];
   b += 1; // warning, as Base declares a virtual destructor
-  
+
   delete[] b;
-  
+
   Derived *d = new Derived[10]; // Derived overrides the destructor, and
 // declares no other virtual functions
   d += 1; // warning only if IgnoreVirtualDeclarationsOnly is set to false
-  
+
   delete[] d;
+
+  FinalDerived *f = new FinalDerived[10];
+  f += 1; // no warning, FinalDerived is final and cannot be further 
derived
+
+  delete[] f;
 }
 
 References

>From c6832232a55d39bc98562537b9a357378a007227 Mon Sep 17 00:00:00 2001
From: Mainak Sil <145980094+mainak...@users.noreply.github.com>
Date: Thu, 12 Sep 2024 19:32:25 +0530
Subject: [PATCH 2/2] Update example to remove new/delete and focus on pointer
 arithmetic

---
 ...inter-arithmetic-on-polymorphic-object.rst | 28 ++-
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
index 4f926808f9e408..cff997d5ada2aa 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
@@ -19,21 +19,23 @@ Example:
 .. code-block:: c++
 
   struct Base {
-  virtual ~Base();
-  int i;
+virtual ~Base();
+int i;
   };
-
+  
   struct Derived : public Base {};
-
-  void foo() {
-  Base *b = new Derived[10];
-
-  b += 1;
-  // warning: pointer arithmetic on class that declares a virtual function can
-  // result in undefined behavior if the dynamic type differs from the
-  // pointer type
-
-  delete[] static_cast(b);
+  
+  // Function that takes a pointer and performs pointer arithmetic
+  void foo(Base* b) {
+b += 1;
+// warning: pointer arithmetic on class that declares a virtual function 
can
+// result in undefined behavior if the dynamic type differs from the
+// pointer type
+  }
+  
+  void bar() {
+Derived d[10];  // Array of derived objects
+foo(d); // Passing Derived pointer to foo(), which performs 
arithmetic
   }
 
   // Another example showing array access with polymorphic objects.

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improve documentation of bugprone-pointer-arithmetic-on-polymorphic-object (PR #108324)

2024-09-12 Thread Mainak Sil via cfe-commits

https://github.com/MainakSil updated 
https://github.com/llvm/llvm-project/pull/108324

>From edb6664fbdafb5127d141fde633779865a90dde1 Mon Sep 17 00:00:00 2001
From: Mainak Sil 
Date: Thu, 12 Sep 2024 08:58:15 +0530
Subject: [PATCH 1/2] Improve documentation for
 bugprone-pointer-arithmetic-on-polymorphic-object

---
 ...inter-arithmetic-on-polymorphic-object.rst | 38 ++-
 1 file changed, 28 insertions(+), 10 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
index 1884acd5f12b3e..4f926808f9e408 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
@@ -19,20 +19,33 @@ Example:
 .. code-block:: c++
 
   struct Base {
-virtual void ~Base();
+  virtual ~Base();
+  int i;
   };
 
   struct Derived : public Base {};
 
   void foo() {
-Base *b = new Derived[10];
+  Base *b = new Derived[10];
 
-b += 1;
-// warning: pointer arithmetic on class that declares a virtual function 
can
-// result in undefined behavior if the dynamic type differs from the
-// pointer type
+  b += 1;
+  // warning: pointer arithmetic on class that declares a virtual function can
+  // result in undefined behavior if the dynamic type differs from the
+  // pointer type
 
-delete[] static_cast(b);
+  delete[] static_cast(b);
+  }
+
+  // Another example showing array access with polymorphic objects.
+  int bar(const Derived d[]) {
+return d[1].i; // warning due to pointer arithmetic on polymorphic object
+  }
+
+  // Making Derived final suppresses the warning
+  struct FinalDerived final : public Base {};
+
+  int baz(const FinalDerived d[]) {
+return d[1].i; // no warning as FinalDerived is final
   }
 
 Options
@@ -50,14 +63,19 @@ Options
 void bar() {
   Base *b = new Base[10];
   b += 1; // warning, as Base declares a virtual destructor
-  
+
   delete[] b;
-  
+
   Derived *d = new Derived[10]; // Derived overrides the destructor, and
 // declares no other virtual functions
   d += 1; // warning only if IgnoreVirtualDeclarationsOnly is set to false
-  
+
   delete[] d;
+
+  FinalDerived *f = new FinalDerived[10];
+  f += 1; // no warning, FinalDerived is final and cannot be further 
derived
+
+  delete[] f;
 }
 
 References

>From c6832232a55d39bc98562537b9a357378a007227 Mon Sep 17 00:00:00 2001
From: Mainak Sil <145980094+mainak...@users.noreply.github.com>
Date: Thu, 12 Sep 2024 19:32:25 +0530
Subject: [PATCH 2/2] Update example to remove new/delete and focus on pointer
 arithmetic

---
 ...inter-arithmetic-on-polymorphic-object.rst | 28 ++-
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
index 4f926808f9e408..cff997d5ada2aa 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
@@ -19,21 +19,23 @@ Example:
 .. code-block:: c++
 
   struct Base {
-  virtual ~Base();
-  int i;
+virtual ~Base();
+int i;
   };
-
+  
   struct Derived : public Base {};
-
-  void foo() {
-  Base *b = new Derived[10];
-
-  b += 1;
-  // warning: pointer arithmetic on class that declares a virtual function can
-  // result in undefined behavior if the dynamic type differs from the
-  // pointer type
-
-  delete[] static_cast(b);
+  
+  // Function that takes a pointer and performs pointer arithmetic
+  void foo(Base* b) {
+b += 1;
+// warning: pointer arithmetic on class that declares a virtual function 
can
+// result in undefined behavior if the dynamic type differs from the
+// pointer type
+  }
+  
+  void bar() {
+Derived d[10];  // Array of derived objects
+foo(d); // Passing Derived pointer to foo(), which performs 
arithmetic
   }
 
   // Another example showing array access with polymorphic objects.

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improve documentation of bugprone-pointer-arithmetic-on-polymorphic-object (PR #108324)

2024-09-12 Thread Mainak Sil via cfe-commits

MainakSil wrote:

I have updated the example based on your feedback. The `new`/`delete` usage has 
been removed to avoid additional undefined behavior. The example now directly 
passes a pointer to a function, which performs the pointer arithmetic, focusing 
solely on the issue of undefined behavior in pointer arithmetic on polymorphic 
objects.

https://github.com/llvm/llvm-project/pull/108324
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improve documentation of bugprone-pointer-arithmetic-on-polymorphic-object (PR #108324)

2024-09-12 Thread Mainak Sil via cfe-commits

https://github.com/MainakSil updated 
https://github.com/llvm/llvm-project/pull/108324

>From edb6664fbdafb5127d141fde633779865a90dde1 Mon Sep 17 00:00:00 2001
From: Mainak Sil 
Date: Thu, 12 Sep 2024 08:58:15 +0530
Subject: [PATCH 1/2] Improve documentation for
 bugprone-pointer-arithmetic-on-polymorphic-object

---
 ...inter-arithmetic-on-polymorphic-object.rst | 38 ++-
 1 file changed, 28 insertions(+), 10 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
index 1884acd5f12b3e..4f926808f9e408 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
@@ -19,20 +19,33 @@ Example:
 .. code-block:: c++
 
   struct Base {
-virtual void ~Base();
+  virtual ~Base();
+  int i;
   };
 
   struct Derived : public Base {};
 
   void foo() {
-Base *b = new Derived[10];
+  Base *b = new Derived[10];
 
-b += 1;
-// warning: pointer arithmetic on class that declares a virtual function 
can
-// result in undefined behavior if the dynamic type differs from the
-// pointer type
+  b += 1;
+  // warning: pointer arithmetic on class that declares a virtual function can
+  // result in undefined behavior if the dynamic type differs from the
+  // pointer type
 
-delete[] static_cast(b);
+  delete[] static_cast(b);
+  }
+
+  // Another example showing array access with polymorphic objects.
+  int bar(const Derived d[]) {
+return d[1].i; // warning due to pointer arithmetic on polymorphic object
+  }
+
+  // Making Derived final suppresses the warning
+  struct FinalDerived final : public Base {};
+
+  int baz(const FinalDerived d[]) {
+return d[1].i; // no warning as FinalDerived is final
   }
 
 Options
@@ -50,14 +63,19 @@ Options
 void bar() {
   Base *b = new Base[10];
   b += 1; // warning, as Base declares a virtual destructor
-  
+
   delete[] b;
-  
+
   Derived *d = new Derived[10]; // Derived overrides the destructor, and
 // declares no other virtual functions
   d += 1; // warning only if IgnoreVirtualDeclarationsOnly is set to false
-  
+
   delete[] d;
+
+  FinalDerived *f = new FinalDerived[10];
+  f += 1; // no warning, FinalDerived is final and cannot be further 
derived
+
+  delete[] f;
 }
 
 References

>From c6832232a55d39bc98562537b9a357378a007227 Mon Sep 17 00:00:00 2001
From: Mainak Sil <145980094+mainak...@users.noreply.github.com>
Date: Thu, 12 Sep 2024 19:32:25 +0530
Subject: [PATCH 2/2] Update example to remove new/delete and focus on pointer
 arithmetic

---
 ...inter-arithmetic-on-polymorphic-object.rst | 28 ++-
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
index 4f926808f9e408..cff997d5ada2aa 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
@@ -19,21 +19,23 @@ Example:
 .. code-block:: c++
 
   struct Base {
-  virtual ~Base();
-  int i;
+virtual ~Base();
+int i;
   };
-
+  
   struct Derived : public Base {};
-
-  void foo() {
-  Base *b = new Derived[10];
-
-  b += 1;
-  // warning: pointer arithmetic on class that declares a virtual function can
-  // result in undefined behavior if the dynamic type differs from the
-  // pointer type
-
-  delete[] static_cast(b);
+  
+  // Function that takes a pointer and performs pointer arithmetic
+  void foo(Base* b) {
+b += 1;
+// warning: pointer arithmetic on class that declares a virtual function 
can
+// result in undefined behavior if the dynamic type differs from the
+// pointer type
+  }
+  
+  void bar() {
+Derived d[10];  // Array of derived objects
+foo(d); // Passing Derived pointer to foo(), which performs 
arithmetic
   }
 
   // Another example showing array access with polymorphic objects.

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improve documentation of bugprone-pointer-arithmetic-on-polymorphic-object (PR #108324)

2024-09-12 Thread Mainak Sil via cfe-commits

https://github.com/MainakSil updated 
https://github.com/llvm/llvm-project/pull/108324

>From edb6664fbdafb5127d141fde633779865a90dde1 Mon Sep 17 00:00:00 2001
From: Mainak Sil 
Date: Thu, 12 Sep 2024 08:58:15 +0530
Subject: [PATCH 1/3] Improve documentation for
 bugprone-pointer-arithmetic-on-polymorphic-object

---
 ...inter-arithmetic-on-polymorphic-object.rst | 38 ++-
 1 file changed, 28 insertions(+), 10 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
index 1884acd5f12b3e..4f926808f9e408 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
@@ -19,20 +19,33 @@ Example:
 .. code-block:: c++
 
   struct Base {
-virtual void ~Base();
+  virtual ~Base();
+  int i;
   };
 
   struct Derived : public Base {};
 
   void foo() {
-Base *b = new Derived[10];
+  Base *b = new Derived[10];
 
-b += 1;
-// warning: pointer arithmetic on class that declares a virtual function 
can
-// result in undefined behavior if the dynamic type differs from the
-// pointer type
+  b += 1;
+  // warning: pointer arithmetic on class that declares a virtual function can
+  // result in undefined behavior if the dynamic type differs from the
+  // pointer type
 
-delete[] static_cast(b);
+  delete[] static_cast(b);
+  }
+
+  // Another example showing array access with polymorphic objects.
+  int bar(const Derived d[]) {
+return d[1].i; // warning due to pointer arithmetic on polymorphic object
+  }
+
+  // Making Derived final suppresses the warning
+  struct FinalDerived final : public Base {};
+
+  int baz(const FinalDerived d[]) {
+return d[1].i; // no warning as FinalDerived is final
   }
 
 Options
@@ -50,14 +63,19 @@ Options
 void bar() {
   Base *b = new Base[10];
   b += 1; // warning, as Base declares a virtual destructor
-  
+
   delete[] b;
-  
+
   Derived *d = new Derived[10]; // Derived overrides the destructor, and
 // declares no other virtual functions
   d += 1; // warning only if IgnoreVirtualDeclarationsOnly is set to false
-  
+
   delete[] d;
+
+  FinalDerived *f = new FinalDerived[10];
+  f += 1; // no warning, FinalDerived is final and cannot be further 
derived
+
+  delete[] f;
 }
 
 References

>From c6832232a55d39bc98562537b9a357378a007227 Mon Sep 17 00:00:00 2001
From: Mainak Sil <145980094+mainak...@users.noreply.github.com>
Date: Thu, 12 Sep 2024 19:32:25 +0530
Subject: [PATCH 2/3] Update example to remove new/delete and focus on pointer
 arithmetic

---
 ...inter-arithmetic-on-polymorphic-object.rst | 28 ++-
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
index 4f926808f9e408..cff997d5ada2aa 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
@@ -19,21 +19,23 @@ Example:
 .. code-block:: c++
 
   struct Base {
-  virtual ~Base();
-  int i;
+virtual ~Base();
+int i;
   };
-
+  
   struct Derived : public Base {};
-
-  void foo() {
-  Base *b = new Derived[10];
-
-  b += 1;
-  // warning: pointer arithmetic on class that declares a virtual function can
-  // result in undefined behavior if the dynamic type differs from the
-  // pointer type
-
-  delete[] static_cast(b);
+  
+  // Function that takes a pointer and performs pointer arithmetic
+  void foo(Base* b) {
+b += 1;
+// warning: pointer arithmetic on class that declares a virtual function 
can
+// result in undefined behavior if the dynamic type differs from the
+// pointer type
+  }
+  
+  void bar() {
+Derived d[10];  // Array of derived objects
+foo(d); // Passing Derived pointer to foo(), which performs 
arithmetic
   }
 
   // Another example showing array access with polymorphic objects.

>From 96fa8165375bf7a5c249c1e7c43a49ce67fd183e Mon Sep 17 00:00:00 2001
From: Mainak Sil <145980094+mainak...@users.noreply.github.com>
Date: Thu, 12 Sep 2024 22:58:11 +0530
Subject: [PATCH 3/3] Address maintainer feedback: remove redundant comments,
 new/delete, and final example

---
 ...inter-arithmetic-on-polymorphic-object.rst | 27 +--
 1 file changed, 1 insertion(+), 26 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmet

[clang-tools-extra] [clang-tidy] Improve documentation of bugprone-pointer-arithmetic-on-polymorphic-object (PR #108324)

2024-09-12 Thread Mainak Sil via cfe-commits

MainakSil wrote:

I have addressed the feedback:
1. Removed unnecessary whitespace.
2. Removed redundant comments and the `FinalDerived` example.
3. Replaced `new/delete` with direct array passing.

Please let me know if further changes are needed.

https://github.com/llvm/llvm-project/pull/108324
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improve documentation of bugprone-pointer-arithmetic-on-polymorphic-object (PR #108324)

2024-09-12 Thread Mainak Sil via cfe-commits


@@ -19,20 +19,23 @@ Example:
 .. code-block:: c++
 
   struct Base {
-virtual void ~Base();
+virtual ~Base();
+int i;
   };
-

MainakSil wrote:

Do you mean like this?

![image](https://github.com/user-attachments/assets/9ea57dc0-0820-4147-bf08-ec3bb96f704a)


https://github.com/llvm/llvm-project/pull/108324
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improve documentation of bugprone-pointer-arithmetic-on-polymorphic-object (PR #108324)

2024-09-12 Thread Mainak Sil via cfe-commits


@@ -19,20 +19,23 @@ Example:
 .. code-block:: c++
 
   struct Base {
-virtual void ~Base();
+virtual ~Base();
+int i;
   };
-

MainakSil wrote:

So should I make any changes?

https://github.com/llvm/llvm-project/pull/108324
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improve documentation of bugprone-pointer-arithmetic-on-polymorphic-object (PR #108324)

2024-09-12 Thread Mainak Sil via cfe-commits

https://github.com/MainakSil updated 
https://github.com/llvm/llvm-project/pull/108324

>From edb6664fbdafb5127d141fde633779865a90dde1 Mon Sep 17 00:00:00 2001
From: Mainak Sil 
Date: Thu, 12 Sep 2024 08:58:15 +0530
Subject: [PATCH 1/4] Improve documentation for
 bugprone-pointer-arithmetic-on-polymorphic-object

---
 ...inter-arithmetic-on-polymorphic-object.rst | 38 ++-
 1 file changed, 28 insertions(+), 10 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
index 1884acd5f12b3e..4f926808f9e408 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
@@ -19,20 +19,33 @@ Example:
 .. code-block:: c++
 
   struct Base {
-virtual void ~Base();
+  virtual ~Base();
+  int i;
   };
 
   struct Derived : public Base {};
 
   void foo() {
-Base *b = new Derived[10];
+  Base *b = new Derived[10];
 
-b += 1;
-// warning: pointer arithmetic on class that declares a virtual function 
can
-// result in undefined behavior if the dynamic type differs from the
-// pointer type
+  b += 1;
+  // warning: pointer arithmetic on class that declares a virtual function can
+  // result in undefined behavior if the dynamic type differs from the
+  // pointer type
 
-delete[] static_cast(b);
+  delete[] static_cast(b);
+  }
+
+  // Another example showing array access with polymorphic objects.
+  int bar(const Derived d[]) {
+return d[1].i; // warning due to pointer arithmetic on polymorphic object
+  }
+
+  // Making Derived final suppresses the warning
+  struct FinalDerived final : public Base {};
+
+  int baz(const FinalDerived d[]) {
+return d[1].i; // no warning as FinalDerived is final
   }
 
 Options
@@ -50,14 +63,19 @@ Options
 void bar() {
   Base *b = new Base[10];
   b += 1; // warning, as Base declares a virtual destructor
-  
+
   delete[] b;
-  
+
   Derived *d = new Derived[10]; // Derived overrides the destructor, and
 // declares no other virtual functions
   d += 1; // warning only if IgnoreVirtualDeclarationsOnly is set to false
-  
+
   delete[] d;
+
+  FinalDerived *f = new FinalDerived[10];
+  f += 1; // no warning, FinalDerived is final and cannot be further 
derived
+
+  delete[] f;
 }
 
 References

>From c6832232a55d39bc98562537b9a357378a007227 Mon Sep 17 00:00:00 2001
From: Mainak Sil <145980094+mainak...@users.noreply.github.com>
Date: Thu, 12 Sep 2024 19:32:25 +0530
Subject: [PATCH 2/4] Update example to remove new/delete and focus on pointer
 arithmetic

---
 ...inter-arithmetic-on-polymorphic-object.rst | 28 ++-
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
index 4f926808f9e408..cff997d5ada2aa 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
@@ -19,21 +19,23 @@ Example:
 .. code-block:: c++
 
   struct Base {
-  virtual ~Base();
-  int i;
+virtual ~Base();
+int i;
   };
-
+  
   struct Derived : public Base {};
-
-  void foo() {
-  Base *b = new Derived[10];
-
-  b += 1;
-  // warning: pointer arithmetic on class that declares a virtual function can
-  // result in undefined behavior if the dynamic type differs from the
-  // pointer type
-
-  delete[] static_cast(b);
+  
+  // Function that takes a pointer and performs pointer arithmetic
+  void foo(Base* b) {
+b += 1;
+// warning: pointer arithmetic on class that declares a virtual function 
can
+// result in undefined behavior if the dynamic type differs from the
+// pointer type
+  }
+  
+  void bar() {
+Derived d[10];  // Array of derived objects
+foo(d); // Passing Derived pointer to foo(), which performs 
arithmetic
   }
 
   // Another example showing array access with polymorphic objects.

>From 96fa8165375bf7a5c249c1e7c43a49ce67fd183e Mon Sep 17 00:00:00 2001
From: Mainak Sil <145980094+mainak...@users.noreply.github.com>
Date: Thu, 12 Sep 2024 22:58:11 +0530
Subject: [PATCH 3/4] Address maintainer feedback: remove redundant comments,
 new/delete, and final example

---
 ...inter-arithmetic-on-polymorphic-object.rst | 27 +--
 1 file changed, 1 insertion(+), 26 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmet

[clang-tools-extra] [clang-tidy] Improve documentation of bugprone-pointer-arithmetic-on-polymorphic-object (PR #108324)

2024-09-12 Thread Mainak Sil via cfe-commits


@@ -19,20 +19,23 @@ Example:
 .. code-block:: c++
 
   struct Base {
-virtual void ~Base();
+virtual ~Base();
+int i;
   };
-

MainakSil wrote:

Check it please.

https://github.com/llvm/llvm-project/pull/108324
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improve documentation of bugprone-pointer-arithmetic-on-polymorphic-object (PR #108324)

2024-09-12 Thread Mainak Sil via cfe-commits

MainakSil wrote:

If it looks good to you, please do merge it.

https://github.com/llvm/llvm-project/pull/108324
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improve documentation of bugprone-pointer-arithmetic-on-polymorphic-object (PR #108324)

2024-09-12 Thread Mainak Sil via cfe-commits

MainakSil wrote:

Unchecked the private email box.

https://github.com/llvm/llvm-project/pull/108324
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Increase VecLib bitfield size to 4 bits in CodeGenOptions.def #3 (PR #108804)

2024-09-16 Thread Mainak Sil via cfe-commits

https://github.com/MainakSil created 
https://github.com/llvm/llvm-project/pull/108804

Summary:
This PR fixes the issue where the VecLib bitfield in CodeGenOptions.def is too 
small to accommodate the increasing number of vector libraries. Specifically, 
the bitfield size was previously set to 3, but with the introduction of more 
vector libraries (currently 9), the bitfield needed to be expanded to avoid 
potential issues in vectorization.

In this PR, I have increased the size of the VecLib bitfield from 3 to 4 to 
account for the additional libraries. This ensures that all 9 vector libraries 
are correctly encoded and available for use without errors.

Changes Made:
Modified: Increased the VecLib bitfield size from 3 to 4 in 
clang/include/clang/Basic/CodeGenOptions.def.

Motivation:
This change is necessary to ensure that all vector libraries are properly 
represented and selectable. The current limitation of the VecLib bitfield size 
was causing some vectorization opportunities to be lost when more than 3 bits 
were needed to represent the library options.

Closes:
Fixes https://github.com/llvm/llvm-project/issues/108704

>From 43e6c22f25f419b64678374dd247eaf8bc28fa57 Mon Sep 17 00:00:00 2001
From: Mainak Sil 
Date: Mon, 16 Sep 2024 09:50:33 +0530
Subject: [PATCH 1/3] [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 
Date: Mon, 16 Sep 2024 14:18:03 +0530
Subject: [PATCH 2/3] 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(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 
Date: Mon, 16 Sep 2024 14:32:26 +0530
Subject: [PATCH 3/3] Update CodeGenOptions.def


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [docs][clang-tidy] Correct StrictMode example in modernize-use-std-print (PR #108805)

2024-09-16 Thread Mainak Sil via cfe-commits

https://github.com/MainakSil created 
https://github.com/llvm/llvm-project/pull/108805

Updated the example in the `StrictMode` section of the clang-tidy check 
`modernize-use-std-print`.

The previous example incorrectly swapped the cast of signed and unsigned 
integers. Specifically:
- The signed integer `i` was being cast to `unsigned int`, and
- The unsigned integer `u` was being cast to `int`.

This correction ensures that the behavior of `std::print` with `StrictMode` 
enabled matches that of `printf`, by reversing the casts to maintain the 
correct signedness. 

Issue Refference
It solves #101397

>From 20b262e9954ec1505b1be4ea3cc362b2a9955bb9 Mon Sep 17 00:00:00 2001
From: Mainak Sil 
Date: Sun, 15 Sep 2024 22:03:43 +0530
Subject: [PATCH 1/2] [docs][clang-tidy] Correct StrictMode example in
 modernize-use-std-print

---
 .../docs/clang-tidy/checks/modernize/use-std-print.rst  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
index 59bb722e2c24fc..a825cd7432a57d 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
@@ -109,7 +109,7 @@ Options
 
   .. code-block:: c++
 
-std::print("{} {}\n", static_cast(i), static_cast(u));
+std::print("{} {}\n", static_cast(u), static_cast(i));
 
   to ensure that the output will continue to be the unsigned representation
   of `-42` and the signed representation of `0x` (often

>From e64700266ecc08b23f88415036c45177a03c40c2 Mon Sep 17 00:00:00 2001
From: Mainak Sil 
Date: Mon, 16 Sep 2024 14:41:49 +0530
Subject: [PATCH 2/2] [docs][clang-tidy] Correct StrictMode example in
 modernize-use-std-print

Updated the example in the StrictMode section of the clang-tidy check 
modernize-use-std-print.

The previous example incorrectly swapped the cast of signed and unsigned 
integers. Specifically:

The signed integer i was being cast to unsigned int, and
The unsigned integer u was being cast to int.
This correction ensures that the behavior of std::print with StrictMode enabled 
matches that of printf, by reversing the casts to maintain the correct 
signedness.

Issue Refference
It solves #llvm#101397

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Increase VecLib bitfield size to 4 bits in CodeGenOptions.def (PR #108804)

2024-09-16 Thread Mainak Sil via cfe-commits

https://github.com/MainakSil edited 
https://github.com/llvm/llvm-project/pull/108804
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [docs][clang-tidy] Correct StrictMode example in modernize-use-std-print (PR #108805)

2024-09-16 Thread Mainak Sil via cfe-commits

https://github.com/MainakSil updated 
https://github.com/llvm/llvm-project/pull/108805

>From 20b262e9954ec1505b1be4ea3cc362b2a9955bb9 Mon Sep 17 00:00:00 2001
From: Mainak Sil 
Date: Sun, 15 Sep 2024 22:03:43 +0530
Subject: [PATCH 1/3] [docs][clang-tidy] Correct StrictMode example in
 modernize-use-std-print

---
 .../docs/clang-tidy/checks/modernize/use-std-print.rst  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
index 59bb722e2c24fc..a825cd7432a57d 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
@@ -109,7 +109,7 @@ Options
 
   .. code-block:: c++
 
-std::print("{} {}\n", static_cast(i), static_cast(u));
+std::print("{} {}\n", static_cast(u), static_cast(i));
 
   to ensure that the output will continue to be the unsigned representation
   of `-42` and the signed representation of `0x` (often

>From e64700266ecc08b23f88415036c45177a03c40c2 Mon Sep 17 00:00:00 2001
From: Mainak Sil 
Date: Mon, 16 Sep 2024 14:41:49 +0530
Subject: [PATCH 2/3] [docs][clang-tidy] Correct StrictMode example in
 modernize-use-std-print

Updated the example in the StrictMode section of the clang-tidy check 
modernize-use-std-print.

The previous example incorrectly swapped the cast of signed and unsigned 
integers. Specifically:

The signed integer i was being cast to unsigned int, and
The unsigned integer u was being cast to int.
This correction ensures that the behavior of std::print with StrictMode enabled 
matches that of printf, by reversing the casts to maintain the correct 
signedness.

Issue Refference
It solves #llvm#101397

>From 000fa0b26c087c17b23da57d02422816c00bcbd1 Mon Sep 17 00:00:00 2001
From: Mainak Sil 
Date: Mon, 16 Sep 2024 22:31:55 +0530
Subject: [PATCH 3/3] Update use-std-print.rst

---
 .../docs/clang-tidy/checks/modernize/use-std-print.rst| 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
index a825cd7432a57d..e70402ad8b3341 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
@@ -103,13 +103,13 @@ Options
 
 int i = -42;
 unsigned int u = 0x;
-printf("%d %u\n", i, u);
+printf("%u %d\n", i, u);
 
   would be converted to:
 
   .. code-block:: c++
 
-std::print("{} {}\n", static_cast(u), static_cast(i));
+std::print("{} {}\n", static_cast(i), static_cast(u));
 
   to ensure that the output will continue to be the unsigned representation
   of `-42` and the signed representation of `0x` (often

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [docs][clang-tidy] Correct StrictMode example in modernize-use-std-print (PR #108805)

2024-09-16 Thread Mainak Sil via cfe-commits

MainakSil wrote:

Please check now.

https://github.com/llvm/llvm-project/pull/108805
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [docs][clang-tidy] Correct StrictMode example in modernize-use-std-print (PR #108805)

2024-09-16 Thread Mainak Sil via cfe-commits

https://github.com/MainakSil updated 
https://github.com/llvm/llvm-project/pull/108805

>From 20b262e9954ec1505b1be4ea3cc362b2a9955bb9 Mon Sep 17 00:00:00 2001
From: Mainak Sil 
Date: Sun, 15 Sep 2024 22:03:43 +0530
Subject: [PATCH 1/4] [docs][clang-tidy] Correct StrictMode example in
 modernize-use-std-print

---
 .../docs/clang-tidy/checks/modernize/use-std-print.rst  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
index 59bb722e2c24fc..a825cd7432a57d 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
@@ -109,7 +109,7 @@ Options
 
   .. code-block:: c++
 
-std::print("{} {}\n", static_cast(i), static_cast(u));
+std::print("{} {}\n", static_cast(u), static_cast(i));
 
   to ensure that the output will continue to be the unsigned representation
   of `-42` and the signed representation of `0x` (often

>From e64700266ecc08b23f88415036c45177a03c40c2 Mon Sep 17 00:00:00 2001
From: Mainak Sil 
Date: Mon, 16 Sep 2024 14:41:49 +0530
Subject: [PATCH 2/4] [docs][clang-tidy] Correct StrictMode example in
 modernize-use-std-print

Updated the example in the StrictMode section of the clang-tidy check 
modernize-use-std-print.

The previous example incorrectly swapped the cast of signed and unsigned 
integers. Specifically:

The signed integer i was being cast to unsigned int, and
The unsigned integer u was being cast to int.
This correction ensures that the behavior of std::print with StrictMode enabled 
matches that of printf, by reversing the casts to maintain the correct 
signedness.

Issue Refference
It solves #llvm#101397

>From 000fa0b26c087c17b23da57d02422816c00bcbd1 Mon Sep 17 00:00:00 2001
From: Mainak Sil 
Date: Mon, 16 Sep 2024 22:31:55 +0530
Subject: [PATCH 3/4] Update use-std-print.rst

---
 .../docs/clang-tidy/checks/modernize/use-std-print.rst| 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
index a825cd7432a57d..e70402ad8b3341 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
@@ -103,13 +103,13 @@ Options
 
 int i = -42;
 unsigned int u = 0x;
-printf("%d %u\n", i, u);
+printf("%u %d\n", i, u);
 
   would be converted to:
 
   .. code-block:: c++
 
-std::print("{} {}\n", static_cast(u), static_cast(i));
+std::print("{} {}\n", static_cast(i), static_cast(u));
 
   to ensure that the output will continue to be the unsigned representation
   of `-42` and the signed representation of `0x` (often

>From b40f7a9fe5964c9436e1bfd28b2dbe91cbcc65ae Mon Sep 17 00:00:00 2001
From: Mainak Sil 
Date: Tue, 17 Sep 2024 08:07:23 +0530
Subject: [PATCH 4/4] Update printf specifiers in StrictMode example

---
 .../docs/clang-tidy/checks/modernize/use-std-format.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-format.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-format.rst
index 1ec753ef090de1..b88fde5162e28c 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-format.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-format.rst
@@ -43,7 +43,7 @@ Options
 extern std::string strprintf(const char *format, ...);
 int i = -42;
 unsigned int u = 0x;
-return strprintf("%d %u\n", i, u);
+return strprintf("%u %d\n", i, u);
 
   would be converted to
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [docs][clang-tidy] Correct StrictMode example in modernize-use-std-print (PR #108805)

2024-09-16 Thread Mainak Sil via cfe-commits

MainakSil wrote:

Thanks for pointing that out, @mikecrowe! I've gone ahead and fixed the same 
mistake in `use-std-format.rst` as well in this PR.


https://github.com/llvm/llvm-project/pull/108805
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Increase VecLib bitfield size to 4 bits in CodeGenOptions.def (PR #108804)

2024-09-18 Thread Mainak Sil via cfe-commits

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 
Date: Mon, 16 Sep 2024 09:50:33 +0530
Subject: [PATCH 01/12] [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 
Date: Mon, 16 Sep 2024 14:18:03 +0530
Subject: [PATCH 02/12] 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(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 
Date: Mon, 16 Sep 2024 14:32:26 +0530
Subject: [PATCH 03/12] Update CodeGenOptions.def


>From 558038b29eedb81e9ce328f323914329af0d8f0f Mon Sep 17 00:00:00 2001
From: Mainak Sil 
Date: Wed, 18 Sep 2024 08:57:16 +0530
Subject: [PATCH 04/12] 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(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(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 
Date: Wed, 18 Sep 2024 09:01:08 +0530
Subject: [PATCH 05/12] Create AllLibrariesFit.cpp

---
 clang/unittests/CodeGen/AllLibrariesFit.cpp | 9 +
 1 file changed, 9 insertions(+)
 create mode 100644 clang/unittests/CodeGen/AllLibrariesFit.

[clang] [clang] Increase VecLib bitfield size to 4 bits in CodeGenOptions.def (PR #108804)

2024-09-18 Thread Mainak Sil via cfe-commits

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 
Date: Mon, 16 Sep 2024 09:50:33 +0530
Subject: [PATCH 1/9] [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 
Date: Mon, 16 Sep 2024 14:18:03 +0530
Subject: [PATCH 2/9] 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(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 
Date: Mon, 16 Sep 2024 14:32:26 +0530
Subject: [PATCH 3/9] Update CodeGenOptions.def


>From 558038b29eedb81e9ce328f323914329af0d8f0f Mon Sep 17 00:00:00 2001
From: Mainak Sil 
Date: Wed, 18 Sep 2024 08:57:16 +0530
Subject: [PATCH 4/9] 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(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(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 
Date: Wed, 18 Sep 2024 09:01:08 +0530
Subject: [PATCH 5/9] Create AllLibrariesFit.cpp

---
 clang/unittests/CodeGen/AllLibrariesFit.cpp | 9 +
 1 file changed, 9 insertions(+)
 create mode 100644 clang/unittests/CodeGen/AllLibrariesFit.cpp

diff 

[clang] [clang] Increase VecLib bitfield size to 4 bits in CodeGenOptions.def (PR #108804)

2024-09-18 Thread Mainak Sil via cfe-commits

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 
Date: Mon, 16 Sep 2024 09:50:33 +0530
Subject: [PATCH 1/8] [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 
Date: Mon, 16 Sep 2024 14:18:03 +0530
Subject: [PATCH 2/8] 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(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 
Date: Mon, 16 Sep 2024 14:32:26 +0530
Subject: [PATCH 3/8] Update CodeGenOptions.def


>From 558038b29eedb81e9ce328f323914329af0d8f0f Mon Sep 17 00:00:00 2001
From: Mainak Sil 
Date: Wed, 18 Sep 2024 08:57:16 +0530
Subject: [PATCH 4/8] 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(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(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 
Date: Wed, 18 Sep 2024 09:01:08 +0530
Subject: [PATCH 5/8] Create AllLibrariesFit.cpp

---
 clang/unittests/CodeGen/AllLibrariesFit.cpp | 9 +
 1 file changed, 9 insertions(+)
 create mode 100644 clang/unittests/CodeGen/AllLibrariesFit.cpp

diff 

[clang] [clang] Increase VecLib bitfield size to 4 bits in CodeGenOptions.def (PR #108804)

2024-09-18 Thread Mainak Sil via cfe-commits

MainakSil wrote:

If it looks good to you guys, please merge it.

https://github.com/llvm/llvm-project/pull/108804
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Increase VecLib bitfield size to 4 bits in CodeGenOptions.def (PR #108804)

2024-09-18 Thread Mainak Sil via cfe-commits

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 
Date: Mon, 16 Sep 2024 09:50:33 +0530
Subject: [PATCH 01/13] [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 
Date: Mon, 16 Sep 2024 14:18:03 +0530
Subject: [PATCH 02/13] 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(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 
Date: Mon, 16 Sep 2024 14:32:26 +0530
Subject: [PATCH 03/13] Update CodeGenOptions.def


>From 558038b29eedb81e9ce328f323914329af0d8f0f Mon Sep 17 00:00:00 2001
From: Mainak Sil 
Date: Wed, 18 Sep 2024 08:57:16 +0530
Subject: [PATCH 04/13] 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(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(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 
Date: Wed, 18 Sep 2024 09:01:08 +0530
Subject: [PATCH 05/13] Create AllLibrariesFit.cpp

---
 clang/unittests/CodeGen/AllLibrariesFit.cpp | 9 +
 1 file changed, 9 insertions(+)
 create mode 100644 clang/unittests/CodeGen/AllLibrariesFit.

[clang] [clang] Increase VecLib bitfield size to 4 bits in CodeGenOptions.def (PR #108804)

2024-09-18 Thread Mainak Sil via cfe-commits

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 
Date: Mon, 16 Sep 2024 09:50:33 +0530
Subject: [PATCH 01/11] [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 
Date: Mon, 16 Sep 2024 14:18:03 +0530
Subject: [PATCH 02/11] 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(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 
Date: Mon, 16 Sep 2024 14:32:26 +0530
Subject: [PATCH 03/11] Update CodeGenOptions.def


>From 558038b29eedb81e9ce328f323914329af0d8f0f Mon Sep 17 00:00:00 2001
From: Mainak Sil 
Date: Wed, 18 Sep 2024 08:57:16 +0530
Subject: [PATCH 04/11] 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(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(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 
Date: Wed, 18 Sep 2024 09:01:08 +0530
Subject: [PATCH 05/11] Create AllLibrariesFit.cpp

---
 clang/unittests/CodeGen/AllLibrariesFit.cpp | 9 +
 1 file changed, 9 insertions(+)
 create mode 100644 clang/unittests/CodeGen/AllLibrariesFit.

[clang] [clang] Increase VecLib bitfield size to 4 bits in CodeGenOptions.def (PR #108804)

2024-09-18 Thread Mainak Sil via cfe-commits

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 
Date: Mon, 16 Sep 2024 09:50:33 +0530
Subject: [PATCH 01/10] [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 
Date: Mon, 16 Sep 2024 14:18:03 +0530
Subject: [PATCH 02/10] 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(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 
Date: Mon, 16 Sep 2024 14:32:26 +0530
Subject: [PATCH 03/10] Update CodeGenOptions.def


>From 558038b29eedb81e9ce328f323914329af0d8f0f Mon Sep 17 00:00:00 2001
From: Mainak Sil 
Date: Wed, 18 Sep 2024 08:57:16 +0530
Subject: [PATCH 04/10] 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(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(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 
Date: Wed, 18 Sep 2024 09:01:08 +0530
Subject: [PATCH 05/10] Create AllLibrariesFit.cpp

---
 clang/unittests/CodeGen/AllLibrariesFit.cpp | 9 +
 1 file changed, 9 insertions(+)
 create mode 100644 clang/unittests/CodeGen/AllLibrariesFit.

[clang-tools-extra] [docs][clang-tidy] Correct StrictMode example in modernize-use-std-print (PR #108805)

2024-09-17 Thread Mainak Sil via cfe-commits

MainakSil wrote:

Please merge it if it looks good to you guys...

https://github.com/llvm/llvm-project/pull/108805
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Increase VecLib bitfield size to 4 bits in CodeGenOptions.def (PR #108804)

2024-09-17 Thread Mainak Sil via cfe-commits

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 
Date: Mon, 16 Sep 2024 09:50:33 +0530
Subject: [PATCH 1/4] [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 
Date: Mon, 16 Sep 2024 14:18:03 +0530
Subject: [PATCH 2/4] 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(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 
Date: Mon, 16 Sep 2024 14:32:26 +0530
Subject: [PATCH 3/4] Update CodeGenOptions.def


>From 558038b29eedb81e9ce328f323914329af0d8f0f Mon Sep 17 00:00:00 2001
From: Mainak Sil 
Date: Wed, 18 Sep 2024 08:57:16 +0530
Subject: [PATCH 4/4] 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(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(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)

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Increase VecLib bitfield size to 4 bits in CodeGenOptions.def (PR #108804)

2024-09-17 Thread Mainak Sil via cfe-commits

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 
Date: Mon, 16 Sep 2024 09:50:33 +0530
Subject: [PATCH 1/5] [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 
Date: Mon, 16 Sep 2024 14:18:03 +0530
Subject: [PATCH 2/5] 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(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 
Date: Mon, 16 Sep 2024 14:32:26 +0530
Subject: [PATCH 3/5] Update CodeGenOptions.def


>From 558038b29eedb81e9ce328f323914329af0d8f0f Mon Sep 17 00:00:00 2001
From: Mainak Sil 
Date: Wed, 18 Sep 2024 08:57:16 +0530
Subject: [PATCH 4/5] 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(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(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 
Date: Wed, 18 Sep 2024 09:01:08 +0530
Subject: [PATCH 5/5] Create AllLibrariesFit.cpp

---
 clang/unittests/CodeGen/AllLibrariesFit.cpp | 9 +
 1 file changed, 9 insertions(+)
 create mode 100644 clang/unittests/CodeGen/AllLibrariesFit.cpp

diff 

[clang] [clang] Increase VecLib bitfield size to 4 bits in CodeGenOptions.def (PR #108804)

2024-09-17 Thread Mainak Sil via cfe-commits

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 
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 
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(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 
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 
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(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(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 
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 

[clang] [clang] Increase VecLib bitfield size to 4 bits in CodeGenOptions.def (PR #108804)

2024-09-17 Thread Mainak Sil via cfe-commits

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 
Date: Mon, 16 Sep 2024 09:50:33 +0530
Subject: [PATCH 1/7] [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 
Date: Mon, 16 Sep 2024 14:18:03 +0530
Subject: [PATCH 2/7] 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(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 
Date: Mon, 16 Sep 2024 14:32:26 +0530
Subject: [PATCH 3/7] Update CodeGenOptions.def


>From 558038b29eedb81e9ce328f323914329af0d8f0f Mon Sep 17 00:00:00 2001
From: Mainak Sil 
Date: Wed, 18 Sep 2024 08:57:16 +0530
Subject: [PATCH 4/7] 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(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(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 
Date: Wed, 18 Sep 2024 09:01:08 +0530
Subject: [PATCH 5/7] Create AllLibrariesFit.cpp

---
 clang/unittests/CodeGen/AllLibrariesFit.cpp | 9 +
 1 file changed, 9 insertions(+)
 create mode 100644 clang/unittests/CodeGen/AllLibrariesFit.cpp

diff 

[clang] [clang] Increase VecLib bitfield size to 4 bits in CodeGenOptions.def (PR #108804)

2024-09-17 Thread Mainak Sil via cfe-commits

MainakSil wrote:

Check Please

https://github.com/llvm/llvm-project/pull/108804
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits