const-init-cxx2a.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s -std=c++2a | FileCheck %s --implicit-check-not=cxx_global_var_init --implicit-check-not=cxa_atexit
  2. // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-pch -o %t.pch %s -std=c++2a
  3. // RUN: %clang_cc1 -triple x86_64-linux-gnu -include-pch %t.pch -x c++ /dev/null -emit-llvm -o - -std=c++2a | FileCheck %s --implicit-check-not=cxx_global_var_init --implicit-check-not=cxa_atexit
  4. // CHECK: @a = global i32 123,
  5. int a = (delete new int, 123);
  6. struct B {
  7. constexpr B() {}
  8. constexpr ~B() { n *= 5; }
  9. int n = 123;
  10. };
  11. // CHECK: @b = global {{.*}} i32 123
  12. extern constexpr B b = B();
  13. // CHECK: @_ZL1c = internal global {{.*}} i32 123
  14. const B c;
  15. int use_c() { return c.n; }
  16. struct D {
  17. int n;
  18. constexpr ~D() {}
  19. };
  20. D d;
  21. // CHECK: @d = global {{.*}} zeroinitializer
  22. D d_arr[3];
  23. // CHECK: @d_arr = global {{.*}} zeroinitializer
  24. thread_local D d_tl;
  25. // CHECK: @d_tl = thread_local global {{.*}} zeroinitializer
  26. // CHECK-NOT: @llvm.global_ctors
  27. // CHECK-LABEL: define {{.*}} @_Z1fv(
  28. void f() {
  29. // CHECK-NOT: call
  30. // CHECK: call {{.*}}memcpy
  31. // CHECK-NOT: call
  32. // CHECK: call {{.*}}memset
  33. // CHECK-NOT: call
  34. // CHECK: }
  35. constexpr B b;
  36. D d = D();
  37. }
  38. // CHECK-LABEL: define {{.*}} @_Z1gv(
  39. void g() {
  40. // CHECK-NOT: call
  41. // CHECK-NOT: cxa_guard
  42. // CHECK-NOT: _ZGV
  43. // CHECK: }
  44. static constexpr B b1;
  45. static const B b2;
  46. static D d;
  47. thread_local D d_tl;
  48. }