From eb85da81e1c1ffcd3ccf557e0d8eff2e56476d85 Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Tue, 3 Apr 2012 05:55:50 -0700 Subject: [PATCH] Further improvements to error reporting with function types. Issue #219. --- expr.cpp | 4 ++-- tests_errors/ptr-1.ispc | 2 +- type.cpp | 23 +++++++++++------------ 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/expr.cpp b/expr.cpp index 78a89b6a..ebfac14f 100644 --- a/expr.cpp +++ b/expr.cpp @@ -328,8 +328,8 @@ lDoTypeConv(const Type *fromType, const Type *toType, Expr **expr, !Type::Equal(fromPointerType->GetBaseType()->GetAsConstType(), toPointerType->GetBaseType())) { if (!failureOk) - Error(pos, "Can't convert between incompatible pointer types " - "\"%s\" and \"%s\" for %s.", + Error(pos, "Can't convert from pointer type \"%s\" to " + "incompatible pointer type \"%s\" for %s.", fromPointerType->GetString().c_str(), toPointerType->GetString().c_str(), errorMsgBase); return false; diff --git a/tests_errors/ptr-1.ispc b/tests_errors/ptr-1.ispc index 66a9bff4..97a88488 100644 --- a/tests_errors/ptr-1.ispc +++ b/tests_errors/ptr-1.ispc @@ -1,4 +1,4 @@ -// Can't convert between incompatible pointer types +// Can't convert from pointer type "void * varying" to incompatible pointer type "uniform int32 * varying" for return statement int *foo(void *p) { return p; diff --git a/type.cpp b/type.cpp index 1aaeb2a6..2fb0a678 100644 --- a/type.cpp +++ b/type.cpp @@ -2466,18 +2466,7 @@ FunctionType::GetAsNonConstType() const { std::string FunctionType::GetString() const { - std::string ret; - if (isTask) ret += "task "; - if (isSafe) ret += "/*safe*/ "; - if (costOverride > 0) { - char buf[32]; - sprintf(buf, "/*cost=%d*/ ", costOverride); - ret += buf; - } - if (returnType != NULL) - ret += returnType->GetString(); - else - ret += "/* ERROR */"; + std::string ret = GetReturnTypeString(); ret += "("; for (unsigned int i = 0; i < paramTypes.size(); ++i) { if (paramTypes[i] == NULL) @@ -2554,6 +2543,9 @@ FunctionType::GetDIType(llvm::DIDescriptor scope) const { const std::string FunctionType::GetReturnTypeString() const { + if (returnType == NULL) + return "/* ERROR */"; + std::string ret; if (isTask) ret += "task "; @@ -2561,6 +2553,13 @@ FunctionType::GetReturnTypeString() const { ret += "export "; if (isExternC) ret += "extern \"C\" "; + if (isSafe) + ret += "/*safe*/ "; + if (costOverride > 0) { + char buf[32]; + sprintf(buf, "/*cost=%d*/ ", costOverride); + ret += buf; + } return ret + returnType->GetString(); }