Give Carbon thunks for C++ callers linkonce_odr linkage (#8022)

This allows two C++ callers to the same Carbon function, written in
different Carbon files, to generate thunks that won't collide/duplicate
symbol at link time - instead the thunks get deduplicated silently by
the linker.
This commit is contained in:
David Blaikie authored and GitHub committed 2026-11-02 18:53:01 +00:00
1 parent 8fc87ebf76
commit 5c9ab26d74
16 files changed
+239 -33

No files matched your search

+5
View File
@@ -622,6 +622,11 @@ auto FileContext::BuildFunctionBody(SemIR::FunctionId function_id,
} else if (specific_id.has_value()) {
// Specific functions are emitted in each file they are referenced in.
linkage = llvm::Function::LinkOnceODRLinkage;
} else if (declaration_function.special_function_kind ==
SemIR::Function::SpecialFunctionKind::CppThunk) {
// A C++ thunk that we define wraps a Carbon function for use from C++. It
// is emitted in each file that exposes the function to C++.
linkage = llvm::Function::LinkOnceODRLinkage;
} else if (declaration_function.special_function_kind ==
SemIR::Function::SpecialFunctionKind::Generated ||
declaration_function.special_function_kind ==
+1 -1
View File
@@ -87,7 +87,7 @@ int H() {
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @_CF__carbon_thunk.Main(ptr noundef nonnull align 4 dereferenceable(20) %_, ptr noundef nonnull align 4 dereferenceable(4) %_1) #4 !dbg !40 {
// CHECK:STDOUT: define linkonce_odr void @_CF__carbon_thunk.Main(ptr noundef nonnull align 4 dereferenceable(20) %_, ptr noundef nonnull align 4 dereferenceable(4) %_1) #4 !dbg !40 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %F.call = call i32 @_CF.Main(ptr %_), !dbg !43
// CHECK:STDOUT: store i32 %F.call, ptr %_1, align 4, !dbg !43
@@ -301,7 +301,7 @@ fn G() {
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @_CCallLayoutA__carbon_thunk.Main(ptr noundef nonnull align 8 dereferenceable(8) %_) #6 !dbg !67 {
// CHECK:STDOUT: define linkonce_odr void @_CCallLayoutA__carbon_thunk.Main(ptr noundef nonnull align 8 dereferenceable(8) %_) #6 !dbg !67 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %.loc21 = load ptr, ptr %_, align 8, !dbg !69
// CHECK:STDOUT: call void @_CCallLayoutA.Main(ptr %.loc21), !dbg !69
@@ -336,7 +336,7 @@ fn G() {
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @_CCallLayoutB__carbon_thunk.Main(ptr noundef nonnull align 8 dereferenceable(8) %_) #6 !dbg !83 {
// CHECK:STDOUT: define linkonce_odr void @_CCallLayoutB__carbon_thunk.Main(ptr noundef nonnull align 8 dereferenceable(8) %_) #6 !dbg !83 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %.loc22 = load ptr, ptr %_, align 8, !dbg !85
// CHECK:STDOUT: call void @_CCallLayoutB.Main(ptr %.loc22), !dbg !85
@@ -371,7 +371,7 @@ fn G() {
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @_CCallLayoutC__carbon_thunk.Main(ptr noundef nonnull align 8 dereferenceable(8) %_) #6 !dbg !99 {
// CHECK:STDOUT: define linkonce_odr void @_CCallLayoutC__carbon_thunk.Main(ptr noundef nonnull align 8 dereferenceable(8) %_) #6 !dbg !99 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %.loc23 = load ptr, ptr %_, align 8, !dbg !101
// CHECK:STDOUT: call void @_CCallLayoutC.Main(ptr %.loc23), !dbg !101
@@ -124,7 +124,7 @@ fn CallCallF() { Cpp.CallStaticF(); }
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @_CF__carbon_thunk.A.Main(ptr noundef nonnull align 1 %self) #6 !dbg !35 {
// CHECK:STDOUT: define linkonce_odr void @_CF__carbon_thunk.A.Main(ptr noundef nonnull align 1 %self) #6 !dbg !35 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: call void @_CF.A.Main(ptr %self), !dbg !37
// CHECK:STDOUT: ret void, !dbg !37
@@ -248,7 +248,7 @@ fn CallCallF() { Cpp.CallStaticF(); }
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @_CF__carbon_thunk.ArgsA.Main(ptr noundef nonnull align 1 %self, ptr noundef nonnull align 4 dereferenceable(4) %_, ptr noundef nonnull align 4 dereferenceable(4) %_1) #6 !dbg !81 {
// CHECK:STDOUT: define linkonce_odr void @_CF__carbon_thunk.ArgsA.Main(ptr noundef nonnull align 1 %self, ptr noundef nonnull align 4 dereferenceable(4) %_, ptr noundef nonnull align 4 dereferenceable(4) %_1) #6 !dbg !81 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %.loc6_29.2 = load i32, ptr %_, align 4, !dbg !85
// CHECK:STDOUT: %ArgsA.F.call = call i32 @_CF.ArgsA.Main(ptr %self, i32 %.loc6_29.2), !dbg !85
@@ -364,7 +364,7 @@ fn CallCallF() { Cpp.CallStaticF(); }
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @_CF__carbon_thunk.StaticA.Main() #4 !dbg !112 {
// CHECK:STDOUT: define linkonce_odr void @_CF__carbon_thunk.StaticA.Main() #4 !dbg !112 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: call void @_CF.StaticA.Main(), !dbg !113
// CHECK:STDOUT: ret void, !dbg !113
@@ -125,14 +125,14 @@ fn DoThing() {
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @_Cfunc__carbon_thunk.Derived.Main(ptr noundef nonnull align 8 dereferenceable(12) %self) #4 !dbg !74 {
// CHECK:STDOUT: define linkonce_odr void @_Cfunc__carbon_thunk.Derived.Main(ptr noundef nonnull align 8 dereferenceable(12) %self) #4 !dbg !74 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: call void @_Cfunc.Derived.Main(ptr %self), !dbg !76
// CHECK:STDOUT: ret void, !dbg !76
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @_Cother_func__carbon_thunk.Derived.Main(ptr noundef nonnull align 8 dereferenceable(12) %self) #4 !dbg !78 {
// CHECK:STDOUT: define linkonce_odr void @_Cother_func__carbon_thunk.Derived.Main(ptr noundef nonnull align 8 dereferenceable(12) %self) #4 !dbg !78 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %Derived.other_func.call.vtable = load ptr, ptr %self, align 8, !dbg !80
// CHECK:STDOUT: %Derived.other_func.call = call ptr @llvm.load.relative.i32(ptr %Derived.other_func.call.vtable, i32 8), !dbg !80
@@ -231,7 +231,7 @@ void delete_new_Base() {
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @_CF__carbon_thunk.Final.Main(ptr noundef nonnull align 8 dereferenceable(8) %self) #7 !dbg !49 {
// CHECK:STDOUT: define linkonce_odr void @_CF__carbon_thunk.Final.Main(ptr noundef nonnull align 8 dereferenceable(8) %self) #7 !dbg !49 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: call void @_CF.Final.Main(ptr %self), !dbg !51
// CHECK:STDOUT: ret void, !dbg !51
@@ -262,7 +262,7 @@ void delete_new_Base() {
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @_CF__carbon_thunk.Base.Main(ptr noundef nonnull align 8 dereferenceable(8) %self) #7 !dbg !66 {
// CHECK:STDOUT: define linkonce_odr void @_CF__carbon_thunk.Base.Main(ptr noundef nonnull align 8 dereferenceable(8) %self) #7 !dbg !66 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: call void @_CF.Base.Main(ptr %self), !dbg !68
// CHECK:STDOUT: ret void, !dbg !68
@@ -101,7 +101,7 @@ fn F() {
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @_Cf__carbon_thunk.Z.Main(ptr noundef nonnull align 8 dereferenceable(8) %self) #3 !dbg !41 {
// CHECK:STDOUT: define linkonce_odr void @_Cf__carbon_thunk.Z.Main(ptr noundef nonnull align 8 dereferenceable(8) %self) #3 !dbg !41 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: call void @_Cf.Z.Main(ptr %self), !dbg !43
// CHECK:STDOUT: ret void, !dbg !43
@@ -84,7 +84,7 @@ void f() {
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @_COneArg__carbon_thunk.OneArg.Main(ptr noundef nonnull align 1 %_, ptr noundef nonnull align 4 dereferenceable(4) %_1) unnamed_addr #5 !dbg !19 {
// CHECK:STDOUT: define linkonce_odr void @_COneArg__carbon_thunk.OneArg.Main(ptr noundef nonnull align 1 %_, ptr noundef nonnull align 4 dereferenceable(4) %_1) unnamed_addr #5 !dbg !19 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %.loc6_28.2 = load i32, ptr %_1, align 4, !dbg !22
// CHECK:STDOUT: call void @_COneArg.OneArg.Main(ptr %_, i32 %.loc6_28.2), !dbg !22
@@ -125,7 +125,7 @@ void CallF() {
// CHECK:STDOUT: declare void @_CF.OtherFunction(i32)
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @_CF__carbon_thunk.OtherFunction(ptr noundef nonnull align 4 dereferenceable(4) %_) #2 !dbg !41 {
// CHECK:STDOUT: define linkonce_odr void @_CF__carbon_thunk.OtherFunction(ptr noundef nonnull align 4 dereferenceable(4) %_) #2 !dbg !41 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %.1 = load i32, ptr %_, align 4, !dbg !43
// CHECK:STDOUT: call void @_CF.OtherFunction(i32 %.1), !dbg !43
@@ -135,7 +135,7 @@ void CallF() {
// CHECK:STDOUT: declare void @_CF.FirstFunction(i32)
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @_CF__carbon_thunk.FirstFunction(ptr noundef nonnull align 4 dereferenceable(4) %_) #2 !dbg !45 {
// CHECK:STDOUT: define linkonce_odr void @_CF__carbon_thunk.FirstFunction(ptr noundef nonnull align 4 dereferenceable(4) %_) #2 !dbg !45 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %.1 = load i32, ptr %_, align 4, !dbg !47
// CHECK:STDOUT: call void @_CF.FirstFunction(i32 %.1), !dbg !47
@@ -212,7 +212,7 @@ fn CallCallBase() { Cpp.CallBase(); }
// CHECK:STDOUT: declare void @_CNoArgs.Other()
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @_CNoArgs__carbon_thunk.Other() #2 !dbg !42 {
// CHECK:STDOUT: define linkonce_odr void @_CNoArgs__carbon_thunk.Other() #2 !dbg !42 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: call void @_CNoArgs.Other(), !dbg !43
// CHECK:STDOUT: ret void, !dbg !43
@@ -221,7 +221,7 @@ fn CallCallBase() { Cpp.CallBase(); }
// CHECK:STDOUT: declare void @_CBoolArg.Other(i1)
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @_CBoolArg__carbon_thunk.Other(ptr noundef nonnull align 1 dereferenceable(1) %_) #2 !dbg !44 {
// CHECK:STDOUT: define linkonce_odr void @_CBoolArg__carbon_thunk.Other(ptr noundef nonnull align 1 dereferenceable(1) %_) #2 !dbg !44 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %.1 = load i8, ptr %_, align 1, !dbg !46
// CHECK:STDOUT: %.11 = trunc i8 %.1 to i1, !dbg !46
@@ -232,7 +232,7 @@ fn CallCallBase() { Cpp.CallBase(); }
// CHECK:STDOUT: declare void @_CIntArg.Other(i32)
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @_CIntArg__carbon_thunk.Other(ptr noundef nonnull align 4 dereferenceable(4) %_) #2 !dbg !48 {
// CHECK:STDOUT: define linkonce_odr void @_CIntArg__carbon_thunk.Other(ptr noundef nonnull align 4 dereferenceable(4) %_) #2 !dbg !48 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %.1 = load i32, ptr %_, align 4, !dbg !50
// CHECK:STDOUT: call void @_CIntArg.Other(i32 %.1), !dbg !50
@@ -242,7 +242,7 @@ fn CallCallBase() { Cpp.CallBase(); }
// CHECK:STDOUT: declare void @_CFloatArg.Other(float)
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @_CFloatArg__carbon_thunk.Other(ptr noundef nonnull align 4 dereferenceable(4) %_) #2 !dbg !52 {
// CHECK:STDOUT: define linkonce_odr void @_CFloatArg__carbon_thunk.Other(ptr noundef nonnull align 4 dereferenceable(4) %_) #2 !dbg !52 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %.1 = load float, ptr %_, align 4, !dbg !54
// CHECK:STDOUT: call void @_CFloatArg.Other(float %.1), !dbg !54
@@ -252,7 +252,7 @@ fn CallCallBase() { Cpp.CallBase(); }
// CHECK:STDOUT: declare i32 @_CIntReturn.Other()
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @_CIntReturn__carbon_thunk.Other(ptr noundef nonnull align 4 dereferenceable(4) %_) #2 !dbg !56 {
// CHECK:STDOUT: define linkonce_odr void @_CIntReturn__carbon_thunk.Other(ptr noundef nonnull align 4 dereferenceable(4) %_) #2 !dbg !56 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %IntReturn.call = call i32 @_CIntReturn.Other(), !dbg !58
// CHECK:STDOUT: store i32 %IntReturn.call, ptr %_, align 4, !dbg !58
@@ -329,7 +329,7 @@ fn CallCallBase() { Cpp.CallBase(); }
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @_CF__carbon_thunk.Main() #1 !dbg !77 {
// CHECK:STDOUT: define linkonce_odr void @_CF__carbon_thunk.Main() #1 !dbg !77 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: call void @_CF.Main(), !dbg !78
// CHECK:STDOUT: ret void, !dbg !78
@@ -409,7 +409,7 @@ fn CallCallBase() { Cpp.CallBase(); }
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @_Cbase__carbon_thunk.Main() #1 !dbg !86 {
// CHECK:STDOUT: define linkonce_odr void @_Cbase__carbon_thunk.Main() #1 !dbg !86 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: call void @_Cbase.Main(), !dbg !87
// CHECK:STDOUT: ret void, !dbg !87
@@ -196,14 +196,14 @@ fn Run() {
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @_CF__carbon_thunk.26f2099a79512a5d.Main(ptr noundef nonnull align 1 %_) #6 !dbg !42 {
// CHECK:STDOUT: define linkonce_odr void @_CF__carbon_thunk.26f2099a79512a5d.Main(ptr noundef nonnull align 1 %_) #6 !dbg !42 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: call void @_CF.Main.6662a1ffb773360a(ptr %_), !dbg !44
// CHECK:STDOUT: ret void, !dbg !44
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @_CF__carbon_thunk.7a3b9f04ddf4269e.Main(ptr noundef nonnull align 1 %_) #6 !dbg !46 {
// CHECK:STDOUT: define linkonce_odr void @_CF__carbon_thunk.7a3b9f04ddf4269e.Main(ptr noundef nonnull align 1 %_) #6 !dbg !46 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: call void @_CF.Main.d53b17eed3ce903c(ptr %_), !dbg !48
// CHECK:STDOUT: ret void, !dbg !48
@@ -84,7 +84,7 @@ fn H() -> i32 { return Cpp.G(); }
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @"\01__CF__carbon_thunk.Main"(ptr noundef nonnull align 4 dereferenceable(4) %_, ptr noundef nonnull align 4 dereferenceable(4) %_1) #3 !dbg !26 {
// CHECK:STDOUT: define linkonce_odr void @"\01__CF__carbon_thunk.Main"(ptr noundef nonnull align 4 dereferenceable(4) %_, ptr noundef nonnull align 4 dereferenceable(4) %_1) #3 !dbg !26 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %.loc6 = load i32, ptr %_, align 4, !dbg !29
// CHECK:STDOUT: %F.call = call i32 @_CF.Main(i32 %.loc6), !dbg !29
@@ -222,7 +222,7 @@ fn H() -> i32 { return Cpp.G(); }
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define noundef ptr @"\01__CC__carbon_thunk.C.Main"(ptr noundef nonnull returned align 4 dereferenceable(4) %_, ptr noundef nonnull align 4 dereferenceable(4) %_1) unnamed_addr #6 !dbg !74 {
// CHECK:STDOUT: define linkonce_odr noundef ptr @"\01__CC__carbon_thunk.C.Main"(ptr noundef nonnull returned align 4 dereferenceable(4) %_, ptr noundef nonnull align 4 dereferenceable(4) %_1) unnamed_addr #6 !dbg !74 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %.loc7_24.2 = load i32, ptr %_1, align 4, !dbg !77
// CHECK:STDOUT: call void @_CC.C.Main(ptr %_, i32 %.loc7_24.2), !dbg !77
@@ -0,0 +1,201 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/int.carbon
//
// AUTOUPDATE
// TIP: To test this file alone, run:
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/lower/testdata/interop/cpp/function/export/multiple_files.carbon
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/interop/cpp/function/export/multiple_files.carbon
// Each file that exports a Carbon function to C++ emits its own copy of the
// Carbon thunk for that function, so the thunk must have linkonce_odr linkage
// to avoid duplicate symbols when the files are linked together.
// --- other.carbon
package Other;
fn Identity(n: i32) -> i32 {
return n;
}
// --- a.carbon
library "[[@TEST_NAME]]";
import Other;
import Cpp inline '''
int UseA() { return Carbon::Other::Identity(3); }
''';
// --- b.carbon
library "[[@TEST_NAME]]";
import Other;
import Cpp inline '''
int UseB() { return Carbon::Other::Identity(4); }
''';
// CHECK:STDOUT: ; ---
// CHECK:STDOUT: ; ModuleID = 'other.carbon'
// CHECK:STDOUT: source_filename = "other.carbon"
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define i32 @_CIdentity.Other(i32 %n) #0 !dbg !23 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: ret i32 %n, !dbg !29
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: attributes #0 = { nounwind }
// CHECK:STDOUT:
// CHECK:STDOUT: !llvm.dbg.cu = !{!19}
// CHECK:STDOUT: !llvm.module.flags = !{!2, !3}
// CHECK:STDOUT:
// CHECK:STDOUT: !2 = !{i32 7, !"Dwarf Version", i32 5}
// CHECK:STDOUT: !3 = !{i32 2, !"Debug Info Version", i32 3}
// CHECK:STDOUT: !18 = !DIFile(filename: "other.carbon", directory: "")
// CHECK:STDOUT: !19 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !18, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
// CHECK:STDOUT: !20 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
// CHECK:STDOUT: !21 = !{!20, !20}
// CHECK:STDOUT: !22 = !DISubroutineType(types: !21)
// CHECK:STDOUT: !23 = distinct !DISubprogram(name: "Identity", linkageName: "_CIdentity.Other", scope: null, file: !18, line: 4, type: !22, spFlags: DISPFlagDefinition, unit: !19, retainedNodes: !30)
// CHECK:STDOUT: !24 = !DILocalVariable(arg: 1, scope: !23, type: !20)
// CHECK:STDOUT: !29 = !DILocation(line: 5, column: 3, scope: !23)
// CHECK:STDOUT: !30 = !{!24}
// CHECK:STDOUT:
// CHECK:STDOUT: ; ---
// CHECK:STDOUT: ; ModuleID = 'a.carbon'
// CHECK:STDOUT: source_filename = "a.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: ; Function Attrs: mustprogress uwtable
// CHECK:STDOUT: define dso_local noundef i32 @_Z4UseAv() #0 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %call = call noundef i32 @_ZN6Carbon5OtherL8IdentityEi(i32 noundef 3)
// CHECK:STDOUT: ret i32 %call
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress nounwind uwtable
// CHECK:STDOUT: define internal noundef i32 @_ZN6Carbon5OtherL8IdentityEi(i32 noundef %0) #1 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %retval = alloca i32, align 4
// CHECK:STDOUT: %.addr = alloca i32, align 4
// CHECK:STDOUT: store i32 %0, ptr %.addr, align 4, !tbaa !43
// CHECK:STDOUT: call void @_CIdentity__carbon_thunk.Other(ptr noundef nonnull align 4 dereferenceable(4) %.addr, ptr noundef nonnull align 4 dereferenceable(4) %retval)
// CHECK:STDOUT: %1 = load i32, ptr %retval, align 4
// CHECK:STDOUT: ret i32 %1
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: declare i32 @_CIdentity.Other(i32)
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define linkonce_odr void @_CIdentity__carbon_thunk.Other(ptr noundef nonnull align 4 dereferenceable(4) %_, ptr noundef nonnull align 4 dereferenceable(4) %_1) #2 !dbg !35 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %.1 = load i32, ptr %_, align 4, !dbg !38
// CHECK:STDOUT: %Identity.call = call i32 @_CIdentity.Other(i32 %.1), !dbg !38
// CHECK:STDOUT: store i32 %Identity.call, ptr %_1, align 4, !dbg !38
// CHECK:STDOUT: ret void, !dbg !38
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: attributes #0 = { 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 = { alwaysinline 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: attributes #2 = { nounwind "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 = !{!32}
// CHECK:STDOUT: !llvm.module.flags = !{!44, !45, !46, !2, !3}
// CHECK:STDOUT: !llvm.errno.tbaa = !{!48}
// CHECK:STDOUT:
// CHECK:STDOUT: !2 = !{i32 7, !"Dwarf Version", i32 5}
// CHECK:STDOUT: !3 = !{i32 2, !"Debug Info Version", i32 3}
// CHECK:STDOUT: !18 = !DIFile(filename: "other.carbon", directory: "")
// CHECK:STDOUT: !20 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
// CHECK:STDOUT: !31 = !DIFile(filename: "a.carbon", directory: "")
// CHECK:STDOUT: !32 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !31, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
// CHECK:STDOUT: !33 = !{null, !20, !20}
// CHECK:STDOUT: !34 = !DISubroutineType(types: !33)
// CHECK:STDOUT: !35 = distinct !DISubprogram(name: "Identity__carbon_thunk", linkageName: "_CIdentity__carbon_thunk.Other", scope: null, file: !18, line: 4, type: !34, spFlags: DISPFlagDefinition, unit: !32, retainedNodes: !39)
// CHECK:STDOUT: !36 = !DILocalVariable(arg: 1, scope: !35, type: !20)
// CHECK:STDOUT: !37 = !DILocalVariable(arg: 2, scope: !35, type: !20)
// CHECK:STDOUT: !38 = !DILocation(line: 4, column: 1, scope: !35)
// CHECK:STDOUT: !39 = !{!36, !37}
// CHECK:STDOUT: !40 = !{!"Simple C++ TBAA"}
// CHECK:STDOUT: !41 = !{!"omnipotent char", !40, i64 0}
// CHECK:STDOUT: !42 = !{!"int", !41, i64 0}
// CHECK:STDOUT: !43 = !{!42, !42, i64 0}
// CHECK:STDOUT: !44 = !{i32 8, !"PIC Level", i32 2}
// CHECK:STDOUT: !45 = !{i32 7, !"PIE Level", i32 2}
// CHECK:STDOUT: !46 = !{i32 7, !"uwtable", i32 2}
// CHECK:STDOUT: !47 = !{!"__libc_errno", !42, i64 0}
// CHECK:STDOUT: !48 = !{!47, !42, i64 0}
// CHECK:STDOUT:
// CHECK:STDOUT: ; ---
// CHECK:STDOUT: ; ModuleID = 'b.carbon'
// CHECK:STDOUT: source_filename = "b.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: ; Function Attrs: mustprogress uwtable
// CHECK:STDOUT: define dso_local noundef i32 @_Z4UseBv() #0 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %call = call noundef i32 @_ZN6Carbon5OtherL8IdentityEi(i32 noundef 4)
// CHECK:STDOUT: ret i32 %call
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress nounwind uwtable
// CHECK:STDOUT: define internal noundef i32 @_ZN6Carbon5OtherL8IdentityEi(i32 noundef %0) #1 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %retval = alloca i32, align 4
// CHECK:STDOUT: %.addr = alloca i32, align 4
// CHECK:STDOUT: store i32 %0, ptr %.addr, align 4, !tbaa !43
// CHECK:STDOUT: call void @_CIdentity__carbon_thunk.Other(ptr noundef nonnull align 4 dereferenceable(4) %.addr, ptr noundef nonnull align 4 dereferenceable(4) %retval)
// CHECK:STDOUT: %1 = load i32, ptr %retval, align 4
// CHECK:STDOUT: ret i32 %1
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: declare i32 @_CIdentity.Other(i32)
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define linkonce_odr void @_CIdentity__carbon_thunk.Other(ptr noundef nonnull align 4 dereferenceable(4) %_, ptr noundef nonnull align 4 dereferenceable(4) %_1) #2 !dbg !51 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %.1 = load i32, ptr %_, align 4, !dbg !54
// CHECK:STDOUT: %Identity.call = call i32 @_CIdentity.Other(i32 %.1), !dbg !54
// CHECK:STDOUT: store i32 %Identity.call, ptr %_1, align 4, !dbg !54
// CHECK:STDOUT: ret void, !dbg !54
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: attributes #0 = { 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 = { alwaysinline 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: attributes #2 = { nounwind "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 = !{!50}
// CHECK:STDOUT: !llvm.module.flags = !{!44, !45, !46, !2, !3}
// CHECK:STDOUT: !llvm.errno.tbaa = !{!48}
// CHECK:STDOUT:
// CHECK:STDOUT: !2 = !{i32 7, !"Dwarf Version", i32 5}
// CHECK:STDOUT: !3 = !{i32 2, !"Debug Info Version", i32 3}
// CHECK:STDOUT: !18 = !DIFile(filename: "other.carbon", directory: "")
// CHECK:STDOUT: !20 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
// CHECK:STDOUT: !33 = !{null, !20, !20}
// CHECK:STDOUT: !34 = !DISubroutineType(types: !33)
// CHECK:STDOUT: !40 = !{!"Simple C++ TBAA"}
// CHECK:STDOUT: !41 = !{!"omnipotent char", !40, i64 0}
// CHECK:STDOUT: !42 = !{!"int", !41, i64 0}
// CHECK:STDOUT: !43 = !{!42, !42, i64 0}
// CHECK:STDOUT: !44 = !{i32 8, !"PIC Level", i32 2}
// CHECK:STDOUT: !45 = !{i32 7, !"PIE Level", i32 2}
// CHECK:STDOUT: !46 = !{i32 7, !"uwtable", i32 2}
// CHECK:STDOUT: !47 = !{!"__libc_errno", !42, i64 0}
// CHECK:STDOUT: !48 = !{!47, !42, i64 0}
// CHECK:STDOUT: !49 = !DIFile(filename: "b.carbon", directory: "")
// CHECK:STDOUT: !50 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !49, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
// CHECK:STDOUT: !51 = distinct !DISubprogram(name: "Identity__carbon_thunk", linkageName: "_CIdentity__carbon_thunk.Other", scope: null, file: !18, line: 4, type: !34, spFlags: DISPFlagDefinition, unit: !50, retainedNodes: !55)
// CHECK:STDOUT: !52 = !DILocalVariable(arg: 1, scope: !51, type: !20)
// CHECK:STDOUT: !53 = !DILocalVariable(arg: 2, scope: !51, type: !20)
// CHECK:STDOUT: !54 = !DILocation(line: 4, column: 1, scope: !51)
// CHECK:STDOUT: !55 = !{!52, !53}
// CHECK:STDOUT:
@@ -196,7 +196,7 @@ fn F() {
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @_CMyCallback__carbon_thunk.Main(ptr noundef nonnull align 4 dereferenceable(4) %_, ptr noundef nonnull align 4 dereferenceable(4) %_1) #1 !dbg !36 {
// CHECK:STDOUT: define linkonce_odr void @_CMyCallback__carbon_thunk.Main(ptr noundef nonnull align 4 dereferenceable(4) %_, ptr noundef nonnull align 4 dereferenceable(4) %_1) #1 !dbg !36 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %.loc8 = load float, ptr %_, align 4, !dbg !39
// CHECK:STDOUT: %MyCallback.call = call i32 @_CMyCallback.Main(float %.loc8), !dbg !40
@@ -271,7 +271,7 @@ fn F() {
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @_CMyCallback__carbon_thunk.Main(ptr noundef nonnull align 4 dereferenceable(4) %_, ptr noundef nonnull align 4 dereferenceable(4) %_1) #1 !dbg !55 {
// CHECK:STDOUT: define linkonce_odr void @_CMyCallback__carbon_thunk.Main(ptr noundef nonnull align 4 dereferenceable(4) %_, ptr noundef nonnull align 4 dereferenceable(4) %_1) #1 !dbg !55 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %.loc5 = load float, ptr %_, align 4, !dbg !58
// CHECK:STDOUT: %MyCallback.call = call i32 @_CMyCallback.Main(float %.loc5), !dbg !58
@@ -484,7 +484,7 @@ fn F() {
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @_CMyCallback__carbon_thunk.Main(ptr noundef nonnull align 4 dereferenceable(4) %_, ptr noundef nonnull align 4 dereferenceable(4) %_1) #1 !dbg !108 {
// CHECK:STDOUT: define linkonce_odr void @_CMyCallback__carbon_thunk.Main(ptr noundef nonnull align 4 dereferenceable(4) %_, ptr noundef nonnull align 4 dereferenceable(4) %_1) #1 !dbg !108 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: call void @_CMyCallback.Main(ptr %_1, ptr %_), !dbg !112
// CHECK:STDOUT: ret void, !dbg !112
@@ -555,7 +555,7 @@ fn F() {
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @_CMyCallback__carbon_thunk.Main(ptr noundef nonnull align 4 dereferenceable(4) %_, ptr noundef nonnull align 4 dereferenceable(4) %_1) #1 !dbg !126 {
// CHECK:STDOUT: define linkonce_odr void @_CMyCallback__carbon_thunk.Main(ptr noundef nonnull align 4 dereferenceable(4) %_, ptr noundef nonnull align 4 dereferenceable(4) %_1) #1 !dbg !126 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: call void @_CMyCallback.Main(ptr %_1, ptr %_), !dbg !129
// CHECK:STDOUT: ret void, !dbg !129
@@ -194,7 +194,7 @@ fn F() {
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @_CMethod__carbon_thunk.C.Main(ptr noundef nonnull align 1 %self) #2 !dbg !44 {
// CHECK:STDOUT: define linkonce_odr void @_CMethod__carbon_thunk.C.Main(ptr noundef nonnull align 1 %self) #2 !dbg !44 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: call void @_CMethod.C.Main(ptr %self), !dbg !47
// CHECK:STDOUT: ret void, !dbg !47
@@ -288,7 +288,7 @@ fn F() {
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @_CMethod__carbon_thunk.C.Main(ptr noundef nonnull align 1 %self) #2 !dbg !73 {
// CHECK:STDOUT: define linkonce_odr void @_CMethod__carbon_thunk.C.Main(ptr noundef nonnull align 1 %self) #2 !dbg !73 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: call void @_CMethod.C.Main(ptr %self), !dbg !75
// CHECK:STDOUT: ret void, !dbg !75
+1 -1
View File
@@ -56,7 +56,7 @@ void f() {
// CHECK:STDOUT: declare ptr @_CGet.Main()
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define void @_CGet__carbon_thunk.Main(ptr noundef nonnull align 8 dereferenceable(8) %_) #1 !dbg !12 {
// CHECK:STDOUT: define linkonce_odr void @_CGet__carbon_thunk.Main(ptr noundef nonnull align 8 dereferenceable(8) %_) #1 !dbg !12 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %Get.call = call ptr @_CGet.Main(), !dbg !14
// CHECK:STDOUT: store ptr %Get.call, ptr %_, align 8, !dbg !14