Add a -fno-elide-constructors option to clang-cc.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79782 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Basic/DiagnosticFrontendKinds.td b/include/clang/Basic/DiagnosticFrontendKinds.td
index edfca6b..ab6e2bc 100644
--- a/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -70,6 +70,9 @@
def warn_pch_opencl : Error<
"OpenCL language extensions were %select{disabled|enabled}0 in PCH file "
"but are currently %select{disabled|enabled}1">;
+ def warn_elide_constructors : Error<
+ "Elidable copy constructors were %select{disabled|enabled}0 in PCH file "
+ "but are currently %select{disabled|enabled}1">;
def warn_pch_exceptions : Error<
"exceptions were %select{disabled|enabled}0 in PCH file but "
"are currently %select{disabled|enabled}1">;
diff --git a/include/clang/Basic/LangOptions.h b/include/clang/Basic/LangOptions.h
index f030c28..aec3422 100644
--- a/include/clang/Basic/LangOptions.h
+++ b/include/clang/Basic/LangOptions.h
@@ -86,6 +86,8 @@
unsigned OpenCL : 1; // OpenCL C99 language extensions.
+ unsigned ElideConstructors : 1; // Whether C++ copy constructors should be
+ // elided if possible.
private:
unsigned GC : 2; // Objective-C Garbage Collection modes. We
// declare this enum as unsigned because MSVC
@@ -136,6 +138,7 @@
// FIXME: The default should be 1.
AccessControl = 0;
+ ElideConstructors = 1;
OverflowChecking = 0;
ObjCGCBitmapPrint = 0;
diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp
index ebe6112..7a2c410 100644
--- a/lib/CodeGen/CGCXX.cpp
+++ b/lib/CodeGen/CGCXX.cpp
@@ -512,7 +512,7 @@
// Code gen optimization to eliminate copy constructor and return
// its first argument instead.
- if (E->isElidable()) {
+ if (getContext().getLangOptions().ElideConstructors && E->isElidable()) {
CXXConstructExpr::const_arg_iterator i = E->arg_begin();
EmitAggExpr((*i), Dest, false);
return;
diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp
index b368124..c025fcd 100644
--- a/lib/Frontend/PCHReader.cpp
+++ b/lib/Frontend/PCHReader.cpp
@@ -107,6 +107,7 @@
PARSE_LANGOPT_BENIGN(getVisibilityMode());
PARSE_LANGOPT_BENIGN(InstantiationDepth);
PARSE_LANGOPT_IMPORTANT(OpenCL, diag::warn_pch_opencl);
+ PARSE_LANGOPT_IMPORTANT(ElideConstructors, diag::warn_elide_constructors);
#undef PARSE_LANGOPT_IRRELEVANT
#undef PARSE_LANGOPT_BENIGN
diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp
index 48a1c9d..5e1ea0b 100644
--- a/lib/Frontend/PCHWriter.cpp
+++ b/lib/Frontend/PCHWriter.cpp
@@ -621,6 +621,7 @@
Record.push_back(LangOpts.getVisibilityMode());
Record.push_back(LangOpts.InstantiationDepth);
Record.push_back(LangOpts.OpenCL);
+ Record.push_back(LangOpts.ElideConstructors);
Stream.EmitRecord(pch::LANGUAGE_OPTIONS, Record);
}
diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp
index 1e4dc81..847826c 100644
--- a/tools/clang-cc/clang-cc.cpp
+++ b/tools/clang-cc/clang-cc.cpp
@@ -651,6 +651,11 @@
AccessControl("faccess-control",
llvm::cl::desc("Enable C++ access control"));
+static llvm::cl::opt<bool>
+NoElideConstructors("fno-elide-constructors",
+ llvm::cl::desc("Disable C++ copy constructor elision"));
+
+
// It might be nice to add bounds to the CommandLine library directly.
struct OptLevelParser : public llvm::cl::parser<unsigned> {
bool parse(llvm::cl::Option &O, const char *ArgName,
@@ -798,6 +803,8 @@
if (AccessControl)
Options.AccessControl = 1;
+ Options.ElideConstructors = !NoElideConstructors;
+
// OpenCL and C++ both have bool, true, false keywords.
Options.Bool = Options.OpenCL | Options.CPlusPlus;