Skip to content

[clang-cl] Fix value of __FUNCTION__ and __FUNC__ in MSVC mode for c++. #66120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Sep 22, 2023
Merged
20 changes: 20 additions & 0 deletions clang/lib/AST/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/AST/TypePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2218,6 +2218,9 @@ printTo(raw_ostream &OS, ArrayRef<TA> Args, const PrintingPolicy &Policy,
} else {
if (!FirstArg)
OS << Comma;
//if (Argument.getKind() == TemplateArgument::Type)
// OS << "class ";

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: if we go with this solution, this needs to happen here, but it should be under some conditions?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move it into printArgument. If you have to, it would be find to add a new flag to PrintingPolicy. We have lots of fine-grained flags there.

// Tries to print the argument with location info if exists.
printArgument(Arg, Policy, ArgOS,
TemplateParameterList::shouldIncludeTypeForArgument(
Expand Down