Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/swift-4.0-branch' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
swift-ci committed Jul 12, 2017
2 parents 54c8e38 + 15f6571 commit 8c38809
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/clang/AST/RecursiveASTVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -1767,6 +1767,7 @@ DEF_TRAVERSE_DECL(CXXRecordDecl, { TRY_TO(TraverseCXXRecordHelper(D)); })
if (TypeSourceInfo *TSI = D->getTypeAsWritten()) \
TRY_TO(TraverseTypeLoc(TSI->getTypeLoc())); \
\
TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); \
if (!getDerived().shouldVisitTemplateInstantiations() && \
D->getTemplateSpecializationKind() != TSK_ExplicitSpecialization) \
/* Returning from here skips traversing the \
Expand Down
9 changes: 8 additions & 1 deletion lib/CodeGen/CGCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3334,6 +3334,14 @@ void CodeGenFunction::EmitCallArgs(
unsigned Idx = LeftToRight ? I : E - I - 1;
CallExpr::const_arg_iterator Arg = ArgRange.begin() + Idx;
if (!LeftToRight) MaybeEmitImplicitObjectSize(Idx, *Arg);
// If *Arg is an ObjCIndirectCopyRestoreExpr, check that either the types of
// the argument and parameter match or the objc method is parameterized.
assert((!isa<ObjCIndirectCopyRestoreExpr>(*Arg) ||
getContext().hasSameUnqualifiedType((*Arg)->getType(),
ArgTypes[Idx]) ||
(isa<ObjCMethodDecl>(AC.getDecl()) &&
isObjCMethodWithTypeParams(cast<ObjCMethodDecl>(AC.getDecl())))) &&
"Argument and parameter types don't match");
EmitCallArg(Args, *Arg, ArgTypes[Idx]);
EmitNonNullArgCheck(Args.back().RV, ArgTypes[Idx], (*Arg)->getExprLoc(),
AC, ParamsToSkip + Idx);
Expand Down Expand Up @@ -3385,7 +3393,6 @@ void CodeGenFunction::EmitCallArg(CallArgList &args, const Expr *E,
if (const ObjCIndirectCopyRestoreExpr *CRE
= dyn_cast<ObjCIndirectCopyRestoreExpr>(E)) {
assert(getLangOpts().ObjCAutoRefCount);
assert(getContext().hasSameUnqualifiedType(E->getType(), type));
return emitWritebackArg(*this, args, CRE);
}

Expand Down
53 changes: 52 additions & 1 deletion lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "llvm/Support/raw_ostream.h"
#include <cstdlib> // ::getenv
#include <system_error>
#include <sys/utsname.h>

using namespace clang::driver;
using namespace clang::driver::toolchains;
Expand Down Expand Up @@ -510,6 +511,56 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
}
}

// Clang-900 specific change that's cherry-picked from the LLVM change r307372:
static std::string getOSVersion() {
struct utsname info;

if (uname(&info))
return "";

return info.release;
}

static std::string updateTripleOSVersion(std::string TargetTripleString) {
// On darwin, we want to update the version to match that of the target.
std::string::size_type DarwinDashIdx = TargetTripleString.find("-darwin");
if (DarwinDashIdx != std::string::npos) {
TargetTripleString.resize(DarwinDashIdx + strlen("-darwin"));
TargetTripleString += getOSVersion();
return TargetTripleString;
}
std::string::size_type MacOSDashIdx = TargetTripleString.find("-macos");
if (MacOSDashIdx != std::string::npos) {
TargetTripleString.resize(MacOSDashIdx);
// Reset the OS to darwin as the OS version from `uname` doesn't use the
// macOS version scheme.
TargetTripleString += "-darwin";
TargetTripleString += getOSVersion();
}
return TargetTripleString;
}

/// Returns the most appropriate macOS target version for the current process.
///
/// If the macOS SDK version is the same or earlier than the system version,
/// then the SDK version is returned. Otherwise the system version is returned.
static std::string getSystemOrSDKMacOSVersion(StringRef MacOSSDKVersion) {
unsigned Major, Minor, Micro;
llvm::Triple SystemTriple(updateTripleOSVersion(llvm::sys::getProcessTriple()));
if (!SystemTriple.isMacOSX())
return MacOSSDKVersion;
SystemTriple.getMacOSXVersion(Major, Minor, Micro);
VersionTuple SystemVersion(Major, Minor, Micro);
bool HadExtra;
if (!Driver::GetReleaseVersion(MacOSSDKVersion, Major, Minor, Micro,
HadExtra))
return MacOSSDKVersion;
VersionTuple SDKVersion(Major, Minor, Micro);
if (SDKVersion > SystemVersion)
return SystemVersion.getAsString();
return MacOSSDKVersion;
}

void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
const OptTable &Opts = getDriver().getOpts();

Expand Down Expand Up @@ -602,7 +653,7 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
SDK.startswith("iPhoneSimulator"))
iOSTarget = Version;
else if (SDK.startswith("MacOSX"))
OSXTarget = Version;
OSXTarget = getSystemOrSDKMacOSVersion(Version);
else if (SDK.startswith("WatchOS") ||
SDK.startswith("WatchSimulator"))
WatchOSTarget = Version;
Expand Down
3 changes: 3 additions & 0 deletions lib/Frontend/SerializedDiagnosticReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ std::error_code SerializedDiagnosticReader::readDiagnostics(StringRef File) {
llvm::BitstreamCursor Stream(**Buffer);
Optional<llvm::BitstreamBlockInfo> BlockInfo;

if (Stream.AtEndOfStream())
return SDError::InvalidSignature;

// Sniff for the signature.
if (Stream.Read(8) != 'D' ||
Stream.Read(8) != 'I' ||
Expand Down
28 changes: 28 additions & 0 deletions test/CodeGenObjC/parameterized_classes.m
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,31 @@ - (void)setDest:(NSObject *)a {
_destination = a;
}
@end

// CHECK-LABEL: define internal void @"\01-[C0 foo1]"(
// CHECK: {{.*}} = alloca
// CHECK: {{.*}} = alloca
// CHECK: %[[D:.*]] = alloca %[[TY:.*]]*
// CHECK: %[[TEMP:.*]] = alloca %[[TY]]*
// CHECK: %[[V4:.*]] = load %[[TY]]*, %[[TY]]** %[[D]]
// CHECK: store %[[TY]]* %[[V4]], %[[TY]]** %[[TEMP]]
// CHECK: %[[V7:.*]] = bitcast %[[TY]]** %[[TEMP]] to i8**
// CHECK: call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, i8**)*)(i8* %{{.*}}, i8* %{{.*}}, i8** %[[V7]])

@interface P0<ObjectType> : NSObject
- (void)m0:(ObjectType *)first;
@end

@interface C0 : NSObject
-(void)foo1;
@end

@implementation C0 {
P0<NSString *> *x;
}

-(void)foo1 {
NSString *d;
[x m0:&d];
}
@end
10 changes: 10 additions & 0 deletions test/Driver/darwin-sdk-vs-os-version.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// REQUIRES: system-darwin

// Ensure that we never pick a version that's based on the SDK that's newer than
// the system version:
// RUN: rm -rf %t/SDKs/MacOSX10.99.99.sdk
// RUN: mkdir -p %t/SDKs/MacOSX10.99.99.sdk
// RUN: %clang -target x86_64-apple-darwin -isysroot %t/SDKs/MacOSX10.99.99.sdk %s -### 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-MACOSX-SYSTEM-VERSION %s

// CHECK-MACOSX-SYSTEM-VERSION-NOT: 10.99.99"
Empty file added test/Index/Inputs/empty.dia
Empty file.
2 changes: 2 additions & 0 deletions test/Index/read-empty-diags.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// RUN: not c-index-test -read-diagnostics %S/Inputs/empty.dia 2>&1 | FileCheck %s
// CHECK: Trouble deserializing file (Invalid File): Invalid diagnostics signature
58 changes: 58 additions & 0 deletions unittests/Tooling/RecursiveASTVisitorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,62 @@ TEST(RecursiveASTVisitor, DefaultArgumentsAreVisited) {
"static int k = f();\n"));
}

// Check to ensure that nested name specifiers are visited.
class NestedNameSpecifiersVisitor
: public ExpectedLocationVisitor<NestedNameSpecifiersVisitor> {
public:
bool VisitRecordTypeLoc(RecordTypeLoc RTL) {
if (!RTL)
return true;
Match(RTL.getDecl()->getName(), RTL.getNameLoc());
return true;
}

bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) {
if (!NNS)
return true;
if (const NamespaceDecl *ND =
NNS.getNestedNameSpecifier()->getAsNamespace())
Match(ND->getName(), NNS.getLocalBeginLoc());
return ExpectedLocationVisitor::TraverseNestedNameSpecifierLoc(NNS);
}
};

TEST(RecursiveASTVisitor,
NestedNameSpecifiersForTemplateSpecializationsAreVisited) {
StringRef Source = R"(
namespace ns {
struct Outer {
template<typename T, typename U>
struct Nested { };

template<typename T>
static T x;
};
}

template<>
struct ns::Outer::Nested<int, int>;

template<>
struct ns::Outer::Nested<int, int> { };

template<typename T>
struct ns::Outer::Nested<int, T> { };

template<>
int ns::Outer::x<int> = 0;
)";
NestedNameSpecifiersVisitor Visitor;
Visitor.ExpectMatch("ns", 13, 8);
Visitor.ExpectMatch("ns", 16, 8);
Visitor.ExpectMatch("ns", 19, 8);
Visitor.ExpectMatch("ns", 22, 5);
Visitor.ExpectMatch("Outer", 13, 12);
Visitor.ExpectMatch("Outer", 16, 12);
Visitor.ExpectMatch("Outer", 19, 12);
Visitor.ExpectMatch("Outer", 22, 9);
EXPECT_TRUE(Visitor.runOver(Source, NestedNameSpecifiersVisitor::Lang_CXX14));
}

} // end anonymous namespace

0 comments on commit 8c38809

Please sign in to comment.