Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Clang] Fixed a crash when __PRETTY_FUNCTION__ or __FUNCSIG__ (clang-cl) appears in the trailing return type of the lambda #122611

Merged
merged 2 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
10 changes: 9 additions & 1 deletion clang/lib/AST/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,15 @@ 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>();

// Bail out if the type of the function has not been set yet.
// This can notably happen in the trailing return type of a lambda
// expression.
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);
Expand Down
15 changes: 15 additions & 0 deletions clang/test/SemaCXX/crash-GH121274.cpp
Original file line number Diff line number Diff line change
@@ -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
}
Loading