<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - -fmodules-local-submodule-visibility fails to merge weak variable definitions."
   href="https://llvm.org/bugs/show_bug.cgi?id=31246">31246</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>-fmodules-local-submodule-visibility fails to merge weak variable definitions.
          </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>Windows NT
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </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>eric@efcs.ca
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=17706" name="attach_17706" title="full reproducer">attachment 17706</a> <a href="attachment.cgi?id=17706&action=edit" title="full reproducer">[details]</a></span>
full reproducer

I'm not exactly sure if this is a bug, because weak variable definitions aren't
standard C++; However llvm/Config/abi-breaking.h uses the feature and this
causes the standalone Clang modules build to fail due to multiple definitions
of `VerifyEnableABIBreakingChecks`.

I've attached a full reproducer and Makefile which triggers the bug.

I'm not sure how Clang should merge weak variable definitions, or if it's even
possible.

Basic reproducer:
// foo.h
__attribute__((weak) int x = 42;

// module1.h
#include "foo.h"

// module2.h
#include "foo.h"

// module.modulemap
module test_modules {
  module module1 {
    header "module1.h"
    export *
  }
  module module2 {
    header "module2.h"
    export *
  }
}

// test.cpp
#include "module1.h"</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>