Skip to content

Commit bfb1bd1

Browse files
egorzhdantstellar
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 (cherry picked from commit c033f0d)
1 parent 1ac6bb3 commit bfb1bd1

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
@@ -15868,7 +15868,7 @@ ExprResult Sema::BuildVAArgExpr(SourceLocation BuiltinLoc,
1586815868
// promoted type and the underlying type are the same except for
1586915869
// signedness. Ask the AST for the correctly corresponding type and see
1587015870
// if that's compatible.
15871-
if (!PromoteType.isNull() &&
15871+
if (!PromoteType.isNull() && !UnderlyingType->isBooleanType() &&
1587215872
PromoteType->isUnsignedIntegerType() !=
1587315873
UnderlyingType->isUnsignedIntegerType()) {
1587415874
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)