cyx-6 opened a new pull request, #632:
URL: https://github.com/apache/tvm-ffi/pull/632

   ## Problem
   
   The macOS clang CI job on `main` fails to compile with `-Werror`:
   
   ```
   include/tvm/ffi/extra/structural_visit.h:575:29: error: the argument to
   '__builtin_assume' has side effects that will be discarded [-Werror,-Wassume]
       TVM_FFI_UNSAFE_ASSUME(result.type_index() == TypeIndex::kTVMFFIInt);
   ```
   
   ## Root cause
   
   clang's `__builtin_assume` discards its argument's side effects, so 
`-Wassume` rejects any argument that **contains a call expression** — this is a 
purely syntactic check, independent of whether the call is actually pure.
   
   This is a regression from #629, which inlined `result.type_index()` directly 
into `TVM_FFI_UNSAFE_ASSUME` to silence `-Wunused-variable`. The two warnings 
pull in opposite directions:
   
   | | `-Wunused-variable` | `-Wassume` |
   |---|---|---|
   | pre-#629 (local var) | ❌ (when assume macro is a no-op) | ✅ |
   | #629 (inlined call) | ✅ | ❌ ← CI fails |
   | this PR | ✅ | ✅ |
   
   Note `result` here is a C++ `Expected`, so `result.type_index()` is a 
**method call**. The other 10 `TVM_FFI_UNSAFE_ASSUME` sites in the tree operate 
on the raw `TVMFFIAny` C struct via the plain field `src->type_index`, which 
contains no call expression and is therefore unaffected. This was the only 
call-expression assume site in the codebase.
   
   ## Fix
   
   Hoist the call back into a local and mark it `[[maybe_unused]]`:
   
   ```cpp
   [[maybe_unused]] int32_t type_index = result.type_index();
   TVM_FFI_UNSAFE_ASSUME(type_index == TypeIndex::kTVMFFIInt);
   ```
   
   - The assume argument is now a plain variable read → satisfies `-Wassume`.
   - `[[maybe_unused]]` keeps `-Wunused-variable` quiet on configs where the 
assume macro compiles away to a no-op → satisfies what #629 was originally 
fixing.
   
   ## Validation
   
   - `clang++ -std=c++17 -Werror -Wassume -fsyntax-only 
src/ffi/extra/structural_visit.cc` (Homebrew clang 22): **passes** after the 
change, **fails** before it (reproduces the CI error).
   - Confirmed `[[maybe_unused]]` suppresses `-Wunused-variable` when the 
assume macro expands to a no-op.
   - `clang-format` clean; lines within the 100-col limit.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to