[clang] [clang][timers][modules] Fix a timer being started when it's running (PR #154231)

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 19 01:31:35 PDT 2025


================
@@ -11003,8 +11003,9 @@ void ASTReader::diagnoseOdrViolations() {
 }
 
 void ASTReader::StartedDeserializing() {
-  if (++NumCurrentElementsDeserializing == 1 && ReadTimer.get())
-    ReadTimer->startTimer();
+  if (llvm::Timer *T = ReadTimer.get();
+      ++NumCurrentElementsDeserializing == 1 && T && !T->isRunning())
+    T->startTimer();
----------------
ilya-biryukov wrote:

Timer is a red flag, but the problem goes deeper and the fact that `FinishDeserializing` starts deserializing again and is therefore called recursively is really hard to wrap your head around.

Could we instead move the decrement of `NumCurrentElementsDeserializing` to the end of `ASTReader::FinishedDeserializing`? That would ensure not only that the timer is never reinitialized, but also that we never call `ASTReader::FinishedDeserializing` from `ASTReader::FinishedDeserializing`.

Basically, this comment from `ASTReader::FinishedDeserializing`:
```
    // We decrease NumCurrentElementsDeserializing only after pending actions
    // are finished, to avoid recursively re-calling finishPendingActions().
```
is actually applicable to the whole function.


Could you try that out and see if any tests fail?

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


More information about the cfe-commits mailing list