This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Split of versions of -Wimplicit-{float,int}-conversion for Objective-C BOOL
ClosedPublic

Authored by erik.pilkington on Sep 13 2019, 9:13 AM.

Details

Summary

Also, add a diagnostic group, -Wobjc-signed-char-bool, to control all these related diagnostics.

See also: D63912, D63856

rdar://problem/51954400 ObjC: Add diagnostics to catch incorrect usage of BOOL

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptSep 13 2019, 9:13 AM

The diagnostics message looks good to me.

Mostly LGTM but a few nits.

clang/include/clang/Basic/DiagnosticGroups.td
65

This makes me wish that all shells would support autocomplete of program options. :-D

clang/include/clang/Basic/DiagnosticSemaKinds.td
3312

Can you put single quotes around BOOL since it's a type name? Same below.

clang/lib/AST/Expr.cpp
191

const auto * ?

clang/test/SemaObjC/signed-char-bool-conversion.m
4

Can you add a test verifying the fix-it behaviors (with and without parens)?

erik.pilkington marked 5 inline comments as done.

Address review comments.

clang/include/clang/Basic/DiagnosticSemaKinds.td
3312

Sure, this also needs to be fixed for warn_impcast_constant_value_to_objc_bool and warn_tautological_compare_objc_bool, I'll do that separately.

clang/test/SemaObjC/signed-char-bool-conversion.m
4

Sure, while testing this I noticed that we don't handle parens with OpaqueValueExprs properly, so I added a case.

aaron.ballman accepted this revision.Sep 17 2019, 11:14 AM

LGTM.

clang/test/Sema/objc-bool-constant-conversion-fixit.m
37

What about:

b = 1 ? (2 ? 3 : 4) : 5;

Will it YES/NO all the way down?

clang/test/SemaObjC/signed-char-bool-conversion.m
48

'BOOL', 'YES', and 'NO' at some point (doesn't have to be in this patch).

This revision is now accepted and ready to land.Sep 17 2019, 11:14 AM
erik.pilkington marked an inline comment as done.Sep 17 2019, 2:10 PM
erik.pilkington added inline comments.
clang/test/Sema/objc-bool-constant-conversion-fixit.m
37

Yeah, we produce the following for this:

b = 1 ? (2 ? 3 ? YES : NO : 4 ? YES : NO) : 5 ? YES : NO;

Not pretty, but not incorrect.

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSep 17 2019, 2:12 PM