Skip to content

Conversation

@VitaNuo
Copy link
Contributor

@VitaNuo VitaNuo commented Nov 22, 2024

…able to handle mangled names generated by clang.

https://discourse.llvm.org/t/rfc-clang-diagnostic-for-demangling-failures/82835/8

Since we're putting the work on the above RFC on hold, let's leave a comment in the source code pointing to prior efforts and the suggestion of further steps.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:codegen IR generation bugs: mangling, exceptions, etc. labels Nov 22, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 22, 2024

@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-clang

Author: Viktoriia Bakalova (VitaNuo)

Changes

…able to handle mangled names generated by clang.

https://discourse.llvm.org/t/rfc-clang-diagnostic-for-demangling-failures/82835/8

Since we're putting the work on the above RFC on hold, let's leave a comment in the source code pointing to prior efforts and the suggestion of further steps.


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

1 Files Affected:

  • (modified) clang/lib/CodeGen/CodeGenModule.cpp (+7)
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index b854eeb62a80ce..6eef085ae336eb 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2047,6 +2047,13 @@ StringRef CodeGenModule::getMangledName(GlobalDecl GD) {
                  GD.getWithKernelReferenceKind(KernelReferenceKind::Kernel),
                  ND));
 
+  // This invariant should hold true in the future.
+  // Prior work: https://discourse.llvm.org/t/rfc-clang-diagnostic-for-demangling-failures/82835/8
+  // https://github.com/llvm/llvm-project/issues/111345
+  // assert(llvm::isMangledName(MangledName) &&
+  //        llvm::demangle(MangledName) != MangledName &&
+  //        "LLVM demangler must demangle clang-generated names");
+
   auto Result = Manglings.insert(std::make_pair(MangledName, GD));
   return MangledDeclNames[CanonicalGD] = Result.first->first();
 }

@github-actions
Copy link

github-actions bot commented Nov 22, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

// Prior work:
// https://discourse.llvm.org/t/rfc-clang-diagnostic-for-demangling-failures/82835/8
// https://github.com/llvm/llvm-project/issues/111345
// assert(llvm::isMangledName(MangledName) &&
Copy link
Member

Choose a reason for hiding this comment

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

isMangledName doesn't seem to exist?

But, also, we'd only want to validate output actually produced by Clang mangleCXXName, and not e.g. a user-written void f() asm("_ZGARBAGE"); void f() {}

Maybe we want:if ((MangledName.startswith("_Z") || MangledName.startswith("?")) & !GD->hasAttr<AsmLabelAttr>())?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it doesn't exist. This was to demonstrate the idea.

Thanks, sure, I can change the text.

@VitaNuo VitaNuo merged commit 3de2147 into llvm:main Nov 25, 2024
8 checks passed
@dwblaikie
Copy link
Collaborator

(please don't merge PRs that haven't been approved, that's against LLVM practices/policies ( https://llvm.org/docs/CodeReview.html#code-review-workflow ), unless they weren't intended for pre-commit review in the first place (if they were only meant for presubmit checks))

@efriedma-quic
Copy link
Collaborator

Yes, review comments don't indicate approval after the comments are addressed unless the reviewer explicitly says that. The reviewer may want to take a look at the updated changes, or responses to review comments, or maybe the review wasn't complete for whatever reason.

That said, given it's just a comment change, I'm okay with leaving it in-tree until @jyknight follows up on the review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:codegen IR generation bugs: mangling, exceptions, etc. clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants