[flang-commits] [flang] [flang] Escape '%' in %VAL/%REF messages (PR #94331)

Leandro Lupori via flang-commits flang-commits at lists.llvm.org
Tue Jun 4 03:05:59 PDT 2024


https://github.com/luporl created https://github.com/llvm/llvm-project/pull/94331

flang/test/Semantics/call40.f90 was failing on Darwin:
actual at 27: VAL or REF are not allowed for dummy argument 'a='
  that must be passed by means of a descriptor
expect at 27: %VAL or %REF are not allowed for dummy argument 'a='
  that must be passed by means of a descriptor

When messages.Say() is called with more arguments than just the
fixed text message, the message is treated as a format string,
passed to vsnprintf. Therefore, the '%' chars in it must be
escaped.

Note that no conversion happens when there is only a fixed text
message. Escaping '%' in this case causes "%%" to be outputted.
This can be confusing for someone expecting printf-like behavior.
Processing these text messages with snprintf could solve this,
as a future improvement.


>From 91619ad7171f09117f929f1b1571d687567bf47d Mon Sep 17 00:00:00 2001
From: Leandro Lupori <leandro.lupori at linaro.org>
Date: Tue, 4 Jun 2024 11:43:41 +0200
Subject: [PATCH] [flang] Escape '%' in %VAL/%REF messages

flang/test/Semantics/call40.f90 was failing on Darwin:
actual at 27: VAL or REF are not allowed for dummy argument 'a='
  that must be passed by means of a descriptor
expect at 27: %VAL or %REF are not allowed for dummy argument 'a='
  that must be passed by means of a descriptor

When messages.Say() is called with more arguments than just the
fixed text message, the message is treated as a format string,
passed to vsnprintf. Therefore, the '%' chars in it must be
escaped.

Note that no conversion happens when there is only a fixed text
message. Escaping '%' in this case causes "%%" to be outputted.
This can be confusing for someone expecting printf-like behavior.
Processing these text messages with snprintf could solve this,
as a future improvement.
---
 flang/lib/Semantics/check-call.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp
index 97c685fa0b2c0..41a2d50b136b8 100644
--- a/flang/lib/Semantics/check-call.cpp
+++ b/flang/lib/Semantics/check-call.cpp
@@ -961,7 +961,7 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
   if ((arg.isPercentRef() || arg.isPercentVal()) &&
       dummy.IsPassedByDescriptor(procedure.IsBindC())) {
     messages.Say(
-        "%VAL or %REF are not allowed for %s that must be passed by means of a descriptor"_err_en_US,
+        "%%VAL or %%REF are not allowed for %s that must be passed by means of a descriptor"_err_en_US,
         dummyName);
   }
   if (arg.isPercentVal() &&



More information about the flang-commits mailing list