#include "CheckerRegistration.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclGroup.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/AST/Stmt.h"
#include "clang/AST/Type.h"
#include "clang/StaticAnalyzer/Core/Checker.h"
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
#include "clang/StaticAnalyzer/Frontend/AnalysisConsumer.h"
#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
#include "clang/Testing/TestClangConfig.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/raw_ostream.h"
#include "gtest/gtest.h"
namespace clang {
LLVM_ATTRIBUTE_UNUSED std::ostream &operator<<(std::ostream &OS,
const QualType &T) { … }
LLVM_ATTRIBUTE_UNUSED std::ostream &operator<<(std::ostream &OS,
const CanQualType &T) { … }
namespace ento {
namespace {
SVals;
class SValCollector : public Checker<check::Bind, check::EndAnalysis> { … };
static void expectSameSignAndBitWidth(QualType ExpectedTy, QualType ActualTy,
const ASTContext &Context) { … }
class SValTest : public testing::TestWithParam<TestClangConfig> { … };
#define SVAL_TEST(NAME, CODE) …
SVAL_TEST(GetConstType, R"(
void foo() {
int x = 42;
int *y = nullptr;
bool z = true;
})") { … }
SVAL_TEST(GetLocAsIntType, R"(
void foo(int *x) {
long int a = (long long int)x;
unsigned b = (long long unsigned)&a;
int c = (long long int)nullptr;
})") { … }
SVAL_TEST(GetSymExprType, R"(
void foo(int a, int b) {
int x = a;
int y = a + b;
long z = a;
})") { … }
SVAL_TEST(GetPointerType, R"(
int *bar();
int &foobar();
struct Z {
int a;
int *b;
};
void foo(int x, int *y, Z z) {
int &a = x;
int &b = *y;
int &c = *bar();
int &d = foobar();
int &e = z.a;
int &f = *z.b;
})") { … }
SVAL_TEST(GetCompoundType, R"(
struct TestStruct {
int a, b;
};
union TestUnion {
int a;
float b;
TestStruct c;
};
void foo(int x) {
int a[] = {1, x, 2};
TestStruct b = {x, 42};
TestUnion c = {42};
TestUnion d = {.c=b};
}
)") { … }
SVAL_TEST(GetStringType, R"(
void foo() {
const char *a = "Hello, world!";
}
)") { … }
SVAL_TEST(GetThisType, R"(
class TestClass {
void foo();
};
void TestClass::foo() {
const auto *a = this;
}
)") { … }
SVAL_TEST(GetFunctionPtrType, R"(
void bar();
void foo() {
auto *a = &bar;
}
)") { … }
SVAL_TEST(GetLabelType, R"(
void foo() {
entry:
void *a = &&entry;
char *b = (char *)&&entry;
}
)") { … }
std::vector<TestClangConfig> allTestClangConfigs() { … }
INSTANTIATE_TEST_SUITE_P(…);
}
}
}