1 //===-- vfabi-demangler-fuzzer.cpp - Fuzzer VFABI using lib/Fuzzer ------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // Build tool to fuzz the demangler for the vector function ABI names.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/AsmParser/Parser.h"
14 #include "llvm/IR/Module.h"
15 #include "llvm/IR/VFABIDemangler.h"
16 #include "llvm/Support/SourceMgr.h"
20 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data
, size_t Size
) {
23 const std::unique_ptr
<Module
> M
=
24 parseAssemblyString("declare i32 @foo(i32 )\n", Err
, Ctx
);
25 const StringRef
MangledName((const char *)Data
, Size
);
26 // Make sure that whatever symbol the demangler is operating on is
27 // present in the module (the signature is not important). This is
28 // because `tryDemangleForVFABI` fails if the function is not
29 // present. We need to make sure we can even invoke
30 // `getOrInsertFunction` because such method asserts on strings with
32 // TODO: What is this actually testing? That we don't crash?
33 if (!MangledName
.empty() && MangledName
.find_first_of(0) == StringRef::npos
) {
35 FunctionType::get(Type::getVoidTy(M
->getContext()), false);
36 const auto Info
= VFABI::tryDemangleForVFABI(MangledName
, FTy
);
38 // Do not optimize away the return value. Inspired by
39 // https://github.com/google/benchmark/blob/main/include/benchmark/benchmark.h#L307-L345
40 asm volatile("" : : "r,m"(Info
) : "memory");