Add checks about references to non-lvalues.
Both ReturnStmt and DeclStmt now check the values being associated with references to make sure that they are legal (e.g. it's illegal to assign a varying lvalue, or a compile-time constant to a reference type). Previously we didn't catch this and would end up hitting assertions in LLVM when code did this stuff. Mostly fixes issue #225 (except for adding a FAQ about what this error message means.)
This commit is contained in:
6
tests_errors/ref-initializer-1.ispc
Normal file
6
tests_errors/ref-initializer-1.ispc
Normal file
@@ -0,0 +1,6 @@
|
||||
// Initializer for reference-type variable "x" must have an lvalue type
|
||||
|
||||
float &func(uniform float a[], int i, float f) {
|
||||
float &x = 1.; // a[i];
|
||||
}
|
||||
|
||||
6
tests_errors/ref-initializer-2.ispc
Normal file
6
tests_errors/ref-initializer-2.ispc
Normal file
@@ -0,0 +1,6 @@
|
||||
// Initializer for reference-type variable "x" must have a uniform lvalue type
|
||||
|
||||
float &func(uniform float a[], int i, float f) {
|
||||
float &x = a[i];
|
||||
}
|
||||
|
||||
6
tests_errors/ref-initializer-3.ispc
Normal file
6
tests_errors/ref-initializer-3.ispc
Normal file
@@ -0,0 +1,6 @@
|
||||
// Initializer for reference-type variable "x" must have a uniform lvalue type
|
||||
|
||||
float &func(uniform int a[], int i, float f) {
|
||||
float &x = a[i];
|
||||
}
|
||||
|
||||
5
tests_errors/return-ref-1.ispc
Normal file
5
tests_errors/return-ref-1.ispc
Normal file
@@ -0,0 +1,5 @@
|
||||
// Illegal to return non-lvalue from function returning reference type
|
||||
|
||||
float &func(uniform float a[], int i, float f) {
|
||||
return 1.f;
|
||||
}
|
||||
5
tests_errors/return-ref-2.ispc
Normal file
5
tests_errors/return-ref-2.ispc
Normal file
@@ -0,0 +1,5 @@
|
||||
// Illegal to return varying lvalue type from function returning a reference type
|
||||
|
||||
float &func(uniform float a[], int i, float f) {
|
||||
return a[i];
|
||||
}
|
||||
Reference in New Issue
Block a user