Skip to content

Commit 14a5144

Browse files
ezhulenevGoogle-ML-Automation
authored andcommitted
[xla:ffi] Fix clang macro expansion warnings
PiperOrigin-RevId: 820212080
1 parent 5bd3de6 commit 14a5144

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

xla/ffi/api/api.h

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,8 +1948,15 @@ auto DictionaryDecoder(Members... m) {
19481948
#define XLA_FFI_ATTRIBUTE_UNUSED
19491949
#endif
19501950

1951-
// Use captureless lambda to function pointer conversion to create a static
1952-
// XLA_FFI_Handler function pointer variable.
1951+
// In all macros below we use captureless lambda to function pointer conversion
1952+
// to create a static XLA_FFI_Handler function pointer variable.
1953+
1954+
// Use explicit binding specification and traits to create a handler.
1955+
#define XLA_FFI_DEFINE_HANDLER_EXPLICIT_WITH_TRAITS(fn, impl, binding, traits) \
1956+
static constexpr XLA_FFI_Handler* fn = +[](XLA_FFI_CallFrame* call_frame) { \
1957+
static auto* handler = binding.To(impl, traits).release(); \
1958+
return handler->Call(call_frame); \
1959+
}
19531960

19541961
// Use explicit binding specification to create a handler.
19551962
#define XLA_FFI_DEFINE_HANDLER_EXPLICIT(fn, impl, binding) \
@@ -1958,12 +1965,6 @@ auto DictionaryDecoder(Members... m) {
19581965
return handler->Call(call_frame); \
19591966
}
19601967

1961-
#define XLA_FFI_DEFINE_HANDLER_EXPLICIT_WITH_TRAITS(fn, impl, binding, traits) \
1962-
static constexpr XLA_FFI_Handler* fn = +[](XLA_FFI_CallFrame* call_frame) { \
1963-
static auto* handler = binding.To(impl, traits).release(); \
1964-
return handler->Call(call_frame); \
1965-
}
1966-
19671968
// Automatically infer binding specification from the implementation.
19681969
#define XLA_FFI_DEFINE_HANDLER_AUTO(fn, impl) \
19691970
static constexpr XLA_FFI_Handler* fn = +[](XLA_FFI_CallFrame* call_frame) { \
@@ -1978,11 +1979,11 @@ auto DictionaryDecoder(Members... m) {
19781979
//
19791980
// This is a trick to define macro with optional parameters.
19801981
// Source: https://stackoverflow.com/a/8814003
1981-
#define XLA_FFI_DEFINE_HANDLER(fn, impl, ...) \
1982-
XLA_FFI_DEFINE_HANDLER_X( \
1983-
, fn, impl, ##__VA_ARGS__, \
1984-
XLA_FFI_DEFINE_HANDLER_EXPLICIT_WITH_TRAITS(fn, impl, __VA_ARGS__), \
1985-
XLA_FFI_DEFINE_HANDLER_EXPLICIT(fn, impl, __VA_ARGS__), \
1982+
#define XLA_FFI_DEFINE_HANDLER(fn, impl, ...) \
1983+
XLA_FFI_DEFINE_HANDLER_X( \
1984+
, fn, impl, ##__VA_ARGS__, \
1985+
XLA_FFI_DEFINE_HANDLER_EXPLICIT_WITH_TRAITS(fn, impl, ##__VA_ARGS__), \
1986+
XLA_FFI_DEFINE_HANDLER_EXPLICIT(fn, impl, ##__VA_ARGS__), \
19861987
XLA_FFI_DEFINE_HANDLER_AUTO(fn, impl))
19871988

19881989
// TODO(ezhulenev): Add a callback so that end users can log registration error

xla/ffi/api/ffi.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,8 +1480,7 @@ XLA_FFI_TypeInfo TypeInfo() {
14801480
return ::xla::ffi::Ffi::RegisterTypeId(API, NAME, TYPE_ID, TYPE_INFO); \
14811481
}()
14821482

1483-
#define XLA_FFI_REGISTER_TYPE_X(x, API, NAME, TYPE_ID, TYPE_INFO, FUNC, ...) \
1484-
FUNC
1483+
#define XLA_FFI_REGISTER_TYPE_X(x, API, NAME, TYPE_ID, TYPE_INFO, FUNC) FUNC
14851484

14861485
// Registers external type with XLA runtime and assigns it a unique type id.
14871486
//

0 commit comments

Comments
 (0)