mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-12 15:11:02 +00:00
Strip minsize attribute from functions with large div/rem (#390)
That's a workaround to avoid LLVM backend crash while selecting instruction for 256-bit integer division. The workaround needs to be removed after we switch to newest inkwell that has a fix in RISC-V backend --------- Signed-off-by: kvp <mammal_windier8j@icloud.com>
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
|
||||
use crate::tests::cli::utils::{
|
||||
self, assert_command_failure, assert_command_success, assert_equal_exit_codes, execute_resolc,
|
||||
execute_solc, RESOLC_YUL_FLAG, SOLIDITY_CONTRACT_PATH, YUL_MEMSET_CONTRACT_PATH,
|
||||
execute_solc, RESOLC_YUL_FLAG, SOLIDITY_CONTRACT_PATH, SOLIDITY_LARGE_DIV_REM_CONTRACT_PATH,
|
||||
YUL_MEMSET_CONTRACT_PATH,
|
||||
};
|
||||
|
||||
const LEVELS: &[char] = &['0', '1', '2', '3', 's', 'z'];
|
||||
@@ -56,3 +57,26 @@ fn disable_solc_optimzer() {
|
||||
|
||||
assert_ne!(enabled.stdout, disabled.stdout);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_large_div_rem_expansion() {
|
||||
for level in LEVELS {
|
||||
let optimization_argument = format!("-O{level}");
|
||||
let arguments = &[SOLIDITY_LARGE_DIV_REM_CONTRACT_PATH, &optimization_argument];
|
||||
let resolc_result = utils::execute_resolc(arguments);
|
||||
assert!(
|
||||
resolc_result.success,
|
||||
"Providing the level `{optimization_argument}` should succeed with exit code {}, got {}.\nDetails: {}",
|
||||
revive_common::EXIT_CODE_SUCCESS,
|
||||
resolc_result.code,
|
||||
resolc_result.stderr
|
||||
);
|
||||
|
||||
assert!(
|
||||
resolc_result
|
||||
.stderr
|
||||
.contains("Compiler run successful. No output requested"),
|
||||
"Expected the output to contain a success message when providing the level `{optimization_argument}`."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,10 @@ pub const YUL_MEMSET_CONTRACT_PATH: &str = "src/tests/data/yul/memset.yul";
|
||||
pub const STANDARD_JSON_CONTRACTS_PATH: &str =
|
||||
"src/tests/data/standard_json/solidity_contracts.json";
|
||||
|
||||
/// The simple Solidity contract containing i256 divisions and remains that should be compiled
|
||||
/// correctly
|
||||
pub const SOLIDITY_LARGE_DIV_REM_CONTRACT_PATH: &str = "src/tests/data/solidity/large_div_rem.sol";
|
||||
|
||||
/// The `resolc` YUL mode flag.
|
||||
pub const RESOLC_YUL_FLAG: &str = "--yul";
|
||||
/// The `--yul` option was deprecated in Solidity 0.8.27 in favor of `--strict-assembly`.
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8;
|
||||
|
||||
contract LargeDivRem {
|
||||
function rem_2(int n) public pure returns (int q) {
|
||||
assembly {
|
||||
q := smod(n, 2)
|
||||
}
|
||||
}
|
||||
|
||||
function div_2(int n) public pure returns (int q) {
|
||||
assembly {
|
||||
q := sdiv(n, 2)
|
||||
}
|
||||
}
|
||||
|
||||
function rem_7(int n) public pure returns (int q) {
|
||||
assembly {
|
||||
q := smod(n, 7)
|
||||
}
|
||||
}
|
||||
|
||||
function div_7(int n) public pure returns (int q) {
|
||||
assembly {
|
||||
q := sdiv(n, 2)
|
||||
}
|
||||
}
|
||||
|
||||
function rem_k(int n, int k) public pure returns (int q) {
|
||||
assembly {
|
||||
q := smod(n, k)
|
||||
}
|
||||
}
|
||||
|
||||
function div_k(int n, int k) public pure returns (int q) {
|
||||
assembly {
|
||||
q := sdiv(n, k)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user