Skip to content
Open
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
4 changes: 3 additions & 1 deletion clang/include/clang/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -2003,7 +2003,9 @@ enum class PredefinedIdentKind {
PrettyFunction,
/// The same as PrettyFunction, except that the
/// 'virtual' keyword is omitted for virtual member functions.
PrettyFunctionNoVirtual
PrettyFunctionNoVirtual,
FQFunction,
MangledFunction
};

/// [C99 6.4.2.2] - A predefined identifier such as __func__.
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/TokenKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,9 @@ KEYWORD(__thread , KEYALL)
KEYWORD(__FUNCTION__ , KEYALL)
KEYWORD(__PRETTY_FUNCTION__ , KEYALL)
KEYWORD(__auto_type , KEYALL)
KEYWORD(__fq_func__, KEYALL)
KEYWORD(__mangled_func__, KEYALL)


// MS Extensions
KEYWORD(__FUNCDNAME__ , KEYMS)
Expand Down
32 changes: 32 additions & 0 deletions clang/lib/AST/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,10 @@ StringRef PredefinedExpr::getIdentKindName(PredefinedIdentKind IK) {
return "__FUNCTION__";
case PredefinedIdentKind::FuncDName:
return "__FUNCDNAME__";
case PredefinedIdentKind::FQFunction:
return "__fq_func__";
case PredefinedIdentKind::MangledFunction:
return "__mangled_func__";
case PredefinedIdentKind::LFunction:
return "L__FUNCTION__";
case PredefinedIdentKind::PrettyFunction:
Expand All @@ -674,6 +678,34 @@ std::string PredefinedExpr::ComputeName(PredefinedIdentKind IK,
bool ForceElaboratedPrinting) {
ASTContext &Context = CurrentDecl->getASTContext();

if (IK == PredefinedIdentKind::FQFunction) {
if (const auto *ND = dyn_cast<NamedDecl>(CurrentDecl))
return ND->getQualifiedNameAsString();
return "<unknown>";
}

if (IK == PredefinedIdentKind::MangledFunction) {
if (const auto *ND = dyn_cast<NamedDecl>(CurrentDecl)) {
std::unique_ptr<MangleContext> MC;
MC.reset(Context.createMangleContext());
SmallString<256> Buffer;
llvm::raw_svector_ostream Out(Buffer);
GlobalDecl GD;
if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(ND))
GD = GlobalDecl(CD, Ctor_Base);
else if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(ND))
GD = GlobalDecl(DD, Dtor_Base);
else if (auto FD = dyn_cast<FunctionDecl>(ND)) {
GD = FD->isReferenceableKernel() ? GlobalDecl(FD) : GlobalDecl(ND);
} else
GD = GlobalDecl(ND);
MC->mangleName(GD, Out);
return std::string(Buffer);
}
return "<unknown>";
}


if (IK == PredefinedIdentKind::FuncDName) {
if (const NamedDecl *ND = dyn_cast<NamedDecl>(CurrentDecl)) {
std::unique_ptr<MangleContext> MC;
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Parse/ParseExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,8 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
case tok::kw_L__FUNCTION__: // primary-expression: L__FUNCTION__ [MS]
case tok::kw_L__FUNCSIG__: // primary-expression: L__FUNCSIG__ [MS]
case tok::kw___PRETTY_FUNCTION__: // primary-expression: __P..Y_F..N__ [GNU]
case tok::kw___fq_func__: // <-- Add this line
case tok::kw___mangled_func__:
// Function local predefined macros are represented by PredefinedExpr except
// when Microsoft extensions are enabled and one of these macros is adjacent
// to a string literal or another one of these macros.
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Sema/SemaExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1992,6 +1992,10 @@ static PredefinedIdentKind getPredefinedExprKind(tok::TokenKind Kind) {
llvm_unreachable("unexpected TokenKind");
case tok::kw___func__:
return PredefinedIdentKind::Func; // [C99 6.4.2.2]
case tok::kw___fq_func__:
return PredefinedIdentKind::FQFunction;
case tok::kw___mangled_func__:
return PredefinedIdentKind::MangledFunction;
case tok::kw___FUNCTION__:
return PredefinedIdentKind::Function;
case tok::kw___FUNCDNAME__:
Expand Down