https://github.com/Rajveer100 created https://github.com/llvm/llvm-project/pull/200574
Resolves #200112 By early checking for placeholder expressions, crash can be avoided for unreachable builtin type when fetching type info. >From d647b420447aed3a5454e465368ea18ce462c002 Mon Sep 17 00:00:00 2001 From: Rajveer <[email protected]> Date: Sat, 30 May 2026 18:31:33 +0530 Subject: [PATCH] [clang][SemaCXX] Fix crash caused by unresolved overloaded function type when using `__builtin_bit_cast` Resolves #200112 By early checking for placeholder expressions, crash can be avoided for unreachable builtin type when fetching type info. --- clang/lib/Sema/SemaCast.cpp | 7 +++++++ clang/test/SemaCXX/builtin-bit-cast.cpp | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp index 0040f3aa1a891..311fdcf8f6efa 100644 --- a/clang/lib/Sema/SemaCast.cpp +++ b/clang/lib/Sema/SemaCast.cpp @@ -439,6 +439,13 @@ ExprResult Sema::ActOnBuiltinBitCastExpr(SourceLocation KWLoc, Declarator &D, ExprResult Sema::BuildBuiltinBitCastExpr(SourceLocation KWLoc, TypeSourceInfo *TSI, Expr *Operand, SourceLocation RParenLoc) { + if (Operand && Operand->getType()->isPlaceholderType()) { + ExprResult PR = CheckPlaceholderExpr(Operand); + if (PR.isInvalid()) + return ExprError(); + Operand = PR.get(); + } + CastOperation Op(*this, TSI->getType(), Operand); Op.OpRange = CastOperation::OpRangeType(KWLoc, KWLoc, RParenLoc); TypeLoc TL = TSI->getTypeLoc(); diff --git a/clang/test/SemaCXX/builtin-bit-cast.cpp b/clang/test/SemaCXX/builtin-bit-cast.cpp index 8717371b941b0..626065d5bdc00 100644 --- a/clang/test/SemaCXX/builtin-bit-cast.cpp +++ b/clang/test/SemaCXX/builtin-bit-cast.cpp @@ -46,3 +46,13 @@ extern S<int> extern_decl; int x = __builtin_bit_cast(int, extern_decl); S<char> y = __builtin_bit_cast(S<char>, 0); } + +template <class To, class From> +// expected-note@+1{{possible target for call}} +constexpr To bit_cast(const From &from) { + return __builtin_bit_cast(To, bit_cast); + // expected-error@-1{{reference to overloaded function could not be resolved; did you mean to call it?}} +} // expected-note {{control reached end of constexpr function}} +constexpr __int128_t foo = bit_cast<__int128_t>((long double)0); +// expected-error@-1{{constexpr variable 'foo' must be initialized by a constant expression}} +// expected-note@-2{{in call to 'bit_cast<__int128, long double>((long double)0)'}} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
