Skip to content
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

[luci] Introduce the parent class method to luci::Pass #14594

Closed
wants to merge 1 commit into from

Conversation

tomdol
Copy link
Contributor

@tomdol tomdol commented Jan 28, 2025

This directive fixes a build break caused by a compiler error emitted when compiling with -Werror=overloaded-virtual flag switched on. The error is about the logo::Pass::run method being hidden by luci::Pass::run.

ONE-DCO-1.0-Signed-off-by: Tomasz Dolbniak [email protected]

Related issue NPU_Compiler/issues/19901

This directive fixes a build break caused by a compiler error emitted when
compiling with -Werror=overloaded-virtual flag switched on. The error is about
the logo::Pass::run method being hidden by luci::Pass::run.

ONE-DCO-1.0-Signed-off-by: Tomasz Dolbniak <[email protected]>
@tomdol tomdol force-pushed the overloaded_virtual branch from b3f60fe to 83e647c Compare January 28, 2025 14:59
tomdol added a commit to tomdol/ONE that referenced this pull request Jan 28, 2025
This directive fixes a build break caused by a compiler error emitted when
compiling with -Werror=overloaded-virtual flag switched on. The error is about
the logo::Pass::run method being hidden by luci::Pass::run.

This is a backport of Samsung#14594
to the release branch.

ONE-DCO-1.0-Signed-off-by: Tomasz Dolbniak <[email protected]>
@seanshpark
Copy link
Contributor

@lemmaa , what is the guide for putting internal server URLs?

@@ -28,6 +28,8 @@ namespace luci
class Pass : public logo::Pass
{
public:
// This directive prevents emitting a compiler erro triggered by -Werror=overloaded-virtual
using logo::Pass::run;
Copy link
Contributor

@seanshpark seanshpark Feb 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why add this here.
I cannot accept the resolution method. please find another way of solution.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in fact the solution. The reason this error occurs in the first place is that the luci::Pass::run(luci::Module *) has a different signature than the parent's loco::Pass::run(loco::Graph *) and this can cause overload resolution problems when compiling the code in certain situations. This is why newer compilers report a warning and the -Werror=overloaded-virtual makes it an error which basically blocks the build on Ubuntu 24.

The using directive adds the logo::Pass::run method to the overload set of the luci::Pass class which makes the warning(error) go away and most importantly - it doesn't break anything.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO you got it wrong. luci::Pass::run(luci::Module *) is also pure virtual so that inherit class SHOULD also override.
You can inherit from loco::Pass if do not want to use luci::Module * parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original build error (screenshot in the linked issue) comes from a file CircleNodePass.h which includes the logo/Pass.h header and contains a class which inherits from logo::Pass. This is correct and matches what you said above - CircleNodePass overrides run(loco::Graph* graph) and doesn't touch the version which operates on luci::Module.

Yet the compiler produces an error about luci::Pass::run hiding logo::Pass::run withing this compilation context.

Here's a smaller snippet that demonstrates how hiding the virtual methods interferes with name lookup and overload resolution https://ideone.com/lI3QNL

Uncomment the using A::run; line fixes the problem and this is exactly what I'm proposing here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only other solution I can imagine is renaming the conflicting methods so that they don't hide each other:

logo::Pass::run(Graph*) -> logo::Pass::run_on_graph(Graph*)
luci::Pass::run(Module*) -> luci::Pass::run_on_module(Module*)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all, I'm not familiar with this kind of warning and I didn't understand neither what above code tries to solve at the first.
So, I've searched the general solution for this warning and found that most of directions guided as @tomdol's.

"In cases where the different signatures are not an accident, the simplest solution is to add a using-declaration to the derived class to un-hide the base function, e.g. add using A::f; to B. "

We may solve the issue in different ways (e.g. duplicating logo::pass to luci:pass, renaming the functions ...) but current suggestion seems quite optimal for me ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried overriding luci::Pass::run(luci::Module *) ? something like

