Page MenuHomePhabricator

Please use GitHub pull requests for new patches. Phabricator shutdown timeline

[Clang] Allow __declspec(noalias) to access inaccessible memory

Authored by nikic on Mon, Aug 28, 6:41 AM.



MSVC defines __declspec(noalias) as follows (

noalias means that a function call does not modify or reference visible global state and only modifies the memory pointed to directly by pointer parameters (first-level indirections).

If a function is annotated as noalias, the optimizer can assume that, in addition to the parameters themselves, only first-level indirections of pointer parameters are referenced or modified inside the function. The visible global state is the set of all data that is not defined or referenced outside of the compilation scope, and their address is not taken. The compilation scope is all source files (/LTCG (Link-time Code Generation) builds) or a single source file (non-/LTCG build).

The wording is not super clear to me, but I believe this is saying that __declspec(noalias) functions may access inaccessible memory (i.e. non-visible global state in their words). Indeed, the Windows CRT applies this attribute to malloc, which does access inaccessible memory under LLVM's memory model.

As such, change the attribute to emit memory(argmem: readwrite, inaccessiblemem: readwrite) instead of memory(argmem: readwrite).


Diff Detail

Event Timeline

nikic created this revision.Mon, Aug 28, 6:41 AM
nikic requested review of this revision.Mon, Aug 28, 6:41 AM
rnk accepted this revision.Mon, Aug 28, 2:46 PM


This revision is now accepted and ready to land.Mon, Aug 28, 2:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptTue, Aug 29, 2:44 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript