diff --git a/expr.cpp b/expr.cpp index 81f51151..2ad7a495 100644 --- a/expr.cpp +++ b/expr.cpp @@ -643,13 +643,17 @@ InitSymbol(llvm::Value *ptr, const Type *symType, Expr *initExpr, return; } - llvm::Value *constPtr = - new llvm::GlobalVariable(*m->module, llvmType, true /* const */, - llvm::GlobalValue::InternalLinkage, - constValue, "const_initializer"); - llvm::Value *size = g->target.SizeOf(llvmType, - ctx->GetCurrentBasicBlock()); - ctx->MemcpyInst(ptr, constPtr, size); + if (Type::IsBasicType(symType)) + ctx->StoreInst(constValue, ptr); + else { + llvm::Value *constPtr = + new llvm::GlobalVariable(*m->module, llvmType, true /* const */, + llvm::GlobalValue::InternalLinkage, + constValue, "const_initializer"); + llvm::Value *size = g->target.SizeOf(llvmType, + ctx->GetCurrentBasicBlock()); + ctx->MemcpyInst(ptr, constPtr, size); + } return; } diff --git a/ispc.cpp b/ispc.cpp index 4e39c0b2..e9357832 100644 --- a/ispc.cpp +++ b/ispc.cpp @@ -518,7 +518,9 @@ Target::SizeOf(LLVM_TYPE_CONST llvm::Type *type, const llvm::TargetData *td = GetTargetMachine()->getTargetData(); Assert(td != NULL); - uint64_t byteSize = td->getTypeSizeInBits(type) / 8; + uint64_t bitSize = td->getTypeSizeInBits(type); + Assert((bitSize % 8) == 0); + uint64_t byteSize = bitSize / 8; if (is32Bit || g->opt.force32BitAddressing) return LLVMInt32((int32_t)byteSize); else