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

Possible preprocessor issues with empty token concatenation #1721

Closed
godlikepanos opened this issue Mar 8, 2019 · 2 comments
Closed

Possible preprocessor issues with empty token concatenation #1721

godlikepanos opened this issue Mar 8, 2019 · 2 comments

Comments

@godlikepanos
Copy link
Contributor

godlikepanos commented Mar 8, 2019

Imagine the following code:

#define MACRO(tokenA, tokenB, tokenC) tokenA##tokenB##tokenC
#define MACRO2(filled, none) MACRO(filled, C, none)

#define NONE()
MACRO2(A, NONE())

In gcc's and clang's preprocessor the outpout is AC. glslang in the other hand outputs ACtokenC.

A slight twist of the above:

#define MACRO(tokenA, tokenB, tokenC) tokenA##tokenB##tokenC
#define MACRO2(filled, none) MACRO(none, filled, C)

#define NONE()
MACRO2(A, NONE())

In gcc's and clang's preprocessor the outpout is AC once again. glslang in the other hand throws some errors:

ERROR: pp_test.frag:5: '##' : unexpected location 
ERROR: pp_test.frag:5: '##' : unexpected location

The following also fails on glslang:

#define MACRO(tokenA, tokenB, tokenC) tokenA##tokenB##tokenC
#define MACRO2(filled, none) MACRO(none, filled, C)

MACRO2(A, )

I'm not sure which behavior is correct but maybe you can verify. Thank you.

@johnkslang
Copy link
Member

johnkslang commented Mar 11, 2019

So, the C++ specification (normative for GLSL preprocessing) says

If (before argument substitution) any argument consists of no preprocessing tokens, the behavior is undefined.

So, generally, for portability, you'd want to set things up without using arguments that have no tokens in them.

Now, if you want to identify a specific behavior that HLSL does define and is important to use, I could look and see whether that is difficult to support or not.

@godlikepanos
Copy link
Contributor Author

If (before argument substitution) any argument consists of no preprocessing tokens, the behavior is undefined.

I'm using GLSL so the spec quote and the explanation covers me.

DXC seems to have the same behavior as GCC and clang (as expected) but I don't care. If anyone does maybe they can reopen the ticket.

Closing for now. Thank you!

xen2 pushed a commit to stride3d/xkslang that referenced this issue Apr 22, 2019
Includes:

    Update OpPhi instructions after splitting block. (KhronosGroup#1783)
    Don't change decorations and names in merge return. (KhronosGroup#1777)
    Transform to combine consecutive access chains
    Handle undef literal value in vector shuffle
    Fix block ordering in dead branch elim
    Fix finding constant with particular type. (KhronosGroup#1724)
    Fix infinite loop while folding OpVectorShuffle (KhronosGroup#1722)
    Fix size error when folding vector shuffle. (KhronosGroup#1721)
    Layout validation: Permit {vec3; float} tight packing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants