[clang] [clang-cl] Fix for __FUNCTION__ in c++. (PR #66120)

via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 12 11:28:30 PDT 2023


llvmbot wrote:

@llvm/pr-subscribers-clang

<details>
<summary>Changes</summary>

None
--
Full diff: https://github.com/llvm/llvm-project/pull/66120.diff

2 Files Affected:

- (modified) clang/lib/AST/Expr.cpp (+20) 
- (modified) clang/lib/AST/TypePrinter.cpp (+4) 


<pre>
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 4f3837371b3fc5e..55b6e2968487b86 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -727,6 +727,26 @@ StringRef PredefinedExpr::getIdentKindName(PredefinedExpr::IdentKind IK) {
 std::string PredefinedExpr::ComputeName(IdentKind IK, const Decl *CurrentDecl) {
   ASTContext &Context = CurrentDecl->getASTContext();
 
+  if (CurrentDecl->getASTContext().getTargetInfo().getCXXABI().isMicrosoft() &&
+      IK == PredefinedExpr::Function) {
+    if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurrentDecl)) {
+      SmallString<256> Name;
+      llvm::raw_svector_ostream Out(Name);
+      PrintingPolicy Policy(Context.getLangOpts());
+      Policy.AlwaysIncludeTypeForTemplateArgument = true;
+      std::string Proto;
+      llvm::raw_string_ostream POut(Proto);
+      const FunctionDecl *Decl = FD;
+      if (const FunctionDecl *Pattern = FD->getTemplateInstantiationPattern())
+        Decl = Pattern;
+      const FunctionType *AFT = Decl->getType()->getAs<FunctionType>();
+      const FunctionProtoType *FT = nullptr;
+      if (FD->hasWrittenPrototype())
+        FT = dyn_cast<FunctionProtoType>(AFT);
+      FD->printQualifiedName(POut, Policy);
+      return std::string(POut.str());
+    }
+  }
   if (IK == PredefinedExpr::FuncDName) {
     if (const NamedDecl *ND = dyn_cast<NamedDecl>(CurrentDecl)) {
       std::unique_ptr<MangleContext> MC;
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index eb69d0bb8755b48..676ce166312adf4 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -2218,6 +2218,10 @@ printTo(raw_ostream &OS, ArrayRef<TA> Args, const PrintingPolicy &Policy,
     } else {
       if (!FirstArg)
         OS << Comma;
+      // zahira
+      //if (Argument.getKind() == TemplateArgument::Type)
+      //  OS << "class ";
+
       // Tries to print the argument with location info if exists.
       printArgument(Arg, Policy, ArgOS,
                     TemplateParameterList::shouldIncludeTypeForArgument(
</pre>

</details>

https://github.com/llvm/llvm-project/pull/66120


More information about the cfe-commits mailing list