Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions toolchain/check/cpp/import.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,18 @@ static auto MapBuiltinIntegerType(Context& context, SemIR::LocId loc_id,
return ExprAsType(context, Parse::NodeId::None,
MakeCharTypeLiteral(context, Parse::NodeId::None));
}

// Special handling for long long: map to a distinct Carbon type convertible
// to i64.
if (ast_context.hasSameType(qual_type, ast_context.LongLongTy)) {
// Create a distinct type for long long, convertible to i64.
// We'll use a custom type id for C++ long long.
GetOrAddInst(context,
SemIR::LocIdAndInst::NoLoc(SemIR::CustomCppLongLongType{
.type_id = SemIR::TypeType::TypeId}));
return ExprAsType(context, Parse::NodeId::None,
SemIR::CustomCppLongLongType::TypeInstId);
}
return TypeExpr::None;
}

Expand Down
3 changes: 3 additions & 0 deletions toolchain/check/cpp/type_mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ static auto MapNonWrapperType(Context& context, SemIR::InstId inst_id,
case SemIR::FloatLiteralType::Kind: {
return context.ast_context().DoubleTy;
}
case SemIR::CustomCppLongLongType::Kind: {
return context.ast_context().LongLongTy;
}
default: {
return clang::QualType();
}
Expand Down
10 changes: 6 additions & 4 deletions toolchain/check/testdata/basics/raw_sem_ir/builtins.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// CHECK:STDOUT: import_ir_insts: {}
// CHECK:STDOUT: clang_decls: {}
// CHECK:STDOUT: name_scopes:
// CHECK:STDOUT: name_scope00000000: {inst: inst0000000E, parent_scope: name_scope<none>, has_error: false, extended_scopes: [], names: {}}
// CHECK:STDOUT: name_scope00000000: {inst: inst0000000F, parent_scope: name_scope<none>, has_error: false, extended_scopes: [], names: {}}
// CHECK:STDOUT: entity_names: {}
// CHECK:STDOUT: cpp_global_vars: {}
// CHECK:STDOUT: functions: {}
Expand All @@ -42,6 +42,7 @@
// CHECK:STDOUT: 'inst(BoolType)': {kind: BoolType, type: type(TypeType)}
// CHECK:STDOUT: 'inst(BoundMethodType)': {kind: BoundMethodType, type: type(TypeType)}
// CHECK:STDOUT: 'inst(CharLiteralType)': {kind: CharLiteralType, type: type(TypeType)}
// CHECK:STDOUT: 'inst(CustomCppLongLongType)': {kind: CustomCppLongLongType, type: type(TypeType)}
// CHECK:STDOUT: 'inst(ErrorInst)': {kind: ErrorInst, type: type(Error)}
// CHECK:STDOUT: 'inst(FloatLiteralType)': {kind: FloatLiteralType, type: type(TypeType)}
// CHECK:STDOUT: 'inst(ImplWitnessTablePlaceholder)': {kind: ImplWitnessTablePlaceholder, type: type(TypeType)}
Expand All @@ -51,14 +52,15 @@
// CHECK:STDOUT: 'inst(SpecificFunctionType)': {kind: SpecificFunctionType, type: type(TypeType)}
// CHECK:STDOUT: 'inst(VtableType)': {kind: VtableType, type: type(TypeType)}
// CHECK:STDOUT: 'inst(WitnessType)': {kind: WitnessType, type: type(TypeType)}
// CHECK:STDOUT: inst0000000E: {kind: Namespace, arg0: name_scope00000000, arg1: inst<none>, type: type(inst(NamespaceType))}
// CHECK:STDOUT: inst0000000F: {kind: Namespace, arg0: name_scope00000000, arg1: inst<none>, type: type(inst(NamespaceType))}
// CHECK:STDOUT: constant_values:
// CHECK:STDOUT: values:
// CHECK:STDOUT: 'inst(TypeType)': concrete_constant(inst(TypeType))
// CHECK:STDOUT: 'inst(AutoType)': concrete_constant(inst(AutoType))
// CHECK:STDOUT: 'inst(BoolType)': concrete_constant(inst(BoolType))
// CHECK:STDOUT: 'inst(BoundMethodType)': concrete_constant(inst(BoundMethodType))
// CHECK:STDOUT: 'inst(CharLiteralType)': concrete_constant(inst(CharLiteralType))
// CHECK:STDOUT: 'inst(CustomCppLongLongType)': concrete_constant(inst(CustomCppLongLongType))
// CHECK:STDOUT: 'inst(ErrorInst)': concrete_constant(inst(ErrorInst))
// CHECK:STDOUT: 'inst(FloatLiteralType)': concrete_constant(inst(FloatLiteralType))
// CHECK:STDOUT: 'inst(ImplWitnessTablePlaceholder)': concrete_constant(inst(ImplWitnessTablePlaceholder))
Expand All @@ -68,13 +70,13 @@
// CHECK:STDOUT: 'inst(SpecificFunctionType)': concrete_constant(inst(SpecificFunctionType))
// CHECK:STDOUT: 'inst(VtableType)': concrete_constant(inst(VtableType))
// CHECK:STDOUT: 'inst(WitnessType)': concrete_constant(inst(WitnessType))
// CHECK:STDOUT: inst0000000E: concrete_constant(inst0000000E)
// CHECK:STDOUT: inst0000000F: concrete_constant(inst0000000F)
// CHECK:STDOUT: symbolic_constants: {}
// CHECK:STDOUT: inst_blocks:
// CHECK:STDOUT: inst_block_empty: {}
// CHECK:STDOUT: exports: {}
// CHECK:STDOUT: imports: {}
// CHECK:STDOUT: global_init: {}
// CHECK:STDOUT: inst_block00000004:
// CHECK:STDOUT: 0: inst0000000E
// CHECK:STDOUT: 0: inst0000000F
// CHECK:STDOUT: ...
Loading
Loading