Give error for calling a user-defined function at global scope.
authorJohn Kessenich <cepheus@frii.com>
Tue, 6 Oct 2015 19:11:38 +0000 (13:11 -0600)
committerJohn Kessenich <cepheus@frii.com>
Tue, 6 Oct 2015 19:11:38 +0000 (13:11 -0600)
Test/110scope.vert
Test/baseResults/110scope.vert.out
glslang/Include/revision.h
glslang/MachineIndependent/ParseHelper.cpp
glslang/MachineIndependent/ParseHelper.h

index 564059a..e28db0f 100644 (file)
@@ -31,7 +31,7 @@ bool radians(bool x) // okay, can overload built-in functions
     return true;\r
 }\r
 \r
-\r
+int gi = f(1,2,3);  // ERROR, can't call user-defined function from global scope\r
 \r
 void main()\r
 {\r
index 0a3089d..3151246 100644 (file)
@@ -1,8 +1,9 @@
 110scope.vert\r
 ERROR: 0:5: 'a' : redefinition \r
+ERROR: 0:34: 'f' : can't call user function from global scope \r
 ERROR: 0:57: 'z' : undeclared identifier \r
 ERROR: 0:57: 'z' : redefinition \r
-ERROR: 3 compilation errors.  No code generated.\r
+ERROR: 4 compilation errors.  No code generated.\r
 \r
 \r
 Shader version: 110\r
@@ -38,6 +39,16 @@ ERROR: node is still EOpNull!
 0:31      Branch: Return with expression\r
 0:31        Constant:\r
 0:31          true (const bool)\r
+0:34  Sequence\r
+0:34    move second child to first child (temp int)\r
+0:34      'gi' (global int)\r
+0:34      Function Call: f(i1;i1;i1; (global int)\r
+0:34        Constant:\r
+0:34          1 (const int)\r
+0:34        Constant:\r
+0:34          2 (const int)\r
+0:34        Constant:\r
+0:34          3 (const int)\r
 0:36  Function Definition: main( (global void)\r
 0:36    Function Parameters: \r
 0:?     Sequence\r
@@ -115,6 +126,7 @@ ERROR: node is still EOpNull!
 0:?     'c' (global bool)\r
 0:?     'f' (global float)\r
 0:?     'tan' (global float)\r
+0:?     'gi' (global int)\r
 \r
 \r
 Linked vertex stage:\r
@@ -153,6 +165,16 @@ ERROR: node is still EOpNull!
 0:31      Branch: Return with expression\r
 0:31        Constant:\r
 0:31          true (const bool)\r
+0:34  Sequence\r
+0:34    move second child to first child (temp int)\r
+0:34      'gi' (global int)\r
+0:34      Function Call: f(i1;i1;i1; (global int)\r
+0:34        Constant:\r
+0:34          1 (const int)\r
+0:34        Constant:\r
+0:34          2 (const int)\r
+0:34        Constant:\r
+0:34          3 (const int)\r
 0:36  Function Definition: main( (global void)\r
 0:36    Function Parameters: \r
 0:?     Sequence\r
@@ -230,4 +252,5 @@ ERROR: node is still EOpNull!
 0:?     'c' (global bool)\r
 0:?     'f' (global float)\r
 0:?     'tan' (global float)\r
+0:?     'gi' (global int)\r
 \r
index 6319080..798e1c7 100644 (file)
@@ -2,5 +2,5 @@
 // For the version, it uses the latest git tag followed by the number of commits.
 // For the date, it uses the current date (when then script is run).
 
-#define GLSLANG_REVISION "3.0.779"
-#define GLSLANG_DATE "05-Oct-2015"
+#define GLSLANG_REVISION "3.0.780"
+#define GLSLANG_DATE "06-Oct-2015"
index b4f0c0b..05d455a 100644 (file)
@@ -1124,7 +1124,10 @@ TIntermTyped* TParseContext::handleFunctionCall(const TSourceLoc& loc, TFunction
                 // if builtIn == true, it's definitely a built-in function with EOpNull
                 if (! builtIn) {
                     call->setUserDefined();
-                    intermediate.addToCallGraph(infoSink, currentCaller, fnCandidate->getMangledName());
+                    if (symbolTable.atGlobalLevel())
+                        error(loc, "can't call user function from global scope", fnCandidate->getName().c_str(), "");
+                    else
+                        intermediate.addToCallGraph(infoSink, currentCaller, fnCandidate->getMangledName());
                 }
 
                 if (builtIn)
index 771a43e..3766bff 100644 (file)
@@ -323,7 +323,7 @@ protected:
     TQualifier globalInputDefaults;
     TQualifier globalOutputDefaults;
     int* atomicUintOffsets;       // to become an array of the right size to hold an offset per binding point
-    TString currentCaller;
+    TString currentCaller;        // name of last function body entered (not valid when at global scope)
     TIdSetType inductiveLoopIds;
     bool anyIndexLimits;
     TVector<TIntermTyped*> needsIndexLimitationChecking;