[clang] Revert "[Clang] Reduce the size of Decl and classes derived from it" (PR #88654)

2024-04-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: Nikolas Klauser (philnik777)


Changes

Reverts llvm/llvm-project#87361

On 32 bit platforms there is only a single bit available in the `DeclCtx`, 
resulting in an assertion failure.


---
Full diff: https://github.com/llvm/llvm-project/pull/88654.diff


3 Files Affected:

- (modified) clang/include/clang/AST/DeclBase.h (+25-47) 
- (modified) clang/lib/AST/DeclBase.cpp (+9-22) 
- (modified) clang/lib/Serialization/ASTReaderDecl.cpp (+1-1) 


``diff
diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 4bee18767dd11b..858450926455c6 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -268,37 +268,17 @@ class alignas(8) Decl {
   ///   }
   ///   void A::f(); // SemanticDC == namespace 'A'
   ///// LexicalDC == global namespace
+  llvm::PointerUnion DeclCtx;
 
-  // Compress the InvalidDecl and HasAttrs bits into DeclCtx to keep Decl below
-  // 32 bytes in size
-  llvm::PointerIntPair<
-  llvm::PointerIntPair, 1,
-   bool>,
-  1, bool>
-  DeclCtxWithInvalidDeclAndHasAttrs;
-
-  bool isInSemaDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.is();
-  }
-
-  bool isOutOfSemaDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.is();
-  }
+  bool isInSemaDC() const { return DeclCtx.is(); }
+  bool isOutOfSemaDC() const { return DeclCtx.is(); }
 
   MultipleDC *getMultipleDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.get();
+return DeclCtx.get();
   }
 
   DeclContext *getSemanticDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.get();
+return DeclCtx.get();
   }
 
   /// Loc - The location of this decl.
@@ -308,6 +288,14 @@ class alignas(8) Decl {
   LLVM_PREFERRED_TYPE(Kind)
   unsigned DeclKind : 7;
 
+  /// InvalidDecl - This indicates a semantic error occurred.
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned InvalidDecl :  1;
+
+  /// HasAttrs - This indicates whether the decl has attributes or not.
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned HasAttrs : 1;
+
   /// Implicit - Whether this declaration was implicitly generated by
   /// the implementation rather than explicitly written by the user.
   LLVM_PREFERRED_TYPE(bool)
@@ -405,22 +393,21 @@ class alignas(8) Decl {
 protected:
   Decl(Kind DK, DeclContext *DC, SourceLocation L)
   : NextInContextAndBits(nullptr, getModuleOwnershipKindForChildOf(DC)),
-DeclCtxWithInvalidDeclAndHasAttrs({DC, false}, false), Loc(L),
-DeclKind(DK), Implicit(false), Used(false), Referenced(false),
+DeclCtx(DC), Loc(L), DeclKind(DK), InvalidDecl(false), HasAttrs(false),
+Implicit(false), Used(false), Referenced(false),
 TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
-if (StatisticsEnabled)
-  add(DK);
+if (StatisticsEnabled) add(DK);
   }
 
   Decl(Kind DK, EmptyShell Empty)
-  : DeclKind(DK), Implicit(false), Used(false), Referenced(false),
-TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
+  : DeclKind(DK), InvalidDecl(false), HasAttrs(false), Implicit(false),
+Used(false), Referenced(false), TopLevelDeclInObjCContainer(false),
+Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
-if (StatisticsEnabled)
-  add(DK);
+if (StatisticsEnabled) add(DK);
   }
 
   virtual ~Decl();
@@ -533,9 +520,7 @@ class alignas(8) Decl {
 return AccessSpecifier(Access);
   }
 
