Skip to content

Commit eef0ef2

Browse files
author
git apple-llvm automerger
committed
Merge commit '7ba7d8e2f7b6' from llvm.org/release/19.x into stable/20240723
2 parents b292ce0 + 7ba7d8e commit eef0ef2

File tree

10 files changed

+56
-45
lines changed

10 files changed

+56
-45
lines changed

clang/lib/CodeGen/CGCall.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ CodeGenTypes::arrangeCXXMethodDeclaration(const CXXMethodDecl *MD) {
314314

315315
if (MD->isImplicitObjectMemberFunction()) {
316316
// The abstract case is perfectly fine.
317-
const CXXRecordDecl *ThisType = TheCXXABI.getThisArgumentTypeForMethod(MD);
317+
const CXXRecordDecl *ThisType =
318+
getCXXABI().getThisArgumentTypeForMethod(MD);
318319
return arrangeCXXMethodType(ThisType, prototype.getTypePtr(), MD);
319320
}
320321

@@ -337,7 +338,7 @@ CodeGenTypes::arrangeCXXStructorDeclaration(GlobalDecl GD) {
337338
SmallVector<CanQualType, 16> argTypes;
338339
SmallVector<FunctionProtoType::ExtParameterInfo, 16> paramInfos;
339340

340-
const CXXRecordDecl *ThisType = TheCXXABI.getThisArgumentTypeForMethod(GD);
341+
const CXXRecordDecl *ThisType = getCXXABI().getThisArgumentTypeForMethod(GD);
341342
argTypes.push_back(DeriveThisType(ThisType, MD));
342343

343344
bool PassParams = true;
@@ -356,7 +357,7 @@ CodeGenTypes::arrangeCXXStructorDeclaration(GlobalDecl GD) {
356357
appendParameterTypes(*this, argTypes, paramInfos, FTP);
357358

358359
CGCXXABI::AddedStructorArgCounts AddedArgs =
359-
TheCXXABI.buildStructorSignature(GD, argTypes);
360+
getCXXABI().buildStructorSignature(GD, argTypes);
360361
if (!paramInfos.empty()) {
361362
// Note: prefix implies after the first param.
362363
if (AddedArgs.Prefix)
@@ -372,11 +373,10 @@ CodeGenTypes::arrangeCXXStructorDeclaration(GlobalDecl GD) {
372373
: RequiredArgs::All);
373374

374375
FunctionType::ExtInfo extInfo = FTP->getExtInfo();
375-
CanQualType resultType = TheCXXABI.HasThisReturn(GD)
376-
? argTypes.front()
377-
: TheCXXABI.hasMostDerivedReturn(GD)
378-
? CGM.getContext().VoidPtrTy
379-
: Context.VoidTy;
376+
CanQualType resultType = getCXXABI().HasThisReturn(GD) ? argTypes.front()
377+
: getCXXABI().hasMostDerivedReturn(GD)
378+
? CGM.getContext().VoidPtrTy
379+
: Context.VoidTy;
380380
return arrangeLLVMFunctionInfo(resultType, FnInfoOpts::IsInstanceMethod,
381381
argTypes, extInfo, paramInfos, required);
382382
}
@@ -437,11 +437,10 @@ CodeGenTypes::arrangeCXXConstructorCall(const CallArgList &args,
437437
: RequiredArgs::All;
438438

439439
GlobalDecl GD(D, CtorKind);
440-
CanQualType ResultType = TheCXXABI.HasThisReturn(GD)
441-
? ArgTypes.front()
442-
: TheCXXABI.hasMostDerivedReturn(GD)
443-
? CGM.getContext().VoidPtrTy
444-
: Context.VoidTy;
440+
CanQualType ResultType = getCXXABI().HasThisReturn(GD) ? ArgTypes.front()
441+
: getCXXABI().hasMostDerivedReturn(GD)
442+
? CGM.getContext().VoidPtrTy
443+
: Context.VoidTy;
445444

446445
FunctionType::ExtInfo Info = FPT->getExtInfo();
447446
llvm::SmallVector<FunctionProtoType::ExtParameterInfo, 16> ParamInfos;
@@ -806,7 +805,7 @@ const CGFunctionInfo &CodeGenTypes::arrangeLLVMFunctionInfo(
806805
} else if (info.getCC() == CC_Swift || info.getCC() == CC_SwiftAsync) {
807806
swiftcall::computeABIInfo(CGM, *FI);
808807
} else {
809-
getABIInfo().computeInfo(*FI);
808+
CGM.getABIInfo().computeInfo(*FI);
810809
}
811810

812811
// Loop over all of the computed argument and return value info. If any of
@@ -6030,6 +6029,6 @@ RValue CodeGenFunction::EmitVAArg(VAArgExpr *VE, Address &VAListAddr,
60306029
: EmitVAListRef(VE->getSubExpr());
60316030
QualType Ty = VE->getType();
60326031
if (VE->isMicrosoftABI())
6033-
return CGM.getTypes().getABIInfo().EmitMSVAArg(*this, VAListAddr, Ty, Slot);
6034-
return CGM.getTypes().getABIInfo().EmitVAArg(*this, VAListAddr, Ty, Slot);
6032+
return CGM.getABIInfo().EmitMSVAArg(*this, VAListAddr, Ty, Slot);
6033+
return CGM.getABIInfo().EmitVAArg(*this, VAListAddr, Ty, Slot);
60356034
}

clang/lib/CodeGen/CGClass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ CodeGenModule::GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl,
209209
return nullptr;
210210

211211
llvm::Type *PtrDiffTy =
212-
Types.ConvertType(getContext().getPointerDiffType());
212+
getTypes().ConvertType(getContext().getPointerDiffType());
213213

214214
return llvm::ConstantInt::get(PtrDiffTy, Offset.getQuantity());
215215
}

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,11 @@ CodeGenModule::CodeGenModule(ASTContext &C,
343343
: Context(C), LangOpts(C.getLangOpts()), FS(FS), HeaderSearchOpts(HSO),
344344
PreprocessorOpts(PPO), CodeGenOpts(CGO), TheModule(M), Diags(diags),
345345
Target(C.getTargetInfo()), ABI(createCXXABI(*this)),
346-
VMContext(M.getContext()), Types(*this), VTables(*this),
346+
VMContext(M.getContext()), VTables(*this),
347347
SanitizerMD(new SanitizerMetadata(*this)) {
348348

349349
// Initialize the type cache.
350+
Types.reset(new CodeGenTypes(*this));
350351
llvm::LLVMContext &LLVMContext = M.getContext();
351352
VoidTy = llvm::Type::getVoidTy(LLVMContext);
352353
Int8Ty = llvm::Type::getInt8Ty(LLVMContext);
@@ -405,7 +406,7 @@ CodeGenModule::CodeGenModule(ASTContext &C,
405406
if (LangOpts.Sanitize.has(SanitizerKind::Thread) ||
406407
(!CodeGenOpts.RelaxedAliasing && CodeGenOpts.OptimizationLevel > 0))
407408
TBAA.reset(new CodeGenTBAA(Context, getTypes(), TheModule, CodeGenOpts,
408-
getLangOpts(), getCXXABI().getMangleContext()));
409+
getLangOpts()));
409410

410411
// If debug info or coverage generation is enabled, create the CGDebugInfo
411412
// object.
@@ -1459,12 +1460,12 @@ void CodeGenModule::EmitBackendOptionsMetadata(
14591460

14601461
void CodeGenModule::UpdateCompletedType(const TagDecl *TD) {
14611462
// Make sure that this type is translated.
1462-
Types.UpdateCompletedType(TD);
1463+
getTypes().UpdateCompletedType(TD);
14631464
}
14641465

14651466
void CodeGenModule::RefreshTypeCacheForClass(const CXXRecordDecl *RD) {
14661467
// Make sure that this type is translated.
1467-
Types.RefreshTypeCacheForClass(RD);
1468+
getTypes().RefreshTypeCacheForClass(RD);
14681469
}
14691470

14701471
llvm::MDNode *CodeGenModule::getTBAATypeInfo(QualType QTy) {
@@ -5383,6 +5384,10 @@ void CodeGenModule::maybeSetTrivialComdat(const Decl &D,
53835384
GO.setComdat(TheModule.getOrInsertComdat(GO.getName()));
53845385
}
53855386

5387+
const ABIInfo &CodeGenModule::getABIInfo() {
5388+
return getTargetCodeGenInfo().getABIInfo();
5389+
}
5390+
53865391
/// Pass IsTentative as true if you want to create a tentative definition.
53875392
void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D,
53885393
bool IsTentative) {
@@ -7791,7 +7796,5 @@ void CodeGenModule::moveLazyEmissionStates(CodeGenModule *NewBuilder) {
77917796

77927797
NewBuilder->WeakRefReferences = std::move(WeakRefReferences);
77937798

7794-
NewBuilder->TBAA = std::move(TBAA);
7795-
77967799
NewBuilder->ABI->MangleCtx = std::move(ABI->MangleCtx);
77977800
}

clang/lib/CodeGen/CodeGenModule.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ class CodeGenModule : public CodeGenTypeCache {
320320
// This should not be moved earlier, since its initialization depends on some
321321
// of the previous reference members being already initialized and also checks
322322
// if TheTargetCodeGenInfo is NULL
323-
CodeGenTypes Types;
323+
std::unique_ptr<CodeGenTypes> Types;
324324

325325
/// Holds information about C++ vtables.
326326
CodeGenVTables VTables;
@@ -781,14 +781,15 @@ class CodeGenModule : public CodeGenTypeCache {
781781
bool supportsCOMDAT() const;
782782
void maybeSetTrivialComdat(const Decl &D, llvm::GlobalObject &GO);
783783

784+
const ABIInfo &getABIInfo();
784785
CGCXXABI &getCXXABI() const { return *ABI; }
785786
llvm::LLVMContext &getLLVMContext() { return VMContext; }
786787

787788
bool shouldUseTBAA() const { return TBAA != nullptr; }
788789

789790
const TargetCodeGenInfo &getTargetCodeGenInfo();
790791

791-
CodeGenTypes &getTypes() { return Types; }
792+
CodeGenTypes &getTypes() { return *Types; }
792793

793794
CodeGenVTables &getVTables() { return VTables; }
794795

clang/lib/CodeGen/CodeGenTBAA.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "CodeGenTBAA.h"
1818
#include "ABIInfoImpl.h"
19+
#include "CGCXXABI.h"
1920
#include "CGRecordLayout.h"
2021
#include "CodeGenTypes.h"
2122
#include "clang/AST/ASTContext.h"
@@ -36,10 +37,10 @@ using namespace CodeGen;
3637

3738
CodeGenTBAA::CodeGenTBAA(ASTContext &Ctx, CodeGenTypes &CGTypes,
3839
llvm::Module &M, const CodeGenOptions &CGO,
39-
const LangOptions &Features, MangleContext &MContext)
40+
const LangOptions &Features)
4041
: Context(Ctx), CGTypes(CGTypes), Module(M), CodeGenOpts(CGO),
41-
Features(Features), MContext(MContext), MDHelper(M.getContext()),
42-
Root(nullptr), Char(nullptr) {}
42+
Features(Features), MDHelper(M.getContext()), Root(nullptr),
43+
Char(nullptr) {}
4344

4445
CodeGenTBAA::~CodeGenTBAA() {
4546
}
@@ -256,7 +257,8 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) {
256257

257258
SmallString<256> OutName;
258259
llvm::raw_svector_ostream Out(OutName);
259-
MContext.mangleCanonicalTypeName(QualType(ETy, 0), Out);
260+
CGTypes.getCXXABI().getMangleContext().mangleCanonicalTypeName(
261+
QualType(ETy, 0), Out);
260262
return createScalarTypeNode(OutName, getChar(), Size);
261263
}
262264

@@ -481,7 +483,8 @@ llvm::MDNode *CodeGenTBAA::getBaseTypeInfoHelper(const Type *Ty) {
481483
if (Features.CPlusPlus) {
482484
// Don't use the mangler for C code.
483485
llvm::raw_svector_ostream Out(OutName);
484-
MContext.mangleCanonicalTypeName(QualType(Ty, 0), Out);
486+
CGTypes.getCXXABI().getMangleContext().mangleCanonicalTypeName(
487+
QualType(Ty, 0), Out);
485488
} else {
486489
OutName = RD->getName();
487490
}

clang/lib/CodeGen/CodeGenTBAA.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ namespace clang {
2424
class ASTContext;
2525
class CodeGenOptions;
2626
class LangOptions;
27-
class MangleContext;
2827
class QualType;
2928
class Type;
3029

@@ -120,7 +119,6 @@ class CodeGenTBAA {
120119
llvm::Module &Module;
121120
const CodeGenOptions &CodeGenOpts;
122121
const LangOptions &Features;
123-
MangleContext &MContext;
124122

125123
// MDHelper - Helper for creating metadata.
126124
llvm::MDBuilder MDHelper;
@@ -174,8 +172,7 @@ class CodeGenTBAA {
174172

175173
public:
176174
CodeGenTBAA(ASTContext &Ctx, CodeGenTypes &CGTypes, llvm::Module &M,
177-
const CodeGenOptions &CGO, const LangOptions &Features,
178-
MangleContext &MContext);
175+
const CodeGenOptions &CGO, const LangOptions &Features);
179176
~CodeGenTBAA();
180177

181178
/// getTypeInfo - Get metadata used to describe accesses to objects of the

clang/lib/CodeGen/CodeGenTypes.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ using namespace clang;
3030
using namespace CodeGen;
3131

3232
CodeGenTypes::CodeGenTypes(CodeGenModule &cgm)
33-
: CGM(cgm), Context(cgm.getContext()), TheModule(cgm.getModule()),
34-
Target(cgm.getTarget()), TheCXXABI(cgm.getCXXABI()),
35-
TheABIInfo(cgm.getTargetCodeGenInfo().getABIInfo()) {
33+
: CGM(cgm), Context(cgm.getContext()), TheModule(cgm.getModule()),
34+
Target(cgm.getTarget()) {
3635
SkippedLayout = false;
3736
LongDoubleReferenced = false;
3837
}
@@ -43,6 +42,8 @@ CodeGenTypes::~CodeGenTypes() {
4342
delete &*I++;
4443
}
4544

45+
CGCXXABI &CodeGenTypes::getCXXABI() const { return getCGM().getCXXABI(); }
46+
4647
const CodeGenOptions &CodeGenTypes::getCodeGenOpts() const {
4748
return CGM.getCodeGenOpts();
4849
}

clang/lib/CodeGen/CodeGenTypes.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ class CodeGenTypes {
5757
ASTContext &Context;
5858
llvm::Module &TheModule;
5959
const TargetInfo &Target;
60-
CGCXXABI &TheCXXABI;
61-
62-
// This should not be moved earlier, since its initialization depends on some
63-
// of the previous reference members being already initialized
64-
const ABIInfo &TheABIInfo;
6560

6661
/// The opaque type map for Objective-C interfaces. All direct
6762
/// manipulation is done by the runtime interfaces, which are
@@ -106,9 +101,8 @@ class CodeGenTypes {
106101
}
107102
CodeGenModule &getCGM() const { return CGM; }
108103
ASTContext &getContext() const { return Context; }
109-
const ABIInfo &getABIInfo() const { return TheABIInfo; }
110104
const TargetInfo &getTarget() const { return Target; }
111-
CGCXXABI &getCXXABI() const { return TheCXXABI; }
105+
CGCXXABI &getCXXABI() const;
112106
llvm::LLVMContext &getLLVMContext() { return TheModule.getContext(); }
113107
const CodeGenOptions &getCodeGenOpts() const;
114108

clang/lib/CodeGen/MicrosoftCXXABI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ static bool isTrivialForMSVC(const CXXRecordDecl *RD, QualType Ty,
11111111
const Type *Base = nullptr;
11121112
uint64_t NumElts = 0;
11131113
if (CGM.getTarget().getTriple().isAArch64() &&
1114-
CGM.getTypes().getABIInfo().isHomogeneousAggregate(Ty, Base, NumElts) &&
1114+
CGM.getABIInfo().isHomogeneousAggregate(Ty, Base, NumElts) &&
11151115
isa<VectorType>(Base)) {
11161116
return true;
11171117
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// REQUIRES: host-supports-jit
2+
// UNSUPPORTED: system-aix
3+
//
4+
// RUN: cat %s | clang-repl | FileCheck %s
5+
// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
6+
7+
struct box { box() = default; box(int *const data) : data{data} {} int *data{}; };
8+
9+
box foo() { box ret; ret = new int{}; return ret; }
10+
11+
extern "C" int printf(const char *, ...);
12+
printf("good");
13+
// CHECK: good

0 commit comments

Comments
 (0)