GBE: Fix a constant bug which over-write memory.
authorRuiling Song <ruiling.song@intel.com>
Tue, 24 Sep 2013 07:39:36 +0000 (15:39 +0800)
committerZhigang Gong <zhigang.gong@linux.intel.com>
Wed, 25 Sep 2013 11:08:10 +0000 (19:08 +0800)
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@intel.com>
Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
backend/src/llvm/llvm_gen_backend.cpp

index 5284ce5..224c971 100644 (file)
@@ -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: