[llvm] [LLVM][Verifier] Improve diagnostic messages for Intrinsics in Verifier (PR #185641)

Rahul Joshi via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 22 18:56:41 PDT 2026


jurahul wrote:

> I think that your general approach here is inherently limited to non-overloaded intrinsics, as only those have a unique signature.
> 
> If we wanted to improve error reporting for overloaded intrinsics as well, I believe that would have to be directly integrated with the intrinsic verification infrastructure -- that is getIntrinsicSignature() itself needs to be able to report an optional error. I think it may be better to directly start with that direction rather than only handle a very limited intrinsic subset in a way that is inherently not extensible further.

I think we should reconsider this suggestion and do something that works for both overloaded and non-overloaded intrinsics in the same go (to avoid reworking the code too much when oveloaded intrinsics are supported). Maybe instead of `MatchIntrinsicTypesResult` being just an enum, it can return additional information that helps understand the exact failure in the signature. As an example, it can be something like:

```
  enum MatchIntrinsicTypesResult {
    MatchIntrinsicTypes_Match = 0,
    MatchIntrinsicTypes_NoMatchRet = 1,
    MatchIntrinsicTypes_NoMatchArg = 2,
  };

struct MatchIntrinsicTypesExResult {
  MatchIntrinsicTypesResult  Result;
  int Num; // the argument or return number that failed to match (for multi-return intrinsics)
  SmallVector<IITDescriptor> IITSegment; // Relevant IIT descriptor segment that describes what failed.
  Type *MismatchType; // The actual type in the IR that mismatched.
  bool IsVarArg; // actual IR function is VarArg?
};

  LLVM_ABI MatchIntrinsicTypesExResult
  matchIntrinsicSignatureEx(FunctionType *FTy, ArrayRef<IITDescriptor> &Infos,
                          SmallVectorImpl<Type *> &OverloadTys);

  LLVM_ABI MatchIntrinsicTypesResult
  matchIntrinsicSignature(FunctionType *FTy, ArrayRef<IITDescriptor> &Infos,
                          SmallVectorImpl<Type *> &OverloadTys) {
  return matchIntrinsicSignatureEx(FTy, Infos, OverloadTys).Result;
  }

  // prints the intrinsic signature mismatch error based on all the data captured in MatchIntrinsicTypesExResult.
  void printIntrinsicSignatureMismatch(const MatchIntrinsicTypesExResult &Info);

```

Based on this, we can print better informative error messages. The IIT segment can either for be a fixed type, or an overloaded type and we can print precise error messages like: expected an integer type (for llvm_anyint_ty), got float for return value, or expected i32 type, got i16 (when using fixed type). 

The verifier will call the Ex version and then we can have other existing pieces to migrate to the new function as well down the line. I understand the scope of this change is larger than what is in this PR, but I feel that will help get very precise error messages when intrinsic signatures mismatch. 

Alternatively, `matchIntrinsicSignature`  can itself take a `raw_ostream` to which it will print an error if there is a mismatch, so that it can internally track all the state needed to print a precise error message instead of trying to capture it all in a new struct. That can work if all calls to `matchIntrinsicSignature` also want to print an informative error message when there is a mismatch. 

@nikic please let us know if this general direction seems ok.

https://github.com/llvm/llvm-project/pull/185641


More information about the llvm-commits mailing list