Skip to content
Closed
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
20 changes: 20 additions & 0 deletions toolchain/check/cpp/import.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1084,27 +1084,47 @@ static auto MakeIntType(Context& context, IntId size_id, bool is_signed)
static auto MapBuiltinIntegerType(Context& context, SemIR::LocId loc_id,
clang::QualType qual_type,
const clang::BuiltinType& type) -> TypeExpr {
// llvm::errs() << "A1 " << qual_type.getAsString() << "\n";
clang::ASTContext& ast_context = context.ast_context();
unsigned width = ast_context.getIntWidth(qual_type);
bool is_signed = type.isSignedInteger();
auto int_n_type = ast_context.getIntTypeForBitwidth(width, is_signed);
if (ast_context.hasSameType(qual_type, int_n_type)) {
// llvm::errs() << "A2\n";
TypeExpr type_expr =
MakeIntType(context, context.ints().Add(width), is_signed);
// Try to make sure integer types of 32 or 64 bits are complete so we can
// check against them when deciding whether we need to generate a thunk.
if (width == 32 || width == 64) {
// llvm::errs() << "A3\n";
SemIR::TypeId type_id = type_expr.type_id;
if (!context.types().IsComplete(type_id)) {
// llvm::errs() << "A4\n";
TryToCompleteType(context, type_id, loc_id);
}
}
return type_expr;
}
// llvm::errs() << "A5\n";
if (ast_context.hasSameType(qual_type, ast_context.CharTy)) {
// llvm::errs() << "A6\n";
return ExprAsType(context, Parse::NodeId::None,
MakeCharTypeLiteral(context, Parse::NodeId::None));
}
// llvm::errs() << "A7\n";
// Special handling for long long: map to a distinct Carbon type convertible
// to i64.
if (qual_type == context.ast_context().LongLongTy) {
// llvm::errs() << "A8\n";
// Create a distinct type for long long, convertible to i64.
// We'll use a custom type id for C++ long long.
// auto longlong_type_id = SemIR::CustomCppLongLongType::TypeInstId;
// 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
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_scope0: {inst: inst14, parent_scope: name_scope<none>, has_error: false, extended_scopes: [], names: {}}
// CHECK:STDOUT: name_scope0: {inst: inst15, parent_scope: name_scope<none>, has_error: false, extended_scopes: [], names: {}}
// CHECK:STDOUT: entity_names: {}
// CHECK:STDOUT: functions: {}
// CHECK:STDOUT: classes: {}
Expand All @@ -41,6 +41,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 @@ -50,14 +51,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: inst14: {kind: Namespace, arg0: name_scope0, arg1: inst<none>, type: type(inst(NamespaceType))}
// CHECK:STDOUT: inst15: {kind: Namespace, arg0: name_scope0, 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 @@ -67,13 +69,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: inst14: concrete_constant(inst14)
// CHECK:STDOUT: inst15: concrete_constant(inst15)
// 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_block4:
// CHECK:STDOUT: 0: inst14
// CHECK:STDOUT: 0: inst15
// CHECK:STDOUT: ...
Loading
Loading