From 9c4d194f44c4f74826b98f2efaa5e8a356650491 Mon Sep 17 00:00:00 2001 From: Steven Wan Date: Thu, 2 Dec 2021 18:29:43 -0500 Subject: [PATCH] [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 --- clang/unittests/StaticAnalyzer/CMakeLists.txt | 1 + clang/unittests/StaticAnalyzer/SValTest.cpp | 52 ++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/clang/unittests/StaticAnalyzer/CMakeLists.txt b/clang/unittests/StaticAnalyzer/CMakeLists.txt index 810cf75..ddfbea9 100644 --- a/clang/unittests/StaticAnalyzer/CMakeLists.txt +++ b/clang/unittests/StaticAnalyzer/CMakeLists.txt @@ -31,5 +31,6 @@ clang_target_link_libraries(StaticAnalysisTests clangSerialization clangStaticAnalyzerCore clangStaticAnalyzerFrontend + clangTesting clangTooling ) diff --git a/clang/unittests/StaticAnalyzer/SValTest.cpp b/clang/unittests/StaticAnalyzer/SValTest.cpp index ea10d69..08853a7 100644 --- a/clang/unittests/StaticAnalyzer/SValTest.cpp +++ b/clang/unittests/StaticAnalyzer/SValTest.cpp @@ -21,6 +21,7 @@ #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" @@ -91,6 +92,21 @@ private: mutable SVals CollectedSVals; }; +// Fixture class for parameterized SValTest +class SValTest : public testing::TestWithParam { +protected: + // FIXME: The tests "GetConstType" and "GetLocAsIntType" infer the type of + // integrals based on their bitwidth. This is not a reliable method on + // platforms where different integrals have the same width. + bool skipTest(StringRef TestName) { + std::string target = GetParam().Target; + return (target == "powerpc-ibm-aix" || target == "i686-apple-darwin9" || + target == "wasm32-unknown-unknown" || + target == "wasm64-unknown-unknown") && + (TestName == "GetConstType" || TestName == "GetLocAsIntType"); + } +}; + // SVAL_TEST is a combined way of providing a short code snippet and // to test some programmatic predicates on symbolic values produced by the // engine for the actual code. @@ -135,7 +151,16 @@ private: }); \ } \ \ - TEST(SValTest, NAME) { runCheckerOnCode(CODE); } \ + TEST_P(SValTest, NAME) { \ + if (skipTest(#NAME)) { \ + std::string target = GetParam().Target; \ + GTEST_SKIP() << "certain integrals have the same bitwidth on " \ + << target; \ + return; \ + } \ + runCheckerOnCodeWithArgs( \ + CODE, GetParam().getCommandLineArgs()); \ + } \ void NAME##SValCollector::test(ExprEngine &Engine, \ const ASTContext &Context) const @@ -361,6 +386,31 @@ void foo() { EXPECT_EQ(Context.VoidPtrTy, B.getType(Context)); } +std::vector allTestClangConfigs() { + std::vector all_configs; + TestClangConfig config; + config.Language = Lang_CXX14; + for (std::string target : + {"i686-pc-windows-msvc", "i686-apple-darwin9", + "x86_64-apple-darwin9", "x86_64-scei-ps4", + "x86_64-windows-msvc", "x86_64-unknown-linux", + "x86_64-apple-macosx", "x86_64-apple-ios14.0", + "wasm32-unknown-unknown", "wasm64-unknown-unknown", + "thumb-pc-win32", "sparc64-none-openbsd", + "sparc-none-none", "riscv64-unknown-linux", + "ppc64-windows-msvc", "powerpc-ibm-aix", + "powerpc64-ibm-aix", "s390x-ibm-zos", + "armv7-pc-windows-msvc", "aarch64-pc-windows-msvc", + "xcore-xmos-elf"}) { + config.Target = target; + all_configs.push_back(config); + } + return all_configs; +} + +INSTANTIATE_TEST_SUITE_P(SValTests, SValTest, + testing::ValuesIn(allTestClangConfigs())); + } // namespace } // namespace ento } // namespace clang -- 2.7.4