PR 69400: Invalid 128-bit modulus result
authorrsandifo <rsandifo@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 26 Jan 2016 09:53:33 +0000 (09:53 +0000)
committerrsandifo <rsandifo@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 26 Jan 2016 09:53:33 +0000 (09:53 +0000)
commitef7be7f8272e24e72bab3f12f38d6d1deb0c7c22
treefd774b686410ec17d1edca42822f9013a8f9d3e8
parent648433a43bfb518b7c49c946634f8140f8ce4a63
PR 69400: Invalid 128-bit modulus result

As described in the PR, wi::divmod_internal was sign- rather than
zero-extending a modulus result in cases where the result has fewer
HWIs than the precision and the upper bit of the upper HWI was set.

This patch tries to make things more robust by getting wi_pack
to handle the canonicalisation step itself.

Tested on x86_64-linux-gnu.  I added tests to the wide-int
plugin since that seemed more direct.

gcc/
PR tree-optimization/69400
* wide-int.cc (wi_pack): Take the precision as argument and
perform canonicalization here rather than in the callers.
Use the main loop to handle all full-width HWIs.  Add a
zero HWI if in_len isn't a full result.
(wi::divmod_internal): Update accordingly.
(wi::mul_internal): Likewise.  Simplify.

gcc/testsuite/
PR tree-optimization/69400
* gcc.dg/plugin/wide-int_plugin.c (test_wide_int_mod_trunc): New
function.
(plugin_init): Call it.
* gcc.dg/torture/pr69400.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@232817 138bc75d-0d04-0410-961f-82ee72b054a4
gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/plugin/wide-int_plugin.c
gcc/testsuite/gcc.dg/torture/pr69400.c [new file with mode: 0644]
gcc/wide-int.cc