SPV: Prevent issue #415 with better semantic checking.
This commit is contained in:
		
							parent
							
								
									11e1a073f3
								
							
						
					
					
						commit
						1176530bf5
					
				@ -2860,7 +2860,7 @@ spv::Id TGlslangToSpvTraverser::handleUserFunctionCall(const glslang::TIntermAgg
 | 
				
			|||||||
        builder.clearAccessChain();
 | 
					        builder.clearAccessChain();
 | 
				
			||||||
        glslangArgs[a]->traverse(this);
 | 
					        glslangArgs[a]->traverse(this);
 | 
				
			||||||
        argTypes.push_back(¶mType);
 | 
					        argTypes.push_back(¶mType);
 | 
				
			||||||
        // keep outputs as and opaque objects l-values, evaluate input-only as r-values
 | 
					        // keep outputs and opaque objects as l-values, evaluate input-only as r-values
 | 
				
			||||||
        if (qualifiers[a] != glslang::EvqConstReadOnly || paramType.isOpaque()) {
 | 
					        if (qualifiers[a] != glslang::EvqConstReadOnly || paramType.isOpaque()) {
 | 
				
			||||||
            // save l-value
 | 
					            // save l-value
 | 
				
			||||||
            lValues.push_back(builder.getAccessChain());
 | 
					            lValues.push_back(builder.getAccessChain());
 | 
				
			||||||
 | 
				
			|||||||
@ -33,7 +33,12 @@ ERROR: 0:67: 'uniform' : no qualifiers allowed for function return
 | 
				
			|||||||
ERROR: 0:69: 'non-opaque uniforms outside a block' : not allowed when using GLSL for Vulkan 
 | 
					ERROR: 0:69: 'non-opaque uniforms outside a block' : not allowed when using GLSL for Vulkan 
 | 
				
			||||||
ERROR: 0:73: 'texture' : no matching overloaded function found 
 | 
					ERROR: 0:73: 'texture' : no matching overloaded function found 
 | 
				
			||||||
ERROR: 0:74: 'imageStore' : no matching overloaded function found 
 | 
					ERROR: 0:74: 'imageStore' : no matching overloaded function found 
 | 
				
			||||||
ERROR: 33 compilation errors.  No code generated.
 | 
					ERROR: 0:91: 'call argument' : sampler constructor must appear at point of use 
 | 
				
			||||||
 | 
					ERROR: 0:92: 'call argument' : sampler constructor must appear at point of use 
 | 
				
			||||||
 | 
					ERROR: 0:93: ',' : sampler constructor must appear at point of use 
 | 
				
			||||||
 | 
					ERROR: 0:94: ':' :  wrong operand types: no operation ':' exists that takes a left-hand operand of type 'temp sampler2D' and a right operand of type 'temp sampler2D' (or there is no acceptable conversion)
 | 
				
			||||||
 | 
					ERROR: 0:94: 'call argument' : sampler constructor must appear at point of use 
 | 
				
			||||||
 | 
					ERROR: 38 compilation errors.  No code generated.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -73,3 +73,23 @@ void fooTex()
 | 
				
			|||||||
    texture(t2d, vec2(1.0));                 // ERROR, need a sampler, not a pure texture
 | 
					    texture(t2d, vec2(1.0));                 // ERROR, need a sampler, not a pure texture
 | 
				
			||||||
    imageStore(t2d, ivec2(4, 5), vec4(1.2)); // ERROR, need an image, not a pure texture
 | 
					    imageStore(t2d, ivec2(4, 5), vec4(1.2)); // ERROR, need an image, not a pure texture
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					precision highp float;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					layout(location=0) in vec2 vTexCoord;
 | 
				
			||||||
 | 
					layout(location=0) out vec4 FragColor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					vec4 userTexture(mediump sampler2D samp, vec2 coord)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return texture(samp, coord);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool cond;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void callUserTexture()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    userTexture(sampler2D(t2d,s), vTexCoord);                            // ERROR, not point of use
 | 
				
			||||||
 | 
					    userTexture((sampler2D(t2d,s)), vTexCoord);                          // ERROR, not point of use
 | 
				
			||||||
 | 
					    userTexture((sampler2D(t2d,s), sampler2D(t2d,s)), vTexCoord);        // ERROR, not point of use
 | 
				
			||||||
 | 
					    userTexture(cond ? sampler2D(t2d,s) : sampler2D(t2d,s), vTexCoord);  // ERROR, no ?:, not point of use
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -2,5 +2,5 @@
 | 
				
			|||||||
// For the version, it uses the latest git tag followed by the number of commits.
 | 
					// 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).
 | 
					// For the date, it uses the current date (when then script is run).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define GLSLANG_REVISION "SPIRV99.1374"
 | 
					#define GLSLANG_REVISION "SPIRV99.1375"
 | 
				
			||||||
#define GLSLANG_DATE "30-Jul-2016"
 | 
					#define GLSLANG_DATE "31-Jul-2016"
 | 
				
			||||||
 | 
				
			|||||||
@ -1181,6 +1181,8 @@ TIntermTyped* TParseContext::handleFunctionCall(const TSourceLoc& loc, TFunction
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                if (builtIn)
 | 
					                if (builtIn)
 | 
				
			||||||
                    nonOpBuiltInCheck(loc, *fnCandidate, *call);
 | 
					                    nonOpBuiltInCheck(loc, *fnCandidate, *call);
 | 
				
			||||||
 | 
					                else
 | 
				
			||||||
 | 
					                    userFunctionCallCheck(loc, *call);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Convert 'out' arguments.  If it was a constant folded built-in, it won't be an aggregate anymore.
 | 
					            // Convert 'out' arguments.  If it was a constant folded built-in, it won't be an aggregate anymore.
 | 
				
			||||||
@ -1723,6 +1725,26 @@ void TParseContext::nonOpBuiltInCheck(const TSourceLoc& loc, const TFunction& fn
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					// Do any extra checking for a user function call.
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					void TParseContext::userFunctionCallCheck(const TSourceLoc& loc, TIntermAggregate& callNode)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    TIntermSequence& arguments = callNode.getSequence();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (int i = 0; i < (int)arguments.size(); ++i)
 | 
				
			||||||
 | 
					        samplerConstructorLocationCheck(loc, "call argument", arguments[i]);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					// Emit an error if this is a sampler constructor
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					void TParseContext::samplerConstructorLocationCheck(const TSourceLoc& loc, const char* token, TIntermNode* node)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (node->getAsOperator() && node->getAsOperator()->getOp() == EOpConstructTextureSampler)
 | 
				
			||||||
 | 
					        error(loc, "sampler constructor must appear at point of use", token, "");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
// Handle seeing a built-in constructor in a grammar production.
 | 
					// Handle seeing a built-in constructor in a grammar production.
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
 | 
				
			|||||||
@ -204,6 +204,8 @@ public:
 | 
				
			|||||||
    TIntermTyped* addOutputArgumentConversions(const TFunction&, TIntermAggregate&) const;
 | 
					    TIntermTyped* addOutputArgumentConversions(const TFunction&, TIntermAggregate&) const;
 | 
				
			||||||
    void builtInOpCheck(const TSourceLoc&, const TFunction&, TIntermOperator&);
 | 
					    void builtInOpCheck(const TSourceLoc&, const TFunction&, TIntermOperator&);
 | 
				
			||||||
    void nonOpBuiltInCheck(const TSourceLoc&, const TFunction&, TIntermAggregate&);
 | 
					    void nonOpBuiltInCheck(const TSourceLoc&, const TFunction&, TIntermAggregate&);
 | 
				
			||||||
 | 
					    void userFunctionCallCheck(const TSourceLoc&, TIntermAggregate&);
 | 
				
			||||||
 | 
					    void samplerConstructorLocationCheck(const TSourceLoc&, const char* token, TIntermNode*);
 | 
				
			||||||
    TFunction* handleConstructorCall(const TSourceLoc&, const TPublicType&);
 | 
					    TFunction* handleConstructorCall(const TSourceLoc&, const TPublicType&);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    bool parseVectorFields(const TSourceLoc&, const TString&, int vecSize, TVectorFields&);
 | 
					    bool parseVectorFields(const TSourceLoc&, const TString&, int vecSize, TVectorFields&);
 | 
				
			||||||
 | 
				
			|||||||
@ -691,6 +691,7 @@ expression
 | 
				
			|||||||
        $$ = $1;
 | 
					        $$ = $1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    | expression COMMA assignment_expression {
 | 
					    | expression COMMA assignment_expression {
 | 
				
			||||||
 | 
					        parseContext.samplerConstructorLocationCheck($2.loc, ",", $3);
 | 
				
			||||||
        $$ = parseContext.intermediate.addComma($1, $3, $2.loc);
 | 
					        $$ = parseContext.intermediate.addComma($1, $3, $2.loc);
 | 
				
			||||||
        if ($$ == 0) {
 | 
					        if ($$ == 0) {
 | 
				
			||||||
            parseContext.binaryOpError($2.loc, ",", $1->getCompleteString(), $3->getCompleteString());
 | 
					            parseContext.binaryOpError($2.loc, ",", $1->getCompleteString(), $3->getCompleteString());
 | 
				
			||||||
 | 
				
			|||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@ -1,8 +1,8 @@
 | 
				
			|||||||
/* A Bison parser, made by GNU Bison 2.7.  */
 | 
					/* A Bison parser, made by GNU Bison 3.0.4.  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Bison interface for Yacc-like parsers in C
 | 
					/* Bison interface for Yacc-like parsers in C
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc.
 | 
					   Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   This program is free software: you can redistribute it and/or modify
 | 
					   This program is free software: you can redistribute it and/or modify
 | 
				
			||||||
   it under the terms of the GNU General Public License as published by
 | 
					   it under the terms of the GNU General Public License as published by
 | 
				
			||||||
@ -30,9 +30,9 @@
 | 
				
			|||||||
   This special exception was added by the Free Software Foundation in
 | 
					   This special exception was added by the Free Software Foundation in
 | 
				
			||||||
   version 2.2 of Bison.  */
 | 
					   version 2.2 of Bison.  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifndef YY_YY_GLSLANG_TAB_CPP_H_INCLUDED
 | 
					#ifndef YY_YY_MACHINEINDEPENDENT_GLSLANG_TAB_CPP_H_INCLUDED
 | 
				
			||||||
# define YY_YY_GLSLANG_TAB_CPP_H_INCLUDED
 | 
					# define YY_YY_MACHINEINDEPENDENT_GLSLANG_TAB_CPP_H_INCLUDED
 | 
				
			||||||
/* Enabling traces.  */
 | 
					/* Debug traces.  */
 | 
				
			||||||
#ifndef YYDEBUG
 | 
					#ifndef YYDEBUG
 | 
				
			||||||
# define YYDEBUG 1
 | 
					# define YYDEBUG 1
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
@ -40,12 +40,11 @@
 | 
				
			|||||||
extern int yydebug;
 | 
					extern int yydebug;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Tokens.  */
 | 
					/* Token type.  */
 | 
				
			||||||
#ifndef YYTOKENTYPE
 | 
					#ifndef YYTOKENTYPE
 | 
				
			||||||
# define YYTOKENTYPE
 | 
					# define YYTOKENTYPE
 | 
				
			||||||
   /* Put the tokens into the symbol table, so that GDB and other debuggers
 | 
					  enum yytokentype
 | 
				
			||||||
      know about them.  */
 | 
					  {
 | 
				
			||||||
   enum yytokentype {
 | 
					 | 
				
			||||||
    ATTRIBUTE = 258,
 | 
					    ATTRIBUTE = 258,
 | 
				
			||||||
    VARYING = 259,
 | 
					    VARYING = 259,
 | 
				
			||||||
    CONST = 260,
 | 
					    CONST = 260,
 | 
				
			||||||
@ -317,12 +316,12 @@ extern int yydebug;
 | 
				
			|||||||
  };
 | 
					  };
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Value type.  */
 | 
				
			||||||
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
 | 
					#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
 | 
				
			||||||
typedef union YYSTYPE
 | 
					
 | 
				
			||||||
 | 
					union YYSTYPE
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
/* Line 2058 of yacc.c  */
 | 
					#line 66 "MachineIndependent/glslang.y" /* yacc.c:1909  */
 | 
				
			||||||
#line 66 "glslang.y"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    struct {
 | 
					    struct {
 | 
				
			||||||
        glslang::TSourceLoc loc;
 | 
					        glslang::TSourceLoc loc;
 | 
				
			||||||
@ -356,28 +355,16 @@ typedef union YYSTYPE
 | 
				
			|||||||
        };
 | 
					        };
 | 
				
			||||||
    } interm;
 | 
					    } interm;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#line 359 "MachineIndependent/glslang_tab.cpp.h" /* yacc.c:1909  */
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Line 2058 of yacc.c  */
 | 
					typedef union YYSTYPE YYSTYPE;
 | 
				
			||||||
#line 362 "glslang_tab.cpp.h"
 | 
					 | 
				
			||||||
} YYSTYPE;
 | 
					 | 
				
			||||||
# define YYSTYPE_IS_TRIVIAL 1
 | 
					# define YYSTYPE_IS_TRIVIAL 1
 | 
				
			||||||
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
 | 
					 | 
				
			||||||
# define YYSTYPE_IS_DECLARED 1
 | 
					# define YYSTYPE_IS_DECLARED 1
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef YYPARSE_PARAM
 | 
					 | 
				
			||||||
#if defined __STDC__ || defined __cplusplus
 | 
					 | 
				
			||||||
int yyparse (void *YYPARSE_PARAM);
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
int yyparse ();
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
#else /* ! YYPARSE_PARAM */
 | 
					 | 
				
			||||||
#if defined __STDC__ || defined __cplusplus
 | 
					 | 
				
			||||||
int yyparse (glslang::TParseContext* pParseContext);
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
int yyparse ();
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
#endif /* ! YYPARSE_PARAM */
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif /* !YY_YY_GLSLANG_TAB_CPP_H_INCLUDED  */
 | 
					int yyparse (glslang::TParseContext* pParseContext);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif /* !YY_YY_MACHINEINDEPENDENT_GLSLANG_TAB_CPP_H_INCLUDED  */
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user