graphitemaster / glsl-parser

A GLSL parser
MIT License
260 stars 30 forks source link

Crash when parsing ternary operator. #5

Closed bkaradzic closed 8 years ago

bkaradzic commented 8 years ago

Here is simple repro case:

void test(float x) {
    float y = x >= 0.0 ? 1.0 : 0.0;
}
graphitemaster commented 8 years ago

I don't think I wrote support for ternaries.

bkaradzic commented 8 years ago

It would be preferable to add support for it since it's supported by GLSL. Or at least syntax error. :)

graphitemaster commented 8 years ago

Yes, adding support would be ideal.

graphitemaster commented 8 years ago

Implemented support in df0e456

bkaradzic commented 8 years ago

I found 2 issues now:

The first one is that code:

void test(float x) {
    float y = x >= 0.0 ? 1.0 : 0.0;
}

Gets converted to (it should stay as float):

void test(float x) {
    float y = x >= 0 ? 1 : 0;
}

The other issue is also related to this but I don't have simple repro case:

Basically I have to trim .0 from condition, otherwise it crashes in lexer.cpp line 126:

#12 0x0000000000411df3 in glsl::lexer::read (this=0x7fffffffd728, out=...) at ../../../3rdparty/glsl-parser/lexer.cpp:126
121         }
122 
123         std::vector<char> numeric = readNumeric(isOctalish, isHexish);
124         if (position() != m_length && at() == '.') {
125             isFloat = true;
126             numeric.push_back('.');
127             m_location.advanceColumn();
128             std::vector<char> others = readNumeric(isOctalish, isHexish);
129             numeric.reserve(numeric.size() + others.size());
130             numeric.insert(numeric.end(), others.begin(), others.end());
bkaradzic commented 8 years ago

Actually ignore the second issue, it was bug in my code, just causing crash here...

graphitemaster commented 8 years ago

Fixed the float printing issue in 61613fe

graphitemaster commented 8 years ago

Need example code that causes the lexer to crash

graphitemaster commented 8 years ago

Pushed some code in fa2e14a to find malformatted floating literals which could get through into the parser and cause some bizzare bugs.

bkaradzic commented 8 years ago

It's non-issue. It was my code that caused corruption, that led to crash...

Anyhow, I'm planning to use your lib as starting point for new bgfx-shaderc compiler (https://bkaradzic.github.io/bgfx/index.html). I'll be adding more test cases from code I have.