
Consider the following code: ```cpp # 1 __FILE__ 1 3 export module a; ``` According to the wording in [P1857R3](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1857r3.html): ``` A module directive may only appear as the first preprocessing tokens in a file (excluding the global module fragment.) ``` and the wording in [[cpp.pre]](https://eel.is/c++draft/cpp.pre#nt:module-file) ``` module-file: pp-global-module-fragment[opt] pp-module group[opt] pp-private-module-fragment[opt] ``` `#` is the first pp-token in the translation unit, and it was rejected by clang, but they really should be exempted from this rule. The goal is to not allow any preprocessor conditionals or most state changes, but these don't fit that. State change would mean most semantically observable preprocessor state, particularly anything that is order dependent. Global flags like being a system header/module shouldn't matter. We should exempt a brunch of directives, even though it violates the current standard wording. In this patch, we introduce a `TrivialDirectiveTracer` to trace the **State change** that described above and propose to exempt the following kind of directive: `#line`, GNU line marker, `#ident`, `#pragma comment`, `#pragma mark`, `#pragma detect_mismatch`, `#pragma clang __debug`, `#pragma message`, `#pragma GCC warning`, `#pragma GCC error`, `#pragma gcc diagnostic`, `#pragma OPENCL EXTENSION`, `#pragma warning`, `#pragma execution_character_set`, `#pragma clang assume_nonnull` and builtin macro expansion. Fixes https://github.com/llvm/llvm-project/issues/145274 --------- Signed-off-by: yronglin <yronglin777@gmail.com>
25 lines
506 B
CMake
25 lines
506 B
CMake
add_clang_unittest(LexTests
|
|
DependencyDirectivesScannerTest.cpp
|
|
HeaderMapTest.cpp
|
|
HeaderSearchTest.cpp
|
|
LexerTest.cpp
|
|
LexHLSLRootSignatureTest.cpp
|
|
ModuleDeclStateTest.cpp
|
|
NoTrivialPPDirectiveTracerTest.cpp
|
|
PPCallbacksTest.cpp
|
|
PPConditionalDirectiveRecordTest.cpp
|
|
PPDependencyDirectivesTest.cpp
|
|
PPMemoryAllocationsTest.cpp
|
|
CLANG_LIBS
|
|
clangAST
|
|
clangBasic
|
|
clangLex
|
|
clangParse
|
|
clangSema
|
|
LINK_LIBS
|
|
LLVMTestingAnnotations
|
|
LLVMTestingSupport
|
|
LLVM_COMPONENTS
|
|
Support
|
|
)
|