Skip to content

Commit 19b4d3c

Browse files
committed
[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
1 parent b1ef919 commit 19b4d3c

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ static void SetupDefaultClangDiagnostics(CompilerInstance &compiler) {
343343
const std::vector<const char *> groupsToIgnore = {
344344
"unused-value",
345345
"odr",
346+
"unused-getter-return-value",
346347
};
347348
for (const char *group : groupsToIgnore) {
348349
compiler.getDiagnostics().setSeverityForGroup(
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
OBJC_SOURCES := main.m
2+
LD_EXTRAS := -framework Foundation
3+
CFLAGS_EXTRAS := -fobjc-arc
4+
5+
include Makefile.rules
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
Test the warnings that LLDB emits when parsing Objective-C expressions.
3+
"""
4+
5+
import lldb
6+
from lldbsuite.test.decorators import *
7+
from lldbsuite.test.lldbtest import *
8+
from lldbsuite.test import lldbutil
9+
10+
class TestCase(TestBase):
11+
12+
mydir = TestBase.compute_mydir(__file__)
13+
14+
@skipUnlessDarwin
15+
@no_debug_info_test
16+
def test(self):
17+
self.build()
18+
lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.m"))
19+
20+
# Don't warn about not using the result of getters. This is perfectly
21+
# fine in the expression parser and LLDB shouldn't warn the user about that.
22+
result = self.frame().EvaluateExpression("m.m; unknown_var_to_cause_an_error")
23+
self.assertNotIn("getters should not", str(result.GetError()))
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <Foundation/Foundation.h>
2+
3+
@interface MyClass : NSObject
4+
@property int m;
5+
@end
6+
7+
@implementation MyClass {
8+
}
9+
@end
10+
11+
int main() {
12+
MyClass *m = [[MyClass alloc] init];
13+
m.m;
14+
return 0; // break here
15+
}

0 commit comments

Comments
 (0)