Skip to content

COMP: Scope the -Wallocator-wrappers suppression and document when to suppress - #7231

Merged
hjmjohnson merged 2 commits into
InsightSoftwareConsortium:mainfrom
hjmjohnson:comp-allocator-wrappers-suppression
Nov 27, 2026
Merged

hjmjohnson merged 2 commits into
InsightSoftwareConsortium:mainfrom
hjmjohnson:comp-allocator-wrappers-suppression

Conversation

@hjmjohnson

Copy link
Copy Markdown
Member

Clear AppleClang's -Wallocator-wrappers false positive on ImportImageContainer::AllocateElements with a suppression scoped to that one definition, and document when ITK accepts a warning suppression. Complements #7228.
Merge danger: two-way door; blast radius is AppleClang warning output only, with no API or behavior change.

Shape of the change
itkMacro.h                    + ITK_CLANG_SUPPRESS_Wallocator_wrappers   (behind __has_warning)
.clang-format                 + StatementMacros entry for the new macro
itkImportImageContainer.hxx     ITK_CLANG_PRAGMA_PUSH / SUPPRESS / POP around AllocateElements only
compiler-cautions.md          + §17 When a Warning May Be Suppressed (this case as the worked example)
Why a suppression, and why only here

-Wallocator-wrappers is part of Apple's typed memory operations and is not in upstream LLVM. Probing with ITK's own compile line shows it fires on a function whose name contains "alloc" and that returns a byte-typed pointer (void *, char *, unsigned char *, signed char *) taken from an allocation. AllocateElements matches only for unsigned char and signed char pixels; new TElement[n] is already typed, so this is a false positive.

Code changes that avoid it were tested: std::make_unique<T[]>(n).release() and catching only std::bad_alloc still warn. Returning std::unique_ptr<TElement[]> does not warn, but AllocateElements is a protected virtual that subclasses override (for example BlueQuartz SIMPL's itkImportDream3DImageContainer), so that is an API change, left for a later release. The suppression names it as the removal condition.

The same warning on vendored Eigen, VNL (vnl_sse_alloc), and PocketFFT wrappers is genuine type erasure and is left for upstream fixes. A project-wide -Wno-allocator-wrappers was dropped from #7228 because it fixed nothing and would hide future cases in ITK code.

Reference: Adopting type-aware memory allocation.

Evidence

AppleClang 21, itkImageGTest.cxx compiled with its build command plus -Wallocator-wrappers:

before: 8 distinct functions flagged, including AllocateElements
after:  7 distinct (Eigen x6, vnl_sse_alloc); AllocateElements gone

ITKCommonGTestDriver and ITKCommon1TestDriver build; 12 of 12 related tests pass (ImportImageContainer, Image.*, itkImageTest, itkImportImageTest, VectorImage). pre-commit run --all-files passes.

Not tested: the Mac26 AppleClang TSan nightly itself.

AI assistance
  • Tool: Claude Code (claude-opus-5-5)
  • Role: reduced the warning to its trigger, tested alternative rewrites, wrote the suppression and the guidance
  • Reviewed and tested locally before committing

…Elements

AppleClang flags functions named "alloc" that return a byte-typed pointer
from an allocation. For unsigned char and signed char pixels,
AllocateElements matches, but new TElement[n] is already typed, so the
warning is a false positive. Returning std::unique_ptr<TElement[]> would
avoid it, but AllocateElements is a protected virtual that subclasses
override, so the definition alone is wrapped in a new
ITK_CLANG_SUPPRESS_Wallocator_wrappers, guarded by __has_warning and
listed in .clang-format StatementMacros.

The same warning on vendored Eigen, VNL, and PocketFFT wrappers is left
for upstream fixes.
Add compiler-cautions.md section 17: a suppression needs a confirmed
false positive or code ITK cannot change, the narrowest scope, a
one-line reason at the site, and a removal condition. The
-Wallocator-wrappers case on AllocateElements is the worked example,
including why a project-wide -Wno- flag was rejected.
@github-actions github-actions Bot added type:Compiler Compiler support or related warnings area:Core Issues affecting the Core module area:Documentation Issues affecting the Documentation module labels Nov 23, 2026
@hjmjohnson
hjmjohnson marked this pull request as ready for review November 23, 2026 21:11
@greptile-apps

greptile-apps Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge.

Summary

Scopes -Wallocator-wrappers suppression to ImportImageContainer::AllocateElements without changing its signature or body.

  • AppleClang skips the allocator warning for one typed image allocation.

Reviews (1) · Last reviewed commit: "DOC: State when a compiler warning may b..." · Reviewed by Greptile

@hjmjohnson
hjmjohnson requested a review from dzenanz November 27, 2026 18:47
@hjmjohnson
hjmjohnson merged commit f10a76e into InsightSoftwareConsortium:main Nov 27, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Core Issues affecting the Core module area:Documentation Issues affecting the Documentation module type:Compiler Compiler support or related warnings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants