1 // RUN: %clang_cc1 -triple=x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s 2 3 // Don't crash if the argument to __builtin_constant_p isn't scalar. 4 template <typename T> is_constant(const T v)5constexpr bool is_constant(const T v) { 6 return __builtin_constant_p(v); 7 } 8 9 template <typename T> 10 class numeric { 11 public: 12 using type = T; 13 14 template <typename S> numeric(S value)15 constexpr numeric(S value) 16 : value_(static_cast<T>(value)) {} 17 18 private: 19 const T value_; 20 }; 21 bcp()22bool bcp() { 23 return is_constant(numeric<int>(1)); 24 } 25 26 // PR45535 27 struct with_dtor { 28 ~with_dtor(); 29 }; 30 // CHECK: define {{.*}}bcp_stmt_expr_1 bcp_stmt_expr_1()31bool bcp_stmt_expr_1() { 32 // CHECK-NOT: call {{.*}}with_dtorD 33 return __builtin_constant_p(({with_dtor wd; 123;})); 34 } 35 36 int do_not_call(); 37 // CHECK: define {{.*}}bcp_stmt_expr_2 bcp_stmt_expr_2(int n)38bool bcp_stmt_expr_2(int n) { 39 // CHECK-NOT: call {{.*}}do_not_call 40 return __builtin_constant_p(({ 41 // This has a side-effect due to the VLA bound, so CodeGen should fold it 42 // to false. 43 typedef int arr[do_not_call()]; 44 n; 45 })); 46 // CHECK-NOT: } 47 // CHECK: ret i1 false 48 } 49