Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2024-08-20
15:41
Merge [42d8ed498a63398c], "[84a5355235]: two more cases of sizeof(long) -> sizeof(Tcl_WideInt), sinc... check-in: 6cd8831a51 user: pooryorick tags: unchained, INCOMPATIBLE_LICENSE
15:34
Merge [73da5acb07ce0b3e], "Fix [84a5355235] (not visible in 8.6, but meant to be forwared to 8.7)" a... check-in: f277124b01 user: pooryorick tags: unchained, INCOMPATIBLE_LICENSE
2023-08-25
15:20 • Closed ticket [84a5355235]: expr {(-549755813888 >> 32) & 0xFF} ... artifact: 804089efcf user: jan.nijtmans
15:18
[84a5355235]: two more cases of sizeof(long) -> sizeof(Tcl_WideInt), since that's the unit we are do... check-in: 6a9a8809f2 user: jan.nijtmans tags: core-8-branch
2023-08-24
23:14 • Open ticket [84a5355235]: expr {(-549755813888 >> 32) & 0xFF} pl... artifact: 6568e09658 user: pointsman
2023-08-23
20:22 • Closed ticket [84a5355235]. artifact: 0d34e63e0a user: jan.nijtmans
20:22 • Ticket [84a5355235]: 3 changes artifact: 7d731ac94d user: jan.nijtmans
16:13
Fix [84a5355235] (not visible in 8.6, but meant to be forwared to 8.7) check-in: b3e43fc764 user: jan.nijtmans tags: core-8-6-branch
2023-08-14
11:37 • Ticket [84a5355235] expr {(-549755813888 >> 32) & 0xFF} status s... artifact: bab4df61b8 user: chrstphrchvz
2023-08-13
15:34 • Ticket [84a5355235]: 4 changes artifact: 702063e228 user: jan.nijtmans
15:32 • Ticket [84a5355235]: 3 changes artifact: 3b3e9c3274 user: jan.nijtmans
14:49 • Ticket [84a5355235]: 3 changes artifact: a3f2bdfb87 user: chrstphrchvz
00:38 • Ticket [84a5355235]: 4 changes artifact: df17903b96 user: pointsman
2023-08-09
22:41 • Ticket [84a5355235]: 3 changes artifact: 8d0a4419c1 user: pointsman
2023-08-08
23:41 • New ticket [84a5355235]. artifact: e414388ff6 user: pointsman

[expr {(-549755813888 >> 32) & 0xFF}]

Closed / Fixed84a5355235e676b42ec000f1289fe03ce8ea824cCreated 3 years agoUpdated 3 years ago
Descriptionplain2023-08-08 23:41:11
With Tcl trunk on linux (debian, gcc 10-2.1)

puts [expr {(-549755813888 >> 32) & 0xFF}]

returns 128 to me.

On windows, build with mingw, gcc 8.1.0 the same line of
code returns 255.
Referenced by4
pointsmanplain2023-08-09 22:41:25
Confirmed for Tcl 9 on 64-bit Windows vc build, 8.7 on 32-bit linux,
OpenBSD 32-bit machine: 8.6:128, 9.0:255, OpenBSD 64-bit machine, 8.6
and 9.0: 128, mac M1 ARM: 128, by reports. The right answer would be
128, I think.

This is perhaps related:

puts [expr {3537118876014219 >> 51}]

Tcl 9 on 64-bit linux: 1 Tcl 9 on 64-bit Windows 0
pointsmanplain2023-08-13 00:38:49
Apparently this was introduced with the implementation of TIP 484.
Since [30f95df8b0] (5 and a half years ago!) the two examples given
so far return the (I think) wrong result on 64-bit windows (the platform
I tested, I suspect thats true for the other reported failing platforms
also). Prior to that commit the results are the same as on 64-bit linux.
chrstphrchvzwiki2023-08-13 14:49:17

In the case for INST_RSHIFT in TEBCresume() (tclExecute.c line 6080 on core-8-branch):

		    /*
		     * Quickly force large right shifts to 0 or -1.
		     */
if (w2 >= (Tcl_WideInt)(CHAR_BIT*sizeof(long))) {

Changing sizeof(long) to sizeof(Tcl_WideInt) appears to fix this issue; I believe that is the appropriate fix since TIP 484 means 32-bit long is no longer used for Tcl integer values. I have not looked for whether the same fix is needed elsewhere for similar issues.

I suggest that a test case for this issue be added to expr.test (only the right shift is important, not the bitwise AND).

jan.nijtmanswiki2023-08-13 15:32:42

I'm on vacation now, without laptop. But reading the analysis, +1 for the proposed solution. A testcase would be very nice too!

jan.nijtmanswiki2023-08-13 15:34:20

Please fix 8.7 as well, I expect the same problem there

chrstphrchvzwiki2023-08-14 11:37:39

Better yet, I suggest following DRY and using sizeof(w1) instead, and then backporting the change and the test to 8.6.

jan.nijtmanswiki2023-08-23 20:22:00

Fixed [here] as suggested. Many Thanks!

jan.nijtmans Closed ticket [84a5355235]. [History diff]2023-08-23 20:22:11
pointsmanplain2023-08-24 23:14:54
Thanks, that works for the reported cases and help me to continue
my testing work with a Tcl 9 adapted tcllib branch.

The root cause here was that sizeof(long) returns something else
under 64-bit windows then on most other 64-bit platforms. That
is obviously a problem: depending on input not always the same
code path is called on different platforms.

Beside the cases you fixed there are two more such sizeof(long)
calls in tclExecute.c:

[https://core.tcl-lang.org/tcl/file?udc=1&ln=8848&ci=73da5acb07ce0b3e&name=generic%2FtclExecute.c]

[https://core.tcl-lang.org/tcl/file?udc=1&ln=8878&ci=73da5acb07ce0b3e&name=generic%2FtclExecute.c]

Perhaps you can say much easier than me if this two are harmless - I would have to get familiar with that code first.
jan.nijtmanswiki2023-08-25 15:20:17

See: [6a9a8809f29fa1be]

Closing now

Log in (anonymous is fine) to add a comment.