Author: Egor Zhdan Date: 2022-01-07T23:57:55-08:00 New Revision: bfb1bd1b9906356c747ac480bc44230790c87cb1
URL: https://github.com/llvm/llvm-project/commit/bfb1bd1b9906356c747ac480bc44230790c87cb1 DIFF: https://github.com/llvm/llvm-project/commit/bfb1bd1b9906356c747ac480bc44230790c87cb1.diff LOG: [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 c033f0d9b1c7816b0488a939475d48a100e4dcab) Added: Modified: clang/lib/Sema/SemaExpr.cpp clang/test/SemaCXX/varargs.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index f04eb91990244..4179249e91de5 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -15868,7 +15868,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 = diff --git a/clang/test/SemaCXX/varargs.cpp b/clang/test/SemaCXX/varargs.cpp index 7bec2f1e63030..bc2fe89a6ff8d 100644 --- a/clang/test/SemaCXX/varargs.cpp +++ b/clang/test/SemaCXX/varargs.cpp @@ -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 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits