修正了一些错误
This commit is contained in:
@@ -336,6 +336,19 @@ class ExprOpsHandle(BaseHandle):
|
||||
}
|
||||
result: bool = cmp_map.get(ComparatorSymbol, False)
|
||||
return ir.Constant(ir.IntType(1), 1 if result else 0)
|
||||
# is / is not: 值类型(IntType)与 None(空指针常量)比较
|
||||
# 值类型(如 i8/i32)永远不可能为 None,因此:
|
||||
# - 值类型 is None → 恒为 false (i1 0)
|
||||
# - 值类型 is not None → 恒为 true (i1 1)
|
||||
# 此检查必须在类型对齐之前,否则类型对齐会对 i8* null 执行 load(空指针解引用)导致崩溃
|
||||
if ComparatorSymbol in ('is', 'is not'):
|
||||
LeftIsNullPtr: bool = isinstance(LeftVal, ir.Constant) and LeftVal.constant is None and isinstance(LeftVal.type, ir.PointerType)
|
||||
RightIsNullPtr: bool = isinstance(RightVal, ir.Constant) and RightVal.constant is None and isinstance(RightVal.type, ir.PointerType)
|
||||
LeftIsValueType: bool = isinstance(LeftVal.type, ir.IntType)
|
||||
RightIsValueType: bool = isinstance(RightVal.type, ir.IntType)
|
||||
if (LeftIsValueType and RightIsNullPtr) or (RightIsValueType and LeftIsNullPtr):
|
||||
IsNotResult: int = 1 if ComparatorSymbol == 'is not' else 0
|
||||
return ir.Constant(ir.IntType(1), IsNotResult)
|
||||
if isinstance(LeftVal.type, ir.IntType) and isinstance(RightVal.type, ir.IntType):
|
||||
if LeftVal.type.width < RightVal.type.width:
|
||||
# 如果宽类型常量值超出窄类型有符号范围,则必须用zext
|
||||
|
||||
Reference in New Issue
Block a user