Use of the restrict type qualifier

ID

objectivec.maintainability.avoid_restrict

Severity

info

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Type Safety

Language

Objective-C

Description

Reports a use of the restrict type qualifier, including its restrict and restrict__ spellings.

Rationale

restrict is a promise to the optimizer, not a checked constraint: it asserts that nothing else in scope reaches the same storage, and the compiler is entitled to reorder and vectorise on that basis without ever verifying it. Break the promise and the result is undefined behaviour that appears only in an optimized build, on one architecture, as wrong data rather than a crash. The promise also binds every caller while being invisible at each call site, and in Objective-C it is rarely defensible on an object pointer at all, since any method the callee invokes may retain the object and reach the same storage through another reference.

The following code illustrates the pattern detected by this rule:

// FLAGGED: Use of the restrict type qualifier
static void blendRows(float * restrict destination, const float * restrict source, size_t count) {
    for (size_t i = 0; i < count; i++) {
        destination[i] += source[i];
    }
}

Remediation

Remove the qualifier; the loss of a few vectorisation opportunities is cheap next to a miscompiled buffer. If the aliasing guarantee really is load-bearing for performance, establish it structurally instead - have the function own or copy the buffer it writes, or take a single buffer plus an offset - and confirm the gain by measurement.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved