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

Wrong output when code contains asm directives. #1470

Closed
cassioneri opened this issue Jul 2, 2019 · 4 comments
Closed

Wrong output when code contains asm directives. #1470

cassioneri opened this issue Jul 2, 2019 · 4 comments
Labels
enhancement request Request for something

Comments

@cassioneri
Copy link
Contributor

I was playing with an idea given in [1] which uses asm directives. In summary:

asm(
    ".ifnc %2,%%eax\n\t"
    "mull %2\n\t"
    ".else\n\t"
    "mull %3\n\t"
    ".endif"
...

Given the .ifnc/.else directives, the output should show either the 1st mull instruction or the 2nd one. It shows both. The complete example can be seen in [2]. Notice that when the code is compiled and disassembled (i.e., option 11010 is selected) the output is as expected. Therefore, it seems to be a bug in CE's parser.

I reckon this issue is a corner case but I hope this helps anyway.

[1] https://stackoverflow.com/questions/13617962/can-gcc-emit-different-instruction-mnemonics-when-choosing-between-multiple-alte
[2] https://godbolt.org/z/Zen61D

@apmorton
Copy link
Member

apmorton commented Jul 2, 2019

This is an issue in the assembly output parser, but it may not be a trivial issue to fix.

If you turn off the assembly directive filtering (button labeled .text) you can see whats going on.
https://godbolt.org/z/vIphR2

Your .ifnc/etc directives are output as is by the compiler.
They aren't evaluated until the assembler itself runs, which is why you are seeing the expected results when using the 11010 button.

The .text button is doing exactly what it is designed to do: filter out all assembler directives. It just happens that you want to see some of them in this particular case.

I don't know how frequently .ifnc/.else/.endif come up, but maybe it would be useful to have an optional whitelist of directives to keep for each compiler.

@cassioneri
Copy link
Contributor Author

Fair enough. As I said, I reckon this is really a corner case which probably don't affect the vast majority of users. I could suggest implementing a simple parser for .ifc/ifnc/.else/.endif directives but it's too much to ask for a very niche use case. The idea of a whilelist that preserves these directives seems to be a good compromise.

It's a shame that, as far as I'm aware, there's no "as preprocessor" that could be used by CE to process the directives.

Also, feel free to close the issue if you see the "fix" as not worth doing.

@mattgodbolt mattgodbolt added enhancement request Request for something labels Jul 9, 2019
@mattgodbolt
Copy link
Member

This is an interesting case! I think it'd be fun to support the conditionals as a special "don't filter them" case.

@mattgodbolt
Copy link
Member

On second thought, given the backlog, I'm going to close this. I wouldn't be against it, but it's niche enough not to even be on the "maybe one day" pile; sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement request Request for something
Projects
None yet
Development

No branches or pull requests

3 participants