[前][次][番号順一覧][スレッド一覧]

ruby-changes:69227

From: Alan <ko1@a...>
Date: Thu, 21 Oct 2021 08:24:16 +0900 (JST)
Subject: [ruby-changes:69227] 00be5846e4 (master): Fix non RUBY_DEBUG build warnings

https://git.ruby-lang.org/ruby.git/commit/?id=00be5846e4

From 00be5846e4793b718da19dafec3f4ecf2d6d0692 Mon Sep 17 00:00:00 2001
From: Alan Wu <XrXr@u...>
Date: Tue, 19 Oct 2021 16:43:20 -0400
Subject: Fix non RUBY_DEBUG build warnings

On non RUBY_DEBUG builds, assert() compiles to nothing and the compiler
warns about uninitialized variables in those code paths. Replace
those asserts with rb_bug() to fix the warnings and do the assert in
all builds. Since yjit_asm_tests.c compiles outside of Ruby, it needed
a distinct version of rb_bug().

Also put YJIT_STATS check for function delcaration that is only defined
in YJIT_STATS builds.
---
 misc/test_yjit_asm.sh |  2 +-
 yjit_asm.c            | 10 +++++-----
 yjit_asm_tests.c      |  9 +++++++++
 yjit_codegen.c        |  2 +-
 yjit_iface.h          |  2 ++
 5 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/misc/test_yjit_asm.sh b/misc/test_yjit_asm.sh
index 546acf39c9..1498789246 100755
--- a/misc/test_yjit_asm.sh
+++ b/misc/test_yjit_asm.sh
@@ -3,7 +3,7 @@ https://github.com/ruby/ruby/blob/trunk/misc/test_yjit_asm.sh#L3
 set -e
 set -x
 
-clang -std=gnu99 -Wall -Werror -Wno-error=unused-function -Wshorten-64-to-32 yjit_asm.c yjit_asm_tests.c -o asm_test
+clang -std=gnu99 -Wall -Werror -Wno-error=unused-function -Wshorten-64-to-32 yjit_asm_tests.c -o asm_test
 
 ./asm_test
 
diff --git a/yjit_asm.c b/yjit_asm.c
index 15da7a37a1..5e433f5ea4 100644
--- a/yjit_asm.c
+++ b/yjit_asm.c
@@ -78,7 +78,7 @@ x86opnd_t mem_opnd_sib(uint32_t num_bits, x86opnd_t base_reg, x86opnd_t index_re https://github.com/ruby/ruby/blob/trunk/yjit_asm.c#L78
         scale_exp = 0;
         break;
       default:
-        assert(false && "scale not one of 1,2,4,8");
+        rb_bug("yjit: scale not one of 1,2,4,8");
         break;
     }
 
@@ -466,7 +466,7 @@ static bool rex_needed(x86opnd_t opnd) https://github.com/ruby/ruby/blob/trunk/yjit_asm.c#L466
         return (opnd.as.mem.base_reg_no > 7) || (opnd.as.mem.has_idx && opnd.as.mem.idx_reg_no > 7);
     }
 
-    assert (false);
+    rb_bug("unreachable");
 }
 
 // Check if an SIB byte is needed to encode this operand
@@ -643,7 +643,7 @@ static void cb_write_rm( https://github.com/ruby/ruby/blob/trunk/yjit_asm.c#L643
         else if (dsize == 32)
             mod = 2;
         else
-            assert (false);
+            rb_bug("unreachable");
     }
 
     // Encode the reg field
@@ -726,7 +726,7 @@ static void write_rm_unary( https://github.com/ruby/ruby/blob/trunk/yjit_asm.c#L726
     if (opnd.type == OPND_REG || opnd.type == OPND_MEM)
         opndSize = opnd.num_bits;
     else
-        assert (false && "invalid operand");
+        rb_bug("yjit: invalid operand");
 
     assert (opndSize == 8 || opndSize == 16 || opndSize == 32 || opndSize == 64);
     bool szPref = opndSize == 16;
@@ -856,7 +856,7 @@ static void cb_write_shift( https://github.com/ruby/ruby/blob/trunk/yjit_asm.c#L856
     if (opnd0.type == OPND_REG || opnd0.type == OPND_MEM)
         opndSize = opnd0.num_bits;
     else
-        assert (false && "shift: invalid first operand");
+        rb_bug("yjit: shift: invalid first operand");
 
     assert (opndSize == 16 || opndSize == 32 || opndSize == 64);
     bool szPref = opndSize == 16;
diff --git a/yjit_asm_tests.c b/yjit_asm_tests.c
index 5f2376127c..295edb86e5 100644
--- a/yjit_asm_tests.c
+++ b/yjit_asm_tests.c
@@ -6,6 +6,15 @@ https://github.com/ruby/ruby/blob/trunk/yjit_asm_tests.c#L6
 #include <string.h>
 #include <assert.h>
 
+// This test executable doesn't compile with the rest of Ruby
+// so we need to define a rb_bug().
+_Noreturn
+static void rb_bug(char *message)
+{
+    fprintf(stderr, "%s\n", message);
+    abort();
+}
+
 #include "yjit_asm.c"
 
 // Print the bytes in a code block
diff --git a/yjit_codegen.c b/yjit_codegen.c
index 54fb6df2c1..3b39c043b5 100644
--- a/yjit_codegen.c
+++ b/yjit_codegen.c
@@ -1455,7 +1455,7 @@ jit_chain_guard(enum jcc_kinds jcc, jitstate_t *jit, const ctx_t *ctx, uint8_t d https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L1455
         target0_gen_fn = gen_jbe_to_target0;
         break;
       default:
-        RUBY_ASSERT(false && "unimplemented jump kind");
+        rb_bug("yjit: unimplemented jump kind");
         break;
     };
 
diff --git a/yjit_iface.h b/yjit_iface.h
index 5f070fc19f..92443dceb6 100644
--- a/yjit_iface.h
+++ b/yjit_iface.h
@@ -22,8 +22,10 @@ static VALUE *yjit_iseq_pc_at_idx(const rb_iseq_t *iseq, uint32_t insn_idx); https://github.com/ruby/ruby/blob/trunk/yjit_iface.h#L22
 static int yjit_opcode_at_pc(const rb_iseq_t *iseq, const VALUE *pc);
 static void yjit_print_iseq(const rb_iseq_t *iseq);
 
+#if YJIT_STATS
 // this function *must* return passed exit_pc
 static const VALUE *yjit_count_side_exit_op(const VALUE *exit_pc);
+#endif
 
 static void yjit_unlink_method_lookup_dependency(block_t *block);
 static void yjit_block_assumptions_free(block_t *block);
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]