[clang] 55662b2 - [analyzer][NFC] Inline ExprEngine::handleLVectorSplat()

Balazs Benics via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 1 01:44:12 PDT 2021


Author: Balazs Benics
Date: 2021-07-01T10:54:28+02:00
New Revision: 55662b24a4755680e4fd34dc22a3dd555fdb1291

URL: https://github.com/llvm/llvm-project/commit/55662b24a4755680e4fd34dc22a3dd555fdb1291
DIFF: https://github.com/llvm/llvm-project/commit/55662b24a4755680e4fd34dc22a3dd555fdb1291.diff

LOG: [analyzer][NFC] Inline ExprEngine::handleLVectorSplat()

It seems like ExprEngine::handleLVectorSplat() was used at only 2
places. It might be better to directly inline them for readability.

It seems like these cases were not covered by tests according to my
coverage measurement, so I'm adding tests as well, demonstrating that no
behavior changed.
Besides that, I'm handling CK_MatrixCast similarly to how the rest of
the unhandled casts are evaluated.

Differential Revision: https://reviews.llvm.org/D105125

Reviewed by: NoQ

Added: 
    

Modified: 
    clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
    clang/test/Analysis/casts.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
index bf3f8dfd0877a..7ad3dca831ac4 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -282,22 +282,6 @@ ProgramStateRef ExprEngine::handleLValueBitCast(
   return state;
 }
 
-ProgramStateRef ExprEngine::handleLVectorSplat(
-    ProgramStateRef state, const LocationContext* LCtx, const CastExpr* CastE,
-    StmtNodeBuilder &Bldr, ExplodedNode* Pred) {
-  // Recover some path sensitivity by conjuring a new value.
-  QualType resultType = CastE->getType();
-  if (CastE->isGLValue())
-    resultType = getContext().getPointerType(resultType);
-  SVal result = svalBuilder.conjureSymbolVal(nullptr, CastE, LCtx,
-                                             resultType,
-                                             currBldrCtx->blockCount());
-  state = state->BindExpr(CastE, LCtx, result);
-  Bldr.generateNode(CastE, Pred, state);
-
-  return state;
-}
-
 void ExprEngine::VisitCast(const CastExpr *CastE, const Expr *Ex,
                            ExplodedNode *Pred, ExplodedNodeSet &Dst) {
 
@@ -535,17 +519,20 @@ void ExprEngine::VisitCast(const CastExpr *CastE, const Expr *Ex,
           continue;
         }
         // Explicitly proceed with default handler for this case cascade.
-        state = handleLVectorSplat(state, LCtx, CastE, Bldr, Pred);
-        continue;
       }
+        LLVM_FALLTHROUGH;
       // Various C++ casts that are not handled yet.
       case CK_ToUnion:
+      case CK_MatrixCast:
       case CK_VectorSplat: {
-        state = handleLVectorSplat(state, LCtx, CastE, Bldr, Pred);
-        continue;
-      }
-      case CK_MatrixCast: {
-        // TODO: Handle MatrixCast here.
+        QualType resultType = CastE->getType();
+        if (CastE->isGLValue())
+          resultType = getContext().getPointerType(resultType);
+        SVal result = svalBuilder.conjureSymbolVal(
+            /*symbolTag=*/nullptr, CastE, LCtx, resultType,
+            currBldrCtx->blockCount());
+        state = state->BindExpr(CastE, LCtx, result);
+        Bldr.generateNode(CastE, Pred, state);
         continue;
       }
     }

diff  --git a/clang/test/Analysis/casts.c b/clang/test/Analysis/casts.c
index 6b9108ac6bb03..ce195297874b1 100644
--- a/clang/test/Analysis/casts.c
+++ b/clang/test/Analysis/casts.c
@@ -1,7 +1,7 @@
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin9 -analyzer-checker=core,alpha.core,debug.ExprInspection -analyzer-store=region -Wno-pointer-to-int-cast -verify -analyzer-config eagerly-assume=false %s
-// RUN: %clang_analyze_cc1 -triple i386-apple-darwin9 -analyzer-checker=core,alpha.core,debug.ExprInspection -analyzer-store=region -Wno-pointer-to-int-cast -verify -analyzer-config eagerly-assume=false %s
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin9 -analyzer-checker=core,alpha.core,debug.ExprInspection -Wno-pointer-to-int-cast -verify -DEAGERLY_ASSUME=1 -w %s
-// RUN: %clang_analyze_cc1 -triple i386-apple-darwin9 -analyzer-checker=core,alpha.core,debug.ExprInspection -Wno-pointer-to-int-cast -verify -DEAGERLY_ASSUME=1 -DBIT32=1 -w %s
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin9 -fenable-matrix -analyzer-checker=core,alpha.core,debug.ExprInspection -analyzer-store=region -Wno-pointer-to-int-cast -verify -analyzer-config eagerly-assume=false %s
+// RUN: %clang_analyze_cc1 -triple i386-apple-darwin9 -fenable-matrix -analyzer-checker=core,alpha.core,debug.ExprInspection -analyzer-store=region -Wno-pointer-to-int-cast -verify -analyzer-config eagerly-assume=false %s
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin9 -fenable-matrix -analyzer-checker=core,alpha.core,debug.ExprInspection -Wno-pointer-to-int-cast -verify -DEAGERLY_ASSUME=1 -w %s
+// RUN: %clang_analyze_cc1 -triple i386-apple-darwin9 -fenable-matrix -analyzer-checker=core,alpha.core,debug.ExprInspection -Wno-pointer-to-int-cast -verify -DEAGERLY_ASSUME=1 -DBIT32=1 -w %s
 
 extern void clang_analyzer_eval(_Bool);
 
@@ -193,6 +193,27 @@ void testSwitchWithSizeofs() {
   }
 }
 
+void test_ToUnion_cast(unsigned long long x) {
+  union Key {
+    unsigned long long data;
+  };
+  void clang_analyzer_dump_union(union Key);
+  clang_analyzer_dump_union((union Key)x); // expected-warning {{Unknown}}
+}
+
+typedef char cx5x5 __attribute__((matrix_type(5, 5)));
+typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+void test_MatrixCast_cast(cx5x5 c) {
+  void clang_analyzer_dump_ix5x5(ix5x5);
+  clang_analyzer_dump_ix5x5((ix5x5)c); // expected-warning {{Unknown}}
+}
+
+void test_VectorSplat_cast(long x) {
+  typedef int __attribute__((ext_vector_type(2))) V;
+  void clang_analyzer_dump_V(V);
+  clang_analyzer_dump_V((V)x); // expected-warning {{Unknown}}
+}
+
 #endif
 
 #ifdef EAGERLY_ASSUME


        


More information about the cfe-commits mailing list