KhronosGroup/webcl-validator — pull request #57 by eras (2013-12-11 15:41:41+00:00)
Title: Sampler safety

Implements safe forwarding of sampler_t arguments. Most of the functionality described below was implemented for passing image2d_t as an argument to read_image, but this change set extends the same abilities combined with the constant integer expression checking to sampler_t.

Safe forwarding in this context means:

When a function with a parameter of type sampler_t is called, the called argument must be either

1) an argument of the calling function without any manipulations (implicit casting node is accepted)

2) an integer constant expression, which is deconstructed and reconstructed with bitwise or operations using the WebCL CLK_* enumerations

3) This check is performed also when the calling argument is of type sampler_t and is implicitly casted to be something else. This probably isn't strictly necessary, but it's there.

4) Also the use of sampler_t-typed values is limited: whenever they are used in an expression, they must be used directly as a function argument. This prohibits the user from taking the address of a sampler_t value and modifying it that way. Also when a pointer of sampler_t is never taken the value will not be placed on the address space structs, preventing the user from excessing the bounds of other values and accessing them in that way.

One can construct sampler_t values and use the enumerations in any way (which are integers at this level anyway), but it is impossible to pass these self-made sampler_t values to a function as an argument.

The last patch of this set addresses bug #43 by prohibiting CLK_ADDRESS_NONE. (Obviously no such limitation can be performed on a sampler_t that flows from the kernel function.)