   bool run(luci::Module *) override { throw "NYI"; }

It's impossible to override the suggested method because it's a member of luci::Pass. The NPU_Compiler does not inherit from this class. It uses logo::Pass instead.

The reason this became a problem is the change how GCC13 and newer versions compile the whole code base. The inheritance hierarchy of logo::Pass <- luci::Pass is analyzed independently from logo::Pass <- CircleNodePass so no matter what I do this warning will still be reported.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why add this here. I cannot accept the resolution method. please find another way of solution.

@seanshpark , I believe some positive opinions about this resolution method were added:
#14594 (comment)
#14594 (comment)

and I believe this resolution is based on GCC documentation. So please give us your final decision about this PR, we want to merge it or close it and prepare patch for ONE in our project to solve this issue on our side.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot accept the resolution method. please find another way of solution.

There was no updates after this comment.
I still do not accept this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason this became a problem is the change how GCC13 and newer versions compile the whole code base. The inheritance hierarchy of logo::Pass <- luci::Pass is analyzed independently from logo::Pass <- CircleNodePass so no matter what I do this warning will still be reported.

#14594 (comment)

There's no other way of solving this warning but the using directive.

@seanshpark
Copy link
Contributor

I assume this issue is to fix for U24.04 cause of your situation.
Current ONE/compiler does not have CI for U24.04.
I cannot confirm this check is appropriate for the issue in internal compiler.
Personally I do not want this patch to land.

What I can suggest is written in #14589 (comment)

@dahlinPL
Copy link
Contributor

Please take a look into #14448, I believe this workaround can be removed after fixing it in a way presented in this PR, @hseok-oh, you're author of #14448 what's your opinion?

@hseok-oh
Copy link
Contributor

hseok-oh commented Feb 12, 2025

@dahlinPL @seanshpark We can see this warning when we are using Clang or latest GCC version.

https://stackoverflow.com/questions/18515183/c-overloaded-virtual-function-warning-by-clang

This warning is there to prevent accidental hiding of overloads when overriding is intended.

Clang users have been experiencing this issue for more than 10 years. And now GCC has begun to warn this issue, unfortunately.
I added comment that TODO Remove -Wno-reoder and -Wno-overloaded-virtual on #14448. But I've changed my opinion because I think overloaded-virtual warning is excessive. I want to ignore this warning by keeping flag -Wno-overloaded-virtual.

@dahlinPL
Copy link
Contributor

@dahlinPL @seanshpark We can see this warning when we are using Clang or latest GCC version.

https://stackoverflow.com/questions/18515183/c-overloaded-virtual-function-warning-by-clang

This warning is there to prevent accidental hiding of overloads when overriding is intended.

Clang users have been experiencing this issue for more than 10 years. And now GCC has begun to warn this issue, unfortunately. I added comment that TODO Remove -Wno-reoder and -Wno-overloaded-virtual on #14448. But I've changed my opinion because I think overloaded-virtual warning is excessive. I want to ignore this warning by keeping flag -Wno-overloaded-virtual.

I fully understand your concern :)

But please keep in mind below:

  • ONE can be used as dependency in some projects, and these projects can face this build issue and maybe project owners don't want to use -Wno-overloaded-virtual
  • in fact overloaded-virtual seems to be quite easy to fix in ONE, even if it's a bit excessive

so, even if opinions about overloaded-virtual usefulness vary, please reconsider fixing these few lines with explicity using to supress compiler doubts :)

I would be grateful, it will help us a lot

@dahlinPL
Copy link
Contributor

@seanshpark @jinevening thanks for merging #14808, thanks to this we are one step closer to bump ONE version in our project. WIll you please reconsider also this contribution?

@jinevening
Copy link
Contributor

First of all, I think this PR can be merged as-is. This seems to be a widely-used solution for this situation.

I can imagine another workaround that makes a separate class for bool run(luci::Module *) (ex: luci::ModulePass) and let luci::Pass inherit both classes (luci::ModulePass and logo::Pass). But I'm not sure the workaround is better than the current PR.

Copy link
Contributor

@jinevening jinevening left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

It's up to @seanshpark 's decision.

Copy link
Contributor

@mbencer mbencer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@dahlinPL dahlinPL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

It's up to @seanshpark 's decision.

@tomdol
Copy link
Contributor Author

tomdol commented Mar 21, 2025

Closing this PR since it hasn't been merged for almost 2 months despite providing the motivation and arguments explaining the proposed solution.

If anything changes, feel free to reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants