Skip to content

Commit e6c4e1e

Browse files
authored
Fix typecast for int64_t type (#942)
* Fix typecast for int64_t type
1 parent 6e41875 commit e6c4e1e

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

Cesium.CodeGen/Extensions/TypeSystemEx.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ public static bool IsSignedInteger(this IType t)
232232
|| t.IsEqualTo(CTypeSystem.Short)
233233
|| t.IsEqualTo(CTypeSystem.Int)
234234
|| t.IsEqualTo(CTypeSystem.Long)
235+
|| t.IsEqualTo(CTypeSystem.LongLong)
235236
|| t.IsEqualTo(CTypeSystem.NativeInt);
236237
}
237238

@@ -275,7 +276,7 @@ public static IType GetCommonNumericType(IType a, IType b)
275276

276277
// Otherwise, if both operands have signed integer types or both have unsigned integer types,
277278
// the operand with the type of lesser integer conversion rank is converted to the type of the operand with greater rank.
278-
var signedTypes = new[] { CTypeSystem.SignedChar, CTypeSystem.Short, CTypeSystem.Int, CTypeSystem.Long, CTypeSystem.NativeInt};
279+
var signedTypes = new[] { CTypeSystem.SignedChar, CTypeSystem.Short, CTypeSystem.Int, CTypeSystem.Long, CTypeSystem.LongLong, CTypeSystem.NativeInt};
279280
var unsignedTypes = new[] { CTypeSystem.Char, CTypeSystem.UnsignedChar, CTypeSystem.UnsignedShort, CTypeSystem.Unsigned, CTypeSystem.UnsignedInt, CTypeSystem.UnsignedLong, CTypeSystem.NativeUInt };
280281
// TODO[#381]: Move NativeInt and NativeUInt accordingly or consider them properly based on the current architecture.
281282

Cesium.CodeGen/Ir/Types/CTypeSystem.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public static bool IsConversionAvailable(IType type, IType targetType)
4848
return true;
4949
else if (targetType.Equals(Long))
5050
return true;
51+
else if (targetType.Equals(LongLong))
52+
return true;
5153
else if (targetType.Equals(Char))
5254
return true;
5355
else if (targetType.Equals(UnsignedShort))
@@ -86,6 +88,8 @@ public static bool IsConversionRequired(IType type, IType targetType)
8688
return !type.Equals(Bool);
8789
else if (targetType.Equals(Long))
8890
return true;
91+
else if (targetType.Equals(LongLong))
92+
return false;
8993
else if (targetType.Equals(Char))
9094
return true;
9195
else if (targetType.Equals(UnsignedShort))

Cesium.IntegrationTests/type_casts.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#include <stddef.h>
8+
#include <stdint.h>
89

910
typedef struct foo_t
1011
{
@@ -58,5 +59,9 @@ int main(void)
5859

5960
unsigned x = (unsigned)2;
6061

62+
int64_t p = 10;
63+
int64_t r = o;
64+
if (p != 10) return -2;
65+
6166
return 42;
6267
}

0 commit comments

Comments
 (0)