Repository navigation
CAML*alloc macros: remove unused variadic argument - #14238
Conversation
|
Assigning to @MisterDA as a C standards compliance expert. (Well, I can't seem to be able to actually assign the PR to him...) |
|
I believe this was part of #13777. There seems to also be more than just these macros (but maybe the branch is too old and that's not the case anymore) |
Indeed, thanks for the pointer. From a quick glance, I think the present PR is complete with regards to these macros, but I will take a closer look later. |
It's a work in progress ;-) I wasn't aware of the problem with variadic macros at the time.
I'm not a core dev! (cf ⬆️ )
Yep, that's 0b01951. No, I don't think that the branch is too old. The C11 atomic issue has been resolved, and the thread_local issue is being addressed. |
Varadic macros expect at least one parameter for the variadic part (at
least until C++20). They were used to allow for possible future
extension by adding more parameters.
/Users/antonin/Tarides/ocaml/trunk/runtime/caml/memory.h:89:32: error: ISO C++11 requires at least one argument for the "..." in a variadic macro [-Werror]
89 | CAMLmalloc(caml_stat_free, 1, 1) CAMLreturns_nonnull()
| ^
0646fc1 to
aec2c9f
Compare
Thanks for the pointer. I replaced my patch by a straight up cherry-pick of your commit and added a |
MisterDA
left a comment
There was a problem hiding this comment.
My concern when I added the variadic macros was to account for future extensibility. Maybe we could add a note saying that the macros are reserved for call headers only and should not be used by 3rd-party code?
You have - as you did - to trick him into commenting and then he can be assigned 😈 |
Polite ping @Octachron: |
|
While this PR reduces the number of false positive warnings emitted by C compilers, my opinion is that the root mistake in the opam-repository is the use of |
|
Apologies, given that the original change was introduced in 5.4 (#13537), I should have cherry-picked this after merging. I agree with @Octachron's assessment, though - however, after 5.4.0 is released, I think we should cherry-pick this to the 5.4 branch just so it can be picked up in a 5.4.1. |
|
Context: This is fully embedded stub library code that was failing - the merger of a popular zip library and OCaml. The zip library uses the I'll dump a couple notes from the Open Source Security Foundation (https://best.openssf.org/Compiler-Hardening-Guides/Compiler-Options-Hardening-Guide-for-C-and-C++.html):
Going by that, the real root cause is that ocaml/ocaml test processes do not include "instrumented test code" where undefined behavior and other bugs are regularly caught by I am quite uncomfortable ignoring real errors that are being uncovered by
What do you think? |
|
I authored a change in Dune that automatically adds
The problem can also be fixed by patching end-users build systems, like Dune, rather than the compiler itself. |
Interesting. Although I'm unsure how comparable OCaml warnings are to C warnings. (related thought: It is rare to find C build tools that don't distinguish between debug and release flags. The major anomaly was autoconf/automake which never standardized a way to split them. Maybe this makes it hard for OCaml? If so, this isn't a small PR discussion.)
How would that work in end-user build systems? To get debug support in MSVC+OCaml today, I have to patch the compiler (https://github.com/diskuv/dkml-compiler/blob/6032af38f19b2d15c45145bd0fef3a9265a2f901/src/p/ocaml-common-4_14-a05-msvccflags.patch) to remove the If you are suggesting that Dune and other build systems parse the C flags provided by |
Am I correct in understanding the return of
That could be considered a bug in
From Dune's Flags in Foreign Code
Using Dune's Ordered Set Language one can build the list of flags, in particular remove a flag from the maybe it can be extended to exclude flags. |
|
Just in case the way at @Octachron and I were expressing things makes it look we're passing the buck completely, I definitely agree that testing on ocaml/ocaml not catching this issue earlier was bad, and anything which can improve this is a good idea (I'm not sure if our sanitizers checks were running this or not, or were catching and were being ignored, cf. https://ci.inria.fr/ocaml/job/sanitizers/). Our own CI - and any working on a dev version of OCaml - is always done with |
|
I have not managed to figure out what configure options the main CI (on GitHub workers) is using:
Just my 2 cents |
|
The compiler itself cannot (currently) be built in pedantic mode as we are using extensions such as casting function pointers to object pointers, passing non |
|
Please do use This could be achieved in @dra27 , Nevertheless taking in account that the variadiac argument was added to those macros in 5.4, and there are removed in trunk, I think that there is a good argument to cherry-pick this change in the 5.4 release candidate. From my point of view, this would simplify the maintenance in the long term to avoiding a transient complexity for just one released version. Similarly, I am not sure if it is a good idea to add the well-named |
A possible starting point, from a while ago: dd1197b ;)
I was slightly wrong here. To get access to these extensions we'd need to specify the GNU C dialect with |
|
Thanks @Octachron but you don't need to send a PR since that change is trivial. More importantly, I'll eventually add a development CI job for ocaml/ocaml+patches in my own test cluster, and can restrict the range of |
CAML*alloc macros: remove unused variadic argument (cherry picked from commit 27ccbcc)
|
Cherry-picked to the 5.4 branch as 59ca319 to avoid ephemeral complexity. It will be part of the final release of 5.4 . |
There are some macros in
misc.h(or rather, their callsites) which are not strictly valid according to C99:This warning does not trigger in the compiler build because not enough warnings are enabled. But since this header is liable to be included in user code which may be compiled with more strict warnings, I think it would be a good idea to fix this, as per this PR.