Fix serious bug in handling constant-valued initializers.
In InitSymbol(), we try to be smart and emit a memcpy when there are a number of values to store (e.g. for arrays, structs, etc.) Unfortunately, this wasn't working as desired for bools (i.e. i1 types), since the SizeOf() call that tried to figure out how many bytes to copy would return 0 bytes, due to dividing the number of bits to copy by 8. Fixes issue #234.
This commit is contained in:
18
expr.cpp
18
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;
|
||||
}
|
||||
|
||||
4
ispc.cpp
4
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
|
||||
|
||||
Reference in New Issue
Block a user