Comments (5)
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.
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.
I believe that would work. Would you mind testing and doing a pull request?
from ivory.
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.
@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)
- Invalid code generated: initialization discards βconstβ qualifier from pointer target type HOT 9
- Hackage build failed HOT 4
- The documentation for the latest version of this package is missing on Hackage. HOT 2
- Question: Using "Simple" Sum Types in Ivory HOT 2
- Why `deref` is effectful? HOT 7
- Add support for template-haskell-2.12 HOT 1
- Constant assertions
- Remove `IvoryZero` constraint from `ifte` and `cond`
- Travis entry for 7.10 looks invalid
- http://ivorylang.org seems down HOT 1
- How to actually run the tutorial? HOT 1
- ivory-backend-acl2 can not work
- Incompatibility with newer versions of base-compat and monadLib HOT 1
- The documentation for the latest version of `ivory-backend-c` is missing on Hackage. HOT 3
- ProcPtrs and Refs in MemAreas
- Remove noop casts in the C code HOT 4
- Finish/integrate new model-checker
- Generalize Ivory memory model
- Ivory module system improvements
- cvc4 errors in local test HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ivory.