From 54b0fb8af38294b3571b798ce0053f79bb6e0d27 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 8 Oct 2019 21:26:03 +0000 Subject: Fix crash or wrong code bug if a lifetime-extended temporary contains a "non-constant" value. If the constant evaluator evaluates part of a variable initializer, including the initializer for some lifetime-extended temporary, but fails to fully evaluate the initializer, it can leave behind wrong values for temporaries encountered in that initialization. Don't try to emit those from CodeGen! Instead, look at the values that constant evaluation produced if (and only if) it actually succeeds and we're emitting the lifetime-extending declaration's initializer as a constant. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@374119 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/CodeGenCXX/no-const-init-cxx2a.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 test/CodeGenCXX/no-const-init-cxx2a.cpp (limited to 'test') diff --git a/test/CodeGenCXX/no-const-init-cxx2a.cpp b/test/CodeGenCXX/no-const-init-cxx2a.cpp new file mode 100644 index 0000000000..a945c066e3 --- /dev/null +++ b/test/CodeGenCXX/no-const-init-cxx2a.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s -std=c++2a | FileCheck %s + +// CHECK-DAG: @p = {{.*}} null +// CHECK-DAG: @_ZGR1p_ = {{.*}} null +int *const &p = new int; + +struct d { + constexpr d(int &&f) : e(f) {} + int &e; +}; + +// CHECK-DAG: @g = {{.*}} null +// CHECK-DAG: @_ZGR1g_ = {{.*}} zeroinitializer +d &&g{{0}}; + +// CHECK: define {{.*}} @__cxx_global_var_init +// CHECK: define {{.*}} @__cxx_global_var_init +// CHECK-NOT: define {{.*}} @__cxx_global_var_init -- cgit v1.2.1