Skip to content

Commit 98cffd9

Browse files
committed
Address code review comments
1 parent 9de711f commit 98cffd9

File tree

6 files changed

+39
-3
lines changed

6 files changed

+39
-3
lines changed

clang/include/clang/CIR/Dialect/IR/CIRAttrs.td

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,15 @@ def ConstComplexAttr : CIR_Attr<"ConstComplex", "const_complex",
288288
type. The `real` parameter gives the real part of the complex number and the
289289
`imag` parameter gives the imaginary part of the complex number.
290290

291-
The `real` and `imag` parameter must be either an IntAttr or an FPAttr that
292-
contains values of the same CIR type.
291+
The `real` and `imag` parameters must both reference the same type and must
292+
be either IntAttr or FPAttr.
293+
294+
```mlir
295+
%ci = #cir.const_complex<#cir.int<1> : !s32i, #cir.int<2> : !s32i>
296+
: !cir.complex<!s32i>
297+
%cf = #cir.const_complex<#cir.fp<1.000000e+00> : !cir.float,
298+
#cir.fp<2.000000e+00> : !cir.float> : !cir.complex<!cir.float>
299+
```
293300
}];
294301

295302
let parameters = (ins

clang/include/clang/CIR/Dialect/IR/CIRTypes.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ def CIR_ComplexType : CIR_Type<"Complex", "complex",
179179
The parameter `elementType` gives the type of the real and imaginary part of
180180
the complex number. `elementType` must be either a CIR integer type or a CIR
181181
floating-point type.
182+
183+
```mlir
184+
!cir.complex<!s32i>
185+
!cir.complex<!cir.float>
186+
```
182187
}];
183188

184189
let parameters = (ins CIR_AnyIntOrFloatType:$elementType);

clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,8 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const APValue &value,
592592
builder.getAttr<cir::IntAttr>(complexElemTy, imag));
593593
}
594594

595+
assert(isa<cir::CIRFPTypeInterface>(complexElemTy) &&
596+
"expected floating-point type");
595597
llvm::APFloat real = value.getComplexFloatReal();
596598
llvm::APFloat imag = value.getComplexFloatImag();
597599
return builder.getAttr<cir::ConstComplexAttr>(

clang/lib/CIR/Dialect/IR/CIRDialect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ static LogicalResult checkConstantTypes(mlir::Operation *op, mlir::Type opType,
235235
opType))
236236
return success();
237237
return op->emitOpError(
238-
"zero expects struct, array, vector or complex type");
238+
"zero expects struct, array, vector, or complex type");
239239
}
240240

241241
if (mlir::isa<cir::BoolAttr>(attrType)) {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: cir-opt %s -verify-diagnostics -split-input-file
2+
3+
!s32i = !cir.int<s, 32>
4+
!s64i = !cir.int<s, 64>
5+
6+
module {
7+
8+
// expected-error @below {{type of the imaginary part does not match the complex type}}
9+
cir.global external @ci2 = #cir.const_complex<#cir.int<1> : !s32i, #cir.int<2> : !s64i> : !cir.complex<!s32i>
10+
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: cir-opt %s -verify-diagnostics -split-input-file
2+
3+
!s32i = !cir.int<s, 32>
4+
!s64i = !cir.int<s, 64>
5+
6+
module {
7+
8+
// expected-error @below {{type of the real part does not match the complex type}}
9+
cir.global external @ci2 = #cir.const_complex<#cir.int<1> : !s64i, #cir.int<2> : !s32i> : !cir.complex<!s32i>
10+
11+
}

0 commit comments

Comments
 (0)