[PATCH] D146932: [compiler-rt] Fix signed shift overflows in absvdi2.c, absvsi2.c, negvdi2.c and negvsi2.c
Karl-Johan Karlsson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 13 22:21:14 PDT 2023
Ka-Ka updated this revision to Diff 513436.
Ka-Ka added a comment.
git-clang-format
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D146932/new/
https://reviews.llvm.org/D146932
Files:
compiler-rt/lib/builtins/absvdi2.c
compiler-rt/lib/builtins/absvsi2.c
compiler-rt/lib/builtins/negvdi2.c
compiler-rt/lib/builtins/negvsi2.c
Index: compiler-rt/lib/builtins/negvsi2.c
===================================================================
--- compiler-rt/lib/builtins/negvsi2.c
+++ compiler-rt/lib/builtins/negvsi2.c
@@ -17,7 +17,8 @@
// Effects: aborts if -a overflows
COMPILER_RT_ABI si_int __negvsi2(si_int a) {
- const si_int MIN = (si_int)1 << ((int)(sizeof(si_int) * CHAR_BIT) - 1);
+ const si_int MIN =
+ (si_int)((su_int)1 << ((int)(sizeof(si_int) * CHAR_BIT) - 1));
if (a == MIN)
compilerrt_abort();
return -a;
Index: compiler-rt/lib/builtins/negvdi2.c
===================================================================
--- compiler-rt/lib/builtins/negvdi2.c
+++ compiler-rt/lib/builtins/negvdi2.c
@@ -17,7 +17,8 @@
// Effects: aborts if -a overflows
COMPILER_RT_ABI di_int __negvdi2(di_int a) {
- const di_int MIN = (di_int)1 << ((int)(sizeof(di_int) * CHAR_BIT) - 1);
+ const di_int MIN =
+ (di_int)((du_int)1 << ((int)(sizeof(di_int) * CHAR_BIT) - 1));
if (a == MIN)
compilerrt_abort();
return -a;
Index: compiler-rt/lib/builtins/absvsi2.c
===================================================================
--- compiler-rt/lib/builtins/absvsi2.c
+++ compiler-rt/lib/builtins/absvsi2.c
@@ -18,7 +18,7 @@
COMPILER_RT_ABI si_int __absvsi2(si_int a) {
const int N = (int)(sizeof(si_int) * CHAR_BIT);
- if (a == ((si_int)1 << (N - 1)))
+ if (a == ((si_int)((su_int)1 << (N - 1))))
compilerrt_abort();
const si_int t = a >> (N - 1);
return (a ^ t) - t;
Index: compiler-rt/lib/builtins/absvdi2.c
===================================================================
--- compiler-rt/lib/builtins/absvdi2.c
+++ compiler-rt/lib/builtins/absvdi2.c
@@ -18,7 +18,7 @@
COMPILER_RT_ABI di_int __absvdi2(di_int a) {
const int N = (int)(sizeof(di_int) * CHAR_BIT);
- if (a == ((di_int)1 << (N - 1)))
+ if (a == ((di_int)((du_int)1 << (N - 1))))
compilerrt_abort();
const di_int t = a >> (N - 1);
return (a ^ t) - t;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146932.513436.patch
Type: text/x-patch
Size: 1964 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230414/b21b50ad/attachment.bin>
More information about the llvm-commits
mailing list