[clang] [clang-repl] Extend the C support. (PR #89804)

Vassil Vassilev via cfe-commits cfe-commits at lists.llvm.org
Mon May 20 07:18:14 PDT 2024


================
@@ -407,6 +406,16 @@ void IncrementalParser::CleanUpPTU(PartialTranslationUnit &PTU) {
       }
     }
   }
+
+  // FIXME: We should de-allocate MostRecentTU
+  for (Decl *D : MostRecentTU->decls()) {
+    if (!isa<NamedDecl>(D))
+      continue;
+    // Check if we need to clean up the IdResolver chain.
+    NamedDecl *ND = cast<NamedDecl>(D);
----------------
vgvassilev wrote:

Hm. Ok I did not realize that code is smelly :)

We are getting a bit theoretical here but for the sake of the argument:

`isa<>` calls [CastInfo<To, const From>::isPossible](https://llvm.org/doxygen/structllvm_1_1CastIsPossible.html#a44e6fa462c45ccec1dcb2e52901e055d)(Val);

`cast<>` calls [CastInfo<To, const From>::doCast](https://llvm.org/doxygen/structllvm_1_1CastInfo.html#a143f6f757917e1245aed3882209b466f)(Val);

`dyn_cast<>` is both `isa + cast`.

My point was that in the case of something that's not a `NamedDecl` we will avoid the check `isPossible` for that case. It's probably peanuts: https://godbolt.org/z/xeh7jh5ax

Anyway, if you feel strongly about the other approach I can do it...

https://github.com/llvm/llvm-project/pull/89804


More information about the cfe-commits mailing list