diff --git a/toolchain/check/testdata/interop/cpp/inline.carbon b/toolchain/check/testdata/interop/cpp/inline.carbon index 36ff58f34f25..96f602621661 100644 --- a/toolchain/check/testdata/interop/cpp/inline.carbon +++ b/toolchain/check/testdata/interop/cpp/inline.carbon @@ -14,12 +14,14 @@ library "[[@TEST_NAME]]"; +//@dump-sem-ir-begin import Cpp inline ''' // A C++ function. inline void func() {} '''; +//@dump-sem-ir-end fn Run() { //@dump-sem-ir-begin @@ -31,12 +33,14 @@ fn Run() { library "[[@TEST_NAME]]"; +//@dump-sem-ir-begin import Cpp inline '''c++ // A C++ function. inline void another_func() {} '''; +//@dump-sem-ir-end fn Run() { //@dump-sem-ir-begin @@ -60,6 +64,12 @@ fn Run() { // CHECK:STDOUT: %func.decl: %func.type = fn_decl @func [concrete = constants.%func] {} {} // CHECK:STDOUT: } // CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: %Cpp.import_cpp = import_cpp { +// CHECK:STDOUT: import Cpp inline +// CHECK:STDOUT: } +// CHECK:STDOUT: } +// CHECK:STDOUT: // CHECK:STDOUT: fn @Run() { // CHECK:STDOUT: !entry: // CHECK:STDOUT: %Cpp.ref: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] @@ -84,6 +94,12 @@ fn Run() { // CHECK:STDOUT: %another_func.decl: %another_func.type = fn_decl @another_func [concrete = constants.%another_func] {} {} // CHECK:STDOUT: } // CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: %Cpp.import_cpp = import_cpp { +// CHECK:STDOUT: import Cpp inline +// CHECK:STDOUT: } +// CHECK:STDOUT: } +// CHECK:STDOUT: // CHECK:STDOUT: fn @Run() { // CHECK:STDOUT: !entry: // CHECK:STDOUT: %Cpp.ref: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] diff --git a/toolchain/sem_ir/formatter.cpp b/toolchain/sem_ir/formatter.cpp index ba49b098a15f..de7afd6ceee3 100644 --- a/toolchain/sem_ir/formatter.cpp +++ b/toolchain/sem_ir/formatter.cpp @@ -1210,10 +1210,16 @@ auto Formatter::FormatImportCppDeclRhs() -> void { OpenBrace(); for (ImportCpp import_cpp : sem_ir_->import_cpps().values()) { Indent(); - out_ << "import Cpp \"" - << FormatEscaped( - sem_ir_->string_literal_values().Get(import_cpp.library_id)) - << "\"\n"; + out_ << "import Cpp "; + if (import_cpp.library_id.has_value()) { + out_ << "\"" + << FormatEscaped( + sem_ir_->string_literal_values().Get(import_cpp.library_id)) + << "\""; + } else { + out_ << "inline"; + } + out_ << "\n"; } CloseBrace(); }