[clang] bb39b52 - Fix conversions in clang and examples

Benjamin Kramer via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 28 17:48:40 PST 2020


Author: Benjamin Kramer
Date: 2020-01-29T02:48:15+01:00
New Revision: bb39b52950e77e650fbdd86f7d5e4b89ff0aac4d

URL: https://github.com/llvm/llvm-project/commit/bb39b52950e77e650fbdd86f7d5e4b89ff0aac4d
DIFF: https://github.com/llvm/llvm-project/commit/bb39b52950e77e650fbdd86f7d5e4b89ff0aac4d.diff

LOG: Fix conversions in clang and examples

Added: 
    

Modified: 
    clang/lib/Basic/Module.cpp
    clang/lib/Frontend/CompilerInvocation.cpp
    llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp
    llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp
    llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
    llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp
    llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h
    llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp
    llvm/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h
    llvm/examples/Kaleidoscope/BuildingAJIT/Chapter5/toy.cpp
    llvm/examples/Kaleidoscope/Chapter8/toy.cpp
    llvm/examples/Kaleidoscope/Chapter9/toy.cpp
    mlir/examples/toy/Ch2/include/toy/Parser.h
    mlir/examples/toy/Ch3/include/toy/Parser.h
    mlir/examples/toy/Ch4/include/toy/Parser.h
    mlir/examples/toy/Ch5/include/toy/Parser.h
    mlir/examples/toy/Ch6/include/toy/Parser.h
    mlir/examples/toy/Ch7/include/toy/Parser.h

Removed: 
    


