[llvm-commits] [llvm] r72248 - in /llvm/trunk: lib/VMCore/Verifier.cpp test/Assembler/2009-05-22-CC.ll test/Verifier/2009-05-22-CC.ll

Torok Edwin edwintorok at gmail.com
Thu May 21 23:41:44 PDT 2009


Author: edwin
Date: Fri May 22 01:41:43 2009
New Revision: 72248

URL: http://llvm.org/viewvc/llvm-project?rev=72248&view=rev
Log:
Verify that calling conventions match function prototype.
This only rejects mismatches between target specific calling convention
and C/LLVM specific calling convention.
There are too many fastcc/C, coldcc/cc42 mismatches in the testsuite, these are
not reject by the verifier.

Added:
    llvm/trunk/test/Assembler/2009-05-22-CC.ll
    llvm/trunk/test/Verifier/2009-05-22-CC.ll
Modified:
    llvm/trunk/lib/VMCore/Verifier.cpp

Modified: llvm/trunk/lib/VMCore/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Verifier.cpp?rev=72248&r1=72247&r2=72248&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Verifier.cpp (original)
+++ llvm/trunk/lib/VMCore/Verifier.cpp Fri May 22 01:41:43 2009
@@ -1024,6 +1024,31 @@
             "Call parameter type does not match function signature!",
             CS.getArgument(i), FTy->getParamType(i), I);
 
+  Assert2(CS.getType() == FTy->getReturnType(),
+          "Call return type does not match function signature!",
+          CS.getInstruction(), FTy->getReturnType());
+
+  // Verify calling convention for direct calls
+  Value *CalledF = CS.getCalledValue()->stripPointerCasts();
+  if (Function *F = dyn_cast<Function>(CalledF)) {
+    unsigned CC1 = CS.getCallingConv();
+    unsigned CC2 = F->getCallingConv();
+    if(CC1 != CC2) {
+      // tolerate some mismatch among C prototype and LLVM-specific calling conv
+      if (CC2 >= CallingConv::FirstTargetCC || 
+          CC1 >= CallingConv::FirstTargetCC) {
+        Instruction *I = CS.getInstruction()->clone();
+        if (CallInst *CI = dyn_cast<CallInst>(I)) {
+          CI->setCallingConv(F->getCallingConv());
+        } else
+          cast<InvokeInst>(I)->setCallingConv(F->getCallingConv());
+        Assert2(0,"Calling convention does not match function signature!",
+                CS.getInstruction(), I);
+        delete I;
+      }
+    }
+  }
+
   if (CS.getCalledValue()->getNameLen() < 5 ||
       strncmp(CS.getCalledValue()->getNameStart(), "llvm.", 5) != 0) {
     // Verify that none of the arguments are metadata...

Added: llvm/trunk/test/Assembler/2009-05-22-CC.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/2009-05-22-CC.ll?rev=72248&view=auto

==============================================================================
--- llvm/trunk/test/Assembler/2009-05-22-CC.ll (added)
+++ llvm/trunk/test/Assembler/2009-05-22-CC.ll Fri May 22 01:41:43 2009
@@ -0,0 +1,9 @@
+; RUN: llvm-as < %s
+
+; Verify that calls with correct calling conv are accepted
+declare x86_stdcallcc i32 @re_string_construct(i8* inreg %pstr, i8* inreg %str, i32 inreg %len, i8* %trans, i32 %icase, i8* %dfa);
+define void @main() {
+entry:
+	%0 = call x86_stdcallcc i32 (...)* bitcast (i32 (i8*, i8*, i32, i8*, i32, i8*)* @re_string_construct to i32 (...)*)(i32 inreg 0, i32 inreg 0, i32 inreg 0, i32 0, i32 0, i8* inttoptr (i32 673194176 to i8*));
+        ret void
+}

Added: llvm/trunk/test/Verifier/2009-05-22-CC.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Verifier/2009-05-22-CC.ll?rev=72248&view=auto

==============================================================================
--- llvm/trunk/test/Verifier/2009-05-22-CC.ll (added)
+++ llvm/trunk/test/Verifier/2009-05-22-CC.ll Fri May 22 01:41:43 2009
@@ -0,0 +1,11 @@
+; RUN: not llvm-as < %s |& grep {Calling convention does not match function signature}
+; PR 4239
+
+; Verify that the calling convention on the call instruction matches the
+; declared calling convention
+declare x86_stdcallcc i32 @re_string_construct(i8* inreg %pstr, i8* inreg %str, i32 inreg %len, i8* %trans, i32 %icase, i8* %dfa);
+define void @main() {
+entry:
+	%0 = call i32 (...)* bitcast (i32 (i8*, i8*, i32, i8*, i32, i8*)* @re_string_construct to i32 (...)*)(i32 inreg 0, i32 inreg 0, i32 inreg 0, i32 0, i32 0, i8* inttoptr (i32 673194176 to i8*))
+        ret void
+}





More information about the llvm-commits mailing list