opentitan icon indicating copy to clipboard operation
opentitan copied to clipboard

[dv] Compile warnings related to uvm_reg predict method is called without void casting

Open gaurangchitroda opened this issue 7 years ago • 14 comments

Hi All,

We are seeing compile warnings for uvm_reg predict method calls such following: test_csrs[i].predict(.value(wdata), .kind(UVM_PREDICT_WRITE));

As the return type of uvm_reg predict method is bit, tool expects that we should do void casting for such calls. Something like, void'(test_csrs[i].predict(.value(wdata), .kind(UVM_PREDICT_WRITE)));

Or should we check return value while calling predict method as follows? `DV_CHECK(test_csrs[i].predict(.value(wdata), .kind(UVM_PREDICT_WRITE)))

Or should we just ignore these warnings through using tool switch?

Best Regards, Gaurang

gaurangchitroda avatar Oct 10 '19 00:10 gaurangchitroda

Is there any reason not to do the last option ... `DV_CHECK?

martin-lueker avatar Oct 10 '19 00:10 martin-lueker

Aside from the effort of adding all those checks that is...

martin-lueker avatar Oct 10 '19 00:10 martin-lueker

@sriyerg @weicaiyang @shakushw @cindychip @udinator - Please also share your thoughts on this. As per our discussion, VCS does not throw these warnings, but I am thinking that we might have enabled ignoring these warnings by passing some switch.

gaurangchitroda avatar Oct 10 '19 00:10 gaurangchitroda

Following is an example of Xcelium warning that we are seeing currently: test_csrs[i].predict(.value(wdata), .kind(UVM_PREDICT_WRITE)); | xmvlog: *W,FUNTSK (../../../../../../../../usr/local/google/home/gaurangg/opentitan01/opentitan/hw/dv/sv/csr_utils/csr_seq_lib.sv,241|27): function called as a task without void'(). rg.predict(.value(val), .kind(UVM_PREDICT_WRITE));

gaurangchitroda avatar Oct 10 '19 00:10 gaurangchitroda

Got it. Would wrapping this in `DV_CHECK be redundant? (Are we losing any checks by not currently doing this?)

martin-lueker avatar Oct 10 '19 00:10 martin-lueker

After thinking more on this, i think warnings thrown makes the code safer. Better to leave them enabled.

The return value of this particular function can be ignored safely. It returns 0 only when there is an error response. We already check error response elsewhere (in the scoreboard).

My vote is for void casting (just for this particular function though). We take the rest on case by case basis.

sriyerg avatar Oct 10 '19 00:10 sriyerg

Thanks @sriyerg. Another best-practice-type perspective: Are there any similar scenarios where we would regret setting a precedent for ignoring this output? (Frankly I think it can go either way). If we have to go through and write all these void casts, is there any reason NOT to just make a policy of doing DV_CHECK's just to avoid having to think about this?

martin-lueker avatar Oct 10 '19 00:10 martin-lueker

@gaurangchitroda @sriyerg I second Martins comment. it can be a debug nightmare if you suppress a message type that flags potential unintended behavior. better to make a conscious decision to either void the return value or check it.

I am ok with letting it be up to the "designer of" to decide in each case.

rasmus-madsen avatar Oct 10 '19 11:10 rasmus-madsen

Return value from a function indicating success or failure of operation in some cases may be redundant and can be safely ignored. Enforcing a check always via `DV_CHECK or otherwise as a coding style rule may not be the right answer. I think this needs to be taken on a case by case basis. We should enforce either explicit void cast OR `DV_CHECK and leave this to the developer's judgement.

Xcelium does the right thing by throwing a warning. I will investigate why VCS doesn't.

In general, we should enforce '0 warnings thrown at compile/run time' policy (which exactly is what brought us here into this discussion in the first place). That will force us to deal with things like these.

Thanks Sri

sriyerg avatar Oct 10 '19 17:10 sriyerg

Thanks Sri. I have some updates to the style guide that I’m doing now. I can take this opportunity to add this as a style guide requirement (both DV_CHECK and void cast would be acceptable options) that will give everyone a forum to sign off/comment on this. How does that sound?

-Martin

martin-lueker avatar Oct 10 '19 17:10 martin-lueker

Sure, SGTM!

sriyerg avatar Oct 10 '19 18:10 sriyerg

This is now fixed for VCS - adding the option below causes VCS to throw a warning:+warn=SV-NFIVC.

sriyerg avatar Oct 17 '19 04:10 sriyerg

#556 should fix warnings related to predict method calls now. @sriyerg @martin-lueker - Let me know if we close this issue now.

gaurangchitroda avatar Oct 23 '19 20:10 gaurangchitroda

Fine with me. Thanks!

martin-lueker avatar Oct 23 '19 20:10 martin-lueker