<div dir="ltr"><div>Nevermind. I saw SimonP just fixed it at 332238.</div><div><br></div><div>-Andrea<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 14, 2018 at 1:24 PM, Andrea Di Biagio <span dir="ltr"><<a href="mailto:andrea.dibiagio@gmail.com" target="_blank">andrea.dibiagio@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hi Robert,</div><div><br></div><div>this commit introduced a new warning in '
lib/IR/Core.cpp':<br></div><div>
<pre><span class="m_4478641345956502441gmail-stdout">warning C4715: 'map_to_llvmModFlagBehavior': not all control paths return a value<br><br></span></pre>
</div><div>
<div>gcc also complains about it:</div><div>lib/IR/Core.cpp:293:1: warning: control reaches end of non-void function [-Wreturn-type]</div><div><br></div></div><div>I think you just forgot to add a llvm_unreachable at the end of that function.</div><div>Could you please fix it?</div><div><br></div><div>Thanks,</div><div>Andrea<br></div><div><br></div><div><br></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 14, 2018 at 9:09 AM, Robert Widmann via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: codafi<br>
Date: Mon May 14 01:09:00 2018<br>
New Revision: 332219<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=332219&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject?rev=332219&view=rev</a><br>
Log:<br>
[LLVM-C] Add Bindings For Module Flags<br>
<br>
Summary:<br>
The first foray into merging debug info into the echo tests.<br>
<br>
- Add bindings to Module::getModuleFlagsMetadata<wbr>() in the form of LLVMCopyModuleFlagsMetadata<br>
- Add the opaque type LLVMModuleFlagEntry to represent Module::ModuleFlagEntry<br>
- Add accessors for LLVMModuleFlagEntry's behavior, key, and metadata node.<br>
<br>
Reviewers: whitequark, deadalnix<br>
<br>
Reviewed By: whitequark<br>
<br>
Subscribers: aprantl, JDevlieghere, llvm-commits, harlanhaskins<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D46792" rel="noreferrer" target="_blank">https://reviews.llvm.org/D4679<wbr>2</a><br>
<br>
Modified:<br>
llvm/trunk/include/llvm-c/Core<wbr>.h<br>
llvm/trunk/include/llvm-c/Type<wbr>s.h<br>
llvm/trunk/lib/IR/Core.cpp<br>
llvm/trunk/test/Bindings/llvm-<wbr>c/echo.ll<br>
llvm/trunk/tools/llvm-c-test/e<wbr>cho.cpp<br>
<br>
Modified: llvm/trunk/include/llvm-c/Core<wbr>.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/Core.h?rev=332219&r1=332218&r2=332219&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/include/llvm-<wbr>c/Core.h?rev=332219&r1=332218&<wbr>r2=332219&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/include/llvm-c/Core<wbr>.h (original)<br>
+++ llvm/trunk/include/llvm-c/Core<wbr>.h Mon May 14 01:09:00 2018<br>
@@ -381,6 +381,57 @@ typedef enum {<br>
LLVMInlineAsmDialectIntel<br>
} LLVMInlineAsmDialect;<br>
<br>
+typedef enum {<br>
+ /**<br>
+ * Emits an error if two values disagree, otherwise the resulting value is<br>
+ * that of the operands.<br>
+ *<br>
+ * @see Module::ModFlagBehavior::Error<br>
+ */<br>
+ LLVMModuleFlagBehaviorError,<br>
+ /**<br>
+ * Emits a warning if two values disagree. The result value will be the<br>
+ * operand for the flag from the first module being linked.<br>
+ *<br>
+ * @see Module::ModFlagBehavior::Warni<wbr>ng<br>
+ */<br>
+ LLVMModuleFlagBehaviorWarning,<br>
+ /**<br>
+ * Adds a requirement that another module flag be present and have a<br>
+ * specified value after linking is performed. The value must be a metadata<br>
+ * pair, where the first element of the pair is the ID of the module flag<br>
+ * to be restricted, and the second element of the pair is the value the<br>
+ * module flag should be restricted to. This behavior can be used to<br>
+ * restrict the allowable results (via triggering of an error) of linking<br>
+ * IDs with the **Override** behavior.<br>
+ *<br>
+ * @see Module::ModFlagBehavior::Requi<wbr>re<br>
+ */<br>
+ LLVMModuleFlagBehaviorRequire,<br>
+ /**<br>
+ * Uses the specified value, regardless of the behavior or value of the<br>
+ * other module. If both modules specify **Override**, but the values<br>
+ * differ, an error will be emitted.<br>
+ *<br>
+ * @see Module::ModFlagBehavior::Overr<wbr>ide<br>
+ */<br>
+ LLVMModuleFlagBehaviorOverride<wbr>,<br>
+ /**<br>
+ * Appends the two values, which are required to be metadata nodes.<br>
+ *<br>
+ * @see Module::ModFlagBehavior::Appen<wbr>d<br>
+ */<br>
+ LLVMModuleFlagBehaviorAppend,<br>
+ /**<br>
+ * Appends the two values, which are required to be metadata<br>
+ * nodes. However, duplicate entries in the second list are dropped<br>
+ * during the append operation.<br>
+ *<br>
+ * @see Module::ModFlagBehavior::Appen<wbr>dUnique<br>
+ */<br>
+ LLVMModuleFlagBehaviorAppendUn<wbr>ique,<br>
+} LLVMModuleFlagBehavior;<br>
+<br>
/**<br>
* Attribute index are either LLVMAttributeReturnIndex,<br>
* LLVMAttributeFunctionIndex or a parameter number from 1 to N.<br>
@@ -666,6 +717,64 @@ const char *LLVMGetTarget(LLVMModuleRef<br>
void LLVMSetTarget(LLVMModuleRef M, const char *Triple);<br>
<br>
/**<br>
+ * Returns the module flags as an array of flag-key-value triples. The caller<br>
+ * is responsible for freeing this array by calling<br>
+ * \c LLVMDisposeModuleFlagsMetadata<wbr>.<br>
+ *<br>
+ * @see Module::getModuleFlagsMetadata<wbr>()<br>
+ */<br>
+LLVMModuleFlagEntry *LLVMCopyModuleFlagsMetadata(L<wbr>LVMModuleRef M, size_t *Len);<br>
+<br>
+/**<br>
+ * Destroys module flags metadata entries.<br>
+ */<br>
+void LLVMDisposeModuleFlagsMetadata<wbr>(LLVMModuleFlagEntry *Entries);<br>
+<br>
+/**<br>
+ * Returns the flag behavior for a module flag entry at a specific index.<br>
+ *<br>
+ * @see Module::ModuleFlagEntry::Behav<wbr>ior<br>
+ */<br>
+LLVMModuleFlagBehavior<br>
+LLVMModuleFlagEntriesGetFlagB<wbr>ehavior(LLVMModuleFlagEntry *Entries,<br>
+ unsigned Index);<br>
+<br>
+/**<br>
+ * Returns the key for a module flag entry at a specific index.<br>
+ *<br>
+ * @see Module::ModuleFlagEntry::Key<br>
+ */<br>
+const char *LLVMModuleFlagEntriesGetKey(L<wbr>LVMModuleFlagEntry *Entries,<br>
+ unsigned Index, size_t *Len);<br>
+<br>
+/**<br>
+ * Returns the metadata for a module flag entry at a specific index.<br>
+ *<br>
+ * @see Module::ModuleFlagEntry::Val<br>
+ */<br>
+LLVMMetadataRef LLVMModuleFlagEntriesGetMetada<wbr>ta(LLVMModuleFlagEntry *Entries,<br>
+ unsigned Index);<br>
+<br>
+/**<br>
+ * Add a module-level flag to the module-level flags metadata if it doesn't<br>
+ * already exist.<br>
+ *<br>
+ * @see Module::getModuleFlag()<br>
+ */<br>
+LLVMMetadataRef LLVMGetModuleFlag(LLVMModuleRe<wbr>f M,<br>
+ const char *Key, size_t KeyLen);<br>
+<br>
+/**<br>
+ * Add a module-level flag to the module-level flags metadata if it doesn't<br>
+ * already exist.<br>
+ *<br>
+ * @see Module::addModuleFlag()<br>
+ */<br>
+void LLVMAddModuleFlag(LLVMModuleRe<wbr>f M, LLVMModuleFlagBehavior Behavior,<br>
+ const char *Key, size_t KeyLen,<br>
+ LLVMMetadataRef Val);<br>
+<br>
+/**<br>
* Dump a representation of a module to stderr.<br>
*<br>
* @see Module::dump()<br>
<br>
Modified: llvm/trunk/include/llvm-c/Type<wbr>s.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/Types.h?rev=332219&r1=332218&r2=332219&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/include/llvm-<wbr>c/Types.h?rev=332219&r1=332218<wbr>&r2=332219&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/include/llvm-c/Type<wbr>s.h (original)<br>
+++ llvm/trunk/include/llvm-c/Type<wbr>s.h Mon May 14 01:09:00 2018<br>
@@ -140,6 +140,11 @@ typedef struct LLVMOpaqueDiagnosticInfo<br>
typedef struct LLVMComdat *LLVMComdatRef;<br>
<br>
/**<br>
+ * @see llvm::Module::ModuleFlagEntry<br>
+ */<br>
+typedef struct LLVMOpaqueModuleFlagEntry LLVMModuleFlagEntry;<br>
+<br>
+/**<br>
* @}<br>
*/<br>
<br>
<br>
Modified: llvm/trunk/lib/IR/Core.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Core.cpp?rev=332219&r1=332218&r2=332219&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/lib/IR/Core.<wbr>cpp?rev=332219&r1=332218&r2=<wbr>332219&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/lib/IR/Core.cpp (original)<br>
+++ llvm/trunk/lib/IR/Core.cpp Mon May 14 01:09:00 2018<br>
@@ -266,6 +266,110 @@ void LLVMSetTarget(LLVMModuleRef M, cons<br>
unwrap(M)->setTargetTriple(Tr<wbr>iple);<br>
}<br>
<br>
+/*--.. Module flags ..............................<wbr>..........................--*/<br>
+struct LLVMOpaqueModuleFlagEntry {<br>
+ LLVMModuleFlagBehavior Behavior;<br>
+ const char *Key;<br>
+ size_t KeyLen;<br>
+ LLVMMetadataRef Metadata;<br>
+};<br>
+<br>
+static Module::ModFlagBehavior<br>
+map_to_llvmModFlagBehavior(LL<wbr>VMModuleFlagBehavior Behavior) {<br>
+ switch (Behavior) {<br>
+ case LLVMModuleFlagBehaviorError:<br>
+ return Module::ModFlagBehavior::Error<wbr>;<br>
+ case LLVMModuleFlagBehaviorWarning:<br>
+ return Module::ModFlagBehavior::Warni<wbr>ng;<br>
+ case LLVMModuleFlagBehaviorRequire:<br>
+ return Module::ModFlagBehavior::Requi<wbr>re;<br>
+ case LLVMModuleFlagBehaviorOverride<wbr>:<br>
+ return Module::ModFlagBehavior::Overr<wbr>ide;<br>
+ case LLVMModuleFlagBehaviorAppend:<br>
+ return Module::ModFlagBehavior::Appen<wbr>d;<br>
+ case LLVMModuleFlagBehaviorAppendUn<wbr>ique:<br>
+ return Module::ModFlagBehavior::Appen<wbr>dUnique;<br>
+ }<br>
+}<br>
+<br>
+static LLVMModuleFlagBehavior<br>
+map_from_llvmModFlagBehavior(<wbr>Module::ModFlagBehavior Behavior) {<br>
+ switch (Behavior) {<br>
+ case Module::ModFlagBehavior::Error<wbr>:<br>
+ return LLVMModuleFlagBehaviorError;<br>
+ case Module::ModFlagBehavior::Warni<wbr>ng:<br>
+ return LLVMModuleFlagBehaviorWarning;<br>
+ case Module::ModFlagBehavior::Requi<wbr>re:<br>
+ return LLVMModuleFlagBehaviorRequire;<br>
+ case Module::ModFlagBehavior::Overr<wbr>ide:<br>
+ return LLVMModuleFlagBehaviorOverride<wbr>;<br>
+ case Module::ModFlagBehavior::Appen<wbr>d:<br>
+ return LLVMModuleFlagBehaviorAppend;<br>
+ case Module::ModFlagBehavior::Appen<wbr>dUnique:<br>
+ return LLVMModuleFlagBehaviorAppendUn<wbr>ique;<br>
+ default:<br>
+ llvm_unreachable("Unhandled Flag Behavior");<br>
+ }<br>
+}<br>
+<br>
+LLVMModuleFlagEntry *LLVMCopyModuleFlagsMetadata(L<wbr>LVMModuleRef M, size_t *Len) {<br>
+ SmallVector<Module::ModuleFlag<wbr>Entry, 8> MFEs;<br>
+ unwrap(M)->getModuleFlagsMetad<wbr>ata(MFEs);<br>
+<br>
+ LLVMOpaqueModuleFlagEntry *Result = static_cast<LLVMOpaqueModuleFl<wbr>agEntry *>(<br>
+ safe_malloc(MFEs.size() * sizeof(LLVMOpaqueModuleFlagEnt<wbr>ry)));<br>
+ for (unsigned i = 0; i < MFEs.size(); ++i) {<br>
+ const auto &ModuleFlag = MFEs[i];<br>
+ Result[i].Behavior = map_from_llvmModFlagBehavior(M<wbr>oduleFlag.Behavior);<br>
+ Result[i].Key = ModuleFlag.Key->getString().da<wbr>ta();<br>
+ Result[i].KeyLen = ModuleFlag.Key->getString().si<wbr>ze();<br>
+ Result[i].Metadata = wrap(ModuleFlag.Val);<br>
+ }<br>
+ *Len = MFEs.size();<br>
+ return Result;<br>
+}<br>
+<br>
+void LLVMDisposeModuleFlagsMetadata<wbr>(LLVMModuleFlagEntry *Entries) {<br>
+ free(Entries);<br>
+}<br>
+<br>
+LLVMModuleFlagBehavior<br>
+LLVMModuleFlagEntriesGetFlagB<wbr>ehavior(LLVMModuleFlagEntry *Entries,<br>
+ unsigned Index) {<br>
+ LLVMOpaqueModuleFlagEntry MFE =<br>
+ static_cast<LLVMOpaqueModuleFl<wbr>agEntry>(Entries[Index]);<br>
+ return MFE.Behavior;<br>
+}<br>
+<br>
+const char *LLVMModuleFlagEntriesGetKey(L<wbr>LVMModuleFlagEntry *Entries,<br>
+ unsigned Index, size_t *Len) {<br>
+ LLVMOpaqueModuleFlagEntry MFE =<br>
+ static_cast<LLVMOpaqueModuleFl<wbr>agEntry>(Entries[Index]);<br>
+ *Len = MFE.KeyLen;<br>
+ return MFE.Key;<br>
+}<br>
+<br>
+LLVMMetadataRef LLVMModuleFlagEntriesGetMetada<wbr>ta(LLVMModuleFlagEntry *Entries,<br>
+ unsigned Index) {<br>
+ LLVMOpaqueModuleFlagEntry MFE =<br>
+ static_cast<LLVMOpaqueModuleFl<wbr>agEntry>(Entries[Index]);<br>
+ return MFE.Metadata;<br>
+}<br>
+<br>
+LLVMMetadataRef LLVMGetModuleFlag(LLVMModuleRe<wbr>f M,<br>
+ const char *Key, size_t KeyLen) {<br>
+ return wrap(unwrap(M)->getModuleFlag(<wbr>{Key, KeyLen}));<br>
+}<br>
+<br>
+void LLVMAddModuleFlag(LLVMModuleRe<wbr>f M, LLVMModuleFlagBehavior Behavior,<br>
+ const char *Key, size_t KeyLen,<br>
+ LLVMMetadataRef Val) {<br>
+ unwrap(M)->addModuleFlag(map_t<wbr>o_llvmModFlagBehavior(Behavior<wbr>),<br>
+ {Key, KeyLen}, unwrap(Val));<br>
+}<br>
+<br>
+/*--.. Printing modules ..............................<wbr>......................--*/<br>
+<br>
void LLVMDumpModule(LLVMModuleRef M) {<br>
unwrap(M)->print(errs(), nullptr,<br>
/*ShouldPreserveUseListOrder=*<wbr>/false, /*IsForDebug=*/true);<br>
<br>
Modified: llvm/trunk/test/Bindings/llvm-<wbr>c/echo.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bindings/llvm-c/echo.ll?rev=332219&r1=332218&r2=332219&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/test/Bindings<wbr>/llvm-c/echo.ll?rev=332219&r1=<wbr>332218&r2=332219&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/test/Bindings/llvm-<wbr>c/echo.ll (original)<br>
+++ llvm/trunk/test/Bindings/llvm-<wbr>c/echo.ll Mon May 14 01:09:00 2018<br>
@@ -159,3 +159,7 @@ cleanup:<br>
exit:<br>
ret void<br>
}<br>
+<br>
+!llvm.module.flags = !{!1}<br>
+<br>
+!1 = !{i32 2, !"Debug Info Version", i32 3}<br>
<br>
Modified: llvm/trunk/tools/llvm-c-test/e<wbr>cho.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-c-test/echo.cpp?rev=332219&r1=332218&r2=332219&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/tools/llvm-c-<wbr>test/echo.cpp?rev=332219&r1=33<wbr>2218&r2=332219&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/tools/llvm-c-test/e<wbr>cho.cpp (original)<br>
+++ llvm/trunk/tools/llvm-c-test/e<wbr>cho.cpp Mon May 14 01:09:00 2018<br>
@@ -997,6 +997,18 @@ int llvm_echo(void) {<br>
LLVMSetSourceFileName(M, SourceFileName, SourceFileLen);<br>
LLVMSetModuleIdentifier(M, ModuleName, ModuleIdentLen);<br>
<br>
+ size_t SourceFlagsLen;<br>
+ LLVMModuleFlagEntry *ModuleFlags =<br>
+ LLVMCopyModuleFlagsMetadata(Sr<wbr>c, &SourceFlagsLen);<br>
+ for (unsigned i = 0; i < SourceFlagsLen; ++i) {<br>
+ size_t EntryNameLen;<br>
+ const char *EntryName =<br>
+ LLVMModuleFlagEntriesGetKey(Mo<wbr>duleFlags, i, &EntryNameLen);<br>
+ LLVMAddModuleFlag(M, LLVMModuleFlagEntriesGetFlagBe<wbr>havior(ModuleFlags, i),<br>
+ EntryName, EntryNameLen,<br>
+ LLVMModuleFlagEntriesGetMetada<wbr>ta(ModuleFlags, i));<br>
+ }<br>
+<br>
LLVMSetTarget(M, LLVMGetTarget(Src));<br>
LLVMSetModuleDataLayout(M, LLVMGetModuleDataLayout(Src));<br>
if (strcmp(LLVMGetDataLayoutStr(M<wbr>), LLVMGetDataLayoutStr(Src)))<br>
@@ -1011,6 +1023,7 @@ int llvm_echo(void) {<br>
char *Str = LLVMPrintModuleToString(M);<br>
fputs(Str, stdout);<br>
<br>
+ LLVMDisposeModuleFlagsMetadata<wbr>(ModuleFlags);<br>
LLVMDisposeMessage(Str);<br>
LLVMDisposeModule(Src);<br>
LLVMDisposeModule(M);<br>
<br>
<br>
______________________________<wbr>_________________<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" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>