glslang icon indicating copy to clipboard operation
glslang copied to clipboard

glslang shouldn't report the error for defined Preprocessor directives

Open ZhiqianXia opened this issue 4 years ago • 5 comments

Hi,

Acoording to the glsl4.6 spec ,ch3.3 Preprocessor :

#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate as is standard for C++ preprocessors.
Expressions following #if and #elif are further restricted to expressions operating on literal integer constants, plus identifiers consumed by the defined operator

So glslang shouldn't report the error for following shader for defined Preprocessor directives. but Glslang report error

ERROR: 0:10: 'defined' : cannot use in preprocessor expression when expanded from macros

shader:

#version 300 es
precision mediump float;
in highp vec4 dEQP_Position;
out float out0;

void main()
{
#define AAA defined(BBB)
#if !AAA
               out0 = 1.0;
#else
               out0 = 0.0;
#endif
               gl_Position = dEQP_Position;
}

thank you.

ZhiqianXia avatar Feb 08 '21 02:02 ZhiqianXia

Yes. This should work.

Would you like me to assign this to you?

greg-lunarg avatar Feb 09 '21 01:02 greg-lunarg

That's problem. Let me give it a try.

ZhiqianXia avatar Feb 09 '21 02:02 ZhiqianXia

if (parseContext.relaxedErrors()) parseContext.ppWarn(ppToken->loc, "nonportable when expanded from macros for preprocessor expression", "defined", "");

Try to add relaxederror option for PP to only warn here.

ShchchowAMD avatar Feb 09 '21 06:02 ShchchowAMD

@ShchchowAMD Thank you for your reminder. @greg-lunarg It's not a glsang bug. so I closed this issue. Thank you.

ZhiqianXia avatar Feb 09 '21 09:02 ZhiqianXia

Hi, Recently I review the issue, and Test the shader on ARM's compiler and PowerVR's compiler. the both compilers didn't report the error for the shader. You can use the https://shader-playground.timjones.io/ to test the shader.In my opinon, the glslang's code PP.cpp + 422 should be removed. because the glsl also support the marco expension . thanks.

if (! parseContext.isReadingHLSL() && isMacroInput()) {
	if (parseContext.relaxedErrors())
		parseContext.ppWarn(ppToken->loc, "nonportable when expanded from macros for preprocessor expression",
			"defined", "");
	else
		parseContext.ppError(ppToken->loc, "cannot use in preprocessor expression when expanded from macros",
			"defined", "");
}

ZhiqianXia avatar Jan 07 '22 07:01 ZhiqianXia