https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108941
Bug ID: 108941 Summary: Error: operand type mismatch for `shr' with binutils master Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: marxin at gcc dot gnu.org CC: jbeulich at suse dot com Target Milestone: --- Since the following binutils revision: commit c34d1cc9200ae24dc7572aaf77d80276c0490e9b Author: Jan Beulich <jbeul...@suse.com> Date: Fri Feb 24 13:56:57 2023 +0100 x86: restrict insn templates accepting negative 8-bit immediates I noticed the following rejected code (reduced from ffmpeg-4 package): $ cat libavformat.i void av_log(); typedef signed char __int8_t; typedef unsigned char __uint8_t; typedef unsigned int __uint32_t; typedef __int8_t int8_t; typedef __uint8_t uint8_t; typedef __uint32_t uint32_t; typedef struct AVCodecParameters { uint8_t *extradata; int extradata_size; } AVCodecParameters; static inline uint32_t NEG_USR32(uint32_t a, int8_t s) { __asm__("shrl %1, %0\n\t" : "+r"(a) : "ic"((uint8_t)(-s))); return a; } typedef struct GetBitContext { } GetBitContext; static inline unsigned int get_bits(GetBitContext *s, int n) { register unsigned int tmp; unsigned int __attribute__((unused)) re_cache; tmp = NEG_USR32(re_cache, n); return tmp; }; typedef struct AVOption { } AVOption; typedef struct AVOutputFormat { int (*init)(struct AVFormatContext *); } AVOutputFormat; typedef struct AVStream { AVCodecParameters *codecpar; } AVStream; typedef struct AVProgram { void *priv_data; AVStream **streams; } AVFormatContext; typedef struct ADTSContext { } ADTSContext; static int adts_decode_extradata(AVFormatContext *s, ADTSContext *adts, const uint8_t *buf, int size) { GetBitContext gb; if (get_bits(&gb, 1)) { av_log(s, 16, "Extension flag is not allowed in ADTS\n"); } } static int adts_init(AVFormatContext *s) { ADTSContext *adts = s->priv_data; AVCodecParameters *par = s->streams[0]->codecpar; return adts_decode_extradata(s, adts, par->extradata, par->extradata_size); } static const AVOption options[] = { }; AVOutputFormat ff_adts_muxer = { .init = adts_init, }; $ gcc libavformat.i -w -S -O2 && grep shr libavformat.s && /home/marxin/Programming/binutils/objdir/gas/as-new libavformat.s shrl $-1, %eax libavformat.i: Assembler messages: libavformat.i:14: Error: operand type mismatch for `shr' So we emit -1 even though the user used cast to uint8_t: ((uint8_t)(-s))