llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.32k stars 12.11k forks source link

No conversion warning on bitfields #19288

Open chengniansun opened 10 years ago

chengniansun commented 10 years ago
Bugzilla Link 18914
Version trunk
OS Windows NT
CC @seanm

Extended Description

trunk 201801

$: cat s.c struct S {unsigned x:3;} s; void f(unsigned sm) { s.x = sm;// no warning here. s.x = 9999111; }

$: clang-trunk -Wconversion s.c -c s.c:4:7: warning: implicit truncation from 'int' to bitfield changes value from 9999111 to 7 [-Wbitfield-constant-conversion] s.x = 9999111; ^ ~~~ 1 warning generated.

$: gcc-trunk -Wconversion s.c -c s.c: In function ‘f’: s.c:3:9: warning: conversion to ‘unsigned char:3’ from ‘unsigned int’ may alter its value [-Wconversion] s.x = sm;// no warning here. ^ s.c:4:9: warning: large integer implicitly truncated to unsigned type [-Woverflow] s.x = 9999111; ^ $

DavidSpickett commented 4 months ago

Was looking into a related warning, can confirm this report is still valid: https://godbolt.org/z/PnGrn5ah6