[PATCH] D51211: [Sema] Emit -Wformat properly for bitfield promotions.

Bevin Hansson via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 3 05:24:34 PST 2018


ebevhan marked an inline comment as done.
ebevhan added inline comments.


================
Comment at: lib/Sema/SemaChecking.cpp:7711-7715
+  // It's an integer promotion if the destination type is the promoted
+  // source type.
+  return ICE->getCastKind() == CK_IntegralCast &&
+         From->isPromotableIntegerType() &&
+         S.Context.getPromotedIntegerType(From) == To;
----------------
aaron.ballman wrote:
> This check is not checking against the promoted type of the bit-field. See `Sema::UsualArithmeticConversions()` for an example of what I'm talking about. Is that expected?
I'm not entirely sure what you mean. Are you referring to the type produced by `isPromotableBitField`? The source type of that promotion is what we don't want to see in these implicit casts.

We don't want to look through promotions here if we promoted from a type which was the result of a bitfield promotion, and that bitfield promotion was from a higher ranked type to a lower ranked type. so, if we have a bitfield of type `short`, then promoting that to `int` is fine, and we will give a warning for the `short`. But if the type of the bitfield is `long`, it could be promoted to `int`. However, the format specifier warning will look through these promotions and think that we passed an expression of `long` to the function even though it was `int`.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D51211/new/

https://reviews.llvm.org/D51211





More information about the cfe-commits mailing list