Skip to content

Commit 82a2bff

Browse files
author
git apple-llvm automerger
committed
Merge commit '3cf1763f83af' from swift/swift-5.2-branch into swift/master
2 parents a1a45d3 + 3cf1763 commit 82a2bff

File tree

10 files changed

+199
-114
lines changed

10 files changed

+199
-114
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/CodeGen/CGDebugInfo.h

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

731730
~ApplyDebugLocation();

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/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/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/SemaObjCProperty.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,11 +1058,13 @@ RedeclarePropertyAccessor(ASTContext &Context, ObjCImplementationDecl *Impl,
10581058
SourceLocation PropertyLoc) {
10591059
ObjCMethodDecl *Decl = AccessorDecl;
10601060
ObjCMethodDecl *ImplDecl = ObjCMethodDecl::Create(
1061-
Context, AtLoc, PropertyLoc, Decl->getSelector(), Decl->getReturnType(),
1061+
Context, AtLoc.isValid() ? AtLoc : Decl->getBeginLoc(),
1062+
PropertyLoc.isValid() ? PropertyLoc : Decl->getEndLoc(),
1063+
Decl->getSelector(), Decl->getReturnType(),
10621064
Decl->getReturnTypeSourceInfo(), Impl, Decl->isInstanceMethod(),
1063-
Decl->isVariadic(), Decl->isPropertyAccessor(), /* isSynthesized*/ true,
1064-
Decl->isImplicit(), Decl->isDefined(), Decl->getImplementationControl(),
1065-
Decl->hasRelatedResultType());
1065+
Decl->isVariadic(), Decl->isPropertyAccessor(),
1066+
/* isSynthesized*/ true, Decl->isImplicit(), Decl->isDefined(),
1067+
Decl->getImplementationControl(), Decl->hasRelatedResultType());
10661068
ImplDecl->getMethodFamily();
10671069
if (Decl->hasAttrs())
10681070
ImplDecl->setAttrs(Decl->getAttrs());

clang/test/CodeGenObjCXX/property-object-cleanup.mm

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %clang_cc1 -triple arm64e-apple-ios13.0 -debug-info-kind=standalone -fobjc-arc -fsanitize=nullability-return \
2+
// RUN: %s -emit-llvm -o - | FileCheck %s
3+
4+
@interface NSObject
5+
+ (id)alloc;
6+
@end
7+
8+
@interface NSString : NSObject
9+
@end
10+
11+
// CHECK: define {{.*}}@"\01-[MyData setData:]"
12+
// CHECK: [[DATA:%.*]] = alloca %struct.Data
13+
// CHECK: call %struct.Data* @_ZN4DataD1Ev(%struct.Data* [[DATA]]){{.*}}, !dbg [[DATA_PROPERTY_LOC:![0-9]+]]
14+
// CHECK-NEXT: ret void
15+
16+
// CHECK: define {{.*}}@"\01-[MyData string]"
17+
// CHECK: call void @__ubsan_handle_nullability_return_v1_abort{{.*}}, !dbg [[STRING_PROPERTY_LOC:![0-9]+]]
18+
// CHECK: ret
19+
20+
@interface MyData : NSObject
21+
struct Data {
22+
NSString *name;
23+
};
24+
25+
// CHECK-DAG: [[DATA_PROPERTY_LOC]] = !DILocation(line: [[@LINE+1]]
26+
@property struct Data data;
27+
28+
// CHECK-DAG: [[STRING_PROPERTY_LOC]] = !DILocation(line: [[@LINE+1]]
29+
@property (nonnull) NSString *string;
30+
31+
@end
32+
33+
@implementation MyData
34+
@end

clang/test/Driver/darwin-opt-record.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
// REQUIRES: system-darwin
22

3-
// RUN: %clang -### -S -o FOO -fsave-optimization-record -arch x86_64 -arch x86_64h %s 2>&1 | FileCheck %s --check-prefix=CHECK-MULTIPLE-ARCH
3+
// RUN: %clang -target x86_64-apple-darwin10 -### -c -o FOO -fsave-optimization-record -arch x86_64 -arch x86_64h %s 2>&1 | FileCheck %s --check-prefix=CHECK-MULTIPLE-ARCH
4+
// RUN: %clang -target x86_64-apple-darwin10 -### -c -o FOO -foptimization-record-file=tmp -arch x86_64 -arch x86_64h %s 2>&1 | FileCheck %s --check-prefix=CHECK-MULTIPLE-ARCH-ERROR
45
//
56
// CHECK-MULTIPLE-ARCH: "-cc1"
67
// CHECK-MULTIPLE-ARCH: "-opt-record-file" "FOO-x86_64.opt.yaml"
78
// CHECK-MULTIPLE-ARCH: "-cc1"
89
// CHECK-MULTIPLE-ARCH: "-opt-record-file" "FOO-x86_64h.opt.yaml"
10+
//
11+
// CHECK-MULTIPLE-ARCH-ERROR: cannot use '-foptimization-record-file' output with multiple -arch options
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %clang_cc1 -ast-dump %s | FileCheck %s
2+
3+
// Test that accessor stubs for default-synthesized ObjC accessors
4+
// have a valid source location.
5+
6+
__attribute__((objc_root_class))
7+
@interface NSObject
8+
+ (id)alloc;
9+
@end
10+
11+
@interface NSString : NSObject
12+
@end
13+
14+
@interface MyData : NSObject
15+
struct Data {
16+
NSString *name;
17+
};
18+
@property struct Data data;
19+
@end
20+
// CHECK: ObjCImplementationDecl {{.*}}line:[[@LINE+2]]{{.*}} MyData
21+
// CHECK: ObjCMethodDecl {{.*}}col:23 implicit - setData: 'void'
22+
@implementation MyData
23+
@end

0 commit comments

Comments
 (0)