From 672e408f14b528fe5e41c5dc99e95e671149a1e9 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 11 Mar 2009 04:03:24 +0000 Subject: [PATCH] Add utility method to BasicValueFactory to convert an APSInt to one of a different sign. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66637 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../clang/Analysis/PathSensitive/BasicValueFactory.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/clang/Analysis/PathSensitive/BasicValueFactory.h b/include/clang/Analysis/PathSensitive/BasicValueFactory.h index 64db2cd87b..18ae1d88e4 100644 --- a/include/clang/Analysis/PathSensitive/BasicValueFactory.h +++ b/include/clang/Analysis/PathSensitive/BasicValueFactory.h @@ -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; -- 2.40.0