Skip to content

[VTR][LOG] Improved Unused Arg Warning Suppression #2656

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

AlexandreSinger
Copy link
Contributor

@AlexandreSinger AlexandreSinger commented Jul 18, 2024

Previously, VTR's logging used sizeof static casted to void in order
to suppress the unused argument warning when we want logs to be a NOP.

The sizeof operator may have some strange affects, but since the code
is NOP anyways thats not a huge deal. The reason for this change is that
intellisence that use clangd flag this as a potential issue causing
warnings.

This also exposes a potential issue where a LOG message is using a
function that may have memory effects, so it may not be cleaned up by
the compiler properly. The unused variables should be handled
explicitly.

Also moved static variables from the header file of vtr_log to the
implementation. No functional change, but just prevents these variables
from being present and accessible in every file that uses vtr_log (which
is alot).

@AlexandreSinger
Copy link
Contributor Author

Well. Now I have seen everything. Removing the sizeof operator actually did have a substantial performance impact on some test cases. I killed CI just to be safe and will investigate further. If sizeof is the only way so be it, but this is bizzar to me...

Previously, VTR's logging used `sizeof` static casted to void in order
to suppress the unused argument warning when we want logs to be a NOP.

The `sizeof` operator may have some strange affects, but since the code
is NOP anyways thats not a huge deal. The reason for this change is that
intellisence that use clangd flag this as a potential issue causing
warnings.

This also exposes a potential issue where a LOG message is using a
function that may have memory effects, so it may not be cleaned up by
the compiler properly. The unused variables should be handled
explicitly.

Also moved static variables from the header file of vtr_log to the
implementation. No functional change, but just prevents these variables
from being present and accessible in every file that uses vtr_log (which
is alot).
@github-actions github-actions bot added the VPR VPR FPGA Placement & Routing Tool label Jul 18, 2024
@AlexandreSinger
Copy link
Contributor Author

AlexandreSinger commented Jul 18, 2024

I realized what is going on here. The way these arguments are being ignored may actually expose a problem. Imagine the following case:

VTR_LOG("Value that I am interested in: %f\n", func_with_mem_effects(dyn_val));

This previously got turned into:

static_cast<void>(sizeof("Value that I am interested in: %f\n"));
static_cast<void>(sizeof(make_tuple(func_with_mem_effects(dyn_val)));

But lets assume that func_with_mem_effects has memory effects (sometimes not as easy to tell), then the compiler would not necessarily optimize this function away; especially if this is a complex function that is never inlined. It could be possible that some of these log statements may be still taking runtime even when debugging is off!

I have noticed that VTR_ASSERT has the exact same problem. This should be investigated. There may be performance being wasted without reason beyond just usability. Maybe sizeof bypasses this, but I have my doubts on this...

@AlexandreSinger
Copy link
Contributor Author

I was reviewing the use of sizeof in the standard library and found why we are using it in this way:
Screenshot from 2024-07-18 17-30-59

https://en.cppreference.com/w/cpp/language/sizeof

Although this is improper it seems to actually avoid performance concerns since the expressions within sizeof are never evaluated! This may make this PR useless, besides making intellisence errors go away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang-cpp C/C++ code libvtrutil VPR VPR FPGA Placement & Routing Tool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant