[llvm-bugs] [Bug 52531] New: [C++20] [Module] The combination of iostream and file with .cppm suffix would crash

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Nov 17 03:56:50 PST 2021


https://bugs.llvm.org/show_bug.cgi?id=52531

            Bug ID: 52531
           Summary: [C++20] [Module] The combination of iostream and file
                    with .cppm suffix would crash
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++2a
          Assignee: unassignedclangbugs at nondot.org
          Reporter: yedeng.yd at linux.alibaba.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

I met an interesting bug which would happen only if iosstream and module file
end with `.cppm`.
Here is the reproducer:
```C++
// Hello.cppm
module;
#include <iostream>
export module Hello;
export void SayHello()
{
    std::cout << "Hello World.\n";

}
// main.cpp
import Hello;
int main() {
   SayHello();
   return 0;
}

```

And if I compile it as:

```
clang++ -std=c++20 --precompile Hello.cppm -o Hello.pcm
clang++ -std=c++20 -fprebuilt-module-path=. Hello.pcm main.cpp
```

And the generated executable would crash.

Interestingly, it wouldn't crash if we use `std::printf` instead of `std::cout`

```C++
// Hello.cppm
module;
#include <cstdio>
export module Hello;
export void SayHello()
{
    std::printf("Hello World.\n");

}
// main.cpp
import Hello;
int main() {
   SayHello();
   return 0;
}
```

Also, it wouldn't crash if the suffix is `cpp` instead of `cppm`. For example:
```C++
// Hello.cpp
module;
#include <iostream>
export module Hello;
export void SayHello()
{
    std::cout << "Hello World.\n";

}
// main.cpp
import Hello;
int main() {
   SayHello();
   return 0;
}

```
Compile argument:
```
clang++ -std=c++20 -Xclang -emit-module-interface Hello.cpp -o Hello.pcm
clang++ -std=c++20 -fprebuilt-module-path=. say_hello.cpp main.cpp
```

I am not sure if this is a bug in compiler or in runtime. It is appreciate if
someone could help to confirm this.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20211117/27b0b0a2/attachment.html>


More information about the llvm-bugs mailing list