[libc-commits] [libc] 8f360c3 - [libc] Temporarily suppress -fsanitize=function for qsort comparator

Leonard Chan via libc-commits libc-commits at lists.llvm.org
Wed Jun 7 11:46:27 PDT 2023


Author: Leonard Chan
Date: 2023-06-07T18:46:15Z
New Revision: 8f360c3560d4d9f093482368475ded761a8cb9ab

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

LOG: [libc] Temporarily suppress -fsanitize=function for qsort comparator

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.

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

Added: 
    

Modified: 
    libc/src/stdlib/qsort.cpp

Removed: 
    


################################################################################
diff  --git a/libc/src/stdlib/qsort.cpp b/libc/src/stdlib/qsort.cpp
index f6e2fc10e4d70..0efeea9f07955 100644
--- a/libc/src/stdlib/qsort.cpp
+++ b/libc/src/stdlib/qsort.cpp
@@ -41,6 +41,15 @@ class Array {
     }
   }
 
+#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.


        


More information about the libc-commits mailing list