This is an archive of the discontinued LLVM Phabricator instance.

[SemaObjC] Add a warning for dictionary literals with duplicate keys
ClosedPublic

Authored by erik.pilkington on Apr 22 2020, 11:53 AM.

Details

Summary

Duplicate keys in a literal break NSDictionary's invariants.

Fixes rdar://50454461

Diff Detail

Event Timeline

Some part of me wishes we could use expression profiling or ODR hashing or something like that for this, but I guess the semantics we're going for don't really match.

clang/lib/Sema/SemaExprObjC.cpp
948

Does EvaluateAsInt really just fail cleanly if the argument doesn't have integral type?

bendjones accepted this revision.EditedMay 5 2020, 2:21 AM
bendjones marked an inline comment as done.

This addresses what we had an issue with on the tin. I’ll defer to @rjmccall for the specifics at the clang level.

clang/lib/Sema/SemaExprObjC.cpp
948

I thought it fails if a type can’t be “some how” converted to an integral type. The loose quotes are key here.

This revision is now accepted and ready to land.May 5 2020, 2:21 AM
erik.pilkington marked an inline comment as done.May 5 2020, 6:10 AM
erik.pilkington added inline comments.
clang/lib/Sema/SemaExprObjC.cpp
948
rjmccall accepted this revision.May 5 2020, 9:50 AM

Anyway, LGTM.

clang/lib/Sema/SemaExprObjC.cpp
948

Alright. That's interesting, I would've given even odds that it would assert.

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMay 5 2020, 12:58 PM