badSuperclass.m 758 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // TEST_CRASHES
  2. /*
  3. TEST_RUN_OUTPUT
  4. objc\[\d+\]: Memory corruption in class list\.
  5. objc\[\d+\]: HALTED
  6. END
  7. */
  8. #include "test.h"
  9. #include "testroot.i"
  10. @interface Super : TestRoot @end
  11. @implementation Super @end
  12. @interface Sub : Super @end
  13. @implementation Sub @end
  14. int main()
  15. {
  16. alarm(10);
  17. Class supercls = [Super class];
  18. Class subcls = [Sub class];
  19. id subobj __unused = [Sub alloc];
  20. // Create a cycle in a superclass chain (Sub->supercls == Sub)
  21. // then attempt to walk that chain. Runtime should halt eventually.
  22. _objc_flush_caches(supercls);
  23. ((Class *)(__bridge void *)subcls)[1] = subcls;
  24. #ifdef CACHE_FLUSH
  25. _objc_flush_caches(supercls);
  26. #else
  27. [subobj class];
  28. #endif
  29. fail("should have crashed");
  30. }