Skip to content

Commit 4e5935f

Browse files
committed
[Clang] Fixed a crash when __PRETTY_FUNCTION__ or __FUNCSIG__ (clang-cl) appears in the trailing return type of the lambda
1 parent 657fb44 commit 4e5935f

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

clang/lib/AST/Expr.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,12 @@ std::string PredefinedExpr::ComputeName(PredefinedIdentKind IK,
774774
const FunctionDecl *Decl = FD;
775775
if (const FunctionDecl* Pattern = FD->getTemplateInstantiationPattern())
776776
Decl = Pattern;
777-
const FunctionType *AFT = Decl->getType()->getAs<FunctionType>();
777+
778+
const Type *Ty = Decl->getType().getTypePtrOrNull();
779+
if (!Ty)
780+
return "";
781+
782+
const FunctionType *AFT = Ty->getAs<FunctionType>();
778783
const FunctionProtoType *FT = nullptr;
779784
if (FD->hasWrittenPrototype())
780785
FT = dyn_cast<FunctionProtoType>(AFT);

clang/test/SemaCXX/crash-GH121274.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %clang_cc1 -std=c++11 -verify %s
2+
// expected-no-diagnostics
3+
4+
// Do not crash when __PRETTY_FUNCTION__ appears in the trailing return type of the lambda
5+
void foo() {
6+
[]() -> decltype(static_cast<const char*>(__PRETTY_FUNCTION__)) {
7+
return nullptr;
8+
}();
9+
10+
#ifdef MS
11+
[]() -> decltype(static_cast<const char*>(__FUNCSIG__)) {
12+
return nullptr;
13+
}();
14+
#endif
15+
}

0 commit comments

Comments
 (0)