Skip to content

Fix -Werror diagnostics in vendored runtime and kernel sources - #24702

Merged
rascani merged 1 commit into
cadence-typing-extensions-overridefrom
esp-idf-log-format
Nov 9, 2026
Merged

rascani merged 1 commit into
cadence-typing-extensions-overridefrom
esp-idf-log-format

Conversation

@rascani

@rascani rascani commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

On toolchains where int32_t and uint32_t are long (the Xtensa and RISC-V
ESP-IDF toolchains, and arm-none-eabi-gcc), log and check messages that pass
them to %d or %u trip -Wformat. ESP-IDF builds with -Werror, so its component
currently compiles the vendored ExecuTorch sources with a blanket -Wno-error;
these fixes let the next change narrow that.

The runtime, flat_tensor and portable kernel sources now use PRId32/PRIu32, or
cast to int where the rest of a message already does. ET_PRI_SIZES_AND_STRIDES,
the format for elements of sizes() and strides(), was "d" in lean mode, which is
wrong for int32_t on these toolchains, so its users such as extension/tensor's
tensor_ptr.cpp failed -Werror=format there. It is now PRId32, which is "d"
wherever int32_t is int. The size and stride messages in op_fft_r2c and in the
ET_CHECK_CONTIGUOUS and ET_CHECK_SAME_STRIDES macros of tensor_util.h use it,
so the STRIDES macros no longer truncate ATen-mode strides to int32_t, and those
macros loop over and print dimensions as size_t, which kernels outside this
tree also get.

Other diagnostics that ESP-IDF turns into errors are fixed in the same sources:
an always-true index >= 0 on a uint32_t in flat_tensor, a cast to a
const-qualified type in native_dropout, prod's *= on bool outputs
(-Wint-in-bool-context), missing parentheses in ET_CHECK_SAME_SHAPE3, and
always_inline on non-inline templates in the Cadence generic im2row operators,
which now use ET_INLINE. prod's bool product, in both prod_out and prod_int_out,
is now && through a template helper, because if constexpr only discards a
branch inside a template; results are unchanged for every dtype.

Verified by compiling every vendored runtime and kernel source (281) as the
generated component builds them for esp32s3 and esp32c6, under ESP-IDF 6.1's
-Wall -Werror, at both -Os and -Og; by compiling extension/tensor/tensor_ptr.cpp
and the tensor_util.h check macros with both ESP-IDF toolchains under
-Werror=format and on host in ATen mode; and by running the component's
emulator tests. On host, portable_kernels_test and the exec_aten util tests
pass.

Authored with Claude Code.

@pytorch-bot

