thunk_ast.carbon 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/int.carbon
  6. // EXTRA-ARGS: --dump-cpp-ast
  7. // SET-CHECK-SUBSET
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/function/export/thunk_ast.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/function/export/thunk_ast.carbon
  14. // CHECK:STDOUT: TranslationUnitDecl {{0x[a-f0-9]+}} <<invalid sloc>> <invalid sloc>
  15. // CHECK:STDOUT: |-NamespaceDecl {{0x[a-f0-9]+}} <<invalid sloc>> <invalid sloc> Carbon
  16. // --- thunk_with_args_and_return.carbon
  17. library "[[@TEST_NAME]]";
  18. import Cpp;
  19. fn F(i: i32) -> i32 {
  20. // CHECK:STDOUT: | `-FunctionDecl {{0x[a-f0-9]+}} <thunk_with_args_and_return.carbon:[[@LINE-1]]:21> col:21 used F 'int (int)' inline
  21. // CHECK:STDOUT: | |-ParmVarDecl {{0x[a-f0-9]+}} <col:21> col:21 used 'int'
  22. // CHECK:STDOUT: | |-CompoundStmt {{0x[a-f0-9]+}} <col:21>
  23. // CHECK:STDOUT: | | |-DeclStmt {{0x[a-f0-9]+}} <col:21>
  24. // CHECK:STDOUT: | | | `-VarDecl {{0x[a-f0-9]+}} <col:21> col:21 used return_storage 'int' nrvo
  25. // CHECK:STDOUT: | | |-CallExpr {{0x[a-f0-9]+}} <col:21> 'void'
  26. // CHECK:STDOUT: | | | |-ImplicitCastExpr {{0x[a-f0-9]+}} <col:21> 'void (*)(int &, int &)' <FunctionToPointerDecay>
  27. // CHECK:STDOUT: | | | | `-DeclRefExpr {{0x[a-f0-9]+}} <col:21> 'void (int &, int &)' Function {{0x[a-f0-9]+}} 'F__carbon_thunk' 'void (int &, int &)'
  28. // CHECK:STDOUT: | | | |-DeclRefExpr {{0x[a-f0-9]+}} <col:21> 'int' lvalue ParmVar {{0x[a-f0-9]+}} depth 0 index 0 'int'
  29. // CHECK:STDOUT: | | | `-DeclRefExpr {{0x[a-f0-9]+}} <col:21> 'int' lvalue Var {{0x[a-f0-9]+}} 'return_storage' 'int'
  30. // CHECK:STDOUT: | | `-ReturnStmt {{0x[a-f0-9]+}} <col:21> nrvo_candidate(Var {{0x[a-f0-9]+}} 'return_storage' 'int')
  31. // CHECK:STDOUT: | | `-DeclRefExpr {{0x[a-f0-9]+}} <col:21> 'int' lvalue Var {{0x[a-f0-9]+}} 'return_storage' 'int'
  32. // CHECK:STDOUT: | |-AlwaysInlineAttr {{0x[a-f0-9]+}} <<invalid sloc>> Implicit always_inline
  33. // CHECK:STDOUT: | `-InternalLinkageAttr {{0x[a-f0-9]+}} <<invalid sloc>> Implicit
  34. // CHECK:STDOUT: `-FunctionDecl {{0x[a-f0-9]+}} <line:35:1, line:37:1> line:35:5 G 'int (int)'
  35. // CHECK:STDOUT: |-ParmVarDecl {{0x[a-f0-9]+}} <col:7, col:11> col:11 used i 'int'
  36. // CHECK:STDOUT: `-CompoundStmt {{0x[a-f0-9]+}} <col:14, line:37:1>
  37. // CHECK:STDOUT: `-ReturnStmt {{0x[a-f0-9]+}} <line:36:3, col:21>
  38. // CHECK:STDOUT: `-CallExpr {{0x[a-f0-9]+}} <col:10, col:21> 'int'
  39. // CHECK:STDOUT: |-ImplicitCastExpr {{0x[a-f0-9]+}} <col:10, col:18> 'int (*)(int)' <FunctionToPointerDecay>
  40. // CHECK:STDOUT: | `-DeclRefExpr {{0x[a-f0-9]+}} <col:10, col:18> 'int (int)' lvalue Function {{0x[a-f0-9]+}} 'F' 'int (int)'
  41. // CHECK:STDOUT: | `-NestedNameSpecifier Namespace {{0x[a-f0-9]+}} 'Carbon'
  42. // CHECK:STDOUT: `-ImplicitCastExpr {{0x[a-f0-9]+}} <col:20> 'int' <LValueToRValue>
  43. // CHECK:STDOUT: `-DeclRefExpr {{0x[a-f0-9]+}} <col:20> 'int' lvalue ParmVar {{0x[a-f0-9]+}} 'i' 'int'
  44. return i;
  45. }
  46. inline Cpp '''
  47. int G(int i) {
  48. return Carbon::F(i);
  49. }
  50. ''';