Git Product home page Git Product logo

Comments (5)

leepike avatar leepike commented on September 23, 2024

Yes, this is a known problem that is at the intersection of common subexpression elimination (CSE) and ifdefs. The CSE helps with readability and code size dramatically.

I would suggest using -Wno-unused-variable; for Ivory generated code, those warnings shouldn't be needed to find bugs.

I would prefer not to decide at Ivory compile-time whether to to use assertions or not, so that the same generated code can be used with or without assertions.

Do you have another proposed solution?

from ivory.

sergei-mironov avatar sergei-mironov commented on September 23, 2024

Well, I thought about re-definition of macros using popular cast-to-void trick[1] in the following manner:

#define COMPILER_ASSERTS(arg) ((void) (arg))

AFAIK, with this declaration compiler has a chance to keep the arg expression in final code, but in practice it optimizes it out. Further research is needed.

[1] http://stackoverflow.com/questions/4178695/c-what-is-the-purpose-of-casting-to-void

from ivory.

leepike avatar leepike commented on September 23, 2024

I believe that would work. Would you mind testing and doing a pull request?

from ivory.

cblp avatar cblp commented on September 23, 2024

I don't believe (void)(something) will always work as expected, i. e. as nop. A better solution would be something like

#ifdef IVORY_TEST
    COMPILER_ASSERTS_BLOCK(init_block, cond) do { init_block; assert(cond) } while(0);
#else /* IVORY_TEST */
    COMPILER_ASSERTS_BLOCK(init_block, cond)
#endif /* IVORY_TEST */
COMPILER_ASSERTS_BLOCK(
    (
        int32_t n_cse1 = (int32_t) -(int32_t) 1;
    ),
    ((bool) ((bool) ((int32_t) 0 < (int32_t) 1024) && (bool) (n_cse1 <= (int32_t) 0)))
);

from ivory.

leepike avatar leepike commented on September 23, 2024

@cblp, but then the Ivory common subexpression elimination pass, creating n_cse1, needs to know if the variable is only used within the assertion, I think. While this is possible, it starts complicating the (Ivory) compiler. If we want to go down that path, we might as well make the use of assertions be something that has to be given at Ivory compile-time. As mentioned, I think it's preferable to defer that decision to C compile-time.

from ivory.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.