[clang] [clang-tools-extra] [clang] Don't cutoff parsing when load C++ named module failed (PR #187858)

Yihan Wang via cfe-commits cfe-commits at lists.llvm.org
Tue May 19 07:55:49 PDT 2026


================
@@ -681,16 +681,25 @@ class TokenCollector::CollectPPExpansions : public PPCallbacks {
 TokenCollector::TokenCollector(Preprocessor &PP) : PP(PP) {
   // Collect the expanded token stream during preprocessing.
   PP.setTokenWatcher([this](const clang::Token &T) {
-    if (T.isAnnotation())
+    if (T.is(tok::annot_module_name)) {
+      auto &SM = this->PP.getSourceManager();
+      StringRef Text = Lexer::getSourceText(
+          CharSourceRange::getTokenRange(T.getAnnotationRange()), SM,
+          this->PP.getLangOpts());
+      Expanded.push_back(
+          syntax::Token(T.getLocation(), Text.size(), tok::annot_module_name));
+    } else if (T.isAnnotation()) {
       return;
+    } else {
+      Expanded.push_back(syntax::Token(T));
+    }
----------------
yronglin wrote:

It's unrelated. I have created a separate PR. https://github.com/llvm/llvm-project/pull/198544

https://github.com/llvm/llvm-project/pull/187858


More information about the cfe-commits mailing list