[clang] [clang-cl] Fix for __FUNCTION__ in c++. (PR #66120)
Zahira Ammarguellat via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 14 05:41:50 PDT 2023
https://github.com/zahiraam updated https://github.com/llvm/llvm-project/pull/66120:
>From 3fcfa303bd211f9a3382657012968cd3f7269db8 Mon Sep 17 00:00:00 2001
From: Ammarguellat <zahira.ammarguellat at intel.com>
Date: Tue, 12 Sep 2023 11:25:19 -0700
Subject: [PATCH 1/2] [clang-cl] Fix for __FUNCTION__ in c++.
---
clang/lib/AST/Expr.cpp | 20 ++++++++++++++++++++
clang/lib/AST/TypePrinter.cpp | 4 ++++
2 files changed, 24 insertions(+)
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(
>From f2c2d9ca4120d61e8cf75165693ead19890be0e0 Mon Sep 17 00:00:00 2001
From: Ammarguellat <zahira.ammarguellat at intel.com>
Date: Wed, 13 Sep 2023 06:45:03 -0700
Subject: [PATCH 2/2] Testing.
---
clang/lib/AST/TypePrinter.cpp | 1 -
1 file changed, 1 deletion(-)
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 676ce166312adf4..e4abf4b2160682a 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -2218,7 +2218,6 @@ printTo(raw_ostream &OS, ArrayRef<TA> Args, const PrintingPolicy &Policy,
} else {
if (!FirstArg)
OS << Comma;
- // zahira
//if (Argument.getKind() == TemplateArgument::Type)
// OS << "class ";
More information about the cfe-commits
mailing list