alexfru wrote:You may have UB. The problem with UB is that it's become a creeping UB, where UB effects may appear far away from the operation actually causing it.
Yeah, I know, I just failed to see where the UB was. That's the problem, despite your best efforts and tests you can never state for sure that your code is totally UB-free.
Octocontrabass wrote:In other words, the value (%rsp+8) is always a multiple of 16 (32) when control is transferred to the function entry point.
That actually helps. The spec is not clear (not for a non-native English speaker at least). I thought that "stack alignment on function call" refers to the environment when the first byte of the function is executed. So they actually meant (%rsp & 0xF == 8 ) when they talked about aligned stack, that's strange, but explains, thanks. Let's hope that it won't mess up other (currently working) functions.
Octocontrabass wrote:It sounds like what you want is a compiler for a language like C, but without all of the design pitfalls.
That came up on LWN too. Nope, I don't want to drop C, I just want to minimize the possibility that a compiler silently miscompiles. From the LWN:
Haase said:
Compiler developers, for better or worse, reserve the right to do whatever they want with undefined behavior, and it's up to the person writing the C code to not include undefined behavior in their own program.
The problem for programmers is a lack of warnings about these kinds of undefined constructs, Wise said. "Every use of undefined behaviour should at minimum result in a compiler warning." But even doing that is difficult (and noisy), Wade Richards said
As a conclusion, there are no warnings, so you could never know if the compiler is really compiling what you wanted. Without optimizations, your chances are much better.
Solar wrote:Could it be that your proc_struct is a / contains bitfields?
Nope, I don't use bitfields at all because you can't refer to them from Assembly. I prefer bitwise operators and defines like "#define FIELD_SOMETHING (1<< 5)", and for C, macros like "#define FIELD_IsSomething(x) ((x)&FIELD_SOMETHING)". Much clearer and readable IMHO, also you don't have to double the definitions for gas. I like to keep my code
DRY.
Solar wrote:bzt is convinced that it's the compiler to blame, so he completely stopped looking for, or even considering, fault of his own.
Why are you making personal insults? As I've asked you politely, don't focus on my examples, focus on the fact, that C has things that compilers can silently compile differently. Which is a well-known fact, not "me blaming the compiler". Where did you get that?
What I'm really after is something like John von Neumann's essay on how to achieve deterministic results on undeterministic machines, but for C compilers. As I've said, avoiding an optimizer seems to increase your odds. But maybe this kind of theoretical discussion is out of your league (no offense of any kind meant, it's just you stuck at an example and failed to see the big picture. As the saying goes: "You can't see the forest because of a tree").
Cheers,
bzt