Fix type conversion to allow array -> void * conversions.
Fixes issue #193.
This commit is contained in:
8
expr.cpp
8
expr.cpp
@@ -253,6 +253,11 @@ lDoTypeConv(const Type *fromType, const Type *toType, Expr **expr,
|
|||||||
// "float foo[10]" -> "float * uniform foo", we have what's seemingly
|
// "float foo[10]" -> "float * uniform foo", we have what's seemingly
|
||||||
// a varying to uniform conversion (but not really)
|
// a varying to uniform conversion (but not really)
|
||||||
if (fromArrayType != NULL && toPointerType != NULL) {
|
if (fromArrayType != NULL && toPointerType != NULL) {
|
||||||
|
// can convert any array to a void pointer (both uniform and
|
||||||
|
// varying).
|
||||||
|
if (PointerType::IsVoidPointer(toPointerType))
|
||||||
|
goto typecast_ok;
|
||||||
|
|
||||||
// array to pointer to array element type
|
// array to pointer to array element type
|
||||||
const Type *eltType = fromArrayType->GetElementType();
|
const Type *eltType = fromArrayType->GetElementType();
|
||||||
if (toPointerType->GetBaseType()->IsConstType())
|
if (toPointerType->GetBaseType()->IsConstType())
|
||||||
@@ -6411,7 +6416,8 @@ TypeCastExpr::GetValue(FunctionEmitContext *ctx) const {
|
|||||||
// implicit array to pointer to first element
|
// implicit array to pointer to first element
|
||||||
Expr *arrayAsPtr = lArrayToPointer(expr);
|
Expr *arrayAsPtr = lArrayToPointer(expr);
|
||||||
if (Type::EqualIgnoringConst(arrayAsPtr->GetType(), toPointerType) == false) {
|
if (Type::EqualIgnoringConst(arrayAsPtr->GetType(), toPointerType) == false) {
|
||||||
Assert(Type::EqualIgnoringConst(arrayAsPtr->GetType()->GetAsVaryingType(),
|
Assert(PointerType::IsVoidPointer(toPointerType) ||
|
||||||
|
Type::EqualIgnoringConst(arrayAsPtr->GetType()->GetAsVaryingType(),
|
||||||
toPointerType) == true);
|
toPointerType) == true);
|
||||||
arrayAsPtr = new TypeCastExpr(toPointerType, arrayAsPtr, pos);
|
arrayAsPtr = new TypeCastExpr(toPointerType, arrayAsPtr, pos);
|
||||||
arrayAsPtr = ::TypeCheck(arrayAsPtr);
|
arrayAsPtr = ::TypeCheck(arrayAsPtr);
|
||||||
|
|||||||
Reference in New Issue
Block a user