[compiler-rt] e556f07 - [NFC][asan] Cleanup AsanThreadIdAndName ctor/init (#111923)

via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 10 21:03:32 PDT 2024


Author: Vitaly Buka
Date: 2024-10-10T21:03:29-07:00
New Revision: e556f0787cb9675a120fcfc91156edcd27047772

URL: https://github.com/llvm/llvm-project/commit/e556f0787cb9675a120fcfc91156edcd27047772
DIFF: https://github.com/llvm/llvm-project/commit/e556f0787cb9675a120fcfc91156edcd27047772.diff

LOG: [NFC][asan] Cleanup AsanThreadIdAndName ctor/init (#111923)

Co-authored-by: YunQiang Su <yunqiang at isrc.iscas.ac.cn>

Added: 
    

Modified: 
    compiler-rt/lib/asan/asan_descriptions.cpp
    compiler-rt/lib/asan/asan_descriptions.h

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/asan/asan_descriptions.cpp b/compiler-rt/lib/asan/asan_descriptions.cpp
index 674fe9c1e90be0..db87789aea86a0 100644
--- a/compiler-rt/lib/asan/asan_descriptions.cpp
+++ b/compiler-rt/lib/asan/asan_descriptions.cpp
@@ -20,24 +20,20 @@
 namespace __asan {
 
 AsanThreadIdAndName::AsanThreadIdAndName(AsanThreadContext *t) {
-  Init(t->tid, t->name);
-}
-
-AsanThreadIdAndName::AsanThreadIdAndName(u32 tid) {
-  if (tid == kInvalidTid) {
-    Init(tid, "");
-  } else {
-    asanThreadRegistry().CheckLocked();
-    AsanThreadContext *t = GetThreadContextByTidLocked(tid);
-    Init(tid, t->name);
+  if (!t) {
+    internal_snprintf(name, sizeof(name), "T-1");
+    return;
   }
+  int len = internal_snprintf(name, sizeof(name), "T%d", t->tid);
+  CHECK(((unsigned int)len) < sizeof(name));
+  if (internal_strlen(t->name))
+    internal_snprintf(&name[len], sizeof(name) - len, " (%s)", t->name);
 }
 
-void AsanThreadIdAndName::Init(u32 tid, const char *tname) {
-  int len = internal_snprintf(name, sizeof(name), "T%d", tid);
-  CHECK(((unsigned int)len) < sizeof(name));
-  if (tname[0] != '\0')
-    internal_snprintf(&name[len], sizeof(name) - len, " (%s)", tname);
+AsanThreadIdAndName::AsanThreadIdAndName(u32 tid)
+    : AsanThreadIdAndName(
+          tid == kInvalidTid ? nullptr : GetThreadContextByTidLocked(tid)) {
+  asanThreadRegistry().CheckLocked();
 }
 
 void DescribeThread(AsanThreadContext *context) {

diff  --git a/compiler-rt/lib/asan/asan_descriptions.h b/compiler-rt/lib/asan/asan_descriptions.h
index 650e2eb9173ad5..a614f47d461bbd 100644
--- a/compiler-rt/lib/asan/asan_descriptions.h
+++ b/compiler-rt/lib/asan/asan_descriptions.h
@@ -35,8 +35,6 @@ class AsanThreadIdAndName {
   const char *c_str() const { return &name[0]; }
 
  private:
-  void Init(u32 tid, const char *tname);
-
   char name[128];
 };
 


        


More information about the llvm-commits mailing list