Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glslang shouldn't report the error for defined Preprocessor directives #2528

Open
ZhiqianXia opened this issue Feb 8, 2021 · 5 comments
Open
Assignees

Comments

@ZhiqianXia
Copy link
Contributor

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 ZhiqianXia changed the title glslang shouldn't report the error for Feb 8, 2021
@greg-lunarg
Copy link
Contributor

Yes. This should work.

Would you like me to assign this to you?

@ZhiqianXia
Copy link
Contributor Author

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

@ShchchowAMD
Copy link
Contributor

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.

@ZhiqianXia
Copy link
Contributor Author

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

@ZhiqianXia
Copy link
Contributor Author

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", "");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants