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

Chris Lattner lattner at cs.uiuc.edu
Wed Apr 16 13:15:01 PDT 2003


Changes in directory llvm/lib/AsmParser:

llvmAsmParser.y updated: 1.103 -> 1.104

---
Log message:

Don't allow declaring an external internal variable


---
Diffs of the changes:

Index: llvm/lib/AsmParser/llvmAsmParser.y
diff -u llvm/lib/AsmParser/llvmAsmParser.y:1.103 llvm/lib/AsmParser/llvmAsmParser.y:1.104
--- llvm/lib/AsmParser/llvmAsmParser.y:1.103	Tue Apr 15 11:09:31 2003
+++ llvm/lib/AsmParser/llvmAsmParser.y	Wed Apr 16 13:13:57 2003
@@ -522,6 +522,8 @@
             EGV->setInitializer(GV->getInitializer());
           if (GV->isConstant())
             EGV->setConstant(true);
+          if (GV->hasInternalLinkage())
+            EGV->setInternalLinkage(true);
           
 	  delete GV;     // Destroy the duplicate!
           return true;   // They are equivalent!
@@ -1154,10 +1156,10 @@
       }
     }
   }
-  | ConstPool OptAssign OptInternal EXTERNAL GlobalType Types {
-    const Type *Ty = *$6;
+  | ConstPool OptAssign EXTERNAL GlobalType Types {
+    const Type *Ty = *$5;
     // Global declarations appear in Constant Pool
-    GlobalVariable *GV = new GlobalVariable(Ty, $5, $3);
+    GlobalVariable *GV = new GlobalVariable(Ty, $4, false);
     if (!setValueName(GV, $2)) {   // If not redefining...
       CurModule.CurrentModule->getGlobalList().push_back(GV);
       int Slot = InsertValue(GV, CurModule.Values);
@@ -1170,7 +1172,7 @@
 				                (char*)GV->getName().c_str()));
       }
     }
-    delete $6;
+    delete $5;
   }
   | /* empty: end of list */ { 
   };
@@ -1216,23 +1218,23 @@
 
 FuncName : VAR_ID | STRINGCONSTANT;
 
-FunctionHeaderH : OptInternal TypesV FuncName '(' ArgList ')' {
-  UnEscapeLexed($3);
-  string FunctionName($3);
+FunctionHeaderH : TypesV FuncName '(' ArgList ')' {
+  UnEscapeLexed($2);
+  string FunctionName($2);
   
   vector<const Type*> ParamTypeList;
-  if ($5) {   // If there are arguments...
-    for (vector<pair<PATypeHolder*,char*> >::iterator I = $5->begin();
-         I != $5->end(); ++I)
+  if ($4) {   // If there are arguments...
+    for (vector<pair<PATypeHolder*,char*> >::iterator I = $4->begin();
+         I != $4->end(); ++I)
       ParamTypeList.push_back(I->first->get());
   }
 
   bool isVarArg = ParamTypeList.size() && ParamTypeList.back() == Type::VoidTy;
   if (isVarArg) ParamTypeList.pop_back();
 
-  const FunctionType *FT = FunctionType::get(*$2, ParamTypeList, isVarArg);
+  const FunctionType *FT = FunctionType::get(*$1, ParamTypeList, isVarArg);
   const PointerType *PFT = PointerType::get(FT);
-  delete $2;
+  delete $1;
 
   Function *Fn = 0;
   // Is the function already in symtab?
@@ -1242,11 +1244,6 @@
     if (!CurMeth.isDeclare && !Fn->isExternal())
       ThrowException("Redefinition of function '" + FunctionName + "'!");
     
-    // Make sure that we keep track of the internal marker, even if there was
-    // a previous "declare".
-    if ($1)
-      Fn->setInternalLinkage(true);
-
     // If we found a preexisting function prototype, remove it from the
     // module, so that we don't get spurious conflicts with global & local
     // variables.
@@ -1258,25 +1255,25 @@
       AI->setName("");
 
   } else  {  // Not already defined?
-    Fn = new Function(FT, $1, FunctionName);
+    Fn = new Function(FT, false, FunctionName);
     InsertValue(Fn, CurModule.Values);
-    CurModule.DeclareNewGlobalValue(Fn, ValID::create($3));
+    CurModule.DeclareNewGlobalValue(Fn, ValID::create($2));
   }
-  free($3);  // Free strdup'd memory!
+  free($2);  // Free strdup'd memory!
 
   CurMeth.FunctionStart(Fn);
 
   // Add all of the arguments we parsed to the function...
-  if ($5) {                     // Is null if empty...
+  if ($4) {                     // Is null if empty...
     if (isVarArg) {  // Nuke the last entry
-      assert($5->back().first->get() == Type::VoidTy && $5->back().second == 0&&
+      assert($4->back().first->get() == Type::VoidTy && $4->back().second == 0&&
              "Not a varargs marker!");
-      delete $5->back().first;
-      $5->pop_back();  // Delete the last entry
+      delete $4->back().first;
+      $4->pop_back();  // Delete the last entry
     }
     Function::aiterator ArgIt = Fn->abegin();
-    for (vector<pair<PATypeHolder*, char*> >::iterator I = $5->begin();
-         I != $5->end(); ++I, ++ArgIt) {
+    for (vector<pair<PATypeHolder*, char*> >::iterator I = $4->begin();
+         I != $4->end(); ++I, ++ArgIt) {
       delete I->first;                          // Delete the typeholder...
 
       if (setValueName(ArgIt, I->second))       // Insert arg into symtab...
@@ -1285,14 +1282,19 @@
       InsertValue(ArgIt);
     }
 
-    delete $5;                     // We're now done with the argument list
+    delete $4;                     // We're now done with the argument list
   }
 };
 
 BEGIN : BEGINTOK | '{';                // Allow BEGIN or '{' to start a function
 
-FunctionHeader : FunctionHeaderH BEGIN {
+FunctionHeader : OptInternal FunctionHeaderH BEGIN {
   $$ = CurMeth.CurrentFunction;
+
+  // Make sure that we keep track of the internal marker, even if there was
+  // a previous "declare".
+  if ($1)
+    $$->setInternalLinkage(true);
 
   // Resolve circular types before we parse the body of the function.
   ResolveTypes(CurMeth.LateResolveTypes);





More information about the llvm-commits mailing list