Skip to content

Commit 6766295

Browse files
committed
[NFC][sanitizer] Return nullptr from PlatformDemangle
Use fallback name only on the top level, in Symbolizer::Demangle or DlAddrSymbolizer. This makes PlatformDemangle to be more consistent with SymbolizerTool and the loop in Symbolizer::Demangle which iterates over all availible options.
1 parent 9f73a9e commit 6766295

File tree

5 files changed

+10
-9
lines changed

5 files changed

+10
-9
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class Symbolizer final {
187187
// If stale, need to reload the modules before looking up addresses.
188188
bool modules_fresh_;
189189

190-
// Platform-specific default demangler, must not return nullptr.
190+
// Platform-specific default demangler, returns nullptr on failure.
191191
const char *PlatformDemangle(const char *name);
192192

193193
static Symbolizer *symbolizer_;

compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_mac.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ bool DlAddrSymbolizer::SymbolizePC(uptr addr, SymbolizedStack *stack) {
4242
}
4343

4444
const char *demangled = DemangleSwiftAndCXX(info.dli_sname);
45-
if (!demangled) return false;
45+
if (!demangled)
46+
demangled = info.dli_sname;
4647
stack->info.function = internal_strdup(demangled);
4748
return true;
4849
}
@@ -52,6 +53,8 @@ bool DlAddrSymbolizer::SymbolizeData(uptr addr, DataInfo *datainfo) {
5253
int result = dladdr((const void *)addr, &info);
5354
if (!result) return false;
5455
const char *demangled = DemangleSwiftAndCXX(info.dli_sname);
56+
if (!demangled)
57+
demangled = info.dli_sname;
5558
datainfo->name = internal_strdup(demangled);
5659
datainfo->start = (uptr)info.dli_saddr;
5760
return true;

compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const char *DemangleCXXABI(const char *name) {
5656
__cxxabiv1::__cxa_demangle(name, 0, 0, 0))
5757
return demangled_name;
5858

59-
return name;
59+
return nullptr;
6060
}
6161

6262
// As of now, there are no headers for the Swift runtime. Once they are

compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_win.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,7 @@ const char *WinSymbolizerTool::Demangle(const char *name) {
175175
return name;
176176
}
177177

178-
const char *Symbolizer::PlatformDemangle(const char *name) {
179-
return name;
180-
}
178+
const char *Symbolizer::PlatformDemangle(const char *name) { return nullptr; }
181179

182180
namespace {
183181
struct ScopedHandle {

compiler-rt/lib/sanitizer_common/tests/sanitizer_symbolizer_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ TEST(Symbolizer, ExtractTokenUpToDelimiter) {
5858
TEST(Symbolizer, DemangleSwiftAndCXX) {
5959
// Swift names are not demangled in default llvm build because Swift
6060
// runtime is not linked in.
61-
EXPECT_STREQ("_TtSd", DemangleSwiftAndCXX("_TtSd"));
61+
EXPECT_STREQ(nullptr, DemangleSwiftAndCXX("_TtSd"));
6262
// Check that the rest demangles properly.
6363
EXPECT_STREQ("f1(char*, int)", DemangleSwiftAndCXX("_Z2f1Pci"));
6464
#if !SANITIZER_FREEBSD // QoI issue with libcxxrt on FreeBSD
65-
EXPECT_STREQ("foo", DemangleSwiftAndCXX("foo"));
65+
EXPECT_STREQ(nullptr, DemangleSwiftAndCXX("foo"));
6666
#endif
67-
EXPECT_STREQ("", DemangleSwiftAndCXX(""));
67+
EXPECT_STREQ(nullptr, DemangleSwiftAndCXX(""));
6868
}
6969
#endif
7070

0 commit comments

Comments
 (0)