[llvm] r329238 - [WebAssembly] Only write 32-bits for WebAssembly::OPERAND_OFFSET32
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 4 15:27:58 PDT 2018
Author: sbc
Date: Wed Apr 4 15:27:58 2018
New Revision: 329238
URL: http://llvm.org/viewvc/llvm-project?rev=329238&view=rev
Log:
[WebAssembly] Only write 32-bits for WebAssembly::OPERAND_OFFSET32
A bug was found where an offset of -1 would generate an encoding
of max int64 which is invalid in the binary format.
Differential Revision: https://reviews.llvm.org/D45280
Added:
llvm/trunk/test/MC/WebAssembly/offset.ll
Modified:
llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCCodeEmitter.cpp
Modified: llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCCodeEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCCodeEmitter.cpp?rev=329238&r1=329237&r2=329238&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCCodeEmitter.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCCodeEmitter.cpp Wed Apr 4 15:27:58 2018
@@ -23,9 +23,11 @@
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/MC/MCSymbol.h"
+#include "llvm/Support/Debug.h"
#include "llvm/Support/EndianStream.h"
#include "llvm/Support/LEB128.h"
#include "llvm/Support/raw_ostream.h"
+
using namespace llvm;
#define DEBUG_TYPE "mccodeemitter"
@@ -86,8 +88,11 @@ void WebAssemblyMCCodeEmitter::encodeIns
assert(Desc.TSFlags == 0 &&
"WebAssembly non-variable_ops don't use TSFlags");
const MCOperandInfo &Info = Desc.OpInfo[i];
+ DEBUG(dbgs() << "Encoding immediate: type=" << int(Info.OperandType) << "\n");
if (Info.OperandType == WebAssembly::OPERAND_I32IMM) {
encodeSLEB128(int32_t(MO.getImm()), OS);
+ } else if (Info.OperandType == WebAssembly::OPERAND_OFFSET32) {
+ encodeULEB128(uint32_t(MO.getImm()), OS);
} else if (Info.OperandType == WebAssembly::OPERAND_I64IMM) {
encodeSLEB128(int64_t(MO.getImm()), OS);
} else if (Info.OperandType == WebAssembly::OPERAND_GLOBAL) {
Added: llvm/trunk/test/MC/WebAssembly/offset.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/WebAssembly/offset.ll?rev=329238&view=auto
==============================================================================
--- llvm/trunk/test/MC/WebAssembly/offset.ll (added)
+++ llvm/trunk/test/MC/WebAssembly/offset.ll Wed Apr 4 15:27:58 2018
@@ -0,0 +1,21 @@
+; RUN: llc -filetype=obj %s -o - | obj2yaml | FileCheck %s
+
+target triple = "wasm32-unknown-unknown-wasm"
+
+; CHECK: - Type: CODE
+; CHECK-NEXT: Functions:
+; CHECK-NEXT: - Index: 0
+; CHECK-NEXT: Locals:
+; CHECK-NEXT: Body: 41002802FFFFFFFF0F0B
+define i32 @load_i32_from_negative_address() {
+ %t = load i32, i32* inttoptr (i32 -1 to i32*)
+ ret i32 %t
+}
+
+; CHECK-NEXT: - Index: 1
+; CHECK-NEXT: Locals:
+; CHECK-NEXT: Body: 41002802030B
+define i32 @load_i32_from_wrapped_address() {
+ %t = load i32, i32* inttoptr (i32 4294967299 to i32*)
+ ret i32 %t
+}
More information about the llvm-commits
mailing list