Skip to content

Commit c033f0d

Browse files
egorzhdanjansvoboda11
authored andcommitted
[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
1 parent 080f372 commit c033f0d

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

clang/lib/Sema/SemaExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15946,7 +15946,7 @@ ExprResult Sema::BuildVAArgExpr(SourceLocation BuiltinLoc,
1594615946
// promoted type and the underlying type are the same except for
1594715947
// signedness. Ask the AST for the correctly corresponding type and see
1594815948
// if that's compatible.
15949-
if (!PromoteType.isNull() &&
15949+
if (!PromoteType.isNull() && !UnderlyingType->isBooleanType() &&
1595015950
PromoteType->isUnsignedIntegerType() !=
1595115951
UnderlyingType->isUnsignedIntegerType()) {
1595215952
UnderlyingType =

clang/test/SemaCXX/varargs.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ void promotable(int a, ...) {
5353

5454
// Ensure that signed vs unsigned doesn't matter either.
5555
(void)__builtin_va_arg(ap, unsigned int);
56+
57+
(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'}}
5658
}
5759

5860
#if __cplusplus >= 201103L

0 commit comments

Comments
 (0)