Skip to content

Commit 7fb608d

Browse files
authored
[CIR][CIRGen] Remove -clangir-disable-emit-cxx-default (#1198)
This is a leftover from when ClangIR was initially focused on analysis and could ignore default method generation. We now handle default methods and should generate them in all cases. This fixes several bugs: - Default methods weren't emitted when emitting LLVM, only CIR. - Default methods only referenced by other default methods weren't emitted.
1 parent 165afb8 commit 7fb608d

32 files changed

+66
-92
lines changed

clang/include/clang/CIR/CIRGenerator.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ class CIRGenerator : public clang::ASTConsumer {
102102
bool verifyModule();
103103

104104
void emitDeferredDecls();
105-
void emitDefaultMethods();
106105
};
107106

108107
} // namespace cir

clang/include/clang/Driver/Options.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3062,10 +3062,6 @@ def clangir_disable_verifier : Flag<["-"], "clangir-disable-verifier">,
30623062
Visibility<[ClangOption, CC1Option]>,
30633063
HelpText<"ClangIR: Disable MLIR module verifier">,
30643064
MarshallingInfoFlag<FrontendOpts<"ClangIRDisableCIRVerifier">>;
3065-
def clangir_disable_emit_cxx_default : Flag<["-"], "clangir-disable-emit-cxx-default">,
3066-
Visibility<[ClangOption, CC1Option]>,
3067-
HelpText<"ClangIR: Disable emission of c++ default (compiler implemented) methods.">,
3068-
MarshallingInfoFlag<FrontendOpts<"ClangIRDisableEmitCXXDefault">>;
30693065
def clangir_verify_diagnostics : Flag<["-"], "clangir-verify-diagnostics">,
30703066
Visibility<[ClangOption, CC1Option]>,
30713067
HelpText<"ClangIR: Enable diagnostic verification in MLIR, similar to clang's -verify">,

