[FFmpeg-devel] [PATCH] intreadwrite: Indicate potential aliasing in AV_RN/AV_WN for Clang/MSVC mode
Martin Storsjö
martin at martin.st
Wed Aug 2 10:02:06 EEST 2023
While MSVC proper doesn't have a way to signal potential aliasing
corresponding to __attribute__((may_alias)) (which is what
av_alias expands to, if supported), Clang does support it.
When building with Clang in MSVC mode, __GNUC__ isn't defined but
_MSC_VER is, so Clang uses the MSVC implementation of AV_RN/AV_WN
which uses __unaligned.
Add the av_alias macro there, to indicate that the reads/writes can
alias other writes. Adding the attribute within the cast itself
doesn't seem to have any effect, it only has an effect if added in
a type definition.
Alternatively the __GNUC__ specific codepath right above could also
be used whenever __clang__ is defined; numerous __GNUC__ checks
also separately check for __clang__ to use them when building with
Clang in MSVC mode.
This fixes a couple HEVC decoder tests when built with Clang 14 or
newer in MSVC mode (with issues observed on all of x86_64, armv7
and aarch64).
---
libavutil/intreadwrite.h | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/libavutil/intreadwrite.h b/libavutil/intreadwrite.h
index c4679fdba4..126ac3c7f8 100644
--- a/libavutil/intreadwrite.h
+++ b/libavutil/intreadwrite.h
@@ -224,8 +224,12 @@ union unaligned_16 { uint16_t l; } __attribute__((packed)) av_alias;
#elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_X64) || defined(_M_ARM64)) && AV_HAVE_FAST_UNALIGNED
-# define AV_RN(s, p) (*((const __unaligned uint##s##_t*)(p)))
-# define AV_WN(s, p, v) (*((__unaligned uint##s##_t*)(p)) = (v))
+typedef __unaligned uint64_t av_alias unaligned_64;
+typedef __unaligned uint32_t av_alias unaligned_32;
+typedef __unaligned uint16_t av_alias unaligned_16;
+
+# define AV_RN(s, p) (*((const unaligned_##s*)(p)))
+# define AV_WN(s, p, v) (*((unaligned_##s*)(p)) = (v))
#elif AV_HAVE_FAST_UNALIGNED
--
2.34.1
More information about the ffmpeg-devel
mailing list