Add a clarifying a comment on CastInst::isNoopCast
authorPhilip Reames <listmail@philipreames.com>
Wed, 7 Oct 2020 19:15:16 +0000 (12:15 -0700)
committerPhilip Reames <listmail@philipreames.com>
Wed, 7 Oct 2020 19:17:07 +0000 (12:17 -0700)
I made exactly the mistake described, so document the precondition.  It would be better to have an assert, but there is (currently) no "castIsValid" with purely type arguments.

llvm/include/llvm/IR/InstrTypes.h

index 00aa79c..c86448e 100644 (file)
@@ -650,8 +650,8 @@ public:
   /// DataLayout argument is to determine the pointer size when examining casts
   /// involving Integer and Pointer types. They are no-op casts if the integer
   /// is the same size as the pointer. However, pointer size varies with
-  /// platform.
-  /// Determine if the described cast is a no-op cast.
+  /// platform.  Note that a precondition of this method is that the cast is
+  /// legal - i.e. the instruction formed with these operands would verify.
   static bool isNoopCast(
     Instruction::CastOps Opcode, ///< Opcode of cast
     Type *SrcTy,         ///< SrcTy of cast