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
[clang-cl] Fix value of __FUNCTION__ and __FUNC__ in MSVC mode for c++. #66120
Conversation
@llvm/pr-subscribers-clang ChangesNoneFull diff: https://github.com/llvm/llvm-project/pull/66120.diff 2 Files Affected:
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(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(); + const FunctionProtoType *FT = nullptr; + if (FD->hasWrittenPrototype()) + FT = dyn_cast(AFT); + FD->printQualifiedName(POut, Policy); + return std::string(POut.str()); + } + } if (IK == PredefinedExpr::FuncDName) { if (const NamedDecl *ND = dyn_cast(CurrentDecl)) { std::unique_ptr 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 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( |
@@ -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 "; | |||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There are still some debug info LIT tests that are failing, but I am not going to edit them because I am not quite sure that's correct. Probably adding the "class" keyword shouldn't happen at all times even when the MSVCPolicy is true? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to make some minor naming suggestions, and I used the GitHub "edit this file" feature for the first time to commit them as new commits to your branch. I've never done this before, so I don't really know how it works, but clang-format isn't available, so now I've messed up the formatting...
I think you should be able to pull the suggested changes down, reformat the affected lines, commit that, push an updated commit, and then I can stamp that? I apologize if this isn't straightforward, it's my first time trying the tools.
No worries. I think it is synced up now. Thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
This implementation has bugs, see #66114 (comment) |
@RIscRIpt Thanks. Will look at them. |
Hi @zahiraam - can we revert this change until #66114 (comment) is resolved? Unfortunately this is impacting our downstream windows-x64 builder. |
I have a fix for it. It should be ready by eod (for me) today. But if that can't wait, sure we can revert it. |
Our preference would be to revert the change and reland it later since this doesn't appear to be a quick fix, which is in line with https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy |
No problem. Go ahead and revert it. Thanks. |
…e for c++. (#66120)" This reverts commit 265568c. See #66114 (comment)
I've reverted the changes in 9243b1b, but you should handle the revert yourself next time because you have commit privileges and it's possible the person requesting a revert does not. (If you can't do the revert immediately for whatever reason, it's fine to tell people something along the lines of "I'll revert by unless someone else is able to revert it sooner.") |
Sorry. Didn't realize that (I would have expected that the person would let me know). Thanks. |
No worries! We could probably make the policy documentation more clear about that. |
…e for c++. (llvm#66120)" This reverts commit 265568c. See llvm#66114 (comment)
Predefined macro FUNCTION in clang is not returning the same string than MS for templated functions. See https://godbolt.org/z/q3EKn5zq4 For the same test case MSVC is returning: function: TestClass::TestClass function: TestStruct::TestStruct function: TestEnum::TestEnum The initial work for this was in the reverted patch (#66120). This patch solves the issues raised in the reverted patch.
Predefined macro FUNCTION in clang is not returning the same string than MS for templated functions. See https://godbolt.org/z/q3EKn5zq4 For the same test case MSVC is returning: function: TestClass::TestClass function: TestStruct::TestStruct function: TestEnum::TestEnum The initial work for this was in the reverted patch (llvm#66120). This patch solves the issues raised in the reverted patch.
Predefined macro FUNCTION in clang is not returning the same string than MS for templated functions.
See https://godbolt.org/z/q3EKn5zq4
For the same test case MSVC is returning:
function: TestClass::TestClass
function: TestStruct::TestStruct
function: TestEnum::TestEnum