[PATCH] D20079: Avoid gcc warning about casting ptr-to-object to ptr-to-fun

Douglas Katzman via llvm-commits llvm-commits at lists.llvm.org
Mon May 9 13:29:28 PDT 2016


dougk created this revision.
dougk added a reviewer: zaks.anna.
dougk added a subscriber: llvm-commits.
Herald added a subscriber: kubabrecka.

Use the workaround provided in the dlsym() man page.


http://reviews.llvm.org/D20079

Files:
  lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
  lib/stats/stats_client.cc

Index: lib/stats/stats_client.cc
===================================================================
--- lib/stats/stats_client.cc
+++ lib/stats/stats_client.cc
@@ -30,11 +30,13 @@
 
 namespace {
 
-void *LookupSymbolFromMain(const char *name) {
+void (*LookupSymbolFromMain(const char *name))() {
 #ifdef _WIN32
-  return reinterpret_cast<void *>(GetProcAddress(GetModuleHandle(0), name));
+  return reinterpret_cast<void (*)()>(GetProcAddress(GetModuleHandle(0), name));
 #else
-  return dlsym(RTLD_DEFAULT, name);
+  void (*f)();
+  *(void**)&f = dlsym(RTLD_DEFAULT, name);
+  return f;
 #endif
 }
 
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
@@ -80,8 +80,8 @@
                                      char *outputBuffer,
                                      size_t *outputBufferSize,
                                      uint32_t flags);
-  swift_demangle_ft swift_demangle_f =
-    (swift_demangle_ft) dlsym(RTLD_DEFAULT, "swift_demangle");
+  swift_demangle_ft swift_demangle_f;
+  *(void**)&swift_demangle_f = dlsym(RTLD_DEFAULT, "swift_demangle");
   if (swift_demangle_f)
     return swift_demangle_f(name, internal_strlen(name), 0, 0, 0);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20079.56618.patch
Type: text/x-patch
Size: 1367 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160509/347189e9/attachment.bin>


More information about the llvm-commits mailing list