Fix nullable-to-nonnull conversion warnings in ExecuTorchModule#19462
Fix nullable-to-nonnull conversion warnings in ExecuTorchModule#19462FieryRobot wants to merge 1 commit into
Conversation
Summary: ## Motivation We have a build failure because the Xcode staging toolchain (clang19) treats `-Wnullable-to-nonnull-conversion` as an error. `NSString.UTF8String` is declared as returning `const char * _Nullable`, but ExecuTorch's C++ Module methods expect `const char * _Nonnull`. The production toolchain doesn't flag this, but the staging toolchain does, blocking the affected build. ## This Diff Adds a `safeUTF8String()` helper that returns `string.UTF8String ?: ""` — falling back to an empty string if UTF8String ever returns nil. Applied to all 8 call sites in ExecuTorchModule.mm. Alternatives considered: - **Explicit nil check + error return at each site**: Safest, but adds 5+ lines of boilerplate at each of 8 sites. Overkill given UTF8String on a valid NSString essentially never returns nil. - **Cast to _Nonnull**: Simpler one-liner but crashes with undefined behavior if UTF8String ever did return nil. - **`#pragma clang diagnostic ignored`**: Suppresses the warning but doesn't fix the underlying issue. The `?: ""` approach was chosen because: it won't crash (empty string is valid), ExecuTorch will return a "method not found" error which existing error handling already surfaces, and the nil case is essentially impossible for ASCII method name strings. The only downside is a slightly misleading error message in the astronomically unlikely failure case. Differential Revision: D104697173
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/19462
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 Awaiting Approval, 1 New FailureAs of commit 8002ef0 with merge base 126507c ( AWAITING APPROVAL - The following workflow needs approval before CI can run:
NEW FAILURE - The following job has failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@FieryRobot has exported this pull request. If you are a Meta employee, you can view the originating Diff in D104697173. |
This PR needs a
|
Summary:
Motivation
We have a build failure because the Xcode staging toolchain (clang19) treats
-Wnullable-to-nonnull-conversionas an error.NSString.UTF8Stringis declared as returningconst char * _Nullable, but ExecuTorch's C++ Module methods expectconst char * _Nonnull. The production toolchain doesn't flag this, but the staging toolchain does, blocking the affected build.This Diff
Adds a
safeUTF8String()helper that returnsstring.UTF8String ?: ""— falling back to an empty string if UTF8String ever returns nil. Applied to all 8 call sites in ExecuTorchModule.mm.Alternatives considered:
#pragma clang diagnostic ignored: Suppresses the warning but doesn't fix the underlying issue.The
?: ""approach was chosen because: it won't crash (empty string is valid), ExecuTorch will return a "method not found" error which existing error handling already surfaces, and the nil case is essentially impossible for ASCII method name strings. The only downside is a slightly misleading error message in the astronomically unlikely failure case.Differential Revision: D104697173