diff options
| author | Justin Bogner <mail@justinbogner.com> | 2015-06-24 05:59:19 +0000 |
|---|---|---|
| committer | Justin Bogner <mail@justinbogner.com> | 2015-06-24 05:59:19 +0000 |
| commit | c97c48aadcf3e2091b6380bfc6b873fbf3909021 (patch) | |
| tree | f3abcccbbd7e46eb33d969c951e9f43adb833038 | |
| parent | ddf71fc3708b9187fdfb38b086b1ee0d4e98825c (diff) | |
| download | bcm5719-llvm-c97c48aadcf3e2091b6380bfc6b873fbf3909021.tar.gz bcm5719-llvm-c97c48aadcf3e2091b6380bfc6b873fbf3909021.zip | |
SystemZ: Rephrase this allOnes calculation to avoid UB
This allOnes function hits undefined behaviour if Count is greater
than 64, but we can avoid that and simplify the calculation by just
saturating if such a value is passed in.
This comes up under ubsan becauseRxSBGOperands is sometimes created
with values that are 128 bits wide. Somebody more familiar with this
code should probably look into whether that's expected, as a 64 bit
mask may or may not be appropriate for such types.
llvm-svn: 240520
| -rw-r--r-- | llvm/lib/Target/SystemZ/SystemZISelDAGToDAG.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/llvm/lib/Target/SystemZ/SystemZISelDAGToDAG.cpp b/llvm/lib/Target/SystemZ/SystemZISelDAGToDAG.cpp index 0eb3d6593fe..26c9c9b9f67 100644 --- a/llvm/lib/Target/SystemZ/SystemZISelDAGToDAG.cpp +++ b/llvm/lib/Target/SystemZ/SystemZISelDAGToDAG.cpp @@ -96,7 +96,9 @@ struct SystemZAddressingMode { // Return a mask with Count low bits set. static uint64_t allOnes(unsigned int Count) { - return Count == 0 ? 0 : (uint64_t(1) << (Count - 1) << 1) - 1; + if (Count > 63) + return UINT64_MAX; + return (uint64_t(1) << Count) - 1; } // Represents operands 2 to 5 of the ROTATE AND ... SELECTED BITS operation |

