Skip to content

Commit 9c4d194

Browse files
committed
[analyzer]Skip unstable CSA tests failing on several platforms
Clang static analyzer uses bitwidth to infer the integer value type, that is, any 32-bit integer is considered of type `int`, and any 64-bit integer is considered of type `long`. This isn't always true, for instance, in ILP32 (e.g., 32-bit AIX), 32-bit could be `long`, and in LP64 (e.g., 64-bit wasm64), 64-bit could be `long long`. Reviewed By: steakhal Differential Revision: https://reviews.llvm.org/D114454
1 parent 885fb9a commit 9c4d194

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

clang/unittests/StaticAnalyzer/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ clang_target_link_libraries(StaticAnalysisTests
3131
clangSerialization
3232
clangStaticAnalyzerCore
3333
clangStaticAnalyzerFrontend
34+
clangTesting
3435
clangTooling
3536
)

clang/unittests/StaticAnalyzer/SValTest.cpp

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
2222
#include "clang/StaticAnalyzer/Frontend/AnalysisConsumer.h"
2323
#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
24+
#include "clang/Testing/TestClangConfig.h"
2425
#include "clang/Tooling/Tooling.h"
2526
#include "llvm/ADT/STLExtras.h"
2627
#include "llvm/ADT/StringRef.h"
@@ -91,6 +92,21 @@ class SValCollector : public Checker<check::Bind, check::EndAnalysis> {
9192
mutable SVals CollectedSVals;
9293
};
9394

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+
94110
// SVAL_TEST is a combined way of providing a short code snippet and
95111
// to test some programmatic predicates on symbolic values produced by the
96112
// engine for the actual code.
@@ -135,7 +151,16 @@ class SValCollector : public Checker<check::Bind, check::EndAnalysis> {
135151
}); \
136152
} \
137153
\
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+
} \
139164
void NAME##SValCollector::test(ExprEngine &Engine, \
140165
const ASTContext &Context) const
141166

@@ -361,6 +386,31 @@ void foo() {
361386
EXPECT_EQ(Context.VoidPtrTy, B.getType(Context));
362387
}
363388

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+
364414
} // namespace
365415
} // namespace ento
366416
} // namespace clang

0 commit comments

Comments
 (0)