Skip to content

Conversation

@klausler
Copy link
Contributor

A complex literal constant can have one BOZ component, since the type and value of the literal can be determined by converting the BOZ value to the type of the other component. But a complex literal constant with two BOZ components doesn't have a well-defined type. The error message was confusing in the case; emit a better one.

Fixes #124201.

A complex literal constant can have one BOZ component, since the
type and value of the literal can be determined by converting the
BOZ value to the type of the other component.  But a complex literal
constant with two BOZ components doesn't have a well-defined type.
The error message was confusing in the case; emit a better one.

Fixes llvm#124201.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Jan 24, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 24, 2025

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

A complex literal constant can have one BOZ component, since the type and value of the literal can be determined by converting the BOZ value to the type of the other component. But a complex literal constant with two BOZ components doesn't have a well-defined type. The error message was confusing in the case; emit a better one.

Fixes #124201.


Full diff: https://github.com/llvm/llvm-project/pull/124331.diff

2 Files Affected:

  • (modified) flang/lib/Evaluate/tools.cpp (+5)
  • (modified) flang/test/Semantics/complex01.f90 (+3-1)
diff --git a/flang/lib/Evaluate/tools.cpp b/flang/lib/Evaluate/tools.cpp
index 2d0e1996632fc2..16b02607190973 100644
--- a/flang/lib/Evaluate/tools.cpp
+++ b/flang/lib/Evaluate/tools.cpp
@@ -212,6 +212,11 @@ ConvertRealOperandsResult ConvertRealOperands(
             return {AsSameKindExprs<TypeCategory::Real>(
                 ConvertTo(ry, std::move(bx)), std::move(ry))};
           },
+          [&](BOZLiteralConstant &&,
+              BOZLiteralConstant &&) -> ConvertRealOperandsResult {
+            messages.Say("operands cannot both be BOZ"_err_en_US);
+            return std::nullopt;
+          },
           [&](auto &&, auto &&) -> ConvertRealOperandsResult { // C718
             messages.Say(
                 "operands must be INTEGER, UNSIGNED, REAL, or BOZ"_err_en_US);
diff --git a/flang/test/Semantics/complex01.f90 b/flang/test/Semantics/complex01.f90
index c9d408ee0e111f..d268eafa685896 100644
--- a/flang/test/Semantics/complex01.f90
+++ b/flang/test/Semantics/complex01.f90
@@ -1,5 +1,5 @@
 ! RUN: %python %S/test_errors.py %s %flang_fc1
-! C718 Each named constant in a complex literal constant shall be of type 
+! C718 Each named constant in a complex literal constant shall be of type
 ! integer or real.
 subroutine s()
   integer :: ivar = 35
@@ -30,4 +30,6 @@ subroutine s()
   complex :: cvar11 = (cconst, 1.0)
   !ERROR: operands must be INTEGER, UNSIGNED, REAL, or BOZ
   complex :: cvar12 = (lconst, 1.0)
+  !ERROR: operands cannot both be BOZ
+  complex :: cvar13 = (z'3f700000', z'00000000')
 end subroutine s

!ERROR: operands must be INTEGER, UNSIGNED, REAL, or BOZ
complex :: cvar12 = (lconst, 1.0)
!ERROR: operands cannot both be BOZ
complex :: cvar13 = (z'3f700000', z'00000000')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there already a test for creating COMPLEX from one BOZ component?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know.

Copy link
Contributor

@DanielCChen DanielCChen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@klausler klausler merged commit 08c3642 into llvm:main Jan 27, 2025
11 checks passed
@klausler klausler deleted the bug124201 branch January 27, 2025 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:semantics flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Flang] Confusing error message on BOZ constant to complex type assignment.

5 participants