solang icon indicating copy to clipboard operation
solang copied to clipboard

Modifying slot causes compilation crash.

Open Subway2023 opened this issue 10 months ago • 1 comments

Version: v0.3.3: Atlantis

contract C {
    struct S { bool f; }
    S s;
    function f(uint256 a) internal returns (S storage c) {
        assembly {
            switch a
                default { c.slot := s.slot }
        }
    }
}
solang compile --target solana  test.sol

solang: llvm/include/llvm/IR/Instructions.h:2765: void llvm::PHINode::setIncomingValue(unsigned int, llvm::Value*): Assertion `getType() == V->getType() && "All operands to PHI node must be the same type as the PHI node!"' failed.
Aborted (core dumped)

Subway2023 avatar Feb 08 '25 04:02 Subway2023

Arithmetic on user-defined type in assembly also cause the error

type U8 is uint8;
using {yoloAdd as +, yoloDiv as /} for U8 global;

function yoloAdd(U8 x, U8 y) pure returns (U8 z) {
    assembly {
        z := add(x, y) // Still no cleanup, but now returns U8.
    }
}

function yoloDiv(U8 x, U8 y) pure returns (U8 z) {
    assembly {
        z := div(x, y) // Still no cleanup, but now returns U8.
    }
}

contract C {
    function divAddNoOverflow(U8 a, U8 b, U8 c) external pure returns (uint8) {
        return U8.unwrap(a / (b + c));
    }
}
solang_v0.3.3: llvm/include/llvm/IR/Instructions.h:2765: void llvm::PHINode::setIncomingValue(unsigned int, llvm::Value*): Assertion `getType() == V->getType() && "All operands to PHI node must be the same type as the PHI node!"' failed.
/mnt/subw3/crossCompilerFuzz/compiler/bin/solangcom: line 6: 645997 Aborted                 (core dumped) /mnt/subw3/crossCompilerFuzz/compiler/bin/solang_v0.3.3 compile --target solana "$1" -o /mnt/subw3/crossCompilerFuzz/output/temp

Subway2023 avatar Apr 16 '25 04:04 Subway2023