73 lines · cpp
1// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -fcxx-exceptions -o - %s | FileCheck %s2// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -fcxx-exceptions -o - %s -fexperimental-new-constant-interpreter | FileCheck %s3 4 5/// In the if expression below, the read from s.i should fail.6/// If it doesn't, and we actually read the value 0, the call to7/// func() will always occur, resuliting in a runtime failure.8 9struct S {10 mutable int i = 0;11};12 13void func() {14 __builtin_abort();15};16 17void setI(const S &s) {18 s.i = 12;19}20 21int main() {22 const S s;23 24 setI(s);25 26 if (s.i == 0)27 func();28 29 return 0;30}31 32// CHECK: define dso_local noundef i32 @main()33// CHECK: br34// CHECK: if.then35// CHECK: if.end36// CHECK: ret i32 037 38 39/// Similarly, here we revisit the BindingDecl.40struct F { int x; };41int main2() {42 const F const s{99};43 const auto& [r1] = s;44 if (&r1 != &s.x)45 __builtin_abort();46 return 0;47}48// CHECK: define dso_local noundef i32 @_Z5main2v()49// CHECK: br50// CHECK: if.then51// CHECK: if.end52// CHECK: ret i32 053 54/// The comparison here should work and return 0.55class X {56public:57 X();58 X(const X&);59 X(const volatile X &);60 ~X();61};62extern X OuterX;63X test24() {64 X x;65 if (&x == &OuterX)66 throw 0;67 return x;68}69 70// CHECK: define dso_local void @_Z6test24v71// CHECK-NOT: lpad72// CHECK-NOT: eh.resume73