llvm / llvm/llvm-project

[clang][Modules] Assertion in ActOnAnnotModuleEnd: `unexpected submodule end in main file`

Open
#203,167 3 comments 0 reactions 0 assignees View on GitHub
clang:modules generated by fuzzer
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

This input is generated by a fuzzer.
```cxx
module M {
#pragma clang module build N
module N {
}
#pragma clang module contents
#pragma clang module begin N
template struct X {
}
}
```

use
```
-std=c++2a -fmodules -fsyntax-only
```

This just causes an assertion, but it does not crash.
seems to be introduced since clang 5.

```
clang++: warning: argument unused during compilation: '-S' [-Wunused-command-line-argument]
:1:10: error: unexpected preprocessing token '{' after module name, only ';' and '[' (start of attribute specifier sequence) are allowed
1 | module M {
| ^
:2:22: error: no matching '#pragma clang module endbuild' for this '#pragma clang module build'
2 | #pragma clang module build N
| ^
N.map:6:2: error: expected ';' after struct
6 | }
| ^
| ;
N.map:7:1: error: extraneous closing brace ('}')
7 | }
| ^
N.map:4:22: error: no matching '#pragma clang module end' for this '#pragma clang module begin'
4 | #pragma clang module begin N
| ^
clang++: /root/llvm-project/llvm/tools/clang/lib/Sema/SemaModule.cpp:807: void clang::Sema::ActOnAnnotModuleEnd(clang::SourceLocation, clang::Module*): Assertion `File != getSourceManager().getMainFileID() && "end of submodule in main source file"' failed.
:1:11: error: module directive must end with a ';'
1 | module M {
| ^
| ;
:1:8: fatal error: module 'M' not found
1 | module M {
| ^
7 errors generated.
Compiler returned: 1
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.