https://github.com/TilakChad updated https://github.com/llvm/llvm-project/pull/122611
>From 4e5935f6631f0f0cd828559ec29ed931bc0333d3 Mon Sep 17 00:00:00 2001 From: Tilak Chad <tilakchad...@gmail.com> Date: Sun, 12 Jan 2025 00:03:32 +0545 Subject: [PATCH 1/2] [Clang] Fixed a crash when __PRETTY_FUNCTION__ or __FUNCSIG__ (clang-cl) appears in the trailing return type of the lambda --- clang/lib/AST/Expr.cpp | 7 ++++++- clang/test/SemaCXX/crash-GH121274.cpp | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaCXX/crash-GH121274.cpp diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 5331357b5d1fef..0caff41c8a8cf6 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -774,7 +774,12 @@ std::string PredefinedExpr::ComputeName(PredefinedIdentKind IK, const FunctionDecl *Decl = FD; if (const FunctionDecl* Pattern = FD->getTemplateInstantiationPattern()) Decl = Pattern; - const FunctionType *AFT = Decl->getType()->getAs<FunctionType>(); + + const Type *Ty = Decl->getType().getTypePtrOrNull(); + if (!Ty) + return ""; + + const FunctionType *AFT = Ty->getAs<FunctionType>(); const FunctionProtoType *FT = nullptr; if (FD->hasWrittenPrototype()) FT = dyn_cast<FunctionProtoType>(AFT); diff --git a/clang/test/SemaCXX/crash-GH121274.cpp b/clang/test/SemaCXX/crash-GH121274.cpp new file mode 100644 index 00000000000000..28677a0949bf9e --- /dev/null +++ b/clang/test/SemaCXX/crash-GH121274.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -std=c++11 -verify %s +// expected-no-diagnostics + +// Do not crash when __PRETTY_FUNCTION__ appears in the trailing return type of the lambda +void foo() { + []() -> decltype(static_cast<const char*>(__PRETTY_FUNCTION__)) { + return nullptr; + }(); + +#ifdef MS + []() -> decltype(static_cast<const char*>(__FUNCSIG__)) { + return nullptr; + }(); +#endif +} >From cea9b5dc4b8440d738609abab93eb6fdfd0eead6 Mon Sep 17 00:00:00 2001 From: Tilak Chad <tilakchad...@gmail.com> Date: Sun, 12 Jan 2025 11:47:10 +0545 Subject: [PATCH 2/2] [Clang] Added comment and updated the clang release notes --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/AST/Expr.cpp | 3 +++ 2 files changed, 4 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 197b3692b8a181..a14fb189c8e132 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -926,6 +926,7 @@ Bug Fixes to C++ Support (`LWG3929 <https://wg21.link/LWG3929>`__.) (#GH121278) - Clang now identifies unexpanded parameter packs within the type constraint on a non-type template parameter. (#GH88866) - Fixed an issue while resolving type of expression indexing into a pack of values of non-dependent type (#GH121242) +- Fixed a crash when __PRETTY_FUNCTION__ or __FUNCSIG__ (clang-cl) appears in the trailing return type of the lambda (#GH121274) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 0caff41c8a8cf6..b5dfc4bfe6dcb8 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -775,6 +775,9 @@ std::string PredefinedExpr::ComputeName(PredefinedIdentKind IK, if (const FunctionDecl* Pattern = FD->getTemplateInstantiationPattern()) Decl = Pattern; + // The type may not be fully initialized at this point. + // For example, in the trailing return type context of the lambda + // expression. const Type *Ty = Decl->getType().getTypePtrOrNull(); if (!Ty) return ""; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits