aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests
diff options
context:
space:
mode:
authorElla Ma <alansnape3058@gmail.com>2022-07-14 15:54:40 +0800
committerElla Ma <alansnape3058@gmail.com>2022-07-14 22:00:38 +0800
commit32fe1a4be95c90da9a24d63a097429ec7c3bbfba (patch)
tree06155b21fa3540cc124cf2d99bbb3ca52206bd81 /clang/unittests
parent74902cc96faa04b8606f4eba59c51dac48cb924d (diff)
downloadllvm-32fe1a4be95c90da9a24d63a097429ec7c3bbfba.zip
llvm-32fe1a4be95c90da9a24d63a097429ec7c3bbfba.tar.gz
llvm-32fe1a4be95c90da9a24d63a097429ec7c3bbfba.tar.bz2
[analyzer] Fixing SVal::getType returns Null Type for NonLoc::ConcreteInt in boolean type
In method `TypeRetrievingVisitor::VisitConcreteInt`, `ASTContext::getIntTypeForBitwidth` is used to get the type for `ConcreteInt`s. However, the getter in ASTContext cannot handle the boolean type with the bit width of 1, which will make method `SVal::getType` return a Null `Type`. In this patch, a check for this case is added to fix this problem by returning the bool type directly when the bit width is 1. Differential Revision: https://reviews.llvm.org/D129737
Diffstat (limited to 'clang/unittests')
-rw-r--r--clang/unittests/StaticAnalyzer/SValTest.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/clang/unittests/StaticAnalyzer/SValTest.cpp b/clang/unittests/StaticAnalyzer/SValTest.cpp
index c41a501..55a0730 100644
--- a/clang/unittests/StaticAnalyzer/SValTest.cpp
+++ b/clang/unittests/StaticAnalyzer/SValTest.cpp
@@ -161,6 +161,7 @@ SVAL_TEST(GetConstType, R"(
void foo() {
int x = 42;
int *y = nullptr;
+ bool z = true;
})") {
SVal X = getByName("x");
ASSERT_FALSE(X.getType(Context).isNull());
@@ -170,6 +171,10 @@ void foo() {
ASSERT_FALSE(Y.getType(Context).isNull());
expectSameSignAndBitWidth(Context.getUIntPtrType(), Y.getType(Context),
Context);
+
+ SVal Z = getByName("z");
+ ASSERT_FALSE(Z.getType(Context).isNull());
+ EXPECT_EQ(Context.BoolTy, Z.getType(Context));
}
SVAL_TEST(GetLocAsIntType, R"(