Sample code:
ushort ee = 1028;
ee <<= 5U;
ee >>= 5U;
writeln(ee);
Regular compiler: https://godbolt.org/z/TcbjP76fW (prints 1028)
Circle CI: 64516 .
Someone, the compiler manages to do a signed arithmetic shift on an unsigned.
Thread overview | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
January 11, 2023 phobos's circle CI runs a busted version of DMD | ||||
---|---|---|---|---|
| ||||
Sample code:
Regular compiler: https://godbolt.org/z/TcbjP76fW (prints 1028) Someone, the compiler manages to do a signed arithmetic shift on an unsigned. |
January 11, 2023 Re: phobos's circle CI runs a busted version of DMD | ||||
---|---|---|---|---|
| ||||
Posted in reply to deadalnix | On Wednesday, 11 January 2023 at 01:03:33 UTC, deadalnix wrote: >Sample code:
Regular compiler: https://godbolt.org/z/TcbjP76fW (prints 1028) Someone, the compiler manages to do a signed arithmetic shift on an unsigned. https://godbolt.org/z/M3fGE9bqY "All versions: Success with output: 64516" from run.dlang.io |
January 11, 2023 Re: phobos's circle CI runs a busted version of DMD | ||||
---|---|---|---|---|
| ||||
Posted in reply to Max Haughton | On Wednesday, 11 January 2023 at 02:50:52 UTC, Max Haughton wrote: >On Wednesday, 11 January 2023 at 01:03:33 UTC, deadalnix wrote: >Regular compiler: https://godbolt.org/z/TcbjP76fW (prints 1028) Someone, the compiler manages to do a signed arithmetic shift on an unsigned. https://godbolt.org/z/M3fGE9bqY "All versions: Success with output: 64516" from run.dlang.io Ok, so Godbolt also runs a busted version of DMD? And why counts 64516 as a success here?!?! |
January 11, 2023 Re: phobos's circle CI runs a busted version of DMD | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dom DiSc | On Wednesday, 11 January 2023 at 11:04:50 UTC, Dom DiSc wrote: > >https://godbolt.org/z/M3fGE9bqY "All versions: Success with output: 64516" from run.dlang.io Ok, so Godbolt also runs a busted version of DMD? And why counts 64516 as a success here?!?! Congratulation for understanding exactly backward. 64516 is not a success, it is a failure. |
January 11, 2023 Re: phobos's circle CI runs a busted version of DMD | ||||
---|---|---|---|---|
| ||||
Posted in reply to deadalnix | On Wednesday, 11 January 2023 at 01:03:33 UTC, deadalnix wrote: >Sample code:
Regular compiler: https://godbolt.org/z/TcbjP76fW (prints 1028) Someone, the compiler manages to do a signed arithmetic shift on an unsigned. The spec says that It's another issue whether that's good design though. For one, it breaks the rule "do what C does, or don't compile". It'd be more reasonable if |
January 11, 2023 Re: phobos's circle CI runs a busted version of DMD | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dukc | On Wednesday, 11 January 2023 at 13:26:57 UTC, Dukc wrote: >On Wednesday, 11 January 2023 at 01:03:33 UTC, deadalnix wrote: >Sample code:
Regular compiler: https://godbolt.org/z/TcbjP76fW (prints 1028) Someone, the compiler manages to do a signed arithmetic shift on an unsigned. The spec says that It's another issue whether that's good design though. For one, it breaks the rule "do what C does, or don't compile". It'd be more reasonable if Not really. If you just do
The problem is the combination with assignment, which is what makes it seem like a bug. According to [1], "the right operand is implicitly converted to the type of the left operand, and assigned to it." So what should happen is that [1] https://dlang.org/spec/expression.html#simple_assignment_expressions |
January 11, 2023 Re: phobos's circle CI runs a busted version of DMD | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dom DiSc | On Wednesday, 11 January 2023 at 11:04:50 UTC, Dom DiSc wrote: >On Wednesday, 11 January 2023 at 02:50:52 UTC, Max Haughton wrote: >On Wednesday, 11 January 2023 at 01:03:33 UTC, deadalnix wrote: >Regular compiler: https://godbolt.org/z/TcbjP76fW (prints 1028) Someone, the compiler manages to do a signed arithmetic shift on an unsigned. https://godbolt.org/z/M3fGE9bqY "All versions: Success with output: 64516" from run.dlang.io Ok, so Godbolt also runs a busted version of DMD? And why counts 64516 as a success here?!?! Success here merely means that it compiled. The "run with all dmd versions" mode is aimed for finding regressions and so on. |
January 11, 2023 Re: phobos's circle CI runs a busted version of DMD | ||||
---|---|---|---|---|
| ||||
Posted in reply to jmh530 | On Wednesday, 11 January 2023 at 13:51:43 UTC, jmh530 wrote: >On Wednesday, 11 January 2023 at 13:26:57 UTC, Dukc wrote: >On Wednesday, 11 January 2023 at 01:03:33 UTC, deadalnix wrote: >Sample code:
Regular compiler: https://godbolt.org/z/TcbjP76fW (prints 1028) Someone, the compiler manages to do a signed arithmetic shift on an unsigned. The spec says that It's another issue whether that's good design though. For one, it breaks the rule "do what C does, or don't compile". It'd be more reasonable if Not really. If you just do
The problem is the combination with assignment, which is what makes it seem like a bug. According to [1], "the right operand is implicitly converted to the type of the left operand, and assigned to it." So what should happen is that [1] https://dlang.org/spec/expression.html#simple_assignment_expressions Upon further investigation, the problem goes away when you cast
Not quite sure why the problem is there for the uint and not the ushort, but it could be related to the sequence of integer promotion and the casting. What happens seems inconsistent with the spec. One weird thing is that if you change the cast from ushort to ulong, then we don't have the problem. It is only uint where we get the weird result. |
January 11, 2023 Re: phobos's circle CI runs a busted version of DMD | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dukc | On Wednesday, 11 January 2023 at 13:26:57 UTC, Dukc wrote: >The spec says that It's another issue whether that's good design though. For one, it breaks the rule "do what C does, or don't compile". It'd be more reasonable if Signed right shift is the same as logical right shift for unsigned integrals. |
January 11, 2023 Re: phobos's circle CI runs a busted version of DMD | ||||
---|---|---|---|---|
| ||||
Posted in reply to deadalnix | On 1/10/23 17:03, deadalnix wrote: I am following the code with "Integer Promotions" open: https://dlang.org/spec/type.html#integer-promotions > ushort ee = 1028; > ee <<= 5U; > ee >>= 5U; ee is promoted to 'int' for both operations. 5U is uint. According to documentation above, 'int' should be converted to 'uint'. > Regular compiler: https://godbolt.org/z/TcbjP76fW (prints 1028) > Circle CI: 64516 . > > Someone, the compiler manages to do a signed arithmetic shift on an > unsigned. I agree, this is a bug. Ali |