llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Rajveer Singh Bharadwaj (Rajveer100) <details> <summary>Changes</summary> Resolves #<!-- -->200112 By early checking for placeholder expressions, crash can be avoided for unreachable builtin type when fetching type info. --- Full diff: https://github.com/llvm/llvm-project/pull/200574.diff 2 Files Affected: - (modified) clang/lib/Sema/SemaCast.cpp (+7) - (modified) clang/test/SemaCXX/builtin-bit-cast.cpp (+10) ``````````diff 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)'}} `````````` </details> https://github.com/llvm/llvm-project/pull/200574 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
