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

fix some clang-cl warnings regarding unused parameters #8

Closed
wants to merge 1 commit into from

Conversation

lemire
Copy link

@lemire lemire commented Dec 5, 2023

They occur because we try to compile C code as C++17. The -std=c++17 flag should not be used when compiling C code. A quickfix is to set cflags_cc=[] in C dependencies. It clears the C++ flags.

Interestingly, it illustrates that the following configuration...

            ['target_arch in "ia32 x64" and OS!="ios"', {
              'defines': [ 'ADLER32_SIMD_SSSE3' ],
              'cflags': [ '-mssse3' ],
              'cflags_cc': [],
              'conditions': [

is not triggered. So you get both a build error because you are missing SSSE3, but also a visible warning.

I am sure that it is quite trivial.

occur because we try to compile C code as C++17.
@@ -18,14 +18,15 @@
'conditions': [
['target_arch in "ia32 x64" and OS!="ios"', {
'defines': [ 'ADLER32_SIMD_SSSE3' ],
'cflags': [ '-mssse3' ],
Copy link
Author

Choose a reason for hiding this comment

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

@anonrig Would you happen to know why these variables (cflags, cflags_cpp) don't take hold here even though we are building under Windows with x64.

Copy link
Owner

Choose a reason for hiding this comment

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

I think it's a GYP issue. It was never meant to support Clang on Windows AFAIK and cflags are passed differently for it. See c1d1878

@@ -78,6 +78,7 @@
'include_dirs': [ 'base64/include', 'base64/lib' ],
'sources': [ 'base64/lib/arch/ssse3/codec.c' ],
'defines': [ 'BASE64_STATIC_DEFINE', 'HAVE_SSSE3=1' ],
'cflags_cpp': [],
Copy link
Owner

Choose a reason for hiding this comment

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

Do these work? What are the fixed warnings?

Copy link
Author

Choose a reason for hiding this comment

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

Without these, you are passing-std=c++17 to clang-cl when compiling C code. The better solution would be for the build engine to recognize that it is compiling C code, and not pass the C++ flags.

Copy link
Owner

Choose a reason for hiding this comment

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

I'm surprised that it works because I don't see any occurence of cflags_cpp in the code base (including the source code of GYP)

Copy link
Author

Choose a reason for hiding this comment

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

You are correct. It should be cflags_cc.

@targos
Copy link
Owner

targos commented Dec 7, 2023

They occur because we try to compile C code as C++17.

I think this comes from common.gypi:

https://github.com/nodejs/node/blob/3f4ea7ad7f4a1cb058bdc5363311607d1793928e/common.gypi#L284-L289

@lemire
Copy link
Author

lemire commented Dec 7, 2023

I think this comes from common.gypi:

Yes. And that flag looks fine to me. The issue is that it gets applied when clang-cl builds C code. Node has several C dependencies and they are the ones that appear most broken right now.

Short of making the build engine smarter, I propose to clear the C++ flags when within a C dependency.

It does not quite work perfectly because, as we have observed, some flags do not get applied under clang-cl when it seems they should. This issue leads to breakage having to do with SIMD instructions.

The better solution would be to fix the build engine so that it actually supports clang-cl as a first class compiler.

@lemire
Copy link
Author

lemire commented Dec 7, 2023

Basically this PR gets you closer to building under clang-cl without warnings and errors because it manually removes the unnecessary C++ flags within C projects. I think that you pretty much need to do this if fixing GYP is not an option.

@targos
Copy link
Owner

targos commented Dec 7, 2023

I understand what you're trying to do but what I understand of GYP is that it ignores cflags and related options for the Visual studio generator.

@lemire
Copy link
Author

lemire commented Dec 7, 2023

I understand what you're trying to do but what I understand of GYP is that it ignores cflags and related options for the Visual studio generator.

Checkout my PR and run it. It will take you a minute.

It works! It drastically reduces the volume of warnings.

It is a verifiable statement, you can check.

@lemire
Copy link
Author

lemire commented Dec 7, 2023

To put it another way, GYP does not ignore all of these changes, just a couple.

@targos
Copy link
Owner

targos commented Dec 7, 2023

First warning I see (clean clone with this patch applied):

clang-cl : warning : argument unused during compilation: '-std:c++17' [-Wunused-command-line-argument] [D:\Git\nodejs\node\deps\histogram\histogram.vcxproj]

Then a lot more in uvwasi and zlib

@lemire
Copy link
Author

lemire commented Dec 7, 2023

First warning I see (clean clone with this patch applied):

With a fresh build? That's intriguing.

@lemire
Copy link
Author

lemire commented Dec 8, 2023

Please see nodejs#35433 (comment)

I think that there is a fundamental problem that should be solved and that what I am proposing here is wrong.

Closing.

@lemire lemire closed this Dec 8, 2023
@lemire
Copy link
Author

lemire commented Dec 8, 2023

@targos Note that the approach illustrated by this PR does work. You do get rid of the warnings when setting cflags_cc to the empty array. (An earlier commit had cflags_cpp which is the wrong variable.)

It is a hack, however. I don't recommend it.

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.

2 participants