Author: Michael Buch
Date: 2026-01-19T14:34:46Z
New Revision: 230f6ab1b84eef24444b86d6ffb18bd2e31822a9

URL: 
https://github.com/llvm/llvm-project/commit/230f6ab1b84eef24444b86d6ffb18bd2e31822a9
DIFF: 
https://github.com/llvm/llvm-project/commit/230f6ab1b84eef24444b86d6ffb18bd2e31822a9.diff

LOG: [lldb][test] Add a test for evaluating Obj-C types with an incomplete 
super-class

LLDB currently crashes when the super-class of an Objective-C type can't
be completed (i.e., has no definition). For Foundation types such as
`NSObject`, the debug-info would usually only contain forward
declarations. The definitions live in the Clang module `.pcm` files. But
if the source of the definition fails to be loaded (e.g., if we just
delete the module cache), then we can no longer guarantee that the
super-class has a definition. This breaks a key Clang invariant, which
requires base-classes to have definitions by the time we try to lay them
out. This patch adds an XFAILed test for such scenario.

rdar://168440264

Added: 
    lldb/test/Shell/Expr/TestObjCIncompleteSuperclass.test

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/lldb/test/Shell/Expr/TestObjCIncompleteSuperclass.test 
b/lldb/test/Shell/Expr/TestObjCIncompleteSuperclass.test
new file mode 100644
index 0000000000000..b6c27826c437e
--- /dev/null
+++ b/lldb/test/Shell/Expr/TestObjCIncompleteSuperclass.test
@@ -0,0 +1,60 @@
+# In this test we compile with -gmodules but delete the ModuleCache.
+# When LLDB tries to find a definition for NSObject (the Foo's super-class)
+# it will fail to do so. LLDB should handle this situation gracefully.
+# A super-class definition is required when laying out Obj-C types.
+#
+# XFAIL: *
+# REQUIRES: system-darwin
+#
+# RUN: split-file %s %t
+#
+# RUN: %clang_host %t/main.m -c -g -gmodules -fmodules -fcxx-modules \
+# RUN:             -fmodule-map-file=%t/module.modulemap \
+# RUN:             -fmodules-cache-path=%t/ModuleCache -o %t/main.o
+#
+# RUN: %clang_host %t/module.m -c -g -gmodules -fmodules -fcxx-modules \
+# RUN:             -fmodule-map-file=%t/module.modulemap \
+# RUN:             -fmodules-cache-path=%t/ModuleCache -o %t/module.o
+#
+# RUN: %clang_host %t/*.o -framework Foundation -o %t.out
+#
+# RUN: rm -r %t/ModuleCache
+#
+# RUN: %lldb -x -o "settings set interpreter.stop-command-source-on-error 
false" \
+# RUN:       -s %t/commands.input %t.out -o exit 2>&1 | FileCheck %s
+
+#--- main.m
+@import foo;
+
+int main() {
+    Foo *f = [Foo new];
+
+    __builtin_debugtrap();
+}
+
+#--- module.m
+
+#import "module.h"
+
+@implementation Foo
+@end
+
+#--- module.h
+
+#import <Foundation/Foundation.h>
+
+@interface Foo : NSObject
+@end
+
+#--- module.modulemap
+module foo {
+  header "module.h"
+  export *
+}
+
+#--- commands.input
+
+run
+expression *f
+
+# CHECK: (lldb) expression *f


        
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to