Skip to content

Commit

Permalink
Merged master:ae74252341a0 into amd-gfx:a7ff35a78a7d
Browse files Browse the repository at this point in the history
Local branch amd-gfx a7ff35a Merged master:befd8f82fe20 into amd-gfx:97f9808176a7
Remote branch master ae74252 [flang] Port test_any.sh tests to FileCheck: Hand port canondo{08-18} tests
  • Loading branch information
Sw authored and Sw committed Jun 26, 2020
2 parents a7ff35a + ae74252 commit 962dcb1
Show file tree
Hide file tree
Showing 98 changed files with 761 additions and 665 deletions.
4 changes: 0 additions & 4 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ New Compiler Flags
simplify access to the many single purpose floating point options. The default
setting is ``precise``.

- The default module cache has moved from /tmp to a per-user cache directory.
By default, this is ~/.cache but on some platforms or installations, this
might be elsewhere. The -fmodules-cache-path=... flag continues to work.

Deprecated Compiler Flags
-------------------------

Expand Down
6 changes: 3 additions & 3 deletions clang/include/clang/Basic/SourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -1645,8 +1645,7 @@ class SourceManager : public RefCountedBase<SourceManager> {
unsigned local_sloc_entry_size() const { return LocalSLocEntryTable.size(); }

/// Get a local SLocEntry. This is exposed for indexing.
const SrcMgr::SLocEntry &getLocalSLocEntry(unsigned Index,
bool *Invalid = nullptr) const {
const SrcMgr::SLocEntry &getLocalSLocEntry(unsigned Index) const {
assert(Index < LocalSLocEntryTable.size() && "Invalid index");
return LocalSLocEntryTable[Index];
}
Expand Down Expand Up @@ -1739,12 +1738,13 @@ class SourceManager : public RefCountedBase<SourceManager> {
const SrcMgr::SLocEntry &loadSLocEntry(unsigned Index, bool *Invalid) const;

/// Get the entry with the given unwrapped FileID.
/// Invalid will not be modified for Local IDs.
const SrcMgr::SLocEntry &getSLocEntryByID(int ID,
bool *Invalid = nullptr) const {
assert(ID != -1 && "Using FileID sentinel value");
if (ID < 0)
return getLoadedSLocEntryByID(ID, Invalid);
return getLocalSLocEntry(static_cast<unsigned>(ID), Invalid);
return getLocalSLocEntry(static_cast<unsigned>(ID));
}

const SrcMgr::SLocEntry &
Expand Down
3 changes: 1 addition & 2 deletions clang/include/clang/Driver/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -621,8 +621,7 @@ class Driver {
static bool GetReleaseVersion(StringRef Str,
MutableArrayRef<unsigned> Digits);
/// Compute the default -fmodule-cache-path.
/// \return True if the system provides a default cache directory.
static bool getDefaultModuleCachePath(SmallVectorImpl<char> &Result);
static void getDefaultModuleCachePath(SmallVectorImpl<char> &Result);
};

/// \return True if the last defined optimization level is -Ofast.
Expand Down
11 changes: 2 additions & 9 deletions clang/lib/Basic/SourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -882,11 +882,8 @@ FileID SourceManager::getFileIDLocal(unsigned SLocOffset) const {
unsigned LessIndex = 0;
NumProbes = 0;
while (true) {
bool Invalid = false;
unsigned MiddleIndex = (GreaterIndex-LessIndex)/2+LessIndex;
unsigned MidOffset = getLocalSLocEntry(MiddleIndex, &Invalid).getOffset();
if (Invalid)
return FileID::get(0);
unsigned MidOffset = getLocalSLocEntry(MiddleIndex).getOffset();

++NumProbes;

Expand Down Expand Up @@ -1694,11 +1691,7 @@ FileID SourceManager::translateFile(const FileEntry *SourceFile) const {
// The location we're looking for isn't in the main file; look
// through all of the local source locations.
for (unsigned I = 0, N = local_sloc_entry_size(); I != N; ++I) {
bool Invalid = false;
const SLocEntry &SLoc = getLocalSLocEntry(I, &Invalid);
if (Invalid)
return FileID();

const SLocEntry &SLoc = getLocalSLocEntry(I);
if (SLoc.isFile() && SLoc.getFile().getContentCache() &&
SLoc.getFile().getContentCache()->OrigEntry == SourceFile)
return FileID::get(I);
Expand Down
57 changes: 41 additions & 16 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,38 @@ static void addDashXForInput(const ArgList &Args, const InputInfo &Input,
}
}

static void appendUserToPath(SmallVectorImpl<char> &Result) {
#ifdef LLVM_ON_UNIX
const char *Username = getenv("LOGNAME");
#else
const char *Username = getenv("USERNAME");
#endif
if (Username) {
// Validate that LoginName can be used in a path, and get its length.
size_t Len = 0;
for (const char *P = Username; *P; ++P, ++Len) {
if (!clang::isAlphanumeric(*P) && *P != '_') {
Username = nullptr;
break;
}
}

if (Username && Len > 0) {
Result.append(Username, Username + Len);
return;
}
}

// Fallback to user id.
#ifdef LLVM_ON_UNIX
std::string UID = llvm::utostr(getuid());
#else
// FIXME: Windows seems to have an 'SID' that might work.
std::string UID = "9999";
#endif
Result.append(UID.begin(), UID.end());
}

static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C,
const Driver &D, const InputInfo &Output,
const ArgList &Args,
Expand Down Expand Up @@ -3169,13 +3201,11 @@ static void RenderBuiltinOptions(const ToolChain &TC, const llvm::Triple &T,
CmdArgs.push_back("-fno-math-builtin");
}

bool Driver::getDefaultModuleCachePath(SmallVectorImpl<char> &Result) {
if (llvm::sys::path::cache_directory(Result)) {
llvm::sys::path::append(Result, "clang");
llvm::sys::path::append(Result, "ModuleCache");
return true;
}
return false;
void Driver::getDefaultModuleCachePath(SmallVectorImpl<char> &Result) {
llvm::sys::path::system_temp_directory(/*erasedOnReboot=*/false, Result);
llvm::sys::path::append(Result, "org.llvm.clang.");
appendUserToPath(Result);
llvm::sys::path::append(Result, "ModuleCache");
}

static void RenderModulesOptions(Compilation &C, const Driver &D,
Expand Down Expand Up @@ -3232,7 +3262,6 @@ static void RenderModulesOptions(Compilation &C, const Driver &D,
if (Arg *A = Args.getLastArg(options::OPT_fmodules_cache_path))
Path = A->getValue();

bool HasPath = true;
if (C.isForDiagnostics()) {
// When generating crash reports, we want to emit the modules along with
// the reproduction sources, so we ignore any provided module path.
Expand All @@ -3241,16 +3270,12 @@ static void RenderModulesOptions(Compilation &C, const Driver &D,
llvm::sys::path::append(Path, "modules");
} else if (Path.empty()) {
// No module path was provided: use the default.
HasPath = Driver::getDefaultModuleCachePath(Path);
Driver::getDefaultModuleCachePath(Path);
}

// `HasPath` will only be false if getDefaultModuleCachePath() fails.
// That being said, that failure is unlikely and not caching is harmless.
if (HasPath) {
const char Arg[] = "-fmodules-cache-path=";
Path.insert(Path.begin(), Arg, Arg + strlen(Arg));
CmdArgs.push_back(Args.MakeArgString(Path));
}
const char Arg[] = "-fmodules-cache-path=";
Path.insert(Path.begin(), Arg, Arg + strlen(Arg));
CmdArgs.push_back(Args.MakeArgString(Path));
}

if (HaveModules) {
Expand Down
26 changes: 25 additions & 1 deletion clang/lib/Tooling/Transformer/Stencil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/Error.h"
#include <atomic>
#include <memory>
#include <string>
Expand Down Expand Up @@ -232,8 +233,31 @@ Error evalData(const SelectorData &Data, const MatchFinder::MatchResult &Match,
return RawRange.takeError();
CharSourceRange Range = Lexer::makeFileCharRange(
*RawRange, *Match.SourceManager, Match.Context->getLangOpts());
if (Range.isInvalid()) {
// Validate the original range to attempt to get a meaningful error message.
// If it's valid, then something else is the cause and we just return the
// generic failure message.
if (auto Err = tooling::validateEditRange(*RawRange, *Match.SourceManager))
return handleErrors(std::move(Err), [](std::unique_ptr<StringError> E) {
assert(E->convertToErrorCode() ==
llvm::make_error_code(errc::invalid_argument) &&
"Validation errors must carry the invalid_argument code");
return llvm::createStringError(
errc::invalid_argument,
"selected range could not be resolved to a valid source range; " +
E->getMessage());
});
return llvm::createStringError(
errc::invalid_argument,
"selected range could not be resolved to a valid source range");
}
// Validate `Range`, because `makeFileCharRange` accepts some ranges that
// `validateEditRange` rejects.
if (auto Err = tooling::validateEditRange(Range, *Match.SourceManager))
return Err;
return joinErrors(
llvm::createStringError(errc::invalid_argument,
"selected range is not valid for editing"),
std::move(Err));
*Result += tooling::getText(Range, *Match.Context);
return Error::success();
}
Expand Down
5 changes: 4 additions & 1 deletion clang/test/Driver/modules-cache-path.m
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
// RUN: env USERNAME=asdf LOGNAME=asdf %clang -fmodules -### %s 2>&1 | FileCheck %s -check-prefix=CHECK-SET
// CHECK-SET: -fmodules-cache-path={{.*}}org.llvm.clang.asdf{{[/\\]+}}ModuleCache

// RUN: %clang -fmodules -### %s 2>&1 | FileCheck %s -check-prefix=CHECK-DEFAULT
// CHECK-DEFAULT: -fmodules-cache-path={{.*}}clang{{[/\\]+}}ModuleCache
// CHECK-DEFAULT: -fmodules-cache-path={{.*}}org.llvm.clang.{{[A-Za-z0-9_]*[/\\]+}}ModuleCache
2 changes: 1 addition & 1 deletion clang/unittests/Driver/ModuleCacheTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TEST(ModuleCacheTest, GetTargetAndMode) {
SmallString<128> Buf;
Driver::getDefaultModuleCachePath(Buf);
StringRef Path = Buf;
EXPECT_TRUE(Path.find("clang") != Path.npos);
EXPECT_TRUE(Path.find("org.llvm.clang") != Path.npos);
EXPECT_TRUE(Path.endswith("ModuleCache"));
}
} // end anonymous namespace.
7 changes: 6 additions & 1 deletion clang/unittests/Tooling/StencilTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,12 @@ TEST_F(StencilTest, CatOfInvalidRangeFails) {
hasArgument(0, expr().bind("arg"))));
ASSERT_TRUE(StmtMatch);
Stencil S = cat(node("arg"));
EXPECT_THAT_EXPECTED(S->eval(StmtMatch->Result), Failed<StringError>());
Expected<std::string> Result = S->eval(StmtMatch->Result);
ASSERT_THAT_EXPECTED(Result, Failed<StringError>());
llvm::handleAllErrors(Result.takeError(), [](const llvm::StringError &E) {
EXPECT_THAT(E.getMessage(), AllOf(HasSubstr("selected range"),
HasSubstr("macro expansion")));
});
}

TEST(StencilToStringTest, RawTextOp) {
Expand Down
2 changes: 0 additions & 2 deletions flang/test/Semantics/Inputs/getsymbols02-a.f90
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
! EXEC: ${F18} -fparse-only %s

module mm2a
implicit none
private
Expand Down
2 changes: 0 additions & 2 deletions flang/test/Semantics/Inputs/getsymbols02-b.f90
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
! EXEC: ${F18} -fparse-only %s

module mm2b
use mm2a
implicit none
Expand Down
12 changes: 0 additions & 12 deletions flang/test/Semantics/Inputs/getsymbols02-c.f90

This file was deleted.

6 changes: 3 additions & 3 deletions flang/test/Semantics/canondo08.f90
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
! RUN: %S/test_any.sh %s %t %f18
! Error test -- DO loop uses obsolete loop termination statement
! See R1131 and C1133

! By default, this is not an error and label do are rewritten to non-label do.
! A warning is generated with -Mstandard


! EXEC: ${F18} -funparse-with-symbols -Mstandard %s 2>&1 | ${FileCheck} %s
! RUN: %f18 -funparse-with-symbols -Mstandard %s 2>%t.stderr | FileCheck %s

! CHECK: end do

Expand All @@ -15,7 +14,8 @@
! not want to see label do in the unparse only.
! CHECK-NOT: do [1-9]

! CHECK: A DO loop should terminate with an END DO or CONTINUE
! RUN: FileCheck --check-prefix=ERR --input-file=%t.stderr %s
! ERR: A DO loop should terminate with an END DO or CONTINUE

subroutine foo1()
do 01 k=1,2
Expand Down
8 changes: 4 additions & 4 deletions flang/test/Semantics/canondo09.f90
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
! RUN: %S/test_any.sh %s %t %f18
! Error test -- DO loop uses obsolete loop termination statement
! Error test -- DO loop uses obsolete loop termination statement (warning)
! See R1131 and C1133

! By default, this is not an error and label do are rewritten to non-label do.
! A warning is generated with -Mstandard


! EXEC: ${F18} -funparse-with-symbols -Mstandard %s 2>&1 | ${FileCheck} %s
! RUN: %f18 -funparse-with-symbols -Mstandard %s 2>%t.stderr | FileCheck %s

! CHECK: end do

Expand All @@ -15,7 +14,8 @@
! not want to see label do in the unparse only.
! CHECK-NOT: do [1-9]

! CHECK: A DO loop should terminate with an END DO or CONTINUE
! RUN: FileCheck --check-prefix=ERR --input-file=%t.stderr %s
! ERR: A DO loop should terminate with an END DO or CONTINUE

subroutine foo0()
do 01 j=1,2
Expand Down
8 changes: 4 additions & 4 deletions flang/test/Semantics/canondo10.f90
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
! RUN: %S/test_any.sh %s %t %f18
! Error test -- DO loop uses obsolete loop termination statement
! Error test -- DO loop uses obsolete loop termination statement (warning)
! See R1131 and C1133

! By default, this is not an error and label do are rewritten to non-label do.
! A warning is generated with -Mstandard


! EXEC: ${F18} -funparse-with-symbols -Mstandard %s 2>&1 | ${FileCheck} %s
! RUN: %f18 -funparse-with-symbols -Mstandard %s 2>%t.stderr | FileCheck %s

! CHECK: end do

Expand All @@ -15,7 +14,8 @@
! not want to see label do in the unparse only.
! CHECK-NOT: do [1-9]

! CHECK: A DO loop should terminate with an END DO or CONTINUE
! RUN: FileCheck --check-prefix=ERR --input-file=%t.stderr %s
! ERR: A DO loop should terminate with an END DO or CONTINUE

subroutine foo2()
do 01 l=1,2
Expand Down
8 changes: 4 additions & 4 deletions flang/test/Semantics/canondo11.f90
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
! RUN: %S/test_any.sh %s %t %f18
! Error test -- DO loop uses obsolete loop termination statement
! Error test -- DO loop uses obsolete loop termination statement (warning)
! See R1131 and C1133

! By default, this is not an error and label do are rewritten to non-label do.
! A warning is generated with -Mstandard


! EXEC: ${F18} -funparse-with-symbols -Mstandard %s 2>&1 | ${FileCheck} %s
! RUN: %f18 -funparse-with-symbols -Mstandard %s 2>%t.stderr | FileCheck %s

! CHECK: end do

Expand All @@ -15,7 +14,8 @@
! not want to see label do in the unparse only.
! CHECK-NOT: do [1-9]

! CHECK: A DO loop should terminate with an END DO or CONTINUE
! RUN: FileCheck --check-prefix=ERR --input-file=%t.stderr %s
! ERR: A DO loop should terminate with an END DO or CONTINUE

subroutine foo3()
real :: a(10, 10), b(10, 10) = 1.0
Expand Down
8 changes: 4 additions & 4 deletions flang/test/Semantics/canondo12.f90
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
! RUN: %S/test_any.sh %s %t %f18
! Error test -- DO loop uses obsolete loop termination statement
! Error test -- DO loop uses obsolete loop termination statement (warning)
! See R1131 and C1133

! By default, this is not an error and label do are rewritten to non-label do.
! A warning is generated with -Mstandard

! EXEC: ${F18} -funparse-with-symbols -Mstandard %s 2>&1 | ${FileCheck} %s
! RUN: %f18 -funparse-with-symbols -Mstandard %s 2>%t.stderr | FileCheck %s

! CHECK: end do

Expand All @@ -14,7 +13,8 @@
! not want to see label do in the unparse only.
! CHECK-NOT: do [1-9]

! CHECK: A DO loop should terminate with an END DO or CONTINUE
! RUN: FileCheck --check-prefix=ERR --input-file=%t.stderr %s
! ERR: A DO loop should terminate with an END DO or CONTINUE

subroutine foo4()
real :: a(10, 10), b(10, 10) = 1.0
Expand Down
Loading

0 comments on commit 962dcb1

Please sign in to comment.