From 3efbfc30b76ac4925e5cea25bec8d5928a698e2a Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Sat, 3 Dec 2011 15:27:54 -0800 Subject: [PATCH] Issue an error if a varying lvalue is passed to a reference function parameter. (Previously, we crashed.) --- expr.cpp | 11 +++++++++++ tests_errors/varying-lvalue-to-ref.ispc | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/expr.cpp b/expr.cpp index e67cb814..f4c84055 100644 --- a/expr.cpp +++ b/expr.cpp @@ -2599,6 +2599,17 @@ FunctionCallExpr::GetValue(FunctionEmitContext *ctx) const { const Type *paramType = ft->GetParameterType(i); + const Type *argLValueType = argExpr->GetLValueType(); + if (argLValueType != NULL && + dynamic_cast(argLValueType) != NULL && + argLValueType->IsVaryingType() && + dynamic_cast(paramType) != NULL) { + Error(argExpr->pos, "Illegal to pass a \"varying\" lvalue to a " + "reference parameter of type \"%s\".", + paramType->GetString().c_str()); + return NULL; + } + // Do whatever type conversion is needed argExpr = TypeConvertExpr(argExpr, paramType, "function call argument"); diff --git a/tests_errors/varying-lvalue-to-ref.ispc b/tests_errors/varying-lvalue-to-ref.ispc index 0944de6e..e6ffc54d 100644 --- a/tests_errors/varying-lvalue-to-ref.ispc +++ b/tests_errors/varying-lvalue-to-ref.ispc @@ -1,4 +1,4 @@ -// ffofoof +// Illegal to pass a "varying" lvalue to a reference parameter void inc(float &x) { ++x; }