Files
TheRock/compiler/amd-llvm/clang/tools/clang-ssaf-analyzer/SSAFAnalyzer.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

135 lines
4.6 KiB
C++

//===- SSAFAnalyzer.cpp - SSAF Analyzer Tool ------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements the SSAF analyzer tool that runs whole-program
// analyses over an LUSummary and writes the resulting WPASuite to an
// output file.
//
//===----------------------------------------------------------------------===//
#include "clang/ScalableStaticAnalysisFramework/Core/EntityLinker/LUSummary.h"
#include "clang/ScalableStaticAnalysisFramework/Core/WholeProgramAnalysis/AnalysisDriver.h"
#include "clang/ScalableStaticAnalysisFramework/Core/WholeProgramAnalysis/AnalysisName.h"
#include "clang/ScalableStaticAnalysisFramework/SSAFForceLinker.h" // IWYU pragma: keep
#include "clang/ScalableStaticAnalysisFramework/Tool/Utils.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/InitLLVM.h"
#include <memory>
#include <string>
using namespace llvm;
using namespace clang::ssaf;
namespace {
//===----------------------------------------------------------------------===//
// Command-Line Options
//===----------------------------------------------------------------------===//
cl::OptionCategory SsafAnalyzerCategory("clang-ssaf-analyzer options");
cl::opt<std::string> InputPath(cl::Positional, cl::desc("<input file>"),
cl::Required, cl::cat(SsafAnalyzerCategory));
cl::opt<std::string> OutputPath("o", cl::desc("Output file path"),
cl::value_desc("path"), cl::Required,
cl::cat(SsafAnalyzerCategory));
cl::list<std::string> AnalysisNames("a", cl::desc("Analysis name to run"),
cl::value_desc("name"),
cl::cat(SsafAnalyzerCategory));
cl::alias AnalysisNamesAlias("analysis", cl::aliasopt(AnalysisNames),
cl::desc("Alias for -a"));
cl::list<std::string> LoadPlugins("load",
cl::desc("Load a plugin shared library"),
cl::value_desc("path"),
cl::cat(SsafAnalyzerCategory));
cl::alias LoadPluginsAlias("l", cl::aliasopt(LoadPlugins),
cl::desc("Alias for --load"));
//===----------------------------------------------------------------------===//
// Input Validation
//===----------------------------------------------------------------------===//
struct AnalyzerInput {
FormatFile InputFile;
FormatFile OutputFile;
llvm::SmallVector<AnalysisName> Names;
};
AnalyzerInput validate() {
AnalyzerInput AI;
// Validate the input path.
AI.InputFile = FormatFile::fromInputPath(InputPath);
// Validate the output path.
AI.OutputFile = FormatFile::fromOutputPath(OutputPath);
// Build and validate analysis names.
for (const auto &Name : AnalysisNames) {
if (Name.empty()) {
fail("analysis name must not be empty");
}
AI.Names.push_back(AnalysisName(Name));
}
return AI;
}
//===----------------------------------------------------------------------===//
// Analysis Pipeline
//===----------------------------------------------------------------------===//
void analyze(const AnalyzerInput &AI) {
// Read the LUSummary.
auto ExpectedLU = AI.InputFile.Format->readLUSummary(AI.InputFile.Path);
if (!ExpectedLU) {
fail(ExpectedLU.takeError());
}
// Run analyses. If specific names were given, run only those;
// otherwise run all registered analyses.
AnalysisDriver Driver(std::make_unique<LUSummary>(std::move(*ExpectedLU)));
auto ExpectedSuite =
AI.Names.empty() ? std::move(Driver).run() : Driver.run(AI.Names);
if (!ExpectedSuite) {
fail(ExpectedSuite.takeError());
}
// Write the WPASuite.
if (auto Err = AI.OutputFile.Format->writeWPASuite(*ExpectedSuite,
AI.OutputFile.Path)) {
fail(std::move(Err));
}
}
} // namespace
//===----------------------------------------------------------------------===//
// Driver
//===----------------------------------------------------------------------===//
int main(int argc, const char **argv) {
llvm::StringRef ToolHeading = "SSAF Analyzer";
InitLLVM X(argc, argv);
initTool(argc, argv, "0.1", SsafAnalyzerCategory, ToolHeading);
loadPlugins(LoadPlugins);
AnalyzerInput AI = validate();
analyze(AI);
return 0;
}