https://github.com/kishan-kumar-s-d-444 updated https://github.com/llvm/llvm-project/pull/145042
>From fdf7f676690f7af5109970f239eba8f34850442f Mon Sep 17 00:00:00 2001 From: KISHAN KUMAR S D <kishankumarsd...@gmail.com> Date: Fri, 20 Jun 2025 19:35:57 +0530 Subject: [PATCH 1/8] Update Expr.h --- clang/include/clang/AST/Expr.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index 9fc23d30b733f..2da16d4dc069d 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -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__. >From b814391bd581ab82acf30366ffd3952f3f72a490 Mon Sep 17 00:00:00 2001 From: KISHAN KUMAR S D <kishankumarsd...@gmail.com> Date: Fri, 20 Jun 2025 19:38:50 +0530 Subject: [PATCH 2/8] Update TokenKinds.def --- clang/include/clang/Basic/TokenKinds.def | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clang/include/clang/Basic/TokenKinds.def b/clang/include/clang/Basic/TokenKinds.def index 94e72fea56a68..1f9f0d60e8b02 100644 --- a/clang/include/clang/Basic/TokenKinds.def +++ b/clang/include/clang/Basic/TokenKinds.def @@ -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) >From fe6fc7ba8183b267ee00fdc66c3060f1449194b2 Mon Sep 17 00:00:00 2001 From: KISHAN KUMAR S D <kishankumarsd...@gmail.com> Date: Fri, 20 Jun 2025 19:39:32 +0530 Subject: [PATCH 3/8] Update Expr.cpp --- clang/lib/AST/Expr.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index c3722c65abf6e..12b6745536d53 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -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: @@ -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; >From add48ac76f28fa94ff4aed30116722a2b24799fb Mon Sep 17 00:00:00 2001 From: KISHAN KUMAR S D <kishankumarsd...@gmail.com> Date: Fri, 20 Jun 2025 19:40:35 +0530 Subject: [PATCH 4/8] Update SemaExpr.cpp --- clang/lib/Sema/SemaExpr.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 413eff4aa294a..2e5cd6a821c70 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -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__: >From f5847a1c5a93bb0e70eae2e211abe50a1cd3677d Mon Sep 17 00:00:00 2001 From: KISHAN KUMAR S D <kishankumarsd...@gmail.com> Date: Fri, 20 Jun 2025 19:41:40 +0530 Subject: [PATCH 5/8] Update ParseExpr.cpp --- clang/lib/Parse/ParseExpr.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp index 3cf3d4ea7d705..afd28da1e2bc4 100644 --- a/clang/lib/Parse/ParseExpr.cpp +++ b/clang/lib/Parse/ParseExpr.cpp @@ -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. >From 828383153d068d229b463fedf54c0df2915e35bc Mon Sep 17 00:00:00 2001 From: KISHAN KUMAR S D <kishankumarsd...@gmail.com> Date: Fri, 20 Jun 2025 22:54:29 +0530 Subject: [PATCH 6/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a9b29ecbc1a3a..897840e92feec 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # The LLVM Compiler Infrastructure - +//Changed// [](https://securityscorecards.dev/viewer/?uri=github.com/llvm/llvm-project) [](https://www.bestpractices.dev/projects/8273) [](https://github.com/llvm/llvm-project/actions/workflows/libcxx-build-and-test.yaml?query=event%3Aschedule) >From e03606deec5a3eda35d2529d2953752dcb7a9412 Mon Sep 17 00:00:00 2001 From: KISHAN KUMAR S D <kishankumarsd...@gmail.com> Date: Fri, 20 Jun 2025 22:58:32 +0530 Subject: [PATCH 7/8] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 897840e92feec..1cbba1b409832 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ # The LLVM Compiler Infrastructure -//Changed// [](https://securityscorecards.dev/viewer/?uri=github.com/llvm/llvm-project) [](https://www.bestpractices.dev/projects/8273) [](https://github.com/llvm/llvm-project/actions/workflows/libcxx-build-and-test.yaml?query=event%3Aschedule) >From a48e978060ea9e1119dca22c201b20b041705590 Mon Sep 17 00:00:00 2001 From: KISHAN KUMAR S D <kishankumarsd...@gmail.com> Date: Tue, 15 Jul 2025 22:04:54 +0530 Subject: [PATCH 8/8] Update README.md --- README.md | 142 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 108 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 1cbba1b409832..9dabbfda2d8e7 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,117 @@ -# The LLVM Compiler Infrastructure -[](https://securityscorecards.dev/viewer/?uri=github.com/llvm/llvm-project) -[](https://www.bestpractices.dev/projects/8273) -[](https://github.com/llvm/llvm-project/actions/workflows/libcxx-build-and-test.yaml?query=event%3Aschedule) +# Clang Enhancement: `__fq_func__` and `__mangled_func__` Support -Welcome to the LLVM project! +## 1) `Expr.h` → `llvm-project/clang/include/clang/AST/Expr.h` -This repository contains the source code for LLVM, a toolkit for the -construction of highly optimized compilers, optimizers, and run-time -environments. +```cpp +enum class PredefinedIdentKind { + Func, + Function, + LFunction, // Same as Function, but as wide string. + FuncDName, + FuncSig, + LFuncSig, // Same as FuncSig, but as wide string + PrettyFunction, + /// The same as PrettyFunction, except that the + /// 'virtual' keyword is omitted for virtual member functions. + PrettyFunctionNoVirtual, + FQFunction, + MangledFunction +}; +``` -The LLVM project has multiple components. The core of the project is -itself called "LLVM". This contains all of the tools, libraries, and header -files needed to process intermediate representations and convert them into -object files. Tools include an assembler, disassembler, bitcode analyzer, and -bitcode optimizer. +## `2)Expr.cpp` -->`llvm-project/clang/lib/AST` +``` +StringRef PredefinedExpr::getIdentKindName(PredefinedIdentKind IK) { + switch (IK) { + case PredefinedIdentKind::Func: + return "__func__"; + case PredefinedIdentKind::Function: + 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: + return "__PRETTY_FUNCTION__"; + case PredefinedIdentKind::FuncSig: + return "__FUNCSIG__"; + case PredefinedIdentKind::LFuncSig: + return "L__FUNCSIG__"; + case PredefinedIdentKind::PrettyFunctionNoVirtual: + break; + } + llvm_unreachable("Unknown ident kind for PredefinedExpr"); +} +``` +``` +std::string PredefinedExpr::ComputeName(PredefinedIdentKind IK, + const Decl *CurrentDecl, + bool ForceElaboratedPrinting) { + ASTContext &Context = CurrentDecl->getASTContext(); -C-like languages use the [Clang](https://clang.llvm.org/) frontend. This -component compiles C, C++, Objective-C, and Objective-C++ code into LLVM bitcode --- and from there into object files, using LLVM. + if (IK == PredefinedIdentKind::FQFunction) { + if (const auto *ND = dyn_cast<NamedDecl>(CurrentDecl)) + return ND->getQualifiedNameAsString(); + return "<unknown>"; +} -Other components include: -the [libc++ C++ standard library](https://libcxx.llvm.org), -the [LLD linker](https://lld.llvm.org), and more. +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>"; +} +// Remaining Code continues +``` -## Getting the Source Code and Building LLVM +## `3)TokenKinds.def` -->`llvm-project/clang/include/clang/Basic/TokenKinds.def` +``` +KEYWORD(__fq_func__, KEYALL) +KEYWORD(__mangled_func__, KEYALL) +``` -Consult the -[Getting Started with LLVM](https://llvm.org/docs/GettingStarted.html#getting-the-source-code-and-building-llvm) -page for information on building and running LLVM. +## `4)SemaExpr.cpp` -->`llvm-project/clang/lib/Sema/SemaExpr.cpp` +``` +static PredefinedIdentKind getPredefinedExprKind(tok::TokenKind Kind) { + switch (Kind) { + default: + llvm_unreachable("unexpected TokenKind"); + case tok::kw___func__: + return PredefinedIdentKind::Func; + case tok::kw___fq_func__: + return PredefinedIdentKind::FQFunction; + case tok::kw___mangled_func__: + return PredefinedIdentKind::MangledFunction; + // Code Continues +``` -For information on how to contribute to the LLVM project, please take a look at -the [Contributing to LLVM](https://llvm.org/docs/Contributing.html) guide. +## `5)ParseExpr.cpp` -->`llvm-project/clang/lib/Parse/ParseExpr.cpp` + ``` + case tok::kw_L__FUNCTION__: + case tok::kw_L__FUNCSIG__: + case tok::kw___PRETTY_FUNCTION__: + //Add below lines + case tok::kw___fq_func__: + case tok::kw___mangled_func__: + //end here +``` -## Getting in touch - -Join the [LLVM Discourse forums](https://discourse.llvm.org/), [Discord -chat](https://discord.gg/xS7Z362), -[LLVM Office Hours](https://llvm.org/docs/GettingInvolved.html#office-hours) or -[Regular sync-ups](https://llvm.org/docs/GettingInvolved.html#online-sync-ups). - -The LLVM project has adopted a [code of conduct](https://llvm.org/docs/CodeOfConduct.html) for -participants to all modes of communication within the project. + _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits