68 lines · cpp
1// RUN: %clang_cc1 -std=c++98 -Wno-constant-evaluated -triple x86_64-linux -include %s -verify %s -emit-llvm -o - | FileCheck %s2// RUN: %clang_cc1 -std=c++98 -Wno-constant-evaluated -triple x86_64-linux -emit-pch %s -o %t3// RUN: %clang_cc1 -std=c++98 -Wno-constant-evaluated -triple x86_64-linux -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s4 5// RUN: %clang_cc1 -std=c++11 -Wno-constant-evaluated -triple x86_64-linux -include %s -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CXX116// RUN: %clang_cc1 -std=c++11 -Wno-constant-evaluated -triple x86_64-linux -emit-pch %s -o %t-cxx117// RUN: %clang_cc1 -std=c++11 -Wno-constant-evaluated -triple x86_64-linux -include-pch %t-cxx11 -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CXX118 9// RUN: %clang_cc1 -std=c++20 -Wno-constant-evaluated -triple x86_64-linux -include %s -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CXX1110// RUN: %clang_cc1 -std=c++20 -Wno-constant-evaluated -triple x86_64-linux -emit-pch %s -o %t-cxx1111// RUN: %clang_cc1 -std=c++20 -Wno-constant-evaluated -triple x86_64-linux -include-pch %t-cxx11 -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CXX1112 13// expected-no-diagnostics14 15#ifndef HEADER_INCLUDED16#define HEADER_INCLUDED17 18// CHECK-DAG: @a ={{.*}} global i8 1,19// CHECK-DAG: @b ={{.*}} constant i8 1,20// CXX11-DAG: @c ={{.*}} constant i8 1,21// CHECK-DAG: @d ={{.*}} global float 1.000000e+0022// CHECK-DAG: @e ={{.*}} constant float 1.000000e+0023 24bool a = __builtin_is_constant_evaluated();25extern const bool b = __builtin_is_constant_evaluated();26#if __cplusplus >= 201103L27extern constexpr bool c = __builtin_is_constant_evaluated();28#endif29float d = __builtin_is_constant_evaluated();30extern const float e = __builtin_is_constant_evaluated();31 32void g(...);33 34// CHECK-LABEL: define {{.*}} @_Z1fv(35// CHECK: store i8 0, ptr %[[A:.*]],36// CHECK: store i8 1, ptr %[[B:.*]],37// CXX11: store i8 1, ptr %[[C:.*]],38// CHECK: store float 0.000000e+00, ptr %[[D:.*]],39// CHECK: store float 0.000000e+00, ptr %[[E:.*]],40// CHECK: load i8, ptr %[[A]],41// CHECK: call {{.*}} @_Z1gz(i32 noundef %{{[^,]+}}, i32 noundef 142// CXX11-SAME: , i32 noundef 143// CHECK-SAME: , double noundef %{{[^,]+}}, double noundef 0.000000e+00)44void f() {45 bool a = __builtin_is_constant_evaluated();46 const bool b = __builtin_is_constant_evaluated();47#if __cplusplus >= 201103L48 constexpr bool c = __builtin_is_constant_evaluated();49#endif50 float d = __builtin_is_constant_evaluated();51 const float e = __builtin_is_constant_evaluated();52 g(a, b53#if __cplusplus >= 201103L54 , c55#endif56 , d, e);57}58 59#else60 61_Static_assert(b, "");62#if __cplusplus >= 201103L63static_assert(c, "");64#endif65_Static_assert(__builtin_constant_p(1) ? e == 1.0f : false, "");66 67#endif68