<div dir="ltr">Hi Adrian,<div><br></div><div>That seems odd. Do you know why this would be happening for llvm-c/Error.h and not other llvm-c headers?</div><div><br></div><div>Cheers,</div><div>Lang.</div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Aug 15, 2018 at 1:53 PM Adrian Prantl <<a href="mailto:aprantl@apple.com">aprantl@apple.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space">It looks like you may also need to update the module.modulemap for building with -DLLVM_ENABLE_MODULES=On:<div><br></div><div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:Menlo;font-size:11px"><span style="font-variant-ligatures:no-common-ligatures">While building module 'LLVM_Utils' imported from ../lib/Support/APSInt.cpp:15:</span></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:Menlo;font-size:11px"><span style="font-variant-ligatures:no-common-ligatures">In file included from <module-includes>:77:</span></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:Menlo;font-size:11px"><span style="font-variant-ligatures:no-common-ligatures">In file included from ../include/llvm/Support/BinaryStreamError.h:14:</span></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:Menlo;font-size:11px"><span style="font-variant-ligatures:no-common-ligatures"><b>../include/llvm/Support/Error.h:17:2: </b></span><span style="font-variant-ligatures:no-common-ligatures;color:#c814c9"><b>warning: </b></span><span style="font-variant-ligatures:no-common-ligatures"><b>missing submodule 'LLVM_C.Error' [-Wincomplete-umbrella]</b></span></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:Menlo;font-size:11px"><span style="font-variant-ligatures:no-common-ligatures">#include "llvm-c/Error.h"</span></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:Menlo;color:rgb(47,180,29);font-size:11px"><span style="font-variant-ligatures:no-common-ligatures"><b> ^       ~~~~~~~~~~~~~~~~</b></span></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:Menlo;font-size:11px"><span style="font-variant-ligatures:no-common-ligatures">1 warning generated.</span></div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div><span style="font-variant-ligatures:no-common-ligatures">thanks,</span></div><div>adrian</div><div><br><blockquote type="cite"><div>On Aug 15, 2018, at 11:42 AM, Lang Hames via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:</div><br class="m_-4023893181820227247Apple-interchange-newline"><div><div>Author: lhames<br>Date: Wed Aug 15 11:42:11 2018<br>New Revision: 339802<br><br>URL: <a href="http://llvm.org/viewvc/llvm-project?rev=339802&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=339802&view=rev</a><br>Log:<br>[Support] Add a basic C API for llvm::Error.<br><br>Summary:<br>The C-API supports consuming errors, converting an error to a string error<br>message, and querying an error's type. Other LLVM C APIs that wish to use<br>llvm::Error can supply error-type-id checkers and custom<br>error-to-structured-type converters for any custom errors they provide.<br><br>Reviewers: bogner, zturner, labath, dblaikie<br><br>Subscribers: llvm-commits<br><br>Differential Revision: <a href="https://reviews.llvm.org/D50716" target="_blank">https://reviews.llvm.org/D50716</a><br><br>Added:<br>    llvm/trunk/include/llvm-c/Error.h<br>Modified:<br>    llvm/trunk/include/llvm/Support/Error.h<br>    llvm/trunk/lib/Support/Error.cpp<br>    llvm/trunk/unittests/Support/ErrorTest.cpp<br><br>Added: llvm/trunk/include/llvm-c/Error.h<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/Error.h?rev=339802&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/Error.h?rev=339802&view=auto</a><br>==============================================================================<br>--- llvm/trunk/include/llvm-c/Error.h (added)<br>+++ llvm/trunk/include/llvm-c/Error.h Wed Aug 15 11:42:11 2018<br>@@ -0,0 +1,65 @@<br>+/*===------- llvm-c/Error.h - llvm::Error class C Interface -------*- C -*-===*\<br>+|*                                                                            *|<br>+|*                     The LLVM Compiler Infrastructure                       *|<br>+|*                                                                            *|<br>+|* This file is distributed under the University of Illinois Open Source      *|<br>+|* License. See LICENSE.TXT for details.                                      *|<br>+|*                                                                            *|<br>+|*===----------------------------------------------------------------------===*|<br>+|*                                                                            *|<br>+|* This file defines the C interface to LLVM's Error class.                   *|<br>+|*                                                                            *|<br>+\*===----------------------------------------------------------------------===*/<br>+<br>+#ifndef LLVM_C_ERROR_H<br>+#define LLVM_C_ERROR_H<br>+<br>+#ifdef __cplusplus<br>+extern "C" {<br>+#endif<br>+<br>+/**<br>+ * Opaque reference to an error instance. Null serves as the 'success' value.<br>+ */<br>+typedef struct LLVMOpaqueError *LLVMErrorRef;<br>+<br>+/**<br>+ * Error type identifier.<br>+ */<br>+typedef const void *LLVMErrorTypeId;<br>+<br>+/**<br>+ * Returns the type id for the given error instance, which must be a failure<br>+ * value (i.e. non-null).<br>+ */<br>+LLVMErrorTypeId LLVMGetErrorTypeId(LLVMErrorRef Err);<br>+<br>+/**<br>+ * Dispose of the given error without handling it. This operation consumes the<br>+ * error, and the given LLVMErrorRef value is not usable once this call returns.<br>+ * Note: This method *only* needs to be called if the error is not being passed<br>+ * to some other consuming operation, e.g. LLVMGetErrorMessage.<br>+ */<br>+void LLVMConsumeError(LLVMErrorRef Err);<br>+<br>+/**<br>+ * Returns the given string's error message. This operation consumes the error,<br>+ * and the given LLVMErrorRef value is not usable once this call returns.<br>+ */<br>+char *LLVMGetErrorMessage(LLVMErrorRef Err);<br>+<br>+/**<br>+ * Dispose of the given error message.<br>+ */<br>+void LLVMDisposeErrorMessage(char *ErrMsg);<br>+<br>+/**<br>+ * Returns the type id for llvm StringError.<br>+ */<br>+LLVMErrorTypeId LLVMGetStringErrorTypeId();<br>+<br>+#ifdef __cplusplus<br>+}<br>+#endif<br>+<br>+#endif<br><br>Modified: llvm/trunk/include/llvm/Support/Error.h<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Error.h?rev=339802&r1=339801&r2=339802&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Error.h?rev=339802&r1=339801&r2=339802&view=diff</a><br>==============================================================================<br>--- llvm/trunk/include/llvm/Support/Error.h (original)<br>+++ llvm/trunk/include/llvm/Support/Error.h Wed Aug 15 11:42:11 2018<br>@@ -14,8 +14,9 @@<br> #ifndef LLVM_SUPPORT_ERROR_H<br> #define LLVM_SUPPORT_ERROR_H<br><br>-#include "llvm/ADT/SmallVector.h"<br>+#include "llvm-c/Error.h"<br> #include "llvm/ADT/STLExtras.h"<br>+#include "llvm/ADT/SmallVector.h"<br> #include "llvm/ADT/StringExtras.h"<br> #include "llvm/ADT/Twine.h"<br> #include "llvm/Config/abi-breaking.h"<br>@@ -167,6 +168,9 @@ class LLVM_NODISCARD Error {<br>   // error.<br>   template <typename T> friend class Expected;<br><br>+  // wrap needs to be able to steal the payload.<br>+  friend LLVMErrorRef wrap(Error);<br>+<br> protected:<br>   /// Create a success value. Prefer using 'Error::success()' for readability<br>   Error() {<br>@@ -1183,6 +1187,17 @@ private:<br>   std::function<int(const Error &)> GetExitCode;<br> };<br><br>+/// Conversion from Error to LLVMErrorRef for C error bindings.<br>+inline LLVMErrorRef wrap(Error Err) {<br>+  return reinterpret_cast<LLVMErrorRef>(Err.takePayload().release());<br>+}<br>+<br>+/// Conversion from LLVMErrorRef to Error for C error bindings.<br>+inline Error unwrap(LLVMErrorRef ErrRef) {<br>+  return Error(std::unique_ptr<ErrorInfoBase>(<br>+      reinterpret_cast<ErrorInfoBase *>(ErrRef)));<br>+}<br>+<br> } // end namespace llvm<br><br> #endif // LLVM_SUPPORT_ERROR_H<br><br>Modified: llvm/trunk/lib/Support/Error.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Error.cpp?rev=339802&r1=339801&r2=339802&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Error.cpp?rev=339802&r1=339801&r2=339802&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/Support/Error.cpp (original)<br>+++ llvm/trunk/lib/Support/Error.cpp Wed Aug 15 11:42:11 2018<br>@@ -126,6 +126,26 @@ void report_fatal_error(Error Err, bool<br>   report_fatal_error(ErrMsg);<br> }<br><br>+} // end namespace llvm<br>+<br>+LLVMErrorTypeId LLVMGetErrorTypeId(LLVMErrorRef Err) {<br>+  return reinterpret_cast<ErrorInfoBase *>(Err)->dynamicClassID();<br>+}<br>+<br>+void LLVMConsumeError(LLVMErrorRef Err) { consumeError(unwrap(Err)); }<br>+<br>+char *LLVMGetErrorMessage(LLVMErrorRef Err) {<br>+  std::string Tmp = toString(unwrap(Err));<br>+  char *ErrMsg = new char[Tmp.size() + 1];<br>+  memcpy(ErrMsg, Tmp.data(), Tmp.size());<br>+  ErrMsg[Tmp.size()] = '\0';<br>+  return ErrMsg;<br>+}<br>+<br>+void LLVMDisposeErrorMessage(char *ErrMsg) { delete[] ErrMsg; }<br>+<br>+LLVMErrorTypeId LLVMGetStringErrorTypeId() {<br>+  return reinterpret_cast<void *>(&StringError::ID);<br> }<br><br> #ifndef _MSC_VER<br><br>Modified: llvm/trunk/unittests/Support/ErrorTest.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/ErrorTest.cpp?rev=339802&r1=339801&r2=339802&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/ErrorTest.cpp?rev=339802&r1=339801&r2=339802&view=diff</a><br>==============================================================================<br>--- llvm/trunk/unittests/Support/ErrorTest.cpp (original)<br>+++ llvm/trunk/unittests/Support/ErrorTest.cpp Wed Aug 15 11:42:11 2018<br>@@ -8,6 +8,7 @@<br> //===----------------------------------------------------------------------===//<br><br> #include "llvm/Support/Error.h"<br>+#include "llvm-c/Error.h"<br><br> #include "llvm/ADT/Twine.h"<br> #include "llvm/Support/Errc.h"<br>@@ -832,4 +833,35 @@ TEST(Error, ErrorMatchers) {<br>       "  Actual: failed  (CustomError {0})");<br> }<br><br>+TEST(Error, C_API) {<br>+  EXPECT_THAT_ERROR(unwrap(wrap(Error::success())), Succeeded())<br>+      << "Failed to round-trip Error success value via C API";<br>+  EXPECT_THAT_ERROR(unwrap(wrap(make_error<CustomError>(0))),<br>+                    Failed<CustomError>())<br>+      << "Failed to round-trip Error failure value via C API";<br>+<br>+  auto Err =<br>+      wrap(make_error<StringError>("test message", inconvertibleErrorCode()));<br>+  EXPECT_EQ(LLVMGetErrorTypeId(Err), LLVMGetStringErrorTypeId())<br>+      << "Failed to match error type ids via C API";<br>+  char *ErrMsg = LLVMGetErrorMessage(Err);<br>+  EXPECT_STREQ(ErrMsg, "test message")<br>+      << "Failed to roundtrip StringError error message via C API";<br>+  LLVMDisposeErrorMessage(ErrMsg);<br>+<br>+  bool GotCSE = false;<br>+  bool GotCE = false;<br>+  handleAllErrors(<br>+    unwrap(wrap(joinErrors(make_error<CustomSubError>(42, 7),<br>+                           make_error<CustomError>(42)))),<br>+    [&](CustomSubError &CSE) {<br>+      GotCSE = true;<br>+    },<br>+    [&](CustomError &CE) {<br>+      GotCE = true;<br>+    });<br>+  EXPECT_TRUE(GotCSE) << "Failed to round-trip ErrorList via C API";<br>+  EXPECT_TRUE(GotCE) << "Failed to round-trip ErrorList via C API";<br>+}<br>+<br> } // end anon namespace<br><br><br>_______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br></div></div></blockquote></div><br></div></div></blockquote></div>