ruby-changes:46389
From: nobu <ko1@a...>
Date: Sat, 29 Apr 2017 11:58:59 +0900 (JST)
Subject: [ruby-changes:46389] nobu:r58503 (trunk): node.h: sign-extend
nobu 2017-04-29 11:58:53 +0900 (Sat, 29 Apr 2017) New Revision: 58503 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58503 Log: node.h: sign-extend * node.h (nd_line): should sign-extend. shifting `VALUE` extends with zero bits if `sizeof(VALUE)` equals to `sizeof(int)`. the zero bits are truncated if `sizeof(VALUE)` is bigger enough. [ruby-core:80920] [Bug #13523] Modified files: trunk/node.h trunk/test/ruby/test_parse.rb Index: node.h =================================================================== --- node.h (revision 58502) +++ node.h (revision 58503) @@ -277,7 +277,7 @@ typedef struct RNode { https://github.com/ruby/ruby/blob/trunk/node.h#L277 #define NODE_LSHIFT (NODE_TYPESHIFT+7) #define NODE_LMASK (((SIGNED_VALUE)1<<(sizeof(VALUE)*CHAR_BIT-NODE_LSHIFT))-1) -#define nd_line(n) (int)(RNODE(n)->flags>>NODE_LSHIFT) +#define nd_line(n) (int)(((SIGNED_VALUE)RNODE(n)->flags)>>NODE_LSHIFT) #define nd_set_line(n,l) \ RNODE(n)->flags=((RNODE(n)->flags&~((VALUE)(-1)<<NODE_LSHIFT))|((VALUE)((l)&NODE_LMASK)<<NODE_LSHIFT)) Index: test/ruby/test_parse.rb =================================================================== --- test/ruby/test_parse.rb (revision 58502) +++ test/ruby/test_parse.rb (revision 58503) @@ -978,6 +978,16 @@ x = __ENCODING__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_parse.rb#L978 assert_equal(line, obj.location.lineno, bug) end + def test_negative_line_number + bug = '[ruby-core:80920] [Bug #13523]' + obj = Object.new + obj.instance_eval("def t(e = false);raise if e; __LINE__;end", "test", -100) + assert_equal(-100, obj.t, bug) + assert_equal(-100, obj.method(:t).source_location[1], bug) + e = assert_raise(RuntimeError) {obj.t(true)} + assert_equal(-100, e.backtrace_locations.first.lineno, bug) + end + =begin def test_past_scope_variable assert_warning(/past scope/) {catch {|tag| eval("BEGIN{throw tag}; tap {a = 1}; a")}} -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/