function_param.carbon 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // AUTOUPDATE
  6. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/lower/testdata/array/function_param.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/array/function_param.carbon
  10. fn F(arr: [i32; 3], i: i32) -> i32 {
  11. return arr[i];
  12. }
  13. fn G() -> i32 {
  14. return F((1, 2, 3), 1);
  15. }
  16. // CHECK:STDOUT: ; ModuleID = 'function_param.carbon'
  17. // CHECK:STDOUT: source_filename = "function_param.carbon"
  18. // CHECK:STDOUT:
  19. // CHECK:STDOUT: @array.loc16_11.1 = internal constant [3 x i32] [i32 1, i32 2, i32 3]
  20. // CHECK:STDOUT:
  21. // CHECK:STDOUT: define i32 @F(ptr %arr, i32 %i) {
  22. // CHECK:STDOUT: entry:
  23. // CHECK:STDOUT: %.loc12_15.2.array.index = getelementptr inbounds [3 x i32], ptr %arr, i32 0, i32 %i
  24. // CHECK:STDOUT: %.loc12_15.3 = load i32, ptr %.loc12_15.2.array.index, align 4
  25. // CHECK:STDOUT: ret i32 %.loc12_15.3
  26. // CHECK:STDOUT: }
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: define i32 @G() {
  29. // CHECK:STDOUT: entry:
  30. // CHECK:STDOUT: %.loc16_20.2.temp = alloca [3 x i32], align 4
  31. // CHECK:STDOUT: %.loc16_20.4.array.index = getelementptr inbounds [3 x i32], ptr %.loc16_20.2.temp, i32 0, i32 0
  32. // CHECK:STDOUT: %.loc16_20.7.array.index = getelementptr inbounds [3 x i32], ptr %.loc16_20.2.temp, i32 0, i32 1
  33. // CHECK:STDOUT: %.loc16_20.10.array.index = getelementptr inbounds [3 x i32], ptr %.loc16_20.2.temp, i32 0, i32 2
  34. // CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %.loc16_20.2.temp, ptr align 4 @array.loc16_11.1, i64 12, i1 false)
  35. // CHECK:STDOUT: %F.call = call i32 @F(ptr %.loc16_20.2.temp, i32 1)
  36. // CHECK:STDOUT: ret i32 %F.call
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT:
  39. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
  40. // CHECK:STDOUT: declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }