brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · 39416b9 Raw
50 lines · cpp
1// RUN: %clang_cc1 -triple=x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s2// RUN: %clang_cc1 -triple=x86_64-linux-gnu -emit-llvm -o - %s -fexperimental-new-constant-interpreter | FileCheck %s3 4// Don't crash if the argument to __builtin_constant_p isn't scalar.5template <typename T>6constexpr bool is_constant(const T v) {7  return __builtin_constant_p(v);8}9 10template <typename T>11class numeric {12 public:13  using type = T;14 15  template <typename S>16  constexpr numeric(S value)17      : value_(static_cast<T>(value)) {}18 19 private:20  const T value_;21};22 23bool bcp() {24  return is_constant(numeric<int>(1));25}26 27// PR4553528struct with_dtor {29  ~with_dtor();30};31// CHECK: define {{.*}}bcp_stmt_expr_132bool bcp_stmt_expr_1() {33  // CHECK-NOT: call {{.*}}with_dtorD34  return __builtin_constant_p(({with_dtor wd; 123;}));35}36 37int do_not_call();38// CHECK: define {{.*}}bcp_stmt_expr_239bool bcp_stmt_expr_2(int n) {40  // CHECK-NOT: call {{.*}}do_not_call41  return __builtin_constant_p(({42    // This has a side-effect due to the VLA bound, so CodeGen should fold it43    // to false.44    typedef int arr[do_not_call()];45    n;46  }));47  // CHECK-NOT: }48  // CHECK: ret i1 false49}50