[compiler-rt] [llvm] [nsan] Emit calls to optimized functions (PR #98900)
Mitch Phillips via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 24 02:00:38 PDT 2024
================
@@ -493,6 +493,60 @@ class ValueToShadowMap {
DenseMap<Value *, Value *> Map;
};
+class NsanMemOpFn {
+public:
+ NsanMemOpFn(Module &M, ArrayRef<StringRef> Sized, StringRef Fallback,
+ size_t NumArgs);
+ FunctionCallee getFunctionFor(uint64_t MemOpSize) const;
+ FunctionCallee getFallback() const;
+
+private:
+ SmallVector<FunctionCallee> Funcs;
+ size_t NumSizedFuncs;
+};
+
+NsanMemOpFn::NsanMemOpFn(Module &M, ArrayRef<StringRef> Sized,
+ StringRef Fallback, size_t NumArgs) {
+ LLVMContext &Ctx = M.getContext();
+ AttributeList Attr;
+ Attr = Attr.addFnAttribute(Ctx, Attribute::NoUnwind);
+ Type *PtrTy = PointerType::getUnqual(Ctx);
+ Type *VoidTy = Type::getVoidTy(Ctx);
+ IntegerType *IntptrTy = M.getDataLayout().getIntPtrType(Ctx);
+ FunctionType *SizedFnTy = nullptr;
+
+ NumSizedFuncs = Sized.size();
+
+ // First entry is fallback function
+ if (NumArgs == 3) {
+ Funcs.push_back(
+ M.getOrInsertFunction(Fallback, Attr, VoidTy, PtrTy, PtrTy, IntptrTy));
+ SizedFnTy = FunctionType::get(VoidTy, {PtrTy, PtrTy}, false);
+ } else if (NumArgs == 2) {
+ Funcs.push_back(
+ M.getOrInsertFunction(Fallback, Attr, VoidTy, PtrTy, IntptrTy));
+ SizedFnTy = FunctionType::get(VoidTy, {PtrTy}, false);
+ } else {
+ assert(!"Unexpected value of sized functions arguments");
----------------
hctim wrote:
Looks like this breaks under buildbots with `-Werror`: https://lab.llvm.org/buildbot/#/builders/109/builds/1300
```
[3128/3995] Building CXX object lib/Transforms/Instrumentation/CMakeFiles/LLVMInstrumentation.dir/NumericalStabilitySanitizer.cpp.o
FAILED: lib/Transforms/Instrumentation/CMakeFiles/LLVMInstrumentation.dir/NumericalStabilitySanitizer.cpp.o
CCACHE_CPP2=yes CCACHE_HASHDIR=yes /usr/bin/ccache /home/buildbots/llvm-external-buildbots/workers/ppc64be-sanitizer/sanitizer-ppc64be/build/llvm_build0/bin/clang++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/buildbots/llvm-external-buildbots/workers/ppc64be-sanitizer/sanitizer-ppc64be/build/build_default/lib/Transforms/Instrumentation -I/home/buildbots/llvm-external-buildbots/workers/ppc64be-sanitizer/sanitizer-ppc64be/build/llvm-project/llvm/lib/Transforms/Instrumentation -I/home/buildbots/llvm-external-buildbots/workers/ppc64be-sanitizer/sanitizer-ppc64be/build/build_default/include -I/home/buildbots/llvm-external-buildbots/workers/ppc64be-sanitizer/sanitizer-ppc64be/build/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -std=c++17 -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT lib/Transforms/Instrumentation/CMakeFiles/LLVMInstrumentation.dir/NumericalStabilitySanitizer.cpp.o -MF lib/Transforms/Instrumentation/CMakeFiles/LLVMInstrumentation.dir/NumericalStabilitySanitizer.cpp.o.d -o lib/Transforms/Instrumentation/CMakeFiles/LLVMInstrumentation.dir/NumericalStabilitySanitizer.cpp.o -c /home/buildbots/llvm-external-buildbots/workers/ppc64be-sanitizer/sanitizer-ppc64be/build/llvm-project/llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp
/home/buildbots/llvm-external-buildbots/workers/ppc64be-sanitizer/sanitizer-ppc64be/build/llvm-project/llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp:530:13: error: implicit conversion turns string literal into bool: 'const char[46]' to 'bool' [-Werror,-Wstring-conversion]
530 | assert(!"Unexpected value of sized functions arguments");
| ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/assert.h:87:5: note: expanded from macro 'assert'
87 | ((expr) \
| ^~~~
1 error generated.
```
https://github.com/llvm/llvm-project/pull/98900
More information about the llvm-commits
mailing list