[compiler-rt] r221287 - [Sanitizer] Get rid of unnecessary allocations in StripModuleName. NFC.

Alexey Samsonov vonosmas at gmail.com
Tue Nov 4 11:34:30 PST 2014


Author: samsonov
Date: Tue Nov  4 13:34:29 2014
New Revision: 221287

URL: http://llvm.org/viewvc/llvm-project?rev=221287&view=rev
Log:
[Sanitizer] Get rid of unnecessary allocations in StripModuleName. NFC.

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_libcdep.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_mapping_libcdep.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_report.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc?rev=221287&r1=221286&r2=221287&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc Tue Nov  4 13:34:29 2014
@@ -155,6 +155,14 @@ const char *StripPathPrefix(const char *
   return pos;
 }
 
+const char *StripModuleName(const char *module) {
+  if (module == 0)
+    return 0;
+  if (const char *slash_pos = internal_strrchr(module, '/'))
+    return slash_pos + 1;
+  return module;
+}
+
 void PrintSourceLocation(InternalScopedString *buffer, const char *file,
                          int line, int column) {
   CHECK(file);
@@ -217,17 +225,6 @@ bool LoadedModule::containsAddress(uptr
   return false;
 }
 
-char *StripModuleName(const char *module) {
-  if (module == 0)
-    return 0;
-  const char *short_module_name = internal_strrchr(module, '/');
-  if (short_module_name)
-    short_module_name += 1;
-  else
-    short_module_name = module;
-  return internal_strdup(short_module_name);
-}
-
 static atomic_uintptr_t g_total_mmaped;
 
 void IncreaseTotalMmap(uptr size) {

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=221287&r1=221286&r2=221287&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Tue Nov  4 13:34:29 2014
@@ -172,6 +172,8 @@ bool IsAccessibleMemoryRange(uptr beg, u
 // Error report formatting.
 const char *StripPathPrefix(const char *filepath,
                             const char *strip_file_prefix);
+// Strip the directories from the module name.
+const char *StripModuleName(const char *module);
 void PrintSourceLocation(InternalScopedString *buffer, const char *file,
                          int line, int column);
 void PrintModuleAndOffset(InternalScopedString *buffer,
@@ -209,9 +211,6 @@ void SleepForMillis(int millis);
 u64 NanoTime();
 int Atexit(void (*function)(void));
 void SortArray(uptr *array, uptr size);
-// Strip the directories from the module name, return a new string allocated
-// with internal_strdup.
-char *StripModuleName(const char *module);
 
 // Exit
 void NORETURN Abort();

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_libcdep.cc?rev=221287&r1=221286&r2=221287&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_libcdep.cc Tue Nov  4 13:34:29 2014
@@ -387,7 +387,7 @@ static void CovDump() {
         CHECK_LE(diff, 0xffffffffU);
         offsets.push_back(static_cast<u32>(diff));
       }
-      char *module_name = StripModuleName(module.data());
+      const char *module_name = StripModuleName(module.data());
       if (cov_sandboxed) {
         if (cov_fd >= 0) {
           CovWritePacked(internal_getpid(), module_name, offsets.data(),
@@ -407,7 +407,6 @@ static void CovDump() {
                   vb - old_vb);
         }
       }
-      InternalFree(module_name);
     }
   }
   if (cov_fd >= 0)

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_mapping_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_mapping_libcdep.cc?rev=221287&r1=221286&r2=221287&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_mapping_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_mapping_libcdep.cc Tue Nov  4 13:34:29 2014
@@ -80,7 +80,7 @@ void CovUpdateMapping(uptr caller_pc) {
 
   text.append("%d\n", sizeof(uptr) * 8);
   for (int i = 0; i < n_modules; ++i) {
-    char *module_name = StripModuleName(modules[i].full_name());
+    const char *module_name = StripModuleName(modules[i].full_name());
     for (unsigned j = 0; j < modules[i].n_ranges(); ++j) {
       if (modules[i].address_range_executable(j)) {
         uptr start = modules[i].address_range_start(j);
@@ -91,7 +91,6 @@ void CovUpdateMapping(uptr caller_pc) {
           cached_mapping.SetModuleRange(start, end);
       }
     }
-    InternalFree(module_name);
   }
 
   int err;

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_report.cc?rev=221287&r1=221286&r2=221287&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_report.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_report.cc Tue Nov  4 13:34:29 2014
@@ -115,9 +115,7 @@ void PrintStack(const ReportStack *ent)
     if (ent->col)
       Printf(":%d", ent->col);
     if (ent->module && ent->offset) {
-      char *stripped_module = StripModuleName(ent->module);
-      Printf(" (%s+%p)\n", stripped_module, (void*)ent->offset);
-      InternalFree(stripped_module);
+      Printf(" (%s+%p)\n", StripModuleName(ent->module), (void*)ent->offset);
     } else {
       Printf(" (%p)\n", (void*)ent->pc);
     }
@@ -162,10 +160,8 @@ static void PrintLocation(const ReportLo
   bool print_stack = false;
   Printf("%s", d.Location());
   if (loc->type == ReportLocationGlobal) {
-    char *stripped_module = StripModuleName(loc->module);
-    Printf("  Location is global '%s' of size %zu at %p (%s+%p)\n\n",
-               loc->name, loc->size, loc->addr, stripped_module, loc->offset);
-    InternalFree(stripped_module);
+    Printf("  Location is global '%s' of size %zu at %p (%s+%p)\n\n", loc->name,
+           loc->size, loc->addr, StripModuleName(loc->module), loc->offset);
   } else if (loc->type == ReportLocationHeap) {
     char thrbuf[kThreadBufSize];
     Printf("  Location is heap block of size %zu at %p allocated by %s:\n",





More information about the llvm-commits mailing list