[PATCH] D115349: [analyzer][NFC] Re-enable skipped SValTests by relaxing expectations

Balázs Benics via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 19 06:16:44 PST 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG881b6a009fb6: [analyzer][NFC] Re-enable skipped SValTests by relaxing expectations (authored by steakhal).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115349/new/

https://reviews.llvm.org/D115349

Files:
  clang/unittests/StaticAnalyzer/SValTest.cpp


Index: clang/unittests/StaticAnalyzer/SValTest.cpp
===================================================================
--- clang/unittests/StaticAnalyzer/SValTest.cpp
+++ clang/unittests/StaticAnalyzer/SValTest.cpp
@@ -92,20 +92,15 @@
   mutable SVals CollectedSVals;
 };
 
+static void expectSameSignAndBitWidth(QualType ExpectedTy, QualType ActualTy,
+                                      const ASTContext &Context) {
+  EXPECT_EQ(ExpectedTy->isUnsignedIntegerType(),
+            ActualTy->isUnsignedIntegerType());
+  EXPECT_EQ(Context.getTypeSize(ExpectedTy), Context.getTypeSize(ActualTy));
+}
+
 // Fixture class for parameterized SValTest
-class SValTest : public testing::TestWithParam<TestClangConfig> {
-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");
-  }
-};
+class SValTest : public testing::TestWithParam<TestClangConfig> {};
 
 // SVAL_TEST is a combined way of providing a short code snippet and
 // to test some programmatic predicates on symbolic values produced by the
@@ -152,14 +147,8 @@
   }                                                                            \
                                                                                \
   TEST_P(SValTest, NAME) {                                                     \
-    if (skipTest(#NAME)) {                                                     \
-      std::string target = GetParam().Target;                                  \
-      GTEST_SKIP() << "certain integrals have the same bitwidth on "           \
-                   << target;                                                  \
-      return;                                                                  \
-    }                                                                          \
-    runCheckerOnCodeWithArgs<add##NAME##SValCollector>(                        \
-        CODE, GetParam().getCommandLineArgs());                                \
+    EXPECT_TRUE(runCheckerOnCodeWithArgs<add##NAME##SValCollector>(            \
+        CODE, GetParam().getCommandLineArgs()));                               \
   }                                                                            \
   void NAME##SValCollector::test(ExprEngine &Engine,                           \
                                  const ASTContext &Context) const
@@ -179,27 +168,30 @@
 
   SVal Y = getByName("y");
   ASSERT_FALSE(Y.getType(Context).isNull());
-  EXPECT_EQ(Context.getUIntPtrType(), Y.getType(Context));
+  expectSameSignAndBitWidth(Context.getUIntPtrType(), Y.getType(Context),
+                            Context);
 }
 
 SVAL_TEST(GetLocAsIntType, R"(
 void foo(int *x) {
-  long int a = (long int)x;
-  unsigned b = (long unsigned)&a;
-  int c = (long int)nullptr;
+  long int a = (long long int)x;
+  unsigned b = (long long unsigned)&a;
+  int c = (long long int)nullptr;
 })") {
   SVal A = getByName("a");
   ASSERT_FALSE(A.getType(Context).isNull());
+
   // TODO: Turn it into signed long
-  EXPECT_EQ(Context.getUIntPtrType(), A.getType(Context));
+  expectSameSignAndBitWidth(Context.UnsignedLongTy, A.getType(Context),
+                            Context);
 
   SVal B = getByName("b");
   ASSERT_FALSE(B.getType(Context).isNull());
-  EXPECT_EQ(Context.UnsignedIntTy, B.getType(Context));
+  expectSameSignAndBitWidth(Context.UnsignedIntTy, B.getType(Context), Context);
 
   SVal C = getByName("c");
   ASSERT_FALSE(C.getType(Context).isNull());
-  EXPECT_EQ(Context.IntTy, C.getType(Context));
+  expectSameSignAndBitWidth(Context.IntTy, C.getType(Context), Context);
 }
 
 SVAL_TEST(GetSymExprType, R"(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115349.401207.patch
Type: text/x-patch
Size: 4101 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220119/15ef69d8/attachment.bin>


More information about the cfe-commits mailing list