struct mutex *mutex = (void *)lock;
                owner = BPF_CORE_READ(mutex, owner.counter);
        } else if (flags == LCB_F_READ || flags == LCB_F_WRITE) {
-#if __has_builtin(bpf_core_type_matches)
+       /*
+        * Support for the BPF_TYPE_MATCHES argument to the
+        * __builtin_preserve_type_info builtin was added at some point during
+        * development of clang 15 and it's what is needed for
+        * bpf_core_type_matches.
+        */
+#if __has_builtin(__builtin_preserve_type_info) && __clang_major__ >= 15
                if (bpf_core_type_matches(struct rw_semaphore___old)) {
                        struct rw_semaphore___old *rwsem = (void *)lock;
                        owner = (unsigned long)BPF_CORE_READ(rwsem, owner);