| 1 |
// Copyright (c) 2019 Google LLC |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
#include "source/fuzz/fact_manager/livesafe_function_facts.h" |
| 16 |
|
| 17 |
#include "source/fuzz/fuzzer_util.h" |
| 18 |
|
| 19 |
namespace spvtools { |
| 20 |
namespace fuzz { |
| 21 |
namespace fact_manager { |
| 22 |
|
| 23 |
LivesafeFunctionFacts::LivesafeFunctionFacts(opt::IRContext* ir_context) |
| 24 |
: ir_context_(ir_context) {} |
| 25 |
|
| 26 |
bool LivesafeFunctionFacts::MaybeAddFact( |
| 27 |
const protobufs::FactFunctionIsLivesafe& fact) { |
| 28 |
if (!fuzzerutil::FindFunction(ir_context_, fact.function_id())) { |
| 29 |
return false; |
| 30 |
} |
| 31 |
|
| 32 |
if (fuzzerutil::FunctionIsEntryPoint(ir_context_, fact.function_id())) { |
| 33 |
return false; |
| 34 |
} |
| 35 |
|
| 36 |
livesafe_function_ids_.insert(fact.function_id()); |
| 37 |
return true; |
| 38 |
} |
| 39 |
|
| 40 |
bool LivesafeFunctionFacts::FunctionIsLivesafe(uint32_t function_id) const { |
| 41 |
return livesafe_function_ids_.count(function_id) != 0; |
| 42 |
} |
| 43 |
|
| 44 |
} // namespace fact_manager |
| 45 |
} // namespace fuzz |
| 46 |
} // namespace spvtools |