Skip to content

Fix sign-compare warnings under xlog backend#620

Open
afrind wants to merge 4 commits into
facebook:mainfrom
afrind:export-D106960646
Open

Fix sign-compare warnings under xlog backend#620
afrind wants to merge 4 commits into
facebook:mainfrom
afrind:export-D106960646

Conversation

@afrind
Copy link
Copy Markdown
Contributor

@afrind afrind commented May 31, 2026

Summary:
folly's XCHECK_OP (and the XCHECK_GT/XCHECK_EQ/... family) wraps the comparison in a lambda that expands inline at the call site. That makes the user's TU responsible for -Wsign-compare. glog's CHECK_OP puts the same comparison inside a function template defined in glog's headers, which are typically -isystem-included so the warning is suppressed for glog's own code — the legacy CHECK_GT(unsigned_thing, 0) pattern was always actually sign-mismatched, glog just hid it.

Switching proxygen's PRX_CHECK_OP family to xlog under proxygen.logging_backend=xlog therefore surfaces ~100 latent mismatches. Each one is the same shape: an unsigned LHS (size_t, uint32_t, uint64_t, etc.) compared against a signed integer literal. Fix them all at the call site by giving the literal a u suffix (or, for numeric_limits<int64_t>::max(), cast to the LHS's size_t). Matches moxygen's xlog convention.

Also marks two inline operator<< helpers in WtStreamManager.cpp as [[maybe_unused]]. glog's CHECK_EQ references them for failure-diff formatting; xlog's XCHECK_EQ does not, so -Wunused-function fires under xlog. The attribute keeps them available for glog without warning under xlog.

Differential Revision: D106960646

