Hi Chris
you’re right only in your last part that clang isn’t my problem
there were much better explanation what’s going on, you should learn from other people how to answer questions.
there was magical word tradeoff, that you clearly missed. Theoretically clang isn’t right, because my initial code should behave identically for debug and release build
and malloc *can* return NULL and therefore clang is inconsistent.
but if we take into consideration all explanations that people gave here clang behavior is reasonable for all practical purposes
every vendor can implement standard in the different level of accuracy. No one will kill vendor if its implementation isn’t 100% standard compliant
as long as normal explanations were given (thanks Jens, Clark, Carl, Steve and others) I’m ok,
so frankly you’re wrong that I don’t agree I do agree.
in relation to clang, we reported many bug reports and some were fixed, so we don’t have to deal with clang all the time, sometimes clang has to deal with us :)
the same is true for Apple, Microsoft, boost, ICU, sqlite and many other vendors, so please Chris don’t teach me how to deal with clang and when and how report bug reports
otherwise thank you very much for your answer
dm
On Jul 4, 2016, at 11:27 PM, Chris Cleeland < email@hidden> wrote:
Whether you agree or disagree with what clang does, it doesn't matter. clang is doing what it is doing; *YOU* have to deal with it in your code.
Your contrived example is not at all like the example you provided where the pointers in a struct-returned-by-value are assigned to the return value of malloc(). In the contrived example clang is well within its rights to optimize out the call to malloc as has been explained well by others (yes, I know you don't agree but that honestly doesn't matter because, frankly, you're wrong in that regard).
I think that if you want to report a bug, you need to model things after your more complicated example because based solely on what you show it seems less likely that the optimizer has enough information to optimize out a malloc.
If you really want to know how much space is available for heap allocation, you're going to have to try to touch every page in your requested set. Even then there would be cases you can't accommodate such as when memory gets freed up you wouldn't know about it.
To really do this correctly, you are going to have to dive down and get intimate with the VM subsystem of each OS on which you run, and hopefully create an abstraction over it that permits you to do what you feel you need.
But, at this point, based on the evidence, clang is not your problem.
|