Skip to content

Commit f5816a3

Browse files
Merge commit 'refs/am/changes/a63fc74743bd32d0f9a3fb81aac23d16c8056e83_swift/swift-5.2-branch' into HEAD
2 parents 86014b2 + a63fc74 commit f5816a3

File tree

96 files changed

+2215
-1092
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+2215
-1092
lines changed

clang/docs/ClangCommandLineReference.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1699,7 +1699,7 @@ Emit OpenMP code only for SIMD-based constructs.
16991699

17001700
.. option:: -foptimization-record-file=<arg>
17011701

1702-
Specify the file name of any generated YAML optimization record
1702+
Specify the output name of the file containing the optimization remarks. Implies -fsave-optimization-record. On Darwin platforms, this cannot be used with multiple -arch <arch> options.
17031703

17041704
.. option:: -foptimize-sibling-calls, -fno-optimize-sibling-calls
17051705

clang/lib/Analysis/BodyFarm.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -741,13 +741,17 @@ static Stmt *createObjCPropertyGetter(ASTContext &Ctx,
741741
// First, find the backing ivar.
742742
const ObjCIvarDecl *IVar = nullptr;
743743

744-
// Property accessor stubs sometimes do not correspond to any property.
744+
// Property accessor stubs sometimes do not correspond to any property decl
745+
// in the current interface (but in a superclass). They still have a
746+
// corresponding property impl decl in this case.
745747
if (MD->isSynthesizedAccessorStub()) {
746748
const ObjCInterfaceDecl *IntD = MD->getClassInterface();
747749
const ObjCImplementationDecl *ImpD = IntD->getImplementation();
748-
for (const auto *V: ImpD->ivars()) {
749-
if (V->getName() == MD->getSelector().getNameForSlot(0))
750-
IVar = V;
750+
for (const auto *PI: ImpD->property_impls()) {
751+
if (const ObjCPropertyDecl *P = PI->getPropertyDecl()) {
752+
if (P->getGetterName() == MD->getSelector())
753+
IVar = P->getPropertyIvarDecl();
754+
}
751755
}
752756
}
753757

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,6 @@ StringRef CGDebugInfo::getObjCMethodName(const ObjCMethodDecl *OMD) {
292292
}
293293
} else if (const auto *OCD = dyn_cast<ObjCCategoryImplDecl>(DC)) {
294294
OS << OCD->getClassInterface()->getName() << '(' << OCD->getName() << ')';
295-
} else if (isa<ObjCProtocolDecl>(DC)) {
296-
// We can extract the type of the class from the self pointer.
297-
if (ImplicitParamDecl *SelfDecl = OMD->getSelfDecl()) {
298-
QualType ClassTy =
299-
cast<ObjCObjectPointerType>(SelfDecl->getType())->getPointeeType();
300-
ClassTy.print(OS, PrintingPolicy(LangOptions()));
301-
}
302295
}
303296
OS << ' ' << OMD->getSelector().getAsString() << ']';
304297

clang/lib/CodeGen/CGDebugInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@ class ApplyDebugLocation {
725725
ApplyDebugLocation(ApplyDebugLocation &&Other) : CGF(Other.CGF) {
726726
Other.CGF = nullptr;
727727
}
728+
ApplyDebugLocation &operator=(ApplyDebugLocation &&) = default;
728729

729730
~ApplyDebugLocation();
730731

clang/lib/CodeGen/CGObjC.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ void CodeGenFunction::GenerateObjCGetter(ObjCImplementationDecl *IMP,
981981

982982
generateObjCGetterBody(IMP, PID, OMD, AtomicHelperFn);
983983

984-
FinishFunction();
984+
FinishFunction(OMD->getEndLoc());
985985
}
986986

987987
static bool hasTrivialGetExpr(const ObjCPropertyImplDecl *propImpl) {
@@ -1515,7 +1515,7 @@ void CodeGenFunction::GenerateObjCSetter(ObjCImplementationDecl *IMP,
15151515

15161516
generateObjCSetterBody(IMP, PID, AtomicHelperFn);
15171517

1518-
FinishFunction();
1518+
FinishFunction(OMD->getEndLoc());
15191519
}
15201520

15211521
namespace {

clang/lib/CodeGen/CGObjCMac.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4029,7 +4029,7 @@ llvm::Function *CGObjCCommonMac::GenerateMethod(const ObjCMethodDecl *OMD,
40294029
llvm::Function *
40304030
CGObjCCommonMac::GenerateDirectMethod(const ObjCMethodDecl *OMD,
40314031
const ObjCContainerDecl *CD) {
4032-
auto I = DirectMethodDefinitions.find(OMD);
4032+
auto I = DirectMethodDefinitions.find(OMD->getCanonicalDecl());
40334033
if (I != DirectMethodDefinitions.end())
40344034
return I->second;
40354035

@@ -4042,7 +4042,7 @@ CGObjCCommonMac::GenerateDirectMethod(const ObjCMethodDecl *OMD,
40424042
llvm::Function *Method =
40434043
llvm::Function::Create(MethodTy, llvm::GlobalValue::ExternalLinkage,
40444044
Name.str(), &CGM.getModule());
4045-
DirectMethodDefinitions.insert(std::make_pair(OMD, Method));
4045+
DirectMethodDefinitions.insert(std::make_pair(OMD->getCanonicalDecl(), Method));
40464046

40474047
return Method;
40484048
}

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6194,7 +6194,7 @@ static llvm::Value *emitReduceFiniFunction(CodeGenModule &CGM,
61946194
// Emit the finalizer body:
61956195
// <destroy>(<type>* %0)
61966196
RCG.emitCleanups(CGF, N, PrivateAddr);
6197-
CGF.FinishFunction();
6197+
CGF.FinishFunction(Loc);
61986198
return Fn;
61996199
}
62006200

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,15 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) {
332332
if (HasCleanups) {
333333
// Make sure the line table doesn't jump back into the body for
334334
// the ret after it's been at EndLoc.
335-
if (CGDebugInfo *DI = getDebugInfo())
335+
Optional<ApplyDebugLocation> AL;
336+
if (CGDebugInfo *DI = getDebugInfo()) {
336337
if (OnlySimpleReturnStmts)
337338
DI->EmitLocation(Builder, EndLoc);
339+
else
340+
// We may not have a valid end location. Try to apply it anyway, and
341+
// fall back to an artificial location if needed.
342+
AL = ApplyDebugLocation::CreateDefaultArtificial(*this, EndLoc);
343+
}
338344

339345
PopCleanupBlocks(PrologueCleanupDepth);
340346
}

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,16 +1510,15 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
15101510
!CodeGenOpts.DisableO0ImplyOptNone && CodeGenOpts.OptimizationLevel == 0;
15111511
// We can't add optnone in the following cases, it won't pass the verifier.
15121512
ShouldAddOptNone &= !D->hasAttr<MinSizeAttr>();
1513-
ShouldAddOptNone &= !F->hasFnAttribute(llvm::Attribute::AlwaysInline);
15141513
ShouldAddOptNone &= !D->hasAttr<AlwaysInlineAttr>();
15151514

1516-
if (ShouldAddOptNone || D->hasAttr<OptimizeNoneAttr>()) {
1515+
// Add optnone, but do so only if the function isn't always_inline.
1516+
if ((ShouldAddOptNone || D->hasAttr<OptimizeNoneAttr>()) &&
1517+
!F->hasFnAttribute(llvm::Attribute::AlwaysInline)) {
15171518
B.addAttribute(llvm::Attribute::OptimizeNone);
15181519

15191520
// OptimizeNone implies noinline; we should not be inlining such functions.
15201521
B.addAttribute(llvm::Attribute::NoInline);
1521-
assert(!F->hasFnAttribute(llvm::Attribute::AlwaysInline) &&
1522-
"OptimizeNone and AlwaysInline on same function!");
15231522

15241523
// We still need to handle naked functions even though optnone subsumes
15251524
// much of their semantics.
@@ -1535,7 +1534,8 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
15351534
B.addAttribute(llvm::Attribute::NoInline);
15361535
} else if (D->hasAttr<NoDuplicateAttr>()) {
15371536
B.addAttribute(llvm::Attribute::NoDuplicate);
1538-
} else if (D->hasAttr<NoInlineAttr>()) {
1537+
} else if (D->hasAttr<NoInlineAttr>() && !F->hasFnAttribute(llvm::Attribute::AlwaysInline)) {
1538+
// Add noinline if the function isn't always_inline.
15391539
B.addAttribute(llvm::Attribute::NoInline);
15401540
} else if (D->hasAttr<AlwaysInlineAttr>() &&
15411541
!F->hasFnAttribute(llvm::Attribute::NoInline)) {

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 128 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,132 @@ static bool isNoCommonDefault(const llvm::Triple &Triple) {
13731373
}
13741374
}
13751375

1376+
static bool shouldEmitRemarks(const ArgList &Args) {
1377+
// -fsave-optimization-record enables it.
1378+
if (Args.hasFlag(options::OPT_fsave_optimization_record,
1379+
options::OPT_fno_save_optimization_record, false))
1380+
return true;
1381+
1382+
// -fsave-optimization-record=<format> enables it as well.
1383+
if (Args.hasFlag(options::OPT_fsave_optimization_record_EQ,
1384+
options::OPT_fno_save_optimization_record, false))
1385+
return true;
1386+
1387+
// -foptimization-record-file alone enables it too.
1388+
if (Args.hasFlag(options::OPT_foptimization_record_file_EQ,
1389+
options::OPT_fno_save_optimization_record, false))
1390+
return true;
1391+
1392+
// -foptimization-record-passes alone enables it too.
1393+
if (Args.hasFlag(options::OPT_foptimization_record_passes_EQ,
1394+
options::OPT_fno_save_optimization_record, false))
1395+
return true;
1396+
return false;
1397+
}
1398+
1399+
static bool hasMultipleInvocations(const llvm::Triple &Triple,
1400+
const ArgList &Args) {
1401+
// Supported only on Darwin where we invoke the compiler multiple times
1402+
// followed by an invocation to lipo.
1403+
if (!Triple.isOSDarwin())
1404+
return false;
1405+
// If more than one "-arch <arch>" is specified, we're targeting multiple
1406+
// architectures resulting in a fat binary.
1407+
return Args.getAllArgValues(options::OPT_arch).size() > 1;
1408+
}
1409+
1410+
static bool checkRemarksOptions(const Driver &D, const ArgList &Args,
1411+
const llvm::Triple &Triple) {
1412+
// When enabling remarks, we need to error if:
1413+
// * The remark file is specified but we're targeting multiple architectures,
1414+
// which means more than one remark file is being generated.
1415+
bool hasMultipleInvocations = ::hasMultipleInvocations(Triple, Args);
1416+
bool hasExplicitOutputFile =
1417+
Args.getLastArg(options::OPT_foptimization_record_file_EQ);
1418+
if (hasMultipleInvocations && hasExplicitOutputFile) {
1419+
D.Diag(diag::err_drv_invalid_output_with_multiple_archs)
1420+
<< "-foptimization-record-file";
1421+
return false;
1422+
}
1423+
return true;
1424+
}
1425+
1426+
static void renderRemarksOptions(const ArgList &Args, ArgStringList &CmdArgs,
1427+
const llvm::Triple &Triple,
1428+
const InputInfo &Input, const JobAction &JA) {
1429+
CmdArgs.push_back("-opt-record-file");
1430+
1431+
const Arg *A = Args.getLastArg(options::OPT_foptimization_record_file_EQ);
1432+
if (A) {
1433+
CmdArgs.push_back(A->getValue());
1434+
} else {
1435+
bool hasMultipleArchs =
1436+
Triple.isOSDarwin() && // Only supported on Darwin platforms.
1437+
Args.getAllArgValues(options::OPT_arch).size() > 1;
1438+
SmallString<128> F;
1439+
1440+
if (Args.hasArg(options::OPT_c) || Args.hasArg(options::OPT_S)) {
1441+
if (Arg *FinalOutput = Args.getLastArg(options::OPT_o))
1442+
F = FinalOutput->getValue();
1443+
}
1444+
1445+
if (F.empty()) {
1446+
// Use the input filename.
1447+
F = llvm::sys::path::stem(Input.getBaseInput());
1448+
1449+
// If we're compiling for an offload architecture (i.e. a CUDA device),
1450+
// we need to make the file name for the device compilation different
1451+
// from the host compilation.
1452+
if (!JA.isDeviceOffloading(Action::OFK_None) &&
1453+
!JA.isDeviceOffloading(Action::OFK_Host)) {
1454+
llvm::sys::path::replace_extension(F, "");
1455+
F += Action::GetOffloadingFileNamePrefix(JA.getOffloadingDeviceKind(),
1456+
Triple.normalize());
1457+
F += "-";
1458+
F += JA.getOffloadingArch();
1459+
}
1460+
}
1461+
1462+
// If we're having more than one "-arch", we should name the files
1463+
// differently so that every cc1 invocation writes to a different file.
1464+
// We're doing that by appending "-<arch>" with "<arch>" being the arch
1465+
// name from the triple.
1466+
if (hasMultipleArchs) {
1467+
// First, remember the extension.
1468+
SmallString<64> OldExtension = llvm::sys::path::extension(F);
1469+
// then, remove it.
1470+
llvm::sys::path::replace_extension(F, "");
1471+
// attach -<arch> to it.
1472+
F += "-";
1473+
F += Triple.getArchName();
1474+
// put back the extension.
1475+
llvm::sys::path::replace_extension(F, OldExtension);
1476+
}
1477+
1478+
std::string Extension = "opt.";
1479+
if (const Arg *A =
1480+
Args.getLastArg(options::OPT_fsave_optimization_record_EQ))
1481+
Extension += A->getValue();
1482+
else
1483+
Extension += "yaml";
1484+
1485+
llvm::sys::path::replace_extension(F, Extension);
1486+
CmdArgs.push_back(Args.MakeArgString(F));
1487+
}
1488+
1489+
if (const Arg *A =
1490+
Args.getLastArg(options::OPT_foptimization_record_passes_EQ)) {
1491+
CmdArgs.push_back("-opt-record-passes");
1492+
CmdArgs.push_back(A->getValue());
1493+
}
1494+
1495+
if (const Arg *A =
1496+
Args.getLastArg(options::OPT_fsave_optimization_record_EQ)) {
1497+
CmdArgs.push_back("-opt-record-format");
1498+
CmdArgs.push_back(A->getValue());
1499+
}
1500+
}
1501+
13761502
namespace {
13771503
void RenderARMABI(const llvm::Triple &Triple, const ArgList &Args,
13781504
ArgStringList &CmdArgs) {
@@ -5174,85 +5300,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
51745300
CmdArgs.push_back("-fapple-pragma-pack");
51755301

51765302
// Remarks can be enabled with any of the `-f.*optimization-record.*` flags.
5177-
if (Args.hasFlag(options::OPT_fsave_optimization_record,
5178-
options::OPT_foptimization_record_file_EQ,
5179-
options::OPT_fno_save_optimization_record, false) ||
5180-
Args.hasFlag(options::OPT_fsave_optimization_record_EQ,
5181-
options::OPT_fno_save_optimization_record, false) ||
5182-
Args.hasFlag(options::OPT_foptimization_record_passes_EQ,
5183-
options::OPT_fno_save_optimization_record, false)) {
5184-
CmdArgs.push_back("-opt-record-file");
5185-
5186-
const Arg *A = Args.getLastArg(options::OPT_foptimization_record_file_EQ);
5187-
if (A) {
5188-
CmdArgs.push_back(A->getValue());
5189-
} else {
5190-
bool hasMultipleArchs =
5191-
Triple.isOSDarwin() && // Only supported on Darwin platforms.
5192-
Args.getAllArgValues(options::OPT_arch).size() > 1;
5193-
SmallString<128> F;
5194-
5195-
if (Args.hasArg(options::OPT_c) || Args.hasArg(options::OPT_S)) {
5196-
if (Arg *FinalOutput = Args.getLastArg(options::OPT_o))
5197-
F = FinalOutput->getValue();
5198-
}
5199-
5200-
if (F.empty()) {
5201-
// Use the input filename.
5202-
F = llvm::sys::path::stem(Input.getBaseInput());
5203-
5204-
// If we're compiling for an offload architecture (i.e. a CUDA device),
5205-
// we need to make the file name for the device compilation different
5206-
// from the host compilation.
5207-
if (!JA.isDeviceOffloading(Action::OFK_None) &&
5208-
!JA.isDeviceOffloading(Action::OFK_Host)) {
5209-
llvm::sys::path::replace_extension(F, "");
5210-
F += Action::GetOffloadingFileNamePrefix(JA.getOffloadingDeviceKind(),
5211-
Triple.normalize());
5212-
F += "-";
5213-
F += JA.getOffloadingArch();
5214-
}
5215-
}
5216-
5217-
// If we're having more than one "-arch", we should name the files
5218-
// differently so that every cc1 invocation writes to a different file.
5219-
// We're doing that by appending "-<arch>" with "<arch>" being the arch
5220-
// name from the triple.
5221-
if (hasMultipleArchs) {
5222-
// First, remember the extension.
5223-
SmallString<64> OldExtension = llvm::sys::path::extension(F);
5224-
// then, remove it.
5225-
llvm::sys::path::replace_extension(F, "");
5226-
// attach -<arch> to it.
5227-
F += "-";
5228-
F += Triple.getArchName();
5229-
// put back the extension.
5230-
llvm::sys::path::replace_extension(F, OldExtension);
5231-
}
5232-
5233-
std::string Extension = "opt.";
5234-
if (const Arg *A =
5235-
Args.getLastArg(options::OPT_fsave_optimization_record_EQ))
5236-
Extension += A->getValue();
5237-
else
5238-
Extension += "yaml";
5239-
5240-
llvm::sys::path::replace_extension(F, Extension);
5241-
CmdArgs.push_back(Args.MakeArgString(F));
5242-
}
5243-
5244-
if (const Arg *A =
5245-
Args.getLastArg(options::OPT_foptimization_record_passes_EQ)) {
5246-
CmdArgs.push_back("-opt-record-passes");
5247-
CmdArgs.push_back(A->getValue());
5248-
}
5249-
5250-
if (const Arg *A =
5251-
Args.getLastArg(options::OPT_fsave_optimization_record_EQ)) {
5252-
CmdArgs.push_back("-opt-record-format");
5253-
CmdArgs.push_back(A->getValue());
5254-
}
5255-
}
5303+
if (shouldEmitRemarks(Args) && checkRemarksOptions(D, Args, Triple))
5304+
renderRemarksOptions(Args, CmdArgs, Triple, Input, JA);
52565305

52575306
bool RewriteImports = Args.hasFlag(options::OPT_frewrite_imports,
52585307
options::OPT_fno_rewrite_imports, false);

clang/lib/Sema/SemaDeclObjC.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4920,6 +4920,9 @@ Decl *Sema::ActOnMethodDeclaration(
49204920
}
49214921
}
49224922

4923+
// Insert the invisible arguments, self and _cmd!
4924+
ObjCMethod->createImplicitParams(Context, ObjCMethod->getClassInterface());
4925+
49234926
ActOnDocumentableDecl(ObjCMethod);
49244927

49254928
return ObjCMethod;

0 commit comments

Comments
 (0)