This is an archive of the discontinued LLVM Phabricator instance.

[C11] Correct global atomic pointer initialization from an integer constant
ClosedPublic

Authored by aaron.ballman on Jul 1 2023, 10:01 AM.

Details

Summary

This is a follow-up to 2e275e24355cb224981f9beb2b026a3169fc7232 and 1395cde24b3641e284bb1daae7d56c189a2635e3 which corrects a missed case: initializing an _Atomic(T *) from a null pointer constant in the form of the integer literal 0.

(Note: a release note is unnecessary for this change as it's correcting an issue introduced during this cycle.)

Fixes https://github.com/llvm/llvm-project/issues/63550

Diff Detail

Event Timeline

aaron.ballman created this revision.Jul 1 2023, 10:01 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 1 2023, 10:01 AM
aaron.ballman requested review of this revision.Jul 1 2023, 10:01 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 1 2023, 10:01 AM
efriedma accepted this revision.Jul 2 2023, 11:17 AM

The testcase doesn't actually trigger the assertion... but I guess it still tests the output, so that's probably okay? Maybe add a case static _Atomic(int *) glob_pointer_from_long = 0LL; just to be sure.

Otherwise LGTM

(The "VarSize == CstSize" assertion has been catching a surprising number of cases of bad codegen; I'm happy I spent the time to add it.)

This revision is now accepted and ready to land.Jul 2 2023, 11:17 AM

The testcase doesn't actually trigger the assertion... but I guess it still tests the output, so that's probably okay? Maybe add a case static _Atomic(int *) glob_pointer_from_long = 0LL; just to be sure.

Thanks for catching that! I added an additional test that doesn't use static, as that was relevant to reproducing the original issue: https://godbolt.org/z/cf4Wzeo3z

Otherwise LGTM

(The "VarSize == CstSize" assertion has been catching a surprising number of cases of bad codegen; I'm happy I spent the time to add it.)

Yeah, this is a handy assertion!

This revision was landed with ongoing or failed builds.Jul 2 2023, 11:42 AM
This revision was automatically updated to reflect the committed changes.