[Beignet] [PATCH] GBE: Fix a constant bug which over-write memory.

Zhigang Gong zhigang.gong at linux.intel.com
Wed Sep 25 01:16:41 PDT 2013


LGTM, will push it latter.
Thanks.

On Tue, Sep 24, 2013 at 03:39:36PM +0800, Ruiling Song wrote:
> Previously it will always write 8 byte no matter what size of integer.
> Fix it by only copying necessary data.
> 
> Reported by Homer Hsing.
> 
> Signed-off-by: Ruiling Song <ruiling.song at intel.com>
> ---
>  backend/src/llvm/llvm_gen_backend.cpp |    6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp
> index 5284ce5..224c971 100644
> --- a/backend/src/llvm/llvm_gen_backend.cpp
> +++ b/backend/src/llvm/llvm_gen_backend.cpp
> @@ -631,8 +631,10 @@ namespace gbe
>        case Type::TypeID::IntegerTyID:
>          {
>            const ConstantInt *ci = dyn_cast<ConstantInt>(c);
> -          *(uint64_t *)((char*)mem + offset) = ci->isNegative() ? ci->getSExtValue() : ci->getZExtValue();
> -          offset += ci->getBitWidth() / 8;
> +          uint32_t size = ci->getBitWidth() / 8;
> +          uint64_t data = ci->isNegative() ? ci->getSExtValue() : ci->getZExtValue();
> +          memcpy((char*)mem+offset, &data, size);
> +          offset += size;
>            break;
>          }
>        case Type::TypeID::FloatTyID:
> -- 
> 1.7.9.5
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list