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

UCS/CPU: Make headers C89 compliant #9911

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bosilca
Copy link

@bosilca bosilca commented May 29, 2024

This is not a correctness issue but a user friendliness issue. Including some UCX headers while compiling OMPI with picky compiler options generate a ton of warnings.

The warning in compiler_def.h is about the two branches of the conditional returning different integer types (one int and the other unsigned long).

The other warnings are about declaration of functions with no arguments. The solution here is either adding void to signal there are no arguments or making the declaration a prototype.

Fixes #9910

@@ -78,7 +78,7 @@
#define UCS_BIT(i) (1ul << (i))

/* Mask of bits 0..i-1 */
#define UCS_MASK(_i) (((_i) >= 64) ? ~0 : (UCS_BIT(_i) - 1))
#define UCS_MASK(_i) (((_i) >= 64) ? ~0ul : (UCS_BIT(_i) - 1))
Copy link
Contributor

@tvegas1 tvegas1 May 29, 2024

Choose a reason for hiding this comment

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

I think this one is intentional, @ivankochin / @yosefe?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, to avoid compiler warnings

Copy link
Author

Choose a reason for hiding this comment

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

Not on a tertiary, the compiler is promoting everything to ul anyway (even when it is not complaining about it).

Copy link
Contributor

Choose a reason for hiding this comment

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

https://dev.azure.com/ucfconsort/ucx/_build/results?buildId=81413&view=logs&j=b225495a-a138-58be-0e0c-72778e1ff6b6&t=c6c5013e-bc26-58e0-88ac-2d26030ca3ad

/__w/1/s/contrib/../src/uct/ib/mlx5/ib_mlx5.c:218:26: error: implicit conversion from 'unsigned long' to 'unsigned int' changes value from 18446744073709551615 to 4294967295 [-Werror,-Wconstant-conversion]
    cq->cq_length_mask = UCS_MASK(cq->cq_length_log);
                       ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/__w/1/s/contrib/../src/ucs/sys/compiler_def.h:81:50: note: expanded from macro 'UCS_MASK'
#define UCS_MASK(_i)             (((_i) >= 64) ? ~0ul : (UCS_BIT(_i) - 1))
                                                 ^~~~
1 error generated.

Copy link
Author

Choose a reason for hiding this comment

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

Interesting, the DPC++ compiler choke on this. Without the ul I get this from gcc

.../include/ucs/sys/compiler_def.h:81:50: warning: operand of '?:' changes signedness from 'int' to 'long unsigned int' due to unsignedness of other operand [-Wsign-compare]
   81 | #define UCS_MASK(_i)             (((_i) >= 64) ? ~0 : (UCS_BIT(_i) - 1))
      |                                                  ^~
.../include/ucp/api/ucp.h:511:31: note: in expansion of macro 'UCS_MASK'
  511 |     UCP_DATATYPE_CLASS_MASK = UCS_MASK(UCP_DATATYPE_SHIFT) /**< Data-type class

Copy link
Author

Choose a reason for hiding this comment

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

We can keep both compilers happy if we use ~0u. Ugly, but it works, there is no demotion of int and no signedness mismatch.

Copy link
Contributor

Choose a reason for hiding this comment

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

/scrap/azure/agent-04/AZP_WORKSPACE/2/s/contrib/../test/gtest/common/mem_buffer.cc:321: Failure
Pattern check failed at 0x289dd10 offset 0: Expected: 0x11111111 Actual: 0x1111111111111111

It's related to UCS_MASK change I guess. We invert unsigned 32bits, then convert to 64bits.

Copy link
Author

Choose a reason for hiding this comment

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

This is puzzling. The current version of the macro does exactly as before, except in unsigned instead of not specified. I'm confused about how did it work before. Was the compiler propagating the type of the lvalue to the 0 in the macro ?

I guess we'll live with the warnings.

@tvegas1
Copy link
Contributor

tvegas1 commented May 29, 2024

To unblock CI, please change commit and pr title to something like UCS/CPU: Make headers C89 compliant

@bosilca bosilca changed the title externally-visible UCX headers are not C89 compliant UCS/CPU: Make headers C89 compliant May 29, 2024
@bosilca bosilca force-pushed the fix/picky_compiler_warnings branch 2 times, most recently from f916d70 to 9e96919 Compare May 29, 2024 14:42
Copy link
Contributor

@yosefe yosefe left a comment

Choose a reason for hiding this comment

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

maybe worth adding a simple test with c89 flag, that includes the relevant headers, to

check_inst_headers() {

This is not a correctness issue but a user friendliness issue. Including some UCX headers while compiling OMPI with picky compiler options generate a ton of warnings.

The warning in compiler_def.h is about the two branches of the conditional returning different integer types (one int and the other unsigned long).

The other warnings are about declaration of functions with no arguments. The solution here is either adding void to signal there are no arguments or making the declaration a prototype.

Fixes openucx#9910

Signed-off-by: George Bosilca <[email protected]>
@bosilca bosilca force-pushed the fix/picky_compiler_warnings branch from 9e96919 to 8a34b22 Compare May 29, 2024 20:25
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.

Some externally-visible UCX headers are not C89 compliant
3 participants