[clang] Revert "[clang][dataflow] Teach `AnalysisASTVisitor` that `typeid()` can be evaluated." (PR #96766)

via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 26 06:40:33 PDT 2024


https://github.com/martinboehme created https://github.com/llvm/llvm-project/pull/96766

Reverts llvm/llvm-project#96731

It causes CI failures.

>From d1ed32e5cb1cb43acf2d9085960ff37c3fe6b09b Mon Sep 17 00:00:00 2001
From: martinboehme <mboehme at google.com>
Date: Wed, 26 Jun 2024 15:40:06 +0200
Subject: [PATCH] =?UTF-8?q?Revert=20"[clang][dataflow]=20Teach=20`Analysis?=
 =?UTF-8?q?ASTVisitor`=20that=20`typeid()`=20can=20be=20e=E2=80=A6"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit dfe80a73223edff5c53f8be7925d302883cb40bc.
---
 .../clang/Analysis/FlowSensitive/ASTOps.h     |  6 +--
 .../Analysis/FlowSensitive/TransferTest.cpp   | 43 -------------------
 2 files changed, 1 insertion(+), 48 deletions(-)

diff --git a/clang/include/clang/Analysis/FlowSensitive/ASTOps.h b/clang/include/clang/Analysis/FlowSensitive/ASTOps.h
index f9c923a36ad22..925b99af9141a 100644
--- a/clang/include/clang/Analysis/FlowSensitive/ASTOps.h
+++ b/clang/include/clang/Analysis/FlowSensitive/ASTOps.h
@@ -113,11 +113,7 @@ class AnalysisASTVisitor : public RecursiveASTVisitor<Derived> {
   // nevertheless it appears in the Clang CFG, so we don't exclude it here.
   bool TraverseDecltypeTypeLoc(DecltypeTypeLoc) { return true; }
   bool TraverseTypeOfExprTypeLoc(TypeOfExprTypeLoc) { return true; }
-  bool TraverseCXXTypeidExpr(CXXTypeidExpr *TIE) {
-    if (TIE->isPotentiallyEvaluated())
-      return RecursiveASTVisitor<Derived>::TraverseCXXTypeidExpr(TIE);
-    return true;
-  }
+  bool TraverseCXXTypeidExpr(CXXTypeidExpr *) { return true; }
   bool TraverseUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *) {
     return true;
   }
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 39e7001393e5e..e743eefa5d458 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -1637,49 +1637,6 @@ TEST(TransferTest, StructModeledFieldsWithAccessor) {
       });
 }
 
-TEST(TransferTest, StructModeledFieldsInTypeid) {
-  // Test that we model fields mentioned inside a `typeid()` expression only if
-  // that expression is potentially evaluated -- i.e. if the expression inside
-  // `typeid()` is a glvalue of polymorphic type (see
-  // `CXXTypeidExpr::isPotentiallyEvaluated()` and [expr.typeid]p3).
-  std::string Code = R"(
-    // Definitions needed for `typeid`.
-    namespace std {
-      class type_info {};
-      class bad_typeid {};
-    }  // namespace std
-
-    struct NonPolymorphic {};
-
-    struct Polymorphic {
-      virtual ~Polymorphic() = default;
-    };
-
-    struct S {
-      NonPolymorphic *NonPoly;
-      Polymorphic *Poly;
-    };
-
-    void target(S &s) {
-      typeid(*s.NonPoly);
-      typeid(*s.Poly);
-      // [[p]]
-    }
-  )";
-  runDataflow(
-      Code,
-      [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
-         ASTContext &ASTCtx) {
-        const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
-        auto &SLoc = getLocForDecl<RecordStorageLocation>(ASTCtx, Env, "s");
-        std::vector<const ValueDecl *> Fields;
-        for (auto [Field, _] : SLoc.children())
-          Fields.push_back(Field);
-        EXPECT_THAT(Fields,
-                    UnorderedElementsAre(findValueDecl(ASTCtx, "Poly")));
-      });
-}
-
 TEST(TransferTest, StructModeledFieldsWithComplicatedInheritance) {
   std::string Code = R"(
     struct Base1 {



More information about the cfe-commits mailing list