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) {...@@ -110,9 +110,11 @@ pub const APFloatBaseSemantics = enum(c_int) {
110 BFloat,110 BFloat,
111 IEEEsingle,111 IEEEsingle,
112 IEEEdouble,112 IEEEdouble,
113 x86DoubleExtended,
114 IEEEquad,113 IEEEquad,
115 PPCDoubleDouble,114 PPCDoubleDouble,
115 Float8E5M2,
116 Float8E4M3FN,
117 x87DoubleExtended,
116};118};
117119
118pub const APInt = opaque {120pub const APInt = opaque {
test/translate_c.zig+14-2
...@@ -1205,7 +1205,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1205,7 +1205,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1205 \\#define baz 1e11205 \\#define baz 1e1
1206 \\#define BAZ 42e-3f1206 \\#define BAZ 42e-3f
1207 \\#define foobar -73.L1207 \\#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{
1209 "pub const foo = @as(f32, 3.14);",1212 "pub const foo = @as(f32, 3.14);",
1210 "pub const bar = @as(c_longdouble, 16.0e-2);",1213 "pub const bar = @as(c_longdouble, 16.0e-2);",
1211 "pub const FOO = @as(f64, 0.12345);",1214 "pub const FOO = @as(f64, 0.12345);",
...@@ -1213,7 +1216,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1213,7 +1216,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1213 "pub const baz = @as(f64, 1e1);",1216 "pub const baz = @as(f64, 1e1);",
1214 "pub const BAZ = @as(f32, 42e-3);",1217 "pub const BAZ = @as(f32, 42e-3);",
1215 "pub const foobar = -@as(c_longdouble, 73.0);",1218 "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
1218 cases.add("macro defines hexadecimal float",1230 cases.add("macro defines hexadecimal float",
1219 \\#define FOO 0xf7p381231 \\#define FOO 0xf7p38