pytorch-bot Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/24702

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 95cef92 with merge base 4411b8d (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 5, 2026
@rascani
rascani added this pull request to stack #24713 November 5, 2026 23:48
@rascani
rascani requested a review from JakeStevens November 6, 2026 17:55
@rascani
rascani marked this pull request as ready for review November 6, 2026 17:55
@rascani
rascani force-pushed the esp-idf-log-format branch from f7f85f7 to df8386b Compare November 6, 2026 20:40
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@JakeStevens JakeStevens left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for cleaning these up! A few things I'd like changed before this lands.

Use ET_PRI_SIZES_AND_STRIDES for sizes/strides instead of per-site casts

There's already a format specifier for SizesType/StridesType elements. It's documented as "must be used instead of using d directly to support ATen mode", but in lean mode it's still "d" (runtime/core/portable_type/tensor_impl.h:337). That makes it wrong on exactly the toolchains this PR targets. Instead of fixing it, the PR casts at each call site, two different ways in the same header:

  • ET_CHECK_CONTIGUOUS and op_fft_r2c.cpp: static_cast<int64_t> + PRId64
  • ET_CHECK_SAME_STRIDES2/3: (int32_t) + PRId32. In ATen mode this truncates int64_t strides, while the macro just above prints the same type at full width.

The macro's existing users are still broken. At this PR's head, extension/tensor/tensor_ptr.cpp:106-108 fails -Werror=format with 3 errors under ESP-IDF GCC 15.2 (xtensa-esp32s3-elf-g++ and riscv32-esp-elf-g++). extension/wasm/wasm_bindings.cpp:171-173 uses the same pattern. extension/tensor isn't vendored into the IDF component, but your out-of-tree argument for tensor_util.h applies to it too.

Suggested fix:

// runtime/core/portable_type/tensor_impl.h
#include <cinttypes>
...
#define ET_PRI_SIZES_AND_STRIDES PRId32

Then use "%" ET_PRI_SIZES_AND_STRIDES with no casts at the four sites. strides[i] * sizes[i] has the element type in both modes, so it fits too. Where int32_t is int, PRId32 is "d", so host builds don't change. With this change, tensor_ptr.cpp and the rewritten macro messages compile cleanly under -Werror=format on both IDF toolchains and on host clang.

Smaller things

  • tensor_util.h:286-290, 319-325: the STRIDES2/3 loop index now prints with ET_PRIsize_t, but i comes from c10::irange(a__.dim()), so it's ssize_t in lean mode and int64_t in ATen mode. The first check in each macro (:276, :306) also still passes dim() to %zu. In ATen mode wherever int64_t is long long (e.g. macOS), plain -Wformat flags both. To fix, loop with size_t as ET_CHECK_CONTIGUOUS does, and print dim() as a size_t as ET_CHECK_SAME_SHAPE3 does.

  • The %zu → ET_PRIsize_t edits don't affect -Werror, since %zu with a size_t is already clean on all the GCC targets named. They do leave the touched functions mixed:

    • flat_tensor_data_map.cpp:359 prints flat_tensor_data->size() with %zu, 14 lines above :373, which prints the same value with ET_PRIsize_t.
    • tensor_parser_exec_aten.cpp:115 sits between the two edited checks.
    • ET_CHECK_SAME_SHAPE3's message (tensor_util.h:108) still uses %zu.

    I'd either convert the touched functions fully or leave the Cadence %zu migration to its own change.

  • op_prod.cpp:105: prod_int_out still computes the bool product as acc * outv, and only prod_out uses multiply(). It avoids the warning only because the conversion happens inside std::tuple's constructor. Using multiply(acc, outv) there would keep one spelling in the file.

  • op_im2row.cpp:13-17 / op_transposed_im2row.cpp:16-20: the patched local ALWAYS_INLINE is now the same as ET_INLINE (runtime/platform/compiler.h:91-94, which also covers MSVC). Nothing defines DISABLE_ALWAYS_INLINE, so both blocks could be replaced with ET_INLINE.

@rascani

rascani commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Thanks Jake — all addressed in e8c8420:

  • ET_PRI_SIZES_AND_STRIDES is now PRId32 in lean mode (with <cinttypes>), and ET_CHECK_CONTIGUOUS, ET_CHECK_SAME_STRIDES2/3 and op_fft_r2c use it with no casts. tensor_ptr.cpp now compiles cleanly under -Werror=format with both IDF toolchains. It reproduced your 3 errors on each toolchain before the change.
  • The STRIDES macros loop over size_t and print dim() as size_t, like ET_CHECK_SAME_SHAPE3. A host ATen-mode compile with -Wformat-signedness flagged 10 diagnostics before the change and none after.
  • I dropped the %zu → ET_PRIsize_t migration and left it for its own change, so the touched functions are consistent again.
  • prod_int_out uses multiply(), and the im2row operators use ET_INLINE.

@rascani
rascani force-pushed the esp-idf-log-format branch from e8c8420 to 9642c76 Compare November 9, 2026 17:32
On toolchains where int32_t and uint32_t are long (the Xtensa and RISC-V
ESP-IDF toolchains, and arm-none-eabi-gcc), log and check messages that pass
them to %d or %u trip -Wformat. ESP-IDF builds with -Werror, so its component
currently compiles the vendored ExecuTorch sources with a blanket -Wno-error;
these fixes let the next change narrow that.

The runtime, flat_tensor and portable kernel sources now use PRId32/PRIu32, or
cast to int where the rest of a message already does. ET_PRI_SIZES_AND_STRIDES,
the format for elements of sizes() and strides(), was "d" in lean mode, which is
wrong for int32_t on these toolchains, so its users such as extension/tensor's
tensor_ptr.cpp failed -Werror=format there. It is now PRId32, which is "d"
wherever int32_t is int. The size and stride messages in op_fft_r2c and in the
ET_CHECK_CONTIGUOUS and ET_CHECK_SAME_STRIDES macros of tensor_util.h use it,
so the STRIDES macros no longer truncate ATen-mode strides to int32_t, and those
macros loop over and print dimensions as size_t, which kernels outside this
tree also get.

Other diagnostics that ESP-IDF turns into errors are fixed in the same sources:
an always-true `index >= 0` on a uint32_t in flat_tensor, a cast to a
const-qualified type in native_dropout, prod's `*=` on bool outputs
(-Wint-in-bool-context), missing parentheses in ET_CHECK_SAME_SHAPE3, and
always_inline on non-inline templates in the Cadence generic im2row operators,
which now use ET_INLINE. prod's bool product, in both prod_out and prod_int_out,
is now `&&` through a template helper, because `if constexpr` only discards a
branch inside a template; results are unchanged for every dtype.

Verified by compiling every vendored runtime and kernel source (281) as the
generated component builds them for esp32s3 and esp32c6, under ESP-IDF 6.1's
-Wall -Werror, at both -Os and -Og; by compiling extension/tensor/tensor_ptr.cpp
and the tensor_util.h check macros with both ESP-IDF toolchains under
-Werror=format and on host in ATen mode; and by running the component's
emulator tests. On host, portable_kernels_test and the exec_aten util tests
pass.

Authored with Claude Code.
@rascani
rascani force-pushed the esp-idf-log-format branch from 9642c76 to 95cef92 Compare November 9, 2026 18:37
@rascani
rascani merged commit 3a9d181 into main Nov 9, 2026
265 checks passed
@rascani
rascani deleted the esp-idf-log-format branch November 9, 2026 21:06

This branch was previously deployed

1 inactive deployment
cadence — 95cef92e Deployed Nov 9, 2026 by rascani via hifi-op-test / hifi4 #37402
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants