mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 21:00:13 +01:00
Properly dump SemIR for inline C++ imports (#6001)
Dumping SemIR crashed on inline C++ imports and this outputs `import Cpp inline` instead. Followup of #5904.
This commit is contained in:
@@ -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: <namespace> = 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: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user