|
21 | 21 | #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
|
22 | 22 | #include "clang/StaticAnalyzer/Frontend/AnalysisConsumer.h"
|
23 | 23 | #include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
|
| 24 | +#include "clang/Testing/TestClangConfig.h" |
24 | 25 | #include "clang/Tooling/Tooling.h"
|
25 | 26 | #include "llvm/ADT/STLExtras.h"
|
26 | 27 | #include "llvm/ADT/StringRef.h"
|
@@ -91,6 +92,21 @@ class SValCollector : public Checker<check::Bind, check::EndAnalysis> {
|
91 | 92 | mutable SVals CollectedSVals;
|
92 | 93 | };
|
93 | 94 |
|
| 95 | +// Fixture class for parameterized SValTest |
| 96 | +class SValTest : public testing::TestWithParam<TestClangConfig> { |
| 97 | +protected: |
| 98 | + // FIXME: The tests "GetConstType" and "GetLocAsIntType" infer the type of |
| 99 | + // integrals based on their bitwidth. This is not a reliable method on |
| 100 | + // platforms where different integrals have the same width. |
| 101 | + bool skipTest(StringRef TestName) { |
| 102 | + std::string target = GetParam().Target; |
| 103 | + return (target == "powerpc-ibm-aix" || target == "i686-apple-darwin9" || |
| 104 | + target == "wasm32-unknown-unknown" || |
| 105 | + target == "wasm64-unknown-unknown") && |
| 106 | + (TestName == "GetConstType" || TestName == "GetLocAsIntType"); |
| 107 | + } |
| 108 | +}; |
| 109 | + |
94 | 110 | // SVAL_TEST is a combined way of providing a short code snippet and
|
95 | 111 | // to test some programmatic predicates on symbolic values produced by the
|
96 | 112 | // engine for the actual code.
|
@@ -135,7 +151,16 @@ class SValCollector : public Checker<check::Bind, check::EndAnalysis> {
|
135 | 151 | }); \
|
136 | 152 | } \
|
137 | 153 | \
|
138 |
| - TEST(SValTest, NAME) { runCheckerOnCode<add##NAME##SValCollector>(CODE); } \ |
| 154 | + TEST_P(SValTest, NAME) { \ |
| 155 | + if (skipTest(#NAME)) { \ |
| 156 | + std::string target = GetParam().Target; \ |
| 157 | + GTEST_SKIP() << "certain integrals have the same bitwidth on " \ |
| 158 | + << target; \ |
| 159 | + return; \ |
| 160 | + } \ |
| 161 | + runCheckerOnCodeWithArgs<add##NAME##SValCollector>( \ |
| 162 | + CODE, GetParam().getCommandLineArgs()); \ |
| 163 | + } \ |
139 | 164 | void NAME##SValCollector::test(ExprEngine &Engine, \
|
140 | 165 | const ASTContext &Context) const
|
141 | 166 |
|
@@ -361,6 +386,31 @@ void foo() {
|
361 | 386 | EXPECT_EQ(Context.VoidPtrTy, B.getType(Context));
|
362 | 387 | }
|
363 | 388 |
|
| 389 | +std::vector<TestClangConfig> allTestClangConfigs() { |
| 390 | + std::vector<TestClangConfig> all_configs; |
| 391 | + TestClangConfig config; |
| 392 | + config.Language = Lang_CXX14; |
| 393 | + for (std::string target : |
| 394 | + {"i686-pc-windows-msvc", "i686-apple-darwin9", |
| 395 | + "x86_64-apple-darwin9", "x86_64-scei-ps4", |
| 396 | + "x86_64-windows-msvc", "x86_64-unknown-linux", |
| 397 | + "x86_64-apple-macosx", "x86_64-apple-ios14.0", |
| 398 | + "wasm32-unknown-unknown", "wasm64-unknown-unknown", |
| 399 | + "thumb-pc-win32", "sparc64-none-openbsd", |
| 400 | + "sparc-none-none", "riscv64-unknown-linux", |
| 401 | + "ppc64-windows-msvc", "powerpc-ibm-aix", |
| 402 | + "powerpc64-ibm-aix", "s390x-ibm-zos", |
| 403 | + "armv7-pc-windows-msvc", "aarch64-pc-windows-msvc", |
| 404 | + "xcore-xmos-elf"}) { |
| 405 | + config.Target = target; |
| 406 | + all_configs.push_back(config); |
| 407 | + } |
| 408 | + return all_configs; |
| 409 | +} |
| 410 | + |
| 411 | +INSTANTIATE_TEST_SUITE_P(SValTests, SValTest, |
| 412 | + testing::ValuesIn(allTestClangConfigs())); |
| 413 | + |
364 | 414 | } // namespace
|
365 | 415 | } // namespace ento
|
366 | 416 | } // namespace clang
|
0 commit comments