114 lines · cpp
1// RUN: %clang_cc1 -std=c++20 %s -emit-llvm -o - -triple x86_64-linux -DCONSTEXPR= | FileCheck %s2// RUN: %clang_cc1 -std=c++20 %s -emit-llvm -o - -triple x86_64-linux -DCONSTEXPR=constexpr | FileCheck %s --check-prefix=CONST3 4template<typename T> CONSTEXPR T id(T v) { return v; }5template<auto V> auto value = id(V);6 7// CHECK: call {{.*}} @_Z2idIiET_S0_(i32 noundef 1)8// CONST: @_Z5valueILi1EE = weak_odr {{.*}} i32 1,9template int value<1>;10 11// CHECK: call {{.*}} @_Z2idIyET_S0_(i64 noundef -1)12// CONST: @_Z5valueILy18446744073709551615EE = weak_odr {{.*}} i64 -1,13template unsigned long long value<-1ULL>;14 15// CHECK: call {{.*}} @_Z2idIfET_S0_(float noundef 1.000000e+00)16// CONST: @_Z5valueILf3f800000EE = weak_odr {{.*}} float 1.000000e+00,17template float value<1.0f>;18// CHECK: call {{.*}} @_Z2idIdET_S0_(double noundef 1.000000e+00)19// CONST: @_Z5valueILd3ff0000000000000EE = weak_odr {{.*}} double 1.000000e+00,20template double value<1.0>;21 22enum E{ E1, E2};23 24// CHECK: call {{.*}} @_Z2idI1EET_S1_(i32 noundef 1)25// CONST: @_Z5valueIL1E1EE = weak_odr {{.*}} i32 1,26template E value<E2>;27 28int n;29// CHECK: call {{.*}} @_Z2idIPiET_S1_(ptr noundef @n)30// CONST: @_Z5valueIXadL_Z1nEEE = weak_odr {{.*}} ptr @n,31template int *value<&n>;32 33struct A { int a[3]; } a;34// CHECK: call {{.*}} @_Z2idIPiET_S1_(ptr noundef @a)35// CONST: @_Z5valueIXadsoiL_Z1aEEEE = weak_odr {{.*}} ptr @a,36template int *value<&a.a[0]>;37// CHECK: call {{.*}} @_Z2idIPiET_S1_(ptr noundef getelementptr (i8, ptr @a, i64 4))38// CONST: @_Z5valueIXadsoiL_Z1aE4EEE = weak_odr {{.*}} ptr getelementptr (i8, ptr @a, i64 4),39template int *value<&a.a[1]>;40// CHECK: call {{.*}} @_Z2idIPiET_S1_(ptr noundef getelementptr (i8, ptr @a, i64 8))41// CONST: @_Z5valueIXadsoiL_Z1aE8EEE = weak_odr {{.*}} ptr getelementptr (i8, ptr @a, i64 8),42template int *value<&a.a[2]>;43// CHECK: call {{.*}} @_Z2idIPiET_S1_(ptr noundef getelementptr (i8, ptr @a, i64 12))44// CONST: @_Z5valueIXadsoiL_Z1aE12pEEE = weak_odr {{.*}} ptr getelementptr (i8, ptr @a, i64 12),45template int *value<&a.a[3]>;46 47union U {48 int x, y;49 union {50 int x, y;51 } internal;52} u;53 54// CHECK: call {{.*}} @_Z2idIPiET_S1_(ptr noundef @u)55// CONST: @_Z5valueIXadsoiL_Z1uE_EEE = weak_odr {{.*}} ptr @u,56template int *value<&u.x>;57// CHECK: call {{.*}} @_Z2idIPiET_S1_(ptr noundef @u)58// CONST: @_Z5valueIXadsoiL_Z1uE_0EEE = weak_odr {{.*}} ptr @u,59template int *value<&u.y>;60// CHECK: call {{.*}} @_Z2idIPiET_S1_(ptr noundef @u)61// CONST: @_Z5valueIXadsoiL_Z1uE_1_0EEE = weak_odr {{.*}} ptr @u,62template int *value<&u.internal.y>;63 64struct B { int x, y; };65// CHECK: call {{.*}} @_Z2idIM1BiET_S2_(i64 0)66// CONST: @_Z5valueIXadL_ZN1B1xEEEE = weak_odr {{.*}} i64 0,67template int B::*value<&B::x>;68// CHECK: call {{.*}} @_Z2idIM1BiET_S2_(i64 4)69// CONST: @_Z5valueIXadL_ZN1B1yEEEE = weak_odr {{.*}} i64 4,70template int B::*value<&B::y>;71 72struct C : A, B { int z; };73// CHECK: call {{.*}} @_Z2idIM1CiET_S2_(i64 12)74// CONST: @_Z5valueIXmcM1CiadL_ZN1B1xEE12EEE = weak_odr {{.*}} i64 12,75template int C::*value<(int C::*)&B::x>;76// CHECK: call {{.*}} @_Z2idIM1BiET_S2_(i64 8)77// CONST: @_Z5valueIXmcM1BiadL_ZN1C1zEEn12EEE = weak_odr {{.*}} i64 8,78template int B::*value<(int B::*)&C::z>;79 80// CHECK: store i32 1,81// CHECK: store i32 2,82// CHECK: load i64,83// CHECK: call {{.*}} @_Z2idICiET_S1_(i64 noundef %84// CONST: @_Z5valueIXtlCiLi1ELi2EEEE = weak_odr {{.*}} { i32, i32 } { i32 1, i32 2 },85template _Complex int value<1 + 2j>;86 87// CHECK: store float 1.000000e+00,88// CHECK: store float 2.000000e+00,89// CHECK: load <2 x float>,90// CHECK: call {{.*}} @_Z2idICfET_S1_(<2 x float> noundef %91// CONST: @_Z5valueIXtlCfLf3f800000ELf40000000EEEE = weak_odr {{.*}} { float, float } { float 1.000000e+00, float 2.000000e+00 },92template _Complex float value<1.0f + 2.0fj>;93 94using V3i __attribute__((ext_vector_type(3))) = int;95// CHECK: call {{.*}} @_Z2idIDv3_iET_S1_(<3 x i32> noundef <i32 1, i32 2, i32 3>)96// CONST: @_Z5valueIXtlDv3_iLi1ELi2ELi3EEEE = weak_odr {{.*}} <3 x i32> <i32 1, i32 2, i32 3>97template V3i value<V3i{1, 2, 3}>;98 99using V3f [[gnu::vector_size(12)]] = float;100// CHECK: call {{.*}} @_Z2idIDv3_fET_S1_(<3 x float> noundef <float 1.000000e+00, float 2.000000e+00, float 3.000000e+00>)101// CONST: @_Z5valueIXtlDv3_fLf3f800000ELf40000000ELf40400000EEEE = weak_odr {{.*}} <3 x float> <float 1.000000e+00, float 2.000000e+00, float 3.000000e+00>102template V3f value<V3f{1, 2, 3}>;103 104 105template <int& i>106void setByRef() {107 i = 1;108}109 110void callSetByRefWithSubobject() {111 // CHECK: store i32 1, ptr getelementptr (i8, ptr @a, i64 4)112 setByRef<a.a[1]>();113}114