Skip to content

Commit f10b62f

Browse files
committed
review comments & add cir-opt
1 parent c3480fd commit f10b62f

File tree

5 files changed

+34
-14
lines changed

5 files changed

+34
-14
lines changed

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,17 +1301,22 @@ def GlobalDtorAttr : CIR_GlobalCtorDtor<"Dtor", "dtor",
13011301
"A function with this attribute excutes before module unloading"
13021302
>;
13031303

1304-
class CIR_CXXSpecialMember<string name, string attrMnemonic, string sum,
1305-
string desc> : CIR_Attr<name, attrMnemonic> {
1304+
class CIR_CXXSpecialMember<string name, string attrMnemonic, string sum>
1305+
: CIR_Attr<name, attrMnemonic> {
13061306
let summary = sum;
1307-
let description = desc;
13081307
let skipDefaultBuilders = 1;
13091308
}
13101309

13111310
def CXXCtorAttr
13121311
: CIR_CXXSpecialMember<
1313-
"CXXCtor", "cxx_ctor", "Marks a function as a CXX constructor",
1314-
"Functions with this attribute are CXX constructors"> {
1312+
"CXXCtor", "cxx_ctor", "Marks a function as a CXX constructor"> {
1313+
let description = [{
1314+
Functions with this attribute are CXX constructors.
1315+
The `is_default_constructor` parameter is a boolean which is set to
1316+
true if the constructor is a default constructor and false otherwise.
1317+
The `is_copy_constructor` parameter is a boolean which is set to
1318+
true if the constructor is a copy constructor and false otherwise.
1319+
}];
13151320
let parameters = (ins "mlir::Type":$type,
13161321
"bool":$is_default_constructor,
13171322
"bool":$is_copy_constructor);
@@ -1337,8 +1342,10 @@ def CXXCtorAttr
13371342

13381343
def CXXDtorAttr
13391344
: CIR_CXXSpecialMember<
1340-
"CXXDtor", "cxx_dtor", "Marks a function as a CXX destructor",
1341-
"Functions with this attribute are CXX destructors"> {
1345+
"CXXDtor", "cxx_dtor", "Marks a function as a CXX destructor"> {
1346+
let description = [{
1347+
Functions with this attribute are CXX destructors
1348+
}];
13421349
let parameters = (ins "mlir::Type":$type);
13431350
let assemblyFormat = [{
13441351
`<`

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2457,11 +2457,14 @@ ParseResult cir::FuncOp::parse(OpAsmParser &parser, OperationState &state) {
24572457
bool defaultCtor = false, copyCtor = false;
24582458
if (parser.parseType(type).failed())
24592459
return failure();
2460-
if (mlir::succeeded(parser.parseOptionalComma()))
2461-
if (mlir::succeeded(parser.parseOptionalKeyword("default_ctor")))
2460+
if (mlir::succeeded(parser.parseOptionalComma())) {
2461+
if (mlir::succeeded(parser.parseOptionalKeyword("default")))
24622462
defaultCtor = true;
2463+
if (mlir::succeeded(parser.parseOptionalKeyword("copy")))
2464+
copyCtor = true;
2465+
}
24632466
if (mlir::succeeded(parser.parseOptionalComma()))
2464-
if (mlir::succeeded(parser.parseOptionalKeyword("copy_ctor")))
2467+
if (mlir::succeeded(parser.parseOptionalKeyword("copy")))
24652468
copyCtor = true;
24662469
if (parser.parseGreater().failed())
24672470
return failure();
@@ -2666,9 +2669,9 @@ void cir::FuncOp::print(OpAsmPrinter &p) {
26662669
if (auto cxxCtor = getCxxCtorAttr()) {
26672670
p << " ctor<" << cxxCtor.getType();
26682671
if (cxxCtor.getIsDefaultConstructor())
2669-
p << ", default_ctor";
2672+
p << ", default";
26702673
if (cxxCtor.getIsCopyConstructor())
2671-
p << ", copy_ctor";
2674+
p << ", copy";
26722675
p << '>';
26732676
}
26742677

clang/test/CIR/CodeGen/ctor-alias.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ B::B() {
3737
// CHECK: %1 = cir.load %0 : !cir.ptr<!cir.ptr<!rec_B>>, !cir.ptr<!rec_B>
3838
// CHECK: cir.return
3939
// CHECK: }
40-
// CHECK: cir.func private dso_local @_ZN1BC1Ev(!cir.ptr<!rec_B>) ctor<!rec_B, default_ctor> alias(@_ZN1BC2Ev)
40+
// CHECK: cir.func private dso_local @_ZN1BC1Ev(!cir.ptr<!rec_B>) ctor<!rec_B, default> alias(@_ZN1BC2Ev)

clang/test/CIR/CodeGen/temporaries.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ void f() {
1414
!E();
1515
}
1616

17-
// CIR: cir.func private @_ZN1EC1Ev(!cir.ptr<!rec_E>) ctor<!rec_E, default_ctor> extra(#fn_attr)
17+
// CIR: cir.func private @_ZN1EC1Ev(!cir.ptr<!rec_E>) ctor<!rec_E, default> extra(#fn_attr)
1818
// CIR-NEXT: cir.func private @_ZN1EntEv(!cir.ptr<!rec_E>) -> !rec_E
1919
// CIR-NEXT: cir.func private @_ZN1ED1Ev(!cir.ptr<!rec_E>) dtor<!rec_E> extra(#fn_attr)
2020
// CIR-NEXT: cir.func dso_local @_Z1fv() extra(#fn_attr1) {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: cir-opt %s
2+
3+
!s32i = !cir.int<s, 32>
4+
!rec_S = !cir.record<struct "S" {!s32i}>
5+
module {
6+
cir.func private @_ZN1SC1ERKS_(!cir.ptr<!rec_S>, !cir.ptr<!rec_S>) ctor<!rec_S, copy>
7+
cir.func private @_ZN1SC2Ei(!cir.ptr<!rec_S>, !cir.ptr<!rec_S>) ctor<!rec_S>
8+
cir.func private @_ZN1SC2Ev(!cir.ptr<!rec_S>) ctor<!rec_S, default>
9+
cir.func private @_ZN1SD2Ev(!cir.ptr<!rec_S>) dtor<!rec_S>
10+
}

0 commit comments

Comments
 (0)