mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-29 06:24:57 +01:00
Change impls from `<interface>.impl` to `<self>.as.<interface>.impl`, and *member* functions to `<parent scope>.<fn>` (non-member functions exclude their parent scope). Stop special-casing builtin functions, given the new naming scheme. The purpose of this is to make it clearer when a member function is being accessed and, if so, which member function. In particular, we often access interface `Op` functions. The builtin function special-casing was intended to help with that, but we still have lots of `Op` functions. This particular approach should make the interactions clearer. This changes up queueing of block IDs a little because, in particular, we need to process bodies of entities only after constants finish processing. But, it should also result in less memory usage during processing because it means we have less on the insts stack at any given time, since we track a block rather than all instructions contained by the block.
127 lines
6.0 KiB
Plaintext
127 lines
6.0 KiB
Plaintext
// 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/method.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/interop/cpp/method.carbon
|
|
|
|
// --- methods.h
|
|
|
|
struct A {
|
|
int by_val() const { return n; }
|
|
int by_ref() { return n; }
|
|
int n;
|
|
};
|
|
|
|
// --- call_by_val.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
import Cpp library "methods.h";
|
|
|
|
fn UseVal(a: Cpp.A) -> i32 {
|
|
return a.by_val();
|
|
}
|
|
|
|
// --- call_by_ref.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
import Cpp library "methods.h";
|
|
|
|
fn UseVal(a: Cpp.A*) -> i32 {
|
|
return a->by_ref();
|
|
}
|
|
|
|
// CHECK:STDOUT: ; ModuleID = 'call_by_val.carbon'
|
|
// CHECK:STDOUT: source_filename = "call_by_val.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 = type { i32 }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: $_ZNK1A6by_valEv = comdat any
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: define i32 @_CUseVal.Main(ptr %a) !dbg !7 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: %A.by_val.call = call i32 @_ZNK1A6by_valEv(ptr %a), !dbg !10
|
|
// CHECK:STDOUT: ret i32 %A.by_val.call, !dbg !11
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: mustprogress noinline nounwind optnone
|
|
// CHECK:STDOUT: define linkonce_odr dso_local i32 @_ZNK1A6by_valEv(ptr nonnull align 4 dereferenceable(4) %this) #0 comdat align 2 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: %this.addr = alloca ptr, align 8
|
|
// CHECK:STDOUT: store ptr %this, ptr %this.addr, align 8
|
|
// CHECK:STDOUT: %this1 = load ptr, ptr %this.addr, align 8
|
|
// CHECK:STDOUT: %n = getelementptr inbounds nuw %struct.A, ptr %this1, i32 0, i32 0
|
|
// CHECK:STDOUT: %0 = load i32, ptr %n, align 4
|
|
// CHECK:STDOUT: ret i32 %0
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: attributes #0 = { mustprogress noinline nounwind optnone "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="0" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4}
|
|
// CHECK:STDOUT: !llvm.dbg.cu = !{!5}
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
|
|
// CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
|
|
// CHECK:STDOUT: !2 = !{i32 1, !"wchar_size", i32 4}
|
|
// CHECK:STDOUT: !3 = !{i32 8, !"PIC Level", i32 0}
|
|
// CHECK:STDOUT: !4 = !{i32 7, !"PIE Level", i32 2}
|
|
// CHECK:STDOUT: !5 = distinct !DICompileUnit(language: DW_LANG_C, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
|
|
// CHECK:STDOUT: !6 = !DIFile(filename: "call_by_val.carbon", directory: "")
|
|
// CHECK:STDOUT: !7 = distinct !DISubprogram(name: "UseVal", linkageName: "_CUseVal.Main", scope: null, file: !6, line: 6, type: !8, spFlags: DISPFlagDefinition, unit: !5)
|
|
// CHECK:STDOUT: !8 = !DISubroutineType(types: !9)
|
|
// CHECK:STDOUT: !9 = !{}
|
|
// CHECK:STDOUT: !10 = !DILocation(line: 7, column: 10, scope: !7)
|
|
// CHECK:STDOUT: !11 = !DILocation(line: 7, column: 3, scope: !7)
|
|
// CHECK:STDOUT: ; ModuleID = 'call_by_ref.carbon'
|
|
// CHECK:STDOUT: source_filename = "call_by_ref.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 = type { i32 }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: $_ZN1A6by_refEv = comdat any
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: define i32 @_CUseVal.Main(ptr %a) !dbg !7 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: %A.by_ref.call = call i32 @_ZN1A6by_refEv(ptr %a), !dbg !10
|
|
// CHECK:STDOUT: ret i32 %A.by_ref.call, !dbg !11
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: mustprogress noinline nounwind optnone
|
|
// CHECK:STDOUT: define linkonce_odr dso_local i32 @_ZN1A6by_refEv(ptr nonnull align 4 dereferenceable(4) %this) #0 comdat align 2 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: %this.addr = alloca ptr, align 8
|
|
// CHECK:STDOUT: store ptr %this, ptr %this.addr, align 8
|
|
// CHECK:STDOUT: %this1 = load ptr, ptr %this.addr, align 8
|
|
// CHECK:STDOUT: %n = getelementptr inbounds nuw %struct.A, ptr %this1, i32 0, i32 0
|
|
// CHECK:STDOUT: %0 = load i32, ptr %n, align 4
|
|
// CHECK:STDOUT: ret i32 %0
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: attributes #0 = { mustprogress noinline nounwind optnone "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="0" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4}
|
|
// CHECK:STDOUT: !llvm.dbg.cu = !{!5}
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
|
|
// CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
|
|
// CHECK:STDOUT: !2 = !{i32 1, !"wchar_size", i32 4}
|
|
// CHECK:STDOUT: !3 = !{i32 8, !"PIC Level", i32 0}
|
|
// CHECK:STDOUT: !4 = !{i32 7, !"PIE Level", i32 2}
|
|
// CHECK:STDOUT: !5 = distinct !DICompileUnit(language: DW_LANG_C, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
|
|
// CHECK:STDOUT: !6 = !DIFile(filename: "call_by_ref.carbon", directory: "")
|
|
// CHECK:STDOUT: !7 = distinct !DISubprogram(name: "UseVal", linkageName: "_CUseVal.Main", scope: null, file: !6, line: 6, type: !8, spFlags: DISPFlagDefinition, unit: !5)
|
|
// CHECK:STDOUT: !8 = !DISubroutineType(types: !9)
|
|
// CHECK:STDOUT: !9 = !{}
|
|
// CHECK:STDOUT: !10 = !DILocation(line: 7, column: 10, scope: !7)
|
|
// CHECK:STDOUT: !11 = !DILocation(line: 7, column: 3, scope: !7)
|