1*443b46e6Seinvbri //===- unittest/StaticAnalyzer/APSIntTest.cpp - getAPSIntType test --===// 2*443b46e6Seinvbri // 3*443b46e6Seinvbri // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*443b46e6Seinvbri // See https://llvm.org/LICENSE.txt for license information. 5*443b46e6Seinvbri // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*443b46e6Seinvbri // 7*443b46e6Seinvbri //===----------------------------------------------------------------------===// 8*443b46e6Seinvbri 9*443b46e6Seinvbri #include "clang/Basic/TargetInfo.h" 10*443b46e6Seinvbri #include "clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h" 11*443b46e6Seinvbri #include "clang/Tooling/Tooling.h" 12*443b46e6Seinvbri #include "llvm/ADT/APSInt.h" 13*443b46e6Seinvbri #include "llvm/Support/raw_ostream.h" 14*443b46e6Seinvbri #include "gtest/gtest.h" 15*443b46e6Seinvbri 16*443b46e6Seinvbri namespace { 17*443b46e6Seinvbri TEST(getAPSIntTypeTest,APSIntTypeTests)18*443b46e6SeinvbriTEST(getAPSIntTypeTest, APSIntTypeTests) { 19*443b46e6Seinvbri std::unique_ptr<clang::ASTUnit> AST = clang::tooling::buildASTFromCode(""); 20*443b46e6Seinvbri clang::ASTContext &Context = AST->getASTContext(); 21*443b46e6Seinvbri llvm::BumpPtrAllocator Arena; 22*443b46e6Seinvbri clang::ento::BasicValueFactory BVF{Context, Arena}; 23*443b46e6Seinvbri 24*443b46e6Seinvbri clang::ento::APSIntType Ty = BVF.getAPSIntType(Context.LongAccumTy); 25*443b46e6Seinvbri EXPECT_TRUE(Ty.getBitWidth() == Context.getTargetInfo().getLongAccumWidth()); 26*443b46e6Seinvbri EXPECT_FALSE(Ty.isUnsigned()); 27*443b46e6Seinvbri 28*443b46e6Seinvbri Ty = BVF.getAPSIntType(Context.UnsignedLongAccumTy); 29*443b46e6Seinvbri EXPECT_TRUE(Ty.getBitWidth() == Context.getTargetInfo().getLongAccumWidth()); 30*443b46e6Seinvbri EXPECT_TRUE(Ty.isUnsigned()); 31*443b46e6Seinvbri 32*443b46e6Seinvbri Ty = BVF.getAPSIntType(Context.LongFractTy); 33*443b46e6Seinvbri EXPECT_TRUE(Ty.getBitWidth() == Context.getTargetInfo().getLongFractWidth()); 34*443b46e6Seinvbri EXPECT_FALSE(Ty.isUnsigned()); 35*443b46e6Seinvbri 36*443b46e6Seinvbri Ty = BVF.getAPSIntType(Context.UnsignedLongFractTy); 37*443b46e6Seinvbri EXPECT_TRUE(Ty.getBitWidth() == Context.getTargetInfo().getLongFractWidth()); 38*443b46e6Seinvbri EXPECT_TRUE(Ty.isUnsigned()); 39*443b46e6Seinvbri 40*443b46e6Seinvbri Ty = BVF.getAPSIntType(Context.SignedCharTy); 41*443b46e6Seinvbri EXPECT_TRUE(Ty.getBitWidth() == Context.getTargetInfo().getCharWidth()); 42*443b46e6Seinvbri EXPECT_FALSE(Ty.isUnsigned()); 43*443b46e6Seinvbri 44*443b46e6Seinvbri Ty = BVF.getAPSIntType(Context.UnsignedCharTy); 45*443b46e6Seinvbri EXPECT_TRUE(Ty.getBitWidth() == Context.getTargetInfo().getCharWidth()); 46*443b46e6Seinvbri EXPECT_TRUE(Ty.isUnsigned()); 47*443b46e6Seinvbri 48*443b46e6Seinvbri Ty = BVF.getAPSIntType(Context.LongTy); 49*443b46e6Seinvbri EXPECT_TRUE(Ty.getBitWidth() == Context.getTargetInfo().getLongWidth()); 50*443b46e6Seinvbri EXPECT_FALSE(Ty.isUnsigned()); 51*443b46e6Seinvbri 52*443b46e6Seinvbri Ty = BVF.getAPSIntType(Context.UnsignedLongTy); 53*443b46e6Seinvbri EXPECT_TRUE(Ty.getBitWidth() == Context.getTargetInfo().getLongWidth()); 54*443b46e6Seinvbri EXPECT_TRUE(Ty.isUnsigned()); 55*443b46e6Seinvbri } 56*443b46e6Seinvbri 57*443b46e6Seinvbri } // end namespace 58