[PATCH] D51211: [Sema] Emit -Wformat properly for bitfield promotions.
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 3 06:24:12 PST 2018
aaron.ballman 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;
----------------
ebevhan wrote:
> 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`.
Ahhh, okay, I see what's going on then. This makes more sense to me now, thank you for the explanation.
================
Comment at: test/Sema/format-strings-bitfield-promotion.c:1
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s
+
----------------
aaron.ballman wrote:
> Running your test through GCC looks like the behavior matches here for C; can you also add a C++ test that demonstrates the behavior does not change?
>
> https://godbolt.org/z/zRYDMG
Strangely, the above godbolt link dropped the output windows, here's a different link that shows the behavioral differences between C and C++ mode in GCC: https://godbolt.org/z/R3zRHe
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D51211/new/
https://reviews.llvm.org/D51211
More information about the cfe-commits
mailing list