diff options
author | Daniel Wirtz <dcode@dcode.io> | 2020-09-02 03:28:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-02 03:28:47 +0200 |
commit | 949bf4916c6dcd9409888a677739c4c844bb9eda (patch) | |
tree | c6b633ba215f4e3e7e4412fc56a19f34760f9984 /src/wasm/literal.cpp | |
parent | 85234cb540c2b2863dfea6c20496dcb451df8889 (diff) | |
download | binaryen-949bf4916c6dcd9409888a677739c4c844bb9eda.tar.gz binaryen-949bf4916c6dcd9409888a677739c4c844bb9eda.tar.bz2 binaryen-949bf4916c6dcd9409888a677739c4c844bb9eda.zip |
Harden exnref literals (#3092)
* Make `Literal::type` immutable to guarantee that we do not lose track of `Literal::exn` by changing the literal's type
* Add an assert to guarantee that we don't create `exnref` literals without an `ExceptionPackage` (for now)
* Enforce rvalue reference when creating an `exnref` Literal from a `std::unique_ptr<ExceptionPackage>`, avoiding a redundant copy by means of requiring `std::move`
Diffstat (limited to 'src/wasm/literal.cpp')
-rw-r--r-- | src/wasm/literal.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp index ce1c73d56..3f635ca19 100644 --- a/src/wasm/literal.cpp +++ b/src/wasm/literal.cpp @@ -136,29 +136,29 @@ ExceptionPackage Literal::getExceptionPackage() const { Literal Literal::castToF32() { assert(type == Type::i32); - Literal ret(i32); - ret.type = Type::f32; + Literal ret(Type::f32); + ret.i32 = i32; return ret; } Literal Literal::castToF64() { assert(type == Type::i64); - Literal ret(i64); - ret.type = Type::f64; + Literal ret(Type::f64); + ret.i64 = i64; return ret; } Literal Literal::castToI32() { assert(type == Type::f32); - Literal ret(i32); - ret.type = Type::i32; + Literal ret(Type::i32); + ret.i32 = i32; return ret; } Literal Literal::castToI64() { assert(type == Type::f64); - Literal ret(i64); - ret.type = Type::i64; + Literal ret(Type::i64); + ret.i64 = i64; return ret; } |