]> granicus.if.org Git - llvm/commitdiff
[llvm] [Support] Clean PrintStackTrace() ptr arithmetic up
authorMichal Gorny <mgorny@gentoo.org>
Tue, 2 Jul 2019 11:32:03 +0000 (11:32 +0000)
committerMichal Gorny <mgorny@gentoo.org>
Tue, 2 Jul 2019 11:32:03 +0000 (11:32 +0000)
Use '%tu' modifier for pointer arithmetic since we are using C++11
already.  Prefer static_cast<> over C-style cast.  Remove unnecessary
conversion of result, and add const qualifier to converted pointers,
to silence the following warning:

  In file included from /home/mgorny/llvm-project/llvm/lib/Support/Signals.cpp:220:0:
  /home/mgorny/llvm-project/llvm/lib/Support/Unix/Signals.inc: In function ‘void llvm::sys::PrintStackTrace(llvm::raw_ostream&)’:
  /home/mgorny/llvm-project/llvm/lib/Support/Unix/Signals.inc:546:53: warning: cast from type ‘const void*’ to type ‘char*’ casts away qualifiers [-Wcast-qual]
                                         (char*)dlinfo.dli_saddr));
                                                       ^~~~~~~~~

Differential Revision: https://reviews.llvm.org/D63888

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364912 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/Unix/Signals.inc

index 51e15071aa418cb0e02ed17acc6992eb32fb5738..ec3935928d23b0fca8301a9d7cad2fed0d544250 100644 (file)
@@ -539,11 +539,8 @@ void llvm::sys::PrintStackTrace(raw_ostream &OS) {
       else    OS << d;
       free(d);
 
-      // FIXME: When we move to C++11, use %t length modifier. It's not in
-      // C++03 and causes gcc to issue warnings. Losing the upper 32 bits of
-      // the stack offset for a stack dump isn't likely to cause any problems.
-      OS << format(" + %u",(unsigned)((char*)StackTrace[i]-
-                                      (char*)dlinfo.dli_saddr));
+      OS << format(" + %tu", (static_cast<const char*>(StackTrace[i])-
+                              static_cast<const char*>(dlinfo.dli_saddr)));
     }
     OS << '\n';
   }