forked from OSchip/llvm-project
[clang][AST] Widen TypeTraitExprBitfields.NumArgs to 16 bits.
`32 - 8 - 1 - NumExprBits` is now only equal to 6, which is way too small. Add a test so that this does not happen again.
This commit is contained in:
parent
6d0f8345ac
commit
8dcc7eecb7
|
@ -775,8 +775,10 @@ protected:
|
|||
/// the trait evaluated true or false.
|
||||
unsigned Value : 1;
|
||||
|
||||
/// The number of arguments to this type trait.
|
||||
unsigned NumArgs : 32 - 8 - 1 - NumExprBits;
|
||||
/// The number of arguments to this type trait. According to [implimits]
|
||||
/// 8 bits would be enough, but we require (and test for) at least 16 bits
|
||||
/// to mirror FunctionType.
|
||||
unsigned NumArgs;
|
||||
};
|
||||
|
||||
class DependentScopeDeclRefExprBitfields {
|
||||
|
|
|
@ -1580,8 +1580,12 @@ TypeTraitExpr::TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
|
|||
: Expr(TypeTraitExprClass, T, VK_RValue, OK_Ordinary), Loc(Loc),
|
||||
RParenLoc(RParenLoc) {
|
||||
TypeTraitExprBits.Kind = Kind;
|
||||
assert(static_cast<unsigned>(Kind) == TypeTraitExprBits.Kind &&
|
||||
"TypeTraitExprBits.Kind overflow!");
|
||||
TypeTraitExprBits.Value = Value;
|
||||
TypeTraitExprBits.NumArgs = Args.size();
|
||||
assert(Args.size() == TypeTraitExprBits.NumArgs &&
|
||||
"TypeTraitExprBits.NumArgs overflow!");
|
||||
|
||||
auto **ToArgs = getTrailingObjects<TypeSourceInfo *>();
|
||||
for (unsigned I = 0, N = Args.size(); I != N; ++I)
|
||||
|
|
|
@ -2829,3 +2829,35 @@ namespace ConstClass {
|
|||
};
|
||||
static_assert(!__is_trivially_assignable(B&, const B&), "");
|
||||
}
|
||||
|
||||
namespace type_trait_expr_numargs_overflow {
|
||||
// Make sure that TypeTraitExpr can store 16 bits worth of arguments.
|
||||
struct S {
|
||||
template <typename... Ts> S(Ts... ts) {
|
||||
static_assert(sizeof...(ts) == 32768+1, "");
|
||||
}
|
||||
};
|
||||
|
||||
#define T4(X) X,X,X,X
|
||||
#define T16(X) T4(X),T4(X),T4(X),T4(X)
|
||||
#define T64(X) T16(X),T16(X),T16(X),T16(X)
|
||||
#define T256(X) T64(X),T64(X),T64(X),T64(X)
|
||||
#define T1024(X) T256(X),T256(X),T256(X),T256(X)
|
||||
#define T4096(X) T1024(X),T1024(X),T1024(X),T1024(X)
|
||||
#define T16384(X) T4096(X),T4096(X),T4096(X),T4096(X)
|
||||
#define T32768(X) T16384(X),T16384(X)
|
||||
|
||||
void test() {
|
||||
static_assert(__is_constructible(S, T32768(int), float), "");
|
||||
}
|
||||
|
||||
#undef T4
|
||||
#undef T16
|
||||
#undef T64
|
||||
#undef T256
|
||||
#undef T1024
|
||||
#undef T4096
|
||||
#undef T16384
|
||||
#undef T32768
|
||||
|
||||
} // namespace type_trait_expr_numargs_overflow
|
||||
|
|
Loading…
Reference in New Issue