[clang] [Webkit Checkers] Introduce a Webkit checker for memory unsafe casts (PR #114606)

Rashmi Mudduluru via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 7 16:19:34 PST 2024


================
@@ -27,3 +27,27 @@ -(void)testCasts:(BaseClass*)base {
   base = (BaseClass*)base;  // no warning
 }
 @end
+
+template <typename T>
+class WrappedObject
+{
+public:
+  T get() const { return mMetalObject; }
+  T mMetalObject = nullptr;
+};
+
+ at protocol MTLCommandEncoder
+ at end
+ at protocol MTLRenderCommandEncoder
+ at end
+class CommandEncoder : public WrappedObject<id<MTLCommandEncoder>> { };
+
+class RenderCommandEncoder final : public CommandEncoder
+{
+private:
+    // Override CommandEncoder
+    id<MTLRenderCommandEncoder> get()
+    {
+        return static_cast<id<MTLRenderCommandEncoder>>(CommandEncoder::get());
----------------
t-rasmud wrote:

Hmmm.. This is a reproducer for the crash when `BaseObjCPtrType` is an invalid type class and we just return in that case.

https://github.com/llvm/llvm-project/pull/114606


More information about the cfe-commits mailing list