Issue an error if the user has nested foreach statements.

Partially addresses issue #280.  (We should support them properly,
but at least now we don't silently generate incorrect code.)
This commit is contained in:
Matt Pharr
2012-06-21 16:53:27 -07:00
parent 8b891da628
commit 2b4a3b22bf
2 changed files with 23 additions and 0 deletions

12
ctx.cpp
View File

@@ -584,6 +584,18 @@ FunctionEmitContext::EndLoop() {
void
FunctionEmitContext::StartForeach() {
// Issue an error if we're in a nested foreach...
for (int i = 0; i < (int)controlFlowInfo.size(); ++i) {
if (controlFlowInfo[i]->type == CFInfo::Foreach) {
Error(currentPos, "Nested \"foreach\" statements are currently illegal.");
break;
// Don't return here, however, and in turn allow the caller to
// do the rest of its codegen and then call EndForeach()
// normally--the idea being that this gives a chance to find
// any other errors inside the body of the foreach loop...
}
}
// Store the current values of various loop-related state so that we
// can restore it when we exit this loop.
llvm::Value *oldMask = GetInternalMask();

View File

@@ -0,0 +1,11 @@
// Nested "foreach" statements are currently illegal
void func();
void foo(uniform int a, uniform int b) {
foreach (i = 0 ... a) {
foreach (j = 0 ... b) {
func();
}
}
}