Fixed issue with aliasing local variables

ISPC++ now produces valid code, or an appropriate error message, for all
of my test cases.
This commit is contained in:
2017-05-11 15:42:11 -04:00
parent bfe723e1b7
commit 5e6f06cf59
12 changed files with 135 additions and 25 deletions

View File

@@ -8099,6 +8099,11 @@ SymbolExpr::ReplacePolyType(const PolyType *from, const Type *to) {
if (!symbol)
return NULL;
Symbol *tmp = m->symbolTable->LookupVariable(symbol->name.c_str());
if (tmp) {
tmp->parentFunction = symbol->parentFunction;
symbol = tmp;
}
if (Type::EqualForReplacement(symbol->type->GetBaseType(), from)) {
symbol->type = PolyType::ReplaceType(symbol->type, to);
@@ -8176,6 +8181,14 @@ FunctionSymbolExpr::Optimize() {
return this;
}
Expr *
FunctionSymbolExpr::ReplacePolyType(const PolyType *from, const Type *to) {
// force re-evaluation of overloaded type
this->triedToResolve = false;
return this;
}
int
FunctionSymbolExpr::EstimateCost() const {
@@ -8422,6 +8435,16 @@ FunctionSymbolExpr::computeOverloadCost(const FunctionType *ftype,
cost[i] += 8 * costScale;
continue;
}
if (callTypeNC->IsPolymorphicType()) {
const PolyType *callTypeP =
CastType<PolyType>(callTypeNC->GetBaseType());
if (callTypeP->CanBeType(fargTypeNC->GetBaseType()) &&
callTypeNC->IsArrayType() == fargTypeNC->IsArrayType() &&
callTypeNC->IsPointerType() == fargTypeNC->IsPointerType()){
cost[i] += 8 * costScale;
continue;
}
}
if (fargType->IsVaryingType() && callType->IsUniformType()) {
// Here we deal with brodcasting uniform to varying.
// callType - varying and fargType - uniform is forbidden.
@@ -8548,6 +8571,12 @@ FunctionSymbolExpr::ResolveOverloads(SourcePos argPos,
return true;
}
else if (matches.size() > 1) {
for (size_t i=0; i<argTypes.size(); i++) {
if (argTypes[i]->IsPolymorphicType()) {
matchingFunc = matches[0];
return true;
}
}
// Multiple matches: ambiguous
std::string candidateMessage =
lGetOverloadCandidateMessage(matches, argTypes, argCouldBeNULL);