This is an archive of the discontinued LLVM Phabricator instance.

[AST][NFC] Silence GCC warning about broken strict aliasing rules

Authored by thopre on Dec 1 2020, 4:40 AM.



The deserialize() method would trigger the following warning on GCC <7:

warning: dereferencing type-punned pointer will break
    strict-aliasing rules [-Wstrict-aliasing]

    ParamIdx P(*reinterpret_cast<ParamIdx *>(&S));

&S was previously reinterpret_casted from a ParamIdx into a SerialType,
it is therefore safe to cast back into a ParamIdx. Similar to what was
done in D50608, we replace it with two static_cast via void * which
silences the warning and presumably makes GCC understand that no
strict-aliasing violation is happening.

No functional change intended.

Diff Detail

Event Timeline

thopre created this revision.Dec 1 2020, 4:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 1 2020, 4:40 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
thopre requested review of this revision.Dec 1 2020, 4:40 AM
aaron.ballman accepted this revision.Dec 4 2020, 5:32 AM

LGTM, thanks!

This revision is now accepted and ready to land.Dec 4 2020, 5:32 AM