thunk_ast.carbon 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 --target=x86_64-linux-gnu
  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/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/thunk_ast.carbon
  14. // CHECK:STDOUT: TranslationUnitDecl {{0x[a-f0-9]+}} <<invalid sloc>> <invalid sloc>
  15. // --- thunk_required.h
  16. auto foo(short a) -> void;
  17. // CHECK:STDOUT: |-FunctionDecl {{0x[a-f0-9]+}} <./thunk_required.h:[[@LINE-1]]:1, col:22> col:6 used foo 'auto (short) -> void'
  18. // CHECK:STDOUT: | `-ParmVarDecl {{0x[a-f0-9]+}} <col:10, col:16> col:16 a 'short'
  19. // CHECK:STDOUT: `-FunctionDecl {{0x[a-f0-9]+}} <col:6> col:6 foo__carbon_thunk 'void (short * _Nonnull)' inline
  20. // CHECK:STDOUT: |-ParmVarDecl {{0x[a-f0-9]+}} <col:6> col:6 used a 'short * _Nonnull':'short *'
  21. // CHECK:STDOUT: |-ReturnStmt {{0x[a-f0-9]+}} <col:6>
  22. // CHECK:STDOUT: | `-CallExpr {{0x[a-f0-9]+}} <col:6> 'void'
  23. // CHECK:STDOUT: | |-ImplicitCastExpr {{0x[a-f0-9]+}} <col:6> 'auto (*)(short) -> void' <FunctionToPointerDecay>
  24. // CHECK:STDOUT: | | `-DeclRefExpr {{0x[a-f0-9]+}} <col:6> 'auto (short) -> void' Function {{0x[a-f0-9]+}} 'foo' 'auto (short) -> void'
  25. // CHECK:STDOUT: | `-ImplicitCastExpr {{0x[a-f0-9]+}} <col:6> 'short' <LValueToRValue>
  26. // CHECK:STDOUT: | `-UnaryOperator {{0x[a-f0-9]+}} <col:6> 'short' lvalue prefix '*' cannot overflow
  27. // CHECK:STDOUT: | `-ImplicitCastExpr {{0x[a-f0-9]+}} <col:6> 'short * _Nonnull':'short *' <LValueToRValue>
  28. // CHECK:STDOUT: | `-DeclRefExpr {{0x[a-f0-9]+}} <col:6> 'short * _Nonnull':'short *' lvalue ParmVar {{0x[a-f0-9]+}} 'a' 'short * _Nonnull':'short *'
  29. // CHECK:STDOUT: |-AlwaysInlineAttr {{0x[a-f0-9]+}} <<invalid sloc>> Implicit always_inline
  30. // CHECK:STDOUT: |-InternalLinkageAttr {{0x[a-f0-9]+}} <<invalid sloc>> Implicit
  31. // CHECK:STDOUT: `-AsmLabelAttr {{0x[a-f0-9]+}} <col:6> Implicit "_Z3foos.carbon_thunk"
  32. // CHECK:STDOUT: TranslationUnitDecl {{0x[a-f0-9]+}} <<invalid sloc>> <invalid sloc>
  33. // --- import_thunk_required.carbon
  34. library "[[@TEST_NAME]]";
  35. import Cpp library "thunk_required.h";
  36. fn F() {
  37. Cpp.foo(1 as i16);
  38. }
  39. // --- return_thunk_required.h
  40. auto foo() -> short;
  41. // CHECK:STDOUT: |-FunctionDecl {{0x[a-f0-9]+}} <./return_thunk_required.h:[[@LINE-1]]:1, col:15> col:6 used foo 'auto () -> short'
  42. // CHECK:STDOUT: `-FunctionDecl {{0x[a-f0-9]+}} <col:6> col:6 foo__carbon_thunk 'void (short * _Nonnull)' inline
  43. // CHECK:STDOUT: |-ParmVarDecl {{0x[a-f0-9]+}} <col:6> col:6 used return 'short * _Nonnull':'short *'
  44. // CHECK:STDOUT: |-CXXNewExpr {{0x[a-f0-9]+}} <col:6> 'short *' global Function {{0x[a-f0-9]+}} 'operator new' 'void *(__size_t, void *) noexcept'
  45. // CHECK:STDOUT: | |-CallExpr {{0x[a-f0-9]+}} <col:6> 'short'
  46. // CHECK:STDOUT: | | `-ImplicitCastExpr {{0x[a-f0-9]+}} <col:6> 'auto (*)() -> short' <FunctionToPointerDecay>
  47. // CHECK:STDOUT: | | `-DeclRefExpr {{0x[a-f0-9]+}} <col:6> 'auto () -> short' Function {{0x[a-f0-9]+}} 'foo' 'auto () -> short'
  48. // CHECK:STDOUT: | `-DeclRefExpr {{0x[a-f0-9]+}} <col:6> 'short * _Nonnull':'short *' lvalue ParmVar {{0x[a-f0-9]+}} 'return' 'short * _Nonnull':'short *'
  49. // CHECK:STDOUT: |-AlwaysInlineAttr {{0x[a-f0-9]+}} <<invalid sloc>> Implicit always_inline
  50. // CHECK:STDOUT: |-InternalLinkageAttr {{0x[a-f0-9]+}} <<invalid sloc>> Implicit
  51. // CHECK:STDOUT: `-AsmLabelAttr {{0x[a-f0-9]+}} <col:6> Implicit "_Z3foov.carbon_thunk"
  52. // --- import_return_thunk_required.carbon
  53. library "[[@TEST_NAME]]";
  54. import Cpp library "return_thunk_required.h";
  55. fn F() -> i16 {
  56. return Cpp.foo();
  57. }