mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
translate-c: Fix #12263
This commit is contained in:
parent
02fff6fd01
commit
2ca503ec05
2 changed files with 34 additions and 37 deletions
|
|
@ -910,7 +910,7 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
|
|||
},
|
||||
.call => {
|
||||
const payload = node.castTag(.call).?.data;
|
||||
const lhs = try renderNode(c, payload.lhs);
|
||||
const lhs = try renderNodeGrouped(c, payload.lhs);
|
||||
return renderCall(c, lhs, payload.args);
|
||||
},
|
||||
.null_literal => return c.addNode(.{
|
||||
|
|
|
|||
|
|
@ -891,42 +891,39 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void {
|
|||
\\}
|
||||
, "");
|
||||
|
||||
if (@import("builtin").zig_backend == .stage1) {
|
||||
// https://github.com/ziglang/zig/issues/12263
|
||||
cases.add("Obscure ways of calling functions; issue #4124",
|
||||
\\#include <stdlib.h>
|
||||
\\static int add(int a, int b) {
|
||||
\\ return a + b;
|
||||
\\}
|
||||
\\typedef int (*adder)(int, int);
|
||||
\\typedef void (*funcptr)(void);
|
||||
\\int main() {
|
||||
\\ if ((add)(1, 2) != 3) abort();
|
||||
\\ if ((&add)(1, 2) != 3) abort();
|
||||
\\ if (add(3, 1) != 4) abort();
|
||||
\\ if ((*add)(2, 3) != 5) abort();
|
||||
\\ if ((**add)(7, -1) != 6) abort();
|
||||
\\ if ((***add)(-2, 9) != 7) abort();
|
||||
\\
|
||||
\\ int (*ptr)(int a, int b);
|
||||
\\ ptr = add;
|
||||
\\
|
||||
\\ if (ptr(1, 2) != 3) abort();
|
||||
\\ if ((*ptr)(3, 1) != 4) abort();
|
||||
\\ if ((**ptr)(2, 3) != 5) abort();
|
||||
\\ if ((***ptr)(7, -1) != 6) abort();
|
||||
\\ if ((****ptr)(-2, 9) != 7) abort();
|
||||
\\
|
||||
\\ funcptr addr1 = (funcptr)(add);
|
||||
\\ funcptr addr2 = (funcptr)(&add);
|
||||
\\
|
||||
\\ if (addr1 != addr2) abort();
|
||||
\\ if (((int(*)(int, int))addr1)(1, 2) != 3) abort();
|
||||
\\ if (((adder)addr2)(1, 2) != 3) abort();
|
||||
\\ return 0;
|
||||
\\}
|
||||
, "");
|
||||
}
|
||||
cases.add("Obscure ways of calling functions; issue #4124",
|
||||
\\#include <stdlib.h>
|
||||
\\static int add(int a, int b) {
|
||||
\\ return a + b;
|
||||
\\}
|
||||
\\typedef int (*adder)(int, int);
|
||||
\\typedef void (*funcptr)(void);
|
||||
\\int main() {
|
||||
\\ if ((add)(1, 2) != 3) abort();
|
||||
\\ if ((&add)(1, 2) != 3) abort();
|
||||
\\ if (add(3, 1) != 4) abort();
|
||||
\\ if ((*add)(2, 3) != 5) abort();
|
||||
\\ if ((**add)(7, -1) != 6) abort();
|
||||
\\ if ((***add)(-2, 9) != 7) abort();
|
||||
\\
|
||||
\\ int (*ptr)(int a, int b);
|
||||
\\ ptr = add;
|
||||
\\
|
||||
\\ if (ptr(1, 2) != 3) abort();
|
||||
\\ if ((*ptr)(3, 1) != 4) abort();
|
||||
\\ if ((**ptr)(2, 3) != 5) abort();
|
||||
\\ if ((***ptr)(7, -1) != 6) abort();
|
||||
\\ if ((****ptr)(-2, 9) != 7) abort();
|
||||
\\
|
||||
\\ funcptr addr1 = (funcptr)(add);
|
||||
\\ funcptr addr2 = (funcptr)(&add);
|
||||
\\
|
||||
\\ if (addr1 != addr2) abort();
|
||||
\\ if (((int(*)(int, int))addr1)(1, 2) != 3) abort();
|
||||
\\ if (((adder)addr2)(1, 2) != 3) abort();
|
||||
\\ return 0;
|
||||
\\}
|
||||
, "");
|
||||
|
||||
cases.add("Return boolean expression as int; issue #6215",
|
||||
\\#include <stdlib.h>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue