Skip to content

[libspirv][NFC] Fix build warnings when -Wall -Wextra is enabled#21586

Open
wenju-he wants to merge 3 commits intointel:syclfrom
wenju-he:fix-libspirv-build-warnings
Open

[libspirv][NFC] Fix build warnings when -Wall -Wextra is enabled#21586
wenju-he wants to merge 3 commits intointel:syclfrom
wenju-he:fix-libspirv-build-warnings

Conversation

@wenju-he
Copy link
Contributor

No description provided.

@wenju-he wenju-he requested review from a team and Maetveis as code owners March 23, 2026 00:00
@wenju-he wenju-he requested a review from kweronsx March 23, 2026 00:00
Comment on lines 10 to +12
int scope, global __CLC_GENTYPE *dst, const local __CLC_GENTYPE *src,
size_t num_gentypes, size_t stride, event_t event) {
(void)scope;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
int scope, global __CLC_GENTYPE *dst, const local __CLC_GENTYPE *src,
size_t num_gentypes, size_t stride, event_t event) {
(void)scope;
int /*scope*/, global __CLC_GENTYPE *dst, const local __CLC_GENTYPE *src,
size_t num_gentypes, size_t stride, event_t event) {

NIT: I'm not sure if libclc has an established existing practice for unused parameters, if it does it might be better to follow that, but I personally prefer this style. See also C++ Core Guidelines - Unused parameters should unnamed

Applies to all the places where there are unused parameters of course, I don't want to comment on all of them :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

int /*scope*/ is not exact the same as the guideline since it contains comment?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes true, I think it is in the spirit of the guidelines to have a comment, and a name is a good short comment of what that parameter would be if it were used (maybe users should still pass it, because the function might start using it in the future).
I don't feel strongly about this though, so if you prefer to completely get rid of the name that's okay for me too.

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW I tried grepping for what is more common in the LLVM codebase. I can find examples of having the comment, but trying to search for the other case brings up too much noise (calls to functions instead of definitions, casts, etc) with a simple regex so I gave up.

Comment on lines +327 to +329
} else { \
__builtin_trap(); \
__builtin_unreachable(); \
Copy link
Contributor

Choose a reason for hiding this comment

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

If op is ever not one of the above values that is an error made by the developer of libclc, and never the user, right?
In that case I think this check should be some kind of build-time controlled assertion that compiles to only __builtin_unreachable in release builds (basically LLVM_UNREACHABLE).

I would also find a structure like this better, in which case we don't need unreachable:

if (op == Reduce) {                                                         \
    result = __clc__SubgroupShuffle(x, __spirv_BuiltInSubgroupSize() - 1);  \
    *carry = result;                                                        \
} /* For InclusiveScan, use results as computed */                          \
else if (op == InclusiveScan) {                                             \
  result = x;                                                               \
  *carry = result;                                                          \
} else {                                                                    \
  LIBCLC_ASSERT(op == ExclusiveScan && "Unexpected operation");             \
  /* For ExclusiveScan, shift and prepend identity */                       \
  *carry = x;                                                               \
  result = __clc__SubgroupShuffleUp(x, 1);                                  \
  if (sg_lid == 0) {                                                        \
    result = IDENTITY;                                                      \
  }                                                                         \
}

Also we're basically expecting the optimizer to fold these conditionals out, correct?
In this case I think just as OP is a macro, we could have a EPILOG_OP. Though honestly using some C++ templates and lambdas in libclc is sounding more and more attractive.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you'd like to get this in quickly and return to LIBCLC_ASSERT or similar in a follow up then I would make the code like the above and only have the "assert" as a TODO comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for the advice. I have change the code to set result to 0 when group operation is unsupported. This aligns with IGC builtin implementation behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

This aligns with IGC builtin implementation behavior.

I don't think we need to necessarily align with that. Could you at the minimum add a TODO comment here and mention that these branches are never expected to be hit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you at the minimum add a TODO comment here

done

Copy link
Contributor

Choose a reason for hiding this comment

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

/* TODO: Not implemented yet */

This is not the comment text I was expecting, and it now makes me question if I understand this code correctly or not. What is not implemented here, are there supposed to be more collective operations, but we are not supporting all of them?

In my first comment I asked this:

If op is ever not one of the above values that is an error made by the developer of libclc, and never the user, right?

You never answered this, I assumed because I was making the right assumption, but now I'm not so sure.
Can you please confirm for me that this code-path is never actually expected to be hit? Even if the user passes values to opencl library functions that are not allowed per the spec?

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 code-path is never actually expected to be hit

I think this code path can be hit, for example, IGC 2.0 supports ClusteredReduce for few group functions.
libspirv implementation SPIR-V function in spec, so all opcode in the spec can be expected.

If op is ever not one of the above values that is an error made by the developer of libclc, and never the user, right?
Even if the user passes values to opencl library functions that are not allowed per the spec?

It could be something gap between what have been implemented and what are allowed.
I think it is fine to either ignore invalid input or put a unreachable for all unimplemented paths.

} else { \
result = OP(sg_x, sg_prefix); \
} \
} else { \
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto 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.

set result to 0 when group operation is unsupported

@wenju-he wenju-he requested a review from Maetveis March 25, 2026 05:13
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