[libc-commits] [PATCH] D152322: [libc] Temporarily suppress -fsanitize=function for qsort comparator

Leonard Chan via Phabricator via libc-commits libc-commits at lists.llvm.org
Tue Jun 6 17:06:12 PDT 2023


leonardchan created this revision.
leonardchan added reviewers: Caslyn, abrachet, mcgrathr.
leonardchan added a project: libc-project.
Herald added subscribers: libc-commits, tschuett.
Herald added a project: All.
leonardchan requested review of this revision.

Recent upstream changes to -fsanitize=function find more instances of function type mismatches. One case is with the comparator passed to this class. Libraries like boringssl will tend to pass comparators that take pointers to varying types while this comparator expects to accept const void pointers. Ideally those tools would pass a function that strictly accepts const void*s to avoid UB, or we'd have something like qsort_r/s.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152322

Files:
  libc/src/stdlib/qsort.cpp


Index: libc/src/stdlib/qsort.cpp
===================================================================
--- libc/src/stdlib/qsort.cpp
+++ libc/src/stdlib/qsort.cpp
@@ -41,6 +41,15 @@
     }
   }
 
+#if defined(__clang__)
+  // Recent upstream changes to -fsanitize=function find more instances of
+  // function type mismatches. One case is with the comparator passed to this
+  // class. Libraries like boringssl will tend to pass comparators that take
+  // pointers to varying types while this comparator expects to accept const
+  // void pointers. Ideally those tools would pass a function that strictly
+  // accepts const void*s to avoid UB, or we'd have something like qsort_r/s.
+  [[clang::no_sanitize("function")]]
+#endif
   int elem_compare(size_t i, const uint8_t *other) const {
     // An element must compare equal to itself so we don't need to consult the
     // user provided comparator.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152322.529095.patch
Type: text/x-patch
Size: 905 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230607/6fa9f997/attachment.bin>


More information about the libc-commits mailing list