Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions flang/lib/Parser/prescan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,18 +815,33 @@ bool Prescanner::ExponentAndKind(TokenSequence &tokens) {
if (ed != 'e' && ed != 'd') {
return false;
}
EmitCharAndAdvance(tokens, ed);
if (*at_ == '+' || *at_ == '-') {
EmitCharAndAdvance(tokens, *at_);
// Do some look-ahead to ensure that this 'e'/'d' is an exponent,
// not the start of an identifier that could be a macro.
const char *p{at_};
if (int n{IsSpace(++p)}) {
p += n;
}
while (IsDecimalDigit(*at_)) {
EmitCharAndAdvance(tokens, *at_);
if (*p == '+' || *p == '-') {
if (int n{IsSpace(++p)}) {
p += n;
}
}
if (*at_ == '_') {
while (IsLegalInIdentifier(EmitCharAndAdvance(tokens, *at_))) {
if (IsDecimalDigit(*p)) { // it's an exponent
EmitCharAndAdvance(tokens, ed);
if (*at_ == '+' || *at_ == '-') {
EmitCharAndAdvance(tokens, *at_);
}
while (IsDecimalDigit(*at_)) {
EmitCharAndAdvance(tokens, *at_);
}
if (*at_ == '_') {
while (IsLegalInIdentifier(EmitCharAndAdvance(tokens, *at_))) {
}
}
return true;
} else {
return false;
}
return true;
}

void Prescanner::QuotedCharacterLiteral(
Expand Down
24 changes: 24 additions & 0 deletions flang/test/Preprocessing/not-an-exponent.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
!RUN: %flang_fc1 -fdebug-unparse %s 2>&1 | FileCheck %s
#define e eeeee
module m
interface operator(.e.)
module procedure ir,rr
end interface operator(.e.)
contains
function ir(k1,k2)
intent(in)::k1,k2
ir=k1+k2
end function ir
function rr(k1,k2)
real,intent(in)::k1,k2
rr=k1+k2
end function rr
end module m
program main
use m
!CHECK: IF (real((ir(1_4,5_4)),kind=4)/=6._4) ERROR STOP 1_4
!CHECK: IF ((rr(1._4,5.e-1_4))/=1.5_4) ERROR STOP 2_4
if((1.e.5)/=6.e0) error stop 1
if((1..e..5)/=1.5) error stop 2
print *,'pass'
end program main
Loading