]> granicus.if.org Git - clang/commitdiff
Add utility method to BasicValueFactory to convert an APSInt to one of a different...
authorTed Kremenek <kremenek@apple.com>
Wed, 11 Mar 2009 04:03:24 +0000 (04:03 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 11 Mar 2009 04:03:24 +0000 (04:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66637 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Analysis/PathSensitive/BasicValueFactory.h

index 64db2cd87bbb3c0e3873a645fc941a72ef33b269..18ae1d88e4ec06892f4f517a22fc8e83b0d4b457 100644 (file)
@@ -75,6 +75,18 @@ public:
   const llvm::APSInt& getValue(const llvm::APInt& X, bool isUnsigned);
   const llvm::APSInt& getValue(uint64_t X, unsigned BitWidth, bool isUnsigned);
   const llvm::APSInt& getValue(uint64_t X, QualType T);
+  
+  const llvm::APSInt& ConvertSignedness(const llvm::APSInt& To,
+                                        const llvm::APSInt& From) {
+    assert(To.getBitWidth() == From.getBitWidth());
+
+    // Same sign?  Just return.
+    if (To.isUnsigned() == From.isUnsigned())
+      return From;
+    
+    // Convert!
+    return getValue(llvm::APSInt((llvm::APInt&) From, To.isUnsigned()));
+  }
 
   const llvm::APSInt& getIntValue(uint64_t X, bool isUnsigned) {
     QualType T = isUnsigned ? Ctx.UnsignedIntTy : Ctx.IntTy;