[clang] [CLANG-CL] ignores wpadded (PR #130182)

2025-03-07 Thread Theo de Magalhaes via cfe-commits

https://github.com/therealcoochieman updated 
https://github.com/llvm/llvm-project/pull/130182

>From 3a9bc908a791669c82f288ff745664411bf285ac Mon Sep 17 00:00:00 2001
From: Theo de Magalhaes 
Date: Thu, 6 Mar 2025 22:26:37 +0100
Subject: [PATCH 1/3] chore(clang-format): formatted
 clang/lib/AST/RecordLayoutBuilder.cpp

---
 clang/lib/AST/RecordLayoutBuilder.cpp | 199 --
 1 file changed, 94 insertions(+), 105 deletions(-)

diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index b8600e6a344a4..695771f67868d 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -43,7 +43,7 @@ struct BaseSubobjectInfo {
   bool IsVirtual;
 
   /// Bases - Information about the base subobjects.
-  SmallVector Bases;
+  SmallVector Bases;
 
   /// PrimaryVirtualBaseInfo - Holds the base info for the primary virtual base
   /// of this base info (if one exists).
@@ -77,8 +77,7 @@ struct ExternalLayout {
   /// Get the offset of the given field. The external source must provide
   /// entries for all fields in the record.
   uint64_t getExternalFieldOffset(const FieldDecl *FD) {
-assert(FieldOffsets.count(FD) &&
-   "Field does not have an external offset");
+assert(FieldOffsets.count(FD) && "Field does not have an external offset");
 return FieldOffsets[FD];
   }
 
@@ -167,16 +166,15 @@ class EmptySubobjectMap {
   CharUnits SizeOfLargestEmptySubobject;
 
   EmptySubobjectMap(const ASTContext &Context, const CXXRecordDecl *Class)
-  : Context(Context), CharWidth(Context.getCharWidth()), Class(Class) {
-  ComputeEmptySubobjectSizes();
+  : Context(Context), CharWidth(Context.getCharWidth()), Class(Class) {
+ComputeEmptySubobjectSizes();
   }
 
   /// CanPlaceBaseAtOffset - Return whether the given base class can be placed
   /// at the given offset.
   /// Returns false if placing the record will result in two components
   /// (direct or indirect) of the same type having the same offset.
-  bool CanPlaceBaseAtOffset(const BaseSubobjectInfo *Info,
-CharUnits Offset);
+  bool CanPlaceBaseAtOffset(const BaseSubobjectInfo *Info, CharUnits Offset);
 
   /// CanPlaceFieldAtOffset - Return whether a field can be placed at the given
   /// offset.
@@ -227,9 +225,8 @@ void EmptySubobjectMap::ComputeEmptySubobjectSizes() {
   }
 }
 
-bool
-EmptySubobjectMap::CanPlaceSubobjectAtOffset(const CXXRecordDecl *RD,
- CharUnits Offset) const {
+bool EmptySubobjectMap::CanPlaceSubobjectAtOffset(const CXXRecordDecl *RD,
+  CharUnits Offset) const {
   // We only need to check empty bases.
   if (!RD->isEmpty())
 return true;
@@ -265,9 +262,8 @@ void EmptySubobjectMap::AddSubobjectAtOffset(const 
CXXRecordDecl *RD,
 MaxEmptyClassOffset = Offset;
 }
 
-bool
-EmptySubobjectMap::CanPlaceBaseSubobjectAtOffset(const BaseSubobjectInfo *Info,
- CharUnits Offset) {
+bool EmptySubobjectMap::CanPlaceBaseSubobjectAtOffset(
+const BaseSubobjectInfo *Info, CharUnits Offset) {
   // We don't have to keep looking past the maximum offset that's known to
   // contain an empty class.
   if (!AnyEmptySubobjectsBeyondOffset(Offset))
@@ -368,10 +364,9 @@ bool EmptySubobjectMap::CanPlaceBaseAtOffset(const 
BaseSubobjectInfo *Info,
   return true;
 }
 
-bool
-EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const CXXRecordDecl *RD,
-  const CXXRecordDecl *Class,
-  CharUnits Offset) const {
+bool EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(
+const CXXRecordDecl *RD, const CXXRecordDecl *Class,
+CharUnits Offset) const {
   // We don't have to keep looking past the maximum offset that's known to
   // contain an empty class.
   if (!AnyEmptySubobjectsBeyondOffset(Offset))
@@ -418,9 +413,8 @@ EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const 
CXXRecordDecl *RD,
   return true;
 }
 
-bool
-EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const FieldDecl *FD,
-  CharUnits Offset) const {
+bool EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const FieldDecl *FD,
+   CharUnits Offset) const 
{
   // We don't have to keep looking past the maximum offset that's known to
   // contain an empty class.
   if (!AnyEmptySubobjectsBeyondOffset(Offset))
@@ -560,7 +554,7 @@ void EmptySubobjectMap::UpdateEmptyFieldSubobjects(
   }
 }
 
-typedef llvm::SmallPtrSet ClassSetTy;
+typedef llvm::SmallPtrSet ClassSetTy;
 
 class ItaniumRecordLayoutBuilder {
 protected:
@@ -712,15 +706,13 @@ class ItaniumRecordLayoutBuilder {
   bool FieldPacked, const FieldDecl *D);
   void LayoutBitField(const FieldDecl *D);
 
-  TargetCXXABI getCXXABI() 

[clang] [CLANG-CL] ignores wpadded (PR #130182)

2025-03-07 Thread Theo de Magalhaes via cfe-commits

therealcoochieman wrote:

> Please make sure to keep the formatting of the file as it was (you can format 
> the changes _you_ made to the file with `git clang-format`.
> 
> 
> 
> Thanks!

Hello, I misread the guidelines and thought I had to make a first clang-format 
commit before editing the file. I reverted the commit.
Thank you for the reactive heads up!

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


[clang] [CLANG-CL] ignores wpadded (PR #130182)

2025-03-06 Thread Theo de Magalhaes via cfe-commits

https://github.com/therealcoochieman created 
https://github.com/llvm/llvm-project/pull/130182

Aims to fix #61702.

I encountered an interesting behavior during my testing. It seems the Itanium 
Record Layout Builder can give out Wpadded-bitfield warnings with the wrong 
amount of padding when mimicking the Microsoft struct layout.

For the following struct:
```cpp
struct __attribute__((ms_struct)) Foo {
  long long x;
  char y : 1;
  long long yy : 1;
};
```

My understanding is we would expect `yy` to be padded by 63 bits, but the 
warning says there are 7 bytes of padding.
Which one is correct? I am not sure this question is within the scope of this 
PR but I am still shooting my shot here. I can always create an issue if needed.

>From 3a9bc908a791669c82f288ff745664411bf285ac Mon Sep 17 00:00:00 2001
From: Theo de Magalhaes 
Date: Thu, 6 Mar 2025 22:26:37 +0100
Subject: [PATCH 1/2] chore(clang-format): formatted
 clang/lib/AST/RecordLayoutBuilder.cpp

---
 clang/lib/AST/RecordLayoutBuilder.cpp | 199 --
 1 file changed, 94 insertions(+), 105 deletions(-)

diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index b8600e6a344a4..695771f67868d 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -43,7 +43,7 @@ struct BaseSubobjectInfo {
   bool IsVirtual;
 
   /// Bases - Information about the base subobjects.
-  SmallVector Bases;
+  SmallVector Bases;
 
   /// PrimaryVirtualBaseInfo - Holds the base info for the primary virtual base
   /// of this base info (if one exists).
@@ -77,8 +77,7 @@ struct ExternalLayout {
   /// Get the offset of the given field. The external source must provide
   /// entries for all fields in the record.
   uint64_t getExternalFieldOffset(const FieldDecl *FD) {
-assert(FieldOffsets.count(FD) &&
-   "Field does not have an external offset");
+assert(FieldOffsets.count(FD) && "Field does not have an external offset");
 return FieldOffsets[FD];
   }
 
@@ -167,16 +166,15 @@ class EmptySubobjectMap {
   CharUnits SizeOfLargestEmptySubobject;
 
   EmptySubobjectMap(const ASTContext &Context, const CXXRecordDecl *Class)
-  : Context(Context), CharWidth(Context.getCharWidth()), Class(Class) {
-  ComputeEmptySubobjectSizes();
+  : Context(Context), CharWidth(Context.getCharWidth()), Class(Class) {
+ComputeEmptySubobjectSizes();
   }
 
   /// CanPlaceBaseAtOffset - Return whether the given base class can be placed
   /// at the given offset.
   /// Returns false if placing the record will result in two components
   /// (direct or indirect) of the same type having the same offset.
-  bool CanPlaceBaseAtOffset(const BaseSubobjectInfo *Info,
-CharUnits Offset);
+  bool CanPlaceBaseAtOffset(const BaseSubobjectInfo *Info, CharUnits Offset);
 
   /// CanPlaceFieldAtOffset - Return whether a field can be placed at the given
   /// offset.
@@ -227,9 +225,8 @@ void EmptySubobjectMap::ComputeEmptySubobjectSizes() {
   }
 }
 
-bool
-EmptySubobjectMap::CanPlaceSubobjectAtOffset(const CXXRecordDecl *RD,
- CharUnits Offset) const {
+bool EmptySubobjectMap::CanPlaceSubobjectAtOffset(const CXXRecordDecl *RD,
+  CharUnits Offset) const {
   // We only need to check empty bases.
   if (!RD->isEmpty())
 return true;
@@ -265,9 +262,8 @@ void EmptySubobjectMap::AddSubobjectAtOffset(const 
CXXRecordDecl *RD,
 MaxEmptyClassOffset = Offset;
 }
 
-bool
-EmptySubobjectMap::CanPlaceBaseSubobjectAtOffset(const BaseSubobjectInfo *Info,
- CharUnits Offset) {
+bool EmptySubobjectMap::CanPlaceBaseSubobjectAtOffset(
+const BaseSubobjectInfo *Info, CharUnits Offset) {
   // We don't have to keep looking past the maximum offset that's known to
   // contain an empty class.
   if (!AnyEmptySubobjectsBeyondOffset(Offset))
@@ -368,10 +364,9 @@ bool EmptySubobjectMap::CanPlaceBaseAtOffset(const 
BaseSubobjectInfo *Info,
   return true;
 }
 
-bool
-EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const CXXRecordDecl *RD,
-  const CXXRecordDecl *Class,
-  CharUnits Offset) const {
+bool EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(
+const CXXRecordDecl *RD, const CXXRecordDecl *Class,
+CharUnits Offset) const {
   // We don't have to keep looking past the maximum offset that's known to
   // contain an empty class.
   if (!AnyEmptySubobjectsBeyondOffset(Offset))
@@ -418,9 +413,8 @@ EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const 
CXXRecordDecl *RD,
   return true;
 }
 
-bool
-EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const FieldDecl *FD,
-  CharUnits Offset) const {
+bool EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const FieldDecl 

[clang] [CLANG-CL] ignores wpadded (PR #130182)

2025-03-18 Thread Theo de Magalhaes via cfe-commits
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes 
Message-ID:
In-Reply-To: 


https://github.com/therealcoochieman updated 
https://github.com/llvm/llvm-project/pull/130182

>From 3a9bc908a791669c82f288ff745664411bf285ac Mon Sep 17 00:00:00 2001
From: Theo de Magalhaes 
Date: Thu, 6 Mar 2025 22:26:37 +0100
Subject: [PATCH 1/7] chore(clang-format): formatted
 clang/lib/AST/RecordLayoutBuilder.cpp

---
 clang/lib/AST/RecordLayoutBuilder.cpp | 199 --
 1 file changed, 94 insertions(+), 105 deletions(-)

diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index b8600e6a344a4..695771f67868d 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -43,7 +43,7 @@ struct BaseSubobjectInfo {
   bool IsVirtual;
 
   /// Bases - Information about the base subobjects.
-  SmallVector Bases;
+  SmallVector Bases;
 
   /// PrimaryVirtualBaseInfo - Holds the base info for the primary virtual base
   /// of this base info (if one exists).
@@ -77,8 +77,7 @@ struct ExternalLayout {
   /// Get the offset of the given field. The external source must provide
   /// entries for all fields in the record.
   uint64_t getExternalFieldOffset(const FieldDecl *FD) {
-assert(FieldOffsets.count(FD) &&
-   "Field does not have an external offset");
+assert(FieldOffsets.count(FD) && "Field does not have an external offset");
 return FieldOffsets[FD];
   }
 
@@ -167,16 +166,15 @@ class EmptySubobjectMap {
   CharUnits SizeOfLargestEmptySubobject;
 
   EmptySubobjectMap(const ASTContext &Context, const CXXRecordDecl *Class)
-  : Context(Context), CharWidth(Context.getCharWidth()), Class(Class) {
-  ComputeEmptySubobjectSizes();
+  : Context(Context), CharWidth(Context.getCharWidth()), Class(Class) {
+ComputeEmptySubobjectSizes();
   }
 
   /// CanPlaceBaseAtOffset - Return whether the given base class can be placed
   /// at the given offset.
   /// Returns false if placing the record will result in two components
   /// (direct or indirect) of the same type having the same offset.
-  bool CanPlaceBaseAtOffset(const BaseSubobjectInfo *Info,
-CharUnits Offset);
+  bool CanPlaceBaseAtOffset(const BaseSubobjectInfo *Info, CharUnits Offset);
 
   /// CanPlaceFieldAtOffset - Return whether a field can be placed at the given
   /// offset.
@@ -227,9 +225,8 @@ void EmptySubobjectMap::ComputeEmptySubobjectSizes() {
   }
 }
 
-bool
-EmptySubobjectMap::CanPlaceSubobjectAtOffset(const CXXRecordDecl *RD,
- CharUnits Offset) const {
+bool EmptySubobjectMap::CanPlaceSubobjectAtOffset(const CXXRecordDecl *RD,
+  CharUnits Offset) const {
   // We only need to check empty bases.
   if (!RD->isEmpty())
 return true;
@@ -265,9 +262,8 @@ void EmptySubobjectMap::AddSubobjectAtOffset(const 
CXXRecordDecl *RD,
 MaxEmptyClassOffset = Offset;
 }
 
-bool
-EmptySubobjectMap::CanPlaceBaseSubobjectAtOffset(const BaseSubobjectInfo *Info,
- CharUnits Offset) {
+bool EmptySubobjectMap::CanPlaceBaseSubobjectAtOffset(
+const BaseSubobjectInfo *Info, CharUnits Offset) {
   // We don't have to keep looking past the maximum offset that's known to
   // contain an empty class.
   if (!AnyEmptySubobjectsBeyondOffset(Offset))
@@ -368,10 +364,9 @@ bool EmptySubobjectMap::CanPlaceBaseAtOffset(const 
BaseSubobjectInfo *Info,
   return true;
 }
 
-bool
-EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const CXXRecordDecl *RD,
-  const CXXRecordDecl *Class,
-  CharUnits Offset) const {
+bool EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(
+const CXXRecordDecl *RD, const CXXRecordDecl *Class,
+CharUnits Offset) const {
   // We don't have to keep looking past the maximum offset that's known to
   // contain an empty class.
   if (!AnyEmptySubobjectsBeyondOffset(Offset))
@@ -418,9 +413,8 @@ EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const 
CXXRecordDecl *RD,
   return true;
 }
 
-bool
-EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const FieldDecl *FD,
-  CharUnits Offset) const {
+bool EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const FieldDecl *FD,
+   CharUnits Offset) const 
{
   // We don't have to keep looking past the maximum offset that's known to
   // contain an empty class.
   if (!AnyEmptySubobjectsBeyondOffset(Offset))
@@ -560,7 +554,7 @@ void EmptySubobjectMap::UpdateEmptyFieldSubobjects(
   }
 }
 
-typedef llvm::SmallPtrSet ClassSetTy;
+typedef llvm::SmallPtrSet ClassSetTy;
 
 class ItaniumRecordLayoutBuilder {
 protected:
@@ -712,15 +706,13 @@ class ItaniumRecordLa

[clang] [CLANG-CL] ignores wpadded (PR #130182)

2025-03-19 Thread Theo de Magalhaes via cfe-commits
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes 
Message-ID:
In-Reply-To: 


https://github.com/therealcoochieman updated 
https://github.com/llvm/llvm-project/pull/130182

>From 3a9bc908a791669c82f288ff745664411bf285ac Mon Sep 17 00:00:00 2001
From: Theo de Magalhaes 
Date: Thu, 6 Mar 2025 22:26:37 +0100
Subject: [PATCH 1/8] chore(clang-format): formatted
 clang/lib/AST/RecordLayoutBuilder.cpp

---
 clang/lib/AST/RecordLayoutBuilder.cpp | 199 --
 1 file changed, 94 insertions(+), 105 deletions(-)

diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index b8600e6a344a4..695771f67868d 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -43,7 +43,7 @@ struct BaseSubobjectInfo {
   bool IsVirtual;
 
   /// Bases - Information about the base subobjects.
-  SmallVector Bases;
+  SmallVector Bases;
 
   /// PrimaryVirtualBaseInfo - Holds the base info for the primary virtual base
   /// of this base info (if one exists).
@@ -77,8 +77,7 @@ struct ExternalLayout {
   /// Get the offset of the given field. The external source must provide
   /// entries for all fields in the record.
   uint64_t getExternalFieldOffset(const FieldDecl *FD) {
-assert(FieldOffsets.count(FD) &&
-   "Field does not have an external offset");
+assert(FieldOffsets.count(FD) && "Field does not have an external offset");
 return FieldOffsets[FD];
   }
 
@@ -167,16 +166,15 @@ class EmptySubobjectMap {
   CharUnits SizeOfLargestEmptySubobject;
 
   EmptySubobjectMap(const ASTContext &Context, const CXXRecordDecl *Class)
-  : Context(Context), CharWidth(Context.getCharWidth()), Class(Class) {
-  ComputeEmptySubobjectSizes();
+  : Context(Context), CharWidth(Context.getCharWidth()), Class(Class) {
+ComputeEmptySubobjectSizes();
   }
 
   /// CanPlaceBaseAtOffset - Return whether the given base class can be placed
   /// at the given offset.
   /// Returns false if placing the record will result in two components
   /// (direct or indirect) of the same type having the same offset.
-  bool CanPlaceBaseAtOffset(const BaseSubobjectInfo *Info,
-CharUnits Offset);
+  bool CanPlaceBaseAtOffset(const BaseSubobjectInfo *Info, CharUnits Offset);
 
   /// CanPlaceFieldAtOffset - Return whether a field can be placed at the given
   /// offset.
@@ -227,9 +225,8 @@ void EmptySubobjectMap::ComputeEmptySubobjectSizes() {
   }
 }
 
-bool
-EmptySubobjectMap::CanPlaceSubobjectAtOffset(const CXXRecordDecl *RD,
- CharUnits Offset) const {
+bool EmptySubobjectMap::CanPlaceSubobjectAtOffset(const CXXRecordDecl *RD,
+  CharUnits Offset) const {
   // We only need to check empty bases.
   if (!RD->isEmpty())
 return true;
@@ -265,9 +262,8 @@ void EmptySubobjectMap::AddSubobjectAtOffset(const 
CXXRecordDecl *RD,
 MaxEmptyClassOffset = Offset;
 }
 
-bool
-EmptySubobjectMap::CanPlaceBaseSubobjectAtOffset(const BaseSubobjectInfo *Info,
- CharUnits Offset) {
+bool EmptySubobjectMap::CanPlaceBaseSubobjectAtOffset(
+const BaseSubobjectInfo *Info, CharUnits Offset) {
   // We don't have to keep looking past the maximum offset that's known to
   // contain an empty class.
   if (!AnyEmptySubobjectsBeyondOffset(Offset))
@@ -368,10 +364,9 @@ bool EmptySubobjectMap::CanPlaceBaseAtOffset(const 
BaseSubobjectInfo *Info,
   return true;
 }
 
-bool
-EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const CXXRecordDecl *RD,
-  const CXXRecordDecl *Class,
-  CharUnits Offset) const {
+bool EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(
+const CXXRecordDecl *RD, const CXXRecordDecl *Class,
+CharUnits Offset) const {
   // We don't have to keep looking past the maximum offset that's known to
   // contain an empty class.
   if (!AnyEmptySubobjectsBeyondOffset(Offset))
@@ -418,9 +413,8 @@ EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const 
CXXRecordDecl *RD,
   return true;
 }
 
-bool
-EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const FieldDecl *FD,
-  CharUnits Offset) const {
+bool EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const FieldDecl *FD,
+   CharUnits Offset) const 
{
   // We don't have to keep looking past the maximum offset that's known to
   // contain an empty class.
   if (!AnyEmptySubobjectsBeyondOffset(Offset))
@@ -560,7 +554,7 @@ void EmptySubobjectMap::UpdateEmptyFieldSubobjects(
   }
 }
 
-typedef llvm::SmallPtrSet ClassSetTy;
+typedef llvm::SmallPtrSet ClassSetTy;
 
 class ItaniumRecordLayoutBuilder {
 protected:
@@ -712,15 

[clang] [CLANG-CL] ignores Wpadded (PR #134426)

2025-04-04 Thread Theo de Magalhaes via cfe-commits
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,Theo de
 Magalhaes 
Message-ID: 
In-Reply-To:


https://github.com/therealcoochieman created 
https://github.com/llvm/llvm-project/pull/134426

Implements the Wpadded diagnostic for clang-cl.
#61702

>From 09572af03c07966925a3456a7d51ad9b3abb750b Mon Sep 17 00:00:00 2001
From: Theo de Magalhaes 
Date: Thu, 6 Mar 2025 22:26:37 +0100
Subject: [PATCH 01/12] chore(clang-format): formatted
 clang/lib/AST/RecordLayoutBuilder.cpp

---
 clang/lib/AST/RecordLayoutBuilder.cpp | 199 --
 1 file changed, 94 insertions(+), 105 deletions(-)

diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index 3e756ab9b9bfe..9740c8e4cdd65 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -43,7 +43,7 @@ struct BaseSubobjectInfo {
   bool IsVirtual;
 
   /// Bases - Information about the base subobjects.
-  SmallVector Bases;
+  SmallVector Bases;
 
   /// PrimaryVirtualBaseInfo - Holds the base info for the primary virtual base
   /// of this base info (if one exists).
@@ -77,8 +77,7 @@ struct ExternalLayout {
   /// Get the offset of the given field. The external source must provide
   /// entries for all fields in the record.
   uint64_t getExternalFieldOffset(const FieldDecl *FD) {
-assert(FieldOffsets.count(FD) &&
-   "Field does not have an external offset");
+assert(FieldOffsets.count(FD) && "Field does not have an external offset");
 return FieldOffsets[FD];
   }
 
@@ -167,16 +166,15 @@ class EmptySubobjectMap {
   CharUnits SizeOfLargestEmptySubobject;
 
   EmptySubobjectMap(const ASTContext &Context, const CXXRecordDecl *Class)
-  : Context(Context), CharWidth(Context.getCharWidth()), Class(Class) {
-  ComputeEmptySubobjectSizes();
+  : Context(Context), CharWidth(Context.getCharWidth()), Class(Class) {
+ComputeEmptySubobjectSizes();
   }
 
   /// CanPlaceBaseAtOffset - Return whether the given base class can be placed
   /// at the given offset.
   /// Returns false if placing the record will result in two components
   /// (direct or indirect) of the same type having the same offset.
-  bool CanPlaceBaseAtOffset(const BaseSubobjectInfo *Info,
-CharUnits Offset);
+  bool CanPlaceBaseAtOffset(const BaseSubobjectInfo *Info, CharUnits Offset);
 
   /// CanPlaceFieldAtOffset - Return whether a field can be placed at the given
   /// offset.
@@ -227,9 +225,8 @@ void EmptySubobjectMap::ComputeEmptySubobjectSizes() {
   }
 }
 
-bool
-EmptySubobjectMap::CanPlaceSubobjectAtOffset(const CXXRecordDecl *RD,
- CharUnits Offset) const {
+bool EmptySubobjectMap::CanPlaceSubobjectAtOffset(const CXXRecordDecl *RD,
+  CharUnits Offset) const {
   // We only need to check empty bases.
   if (!RD->isEmpty())
 return true;
@@ -265,9 +262,8 @@ void EmptySubobjectMap::AddSubobjectAtOffset(const 
CXXRecordDecl *RD,
 MaxEmptyClassOffset = Offset;
 }
 
-bool
-EmptySubobjectMap::CanPlaceBaseSubobjectAtOffset(const BaseSubobjectInfo *Info,
- CharUnits Offset) {
+bool EmptySubobjectMap::CanPlaceBaseSubobjectAtOffset(
+const BaseSubobjectInfo *Info, CharUnits Offset) {
   // We don't have to keep looking past the maximum offset that's known to
   // contain an empty class.
   if (!AnyEmptySubobjectsBeyondOffset(Offset))
@@ -368,10 +364,9 @@ bool EmptySubobjectMap::CanPlaceBaseAtOffset(const 
BaseSubobjectInfo *Info,
   return true;
 }
 
-bool
-EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const CXXRecordDecl *RD,
-  const CXXRecordDecl *Class,
-  CharUnits Offset) const {
+bool EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(
+const CXXRecordDecl *RD, const CXXRecordDecl *Class,
+CharUnits Offset) const {
   // We don't have to keep looking past the maximum offset that's known to
   // contain an empty class.
   if (!AnyEmptySubobjectsBeyondOffset(Offset))
@@ -418,9 +413,8 @@ EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const 
CXXRecordDecl *RD,
   return true;
 }
 
-bool
-EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const FieldDecl *FD,
-  CharUnits Offset) const {
+bool EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const FieldDecl *FD,
+   CharUnits Offset) const 
{
   // We don't have to keep looking past the maximum offset that's known to
   // contain an empty class.
   if (!AnyEmptySubobjectsBeyondOffset(Offset))
@@ -560,7 +554,7 @@ void EmptySubobjectMap::Upd

[clang] [CLANG-CL] ignores Wpadded (PR #134426)

2025-04-04 Thread Theo de Magalhaes via cfe-commits
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,Theo de
 Magalhaes 
Message-ID:
In-Reply-To: 


therealcoochieman wrote:

Fixes the issue in #130182 where the variable `RemainingBitsInField` was used 
uninitialized, leading to undefined behavior in certain cases.
Although I wasn't able to reproduce the undefined behavior using Clang 18.1.8, 
I validated the fix with Valgrind while running the windows-Wpadded.cpp test.

@mikaelholmen @asb, could you please confirm if this resolves the issue on your 
end?
Thanks for your patience, and I hope the pin isn't too disruptive.

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


[clang] [CLANG-CL] ignores wpadded (PR #130182)

2025-04-03 Thread Theo de Magalhaes via cfe-commits
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes 
Message-ID:
In-Reply-To: 



@@ -3004,6 +3010,15 @@ void MicrosoftRecordLayoutBuilder::layoutField(const 
FieldDecl *FD) {
   } else {
 FieldOffset = Size.alignTo(Info.Alignment);
   }
+
+  uint64_t UnpaddedFielddOffsetInBits =
+  Context.toBits(DataSize) - RemainingBitsInField;

therealcoochieman wrote:

Hello, this is also my main suspicion. I will fix this later today.

Thank you for your thoroughness, I did not think to check with other compilers 
or do a valgrind check. Sorry for that.

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


[clang] [CLANG-CL] ignores wpadded (PR #130182)

2025-04-04 Thread Theo de Magalhaes via cfe-commits
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,12 @@
+// RUN: %clang_cl -Wpadded -Wno-msvc-not-found -fsyntax-only -- %s 2>&1 | 
FileCheck -check-prefix=WARN %s

therealcoochieman wrote:

I have merged every test inside the same file 
(`clang/test/SemaCXX/windows-Wpadded.cpp`) except for the one dealing with 
Bitfields as it cannot be tested with both target triples. This test is in a 
separate file.

Thank you for your patience. 

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


[clang] [CLANG-CL] ignores Wpadded (PR #134426)

2025-04-04 Thread Theo de Magalhaes via cfe-commits
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,Theo de
 Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes 
Message-ID:
In-Reply-To: 


https://github.com/therealcoochieman updated 
https://github.com/llvm/llvm-project/pull/134426

>From 09572af03c07966925a3456a7d51ad9b3abb750b Mon Sep 17 00:00:00 2001
From: Theo de Magalhaes 
Date: Thu, 6 Mar 2025 22:26:37 +0100
Subject: [PATCH 01/13] chore(clang-format): formatted
 clang/lib/AST/RecordLayoutBuilder.cpp

---
 clang/lib/AST/RecordLayoutBuilder.cpp | 199 --
 1 file changed, 94 insertions(+), 105 deletions(-)

diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index 3e756ab9b9bfe..9740c8e4cdd65 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -43,7 +43,7 @@ struct BaseSubobjectInfo {
   bool IsVirtual;
 
   /// Bases - Information about the base subobjects.
-  SmallVector Bases;
+  SmallVector Bases;
 
   /// PrimaryVirtualBaseInfo - Holds the base info for the primary virtual base
   /// of this base info (if one exists).
@@ -77,8 +77,7 @@ struct ExternalLayout {
   /// Get the offset of the given field. The external source must provide
   /// entries for all fields in the record.
   uint64_t getExternalFieldOffset(const FieldDecl *FD) {
-assert(FieldOffsets.count(FD) &&
-   "Field does not have an external offset");
+assert(FieldOffsets.count(FD) && "Field does not have an external offset");
 return FieldOffsets[FD];
   }
 
@@ -167,16 +166,15 @@ class EmptySubobjectMap {
   CharUnits SizeOfLargestEmptySubobject;
 
   EmptySubobjectMap(const ASTContext &Context, const CXXRecordDecl *Class)
-  : Context(Context), CharWidth(Context.getCharWidth()), Class(Class) {
-  ComputeEmptySubobjectSizes();
+  : Context(Context), CharWidth(Context.getCharWidth()), Class(Class) {
+ComputeEmptySubobjectSizes();
   }
 
   /// CanPlaceBaseAtOffset - Return whether the given base class can be placed
   /// at the given offset.
   /// Returns false if placing the record will result in two components
   /// (direct or indirect) of the same type having the same offset.
-  bool CanPlaceBaseAtOffset(const BaseSubobjectInfo *Info,
-CharUnits Offset);
+  bool CanPlaceBaseAtOffset(const BaseSubobjectInfo *Info, CharUnits Offset);
 
   /// CanPlaceFieldAtOffset - Return whether a field can be placed at the given
   /// offset.
@@ -227,9 +225,8 @@ void EmptySubobjectMap::ComputeEmptySubobjectSizes() {
   }
 }
 
-bool
-EmptySubobjectMap::CanPlaceSubobjectAtOffset(const CXXRecordDecl *RD,
- CharUnits Offset) const {
+bool EmptySubobjectMap::CanPlaceSubobjectAtOffset(const CXXRecordDecl *RD,
+  CharUnits Offset) const {
   // We only need to check empty bases.
   if (!RD->isEmpty())
 return true;
@@ -265,9 +262,8 @@ void EmptySubobjectMap::AddSubobjectAtOffset(const 
CXXRecordDecl *RD,
 MaxEmptyClassOffset = Offset;
 }
 
-bool
-EmptySubobjectMap::CanPlaceBaseSubobjectAtOffset(const BaseSubobjectInfo *Info,
- CharUnits Offset) {
+bool EmptySubobjectMap::CanPlaceBaseSubobjectAtOffset(
+const BaseSubobjectInfo *Info, CharUnits Offset) {
   // We don't have to keep looking past the maximum offset that's known to
   // contain an empty class.
   if (!AnyEmptySubobjectsBeyondOffset(Offset))
@@ -368,10 +364,9 @@ bool EmptySubobjectMap::CanPlaceBaseAtOffset(const 
BaseSubobjectInfo *Info,
   return true;
 }
 
-bool
-EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const CXXRecordDecl *RD,
-  const CXXRecordDecl *Class,
-  CharUnits Offset) const {
+bool EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(
+const CXXRecordDecl *RD, const CXXRecordDecl *Class,
+CharUnits Offset) const {
   // We don't have to keep looking past the maximum offset that's known to
   // contain an empty class.
   if (!AnyEmptySubobjectsBeyondOffset(Offset))
@@ -418,9 +413,8 @@ EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const 
CXXRecordDecl *RD,
   return true;
 }
 
-bool
-EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const FieldDecl *FD,
-  CharUnits Offset) const {
+bool EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const FieldDecl *FD,
+   CharUnits Offset) const 
{
   // We don't have to keep looking past the maximum offset that's known to
   // contain an empty class.
   if (!AnyEmptySubobjectsBeyondOffset(Offset))
@@ -560,7 +554,7 @@ void EmptySubobjectMap::UpdateEmptyFieldSubobjects(

[clang] [CLANG-CL] ignores Wpadded (PR #134426)

2025-04-04 Thread Theo de Magalhaes via cfe-commits
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,Theo de
 Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes 
Message-ID:
In-Reply-To: 


https://github.com/therealcoochieman updated 
https://github.com/llvm/llvm-project/pull/134426

>From 09572af03c07966925a3456a7d51ad9b3abb750b Mon Sep 17 00:00:00 2001
From: Theo de Magalhaes 
Date: Thu, 6 Mar 2025 22:26:37 +0100
Subject: [PATCH 01/14] chore(clang-format): formatted
 clang/lib/AST/RecordLayoutBuilder.cpp

---
 clang/lib/AST/RecordLayoutBuilder.cpp | 199 --
 1 file changed, 94 insertions(+), 105 deletions(-)

diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index 3e756ab9b9bfe..9740c8e4cdd65 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -43,7 +43,7 @@ struct BaseSubobjectInfo {
   bool IsVirtual;
 
   /// Bases - Information about the base subobjects.
-  SmallVector Bases;
+  SmallVector Bases;
 
   /// PrimaryVirtualBaseInfo - Holds the base info for the primary virtual base
   /// of this base info (if one exists).
@@ -77,8 +77,7 @@ struct ExternalLayout {
   /// Get the offset of the given field. The external source must provide
   /// entries for all fields in the record.
   uint64_t getExternalFieldOffset(const FieldDecl *FD) {
-assert(FieldOffsets.count(FD) &&
-   "Field does not have an external offset");
+assert(FieldOffsets.count(FD) && "Field does not have an external offset");
 return FieldOffsets[FD];
   }
 
@@ -167,16 +166,15 @@ class EmptySubobjectMap {
   CharUnits SizeOfLargestEmptySubobject;
 
   EmptySubobjectMap(const ASTContext &Context, const CXXRecordDecl *Class)
-  : Context(Context), CharWidth(Context.getCharWidth()), Class(Class) {
-  ComputeEmptySubobjectSizes();
+  : Context(Context), CharWidth(Context.getCharWidth()), Class(Class) {
+ComputeEmptySubobjectSizes();
   }
 
   /// CanPlaceBaseAtOffset - Return whether the given base class can be placed
   /// at the given offset.
   /// Returns false if placing the record will result in two components
   /// (direct or indirect) of the same type having the same offset.
-  bool CanPlaceBaseAtOffset(const BaseSubobjectInfo *Info,
-CharUnits Offset);
+  bool CanPlaceBaseAtOffset(const BaseSubobjectInfo *Info, CharUnits Offset);
 
   /// CanPlaceFieldAtOffset - Return whether a field can be placed at the given
   /// offset.
@@ -227,9 +225,8 @@ void EmptySubobjectMap::ComputeEmptySubobjectSizes() {
   }
 }
 
-bool
-EmptySubobjectMap::CanPlaceSubobjectAtOffset(const CXXRecordDecl *RD,
- CharUnits Offset) const {
+bool EmptySubobjectMap::CanPlaceSubobjectAtOffset(const CXXRecordDecl *RD,
+  CharUnits Offset) const {
   // We only need to check empty bases.
   if (!RD->isEmpty())
 return true;
@@ -265,9 +262,8 @@ void EmptySubobjectMap::AddSubobjectAtOffset(const 
CXXRecordDecl *RD,
 MaxEmptyClassOffset = Offset;
 }
 
-bool
-EmptySubobjectMap::CanPlaceBaseSubobjectAtOffset(const BaseSubobjectInfo *Info,
- CharUnits Offset) {
+bool EmptySubobjectMap::CanPlaceBaseSubobjectAtOffset(
+const BaseSubobjectInfo *Info, CharUnits Offset) {
   // We don't have to keep looking past the maximum offset that's known to
   // contain an empty class.
   if (!AnyEmptySubobjectsBeyondOffset(Offset))
@@ -368,10 +364,9 @@ bool EmptySubobjectMap::CanPlaceBaseAtOffset(const 
BaseSubobjectInfo *Info,
   return true;
 }
 
-bool
-EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const CXXRecordDecl *RD,
-  const CXXRecordDecl *Class,
-  CharUnits Offset) const {
+bool EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(
+const CXXRecordDecl *RD, const CXXRecordDecl *Class,
+CharUnits Offset) const {
   // We don't have to keep looking past the maximum offset that's known to
   // contain an empty class.
   if (!AnyEmptySubobjectsBeyondOffset(Offset))
@@ -418,9 +413,8 @@ EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const 
CXXRecordDecl *RD,
   return true;
 }
 
-bool
-EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const FieldDecl *FD,
-  CharUnits Offset) const {
+bool EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const FieldDecl *FD,
+   CharUnits Offset) const 
{
   // We don't have to keep looking past the maximum offset that's known to
   // contain an empty class.
   if (!AnyEmptySubobjectsBeyondOffset(Offset))
@@ -560,7 +554,7 @@ void EmptySubobject

[clang] [CLANG-CL] ignores wpadded (PR #130182)

2025-03-27 Thread Theo de Magalhaes via cfe-commits
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes 
Message-ID:
In-Reply-To: 


https://github.com/therealcoochieman updated 
https://github.com/llvm/llvm-project/pull/130182

>From 3a9bc908a791669c82f288ff745664411bf285ac Mon Sep 17 00:00:00 2001
From: Theo de Magalhaes 
Date: Thu, 6 Mar 2025 22:26:37 +0100
Subject: [PATCH 1/9] chore(clang-format): formatted
 clang/lib/AST/RecordLayoutBuilder.cpp

---
 clang/lib/AST/RecordLayoutBuilder.cpp | 199 --
 1 file changed, 94 insertions(+), 105 deletions(-)

diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index b8600e6a344a4..695771f67868d 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -43,7 +43,7 @@ struct BaseSubobjectInfo {
   bool IsVirtual;
 
   /// Bases - Information about the base subobjects.
-  SmallVector Bases;
+  SmallVector Bases;
 
   /// PrimaryVirtualBaseInfo - Holds the base info for the primary virtual base
   /// of this base info (if one exists).
@@ -77,8 +77,7 @@ struct ExternalLayout {
   /// Get the offset of the given field. The external source must provide
   /// entries for all fields in the record.
   uint64_t getExternalFieldOffset(const FieldDecl *FD) {
-assert(FieldOffsets.count(FD) &&
-   "Field does not have an external offset");
+assert(FieldOffsets.count(FD) && "Field does not have an external offset");
 return FieldOffsets[FD];
   }
 
@@ -167,16 +166,15 @@ class EmptySubobjectMap {
   CharUnits SizeOfLargestEmptySubobject;
 
   EmptySubobjectMap(const ASTContext &Context, const CXXRecordDecl *Class)
-  : Context(Context), CharWidth(Context.getCharWidth()), Class(Class) {
-  ComputeEmptySubobjectSizes();
+  : Context(Context), CharWidth(Context.getCharWidth()), Class(Class) {
+ComputeEmptySubobjectSizes();
   }
 
   /// CanPlaceBaseAtOffset - Return whether the given base class can be placed
   /// at the given offset.
   /// Returns false if placing the record will result in two components
   /// (direct or indirect) of the same type having the same offset.
-  bool CanPlaceBaseAtOffset(const BaseSubobjectInfo *Info,
-CharUnits Offset);
+  bool CanPlaceBaseAtOffset(const BaseSubobjectInfo *Info, CharUnits Offset);
 
   /// CanPlaceFieldAtOffset - Return whether a field can be placed at the given
   /// offset.
@@ -227,9 +225,8 @@ void EmptySubobjectMap::ComputeEmptySubobjectSizes() {
   }
 }
 
-bool
-EmptySubobjectMap::CanPlaceSubobjectAtOffset(const CXXRecordDecl *RD,
- CharUnits Offset) const {
+bool EmptySubobjectMap::CanPlaceSubobjectAtOffset(const CXXRecordDecl *RD,
+  CharUnits Offset) const {
   // We only need to check empty bases.
   if (!RD->isEmpty())
 return true;
@@ -265,9 +262,8 @@ void EmptySubobjectMap::AddSubobjectAtOffset(const 
CXXRecordDecl *RD,
 MaxEmptyClassOffset = Offset;
 }
 
-bool
-EmptySubobjectMap::CanPlaceBaseSubobjectAtOffset(const BaseSubobjectInfo *Info,
- CharUnits Offset) {
+bool EmptySubobjectMap::CanPlaceBaseSubobjectAtOffset(
+const BaseSubobjectInfo *Info, CharUnits Offset) {
   // We don't have to keep looking past the maximum offset that's known to
   // contain an empty class.
   if (!AnyEmptySubobjectsBeyondOffset(Offset))
@@ -368,10 +364,9 @@ bool EmptySubobjectMap::CanPlaceBaseAtOffset(const 
BaseSubobjectInfo *Info,
   return true;
 }
 
-bool
-EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const CXXRecordDecl *RD,
-  const CXXRecordDecl *Class,
-  CharUnits Offset) const {
+bool EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(
+const CXXRecordDecl *RD, const CXXRecordDecl *Class,
+CharUnits Offset) const {
   // We don't have to keep looking past the maximum offset that's known to
   // contain an empty class.
   if (!AnyEmptySubobjectsBeyondOffset(Offset))
@@ -418,9 +413,8 @@ EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const 
CXXRecordDecl *RD,
   return true;
 }
 
-bool
-EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const FieldDecl *FD,
-  CharUnits Offset) const {
+bool EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const FieldDecl *FD,
+   CharUnits Offset) const 
{
   // We don't have to keep looking past the maximum offset that's known to
   // contain an empty class.
   if (!AnyEmptySubobjectsBeyondOffset(Offset))
@@ -560,7 +554,7 @@ void EmptySubobjectMap::UpdateEmptyFieldSubobjects(
   }
 }
 
-typedef llvm::SmallPtrSet ClassSetTy;
+typedef llvm::SmallPtrSet ClassSetTy;
 
 class ItaniumRecordLayoutB

[clang] [CLANG-CL] ignores wpadded (PR #130182)

2025-03-27 Thread Theo de Magalhaes via cfe-commits
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,12 @@
+// RUN: %clang_cl -Wpadded -Wno-msvc-not-found -fsyntax-only -- %s 2>&1 | 
FileCheck -check-prefix=WARN %s

therealcoochieman wrote:

Hello @efriedma-quic, I hope you don’t mind the ping.
While waiting for your response, I’ve added more bitfield tests.
I’ve also fixed #131647 in a different branch. Once these tests are validated, 
I’ll rebase this PR onto that branch and merge the two test files.

Would you like me to notify you directly when the next PR is ready for review?
Thank you.

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


[clang] [CLANG-CL] ignores wpadded (PR #130182)

2025-03-28 Thread Theo de Magalhaes via cfe-commits
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes 
Message-ID:
In-Reply-To: 


https://github.com/therealcoochieman updated 
https://github.com/llvm/llvm-project/pull/130182

>From 3a9bc908a791669c82f288ff745664411bf285ac Mon Sep 17 00:00:00 2001
From: Theo de Magalhaes 
Date: Thu, 6 Mar 2025 22:26:37 +0100
Subject: [PATCH 01/11] chore(clang-format): formatted
 clang/lib/AST/RecordLayoutBuilder.cpp

---
 clang/lib/AST/RecordLayoutBuilder.cpp | 199 --
 1 file changed, 94 insertions(+), 105 deletions(-)

diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index b8600e6a344a4..695771f67868d 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -43,7 +43,7 @@ struct BaseSubobjectInfo {
   bool IsVirtual;
 
   /// Bases - Information about the base subobjects.
-  SmallVector Bases;
+  SmallVector Bases;
 
   /// PrimaryVirtualBaseInfo - Holds the base info for the primary virtual base
   /// of this base info (if one exists).
@@ -77,8 +77,7 @@ struct ExternalLayout {
   /// Get the offset of the given field. The external source must provide
   /// entries for all fields in the record.
   uint64_t getExternalFieldOffset(const FieldDecl *FD) {
-assert(FieldOffsets.count(FD) &&
-   "Field does not have an external offset");
+assert(FieldOffsets.count(FD) && "Field does not have an external offset");
 return FieldOffsets[FD];
   }
 
@@ -167,16 +166,15 @@ class EmptySubobjectMap {
   CharUnits SizeOfLargestEmptySubobject;
 
   EmptySubobjectMap(const ASTContext &Context, const CXXRecordDecl *Class)
-  : Context(Context), CharWidth(Context.getCharWidth()), Class(Class) {
-  ComputeEmptySubobjectSizes();
+  : Context(Context), CharWidth(Context.getCharWidth()), Class(Class) {
+ComputeEmptySubobjectSizes();
   }
 
   /// CanPlaceBaseAtOffset - Return whether the given base class can be placed
   /// at the given offset.
   /// Returns false if placing the record will result in two components
   /// (direct or indirect) of the same type having the same offset.
-  bool CanPlaceBaseAtOffset(const BaseSubobjectInfo *Info,
-CharUnits Offset);
+  bool CanPlaceBaseAtOffset(const BaseSubobjectInfo *Info, CharUnits Offset);
 
   /// CanPlaceFieldAtOffset - Return whether a field can be placed at the given
   /// offset.
@@ -227,9 +225,8 @@ void EmptySubobjectMap::ComputeEmptySubobjectSizes() {
   }
 }
 
-bool
-EmptySubobjectMap::CanPlaceSubobjectAtOffset(const CXXRecordDecl *RD,
- CharUnits Offset) const {
+bool EmptySubobjectMap::CanPlaceSubobjectAtOffset(const CXXRecordDecl *RD,
+  CharUnits Offset) const {
   // We only need to check empty bases.
   if (!RD->isEmpty())
 return true;
@@ -265,9 +262,8 @@ void EmptySubobjectMap::AddSubobjectAtOffset(const 
CXXRecordDecl *RD,
 MaxEmptyClassOffset = Offset;
 }
 
-bool
-EmptySubobjectMap::CanPlaceBaseSubobjectAtOffset(const BaseSubobjectInfo *Info,
- CharUnits Offset) {
+bool EmptySubobjectMap::CanPlaceBaseSubobjectAtOffset(
+const BaseSubobjectInfo *Info, CharUnits Offset) {
   // We don't have to keep looking past the maximum offset that's known to
   // contain an empty class.
   if (!AnyEmptySubobjectsBeyondOffset(Offset))
@@ -368,10 +364,9 @@ bool EmptySubobjectMap::CanPlaceBaseAtOffset(const 
BaseSubobjectInfo *Info,
   return true;
 }
 
-bool
-EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const CXXRecordDecl *RD,
-  const CXXRecordDecl *Class,
-  CharUnits Offset) const {
+bool EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(
+const CXXRecordDecl *RD, const CXXRecordDecl *Class,
+CharUnits Offset) const {
   // We don't have to keep looking past the maximum offset that's known to
   // contain an empty class.
   if (!AnyEmptySubobjectsBeyondOffset(Offset))
@@ -418,9 +413,8 @@ EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const 
CXXRecordDecl *RD,
   return true;
 }
 
-bool
-EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const FieldDecl *FD,
-  CharUnits Offset) const {
+bool EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const FieldDecl *FD,
+   CharUnits Offset) const 
{
   // We don't have to keep looking past the maximum offset that's known to
   // contain an empty class.
   if (!AnyEmptySubobjectsBeyondOffset(Offset))
@@ -560,7 +554,7 @@ void EmptySubobjectMap::UpdateEmptyFieldSubobjects(
   }
 }
 
-typedef llvm::SmallPtrSet ClassSetTy;
+t

[clang] [CLANG-CL] ignores wpadded (PR #130182)

2025-04-05 Thread Theo de Magalhaes via cfe-commits
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes ,
=?utf-8?q?Théo?= De Magalhaes 
Message-ID:
In-Reply-To: 


https://github.com/therealcoochieman updated 
https://github.com/llvm/llvm-project/pull/130182

>From 09572af03c07966925a3456a7d51ad9b3abb750b Mon Sep 17 00:00:00 2001
From: Theo de Magalhaes 
Date: Thu, 6 Mar 2025 22:26:37 +0100
Subject: [PATCH 01/11] chore(clang-format): formatted
 clang/lib/AST/RecordLayoutBuilder.cpp

---
 clang/lib/AST/RecordLayoutBuilder.cpp | 199 --
 1 file changed, 94 insertions(+), 105 deletions(-)

diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index 3e756ab9b9bfe..9740c8e4cdd65 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -43,7 +43,7 @@ struct BaseSubobjectInfo {
   bool IsVirtual;
 
   /// Bases - Information about the base subobjects.
-  SmallVector Bases;
+  SmallVector Bases;
 
   /// PrimaryVirtualBaseInfo - Holds the base info for the primary virtual base
   /// of this base info (if one exists).
@@ -77,8 +77,7 @@ struct ExternalLayout {
   /// Get the offset of the given field. The external source must provide
   /// entries for all fields in the record.
   uint64_t getExternalFieldOffset(const FieldDecl *FD) {
-assert(FieldOffsets.count(FD) &&
-   "Field does not have an external offset");
+assert(FieldOffsets.count(FD) && "Field does not have an external offset");
 return FieldOffsets[FD];
   }
 
@@ -167,16 +166,15 @@ class EmptySubobjectMap {
   CharUnits SizeOfLargestEmptySubobject;
 
   EmptySubobjectMap(const ASTContext &Context, const CXXRecordDecl *Class)
-  : Context(Context), CharWidth(Context.getCharWidth()), Class(Class) {
-  ComputeEmptySubobjectSizes();
+  : Context(Context), CharWidth(Context.getCharWidth()), Class(Class) {
+ComputeEmptySubobjectSizes();
   }
 
   /// CanPlaceBaseAtOffset - Return whether the given base class can be placed
   /// at the given offset.
   /// Returns false if placing the record will result in two components
   /// (direct or indirect) of the same type having the same offset.
-  bool CanPlaceBaseAtOffset(const BaseSubobjectInfo *Info,
-CharUnits Offset);
+  bool CanPlaceBaseAtOffset(const BaseSubobjectInfo *Info, CharUnits Offset);
 
   /// CanPlaceFieldAtOffset - Return whether a field can be placed at the given
   /// offset.
@@ -227,9 +225,8 @@ void EmptySubobjectMap::ComputeEmptySubobjectSizes() {
   }
 }
 
-bool
-EmptySubobjectMap::CanPlaceSubobjectAtOffset(const CXXRecordDecl *RD,
- CharUnits Offset) const {
+bool EmptySubobjectMap::CanPlaceSubobjectAtOffset(const CXXRecordDecl *RD,
+  CharUnits Offset) const {
   // We only need to check empty bases.
   if (!RD->isEmpty())
 return true;
@@ -265,9 +262,8 @@ void EmptySubobjectMap::AddSubobjectAtOffset(const 
CXXRecordDecl *RD,
 MaxEmptyClassOffset = Offset;
 }
 
-bool
-EmptySubobjectMap::CanPlaceBaseSubobjectAtOffset(const BaseSubobjectInfo *Info,
- CharUnits Offset) {
+bool EmptySubobjectMap::CanPlaceBaseSubobjectAtOffset(
+const BaseSubobjectInfo *Info, CharUnits Offset) {
   // We don't have to keep looking past the maximum offset that's known to
   // contain an empty class.
   if (!AnyEmptySubobjectsBeyondOffset(Offset))
@@ -368,10 +364,9 @@ bool EmptySubobjectMap::CanPlaceBaseAtOffset(const 
BaseSubobjectInfo *Info,
   return true;
 }
 
-bool
-EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const CXXRecordDecl *RD,
-  const CXXRecordDecl *Class,
-  CharUnits Offset) const {
+bool EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(
+const CXXRecordDecl *RD, const CXXRecordDecl *Class,
+CharUnits Offset) const {
   // We don't have to keep looking past the maximum offset that's known to
   // contain an empty class.
   if (!AnyEmptySubobjectsBeyondOffset(Offset))
@@ -418,9 +413,8 @@ EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const 
CXXRecordDecl *RD,
   return true;
 }
 
-bool
-EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const FieldDecl *FD,
-  CharUnits Offset) const {
+bool EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const FieldDecl *FD,
+   CharUnits Offset) const 
{
   // We don't have to keep looking past the maximum offset that's known to
   // contain an empty class.
   if (!AnyEmptySubobjectsBeyondOffset(Offset))
@@ -560,7 +554,7 @@ void EmptySubobjectMap::UpdateEmptyFieldSubobjects(
   }
 }
 
-typedef llvm::SmallPtrSet ClassSetTy;
+t