xref: /llvm-project/compiler-rt/test/fuzzer/FlagsTest.cpp (revision 3ba498d145f7ce07b5c25633c2179e64943dae13)
1 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2 // See https://llvm.org/LICENSE.txt for license information.
3 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4 
5 // Parse some flags
6 #include <cstdint>
7 #include <string>
8 #include <vector>
9 
10 static std::vector<std::string> Flags;
11 
LLVMFuzzerInitialize(int * Argc,char *** Argv)12 extern "C" int LLVMFuzzerInitialize(int *Argc, char ***Argv) {
13   // Parse --flags and anything after -ignore_remaining_args=1 is passed.
14   int I = 1;
15   while (I < *Argc) {
16     std::string S((*Argv)[I++]);
17     if (S == "-ignore_remaining_args=1")
18       break;
19     if (S.substr(0, 2) == "--")
20       Flags.push_back(S);
21   }
22   while (I < *Argc)
23     Flags.push_back(std::string((*Argv)[I++]));
24 
25   return 0;
26 }
27 
LLVMFuzzerTestOneInput(const uint8_t * Data,size_t Size)28 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
29   fprintf(stderr, "BINGO ");
30   for (auto Flag : Flags)
31     fprintf(stderr, "%s ", Flag.c_str());
32   fprintf(stderr, "\n");
33   return 0;
34 }
35