summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksandr Urakov <aleksandr.urakov@jetbrains.com>2018-12-04 09:51:29 +0000
committerAleksandr Urakov <aleksandr.urakov@jetbrains.com>2018-12-04 09:51:29 +0000
commitf335188925b923dc68243f2b2722e5cc5b259e1b (patch)
tree7a90e75d9aee7d137ef0e2d4a5d024e8f884db96
parent9d432e0d1412bfdbea7a0d18295d63c7d30d3952 (diff)
downloadbcm5719-llvm-f335188925b923dc68243f2b2722e5cc5b259e1b.tar.gz
bcm5719-llvm-f335188925b923dc68243f2b2722e5cc5b259e1b.zip
[Expr] Check the language before ignoring Objective C keywords
Summary: This patch adds the check of the language before ignoring names like `id` or `Class`, which are reserved in Objective C, but are allowed in C++. It is needed to make it possible to evaluate expressions in a C++ program containing names like `id` or `Class`. Reviewers: jingham, zturner, labath, clayborg Reviewed By: jingham, clayborg Tags: #lldb Differential Revision: https://reviews.llvm.org/D54843 llvm-svn: 348240
-rw-r--r--lldb/packages/Python/lldbsuite/test/expression_command/options/TestExprOptions.py13
-rw-r--r--lldb/packages/Python/lldbsuite/test/expression_command/options/main.cpp4
-rw-r--r--lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp5
-rw-r--r--lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp7
4 files changed, 22 insertions, 7 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/options/TestExprOptions.py b/lldb/packages/Python/lldbsuite/test/expression_command/options/TestExprOptions.py
index 1dbafc36a82..e1a4d8b9414 100644
--- a/lldb/packages/Python/lldbsuite/test/expression_command/options/TestExprOptions.py
+++ b/lldb/packages/Python/lldbsuite/test/expression_command/options/TestExprOptions.py
@@ -63,3 +63,16 @@ class ExprOptionsTestCase(TestBase):
val = frame.EvaluateExpression('foo != nullptr', options)
self.assertTrue(val.IsValid())
self.assertFalse(val.GetError().Success())
+
+ # Make sure we can retrieve `id` variable if language is set to C++11:
+ options.SetLanguage(lldb.eLanguageTypeC_plus_plus_11)
+ val = frame.EvaluateExpression('id == 0', options)
+ self.assertTrue(val.IsValid())
+ self.assertTrue(val.GetError().Success())
+ self.DebugSBValue(val)
+
+ # Make sure we can't retrieve `id` variable if language is set to ObjC:
+ options.SetLanguage(lldb.eLanguageTypeObjC)
+ val = frame.EvaluateExpression('id == 0', options)
+ self.assertTrue(val.IsValid())
+ self.assertFalse(val.GetError().Success())
diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/options/main.cpp b/lldb/packages/Python/lldbsuite/test/expression_command/options/main.cpp
index ecd9a90f662..0d30c79bd22 100644
--- a/lldb/packages/Python/lldbsuite/test/expression_command/options/main.cpp
+++ b/lldb/packages/Python/lldbsuite/test/expression_command/options/main.cpp
@@ -1,11 +1,13 @@
extern "C" int foo(void);
static int static_value = 0;
+static int id = 1234;
int
bar()
{
static_value++;
- return static_value;
+ id++;
+ return static_value + id;
}
int main (int argc, char const *argv[])
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
index d98a2b25fbb..1116624aab2 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -771,8 +771,9 @@ bool ClangASTSource::IgnoreName(const ConstString name,
static const ConstString id_name("id");
static const ConstString Class_name("Class");
- if (name == id_name || name == Class_name)
- return true;
+ if (m_ast_context->getLangOpts().ObjC)
+ if (name == id_name || name == Class_name)
+ return true;
StringRef name_string_ref = name.GetStringRef();
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 45812032cac..18d1507446a 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -398,10 +398,9 @@ ClangExpressionParser::ClangExpressionParser(ExecutionContextScope *exe_scope,
LLVM_FALLTHROUGH;
case lldb::eLanguageTypeC_plus_plus_03:
m_compiler->getLangOpts().CPlusPlus = true;
- // FIXME: the following language option is a temporary workaround,
- // to "ask for C++, get ObjC++". Apple hopes to remove this requirement on
- // non-Apple platforms, but for now it is needed.
- m_compiler->getLangOpts().ObjC = true;
+ if (process_sp)
+ m_compiler->getLangOpts().ObjC =
+ process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC) != nullptr;
break;
case lldb::eLanguageTypeObjC_plus_plus:
case lldb::eLanguageTypeUnknown:
OpenPOWER on IntegriCloud