[Lldb-commits] [lldb] 5f88f39 - [lldb] Enable C++14 when evaluating expressions in a C++14 frame
Raphael Isemann via lldb-commits
lldb-commits at lists.llvm.org
Fri May 22 02:43:01 PDT 2020
Author: Raphael Isemann
Date: 2020-05-22T11:42:44+02:00
New Revision: 5f88f39ab8154682c3b1eb9d7050a9412a55d9e7
URL: https://github.com/llvm/llvm-project/commit/5f88f39ab8154682c3b1eb9d7050a9412a55d9e7
DIFF: https://github.com/llvm/llvm-project/commit/5f88f39ab8154682c3b1eb9d7050a9412a55d9e7.diff
LOG: [lldb] Enable C++14 when evaluating expressions in a C++14 frame
Summary:
Currently we never enable C++14 in the expression evaluator. This enables it when the language of the program is C++14.
It seems C++17 and so on isn't yet in any of the language enums (and the DWARF standard it seems), so C++17 support will be a follow up patch.
Reviewers: labath, JDevlieghere
Reviewed By: labath, JDevlieghere
Subscribers: aprantl
Differential Revision: https://reviews.llvm.org/D80308
Added:
lldb/test/API/lang/cpp/standards/cpp11/Makefile
lldb/test/API/lang/cpp/standards/cpp11/TestCPP11Standard.py
lldb/test/API/lang/cpp/standards/cpp11/main.cpp
lldb/test/API/lang/cpp/standards/cpp14/Makefile
lldb/test/API/lang/cpp/standards/cpp14/TestCPP14Standard.py
lldb/test/API/lang/cpp/standards/cpp14/main.cpp
Modified:
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
Removed:
################################################################################
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 8885cbc85b2c..877d75cfec30 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -491,9 +491,11 @@ ClangExpressionParser::ClangExpressionParser(
// be re-evaluated in the future.
lang_opts.CPlusPlus11 = true;
break;
+ case lldb::eLanguageTypeC_plus_plus_14:
+ lang_opts.CPlusPlus14 = true;
+ LLVM_FALLTHROUGH;
case lldb::eLanguageTypeC_plus_plus:
case lldb::eLanguageTypeC_plus_plus_11:
- case lldb::eLanguageTypeC_plus_plus_14:
lang_opts.CPlusPlus11 = true;
m_compiler->getHeaderSearchOpts().UseLibcxx = true;
LLVM_FALLTHROUGH;
diff --git a/lldb/test/API/lang/cpp/standards/cpp11/Makefile b/lldb/test/API/lang/cpp/standards/cpp11/Makefile
new file mode 100644
index 000000000000..e78030cbf752
--- /dev/null
+++ b/lldb/test/API/lang/cpp/standards/cpp11/Makefile
@@ -0,0 +1,4 @@
+CXX_SOURCES := main.cpp
+CXXFLAGS_EXTRAS := -std=c++11
+
+include Makefile.rules
diff --git a/lldb/test/API/lang/cpp/standards/cpp11/TestCPP11Standard.py b/lldb/test/API/lang/cpp/standards/cpp11/TestCPP11Standard.py
new file mode 100644
index 000000000000..e4162c09758f
--- /dev/null
+++ b/lldb/test/API/lang/cpp/standards/cpp11/TestCPP11Standard.py
@@ -0,0 +1,19 @@
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ def test(self):
+ self.build()
+ lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.cpp"))
+
+ # Run an expression that is valid in C++11 (as it uses nullptr).
+ self.expect_expr("nullptr == nullptr", result_type="bool", result_value="true")
+
+ # Run a expression that is not valid in C++11 (as it uses polymorphic
+ # lambdas from C++14).
+ self.expect("expr [](auto x) { return x; }(1)", error=True, substrs=["'auto' not allowed in lambda parameter"])
diff --git a/lldb/test/API/lang/cpp/standards/cpp11/main.cpp b/lldb/test/API/lang/cpp/standards/cpp11/main.cpp
new file mode 100644
index 000000000000..ba45ee316cd4
--- /dev/null
+++ b/lldb/test/API/lang/cpp/standards/cpp11/main.cpp
@@ -0,0 +1,3 @@
+int main() {
+ return 0; // break here
+}
diff --git a/lldb/test/API/lang/cpp/standards/cpp14/Makefile b/lldb/test/API/lang/cpp/standards/cpp14/Makefile
new file mode 100644
index 000000000000..a27336ffd9ac
--- /dev/null
+++ b/lldb/test/API/lang/cpp/standards/cpp14/Makefile
@@ -0,0 +1,4 @@
+CXX_SOURCES := main.cpp
+CXXFLAGS_EXTRAS := -std=c++14
+
+include Makefile.rules
diff --git a/lldb/test/API/lang/cpp/standards/cpp14/TestCPP14Standard.py b/lldb/test/API/lang/cpp/standards/cpp14/TestCPP14Standard.py
new file mode 100644
index 000000000000..3422cf19b3d7
--- /dev/null
+++ b/lldb/test/API/lang/cpp/standards/cpp14/TestCPP14Standard.py
@@ -0,0 +1,19 @@
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ def test(self):
+ self.build()
+ lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.cpp"))
+
+ # Run an expression that is valid in C++11 (as it uses nullptr).
+ self.expect_expr("nullptr == nullptr", result_type="bool", result_value="true")
+
+ # Run a expression that is only valid in C++14 that (as it uses
+ # polymorphic lambdas).
+ self.expect_expr("[](auto x) { return x; }(1)", result_type="int", result_value="1")
diff --git a/lldb/test/API/lang/cpp/standards/cpp14/main.cpp b/lldb/test/API/lang/cpp/standards/cpp14/main.cpp
new file mode 100644
index 000000000000..ba45ee316cd4
--- /dev/null
+++ b/lldb/test/API/lang/cpp/standards/cpp14/main.cpp
@@ -0,0 +1,3 @@
+int main() {
+ return 0; // break here
+}
More information about the lldb-commits
mailing list