aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Klausler <35819229+klausler@users.noreply.github.com>2024-06-18 12:45:55 -0700
committerGitHub <noreply@github.com>2024-06-18 12:45:55 -0700
commitd7b5741ad117a068537e2f0101999d1184acab4e (patch)
tree6ac272d21af63821beb7720230063c5d50dd0fc4
parentad2905e52c2016a7de02ace59e33c3ca6ab53cd9 (diff)
downloadllvm-d7b5741ad117a068537e2f0101999d1184acab4e.zip
llvm-d7b5741ad117a068537e2f0101999d1184acab4e.tar.gz
llvm-d7b5741ad117a068537e2f0101999d1184acab4e.tar.bz2
[flang] Fix crash due to overly broad assertion (#95809)
Fix https://github.com/llvm/llvm-project/issues/95689 and add a regression test.
-rw-r--r--flang/lib/Parser/prescan.cpp8
-rw-r--r--flang/test/Preprocessing/multi-cont.F906
2 files changed, 9 insertions, 5 deletions
diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index 8efcd61..2a6ecfb 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -185,11 +185,9 @@ void Prescanner::Statement() {
// a comment marker or directive sentinel. If so, disable line
// continuation, so that NextToken() won't consume anything from
// following lines.
- if (IsLegalIdentifierStart(*at_)) {
- CHECK(NextToken(tokens));
- CHECK(tokens.SizeInTokens() == 1);
- CharBlock id{tokens.TokenAt(0)};
- if (preprocessor_.IsNameDefined(id) &&
+ if (IsLegalIdentifierStart(*at_) && NextToken(tokens) &&
+ tokens.SizeInTokens() > 0) {
+ if (CharBlock id{tokens.TokenAt(0)}; preprocessor_.IsNameDefined(id) &&
!preprocessor_.IsFunctionLikeDefinition(id)) {
if (auto replaced{preprocessor_.MacroReplacement(tokens, *this)}) {
auto newLineClass{ClassifyLine(*replaced, GetCurrentProvenance())};
diff --git a/flang/test/Preprocessing/multi-cont.F90 b/flang/test/Preprocessing/multi-cont.F90
new file mode 100644
index 0000000..5a2c0b9
--- /dev/null
+++ b/flang/test/Preprocessing/multi-cont.F90
@@ -0,0 +1,6 @@
+! RUN: %flang -E %s 2>&1 | FileCheck --strict-whitespace %s
+! CHECK: print *, 666
+pr&
+&i&
+&nt *, 666
+end