[PATCH] D44106: TableGen: More helpful error messages

Artem Belevich via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 7 10:08:23 PST 2018


tra added inline comments.


================
Comment at: lib/TableGen/Record.cpp:1839
+      if (Value.setValue(VR)) {
+        std::string Type;
+        if (TypedInit *VRT = dyn_cast<TypedInit>(VR))
----------------
nhaehnle wrote:
> tra wrote:
> > You are constructing a std::string only to use it  to build another Twine. Why not just use Twine here?
> Because of `Twine` lifetime limitations. Twine works by chaining together temporary node objects to represent the string concatenations. So changing Type to type Twine can't work, because the temporary node objects would be destroyed again immediately, before they are passed to PrintFatalError.
> 
> (The compiler actually prevents attempts to do this, since Twine::operator= is deleted.)
> 
> I think it would work to "inline" Type in the argument to PrintFatalError, guarding it with a ternary ?: operator, but that seemed uglier to me.
Thank you for the explanation. Reading ADT/Twine.h was enlightening. Now std::string makes sense to me.


Repository:
  rL LLVM

https://reviews.llvm.org/D44106





More information about the llvm-commits mailing list