[clang] [llvm] [NFC] Address bit-field storage sizes to ensure ideal packing (PR #139825)
Oliver Hunt via cfe-commits
cfe-commits at lists.llvm.org
Thu May 15 17:47:02 PDT 2025
https://github.com/ojhunt updated https://github.com/llvm/llvm-project/pull/139825
>From a28452d50023ca12435e2d60933852e1b6728fe1 Mon Sep 17 00:00:00 2001
From: Oliver Hunt <oliver at apple.com>
Date: Tue, 13 May 2025 19:17:27 -0700
Subject: [PATCH 1/5] [NFC] Address bit-field storage sizes to ensure ideal
packing
The MS bit-field packing ABI depends on the storage size of the type
of being placed in the bit-field. This PR addresses a number of cases
in llvm where the storage type has lead to suboptimal packing.
---
llvm/include/llvm/ADT/ImmutableSet.h | 10 +++++++---
llvm/include/llvm/Bitstream/BitCodes.h | 6 ++++--
llvm/include/llvm/Demangle/ItaniumDemangle.h | 10 ++++++----
llvm/include/llvm/IR/Metadata.h | 4 ++--
llvm/include/llvm/IR/ModuleSummaryIndex.h | 4 +++-
llvm/include/llvm/IR/User.h | 4 ++--
6 files changed, 24 insertions(+), 14 deletions(-)
diff --git a/llvm/include/llvm/ADT/ImmutableSet.h b/llvm/include/llvm/ADT/ImmutableSet.h
index 5bee746688ce4..ac86f43b2048e 100644
--- a/llvm/include/llvm/ADT/ImmutableSet.h
+++ b/llvm/include/llvm/ADT/ImmutableSet.h
@@ -20,6 +20,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/iterator.h"
#include "llvm/Support/Allocator.h"
+#include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorHandling.h"
#include <cassert>
#include <cstdint>
@@ -213,9 +214,12 @@ class ImutAVLTree {
ImutAVLTree *next = nullptr;
unsigned height : 28;
- bool IsMutable : 1;
- bool IsDigestCached : 1;
- bool IsCanonicalized : 1;
+ LLVM_PREFERRED_TYPE(bool)
+ unsigned IsMutable : 1;
+ LLVM_PREFERRED_TYPE(bool)
+ unsigned IsDigestCached : 1;
+ LLVM_PREFERRED_TYPE(bool)
+ unsigned IsCanonicalized : 1;
value_type value;
uint32_t digest = 0;
diff --git a/llvm/include/llvm/Bitstream/BitCodes.h b/llvm/include/llvm/Bitstream/BitCodes.h
index 93888f7d3b335..59e937bb2807d 100644
--- a/llvm/include/llvm/Bitstream/BitCodes.h
+++ b/llvm/include/llvm/Bitstream/BitCodes.h
@@ -20,6 +20,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Bitstream/BitCodeEnums.h"
+#include "llvm/Support/Compiler.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/ErrorHandling.h"
#include <cassert>
@@ -32,8 +33,9 @@ namespace llvm {
///
class BitCodeAbbrevOp {
uint64_t Val; // A literal value or data for an encoding.
- bool IsLiteral : 1; // Indicate whether this is a literal value or not.
- unsigned Enc : 3; // The encoding to use.
+ LLVM_PREFERRED_TYPE(bool)
+ uint64_t IsLiteral : 1; // Indicate whether this is a literal value or not.
+ uint64_t Enc : 3; // The encoding to use.
public:
enum Encoding {
Fixed = 1, // A fixed width field, Val specifies number of bits.
diff --git a/llvm/include/llvm/Demangle/ItaniumDemangle.h b/llvm/include/llvm/Demangle/ItaniumDemangle.h
index 295c12ab24916..e560fdf39a205 100644
--- a/llvm/include/llvm/Demangle/ItaniumDemangle.h
+++ b/llvm/include/llvm/Demangle/ItaniumDemangle.h
@@ -19,6 +19,7 @@
#include "DemangleConfig.h"
#include "StringViewExtras.h"
#include "Utility.h"
+#include "llvm/Support/Compiler.h"
#include <algorithm>
#include <cctype>
#include <cstdio>
@@ -164,18 +165,18 @@ class NodeArray;
// traversed by the printLeft/Right functions to produce a demangled string.
class Node {
public:
- enum Kind : unsigned char {
+ enum Kind : unsigned {
#define NODE(NodeKind) K##NodeKind,
#include "ItaniumNodes.def"
};
/// Three-way bool to track a cached value. Unknown is possible if this node
/// has an unexpanded parameter pack below it that may affect this cache.
- enum class Cache : unsigned char { Yes, No, Unknown, };
+ enum class Cache : unsigned { Yes, No, Unknown, };
/// Operator precedence for expression nodes. Used to determine required
/// parens in expression emission.
- enum class Prec {
+ enum class Prec : unsigned {
Primary,
Postfix,
Unary,
@@ -2995,7 +2996,8 @@ template <typename Derived, typename Alloc> struct AbstractManglingParser {
};
char Enc[2]; // Encoding
OIKind Kind; // Kind of operator
- bool Flag : 1; // Entry-specific flag
+ LLVM_PREFERRED_TYPE(bool)
+ unsigned Flag : 1; // Entry-specific flag
Node::Prec Prec : 7; // Precedence
const char *Name; // Spelling
diff --git a/llvm/include/llvm/IR/Metadata.h b/llvm/include/llvm/IR/Metadata.h
index 22ab59be55eb2..3d06edeed6c46 100644
--- a/llvm/include/llvm/IR/Metadata.h
+++ b/llvm/include/llvm/IR/Metadata.h
@@ -1076,8 +1076,8 @@ class MDNode : public Metadata {
/// Explicity set alignment because bitfields by default have an
/// alignment of 1 on z/OS.
struct alignas(alignof(size_t)) Header {
- bool IsResizable : 1;
- bool IsLarge : 1;
+ size_t IsResizable : 1;
+ size_t IsLarge : 1;
size_t SmallSize : 4;
size_t SmallNumOps : 4;
size_t : sizeof(size_t) * CHAR_BIT - 10;
diff --git a/llvm/include/llvm/IR/ModuleSummaryIndex.h b/llvm/include/llvm/IR/ModuleSummaryIndex.h
index 5080fa235905d..65e428a3adea7 100644
--- a/llvm/include/llvm/IR/ModuleSummaryIndex.h
+++ b/llvm/include/llvm/IR/ModuleSummaryIndex.h
@@ -28,6 +28,7 @@
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/Allocator.h"
+#include "llvm/Support/Compiler.h"
#include "llvm/Support/InterleavedRange.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/ScaledNumber.h"
@@ -72,7 +73,8 @@ struct CalleeInfo {
uint32_t Hotness : 3;
// True if at least one of the calls to the callee is a tail call.
- bool HasTailCall : 1;
+ LLVM_PREFERRED_TYPE(bool)
+ uint32_t HasTailCall : 1;
/// The value stored in RelBlockFreq has to be interpreted as the digits of
/// a scaled number with a scale of \p -ScaleShift.
diff --git a/llvm/include/llvm/IR/User.h b/llvm/include/llvm/IR/User.h
index 39e1314bd8130..be99e7a700374 100644
--- a/llvm/include/llvm/IR/User.h
+++ b/llvm/include/llvm/IR/User.h
@@ -79,8 +79,8 @@ class User : public Value {
struct AllocInfo {
public:
const unsigned NumOps : NumUserOperandsBits;
- const bool HasHungOffUses : 1;
- const bool HasDescriptor : 1;
+ const unsigned HasHungOffUses : 1;
+ const unsigned HasDescriptor : 1;
AllocInfo() = delete;
>From 3a2b2f24d0c94035e534f4021522c28de205c4ec Mon Sep 17 00:00:00 2001
From: Oliver Hunt <oliver at apple.com>
Date: Thu, 15 May 2025 03:40:39 -0700
Subject: [PATCH 2/5] More storage fixes
---
clang/include/clang/AST/DeclTemplate.h | 3 ++-
.../clang/Analysis/Analyses/ThreadSafetyTIL.h | 4 +++-
clang/include/clang/Sema/Overload.h | 6 ++++--
clang/include/clang/Sema/ScopeInfo.h | 2 +-
.../clang/StaticAnalyzer/Core/AnalyzerOptions.h | 4 +++-
clang/lib/Basic/DiagnosticIDs.cpp | 14 +++++++-------
llvm/include/llvm/CodeGen/MachineInstr.h | 2 +-
llvm/include/llvm/Support/MathExtras.h | 5 +++++
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h | 4 ++--
llvm/lib/Target/AArch64/AArch64CollectLOH.cpp | 9 ++++++---
llvm/lib/Target/ARM/ARMConstantIslandPass.cpp | 3 ++-
llvm/lib/Target/CSKY/CSKYConstantIslandPass.cpp | 3 ++-
llvm/lib/Target/Mips/MipsConstantIslandPass.cpp | 3 ++-
13 files changed, 40 insertions(+), 22 deletions(-)
diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h
index 80c97681d9163..506cec554972a 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -1859,7 +1859,8 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl,
/// This needs to be cached as deduction is performed during declaration,
/// and we need the information to be preserved so that it is consistent
/// during instantiation.
- bool StrictPackMatch : 1;
+ LLVM_PREFERRED_TYPE(bool)
+ unsigned StrictPackMatch : 1;
protected:
ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK,
diff --git a/clang/include/clang/Analysis/Analyses/ThreadSafetyTIL.h b/clang/include/clang/Analysis/Analyses/ThreadSafetyTIL.h
index 9f365d1a3b655..14c5b679428a3 100644
--- a/clang/include/clang/Analysis/Analyses/ThreadSafetyTIL.h
+++ b/clang/include/clang/Analysis/Analyses/ThreadSafetyTIL.h
@@ -52,6 +52,7 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Casting.h"
+#include "llvm/Support/Compiler.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
@@ -1664,7 +1665,8 @@ class BasicBlock : public SExpr {
unsigned BlockID : 31;
// Bit to determine if a block has been visited during a traversal.
- bool Visited : 1;
+ LLVM_PREFERRED_TYPE(bool)
+ unsigned Visited : 1;
// Predecessor blocks in the CFG.
BlockArray Predecessors;
diff --git a/clang/include/clang/Sema/Overload.h b/clang/include/clang/Sema/Overload.h
index 58452e159821a..808c89b17015e 100644
--- a/clang/include/clang/Sema/Overload.h
+++ b/clang/include/clang/Sema/Overload.h
@@ -980,7 +980,8 @@ class Sema;
/// Have we matched any packs on the parameter side, versus any non-packs on
/// the argument side, in a context where the opposite matching is also
/// allowed?
- bool StrictPackMatch : 1;
+ LLVM_PREFERRED_TYPE(bool)
+ unsigned StrictPackMatch : 1;
/// True if the candidate was found using ADL.
LLVM_PREFERRED_TYPE(CallExpr::ADLCallKind)
@@ -996,7 +997,8 @@ class Sema;
/// FailureKind - The reason why this candidate is not viable.
/// Actually an OverloadFailureKind.
- unsigned char FailureKind;
+ LLVM_PREFERRED_TYPE(OverloadFailureKind)
+ unsigned FailureKind : 8;
/// The number of call arguments that were explicitly provided,
/// to be used while performing partial ordering of function templates.
diff --git a/clang/include/clang/Sema/ScopeInfo.h b/clang/include/clang/Sema/ScopeInfo.h
index 6bf9ae8d074fb..94b247a689c2d 100644
--- a/clang/include/clang/Sema/ScopeInfo.h
+++ b/clang/include/clang/Sema/ScopeInfo.h
@@ -103,7 +103,7 @@ enum class FirstCoroutineStmtKind { CoReturn, CoAwait, CoYield };
/// currently being parsed.
class FunctionScopeInfo {
protected:
- enum ScopeKind {
+ enum ScopeKind : uint8_t {
SK_Function,
SK_Block,
SK_Lambda,
diff --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
index 54c2fb8a60ca1..db7fb9a754021 100644
--- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
+++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
@@ -19,6 +19,7 @@
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Compiler.h"
#include <string>
#include <utility>
#include <vector>
@@ -269,7 +270,8 @@ class AnalyzerOptions {
unsigned NoRetryExhausted : 1;
/// Emit analyzer warnings as errors.
- bool AnalyzerWerror : 1;
+ LLVM_PREFERRED_TYPE(bool)
+ unsigned AnalyzerWerror : 1;
/// The inlining stack depth limit.
unsigned InlineMaxStackDepth;
diff --git a/clang/lib/Basic/DiagnosticIDs.cpp b/clang/lib/Basic/DiagnosticIDs.cpp
index e2d940c0d39e9..984f2f9506bfd 100644
--- a/clang/lib/Basic/DiagnosticIDs.cpp
+++ b/clang/lib/Basic/DiagnosticIDs.cpp
@@ -74,18 +74,18 @@ enum DiagnosticClass {
struct StaticDiagInfoRec {
uint16_t DiagID;
LLVM_PREFERRED_TYPE(diag::Severity)
- uint8_t DefaultSeverity : 3;
+ uint16_t DefaultSeverity : 3;
LLVM_PREFERRED_TYPE(DiagnosticClass)
- uint8_t Class : 3;
+ uint16_t Class : 3;
LLVM_PREFERRED_TYPE(DiagnosticIDs::SFINAEResponse)
- uint8_t SFINAE : 2;
- uint8_t Category : 6;
+ uint16_t SFINAE : 2;
+ uint16_t Category : 6;
LLVM_PREFERRED_TYPE(bool)
- uint8_t WarnNoWerror : 1;
+ uint16_t WarnNoWerror : 1;
LLVM_PREFERRED_TYPE(bool)
- uint8_t WarnShowInSystemHeader : 1;
+ uint16_t WarnShowInSystemHeader : 1;
LLVM_PREFERRED_TYPE(bool)
- uint8_t WarnShowInSystemMacro : 1;
+ uint16_t WarnShowInSystemMacro : 1;
uint16_t OptionGroupIndex : 15;
LLVM_PREFERRED_TYPE(bool)
diff --git a/llvm/include/llvm/CodeGen/MachineInstr.h b/llvm/include/llvm/CodeGen/MachineInstr.h
index 2b7fda1878e35..de88f330855bc 100644
--- a/llvm/include/llvm/CodeGen/MachineInstr.h
+++ b/llvm/include/llvm/CodeGen/MachineInstr.h
@@ -149,7 +149,7 @@ class MachineInstr
/// Various bits of information used by the AsmPrinter to emit helpful
/// comments. This is *not* semantic information. Do not use this for
/// anything other than to convey comment information to AsmPrinter.
- uint8_t AsmPrinterFlags : LLVM_MI_ASMPRINTERFLAGS_BITS;
+ uint32_t AsmPrinterFlags : LLVM_MI_ASMPRINTERFLAGS_BITS;
/// Internal implementation detail class that provides out-of-line storage for
/// extra info used by the machine instruction when this info cannot be stored
diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h
index 246080aa45ce0..c62e698d64d7c 100644
--- a/llvm/include/llvm/Support/MathExtras.h
+++ b/llvm/include/llvm/Support/MathExtras.h
@@ -40,6 +40,9 @@ template <typename T, typename U, typename = enableif_int<T, U>>
using common_sint =
std::common_type_t<std::make_signed_t<T>, std::make_signed_t<U>>;
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wc++17-extensions"
+
/// Mathematical constants.
namespace numbers {
// TODO: Track C++20 std::numbers.
@@ -77,6 +80,8 @@ constexpr float ef = 0x1.5bf0a8P+1F, // (2.71828183) https://oeis.org/A
// clang-format on
} // namespace numbers
+#pragma GCC diagnostic pop
+
/// Create a bitmask with the N right-most bits set to 1, and all other
/// bits set to 0. Only unsigned types are allowed.
template <typename T> T maskTrailingOnes(unsigned N) {
diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
index 7a138a0332b6d..be6eb4c8998bd 100644
--- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
+++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
@@ -63,10 +63,10 @@ class LLVM_LIBRARY_VISIBILITY CodeViewDebug : public DebugHandlerBase {
int DataOffset : 31;
/// Non-zero if this is a piece of an aggregate.
- uint16_t IsSubfield : 1;
+ uint32_t IsSubfield : 1;
/// Offset into aggregate.
- uint16_t StructOffset : 15;
+ uint32_t StructOffset : 15;
/// Register containing the data or the register base of the memory
/// location containing the data.
diff --git a/llvm/lib/Target/AArch64/AArch64CollectLOH.cpp b/llvm/lib/Target/AArch64/AArch64CollectLOH.cpp
index 4d0d99bce258a..c3370cd6e946c 100644
--- a/llvm/lib/Target/AArch64/AArch64CollectLOH.cpp
+++ b/llvm/lib/Target/AArch64/AArch64CollectLOH.cpp
@@ -272,9 +272,12 @@ static int mapRegToGPRIndex(MCRegister Reg) {
/// datastructure for each tracked general purpose register.
struct LOHInfo {
MCLOHType Type : 8; ///< "Best" type of LOH possible.
- bool IsCandidate : 1; ///< Possible LOH candidate.
- bool OneUser : 1; ///< Found exactly one user (yet).
- bool MultiUsers : 1; ///< Found multiple users.
+ LLVM_PREFERRED_TYPE(bool)
+ unsigned IsCandidate : 1; ///< Possible LOH candidate.
+ LLVM_PREFERRED_TYPE(bool)
+ unsigned OneUser : 1; ///< Found exactly one user (yet).
+ LLVM_PREFERRED_TYPE(bool)
+ unsigned MultiUsers : 1; ///< Found multiple users.
const MachineInstr *MI0; ///< First instruction involved in the LOH.
const MachineInstr *MI1; ///< Second instruction involved in the LOH
/// (if any).
diff --git a/llvm/lib/Target/ARM/ARMConstantIslandPass.cpp b/llvm/lib/Target/ARM/ARMConstantIslandPass.cpp
index 89eb49ed416ae..2972316fcee00 100644
--- a/llvm/lib/Target/ARM/ARMConstantIslandPass.cpp
+++ b/llvm/lib/Target/ARM/ARMConstantIslandPass.cpp
@@ -193,7 +193,8 @@ namespace {
struct ImmBranch {
MachineInstr *MI;
unsigned MaxDisp : 31;
- bool isCond : 1;
+ LLVM_PREFERRED_TYPE(bool)
+ unsigned isCond : 1;
unsigned UncondBr;
ImmBranch(MachineInstr *mi, unsigned maxdisp, bool cond, unsigned ubr)
diff --git a/llvm/lib/Target/CSKY/CSKYConstantIslandPass.cpp b/llvm/lib/Target/CSKY/CSKYConstantIslandPass.cpp
index d7f4d4b93f957..e21f4ea45b595 100644
--- a/llvm/lib/Target/CSKY/CSKYConstantIslandPass.cpp
+++ b/llvm/lib/Target/CSKY/CSKYConstantIslandPass.cpp
@@ -184,7 +184,8 @@ class CSKYConstantIslands : public MachineFunctionPass {
struct ImmBranch {
MachineInstr *MI;
unsigned MaxDisp : 31;
- bool IsCond : 1;
+ LLVM_PREFERRED_TYPE(bool)
+ unsigned IsCond : 1;
int UncondBr;
ImmBranch(MachineInstr *Mi, unsigned Maxdisp, bool Cond, int Ubr)
diff --git a/llvm/lib/Target/Mips/MipsConstantIslandPass.cpp b/llvm/lib/Target/Mips/MipsConstantIslandPass.cpp
index c53a73db1dd92..760be36b7667d 100644
--- a/llvm/lib/Target/Mips/MipsConstantIslandPass.cpp
+++ b/llvm/lib/Target/Mips/MipsConstantIslandPass.cpp
@@ -321,7 +321,8 @@ namespace {
struct ImmBranch {
MachineInstr *MI;
unsigned MaxDisp : 31;
- bool isCond : 1;
+ LLVM_PREFERRED_TYPE(bool)
+ unsigned isCond : 1;
int UncondBr;
ImmBranch(MachineInstr *mi, unsigned maxdisp, bool cond, int ubr)
>From 868f0a965ceb2b0af306c62140eb1921a37a70e2 Mon Sep 17 00:00:00 2001
From: Oliver Hunt <oliver at apple.com>
Date: Thu, 15 May 2025 15:04:05 -0700
Subject: [PATCH 3/5] Address erroneous warning in clang <= 19.0
---
clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
index db7fb9a754021..543ac8ab2ab12 100644
--- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
+++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
@@ -412,7 +412,7 @@ class AnalyzerOptions {
// an alias to the new verbose filename option because this
// closely mimics the behavior under the old option.
ShouldWriteStableReportFilename || ShouldWriteVerboseReportFilename,
- AnalyzerWerror,
+ static_cast<bool>(AnalyzerWerror),
ShouldApplyFixIts,
ShouldDisplayCheckerNameForText};
}
>From 980a6fa5e3ac3a52aa8c6768f4bc216199732bc5 Mon Sep 17 00:00:00 2001
From: Oliver Hunt <oliver at apple.com>
Date: Thu, 15 May 2025 17:06:57 -0700
Subject: [PATCH 4/5] More changes to make things better, for a given value of
better
---
clang/include/clang/Basic/DiagnosticCategories.h | 2 +-
clang/lib/Basic/DiagnosticIDs.cpp | 4 ++++
llvm/include/llvm/Bitstream/BitCodes.h | 12 ++++++++----
llvm/include/llvm/Demangle/ItaniumDemangle.h | 9 ++++-----
4 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/clang/include/clang/Basic/DiagnosticCategories.h b/clang/include/clang/Basic/DiagnosticCategories.h
index 839f8dee3ca89..52bb7a268b418 100644
--- a/clang/include/clang/Basic/DiagnosticCategories.h
+++ b/clang/include/clang/Basic/DiagnosticCategories.h
@@ -11,7 +11,7 @@
namespace clang {
namespace diag {
- enum {
+ enum DiagCategory {
#define GET_CATEGORY_TABLE
#define CATEGORY(X, ENUM) ENUM,
#include "clang/Basic/DiagnosticGroups.inc"
diff --git a/clang/lib/Basic/DiagnosticIDs.cpp b/clang/lib/Basic/DiagnosticIDs.cpp
index 984f2f9506bfd..0910b8d340f9b 100644
--- a/clang/lib/Basic/DiagnosticIDs.cpp
+++ b/clang/lib/Basic/DiagnosticIDs.cpp
@@ -18,6 +18,7 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringTable.h"
+#include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Path.h"
#include <map>
@@ -79,6 +80,7 @@ struct StaticDiagInfoRec {
uint16_t Class : 3;
LLVM_PREFERRED_TYPE(DiagnosticIDs::SFINAEResponse)
uint16_t SFINAE : 2;
+ LLVM_PREFERRED_TYPE(diag::DiagCategory)
uint16_t Category : 6;
LLVM_PREFERRED_TYPE(bool)
uint16_t WarnNoWerror : 1;
@@ -87,7 +89,9 @@ struct StaticDiagInfoRec {
LLVM_PREFERRED_TYPE(bool)
uint16_t WarnShowInSystemMacro : 1;
+ LLVM_PREFERRED_TYPE(diag::Group)
uint16_t OptionGroupIndex : 15;
+
LLVM_PREFERRED_TYPE(bool)
uint16_t Deferrable : 1;
diff --git a/llvm/include/llvm/Bitstream/BitCodes.h b/llvm/include/llvm/Bitstream/BitCodes.h
index 59e937bb2807d..205024f754dfb 100644
--- a/llvm/include/llvm/Bitstream/BitCodes.h
+++ b/llvm/include/llvm/Bitstream/BitCodes.h
@@ -32,10 +32,6 @@ namespace llvm {
/// 2. It could be an encoding specification ("this operand encoded like so").
///
class BitCodeAbbrevOp {
- uint64_t Val; // A literal value or data for an encoding.
- LLVM_PREFERRED_TYPE(bool)
- uint64_t IsLiteral : 1; // Indicate whether this is a literal value or not.
- uint64_t Enc : 3; // The encoding to use.
public:
enum Encoding {
Fixed = 1, // A fixed width field, Val specifies number of bits.
@@ -45,6 +41,14 @@ class BitCodeAbbrevOp {
Blob = 5 // 32-bit aligned array of 8-bit characters.
};
+protected:
+ uint64_t Val; // A literal value or data for an encoding.
+ LLVM_PREFERRED_TYPE(bool)
+ uint64_t IsLiteral : 1; // Indicate whether this is a literal value or not.
+ LLVM_PREFERRED_TYPE(Encoding)
+ uint64_t Enc : 3; // The encoding to use.
+
+public:
static bool isValidEncoding(uint64_t E) {
return E >= 1 && E <= 5;
}
diff --git a/llvm/include/llvm/Demangle/ItaniumDemangle.h b/llvm/include/llvm/Demangle/ItaniumDemangle.h
index e560fdf39a205..39770169dd0ab 100644
--- a/llvm/include/llvm/Demangle/ItaniumDemangle.h
+++ b/llvm/include/llvm/Demangle/ItaniumDemangle.h
@@ -165,18 +165,18 @@ class NodeArray;
// traversed by the printLeft/Right functions to produce a demangled string.
class Node {
public:
- enum Kind : unsigned {
+ enum Kind : uint8_t {
#define NODE(NodeKind) K##NodeKind,
#include "ItaniumNodes.def"
};
/// Three-way bool to track a cached value. Unknown is possible if this node
/// has an unexpanded parameter pack below it that may affect this cache.
- enum class Cache : unsigned { Yes, No, Unknown, };
+ enum class Cache : uint8_t { Yes, No, Unknown, };
/// Operator precedence for expression nodes. Used to determine required
/// parens in expression emission.
- enum class Prec : unsigned {
+ enum class Prec : uint8_t {
Primary,
Postfix,
Unary,
@@ -2996,8 +2996,7 @@ template <typename Derived, typename Alloc> struct AbstractManglingParser {
};
char Enc[2]; // Encoding
OIKind Kind; // Kind of operator
- LLVM_PREFERRED_TYPE(bool)
- unsigned Flag : 1; // Entry-specific flag
+ bool Flag : 1; // Entry-specific flag
Node::Prec Prec : 7; // Precedence
const char *Name; // Spelling
>From c74da90ebe820692d3ca0a3d468c18924a5a1c04 Mon Sep 17 00:00:00 2001
From: Oliver Hunt <oliver at apple.com>
Date: Thu, 15 May 2025 17:41:09 -0700
Subject: [PATCH 5/5] add preferred type annotations i inexplicably didn't add
earlier and remove the MathExtras.h noise
---
llvm/include/llvm/Demangle/ItaniumDemangle.h | 2 +-
llvm/include/llvm/IR/User.h | 2 ++
llvm/include/llvm/Support/MathExtras.h | 5 -----
3 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/llvm/include/llvm/Demangle/ItaniumDemangle.h b/llvm/include/llvm/Demangle/ItaniumDemangle.h
index 39770169dd0ab..7c24995e74638 100644
--- a/llvm/include/llvm/Demangle/ItaniumDemangle.h
+++ b/llvm/include/llvm/Demangle/ItaniumDemangle.h
@@ -2996,7 +2996,7 @@ template <typename Derived, typename Alloc> struct AbstractManglingParser {
};
char Enc[2]; // Encoding
OIKind Kind; // Kind of operator
- bool Flag : 1; // Entry-specific flag
+ bool Flag : 1; // Entry-specific flag
Node::Prec Prec : 7; // Precedence
const char *Name; // Spelling
diff --git a/llvm/include/llvm/IR/User.h b/llvm/include/llvm/IR/User.h
index be99e7a700374..25ca8d744a591 100644
--- a/llvm/include/llvm/IR/User.h
+++ b/llvm/include/llvm/IR/User.h
@@ -79,7 +79,9 @@ class User : public Value {
struct AllocInfo {
public:
const unsigned NumOps : NumUserOperandsBits;
+ LLVM_PREFERRED_TYPE(bool)
const unsigned HasHungOffUses : 1;
+ LLVM_PREFERRED_TYPE(bool)
const unsigned HasDescriptor : 1;
AllocInfo() = delete;
diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h
index c62e698d64d7c..246080aa45ce0 100644
--- a/llvm/include/llvm/Support/MathExtras.h
+++ b/llvm/include/llvm/Support/MathExtras.h
@@ -40,9 +40,6 @@ template <typename T, typename U, typename = enableif_int<T, U>>
using common_sint =
std::common_type_t<std::make_signed_t<T>, std::make_signed_t<U>>;
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wc++17-extensions"
-
/// Mathematical constants.
namespace numbers {
// TODO: Track C++20 std::numbers.
@@ -80,8 +77,6 @@ constexpr float ef = 0x1.5bf0a8P+1F, // (2.71828183) https://oeis.org/A
// clang-format on
} // namespace numbers
-#pragma GCC diagnostic pop
-
/// Create a bitmask with the N right-most bits set to 1, and all other
/// bits set to 0. Only unsigned types are allowed.
template <typename T> T maskTrailingOnes(unsigned N) {
More information about the cfe-commits
mailing list