Summary: | media-gfx/imagemagick-9999 (and current stable) miscompiled with sys-devel/gcc-13.3.1_p20240614 -O3 | ||
---|---|---|---|
Product: | Gentoo Linux | Reporter: | Hadrien Lacour <hadrien.lacour> |
Component: | Current packages | Assignee: | Codec Project <codec> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | dilfridge, hadrien.lacour, sam, toolchain |
Priority: | Normal | ||
Version: | unspecified | ||
Hardware: | All | ||
OS: | Linux | ||
See Also: |
https://github.com/ImageMagick/ImageMagick/issues/7677 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110315 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109695 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117100 |
||
Whiteboard: | |||
Package list: | Runtime testing required: | --- | |
Bug Depends on: | 942691, 942692 | ||
Bug Blocks: | 915000 | ||
Attachments: |
emerge --info media-gfx/imagemagick >emerge_info.txt
libMagickCore_7_Q16HDRI_la-composite.i.xz |
Description
Hadrien Lacour
2024-10-09 16:47:46 UTC
I can take a look but please give full, verbose instructions to reproduce (given I've barely ever used IM)? I'll then probe it tomorrow. Thank you! The IM bug was updated to be more explicit. But to make it simple: 1. Take the current media-gfx/imagemagick (7.1.1.38-r1) 2. Build it with -O3 in your FLAGS using sys-devel/gcc-13.3.1_p20240614 3. Take any image with transparency, let us say "alpha.png" 4. Run `magick alpha.png -distort Resize 200% out.png` 5. Observe that the resulting out.png is completely black 6. Repeat all of that using -O2 instead to observe the right behaviour (resized image) As said in the (now closed) bug, I don't know if this is a gcc or IM bug. And using clang instead doesn't reproduce, but that doesn't mean much. Since I tested using upstream, this is not a bug in our packaging or IM. Typo; this is not a bug in our packaging of IM. Thanks. Yeah, it's fine that it's not a packaging bug, I'm happy to spend some time looking at it nonetheless. Well, you're brave. Good luck, you'll need it! The funny thing is that we had bug 940923 only the other day too - which was good fun. 14+15 (trunk) are fine, bisecting first. r13-7841-g70639014a69cf5 breaks it, reverting that on releases/gcc-13 fixes it, but that doesn't mean it's actually to blame. Looking more. basepoints/gcc-14 works releases/gcc-13.1.0 works r13-7841-g70639014a69cf5 got backported for 13.3 to fix https://gcc.gnu.org/PR110315. The patch originally came from https://gcc.gnu.org/PR109695 but it got cherry-picked with a different title at least (not compared contents yet or figured out which commit on 14 it corresponds to). This means we can't bisect for the fix on 13-vs-14 as 14 was never broken. Correction: the failing result isn't completely black, transparency is replaced by black. I manually reduced the '-O3' failure to '-O1 -funswitch-loops', if this can help. That is indeed helpful, thanks, as it means I can rule out a lot. Created attachment 905157 [details]
libMagickCore_7_Q16HDRI_la-composite.i.xz
libMagickCore_7_Q16HDRI_la-composite.o is the bad object. Attached preprocessed source.
--- a/libMagickCore_7_Q16HDRI_la-composite.i.141t.lim2 +++ b/libMagickCore_7_Q16HDRI_la-composite.i.141t.lim2 @@ -3402,6 +3402,7 @@ void BlendRMSEResidual._omp_fn.0 (struct .omp_data_s.89 & restrict .omp_data_i) goto <bb 38>; [50.00%] <bb 38> [local count: 15364004]: + columns.88_174 = (long int) columns_26; <bb 4> [local count: 139672780]: # y_3 = PHI <_42(38), y_119(41)> @@ -3433,7 +3434,6 @@ void BlendRMSEResidual._omp_fn.0 (struct .omp_data_s.89 & restrict .omp_data_i) goto <bb 7>; [42.89%] <bb 7> [local count: 29952828]: - columns.88_174 = (long int) columns_26; if (columns.88_174 > 0) goto <bb 39>; [89.00%] else [...] @@ -12857,6 +12857,7 @@ MagickBooleanType CompositeImage (struct Image * image, const struct Image * com goto <bb 91>; [3.66%] <bb 305> [local count: 11561895]: + _70 = ABS_EXPR <angle_range_249>; <bb 72> [local count: 228832040]: # y_1117 = PHI <y_546(311), 0(305)> @@ -12930,7 +12931,6 @@ MagickBooleanType CompositeImage (struct Image * image, const struct Image * com goto <bb 88>; [100.00%] <bb 79> [local count: 179090238]: - _70 = ABS_EXPR <angle_range_249>; if (_70 > 9.99999999999999979886647629255615367252843506129522666015e-13) goto <bb 80>; [50.00%] else -- --- a/libMagickCore_7_Q16HDRI_la-composite.i.144t.sink1 +++ b/libMagickCore_7_Q16HDRI_la-composite.i.144t.sink1 @@ -3901,6 +3901,7 @@ void BlendRMSEResidual._omp_fn.0 (struct .omp_data_s.89 & restrict .omp_data_i) residual_30 = *.omp_data_i_24(D).residual; beta_image_31 = *.omp_data_i_24(D).beta_image; alpha_image_32 = *.omp_data_i_24(D).alpha_image; + columns.88_174 = (long int) columns_26; <bb 4> [local count: 139672780]: # y_3 = PHI <_42(38), y_119(41)> @@ -3937,7 +3938,6 @@ void BlendRMSEResidual._omp_fn.0 (struct .omp_data_s.89 & restrict .omp_data_i) goto <bb 7>; [42.89%] <bb 7> [local count: 29952828]: - columns.88_174 = (long int) columns_26; if (columns.88_174 > 0) goto <bb 39>; [89.00%] else @@ -4483,8 +4483,8 @@ MagickBooleanType CompositeOverImage (struct Image * image, const struct Image * [...] @@ -13963,6 +13963,7 @@ MagickBooleanType CompositeImage (struct Image * image, const struct Image * com goto <bb 348>; [3.66%] <bb 305> [local count: 11561895]: + _70 = ABS_EXPR <angle_range_249>; <bb 72> [local count: 228832040]: # y_1117 = PHI <y_546(311), 0(305)> @@ -14050,7 +14051,6 @@ MagickBooleanType CompositeImage (struct Image * image, const struct Image * com goto <bb 88>; [100.00%] <bb 79> [local count: 179090238]: - _70 = ABS_EXPR <angle_range_249>; if (_70 > 9.99999999999999979886647629255615367252843506129522666015e-13) goto <bb 80>; [50.00%] else --- --- a/libMagickCore_7_Q16HDRI_la-composite.i.148t.dse3 +++ b/libMagickCore_7_Q16HDRI_la-composite.i.148t.dse3 @@ -3232,6 +3232,7 @@ void BlendRMSEResidual._omp_fn.0 (struct .omp_data_s.89 & restrict .omp_data_i) residual_30 = *.omp_data_i_24(D).residual; beta_image_31 = *.omp_data_i_24(D).beta_image; alpha_image_32 = *.omp_data_i_24(D).alpha_image; + columns.88_174 = (long int) columns_26; <bb 4> [local count: 139672780]: # y_3 = PHI <_42(38), y_119(41)> @@ -3268,7 +3269,6 @@ void BlendRMSEResidual._omp_fn.0 (struct .omp_data_s.89 & restrict .omp_data_i) goto <bb 7>; [42.89%] <bb 7> [local count: 29952828]: - columns.88_174 = (long int) columns_26; if (columns.88_174 > 0) goto <bb 39>; [89.00%] else [...] @@ -11754,6 +11754,7 @@ MagickBooleanType CompositeImage (struct Image * image, const struct Image * com goto <bb 348>; [3.66%] <bb 305> [local count: 11561895]: + _70 = ABS_EXPR <angle_range_249>; <bb 72> [local count: 228832040]: # y_1117 = PHI <y_546(311), 0(305)> @@ -11841,7 +11842,6 @@ MagickBooleanType CompositeImage (struct Image * image, const struct Image * com goto <bb 88>; [100.00%] <bb 79> [local count: 179090238]: - _70 = ABS_EXPR <angle_range_249>; if (_70 > 9.99999999999999979886647629255615367252843506129522666015e-13) goto <bb 80>; [50.00%] else ---- --- a/libMagickCore_7_Q16HDRI_la-composite.i.149t.dce4 +++ b/libMagickCore_7_Q16HDRI_la-composite.i.149t.dce4 @@ -3232,6 +3232,7 @@ void BlendRMSEResidual._omp_fn.0 (struct .omp_data_s.89 & restrict .omp_data_i) residual_30 = *.omp_data_i_24(D).residual; beta_image_31 = *.omp_data_i_24(D).beta_image; alpha_image_32 = *.omp_data_i_24(D).alpha_image; + columns.88_174 = (long int) columns_26; <bb 4> [local count: 139672780]: # y_3 = PHI <_42(38), y_119(41)> @@ -3268,7 +3269,6 @@ void BlendRMSEResidual._omp_fn.0 (struct .omp_data_s.89 & restrict .omp_data_i) goto <bb 7>; [42.89%] <bb 7> [local count: 29952828]: - columns.88_174 = (long int) columns_26; if (columns.88_174 > 0) goto <bb 39>; [89.00%] else @@ -3757,8 +3757,8 @@ MagickBooleanType CompositeOverImage (struct Image * image, const struct Image * [...] @@ -11754,6 +11754,7 @@ MagickBooleanType CompositeImage (struct Image * image, const struct Image * com goto <bb 348>; [3.66%] <bb 305> [local count: 11561895]: + _70 = ABS_EXPR <angle_range_249>; <bb 72> [local count: 228832040]: # y_1117 = PHI <y_546(311), 0(305)> @@ -11841,7 +11842,6 @@ MagickBooleanType CompositeImage (struct Image * image, const struct Image * com goto <bb 88>; [100.00%] <bb 79> [local count: 179090238]: - _70 = ABS_EXPR <angle_range_249>; if (_70 > 9.99999999999999979886647629255615367252843506129522666015e-13) goto <bb 80>; [50.00%] else ---- --- a/libMagickCore_7_Q16HDRI_la-composite.i.150t.fix_loops +++ b/libMagickCore_7_Q16HDRI_la-composite.i.150t.fix_loops @@ -3232,6 +3232,7 @@ void BlendRMSEResidual._omp_fn.0 (struct .omp_data_s.89 & restrict .omp_data_i) residual_30 = *.omp_data_i_24(D).residual; beta_image_31 = *.omp_data_i_24(D).beta_image; alpha_image_32 = *.omp_data_i_24(D).alpha_image; + columns.88_174 = (long int) columns_26; <bb 4> [local count: 139672780]: # y_3 = PHI <_42(38), y_119(41)> @@ -3268,7 +3269,6 @@ void BlendRMSEResidual._omp_fn.0 (struct .omp_data_s.89 & restrict .omp_data_i) goto <bb 7>; [42.89%] <bb 7> [local count: 29952828]: - columns.88_174 = (long int) columns_26; if (columns.88_174 > 0) goto <bb 39>; [89.00%] else [...] @@ -11754,6 +11754,7 @@ MagickBooleanType CompositeImage (struct Image * image, const struct Image * com goto <bb 348>; [3.66%] <bb 305> [local count: 11561895]: + _70 = ABS_EXPR <angle_range_249>; <bb 72> [local count: 228832040]: # y_1117 = PHI <y_546(311), 0(305)> @@ -11841,7 +11842,6 @@ MagickBooleanType CompositeImage (struct Image * image, const struct Image * com goto <bb 88>; [100.00%] <bb 79> [local count: 179090238]: - _70 = ABS_EXPR <angle_range_249>; if (_70 > 9.99999999999999979886647629255615367252843506129522666015e-13) goto <bb 80>; [50.00%] else diff --git a/libMagickCore_7_Q16HDRI_la-composite.i.151t.loop b/libMagickCore_7_Q16HDRI_la-composite.i.151t.loop index 9b848e2..2177f85 100644 --- a/libMagickCore_7_Q16HDRI_la-composite.i.151t.loop +++ b/libMagickCore_7_Q16HDRI_la-composite.i.151t.loop @@ -3188,6 +3188,7 @@ void BlendRMSEResidual._omp_fn.0 (struct .omp_data_s.89 & restrict .omp_data_i) residual_30 = *.omp_data_i_24(D).residual; beta_image_31 = *.omp_data_i_24(D).beta_image; alpha_image_32 = *.omp_data_i_24(D).alpha_image; + columns.88_174 = (long int) columns_26; <bb 4> [local count: 139672780]: # y_3 = PHI <_42(38), y_119(41)> @@ -3224,7 +3225,6 @@ void BlendRMSEResidual._omp_fn.0 (struct .omp_data_s.89 & restrict .omp_data_i) goto <bb 7>; [42.89%] <bb 7> [local count: 29952828]: - columns.88_174 = (long int) columns_26; if (columns.88_174 > 0) goto <bb 39>; [89.00%] else [...] @@ -14021,6 +14021,7 @@ MagickBooleanType CompositeImage (struct Image * image, const struct Image * com goto <bb 348>; [3.66%] <bb 305> [local count: 11561895]: + _70 = ABS_EXPR <angle_range_249>; <bb 72> [local count: 228832040]: # y_1117 = PHI <y_546(311), 0(305)> @@ -14108,7 +14109,6 @@ MagickBooleanType CompositeImage (struct Image * image, const struct Image * com goto <bb 88>; [100.00%] <bb 79> [local count: 179090238]: - _70 = ABS_EXPR <angle_range_249>; if (_70 > 9.99999999999999979886647629255615367252843506129522666015e-13) goto <bb 80>; [50.00%] else Then sccp comes and does a lot. What I don't get is, I don't see an unswitch-loops pass, but I see refs to -fdump-tree-unswitch-all? OK, no, it makes sense (https://gcc.gnu.org/onlinedocs/gccint/Tree-SSA-passes.html): > Loop invariant motion. This pass moves only invariants that would be hard to handle on RTL level (function calls, operations that expand to nontrivial sequences of insns). With -funswitch-loops it also moves operands of conditions that are invariant out of the loop, so that we can use just trivial invariantness analysis in loop unswitching. The pass also includes store motion. The pass is implemented in tree-ssa-loop-im.cc. so the goodies are in lim, and that's where we see our first difference Great detective work! I had myself narrowed it to the final composite operation via manual debugging, but didn't know how to proceed further with IM's spaghetti AbstractBeanFactory code. I'll try extract it into something standalone next but kind of dreading it.. Might help to know that I remember having reproduced --without-openmp, as it may make debugging much harder. Thanks, I've swapped to that now (and it does help). Thank you for reporting - reduced & sent upstream at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117100. The bug has been closed via the following commit(s): https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=56b835de43c60269973d4c7ea331338cd4eb9011 commit 56b835de43c60269973d4c7ea331338cd4eb9011 Author: Sam James <sam@gentoo.org> AuthorDate: 2024-10-12 05:29:09 +0000 Commit: Sam James <sam@gentoo.org> CommitDate: 2024-10-12 05:31:22 +0000 media-gfx/imagemagick: workaround GCC 13 bug -O3 implies -funswitch-loops which triggers an unfortunate rare edgecase with one of the switch statements in ImageMagick. Apply a workaround for GCC 13 for now (14+ is fixed already and it's latent otherwise). The fix will land on the 13 branch shortly upstream but let's get the fix out quickly on our end so we don't have to rush to stable it and so on (although we will of course do it soon). Bug: https://github.com/ImageMagick/ImageMagick/issues/7677 Bug: https://gcc.gnu.org/PR117100 Closes: https://bugs.gentoo.org/941208 Signed-off-by: Sam James <sam@gentoo.org> .../imagemagick/imagemagick-6.9.13.16-r1.ebuild | 245 ++++++++++++++++++++ ....1.25.ebuild => imagemagick-7.1.1.25-r1.ebuild} | 3 + .../imagemagick/imagemagick-7.1.1.38-r2.ebuild | 257 +++++++++++++++++++++ media-gfx/imagemagick/imagemagick-9999.ebuild | 3 + 4 files changed, 508 insertions(+) Workaround applied, I'll get it fixed on 13 branch shortly as well upstream, then can drop the workaround in due course. Thanks again for the report. Thanks a lot for your dedication! I'm amazed you're doing this without being paid, to be honest. The bug has been referenced in the following commit(s): https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=8496bc7616eaa8dda229ec15e2629051e10814a9 commit 8496bc7616eaa8dda229ec15e2629051e10814a9 Author: Sam James <sam@gentoo.org> AuthorDate: 2024-10-19 05:58:33 +0000 Commit: Sam James <sam@gentoo.org> CommitDate: 2024-10-19 05:58:55 +0000 sys-devel/gcc: add 13.3.1_p20241018 Bug: https://bugs.gentoo.org/880677 Bug: https://bugs.gentoo.org/941208 Signed-off-by: Sam James <sam@gentoo.org> sys-devel/gcc/Manifest | 1 + sys-devel/gcc/gcc-13.3.1_p20241018.ebuild | 66 +++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) commit 1debd3c0d720f769042152e951c2d51b778a459f Author: Sam James <sam@gentoo.org> Date: Tue Oct 29 04:58:47 2024 +0000 sys-devel/gcc: keyword 13.3.1_p20241025 Signed-off-by: Sam James <sam@gentoo.org> The bug has been referenced in the following commit(s): https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=0c5aab3a19d7273851a164c9140700cc3a54c5bf commit 0c5aab3a19d7273851a164c9140700cc3a54c5bf Author: Sam James <sam@gentoo.org> AuthorDate: 2024-10-31 22:42:37 +0000 Commit: Sam James <sam@gentoo.org> CommitDate: 2024-10-31 22:43:45 +0000 sys-devel/gcc: add 12.4.1_p20241031 Bug: https://bugs.gentoo.org/941208 Signed-off-by: Sam James <sam@gentoo.org> sys-devel/gcc/Manifest | 1 + sys-devel/gcc/gcc-12.4.1_p20241031.ebuild | 65 +++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) |