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

glibc's assert(3) expansion causes most functions to be omitted #24

Closed
ctz opened this issue Aug 29, 2018 · 3 comments
Closed

glibc's assert(3) expansion causes most functions to be omitted #24

ctz opened this issue Aug 29, 2018 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@ctz
Copy link

ctz commented Aug 29, 2018

Thanks for this, this is a very interesting project.

I'm translating a large single file project, where most functions validate arguments using assert(3). All these functions are omitted from the generated rust. That was confusing me for a while, until I discovered the -a="--fail-on-error" option which gives a hint in the logfile:

DEBUG:root:thread 'main' panicked at 'Failed translating declaration due to error:
Statement expression didn't end in an expression: If { scrutinee: CExprId(13370),
true_variant: CStmtId(13371), false_variant: Some(CStmtId(13372)) },
kind: Some(Function { is_extern: false, is_inline: false, is_implicit: false,
typ: CTypeId(2606), name: "tdefl_flush_block",
parameters: [CDeclId(2609), CDeclId(2610)], body: Some(CStmtId(2608)) })',
src/translator.rs:251:9

That's weird, I thought, because this function contains no expression-flavour if statements. But it's actually the asserts, because glibc's assert here looks like:

#  define assert(expr)							\
  ((void) sizeof ((expr) ? 1 : 0), __extension__ ({			\
      if (expr)								\
        ; /* empty */							\
      else								\
        __assert_fail (#expr, __FILE__, __LINE__, __ASSERT_FUNCTION);	\
    }))

Preprocessing-out asserts with -DNDEBUG fixes this.

@thedataking thedataking added the bug Something isn't working label Aug 29, 2018
@thedataking
Copy link
Contributor

Hi @ctz, thanks for the report and words of encouragement! We'll get support for asserts fixed.

@glguy
Copy link
Contributor

glguy commented Aug 29, 2018

Reduced example

void example(void) {
  ({if (1) ; else { int x = 0; }});
}

@glguy glguy self-assigned this Aug 29, 2018
@glguy
Copy link
Contributor

glguy commented Aug 30, 2018

Fix coming in 3745142

@glguy glguy closed this as completed Aug 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants