Fix a nasty order of evaluation bug that Gabor Greif ran into. Here's an
authorChris Lattner <sabre@nondot.org>
Wed, 2 Mar 2005 03:54:43 +0000 (03:54 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 2 Mar 2005 03:54:43 +0000 (03:54 +0000)
explanation from IRC:

|sabre| I think it's an order of evaluation thing
|sabre| for me, the RHS of the assignment is evaluated first
|sabre| getTypeDescription checks to see if ConcreteTypeDescription[Ty] contains anything
|sabre| since it doesn't, it computes and returns the value
|sabre| this gets put into the map.
|sabre| For you, the LHS is evaluated first.
|sabre| Map[Ty] (aka ConcreteTypeDescriptions[Ty]) inserts an empty string into the map, returning a reference
|sabre| getTypeDesc then sees the empty string in the map
|sabre| and returns it
|sabre| bork :)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20394 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/Type.cpp

index d2d6a2a9439daae0198bd45ccd1523a237962272..875de4b6357d2dda69dc77e88ae61f49682a70dc 100644 (file)
@@ -291,7 +291,8 @@ static const std::string &getOrCreateDesc(std::map<const Type*,std::string>&Map,
   if (I != Map.end()) return I->second;
     
   std::vector<const Type *> TypeStack;
-  return Map[Ty] = getTypeDescription(Ty, TypeStack);
+  std::string Result = getTypeDescription(Ty, TypeStack);
+  return Map[Ty] = Result;
 }