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

_Alignas(x) does not work with custom types #472

Open
vit9696 opened this issue Sep 6, 2022 · 2 comments
Open

_Alignas(x) does not work with custom types #472

vit9696 opened this issue Sep 6, 2022 · 2 comments

Comments

@vit9696
Copy link
Contributor

vit9696 commented Sep 6, 2022

typedef int test_int;

typedef struct
{
  _Alignas(int) _Atomic test_int a1;
  int a2;
} test_struct;

Adding the following sequence to c11.c causes the following error:

======================================================================
ERROR: test_c11_with_cpp (tests.test_general.TestParsing)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/user/Developer/pycparser/tests/test_general.py", line 62, in test_c11_with_cpp
    ast = parse_file(self._find_file('c11.c'), use_cpp=True,
  File "/Users/user/Developer/pycparser/pycparser/__init__.py", line 90, in parse_file
    return parser.parse(text, filename)
  File "/Users/user/Developer/pycparser/pycparser/c_parser.py", line 147, in parse
    return self.cparser.parse(
  File "/Users/user/Developer/pycparser/pycparser/ply/yacc.py", line 331, in parse
    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
  File "/Users/user/Developer/pycparser/pycparser/ply/yacc.py", line 1199, in parseopt_notrack
    tok = call_errorfunc(self.errorfunc, errtoken, self)
  File "/Users/user/Developer/pycparser/pycparser/ply/yacc.py", line 193, in call_errorfunc
    r = errorfunc(token)
  File "/Users/user/Developer/pycparser/pycparser/c_parser.py", line 1931, in p_error
    self._parse_error(
  File "/Users/user/Developer/pycparser/pycparser/plyparser.py", line 67, in _parse_error
    raise ParseError("%s: %s" % (coord, msg))
pycparser.plyparser.ParseError: /Users/user/Developer/pycparser/tests/c_files/c11.c:25:34: before: a1

----------------------------------------------------------------------
Ran 130 tests in 6.860s

FAILED (errors=1)
@vit9696 vit9696 changed the title _Atomic does not work with custom types _Alignas(x) does not work with custom types Sep 6, 2022
@vit9696
Copy link
Contributor Author

vit9696 commented Sep 6, 2022

It is enough to use:

typedef int test_int;

typedef struct
{
  _Alignas(int) test_int a1;
  int a2;
} test_struct;

for this issue to reproduce. The issue is actually with _Alignas, not with _Atomic.

@vit9696
Copy link
Contributor Author

vit9696 commented Sep 6, 2022

@eliben, I have a suspect the issue is caused by:

    def p_declaration_specifiers_7(self, p):
        """ declaration_specifiers  : declaration_specifiers alignment_specifier
        """
        p[0] = self._add_declaration_specifier(p[1], p[2], 'alignment', append=True)

The error feels like after we parse alignment we believe our type declaration is complete, and test_int is read as a variable name. However, so far I cannot easily deduce what exactly is wrong.

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

1 participant