[flang-commits] [flang] [flang] Tokenize all -D macro bodies, and do it better (PR #168116)

Andre Kuhlenschmidt via flang-commits flang-commits at lists.llvm.org
Tue Nov 18 10:25:02 PST 2025


================
@@ -371,40 +374,66 @@ TokenSequence Preprocessor::TokenizeMacroBody(const std::string &str) {
   Provenance provenance{allSources_.AddCompilerInsertion(str).start()};
   auto end{str.size()};
   for (std::string::size_type at{0}; at < end;) {
-    // Alternate between tokens that are identifiers (and therefore subject
-    // to argument replacement) and those that are not.
-    auto start{str.find_first_of(idChars, at)};
-    if (start == str.npos) {
-      tokens.Put(str.substr(at), provenance + at);
-      break;
-    } else if (start > at) {
-      tokens.Put(str.substr(at, start - at), provenance + at);
+    char ch{str.at(at)};
+    if (IsWhiteSpace(ch)) {
+      ++at;
+      continue;
     }
-    at = str.find_first_not_of(idChars, start + 1);
-    if (at == str.npos) {
+    auto start{at};
----------------
akuhlens wrote:

Should you use an explicit type here?

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


More information about the flang-commits mailing list