[clang] 3ec78d9 - [Clang] NFCI: Add a new bit HasExtraBitfields to FunctionType.
Sander de Smalen via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 1 03:41:10 PDT 2022
Author: Sander de Smalen
Date: 2022-06-01T12:40:33+02:00
New Revision: 3ec78d9ff1b3f430dab27434fe8f9a3790d08808
URL: https://github.com/llvm/llvm-project/commit/3ec78d9ff1b3f430dab27434fe8f9a3790d08808
DIFF: https://github.com/llvm/llvm-project/commit/3ec78d9ff1b3f430dab27434fe8f9a3790d08808.diff
LOG: [Clang] NFCI: Add a new bit HasExtraBitfields to FunctionType.
The FunctionTypeExtraBitfields is currently only available when the
ExceptionSpecificationType == Dynamic, which means that there is no other
way to use or extend the FunctionTypeExtraBitfields independently of the
exception specification type.
This patch adds a new field HasExtraBitfields to specify
whether the prototype has trailing ExtraBitfields.
This patch intends to be NFC and is required for future extension
and use of the ExtraBitfields struct.
Reviewed By: aaron.ballman, erichkeane
Differential Revision: https://reviews.llvm.org/D126642
Added:
Modified:
clang/include/clang/AST/Type.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/Type.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 45b75fe7960c3..5784839f4f961 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1624,6 +1624,9 @@ class alignas(8) Type : public ExtQualsTypeCommonBase {
/// Whether this function has extended parameter information.
unsigned HasExtParameterInfos : 1;
+ /// Whether this function has extra bitfields for the prototype.
+ unsigned HasExtraBitfields : 1;
+
/// Whether the function is variadic.
unsigned Variadic : 1;
@@ -3798,13 +3801,12 @@ class FunctionType : public Type {
/// A simple holder for various uncommon bits which do not fit in
/// FunctionTypeBitfields. Aligned to alignof(void *) to maintain the
- /// alignment of subsequent objects in TrailingObjects. You must update
- /// hasExtraBitfields in FunctionProtoType after adding extra data here.
+ /// alignment of subsequent objects in TrailingObjects.
struct alignas(void *) FunctionTypeExtraBitfields {
/// The number of types in the exception specification.
/// A whole unsigned is not needed here and according to
/// [implimits] 8 bits would be enough here.
- unsigned NumExceptionType;
+ unsigned NumExceptionType = 0;
};
protected:
@@ -3998,6 +4000,10 @@ class FunctionProtoType final
Result.ExceptionSpec = ESI;
return Result;
}
+
+ bool requiresFunctionProtoTypeExtraBitfields() const {
+ return ExceptionSpec.Type == EST_Dynamic;
+ }
};
private:
@@ -4088,16 +4094,13 @@ class FunctionProtoType final
return getExceptionSpecSize(getExceptionSpecType(), getNumExceptions());
}
- /// Whether the trailing FunctionTypeExtraBitfields is present.
- static bool hasExtraBitfields(ExceptionSpecificationType EST) {
- // If the exception spec type is EST_Dynamic then we have > 0 exception
- // types and the exact number is stored in FunctionTypeExtraBitfields.
- return EST == EST_Dynamic;
- }
-
/// Whether the trailing FunctionTypeExtraBitfields is present.
bool hasExtraBitfields() const {
- return hasExtraBitfields(getExceptionSpecType());
+ assert((getExceptionSpecType() != EST_Dynamic ||
+ FunctionTypeBits.HasExtraBitfields) &&
+ "ExtraBitfields are required for given ExceptionSpecType");
+ return FunctionTypeBits.HasExtraBitfields;
+
}
bool hasExtQualifiers() const {
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 1ee18f913b914..6349d7b7c46f3 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -4451,8 +4451,7 @@ QualType ASTContext::getFunctionTypeInternal(
QualType, SourceLocation, FunctionType::FunctionTypeExtraBitfields,
FunctionType::ExceptionType, Expr *, FunctionDecl *,
FunctionProtoType::ExtParameterInfo, Qualifiers>(
- NumArgs, EPI.Variadic,
- FunctionProtoType::hasExtraBitfields(EPI.ExceptionSpec.Type),
+ NumArgs, EPI.Variadic, EPI.requiresFunctionProtoTypeExtraBitfields(),
ESH.NumExceptionType, ESH.NumExprPtr, ESH.NumFunctionDeclPtr,
EPI.ExtParameterInfos ? NumArgs : 0,
EPI.TypeQuals.hasNonFastQualifiers() ? 1 : 0);
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index ece4165c51f53..0f168a518707e 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -3213,12 +3213,15 @@ FunctionProtoType::FunctionProtoType(QualType result, ArrayRef<QualType> params,
FunctionTypeBits.Variadic = epi.Variadic;
FunctionTypeBits.HasTrailingReturn = epi.HasTrailingReturn;
- // Fill in the extra trailing bitfields if present.
- if (hasExtraBitfields(epi.ExceptionSpec.Type)) {
+ if (epi.requiresFunctionProtoTypeExtraBitfields()) {
+ FunctionTypeBits.HasExtraBitfields = true;
auto &ExtraBits = *getTrailingObjects<FunctionTypeExtraBitfields>();
- ExtraBits.NumExceptionType = epi.ExceptionSpec.Exceptions.size();
+ ExtraBits = FunctionTypeExtraBitfields();
+ } else {
+ FunctionTypeBits.HasExtraBitfields = false;
}
+
// Fill in the trailing argument array.
auto *argSlot = getTrailingObjects<QualType>();
for (unsigned i = 0; i != getNumParams(); ++i) {
@@ -3229,6 +3232,9 @@ FunctionProtoType::FunctionProtoType(QualType result, ArrayRef<QualType> params,
// Fill in the exception type array if present.
if (getExceptionSpecType() == EST_Dynamic) {
+ auto &ExtraBits = *getTrailingObjects<FunctionTypeExtraBitfields>();
+ ExtraBits.NumExceptionType = epi.ExceptionSpec.Exceptions.size();
+
assert(hasExtraBitfields() && "missing trailing extra bitfields!");
auto *exnSlot =
reinterpret_cast<QualType *>(getTrailingObjects<ExceptionType>());
More information about the cfe-commits
mailing list