diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp
index 779054b..d29398b 100644
--- a/lib/CodeGen/CGStmt.cpp
+++ b/lib/CodeGen/CGStmt.cpp
@@ -811,7 +811,8 @@ void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) {
 
   // FIXME: Clean this up by using an LValue for ReturnTemp,
   // EmitStoreThroughLValue, and EmitAnyExpr.
-  if (S.getNRVOCandidate() && S.getNRVOCandidate()->isNRVOVariable()) {
+  if (getLangOpts().ElideConstructors &&
+      S.getNRVOCandidate() && S.getNRVOCandidate()->isNRVOVariable()) {
     // Apply the named return value optimization for this return statement,
     // which means doing nothing: the appropriate result has already been
     // constructed into the NRVO variable.
diff --git a/test/CodeGenCXX/no-elide-constructors.cpp b/test/CodeGenCXX/no-elide-constructors.cpp
new file mode 100644
index 0000000..69b45e1
--- /dev/null
+++ b/test/CodeGenCXX/no-elide-constructors.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -std=c++98 -triple i386-unknown-unknown -fno-elide-constructors -emit-llvm -O1 -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-CXX98
+// RUN: %clang_cc1 -std=c++11 -triple i386-unknown-unknown -fno-elide-constructors -emit-llvm -O1 -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-CXX11
+
+// Reduced from PR12208
+class X {
+public:
+  X();
+  X(const X&);
+#if (__has_feature(cxx_rvalue_references))
+  X(X&&);
+#endif
+  ~X();
+};
+
+// CHECK-LABEL: define void @_Z4Testv
+X Test()
+{
+  X x;
+  // If rvalue references unavailable, check that copy constructor for X is
+  // called with result variable as sret argument.
+  // CHECK-CXX98: call void @_ZN1XC1ERKS_(%class.X* %agg.result, %class.X* %x)
+
+  // If rvalue references available, check that move constructor for X is
+  // called instead.
+  // CHECK-CXX11: call void @_ZN1XC1EOS_(%class.X* %agg.result, %class.X* %x)
+  return x;
+}
