Skip to content

Conversation

@kumarak
Copy link
Collaborator

@kumarak kumarak commented Oct 3, 2025

No description provided.

@kumarak kumarak requested a review from Copilot October 3, 2025 18:41
@kumarak kumarak marked this pull request as draft October 3, 2025 18:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive support for static contracts during the instrumentation pass, extending the existing runtime contract system. It introduces a new Contracts dialect with MLIR attributes to embed pre/post conditions directly into operations, enabling compile-time contract verification alongside runtime validation.

  • Support for both static and runtime contract types with type-specific processing
  • New Contracts MLIR dialect with attributes for static contract specifications
  • Refactored patch and contract operation implementations into separate modules for better maintainability

Reviewed Changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tools/*/CMakeLists.txt Added MLIRContracts library linking to all tools
tools/patchir-transform/main.cpp Added Contracts dialect registration and context initialization
test/patchir-transform/contracts/usb_security_contracts.yaml Extended test contracts with static contract examples
test/patchir-transform/bl_usb__send_message_before_patch.yaml Updated test to use static contract ID
lib/patchestry/Passes/PatchOperationImpl.* New implementation module for patch operations
lib/patchestry/Passes/ContractOperationImpl.* New implementation module for contract operations
lib/patchestry/Passes/InstrumentationPass.cpp Refactored to use new implementation modules and support static contracts
lib/patchestry/Dialect/Contracts/* New Contracts dialect with attributes and tablegen definitions
include/patchestry/YAML/ContractSpec.hpp Extended contract specification to support static contracts
include/patchestry/YAML/BaseSpec.hpp Added ContractType enum for runtime/static distinction
include/patchestry/Passes/*.hpp Updated headers for refactored implementation structure

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@kumarak kumarak requested a review from Copilot October 12, 2025 11:57
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 27 out of 27 changed files in this pull request and generated 5 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


default:
LOG(ERROR) << "Unsupported contract mode for static contracts: "
<< infoModeToString(mode) << "\n";
Copy link

Copilot AI Oct 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function infoModeToString is called but it's not in scope. It should be contract::infoModeToString(mode) to use the function from the contract namespace.

Suggested change
<< infoModeToString(mode) << "\n";
<< contracts::infoModeToString(mode) << "\n";

Copilot uses AI. Check for mistakes.
Comment on lines 40 to 43
const cl::opt< std::string > output_filename( // NOLINT(cert-err58-cpp)
"o", llvm::cl::desc("Output filename for the patched CIR"), llvm::cl::value_desc("filename"),
llvm::cl::init("-"), cl::cat(category)
"o", llvm::cl::desc("Output filename for the patched CIR"),
llvm::cl::value_desc("filename"), llvm::cl::init("-"), cl::cat(category)
);
Copy link

Copilot AI Oct 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The line break changes appear to be only formatting changes that don't affect functionality. Consider using a consistent formatting style throughout the file.

Copilot uses AI. Check for mistakes.
Comment on lines 365 to +393
auto contracts_file_path =
ConfigurationFile::getInstance().resolve_path(spec.implementation.code_file);
ConfigurationFile::getInstance().resolve_path(spec.implementation->code_file);
Copy link

Copilot AI Oct 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential null pointer dereference. The code accesses spec.implementation->code_file without verifying that spec.implementation is not null, even though there's a check for !spec.implementation just above. The logic should be restructured to avoid this inconsistency.

Copilot uses AI. Check for mistakes.
std::string severity;
Implementation implementation;
std::optional< std::string > contract_module;
ContractType type; // "STATIC" or "RUNTIME"
Copy link

Copilot AI Oct 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment should be updated to reflect that type is an enum value, not a string. It should read // ContractType::STATIC or ContractType::RUNTIME

Suggested change
ContractType type; // "STATIC" or "RUNTIME"
ContractType type; // ContractType::STATIC or ContractType::RUNTIME

Copilot uses AI. Check for mistakes.
targetAttr = ::contracts::TargetAttr::get(
ctx, pred.target, *pred.arg_index, mlir::FlatSymbolRefAttr()
);
targetAttr.dump();
Copy link

Copilot AI Oct 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This debug statement targetAttr.dump() should be removed as it appears to be leftover debugging code that will produce unwanted output in production.

Suggested change
targetAttr.dump();

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants