It appears that for roughly the last three months, cast<X>
has not been asserting that X actually isa<X>
. This is very unfortunate as the entire, explicitly documented in our developer guide, purpose of cast<Ty>(X)
is to provide a checked cast.
I have a patch which restores the asserts into cast, but as you might expect, we have some breakage in tree. This email lays out a proposal for how to handle this.
Current Status
As of now, the patch linked above does not build cleanly on ToT. We get template instantiation errors. Getting us into a buildable state is easy, I plan to land the require changes shortly after posting this.
Unfortunately, this reveals that we have significant breakage in tree where changes have landed which falsely cast to unrelated types. These are likely all programming errors which developers and reviewers assumed would be caught by cast. (This is how I noticed this issue myself.)
Here are the current failures in ninja check for core LLVM and clang.
Failed Tests (23):
Clang :: Modules/prune.m ā this is a flaky test, ignore it
LLVM :: Analysis/BasicAA/intrinsics.ll
LLVM :: Analysis/TypeBasedAliasAnalysis/intrinsics.ll
LLVM :: CodeGen/AMDGPU/rewrite-out-arguments-address-space.ll
LLVM :: CodeGen/AMDGPU/rewrite-out-arguments.ll
LLVM :: Transforms/GVN/masked-load-store-vn-crash.ll
LLVM :: Transforms/GVN/masked-load-store.ll
LLVM :: Transforms/GuardWidening/basic.ll
LLVM :: Transforms/GuardWidening/basic_widenable_condition_guards.ll
LLVM :: Transforms/GuardWidening/loop-schedule.ll
LLVM :: Transforms/GuardWidening/range-check-merging.ll
LLVM-Unit :: Transforms/Vectorize/./VectorizeTests/26/38
LLVM-Unit :: Transforms/Vectorize/./VectorizeTests/27/38
LLVM-Unit :: Transforms/Vectorize/./VectorizeTests/28/38
LLVM-Unit :: Transforms/Vectorize/./VectorizeTests/29/38
LLVM-Unit :: Transforms/Vectorize/./VectorizeTests/30/38
LLVM-Unit :: Transforms/Vectorize/./VectorizeTests/31/38
LLVM-Unit :: Transforms/Vectorize/./VectorizeTests/32/38
LLVM-Unit :: Transforms/Vectorize/./VectorizeTests/33/38
LLVM-Unit :: Transforms/Vectorize/./VectorizeTests/34/38
LLVM-Unit :: Transforms/Vectorize/./VectorizeTests/35/38
LLVM-Unit :: Transforms/Vectorize/./VectorizeTests/36/38
LLVM-Unit :: Transforms/Vectorize/./VectorizeTests/37/38
Proposed Approach
I propose, and plan to move forward with unless objections are raised, the following steps.
First, aggressively revert changes or fix forward if thatās easiest to resolve each of the above failures. (I could greatly use help with this, see below.)
Second, land the above linked patch. However, unlikely your typical patch, I plan to explicitly ask in the commit message that it not be reverted.
Once his lands, I expect to find further cast violations in less common configurations. Critically, I do not plan to revert when this happens, and instead will push the owners of those configurations to fix forward. We will be knowingly trading the stability of core LLVM and our ability to be confident in ongoing development against build failures for lessor used sub-projects. I think this is the right tradeoff in this case.
Timeline wise, I hope to accomplish steps one and two above in the next couple of days.
How can I help?
We urgently need folks knowledgeable of the respective areas to investigate each failure, fix forward or revert bad changes.
If you have a configuration which is anything other than default LLVM + clang that you care about, please apply the above patch and run tests. You will probably find problems which need to be fixed. Please either fix them yourself, or reply to this thread with your findings.
FAQ
Q: How did this happen?
This was done accidentally in ā D123901 [LLVM][Casting.h] Update dyn_cast machinery to provide more control over how the casting is performed., which was a fairly major reworking of the casting infrastructure to support new MLIR inspired use cases.
Q: The change above broke my downstream project, will you revert?
No.
Q: The change above broke this LLVM subproject, will you revert?
Probably not. This will be case by case, and may depend on the severity of the breakage. However, as noted in the writeup above we have a tradeoff here between leaving core LLVM exposed to further bad changes landing in tree, and the stability of each sub-project. We strongly encourage each sub-project to fix forward urgently.
Philip