[Lldb-commits] [lldb] 19b4d3c - [lldb] Don't emit a warning when using Objective-C getters in expressions
Raphael Isemann via lldb-commits
lldb-commits at lists.llvm.org
Thu Feb 11 07:49:02 PST 2021
Author: Raphael Isemann
Date: 2021-02-11T16:48:41+01:00
New Revision: 19b4d3ce27d5c8ed19bf08cdceb4c03608d2c66d
URL: https://github.com/llvm/llvm-project/commit/19b4d3ce27d5c8ed19bf08cdceb4c03608d2c66d
DIFF: https://github.com/llvm/llvm-project/commit/19b4d3ce27d5c8ed19bf08cdceb4c03608d2c66d.diff
LOG: [lldb] Don't emit a warning when using Objective-C getters in expressions
Clang emits a warning when accessing an Objective-C getter but not using the result.
This gets triggered when just trying to print a getter value in the expression parser (where
Clang just sees a normal expression like `obj.getter` while parsing).
This patch just disables the warning in the expression parser (similar to what we do with
the C++ equivalent of just accessing a member variable but not doing anything with it).
Reviewed By: kastiglione
Differential Revision: https://reviews.llvm.org/D94307
Added:
lldb/test/API/lang/objc/warnings-in-expr-parser/Makefile
lldb/test/API/lang/objc/warnings-in-expr-parser/TestObjCWarningsInExprParser.py
lldb/test/API/lang/objc/warnings-in-expr-parser/main.m
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 7644a5e1423e..0f3d36cec937 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -343,6 +343,7 @@ static void SetupDefaultClangDiagnostics(CompilerInstance &compiler) {
const std::vector<const char *> groupsToIgnore = {
"unused-value",
"odr",
+ "unused-getter-return-value",
};
for (const char *group : groupsToIgnore) {
compiler.getDiagnostics().setSeverityForGroup(
diff --git a/lldb/test/API/lang/objc/warnings-in-expr-parser/Makefile b/lldb/test/API/lang/objc/warnings-in-expr-parser/Makefile
new file mode 100644
index 000000000000..2f74200fd6f1
--- /dev/null
+++ b/lldb/test/API/lang/objc/warnings-in-expr-parser/Makefile
@@ -0,0 +1,5 @@
+OBJC_SOURCES := main.m
+LD_EXTRAS := -framework Foundation
+CFLAGS_EXTRAS := -fobjc-arc
+
+include Makefile.rules
diff --git a/lldb/test/API/lang/objc/warnings-in-expr-parser/TestObjCWarningsInExprParser.py b/lldb/test/API/lang/objc/warnings-in-expr-parser/TestObjCWarningsInExprParser.py
new file mode 100644
index 000000000000..b0b52cbdab76
--- /dev/null
+++ b/lldb/test/API/lang/objc/warnings-in-expr-parser/TestObjCWarningsInExprParser.py
@@ -0,0 +1,23 @@
+"""
+Test the warnings that LLDB emits when parsing Objective-C expressions.
+"""
+
+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__)
+
+ @skipUnlessDarwin
+ @no_debug_info_test
+ def test(self):
+ self.build()
+ lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.m"))
+
+ # Don't warn about not using the result of getters. This is perfectly
+ # fine in the expression parser and LLDB shouldn't warn the user about that.
+ result = self.frame().EvaluateExpression("m.m; unknown_var_to_cause_an_error")
+ self.assertNotIn("getters should not", str(result.GetError()))
diff --git a/lldb/test/API/lang/objc/warnings-in-expr-parser/main.m b/lldb/test/API/lang/objc/warnings-in-expr-parser/main.m
new file mode 100644
index 000000000000..8d7193304e54
--- /dev/null
+++ b/lldb/test/API/lang/objc/warnings-in-expr-parser/main.m
@@ -0,0 +1,15 @@
+#include <Foundation/Foundation.h>
+
+ at interface MyClass : NSObject
+ at property int m;
+ at end
+
+ at implementation MyClass {
+}
+ at end
+
+int main() {
+ MyClass *m = [[MyClass alloc] init];
+ m.m;
+ return 0; // break here
+}
More information about the lldb-commits
mailing list