[flang-commits] [flang] [FLANG][OPENMP] Fix handling of continuation lines in mixed OpenMP an… (PR #120714)

Leandro Lupori via flang-commits flang-commits at lists.llvm.org
Fri Dec 20 10:54:06 PST 2024


================
@@ -1289,29 +1289,49 @@ const char *Prescanner::FreeFormContinuationLine(bool ampersand) {
     return nullptr;
   }
   p = SkipWhiteSpace(p);
-  if (InCompilerDirective()) {
-    if (*p++ != '!') {
-      return nullptr;
-    }
-    for (const char *s{directiveSentinel_}; *s != '\0'; ++p, ++s) {
-      if (*s != ToLowerCaseLetter(*p)) {
+  if (*p == '!') {
+    if (InCompilerDirective()) {
+      if (*p++ != '!') {
         return nullptr;
       }
-    }
-    p = SkipWhiteSpace(p);
-    if (*p == '&') {
-      if (!ampersand) {
-        insertASpace_ = true;
+      for (const char *s{directiveSentinel_}; *s != '\0'; ++p, ++s) {
+        if (*s != ToLowerCaseLetter(*p)) {
+          return nullptr;
+        }
+      }
+      p = SkipWhiteSpace(p);
+      if (*p == '&') {
+        if (!ampersand) {
+          insertASpace_ = true;
+        }
+        return p + 1;
+      } else if (ampersand) {
+        return p;
+      } else {
+        return nullptr;
+      }
+    } else if (features_.IsEnabled(LanguageFeature::OpenMP)) {
+      if (*p + 1 == '$')
+        return nullptr;
+      p += 2;
+      p = SkipWhiteSpace(p);
+      if (*p == '&') {
+        if (!ampersand) {
+          insertASpace_ = true;
+        }
+        return p + 1;
+      } else if (ampersand) {
+        return p;
+      } else {
+        return nullptr;
       }
-      return p + 1;
-    } else if (ampersand) {
-      return p;
     } else {
       return nullptr;
     }
   } else {
     if (*p == '&') {
-      return p + 1;
+      p = SkipWhiteSpace(p + 1);
+      return p;
----------------
luporl wrote:

This change will cause issues with strings.
For example, this line
```
print *, "one&
& two"
```
would print "onetwo" instead of "one two".

At least GFortran and one other Fortran compiler don't skip white spaces after `'&'`.

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


More information about the flang-commits mailing list