afrind and others added 4 commits May 30, 2026 16:07
Summary:
folly's `Compression.cpp` `dynamic_cast`s `snappy::Source` / `snappy::Sink`, which requires their typeinfo symbols. The snappy revision pinned in our manifest (`27ab5f7f...`) hardcodes `-fno-rtti` in `CMAKE_CXX_FLAGS` and even strips any `-frtti` we try to inject, so `libsnappy.so` ships without typeinfo for those polymorphic bases. Any downstream that actually pulls in folly's Snappy codec (proxygen, mvfst, folly's own `compression_compression_test` which is gated behind `BUILD_SLOW_TESTS`) fails to link with:

  undefined reference to `typeinfo for snappy::Source'

Override via `CMAKE_CXX_FLAGS_<CONFIG>`, which CMake appends after `CMAKE_CXX_FLAGS` and snappy doesn't touch — the trailing `-frtti` wins over the earlier `-fno-rtti` in gcc.

Differential Revision: D106941114
Summary:
Introduces `proxygen/lib/utils/LogShim.h`, a header-only macro layer that lets downstream builds choose at compile time which backend services log emission:

- `PRX_LOGGING_GLOG=1` (default) — glog via `<folly/GLog.h>`. Behavior identical to today for files that previously used `LOG`/`CHECK`; behavior change for files that previously used `XLOG`/`XCHECK` (lose folly category-based runtime filtering and folly's formatter-based ostream).
- `PRX_LOGGING_XLOG=1` — folly::xlog via `<folly/logging/xlog.h>`. Routes through folly's category tree.
- `PRX_LOGGING_DISABLED=1` — fully stripped. `PRX_CHECK` -> `if (!e) abort()`, `PRX_DCHECK` -> `assert(e)`, log streams become a noop sink.

The pattern mirrors `fizz/util/Logging.h` and the wangle shim in D106528033. The default is glog because every existing wangle/fizz call site uses glog today; opting in to xlog or noop lets OSS users ship without a glog dependency. Proxygen had a mix of `LOG`/`CHECK` (older code) and `XLOG`/`XCHECK` (newer `lib/http/coro/`, `lib/transport/qmux/`, `lib/http/webtransport/`, `lib/http/sink/`); both families are routed through the unified `PRX_*` set so the backend choice applies everywhere.

All ~370 OSS call sites converted to the `PRX_*` macros via codemod. Scope is OSS dirs only — `proxygen/lib`, `proxygen/httpserver`, `proxygen/httpclient`, `proxygen/external`, `proxygen/fuzzers`, `proxygen/public_tld`. `proxygen/facebook/` is untouched except for one missing `#include <folly/logging/xlog.h>` in `HostResources.h` that was previously satisfied transitively.

The codemod also normalized xlog-vocab levels to glog vocab inside `PRX_*` calls so the GLOG backend resolves the tokens: `PRX_LOG(ERR)` -> `PRX_LOG(ERROR)`, `PRX_LOG(DBG<n>)` -> `PRX_VLOG(<n>)` (and the same for `*_IF`, `*_EVERY_MS`, `*_EVERY_N`).

A handful of hand fixes for behavioral differences between folly's xlog and glog's LOG:
- Replaced three `XLOG_FILENAME` use sites with `__FILE__` (xlog-only macro).
- Added `operator<<` for `HTTPStreamSource::ReadState` (inline friend), `WriteHandleState`, and `ReadHandleState` (in WtStreamManager.cpp anonymous namespace) so `PRX_CHECK_{EQ,NE}` of those enums compiles under glog's `MakeCheckOpString`.
- Switched `PRX_CHECK_NE(it, deque.end())` to `PRX_CHECK(it != deque.end())` since `std::_Deque_iterator` has no `operator<<`.
- Replaced five `PRX_LOG(FATAL) << "..."; return X;` in `HTTPSourceTests.cpp` lambdas with `ADD_FAILURE() << "..."; return X;` — glog's `LOG(FATAL)` is `[[noreturn]]` which made the trailing return dead code under `-Werror=unreachable-code-return`.
- Removed one dead `return ""` after `PRX_LOG(FATAL)` in a switch default in `HTTPCoroSessionTests.cpp`.

CMake/getdeps integration mirrors the BUCK story: top-level `proxygen/public_tld/CMakeLists.txt` exposes `PROXYGEN_LOGGING_BACKEND` (`GLOG`/`XLOG`/`DISABLED`, default `GLOG`) and conditionally `find_package`s glog, generates `<proxygen/proxygen-config.h>` from `proxygen/lib/utils/proxygen-config.h.in`, and narrows `proxygen_utils_log_shim`'s `INTERFACE_LINK_LIBRARIES` per backend. Per-subdir `CMakeLists.txt` regenerated by `proxygen/facebook/generate_cmake.py`. Manually-maintained CMake files (`httpserver/CMakeLists.txt`, `httpserver/samples/hq/CMakeLists.txt`, `httpserver/samples/hq/devious/CMakeLists.txt`) got `proxygen_utils_log_shim` added by hand.

Buck: new `:config` (header_namespace="" remap of `<proxygen/proxygen-config.h>` to the appropriate per-build variant in `lib/utils/facebook/`) and `:log_shim` `cpp_library` targets in `proxygen/lib/utils/TARGETS`. AUTODEPS added `:log_shim` to consumers; matching `:proxygen_config` and `:proxygen_lib_utils_log_shim` `fb_xplat_cxx_library` targets added to `xplat/proxygen/BUCK`, plus `:proxygen_lib_utils_log_shim` propagated to every `fb_xplat_cxx_library`/`fb_xplat_cxx_test` in that file.

`PRX_PCHECK` loses the `: <strerror(errno)>` suffix in xlog and disabled modes; TODO to fix once folly exposes `XPCHECK`.

Differential Revision: D106960643
Summary:
`PRX_VLOG(n)` requires `n` to be a literal so the token-paste path (`PRX_LOGGING_DBG_##n` → `DBG0..DBG9`) hits XLOG's fast static-cached check. Callers that pass a runtime int (e.g. `PRX_VLOG(level)` where `level` is a parameter) can't use that form under the xlog backend — folly's `XLOG()` requires a compile-time `folly::LogLevel` (the level is used in a template non-type argument for `LogStreamVoidify<isLogLevelFatal(level)>`).

Add `PRX_VLOG_LEVEL(n)` / `PRX_DVLOG_LEVEL(n)` for those callers. Under xlog the implementation routes through `FB_LOG_RAW` with a per-call-site cached `folly::Logger` (a static inside a non-capturing IIFE), so the category lookup happens once per call site rather than once per call. Under glog and disabled backends these are aliases for `VLOG`/`PRX_VLOG`.

The compile-time `PRX_VLOG(literal_n)` path is unchanged — same fast XLOG static-cached check as before. No runtime cost added for the common case.

Convert the three known runtime-`n` call sites:
- `proxygen/lib/http/HTTPMessage.cpp` — `dumpMessage(int vlogLevel)`
- `proxygen/lib/http/coro/filters/Logger.cpp` — `logWithVlog(int level)`
- `proxygen/lib/http/codec/test/TestUtils.h` — `dumpCounters(int verbosity)` (27 sites)

Differential Revision: D106960645
Summary:
folly's `XCHECK_OP` (and the `XCHECK_GT`/`XCHECK_EQ`/... family) wraps the comparison in a lambda that expands inline at the call site. That makes the user's TU responsible for `-Wsign-compare`. glog's `CHECK_OP` puts the same comparison inside a function template defined in glog's headers, which are typically `-isystem`-included so the warning is suppressed for glog's own code — the legacy `CHECK_GT(unsigned_thing, 0)` pattern was always actually sign-mismatched, glog just hid it.

Switching proxygen's `PRX_CHECK_OP` family to xlog under `proxygen.logging_backend=xlog` therefore surfaces ~100 latent mismatches. Each one is the same shape: an unsigned LHS (`size_t`, `uint32_t`, `uint64_t`, etc.) compared against a signed integer literal. Fix them all at the call site by giving the literal a `u` suffix (or, for `numeric_limits<int64_t>::max()`, cast to the LHS's `size_t`). Matches moxygen's xlog convention.

Also marks two `inline operator<<` helpers in `WtStreamManager.cpp` as `[[maybe_unused]]`. glog's `CHECK_EQ` references them for failure-diff formatting; xlog's `XCHECK_EQ` does not, so `-Wunused-function` fires under xlog. The attribute keeps them available for glog without warning under xlog.

Differential Revision: D106960646
@meta-cla meta-cla Bot added the CLA Signed label May 31, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync Bot commented May 31, 2026

@afrind has exported this pull request. If you are a Meta employee, you can view the originating Diff in D106960646.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant