Open Bug 1757080 Opened 4 years ago Updated 4 years ago

nullptr warning when constructing mozilla::TimeDuration with constant 0

Categories

(Developer Infrastructure :: Source Code Analysis, defect, P4)

defect

Tracking

(Not tracked)

People

(Reporter: sfink, Unassigned)

Details

I believe clang-tidy is incorrect about these complaints:

// static
void nsJSContext::PokeGC(JS::GCReason aReason, JSObject* aObj,
                         TimeDuration aDelay) {
  MOZ_ASSERT(aReason != JS::GCReason::NO_REASON);
  sScheduler.PokeGC(aReason, aObj, aDelay);
}

// static
void nsJSContext::MaybePokeGC() {
  if (sShuttingDown) {
    return;
  }

  JSRuntime* rt = CycleCollectedJSRuntime::Get()->Runtime();
  JS::GCReason reason = JS::WantEagerMinorGC(rt);
  if (reason != JS::GCReason::NO_REASON) {
    MOZ_ASSERT(reason == JS::GCReason::EAGER_NURSERY_COLLECTION);
    PokeGC(reason, nullptr, 0); // WARNING: use nullptr
  }
  reason = JS::WantEagerMajorGC(rt);
  if (reason != JS::GCReason::NO_REASON) {
    PokeGC(reason, nullptr, 0); // WARNING: use nullptr

https://phabricator.services.mozilla.com/D100368 currently shows the above two warnings. But you can see the signature of PokeGC just above: it takes a reason, a pointer, and a TimeDuration. I'm guessing that the analysis sees that I am passing a 0 to a function that takes a pointer value -- except it's for a different parameter.

One thing that might factor in here is that the 3rd parameter has a default value?

static void PokeGC(JS::GCReason aReason, JSObject* aObj,
                     mozilla::TimeDuration aDelay = 0);

Or maybe it just thinks that the autoconversion from 0 to TimeDuration is the same as autoconverting 0 to nullptr?

Ok, I have another instance, and it's much simpler than what I was hypothesizing:

  EnsureGCRunner(0);

where

  void EnsureGCRunner(TimeDuration aDelay);

so it's complaining purely about passing a 0 for a TimeDuration. So actually this is not a bug in the static analysis, it's a warning for a weird hack that allows 0 and only 0 to be used to initialize a TImeDuration.

Summary: nullptr false positive → nullptr warning when constructing mozilla::TimeDuration with constant 0

The severity field is not set for this bug.
:andi, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(bpostelnicu)
Severity: -- → S4
Flags: needinfo?(bpostelnicu)
Priority: -- → P4
Product: Firefox Build System → Developer Infrastructure
You need to log in before you can comment on or make changes to this bug.