<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 --- - Unexpected divergence between -fmodules and not (due to "<undeserialized declarations>"?)"
   href="https://llvm.org/bugs/show_bug.cgi?id=24425">24425</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Unexpected divergence between -fmodules and not (due to "<undeserialized declarations>"?)
          </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>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>chisophugis@gmail.com
          </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>Here's an example where -fmodules has an unexpected effect on the output. We
seem to not be deserializing some stuff.

a.cpp:
#include "a.h"                                                                  
// Modules version has Foo<int>::s_bar undefined.
// Nonmodules version has Foo<int>::s_bar defined.
template <typename T> char Foo<T>::s_bar;

a.h:
template <class T> struct Foo { static char s_bar; };
char baz() { return Foo<int>::s_bar; }

module.modulemap:
module a {                                                                      
  header "a.h"
}

repro.sh:
BIN=~/pg/d+a/bin                                                                
CLANGXX=$BIN/clang++
NM=$BIN/llvm-nm
CACHE_PATH=./cache_path

rm -rf $CACHE_PATH
$CLANGXX -c a.cpp -o a.o -fmodules-cache-path=$CACHE_PATH -fmodules && $NM a.o
| grep 's_bar'
$CLANGXX -c a.cpp -o a.o && $NM a.o | grep 's_bar'


Observed output on trunk:
% ./repro.sh
                 U __ZN3FooIiE5s_barE
0000000000000010 S __ZN3FooIiE5s_barE


Adding `-Xclang -ast-dump` to the compiler invocations in repro.sh suggests
that the issue is that we aren't deserializing `Foo<int>::s_bar`

(-fmodules)
...
|-ImportDecl 0x7f9b838394f8 <a.cpp:1:1> col:1 implicit a
|-VarDecl 0x7f9b84008058 parent 0x7f9b83839738 prev 0x7f9b84007fe8 <line:4:1,
col:36> col:36 s_bar 'char'
`-<undeserialized declarations>

(no -fmodules)
...
|-ClassTemplateDecl 0x7fc28883d910 <./a.h:1:1, col:52> col:27 Foo
| |-TemplateTypeParmDecl 0x7fc28883d7c8 <col:11, col:17> col:17 class T
| |-CXXRecordDecl 0x7fc28883d880 <col:20, col:52> col:27 struct Foo definition
| | |-CXXRecordDecl 0x7fc288885a00 <col:20, col:27> col:27 implicit struct Foo
| | `-VarDecl 0x7fc288885aa0 <col:33, col:45> col:45 s_bar 'char' static
| `-ClassTemplateSpecializationDecl 0x7fc288885c48 <col:1, col:52> col:27
struct Foo definition
|   |-TemplateArgument type 'int'
|   |-CXXRecordDecl 0x7fc288885e38 prev 0x7fc288885c48 <col:20, col:27> col:27
implicit struct Foo
|   `-VarDecl 0x7fc288885ec8 <col:33, col:45> col:45 used s_bar 'char' static
|-FunctionDecl 0x7fc288885b50 <line:2:1, col:38> col:6 baz 'char (void)'
| `-CompoundStmt 0x7fc288885fd0 <col:12, col:38>
|   `-ReturnStmt 0x7fc288885fb8 <col:14, col:31>
|     `-ImplicitCastExpr 0x7fc288885fa0 <col:21, col:31> 'char'
<LValueToRValue>
|       `-DeclRefExpr 0x7fc288885f68 <col:21, col:31> 'char' lvalue Var
0x7fc288885ec8 's_bar' 'char'
|-VarDecl 0x7fc288886280 parent 0x7fc28883d880 prev 0x7fc288885aa0 <a.cpp:4:1,
col:36> col:36 s_bar 'char'
`-VarDecl 0x7fc288886320 parent 0x7fc288885c48 prev 0x7fc288885ec8 <col:23,
col:36> col:36 used s_bar 'char'</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>