Fix wrong-code bug when a const automatic variable of struct type has both a
mutable member and a constant initializer. We'd previously promoted such
variables to global constants, resulting in nasal demons if the mutable member
was modified.

This is only a temporary fix. The subtle interplay between isConstantInitializer
and CGExprConstant is very bug-prone; there are some other issues in this area
which I will be addressing in subsequent, more major reworking of this code.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145654 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/CodeGenCXX/const-init.cpp b/test/CodeGenCXX/const-init.cpp
index 1fc3deb..aa77d5c 100644
--- a/test/CodeGenCXX/const-init.cpp
+++ b/test/CodeGenCXX/const-init.cpp
@@ -45,3 +45,14 @@
 // We don't expect to fold this in the frontend, but make sure it doesn't crash.
 // CHECK: @PR9558 = global float 0.000000e+0
 float PR9558 = reinterpret_cast<const float&>("asd");
+
+// An initialized const automatic variable cannot be promoted to a constant
+// global if it has a mutable member.
+struct MutableMember {
+  mutable int n;
+};
+int writeToMutable() {
+  // CHECK-NOT: {{.*}}MM{{.*}} = {{.*}}constant
+  const MutableMember MM = { 0 };
+  return ++MM.n;
+}