[PATCH] D18699: [ELF] - Teach linkerscript error handler to show full script line + column marker on error.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 3 11:44:03 PDT 2016


ruiu added a comment.

Looks much better.


================
Comment at: ELF/LinkerScript.cpp:176
@@ -174,1 +175,3 @@
 
+static StringRef getLine(StringRef S, size_t Pos) {
+  size_t Begin = S.rfind('\n', Pos);
----------------
Add a comment.

  // Returns the line that the character S[Pos] is in.

================
Comment at: ELF/LinkerScript.cpp:182
@@ +181,3 @@
+    End = S.size();
+  // rtrim() needed here because string can have '\r\n' at end.
+  return S.substr(Begin, End - Begin).rtrim();
----------------
Do we have to care about DOS-style newline here?

================
Comment at: ELF/LinkerScript.cpp:186
@@ +185,3 @@
+
+void ScriptParser::printLineColumn() {
+  StringRef Tok = Tokens[Pos == 0 ? 0 : Pos - 1];
----------------
Rename printErrorPos.

================
Comment at: ELF/LinkerScript.cpp:189-191
@@ +188,5 @@
+  StringRef Line = getLine(Input, Tok.data() - Input.data());
+  size_t Col = Tok.data() - Line.data() + 1;
+  error(Line);
+  error(std::string(Col - 1, ' ') + "^");
+}
----------------
Remove +1 and -1.

================
Comment at: test/ELF/linkerscript-diagnostic.s:70
@@ +69,2 @@
+## Check that last line is "     ^"
+# ERR7DUMP: 00000040 20 20 20 20 20 5e
----------------
This is probably too much. Please just use a regexp {{.....^}} instead.


http://reviews.llvm.org/D18699





More information about the llvm-commits mailing list