authorgravatar for carl@astholm.seCarl Åstholm <carl@astholm.se> 2023-09-05 17:41:53+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-09-06 11:12:32+03:00
loge980bd0aeedff7841882373b42a036c1c985e28f
treeb9c11ea71d42dc32c5e14c136f0f614b384dda7c
parentd1a14e7b6d90a0f285dead85c72a9ac73dd692bd

translate-c: fix panic when translating long double literals


2 files changed, 17 insertions(+), 3 deletions(-)

src/clang.zig+3-1
......@@ -110,9 +110,11 @@ pub const APFloatBaseSemantics = enum(c_int) {
110110 BFloat,
111111 IEEEsingle,
112112 IEEEdouble,
113 x86DoubleExtended,
114113 IEEEquad,
115114 PPCDoubleDouble,
115 Float8E5M2,
116 Float8E4M3FN,
117 x87DoubleExtended,
116118};
117119
118120pub const APInt = opaque {
test/translate_c.zig+14-2
......@@ -1205,7 +1205,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
12051205 \\#define baz 1e1
12061206 \\#define BAZ 42e-3f
12071207 \\#define foobar -73.L
1208 , &[_][]const u8{
1208 \\extern const float my_float = 1.0f;
1209 \\extern const double my_double = 1.0;
1210 \\extern const long double my_longdouble = 1.0l;
1211 , &([_][]const u8{
12091212 "pub const foo = @as(f32, 3.14);",
12101213 "pub const bar = @as(c_longdouble, 16.0e-2);",
12111214 "pub const FOO = @as(f64, 0.12345);",
......@@ -1213,7 +1216,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
12131216 "pub const baz = @as(f64, 1e1);",
12141217 "pub const BAZ = @as(f32, 42e-3);",
12151218 "pub const foobar = -@as(c_longdouble, 73.0);",
1216 });
1219 "pub export const my_float: f32 = 1.0;",
1220 "pub export const my_double: f64 = 1.0;",
1221 } ++ if (@bitSizeOf(c_longdouble) != 64) .{
1222 // TODO properly translate non-64-bit long doubles
1223 "source.h:10:42: warning: unsupported floating point constant format",
1224 "source.h:10:26: warning: unable to translate variable initializer, demoted to extern",
1225 "pub extern const my_longdouble: c_longdouble;",
1226 } else .{
1227 "pub export const my_longdouble: c_longdouble = 1.0;",
1228 }));
12171229
12181230 cases.add("macro defines hexadecimal float",
12191231 \\#define FOO 0xf7p38