|
2024-03-26
| ||
| 08:44 | • Ticket [1f40aa83c5] crash with CFLAGS=-ftrapv status still Closed with 5 oth... artifact: ce47821f25 user: jan.nijtmans | |
|
2024-03-25
| ||
| 20:24 | • Ticket [1f40aa83c5]: 4 changes artifact: be7ef99ffa user: sebres | |
|
2024-03-24
| ||
| 22:32 | • Ticket [1f40aa83c5]: 5 changes artifact: 0d486c6c48 user: sebres | |
| 17:58 | • Ticket [1f40aa83c5]: 5 changes artifact: 5e87430d01 user: jan.nijtmans | |
| 17:05 | • Closed ticket [1f40aa83c5]. artifact: 79b356a875 user: sebres | |
| 16:41 | • Ticket [1f40aa83c5]: 3 changes artifact: 19b3851197 user: sebres | |
| 16:37 | still one fix for [1f40aa83c552f597], now for freescan (overflow in tests clock-6.10e/clock-6.10f): ... check-in: 5696b3f72c user: sebres tags: tip-688 | |
| 15:55 | • Ticket [1f40aa83c5] crash with CFLAGS=-ftrapv status still Pending with 3 ot... artifact: 3f847c7113 user: jan.nijtmans | |
| 15:25 | • Ticket [1f40aa83c5]: 3 changes artifact: 0272e747eb user: sebres | |
| 14:40 | • Ticket [1f40aa83c5]: 3 changes artifact: 88c953de99 user: jan.nijtmans | |
|
2024-03-23
| ||
| 10:00 | • Pending ticket [1f40aa83c5]. artifact: b298037921 user: jan.nijtmans | |
| 09:59 | • Ticket [1f40aa83c5]: 5 changes artifact: b5bf4fa0f7 user: jan.nijtmans | |
|
2024-03-22
| ||
| 19:31 | • Closed ticket [1f40aa83c5]. artifact: ab2e2016c0 user: sebres | |
| 19:15 | fix for [1f40aa83c552f597]: the overflow check could mistakenly pass in some cases (so basically exp... check-in: 4fa26c98f2 user: sebres tags: tip-688 | |
| 09:12 | • Open ticket [1f40aa83c5]: crash with CFLAGS=-ftrapv plus 7 other changes artifact: e72c867bd3 user: jan.nijtmans | |
| 09:03 | Add testcase for bug [1f40aa83c5]: crash with CFLAGS=-ftrapv check-in: a601eda829 user: jan.nijtmans tags: tip-688 | |
|
2024-03-15
| ||
| 14:20 | • Closed ticket [1f40aa83c5]: crash with CFLAGS=-ftrapv plus 6 other changes artifact: 39ffd35891 user: sebres | |
| 14:14 | fixes [1f40aa83c552f597]: suppress integer-overflow trapping (atm, GCC "trapv" only) for intended pi... check-in: 176cb4ca94 user: sebres tags: sebres-9-0-clock-speedup-cr2 | |
| 12:38 | Mark 4 "clock" testcases with "knownBug". Ticket [1f40aa83c5] describes the details. check-in: a6414f845e user: jan.nijtmans tags: sebres-9-0-clock-speedup-cr2 | |
| 12:36 | • New ticket [1f40aa83c5] crash with CFLAGS=-ftrapv. artifact: e5d954a03c user: jan.nijtmans | |
crash with CFLAGS=-ftrapv
1) clock-6.9 2) clock-6.10 3) clock-34.16.1a 4) clock-34.16.1b
See: https://github.com/tcltk/tcl/actions/runs/8292646669/job/22694304229
For now, I marked those 4 testcases as "knownBug"
a601eda829Add testcase for bug [1f40aa83c5]: crash with CFLAGS=-ftrapv check-in2024-03-22 09:03:38a6414f845eMark 4 "clock" testcases with "knownBug". Ticket [1f40aa83c5] describes the details. check-in2024-03-15 12:38:17
Fixed in [176cb4ca94597dcc] by suppressing of integer-overflow trapping (at the moment, GCC "trapv" only) for intended pieces; test cases (knownBug) reverted.
By the way, imho usage of overflow trapping is bad (too expensive in gcc)... it's better use overflow detecting intrinsics where it's needed (and -fsanitize=signed-integer-overflow produces more efficient code, anyway).
Re-opening, because there really is a bug, discovered by the -ftrapv option. First:
$ tclsh9.0 % clock scan 27670116110564327424 -format %s integer value too large to represent % clock scan 27670116110564327424 AbortedThe first answer is correct: 27670116110564327424 in hex is 0x18000000000000000, which - indeed - is too large to represent in 64-bit. Now:
$ tclsh9.0 % clock scan 27670116110564327423 -format %s 9223372036854775807 % clock scan 27670116110564327423 Aborted
Now, the first command gives an - incorrect - answer: The hex value of 27670116110564327423 is 0x17fffffffffffffff, which is also too large to represent in 64-bit. The second crash - most likely - happened because my build was with CFLAGS=-ftrapv, and an overflow occurred somewhere else.
Compare this with Tcl 8.6:
$ tclsh8.6 % clock scan 27670116110564327423 -format %s integer value too large to represent % clock scan 27670116110564327423 89170590265200
Explanation: Let's parse the string "27670116110564327423" with function _str2wideInt(). After 19 iterations, the string is parsed almost completely, only the last digit is missing. "prev" has the value 2767011611056432742, which is 0x2666666666666666 in hex, everything fine. Then "val" is multiplied by 10 and the last digit is added. Result is 0x17fffffffffffffff, which overflows and thus is truncated to 0x7fffffffffffffff. This means val > prev, and the function returns TCL_OK, without detecting that an overflow happened.
I agree with you that usage of overflow trapping is bad .... in production code. But it's useful for finding bugs otherwise difficult to detect, as proven in this example: Whenever an overflow occurs during multiplication and this overflow is not detected, it might lead to a wrong answer without any indication that it happened. That's why a -ftrapv build is included in our build automation. It should never be used in production builds.
My recommendation would be to use the function strtoll(). It's not ideal, because you need to check the overflow situation using errno (or - mayby - just by using *endptr), but it's better than using this (buggy) _str2wideInt(). But ... I'll leave the solution to you.
A "knownBug" testcase is [here], now committed to the tip-688 branch. We don't need to stop the Voting: I'm sure this bug can be fixed (if you don't do it, I will)
Thanks!
Fixed now in [4fa26c98f225a44f]: the overflow check could indeed mistakenly pass in some cases (so basically needs div 10 to do it properly);
Additionally I optimized both str2int now, because we don't need to check it for most cases at all (up to 10 char and 18 chars accordingly), thus definitely faster now (bounds O(n)+O(1) vs. O(n)+O(n) in most cases, and has also fewer branch mispredictions now, essentially almost none anymore).
Thus closed.
P.S. I moved trap-pragma back, because although we may don't have tests right now, but someone can indeed compile it with trapping, and it can definitely overflow in format-scan, so would crash in that (surely obscure) cases. So if it is known, intentional code-piece, made on purpose, why not disable the trap?
> Fixed now in [4fa26c98f225a44f]
Sorry, but this fix has one remaining problem and one new problem.
The new problem is for --enable-symbols=mem builds, seen on all platforms:
==== var-22.1 leak in localVarName internalrep: Bug 80304238ac FAILED ==== Contents of test case:set end [getbytes] for {set i 0} {$i < 5} {incr i} { doit set tmp $end set end [getbytes] } set leakedBytes [expr {$end - $tmp}]---- Result was: 4488 ---- Result should have been (exact matching): 0
The remaining problem is with CFLAGS=-ftrapv builds. Still some overflow somewhere https://github.com/tcltk/tcl/actions/runs/8400230213/job/23008061558:
clock-ivm.test Validity default mode: on Test file error: child killed: SIGABRT clock.test Validity default mode: off Test file error: child killed: SIGABRT
Yes, there's progress, but we'r not there yet.
It turns out that the "new" test failures were not actually new: The "sebres-9-0-clock-speedup-cr2" branch had them as well, this branch was never executed with --enable-symbols=mem, therefore it was never noticed.
I suspect that the failure is related with the literals in CLOCK_LITERAL_ARRAY, which is not cleaned-up when the interpreter is deleted. That's what the failing testcases are testing for: leaked memory. If I'm right, this failure is a different problem than this ticket, if you prefer it can be handled in a separate ticket. Anyway, it's important to fix this before merging the tip-688 branch to trunk.
Regarding the mem tests, it's not a leak at all. It goes to internal global cache or storage-GC, which contains few (default 32) last used formats (as well as for scan and format), that allows, reuse them again across all threads and interpreters. I guess to pass such tests we'd need either to disable this cache for that kind of build (e. g. define CLOCK_FMT_SCN_STORAGE_GC_SIZE 0), or to provide some command (unsupported? configure?) forcing GC to clean everything.
As for the overflow, how it is possible, Jan? If you'd take a closer look at [4fa26c98f225a44f], every change, I made here, is in the area with disabled trapping. So it is something else (some of your previous commits)?
But OK, I'll see whether I can find it.
disabling this cache for --enable-symbols=mem builds is OK for me
Yes, it was yours [bef135d7a5f32c78] ...
Anyway number conversion in free-scan rewritten now in [5696b3f72c6d9d98] with common str2wide primitive.
There are no overflow anymore and trapping is disabled only in that str2int facilities.
Fix for mem-build follows.
> Fix for mem-build follows.
I don't know if more is going to follow, but [this commit] doesn't help :-(
Review: please don't use the "register" keyword. It's going to be removed from the C/C++ standard, since modern optimizers can figure it out by themselves.
> please don't use the "register" keyword
It was a cherry-pick and I simply missed to remove it (overlooked).
As for mem-debug build, I'll try to find out what is going on.
@Jan, the mem-leak was introduced by your move of configure to unsupported [06b7ba18bdd9c2c3] (reason: missing clean-up and therefore decreased refCount).
Fixed now in [c151959ad5409c53].
Indeed, mea culpa. Confirming, it's fixed now. Many thanks!