[clang] 26bc7cb - [clang, MveEmitter] Fix sign/zero extension in range limits.

Simon Tatham via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 6 01:02:06 PST 2019


Author: Simon Tatham
Date: 2019-11-06T09:01:42Z
New Revision: 26bc7cb05edd6bea4b9a1593baf0fbe9e45f54e4

URL: https://github.com/llvm/llvm-project/commit/26bc7cb05edd6bea4b9a1593baf0fbe9e45f54e4
DIFF: https://github.com/llvm/llvm-project/commit/26bc7cb05edd6bea4b9a1593baf0fbe9e45f54e4.diff

LOG: [clang,MveEmitter] Fix sign/zero extension in range limits.

In the code that generates Sema range checks on constant arguments, I
had a piece of code that checks the bounds specified in the Tablegen
intrinsic description against the range of the integer type being
tested. If the bounds are large enough to permit any value of the
integer type, you can omit the compile-time range check. (This case is
expected to come up in some of the bitwise operation intrinsics.)

But somehow I got my signed/unsigned check backwards (asking for the
signed min/max of an unsigned type and vice versa), and also made a
sign extension error in which a signed negative value gets
zero-extended. Now rewritten more sensibly, and it should get its
first sensible test from the next batch of intrinsics I'm planning to
add in D69791.

Reviewers: dmgreen

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69789

Added: 
    

Modified: 
    clang/utils/TableGen/MveEmitter.cpp

Removed: 
    


################################################################################
diff  --git a/clang/utils/TableGen/MveEmitter.cpp b/clang/utils/TableGen/MveEmitter.cpp
index 9c3328e3bbfb..1f9752261fbf 100644
--- a/clang/utils/TableGen/MveEmitter.cpp
+++ b/clang/utils/TableGen/MveEmitter.cpp
@@ -782,15 +782,14 @@ class ACLEIntrinsic {
       }
 
       llvm::APInt typelo, typehi;
-      if (cast<ScalarType>(IA.ArgType)->kind() == ScalarTypeKind::UnsignedInt) {
-        typelo = llvm::APInt::getSignedMinValue(IA.ArgType->sizeInBits());
-        typehi = llvm::APInt::getSignedMaxValue(IA.ArgType->sizeInBits());
+      unsigned Bits = IA.ArgType->sizeInBits();
+      if (cast<ScalarType>(IA.ArgType)->kind() == ScalarTypeKind::SignedInt) {
+        typelo = llvm::APInt::getSignedMinValue(Bits).sext(128);
+        typehi = llvm::APInt::getSignedMaxValue(Bits).sext(128);
       } else {
-        typelo = llvm::APInt::getMinValue(IA.ArgType->sizeInBits());
-        typehi = llvm::APInt::getMaxValue(IA.ArgType->sizeInBits());
+        typelo = llvm::APInt::getMinValue(Bits).zext(128);
+        typehi = llvm::APInt::getMaxValue(Bits).zext(128);
       }
-      typelo = typelo.sext(128);
-      typehi = typehi.sext(128);
 
       std::string Index = utostr(kv.first);
 


        


More information about the cfe-commits mailing list