aboutsummaryrefslogtreecommitdiff
path: root/flang/lib
diff options
context:
space:
mode:
authorPeter Klausler <35819229+klausler@users.noreply.github.com>2023-11-13 15:25:10 -0800
committerGitHub <noreply@github.com>2023-11-13 15:25:10 -0800
commitf2bf44b6ec2aa2ce014446cf3981275cb81f0de3 (patch)
tree3075f45b8dc7495fc6c624aea2e60a08df76c523 /flang/lib
parent9c1c56a80323291cd47af59d96122ec5bd42ea83 (diff)
downloadllvm-f2bf44b6ec2aa2ce014446cf3981275cb81f0de3.zip
llvm-f2bf44b6ec2aa2ce014446cf3981275cb81f0de3.tar.gz
llvm-f2bf44b6ec2aa2ce014446cf3981275cb81f0de3.tar.bz2
[flang][preprocessor] Finesse disabling of function-like macros (#71589)
During function-like macro expansion in a standard C/C++ preprocessor, the macro being expanded is disabled from recursive macro expansion. The implementation in this compiler's preprocessor, however, was too broad; the macro expansion needs to be disabled for the "rescanning" phase only, not for actual argument expansion. (Also corrects an obsolete comment elsewhere that was noticed during reduction of an original test case.)
Diffstat (limited to 'flang/lib')
-rw-r--r--flang/lib/Parser/preprocessor.cpp4
-rw-r--r--flang/lib/Semantics/check-call.cpp14
2 files changed, 11 insertions, 7 deletions
diff --git a/flang/lib/Parser/preprocessor.cpp b/flang/lib/Parser/preprocessor.cpp
index 5af1632..88efcf7 100644
--- a/flang/lib/Parser/preprocessor.cpp
+++ b/flang/lib/Parser/preprocessor.cpp
@@ -397,9 +397,9 @@ std::optional<TokenSequence> Preprocessor::MacroReplacement(
(n + 1 == argStart.size() ? k : argStart[n + 1] - 1) - at};
args.emplace_back(TokenSequence(input, at, count));
}
+ TokenSequence applied{def->Apply(args, prescanner)};
def->set_isDisabled(true);
- TokenSequence replaced{
- ReplaceMacros(def->Apply(args, prescanner), prescanner)};
+ TokenSequence replaced{ReplaceMacros(std::move(applied), prescanner)};
def->set_isDisabled(false);
if (!replaced.empty()) {
ProvenanceRange from{def->replacement().GetProvenanceRange()};
diff --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp
index 47d66ab..0027dbe 100644
--- a/flang/lib/Semantics/check-call.cpp
+++ b/flang/lib/Semantics/check-call.cpp
@@ -1285,11 +1285,15 @@ static void CheckAssociated(evaluate::ActualArguments &arguments,
return;
}
if (const auto &targetArg{arguments[1]}) {
- // The standard requires that the POINTER= argument be a valid LHS for
- // a pointer assignment when the TARGET= argument is present. This,
- // perhaps unintentionally, excludes function results, including NULL(),
- // from being used there, as well as INTENT(IN) dummy pointers.
- // Allow this usage as a benign extension with a portability warning.
+ // The standard requires that the TARGET= argument, when present,
+ // be a valid RHS for a pointer assignment that has the POINTER=
+ // argument as its LHS. Some popular compilers misinterpret this
+ // requirement more strongly than necessary, and actually validate
+ // the POINTER= argument as if it were serving as the LHS of a pointer
+ // assignment. This, perhaps unintentionally, excludes function
+ // results, including NULL(), from being used there, as well as
+ // INTENT(IN) dummy pointers. Detect these conditions and emit
+ // portability warnings.
if (!evaluate::ExtractDataRef(*pointerExpr) &&
!evaluate::IsProcedurePointer(*pointerExpr)) {
context.messages().Say(pointerArg->sourceLocation(),