[llvm-commits] CVS: llvm/utils/TableGen/IntrinsicEmitter.cpp

Reid Spencer reid at x10sys.com
Tue May 22 12:30:50 PDT 2007



Changes in directory llvm/utils/TableGen:

IntrinsicEmitter.cpp updated: 1.31 -> 1.32
---
Log message:

The Intrinsic::getDeclaration function's Tys parameter only contains the
types of the iAny types involved in the overloaded intrinsic. Thus, we
can't use the argument number as the index but have to count them separately
in order to index Tys correctly. This patch rectifies this situation.


---
Diffs of the changes:  (+12 -5)

 IntrinsicEmitter.cpp |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)


Index: llvm/utils/TableGen/IntrinsicEmitter.cpp
diff -u llvm/utils/TableGen/IntrinsicEmitter.cpp:1.31 llvm/utils/TableGen/IntrinsicEmitter.cpp:1.32
--- llvm/utils/TableGen/IntrinsicEmitter.cpp:1.31	Mon Apr 16 01:54:34 2007
+++ llvm/utils/TableGen/IntrinsicEmitter.cpp	Tue May 22 14:30:31 2007
@@ -134,11 +134,18 @@
   return false;
 }
 
-static void EmitTypeGenerate(std::ostream &OS, Record *ArgType, unsigned ArgNo){
+static void EmitTypeGenerate(std::ostream &OS, Record *ArgType, 
+                             unsigned &ArgNo) {
   if (ArgType->isSubClassOf("LLVMIntegerType")) {
     unsigned BitWidth = ArgType->getValueAsInt("Width");
+    // NOTE: The ArgNo variable here is not the absolute argument number, it is
+    // the index of the "arbitrary" type in the Tys array passed to the
+    // Intrinsic::getDeclaration function. Consequently, we only want to
+    // increment it when we actually hit an arbitray integer type which is
+    // identified by BitWidth == 0. Getting this wrong leads to very subtle
+    // bugs!
     if (BitWidth == 0)
-      OS << "Tys[" << ArgNo << "]";
+      OS << "Tys[" << ArgNo++ << "]";
     else
       OS << "IntegerType::get(" << BitWidth << ")";
   } else if (ArgType->isSubClassOf("LLVMVectorType")) {
@@ -253,16 +260,16 @@
       --N;
     }
     
+    unsigned ArgNo = 0;
     OS << "    ResultTy = ";
-    EmitTypeGenerate(OS, ArgTypes[0], 0);
+    EmitTypeGenerate(OS, ArgTypes[0], ArgNo);
     OS << ";\n";
     
     for (unsigned j = 1; j != N; ++j) {
       OS << "    ArgTys.push_back(";
-      EmitTypeGenerate(OS, ArgTypes[j], j);
+      EmitTypeGenerate(OS, ArgTypes[j], ArgNo);
       OS << ");\n";
     }
-    
     OS << "    break;\n";
   }
   OS << "  }\n";






More information about the llvm-commits mailing list