Skip to content

Commit

Permalink
[Clang] Fixed a crash when __PRETTY_FUNCTION__ or __FUNCSIG__ (clang-…
Browse files Browse the repository at this point in the history
…cl) appears in the trailing return type of the lambda
  • Loading branch information
TilakChad committed Jan 11, 2025
1 parent 657fb44 commit 4e5935f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
7 changes: 6 additions & 1 deletion clang/lib/AST/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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
}

0 comments on commit 4e5935f

Please sign in to comment.