Skip to content

Commit 76ba29b

Browse files
authored
[NFC] Address bit-field storage sizes to ensure ideal packing (#139825)
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.
1 parent c41812e commit 76ba29b

File tree

19 files changed

+69
-38
lines changed

19 files changed

+69
-38
lines changed

clang/include/clang/AST/DeclTemplate.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1858,7 +1858,8 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl,
18581858
/// This needs to be cached as deduction is performed during declaration,
18591859
/// and we need the information to be preserved so that it is consistent
18601860
/// during instantiation.
1861-
bool StrictPackMatch : 1;
1861+
LLVM_PREFERRED_TYPE(bool)
1862+
unsigned StrictPackMatch : 1;
18621863

18631864
protected:
18641865
ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK,

clang/include/clang/Analysis/Analyses/ThreadSafetyTIL.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include "llvm/ADT/ArrayRef.h"
5353
#include "llvm/ADT/StringRef.h"
5454
#include "llvm/Support/Casting.h"
55+
#include "llvm/Support/Compiler.h"
5556
#include "llvm/Support/raw_ostream.h"
5657
#include <algorithm>
5758
#include <cassert>
@@ -1664,7 +1665,8 @@ class BasicBlock : public SExpr {
16641665
unsigned BlockID : 31;
16651666

16661667
// Bit to determine if a block has been visited during a traversal.
1667-
bool Visited : 1;
1668+
LLVM_PREFERRED_TYPE(bool)
1669+
unsigned Visited : 1;
16681670

16691671
// Predecessor blocks in the CFG.
16701672
BlockArray Predecessors;

clang/include/clang/Basic/DiagnosticCategories.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace clang {
1313
namespace diag {
14-
enum {
14+
enum DiagCategory {
1515
#define GET_CATEGORY_TABLE
1616
#define CATEGORY(X, ENUM) ENUM,
1717
#include "clang/Basic/DiagnosticGroups.inc"

clang/include/clang/Sema/Overload.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,8 @@ class Sema;
986986
/// Have we matched any packs on the parameter side, versus any non-packs on
987987
/// the argument side, in a context where the opposite matching is also
988988
/// allowed?
989-
bool StrictPackMatch : 1;
989+
LLVM_PREFERRED_TYPE(bool)
990+
unsigned StrictPackMatch : 1;
990991

991992
/// True if the candidate was found using ADL.
992993
LLVM_PREFERRED_TYPE(CallExpr::ADLCallKind)
@@ -1002,7 +1003,8 @@ class Sema;
10021003

10031004
/// FailureKind - The reason why this candidate is not viable.
10041005
/// Actually an OverloadFailureKind.
1005-
unsigned char FailureKind;
1006+
LLVM_PREFERRED_TYPE(OverloadFailureKind)
1007+
unsigned FailureKind : 8;
10061008

10071009
/// The number of call arguments that were explicitly provided,
10081010
/// to be used while performing partial ordering of function templates.

clang/include/clang/Sema/ScopeInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ enum class FirstCoroutineStmtKind { CoReturn, CoAwait, CoYield };
103103
/// currently being parsed.
104104
class FunctionScopeInfo {
105105
protected:
106-
enum ScopeKind {
106+
enum ScopeKind : uint8_t {
107107
SK_Function,
108108
SK_Block,
109109
SK_Lambda,

clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/ADT/IntrusiveRefCntPtr.h"
2020
#include "llvm/ADT/StringMap.h"
2121
#include "llvm/ADT/StringRef.h"
22+
#include "llvm/Support/Compiler.h"
2223
#include <string>
2324
#include <utility>
2425
#include <vector>
@@ -269,7 +270,8 @@ class AnalyzerOptions {
269270
unsigned NoRetryExhausted : 1;
270271

271272
/// Emit analyzer warnings as errors.
272-
bool AnalyzerWerror : 1;
273+
LLVM_PREFERRED_TYPE(bool)
274+
unsigned AnalyzerWerror : 1;
273275

274276
/// The inlining stack depth limit.
275277
unsigned InlineMaxStackDepth;
@@ -410,7 +412,7 @@ class AnalyzerOptions {
410412
// an alias to the new verbose filename option because this
411413
// closely mimics the behavior under the old option.
412414
ShouldWriteStableReportFilename || ShouldWriteVerboseReportFilename,
413-
AnalyzerWerror,
415+
static_cast<bool>(AnalyzerWerror),
414416
ShouldApplyFixIts,
415417
ShouldDisplayCheckerNameForText};
416418
}

clang/lib/Basic/DiagnosticIDs.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/ADT/STLExtras.h"
1919
#include "llvm/ADT/SmallVector.h"
2020
#include "llvm/ADT/StringTable.h"
21+
#include "llvm/Support/Compiler.h"
2122
#include "llvm/Support/ErrorHandling.h"
2223
#include "llvm/Support/Path.h"
2324
#include <map>
@@ -74,19 +75,21 @@ enum DiagnosticClass {
7475
struct StaticDiagInfoRec {
7576
uint16_t DiagID;
7677
LLVM_PREFERRED_TYPE(diag::Severity)
77-
uint8_t DefaultSeverity : 3;
78+
uint16_t DefaultSeverity : 3;
7879
LLVM_PREFERRED_TYPE(DiagnosticClass)
79-
uint8_t Class : 3;
80+
uint16_t Class : 3;
8081
LLVM_PREFERRED_TYPE(DiagnosticIDs::SFINAEResponse)
81-
uint8_t SFINAE : 2;
82-
uint8_t Category : 6;
82+
uint16_t SFINAE : 2;
83+
LLVM_PREFERRED_TYPE(diag::DiagCategory)
84+
uint16_t Category : 6;
8385
LLVM_PREFERRED_TYPE(bool)
84-
uint8_t WarnNoWerror : 1;
86+
uint16_t WarnNoWerror : 1;
8587
LLVM_PREFERRED_TYPE(bool)
86-
uint8_t WarnShowInSystemHeader : 1;
88+
uint16_t WarnShowInSystemHeader : 1;
8789
LLVM_PREFERRED_TYPE(bool)
88-
uint8_t WarnShowInSystemMacro : 1;
90+
uint16_t WarnShowInSystemMacro : 1;
8991

92+
LLVM_PREFERRED_TYPE(diag::Group)
9093
uint16_t OptionGroupIndex : 15;
9194
LLVM_PREFERRED_TYPE(bool)
9295
uint16_t Deferrable : 1;

llvm/include/llvm/ADT/ImmutableSet.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "llvm/ADT/SmallVector.h"
2121
#include "llvm/ADT/iterator.h"
2222
#include "llvm/Support/Allocator.h"
23+
#include "llvm/Support/Compiler.h"
2324
#include "llvm/Support/ErrorHandling.h"
2425
#include <cassert>
2526
#include <cstdint>
@@ -213,9 +214,12 @@ class ImutAVLTree {
213214
ImutAVLTree *next = nullptr;
214215

215216
unsigned height : 28;
216-
bool IsMutable : 1;
217-
bool IsDigestCached : 1;
218-
bool IsCanonicalized : 1;
217+
LLVM_PREFERRED_TYPE(bool)
218+
unsigned IsMutable : 1;
219+
LLVM_PREFERRED_TYPE(bool)
220+
unsigned IsDigestCached : 1;
221+
LLVM_PREFERRED_TYPE(bool)
222+
unsigned IsCanonicalized : 1;
219223

220224
value_type value;
221225
uint32_t digest = 0;

llvm/include/llvm/Bitstream/BitCodes.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "llvm/ADT/SmallVector.h"
2121
#include "llvm/ADT/StringExtras.h"
2222
#include "llvm/Bitstream/BitCodeEnums.h"
23+
#include "llvm/Support/Compiler.h"
2324
#include "llvm/Support/DataTypes.h"
2425
#include "llvm/Support/ErrorHandling.h"
2526
#include <cassert>
@@ -31,9 +32,6 @@ namespace llvm {
3132
/// 2. It could be an encoding specification ("this operand encoded like so").
3233
///
3334
class BitCodeAbbrevOp {
34-
uint64_t Val; // A literal value or data for an encoding.
35-
bool IsLiteral : 1; // Indicate whether this is a literal value or not.
36-
unsigned Enc : 3; // The encoding to use.
3735
public:
3836
enum Encoding {
3937
Fixed = 1, // A fixed width field, Val specifies number of bits.
@@ -43,6 +41,14 @@ class BitCodeAbbrevOp {
4341
Blob = 5 // 32-bit aligned array of 8-bit characters.
4442
};
4543

44+
protected:
45+
uint64_t Val; // A literal value or data for an encoding.
46+
LLVM_PREFERRED_TYPE(bool)
47+
uint64_t IsLiteral : 1; // Indicate whether this is a literal value or not.
48+
LLVM_PREFERRED_TYPE(Encoding)
49+
uint64_t Enc : 3; // The encoding to use.
50+
51+
public:
4652
static bool isValidEncoding(uint64_t E) {
4753
return E >= 1 && E <= 5;
4854
}

llvm/include/llvm/CodeGen/MachineInstr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class MachineInstr
149149
/// Various bits of information used by the AsmPrinter to emit helpful
150150
/// comments. This is *not* semantic information. Do not use this for
151151
/// anything other than to convey comment information to AsmPrinter.
152-
uint8_t AsmPrinterFlags : LLVM_MI_ASMPRINTERFLAGS_BITS;
152+
uint32_t AsmPrinterFlags : LLVM_MI_ASMPRINTERFLAGS_BITS;
153153

154154
/// Internal implementation detail class that provides out-of-line storage for
155155
/// extra info used by the machine instruction when this info cannot be stored

0 commit comments

Comments
 (0)