clang/include/clang/Frontend/FrontendOptions.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,6 @@ class FrontendOptions {
433433
/// Disable Clang IR (CIR) verifier
434434
unsigned ClangIRDisableCIRVerifier : 1;
435435

436-
/// Disable ClangIR emission for CXX default (compiler generated methods).
437-
unsigned ClangIRDisableEmitCXXDefault : 1;
438-
439436
/// Enable diagnostic verification for CIR
440437
unsigned ClangIRVerifyDiags : 1;
441438

@@ -655,10 +652,9 @@ class FrontendOptions {
655652
EmitPrettySymbolGraphs(false), GenReducedBMI(false),
656653
UseClangIRPipeline(false), ClangIRDirectLowering(false),
657654
ClangIRDisablePasses(false), ClangIRDisableCIRVerifier(false),
658-
ClangIRDisableEmitCXXDefault(false), ClangIRLifetimeCheck(false),
659-
ClangIRIdiomRecognizer(false), ClangIRLibOpt(false),
660-
ClangIRAnalysisOnly(false), TimeTraceGranularity(500),
661-
TimeTraceVerbose(false) {}
655+
ClangIRLifetimeCheck(false), ClangIRIdiomRecognizer(false),
656+
ClangIRLibOpt(false), ClangIRAnalysisOnly(false),
657+
TimeTraceGranularity(500), TimeTraceVerbose(false) {}
662658

663659
/// getInputKindForExtension - Return the appropriate input kind for a file
664660
/// extension. For example, "c" would return Language::C.

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2786,10 +2786,7 @@ cir::FuncOp CIRGenModule::GetOrCreateCIRFunction(
27862786
FD = FD->getPreviousDecl()) {
27872787
if (isa<CXXRecordDecl>(FD->getLexicalDeclContext())) {
27882788
if (FD->doesThisDeclarationHaveABody()) {
2789-
if (isDefaultedMethod(FD))
2790-
addDefaultMethodsToEmit(GD.getWithDecl(FD));
2791-
else
2792-
addDeferredDeclToEmit(GD.getWithDecl(FD));
2789+
addDeferredDeclToEmit(GD.getWithDecl(FD));
27932790
break;
27942791
}
27952792
}
@@ -2939,13 +2936,6 @@ void CIRGenModule::emitDeferred(unsigned recursionLimit) {
29392936
}
29402937
}
29412938

2942-
void CIRGenModule::emitDefaultMethods() {
2943-
// Differently from DeferredDeclsToEmit, there's no recurrent use of
2944-
// DefaultMethodsToEmit, so use it directly for emission.
2945-
for (auto &D : DefaultMethodsToEmit)
2946-
emitGlobalDecl(D);
2947-
}
2948-
29492939
mlir::IntegerAttr CIRGenModule::getSize(CharUnits size) {
29502940
return builder.getSizeFromCharUnits(&getMLIRContext(), size);
29512941
}

clang/lib/CIR/CodeGen/CIRGenModule.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -566,14 +566,6 @@ class CIRGenModule : public CIRGenTypeCache {
566566
DeferredDeclsToEmit.emplace_back(GD);
567567
}
568568

569-
// After HandleTranslation finishes, differently from DeferredDeclsToEmit,
570-
// DefaultMethodsToEmit is only called after a set of CIR passes run. See
571-
// addDefaultMethodsToEmit usage for examples.
572-
std::vector<clang::GlobalDecl> DefaultMethodsToEmit;
573-
void addDefaultMethodsToEmit(clang::GlobalDecl GD) {
574-
DefaultMethodsToEmit.emplace_back(GD);
575-
}
576-
577569
std::pair<cir::FuncType, cir::FuncOp> getAddrAndTypeOfCXXStructor(
578570
clang::GlobalDecl GD, const CIRGenFunctionInfo *FnInfo = nullptr,
579571
cir::FuncType FnType = nullptr, bool Dontdefer = false,
@@ -718,9 +710,6 @@ class CIRGenModule : public CIRGenTypeCache {
718710
/// Helper for `emitDeferred` to apply actual codegen.
719711
void emitGlobalDecl(clang::GlobalDecl &D);
720712

721-
/// Build default methods not emitted before this point.
722-
void emitDefaultMethods();
723-
724713
const llvm::Triple &getTriple() const { return target.getTriple(); }
725714

726715
// Finalize CIR code generation.

clang/lib/CIR/CodeGen/CIRGenerator.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ void CIRGenerator::HandleInlineFunctionDefinition(FunctionDecl *D) {
123123
CGM->AddDeferredUnusedCoverageMapping(D);
124124
}
125125

126-
void CIRGenerator::emitDefaultMethods() { CGM->emitDefaultMethods(); }
127-
128126
void CIRGenerator::emitDeferredDecls() {
129127
if (DeferredInlineMemberFuncDefs.empty())
130128
return;

clang/lib/CIR/FrontendAction/CIRGenAction.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,6 @@ class CIRGenConsumer : public clang::ASTConsumer {
261261
case CIRGenAction::OutputType::EmitCIR:
262262
case CIRGenAction::OutputType::EmitCIRFlat:
263263
if (outputStream && mlirMod) {
264-
// Emit remaining defaulted C++ methods
265-
if (!feOptions.ClangIRDisableEmitCXXDefault)
266-
gen->emitDefaultMethods();
267-
268264
// FIXME: we cannot roundtrip prettyForm=true right now.
269265
mlir::OpPrintingFlags flags;
270266
flags.enableDebugInfo(/*enable=*/true, /*prettyForm=*/false);

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3055,9 +3055,6 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
30553055
if (Args.hasArg(OPT_clangir_disable_verifier))
30563056
Opts.ClangIRDisableCIRVerifier = true;
30573057

3058-
if (Args.hasArg(OPT_clangir_disable_emit_cxx_default))
3059-
Opts.ClangIRDisableEmitCXXDefault = true;
3060-
30613058
if (Args.hasArg(OPT_clangir_verify_diagnostics))
30623059
Opts.ClangIRVerifyDiags = true;
30633060

clang/test/CIR/CodeGen/assign-operator.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// RUN: %clang_cc1 -std=c++17 -mconstructor-aliases -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
22
// RUN: FileCheck --input-file=%t.cir %s
33

4-
// RUN: %clang_cc1 -std=c++17 -mconstructor-aliases -triple x86_64-unknown-linux-gnu -fclangir -emit-cir -clangir-disable-emit-cxx-default %s -o %t-disable.cir
5-
// RUN: FileCheck --input-file=%t-disable.cir %s --check-prefix=DISABLE
6-
74
int strlen(char const *);
85

96
struct String {
@@ -40,9 +37,6 @@ struct String {
4037
// CHECK: cir.return
4138
// CHECK: }
4239

43-
// DISABLE: cir.func linkonce_odr @_ZN10StringViewC2ERK6String
44-
// DISABLE-NEXT: %0 = cir.alloca !cir.ptr<!ty_StringView>, !cir.ptr<!cir.ptr<!ty_StringView>>, ["this", init] {alignment = 8 : i64}
45-
4640
// StringView::operator=(StringView&&)
4741
//
4842
// CHECK: cir.func linkonce_odr @_ZN10StringViewaSEOS_
@@ -61,9 +55,6 @@ struct String {
6155
// CHECK: %8 = cir.load %2 : !cir.ptr<!cir.ptr<!ty_StringView>>
6256
// CHECK: cir.return %8 : !cir.ptr<!ty_StringView>
6357
// CHECK: }
64-
65-
// DISABLE: cir.func private @_ZN10StringViewaSEOS_
66-
// DISABLE-NEXT: cir.func @main()
6758
};
6859

6960
struct StringView {
@@ -179,8 +170,6 @@ struct Trivial {
179170
// CHECK-NEXT: %[[#OTHER_I_CAST:]] = cir.cast(bitcast, %[[#OTHER_I]] : !cir.ptr<!s32i>), !cir.ptr<!void>
180171
// CHECK-NEXT: cir.libc.memcpy %[[#MEMCPY_SIZE]] bytes from %[[#OTHER_I_CAST]] to %[[#THIS_I_CAST]]
181172
// CHECK-NEXT: cir.store %[[#THIS_LOAD]], %[[#RETVAL]]
182-
// CHECK-NEXT: cir.br ^bb1
183-
// CHECK-NEXT: ^bb1:
184173
// CHECK-NEXT: %[[#RETVAL_LOAD:]] = cir.load %[[#RETVAL]]
185174
// CHECK-NEXT: cir.return %[[#RETVAL_LOAD]]
186175
// CHECK-NEXT: }

clang/test/CIR/CodeGen/coro-task.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -clangir-disable-emit-cxx-default -emit-cir %s -o %t.cir
1+
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
22
// RUN: FileCheck --input-file=%t.cir %s
33

44
namespace std {

0 commit comments

Comments
 (0)