-  bool hasAttrs() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer().getInt();
-  }
+  bool hasAttrs() const { return HasAttrs; }
 
   void setAttrs(const AttrVec& Attrs) {
 return setAttrsImpl(Attrs, getASTContext());
@@ -564,17 +549,13 @@ class alignas(8) Decl {
   }
 
   template  void dropAttrs() {
-if (!hasAttrs())
-  return;
+if (!HasAttrs) return;
 
 AttrVec  = getAttrs();
 llvm::erase_if(Vec, [](Attr *A) { return isa(A); });
 
-if (Vec.empty()) {
-  auto InnerPtr = DeclCtxWithInvalidDeclAndHasAttrs.getPointer();
-  InnerPtr.setInt(false);
-  DeclCtxWithInvalidDeclAndHasAttrs.setPointer(InnerPtr);
-}
+if (Vec.empty())
+  HasAttrs = false;
   }
 
   template  void dropAttr() { dropAttrs(); }
@@ -609,10 +590,7 @@ class alignas(8) Decl {
   /// setInvalidDecl - Indicates the Decl had a semantic error. This
   /// allows for graceful error recovery.
   void setInvalidDecl(bool Invalid = true);
-
-  bool isInvalidDecl() const {
-return 

[clang] Revert "[Clang] Reduce the size of Decl and classes derived from it" (PR #88654)

2024-04-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Nikolas Klauser (philnik777)


Changes

Reverts llvm/llvm-project#87361

On 32 bit platforms there is only a single bit available in the `DeclCtx`, 
resulting in an assertion failure.


---
Full diff: https://github.com/llvm/llvm-project/pull/88654.diff


3 Files Affected:

- (modified) clang/include/clang/AST/DeclBase.h (+25-47) 
- (modified) clang/lib/AST/DeclBase.cpp (+9-22) 
- (modified) clang/lib/Serialization/ASTReaderDecl.cpp (+1-1) 


``diff
diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 4bee18767dd11b..858450926455c6 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -268,37 +268,17 @@ class alignas(8) Decl {
   ///   }
   ///   void A::f(); // SemanticDC == namespace 'A'
   ///// LexicalDC == global namespace
+  llvm::PointerUnion DeclCtx;
 
-  // Compress the InvalidDecl and HasAttrs bits into DeclCtx to keep Decl below
-  // 32 bytes in size
-  llvm::PointerIntPair<
-  llvm::PointerIntPair, 1,
-   bool>,
-  1, bool>
-  DeclCtxWithInvalidDeclAndHasAttrs;
-
-  bool isInSemaDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.is();
-  }
-
-  bool isOutOfSemaDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.is();
-  }
+  bool isInSemaDC() const { return DeclCtx.is(); }
+  bool isOutOfSemaDC() const { return DeclCtx.is(); }
 
   MultipleDC *getMultipleDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.get();
+return DeclCtx.get();
   }
 
   DeclContext *getSemanticDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.get();
+return DeclCtx.get();
   }
 
   /// Loc - The location of this decl.
@@ -308,6 +288,14 @@ class alignas(8) Decl {
   LLVM_PREFERRED_TYPE(Kind)
   unsigned DeclKind : 7;
 
+  /// InvalidDecl - This indicates a semantic error occurred.
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned InvalidDecl :  1;
+
+  /// HasAttrs - This indicates whether the decl has attributes or not.
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned HasAttrs : 1;
+
   /// Implicit - Whether this declaration was implicitly generated by
   /// the implementation rather than explicitly written by the user.
   LLVM_PREFERRED_TYPE(bool)
@@ -405,22 +393,21 @@ class alignas(8) Decl {
 protected:
   Decl(Kind DK, DeclContext *DC, SourceLocation L)
   : NextInContextAndBits(nullptr, getModuleOwnershipKindForChildOf(DC)),
-DeclCtxWithInvalidDeclAndHasAttrs({DC, false}, false), Loc(L),
-DeclKind(DK), Implicit(false), Used(false), Referenced(false),
+DeclCtx(DC), Loc(L), DeclKind(DK), InvalidDecl(false), HasAttrs(false),
+Implicit(false), Used(false), Referenced(false),
 TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
-if (StatisticsEnabled)
-  add(DK);
+if (StatisticsEnabled) add(DK);
   }
 
   Decl(Kind DK, EmptyShell Empty)
-  : DeclKind(DK), Implicit(false), Used(false), Referenced(false),
-TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
+  : DeclKind(DK), InvalidDecl(false), HasAttrs(false), Implicit(false),
+Used(false), Referenced(false), TopLevelDeclInObjCContainer(false),
+Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
-if (StatisticsEnabled)
-  add(DK);
+if (StatisticsEnabled) add(DK);
   }
 
   virtual ~Decl();
@@ -533,9 +520,7 @@ class alignas(8) Decl {
 return AccessSpecifier(Access);
   }
 
-  bool hasAttrs() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer().getInt();
-  }
+  bool hasAttrs() const { return HasAttrs; }
 
   void setAttrs(const AttrVec& Attrs) {
 return setAttrsImpl(Attrs, getASTContext());
@@ -564,17 +549,13 @@ class alignas(8) Decl {
   }
 
   template  void dropAttrs() {
-if (!hasAttrs())
-  return;
+if (!HasAttrs) return;
 
 AttrVec  = getAttrs();
 llvm::erase_if(Vec, [](Attr *A) { return isa(A); });
 
-if (Vec.empty()) {
-  auto InnerPtr = DeclCtxWithInvalidDeclAndHasAttrs.getPointer();
-  InnerPtr.setInt(false);
-  DeclCtxWithInvalidDeclAndHasAttrs.setPointer(InnerPtr);
-}
+if (Vec.empty())
+  HasAttrs = false;
   }
 
   template  void dropAttr() { dropAttrs(); }
@@ -609,10 +590,7 @@ class alignas(8) Decl {
   /// setInvalidDecl - Indicates the Decl had a semantic error. This
   /// allows for graceful error recovery.
   void setInvalidDecl(bool Invalid = true);
-
-  bool isInvalidDecl() const {
-return 

[clang] Revert "[Clang] Reduce the size of Decl and classes derived from it" (PR #88654)

2024-04-14 Thread Nikolas Klauser via cfe-commits

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


[clang] Revert "[Clang] Reduce the size of Decl and classes derived from it" (PR #88654)

2024-04-14 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 created 
https://github.com/llvm/llvm-project/pull/88654

Reverts llvm/llvm-project#87361

On 32 bit platforms there is only a single bit available in the `DeclCtx`, 
resulting in an assertion failure.


>From b243ca1d3616d1dd61b81e3a112707e27cd4c865 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Sun, 14 Apr 2024 12:23:21 +0200
Subject: [PATCH] Revert "[Clang] Reduce the size of Decl and classes derived
 from it (#87361)"

This reverts commit c6f9c84e498ee05a812511ae969773ff166fd25e.
---
 clang/include/clang/AST/DeclBase.h| 72 ---
 clang/lib/AST/DeclBase.cpp| 31 +++---
 clang/lib/Serialization/ASTReaderDecl.cpp |  2 +-
 3 files changed, 35 insertions(+), 70 deletions(-)

diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 4bee18767dd11b..858450926455c6 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -268,37 +268,17 @@ class alignas(8) Decl {
   ///   }
   ///   void A::f(); // SemanticDC == namespace 'A'
   ///// LexicalDC == global namespace
+  llvm::PointerUnion DeclCtx;
 
-  // Compress the InvalidDecl and HasAttrs bits into DeclCtx to keep Decl below
-  // 32 bytes in size
-  llvm::PointerIntPair<
-  llvm::PointerIntPair, 1,
-   bool>,
-  1, bool>
-  DeclCtxWithInvalidDeclAndHasAttrs;
-
-  bool isInSemaDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.is();
-  }
-
-  bool isOutOfSemaDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.is();
-  }
+  bool isInSemaDC() const { return DeclCtx.is(); }
+  bool isOutOfSemaDC() const { return DeclCtx.is(); }
 
   MultipleDC *getMultipleDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.get();
+return DeclCtx.get();
   }
 
   DeclContext *getSemanticDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.get();
+return DeclCtx.get();
   }
 
   /// Loc - The location of this decl.
@@ -308,6 +288,14 @@ class alignas(8) Decl {
   LLVM_PREFERRED_TYPE(Kind)
   unsigned DeclKind : 7;
 
+  /// InvalidDecl - This indicates a semantic error occurred.
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned InvalidDecl :  1;
+
+  /// HasAttrs - This indicates whether the decl has attributes or not.
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned HasAttrs : 1;
+
   /// Implicit - Whether this declaration was implicitly generated by
   /// the implementation rather than explicitly written by the user.
   LLVM_PREFERRED_TYPE(bool)
@@ -405,22 +393,21 @@ class alignas(8) Decl {
 protected:
   Decl(Kind DK, DeclContext *DC, SourceLocation L)
   : NextInContextAndBits(nullptr, getModuleOwnershipKindForChildOf(DC)),
-DeclCtxWithInvalidDeclAndHasAttrs({DC, false}, false), Loc(L),
-DeclKind(DK), Implicit(false), Used(false), Referenced(false),
+DeclCtx(DC), Loc(L), DeclKind(DK), InvalidDecl(false), HasAttrs(false),
+Implicit(false), Used(false), Referenced(false),
 TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
-if (StatisticsEnabled)
-  add(DK);
+if (StatisticsEnabled) add(DK);
   }
 
   Decl(Kind DK, EmptyShell Empty)
-  : DeclKind(DK), Implicit(false), Used(false), Referenced(false),
-TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
+  : DeclKind(DK), InvalidDecl(false), HasAttrs(false), Implicit(false),
+Used(false), Referenced(false), TopLevelDeclInObjCContainer(false),
+Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
-if (StatisticsEnabled)
-  add(DK);
+if (StatisticsEnabled) add(DK);
   }
 
   virtual ~Decl();
@@ -533,9 +520,7 @@ class alignas(8) Decl {
 return AccessSpecifier(Access);
   }
 
-  bool hasAttrs() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer().getInt();
-  }
+  bool hasAttrs() const { return HasAttrs; }
 
   void setAttrs(const AttrVec& Attrs) {
 return setAttrsImpl(Attrs, getASTContext());
@@ -564,17 +549,13 @@ class alignas(8) Decl {
   }
 
   template  void dropAttrs() {
-if (!hasAttrs())
-  return;
+if (!HasAttrs) return;
 
 AttrVec  = getAttrs();
 llvm::erase_if(Vec, [](Attr *A) { return isa(A); });
 
-if (Vec.empty()) {
-  auto InnerPtr = DeclCtxWithInvalidDeclAndHasAttrs.getPointer();
-  InnerPtr.setInt(false);
-  DeclCtxWithInvalidDeclAndHasAttrs.setPointer(InnerPtr);
-}
+if (Vec.empty())
+  HasAttrs = false;
   }
 
   template  void dropAttr() { dropAttrs(); }
@@ -609,10