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