[flang-commits] [flang] b9aa3eb - [Flang] Add a missing case for bfloat

Kiran Chandramohan via flang-commits flang-commits at lists.llvm.org
Fri Apr 28 11:39:38 PDT 2023


Author: Kiran Chandramohan
Date: 2023-04-28T18:38:14Z
New Revision: b9aa3eb28cd9d818c2ca8f3c62cb4b780cdc145c

URL: https://github.com/llvm/llvm-project/commit/b9aa3eb28cd9d818c2ca8f3c62cb4b780cdc145c
DIFF: https://github.com/llvm/llvm-project/commit/b9aa3eb28cd9d818c2ca8f3c62cb4b780cdc145c.diff

LOG: [Flang] Add a missing case for bfloat

A case was missed for the bfloat type in the getRealType function
in FIRBuilder. This can cause a crash in some situations like in
the provided test. The patch adds the missing case.

Reviewed By: vzakhari

Differential Revision: https://reviews.llvm.org/D149469

Added: 
    flang/test/Lower/complex-real.f90

Modified: 
    flang/lib/Optimizer/Builder/FIRBuilder.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Optimizer/Builder/FIRBuilder.cpp b/flang/lib/Optimizer/Builder/FIRBuilder.cpp
index 020d6c7b27eb..8ffff7ad7809 100644
--- a/flang/lib/Optimizer/Builder/FIRBuilder.cpp
+++ b/flang/lib/Optimizer/Builder/FIRBuilder.cpp
@@ -70,6 +70,8 @@ mlir::Type fir::FirOpBuilder::getRealType(int kind) {
   switch (kindMap.getRealTypeID(kind)) {
   case llvm::Type::TypeID::HalfTyID:
     return mlir::FloatType::getF16(getContext());
+  case llvm::Type::TypeID::BFloatTyID:
+    return mlir::FloatType::getBF16(getContext());
   case llvm::Type::TypeID::FloatTyID:
     return mlir::FloatType::getF32(getContext());
   case llvm::Type::TypeID::DoubleTyID:

diff  --git a/flang/test/Lower/complex-real.f90 b/flang/test/Lower/complex-real.f90
new file mode 100644
index 000000000000..72bd3cf30097
--- /dev/null
+++ b/flang/test/Lower/complex-real.f90
@@ -0,0 +1,15 @@
+! RUN: bbc -emit-fir %s -o - | FileCheck %s
+! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s
+
+! CHECK-LABEL: @_QPsb_complex_bfloat
+! CHECK: %[[C_REF:.*]] = fir.alloca !fir.complex<3> {bindc_name = "c", uniq_name = "_QFsb_complex_bfloatEc"}
+! CHECK: %[[R_REF:.*]] = fir.alloca bf16 {bindc_name = "r", uniq_name = "_QFsb_complex_bfloatEr"}
+! CHECK: %[[R_VAL:.*]] = fir.load %[[R_REF]] : !fir.ref<bf16>
+! CHECK: %[[C0:.*]] = arith.constant 0 : i32
+! CHECK: %[[CREAL_REF:.*]] = fir.coordinate_of %[[C_REF]], %[[C0]] : (!fir.ref<!fir.complex<3>>, i32) -> !fir.ref<bf16>
+! CHECK: fir.store %[[R_VAL]] to %[[CREAL_REF]] : !fir.ref<bf16>
+subroutine sb_complex_bfloat
+  complex(kind=3) :: c
+  real(kind=3) :: r
+  c%re = r
+end subroutine


        


More information about the flang-commits mailing list