Merge pull request #652 from jbrodman/ptrarithlvalues

Fix a case for a missing lvalue for pointer arithmetic
This commit is contained in:
Dmitry Babokin
2013-11-01 10:39:27 -07:00
3 changed files with 31 additions and 2 deletions

View File

@@ -2798,6 +2798,17 @@ BinaryExpr::TypeCheck() {
}
}
const Type *
BinaryExpr::GetLValueType() const {
const Type *t = GetType();
if (CastType<PointerType>(t) != NULL) {
// Are we doing something like (basePtr + offset)[...] = ...
return t;
}
else {
return NULL;
}
}
int
BinaryExpr::EstimateCost() const {
@@ -4266,8 +4277,9 @@ IndexExpr::GetValue(FunctionEmitContext *ctx) const {
}
else {
Symbol *baseSym = GetBaseSymbol();
if (dynamic_cast<FunctionCallExpr *>(baseExpr) == NULL) {
// Only check for non-function calls
if (dynamic_cast<FunctionCallExpr *>(baseExpr) == NULL &&
dynamic_cast<BinaryExpr *>(baseExpr) == NULL) {
// Don't check if we're doing a function call or pointer arith
AssertPos(pos, baseSym != NULL);
}
mask = lMaskForSymbol(baseSym, ctx);

1
expr.h
View File

@@ -155,6 +155,7 @@ public:
llvm::Value *GetValue(FunctionEmitContext *ctx) const;
const Type *GetType() const;
const Type *GetLValueType() const;
void Print() const;
Expr *Optimize();

View File

@@ -0,0 +1,16 @@
export uniform int width() { return programCount; }
int foo(uniform float * uniform base, uniform int uOfs, varying int vOfs) {
return (base+uOfs)[vOfs];
}
export void f_f(uniform float RET[], uniform float aFOO[]) {
uniform float * uniform ptr = &aFOO[0];
int val = foo(ptr, programCount, programIndex);
RET[programIndex] = val;
}
export void result(uniform float RET[]) {
RET[programIndex] = 1+programCount+programIndex;
}