This is an archive of the discontinued LLVM Phabricator instance.

[AlignmentFromAssumptions] avoid crash on alignment constant expression
AbandonedPublic

Authored by spatel on Jul 20 2021, 8:20 AM.

Details

Reviewers
nikic
jdoerfert
Summary

I'm not familiar with this pass, but we have a crash shown in:
https://llvm.org/PR50978
...so I think we can either bail out as shown here or dyn_cast later to avoid the assert failure in getNewAlignmentDiff() that happens with the plain cast<SCEVConstant>.

Diff Detail

Event Timeline

spatel created this revision.Jul 20 2021, 8:20 AM
spatel requested review of this revision.Jul 20 2021, 8:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 20 2021, 8:20 AM

I still believe we should not create alignment annotations for non-power-of-two constants. This is the second time in a few weeks this causes problems and we still play whack-a-mole instead of restricting clang and teaching the verifier.

https://reviews.llvm.org/D94433

This revision now requires changes to proceed.Jul 20 2021, 8:39 AM

I still believe we should not create alignment annotations for non-power-of-two constants. This is the second time in a few weeks this causes problems and we still play whack-a-mole instead of restricting clang and teaching the verifier.

https://reviews.llvm.org/D94433

Ah, I didn't realize this is the same problem based on the reduced test. Someone familiar with this feature in Clang -- and compatibility with GCC? -- should have a look then ( @lebedev.ri @erichkeane ? ) - I have no idea what this is supposed to do.

I still believe we should not create alignment annotations for non-power-of-two constants. This is the second time in a few weeks this causes problems and we still play whack-a-mole instead of restricting clang and teaching the verifier.

https://reviews.llvm.org/D94433

Ah, I didn't realize this is the same problem based on the reduced test. Someone familiar with this feature in Clang -- and compatibility with GCC? -- should have a look then ( @lebedev.ri @erichkeane ? ) - I have no idea what this is supposed to do.

We (clang) already diagnoses it, but doesn't refuse to codegen it.
I think it should just hard-error on it, without emitting IR.

I still believe we should not create alignment annotations for non-power-of-two constants. This is the second time in a few weeks this causes problems and we still play whack-a-mole instead of restricting clang and teaching the verifier.

https://reviews.llvm.org/D94433

Ah, I didn't realize this is the same problem based on the reduced test. Someone familiar with this feature in Clang -- and compatibility with GCC? -- should have a look then ( @lebedev.ri @erichkeane ? ) - I have no idea what this is supposed to do.

We (clang) already diagnoses it, but doesn't refuse to codegen it.
I think it should just hard-error on it, without emitting IR.

Wouldn't that be revert of https://reviews.llvm.org/D73996 which softened it to a warning then?

I still believe we should not create alignment annotations for non-power-of-two constants. This is the second time in a few weeks this causes problems and we still play whack-a-mole instead of restricting clang and teaching the verifier.

https://reviews.llvm.org/D94433

Ah, I didn't realize this is the same problem based on the reduced test. Someone familiar with this feature in Clang -- and compatibility with GCC? -- should have a look then ( @lebedev.ri @erichkeane ? ) - I have no idea what this is supposed to do.

We (clang) already diagnoses it, but doesn't refuse to codegen it.
I think it should just hard-error on it, without emitting IR.

Wouldn't that be revert of https://reviews.llvm.org/D73996 which softened it to a warning then?

Oh, i forgot that i had such a patch.
That seems to list a reason why clang does what it does,
I guess then we need two changes:

  1. don't use alignment assume bundle to store non-power-of-two alignment, because that is obviously not an alignment
  2. verifier to enforce that alignment assume bundle must contain powers of two.

I should mention Haiku has seen this crash via https://github.com/llvm/llvm-project/issues/53159

  • -O2 results in a crash
  • -O0 fixes the crash
  • Fixing the alignment to non-0 fixes the crash.
nikic accepted this revision.Apr 5 2022, 7:54 AM

D119414 clarified that this is legal IR, so this LGTM now.

Herald added a project: Restricted Project. · View Herald TranscriptApr 5 2022, 7:54 AM
nikic added a comment.Apr 5 2022, 7:58 AM

Actually, it looks like the same patch has already been committed in the meantime: https://github.com/llvm/llvm-project/commit/9b45fd909ffa754acbb4e927bc2d55c7ab0d4e3f

spatel abandoned this revision.Apr 11 2022, 2:05 AM