[llvm] [DebugInfo][RemoveDIs] Use autoupgrader to convert old debug-info (PR #143452)
Orlando Cazalet-Hyams via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 10 02:51:07 PDT 2025
================
@@ -4398,11 +4397,25 @@ static Value *upgradeAMDGCNIntrinsicCall(StringRef Name, CallBase *CI,
/// Helper to unwrap intrinsic call MetadataAsValue operands.
template <typename MDType>
static MDType *unwrapMAVOp(CallBase *CI, unsigned Op) {
- if (MetadataAsValue *MAV = dyn_cast<MetadataAsValue>(CI->getArgOperand(Op)))
- return dyn_cast<MDType>(MAV->getMetadata());
+ if (Op < CI->arg_size()) {
+ if (MetadataAsValue *MAV = dyn_cast<MetadataAsValue>(CI->getArgOperand(Op)))
+ // Use a reinterpret cast rather than a safe default-to-null cast: the
+ // autoupgrade process happens before the verifier, and thus there might
+ // be some nonsense metadata in there.
+ return reinterpret_cast<MDType*>(MAV->getMetadata());
----------------
OCHyams wrote:
nit: I think this comment could be simplified? Something like "Use reinterpret_cast rather than dyn_cast because the autoupgrade process happens before the verifier, meaning we may see unexpected operands here". YMMV. Also I think the style guide says to put braces around multi-line ifs (even if it's a comment making it multi-line).
https://github.com/llvm/llvm-project/pull/143452
More information about the llvm-commits
mailing list