-
Notifications
You must be signed in to change notification settings - Fork 30
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
Fix handling of empty type #776
Conversation
I noticed this regression when running the svcomp benchmarks. The fix restores the previous behavior. @natgavrilenko can you please review? |
There is nothing to review really. The empty struct is 1-aligned but #776 changed the behaviour to throw an error instead. |
I don't see why it would change the behavior. The getAlignment method is called either from computeDefaultOffsets or from getMemorySizeInBytes. Both caller methods check if the AggregateType is empty. How can reproduce the problem? |
Try this file. It should be reproducible with all memory models. |
I just noticed that the commit message of this PR is wrong (it seems I accidentally took the one from #775). Not sure how that happened. |
Btw. I think this part of the alignment computation is wrong (*) as well:
The array should be aligned according to the alignment of its elements, not their size. (*) This might technically not wrong because we simply overalign. But it does not match the usually expected alignment. |
Actually, there are more issues. (1) The behaviour of (2) In C, empty structs are undefined behavior, at least in theory!!! The SVCOMP benchmark is thus problematic. GCC allows empty structs as a custom extension and gives them size 0, and since Clang tries to be compatible with GCC, it shows the same behaviour. EDIT: I fixed the above mentioned issues. |
Fixed alignment computation of arrays. Added TypeFactory.hasKnownSize helper function.
If empty structures are undefined behavior, we should report this and throw an exception when verifying C code. @natgavrilenko what does the spirv standard say about empty structures? Can we have "This is UB" as a general solution? |
Thanks, now I see what is the problem. |
Yes, it works fine for spirv with empty structures. @ThomasHaas could you add this case to AggregateTypeTest? |
I think this solution is not practically viable because its a feature that is expected to work since GCC/Clang support it. One might say it is more implementation-defined in practice rather than undefined. On top of that you have the issue that we are technically parsing LLVM and not C directly, and so it makes sense to take LLVM semantics into account. For LLVM, empty structs are not an issue it seems. |
will do. |
This fixes a bug introduced in #770.
EDIT: I renamed the PR and added more fixes, mostly related to handling the empty type (+ one fix for alignments computation of arrays).