solang icon indicating copy to clipboard operation
solang copied to clipboard

[ICE]: BitwiseNot followed by a variable in a struct causes an error.

Open Subway2023 opened this issue 8 months ago • 1 comments

Version: v0.3.3: v0.3.3-70-g32a45ea1 Description: Solc can compile normally. The error location in the source code can be found at the link.

contract test {
    struct ComplexType {
        bool flag;
        uint32 value32;
        uint64 value64;
    }

    function run(ComplexType memory x) public returns(uint256 y) {
        if (x.flag) y = 1;
        y = y * 0x100000000 | ~x.value32;
        y = y * 0x10000000000000000 | ~x.value64;
    }
}
thread 'main' panicked at /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/inkwell-0.4.0/src/values/enums.rs:286:13:
Found PointerValue(PointerValue { ptr_value: Value { name: "struct member1", address: 0x5a52fc9c8930, is_const: false, is_null: false, is_undef: false, llvm_value: "  %\"struct member1\" = getelementptr inbounds { i1, i32, i64 }, ptr %0, i32 0, i32 1", llvm_type: "ptr" } }) but expected the IntValue variant
stack backtrace:
   0: rust_begin_unwind
             at /rustc/7608018cbdac9e55d0d13529cf43adc33d53efcf/library/std/src/panicking.rs:665:5
   1: core::panicking::panic_fmt
             at /rustc/7608018cbdac9e55d0d13529cf43adc33d53efcf/library/core/src/panicking.rs:74:14
   2: inkwell::values::enums::BasicValueEnum::into_int_value
             at /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/inkwell-0.4.0/src/values/enums.rs:286:13
   3: solang::emit::expression::expression
             at ./src/emit/expression.rs:1312:21
   4: solang::emit::expression::expression
             at ./src/emit/expression.rs:1090:23
   5: solang::emit::expression::expression
             at ./src/emit/expression.rs:1163:21
   6: solang::emit::expression::expression
             at ./src/emit/expression.rs:1318:25
   7: solang::emit::instructions::process_instruction
             at ./src/emit/instructions.rs:78:21
   8: solang::emit::cfg::emit_cfg
             at ./src/emit/cfg.rs:211:13
   9: solang::emit::functions::emit_functions
             at ./src/emit/functions.rs:49:9
  10: solang::emit::solana::SolanaTarget::build
             at ./src/emit/solana/mod.rs:73:9
  11: solang::emit::binary::Binary::build
             at ./src/emit/binary.rs:185:31
  12: solang::emit::<impl solang::sema::ast::Contract>::binary
             at ./src/emit/mod.rs:376:9
  13: solang::contract_results
             at ./src/bin/solang.rs:414:18
  14: solang::compile
             at ./src/bin/solang.rs:272:17
  15: solang::main
             at ./src/bin/solang.rs:59:13
  16: core::ops::function::FnOnce::call_once
             at /root/.rustup/toolchains/nightly-2024-09-30-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Subway2023 avatar Mar 12 '25 05:03 Subway2023

Similarly, using ShiftLeft,ShiftRight with a variable in a struct on the right side also causes an error.

contract C {
    struct MyStruct {
        uint256 value;
    }

    mapping(uint256 => uint256) myMapping;

    function f(MyStruct memory a, MyStruct memory b) public returns (MyStruct memory) {
        a.value <<= b.value;
        return a;
    }
}

Subway2023 avatar Mar 12 '25 06:03 Subway2023