Issue 98021
Summary C++ modules appear to be exceedignly strict with intrinsic headers
Labels new issue
Assignees
Reporter chriselrod
    That is, code using `immintrin.h` tends to fail to compile when using modules while working fine with headers.
I'll try to produce a minimal example in the next few hours.
For now, I have an example using boost_unordered.
When problems showed up in my own code using intrinsics, I could generally fix it by declaring all arguments as variables, and then passing the lvalues to the intriinsic function.

Hello.cxxm:
```c++
#ifndef USE_HEADERS
module;
#endif
#include <boost/unordered/unordered_flat_map.hpp>
#include <iostream>

#ifndef USE_HEADERS
export module Hello;
export {
#endif
  void hello() { std::cout << "Hello World!\n"; }
 template <typename K, typename V> using map = boost::unordered_flat_map<K, V>;
#ifndef USE_HEADERS
}
#endif
```
user.cpp:
```c++
#ifndef USE_HEADERS
import Hello;
#else
#include "hello.cxxm"
#endif

int main() {
  hello();
  int x = 0;
  long y = 0;
  map<int*,long*> m;
  m[&x] = &y;
 [[maybe_unused]] auto f = m.find(&x);
  return 0;
}
```

Compiling with headers:
```sh
$ clang++ -std=c++23 use.cpp -DUSE_HEADERS -o Hello.out
$ ./Hello.out
Hello World!
```
With modules:
```sh
$ clang++ -std=c++23 --precompile hello.cxxm -o M-hello.pcm
$ clang++ -std=c++23 use.cpp -fmodule-file=Hello=M-hello.pcm M-hello.pcm -o Hello_mod.out
```
results in
```
/usr/include/boost/unordered/detail/foa/core.hpp:293:7: error: no matching function for call to '_mm_cmpeq_epi8'
  293 | _mm_cmpeq_epi8(load_metadata(),_mm_setzero_si128()))&0x7FFF;
      | ^~~~~~~~~~~~~~
/usr/include/boost/unordered/detail/foa/core.hpp:309:14: note: in instantiation of member function 'boost::unordered::detail::foa::group15<boost::unordered::detail::foa::plain_integral>::match_available' requested here
  309 |     return (~match_available())&0x7FFF;
```
I could file this as a `boost_unordered` issue or make a PR there, as I've generally found I can work around the problem.
But I'll see about creating a minimal reproducer using `#include <immintrin.h>` directlry that works with headers but fails with modules.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to