Skip to content

Commit

Permalink
Merged master:cf715717aa8c into amd-gfx:b935d4513c07
Browse files Browse the repository at this point in the history
Local branch amd-gfx b935d45 Merged master:034b95e2839e into amd-gfx:712b9ec4fc09
Remote branch master cf71571 [flang] Allow compiler directives in more places
  • Loading branch information
Sw authored and Sw committed Aug 11, 2020
2 parents b935d45 + cf71571 commit ad88373
Show file tree
Hide file tree
Showing 81 changed files with 17,063 additions and 441 deletions.
6 changes: 4 additions & 2 deletions clang-tools-extra/clangd/CodeComplete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1617,8 +1617,10 @@ class CodeCompleteFlow {

llvm::Optional<float> fuzzyScore(const CompletionCandidate &C) {
// Macros can be very spammy, so we only support prefix completion.
// We won't end up with underfull index results, as macros are sema-only.
if (C.SemaResult && C.SemaResult->Kind == CodeCompletionResult::RK_Macro &&
if (((C.SemaResult &&
C.SemaResult->Kind == CodeCompletionResult::RK_Macro) ||
(C.IndexResult &&
C.IndexResult->SymInfo.Kind == index::SymbolKind::Macro)) &&
!C.Name.startswith_lower(Filter->pattern()))
return None;
return Filter->match(C.Name);
Expand Down
2 changes: 2 additions & 0 deletions clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,8 @@ bool ExtractFunction::prepare(const Selection &Inputs) {
const Node *CommonAnc = Inputs.ASTSelection.commonAncestor();
const SourceManager &SM = Inputs.AST->getSourceManager();
const LangOptions &LangOpts = Inputs.AST->getLangOpts();
if (!LangOpts.CPlusPlus)
return false;
if (auto MaybeExtZone = findExtractionZone(CommonAnc, SM, LangOpts)) {
ExtZone = std::move(*MaybeExtZone);
return true;
Expand Down
11 changes: 8 additions & 3 deletions clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,14 @@ TEST(CompletionTest, Filter) {
EXPECT_THAT(completions(Body + "int main() { S().Foba^ }").Completions,
AllOf(Has("FooBar"), Has("FooBaz"), Not(Has("Qux"))));

// Macros require prefix match.
EXPECT_THAT(completions(Body + "int main() { C^ }").Completions,
AllOf(Has("Car"), Not(Has("MotorCar"))));
// Macros require prefix match, either from index or AST.
Symbol Sym = var("MotorCarIndex");
Sym.SymInfo.Kind = index::SymbolKind::Macro;
EXPECT_THAT(
completions(Body + "int main() { C^ }", {Sym}).Completions,
AllOf(Has("Car"), Not(Has("MotorCar")), Not(Has("MotorCarIndex"))));
EXPECT_THAT(completions(Body + "int main() { M^ }", {Sym}).Completions,
AllOf(Has("MotorCar"), Has("MotorCarIndex")));
}

void testAfterDotCompletion(clangd::CodeCompleteOptions Opts) {
Expand Down
3 changes: 3 additions & 0 deletions clang-tools-extra/clangd/unittests/TweakTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,9 @@ TEST_F(ExtractFunctionTest, FunctionTest) {
EXPECT_THAT(apply(" if(true) [[{ return; }]] "), HasSubstr("extracted"));
// Don't extract uncertain return
EXPECT_THAT(apply(" if(true) [[if (false) return;]] "), StartsWith("fail"));

FileName = "a.c";
EXPECT_THAT(apply(" for([[int i = 0;]];);"), HasSubstr("unavailable"));
}

TEST_F(ExtractFunctionTest, FileTest) {
Expand Down
12 changes: 12 additions & 0 deletions clang/include/clang/ASTMatchers/ASTMatchers.h
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,18 @@ extern const internal::VariadicDynCastAllOfMatcher<Decl,
extern const internal::VariadicDynCastAllOfMatcher<Decl, TemplateTypeParmDecl>
templateTypeParmDecl;

/// Matches template template parameter declarations.
///
/// Given
/// \code
/// template <template <typename> class Z, int N> struct C {};
/// \endcode
/// templateTypeParmDecl()
/// matches 'Z', but not 'N'.
extern const internal::VariadicDynCastAllOfMatcher<Decl,
TemplateTemplateParmDecl>
templateTemplateParmDecl;

/// Matches public C++ declarations and C++ base specifers that specify public
/// inheritance.
///
Expand Down
21 changes: 17 additions & 4 deletions clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2934,14 +2934,27 @@ QualType ASTContext::getAddrSpaceQualType(QualType T,
}

QualType ASTContext::removeAddrSpaceQualType(QualType T) const {
// If the type is not qualified with an address space, just return it
// immediately.
if (!T.hasAddressSpace())
return T;

// If we are composing extended qualifiers together, merge together
// into one ExtQuals node.
QualifierCollector Quals;
const Type *TypeNode = Quals.strip(T);
const Type *TypeNode;

// If the qualifier doesn't have an address space just return it.
if (!Quals.hasAddressSpace())
return T;
while (T.hasAddressSpace()) {
TypeNode = Quals.strip(T);

// If the type no longer has an address space after stripping qualifiers,
// jump out.
if (!QualType(TypeNode, 0).hasAddressSpace())
break;

// There might be sugar in the way. Strip it and try again.
T = T.getSingleStepDesugaredType(*this);
}

Quals.removeAddressSpace();

Expand Down
3 changes: 3 additions & 0 deletions clang/lib/ASTMatchers/ASTMatchersInternal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,9 @@ const internal::VariadicDynCastAllOfMatcher<Decl, NonTypeTemplateParmDecl>
nonTypeTemplateParmDecl;
const internal::VariadicDynCastAllOfMatcher<Decl, TemplateTypeParmDecl>
templateTypeParmDecl;
const internal::VariadicDynCastAllOfMatcher<Decl, TemplateTemplateParmDecl>
templateTemplateParmDecl;

const internal::VariadicAllOfMatcher<QualType> qualType;
const internal::VariadicAllOfMatcher<Type> type;
const internal::VariadicAllOfMatcher<TypeLoc> typeLoc;
Expand Down
1 change: 1 addition & 0 deletions clang/lib/ASTMatchers/Dynamic/Registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ RegistryMaps::RegistryMaps() {
REGISTER_MATCHER(templateArgumentCountIs);
REGISTER_MATCHER(templateName);
REGISTER_MATCHER(templateSpecializationType);
REGISTER_MATCHER(templateTemplateParmDecl);
REGISTER_MATCHER(templateTypeParmDecl);
REGISTER_MATCHER(templateTypeParmType);
REGISTER_MATCHER(throughUsingDecl);
Expand Down
15 changes: 8 additions & 7 deletions clang/lib/Sema/SemaDeclObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2122,7 +2122,12 @@ void Sema::CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
// Add ivar's to class's DeclContext.
for (unsigned i = 0, e = numIvars; i != e; ++i) {
ivars[i]->setLexicalDeclContext(ImpDecl);
IDecl->makeDeclVisibleInContext(ivars[i]);
// In a 'fragile' runtime the ivar was added to the implicit
// ObjCInterfaceDecl while in a 'non-fragile' runtime the ivar is
// only in the ObjCImplementationDecl. In the non-fragile case the ivar
// therefore also needs to be propagated to the ObjCInterfaceDecl.
if (!LangOpts.ObjCRuntime.isFragile())
IDecl->makeDeclVisibleInContext(ivars[i]);
ImpDecl->addDecl(ivars[i]);
}

Expand Down Expand Up @@ -3922,15 +3927,11 @@ Decl *Sema::ActOnAtEnd(Scope *S, SourceRange AtEnd, ArrayRef<Decl *> allMethods,
if (auto *OID = dyn_cast<ObjCImplementationDecl>(CurContext)) {
for (auto PropImpl : OID->property_impls()) {
if (auto *Getter = PropImpl->getGetterMethodDecl())
if (Getter->isSynthesizedAccessorStub()) {
OID->makeDeclVisibleInContext(Getter);
if (Getter->isSynthesizedAccessorStub())
OID->addDecl(Getter);
}
if (auto *Setter = PropImpl->getSetterMethodDecl())
if (Setter->isSynthesizedAccessorStub()) {
OID->makeDeclVisibleInContext(Setter);
if (Setter->isSynthesizedAccessorStub())
OID->addDecl(Setter);
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions clang/lib/Sema/SemaExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,11 @@ static QualType handleFloatConversion(Sema &S, ExprResult &LHS,
bool LHSFloat = LHSType->isRealFloatingType();
bool RHSFloat = RHSType->isRealFloatingType();

// FIXME: Implement floating to fixed point conversion.(Bug 46268)
// Reference N1169 4.1.4 (Type conversion, usual arithmetic conversions).
if ((LHSType->isFixedPointType() && RHSFloat) ||
(LHSFloat && RHSType->isFixedPointType()))
return QualType();
// If we have two real floating types, convert the smaller operand
// to the bigger result.
if (LHSFloat && RHSFloat) {
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ unsigned getOffsetAfterHeaderGuardsAndComments(StringRef FileName,
[](const SourceManager &SM, Lexer &Lex, Token Tok) -> unsigned {
if (checkAndConsumeDirectiveWithName(Lex, "ifndef", Tok)) {
skipComments(Lex, Tok);
if (checkAndConsumeDirectiveWithName(Lex, "define", Tok))
if (checkAndConsumeDirectiveWithName(Lex, "define", Tok) &&
Tok.isAtStartOfLine())
return SM.getFileOffset(Tok.getLocation());
}
return 0;
Expand Down
10 changes: 10 additions & 0 deletions clang/test/CodeGenCXX/address-space-cast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ void func_pchar(__private__ char *x);
void func_pvoid(__private__ void *x);
void func_pint(__private__ int *x);

class Base {
};

class Derived : public Base {
};

void fn(Derived *p) {
__private__ Base *b = (__private__ Base *)p;
}

void test_cast(char *gen_char_ptr, void *gen_void_ptr, int *gen_int_ptr) {
// CHECK: %[[cast:.*]] = addrspacecast i8* %{{.*}} to i8 addrspace(5)*
// CHECK-NEXT: store i8 addrspace(5)* %[[cast]]
Expand Down
5 changes: 5 additions & 0 deletions clang/test/Frontend/fixed_point_errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,8 @@ short _Accum shl_sat = (_Sat short _Accum)200.0hk << 5;

// Division by zero
short _Accum div_zero = 4.5k / 0.0lr; // expected-error {{initializer element is not a compile-time constant}}

void foo(void) {
_Accum x = 0.5k;
if (x == 0.5) {} // expected-error{{invalid operands to binary expression ('_Accum' and 'double')}}
}
9 changes: 9 additions & 0 deletions clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,15 @@ TEST_P(ASTMatchersTest, TemplateTypeParmDecl) {
EXPECT_TRUE(notMatches("template <int N> void f();", templateTypeParmDecl()));
}

TEST_P(ASTMatchersTest, TemplateTemplateParmDecl) {
if (!GetParam().isCXX())
return;
EXPECT_TRUE(matches("template <template <typename> class Z> void f();",
templateTemplateParmDecl(hasName("Z"))));
EXPECT_TRUE(notMatches("template <typename, int> void f();",
templateTemplateParmDecl()));
}

TEST_P(ASTMatchersTest, UserDefinedLiteral) {
if (!GetParam().isCXX11OrLater()) {
return;
Expand Down
12 changes: 12 additions & 0 deletions clang/unittests/Tooling/HeaderIncludesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,18 @@ TEST_F(HeaderIncludesTest, FakeHeaderGuard) {
EXPECT_EQ(Expected, insert(Code, "<vector>"));
}

TEST_F(HeaderIncludesTest, FakeHeaderGuardIfnDef) {
std::string Code = "#ifndef A_H\n"
"#define A_H 1\n"
"#endif";
std::string Expected = "#include \"b.h\"\n"
"#ifndef A_H\n"
"#define A_H 1\n"
"#endif";

EXPECT_EQ(Expected, insert(Code, "\"b.h\""));
}

TEST_F(HeaderIncludesTest, HeaderGuardWithComment) {
std::string Code = "// comment \n"
"#ifndef X // comment\n"
Expand Down
3 changes: 3 additions & 0 deletions flang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
endif()
option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
if(CMAKE_COMPILER_IS_GNUCXX)
set(USE_NO_MAYBE_UNINITIALIZED 1)
endif()

include(CMakeParseArguments)
include(AddLLVM)
Expand Down
4 changes: 3 additions & 1 deletion flang/include/flang/Parser/parse-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ struct ImplicitPartStmt {
Statement<common::Indirection<ParameterStmt>>,
Statement<common::Indirection<OldParameterStmt>>,
Statement<common::Indirection<FormatStmt>>,
Statement<common::Indirection<EntryStmt>>>
Statement<common::Indirection<EntryStmt>>,
common::Indirection<CompilerDirective>>
u;
};

Expand All @@ -430,6 +431,7 @@ struct SpecificationPart {
TUPLE_CLASS_BOILERPLATE(SpecificationPart);
std::tuple<std::list<OpenACCDeclarativeConstruct>,
std::list<OpenMPDeclarativeConstruct>,
std::list<common::Indirection<CompilerDirective>>,
std::list<Statement<common::Indirection<UseStmt>>>,
std::list<Statement<common::Indirection<ImportStmt>>>, ImplicitPart,
std::list<DeclarationConstruct>>
Expand Down
3 changes: 2 additions & 1 deletion flang/lib/Parser/Fortran-parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ TYPE_PARSER(first(
construct<ImplicitPartStmt>(statement(indirect(parameterStmt))),
construct<ImplicitPartStmt>(statement(indirect(oldParameterStmt))),
construct<ImplicitPartStmt>(statement(indirect(formatStmt))),
construct<ImplicitPartStmt>(statement(indirect(entryStmt)))))
construct<ImplicitPartStmt>(statement(indirect(entryStmt))),
construct<ImplicitPartStmt>(indirect(compilerDirective))))

// R512 internal-subprogram -> function-subprogram | subroutine-subprogram
// Internal subprograms are not program units, so their END statements
Expand Down
4 changes: 2 additions & 2 deletions flang/lib/Parser/program-parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ TYPE_PARSER(construct<ProgramUnit>(indirect(Parser<Module>{})) ||
// [declaration-construct]...
TYPE_CONTEXT_PARSER("specification part"_en_US,
construct<SpecificationPart>(many(openaccDeclarativeConstruct),
many(openmpDeclarativeConstruct),
many(openmpDeclarativeConstruct), many(indirect(compilerDirective)),
many(statement(indirect(Parser<UseStmt>{}))),
many(unambiguousStatement(indirect(Parser<ImportStmt>{}))),
implicitPart, many(declarationConstruct)))
Expand Down Expand Up @@ -128,7 +128,7 @@ constexpr auto limitedDeclarationConstruct{recovery(
// statement.
constexpr auto limitedSpecificationPart{inContext("specification part"_en_US,
construct<SpecificationPart>(many(openaccDeclarativeConstruct),
many(openmpDeclarativeConstruct),
many(openmpDeclarativeConstruct), many(indirect(compilerDirective)),
many(statement(indirect(Parser<UseStmt>{}))),
many(unambiguousStatement(indirect(Parser<ImportStmt>{}))),
implicitPart, many(limitedDeclarationConstruct)))};
Expand Down
3 changes: 2 additions & 1 deletion flang/lib/Semantics/resolve-names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5916,7 +5916,8 @@ bool ResolveNamesVisitor::Pre(const parser::SpecificationPart &x) {
Walk(std::get<2>(x.t));
Walk(std::get<3>(x.t));
Walk(std::get<4>(x.t));
const std::list<parser::DeclarationConstruct> &decls{std::get<5>(x.t)};
Walk(std::get<5>(x.t));
const std::list<parser::DeclarationConstruct> &decls{std::get<6>(x.t)};
for (const auto &decl : decls) {
if (const auto *spec{
std::get_if<parser::SpecificationConstruct>(&decl.u)}) {
Expand Down
11 changes: 11 additions & 0 deletions flang/test/Parser/compiler-directives.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
! RUN: %f18 -funparse %s 2>&1

! Test that compiler directives can appear in various places.

module m
!dir$ integer
use iso_fortran_env
!dir$ integer
implicit integer(a-z)
!dir$ integer
end
4 changes: 1 addition & 3 deletions lld/ELF/AArch64ErrataFix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,7 @@ void Patch843419Section::writeTo(uint8_t *buf) {
write32le(buf, read32le(patchee->data().begin() + patcheeOffset));

// Apply any relocation transferred from the original patchee section.
// For a SyntheticSection Buf already has outSecOff added, but relocateAlloc
// also adds outSecOff so we need to subtract to avoid double counting.
this->relocateAlloc(buf - outSecOff, buf - outSecOff + getSize());
relocateAlloc(buf, buf + getSize());

// Return address is the next instruction after the one we have just copied.
uint64_t s = getLDSTAddr() + 4;
Expand Down
6 changes: 2 additions & 4 deletions lld/ELF/ARMErrataFix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,9 @@ void Patch657417Section::writeTo(uint8_t *buf) {
write32le(buf, 0xea000000);
else
write32le(buf, 0x9000f000);
// If we have a relocation then apply it. For a SyntheticSection buf already
// has outSecOff added, but relocateAlloc also adds outSecOff so we need to
// subtract to avoid double counting.
// If we have a relocation then apply it.
if (!relocations.empty()) {
relocateAlloc(buf - outSecOff, buf - outSecOff + getSize());
relocateAlloc(buf, buf + getSize());
return;
}

Expand Down
Loading

0 comments on commit ad88373

Please sign in to comment.