diff --git a/compiler/compiler.go b/compiler/compiler.go index 8707e1bc9..a4c2d2e8a 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -873,6 +873,10 @@ func (c *compilerContext) createPackage(irbuilder llvm.Builder, pkg *ssa.Package // with a LLVM intrinsic. continue } + if ok := b.defineCryptoIntrinsic(); ok { + // Body of this function was replaced + continue + } if member.Blocks == nil { // Try to define this as an intrinsic function. b.defineIntrinsicFunction() diff --git a/compiler/intrinsics.go b/compiler/intrinsics.go index d9d8bba5b..e60d16ebf 100644 --- a/compiler/intrinsics.go +++ b/compiler/intrinsics.go @@ -208,6 +208,23 @@ func (b *builder) defineMathOp() { b.CreateRet(result) } +func (b *builder) defineCryptoIntrinsic() bool { + if b.fn.Pkg.Pkg.Path() != "crypto/internal/constanttime" { + return false + } + + switch b.fn.Name() { + case "boolToUint8": + b.createFunctionStart(true) + param := b.getValue(b.fn.Params[0], b.fn.Pos()) + result := b.CreateZExt(param, b.ctx.Int8Type(), "") + b.CreateRet(result) + return true + } + + return false +} + // Implement most math/bits functions. // // This implements all the functions that operate on bits. It does not yet