From cd469285ddf18521b5f3c7d9049ac96356e15d28 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Fri, 24 Feb 2023 13:50:22 -0500 Subject: [PATCH 1/6] [SH] Fix unsued function warnings. --- arch/SH/SHDisassembler.c | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/arch/SH/SHDisassembler.c b/arch/SH/SHDisassembler.c index 4591669f0..618252807 100644 --- a/arch/SH/SHDisassembler.c +++ b/arch/SH/SHDisassembler.c @@ -564,13 +564,6 @@ static bool opMOV_rpd(uint16_t code, uint64_t address, MCInst *MI, return MCDisassembler_Success; } -static bool opDIV0U(uint16_t code, uint64_t address, MCInst *MI, cs_mode mode, - sh_info *info, cs_detail *detail) -{ - MCInst_setOpcode(MI, SH_INS_DIV0U); - return MCDisassembler_Success; -} - opRR(ISA_ALL, TST, 0) opRR(ISA_ALL, AND, 0) opRR(ISA_ALL, XOR, 0) @@ -1233,21 +1226,6 @@ static bool opMOVA(uint16_t code, uint64_t address, MCInst *MI, cs_mode mode, return MCDisassembler_Success; } -static bool opc8xx(uint16_t code, uint64_t address, MCInst *MI, cs_mode mode, - sh_info *info, cs_detail *detail) -{ - int imm = (code & 0x00ff); - sh_insn insn[] = {SH_INS_TST, SH_INS_AND, SH_INS_XOR, SH_INS_OR}; - MCInst_setOpcode(MI, insn[(code >> 8) & 3]); - set_imm(info, 1, imm); - if (code & 0x0400) { - set_mem(info, SH_OP_MEM_GBR_R0, SH_REG_INVALID, 0, 8, detail); - } else { - set_reg(info, SH_REG_R0, write, detail); - } - return MCDisassembler_Success; -} - static bool opMOV_i(uint16_t code, uint64_t address, MCInst *MI, cs_mode mode, sh_info *info, cs_detail *detail) { From 4f7f86c0c20c1bb5fd854f53d26ddd9cbe56a8f5 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Thu, 23 Feb 2023 18:16:50 -0500 Subject: [PATCH 2/6] [SH] Fix parantheses and int-in-bool-context build warnings. --- CMakeLists.txt | 2 ++ cs.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3502df2ca..a08525325 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,8 @@ # For MSVC_RUNTIME_LIBRARY cmake_minimum_required(VERSION 3.15) +add_compile_options(-Wunused-function -Warray-bounds -Wunused-variable -Wparentheses -Wint-in-bool-context) + if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) message(FATAL_ERROR "In-tree builds are not supported. Run CMake from a separate directory: cmake -B build") endif() diff --git a/cs.c b/cs.c index 73c70fd52..09db59e03 100644 --- a/cs.c +++ b/cs.c @@ -369,8 +369,8 @@ bool CAPSTONE_API cs_support(int query) (1 << CS_ARCH_M68K) | (1 << CS_ARCH_TMS320C64X) | (1 << CS_ARCH_M680X) | (1 << CS_ARCH_EVM) | (1 << CS_ARCH_RISCV) | (1 << CS_ARCH_MOS65XX) | - (1 << CS_ARCH_WASM) | (1 << CS_ARCH_BPF)) | - (1 << CS_ARCH_SH); + (1 << CS_ARCH_WASM) | (1 << CS_ARCH_BPF) | + (1 << CS_ARCH_SH)); if ((unsigned int)query < CS_ARCH_MAX) return all_arch & (1 << query); From 52ab4fd9741ebc30c021b3a633ccfad6bd9cd2d3 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Fri, 24 Feb 2023 14:19:53 -0500 Subject: [PATCH 3/6] Add MSVC options. --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a08525325..da07cde6c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,11 @@ # For MSVC_RUNTIME_LIBRARY cmake_minimum_required(VERSION 3.15) -add_compile_options(-Wunused-function -Warray-bounds -Wunused-variable -Wparentheses -Wint-in-bool-context) +if (MSVC) + add_compile_options(/W1 /w14189 /w16268) +else() + add_compile_options(-Wunused-function -Warray-bounds -Wunused-variable -Wparentheses -Wint-in-bool-context) +endif() if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) message(FATAL_ERROR "In-tree builds are not supported. Run CMake from a separate directory: cmake -B build") From 854153e7c9574d6b347691cc98e0955559c9bd96 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Fri, 24 Feb 2023 14:20:41 -0500 Subject: [PATCH 4/6] [SH] Fix several unused variable warnings. --- CMakeLists.txt | 2 +- arch/SH/SHDisassembler.c | 9 --------- tests/test_sh.c | 5 ----- 3 files changed, 1 insertion(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index da07cde6c..03b1d2263 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ # For MSVC_RUNTIME_LIBRARY cmake_minimum_required(VERSION 3.15) -if (MSVC) +if (CMAKE_C_COMPILER_ID MATCHES "MSVC") add_compile_options(/W1 /w14189 /w16268) else() add_compile_options(-Wunused-function -Warray-bounds -Wunused-variable -Wparentheses -Wint-in-bool-context) diff --git a/arch/SH/SHDisassembler.c b/arch/SH/SHDisassembler.c index 618252807..e3a685d7b 100644 --- a/arch/SH/SHDisassembler.c +++ b/arch/SH/SHDisassembler.c @@ -374,7 +374,6 @@ static bool op0xx8(uint16_t code, uint64_t address, MCInst *MI, cs_mode mode, {-1, SH_INS_INVALID, ISA_ALL, none}, }; - int lvl = isalevel(mode); sh_insn insn = lookup_insn(list, insn_code, mode); if (code & 0x0f00) return MCDisassembler_Fail; @@ -730,8 +729,6 @@ static bool op4xx5(uint16_t code, uint64_t address, MCInst *MI, cs_mode mode, sh_info *info, cs_detail *detail) { int r = (code >> 8) & 0x0f; - uint16_t *regs; - uint8_t *count; enum direction rw; static const struct ri_list list[] = { {0, SH_INS_ROTR, ISA_ALL, none}, @@ -1130,7 +1127,6 @@ opLDRSE(LDRE) static bool op##insn##_i(uint16_t code, uint64_t address, MCInst *MI, \ cs_mode mode, sh_info *info, cs_detail *detail) \ { \ - int dsp = code & 0x00ff; \ MCInst_setOpcode(MI, SH_INS_##insn); \ set_imm(info, 0, code & 0xff); \ set_reg(info, SH_REG_R0, write, detail); \ @@ -1146,7 +1142,6 @@ opImmR0(OR) static bool op##insn##_B(uint16_t code, uint64_t address, MCInst *MI, \ cs_mode mode, sh_info *info, cs_detail *detail) \ { \ - int dsp = code & 0x00ff; \ MCInst_setOpcode(MI, SH_INS_##insn); \ set_imm(info, 0, code & 0xff); \ set_mem(info, SH_OP_MEM_GBR_R0, SH_REG_R0, 0, 8, detail); \ @@ -1587,7 +1582,6 @@ static bool set_dsp_move_d(sh_info *info, int xy, uint16_t code, cs_mode mode, c int a; int d; int dir; - int sz; int op; static const sh_reg base[] = {SH_REG_DSP_A0, SH_REG_DSP_X0}; switch (xy) { @@ -1802,7 +1796,6 @@ static bool dsp_op_cc0_2opr(uint32_t code, sh_info *info, sh_insn insn, static bool decode_dsp_3op(const uint32_t code, sh_info *info, cs_detail *detail) { - int r; int cc = (code >> 8) & 3; int sx = (code >> 6) & 3; int sy = (code >> 4) & 3; @@ -2030,8 +2023,6 @@ static bool decode_dsp_3op(const uint32_t code, sh_info *info, static bool decode_dsp_p(const uint32_t code, MCInst *MI, cs_mode mode, sh_info *info, cs_detail *detail) { - bool ret; - int dz = code & 0x0f; MCInst_setOpcode(MI, SH_INS_DSP); if (!decode_dsp_d(code >> 16, MI, mode, info, detail)) diff --git a/tests/test_sh.c b/tests/test_sh.c index 89310bbe8..a57811052 100644 --- a/tests/test_sh.c +++ b/tests/test_sh.c @@ -37,10 +37,6 @@ static void print_string_hex_short(unsigned char *str, size_t len) printf("%02x", *c & 0xff); } -static const char *s_access[] = { - "UNCHANGED", "READ", "WRITE", "READ | WRITE", -}; - static void print_read_write_regs(csh handle, cs_detail *detail) { int i; @@ -89,7 +85,6 @@ static void print_insn_detail(csh handle, cs_insn *insn) for (i = 0; i < sh->op_count; i++) { cs_sh_op *op = &(sh->operands[i]); - const char *comment; switch ((int)op->type) { default: From c3cc9ae533bc25327361a8d611aaaf413b1ad73f Mon Sep 17 00:00:00 2001 From: Rot127 Date: Thu, 6 Apr 2023 03:57:28 -0500 Subject: [PATCH 5/6] Remove unused variable --- arch/SH/SHInstPrinter.c | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/SH/SHInstPrinter.c b/arch/SH/SHInstPrinter.c index 51b20ec04..83fbd52fc 100644 --- a/arch/SH/SHInstPrinter.c +++ b/arch/SH/SHInstPrinter.c @@ -351,7 +351,6 @@ void SH_printInst(MCInst* MI, SStream* O, void* PrinterInfo) { #ifndef CAPSTONE_DIET sh_info *info = (sh_info *)PrinterInfo; - cs_detail *detail = MI->flat_insn->detail; int i; int imm; From f7fe2fc9cc29ed170c3a57da7574091866e22e32 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Thu, 6 Apr 2023 03:58:09 -0500 Subject: [PATCH 6/6] Move "add_compile_options" behind project() command. --- CMakeLists.txt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 270a08f0f..395e1937f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,6 @@ # For MSVC_RUNTIME_LIBRARY cmake_minimum_required(VERSION 3.15) -if (CMAKE_C_COMPILER_ID MATCHES "MSVC") - add_compile_options(/W1 /w14189 /w16268) -else() - add_compile_options(-Wunused-function -Warray-bounds -Wunused-variable -Wparentheses -Wint-in-bool-context) -endif() - if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) message(FATAL_ERROR "In-tree builds are not supported. Run CMake from a separate directory: cmake -B build") endif() @@ -31,6 +25,13 @@ project(capstone VERSION 5.0 ) +if (MSVC) + add_compile_options(/W1 /w14189 /w16268) +else() + add_compile_options(-Wunused-function -Warray-bounds -Wunused-variable -Wparentheses -Wint-in-bool-context) +endif() + + # to configure the options specify them in in the command line or change them in the cmake UI. # Don't edit the makefile! option(BUILD_SHARED_LIBS "Build shared library" OFF)