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

Parameterized gcc Attributes are pretty-printed with erroneous parentheses #47

Open
200sc opened this issue May 31, 2017 · 9 comments
Open

Comments

@200sc
Copy link
Contributor

200sc commented May 31, 2017

An attribute like __attribute__(name(arg1, arg2)) is currently being written by ableC as __attribute__((name(arg1,(arg2)))), but this is invalid syntax.

The specific example that brought this up was posix_memalign on osx in stdlib.h. Including this will raise this error (as in the matlab extension):

simple_cat.c:838:95: error: expected 'introduced', 'deprecated', or 'obsoleted'
signed int posix_memalign(void  * * , size_t  , size_t  ) __attribute__((availability(macosx, ((introduced) = 10.6))));

Removing the extra parentheses (after availability) will let gcc run the file.

Ideally we'd catch something like this in the future by adding in some tests that run on or simulate an osx environment.

This TODO: mentioned in VariableAttributes.sv looks like it could solve this bug.

@remexre
Copy link
Member

remexre commented May 31, 2017

The cause looks to be

https://github.com/melt-umn/ableC/blob/develop/edu.umn.cs.melt.ableC/abstractsyntax/Expr.sv#L46

abstract production declRefExpr
top::Expr ::= id::Name
{
  ...
  top.pp = parens( id.pp );
  ...
}

We parenthesize all expressions except literals (as far as I can tell from quickly skimming) to avoid implementing precedence, so we could implement that to fix this.

Alternatively, Patrick is writing a helper that maps over the ExprList and returns declRefExpr's id's pp instead of its own, which should also fix the case where an attribute requires an identifier (rather than an expression). Literals don't get parenthesized either, so they should be fine as well.

Lastly, we could make declRefExpr's pp always be id.pp without parentheses -- I tried that, but I got every single positive test failing, so I assume something's wrong in my setup. (Or my running of the tests; it's testing/runTests, right?)

@200sc
Copy link
Contributor Author

200sc commented May 31, 2017

We tested on a mac if availability(macosx, (introduced = 10.6)) would run, and it did not, meaning that just removing parens from declRefExpr wouldn't be a fix, unfortunately.

@krame505
Copy link
Member

krame505 commented Jun 1, 2017 via email

@krame505 krame505 changed the title Parameterized gcc Attributes are written with erroneous parentheses Parameterized gcc Attributes are pretty-printed with erroneous parentheses Jun 1, 2017
@ericvanwyk
Copy link
Contributor

ericvanwyk commented Jun 1, 2017 via email

@tedinski
Copy link
Member

tedinski commented Jun 1, 2017

I don't really know, sorry.

@200sc
Copy link
Contributor Author

200sc commented Jun 1, 2017

I can't find an attribute that isn't obscure-platform specific outside of clang's attributes that ableC currently fails to parse, so its fair to call this a mac issue and wait on it.

@krame505
Copy link
Member

krame505 commented Jun 1, 2017 via email

@remexre
Copy link
Member

remexre commented Jun 1, 2017 via email

@krame505
Copy link
Member

krame505 commented Jun 1, 2017 via email

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

5 participants