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

Incorrect Parsing of Hexadecimal Floating Point Literals #556

Open
graypinkfurball opened this issue Nov 14, 2024 · 1 comment
Open

Incorrect Parsing of Hexadecimal Floating Point Literals #556

graypinkfurball opened this issue Nov 14, 2024 · 1 comment

Comments

@graypinkfurball
Copy link

graypinkfurball commented Nov 14, 2024

Related to #253. I noticed that in c_parser.py at L1882, it ignores type suffixes on hexadecimal floating point literals.

This commit explicitly ignoring hexadecimal literals, and this commit added an incorrect test.

float* a = { 0.1f, 0.1, 0.1l, 0x1p0f, 0x1p0, 0x1p0l };
FileAST:
  Decl: a, [], [], [], []
    PtrDecl: []
      TypeDecl: a, [], None
        IdentifierType: ['float']
    InitList:
      Constant: float, 0.1f
      Constant: double, 0.1
      Constant: long double, 0.1l
      Constant: float, 0x1p0f
      Constant: float, 0x1p0
      Constant: float, 0x1p0l

The type of the hexadecimal constants should be "float", "double" and "long double" in that order. Test cases should be amended.


I ran a little test with my compiler to verify the sizes of the literals.

#include <stdio.h>
int main(void) {
  printf("%llu %llu %llu\n%llu %llu %llu",
    sizeof(0.1f), sizeof(0.1), sizeof(0.1l),
    sizeof(0x1p0f), sizeof(0x1p0), sizeof(0x1p0l));
  return 0;
}
4 8 16
4 8 16
@eliben
Copy link
Owner

eliben commented Nov 16, 2024

Thank you for the report. Please feel free to submit a PR with a fix

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

No branches or pull requests

2 participants