This is an archive of the discontinued LLVM Phabricator instance.

[libc] Make string functions buildable with GCC
ClosedPublic

Authored by gchatelet on Dec 13 2022, 7:48 AM.

Diff Detail

Event Timeline

gchatelet created this revision.Dec 13 2022, 7:48 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptDec 13 2022, 7:48 AM
gchatelet requested review of this revision.Dec 13 2022, 7:48 AM

@sivachandra can you have a look ?

sivachandra accepted this revision.Dec 15 2022, 8:55 AM
sivachandra added inline comments.
libc/src/string/memory_utils/bcmp_implementations.h
103

What was the problem with these constexpr conditionals? Because the inline_* functions are now potentially excluded by the preprocessor, they could be invisible at compile time?

This revision is now accepted and ready to land.Dec 15 2022, 8:55 AM
gchatelet marked an inline comment as done.Dec 16 2022, 2:45 AM
gchatelet added inline comments.
libc/src/string/memory_utils/bcmp_implementations.h
103

avx512 functions requires a specific ABI. When compiling op_x86.h without avx512 support, GCC complains about these avx512 specific functions not having the right ABI -> I had to selectively exclude them using the preprocessor. Now these functions do not exist anymore when not compiling for avx512, so we cannot refer to them in the XXX_implementations_h files.

Using if constexpr would fail since the code still needs to be valid (even if disabled) so I had to use the preprocessor here as well.

This is far from ideal, it adds a lot of visual clutter.

Another option would be to disable the body of the function in op_x86.h instead of the function itself. So the function would still exist and could be referred to through if constexpr constructs.
I'll give it a try.

gchatelet updated this revision to Diff 483484.Dec 16 2022, 3:55 AM
gchatelet marked an inline comment as done.
  • Disable function body instead of the function itself.

@sivachandra let me know if you prefer this version or the previous one.

gchatelet updated this revision to Diff 483489.Dec 16 2022, 4:08 AM
  • Prevent warning about unused variables.
This revision was automatically updated to reflect the committed changes.

@sivachandra let me know if you prefer this version or the previous one.

LGTM; Could we make the alternate paths simply a failing static_assert?

@sivachandra let me know if you prefer this version or the previous one.

LGTM; Could we make the alternate paths simply a failing static_assert?

I wish I could but this would result in a compilation failure.
There's a proposal to support this use case but it's not currently implemented.
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2593r0.html

Let me know if you prefer the preprocessor solution that adds more safety at the cost of less readable code.

Let me know if you prefer the preprocessor solution that adds more safety at the cost of less readable code.

This is fine, thanks!