https://github.com/PrabbyDD updated https://github.com/llvm/llvm-project/pull/195945
>From 36ce4b83c0c674cdc6439f49a90c59ee5bdc613a Mon Sep 17 00:00:00 2001 From: PrabbyDD <[email protected]> Date: Tue, 5 May 2026 14:16:55 -0700 Subject: [PATCH 1/2] Fix crash by checking for the type signage before entering getCorrespondingSignedType() --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaExpr.cpp | 18 +++++++++++------- clang/test/Sema/va_arg_enum_underlying.cpp | 15 +++++++++++++++ 3 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 clang/test/Sema/va_arg_enum_underlying.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index ec64c2008d89b..f01a73739d8e0 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -519,6 +519,7 @@ Bug Fixes in This Version - Clang now emits an error for friend declarations of lambda members. (#GH26540) - Fixed a crash caused by lambda capture handling in delayed default arguments. (#GH176534) - Fixed a crash when parsing invalid ``static_assert`` declarations with string-literal messages (#GH187690). +- Fixed an assert/crash in ``__builtin_va_arg`` when the argument type is an enum without a correspoding signed type (#GH191698). Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index c494669420282..2712acb0d0936 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -17314,13 +17314,17 @@ ExprResult Sema::BuildVAArgExpr(SourceLocation BuiltinLoc, if (!PromoteType.isNull() && !UnderlyingType->isBooleanType() && PromoteType->isUnsignedIntegerType() != UnderlyingType->isUnsignedIntegerType()) { - UnderlyingType = - UnderlyingType->isUnsignedIntegerType() - ? Context.getCorrespondingSignedType(UnderlyingType) - : Context.getCorrespondingUnsignedType(UnderlyingType); - if (Context.typesAreCompatible(PromoteType, UnderlyingType, - /*CompareUnqualified*/ true)) - PromoteType = QualType(); + + if (!UnderlyingType->isUnsignedIntegerType() || + UnderlyingType->hasSignedIntegerRepresentation()) { + UnderlyingType = + UnderlyingType->isUnsignedIntegerType() + ? Context.getCorrespondingSignedType(UnderlyingType) + : Context.getCorrespondingUnsignedType(UnderlyingType); + if (Context.typesAreCompatible(PromoteType, UnderlyingType, + /*CompareUnqualified*/ true)) + PromoteType = QualType(); + } } } if (TInfo->getType()->isSpecificBuiltinType(BuiltinType::Float)) diff --git a/clang/test/Sema/va_arg_enum_underlying.cpp b/clang/test/Sema/va_arg_enum_underlying.cpp new file mode 100644 index 0000000000000..e4962f4e1326e --- /dev/null +++ b/clang/test/Sema/va_arg_enum_underlying.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +__builtin_va_list ap; + +void foo() { + enum E1 : char16_t {}; + enum E2 : char32_t {}; + enum E3 : unsigned char {}; + enum E4 : wchar_t {}; + + (void)__builtin_va_arg(ap, E1); // expected-warning {{second argument to 'va_arg' is of promotable type}} + (void)__builtin_va_arg(ap, E2); // expected-warning {{second argument to 'va_arg' is of promotable type}} + (void)__builtin_va_arg(ap, E3); // expected-warning {{second argument to 'va_arg' is of promotable type}} + (void)__builtin_va_arg(ap, E4); // expected-warning {{second argument to 'va_arg' is of promotable type}} +} >From 14b664ec4a3b1251679b71c93f3eca3e37168d8f Mon Sep 17 00:00:00 2001 From: PrabbyDD <[email protected]> Date: Tue, 5 May 2026 14:46:42 -0700 Subject: [PATCH 2/2] adding an expected warning to varargs test since we now emit that --- clang/test/SemaCXX/varargs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/SemaCXX/varargs.cpp b/clang/test/SemaCXX/varargs.cpp index 1e5920a8728d3..c84d765296e88 100644 --- a/clang/test/SemaCXX/varargs.cpp +++ b/clang/test/SemaCXX/varargs.cpp @@ -31,7 +31,7 @@ void record_context(int a, ...) { // Ensure the correct behavior for promotable type UB checking. void promotable(int a, ...) { enum Unscoped1 { One = 0x7FFFFFFF }; - (void)__builtin_va_arg(ap, Unscoped1); // ok + (void)__builtin_va_arg(ap, Unscoped1); // expected-warning {{second argument to 'va_arg' is of promotable type}} enum Unscoped2 { Two = 0xFFFFFFFF }; (void)__builtin_va_arg(ap, Unscoped2); // ok _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
