<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Clang emits __attribute__((__used__)) functions in submodules that weren't imported"
   href="https://bugs.llvm.org/show_bug.cgi?id=48501">48501</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Clang emits __attribute__((__used__)) functions in submodules that weren't imported
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Modules
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>teemperor@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The example below reproduces the bug. 'use.h' is never actually imported by
main.cpp, but as it's in the same top-level module as 'other.h', the
'call_undefined' function is still deserialised and emitted. Note that this
happens with local-submodule-visibility turned on and off (at least with LSV=on
this seems like a bug):

$ cat main.cpp
#include "other.h"
int main() {}

$ cat other.h
struct Foo {
};

$ cat use.h
int undefined();
__attribute__((__used__))
inline int call_undefined() { undefined(); }

$ cat module.modulemap
module A {
  module Use { header "use.h" export * }
  module Other { header "other.h" export * }
}

$ clang main.cpp -fmodules -fcxx-modules  -Rmodule-build
-fmodules-cache-path=pcms -Xclang -fmodules-local-submodule-visibility
Undefined symbols for architecture x86_64:
  "undefined()", referenced from:
      call_undefined() in main-fe42f9.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

$ clang main.cpp -fmodules -fcxx-modules  -Rmodule-build
-fmodules-cache-path=pcms -Xclang -fmodules-local-submodule-visibility -S
-emit-llvm -o - | grep undefined
@llvm.used = appending global [1 x i8*] [i8* bitcast (i32 ()*
@_Z14call_undefinedv to i8*)], section "llvm.metadata"
define linkonce_odr i32 @_Z14call_undefinedv() #0 {
  %2 = call i32 @_Z9undefinedv()
declare i32 @_Z9undefinedv() #1</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>