Support indirect C++ dependency by sharing domains more broadly (#7763)

Fixes #7731, at least under `--share-cpp-ast` which is expected to be
the future direction.

When --share-cpp-ast is enabled and any compilation unit has C++
imports, include all compilation units in the shared CppDomain inputs
and assign the domain to every unit. In ImportCpp, when a unit has no
direct C++ imports but is covered by a shared CppDomain, initialize
its C++ AST context and import namespace. This ensures units without
direct C++ imports have access to the C++ AST and code generator when
instantiating generics or referencing declarations from units that do.

Assisted-by: Antigravity with Gemini
This commit is contained in:
David Blaikie
2026-09-15 20:45:18 +00:00
committed by GitHub
parent 37949a2066
commit 9e68ee0806
4 changed files with 297 additions and 124 deletions
+9 -10
View File
@@ -507,22 +507,21 @@ auto CheckParseTrees(
// Create C++ domains for Cpp imports.
if (options.share_cpp_ast) {
bool any_cpp_imports = false;
llvm::SmallVector<SemIR::CppInputFile> inputs;
for (auto& unit_info : unit_infos) {
if (unit_info.cpp_imports.empty()) {
continue;
}
any_cpp_imports |= !unit_info.cpp_imports.empty();
inputs.push_back({.check_ir_id = unit_info.unit->sem_ir->check_ir_id(),
.filename = unit_info.unit->sem_ir->filename(),
.is_lowered = unit_info.unit->is_lowered});
}
// TODO: Remove dependence on properties of the first unit here.
if (auto cpp_domain = InitializeCppDomain(
unit_infos.front().err_tracker, inputs, fs,
unit_infos.front().unit->llvm_context, clang_invocation)) {
cpp_domains.push_back(std::move(cpp_domain));
for (auto& unit_info : unit_infos) {
if (!unit_info.cpp_imports.empty()) {
if (any_cpp_imports) {
// TODO: Remove dependence on properties of the first unit here.
if (auto cpp_domain = InitializeCppDomain(
unit_infos.front().err_tracker, inputs, fs,
unit_infos.front().unit->llvm_context, clang_invocation)) {
cpp_domains.push_back(std::move(cpp_domain));
for (auto& unit_info : unit_infos) {
unit_info.cpp_domain = cpp_domains.back().get();
}
}
+21 -12
View File
@@ -99,13 +99,28 @@ auto AddIdentifierName(Context& context, llvm::StringRef name)
}
// Adds a namespace for the `Cpp` import and returns its `NameScopeId`.
static auto AddNamespace(Context& context, PackageNameId cpp_package_id,
static auto AddNamespace(Context& context,
llvm::ArrayRef<Parse::Tree::PackagingNames> imports)
-> SemIR::NameScopeId {
if (imports.empty()) {
return AddImportNamespace(
context,
GetSingletonType(context, SemIR::NamespaceType::TypeInstId),
SemIR::NameId::Cpp, SemIR::NameScopeId::Package,
/*import_id=*/SemIR::InstId::None)
.name_scope_id;
}
PackageNameId package_id = imports.front().package_id;
CARBON_CHECK(
llvm::all_of(imports, [&](const Parse::Tree::PackagingNames& import) {
return import.package_id == package_id;
}));
return AddImportNamespaceToScope(
context,
GetSingletonType(context, SemIR::NamespaceType::TypeInstId),
SemIR::NameId::ForPackageName(cpp_package_id),
SemIR::NameId::ForPackageName(package_id),
SemIR::NameScopeId::Package,
/*diagnose_duplicate_namespace=*/false,
[&] {
@@ -121,19 +136,13 @@ static auto AddNamespace(Context& context, PackageNameId cpp_package_id,
auto ImportCpp(Context& context,
llvm::ArrayRef<Parse::Tree::PackagingNames> imports,
SemIR::CppDomain* domain) -> void {
if (imports.empty()) {
// TODO: Consider always having a (non-null) AST even if there are no Cpp
// imports.
// If there are no direct C++ imports and no shared domain covers this unit,
// there is nothing to import.
if (imports.empty() && !domain) {
return;
}
PackageNameId package_id = imports.front().package_id;
CARBON_CHECK(
llvm::all_of(imports, [&](const Parse::Tree::PackagingNames& import) {
return import.package_id == package_id;
}));
auto name_scope_id = AddNamespace(context, package_id, imports);
auto name_scope_id = AddNamespace(context, imports);
SemIR::NameScope& name_scope = context.name_scopes().Get(name_scope_id);
name_scope.set_is_closed_import(true);
@@ -100,22 +100,13 @@ fn TryToUseNotLeaked() {
var unused x: Cpp.A.X = 0;
}
// --- fail_todo_no_cpp_import.carbon
// --- no_cpp_import.carbon
library "[[@TEST_NAME]]";
// CHECK:STDERR: fail_todo_no_cpp_import.carbon:[[@LINE+6]]:1: in import [InImport]
// CHECK:STDERR: direct_import.carbon:4:10: in file included here [InCppInclude]
// CHECK:STDERR: ./shared.h:3:10: error: semantics TODO: `indirect import of C++ declaration with no direct Cpp import` [SemanticsTodo]
// CHECK:STDERR: struct X {
// CHECK:STDERR: ^
// CHECK:STDERR:
import library "direct_import";
fn Field() -> i32 {
// TODO: This should eventually work, by importing the C++ AST from
// `direct_import`, even though we don't otherwise have any C++ imports in
// this compilation.
return F().x;
}
+266 -92
View File
@@ -62,6 +62,23 @@ fn TestB() -> i32 {
return b.x;
}
// --- generic_lib.carbon
library "[[@TEST_NAME]]";
import Cpp library "a.h";
fn MakeA[T: type](unused x: T) -> i32 {
var a: Cpp.A = Cpp.make_a();
return a.b;
}
// --- no_cpp_imports.carbon
library "[[@TEST_NAME]]";
import library "generic_lib";
fn CallGeneric() -> i32 {
return MakeA(0);
}
// CHECK:STDOUT: ; ---
// CHECK:STDOUT: ; ModuleID = 'use_a.carbon'
@@ -74,22 +91,22 @@ fn TestB() -> i32 {
// CHECK:STDOUT: $_Z6make_av = comdat any
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define i32 @_CTest.Main() #0 !dbg !40 {
// CHECK:STDOUT: define i32 @_CTest.Main() #0 !dbg !48 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %a.var = alloca [8 x i8], align 4, !dbg !43
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %a.var), !dbg !43
// CHECK:STDOUT: call void @_Z6make_av.carbon_thunk.(ptr %a.var), !dbg !44
// CHECK:STDOUT: %.loc6_11.1.b = getelementptr inbounds nuw [8 x i8], ptr %a.var, i32 0, i32 4, !dbg !46
// CHECK:STDOUT: %.loc6_11.2 = load i32, ptr %.loc6_11.1.b, align 4, !dbg !46
// CHECK:STDOUT: ret i32 %.loc6_11.2, !dbg !47
// CHECK:STDOUT: %a.var = alloca [8 x i8], align 4, !dbg !51
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %a.var), !dbg !51
// CHECK:STDOUT: call void @_Z6make_av.carbon_thunk.(ptr %a.var), !dbg !52
// CHECK:STDOUT: %.loc6_11.1.b = getelementptr inbounds nuw [8 x i8], ptr %a.var, i32 0, i32 4, !dbg !54
// CHECK:STDOUT: %.loc6_11.2 = load i32, ptr %.loc6_11.1.b, align 4, !dbg !54
// CHECK:STDOUT: ret i32 %.loc6_11.2, !dbg !55
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
// CHECK:STDOUT: define internal void @_Z6make_av.carbon_thunk.(ptr noundef %return) #1 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %return.addr = alloca ptr, align 8
// CHECK:STDOUT: store ptr %return, ptr %return.addr, align 8, !tbaa !52
// CHECK:STDOUT: %0 = load ptr, ptr %return.addr, align 8, !tbaa !52
// CHECK:STDOUT: store ptr %return, ptr %return.addr, align 8, !tbaa !58
// CHECK:STDOUT: %0 = load ptr, ptr %return.addr, align 8, !tbaa !58
// CHECK:STDOUT: %call = call i64 @_Z6make_av()
// CHECK:STDOUT: store i64 %call, ptr %0, align 4
// CHECK:STDOUT: ret void
@@ -103,9 +120,9 @@ fn TestB() -> i32 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %retval = alloca %struct.A, align 4
// CHECK:STDOUT: %a = getelementptr inbounds nuw %struct.A, ptr %retval, i32 0, i32 0
// CHECK:STDOUT: store i32 1, ptr %a, align 4, !tbaa !55
// CHECK:STDOUT: store i32 1, ptr %a, align 4, !tbaa !60
// CHECK:STDOUT: %b = getelementptr inbounds nuw %struct.A, ptr %retval, i32 0, i32 1
// CHECK:STDOUT: store i32 2, ptr %b, align 4, !tbaa !56
// CHECK:STDOUT: store i32 2, ptr %b, align 4, !tbaa !61
// CHECK:STDOUT: %0 = load i64, ptr %retval, align 4
// CHECK:STDOUT: ret i64 %0
// CHECK:STDOUT: }
@@ -115,36 +132,36 @@ fn TestB() -> i32 {
// CHECK:STDOUT: attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
// CHECK:STDOUT: attributes #3 = { inlinehint mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
// CHECK:STDOUT:
// CHECK:STDOUT: !llvm.dbg.cu = !{!33}
// CHECK:STDOUT: !llvm.module.flags = !{!57, !58, !59, !2, !3}
// CHECK:STDOUT: !llvm.errno.tbaa = !{!61}
// CHECK:STDOUT: !llvm.dbg.cu = !{!41}
// CHECK:STDOUT: !llvm.module.flags = !{!2, !3, !4, !10, !11}
// CHECK:STDOUT: !llvm.errno.tbaa = !{!9}
// CHECK:STDOUT:
// CHECK:STDOUT: !2 = !{i32 7, !"Dwarf Version", i32 5}
// CHECK:STDOUT: !3 = !{i32 2, !"Debug Info Version", i32 3}
// CHECK:STDOUT: !32 = !DIFile(filename: "use_a.carbon", directory: "")
// CHECK:STDOUT: !33 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !32, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
// CHECK:STDOUT: !34 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
// CHECK:STDOUT: !35 = !{!34}
// CHECK:STDOUT: !36 = !DISubroutineType(types: !35)
// CHECK:STDOUT: !40 = distinct !DISubprogram(name: "Test", linkageName: "_CTest.Main", scope: null, file: !32, line: 4, type: !36, spFlags: DISPFlagDefinition, unit: !33)
// CHECK:STDOUT: !43 = !DILocation(line: 5, column: 3, scope: !40)
// CHECK:STDOUT: !44 = !DILocation(line: 5, column: 18, scope: !40)
// CHECK:STDOUT: !46 = !DILocation(line: 6, column: 10, scope: !40)
// CHECK:STDOUT: !47 = !DILocation(line: 6, column: 3, scope: !40)
// CHECK:STDOUT: !48 = !{!"Simple C++ TBAA"}
// CHECK:STDOUT: !49 = !{!"omnipotent char", !48, i64 0}
// CHECK:STDOUT: !50 = !{!"any pointer", !49, i64 0}
// CHECK:STDOUT: !51 = !{!"p1 _ZTS1A", !50, i64 0}
// CHECK:STDOUT: !52 = !{!51, !51, i64 0}
// CHECK:STDOUT: !53 = !{!"int", !49, i64 0}
// CHECK:STDOUT: !54 = !{!"_ZTS1A", !53, i64 0, !53, i64 4}
// CHECK:STDOUT: !55 = !{!54, !53, i64 0}
// CHECK:STDOUT: !56 = !{!54, !53, i64 4}
// CHECK:STDOUT: !57 = !{i32 8, !"PIC Level", i32 2}
// CHECK:STDOUT: !58 = !{i32 7, !"PIE Level", i32 2}
// CHECK:STDOUT: !59 = !{i32 7, !"uwtable", i32 2}
// CHECK:STDOUT: !60 = !{!"__libc_errno", !53, i64 0}
// CHECK:STDOUT: !61 = !{!60, !53, i64 0}
// CHECK:STDOUT: !2 = !{i32 8, !"PIC Level", i32 2}
// CHECK:STDOUT: !3 = !{i32 7, !"PIE Level", i32 2}
// CHECK:STDOUT: !4 = !{i32 7, !"uwtable", i32 2}
// CHECK:STDOUT: !5 = !{!"Simple C++ TBAA"}
// CHECK:STDOUT: !6 = !{!"omnipotent char", !5, i64 0}
// CHECK:STDOUT: !7 = !{!"int", !6, i64 0}
// CHECK:STDOUT: !8 = !{!"__libc_errno", !7, i64 0}
// CHECK:STDOUT: !9 = !{!8, !7, i64 0}
// CHECK:STDOUT: !10 = !{i32 7, !"Dwarf Version", i32 5}
// CHECK:STDOUT: !11 = !{i32 2, !"Debug Info Version", i32 3}
// CHECK:STDOUT: !40 = !DIFile(filename: "use_a.carbon", directory: "")
// CHECK:STDOUT: !41 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !40, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
// CHECK:STDOUT: !42 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
// CHECK:STDOUT: !43 = !{!42}
// CHECK:STDOUT: !44 = !DISubroutineType(types: !43)
// CHECK:STDOUT: !48 = distinct !DISubprogram(name: "Test", linkageName: "_CTest.Main", scope: null, file: !40, line: 4, type: !44, spFlags: DISPFlagDefinition, unit: !41)
// CHECK:STDOUT: !51 = !DILocation(line: 5, column: 3, scope: !48)
// CHECK:STDOUT: !52 = !DILocation(line: 5, column: 18, scope: !48)
// CHECK:STDOUT: !54 = !DILocation(line: 6, column: 10, scope: !48)
// CHECK:STDOUT: !55 = !DILocation(line: 6, column: 3, scope: !48)
// CHECK:STDOUT: !56 = !{!"any pointer", !6, i64 0}
// CHECK:STDOUT: !57 = !{!"p1 _ZTS1A", !56, i64 0}
// CHECK:STDOUT: !58 = !{!57, !57, i64 0}
// CHECK:STDOUT: !59 = !{!"_ZTS1A", !7, i64 0, !7, i64 4}
// CHECK:STDOUT: !60 = !{!59, !7, i64 0}
// CHECK:STDOUT: !61 = !{!59, !7, i64 4}
// CHECK:STDOUT:
// CHECK:STDOUT: ; ---
// CHECK:STDOUT: ; ModuleID = 'use_b.carbon'
@@ -199,35 +216,35 @@ fn TestB() -> i32 {
// CHECK:STDOUT: attributes #3 = { inlinehint mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
// CHECK:STDOUT:
// CHECK:STDOUT: !llvm.dbg.cu = !{!63}
// CHECK:STDOUT: !llvm.module.flags = !{!57, !58, !59, !2, !3}
// CHECK:STDOUT: !llvm.errno.tbaa = !{!61}
// CHECK:STDOUT: !llvm.module.flags = !{!2, !3, !4, !10, !11}
// CHECK:STDOUT: !llvm.errno.tbaa = !{!9}
// CHECK:STDOUT:
// CHECK:STDOUT: !2 = !{i32 7, !"Dwarf Version", i32 5}
// CHECK:STDOUT: !3 = !{i32 2, !"Debug Info Version", i32 3}
// CHECK:STDOUT: !34 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
// CHECK:STDOUT: !35 = !{!34}
// CHECK:STDOUT: !36 = !DISubroutineType(types: !35)
// CHECK:STDOUT: !48 = !{!"Simple C++ TBAA"}
// CHECK:STDOUT: !49 = !{!"omnipotent char", !48, i64 0}
// CHECK:STDOUT: !50 = !{!"any pointer", !49, i64 0}
// CHECK:STDOUT: !53 = !{!"int", !49, i64 0}
// CHECK:STDOUT: !57 = !{i32 8, !"PIC Level", i32 2}
// CHECK:STDOUT: !58 = !{i32 7, !"PIE Level", i32 2}
// CHECK:STDOUT: !59 = !{i32 7, !"uwtable", i32 2}
// CHECK:STDOUT: !60 = !{!"__libc_errno", !53, i64 0}
// CHECK:STDOUT: !61 = !{!60, !53, i64 0}
// CHECK:STDOUT: !2 = !{i32 8, !"PIC Level", i32 2}
// CHECK:STDOUT: !3 = !{i32 7, !"PIE Level", i32 2}
// CHECK:STDOUT: !4 = !{i32 7, !"uwtable", i32 2}
// CHECK:STDOUT: !5 = !{!"Simple C++ TBAA"}
// CHECK:STDOUT: !6 = !{!"omnipotent char", !5, i64 0}
// CHECK:STDOUT: !7 = !{!"int", !6, i64 0}
// CHECK:STDOUT: !8 = !{!"__libc_errno", !7, i64 0}
// CHECK:STDOUT: !9 = !{!8, !7, i64 0}
// CHECK:STDOUT: !10 = !{i32 7, !"Dwarf Version", i32 5}
// CHECK:STDOUT: !11 = !{i32 2, !"Debug Info Version", i32 3}
// CHECK:STDOUT: !42 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
// CHECK:STDOUT: !43 = !{!42}
// CHECK:STDOUT: !44 = !DISubroutineType(types: !43)
// CHECK:STDOUT: !56 = !{!"any pointer", !6, i64 0}
// CHECK:STDOUT: !62 = !DIFile(filename: "use_b.carbon", directory: "")
// CHECK:STDOUT: !63 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !62, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
// CHECK:STDOUT: !64 = distinct !DISubprogram(name: "Test", linkageName: "_CTest.Main", scope: null, file: !62, line: 4, type: !36, spFlags: DISPFlagDefinition, unit: !63)
// CHECK:STDOUT: !64 = distinct !DISubprogram(name: "Test", linkageName: "_CTest.Main", scope: null, file: !62, line: 4, type: !44, spFlags: DISPFlagDefinition, unit: !63)
// CHECK:STDOUT: !67 = !DILocation(line: 5, column: 3, scope: !64)
// CHECK:STDOUT: !68 = !DILocation(line: 5, column: 18, scope: !64)
// CHECK:STDOUT: !70 = !DILocation(line: 6, column: 10, scope: !64)
// CHECK:STDOUT: !71 = !DILocation(line: 6, column: 3, scope: !64)
// CHECK:STDOUT: !72 = !{!"p1 _ZTS1B", !50, i64 0}
// CHECK:STDOUT: !72 = !{!"p1 _ZTS1B", !56, i64 0}
// CHECK:STDOUT: !73 = !{!72, !72, i64 0}
// CHECK:STDOUT: !74 = !{!"_ZTS1B", !53, i64 0, !53, i64 4}
// CHECK:STDOUT: !75 = !{!74, !53, i64 0}
// CHECK:STDOUT: !76 = !{!74, !53, i64 4}
// CHECK:STDOUT: !74 = !{!"_ZTS1B", !7, i64 0, !7, i64 4}
// CHECK:STDOUT: !75 = !{!74, !7, i64 0}
// CHECK:STDOUT: !76 = !{!74, !7, i64 4}
// CHECK:STDOUT:
// CHECK:STDOUT: ; ---
// CHECK:STDOUT: ; ModuleID = 'use_both.carbon'
@@ -257,8 +274,8 @@ fn TestB() -> i32 {
// CHECK:STDOUT: define internal void @_Z6make_av.carbon_thunk.(ptr noundef %return) #1 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %return.addr = alloca ptr, align 8
// CHECK:STDOUT: store ptr %return, ptr %return.addr, align 8, !tbaa !52
// CHECK:STDOUT: %0 = load ptr, ptr %return.addr, align 8, !tbaa !52
// CHECK:STDOUT: store ptr %return, ptr %return.addr, align 8, !tbaa !58
// CHECK:STDOUT: %0 = load ptr, ptr %return.addr, align 8, !tbaa !58
// CHECK:STDOUT: %call = call i64 @_Z6make_av()
// CHECK:STDOUT: store i64 %call, ptr %0, align 4
// CHECK:STDOUT: ret void
@@ -294,9 +311,9 @@ fn TestB() -> i32 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %retval = alloca %struct.A.32, align 4
// CHECK:STDOUT: %a = getelementptr inbounds nuw %struct.A.32, ptr %retval, i32 0, i32 0
// CHECK:STDOUT: store i32 1, ptr %a, align 4, !tbaa !55
// CHECK:STDOUT: store i32 1, ptr %a, align 4, !tbaa !60
// CHECK:STDOUT: %b = getelementptr inbounds nuw %struct.A.32, ptr %retval, i32 0, i32 1
// CHECK:STDOUT: store i32 2, ptr %b, align 4, !tbaa !56
// CHECK:STDOUT: store i32 2, ptr %b, align 4, !tbaa !61
// CHECK:STDOUT: %0 = load i64, ptr %retval, align 4
// CHECK:STDOUT: ret i64 %0
// CHECK:STDOUT: }
@@ -322,43 +339,200 @@ fn TestB() -> i32 {
// CHECK:STDOUT: attributes #3 = { inlinehint mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
// CHECK:STDOUT:
// CHECK:STDOUT: !llvm.dbg.cu = !{!78}
// CHECK:STDOUT: !llvm.module.flags = !{!57, !58, !59, !2, !3}
// CHECK:STDOUT: !llvm.errno.tbaa = !{!61}
// CHECK:STDOUT: !llvm.module.flags = !{!2, !3, !4, !10, !11}
// CHECK:STDOUT: !llvm.errno.tbaa = !{!9}
// CHECK:STDOUT:
// CHECK:STDOUT: !2 = !{i32 7, !"Dwarf Version", i32 5}
// CHECK:STDOUT: !3 = !{i32 2, !"Debug Info Version", i32 3}
// CHECK:STDOUT: !34 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
// CHECK:STDOUT: !35 = !{!34}
// CHECK:STDOUT: !36 = !DISubroutineType(types: !35)
// CHECK:STDOUT: !48 = !{!"Simple C++ TBAA"}
// CHECK:STDOUT: !49 = !{!"omnipotent char", !48, i64 0}
// CHECK:STDOUT: !50 = !{!"any pointer", !49, i64 0}
// CHECK:STDOUT: !51 = !{!"p1 _ZTS1A", !50, i64 0}
// CHECK:STDOUT: !52 = !{!51, !51, i64 0}
// CHECK:STDOUT: !53 = !{!"int", !49, i64 0}
// CHECK:STDOUT: !54 = !{!"_ZTS1A", !53, i64 0, !53, i64 4}
// CHECK:STDOUT: !55 = !{!54, !53, i64 0}
// CHECK:STDOUT: !56 = !{!54, !53, i64 4}
// CHECK:STDOUT: !57 = !{i32 8, !"PIC Level", i32 2}
// CHECK:STDOUT: !58 = !{i32 7, !"PIE Level", i32 2}
// CHECK:STDOUT: !59 = !{i32 7, !"uwtable", i32 2}
// CHECK:STDOUT: !60 = !{!"__libc_errno", !53, i64 0}
// CHECK:STDOUT: !61 = !{!60, !53, i64 0}
// CHECK:STDOUT: !72 = !{!"p1 _ZTS1B", !50, i64 0}
// CHECK:STDOUT: !2 = !{i32 8, !"PIC Level", i32 2}
// CHECK:STDOUT: !3 = !{i32 7, !"PIE Level", i32 2}
// CHECK:STDOUT: !4 = !{i32 7, !"uwtable", i32 2}
// CHECK:STDOUT: !5 = !{!"Simple C++ TBAA"}
// CHECK:STDOUT: !6 = !{!"omnipotent char", !5, i64 0}
// CHECK:STDOUT: !7 = !{!"int", !6, i64 0}
// CHECK:STDOUT: !8 = !{!"__libc_errno", !7, i64 0}
// CHECK:STDOUT: !9 = !{!8, !7, i64 0}
// CHECK:STDOUT: !10 = !{i32 7, !"Dwarf Version", i32 5}
// CHECK:STDOUT: !11 = !{i32 2, !"Debug Info Version", i32 3}
// CHECK:STDOUT: !42 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
// CHECK:STDOUT: !43 = !{!42}
// CHECK:STDOUT: !44 = !DISubroutineType(types: !43)
// CHECK:STDOUT: !56 = !{!"any pointer", !6, i64 0}
// CHECK:STDOUT: !57 = !{!"p1 _ZTS1A", !56, i64 0}
// CHECK:STDOUT: !58 = !{!57, !57, i64 0}
// CHECK:STDOUT: !59 = !{!"_ZTS1A", !7, i64 0, !7, i64 4}
// CHECK:STDOUT: !60 = !{!59, !7, i64 0}
// CHECK:STDOUT: !61 = !{!59, !7, i64 4}
// CHECK:STDOUT: !72 = !{!"p1 _ZTS1B", !56, i64 0}
// CHECK:STDOUT: !73 = !{!72, !72, i64 0}
// CHECK:STDOUT: !74 = !{!"_ZTS1B", !53, i64 0, !53, i64 4}
// CHECK:STDOUT: !75 = !{!74, !53, i64 0}
// CHECK:STDOUT: !76 = !{!74, !53, i64 4}
// CHECK:STDOUT: !74 = !{!"_ZTS1B", !7, i64 0, !7, i64 4}
// CHECK:STDOUT: !75 = !{!74, !7, i64 0}
// CHECK:STDOUT: !76 = !{!74, !7, i64 4}
// CHECK:STDOUT: !77 = !DIFile(filename: "use_both.carbon", directory: "")
// CHECK:STDOUT: !78 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !77, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
// CHECK:STDOUT: !79 = distinct !DISubprogram(name: "TestA", linkageName: "_CTestA.Main", scope: null, file: !77, line: 5, type: !36, spFlags: DISPFlagDefinition, unit: !78)
// CHECK:STDOUT: !79 = distinct !DISubprogram(name: "TestA", linkageName: "_CTestA.Main", scope: null, file: !77, line: 5, type: !44, spFlags: DISPFlagDefinition, unit: !78)
// CHECK:STDOUT: !82 = !DILocation(line: 6, column: 3, scope: !79)
// CHECK:STDOUT: !83 = !DILocation(line: 6, column: 18, scope: !79)
// CHECK:STDOUT: !85 = !DILocation(line: 7, column: 10, scope: !79)
// CHECK:STDOUT: !86 = !DILocation(line: 7, column: 3, scope: !79)
// CHECK:STDOUT: !87 = distinct !DISubprogram(name: "TestB", linkageName: "_CTestB.Main", scope: null, file: !77, line: 10, type: !36, spFlags: DISPFlagDefinition, unit: !78)
// CHECK:STDOUT: !87 = distinct !DISubprogram(name: "TestB", linkageName: "_CTestB.Main", scope: null, file: !77, line: 10, type: !44, spFlags: DISPFlagDefinition, unit: !78)
// CHECK:STDOUT: !90 = !DILocation(line: 11, column: 3, scope: !87)
// CHECK:STDOUT: !91 = !DILocation(line: 11, column: 18, scope: !87)
// CHECK:STDOUT: !93 = !DILocation(line: 12, column: 10, scope: !87)
// CHECK:STDOUT: !94 = !DILocation(line: 12, column: 3, scope: !87)
// CHECK:STDOUT:
// CHECK:STDOUT: ; ---
// CHECK:STDOUT: ; ModuleID = 'generic_lib.carbon'
// CHECK:STDOUT: source_filename = "generic_lib.carbon"
// CHECK:STDOUT: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
// CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu"
// CHECK:STDOUT:
// CHECK:STDOUT: %struct.A.36 = type { i32, i32 }
// CHECK:STDOUT:
// CHECK:STDOUT: $_Z6make_av = comdat any
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
// CHECK:STDOUT: define internal void @_Z6make_av.carbon_thunk.(ptr noundef %return) #0 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %return.addr = alloca ptr, align 8
// CHECK:STDOUT: store ptr %return, ptr %return.addr, align 8, !tbaa !58
// CHECK:STDOUT: %0 = load ptr, ptr %return.addr, align 8, !tbaa !58
// CHECK:STDOUT: %call = call i64 @_Z6make_av()
// CHECK:STDOUT: store i64 %call, ptr %0, align 4
// CHECK:STDOUT: ret void
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: inlinehint mustprogress nounwind uwtable
// CHECK:STDOUT: define linkonce_odr dso_local i64 @_Z6make_av() #1 comdat {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %retval = alloca %struct.A.36, align 4
// CHECK:STDOUT: %a = getelementptr inbounds nuw %struct.A.36, ptr %retval, i32 0, i32 0
// CHECK:STDOUT: store i32 1, ptr %a, align 4, !tbaa !60
// CHECK:STDOUT: %b = getelementptr inbounds nuw %struct.A.36, ptr %retval, i32 0, i32 1
// CHECK:STDOUT: store i32 2, ptr %b, align 4, !tbaa !61
// CHECK:STDOUT: %0 = load i64, ptr %retval, align 4
// CHECK:STDOUT: ret i64 %0
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: attributes #0 = { alwaysinline mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
// CHECK:STDOUT: attributes #1 = { inlinehint mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
// CHECK:STDOUT:
// CHECK:STDOUT: !llvm.dbg.cu = !{!96}
// CHECK:STDOUT: !llvm.module.flags = !{!2, !3, !4, !10, !11}
// CHECK:STDOUT: !llvm.errno.tbaa = !{!9}
// CHECK:STDOUT:
// CHECK:STDOUT: !2 = !{i32 8, !"PIC Level", i32 2}
// CHECK:STDOUT: !3 = !{i32 7, !"PIE Level", i32 2}
// CHECK:STDOUT: !4 = !{i32 7, !"uwtable", i32 2}
// CHECK:STDOUT: !5 = !{!"Simple C++ TBAA"}
// CHECK:STDOUT: !6 = !{!"omnipotent char", !5, i64 0}
// CHECK:STDOUT: !7 = !{!"int", !6, i64 0}
// CHECK:STDOUT: !8 = !{!"__libc_errno", !7, i64 0}
// CHECK:STDOUT: !9 = !{!8, !7, i64 0}
// CHECK:STDOUT: !10 = !{i32 7, !"Dwarf Version", i32 5}
// CHECK:STDOUT: !11 = !{i32 2, !"Debug Info Version", i32 3}
// CHECK:STDOUT: !56 = !{!"any pointer", !6, i64 0}
// CHECK:STDOUT: !57 = !{!"p1 _ZTS1A", !56, i64 0}
// CHECK:STDOUT: !58 = !{!57, !57, i64 0}
// CHECK:STDOUT: !59 = !{!"_ZTS1A", !7, i64 0, !7, i64 4}
// CHECK:STDOUT: !60 = !{!59, !7, i64 0}
// CHECK:STDOUT: !61 = !{!59, !7, i64 4}
// CHECK:STDOUT: !95 = !DIFile(filename: "generic_lib.carbon", directory: "")
// CHECK:STDOUT: !96 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !95, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
// CHECK:STDOUT:
// CHECK:STDOUT: ; ---
// CHECK:STDOUT: ; ModuleID = 'no_cpp_imports.carbon'
// CHECK:STDOUT: source_filename = "no_cpp_imports.carbon"
// CHECK:STDOUT: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
// CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu"
// CHECK:STDOUT:
// CHECK:STDOUT: %struct.A.39 = type { i32, i32 }
// CHECK:STDOUT:
// CHECK:STDOUT: $_Z6make_av = comdat any
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define i32 @_CCallGeneric.Main() #0 !dbg !99 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %MakeA.call = call i32 @_CMakeA.Main.084a2801e0f5d754({} zeroinitializer), !dbg !102
// CHECK:STDOUT: ret i32 %MakeA.call, !dbg !105
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define linkonce_odr i32 @_CMakeA.Main.084a2801e0f5d754({} %x) #0 !dbg !106 {
// CHECK:STDOUT: %1 = alloca [8 x i8], align 4, !dbg !111
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %1), !dbg !111
// CHECK:STDOUT: call void @_Z6make_av.carbon_thunk.(ptr %1), !dbg !112
// CHECK:STDOUT: %b = getelementptr inbounds nuw [8 x i8], ptr %1, i32 0, i32 4, !dbg !114
// CHECK:STDOUT: %2 = load i32, ptr %b, align 4, !dbg !114
// CHECK:STDOUT: ret i32 %2, !dbg !115
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
// CHECK:STDOUT: define internal void @_Z6make_av.carbon_thunk.(ptr noundef %return) #1 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %return.addr = alloca ptr, align 8
// CHECK:STDOUT: store ptr %return, ptr %return.addr, align 8, !tbaa !58
// CHECK:STDOUT: %0 = load ptr, ptr %return.addr, align 8, !tbaa !58
// CHECK:STDOUT: %call = call i64 @_Z6make_av()
// CHECK:STDOUT: store i64 %call, ptr %0, align 4
// CHECK:STDOUT: ret void
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
// CHECK:STDOUT: declare void @llvm.lifetime.start.p0(ptr captures(none)) #2
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: inlinehint mustprogress nounwind uwtable
// CHECK:STDOUT: define linkonce_odr dso_local i64 @_Z6make_av() #3 comdat {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %retval = alloca %struct.A.39, align 4
// CHECK:STDOUT: %a = getelementptr inbounds nuw %struct.A.39, ptr %retval, i32 0, i32 0
// CHECK:STDOUT: store i32 1, ptr %a, align 4, !tbaa !60
// CHECK:STDOUT: %b = getelementptr inbounds nuw %struct.A.39, ptr %retval, i32 0, i32 1
// CHECK:STDOUT: store i32 2, ptr %b, align 4, !tbaa !61
// CHECK:STDOUT: %0 = load i64, ptr %retval, align 4
// CHECK:STDOUT: ret i64 %0
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: attributes #0 = { nounwind }
// CHECK:STDOUT: attributes #1 = { alwaysinline mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
// CHECK:STDOUT: attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
// CHECK:STDOUT: attributes #3 = { inlinehint mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
// CHECK:STDOUT:
// CHECK:STDOUT: !llvm.dbg.cu = !{!98}
// CHECK:STDOUT: !llvm.module.flags = !{!2, !3, !4, !10, !11}
// CHECK:STDOUT: !llvm.errno.tbaa = !{!9}
// CHECK:STDOUT:
// CHECK:STDOUT: !2 = !{i32 8, !"PIC Level", i32 2}
// CHECK:STDOUT: !3 = !{i32 7, !"PIE Level", i32 2}
// CHECK:STDOUT: !4 = !{i32 7, !"uwtable", i32 2}
// CHECK:STDOUT: !5 = !{!"Simple C++ TBAA"}
// CHECK:STDOUT: !6 = !{!"omnipotent char", !5, i64 0}
// CHECK:STDOUT: !7 = !{!"int", !6, i64 0}
// CHECK:STDOUT: !8 = !{!"__libc_errno", !7, i64 0}
// CHECK:STDOUT: !9 = !{!8, !7, i64 0}
// CHECK:STDOUT: !10 = !{i32 7, !"Dwarf Version", i32 5}
// CHECK:STDOUT: !11 = !{i32 2, !"Debug Info Version", i32 3}
// CHECK:STDOUT: !42 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
// CHECK:STDOUT: !43 = !{!42}
// CHECK:STDOUT: !44 = !DISubroutineType(types: !43)
// CHECK:STDOUT: !45 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
// CHECK:STDOUT: !56 = !{!"any pointer", !6, i64 0}
// CHECK:STDOUT: !57 = !{!"p1 _ZTS1A", !56, i64 0}
// CHECK:STDOUT: !58 = !{!57, !57, i64 0}
// CHECK:STDOUT: !59 = !{!"_ZTS1A", !7, i64 0, !7, i64 4}
// CHECK:STDOUT: !60 = !{!59, !7, i64 0}
// CHECK:STDOUT: !61 = !{!59, !7, i64 4}
// CHECK:STDOUT: !95 = !DIFile(filename: "generic_lib.carbon", directory: "")
// CHECK:STDOUT: !97 = !DIFile(filename: "no_cpp_imports.carbon", directory: "")
// CHECK:STDOUT: !98 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !97, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
// CHECK:STDOUT: !99 = distinct !DISubprogram(name: "CallGeneric", linkageName: "_CCallGeneric.Main", scope: null, file: !97, line: 4, type: !44, spFlags: DISPFlagDefinition, unit: !98)
// CHECK:STDOUT: !102 = !DILocation(line: 5, column: 10, scope: !99)
// CHECK:STDOUT: !103 = !{!42, !45}
// CHECK:STDOUT: !104 = !DISubroutineType(types: !103)
// CHECK:STDOUT: !105 = !DILocation(line: 5, column: 3, scope: !99)
// CHECK:STDOUT: !106 = distinct !DISubprogram(name: "MakeA", linkageName: "_CMakeA.Main.084a2801e0f5d754", scope: null, file: !95, line: 4, type: !104, spFlags: DISPFlagDefinition, unit: !98, retainedNodes: !116)
// CHECK:STDOUT: !107 = !DILocalVariable(arg: 1, scope: !106, type: !45)
// CHECK:STDOUT: !111 = !DILocation(line: 5, column: 3, scope: !106)
// CHECK:STDOUT: !112 = !DILocation(line: 5, column: 18, scope: !106)
// CHECK:STDOUT: !114 = !DILocation(line: 6, column: 10, scope: !106)
// CHECK:STDOUT: !115 = !DILocation(line: 6, column: 3, scope: !106)
// CHECK:STDOUT: !116 = !{!107}
// CHECK:STDOUT: