[PATCH] D70263: [Error] Add source location macro
Don Hinton via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 14 13:48:13 PST 2019
hintonda updated this revision to Diff 229397.
hintonda added a comment.
- Remove SourceLocationError class and reuse FileError.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D70263/new/
https://reviews.llvm.org/D70263
Files:
llvm/include/llvm/Support/Error.h
llvm/unittests/Support/ErrorTest.cpp
Index: llvm/unittests/Support/ErrorTest.cpp
===================================================================
--- llvm/unittests/Support/ErrorTest.cpp
+++ llvm/unittests/Support/ErrorTest.cpp
@@ -906,6 +906,24 @@
0);
}
+TEST(Error, SourceLocationErrorTest) {
+ std::string ErrStr;
+ raw_string_ostream OS(ErrStr);
+
+#if defined(NDEBUG)
+ // __FILE__ and __LINE_ not added
+ OS << "^CustomError \\{1\\}$";
+ auto E = llvm_SourceLocationError(make_error<CustomError>(1));
+ EXPECT_THAT(toString(std::move(FE1)), ::testing::ContainsRegex(OS.str()));
+#else
+ // __FILE__ and __LINE__ added
+ int Line = __LINE__;
+ OS << "'" << __FILE__ << "': line " << (Line + 2) << ": CustomError \\{1\\}$";
+ auto E = llvm_SourceLocationError(make_error<CustomError>(1));
+ EXPECT_THAT(toString(std::move(E)), ::testing::ContainsRegex(OS.str()));
+#endif
+}
+
enum class test_error_code {
unspecified = 1,
error_1,
Index: llvm/include/llvm/Support/Error.h
===================================================================
--- llvm/include/llvm/Support/Error.h
+++ llvm/include/llvm/Support/Error.h
@@ -1286,6 +1286,13 @@
Error createFileError(const Twine &F, ErrorSuccess) = delete;
+#ifndef NDEBUG
+#define llvm_SourceLocationError(E) \
+ ::llvm::createFileError(__FILE__, __LINE__, E)
+#else
+#define llvm_SourceLocationError(E) E
+#endif
+
/// Helper for check-and-exit error handling.
///
/// For tool use only. NOT FOR USE IN LIBRARY CODE.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70263.229397.patch
Type: text/x-patch
Size: 1477 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191114/e166c394/attachment.bin>
More information about the llvm-commits
mailing list