[llvm] r229366 - IR: SrcTy == DstTy doesn't imply that a cast is valid

David Majnemer david.majnemer at gmail.com
Mon Feb 16 01:37:35 PST 2015


Author: majnemer
Date: Mon Feb 16 03:37:35 2015
New Revision: 229366

URL: http://llvm.org/viewvc/llvm-project?rev=229366&view=rev
Log:
IR: SrcTy == DstTy doesn't imply that a cast is valid

Cast validity depends on the cast's kind, not just its types.

Added:
    llvm/trunk/test/Assembler/invalid_cast4.ll
Modified:
    llvm/trunk/lib/IR/Instructions.cpp

Modified: llvm/trunk/lib/IR/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Instructions.cpp?rev=229366&r1=229365&r2=229366&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Instructions.cpp (original)
+++ llvm/trunk/lib/IR/Instructions.cpp Mon Feb 16 03:37:35 2015
@@ -2864,10 +2864,6 @@ CastInst::castIsValid(Instruction::CastO
   // Check for type sanity on the arguments
   Type *SrcTy = S->getType();
 
-  // If this is a cast to the same type then it's trivially true.
-  if (SrcTy == DstTy)
-    return true;
-
   if (!SrcTy->isFirstClassType() || !DstTy->isFirstClassType() ||
       SrcTy->isAggregateType() || DstTy->isAggregateType())
     return false;

Added: llvm/trunk/test/Assembler/invalid_cast4.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid_cast4.ll?rev=229366&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid_cast4.ll (added)
+++ llvm/trunk/test/Assembler/invalid_cast4.ll Mon Feb 16 03:37:35 2015
@@ -0,0 +1,4 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+
+; CHECK: invalid cast opcode for cast from 'i64' to 'i64'
+global i64* inttoptr (i64 0 to i64)





More information about the llvm-commits mailing list