glslang
glslang copied to clipboard
glslang shouldn't report the error for defined Preprocessor directives
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.
Yes. This should work.
Would you like me to assign this to you?
That's problem. Let me give it a try.
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 Thank you for your reminder. @greg-lunarg It's not a glsang bug. so I closed this issue. Thank you.
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", "");
}