Skip to content

Commit

Permalink
Merge from 'main' to 'sycl-web' (intel#52)
Browse files Browse the repository at this point in the history
  CONFLICT (content): Merge conflict in clang/lib/Frontend/CompilerInvocation.cpp
  • Loading branch information
abhinavgaba committed Jun 3, 2021
2 parents 0c366d4 + e6f88dc commit ff9f54e
Show file tree
Hide file tree
Showing 223 changed files with 6,115 additions and 2,407 deletions.
36 changes: 32 additions & 4 deletions clang-tools-extra/clangd/CodeCompletionStrings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ void getSignature(const CodeCompletionString &CCS, std::string *Signature,
}
unsigned SnippetArg = 0;
bool HadObjCArguments = false;
bool HadInformativeChunks = false;
for (const auto &Chunk : CCS) {
// Informative qualifier chunks only clutter completion results, skip
// them.
Expand All @@ -129,10 +130,14 @@ void getSignature(const CodeCompletionString &CCS, std::string *Signature,
// reclassified as qualifiers.
//
// Objective-C:
// Objective-C methods may have multiple typed-text chunks, so we must
// treat them carefully. For Objective-C methods, all typed-text chunks
// will end in ':' (unless there are no arguments, in which case we
// can safely treat them as C++).
// Objective-C methods expressions may have multiple typed-text chunks,
// so we must treat them carefully. For Objective-C methods, all
// typed-text and informative chunks will end in ':' (unless there are
// no arguments, in which case we can safely treat them as C++).
//
// Completing a method declaration itself (not a method expression) is
// similar except that we use the `RequiredQualifiers` to store the
// text before the selector, e.g. `- (void)`.
if (!llvm::StringRef(Chunk.Text).endswith(":")) { // Treat as C++.
if (RequiredQualifiers)
*RequiredQualifiers = std::move(*Signature);
Expand All @@ -147,6 +152,28 @@ void getSignature(const CodeCompletionString &CCS, std::string *Signature,
// methods.
if (!HadObjCArguments) {
HadObjCArguments = true;
// If we have no previous informative chunks (informative selector
// fragments in practice), we treat any previous chunks as
// `RequiredQualifiers` so they will be added as a prefix during the
// completion.
//
// e.g. to complete `- (void)doSomething:(id)argument`:
// - Completion name: `doSomething:`
// - RequiredQualifiers: `- (void)`
// - Snippet/Signature suffix: `(id)argument`
//
// This differs from the case when we're completing a method
// expression with a previous informative selector fragment.
//
// e.g. to complete `[self doSomething:nil ^somethingElse:(id)]`:
// - Previous Informative Chunk: `doSomething:`
// - Completion name: `somethingElse:`
// - Snippet/Signature suffix: `(id)`
if (!HadInformativeChunks) {
if (RequiredQualifiers)
*RequiredQualifiers = std::move(*Signature);
Snippet->clear();
}
Signature->clear();
} else { // Subsequent argument, considered part of snippet/signature.
*Signature += Chunk.Text;
Expand All @@ -173,6 +200,7 @@ void getSignature(const CodeCompletionString &CCS, std::string *Signature,
*Snippet += '}';
break;
case CodeCompletionString::CK_Informative:
HadInformativeChunks = true;
// For example, the word "const" for a const method, or the name of
// the base class for methods that are part of the base class.
*Signature += Chunk.Text;
Expand Down
10 changes: 0 additions & 10 deletions clang-tools-extra/clangd/FindTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,6 @@ struct TargetFinder {
Outer.add(OME->getMethodDecl(), Flags);
}
void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *OPRE) {
// FIXME: We miss visiting the class receiver if one exists, which
// means we skip the corresponding ObjCInterfaceDecl ref since it
// doesn't have a corresponding node.
if (OPRE->isExplicitProperty())
Outer.add(OPRE->getExplicitProperty(), Flags);
else {
Expand Down Expand Up @@ -766,13 +763,6 @@ llvm::SmallVector<ReferenceLoc> refInStmt(const Stmt *S,
}

void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *E) {
// There's no contained TypeLoc node for a class receiver type.
if (E->isClassReceiver()) {
Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(),
E->getReceiverLocation(),
/*IsDecl=*/false,
{E->getClassReceiver()}});
}
Refs.push_back(ReferenceLoc{
NestedNameSpecifierLoc(), E->getLocation(),
/*IsDecl=*/false,
Expand Down
73 changes: 73 additions & 0 deletions clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2796,6 +2796,79 @@ TEST(CompletionTest, ObjectiveCMethodTwoArgumentsFromMiddle) {
EXPECT_THAT(C, ElementsAre(SnippetSuffix("${1:(unsigned int)}")));
}

TEST(CompletionTest, ObjectiveCSimpleMethodDeclaration) {
auto Results = completions(R"objc(
@interface Foo
- (void)foo;
@end
@implementation Foo
fo^
@end
)objc",
/*IndexSymbols=*/{},
/*Opts=*/{}, "Foo.m");

auto C = Results.Completions;
EXPECT_THAT(C, ElementsAre(Named("foo")));
EXPECT_THAT(C, ElementsAre(Kind(CompletionItemKind::Method)));
EXPECT_THAT(C, ElementsAre(Qualifier("- (void)")));
}

TEST(CompletionTest, ObjectiveCMethodDeclaration) {
auto Results = completions(R"objc(
@interface Foo
- (int)valueForCharacter:(char)c secondArgument:(id)object;
@end
@implementation Foo
valueFor^
@end
)objc",
/*IndexSymbols=*/{},
/*Opts=*/{}, "Foo.m");

auto C = Results.Completions;
EXPECT_THAT(C, ElementsAre(Named("valueForCharacter:")));
EXPECT_THAT(C, ElementsAre(Kind(CompletionItemKind::Method)));
EXPECT_THAT(C, ElementsAre(Qualifier("- (int)")));
EXPECT_THAT(C, ElementsAre(Signature("(char)c secondArgument:(id)object")));
}

TEST(CompletionTest, ObjectiveCMethodDeclarationPrefixTyped) {
auto Results = completions(R"objc(
@interface Foo
- (int)valueForCharacter:(char)c;
@end
@implementation Foo
- (int)valueFor^
@end
)objc",
/*IndexSymbols=*/{},
/*Opts=*/{}, "Foo.m");

auto C = Results.Completions;
EXPECT_THAT(C, ElementsAre(Named("valueForCharacter:")));
EXPECT_THAT(C, ElementsAre(Kind(CompletionItemKind::Method)));
EXPECT_THAT(C, ElementsAre(Signature("(char)c")));
}

TEST(CompletionTest, ObjectiveCMethodDeclarationFromMiddle) {
auto Results = completions(R"objc(
@interface Foo
- (int)valueForCharacter:(char)c secondArgument:(id)object;
@end
@implementation Foo
- (int)valueForCharacter:(char)c second^
@end
)objc",
/*IndexSymbols=*/{},
/*Opts=*/{}, "Foo.m");

auto C = Results.Completions;
EXPECT_THAT(C, ElementsAre(Named("secondArgument:")));
EXPECT_THAT(C, ElementsAre(Kind(CompletionItemKind::Method)));
EXPECT_THAT(C, ElementsAre(Signature("(id)object")));
}

TEST(CompletionTest, CursorInSnippets) {
clangd::CodeCompleteOptions Options;
Options.EnableSnippets = true;
Expand Down
3 changes: 1 addition & 2 deletions clang-tools-extra/clangd/unittests/FindTargetTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -981,8 +981,7 @@ TEST_F(TargetDeclTest, ObjC) {
id value = [[Foo]].sharedInstance;
}
)cpp";
// FIXME: We currently can't identify the interface here.
EXPECT_DECLS("ObjCPropertyRefExpr", "+ (id)sharedInstance");
EXPECT_DECLS("ObjCInterfaceTypeLoc", "@interface Foo");

Code = R"cpp(
@interface Foo
Expand Down
9 changes: 8 additions & 1 deletion clang/cmake/caches/Fuchsia-stage2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ if(FUCHSIA_SDK)
set(RUNTIMES_${target}_LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "")

# Compat multilibs.
set(RUNTIMES_${target}+compat_LLVM_BUILD_COMPILER_RT OFF CACHE BOOL "")
set(RUNTIMES_${target}+compat_LIBCXXABI_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
set(RUNTIMES_${target}+compat_LIBCXX_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
set(RUNTIMES_${target}+compat_CMAKE_CXX_FLAGS "${FUCHSIA_${target}_COMPILER_FLAGS} -fc++-abi=itanium" CACHE STRING "")

set(RUNTIMES_${target}+asan_LLVM_BUILD_COMPILER_RT OFF CACHE BOOL "")
set(RUNTIMES_${target}+asan_LLVM_USE_SANITIZER "Address" CACHE STRING "")
set(RUNTIMES_${target}+asan_LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS OFF CACHE BOOL "")
Expand Down Expand Up @@ -237,9 +243,10 @@ if(FUCHSIA_SDK)
list(APPEND RUNTIME_BUILD_ID_LINK "${target}")
endforeach()

set(LLVM_RUNTIME_MULTILIBS "asan;noexcept;asan+noexcept;relative-vtables;relative-vtables+noexcept;relative-vtables+asan;relative-vtables+asan+noexcept" CACHE STRING "")
set(LLVM_RUNTIME_MULTILIBS "asan;noexcept;compat;asan+noexcept;relative-vtables;relative-vtables+noexcept;relative-vtables+asan;relative-vtables+asan+noexcept" CACHE STRING "")
set(LLVM_RUNTIME_MULTILIB_asan_TARGETS "x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
set(LLVM_RUNTIME_MULTILIB_noexcept_TARGETS "x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
set(LLVM_RUNTIME_MULTILIB_compat_TARGETS "x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
set(LLVM_RUNTIME_MULTILIB_asan+noexcept_TARGETS "x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
set(LLVM_RUNTIME_MULTILIB_relative-vtables_TARGETS "x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
set(LLVM_RUNTIME_MULTILIB_relative-vtables+noexcept_TARGETS "x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
Expand Down
11 changes: 10 additions & 1 deletion clang/include/clang/AST/RecursiveASTVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -2638,7 +2638,16 @@ DEF_TRAVERSE_STMT(ObjCMessageExpr, {
TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
})

DEF_TRAVERSE_STMT(ObjCPropertyRefExpr, {})
DEF_TRAVERSE_STMT(ObjCPropertyRefExpr, {
if (S->isClassReceiver()) {
ObjCInterfaceDecl *IDecl = S->getClassReceiver();
QualType Type = IDecl->getASTContext().getObjCInterfaceType(IDecl);
ObjCInterfaceLocInfo Data;
Data.NameLoc = S->getReceiverLocation();
Data.NameEndLoc = Data.NameLoc;
TRY_TO(TraverseTypeLoc(TypeLoc(Type, &Data)));
}
})
DEF_TRAVERSE_STMT(ObjCSubscriptRefExpr, {})
DEF_TRAVERSE_STMT(ObjCProtocolExpr, {})
DEF_TRAVERSE_STMT(ObjCSelectorExpr, {})
Expand Down
5 changes: 4 additions & 1 deletion clang/include/clang/Basic/DiagnosticGroups.td
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@ def UnusedMemberFunction : DiagGroup<"unused-member-function",
def UnusedLabel : DiagGroup<"unused-label">;
def UnusedLambdaCapture : DiagGroup<"unused-lambda-capture">;
def UnusedParameter : DiagGroup<"unused-parameter">;
def UnusedButSetParameter : DiagGroup<"unused-but-set-parameter">;
def UnusedResult : DiagGroup<"unused-result">;
def PotentiallyEvaluatedExpression : DiagGroup<"potentially-evaluated-expression">;
def UnevaluatedExpression : DiagGroup<"unevaluated-expression",
Expand All @@ -736,6 +737,7 @@ def UnusedValue : DiagGroup<"unused-value", [UnusedComparison, UnusedResult,
def UnusedConstVariable : DiagGroup<"unused-const-variable">;
def UnusedVariable : DiagGroup<"unused-variable",
[UnusedConstVariable]>;
def UnusedButSetVariable : DiagGroup<"unused-but-set-variable">;
def UnusedLocalTypedef : DiagGroup<"unused-local-typedef">;
def UnusedPropertyIvar : DiagGroup<"unused-property-ivar">;
def UnusedGetterReturnValue : DiagGroup<"unused-getter-return-value">;
Expand Down Expand Up @@ -877,7 +879,7 @@ def Unused : DiagGroup<"unused",
// UnusedMemberFunction, (clean-up llvm before enabling)
UnusedPrivateField, UnusedLambdaCapture,
UnusedLocalTypedef, UnusedValue, UnusedVariable,
UnusedPropertyIvar]>,
UnusedButSetVariable, UnusedPropertyIvar]>,
DiagCategory<"Unused Entity Issue">;

// Format settings.
Expand Down Expand Up @@ -929,6 +931,7 @@ def Extra : DiagGroup<"extra", [
MissingMethodReturnType,
SignCompare,
UnusedParameter,
UnusedButSetParameter,
NullPointerArithmetic,
EmptyInitStatement,
StringConcatation,
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticParseKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let CategoryName = "Inline Assembly Issue" in {
def err_asm_empty : Error<"__asm used with no assembly instructions">;
def err_inline_ms_asm_parsing : Error<"%0">;
def err_msasm_unsupported_arch : Error<
"Unsupported architecture '%0' for MS-style inline assembly">;
"unsupported architecture '%0' for MS-style inline assembly">;
def err_msasm_unable_to_create_target : Error<
"MS-style inline assembly is not available: %0">;
def err_gnu_inline_asm_disabled : Error<
Expand Down
4 changes: 4 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,12 @@ def note_riscv_repeated_interrupt_attribute : Note<
"repeated RISC-V 'interrupt' attribute is here">;
def warn_unused_parameter : Warning<"unused parameter %0">,
InGroup<UnusedParameter>, DefaultIgnore;
def warn_unused_but_set_parameter : Warning<"parameter %0 set but not used">,
InGroup<UnusedButSetParameter>, DefaultIgnore;
def warn_unused_variable : Warning<"unused variable %0">,
InGroup<UnusedVariable>, DefaultIgnore;
def warn_unused_but_set_variable : Warning<"variable %0 set but not used">,
InGroup<UnusedButSetVariable>, DefaultIgnore;
def warn_unused_local_typedef : Warning<
"unused %select{typedef|type alias}0 %1">,
InGroup<UnusedLocalTypedef>, DefaultIgnore;
Expand Down
6 changes: 6 additions & 0 deletions clang/include/clang/Basic/TargetCXXABI.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ class TargetCXXABI {
return getABIMap().find(Name) != getABIMap().end();
}

// Return true if this target should use the relative vtables C++ ABI by
// default.
static bool usesRelativeVTables(const llvm::Triple &T) {
return T.isOSFuchsia();
}

/// A bogus initialization of the platform ABI.
TargetCXXABI() : TheKind(GenericItanium) {}

Expand Down
12 changes: 8 additions & 4 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -1952,10 +1952,14 @@ defm fine_grained_bitfield_accesses : BoolOption<"f", "fine-grained-bitfield-acc
BothFlags<[CC1Option]>>,
Group<f_clang_Group>;

defm experimental_relative_cxx_abi_vtables : BoolFOption<"experimental-relative-c++-abi-vtables",
LangOpts<"RelativeCXXABIVTables">, DefaultFalse,
PosFlag<SetTrue, [], "Use">, NegFlag<SetFalse, [], "Do not use">,
BothFlags<[CC1Option], " the experimental C++ class ABI for classes with virtual tables">>;
def fexperimental_relative_cxx_abi_vtables :
Flag<["-"], "fexperimental-relative-c++-abi-vtables">,
Group<f_clang_Group>, Flags<[CC1Option]>,
HelpText<"Use the experimental C++ class ABI for classes with virtual tables">;
def fno_experimental_relative_cxx_abi_vtables :
Flag<["-"], "fno-experimental-relative-c++-abi-vtables">,
Group<f_clang_Group>, Flags<[CC1Option]>,
HelpText<"Do not use the experimental C++ class ABI for classes with virtual tables">;

def fcxx_abi_EQ : Joined<["-"], "fc++-abi=">,
Group<f_clang_Group>, Flags<[CC1Option]>,
Expand Down
9 changes: 9 additions & 0 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,11 @@ class Sema final {

bool WarnedStackExhausted = false;

/// Increment when we find a reference; decrement when we find an ignored
/// assignment. Ultimately the value is 0 if every reference is an ignored
/// assignment.
llvm::DenseMap<const VarDecl *, int> RefsMinusAssignments;

public:
Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
TranslationUnitKind TUKind = TU_Complete,
Expand Down Expand Up @@ -5101,6 +5106,10 @@ class Sema final {
void DiagnoseUnusedNestedTypedefs(const RecordDecl *D);
void DiagnoseUnusedDecl(const NamedDecl *ND);

/// If VD is set but not otherwise used, diagnose, for a parameter or a
/// variable.
void DiagnoseUnusedButSetDecl(const VarDecl *VD);

/// Emit \p DiagID if statement located on \p StmtLoc has a suspicious null
/// statement as a \p Body, and it is located on the same line.
///
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5784,6 +5784,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
if (Arg *A = Args.getLastArg(options::OPT_fcxx_abi_EQ))
A->render(Args, CmdArgs);

Args.AddLastArg(CmdArgs, options::OPT_fexperimental_relative_cxx_abi_vtables,
options::OPT_fno_experimental_relative_cxx_abi_vtables);

// Handle -{std, ansi, trigraphs} -- take the last of -{std, ansi}
// (-ansi is equivalent to -std=c89 or -std=c++98).
//
Expand Down
10 changes: 10 additions & 0 deletions clang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3536,6 +3536,11 @@ void CompilerInvocation::GenerateLangArgs(const LangOptions &Opts,
GenerateArg(Args, OPT_fcxx_abi_EQ, TargetCXXABI::getSpelling(*Opts.CXXABI),
SA);

if (Opts.RelativeCXXABIVTables)
GenerateArg(Args, OPT_fexperimental_relative_cxx_abi_vtables, SA);
else
GenerateArg(Args, OPT_fno_experimental_relative_cxx_abi_vtables, SA);

switch (Opts.getDefaultSubGroupSizeType()) {
case LangOptions::SubGroupSizeType::Auto:
GenerateArg(Args, OPT_fsycl_default_sub_group_size, "automatic", SA);
Expand Down Expand Up @@ -4082,6 +4087,11 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
}
}

Opts.RelativeCXXABIVTables =
Args.hasFlag(options::OPT_fexperimental_relative_cxx_abi_vtables,
options::OPT_fno_experimental_relative_cxx_abi_vtables,
TargetCXXABI::usesRelativeVTables(T));

return Diags.getNumErrors() == NumErrorsBefore;
}

Expand Down
3 changes: 0 additions & 3 deletions clang/lib/Index/IndexBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,6 @@ class BodyIndexer : public RecursiveASTVisitor<BodyIndexer> {
}

bool VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
if (E->isClassReceiver())
IndexCtx.handleReference(E->getClassReceiver(), E->getReceiverLocation(),
Parent, ParentDC);
if (E->isExplicitProperty()) {
SmallVector<SymbolRelation, 2> Relations;
SymbolRoleSet Roles = getRolesForRef(E, Relations);
Expand Down
5 changes: 3 additions & 2 deletions clang/lib/Lex/PPDirectives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation HashTokenLoc,

// If this is a #else with a #else before it, report the error.
if (CondInfo.FoundElse)
Diag(Tok, diag::pp_err_else_after_else) << PED_Elif;
Diag(Tok, diag::pp_err_else_after_else);

// Note that we've seen a #else in this conditional.
CondInfo.FoundElse = true;
Expand All @@ -611,7 +611,8 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation HashTokenLoc,
PPConditionalInfo &CondInfo = CurPPLexer->peekConditionalLevel();

// If this is a #elif with a #else before it, report the error.
if (CondInfo.FoundElse) Diag(Tok, diag::pp_err_elif_after_else);
if (CondInfo.FoundElse)
Diag(Tok, diag::pp_err_elif_after_else) << PED_Elif;

// If this is in a skipping block or if we're already handled this #if
// block, don't bother parsing the condition.
Expand Down
Loading

0 comments on commit ff9f54e

Please sign in to comment.