[Clang][Sema] Avoid crashing for va_arg expressions with bool argument

This change fixes a compiler crash that was introduced in https://reviews.llvm.org/D103611: `Sema::BuildVAArgExpr` attempted to retrieve a corresponding signed type for `bool` by calling `ASTContext::getCorrespondingSignedType`.

rdar://86580370

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D116272
This commit is contained in:
Egor Zhdan 2022-01-07 10:30:25 +01:00 committed by Jan Svoboda
parent 080f372ad3
commit c033f0d9b1
2 changed files with 3 additions and 1 deletions

View File

@ -15946,7 +15946,7 @@ ExprResult Sema::BuildVAArgExpr(SourceLocation BuiltinLoc,
// promoted type and the underlying type are the same except for
// signedness. Ask the AST for the correctly corresponding type and see
// if that's compatible.
if (!PromoteType.isNull() &&
if (!PromoteType.isNull() && !UnderlyingType->isBooleanType() &&
PromoteType->isUnsignedIntegerType() !=
UnderlyingType->isUnsignedIntegerType()) {
UnderlyingType =

View File

@ -53,6 +53,8 @@ void promotable(int a, ...) {
// Ensure that signed vs unsigned doesn't matter either.
(void)__builtin_va_arg(ap, unsigned int);
(void)__builtin_va_arg(ap, bool); // expected-warning {{second argument to 'va_arg' is of promotable type 'bool'; this va_arg has undefined behavior because arguments will be promoted to 'int'}}
}
#if __cplusplus >= 201103L