[clang] e3f684d - [clang][NFC] Refactor bit-fields in `DefaultedFunctionKind`
Vlad Serebrennikov via cfe-commits
cfe-commits at lists.llvm.org
Sun Feb 11 06:27:47 PST 2024
Author: Vlad Serebrennikov
Date: 2024-02-11T17:27:31+03:00
New Revision: e3f684d86b308bc2576d813aad1a230aa6b295ab
URL: https://github.com/llvm/llvm-project/commit/e3f684d86b308bc2576d813aad1a230aa6b295ab
DIFF: https://github.com/llvm/llvm-project/commit/e3f684d86b308bc2576d813aad1a230aa6b295ab.diff
LOG: [clang][NFC] Refactor bit-fields in `DefaultedFunctionKind`
This patch makes all bit-fields in `DefaultedFunctionKind` of type `unsigned`, which brings `sizeof(DefaultedFunctionKind)` down from 8 to 4 when compiling Clang for Microsoft ABI.
Added:
Modified:
clang/include/clang/Sema/Sema.h
Removed:
################################################################################
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 3c26003b5bda7f..851560f759f0e4 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3501,29 +3501,29 @@ class Sema final {
/// For a defaulted function, the kind of defaulted function that it is.
class DefaultedFunctionKind {
- CXXSpecialMember SpecialMember : 8;
- DefaultedComparisonKind Comparison : 8;
+ unsigned SpecialMember : 8;
+ unsigned Comparison : 8;
public:
DefaultedFunctionKind()
- : SpecialMember(CXXInvalid), Comparison(DefaultedComparisonKind::None) {
+ : SpecialMember(CXXInvalid), Comparison(llvm::to_underlying(DefaultedComparisonKind::None)) {
}
DefaultedFunctionKind(CXXSpecialMember CSM)
- : SpecialMember(CSM), Comparison(DefaultedComparisonKind::None) {}
+ : SpecialMember(CSM), Comparison(llvm::to_underlying(DefaultedComparisonKind::None)) {}
DefaultedFunctionKind(DefaultedComparisonKind Comp)
- : SpecialMember(CXXInvalid), Comparison(Comp) {}
+ : SpecialMember(CXXInvalid), Comparison(llvm::to_underlying(Comp)) {}
bool isSpecialMember() const { return SpecialMember != CXXInvalid; }
bool isComparison() const {
- return Comparison != DefaultedComparisonKind::None;
+ return static_cast<DefaultedComparisonKind>(Comparison) != DefaultedComparisonKind::None;
}
explicit operator bool() const {
return isSpecialMember() || isComparison();
}
- CXXSpecialMember asSpecialMember() const { return SpecialMember; }
- DefaultedComparisonKind asComparison() const { return Comparison; }
+ CXXSpecialMember asSpecialMember() const { return static_cast<CXXSpecialMember>(SpecialMember); }
+ DefaultedComparisonKind asComparison() const { return static_cast<DefaultedComparisonKind>(Comparison); }
/// Get the index of this function kind for use in diagnostics.
unsigned getDiagnosticIndex() const {
@@ -3531,7 +3531,7 @@ class Sema final {
"invalid should have highest index");
static_assert((unsigned)DefaultedComparisonKind::None == 0,
"none should be equal to zero");
- return SpecialMember + (unsigned)Comparison;
+ return SpecialMember + Comparison;
}
};
More information about the cfe-commits
mailing list