################################################################################
diff  --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp
index 541431dbbe7d..92835c9aca7d 100644
--- a/clang/lib/Basic/Module.cpp
+++ b/clang/lib/Basic/Module.cpp
@@ -276,7 +276,7 @@ bool Module::directlyUses(const Module *Requested) const {
 void Module::addRequirement(StringRef Feature, bool RequiredState,
                             const LangOptions &LangOpts,
                             const TargetInfo &Target) {
-  Requirements.push_back(Requirement(Feature, RequiredState));
+  Requirements.push_back(Requirement(std::string(Feature), RequiredState));
 
   // If this feature is currently available, we're done.
   if (hasFeature(Feature, LangOpts, Target) == RequiredState)

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 14cbf39cee45..a8dfd8a97c8c 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -340,7 +340,8 @@ static bool ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args,
     SmallVector<StringRef, 16> CheckersAndPackages;
     CheckerAndPackageList.split(CheckersAndPackages, ",");
     for (const StringRef &CheckerOrPackage : CheckersAndPackages)
-      Opts.CheckersAndPackages.emplace_back(CheckerOrPackage, IsEnabled);
+      Opts.CheckersAndPackages.emplace_back(std::string(CheckerOrPackage),
+                                            IsEnabled);
   }
 
   // Go through the analyzer configuration options.

diff  --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp
index b4605bae4ed9..ad942d1e45e7 100644
--- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp
+++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp
@@ -727,7 +727,7 @@ Function *getFunction(std::string Name) {
 /// CreateEntryBlockAlloca - Create an alloca instruction in the entry block of
 /// the function.  This is used for mutable variables etc.
 static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
-                                          const std::string &VarName) {
+                                          StringRef VarName) {
   IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
                    TheFunction->getEntryBlock().begin());
   return TmpB.CreateAlloca(Type::getDoubleTy(*TheContext), nullptr, VarName);
@@ -1076,7 +1076,7 @@ Function *FunctionAST::codegen() {
     Builder->CreateStore(&Arg, Alloca);
 
     // Add arguments to variable symbol table.
-    NamedValues[Arg.getName()] = Alloca;
+    NamedValues[std::string(Arg.getName())] = Alloca;
   }
 
   if (Value *RetVal = Body->codegen()) {

diff  --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp
index 743d50829dc3..136ae9636c56 100644
--- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp
+++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp
@@ -727,7 +727,7 @@ Function *getFunction(std::string Name) {
 /// CreateEntryBlockAlloca - Create an alloca instruction in the entry block of
 /// the function.  This is used for mutable variables etc.
 static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
-                                          const std::string &VarName) {
+                                          StringRef VarName) {
   IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
                    TheFunction->getEntryBlock().begin());
   return TmpB.CreateAlloca(Type::getDoubleTy(*TheContext), nullptr, VarName);
@@ -1076,7 +1076,7 @@ Function *FunctionAST::codegen() {
     Builder->CreateStore(&Arg, Alloca);
 
     // Add arguments to variable symbol table.
-    NamedValues[Arg.getName()] = Alloca;
+    NamedValues[std::string(Arg.getName())] = Alloca;
   }
 
   if (Value *RetVal = Body->codegen()) {

diff  --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
index add38fdb8193..34c4b9683572 100644
--- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
+++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
@@ -100,13 +100,13 @@ class KaleidoscopeJIT {
     // Build a resolver and associate it with the new key.
     Resolvers[K] = createLegacyLookupResolver(
         ES,
-        [this](const std::string &Name) -> JITSymbol {
-          if (auto Sym = CompileLayer.findSymbol(Name, false))
+        [this](StringRef Name) -> JITSymbol {
+          if (auto Sym = CompileLayer.findSymbol(std::string(Name), false))
             return Sym;
           else if (auto Err = Sym.takeError())
             return std::move(Err);
-          if (auto SymAddr =
-                  RTDyldMemoryManager::getSymbolAddressInProcess(Name))
+          if (auto SymAddr = RTDyldMemoryManager::getSymbolAddressInProcess(
+                  std::string(Name)))
             return JITSymbol(SymAddr, JITSymbolFlags::Exported);
           return nullptr;
         },

diff  --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp
index e9505033106e..d082e510e291 100644
--- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp
+++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp
@@ -726,7 +726,7 @@ Function *getFunction(std::string Name) {
 /// CreateEntryBlockAlloca - Create an alloca instruction in the entry block of
 /// the function.  This is used for mutable variables etc.
 static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
-                                          const std::string &VarName) {
+                                          StringRef VarName) {
   IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
                    TheFunction->getEntryBlock().begin());
   return TmpB.CreateAlloca(Type::getDoubleTy(TheContext), nullptr, VarName);
@@ -1075,7 +1075,7 @@ Function *FunctionAST::codegen() {
     Builder.CreateStore(&Arg, Alloca);
 
     // Add arguments to variable symbol table.
-    NamedValues[Arg.getName()] = Alloca;
+    NamedValues[std::string(Arg.getName())] = Alloca;
   }
 
   if (Value *RetVal = Body->codegen()) {

diff  --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h
index dd6304b7a78c..c87565737f2d 100644
--- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h
+++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h
@@ -91,15 +91,15 @@ class KaleidoscopeJIT {
   KaleidoscopeJIT()
       : Resolver(createLegacyLookupResolver(
             ES,
-            [this](const std::string &Name) -> JITSymbol {
+            [this](StringRef Name) -> JITSymbol {
               if (auto Sym = IndirectStubsMgr->findStub(Name, false))
                 return Sym;
-              if (auto Sym = OptimizeLayer.findSymbol(Name, false))
+              if (auto Sym = OptimizeLayer.findSymbol(std::string(Name), false))
                 return Sym;
               else if (auto Err = Sym.takeError())
                 return std::move(Err);
-              if (auto SymAddr =
-                      RTDyldMemoryManager::getSymbolAddressInProcess(Name))
+              if (auto SymAddr = RTDyldMemoryManager::getSymbolAddressInProcess(
+                      std::string(Name)))
                 return JITSymbol(SymAddr, JITSymbolFlags::Exported);
               return nullptr;
             },

diff  --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp
index bfd57e621cda..e39e8a94d037 100644
--- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp
+++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp
@@ -712,7 +712,7 @@ Function *getFunction(std::string Name) {
 /// CreateEntryBlockAlloca - Create an alloca instruction in the entry block of
 /// the function.  This is used for mutable variables etc.
 static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
-                                          const std::string &VarName) {
+                                          StringRef VarName) {
   IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
                    TheFunction->getEntryBlock().begin());
   return TmpB.CreateAlloca(Type::getDoubleTy(TheContext), nullptr, VarName);
@@ -1068,7 +1068,7 @@ Function *FunctionAST::codegen() {
     Builder.CreateStore(&Arg, Alloca);
 
     // Add arguments to variable symbol table.
-    NamedValues[Arg.getName()] = Alloca;
+    NamedValues[std::string(Arg.getName())] = Alloca;
   }
 
   if (Value *RetVal = Body->codegen()) {

diff  --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h
index 1d9c98a9d72a..d22f893ac611 100644
--- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h
+++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h
@@ -98,10 +98,10 @@ class KaleidoscopeJIT {
       : ES(ES),
         Resolver(createLegacyLookupResolver(
             ES,
-            [this](const std::string &Name) -> JITSymbol {
+            [this](StringRef Name) -> JITSymbol {
               if (auto Sym = IndirectStubsMgr->findStub(Name, false))
                 return Sym;
-              if (auto Sym = OptimizeLayer.findSymbol(Name, false))
+              if (auto Sym = OptimizeLayer.findSymbol(std::string(Name), false))
                 return Sym;
               else if (auto Err = Sym.takeError())
                 return std::move(Err);

diff  --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter5/toy.cpp b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter5/toy.cpp
index eff61fb954df..b9819327f843 100644
--- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter5/toy.cpp
+++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter5/toy.cpp
@@ -736,7 +736,7 @@ Function *getFunction(std::string Name) {
 /// CreateEntryBlockAlloca - Create an alloca instruction in the entry block of
 /// the function.  This is used for mutable variables etc.
 static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
-                                          const std::string &VarName) {
+                                          StringRef VarName) {
   IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
                    TheFunction->getEntryBlock().begin());
   return TmpB.CreateAlloca(Type::getDoubleTy(TheContext), nullptr, VarName);
@@ -1092,7 +1092,7 @@ Function *FunctionAST::codegen() {
     Builder.CreateStore(&Arg, Alloca);
 
     // Add arguments to variable symbol table.
-    NamedValues[Arg.getName()] = Alloca;
+    NamedValues[std::string(Arg.getName())] = Alloca;
   }
 
   if (Value *RetVal = Body->codegen()) {

diff  --git a/llvm/examples/Kaleidoscope/Chapter8/toy.cpp b/llvm/examples/Kaleidoscope/Chapter8/toy.cpp
index 2da3b602b62f..92903741f210 100644
--- a/llvm/examples/Kaleidoscope/Chapter8/toy.cpp
+++ b/llvm/examples/Kaleidoscope/Chapter8/toy.cpp
@@ -731,7 +731,7 @@ Function *getFunction(std::string Name) {
 /// CreateEntryBlockAlloca - Create an alloca instruction in the entry block of
 /// the function.  This is used for mutable variables etc.
 static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
-                                          const std::string &VarName) {
+                                          StringRef VarName) {
   IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
                    TheFunction->getEntryBlock().begin());
   return TmpB.CreateAlloca(Type::getDoubleTy(TheContext), nullptr, VarName);
@@ -1080,7 +1080,7 @@ Function *FunctionAST::codegen() {
     Builder.CreateStore(&Arg, Alloca);
 
     // Add arguments to variable symbol table.
-    NamedValues[Arg.getName()] = Alloca;
+    NamedValues[std::string(Arg.getName())] = Alloca;
   }
 
   if (Value *RetVal = Body->codegen()) {

diff  --git a/llvm/examples/Kaleidoscope/Chapter9/toy.cpp b/llvm/examples/Kaleidoscope/Chapter9/toy.cpp
index 21c8993e1a06..23b25b15c9b8 100644
--- a/llvm/examples/Kaleidoscope/Chapter9/toy.cpp
+++ b/llvm/examples/Kaleidoscope/Chapter9/toy.cpp
@@ -884,11 +884,10 @@ Function *getFunction(std::string Name) {
 /// CreateEntryBlockAlloca - Create an alloca instruction in the entry block of
 /// the function.  This is used for mutable variables etc.
 static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
-                                          const std::string &VarName) {
+                                          StringRef VarName) {
   IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
                    TheFunction->getEntryBlock().begin());
-  return TmpB.CreateAlloca(Type::getDoubleTy(TheContext), nullptr,
-                           VarName.c_str());
+  return TmpB.CreateAlloca(Type::getDoubleTy(TheContext), nullptr, VarName);
 }
 
 Value *NumberExprAST::codegen() {
@@ -1277,7 +1276,7 @@ Function *FunctionAST::codegen() {
     Builder.CreateStore(&Arg, Alloca);
 
     // Add arguments to variable symbol table.
-    NamedValues[Arg.getName()] = Alloca;
+    NamedValues[std::string(Arg.getName())] = Alloca;
   }
 
   KSDbgInfo.emitLocation(Body.get());

diff  --git a/mlir/examples/toy/Ch2/include/toy/Parser.h b/mlir/examples/toy/Ch2/include/toy/Parser.h
index bbab7f57f140..e1634fca9d74 100644
--- a/mlir/examples/toy/Ch2/include/toy/Parser.h
+++ b/mlir/examples/toy/Ch2/include/toy/Parser.h
@@ -171,7 +171,7 @@ class Parser {
   ///   ::= identifier
   ///   ::= identifier '(' expression ')'
   std::unique_ptr<ExprAST> parseIdentifierExpr() {
-    std::string name = lexer.getId();
+    std::string name(lexer.getId());
 
     auto loc = lexer.getLastLocation();
     lexer.getNextToken(); // eat identifier.
@@ -321,7 +321,7 @@ class Parser {
     if (lexer.getCurToken() != tok_identifier)
       return parseError<VarDeclExprAST>("identified",
                                         "after 'var' declaration");
-    std::string id = lexer.getId();
+    std::string id(lexer.getId());
     lexer.getNextToken(); // eat id
 
     std::unique_ptr<VarType> type; // Type is optional, it can be inferred
@@ -400,7 +400,7 @@ class Parser {
     if (lexer.getCurToken() != tok_identifier)
       return parseError<PrototypeAST>("function name", "in prototype");
 
-    std::string fnName = lexer.getId();
+    std::string fnName(lexer.getId());
     lexer.consume(tok_identifier);
 
     if (lexer.getCurToken() != '(')
@@ -410,7 +410,7 @@ class Parser {
     std::vector<std::unique_ptr<VariableExprAST>> args;
     if (lexer.getCurToken() != ')') {
       do {
-        std::string name = lexer.getId();
+        std::string name(lexer.getId());
         auto loc = lexer.getLastLocation();
         lexer.consume(tok_identifier);
         auto decl = std::make_unique<VariableExprAST>(std::move(loc), name);

diff  --git a/mlir/examples/toy/Ch3/include/toy/Parser.h b/mlir/examples/toy/Ch3/include/toy/Parser.h
index bbab7f57f140..e1634fca9d74 100644
--- a/mlir/examples/toy/Ch3/include/toy/Parser.h
+++ b/mlir/examples/toy/Ch3/include/toy/Parser.h
@@ -171,7 +171,7 @@ class Parser {
   ///   ::= identifier
   ///   ::= identifier '(' expression ')'
   std::unique_ptr<ExprAST> parseIdentifierExpr() {
-    std::string name = lexer.getId();
+    std::string name(lexer.getId());
 
     auto loc = lexer.getLastLocation();
     lexer.getNextToken(); // eat identifier.
@@ -321,7 +321,7 @@ class Parser {
     if (lexer.getCurToken() != tok_identifier)
       return parseError<VarDeclExprAST>("identified",
                                         "after 'var' declaration");
-    std::string id = lexer.getId();
+    std::string id(lexer.getId());
     lexer.getNextToken(); // eat id
 
     std::unique_ptr<VarType> type; // Type is optional, it can be inferred
@@ -400,7 +400,7 @@ class Parser {
     if (lexer.getCurToken() != tok_identifier)
       return parseError<PrototypeAST>("function name", "in prototype");
 
-    std::string fnName = lexer.getId();
+    std::string fnName(lexer.getId());
     lexer.consume(tok_identifier);
 
     if (lexer.getCurToken() != '(')
@@ -410,7 +410,7 @@ class Parser {
     std::vector<std::unique_ptr<VariableExprAST>> args;
     if (lexer.getCurToken() != ')') {
       do {
-        std::string name = lexer.getId();
+        std::string name(lexer.getId());
         auto loc = lexer.getLastLocation();
         lexer.consume(tok_identifier);
         auto decl = std::make_unique<VariableExprAST>(std::move(loc), name);

diff  --git a/mlir/examples/toy/Ch4/include/toy/Parser.h b/mlir/examples/toy/Ch4/include/toy/Parser.h
index bbab7f57f140..e1634fca9d74 100644
--- a/mlir/examples/toy/Ch4/include/toy/Parser.h
+++ b/mlir/examples/toy/Ch4/include/toy/Parser.h
@@ -171,7 +171,7 @@ class Parser {
   ///   ::= identifier
   ///   ::= identifier '(' expression ')'
   std::unique_ptr<ExprAST> parseIdentifierExpr() {
-    std::string name = lexer.getId();
+    std::string name(lexer.getId());
 
     auto loc = lexer.getLastLocation();
     lexer.getNextToken(); // eat identifier.
@@ -321,7 +321,7 @@ class Parser {
     if (lexer.getCurToken() != tok_identifier)
       return parseError<VarDeclExprAST>("identified",
                                         "after 'var' declaration");
-    std::string id = lexer.getId();
+    std::string id(lexer.getId());
     lexer.getNextToken(); // eat id
 
     std::unique_ptr<VarType> type; // Type is optional, it can be inferred
@@ -400,7 +400,7 @@ class Parser {
     if (lexer.getCurToken() != tok_identifier)
       return parseError<PrototypeAST>("function name", "in prototype");
 
-    std::string fnName = lexer.getId();
+    std::string fnName(lexer.getId());
     lexer.consume(tok_identifier);
 
     if (lexer.getCurToken() != '(')
@@ -410,7 +410,7 @@ class Parser {
     std::vector<std::unique_ptr<VariableExprAST>> args;
     if (lexer.getCurToken() != ')') {
       do {
-        std::string name = lexer.getId();
+        std::string name(lexer.getId());
         auto loc = lexer.getLastLocation();
         lexer.consume(tok_identifier);
         auto decl = std::make_unique<VariableExprAST>(std::move(loc), name);

diff  --git a/mlir/examples/toy/Ch5/include/toy/Parser.h b/mlir/examples/toy/Ch5/include/toy/Parser.h
index bbab7f57f140..e1634fca9d74 100644
--- a/mlir/examples/toy/Ch5/include/toy/Parser.h
+++ b/mlir/examples/toy/Ch5/include/toy/Parser.h
@@ -171,7 +171,7 @@ class Parser {
   ///   ::= identifier
   ///   ::= identifier '(' expression ')'
   std::unique_ptr<ExprAST> parseIdentifierExpr() {
-    std::string name = lexer.getId();
+    std::string name(lexer.getId());
 
     auto loc = lexer.getLastLocation();
     lexer.getNextToken(); // eat identifier.
@@ -321,7 +321,7 @@ class Parser {
     if (lexer.getCurToken() != tok_identifier)
       return parseError<VarDeclExprAST>("identified",
                                         "after 'var' declaration");
-    std::string id = lexer.getId();
+    std::string id(lexer.getId());
     lexer.getNextToken(); // eat id
 
     std::unique_ptr<VarType> type; // Type is optional, it can be inferred
@@ -400,7 +400,7 @@ class Parser {
     if (lexer.getCurToken() != tok_identifier)
       return parseError<PrototypeAST>("function name", "in prototype");
 
-    std::string fnName = lexer.getId();
+    std::string fnName(lexer.getId());
     lexer.consume(tok_identifier);
 
     if (lexer.getCurToken() != '(')
@@ -410,7 +410,7 @@ class Parser {
     std::vector<std::unique_ptr<VariableExprAST>> args;
     if (lexer.getCurToken() != ')') {
       do {
-        std::string name = lexer.getId();
+        std::string name(lexer.getId());
         auto loc = lexer.getLastLocation();
         lexer.consume(tok_identifier);
         auto decl = std::make_unique<VariableExprAST>(std::move(loc), name);

diff  --git a/mlir/examples/toy/Ch6/include/toy/Parser.h b/mlir/examples/toy/Ch6/include/toy/Parser.h
index bbab7f57f140..e1634fca9d74 100644
--- a/mlir/examples/toy/Ch6/include/toy/Parser.h
+++ b/mlir/examples/toy/Ch6/include/toy/Parser.h
@@ -171,7 +171,7 @@ class Parser {
   ///   ::= identifier
   ///   ::= identifier '(' expression ')'
   std::unique_ptr<ExprAST> parseIdentifierExpr() {
-    std::string name = lexer.getId();
+    std::string name(lexer.getId());
 
     auto loc = lexer.getLastLocation();
     lexer.getNextToken(); // eat identifier.
@@ -321,7 +321,7 @@ class Parser {
     if (lexer.getCurToken() != tok_identifier)
       return parseError<VarDeclExprAST>("identified",
                                         "after 'var' declaration");
-    std::string id = lexer.getId();
+    std::string id(lexer.getId());
     lexer.getNextToken(); // eat id
 
     std::unique_ptr<VarType> type; // Type is optional, it can be inferred
@@ -400,7 +400,7 @@ class Parser {
     if (lexer.getCurToken() != tok_identifier)
       return parseError<PrototypeAST>("function name", "in prototype");
 
-    std::string fnName = lexer.getId();
+    std::string fnName(lexer.getId());
     lexer.consume(tok_identifier);
 
     if (lexer.getCurToken() != '(')
@@ -410,7 +410,7 @@ class Parser {
     std::vector<std::unique_ptr<VariableExprAST>> args;
     if (lexer.getCurToken() != ')') {
       do {
-        std::string name = lexer.getId();
+        std::string name(lexer.getId());
         auto loc = lexer.getLastLocation();
         lexer.consume(tok_identifier);
         auto decl = std::make_unique<VariableExprAST>(std::move(loc), name);

diff  --git a/mlir/examples/toy/Ch7/include/toy/Parser.h b/mlir/examples/toy/Ch7/include/toy/Parser.h
index e8b080fc4171..3d9128178765 100644
--- a/mlir/examples/toy/Ch7/include/toy/Parser.h
+++ b/mlir/examples/toy/Ch7/include/toy/Parser.h
@@ -257,14 +257,15 @@ class Parser {
     }
 
     // Call to a user-defined function
-    return std::make_unique<CallExprAST>(std::move(loc), name, std::move(args));
+    return std::make_unique<CallExprAST>(std::move(loc), std::string(name),
+                                         std::move(args));
   }
 
   /// identifierexpr
   ///   ::= identifier
   ///   ::= identifier '(' expression ')'
   std::unique_ptr<ExprAST> parseIdentifierExpr() {
-    std::string name = lexer.getId();
+    std::string name(lexer.getId());
 
     auto loc = lexer.getLastLocation();
     lexer.getNextToken(); // eat identifier.
@@ -378,7 +379,7 @@ class Parser {
   /// Parse either a variable declaration or a call expression.
   std::unique_ptr<ExprAST> parseDeclarationOrCallExpr() {
     auto loc = lexer.getLastLocation();
-    std::string id = lexer.getId();
+    std::string id(lexer.getId());
     lexer.consume(tok_identifier);
 
     // Check for a call expression.
@@ -396,7 +397,7 @@ class Parser {
     // Parse the variable name.
     if (lexer.getCurToken() != tok_identifier)
       return parseError<VarDeclExprAST>("name", "in variable declaration");
-    std::string id = lexer.getId();
+    std::string id(lexer.getId());
     lexer.getNextToken(); // eat id
 
     // Parse the initializer.
@@ -410,7 +411,7 @@ class Parser {
     }
 
     VarType type;
-    type.name = typeName;
+    type.name = std::string(typeName);
     return std::make_unique<VarDeclExprAST>(loc, std::move(id), std::move(type),
                                             std::move(expr));
   }
@@ -428,7 +429,7 @@ class Parser {
     if (lexer.getCurToken() != tok_identifier)
       return parseError<VarDeclExprAST>("type name", "in variable declaration");
     auto loc = lexer.getLastLocation();
-    std::string typeName = lexer.getId();
+    std::string typeName(lexer.getId());
     lexer.getNextToken(); // eat id
 
     // Parse the rest of the declaration.
@@ -449,7 +450,7 @@ class Parser {
     if (lexer.getCurToken() != tok_identifier)
       return parseError<VarDeclExprAST>("identified",
                                         "after 'var' declaration");
-    std::string id = lexer.getId();
+    std::string id(lexer.getId());
     lexer.getNextToken(); // eat id
 
     std::unique_ptr<VarType> type; // Type is optional, it can be inferred
@@ -537,7 +538,7 @@ class Parser {
     if (lexer.getCurToken() != tok_identifier)
       return parseError<PrototypeAST>("function name", "in prototype");
 
-    std::string fnName = lexer.getId();
+    std::string fnName(lexer.getId());
     lexer.consume(tok_identifier);
 
     if (lexer.getCurToken() != '(')
@@ -551,7 +552,7 @@ class Parser {
         std::string name;
 
         // Parse either the name of the variable, or its type.
-        std::string nameOrType = lexer.getId();
+        std::string nameOrType(lexer.getId());
         auto loc = lexer.getLastLocation();
         lexer.consume(tok_identifier);
 
@@ -560,7 +561,7 @@ class Parser {
           type.name = std::move(nameOrType);
 
           // Parse the name.
-          name = lexer.getId();
+          name = std::string(lexer.getId());
           lexer.consume(tok_identifier);
         } else {
           // Otherwise, we just parsed the name.
@@ -610,7 +611,7 @@ class Parser {
     lexer.consume(tok_struct);
     if (lexer.getCurToken() != tok_identifier)
       return parseError<StructAST>("name", "in struct definition");
-    std::string name = lexer.getId();
+    std::string name(lexer.getId());
     lexer.consume(tok_identifier);
 
     // Parse: '{'


        


More information about the cfe-commits mailing list