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: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected]

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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to