[PATCH] D44106: TableGen: More helpful error messages

Nicolai Hähnle via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 7 02:10:18 PST 2018


nhaehnle added inline comments.


================
Comment at: lib/TableGen/Record.cpp:1839
+      if (Value.setValue(VR)) {
+        std::string Type;
+        if (TypedInit *VRT = dyn_cast<TypedInit>(VR))
----------------
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.


Repository:
  rL LLVM

https://reviews.llvm.org/D44106





More information about the llvm-commits mailing list