[llvm-commits] CVS: llvm/lib/AsmParser/llvmAsmParser.y

Chris Lattner lattner at cs.uiuc.edu
Sun Mar 20 22:27:55 PST 2005



Changes in directory llvm/lib/AsmParser:

llvmAsmParser.y updated: 1.216 -> 1.217
---
Log message:

Remove a bunch of cruft and dead code for handling the case when types were
defined in function constant pools.  The assembler grammar has long 
disallowed functions from having constant pools, so all of this stuff is
dead.

This makes it an immediate error for functions to refer to nonexisting
types, fixing Regression/Verifier/2005-03-21-UndefinedTypeReference.ll.

Before, references to non-existing types in functions would only be
detected when the subsequent function was parsed, due to the call to 
"ResolveTypes".  "ResolveTypes" has not resolved any types for a long time,
instead it emitted an error message if no resolved types are left.  Since
the only caller of this method is in the module code, just inline it.



---
Diffs of the changes:  (+31 -49)

 llvmAsmParser.y |   80 +++++++++++++++++++++-----------------------------------
 1 files changed, 31 insertions(+), 49 deletions(-)


Index: llvm/lib/AsmParser/llvmAsmParser.y
diff -u llvm/lib/AsmParser/llvmAsmParser.y:1.216 llvm/lib/AsmParser/llvmAsmParser.y:1.217
--- llvm/lib/AsmParser/llvmAsmParser.y:1.216	Mon Mar 14 22:54:18 2005
+++ llvm/lib/AsmParser/llvmAsmParser.y	Mon Mar 21 00:27:42 2005
@@ -130,8 +130,6 @@
 
   std::map<const Type*, ValueList> Values;   // Keep track of #'d definitions
   std::map<const Type*, ValueList> LateResolveValues;
-  std::vector<PATypeHolder> Types;
-  std::map<ValID, PATypeHolder> LateResolveTypes;
   bool isDeclare;                // Is this function a forward declararation?
 
   /// BBForwardRefs - When we see forward references to basic blocks, keep
@@ -162,7 +160,6 @@
     ResolveDefinitions(LateResolveValues, &CurModule.LateResolveValues);
 
     Values.clear();         // Clear out function local definitions
-    Types.clear();          // Clear out function local types
     CurrentFunction = 0;
     isDeclare = false;
   }
@@ -208,18 +205,22 @@
   //
   if (DoNotImprovise) return 0;  // Do we just want a null to be returned?
 
-  std::map<ValID, PATypeHolder> &LateResolver = inFunctionScope() ? 
-    CurFun.LateResolveTypes : CurModule.LateResolveTypes;
-  
-  std::map<ValID, PATypeHolder>::iterator I = LateResolver.find(D);
-  if (I != LateResolver.end()) {
-    return I->second;
+
+  if (inFunctionScope()) {
+    if (D.Type == ValID::NameVal)
+      ThrowException("Reference to an undefined type: '" + D.getName() + "'");
+    else
+      ThrowException("Reference to an undefined type: #" + itostr(D.Num));
   }
 
+  std::map<ValID, PATypeHolder>::iterator I =CurModule.LateResolveTypes.find(D);
+  if (I != CurModule.LateResolveTypes.end())
+    return I->second;
+
   Type *Typ = OpaqueType::get();
-  LateResolver.insert(std::make_pair(D, Typ));
+  CurModule.LateResolveTypes.insert(std::make_pair(D, Typ));
   return Typ;
-}
+ }
 
 static Value *lookupInSymbolTable(const Type *Ty, const std::string &Name) {
   SymbolTable &SymTab = 
@@ -473,34 +474,15 @@
 // refering to the number can be resolved.  Do this now.
 //
 static void ResolveTypeTo(char *Name, const Type *ToTy) {
-  std::vector<PATypeHolder> &Types = inFunctionScope() ? 
-     CurFun.Types : CurModule.Types;
-
-   ValID D;
-   if (Name) D = ValID::create(Name);
-   else      D = ValID::create((int)Types.size());
-
-   std::map<ValID, PATypeHolder> &LateResolver = inFunctionScope() ? 
-     CurFun.LateResolveTypes : CurModule.LateResolveTypes;
-  
-   std::map<ValID, PATypeHolder>::iterator I = LateResolver.find(D);
-   if (I != LateResolver.end()) {
-     ((DerivedType*)I->second.get())->refineAbstractTypeTo(ToTy);
-     LateResolver.erase(I);
-   }
-}
-
-// ResolveTypes - At this point, all types should be resolved.  Any that aren't
-// are errors.
-//
-static void ResolveTypes(std::map<ValID, PATypeHolder> &LateResolveTypes) {
-  if (!LateResolveTypes.empty()) {
-    const ValID &DID = LateResolveTypes.begin()->first;
-
-    if (DID.Type == ValID::NameVal)
-      ThrowException("Reference to an invalid type: '" +DID.getName() + "'");
-    else
-      ThrowException("Reference to an invalid type: #" + itostr(DID.Num));
+  ValID D;
+  if (Name) D = ValID::create(Name);
+  else      D = ValID::create((int)CurModule.Types.size());
+
+  std::map<ValID, PATypeHolder>::iterator I =
+    CurModule.LateResolveTypes.find(D);
+  if (I != CurModule.LateResolveTypes.end()) {
+    ((DerivedType*)I->second.get())->refineAbstractTypeTo(ToTy);
+    CurModule.LateResolveTypes.erase(I);
   }
 }
 
@@ -1457,12 +1439,18 @@
   }
   | ConstPool {
     $$ = CurModule.CurrentModule;
-    // Resolve circular types before we parse the body of the module
-    ResolveTypes(CurModule.LateResolveTypes);
+    // Emit an error if there are any unresolved types left.
+    if (!CurModule.LateResolveTypes.empty()) {
+      const ValID &DID = CurModule.LateResolveTypes.begin()->first;
+      if (DID.Type == ValID::NameVal)
+        ThrowException("Reference to an undefined type: '"+DID.getName() + "'");
+      else
+        ThrowException("Reference to an undefined type: #" + itostr(DID.Num));
+    }
   };
 
 // ConstPool - Constants with optional names assigned to them.
-ConstPool : ConstPool OptAssign TYPE TypesV {  // Types can be defined in the const pool
+ConstPool : ConstPool OptAssign TYPE TypesV {
     // Eagerly resolve types.  This is not an optimization, this is a
     // requirement that is due to the fact that we could have this:
     //
@@ -1477,10 +1465,7 @@
     if (!setTypeName(*$4, $2) && !$2) {
       // If this is a named type that is not a redefinition, add it to the slot
       // table.
-      if (inFunctionScope())
-        CurFun.Types.push_back(*$4);
-      else
-        CurModule.Types.push_back(*$4);
+      CurModule.Types.push_back(*$4);
     }
 
     delete $4;
@@ -1664,9 +1649,6 @@
   // Make sure that we keep track of the linkage type even if there was a
   // previous "declare".
   $$->setLinkage($1);
-
-  // Resolve circular types before we parse the body of the function.
-  ResolveTypes(CurFun.LateResolveTypes);
 };
 
 END : ENDTOK | '}';                    // Allow end of '}' to end a function






More information about the llvm-commits mailing list