translate-c: take address of functions before passing them to @ptrToInt

Fixes #12194
This commit is contained in:
Evan Haas
2022-07-25 09:53:40 -07:00
committed by Veikka Tuominen
parent c8c798685f
commit 7ba1f9bfb5
7 changed files with 66 additions and 5 deletions

View File

@@ -1861,4 +1861,18 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void {
\\ return 0;
\\}
, "");
// The C standard does not require function pointers to be convertible to any integer type.
// However, POSIX requires that function pointers have the same representation as `void *`
// so that dlsym() can work
cases.add("Function to integral",
\\#include <stdint.h>
\\int main(void) {
\\#if defined(__UINTPTR_MAX__) && __has_include(<unistd.h>)
\\ uintptr_t x = main;
\\ x = (uintptr_t)main;
\\#endif
\\ return 0;
\\}
, "");
}