[PATCH] D22939: Only use __cxa_demangle on C++ mangled names

Dimitry Andric via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 28 14:35:54 PDT 2016


dim created this revision.
dim added reviewers: rnk, emaste.
dim added a subscriber: llvm-commits.
Herald added subscribers: kubabrecka, emaste.

Fix the Symbolizer.DemangleSwiftAndCXX test on FreeBSD, where one should
not call `__cxa_demangle()` with an identifier that is not a C++ mangled
name.  This would translate "foo" to "float", causing the test to fail.

To prevent this, test if the symbol starts with "_Z" before calling
`__cxa_demangle()`.

https://reviews.llvm.org/D22939

Files:
  lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc

Index: lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
===================================================================
--- lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
+++ lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
@@ -50,6 +50,11 @@
 
 // Attempts to demangle the name via __cxa_demangle from __cxxabiv1.
 const char *DemangleCXXABI(const char *name) {
+  // Check if we are dealing with a C++ mangled name first.
+  if (name[0] != '_' || name[1] != 'Z') {
+    return nullptr;
+  }
+
   // FIXME: __cxa_demangle aggressively insists on allocating memory.
   // There's not much we can do about that, short of providing our
   // own demangler (libc++abi's implementation could be adapted so that


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22939.66010.patch
Type: text/x-patch
Size: 743 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160728/390c7988/attachment.bin>


More information about the llvm-commits mailing list