brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.6 KiB · dd760b4 Raw
161 lines · cpp
1// RUN: %clang_cc1 -triple x86_64-linux -fblocks -emit-llvm -o - %s -std=c++1y | FileCheck %s2 3// CHECK: @"_ZZZNK17pr18020_constexpr3$_1clEvENKUlvE_clEvE2l2" =4// CHECK: internal global ptr @"_ZZNK17pr18020_constexpr3$_1clEvE2l1"5// CHECK: @_ZZL14deduced_returnvE1n = internal global i32 426// CHECK: @_ZZZL20block_deduced_returnvEUb_E1n = internal global i32 427// CHECK: @_ZZ18static_local_labelPvE1q = linkonce_odr global ptr blockaddress(@_Z18static_local_labelPv, %{{.*}})8// CHECK: @"_ZZNK3$_2clEvE1x" = internal global i32 429 10namespace pr6769 {11struct X {12  static void f();13};14 15void X::f() {16  static int *i;17  {18    struct Y {19      static void g() {20        i = new int();21	*i = 100;22	(*i) = (*i) +1;23      }24    };25    (void)Y::g();26  }27  (void)i;28}29}30 31namespace pr7101 {32void foo() {33    static int n = 0;34    struct Helper {35        static void Execute() {36            n++;37        }38    };39    Helper::Execute();40}41}42 43// These tests all break the assumption that the static var decl has to be44// emitted before use of the var decl.  This happens because we defer emission45// of variables with internal linkage and no initialization side effects, such46// as 'x'.  Then we hit operator()() in 'f', and emit the callee before we emit47// the arguments, so we emit the innermost function first.48 49namespace pr18020_lambda {50// Referring to l1 before emitting it used to crash.51auto x = []() {52  static int l1 = 0;53  return [] { return l1; };54};55int f() { return x()(); }56}57 58// CHECK-LABEL: define internal noundef i32 @"_ZZNK14pr18020_lambda3$_0clEvENKUlvE_clEv"59// CHECK: load i32, ptr @"_ZZNK14pr18020_lambda3$_0clEvE2l1"60 61namespace pr18020_constexpr {62// Taking the address of l1 in a constant expression used to crash.63auto x = []() {64  static int l1 = 0;65  return [] {66    static int *l2 = &l1;67    return *l2;68  };69};70int f() { return x()(); }71}72 73// CHECK-LABEL: define internal noundef i32 @"_ZZNK17pr18020_constexpr3$_1clEvENKUlvE_clEv"74// CHECK: load ptr, ptr @"_ZZZNK17pr18020_constexpr3$_1clEvENKUlvE_clEvE2l2"75 76// Lambda-less reduction that references l1 before emitting it.  This didn't77// crash if you put it in a namespace.78struct pr18020_class {79  auto operator()() {80    static int l1 = 0;81    struct U {82      int operator()() { return l1; }83    };84    return U();85  }86};87static pr18020_class x;88int pr18020_f() { return x()(); }89 90// CHECK-LABEL: define linkonce_odr noundef i32 @_ZZN13pr18020_classclEvEN1UclEv91// CHECK: load i32, ptr @_ZZN13pr18020_classclEvE2l192 93// In this test case, the function containing the static local will not be94// emitted because it is unneeded. However, the operator call of the inner class95// is called, and the static local is referenced and must be emitted.96static auto deduced_return() {97  static int n = 42;98  struct S { int *operator()() { return &n; } };99  return S();100}101extern "C" int call_deduced_return_operator() {102  return *decltype(deduced_return())()();103}104 105// CHECK-LABEL: define{{.*}} i32 @call_deduced_return_operator()106// CHECK: call noundef ptr @_ZZL14deduced_returnvEN1SclEv(107// CHECK: load i32, ptr %108// CHECK: ret i32 %109 110// CHECK-LABEL: define internal noundef ptr @_ZZL14deduced_returnvEN1SclEv(ptr {{[^,]*}} %this)111// CHECK: ret ptr @_ZZL14deduced_returnvE1n112 113static auto block_deduced_return() {114  auto (^b)() = ^() {115    static int n = 42;116    struct S { int *operator()() { return &n; } };117    return S();118  };119  return b();120}121extern "C" int call_block_deduced_return() {122  return *decltype(block_deduced_return())()();123}124 125// CHECK-LABEL: define{{.*}} i32 @call_block_deduced_return()126// CHECK: call noundef ptr @_ZZZL20block_deduced_returnvEUb_EN1SclEv(127// CHECK: load i32, ptr %128// CHECK: ret i32 %129 130// CHECK-LABEL: define internal noundef ptr @_ZZZL20block_deduced_returnvEUb_EN1SclEv(ptr {{[^,]*}} %this) #1 align 2 {131// CHECK: ret ptr @_ZZZL20block_deduced_returnvEUb_E1n132 133inline auto static_local_label(void *p) {134  if (p)135    goto *p;136  static void *q = &&label;137  struct S { static void *get() { return q; } };138  return S();139label:140  __builtin_abort();141}142void *global_label = decltype(static_local_label(0))::get();143 144// CHECK-LABEL: define linkonce_odr noundef ptr @_ZZ18static_local_labelPvEN1S3getEv()145// CHECK: %[[lbl:[^ ]*]] = load ptr, ptr @_ZZ18static_local_labelPvE1q146// CHECK: ret ptr %[[lbl]]147 148auto global_lambda = []() {149  static int x = 42;150  struct S { static int *get() { return &x; } };151  return S();152};153extern "C" int use_global_lambda() {154  return *decltype(global_lambda())::get();155}156// CHECK-LABEL: define{{.*}} i32 @use_global_lambda()157// CHECK: call noundef ptr @"_ZZNK3$_2clEvEN1S3getEv"()158 159// CHECK-LABEL: define internal noundef ptr @"_ZZNK3$_2clEvEN1S3getEv"()160// CHECK: ret ptr @"_ZZNK3$_2clEvE1x"161